### WebSocket User Data Stream Setup and Examples (Bash) Source: https://context7.com/zzfzgs-vick/binance-usdt-m-futures/llms.txt Establishes a WebSocket connection for real-time account updates, including balance and position changes. This process involves generating a listenKey via REST API, connecting to the WebSocket endpoint, and maintaining the connection with periodic keepalive requests. The example shows the steps and sample JSON payloads for order and account updates. ```bash # Step 1: Generate listenKey (POST /fapi/v1/listenKey) curl -H "X-MBX-APIKEY: $apiKey" -X POST "https://fapi.binance.com/fapi/v1/listenKey" # Response: {"listenKey":"pqia91ma19a5s61cv6a81va65sdf19v8a65a1a5s61cv6a81va65sdf19v8a65a1"} # Step 2: Connect to WebSocket listenKey="pqia91ma19a5s61cv6a81va65sdf19v8a65a1a5s61cv6a81va65sdf19v8a65a1" # wss://fstream.binance.com/ws/$listenKey # Step 3: Keepalive every 30 minutes (PUT /fapi/v1/listenKey) curl -H "X-MBX-APIKEY: $apiKey" -X PUT "https://fapi.binance.com/fapi/v1/listenKey" # WebSocket message examples: # Order update { "e": "ORDER_TRADE_UPDATE", "T": 1568879465651, "E": 1568879465651, "o": { "s": "BTCUSDT", "c": "TEST", "S": "SELL", "o": "TRAILING_STOP_MARKET", "f": "GTC", "q": "2", "p": "0", "ap": "0", "sp": "9103.1", "x": "NEW", "X": "NEW", "i": 8886774, "l": "0", "z": "0", "L": "0", "ma": "USDT", "N": "USDT", "n": "0", "T": 1568879465651, "t": 0, "rp": "0", "b": "0", "a": "0", "m": false, "R": false, "wt": "CONTRACT_PRICE", "ot": "TRAILING_STOP_MARKET", "ps": "BOTH", "cp": false, "AP": "9476.8", "cr": "2.0", "pP": false } } # Balance and position update { "e": "ACCOUNT_UPDATE", "T": 1564745798939, "E": 1564745798939, "a": { "m": "ORDER", "B": [ { "a": "USDT", "wb": "122624.12345678", "cw": "100.12345678", "bc": "50.12345678" } ], "P": [ { "s": "BTCUSDT", "pa": "1", "ep": "9000", "cr": "200", "up": "2.3456", "mt": "isolated", "iw": "0.00000000", "ps": "BOTH" } ] } } ``` -------------------------------- ### GET /fapi/v1/exchangeInfo Source: https://context7.com/zzfzgs-vick/binance-usdt-m-futures/llms.txt Retrieves comprehensive information about the exchange, including trading rules, symbols, rate limits, and available assets. ```APIDOC ## GET /fapi/v1/exchangeInfo ### Description Retrieve trading rules and symbol configurations. Returns comprehensive exchange information including rate limits, asset details, symbol specifications, order types, filters (price, quantity, notional limits), and trading parameters. Essential for understanding trading constraints and available instruments. ### Method GET ### Endpoint `https://fapi.binance.com/fapi/v1/exchangeInfo` ### Parameters #### Query Parameters - **symbol** (string) - Optional - Trading pair to get information for. ### Request Example ```bash curl -X GET "https://fapi.binance.com/fapi/v1/exchangeInfo" ``` ### Response #### Success Response (200) - **exchangeFilters** (array) - Exchange-level filters. - **rateLimits** (array) - Rate limit information. - **interval** (string) - Rate limit interval. - **intervalNum** (integer) - Number of intervals. - **limit** (integer) - Limit count. - **rateLimitType** (string) - Type of rate limit. - **serverTime** (long) - Server timestamp in milliseconds. - **assets** (array) - List of available assets. - **asset** (string) - Asset symbol. - **marginAvailable** (boolean) - Whether margin is available. - **autoAssetExchange** (string) - Auto asset exchange information. - **symbols** (array) - List of trading symbols. - **symbol** (string) - Trading pair. - **pair** (string) - Trading pair. - **contractType** (string) - Contract type (e.g., "PERPETUAL"). - **deliveryDate** (long) - Delivery date in milliseconds. - **onboardDate** (long) - Onboard date in milliseconds. - **status** (string) - Trading status. - **baseAsset** (string) - Base asset. - **quoteAsset** (string) - Quote asset. - **marginAsset** (string) - Margin asset. - **pricePrecision** (integer) - Price precision. - **quantityPrecision** (integer) - Quantity precision. - **baseAssetPrecision** (integer) - Base asset precision. - **quotePrecision** (integer) - Quote precision. - **underlyingType** (string) - Underlying asset type. - **triggerProtect** (string) - Trigger protect value. - **filters** (array) - List of filters for the symbol. - **filterType** (string) - Type of filter. - (Specific filter parameters like `maxPrice`, `minPrice`, `tickSize`, `maxQty`, `minQty`, `stepSize`, `notional`) - **orderTypes** (array) - Supported order types. - **timeInForce** (array) - Supported time in force types. - **liquidationFee** (string) - Liquidation fee. - **marketTakeBound** (string) - Market take bound. - **timezone** (string) - Timezone of the server. #### Response Example ```json { "exchangeFilters": [], "rateLimits": [ { "interval": "MINUTE", "intervalNum": 1, "limit": 2400, "rateLimitType": "REQUEST_WEIGHT" }, { "interval": "MINUTE", "intervalNum": 1, "limit": 1200, "rateLimitType": "ORDERS" } ], "serverTime": 1565613908500, "assets": [ { "asset": "BTC", "marginAvailable": true, "autoAssetExchange": "-0.10" }, { "asset": "USDT", "marginAvailable": true, "autoAssetExchange": "0" } ], "symbols": [ { "symbol": "BLZUSDT", "pair": "BLZUSDT", "contractType": "PERPETUAL", "deliveryDate": 4133404800000, "onboardDate": 1598252400000, "status": "TRADING", "baseAsset": "BLZ", "quoteAsset": "USDT", "marginAsset": "USDT", "pricePrecision": 5, "quantityPrecision": 0, "baseAssetPrecision": 8, "quotePrecision": 8, "underlyingType": "COIN", "triggerProtect": "0.15", "filters": [ { "filterType": "PRICE_FILTER", "maxPrice": "300", "minPrice": "0.0001", "tickSize": "0.0001" }, { "filterType": "LOT_SIZE", "maxQty": "10000000", "minQty": "1", "stepSize": "1" }, { "filterType": "MIN_NOTIONAL", "notional": "5.0" } ], "orderTypes": [ "LIMIT", "MARKET", "STOP", "STOP_MARKET", "TAKE_PROFIT", "TAKE_PROFIT_MARKET", "TRAILING_STOP_MARKET" ], "timeInForce": ["GTC", "IOC", "FOK", "GTX"], "liquidationFee": "0.010000", "marketTakeBound": "0.30" } ], "timezone": "UTC" } ``` ``` -------------------------------- ### Get Exchange Information with cURL Source: https://context7.com/zzfzgs-vick/binance-usdt-m-futures/llms.txt Retrieves comprehensive exchange information, including rate limits, assets, and symbol configurations, using a GET request to the /fapi/v1/exchangeInfo endpoint. The response provides details on trading rules and available instruments. ```bash # GET /fapi/v1/exchangeInfo curl -X GET "https://fapi.binance.com/fapi/v1/exchangeInfo" ``` -------------------------------- ### Trailing Stop Market Order Example Source: https://context7.com/zzfzgs-vick/binance-usdt-m-futures/llms.txt Illustrates the parameters for placing a trailing stop market order. It highlights the use of `callbackRate` for the trailing percentage and `activationPrice` to set the trigger level for the conditional order. ```bash # Trailing stop market order example params="algoType=CONDITIONAL&symbol=BTCUSDT&side=BUY&type=TRAILING_STOP_MARKET&callbackRate=1.5&activationPrice=30000&workingType=CONTRACT_PRICE×tamp=$timestamp" # callbackRate=1.5 means 1.5% callback from highest/lowest price # activationPrice=30000 triggers trailing when price reaches this level ``` -------------------------------- ### Get Account Information V2 (Bash) Source: https://context7.com/zzfzgs-vick/binance-usdt-m-futures/llms.txt Retrieves detailed futures account balances and positions using the /fapi/v3/account endpoint. Requires API key, secret key, and a valid signature. The response format differs based on single-asset or multi-asset mode. ```bash # GET /fapi/v3/account (requires signature) timestamp=$(date +%s000) params="timestamp=$timestamp&recvWindow=5000" signature=$(echo -n "$params" | openssl dgst -sha256 -hmac "$secretKey" | awk '{print $2}') curl -H "X-MBX-APIKEY: $apiKey" -X GET \ "https://fapi.binance.com/fapi/v3/account?$params&signature=$signature" # Response (single-asset mode) { "totalInitialMargin": "0.00000000", "totalMaintMargin": "0.00000000", "totalWalletBalance": "103.12345678", "totalUnrealizedProfit": "0.00000000", "totalMarginBalance": "103.12345678", "totalPositionInitialMargin": "0.00000000", "totalOpenOrderInitialMargin": "0.00000000", "totalCrossWalletBalance": "103.12345678", "totalCrossUnPnl": "0.00000000", "availableBalance": "103.12345678", "maxWithdrawAmount": "103.12345678", "assets": [ { "asset": "USDT", "walletBalance": "23.72469206", "unrealizedProfit": "0.00000000", "marginBalance": "23.72469206", "maintMargin": "0.00000000", "initialMargin": "0.00000000", "positionInitialMargin": "0.00000000", "openOrderInitialMargin": "0.00000000", "crossWalletBalance": "23.72469206", "crossUnPnl": "0.00000000", "availableBalance": "23.72469206", "maxWithdrawAmount": "23.72469206", "updateTime": 1625474304765 } ], "positions": [ { "symbol": "BTCUSDT", "positionSide": "BOTH", "positionAmt": "1.000", "unrealizedProfit": "0.00000000", "isolatedMargin": "0.00000000", "notional": "0", "isolatedWallet": "0", "initialMargin": "0", "maintMargin": "0", "updateTime": 0 } ] } ``` -------------------------------- ### Make POST Request with cURL Source: https://context7.com/zzfzgs-vick/binance-usdt-m-futures/llms.txt Demonstrates making a POST request to the Binance API using cURL. It includes setting the X-MBX-APIKEY header and appending parameters and the URL-encoded signature to the request URL. This is typically used for order placement or modification. ```bash # Make request curl -H "X-MBX-APIKEY: $apiKey" -X POST \ "https://fapi.binance.com/fapi/v1/order?$params&signature=$signature" ``` -------------------------------- ### GET /fapi/v3/account Source: https://context7.com/zzfzgs-vick/binance-usdt-m-futures/llms.txt Retrieve detailed futures account information including balances, margins, and current positions. The response structure varies between single-asset and multi-asset modes. ```APIDOC ## GET /fapi/v3/account ### Description Retrieve detailed futures account information including balances, margins, and current positions. The response structure varies between single-asset and multi-asset modes. ### Method GET ### Endpoint /fapi/v3/account ### Parameters #### Query Parameters - **timestamp** (long) - Required - The timestamp of the request. - **recvWindow** (long) - Optional - The number of milliseconds the server should wait before sending an error message. - **signature** (string) - Required - The SHA256 HMAC signature of the parameters. ### Request Example ```bash # GET /fapi/v3/account (requires signature) timestamp=$(date +%s000) params="timestamp=$timestamp&recvWindow=5000" signature=$(echo -n "$params" | openssl dgst -sha256 -hmac "$secretKey" | awk '{print $2}') curl -H "X-MBX-APIKEY: $apiKey" -X GET \ "https://fapi.binance.com/fapi/v3/account?$params&signature=$signature" ``` ### Response #### Success Response (200) - **totalInitialMargin** (string) - Total initial margin. - **totalMaintMargin** (string) - Total maintenance margin. - **totalWalletBalance** (string) - Total wallet balance. - **totalUnrealizedProfit** (string) - Total unrealized profit. - **totalMarginBalance** (string) - Total margin balance. - **totalPositionInitialMargin** (string) - Total position initial margin. - **totalOpenOrderInitialMargin** (string) - Total open order initial margin. - **totalCrossWalletBalance** (string) - Total cross wallet balance. - **totalCrossUnPnl** (string) - Total cross unrealized profit. - **availableBalance** (string) - Available balance. - **maxWithdrawAmount** (string) - Maximum withdraw amount. - **assets** (array) - List of asset details. - **asset** (string) - The asset name. - **walletBalance** (string) - Wallet balance for the asset. - **unrealizedProfit** (string) - Unrealized profit for the asset. - **marginBalance** (string) - Margin balance for the asset. - **maintMargin** (string) - Maintenance margin for the asset. - **initialMargin** (string) - Initial margin for the asset. - **positionInitialMargin** (string) - Position initial margin for the asset. - **openOrderInitialMargin** (string) - Open order initial margin for the asset. - **crossWalletBalance** (string) - Cross wallet balance for the asset. - **crossUnPnl** (string) - Cross unrealized profit for the asset. - **availableBalance** (string) - Available balance for the asset. - **maxWithdrawAmount** (string) - Maximum withdraw amount for the asset. - **updateTime** (long) - Update time for the asset. - **positions** (array) - List of position details. - **symbol** (string) - The symbol for the position. - **positionSide** (string) - The side of the position (e.g., LONG, SHORT, BOTH). - **positionAmt** (string) - The amount of the position. - **unrealizedProfit** (string) - Unrealized profit for the position. - **isolatedMargin** (string) - Isolated margin for the position. - **notional** (string) - Notional value of the position. - **isolatedWallet** (string) - Isolated wallet balance for the position. - **initialMargin** (string) - Initial margin for the position. - **maintMargin** (string) - Maintenance margin for the position. - **updateTime** (long) - Update time for the position. #### Response Example (single-asset mode) ```json { "totalInitialMargin": "0.00000000", "totalMaintMargin": "0.00000000", "totalWalletBalance": "103.12345678", "totalUnrealizedProfit": "0.00000000", "totalMarginBalance": "103.12345678", "totalPositionInitialMargin": "0.00000000", "totalOpenOrderInitialMargin": "0.00000000", "totalCrossWalletBalance": "103.12345678", "totalCrossUnPnl": "0.00000000", "availableBalance": "103.12345678", "maxWithdrawAmount": "103.12345678", "assets": [ { "asset": "USDT", "walletBalance": "23.72469206", "unrealizedProfit": "0.00000000", "marginBalance": "23.72469206", "maintMargin": "0.00000000", "initialMargin": "0.00000000", "positionInitialMargin": "0.00000000", "openOrderInitialMargin": "0.00000000", "crossWalletBalance": "23.72469206", "crossUnPnl": "0.00000000", "availableBalance": "23.72469206", "maxWithdrawAmount": "23.72469206", "updateTime": 1625474304765 } ], "positions": [ { "symbol": "BTCUSDT", "positionSide": "BOTH", "positionAmt": "1.000", "unrealizedProfit": "0.00000000", "isolatedMargin": "0.00000000", "notional": "0", "isolatedWallet": "0", "initialMargin": "0", "maintMargin": "0", "updateTime": 0 } ] } ``` ``` -------------------------------- ### POST /fapi/v1/order Source: https://context7.com/zzfzgs-vick/binance-usdt-m-futures/llms.txt Places an order on the Binance Futures market. This endpoint supports various order types and requires proper authentication and signature. ```APIDOC ## POST /fapi/v1/order ### Description Places an order on the Binance Futures market. Requires API key, secret key, and a signed request. ### Method POST ### Endpoint `https://fapi.binance.com/fapi/v1/order` ### Parameters #### Query Parameters - **symbol** (string) - Required - The trading pair (e.g., "BTCUSDT") - **side** (enum) - Required - "BUY" or "SELL" - **type** (enum) - Required - Order type (e.g., "LIMIT", "MARKET") - **timeInForce** (enum) - Optional - "GTC", "IOC", "FOK", "GTX" - **quantity** (decimal) - Required for MARKET order, Optional for others - The quantity to trade - **price** (decimal) - Required for LIMIT order, Optional for others - The price of the order - **newClientOrderId** (string) - Optional - Unique id to identify the order - **stopPrice** (decimal) - Optional - Used with STOP_MARKET or TAKE_PROFIT_MARKET orders - **trailingDelta** (long) - Optional - Trailing step for TRAILING_STOP_MARKET orders - **workingType** (enum) - Optional - "MARK_PRICE", "CONTRACT_PRICE", default: "CONTRACT_PRICE" - **reduceOnly** (boolean) - Optional - "true" or "false" - **priceProtect** (boolean) - Optional - "true" or "false" - **newOrderRespType** (enum) - Optional - "ACK", "RESULT", "FULL" - **recvWindow** (long) - Optional - Server receive window - **timestamp** (long) - Required - UTC timestamp in milliseconds #### Request Body (Not typically used for this endpoint, parameters are usually in query string) ### Request Example ```bash apiKey="YOUR_API_KEY" secretKey="YOUR_SECRET_KEY" params="symbol=BTCUSDT&side=SELL&type=MARKET&quantity=1.23×tamp=$(date +%s000)" # URL encode the signature (handle special characters) signature=$(python3 -c "import urllib.parse; print(urllib.parse.quote('$(echo -n "$params" | openssl dgst -sha256 -hmac "$secretKey" | awk '{print $2}')'))") curl -H "X-MBX-APIKEY: $apiKey" -X POST \ "https://fapi.binance.com/fapi/v1/order?$params&signature=$signature" ``` ### Response #### Success Response (200) - **orderId** (long) - Order ID - **symbol** (string) - Trading pair - **status** (enum) - Order status (e.g., "FILLED", "NEW") - **clientOrderId** (string) - Client-provided order ID - **price** (string) - Order price - **avgPrice** (string) - Average execution price - **origQty** (string) - Original order quantity - **executedQty** (string) - Executed quantity - **cumQty** (string) - Cumulative filled quantity - **cumQuote** (string) - Cumulative quote quantity - **timeInForce** (enum) - Time in force - **type** (enum) - Order type - **reduceOnly** (boolean) - Reduce only flag - **closePosition** (boolean) - Close position flag - **side** (enum) - Order side ("BUY" or "SELL") - **positionSide** (enum) - Position side - **stopPrice** (string) - Stop price - **workingType** (enum) - Working type - **priceProtect** (boolean) - Price protect flag - **origType** (enum) - Original order type - **updateTime** (long) - Update time #### Response Example ```json { "orderId": 28141876, "symbol": "BTCUSDT", "status": "FILLED", "clientOrderId": "x-xcKtGhcu3f7ae3d2f6f6a8c5e1d9f1", "price": "0", "avgPrice": "23416.70", "origQty": "1.23", "executedQty": "1.23", "cumQty": "1.23", "cumQuote": "28802.541", "timeInForce": "GTC", "type": "MARKET", "reduceOnly": false, "closePosition": false, "side": "SELL", "positionSide": "BOTH", "stopPrice": "0", "workingType": "CONTRACT_PRICE", "priceProtect": false, "origType": "MARKET", "updateTime": 1671090802145 } ``` ``` -------------------------------- ### User Data Stream (WebSocket) Source: https://context7.com/zzfzgs-vick/binance-usdt-m-futures/llms.txt Subscribe to real-time account updates via WebSocket for balance changes, position updates, order status, and more. Requires generating and maintaining a listenKey. ```APIDOC ## WebSocket User Data Stream ### Description Subscribe to real-time account updates via WebSocket. Provides real-time push notifications for account changes including balance updates, position updates, order updates, leverage changes, and margin calls. Requires generating a listenKey via REST API and maintaining it with periodic keepalive requests. ### Steps 1. **Generate listenKey**: Use the `POST /fapi/v1/listenKey` endpoint. 2. **Connect to WebSocket**: Establish a WebSocket connection using the obtained listenKey to the URL `wss://fstream.binance.com/ws/`. 3. **Keepalive**: Periodically send keepalive requests using `PUT /fapi/v1/listenKey` every 30 minutes to prevent the listenKey from expiring. ### Endpoints - **POST /fapi/v1/listenKey**: Generates a listenKey. - **PUT /fapi/v1/listenKey**: Renews the listenKey. ### Request Example (Generate listenKey) ```bash # Step 1: Generate listenKey (POST /fapi/v1/listenKey) curl -H "X-MBX-APIKEY: $apiKey" -X POST "https://fapi.binance.com/fapi/v1/listenKey" # Response: {"listenKey":"pqia91ma19a5s61cv6a81va65sdf19v8a65a1a5s61cv6a81va65sdf19v8a65a1"} ``` ### Request Example (Keepalive) ```bash # Step 3: Keepalive every 30 minutes (PUT /fapi/v1/listenKey) curl -H "X-MBX-APIKEY: $apiKey" -X PUT "https://fapi.binance.com/fapi/v1/listenKey" ``` ### WebSocket Connection `wss://fstream.binance.com/ws/` ### WebSocket Message Examples #### Order Update ```json { "e": "ORDER_TRADE_UPDATE", "T": 1568879465651, "E": 1568879465651, "o": { "s": "BTCUSDT", "c": "TEST", "S": "SELL", "o": "TRAILING_STOP_MARKET", "f": "GTC", "q": "2", "p": "0", "ap": "0", "sp": "9103.1", "x": "NEW", "X": "NEW", "i": 8886774, "l": "0", "z": "0", "L": "0", "ma": "USDT", "N": "USDT", "n": "0", "T": 1568879465651, "t": 0, "rp": "0", "b": "0", "a": "0", "m": false, "R": false, "wt": "CONTRACT_PRICE", "ot": "TRAILING_STOP_MARKET", "ps": "BOTH", "cp": false, "AP": "9476.8", "cr": "2.0", "pP": false } } ``` #### Balance and Position Update ```json { "e": "ACCOUNT_UPDATE", "T": 1564745798939, "E": 1564745798939, "a": { "m": "ORDER", "B": [ { "a": "USDT", "wb": "122624.12345678", "cw": "100.12345678", "bc": "50.12345678" } ], "P": [ { "s": "BTCUSDT", "pa": "1", "ep": "9000", "cr": "200", "up": "2.3456", "mt": "isolated", "iw": "0.00000000", "ps": "BOTH" } ] } } ``` ``` -------------------------------- ### Place Conditional Order with cURL and OpenSSL Source: https://context7.com/zzfzgs-vick/binance-usdt-m-futures/llms.txt Shows how to place a conditional order (e.g., TAKE_PROFIT) using a POST request to the /fapi/v1/algoOrder endpoint. It includes generating a timestamp, constructing parameters, and signing the request using OpenSSL's HMAC SHA256 function. ```bash # POST /fapi/v1/algoOrder timestamp=$(date +%s000) params="algoType=CONDITIONAL&symbol=BNBUSDT&side=SELL&type=TAKE_PROFIT&quantity=0.01&price=750.000&triggerPrice=750.000&timeInForce=GTC&workingType=CONTRACT_PRICE&priceProtect=FALSE&selfTradePreventionMode=EXPIRE_MAKER×tamp=$timestamp" # Generate signature (assuming HMAC authentication) signature=$(echo -n "$params" | openssl dgst -sha256 -hmac "$secretKey" | awk '{print $2}') curl -H "X-MBX-APIKEY: $apiKey" -X POST \ "https://fapi.binance.com/fapi/v1/algoOrder?$params&signature=$signature" ``` -------------------------------- ### POST /fapi/v1/algoOrder Source: https://context7.com/zzfzgs-vick/binance-usdt-m-futures/llms.txt Places conditional orders such as stop-loss, take-profit, and trailing stop orders. ```APIDOC ## POST /fapi/v1/algoOrder ### Description Create conditional orders (stop-loss, take-profit, trailing stop). Places algorithmic orders that trigger based on market conditions. Supports STOP, TAKE_PROFIT, STOP_MARKET, TAKE_PROFIT_MARKET, and TRAILING_STOP_MARKET order types with customizable trigger prices, activation prices, and callback rates. ### Method POST ### Endpoint `https://fapi.binance.com/fapi/v1/algoOrder` ### Parameters #### Query Parameters - **algoType** (enum) - Required - "CONDITIONAL" - **symbol** (string) - Required - Trading pair (e.g., "BNBUSDT") - **side** (enum) - Required - "BUY" or "SELL" - **type** (enum) - Required - Order type (e.g., "STOP", "TAKE_PROFIT", "TRAILING_STOP_MARKET") - **quantity** (decimal) - Required - Order quantity - **price** (decimal) - Required for non-market types - Order price - **stopPrice** (decimal) - Required for STOP and TAKE_PROFIT types - Stop price - **triggerPrice** (decimal) - Required for STOP_MARKET and TAKE_PROFIT_MARKET types - Trigger price - **activationPrice** (decimal) - Optional - Activation price for trailing stop orders - **callbackRate** (decimal) - Optional - Callback rate for trailing stop orders (e.g., 1.5 for 1.5%) - **timeInForce** (enum) - Optional - "GTC", "IOC", "FOK", "GTX" - **workingType** (enum) - Optional - "MARK_PRICE", "CONTRACT_PRICE", default: "CONTRACT_PRICE" - **priceProtect** (boolean) - Optional - "true" or "false" - **selfTradePreventionMode** (enum) - Optional - "EXPIRE_MAKER", "EXPIRE_BOTH", "NONE" - **reduceOnly** (boolean) - Optional - "true" or "false" - **newOrderRespType** (enum) - Optional - "ACK", "RESULT", "FULL" - **recvWindow** (long) - Optional - Server receive window - **timestamp** (long) - Required - UTC timestamp in milliseconds #### Request Body (Not typically used for this endpoint, parameters are usually in query string) ### Request Example ```bash apiKey="YOUR_API_KEY" secretKey="YOUR_SECRET_KEY" # Example for TAKE_PROFIT order params="algoType=CONDITIONAL&symbol=BNBUSDT&side=SELL&type=TAKE_PROFIT&quantity=0.01&price=750.000&triggerPrice=750.000&timeInForce=GTC&workingType=CONTRACT_PRICE&priceProtect=FALSE&selfTradePreventionMode=EXPIRE_MAKER×tamp=$(date +%s000)" # Generate signature signature=$(echo -n "$params" | openssl dgst -sha256 -hmac "$secretKey" | awk '{print $2}') curl -H "X-MBX-APIKEY: $apiKey" -X POST \ "https://fapi.binance.com/fapi/v1/algoOrder?$params&signature=$signature" # Example for TRAILING_STOP_MARKET order params="algoType=CONDITIONAL&symbol=BTCUSDT&side=BUY&type=TRAILING_STOP_MARKET&callbackRate=1.5&activationPrice=30000&workingType=CONTRACT_PRICE×tamp=$(date +%s000)" # callbackRate=1.5 means 1.5% callback from highest/lowest price # activationPrice=30000 triggers trailing when price reaches this level # Signature generation would be similar to the above example. ``` ### Response #### Success Response (200) - **algoId** (long) - Algorithm order ID. - **clientAlgoId** (string) - Client-provided algorithm order ID. - **algoType** (string) - Type of algorithm order (e.g., "CONDITIONAL"). - **orderType** (string) - Type of order (e.g., "TAKE_PROFIT"). - **symbol** (string) - Trading pair. - **side** (enum) - Order side ("BUY" or "SELL"). - **positionSide** (enum) - Position side. - **timeInForce** (string) - Time in force. - **quantity** (string) - Order quantity. - **algoStatus** (string) - Status of the algorithm order. - **triggerPrice** (string) - Trigger price. - **price** (string) - Order price. - **icebergQuantity** (null or string) - Iceberg quantity. - **selfTradePreventionMode** (string) - Self-trade prevention mode. - **workingType** (string) - Working type. - **priceMatch** (string) - Price match setting. - **closePosition** (boolean) - Close position flag. - **priceProtect** (boolean) - Price protect flag. - **reduceOnly** (boolean) - Reduce only flag. - **activatePrice** (string) - Activation price. - **callbackRate** (string) - Callback rate. - **createTime** (long) - Creation timestamp. - **updateTime** (long) - Update timestamp. - **triggerTime** (long) - Trigger timestamp. - **goodTillDate** (long) - Good till date. #### Response Example ```json { "algoId": 2146760, "clientAlgoId": "6B2I9XVcJpCjqPAJ4YoFX7", "algoType": "CONDITIONAL", "orderType": "TAKE_PROFIT", "symbol": "BNBUSDT", "side": "SELL", "positionSide": "BOTH", "timeInForce": "GTC", "quantity": "0.01", "algoStatus": "NEW", "triggerPrice": "750.000", "price": "750.000", "icebergQuantity": null, "selfTradePreventionMode": "EXPIRE_MAKER", "workingType": "CONTRACT_PRICE", "priceMatch": "NONE", "closePosition": false, "priceProtect": false, "reduceOnly": false, "activatePrice": "", "callbackRate": "", "createTime": 1750485492076, "updateTime": 1750485492076, "triggerTime": 0, "goodTillDate": 0 } ``` ``` -------------------------------- ### WebSocket Market Data Streams Source: https://context7.com/zzfzgs-vick/binance-usdt-m-futures/llms.txt Subscribe to real-time market data including trades, klines, orderbook, and tickers via public WebSocket streams. No authentication is required. ```APIDOC ## WebSocket Market Data Streams ### Description Subscribe to real-time market data (trades, klines, orderbook, tickers) using public WebSocket streams. These streams do not require authentication and support various data types. ### Endpoint Examples * **Aggregate Trades:** `wss://fstream.binance.com/ws/<symbol>@aggTrade` * **Kline/Candlestick:** `wss://fstream.binance.com/ws/<symbol>@kline_<interval>` * **Partial Book Depth:** `wss://fstream.binance.com/ws/<symbol>@depth<level>@<updateSpeed>ms` * **Combined Streams:** `wss://fstream.binance.com/stream?streams=<streamName1>/<streamName2>[/...] ### Stream Parameters * **`<symbol>`**: The trading symbol (e.g., `btcusdt`). * **`<interval>`**: Candlestick interval (e.g., `1m`, `5m`, `1h`). * **`<level>`**: Depth level (e.g., `5`, `10`, `20`). * **`<updateSpeed>`**: Update speed in milliseconds (e.g., `100ms`, `500ms`). * **`<streamName>`**: The name of the stream (e.g., `btcusdt@aggTrade`). ### Request Example (Combined Streams) ``` GET wss://fstream.binance.com/stream?streams=btcusdt@aggTrade/btcusdt@depth/ethusdt@ticker ``` ### Response Example (Aggregate Trades) ```json { "e": "aggTrade", "E": 1568879465651, "s": "BTCUSDT", "a": 123456789, "p": "9416.8", "q": "2", "f": 123456788, "l": 123456790, "T": 1568879465650, "m": false } ``` ### Response Example (Kline/Candlestick) ```json { "e": "kline", "E": 1568879465651, "s": "BTCUSDT", "k": { "t": 1568879460000, "T": 1568879519999, "s": "BTCUSDT", "i": "1m", "f": 123456789, "L": 123456799, "o": "9416.00", "c": "9417.00", "h": "9417.50", "l": "9415.00", "v": "153.2", "n": 11, "x": false, "q": "1442410.03", "V": "87.2", "Q": "821122.89", "B": "0" } } ``` ### Response Example (Partial Book Depth) ```json { "e": "depthUpdate", "E": 1568879465651, "T": 1568879465650, "s": "BTCUSDT", "U": 157, "u": 160, "pu": 149, "b": [ ["9416.00", "10"], ["9415.00", "5"], ["9414.00", "3"], ["9413.00", "2"], ["9412.00", "1"] ], "a": [ ["9417.00", "8"], ["9418.00", "6"], ["9419.00", "4"], ["9420.00", "2"], ["9421.00", "1"] ] } ``` ### Response Example (Combined Streams Data) ```json { "stream": "btcusdt@aggTrade", "data": { "e": "aggTrade", "E": 1568879465651, "s": "BTCUSDT", "a": 123456789, "p": "9416.8", "q": "2", "f": 123456788, "l": 123456790, "T": 1568879465650, "m": false } } ``` ``` -------------------------------- ### GET /sapi/v1/portfolio/earn-asset-balance Source: https://github.com/zzfzgs-vick/binance-usdt-m-futures/blob/main/统一账户专业版/账户接口/查询统一账户LDUSDT可转金额(TRADE).md Queries the transferable earn asset balance for all types of Portfolio Margin accounts. This endpoint is useful for understanding available funds for transfers between Earn and Futures accounts. ```APIDOC ## GET /sapi/v1/portfolio/earn-asset-balance ### Description Get transferable earn asset balance for all types of Portfolio Margin account. ### Method GET ### Endpoint `/sapi/v1/portfolio/earn-asset-balance` ### Parameters #### Query Parameters - **asset** (STRING) - Required - `LDUSDT` only - **transferType** (STRING) - Required - `EARN_TO_FUTURE` /`FUTURE_TO_EARN` - **recvWindow** (LONG) - Optional - Recv window - **timestamp** (LONG) - Required - Timestamp ### Request Example ```json { "asset": "LDUSDT", "transferType": "EARN_TO_FUTURE", "timestamp": 1678886400000 } ``` ### Response #### Success Response (200) - **asset** (STRING) - The asset symbol - **amount** (STRING) - The transferable amount #### Response Example ```json { "asset": "LDUSDT", "amount": "0.55" } ``` ```