Balances
Updating An Account Balance
A balance can also be updated via the SDK. To update a balance you must provide the account ID for the account you wish to update the balance for and the transaction amount.
Please Note: Balance updates may not be performed with any Account/User level method of authentication.
In addition, the balance operation
should be carefully chosen based on the desired outcome.
The various available balance operations are as follows:
enum BalanceOperation {
ADD = 'add',
SUB = 'sub',
ADJUSTMENT = 'adjustment',
COMMISSION = 'commission',
SWAP = 'swap',
CREDIT = 'credit',
DEBIT = 'debit',
}
Please Note: The balance operation reflects the change that will happen on the balance. For all balance operations
(except for Adjustment
) the absolute amount will be considered.
For example, if a request is made to Add
-200 to the balance, the balance will be increased by abs(200)
.
The following operations will increase the balance:
Add
Credit
Debit
The following operations will decrease the balance:
Sub
Swap
Commission
In the case of Adjustment
the balance will be adjusted in a positive or negative way depending on the amount sent
in the request.
import { BalanceOperation, UpdateBalanceDto } from '@tradrapi/trading-sdk';
const body: UpdateBalanceDto = {
accountId: 1010001,
operation: BalanceOperation.Add,
amount: 200,
comment: 'Adding 200 to the balance',
referenceId: '123456789',
};
const result: boolean = await tradrApi.admin.balance.update(body);
The referenceId
is an optional field which can be used to associate a balance update with an external reference of your choice.
This allows the balance update to be linked to an external system and also makes it transactional. TradrAPI will only
process an operation with a unique referenceId
once.
If the same referenceId
is used again then the operation will not
be processed.
Balance Operation Types
Using the correct balance operation
is important as it will determine how the balance is updated.
In cases which involve deposits and withdrawals then the Add
and Sub
operations should be used respectively. These two
operations will increase or decrease the balance by the absolute amount provided.
In cases which involve commissions, swaps, credits and debits then the Commission
, Swap
, Credit
and Debit
operations
should be used respectively.
Funds added to a balance using the Credit
operation will not be available for withdrawal Sub
. The Credit
operation
is used to add bonus funds to a balance which although the funds may be traded they cannot be withdrawn.
Adjustments
should be used to effect manual changes to a balance. For example, if a balance is incorrect and needs to
be corrected then the Adjustment
operation should be used.
In all cases, when using the TradrAPI, a comment can be associated with each balance update.