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

      @Deprecated public AccountInfo getPrimaryAccountByProvider(String providerProgrammaticName)
      Deprecated.
      primary can be selected for each instrument separately from GUI. So for the same provider there can be multiple primary accounts. Use getSelectedAccountForAlias(String) instead.
      Returns primary account info for the provider.
      Parameters:
      providerProgrammaticName - provider programmatic name for the account. See AccountInfo.providerProgrammaticName
      Returns:
      always returns null primary account info for the provider or null if not found
      See Also:
    • isAccountSelectedForAlias

      public boolean isAccountSelectedForAlias(String accountId, String alias)
      Checks if the account is selected for the alias of the instrument (the one selected in the GUI on TCP).
      Parameters:
      accountId - account id of the account to check. Should be not null. To check if no account is selected use
      alias - instrument alias
      Returns:
      true if the account is selected for the alias, false otherwise
      Throws:
      NullPointerException - if the alias is null or if the accountId is null.
    • isAnyAccountSelectedForAlias

      public boolean isAnyAccountSelectedForAlias(String alias)
    • getSelectedAccountForAlias

      public Optional<AccountInfo> getSelectedAccountForAlias(String alias)
      Returns selected account id by the alias of the instrument (the one selected in the GUI on TCP).
      Parameters:
      alias - instrument alias
      Returns:
      selected account info for the alias or empty Optional if no account is selected for the instrument of the alias
    • getSelectedAccountIdForAlias

      public Optional<String> getSelectedAccountIdForAlias(String alias)
      Returns selected account info by the alias of the instrument (the one selected in the GUI).
      Parameters:
      alias - instrument alias
      Returns:
      selected account id for the alias or empty optional if no account is selected for the instrument of the alias
    • getAccountsByProvider

      public List<AccountInfo> getAccountsByProvider(String providerProgrammaticName)
      Returns all accounts for the provider by the provider programmatic name.
      Parameters:
      providerProgrammaticName - provider programmatic name. See AccountInfo.providerProgrammaticName
      Returns:
      list of all accounts for the provider by the provider programmatic name
    • getProviderOtherAccountsByAccountId

      @Deprecated public List<AccountInfo> getProviderOtherAccountsByAccountId(String accountId, boolean includePrimary)
      Deprecated.
      use getAccountsByProvider(String) instead. This method is deprecated because of deprecation of primary account concept.
      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 - ignored (all accounts are always included in the result) 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
    • getAccountsByProviderAccountId

      public List<AccountInfo> getAccountsByProviderAccountId(String accountId)
      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
      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

      @Deprecated public Boolean isPrimaryAccountOrNull(String accountId)
      Deprecated.
      primary can be selected for each instrument separately from GUI. So now the same account can be primary for one instrument and not primary for another.
      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:
      Always returns null. true if the account is primary, false otherwise or null if the account is not found.
    • isPrimaryAccount

      @Deprecated public boolean isPrimaryAccount(String accountId)
      Deprecated.
      primary can be selected for each instrument separately from GUI. So now the same account can be primary for one instrument and not primary for another.
      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:
      Always returns false. true if the account is primary, false otherwise
    • isPrimaryAccountOrderOrNull

      @Deprecated public Boolean isPrimaryAccountOrderOrNull(String orderId)
      Deprecated.
      primary account concept is now deprecated. Now it's possible to select and change accounts for each instrument, so you need to check it for each instrument separately.
      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

      @Deprecated public boolean isPrimaryAccountOrder(String orderId)
      Deprecated.
      primary account concept is now deprecated. Now it's possible to select and change accounts for each instrument
      Checks if the account is primary by order id. If the order is not found returns true.
      Parameters:
      orderId - order id
      Returns:
      true if the account is primary, false otherwise
    • isAccountSelectedForOrderId

      public boolean isAccountSelectedForOrderId(String orderId)
      Checks if the order belongs to the currently selected account on the TCP.
      Parameters:
      orderId - order id
      Returns:
      true if the account of the orders is selected on TCP, or order is not found, false otherwise
    • isAccountSelectedForOrderIdOrNull

      public Boolean isAccountSelectedForOrderIdOrNull(String orderId)
      Checks if the order belongs to the currently selected account on the TCP.
      Parameters:
      orderId - order id
      Returns:
      true if the account of the orders is selected on TCP, false otherwise, or null if the order or account is not found
    • onUserMessage

      public boolean onUserMessage(Object message)
      Takes any user messages while accepts and processes only TradingAccountsInfoMessage and SelectedAccountChangedMessage (ignoring all other messages) to update the accounts list and selected account for aliases.
      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 or the selected account has been changed 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 selected account was changed), false otherwise
    • generateMessagesFromAccountsList

      public List<TradingAccountsInfoMessage> generateMessagesFromAccountsList()
      Generates TradingAccountsInfoMessage 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
    • generateMessagesFromAccountsList

      public List<TradingAccountsInfoMessage> generateMessagesFromAccountsList(String alias)
      Generates TradingAccountsInfoMessage messages from the accounts list as if they were received from the provider (with isAdd=true for each) for the specific alias.
      Parameters:
      alias - alias to get accounts for
      Returns:
      list of messages for each account
    • generateMessagesFromSelectedAccounts

      public List<SelectedAccountChangedMessage> generateMessagesFromSelectedAccounts()
      Generates SelectedAccountChangedMessage messages from the previously recorded selected accounts list.
      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)
    • getOrderIdsByAccountAndAlias

      public Set<String> getOrderIdsByAccountAndAlias(String accountId, String alias)
    • getOrderInfoUpdate

      public OrderInfoUpdate getOrderInfoUpdate(String orderId)