Type/to search
Built-in Functions
Structures
Built-in Variables and Constants
Conventions
Exchanges
Capability Matrix
Centralized Exchanges
AscendEx
Backpack
BigONE
Binance
Bitfinex
bitFlyer
Bitget
Bithumb
Bitstamp
Bybit
Coincheck
Coinone
CoinW
Crypto.com
DeepCoin
Deribit
DigiFinex
Gate
Gemini
HashKey
HitBTC
HTX
Korbit
Kraken
KuCoin
LBank
MEXC
OKX
Poloniex
Upbit
WEEX
WOO X
Zaif
Decentralized Exchanges (DEX)
Prediction Markets
Securities and Futures
On-chain & Custom

Binance (Spot): Binance spot, plus Binance margin accounts (isolated and cross) and cross margin trading under a unified (portfolio margin) account. It connects with a Binance API Key whose Secret Key may be an HMAC secret or an RSA private key; with the Simulate box checked it connects to the Binance demo environment.

Futures_Binance (Futures): Binance USDⓈ-M (USDT- and USDC-margined) and COIN-M perpetual and delivery contracts, plus Binance European options (USDT-settled). It connects with a Binance API Key whose Secret Key may be an HMAC secret or an RSA private key; a unified (portfolio margin) account is detected automatically; with the Simulate box checked it connects to the Binance demo environment.

Names and Configuration
exchange.GetName()Type
BinanceSpot
Futures_BinanceFutures
FieldRequired
--
Access KeyYes
Secret KeyYes
SimulateNo

Trading Pairs and Contract Codes
Binance (Spot)

Pair examples: BTC_USDT, ETH_BTC

Pairs are written as BTC_USDT without a contract code; symbols with a contract suffix such as .swap are rejected (use a Futures_Binance exchange object for contracts).

Futures_Binance (Futures)

Pair examples: BTC_USDT, BTC_USDC, BTC_USD

The quote currency selects the contract family: BTC_USDT and BTC_USDC are USDⓈ-M contracts, BTC_USD is COIN-M. Binance trading pairs with Chinese names are supported, for example 币安人生_USDT.swap.

Contract codeDescription
swapPerpetual contract (the default), available as USDⓈ-M and COIN-M.
quarterCurrent-quarter delivery contract. Listed for COIN-M; USDⓈ-M only for some coins.
next_quarterNext-quarter delivery contract, listed like quarter.

Common contract codes not available: this_week, next_week.

Binance has no weekly contracts; this_week and next_week are rejected.

Native contract code examples: BTCUSDT_260925, BTCUSD_260925

Delivery contracts can also be given by their Binance native code (the pair without the underscore, then _ and the delivery date).

Exchange-specific IO Commands
Binance (Spot)
CommandArgumentsDescriptionReturns
trade_margin—Switch to the isolated margin account; account, order and order-query calls then use the isolated margin API. The demo environment has no margin API and reports an error.The command name itself.
trade_super_margin—Switch to the cross margin account (not available on demo). When the account is a unified account, the unified account's (papi.binance.com) cross margin API is used.The command name itself.
trade_normal—Switch back to the normal spot account (the default).The command name itself.
unifiedboolUnified account (portfolio margin); only takes effect under cross margin (trade_super_margin). When not set, it is detected automatically on the first request after switching to cross margin.Null also on success; check GetLastError() afterwards when needed.
selfTradePreventionModestringSelf-trade prevention for subsequent orders; one of EXPIRE_TAKER, EXPIRE_MAKER, EXPIRE_BOTH, NONE.Null also on success; check GetLastError() afterwards when needed.

For the common commands api, base and currency see exchange.IO.

Futures_Binance (Futures)
CommandArgumentsDescriptionReturns
crossbool[, symbol]Cross (true) / isolated (false) margin, set per contract; the current contract is used when symbol is omitted. Not available for option contracts.Null also on success; check GetLastError() afterwards when needed. The exchange reports an error (-4046) when the contract is already in the requested mode.
dualbool[, symbol]Hedge (true) / one-way (false) position mode, set separately for USDⓈ-M and COIN-M; symbol (the current contract when omitted) selects which one. Not available for option contracts.Null also on success; check GetLastError() afterwards when needed. The exchange reports an error (-4059) when that mode is already set.
unifiedbool[, symbol]Unified account (portfolio margin), using papi.binance.com after switching; detected automatically on the first private request when not set. Fails while the current contract is an option.Null also on success; check GetLastError() afterwards when needed.
selfTradePreventionModestringSelf-trade prevention for subsequent orders; one of EXPIRE_TAKER, EXPIRE_MAKER, EXPIRE_BOTH, NONE.Null also on success; check GetLastError() afterwards when needed.
base[string]Query or switch the API base address. (more below the table)The USDⓈ-M address before the change; the current USDⓈ-M address when called without an argument.
coinmBase[string]Query or switch the COIN-M API base address; affects COIN-M only.The address before the change; the current address when called without an argument.
eapiBase[string]Query or switch the options API base address. In simulation there is no options address by default; set one explicitly with this command.The address before the change; the current address when called without an argument.

The rest of the longer descriptions in the table:

  • base: With an official Binance mainnet address (https://fapi.binance.com, https://dapi.binance.com, https://papi.binance.com, https://eapi.binance.com or https://api.binance.com), USDⓈ-M uses that address and COIN-M, unified account and options each go back to their own official mainnet address; with any other address (a proxy, gateway, etc.), USDⓈ-M, COIN-M, unified account and options requests all go to that address. coinmBase and eapiBase can override them individually afterwards.

For the common commands api and currency see exchange.IO.

Common Usage
Query and switch the endpoint base addresses (access through a proxy) (Futures_Binance only)
javascript
function main() { // Without an argument the current address is returned Log("USDT-M:", exchange.IO("base"), "COIN-M:", exchange.IO("coinmBase")) Log("Options:", exchange.IO("eapiBase")) // A proxy address: USDT-M, COIN-M, unified account and options requests all go to it; // the previous USDT-M address is returned var old = exchange.IO("base", "https://binance-proxy.example.com") Log("Previous:", old, "COIN-M:", exchange.IO("coinmBase")) // COIN-M uses the proxy too // Send only COIN-M back to the official address exchange.IO("coinmBase", "https://dapi.binance.com") // Setting an official address sends COIN-M, unified account and options back to // their own official mainnet addresses exchange.IO("base", "https://fapi.binance.com") }

Function Support
Binance (Spot)

No unsupported standard functions.

Served through a fallback:

  • exchange.GetRecords: Native periods are 1s, 1m, 3m, 5m, 15m, 30m, 1h, 2h, 4h, 6h, 8h, 12h, 1d, 3d, 1w, 1M; other periods are synthesized by the docker.
Futures_Binance (Futures)

Not supported (the call fails with an error and returns null): exchange.ModifyConditionOrder.

Served through a fallback:

  • exchange.GetRecords: Native periods are 1m, 3m, 5m, 15m, 30m, 1h, 2h, 4h, 6h, 8h, 12h, 1d, 3d, 1w, 1M; other periods are synthesized by the docker.

Margin, Account and Simulation
Binance (Spot)

Account: The default is the normal spot account; exchange.IO("trade_margin") and exchange.IO("trade_super_margin") switch to the isolated and cross margin accounts, after which all account and order calls use the corresponding margin API until exchange.IO("trade_normal") switches back. Under isolated margin, exchange.GetAssets() sums each coin's balance across the isolated pairs.

Simulation: The Simulate box uses the Binance demo environment (demo-api.binance.com). The demo environment has no margin API; only normal spot can be traded.

Futures_Binance (Futures)

Margin mode: Switch cross/isolated margin per contract with exchange.IO("cross", bool); set leverage with exchange.SetMarginLevel(). A unified account is always cross margin; switching to isolated fails. When the account has Multi-Assets mode enabled, the exchange rejects switching to isolated margin (-4168).

Position mode: Switch hedge/one-way mode with exchange.IO("dual", bool); USDⓈ-M and COIN-M are independent. Orders carry position parameters matching the account's actual mode, or an explicit positionSide in the order's extra parameters.

Account: A unified (portfolio margin) account is detected on the first private request, or set with exchange.IO("unified", bool). Under a unified account the Balance of exchange.GetAccount() is all assets converted to USD; divide it by an asset's index price and then by its collateral ratio to get the amount in that asset.

Simulation: The Simulate box uses the Binance demo environment (demo-fapi, demo-dapi). The demo environment has no options API, so option calls fail in simulation (an options base address can be set explicitly with exchange.IO("eapiBase", url)).

Options
Futures_Binance (Futures)

Binance European options (USDT-settled) are supported; options trading must be enabled on the account, and the exchange may require a separate seller qualification. Limitations:

  • Only limit orders; market orders, conditional orders and order amendment (exchange.ModifyOrder()) are not supported.
  • exchange.SetMarginLevel() and exchange.GetFundings() are not supported, and option contracts cannot switch margin mode.
  • exchange.IO("unified", true) fails while the current contract is an option; if the account itself is a unified account, options are still traded through the options API.
  • exchange.GetMarkets() does not list option contracts; get option codes from the Binance API or website.
  • The options account is a separate account; exchange.GetAccount() and exchange.GetAssets() do not include its assets.

Option code examples: BTC-260925-145000-C, XRP-240112-0.5-C

Option codes are Binance native codes: underlying-expiry (YYMMDD)-strike-C/P, C for a call and P for a put. Binance options settle in USDT; set the trading pair to BTC_USDT, the full symbol looks like BTC_USDT.BTC-260925-145000-C.

Notes
Binance (Spot)
  • The amount of a market buy order is the quote-currency amount (sent as Binance's quoteOrderQty); a market sell order uses the base-currency quantity. Conditional orders always use the base-currency quantity, for both buys and sells.
  • exchange.ModifyOrder() and exchange.ModifyConditionOrder() use Binance's cancel-replace endpoint (cancelReplace; no new order is placed if the cancellation fails) and return the new order's ID, which should be used from then on; only the normal spot account is supported, margin accounts report an error.
  • Conditional orders support take-profit and stop-loss only, not OCO; create a take-profit order and a stop-loss order separately when needed.
  • exchange.GetHistoryOrders() and exchange.GetHistoryConditionOrders() require a trading pair.
Futures_Binance (Futures)
  • Order amounts: base-currency quantity for USDⓈ-M, number of contracts for COIN-M (each contract's face value is the CtVal of exchange.GetMarkets(), in USD); market buy orders also use the quantity.
  • exchange.ModifyOrder() amends the price and quantity in place and keeps the order ID; a price or quantity not given keeps the original order's value (the quantity is the original order quantity).
  • Conditional orders support take-profit and stop-loss only, not OCO (Binance futures have no OCO endpoint); modifying a conditional order is not supported, cancel and recreate it instead.
  • exchange.GetHistoryOrders() and exchange.GetHistoryConditionOrders() require a contract.