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 TypeMethodDescriptionGeneratesTradingAccountsInfoMessagemessages from the accounts list as if they were received from the provider (with isAdd=true for each).GeneratesTradingAccountsInfoMessagemessages from the accounts list as if they were received from the provider (with isAdd=true for each) for the specific alias.GeneratesSelectedAccountChangedMessagemessages from the previously recorded selected accounts list.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.getAccountsByProvider(String providerProgrammaticName) Returns all accounts for the provider by the provider programmatic name.getAccountsByProviderAccountId(String accountId) Returns all accounts for the provider by the id of one of the provider accounts (e.g.getAliasesByAccountId(String accountId) Returns the list of all currently subscribed instrument aliases for account id.getOrderIdsByAccountAndAlias(String accountId, String alias) getOrderInfoUpdate(String orderId) getPrimaryAccountByProvider(String providerProgrammaticName) Deprecated.primary can be selected for each instrument separately from GUI.getProviderOtherAccountsByAccountId(String accountId, boolean includePrimary) Deprecated.usegetAccountsByProvider(String)instead.Returns all providers with multiple accounts (providers are represented by their programmatic name).getSelectedAccountForAlias(String alias) Returns selected account id by the alias of the instrument (the one selected in the GUI on TCP).Returns selected account info by the alias of the instrument (the one selected in the GUI).booleanisAccountSelectedForAlias(String accountId, String alias) Checks if the account is selected for the alias of the instrument (the one selected in the GUI on TCP).booleanisAccountSelectedForOrderId(String orderId) Checks if the order belongs to the currently selected account on the TCP.isAccountSelectedForOrderIdOrNull(String orderId) Checks if the order belongs to the currently selected account on the TCP.booleanbooleanisPrimaryAccount(String accountId) Deprecated.primary can be selected for each instrument separately from GUI.booleanisPrimaryAccountOrder(String orderId) Deprecated.primary account concept is now deprecated.isPrimaryAccountOrderOrNull(String orderId) Deprecated.primary account concept is now deprecated.isPrimaryAccountOrNull(String accountId) Deprecated.primary can be selected for each instrument separately from GUI.voidonOrderUpdated(OrderInfoUpdate orderInfoUpdate) Takes order update messages to map orders to the accounts.booleanonUserMessage(Object message) Takes any user messages while accepts and processes onlyTradingAccountsInfoMessageandSelectedAccountChangedMessage(ignoring all other messages) to update the accounts list and selected account for aliases.
Should be called fromLayer1ApiAdminListener.onUserMessage(Object)like this:
-
Constructor Details
-
AccountListManager
public AccountListManager()
-
-
Method Details
-
getAccounts
Returns all available accounts.- Returns:
- account info set
-
getPrimaryAccountByProvider
Deprecated.primary can be selected for each instrument separately from GUI. So for the same provider there can be multiple primary accounts. UsegetSelectedAccountForAlias(String)instead.Returns primary account info for the provider.- Parameters:
providerProgrammaticName- provider programmatic name for the account. SeeAccountInfo.providerProgrammaticName- Returns:
- always returns null
primary account info for the provider or null if not found - See Also:
-
isAccountSelectedForAlias
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 usealias- 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
-
getSelectedAccountForAlias
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
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
Returns all accounts for the provider by the provider programmatic name.- Parameters:
providerProgrammaticName- provider programmatic name. SeeAccountInfo.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.usegetAccountsByProvider(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 accountsincludePrimary- 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
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
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
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.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.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.primary account concept is now deprecated. Now it's possible to select and change accounts for each instrumentChecks 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
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
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
Takes any user messages while accepts and processes onlyTradingAccountsInfoMessageandSelectedAccountChangedMessage(ignoring all other messages) to update the accounts list and selected account for aliases.
Should be called fromLayer1ApiAdminListener.onUserMessage(Object)like this:
You can check if the account list has been updated or the selected account has been changed 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 selected account was changed), false otherwise
-
generateMessagesFromAccountsList
GeneratesTradingAccountsInfoMessagemessages 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
GeneratesTradingAccountsInfoMessagemessages 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
GeneratesSelectedAccountChangedMessagemessages from the previously recorded selected accounts list.- 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)
-
getOrderIdsByAccountAndAlias
-
getOrderInfoUpdate
-