### Check Server Time Endpoint Source: https://github.com/binance/binance-spot-api-docs/blob/master/rest-api.md This example shows how to check the server time using the Binance Spot API. It is a simple GET request to the /api/v3/time endpoint. ```bash GET /api/v3/time ``` -------------------------------- ### Successful Response Example Source: https://github.com/binance/binance-spot-api-docs/blob/master/testnet/web-socket-api.md An example of a successful response from the Binance WebSocket API, detailing order information and rate limits. ```APIDOC ## Successful Response Example ```json { "id": "e2a85d9f-07a5-4f94-8d5f-789dc3deb097", "status": 200, "result": { "symbol": "BTCUSDT", "orderId": 12510053279, "orderListId": -1, "clientOrderId": "a097fe6304b20a7e4fc436", "transactTime": 1655716096505, "price": "0.10000000", "origQty": "10.00000000", "executedQty": "0.00000000", "origQuoteOrderQty": "0.000000", "cummulativeQuoteQty": "0.00000000", "status": "NEW", "timeInForce": "GTC", "type": "LIMIT", "side": "BUY", "workingTime": 1655716096505, "selfTradePreventionMode": "NONE" }, "rateLimits": [ { "rateLimitType": "ORDERS", "interval": "SECOND", "intervalNum": 10, "limit": 50, "count": 12 }, { "rateLimitType": "ORDERS", "interval": "DAY", "intervalNum": 1, "limit": 160000, "count": 4043 }, { "rateLimitType": "REQUEST_WEIGHT", "interval": "MINUTE", "intervalNum": 1, "limit": 6000, "count": 321 } ] } ``` ``` -------------------------------- ### Iceberg Quantity Example Source: https://github.com/binance/binance-spot-api-docs/blob/master/rest-api.md Example of the `icebergQty` parameter for iceberg orders. ```json "icebergQty": "0.00000000" ``` -------------------------------- ### Execution Rules Response Example Source: https://github.com/binance/binance-spot-api-docs/blob/master/rest-api.md Example JSON response when querying execution rules. ```JSON { "symbolRules": [ { "symbol": "BAZUSD", "rules": [ { "ruleType": "PRICE_RANGE", "bidLimitMultUp": "1.0001", "bidLimitMultDown": "0.9999", "askLimitMultUp": "1.0001", "askLimitMultDown": "0.9999" } ] } ] } ``` -------------------------------- ### Pegged Price Example Source: https://github.com/binance/binance-spot-api-docs/blob/master/rest-api.md Example of the `peggedPrice` parameter, showing the current price an order is pegged at. ```json "peggedPrice": "87523.83710000" ``` -------------------------------- ### Working Floor Example Source: https://github.com/binance/binance-spot-api-docs/blob/master/rest-api.md Example of the `workingFloor` string parameter, specifying whether an order is filled by SOR or the order book. ```json "workingFloor": "SOR" ``` -------------------------------- ### Stop Price Example Source: https://github.com/binance/binance-spot-api-docs/blob/master/rest-api.md Example of the `stopPrice` parameter, used for triggering algorithmic orders like `STOP_LOSS` and `TAKE_PROFIT`. ```json "stopPrice": "23500.00000000" ``` -------------------------------- ### Rolling Window Computation Example Source: https://github.com/binance/binance-spot-api-docs/blob/master/testnet/web-socket-api.md Illustrates the potential open and close times for a rolling window calculation, demonstrating how the effective window might be slightly larger than requested due to minute boundary alignment. ```json { "openTime": 1659580020000, "closeTime": 1660184865291 } ``` -------------------------------- ### Trailing Time Example Source: https://github.com/binance/binance-spot-api-docs/blob/master/rest-api.md Example of the `trailingTime` parameter for Trailing Stop Orders, indicating when the order became active and started tracking price changes. ```json "trailingTime": -1 ``` -------------------------------- ### Example Commission Configuration Source: https://github.com/binance/binance-spot-api-docs/blob/master/faqs/commission_faq.md This JSON object shows a sample commission configuration for a symbol, detailing standard, special, and tax commissions, as well as discount settings. ```json { "symbol": "BTCUSDT", "standardCommission": { "maker": "0.00000010", "taker": "0.00000020", "buyer": "0.00000030", "seller": "0.00000040" }, "specialCommission": { "maker": "0.01000000", "taker": "0.02000000", "buyer": "0.03000000", "seller": "0.04000000" }, "taxCommission": { "maker": "0.00000112", "taker": "0.00000114", "buyer": "0.00000118", "seller": "0.00000116" }, "discount": { "enabledForAccount": true, "enabledForSymbol": true, "discountAsset": "BNB", "discount": "0.25000000" } } ``` -------------------------------- ### Get Exchange Information with Symbol Status Filter Source: https://github.com/binance/binance-spot-api-docs/blob/master/rest-api.md Retrieve exchange information filtered by symbol trading status. This example uses the 'symbolStatus' parameter to get 'TRADING' symbols. ```http curl -X GET "https://api.binance.com/api/v3/exchangeInfo?symbolStatus=TRADING" ``` -------------------------------- ### Example FIX Message Structure Source: https://github.com/binance/binance-spot-api-docs/blob/master/testnet/fix-api.md This example shows the structure of a FIX message, where the SOH (Start of Header) character is represented by '|'. This format is common for FIX protocol communication. ```plaintext 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| ``` -------------------------------- ### Build Simple Binary Encoding Tool Source: https://github.com/binance/binance-spot-api-docs/blob/master/faqs/sbe_faq.md Commands to clone the SBE repository and build the tool using Gradle. This tool is required to generate decoders from the provided XML schema files. ```shell $ git clone https://github.com/real-logic/simple-binary-encoding.git $ cd simple-binary-encoding $ ./gradlew ``` -------------------------------- ### GET /api/v3/ticker Source: https://github.com/binance/binance-spot-api-docs/blob/master/rest-api.md Retrieves rolling window price change statistics for a symbol or symbols. The open time is always at the start of a minute. ```http GET /api/v3/ticker ``` -------------------------------- ### order.place Source: https://github.com/binance/binance-spot-api-docs/blob/master/web-socket-api.md This section describes how to place an order using the Binance Spot API. It covers the necessary parameters, signature construction, and provides examples for both ASCII and non-ASCII characters in parameters. ```APIDOC ## order.place ### Description This endpoint allows users to place orders on the Binance Spot market. It requires a signature generated from the request parameters. ### Method POST (Implied by the JSON RPC-like structure and signature requirement) ### Endpoint Not explicitly defined, but typically a WebSocket endpoint for JSON RPC calls. ### Parameters #### Request Parameters (within `params` object) - **symbol** (string) - Required - The trading pair symbol (e.g., BTCUSDT). - **side** (string) - Required - The order side (BUY or SELL). - **type** (string) - Required - The order type (e.g., LIMIT, MARKET). - **timeInForce** (string) - Optional - The time in force for the order (e.g., GTC). - **quantity** (string) - Required - The quantity of the asset to trade. - **price** (string) - Required for LIMIT orders - The price at which to place the order. - **recvWindow** (integer) - Optional - The number of milliseconds the server should wait for the request. - **timestamp** (integer) - Required - The current timestamp in milliseconds. - **apiKey** (string) - Required - Your API key. - **signature** (string) - Required - The signature generated from the request parameters and your secret key. ### Signature Generation 1. **Construct Payload**: Collect all parameters except `signature`. Sort them alphabetically by parameter name. Format as `key=value` pairs separated by `&`. 2. **Compute Signature**: Use HMAC-SHA-256 with your `secretKey` as the signing key. Sign the UTF-8 bytes of the payload. Encode the result as a hex string. ### Request Example (ASCII Only) ```json { "id": "4885f793-e5ad-4c3b-8f6c-55d891472b71", "method": "order.place", "params": { "symbol": "BTCUSDT", "side": "SELL", "type": "LIMIT", "timeInForce": "GTC", "quantity": "0.01000000", "price": "52000.00", "recvWindow": 100, "timestamp": 1645423376532, "apiKey": "vmPUZE6mv9SD5VNHk4HlWFsOr6aKE2zvsw0MuIgwCIPy6utIco14y7Ju91duEh8A", "signature": "aa1b5712c094bc4e57c05a1a5c1fd8d88dcd628338ea863fec7b88e59fe2db24" } } ``` ### Request Example (Non-ASCII Characters) ```json { "id": "4885f793-e5ad-4c3b-8f6c-55d891472b71", "method": "order.place", "params": { "symbol": "123456", "side": "BUY", "type": "LIMIT", "timeInForce": "GTC", "quantity": "1.00000000", "price": "0.10000000", "recvWindow": 5000, "timestamp": 1645423376532, "apiKey": "vmPUZE6mv9SD5VNHk4HlWFsOr6aKE2zvsw0MuIgwCIPy6utIco14y7Ju91duEh8A", "signature": "b33892ae8e687c939f4468c6268ddd4c40ac1af18ad19a064864c47bae0752cd" } } ``` ### Response (Response details are not provided in the source text.) ``` -------------------------------- ### Order List Response Example Source: https://github.com/binance/binance-spot-api-docs/blob/master/rest-api.md This is an example of a response received after placing an order list. It includes details about the order list and individual orders within it. ```json { "orderListId": 0, "contingencyType": "OTO", "listStatusType": "EXEC_STARTED", "listOrderStatus": "EXECUTING", "listClientOrderId": "yl2ERtcar1o25zcWtqVBTC", "transactionTime": 1712289389158, "symbol": "LTCBTC", "orders": [ { "symbol": "LTCBTC", "orderId": 4, "clientOrderId": "Bq17mn9fP6vyCn75Jw1xya" }, { "symbol": "LTCBTC", "orderId": 5, "clientOrderId": "arLFo0zGJVDE69cvGBaU0d" } ], "orderReports": [ { "symbol": "LTCBTC", "orderId": 4, "orderListId": 0, "clientOrderId": "Bq17mn9fP6vyCn75Jw1xya", "transactTime": 1712289389158, "price": "1.00000000", "origQty": "1.00000000", "executedQty": "0.00000000", "origQuoteOrderQty": "0.000000", "cummulativeQuoteQty": "0.00000000", "status": "NEW", "timeInForce": "GTC", "type": "LIMIT", "side": "SELL", "workingTime": 1712289389158, "selfTradePreventionMode": "NONE" }, { "symbol": "LTCBTC", "orderId": 5, "orderListId": 0, "clientOrderId": "arLFo0zGJVDE69cvGBaU0d", "transactTime": 1712289389158, "price": "0.00000000", "origQty": "5.00000000", "executedQty": "0.00000000", "origQuoteOrderQty": "0.000000", "cummulativeQuoteQty": "0.00000000", "status": "PENDING_NEW", "timeInForce": "GTC", "type": "MARKET", "side": "BUY", "workingTime": -1, "selfTradePreventionMode": "NONE" } ] } ``` -------------------------------- ### Get Average Price Response Source: https://github.com/binance/binance-spot-api-docs/blob/master/testnet/rest-api.md Example response structure for the current average price endpoint, showing the average price and the time interval. ```javascript { "mins": 5, // Average price interval (in minutes) "price": "9.35751834", // Average price "closeTime": 1694061154503 // Last trade time } ``` -------------------------------- ### Get Multiple Symbols Price Ticker Response Source: https://github.com/binance/binance-spot-api-docs/blob/master/testnet/web-socket-api.md Example response when requesting prices for multiple symbols. The 'result' field is an array of symbol-price objects. ```javascript { "id": "e739e673-24c8-4adf-9cfa-b81f30330b09", "status": 200, "result": [ { "symbol": "BNBBTC", "price": "0.01363700" }, { "symbol": "BTCUSDT", "price": "24267.15000000" }, { "symbol": "BNBBUSD", "price": "331.10000000" } ], "rateLimits": [ { "rateLimitType": "REQUEST_WEIGHT", "interval": "MINUTE", "intervalNum": 1, "limit": 6000, "count": 4 } ] } ``` -------------------------------- ### Order Response Example Source: https://github.com/binance/binance-spot-api-docs/blob/master/testnet/web-socket-api.md This is an example of a response received from the Binance Spot API WebSocket for an order. It includes details about the order's status, transaction, and associated reports. Refer to the conditional fields documentation for a complete list of possible fields. ```json { "id": "1712544408508", "status": 200, "result": { "orderListId": 629, "contingencyType": "OTO", "listStatusType": "EXEC_STARTED", "listOrderStatus": "EXECUTING", "listClientOrderId": "GaeJHjZPasPItFj4x7Mqm6", "transactionTime": 1712544408537, "symbol": "1712544378871", "orders": [ { "symbol": "LTCBNB", "orderId": 23, "clientOrderId": "OVQOpKwfmPCfaBTD0n7e7H" }, { "symbol": "LTCBNB", "orderId": 24, "clientOrderId": "YcCPKCDMQIjNvLtNswt82X" }, { "symbol": "LTCBNB", "orderId": 25, "clientOrderId": "ilpIoShcFZ1ZGgSASKxMPt" } ], "orderReports": [ { "symbol": "LTCBNB", "orderId": 23, "orderListId": 629, "clientOrderId": "OVQOpKwfmPCfaBTD0n7e7H", "transactTime": 1712544408537, "price": "1.500000", "origQty": "1.000000", "executedQty": "0.000000", "origQuoteOrderQty": "0.000000", "cummulativeQuoteQty": "0.000000", "status": "NEW", "timeInForce": "GTC", "type": "LIMIT", "side": "BUY", "workingTime": 1712544408537, "selfTradePreventionMode": "NONE" }, { "symbol": "LTCBNB", "orderId": 24, "orderListId": 629, "clientOrderId": "YcCPKCDMQIjNvLtNswt82X", "transactTime": 1712544408537, "price": "0.000000", "origQty": "5.000000", "executedQty": "0.000000", "origQuoteOrderQty": "0.000000", "cummulativeQuoteQty": "0.000000", "status": "PENDING_NEW", "timeInForce": "GTC", "type": "STOP_LOSS", "side": "SELL", "stopPrice": "0.500000", "workingTime": -1, "selfTradePreventionMode": "NONE" }, { "symbol": "LTCBNB", "orderId": 25, "orderListId": 629, "clientOrderId": "ilpIoShcFZ1ZGgSASKxMPt", "transactTime": 1712544408537, "price": "5.000000", "origQty": "5.000000", "executedQty": "0.000000", "origQuoteOrderQty": "0.000000", "cummulativeQuoteQty": "0.000000", "status": "PENDING_NEW", "timeInForce": "GTC", "type": "LIMIT_MAKER", "side": "SELL", "workingTime": -1, "selfTradePreventionMode": "NONE" } ] }, "rateLimits": [ { "rateLimitType": "ORDERS", "interval": "MINUTE", "intervalNum": 1, "limit": 10000000, "count": 18 }, { "rateLimitType": "REQUEST_WEIGHT", "interval": "MINUTE", "intervalNum": 1, "limit": 1000, "count": 65 } ] } ``` -------------------------------- ### Get Exchange Information with Symbol Filter Source: https://github.com/binance/binance-spot-api-docs/blob/master/rest-api.md Retrieve exchange information filtered by a specific symbol. This example shows how to use the 'symbol' query parameter. ```http curl -X GET "https://api.binance.com/api/v3/exchangeInfo?symbol=BNBBTC" ``` -------------------------------- ### Order Placement Request Example (ASCII Symbol) Source: https://github.com/binance/binance-spot-api-docs/blob/master/testnet/web-socket-api.md Example of a WebSocket request to place an order with an ASCII symbol, demonstrating the structure and parameters required for signed requests. ```APIDOC ## POST /api/v1/stream ### Description This endpoint is used to place an order via the WebSocket API. It requires a signed request payload. ### Method POST (via WebSocket) ### Endpoint /api/v1/stream ### Parameters #### Request Body - **id** (string) - Required - Unique identifier for the request. - **method** (string) - Required - The method to call, e.g., "order.place". - **params** (object) - Required - Parameters for the method. - **symbol** (string) - Required - The trading symbol (e.g., "BTCUSDT"). - **side** (string) - Required - Order side, "BUY" or "SELL". - **type** (string) - Required - Order type, e.g., "LIMIT". - **timeInForce** (string) - Required - Time in force, e.g., "GTC". - **quantity** (string) - Required - The amount of the asset to trade. - **price** (string) - Required - The price at which to place the limit order. - **recvWindow** (integer) - Optional - The number of milliseconds the server waits for the request to be processed. - **timestamp** (integer) - Required - The current timestamp in milliseconds. - **apiKey** (string) - Required - Your API key. - **signature** (string) - Required - The signature generated from the request parameters. ### Request Example ```json { "id": "4885f793-e5ad-4c3b-8f6c-55d891472b71", "method": "order.place", "params": { "symbol": "BTCUSDT", "side": "SELL", "type": "LIMIT", "timeInForce": "GTC", "quantity": "0.01000000", "price": "52000.00", "recvWindow": 100, "timestamp": 1645423376532, "apiKey": "CAvIjXy3F44yW6Pou5k8Dy1swsYDWJZLeoK2r8G4cFDnE9nosRppc2eKc1T8TRTQ", "signature": "------ FILL ME ------" } } ``` ### Response #### Success Response (200) *The response structure for a successful order placement is not detailed in the provided source.* ``` -------------------------------- ### Place a Limit Sell Order Source: https://github.com/binance/binance-spot-api-docs/blob/master/rest-api.md This Python script demonstrates how to place a limit sell order using the Binance Spot API. It includes setting up authentication with an API key and private key, signing the request, and sending it to the API. ```python #!/usr/bin/env python3 import base64 import requests import time import urllib.parse from cryptography.hazmat.primitives.serialization import load_pem_private_key # Set up authentication API_KEY='put your own API Key here' PRIVATE_KEY_PATH='test-prv-key.pem' # Load the private key. # In this example the key is expected to be stored without encryption, # but we recommend using a strong password for improved security. with open(PRIVATE_KEY_PATH, 'rb') as f: private_key = load_pem_private_key(data=f.read(), password=None) # Set up the request parameters params = { 'symbol': 'BTCUSDT', 'side': 'SELL', 'type': 'LIMIT', 'timeInForce': 'GTC', 'quantity': '1.0000000', 'price': '0.20', } # Timestamp the request timestamp = int(time.time() * 1000) # UNIX timestamp in milliseconds params['timestamp'] = timestamp # Sign the request payload = urllib.parse.urlencode(params, encoding='UTF-8') signature = base64.b64encode(private_key.sign(payload.encode('ASCII'))) params['signature'] = signature # Send the request headers = { 'X-MBX-APIKEY': API_KEY, } response = requests.post( 'https://api.binance.com/api/v3/order', headers=headers, data=params, ) print(response.json()) ``` -------------------------------- ### Get Single Symbol Price Ticker Response Source: https://github.com/binance/binance-spot-api-docs/blob/master/testnet/web-socket-api.md Example response for a single symbol price ticker request. The 'result' field contains the symbol and its current price. ```javascript { "id": "043a7cf2-bde3-4888-9604-c8ac41fcba4d", "status": 200, "result": { "symbol": "BNBBTC", "price": "0.01361900" }, "rateLimits": [ { "rateLimitType": "REQUEST_WEIGHT", "interval": "MINUTE", "intervalNum": 1, "limit": 6000, "count": 2 } ] } ``` -------------------------------- ### Bash script for Binance Spot API order placement Source: https://github.com/binance/binance-spot-api-docs/blob/master/testnet/rest-api.md This Bash script automates the process of placing an order on the Binance Spot Testnet. It includes functions for URL encoding, timestamp generation, signature computation using OpenSSL, and constructing the final cURL request. ```bash function rawurlencode { local string="${1}" local strlen=${#string} local encoded="" local pos c o for (( pos=0 ; pos