Creating custom trade subscription filters
All of the predefined trade filters derive from the TradeSubscriptionFilter class. You can also create your own custom filters.
To create a custom filter class, you:
- Derive your custom filter class from the TradeSubscriptionFilter class.
- Provide implementations in your custom filter class for the following abstract base class methods:
public abstract bool IsMatch(Order order);
Determines whether a given order matches your
public abstract bool IsMatch(Fill fill);
Determines whether a given fill matches your filter
public abstract TradeSubscriptionFilter Clone();
Creates a deep copy of your filter
public abstract bool IsEqual(TradeSubscriptionFilter filter);
Determines whether two filters match
TT recommends that you write filter logic from a positive match perspective and avoid using the Negates property in your logic.
The following example creates a custom trade subscription filter that includes only those orders and fills whose BuySell and Username properties match those values provided in the constructor.
class TradeSubscriptionMyCustomFilter : TradeSubscriptionFilter
{
private BuySell dir { get; set; }
private String userName { get; set; }
public BuySell Direction
{
get
{
return dir;
}
}
public String Username
{
get
{
return userName;
}
}
public TradeSubscriptionMyCustomFilter(BuySell d, String un, bool negates,
string name) : base(negates, name)
{
dir = d;
userName = un;
}
public override bool IsMatch(Order order)
{
return (dir == order.BuySell && userName == order.UserName);
}
public override bool IsMatch(Fill fill)
{
return (dir == fill.BuySell && userName == fill.UserName);
}
public override TradeSubscriptionFilter Clone()
{
TradeSubscriptionMyCustomFilter clonedFilter = new
TradeSubscriptionMyCustomFilter(this.dir, this.userName, this.Negates,
this.Name);
return clonedFilter;
}
public override bool IsEqual(TradeSubscriptionFilter filter)
{
TradeSubscriptionMyCustomFilter myCustFilter = filter as
TradeSubscriptionMyCustomFilter;
if (myCustFilter != null)
{
return (Direction == myCustFilter.Direction &&
Username == myCustFilter.Username &&
Negates == myCustFilter.Negates);
}
return false;
}
}