Class AccountListManager

java.lang.Object
velox.api.layer1.common.helper.AccountListManager

public class AccountListManager extends Object
Helper class to manage account list, map instrument aliases to account and map orders to accounts.

To use this class, you need to call onUserMessage(Object) with any user message you receive in Layer1ApiAdminListener.onUserMessage(Object) (needed message will be picked by this class itself)

To be able to map orders to accounts, you need to call onOrderUpdated(OrderInfoUpdate) with any order updates you receive in Layer1ApiTradingListener.onOrderUpdated(OrderInfoUpdate).

This class is thread-safe.

  • Constructor Details

    • AccountListManager

      public AccountListManager()
  • Method Details

    • getAccounts

      public Set<AccountInfo> getAccounts()
      Returns all available accounts.
      Returns:
      account info set
    • getPrimaryAccountByProvider

      public AccountInfo getPrimaryAccountByProvider(String providerProgrammaticName)
      Returns primary account info for the provider.
      Parameters:
      providerProgrammaticName - provider programmatic name for the account. See AccountInfo.providerProgrammaticName
      Returns:
      primary account info for the provider or null if not found
      See Also:
    • getProviderOtherAccountsByAccountId

      public List<AccountInfo> getProviderOtherAccountsByAccountId(String accountId, boolean includePrimary)
      Returns all accounts for the provider by the id of one of the provider accounts (e.g. if the provider has multiple accounts, you can get all of them by the id of one of them).
      Parameters:
      accountId - account id of one of the provider accounts
      includePrimary - whether to include primary account to the result
      Returns:
      list of all accounts for the provider by the id of one of the provider accounts
    • getProvidersWithMultiAccounts

      public Set<String> getProvidersWithMultiAccounts()
      Returns all providers with multiple accounts (providers are represented by their programmatic name).
      Returns:
      set of providers programmatic name for providers with multiple accounts
      See Also:
    • getAccountById

      public AccountInfo getAccountById(String accountId)
      Returns account info by account id.
      Parameters:
      accountId - account id
      Returns:
      account info or null if not found
    • getAccountsByAlias

      public Set<AccountInfo> getAccountsByAlias(String alias)
      Returns all account infos for instrument alias.
      Parameters:
      alias - instrument alias
      Returns:
      account info set
    • getAliasesByAccountId

      public Set<String> getAliasesByAccountId(String accountId)
      Returns the list of all currently subscribed instrument aliases for account id.
      Parameters:
      accountId - account id
      Returns:
      set of instrument aliases for given account id
    • getAccountByOrderId

      public AccountInfo getAccountByOrderId(String orderId)
      Returns account info by order id.
      Parameters:
      orderId - order id
      Returns:
      account info or null if not found
    • isPrimaryAccountOrNull

      public Boolean isPrimaryAccountOrNull(String accountId)
      Checks if the account is primary by account id (null is considered primary). If the account is not found returns null.
      Parameters:
      accountId - account id
      Returns:
      true if the account is primary, false otherwise or null if the account is not found
    • isPrimaryAccount

      public boolean isPrimaryAccount(String accountId)
      Checks if the account is primary by account id (null is considered primary). If the account is not found returns true.
      Parameters:
      accountId - account id
      Returns:
      true if the account is primary, false otherwise
    • isPrimaryAccountOrderOrNull

      public Boolean isPrimaryAccountOrderOrNull(String orderId)
      Checks if the account is primary by order id. If the account or order is not found returns null.
      Parameters:
      orderId - order id
      Returns:
      true if the account is primary, false otherwise or null if the account or order is not found
    • isPrimaryAccountOrder

      public boolean isPrimaryAccountOrder(String orderId)
      Checks if the account is primary by order id. If the account or order is not found returns true.
      Parameters:
      orderId - order id
      Returns:
      true if the account is primary, false otherwise
    • onUserMessage

      public boolean onUserMessage(Object message)
      Takes any user messages while accepts and processes only TradingAccountsInfoMessage to update the account list. Should be called from Layer1ApiAdminListener.onUserMessage(Object) like this:
       
            AccountListManager accountListManager = new AccountListManager();
            // ...
            @Override
            void onUserMessage(Object data) {
                accountListManager.onUserMessage(data);
      
                // your code to handle any other messages here ...
            }
       
      You can check if the account list has been updated by checking the return value.
      Parameters:
      message - any user message received by Layer1ApiAdminListener.onUserMessage(Object)
      Returns:
      true if the account list has any updates (new account added/removed or account has new alias added/removed, or primary account was changed), false otherwise
    • generateMessagesFromAccountsList

      public List<TradingAccountsInfoMessage> generateMessagesFromAccountsList()
      Generates messages from the accounts list as if they were received from the provider (with isAdd=true for each).
      Returns:
      list of messages for each account
    • onOrderUpdated

      public void onOrderUpdated(OrderInfoUpdate orderInfoUpdate)
      Takes order update messages to map orders to the accounts. Should be called from Layer1ApiTradingListener.onOrderUpdated(OrderInfoUpdate) like this:
       
            AccountListManager accountListManager = new AccountListManager();
            // ...
            @Override
            void onOrderUpdated(OrderInfoUpdate orderInfoUpdate) {
                accountListManager.onOrderUpdated(data);
      
                // your code to handle orderInfoUpdate the way you want ...
            }
       

      Note: if you don't need to know account info for any order, no need to call this method.

      Parameters:
      orderInfoUpdate - order info update message with account id (if specified)