curl
List your linked accounts with GET https://api.fivesocket.com/v1/accounts to find the account ID, then read the balance.
curl -H "Authorization: Bearer $FIVESOCKET_KEY" \ https://api.fivesocket.com/v1/accounts/acc_7Hq2Xv/balance
Python
import os
import time
import requests
base = "https://api.fivesocket.com/v1"
headers = {"Authorization": f"Bearer {os.environ['FIVESOCKET_KEY']}"}
accounts = requests.get(f"{base}/accounts", headers=headers, timeout=30)
accounts.raise_for_status()
account_id = accounts.json()["data"][0]["id"]
while True:
response = requests.get(f"{base}/accounts/{account_id}/balance", headers=headers, timeout=60)
if response.status_code != 202:
break
time.sleep(int(response.headers.get("Retry-After", "5")))
response.raise_for_status()
account = response.json()
print(account["balance"], account["equity"], account["currency"])JavaScript
This runs in Node.js 18 or later, Bun or Deno as an ES module.
const base = "https://api.fivesocket.com/v1"
const headers = { Authorization: `Bearer ${process.env.FIVESOCKET_KEY}` }
async function balance(accountId) {
while (true) {
const response = await fetch(`${base}/accounts/${accountId}/balance`, { headers })
if (response.status === 202) {
const seconds = Number(response.headers.get("retry-after") ?? "5")
await new Promise((resolve) => setTimeout(resolve, seconds * 1000))
continue
}
if (!response.ok) {
throw new Error(`FiveSocket returned ${response.status}`)
}
return await response.json()
}
}
const account = await balance("acc_7Hq2Xv")
console.log(account.balance, account.equity, account.currency)What comes back
Balance fields
balance, equity, margin, marginFree, credit, currency, leverage
Money values are decimal strings in the account currency, so parse them with a decimal type. The response also carries accountId, login, server, observedAt and latencyMs.
A 202 response with the code account_warming means MT5 is still logging in. Wait for the Retry-After seconds and send the same request again. The examples above do that.
Frequently asked questions
- Is the balance real time?
- Each successful read comes from a live MT5 session at the moment you ask. FiveSocket does not store balances.
- Can I read the balance with an investor password?
- Yes. Reads work with the MT5 investor password, and MT5 then refuses any trade on that link.
- Can I get a push when the balance changes?
- No. There are no webhooks or streams, so poll within your plan's rate limit.
- How much does it cost?
- Plans start at $9.99 a month for one MT5 account. Link your MT5 account and try it free, no card: 24 hours or 100 calls, whichever comes first. Then a 7-day free trial, card required. Cancel anytime. The trial includes one connected MT5 account.