Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/tiagosiebler/binance/llms.txt

Use this file to discover all available pages before exploring further.

The binance package is written in TypeScript and re-exports every type from its src/index.ts entry point. All types, interfaces, enums, and type unions are available as named imports from 'binance' — no deep path imports are required. This page organises the most important exports by module so you can quickly find what you need.

How to Import Types

import type {
  WSClientConfigurableOptions,
  WsMarket,
  WsKey,
  KlineInterval,
  OrderSide,
  OrderType,
  WsFormattedMessage,
  WsUserDataEvents,
} from 'binance';
Use import type { ... } for type-only imports to ensure they are erased at compile time and do not affect your bundle size.

types/shared — Common Trading Types

These types are used across all product groups (Spot, Margin, Futures) and form the foundation of the SDK’s type system.

Primitive Types

TypeKindDescription
numberInStringtypestring | number. Binance often returns numbers as strings in REST responses.
ExchangeSymboltypeAn alias for string used to represent a trading pair symbol.
BooleanStringtype'true' | 'false' — Binance’s string-encoded boolean.
BinanceBaseUrlKeytypeUnion of base URL identifier strings.

Order Types and Enums

TypeKindValues / Description
OrderSidetype'BUY' | 'SELL'
OrderTypetype'LIMIT' | 'MARKET' | 'STOP_LOSS' | 'STOP_LOSS_LIMIT' | 'TAKE_PROFIT' | 'TAKE_PROFIT_LIMIT' | 'LIMIT_MAKER'
OrderStatustype'NEW' | 'PARTIALLY_FILLED' | 'FILLED' | 'CANCELED' | 'PENDING_CANCEL' | 'REJECTED' | 'EXPIRED' | 'EXPIRED_IN_MATCH'
OrderTimeInForcetype'GTC' | 'IOC' | 'FOK' | 'GTX' | 'GTD' | 'PO'
OrderExecutionTypetypeExecution report event type: 'NEW' | 'CANCELED' | 'REPLACED' | ...
OrderResponseTypetype'ACK' | 'RESULT' | 'FULL'
OrderListOrderTypetypeOrder list constituent order types.
SelfTradePreventionModetype'EXPIRE_TAKER' | 'EXPIRE_MAKER' | 'EXPIRE_BOTH' | 'NONE'
OCOStatustype'RESPONSE' | 'EXEC_STARTED' | 'ALL_DONE'
OCOOrderStatustype'EXECUTING' | 'ALL_DONE' | 'REJECT'
SideEffectstypeMargin order side effects union.

Interval and Kline Types

TypeKindDescription
KlineIntervaltypeAll valid candlestick intervals: '1s' | '1m' | '3m' | '5m' | '15m' | '30m' | '1h' | '2h' | '4h' | '6h' | '8h' | '12h' | '1d' | '3d' | '1w' | '1M'
KlinetypeTuple representing a single kline row from REST responses.
FuturesKlinetypeAlias for Kline — used in futures contexts.

Parameter Interfaces

InterfaceDescription
BasicSymbolParam{ symbol: string } — the most common request parameter shape.
BasicAssetParam{ asset: string }
SymbolArrayParam{ symbols: string[] }
BasicSymbolPaginatedParamsSymbol + standard pagination fields (limit, fromId, etc).
BasicAssetPaginatedParamsAsset + pagination fields.
GetOrderParamsParameters for querying a single order.
CancelOrderParamsParameters for cancelling an order.
KlinesParamsSymbol + interval + optional time range for kline queries.
NewOCOParamsFull parameter set for placing an OCO order.
OrderBookParams{ symbol: string, limit?: number }

Exchange Filter Types

TypeDescription
SymbolPriceFilterPrice filter applied to a symbol.
SymbolLotSizeFilterLot size constraints for a symbol.
SymbolMinNotionalFilterMinimum notional value filter.
SymbolFilterUnion of all possible symbol-level filters.
ExchangeFilterUnion of all exchange-level filters.

types/spot — Spot Trading Types

Spot-specific types for REST API responses and parameters.
Type / InterfaceDescription
SpotBalanceA single asset balance entry ({ asset, free, locked }).
SystemStatusResponseSystem status: { status: 0 | 1, msg: string }.
DailyAccountSnapshotDaily account snapshot response.
AllCoinsInformationResponseFull coin information including deposit/withdrawal status.
DepositHistoryA single deposit history entry.
WithdrawHistoryA single withdrawal history entry.
DepositAddressResponseDeposit address for a coin and network.
EnumDepositStatusEnum: deposit statuses.
EnumWithdrawStatusEnum: withdrawal statuses.
EnumWithdrawTransferTypeEnum: withdrawal transfer types.
SymbolStatusUnion of symbol status strings: 'PRE_TRADING' | 'TRADING' | 'POST_TRADING' | ...

types/futures — USD-M & Derivatives Types

Types specific to the USD-M Futures and related derivatives markets.
Type / InterfaceDescription
FuturesContractType'CURRENT_QUARTER' | 'NEXT_QUARTER' | 'PERPETUAL'
FuturesOrderTypeFutures-specific order types including 'STOP' | 'TAKE_PROFIT' | 'TRAILING_STOP_MARKET'
PositionSide'BOTH' | 'LONG' | 'SHORT'
MarginType'ISOLATED' | 'CROSSED'
WorkingType'MARK_PRICE' | 'CONTRACT_PRICE'
PriceMatchModePrice match options for futures orders.
IncomeTypeAll valid income type strings for futures income history.
ForceOrderCloseType'LIQUIDATION' | 'ADL'
NewFuturesOrderParamsFull parameter type for placing a futures order.
ModifyFuturesOrderParamsParameters for modifying an open futures order.
SetLeverageParams{ symbol, leverage }
SetLeverageResultReturned after setting leverage.
SetIsolatedMarginParamsParameters for adjusting isolated margin.
GetIncomeHistoryParamsParameters for querying futures income history.
IncomeHistoryA single income history entry.
FuturesAlgoOrderType'CONDITIONAL'
FuturesAlgoConditionalOrderTypesAll conditional algo order sub-types.
FuturesAlgoOrderStatusStatus values for algo orders.
FuturesNewAlgoOrderParamsParameters for submitting a futures algo order.
FuturesAlgoOrderResponseResponse from algo order creation.

types/coin — COIN-M Futures Types

Types specific to the COIN-M (inverse, coin-margined) futures product group.
Type / InterfaceDescription
PositionRiskPosition risk information for a COIN-M contract.
CoinMOpenInterestOpen interest data for a COIN-M symbol.
SymbolOrPairUnion: a single symbol or a pair string.
CoinMSymbolOrderBookTickerOrder book ticker shape for COIN-M symbols.
CoinMPositionTradeTrade entry for a COIN-M position.
FundingRateHistorical funding rate entry.
CoinMAccountTradeParamsUnion of COIN-M trade query parameter shapes.

types/portfolio-margin — Portfolio Margin Types

Types for the Portfolio Margin and Portfolio Margin Pro product groups.
Type / InterfaceDescription
PMStrategyTypePortfolio margin strategy type union.
PMWorkingType'MARK_PRICE' | 'CONTRACT_PRICE'
PMPriceMatchPrice match mode options for PM orders.
PMMarginOrderTypeOrder type union for Portfolio Margin.
PMSelfTradePreventionModeSTP mode options for Portfolio Margin orders.
NewPortfolioUMOrderReqRequest for placing a USD-M Portfolio Margin order.
NewPortfolioUMOrderResponseResponse from a PM USD-M order placement.
NewPortfolioUMConditionalOrderReqRequest for a conditional PM order.
NewPortfolioUMAlgoOrderReqRequest for a PM algo order.
PortfolioUMAlgoOrderShape of a PM algo order.

types/websockets/ws-general — WebSocket Configuration

Core WebSocket types shared across streams and the WS API.
Type / InterfaceDescription
WSClientConfigurableOptionsConstructor options for WebsocketClient and WebsocketAPIClient. Includes api_key, api_secret, beautify, testnet, demoTrading, reconnectTimeout, and more.
WebsocketClientOptionsExtended form of WSClientConfigurableOptions with all defaults filled in.
WsMarketUnion of market strings: 'spot' | 'spotTestnet' | 'crossMargin' | 'isolatedMargin' | 'usdm' | 'usdmTestnet' | 'coinm' | 'coinmTestnet' | 'options' | 'portfoliom' | 'alpha'
WsTopicAlias for a raw topic string used in subscribe/unsubscribe calls.
WsSharedBaseBase interface extended by all formatted and raw WS message types. Fields: wsMarket, wsKey, streamName.
WsResponseShape of a WebSocket command confirmation response.

WsKey Values

WsKey is a union of all keys from WS_KEY_MAP. Commonly used values:
import type { WsKey } from 'binance';

// Examples:
const spotKey: WsKey = 'main';
const usdmKey: WsKey = 'usdm';
const coinmKey: WsKey = 'coinm';
const testnetKey: WsKey = 'mainTestnetPublic';

types/websockets/ws-events-formatted — Formatted Event Types

These types are the shapes of objects emitted on the formattedMessage and formattedUserDataMessage events when beautify: true.

Market Data Event Types

InterfaceeventTypeDescription
WsMessageKlineFormatted'kline'Candlestick update. Contains a nested kline object with OHLCV data.
WsMessageContinuousKlineFormatted'continuous_kline'Continuous contract kline update (futures).
WsMessageAggTradeFormatted'aggTrade'Compressed aggregate trade.
WsMessageTradeFormatted'trade'Individual raw trade event.
WsMessage24hrMiniTickerFormatted'24hrMiniTicker'24-hour mini ticker (OHLC + volume).
WsMessage24hrTickerFormatted'24hrTicker'Full 24-hour rolling window ticker.
WsMessageRollingWindowTickerFormatted'1hTicker' | '4hTicker' | '1dTicker'Rolling window ticker with custom window.
WsMessageBookTickerEventFormattedBest bid/ask update.
WsMessagePartialBookDepthEventFormatted'partialBookDepth'Partial order book snapshot.
WsMessageDiffBookDepthEventFormatted'depthUpdate'Incremental order book diff.
WsMessageMarkPriceEventFormatted'markPriceUpdate'Mark price update (futures).
WsMessageForceOrderFormatted'forceOrder'Liquidation order event (futures).
WsMessageIndexPriceUpdateEventFormattedIndex price update (options).

User Data Event Types

TypeDescription
WsMessageSpotUserDataEventFormattedUnion of all Spot user data event types.
WsMessageFuturesUserDataEventFormattedUnion of all USD-M Futures user data event types.
WsUserDataEventsCombined union of Spot + Futures + Portfolio Margin user data events. Used by the formattedUserDataMessage event.
WsFormattedMessageTop-level union of every possible formatted event (market data + user data). Narrowed using type guards.

Spot User Data Events

InterfaceeventTypeDescription
WsMessageSpotUserDataExecutionReportEventFormatted'executionReport'Order update (placed, filled, cancelled, etc).
WsMessageSpotOutboundAccountPositionFormatted'outboundAccountPosition'Balance update triggered by an order or transfer.
WsMessageSpotBalanceUpdateFormatted'balanceUpdate'Account balance delta event.
WsMessageSpotUserDataListStatusEventFormatted'listStatus'OCO order list status update.

Futures User Data Events

InterfaceeventTypeDescription
WsMessageFuturesUserDataAccountUpdateFormatted'ACCOUNT_UPDATE'Futures account balance and position update.
WsMessageFuturesUserDataTradeUpdateEventFormatted'ORDER_TRADE_UPDATE'Futures order / trade update.
WsMessageFuturesUserDataMarginCallFormatted'MARGIN_CALL'Margin call notification.
WsMessageFuturesUserDataAlgoUpdateFormatted'ALGO_UPDATE'Algo order status update.
WsMessageFuturesUserDataCondOrderTriggerRejectEventFormatted'CONDITIONAL_ORDER_TRIGGER_REJECT'Conditional order trigger rejection.
WsMessageFuturesUserDataAccountConfigUpdateEventFormatted'ACCOUNT_CONFIG_UPDATE'Account configuration change (e.g. leverage).
WsMessageFuturesUserDataListenKeyExpiredFormatted'listenKeyExpired'Listen key expiry notification.

types/websockets/ws-events-raw — Raw Event Types

These are the unprocessed message shapes used when beautify is not enabled (or for the message event). They mirror Binance’s original abbreviated field names (e.g. e, s, T). Key raw types include: WsMessageKlineRaw, WsMessageAggTradeRaw, WsMessageTradeRaw, WsMessage24hrMiniTickerRaw, WsMessageBookTickerEventRaw, WsMessagePartialBookDepthEventRaw, WsMessageDiffBookDepthEventRaw, WsMessageFuturesUserDataAccountUpdateRaw, WsMessageFuturesUserDataOrderTradeUpdateEventRaw, WsMessageFuturesUserDataAlgoUpdateRaw, WsMessageFuturesUserDataAccountConfigUpdateEventRaw, WsEventStreamTerminatedRaw, AccountUpdateEventType. The top-level union WsRawMessage covers all raw message shapes and is the type of the payload in the message event.

types/websockets/ws-api — WebSocket API Types

Types describing WS API requests, responses, and internal operation mappings.
Type / InterfaceDescription
WSAPIResponse<T>Generic response wrapper: { result: T, rateLimits: WSAPIRateLimit[], id: number }.
WsOperationUnion of all valid WS stream operations (e.g. 'SUBSCRIBE', 'UNSUBSCRIBE').
WsAPIOperationUnion of all valid WS API method names (e.g. 'order.place', 'ticker.book').
WsRequestOperationBinanceShape of a WS API JSON request object sent over the socket.
WSAPIUserDataListenKeyRequestParameter shape for listen-key related WS API calls.
WsAPITopicRequestParamMapMaps WS API operation strings to their expected request parameter types.
WsAPIOperationResponseMapMaps WS API operation strings to their expected response types.

types/websockets/ws-api-requests & ws-api-responses

These modules define the typed request and response shapes for every WS API method exposed by WebsocketAPIClient. All types follow a WSAPI*Request / WSAPI* naming pattern and are re-exported from the package root. Notable examples:
import type {
  WSAPINewSpotOrderRequest,
  WSAPIOrderStatusRequest,
  WSAPIOrderBookRequest,
  WSAPIAccountInformationRequest,
  WSAPIKlinesRequest,
  WSAPIOrder,
  WSAPIOrderBook,
  WSAPIAccountInformation,
  WSAPIKline,
  WSAPIAccountCommission,
  WSAPIFuturesOrder,
  WSAPIFuturesOrderBook,
} from 'binance';

Typed Usage Example

import {
  WebsocketClient,
  type WSClientConfigurableOptions,
  type WsFormattedMessage,
  type WsMessageKlineFormatted,
  type KlineInterval,
  type OrderSide,
} from 'binance';

const options: WSClientConfigurableOptions = {
  api_key: 'YOUR_API_KEY',
  api_secret: 'YOUR_API_SECRET',
  beautify: true,
  reconnectTimeout: 1500,
};

const wsClient = new WebsocketClient(options);

// Fully typed event handler
wsClient.on('formattedMessage', (data: WsFormattedMessage) => {
  // Type guard narrows from WsFormattedMessage → WsMessageKlineFormatted
  if (!Array.isArray(data) && data.eventType === 'kline') {
    const klineEvent = data as WsMessageKlineFormatted;
    const close: number = klineEvent.kline.close;
    const interval: KlineInterval = klineEvent.kline.interval;
    console.log(`${klineEvent.symbol} [${interval}] close = ${close}`);
  }
});

// KlineInterval and OrderSide used as typed parameters
const interval: KlineInterval = '1m';
const side: OrderSide = 'BUY';
wsClient.subscribeKlines('BTCUSDT', interval, 'spot');

Build docs developers (and LLMs) love