{"id":8086,"date":"2025-09-04T23:21:47","date_gmt":"2025-09-05T04:21:47","guid":{"rendered":"https:\/\/librarytestdev.wpenginepowered.com\/?post_type=doc&#038;p=8086"},"modified":"2025-09-04T23:23:49","modified_gmt":"2025-09-05T04:23:49","slug":"creating-custom-trade-subscription-filters","status":"publish","type":"doc","link":"https:\/\/library-staging.tradingtechnologies.com\/apis\/tt-net-sdk\/working-with-trade-subscriptions\/creating-custom-trade-subscription-filters\/","title":{"rendered":"Creating custom trade subscription filters"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">All of the predefined trade filters derive from the&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.TradeSubscriptionFilter.html\">TradeSubscriptionFilter<\/a>&nbsp;class. You can also create your own custom filters.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To create a custom filter class, you:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Derive your custom filter class from the\u00a0<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.TradeSubscriptionFilter.html\">TradeSubscriptionFilter<\/a>\u00a0class.<\/li>\n\n\n\n<li>Provide implementations in your custom filter class for the following abstract base class methods:\n<ul class=\"wp-block-list\">\n<li><code>public abstract bool IsMatch(Order order);<\/code>Determines whether a given order matches your<\/li>\n\n\n\n<li><code>public abstract bool IsMatch(Fill fill);<\/code>Determines whether a given fill matches your filter<\/li>\n\n\n\n<li><code>public abstract TradeSubscriptionFilter Clone();<\/code>Creates a deep copy of your filter<\/li>\n\n\n\n<li><code>public abstract bool IsEqual(TradeSubscriptionFilter filter);<\/code>Determines whether two filters match<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">TT recommends that you write filter logic from a positive match perspective and avoid using the Negates property in your logic.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class TradeSubscriptionMyCustomFilter : TradeSubscriptionFilter\n{\n  private BuySell dir { get; set; }\n  private String userName { get; set; }\n\n  public BuySell Direction\n  {\n    get\n    {\n      return dir;\n    }\n  }\n\n  public String Username\n  {\n    get\n    {\n      return userName;\n    }\n  }\n\n  public TradeSubscriptionMyCustomFilter(BuySell d, String un, bool negates,\n    string name) : base(negates, name)\n  {\n    dir = d;\n    userName = un;\n  }\n\n  public override bool IsMatch(Order order)\n  {\n    return (dir == order.BuySell &amp;&amp; userName == order.UserName);\n  }\n\n  public override bool IsMatch(Fill fill)\n  {\n    return (dir == fill.BuySell &amp;&amp; userName == fill.UserName);\n  }\n\n  public override TradeSubscriptionFilter Clone()\n  {\n    TradeSubscriptionMyCustomFilter clonedFilter = new\n      TradeSubscriptionMyCustomFilter(this.dir, this.userName, this.Negates,\n        this.Name);\n    return clonedFilter;\n  }\n\n  public override bool IsEqual(TradeSubscriptionFilter filter)\n  {\n    TradeSubscriptionMyCustomFilter myCustFilter = filter as\n      TradeSubscriptionMyCustomFilter;\n    if (myCustFilter != null)\n    {\n      return (Direction == myCustFilter.Direction &amp;&amp;\n        Username == myCustFilter.Username &amp;&amp;\n        Negates == myCustFilter.Negates);\n    }\n    return false;\n  }\n}\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"see-also\"><a href=\"\/tt-net-sdk\/articles\/trd-create-custom-filters.html#see-also\"><\/a>See Also<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"\/tt-net-sdk\/api\/tt_net_sdk.TradeSubscriptionFilter.html#tt_net_sdk_TradeSubscriptionFilter_Clone\">TradeSubscriptionFilter.Clone()<\/a><\/li>\n\n\n\n<li><a href=\"\/tt-net-sdk\/api\/tt_net_sdk.TradeSubscriptionFilter.html#tt_net_sdk_TradeSubscriptionFilter_IsEqual_tt_net_sdk_TradeSubscriptionFilter_\">TradeSubscriptionFilter.IsEqual()<\/a><\/li>\n\n\n\n<li><a href=\"\/tt-net-sdk\/apitt_net_sdk.TradeSubscriptionFilter.html#tt_net_sdk_TradeSubscriptionFilter_IsMatch_tt_net_sdk_Fill_\">TradeSubscriptionFilter.IsMatch()<\/a><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p class=\"wp-block-paragraph\">All of the predefined trade filters derive from the&nbsp;<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.TradeSubscriptionFilter.html\">TradeSubscriptionFilter<\/a>&nbsp;class. You can also create your own custom filters.<\/p>\n<p class=\"wp-block-paragraph\">To create a custom filter class, you:<\/p>\n<p class=\"wp-block-paragraph\">TT recommends that you write filter logic from a positive match perspective and avoid using the Negates property in your logic.<\/p>\n<p class=\"wp-block-paragraph\">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.<\/p>\n<h3 class=\"wp-block-heading\" id=\"see-also\"><a href=\"\/tt-net-sdk\/articles\/trd-create-custom-filters.html#see-also\"><\/a>See Also<\/h3>\n<p class=\"wp-block-paragraph\">\n","protected":false},"author":2,"template":"wp-custom-template-single-doc-tt-net-sdk","meta":{"_acf_changed":true,"footnotes":""},"docs-category":[1610],"class_list":["post-8086","doc","type-doc","status-publish","hentry","docs-category-working-with-trade-subscriptions"],"acf":[],"_links":{"self":[{"href":"https:\/\/library-staging.tradingtechnologies.com\/ja\/wp-json\/wp\/v2\/doc\/8086","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/library-staging.tradingtechnologies.com\/ja\/wp-json\/wp\/v2\/doc"}],"about":[{"href":"https:\/\/library-staging.tradingtechnologies.com\/ja\/wp-json\/wp\/v2\/types\/doc"}],"author":[{"embeddable":true,"href":"https:\/\/library-staging.tradingtechnologies.com\/ja\/wp-json\/wp\/v2\/users\/2"}],"version-history":[{"count":0,"href":"https:\/\/library-staging.tradingtechnologies.com\/ja\/wp-json\/wp\/v2\/doc\/8086\/revisions"}],"wp:attachment":[{"href":"https:\/\/library-staging.tradingtechnologies.com\/ja\/wp-json\/wp\/v2\/media?parent=8086"}],"wp:term":[{"taxonomy":"docs-category","embeddable":true,"href":"https:\/\/library-staging.tradingtechnologies.com\/ja\/wp-json\/wp\/v2\/docs-category?post=8086"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}