CCXT.Balance (ccxt_client v0.6.1)

Copy Markdown View Source

Unified account balance across currencies.

Balances are stored as maps of currency => amount for each category (free, used, total).

Fields

  • free - Available balance per currency
  • used - Balance locked in orders per currency
  • total - Total balance per currency (free + used)
  • timestamp - Exchange timestamp in milliseconds
  • datetime - ISO 8601 datetime string
  • info - Raw exchange response

Examples

balance = %CCXT.Balance{
  free: %{"BTC" => 1.5, "USDT" => 10000.0},
  used: %{"BTC" => 0.5},
  total: %{"BTC" => 2.0, "USDT" => 10000.0}
}

CCXT.Balance.get(balance, "BTC")
#=> %{free: 1.5, used: 0.5, total: 2.0}

Summary

Functions

Returns a sorted list of all currencies in the balance.

Returns the balance for a specific currency.

JSON Schema for the Balance unified type.

Types

t()

@type t() :: %CCXT.Balance{
  datetime: String.t() | nil,
  free: %{required(String.t()) => number()},
  info: map() | nil,
  timestamp: integer() | nil,
  total: %{required(String.t()) => number()},
  used: %{required(String.t()) => number()}
}

Functions

currencies(balance)

@spec currencies(t()) :: [String.t()]

Returns a sorted list of all currencies in the balance.

Examples

CCXT.Balance.currencies(balance)
#=> ["BTC", "ETH", "USDT"]

get(balance, currency)

@spec get(t(), String.t()) :: %{free: number(), used: number(), total: number()} | nil

Returns the balance for a specific currency.

Returns a map with :free, :used, and :total keys, defaulting missing values to 0.0. Returns nil if the currency has no entries.

Examples

CCXT.Balance.get(balance, "BTC")
#=> %{free: 1.5, used: 0.5, total: 2.0}

CCXT.Balance.get(balance, "UNKNOWN")
#=> nil

schema()

@spec schema() :: map()

JSON Schema for the Balance unified type.