### Get Leverage Bracket Information - Response Example Source: https://developers.binance.com/docs/zh-CN/derivatives/coin-margined-futures/account/rest-api/Notional-Bracket-for-Pair This is an example of the JSON response received when querying the leverage bracket information. It details the trading pair, leverage tiers, initial leverage, quantity cap, quantity floor, maintenance margin ratio, and cum. ```JSON [ { "pair": "BTCUSD", "brackets": [ { "bracket": 1, "initialLeverage": 125, "qtyCap": 50, "qtylFloor": 0, "maintMarginRatio": 0.004, "cum": 0.0 } ] } ] ``` -------------------------------- ### Get Quote Response Example (JSON) Source: https://developers.binance.com/docs/zh-CN/derivatives/usds-margined-futures/convert/Send-quote-request This is an example JSON response received after successfully sending a get quote request to the Binance Derivatives API. It includes the quote ID, conversion ratio (ratio and inverseRatio), the validity timestamp of the quote, and the calculated fromAmount and toAmount based on the request. ```JSON { "quoteId":"12415572564", "ratio":"38163.7", "inverseRatio":"0.0000262", "validTimestamp":1623319461670, "toAmount":"3816.37", "fromAmount":"0.1" } ``` -------------------------------- ### Install Binance Derivatives SDKs Source: https://developers.binance.com/docs/zh-CN/derivatives/usds-margined-futures/general-info Commands to install or retrieve the community-provided SDKs for Python and Java to facilitate API interaction. ```bash pip install binance-sdk-derivatives-trading-usds-futures ``` ```bash git clone https://github.com/binance/binance-connector-java.git ``` -------------------------------- ### Get Futures Account Balance Source: https://developers.binance.com/docs/zh-CN/derivatives/usds-margined-futures/account/rest-api/Futures-Account-Balance-V3 This example shows the structure of the response when querying the futures account balance. It includes details for each asset in the account. ```json [ { "accountAlias": "SgsR", "asset": "USDT", "balance": "122607.35137903", "crossWalletBalance": "23.72469206", "crossUnPnl": "0.00000000", "availableBalance": "23.72469206", "maxWithdrawAmount": "23.72469206", "marginAvailable": true, "updateTime": 1617939110373 } ] ``` -------------------------------- ### Batch Orders Response Example Source: https://developers.binance.com/docs/zh-CN/derivatives/usds-margined-futures/trade/rest-api/Place-Multiple-Orders This is an example of a successful response when placing multiple orders. It includes details for each order, such as `orderId`, `status`, and `symbol`. An example of an error response for a rejected order is also shown. ```JSON [ { "clientOrderId": "testOrder", // 用户自定义的订单号 "cumQty": "0", "cumQuote": "0", // 成交金额 — 迁移后会移除 "executedQty": "0", // 成交量 "orderId": 22542179, // 系统订单号 "avgPrice": "0.00000", // 平均成交价 — 迁移后会移除 "origQty": "10", // 原始委托数量 "price": "0", // 委托价格 "reduceOnly": false, // 仅减仓 "side": "SELL", // 买卖方向 "positionSide": "SHORT", // 持仓方向 "status": "NEW", // 订单状态 "stopPrice": "0", "closePosition": false, // 是否条件全平仓 "symbol": "BTCUSDT", // 交易对 "timeInForce": "GTC", // 有效方法 "type": "TRAILING_STOP_MARKET", // 订单类型 "origType": "TRAILING_STOP_MARKET", // 触发前订单类型 "updateTime": 1566818724722, // 更新时间 "workingType": "CONTRACT_PRICE", // 条件价格触发类型 "priceProtect": false, // 是否开启条件单触发保护 "priceMatch": "NONE", //盘口价格下单模式 "selfTradePreventionMode": "NONE", //订单自成交保护模式 "goodTillDate": 1693207680000 //订单TIF为GTD时的自动取消时间 }, { "code": -2022, "msg": "ReduceOnly Order is rejected." } ] ``` -------------------------------- ### Account Information Response Example Source: https://developers.binance.com/docs/zh-CN/derivatives/usds-margined-futures/account/rest-api/Account-Information-V3 This is an example of the response received when querying account information, detailing current futures positions. ```APIDOC ## Response Example ```json { "positions": [ // Only trading pairs with open positions or orders will be returned. // The position direction is displayed according to the user's position mode: // In one-way mode, only BOTH positions are returned. // In hedge mode, only LONG and SHORT positions are returned. { "symbol": "BTCUSDT", // Trading pair "positionSide": "BOTH", // Position side "positionAmt": "1.000", // Position quantity "unrealizedProfit": "0.00000000", // Unrealized profit/loss of the position "isolatedMargin": "0.00000000", "notional": "0", "isolatedWallet": "0", "initialMargin": "0", // Initial margin required for the position (based on the latest mark price) "maintMargin": "0", // Maximum notional value available under the current leverage "updateTime": 0 // Update time } ] } ``` ``` -------------------------------- ### Query All Algo Orders Response Example Source: https://developers.binance.com/docs/zh-CN/derivatives/usds-margined-futures/trade/rest-api/Query-All-Algo-Orders This is an example of the JSON response when querying all algo orders. It includes details for a canceled TAKE_PROFIT order. ```json [ { "algoId": 2146760, "clientAlgoId": "6B2I9XVcJpCjqPAJ4YoFX7", "algoType": "CONDITIONAL", "orderType": "TAKE_PROFIT", "symbol": "BNBUSDT", "side": "SELL", "positionSide": "BOTH", "timeInForce": "GTC", "quantity": "0.01", "algoStatus": "CANCELED", "actualOrderId": "", "actualPrice": "0.00000", "triggerPrice": "750.000", "price": "750.000", "icebergQuantity": null, "tpTriggerPrice": "0.000", "tpPrice": "0.000", "slTriggerPrice": "0.000", "slPrice": "0.000", "tpOrderType": "", "selfTradePreventionMode": "EXPIRE_MAKER", "workingType": "CONTRACT_PRICE", "priceMatch": "NONE", "closePosition": false, "priceProtect": false, "reduceOnly": false, "createTime": 1750485492076, "updateTime": 1750514545091, "triggerTime": 0, "goodTillDate": 0 } ] ``` -------------------------------- ### CM Position Mode Response Example Source: https://developers.binance.com/docs/zh-CN/derivatives/portfolio-margin/account/Change-CM-Position-Mode This is an example of a successful response when changing the CM position mode. It indicates the operation was successful. ```json { "code": 200, "msg": "success" } ``` -------------------------------- ### DAPI Request Weight Changes Source: https://developers.binance.com/docs/zh-CN/derivatives/coin-margined-futures The request weight for several DAPI interfaces has been adjusted. For example, `GET /dapi/v2/leverageBracket` now has a weight of 1 with a `symbol` parameter and 2 without. `GET /dapi/v1/allOrders` and `GET /dapi/v1/userTrades` now have a fixed weight of 5. ```APIDOC ## DAPI Request Weight Changes ### Description The request weight for several DAPI interfaces has been adjusted. For example, `GET /dapi/v2/leverageBracket` now has a weight of 1 with a `symbol` parameter and 2 without. `GET /dapi/v1/allOrders` and `GET /dapi/v1/userTrades` now have a fixed weight of 5. | Interface | Before Migration | After Migration | |-----------------------|------------------|---------------------------------| | `GET /dapi/v2/leverageBracket` | `1` (Fixed) | `1` (with `symbol`) / `2` (without `symbol`) | | `GET /dapi/v1/allOrders` | `20` / `40` | `5` (Fixed) | | `GET /dapi/v1/userTrades` | `20` / `40` | `5` (Fixed) | | `GET /dapi/v1/forceOrders` | `20` (Fixed) | `20` (with `symbol`) / `50` (without `symbol`) | ``` -------------------------------- ### Example: POST /papi/v1/um/order with HMAC Keys Source: https://developers.binance.com/docs/zh-CN/derivatives/portfolio-margin/general-info A practical example demonstrating how to call the order placement endpoint using HMAC authentication with Linux bash tools. ```APIDOC ## Example: POST /papi/v1/um/order - HMAC Keys This example demonstrates calling the order placement endpoint using `openssl` and `curl` in a Linux bash environment. `apiKey` and `secretKey` are for demonstration purposes only. ### API Credentials | Key | Value | |------------|-----------------------------------------------------------------------| | `apiKey` | `dbefbc809e3e83c283a984c3a1459732ea7db1360ca80c5c2c8867408d28cc83` | | `secretKey`| `2b5eb11e18796d12d88f13dc27dbbd02c2cc51ff7059765ed9821957d82bb4d9` | ### Request Parameters | Parameter | Value | |----------------|---------| | `symbol` | `BTCUSDT` | | `side` | `BUY` | | `type` | `LIMIT` | | `timeInForce` | `GTC` | | `quantity` | `1` | | `price` | `9000` | | `recvWindow` | `5000` | | `timestamp` | `1591702613943` | ``` -------------------------------- ### Account Trade List API Request Example Source: https://developers.binance.com/docs/zh-CN/derivatives/usds-margined-futures/trade/rest-api/Account-Trade-List This example demonstrates a GET request to the /fapi/v1/userTrades endpoint to retrieve trade history. Ensure you include necessary parameters like 'symbol' and 'timestamp'. ```HTTP GET /fapi/v1/userTrades?symbol=BTCUSDT&limit=500×tamp=1678886400000&signature=xxx ``` -------------------------------- ### Place Order via Query String - Bash/Curl Source: https://developers.binance.com/docs/zh-CN/derivatives/coin-margined-futures/general-info This example demonstrates how to place a derivatives order using the Binance API by sending all parameters in the query string. It includes generating the HMAC SHA256 signature using openssl and then making the API call with curl. Ensure your API key and secret are kept secure. ```bash $ echo -n "symbol=BTCUSD_200925&side=BUY&type=LIMIT&quantity=1&price=9000&timeInForce=GTC&recvWindow=5000×tamp=1591702613943" | openssl dgst -sha256 -hmac "2b5eb11e18796d12d88f13dc27dbbd02c2cc51ff7059765ed9821957d82bb4d9" (stdin)= 21fd819734bf0e5c68740eed892909414d693635c5f7fffab1313925ae13556a $ curl -H "X-MBX-APIKEY: dbefbc809e3e83c283a984c3a1459732ea7db1360ca80c5c2c8867408d28cc83" -X POST 'https://dapi.binance.com/dapi/v1/order?symbol=BTCUSD_200925&side=BUY&type=LIMIT&quantity=1&price=9000&timeInForce=GTC&recvWindow=5000×tamp=1591702613943&signature= 21fd819734bf0e5c68740eed892909414d693635c5f7fffab1313925ae13556a' ``` -------------------------------- ### Batch Orders Request Example Source: https://developers.binance.com/docs/zh-CN/derivatives/coin-margined-futures/trade/rest-api/Place-Multiple-Orders This example demonstrates how to structure a request to place multiple orders using the `batchOrders` parameter. It includes parameters for order type, time in force, symbol, side, price, and quantity. ```HTTP POST /dapi/v1/batchOrders?batchOrders=[{"type":"LIMIT","timeInForce":"GTC", "symbol":"BTCUSD_PERP","side":"BUY","price":"10001","quantity":"1"}] ``` -------------------------------- ### Query Open Interest Source: https://developers.binance.com/docs/zh-CN/derivatives/change-log Use this endpoint to get the current market open interest. No setup is required. ```HTTP GET /fapi/v1/openInterest ``` -------------------------------- ### POST /fapi/v1/order - HMAC Keys Example Source: https://developers.binance.com/docs/zh-CN/derivatives/usds-margined-futures/general-info Provides examples of calling the order placement endpoint using HMAC SHA256 signatures, demonstrating different ways to send parameters. ```APIDOC ## POST /fapi/v1/order - HMAC Keys Example ### Description This section demonstrates how to call the `/fapi/v1/order` endpoint using HMAC SHA256 keys. It covers three scenarios: sending all parameters via query string, sending all parameters via request body, and a mixed approach. **API Key and Secret Key (for demonstration purposes only):** - `apiKey`: `dbefbc809e3e83c283a984c3a1459732ea7db1360ca80c5c2c8867408d28cc83` - `secretKey`: `2b5eb11e18796d12d88f13dc27dbbd02c2cc51ff7059765ed9821957d82bb4d9` **Common Parameters:** - `symbol` (string) - e.g., `BTCUSDT` - `side` (string) - e.g., `BUY` - `type` (string) - e.g., `LIMIT` - `timeInForce` (string) - e.g., `GTC` - `quantity` (string) - e.g., `1` - `price` (string) - e.g., `9000` - `recvWindow` (integer) - Optional, e.g., `5000` - `timestamp` (integer) - Unix timestamp in milliseconds, e.g., `1591702613943` ### Example 1: All Parameters via Query String #### HMAC SHA256 Signature Generation: ```bash $ echo -n "symbol=BTCUSDT&side=BUY&type=LIMIT&quantity=1&price=9000&timeInForce=GTC&recvWindow=5000×tamp=1591702613943" | openssl dgst -sha256 -hmac "2b5eb11e18796d12d88f13dc27dbbd02c2cc51ff7059765ed9821957d82bb4d9" (stdin)= 3c661234138461fcc7a7d8746c6558c9842d4e10870d2ecbedf7777cad694af9 ``` #### cURL Call: ```bash $ curl -H "X-MBX-APIKEY: dbefbc809e3e83c283a984c3a1459732ea7db1360ca80c5c2c8867408d28cc83" -X POST 'https://fapi.binance.com/fapi/v1/order?symbol=BTCUSDT&side=BUY&type=LIMIT&quantity=1&price=9000&timeInForce=GTC&recvWindow=5000×tamp=1591702613943&signature=3c661234138461fcc7a7d8746c6558c9842d4e10870d2ecbedf7777cad694af9' ``` ### Example 2: All Parameters via Request Body #### HMAC SHA256 Signature Generation: ```bash $ echo -n "symbol=BTCUSDT&side=BUY&type=LIMIT&quantity=1&price=9000&timeInForce=GTC&recvWindow=5000×tamp=1591702613943" | openssl dgst -sha256 -hmac "2b5eb11e18796d12d88f13dc27dbbd02c2cc51ff7059765ed9821957d82bb4d9" (stdin)= 3c661234138461fcc7a7d8746c6558c9842d4e10870d2ecbedf7777cad694af9 ``` #### cURL Call: ```bash $ curl -H "X-MBX-APIKEY: dbefbc809e3e83c283a984c3a1459732ea7db1360ca80c5c2c8867408d28cc83" -X POST 'https://fapi.binance.com/fapi/v1/order' -d 'symbol=BTCUSDT&side=BUY&type=LIMIT&quantity=1&price=9000&timeInForce=GTC&recvWindow=5000×tamp=1591702613943&signature=3c661234138461fcc7a7d8746c6558c9842d4e10870d2ecbedf7777cad694af9' ``` ### Example 3: Mixed Query String and Request Body **Note:** In this example, there is no '&' character between `GTC` and `quantity=1` in the signature string. #### HMAC SHA256 Signature Generation: ```bash $ echo -n "symbol=BTCUSDT&side=BUY&type=LIMIT&timeInForce=GTCquantity=1&price=9000&recvWindow=5000×tamp=1591702613943" | openssl dgst -sha256 -hmac "2b5eb11e18796d12d88f13dc27dbbd02c2cc51ff7059765ed9821957d82bb4d9" (stdin)= f9d0ae5e813ef6ccf15c2b5a434047a0181cb5a342b903b367ca6d27a66e36f2 ``` #### cURL Call: ```bash $ curl -H "X-MBX-APIKEY: dbefbc809e3e83c283a984c3a1459732ea7db1360ca80c5c2c8867408d28cc83" -X POST 'https://fapi.binance.com/fapi/v1/order?symbol=BTCUSDT&side=BUY&type=LIMIT&timeInForce=GTC' -d 'quantity=1&price=9000&recvWindow=5000×tamp=1591702613943&signature=f9d0ae5e813ef6ccf15c2b5a434047a0181cb5a342b903b367ca6d27a66e36f2' ``` ``` -------------------------------- ### Get Latest Price - REST API Example Source: https://developers.binance.com/docs/zh-CN/derivatives/coin-margined-futures/market-data/rest-api/Symbol-Price-Ticker This snippet demonstrates how to make an HTTP GET request to the Binance Futures API to retrieve the latest price for a trading pair. It shows the structure of the request and the expected JSON response format. ```HTTP GET /dapi/v1/ticker/price?symbol=BTCUSD_200626 ``` ```JSON [ { "symbol": "BTCUSD_200626", "ps": "BTCUSD", "price": "9647.8", "time": 1591257246176 } ] ``` -------------------------------- ### Place Order Request Example Source: https://developers.binance.com/docs/zh-CN/derivatives/coin-margined-futures/trade/websocket-api This is an example of a JSON request to place a LIMIT order for BTCUSD_PERP using the `order.place` method. Ensure all required parameters like symbol, side, type, quantity, price, timestamp, and signature are correctly provided. ```json { "id": "60fa4366-f96e-42fe-a82b-f819952c6db4", "method": "order.place", "params": { "apiKey": "", "price": "50000", "quantity": 1, "side": "BUY", "symbol": "BTCUSD_PERP", "timeInForce": "GTC", "timestamp": 1728413737111, "type": "LIMIT", "signature": "0f04368b2d22aafd0ggc8809ea34297eff602272917b5f01267db4efbc1c9422" } } ``` -------------------------------- ### Query Funding Rate History - HTTP GET Request Source: https://developers.binance.com/docs/zh-CN/derivatives/usds-margined-futures/market-data/rest-api/Get-Funding-Rate-History This snippet demonstrates how to make an HTTP GET request to the `/fapi/v1/fundingRate` endpoint to retrieve historical funding rate data. It includes optional parameters for filtering by symbol, start time, end time, and limit. If no time parameters are provided, it returns the 200 most recent records. If the data exceeds the limit, it returns data up to the limit from the start time. ```HTTP GET /fapi/v1/fundingRate?symbol=BTCUSDT&startTime=1640995200000&endTime=1641081600000&limit=200 ``` -------------------------------- ### Response Example Source: https://developers.binance.com/docs/zh-CN/derivatives/coin-margined-futures/trade/rest-api/Change-Position-Mode A successful response indicates the position mode has been updated. ```JSON { "code": 200, "msg": "success" } ``` -------------------------------- ### Generate RSA Signature and Execute Request via Bash Source: https://developers.binance.com/docs/zh-CN/derivatives/coin-margined-futures/general-info Demonstrates the step-by-step process of creating a signature using OpenSSL and sending a signed POST request to the Binance Derivatives API. Includes parameter concatenation, signing, base64 encoding, and URL encoding. ```bash #!/usr/bin/env bash apiKey="vE3BDAL1gP1UaexugRLtteaAHg3UO8Nza20uexEuW1Kh3tVwQfFHdAiyjjY428o2" apiMethod="POST" apiCall="v1/order" apiParams="timestamp=1671090801999&recvWindow=9999999&symbol=BTCUSD_PERP&side=SELL&type=MARKET&quantity=100" function rawurlencode { local value="$1" local len=${#value} local encoded="" local pos c o for (( pos=0 ; pos