using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using TradeIdeas.TIProGUI;
using TradeIdeas.MiscSupport;
namespace TIProAutoTradeExtension
{
///
/// A single order can be executed by breaking it up into any number of executions of any size to actuall fill the order.
///
public class TradeExecution : IRowDataCapable
{
private string _execId = "";
public string ExecId
{
get { return _execId; }
set { _execId = value; }
}
private string _orderId = "";
public string OrderId
{
get { return _orderId; }
set { _orderId = value; }
}
private string _symbol = "";
public string Symbol
{
get { return _symbol; }
set { _symbol = value; }
}
private double _commission = 0;
[ColumnInfoAttribute(Format = "2", SizeHint = "XXXXX.XX", DisplayName = "Commission")]
public double Commission
{
get { return _commission; }
set { _commission = value; }
}
private double _realizedPnl = 0;
[ColumnInfoAttribute(Format = "profit", SizeHint = "XXXXX.XX", DisplayName = "Realized P&L")]
[Browsable(false)]
public double RealizedPnl
{
get { return _realizedPnl; }
set { _realizedPnl = value; }
}
private Instrument _instrument;
[Browsable(false)]
public Instrument Instrument
{
get { return _instrument; }
set { _instrument = value; }
}
private TradingStrategy _strategy;
[Browsable(false)]
public TradingStrategy Strategy
{
get { return _strategy; }
set { _strategy = value; }
}
///
/// Name of the strategy that corresponds to the order.
///
[ColumnInfoAttribute(DisplayName = "Strategy")]
public string StrategyName
{
get
{
if (null != _strategy)
return _strategy.Name;
return "";
}
}
private double _price;
[ColumnInfoAttribute(Format = "4")]
public double Price
{
get { return _price; }
set { _price = value; }
}
private decimal _shares = 0;
[ColumnInfoAttribute(Format = "N1")]
public decimal Shares
{
get { return _shares; }
set { _shares = value; }
}
private bool _isBuy = true;
[Browsable(false)]
public bool IsBuy
{
get { return _isBuy; }
set { _isBuy = value; }
}
[ColumnInfoAttribute()]
public string Direction
{
get
{
if (_isBuy)
return "Buy";
else
return "Sell";
}
}
private DateTime _fillTime = ServerFormats.Now;
[ColumnInfoAttribute(SizeHint = "XX:XX XX", Format = "t", DisplayName = "Fill Time")]
public DateTime FillTime
{
get { return _fillTime; }
set { _fillTime = value; }
}
///
/// Order reference as submitted in the executing order in the OrderRef field.
///
//[Browsable(false)]
public string OrderReference { get; set; }
private Account _account;
[Browsable(false)]
public Account Account
{
get { return _account; }
set { _account = value; }
}
private double _stopPrice = -1;
[Browsable(false)]
public double StopPrice { get { return _stopPrice; } set { _stopPrice = value; } }
private double _signalPrice = -1;
[Browsable(false)]
public double SignalPrice { get { return _signalPrice; } set { _signalPrice = value; } }
[Browsable(false)]
public string Tags { get; set; }
[ColumnInfoAttribute(DisplayName = "Account")]
public string AccountName
{
get
{
if (null != _account)
return _account.DisplayName;
return "";
}
}
private IBroker _broker;
[Browsable(false)]
public IBroker Broker
{
get { return _broker; }
set { _broker = value; }
}
[Browsable(false)]
public TradeOrder TradeOrder { get; set; }
public TradeExecution() { }
public RowData ToRowData()
{
return RowDataHelper.GetRowDataFromObject(this);
}
public override bool Equals(System.Object obj)
{
// If parameter is null return false.
if (obj == null)
return false;
// If parameter cannot be cast to TradeExecution return false.
TradeExecution c = obj as TradeExecution;
if ((System.Object)c == null)
return false;
// Return true if the fields match:
bool matches = ExecId == c.ExecId && Account.Equals(c.Account);
return matches;
}
public bool Equals(TradeExecution c)
{
// If parameter is null return false:
if ((object)c == null)
return false;
// Return true if the fields match:
bool matches = ExecId == c.ExecId && Account.Equals(c.Account);
return matches;
}
public override int GetHashCode()
{
return ExecId.GetHashCode();
}
}
}