Binance Spot API Documentation

repository·master·Indexed 26 days ago

https://github.com/binance/binance-spot-api-docs

Official documentation for the Binance Spot API, providing technical specifications for REST, WebSocket, FIX, and SBE interfaces. Includes guides for core API modules, specialized APIs for Wallet and Sub Accounts, and official connectors for Python, Node.js, Ruby, DotNET C#, Java, Rust, PHP, Go, and TypeScript. Covers endpoints, parameters, payloads, error codes, and the SPOT Testnet environment.

Tokens
206.6K
Snippets
354
Records
791
Agent score
85%

What's inside Binance Spot API

  1. Overview of the FIX API

    master

    The FIX (Financial Information eXchange) API is a high-performance interface available exclusively for the SPOT Exchange. It supports multiple session types including Order Entry, Drop Copy, and Market Data. The API can be implemented using NodeJS or custom TLS implementations in other languages.

    Note: This API is restricted to the SPOT Exchange only.

  2. Understand Pegged Orders (BBO Orders)

    master

    Pegged orders (also known as Best Bid-Offer or BBO orders) are essentially Limit orders where the price is derived from the current order book rather than a fixed value.

    They allow you to:

    • Sell at the best available sell price (e.g., placing an order just behind the highest bid).
    • Buy at the best available buy price (e.g., picking the lowest seller).

    This mechanism helps market makers match prices with minimal latency and helps retail users achieve best execution with minimized slippage.

  3. Understand Data Source Latency

    master

    The API is asynchronous, and data retrieval latency varies depending on the data source. Sources are ordered from least to most potential for delay:

    1. Matching Engine: Data is directly from the engine (most up-to-date).
    2. Memory: Data is from a server's local or external memory.
    3. Database: Data is taken directly from a database (highest potential delay).

    Some endpoints use multiple sources (e.g., Memory => Database), checking the first source and falling back to the next if the value is not found.

  4. Understand API Authentication Types

    master

    Binance APIs use different authentication types based on the required permissions. If no type is specified next to an endpoint name, the type is NONE.

    Authentication TypeDescription
    NONEPublic market data
    TRADETrading on the exchange (placing and canceling orders)
    USER_DATAPrivate account information (e.g., order status, trade history)
    USER_STREAMManaging user data stream subscriptions

    All endpoints with an authentication type other than NONE are considered SIGNED requests and require a signature parameter. API keys can be configured to allow only specific permissions (e.g., a key with TRADE permission for trading and another with USER_DATA for monitoring).

  5. Access Binance Spot API documentation

    master

    The Binance Spot API documentation is organized into several core technical modules. Use the following guides to navigate the API surface:

    Core API Modules

    • Spot REST API (/api): Main endpoints for trading and account management.
    • Spot WebSocket API: Real-time data via WebSockets.
    • Spot Market Data WebSocket streams: Real-time market data.
    • Spot User Data WebSocket streams: Real-time account and order updates.
    • FIX API: Access via the FIX protocol.
    • SBE Market Data Streams: Simple Binary Encoding (SBE) market data.
    • Enums, Errors, and Filters: Detailed technical specifications for enums.md, errors.md, and filters.md.

    Specialized APIs

    • Wallet (/sapi): Wallet and account management.
    • Sub Account (/sapi): Sub-account management.
    • Testnet: Documentation for features available only on the SPOT Testnet.
  6. Understand Binance API Security Types

    master

    Each endpoint has a security type indicating required API key permissions. If unspecified, the security type is NONE.

    Security typeDescription
    NONEPublic market data
    TRADETrading on the exchange, placing and canceling orders
    USER_DATAPrivate account information, such as order status and your trading history
    USER_STREAMManaging User Data Stream subscriptions

    Secure endpoints require a valid API key. API keys can be configured with specific permissions (e.g., a TRADE key for trading and a separate USER_DATA key for monitoring). By default, an API key cannot TRADE until enabled in API Management.

  7. Understand Smart Order Routing (SOR)

    master

    Smart Order Routing (SOR) allows you to access better liquidity by filling an order using liquidity from multiple order books that share the same base asset and have interchangeable quote assets (e.g., stablecoins with a 1:1 exchange rate).

    Key Behaviors:

    • Quote Assets: Even if liquidity is taken from a different quote asset (e.g., BTCUSDC), you will always receive the quote asset of the symbol you originally submitted (e.g., USDT).
    • Order Expiration:
      • LIMIT IOC or MARKET orders: If the SOR cannot fully fill the order using available liquidity across all eligible books, the remaining quantity expires immediately.
      • LIMIT GTC orders: If the SOR cannot fully fill the order, the remaining quantity is placed on the original order book you submitted the order to.
    • Goal: SOR aims to fill orders more fully and at better prices during the taker phase by accessing liquidity across multiple books.
  8. FIX Message Structure and Components

    master

    Binance FIX API messages consist of a Header, a Body (containing message-specific tags), and a Trailer.

    Note on Delimiters: In documentation examples, the | character represents the SOH (Start of Header) character used in actual FIX protocol messages.

    Example Message:

    8=FIX.4.4|9=113|35=A|34=1|49=SPOT|52=20240612-08:52:21.636837|56=5JQmUOsm|98=0|108=30|25037=4392a152-3481-4499-921a-6d42c50702e2|10=051|
  9. Understand Data Sources and Latency

    master

    Because the API system is asynchronous, data latency is expected. Data sources are ranked by update speed (fastest to slowest):

    1. Matching Engine (撮合引擎): Most up-to-date data.
    2. Cache (缓存): Internal or external cache.
    3. Database (数据库): Direct from the database.

    Some endpoints may list multiple sources (e.g., Cache => Database), meaning the system checks the cache first and falls back to the database if no data is found.

  10. Explore Binance Spot API Reference Modules

    master

    The documentation is organized into several specialized modules for Spot trading and related services:

    Core Spot API

    • Rest API (/api): Interface definitions for RESTful requests.
    • WebSocket API: Real-time data via WebSocket.
    • WebSocket Streams: Descriptions of market data streams.
    • User Data Stream: Interface for user-specific data streams.
    • FIX API: Access via the FIX protocol.
    • SBE Market Data Streams: Simple Binary Encoding (SBE) market data.
    • Enums: Definitions for Rest and WebSocket APIs.
    • Errors: Error codes and meanings for Spot API.
    • Filters: Detailed information on filters used in Spot API.

    Specialized Trading & Services

    • Testnet: APIs available only in the Spot Testnet environment.
    • Demo Mode: Information regarding simulated trading.
    • Margin Trading: Leveraged trading documentation.
    • Derivatives: Includes USD-M Futures (/fapi), Coin-M Futures (/dapi), Options (/eapi), and Portfolio Margin (/papi).
    • Wallet & Sub-Account: Management via /sapi endpoints.
    • Other Services: Simple Earn, Dual Investment, Auto Invest, Staking, Mining, Algo Trading, Copy Trading, Fiat, C2C, VIP/Crypto Loans, Binance Pay, Convert, and NFT.
  11. Access Binance API Documentation and Announcements

    master

    The Binance Spot API documentation provides definitions for interfaces, data streams, parameters, and responses.

    Important Notes:

    • For official announcements regarding API and data stream changes or downtime, monitor the Telegram channel: https://t.me/binance_api_announcements.
    • If there is a conflict between the Chinese translation and the English documentation, the English documentation takes precedence.