Package velox.api.layer1.common.helper
Class AccountListManager
java.lang.Object
velox.api.layer1.common.helper.AccountListManager
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionGenerates messages from the accounts list as if they were received from the provider (with isAdd=true for each).getAccountById(String accountId) Returns account info by account id.getAccountByOrderId(String orderId) Returns account info by order id.Returns all available accounts.getAccountsByAlias(String alias) Returns all account infos for instrument alias.getAliasesByAccountId(String accountId) Returns the list of all currently subscribed instrument aliases for account id.getPrimaryAccountByProvider(String providerProgrammaticName) Returns primary account info for the provider.getProviderOtherAccountsByAccountId(String accountId, boolean includePrimary) Returns all accounts for the provider by the id of one of the provider accounts (e.g.Returns all providers with multiple accounts (providers are represented by their programmatic name).booleanisPrimaryAccount(String accountId) Checks if the account is primary by account id (null is considered primary).booleanisPrimaryAccountOrder(String orderId) Checks if the account is primary by order id.isPrimaryAccountOrderOrNull(String orderId) Checks if the account is primary by order id.isPrimaryAccountOrNull(String accountId) Checks if the account is primary by account id (null is considered primary).voidonOrderUpdated(OrderInfoUpdate orderInfoUpdate) Takes order update messages to map orders to the accounts.booleanonUserMessage(Object message) Takes any user messages while accepts and processes onlyTradingAccountsInfoMessageto update the account list.
-
Constructor Details
-
AccountListManager
public AccountListManager()
-
-
Method Details
-
getAccounts
Returns all available accounts.- Returns:
- account info set
-
getPrimaryAccountByProvider
Returns primary account info for the provider.- Parameters:
providerProgrammaticName- provider programmatic name for the account. SeeAccountInfo.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 accountsincludePrimary- 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
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
Returns account info by account id.- Parameters:
accountId- account id- Returns:
- account info or null if not found
-
getAccountsByAlias
Returns all account infos for instrument alias.- Parameters:
alias- instrument alias- Returns:
- account info set
-
getAliasesByAccountId
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
Returns account info by order id.- Parameters:
orderId- order id- Returns:
- account info or null if not found
-
isPrimaryAccountOrNull
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
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
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
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
Takes any user messages while accepts and processes onlyTradingAccountsInfoMessageto update the account list. Should be called fromLayer1ApiAdminListener.onUserMessage(Object)like this:
You can check if the account list has been updated by checking the return value.AccountListManager accountListManager = new AccountListManager(); // ... @Override void onUserMessage(Object data) { accountListManager.onUserMessage(data); // your code to handle any other messages here ... }- Parameters:
message- any user message received byLayer1ApiAdminListener.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
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
Takes order update messages to map orders to the accounts. Should be called fromLayer1ApiTradingListener.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)
-