client.balances reads current ledger balances and balance/equity history, and can stream live
updates. Methods are authenticated and account-scoped (account / sub_account_id).
Balance component fields (trading, funding, reserved, available) are scaled integer
decimal strings (ledger u128), not human floats. Values are already scaled integers on the
wire. Format once with format_ledger_u128 (default scale 18) for display. Do not multiply
by 1e18 again.
Methods
| Method | Summary |
|---|---|
list | Current balances for the account scope. |
get_balance_history | Columnar balance history over a range. |
get_equity_history | Columnar equity history over a range. |
subscribe | Stream private balance updates. |
List
Python takes no required request object, optional scope only:
from polyester import format_ledger_u128
balances = await client.balances.list()
for b in balances.balances:
print(
b.asset_id,
format_ledger_u128(b.available),
format_ledger_u128(b.trading),
format_ledger_u128(b.funding),
format_ledger_u128(b.reserved),
)
# Subaccount override
sub = await client.balances.list(account={"sub_account_id": "123"})Held amounts come from each Asset's reserved balance in this result. Individual hold IDs and
expiry times have no replacement. available already accounts for reservations; size new orders
from it.
AssetBalance
| Field | Notes |
|---|---|
asset_id | Ledger asset id |
trading / funding / reserved / available | Scaled integer strings |
trading_revision | Orders trading/reserved/available |
funding_revision | Orders funding independently |
Get balance history
history = await client.balances.get_balance_history(
range="30d", # 1d, 7d, 30d, 90d, 180d, 365d
account_codes=None, # optional list[int]
ledger=0,
)
print(history.bucket, history.points, history.start_ts_sec, history.end_ts_sec)
for series in history.series:
print(series.asset_id, series.account_code, len(series.balance_q))Get equity history
equity = await client.balances.get_equity_history(
range="90d",
group_by="asset", # or "account"
)
print(equity.quote_asset, equity.points)
for series in equity.series:
print(series.asset_symbol or series.account_name, len(series.equity_q))Subscribe
Private channel; needs Account ID. Handshake-before-return; fail-closed overflow.
from polyester import format_ledger_u128
sub = await client.balances.subscribe(account_id=account_id)
async with sub:
async for balance in sub:
print(balance.asset_id, format_ledger_u128(balance.available))
break