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); }
Important Notes
An application will need to keep track of the accounts that are finished if it needs to wait for all of the orders / fills for all of the accounts to be downloaded before proceeding.
If an order is sent on an account not subscribed to in SubscribeAccounts, it will be rejected with a routing error.
TradeSubscriptions instances started before the SubscribeAccounts() method is called will be empty but would populate as orders / fills arrive after the SubscribeAccounts() method is called.
If EnableAccountFiltering is set to true and SubscribeAccounts is not called with a valid list of accounts (should not be empty), no accounts will be subscribed by the API and therefore not be available to trade. If this occurs, your logs will contain Missing account subscription messages on the rejected orders along with the OrderRejectReason.RoutingError. Accounts must be synced before routing an order. Typically, this point in time is known to the user via the OrderbookDownload event but when you use the advanced EnableAccountFiltering, it is when each account is synced, which is indicated by the AccountSynced event.
When using EnableAccountFiltering, please also make certain EnableOrderExecution is set to true when the SDK is initialized.