Balance
AccountAuth RequiredGet the current account balance and optionally subscribe to real-time balance updates. The New API returns only the balance of the account your token selects.
4 Breaking Changes
account and loginid parameters are removed, and so are the accounts and total objects in the response.Quick comparison
Breaking changes
1. account parameter removed
In the Legacy API, account chose which balance to return: current, all or a specific login ID. The New API does not accept it and returns the balance of the account your token selects.
Required change: Remove account from your balance requests.
2. loginid parameter removed
In the Legacy API, loginid selected the account when you authorised several accounts. The New API does not accept it.
Required change: Remove loginid from your balance requests. Your token selects the account.
3. accounts removed from the response
The Legacy API returned an accounts object with the balance, currency, status and type of each account when you sent account set to all. The New API does not return it.
Required change: Request the balance of each account with that account's token.
4. total removed from the response
The Legacy API returned a total object with summed balances for Deriv and MT5 real and demo accounts. The New API does not return it.
Required change: Add up the balances of your accounts yourself if you need a total.
Request structure
{
"balance": 1,
"account": "all",
"loginid": "CR123456",
"subscribe": 1,
"req_id": 1
}{
"balance": 1,
"subscribe": 1,
"req_id": 1
}Response structure
{
"balance": {
"accounts": {
"CR123456": {
"balance": 10000.5,
"converted_amount": 10000.5,
"currency": "USD",
"demo_account": 0,
"status": 1,
"type": "deriv"
}
},
"balance": 10000.5,
"currency": "USD",
"id": "c84a793b-8a87-7999-ce10-9b22f7ceead3",
"loginid": "CR123456",
"total": {
"deriv": {
"amount": 10000.5,
"currency": "USD"
}
}
},
"echo_req": {
"balance": 1,
"account": "all",
"loginid": "CR123456",
"subscribe": 1,
"req_id": 1
},
"msg_type": "balance",
"req_id": 1,
"subscription": {
"id": "c84a793b-8a87-7999-ce10-9b22f7ceead3"
}
}{
"balance": {
"balance": 10000.5,
"currency": "USD",
"id": "c84a793b-8a87-7999-ce10-9b22f7ceead3",
"loginid": "CR123456"
},
"echo_req": {
"balance": 1,
"subscribe": 1,
"req_id": 1
},
"msg_type": "balance",
"req_id": 1,
"subscription": {
"id": "c84a793b-8a87-7999-ce10-9b22f7ceead3"
}
}Code examples
function getBalances(loginId) {
ws.send(JSON.stringify({ balance: 1, account: "all", loginid: loginId, subscribe: 1 }));
ws.onmessage = (event) => {
const response = JSON.parse(event.data);
if (response.msg_type !== "balance" || !response.balance) return;
console.log("Balance:", response.balance.balance, response.balance.currency);
const accounts = response.balance.accounts ?? {};
Object.keys(accounts).forEach((id) => {
console.log("Account " + id + ": " + accounts[id].balance);
});
};
}Any other questions? Get in touch