AlgoTraderAlgoTrader Documentation

Chapter 20. Account Data

20.1. Account balances
20.2. Withdrawal
20.3. Deposit address
20.4. Account Events

AlgoTrader provides Account Data Service for the following adapters:

Depending on the Account Data Adapter in use the corresponding account profile has to be specified via VM argument.

InteractiveBrokers:

-Dspring.profiles.active=iBAccount

Binance:

-Dspring.profiles.active=bNCAccount

Bitfinex:

-Dspring.profiles.active=bFXAccount

Bitflyer:

-Dspring.profiles.active=bFLAccount

BitMEX:

-Dspring.profiles.active=bMXAccount

Bitstamp:

-Dspring.profiles.active=bTSAccount

Coinbase Pro:

-Dspring.profiles.active=cNBAccount

Coinigy:

-Dspring.profiles.active=cNGAccount

Note

When running a strategy in distributed mode in case that requires account data service, a special account profile must be specified on the strategy side. In addition an actual historical data profile (e.g. iBAccount) must be specified on the server side.

-Dspring.profiles.active=live,account

The AccountService interface defines a method for retrieving account balances for the specified account ID. A list of NamedCurrencyAmountVO items is returned. The retrieveAccountBalances method can be called from the strategy like this:

List<NamedCurrencyAmountVO> balances = getAccountService().retrieveAccountBalances(accountId);

The AccountService interface defines a method to initiate a crypto withdrawal for crypto exchanges. The withdraw method can be called from the strategy like this:

WithdrawStatusVO status = getAccountService().withdraw(accountId, currency, amount, withdrawContext);

The withdrawContext parameter contains additional information that might be required by certain exchanges (e.g. address and/or paymentId). The method returns a WithdrawStatusVO which contains information like message and externalId.

For withdrawal operations exchanges typically require additional security constraints, which might include:

Please consult the corresponding exchange's documentation about the details on how to enable withdrawals.

The AccountService provides a method for getting the deposit address. The method can be called from a strategy like this:

String depositAddress = getAccountService().getDepositAddress(DepositAddressVo depositParams);

This returns the deposit address for an exchange, currency and wallet type (wallet type is required for Bitfinex only). It returns the value as a String. Please check the exchange documentation on how to create deposit addresses. The getDepositAddress method sends the request to an enabled exchange (see Section 25.1, “Starter Classes”). If the requested exchange profile is not present, an exception is thrown. Some exchanges support different currencies (please check the corresponding adapter section).

Using the AccountService it is also possible to subscribe for account events. After successful subscription the strategy will be notified each time the account balances are changed.

In order to subscribe the strategy needs to call

getAccountService().subscribeAccountEvent(accountId);

To process events the strategy must implement a listener method:

void onAccountEvent(AccountEventVO event)

The AccountEventVO has a method getAccountBalances which returns the received balances.

List<NamedCurrencyAmountVO> getAccountBalances();

Unlike the retrieveAccountBalances which always return all balances, the account update event may contain only the balance which has changed.