Account Filtering
By default, all orders / fills are loaded at startup for all accounts to which the user is mapped. You can specify that order/ fills be loaded for only a specific set of accounts by enabling account filtering. Account Filtering is done at the API level and if it is enabled, the API will only subscribe and sync to the accounts specified.
Creating a filter on the TradeSubscription is not the same as setting EnableAccountFiltering to true. Listed below are the differences:
| Creating a TradeSubscription Filter | EnableAccountFiltering |
|---|---|
| TradeSubscription will only have the order and fills for that particular Account | The API will only subscribe and sync to the accounts specified ( only those accounts will be available to trade and order/ fills be loaded for only for those specific set of accounts). |
| The API gets messages for all accounts from the edge server and the API then processes the messages based on the account filter on the TradeSubscription. | Reduces the number of messages on the network because the edge only sends in communication for the accounts subscribed for. |
Specifically, you perform the following steps.
-
Set the tt_net_sdk.TTAPIOptions.EnableAccountFiltering property to ‘true’ before initializing the SDK.
// ... tt_net_sdk.TTAPIOptions apiConfig = new tt_net_sdk.TTAPIOptions( tt_net_sdk.TTAPIOptions.SDKMode.Server, environment, appSecretKey, 5000); apiConfig.EnableAccountFiltering = true; // … -
Register for the tt_net_sdk.TTAPI.AccountSynced event and define the corresponding event handler
TTAPI m_api; // … public void m_api_TTAPIStatusUpdate(object sender, TTAPIStatusUpdateEventArgs e) { // … m_api.AccountSynced += m_api_AccountSynced; // ... } private void m_api_AccountSynced(object sender, AccountSyncedEventArgs e) { // An order can be placed at this point and not before this (even if the OrderBookSync event is received) with the account that this event was received for } -
Call the tt_net_sdk.TTAPI.SubscribeAccounts() method passing a list of the accounts for which you want to load orders / fills. Please note the SubscribeAccounts() should be called as soon as the API is initialized and ready to be used.
void loadAccounts (List<Account> accounts) { m_api.SubscribeAccounts(accounts); }