From bd300ae55866cfb084fd5c38d19e4ca4e5063ba3 Mon Sep 17 00:00:00 2001 From: David Mohl Date: Sat, 1 Jul 2023 19:22:46 +1000 Subject: [PATCH 01/25] Start implementing auto-generation from docs --- lib/binance/docs/spot.json | 15304 ++++++++++++++++++++++++++++++ lib/binance/docs_parser.ex | 95 + lib/binance/rest/http_client.ex | 58 +- lib/binance2.ex | 91 + 4 files changed, 15534 insertions(+), 14 deletions(-) create mode 100644 lib/binance/docs/spot.json create mode 100644 lib/binance/docs_parser.ex create mode 100644 lib/binance2.ex diff --git a/lib/binance/docs/spot.json b/lib/binance/docs/spot.json new file mode 100644 index 0000000..80710b8 --- /dev/null +++ b/lib/binance/docs/spot.json @@ -0,0 +1,15304 @@ +{ + "info": { + "_postman_id": "41cefd3a-b3d7-4fb4-b1e3-3b010bdbf070", + "name": "Binance Spot API", + "description": "Binance official supported Postman collections.
\n- API documents: https://binance-docs.github.io/apidocs/spot/en/#change-log\n- Telegram: https://t.me/binance_api_english\n- Open Issue at: https://github.com/binance-exchange/binance-api-postman", + "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json", + "_exporter_id": "10130460" + }, + "item": [ + { + "name": "BLVT", + "item": [ + { + "name": "Get BLVT Info (MARKET_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/blvt/tokenInfo", + "host": ["{{url}}"], + "path": ["sapi", "v1", "blvt", "tokenInfo"], + "query": [ + { + "key": "tokenName", + "value": "", + "description": "BTCDOWN, BTCUP", + "disabled": true + } + ] + }, + "description": "Weight(IP): 1" + }, + "response": [] + }, + { + "name": "Subscribe BLVT (USER_DATA)", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/blvt/subscribe?tokenName=&cost=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "blvt", "subscribe"], + "query": [ + { + "key": "tokenName", + "value": "", + "description": "BTCDOWN, BTCUP" + }, + { + "key": "cost", + "value": "", + "description": "Spot balance" + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Weight(IP): 1" + }, + "response": [] + }, + { + "name": "Query Subscription Record (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/blvt/subscribe/record?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "blvt", "subscribe", "record"], + "query": [ + { + "key": "tokenName", + "value": "", + "description": "BTCDOWN, BTCUP", + "disabled": true + }, + { + "key": "id", + "value": "", + "disabled": true + }, + { + "key": "startTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "endTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "limit", + "value": "500", + "description": "Default 500; max 1000.", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "- Only the data of the latest 90 days is available\n\nWeight(IP): 1" + }, + "response": [] + }, + { + "name": "Redeem BLVT (USER_DATA)", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/blvt/redeem?tokenName=&amount=1.01×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "blvt", "redeem"], + "query": [ + { + "key": "tokenName", + "value": "", + "description": "BTCDOWN, BTCUP" + }, + { + "key": "amount", + "value": "1.01" + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Weight(IP): 1" + }, + "response": [] + }, + { + "name": "Query Redemption Record (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/blvt/redeem/record?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "blvt", "redeem", "record"], + "query": [ + { + "key": "tokenName", + "value": "", + "description": "BTCDOWN, BTCUP", + "disabled": true + }, + { + "key": "id", + "value": "", + "disabled": true + }, + { + "key": "startTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "endTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "limit", + "value": "", + "description": "default 1000, max 1000", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "- Only the data of the latest 90 days is available\n\nWeight(IP): 1" + }, + "response": [] + }, + { + "name": "Get BLVT User Limit Info (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/blvt/userLimit?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "blvt", "userLimit"], + "query": [ + { + "key": "tokenName", + "value": "", + "description": "BTCDOWN, BTCUP", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Weight(IP): 1" + }, + "response": [] + } + ], + "description": "Binance Leveraged Tokens Endpoints" + }, + { + "name": "BSwap", + "item": [ + { + "name": "List All Swap Pools (MARKET_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/bswap/pools", + "host": ["{{url}}"], + "path": ["sapi", "v1", "bswap", "pools"] + }, + "description": "Get metadata about all swap pools.\n\nWeight(IP): 1" + }, + "response": [] + }, + { + "name": "Get liquidity information of a pool (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/bswap/liquidity?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "bswap", "liquidity"], + "query": [ + { + "key": "poolId", + "value": "", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Get liquidity information and user share of a pool.\n\nWeight(IP):\n- `1` for one pool;\n- `10` when the poolId parameter is omitted;" + }, + "response": [] + }, + { + "name": "Add Liquidity (TRADE)", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/bswap/liquidityAdd?poolId=&asset=BTC&quantity=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "bswap", "liquidityAdd"], + "query": [ + { + "key": "poolId", + "value": "" + }, + { + "key": "type", + "value": "Single", + "description": "* `Single` - to add a single token\n* `Combination` - to add dual tokens", + "disabled": true + }, + { + "key": "asset", + "value": "BTC" + }, + { + "key": "quantity", + "value": "" + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Add liquidity to a pool.\n\nWeight(UID): 1000 (Additional: 3 times one second)" + }, + "response": [] + }, + { + "name": "Remove Liquidity (TRADE)", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/bswap/liquidityRemove?poolId=&type=SINGLE&shareAmount=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "bswap", "liquidityRemove"], + "query": [ + { + "key": "poolId", + "value": "" + }, + { + "key": "type", + "value": "SINGLE", + "description": "* `SINGLE` - for single asset removal\n* `COMBINATION` - for combination of all coins removal" + }, + { + "key": "asset", + "value": "BNB", + "description": "Mandatory for single asset removal", + "disabled": true + }, + { + "key": "shareAmount", + "value": "" + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Remove liquidity from a pool, `type` include `SINGLE` and `COMBINATION`, asset is mandatory for single asset removal\n\nWeight(UID): 1000 (Additional: 3 times one second)" + }, + "response": [] + }, + { + "name": "Get Liquidity Operation Record (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/bswap/liquidityOps?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "bswap", "liquidityOps"], + "query": [ + { + "key": "operationId", + "value": "", + "disabled": true + }, + { + "key": "poolId", + "value": "", + "disabled": true + }, + { + "key": "operation", + "value": "", + "disabled": true + }, + { + "key": "startTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "endTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "limit", + "value": "100", + "description": "Default 500; max 1000.", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Get liquidity operation (add/remove) records.\n\nWeight(UID): 3000" + }, + "response": [] + }, + { + "name": "Request Quote (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/bswap/quote?quoteAsset=USDT&baseAsset=BUSD"eQty=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "bswap", "quote"], + "query": [ + { + "key": "quoteAsset", + "value": "USDT" + }, + { + "key": "baseAsset", + "value": "BUSD" + }, + { + "key": "quoteQty", + "value": "" + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Request a quote for swap quote asset (selling asset) for base asset (buying asset), essentially price/exchange rates.\n\nquoteQty is quantity of quote asset (to sell).\n\nPlease be noted the quote is for reference only, the actual price will change as the liquidity changes, it's recommended to swap immediate after request a quote for slippage prevention.\n\nWeight(UID): 150" + }, + "response": [] + }, + { + "name": "Swap (TRADE)", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/bswap/swap?quoteAsset=USDT&baseAsset=BUSD"eQty=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "bswap", "swap"], + "query": [ + { + "key": "quoteAsset", + "value": "USDT" + }, + { + "key": "baseAsset", + "value": "BUSD" + }, + { + "key": "quoteQty", + "value": "" + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Swap `quoteAsset` for `baseAsset`.\n\nWeight(UID): 1000 (Additional: 3 times one second)" + }, + "response": [] + }, + { + "name": "Get Swap History (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/bswap/swap?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "bswap", "swap"], + "query": [ + { + "key": "swapId", + "value": "", + "disabled": true + }, + { + "key": "startTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "endTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "status", + "value": "", + "description": "* `0` - pending for swap\n* `1` - success\n* `2` - failed", + "disabled": true + }, + { + "key": "quoteAsset", + "value": "USDT", + "disabled": true + }, + { + "key": "baseAsset", + "value": "BUSD", + "disabled": true + }, + { + "key": "limit", + "value": "", + "description": "default 3, max 100", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Get swap history.\n\nWeight(UID): 3000" + }, + "response": [] + }, + { + "name": "Get Pool Configure (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/bswap/poolConfigure?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "bswap", "poolConfigure"], + "query": [ + { + "key": "poolId", + "value": "2", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Weight(IP): 150" + }, + "response": [] + }, + { + "name": "Add Liquidity Preview (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/bswap/addLiquidityPreview?poolId=2&type=SINGLE"eAsset=USDT"eQty=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "bswap", "addLiquidityPreview"], + "query": [ + { + "key": "poolId", + "value": "2" + }, + { + "key": "type", + "value": "SINGLE", + "description": "* `SINGLE` - for adding a single token\n* `COMBINATION` - for adding dual tokens" + }, + { + "key": "quoteAsset", + "value": "USDT" + }, + { + "key": "quoteQty", + "value": "" + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Calculate expected share amount for adding liquidity in single or dual token.\n\nWeight(IP): 150" + }, + "response": [] + }, + { + "name": "Remove Liquidity Preview (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/bswap/removeLiquidityPreview?poolId=2&type=SINGLE"eAsset=USDT&shareAmount=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "bswap", "removeLiquidityPreview"], + "query": [ + { + "key": "poolId", + "value": "2" + }, + { + "key": "type", + "value": "SINGLE", + "description": "* `SINGLE` - remove and obtain a single token\n* `COMBINATION` - remove and obtain dual token" + }, + { + "key": "quoteAsset", + "value": "USDT" + }, + { + "key": "shareAmount", + "value": "" + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Calculate the expected asset amount of single token redemption or dual token redemption.\n\nWeight(IP): 150" + }, + "response": [] + }, + { + "name": "Get Unclaimed Rewards Record (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/bswap/unclaimedRewards?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "bswap", "unclaimedRewards"], + "query": [ + { + "key": "type", + "value": "0", + "description": "0: Swap rewards, 1: Liquidity rewards, default to 0", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Get unclaimed rewards record.\n \nWeight(UID): 1000" + }, + "response": [] + }, + { + "name": "Claim Rewards (TRADE)", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/bswap/claimRewards?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "bswap", "claimRewards"], + "query": [ + { + "key": "type", + "value": "0", + "description": "0: Swap rewards, 1: Liquidity rewards, default to 0", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Claim swap rewards or liquidity rewards\n \nWeight(UID): 1000" + }, + "response": [] + }, + { + "name": "Get Claimed History (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/bswap/claimedHistory?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "bswap", "claimedHistory"], + "query": [ + { + "key": "poolId", + "value": "", + "disabled": true + }, + { + "key": "assetRewards", + "value": "", + "disabled": true + }, + { + "key": "type", + "value": "0", + "description": "0: Swap rewards, 1: Liquidity rewards, default to 0", + "disabled": true + }, + { + "key": "startTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "endTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "limit", + "value": "", + "description": "Default 3, max 100", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Get history of claimed rewards.\n \nWeight(UID): 1000" + }, + "response": [] + } + ], + "description": "Binance Swap Endpoints" + }, + { + "name": "C2C", + "item": [ + { + "name": "Get C2C Trade History (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/c2c/orderMatch/listUserOrderHistory?tradeType=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": [ + "sapi", + "v1", + "c2c", + "orderMatch", + "listUserOrderHistory" + ], + "query": [ + { + "key": "tradeType", + "value": "", + "description": "BUY, SELL" + }, + { + "key": "startTimestamp", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "endTimestamp", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "page", + "value": "1", + "description": "Default 1", + "disabled": true + }, + { + "key": "rows", + "value": "", + "description": "default 100, max 100", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "- If startTimestamp and endTimestamp are not sent, the recent 30-day data will be returned.\n- The max interval between startTimestamp and endTimestamp is 30 days.\n\nWeight(IP): 1" + }, + "response": [] + } + ], + "description": "Consumer-To-Consumer Endpoints" + }, + { + "name": "Convert", + "item": [ + { + "name": "List All Convert Pairs (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/convert/exchangeInfo?fromAsset=&toAsset=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "convert", "exchangeInfo"], + "query": [ + { + "key": "fromAsset", + "value": "", + "description": "User spends coin" + }, + { + "key": "toAsset", + "value": "", + "description": "User receives coin" + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "- The max interval between startTime and endTime is 30 days.\n\nWeight(UID): 100" + }, + "response": [] + }, + { + "name": "Query order quantity precision per asset (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/convert/assetInfo?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "convert", "assetInfo"], + "query": [ + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "- The max interval between startTime and endTime is 30 days.\n\nWeight(UID): 100" + }, + "response": [] + }, + { + "name": "Send quote request (USER_DATA)", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/convert/getQuote?fromAsset=&toAsset=&fromAmount=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "convert", "getQuote"], + "query": [ + { + "key": "fromAsset", + "value": "" + }, + { + "key": "toAsset", + "value": "" + }, + { + "key": "fromAmount", + "value": "", + "description": "When specified, it is the amount you will be debited after the conversion" + }, + { + "key": "toAmount", + "value": "", + "description": "When specified, it is the amount you will be credited after the conversion", + "disabled": true + }, + { + "key": "validTime", + "value": "10s", + "description": "10s, 30s, 1m, 2m, default 10s", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "- The max interval between startTime and endTime is 30 days.\n\nWeight(UID): 100" + }, + "response": [] + }, + { + "name": "Accept Quote (TRADE)", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/convert/acceptQuote?quoteId=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "convert", "acceptQuote"], + "query": [ + { + "key": "quoteId", + "value": "" + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "- The max interval between startTime and endTime is 30 days.\n\nWeight(UID): 100" + }, + "response": [] + }, + { + "name": "Order status (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/convert/orderStatus?orderId=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "convert", "orderStatus"], + "query": [ + { + "key": "orderId", + "value": "" + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "- The max interval between startTime and endTime is 30 days.\n\nWeight(UID): 100" + }, + "response": [] + }, + { + "name": "Get Convert Trade History (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/convert/tradeFlow?startTime=&endTime=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "convert", "tradeFlow"], + "query": [ + { + "key": "startTime", + "value": "", + "description": "UTC timestamp in ms" + }, + { + "key": "endTime", + "value": "", + "description": "UTC timestamp in ms" + }, + { + "key": "limit", + "value": "100", + "description": "default 100, max 1000", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "- The max interval between startTime and endTime is 30 days.\n\nWeight(UID): 100" + }, + "response": [] + } + ], + "description": "Convert Endpoints" + }, + { + "name": "Crypto Loans", + "item": [ + { + "name": "Get Crypto Loans Income History (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/loan/income?asset=BTC×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "loan", "income"], + "query": [ + { + "key": "asset", + "value": "BTC" + }, + { + "key": "type", + "value": "", + "description": "All types will be returned by default.\n* `borrowIn`\n* `collateralSpent`\n* `repayAmount`\n* `collateralReturn` - Collateral return after repayment\n* `addCollateral`\n* `removeCollateral`\n* `collateralReturnAfterLiquidation`", + "disabled": true + }, + { + "key": "startTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "endTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "limit", + "value": "20", + "description": "default 20, max 100", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "- If startTime and endTime are not sent, the recent 7-day data will be returned.\n- The max interval between startTime and endTime is 30 days.\n\nWeight(UID): 6000" + }, + "response": [] + }, + { + "name": "Borrow - Crypto Loan Borrow (TRADE)", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/loan/borrow?loanCoin=&collateralCoin=&loanTerm=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "loan", "borrow"], + "query": [ + { + "key": "loanAmount", + "value": "", + "description": "Mandatory when collateralAmount is empty", + "disabled": true + }, + { + "key": "collateralAmount", + "value": "", + "description": "Mandatory when loanAmount is empty", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "loanCoin", + "value": "" + }, + { + "key": "collateralCoin", + "value": "" + }, + { + "key": "loanTerm", + "value": "" + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + } + }, + "response": [] + }, + { + "name": "Borrow - Get Loan Borrow History (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/loan/borrow/history?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "loan", "borrow", "history"], + "query": [ + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + }, + { + "key": "loanCoin", + "value": "", + "disabled": true + }, + { + "key": "collateralCoin", + "value": "", + "disabled": true + }, + { + "key": "orderId", + "value": "", + "description": "orderId in POST /sapi/v1/loan/borrow", + "disabled": true + }, + { + "key": "startTime", + "value": "", + "disabled": true + }, + { + "key": "endTime", + "value": "", + "disabled": true + }, + { + "key": "current", + "value": "", + "description": "Current querying page. Start from 1; default: 1; max: 1000", + "disabled": true + }, + { + "key": "limit", + "value": "", + "description": "Default: 10; max: 100.", + "disabled": true + } + ] + } + }, + "response": [] + }, + { + "name": "Borrow - Get Loan Ongoing Orders (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/loan/ongoing/orders?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "loan", "ongoing", "orders"], + "query": [ + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + }, + { + "key": "loanCoin", + "value": "", + "disabled": true + }, + { + "key": "collateralCoin", + "value": "", + "disabled": true + }, + { + "key": "orderId", + "value": "", + "description": "orderId in POST /sapi/v1/loan/borrow", + "disabled": true + }, + { + "key": "current", + "value": "", + "description": "Current querying page. Start from 1; default: 1; max: 1000", + "disabled": true + }, + { + "key": "limit", + "value": "", + "description": "Default: 10; max: 100.", + "disabled": true + } + ] + } + }, + "response": [] + }, + { + "name": "Repay - Crypto Loan Repay (TRADE)", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/loan/repay?timestamp={{timestamp}}&signature={{signature}}&orderId=&amount=", + "host": ["{{url}}"], + "path": ["sapi", "v1", "loan", "repay"], + "query": [ + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + }, + { + "key": "collateralReturn", + "value": "", + "description": "Default: TRUE. TRUE: Return extra collateral to spot account; FALSE: Keep extra collateral in the order.", + "disabled": true + }, + { + "key": "orderId", + "value": "" + }, + { + "key": "amount", + "value": "" + }, + { + "key": "type", + "value": "", + "description": "Default: 1. 1 for \"repay with borrowed coin\"; 2 for \"repay with collateral\".", + "disabled": true + } + ] + } + }, + "response": [] + }, + { + "name": "Repay - Get Loan Repayment History (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/loan/repay/history?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "loan", "repay", "history"], + "query": [ + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + }, + { + "key": "loanCoin", + "value": "", + "disabled": true + }, + { + "key": "collateralCoin", + "value": "", + "disabled": true + }, + { + "key": "orderId", + "value": "", + "disabled": true + }, + { + "key": "current", + "value": "", + "description": "Current querying page. Start from 1; default: 1; max: 1000", + "disabled": true + }, + { + "key": "limit", + "value": "", + "description": "Default: 10; max: 100.", + "disabled": true + }, + { + "key": "startTime", + "value": "", + "disabled": true + }, + { + "key": "endTime", + "value": "", + "disabled": true + } + ] + } + }, + "response": [] + }, + { + "name": "Adjust LTV - Crypto Loan Adjust LTV (TRADE)", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/loan/adjust/ltv?timestamp={{timestamp}}&signature={{signature}}&orderId=&amount=&direction=", + "host": ["{{url}}"], + "path": ["sapi", "v1", "loan", "adjust", "ltv"], + "query": [ + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + }, + { + "key": "orderId", + "value": "" + }, + { + "key": "amount", + "value": "" + }, + { + "key": "direction", + "value": "", + "description": "\"ADDITIONAL\", \"REDUCED\"" + } + ] + } + }, + "response": [] + }, + { + "name": "Adjust LTV - Get Loan LTV Adjustment History (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/loan/ltv/adjustment/history?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "loan", "ltv", "adjustment", "history"], + "query": [ + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + }, + { + "key": "loanCoin", + "value": "", + "disabled": true + }, + { + "key": "collateralCoin", + "value": "", + "disabled": true + }, + { + "key": "orderId", + "value": "", + "disabled": true + }, + { + "key": "current", + "value": "", + "description": "Current querying page. Start from 1; default: 1; max: 1000", + "disabled": true + }, + { + "key": "limit", + "value": "", + "description": "Default: 10; max: 100.", + "disabled": true + }, + { + "key": "startTime", + "value": "", + "disabled": true + }, + { + "key": "endTime", + "value": "", + "disabled": true + } + ] + } + }, + "response": [] + }, + { + "name": "Get Loanable Assets Data (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/loan/loanable/data?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "loan", "loanable", "data"], + "query": [ + { + "key": "loanCoin", + "value": "", + "disabled": true + }, + { + "key": "vipLevel", + "value": "", + "description": "Default: user's vip level. Send \"-1\" to check specified configuration", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + } + }, + "response": [] + }, + { + "name": "Get Collateral Assets Data (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/loan/collateral/data?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "loan", "collateral", "data"], + "query": [ + { + "key": "collateralCoin", + "value": "", + "disabled": true + }, + { + "key": "vipLevel", + "value": "", + "description": "Default: user's vip level. Send \"-1\" to check specified configuration", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + } + }, + "response": [] + }, + { + "name": "Check Collateral Repay Rate (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/loan/repay/collateral/rate?loanCoin=&collateralCoin=&repayAmount=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "loan", "repay", "collateral", "rate"], + "query": [ + { + "key": "loanCoin", + "value": "" + }, + { + "key": "collateralCoin", + "value": "" + }, + { + "key": "repayAmount", + "value": "", + "description": "repay amount of loanCoin" + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + } + }, + "response": [] + }, + { + "name": "Crypto Loan Customize Margin Call (TRADE)", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/loan/customize/margin_call?marginCall=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "loan", "customize", "margin_call"], + "query": [ + { + "key": "orderId", + "value": "", + "description": "Mandatory when collateralCoin is empty. Send either orderId or collateralCoin, if both parameters are sent, take orderId only", + "disabled": true + }, + { + "key": "collateralCoin", + "value": null, + "description": "Mandatory when orderID is empty. Send either orderId or collateralCoin, if both parameters are sent, take orderId only.", + "disabled": true + }, + { + "key": "marginCall", + "value": "" + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + } + }, + "response": [] + } + ], + "description": "Crypto Loans Endpoints" + }, + { + "name": "Fiat", + "item": [ + { + "name": "Get Fiat Deposit/Withdraw History (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/fiat/orders?transactionType=0×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "fiat", "orders"], + "query": [ + { + "key": "transactionType", + "value": "0", + "description": "* `0` - deposit\n* `1` - withdraw" + }, + { + "key": "beginTime", + "value": "1626144956000", + "disabled": true + }, + { + "key": "endTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "page", + "value": "1", + "description": "Default 1", + "disabled": true + }, + { + "key": "rows", + "value": "300", + "description": "Default 100, max 500", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "- If beginTime and endTime are not sent, the recent 30-day data will be returned.\n\nWeight(UID): 90000" + }, + "response": [] + }, + { + "name": "Get Fiat Payments History (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/fiat/payments?transactionType=0×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "fiat", "payments"], + "query": [ + { + "key": "transactionType", + "value": "0", + "description": "* `0` - deposit\n* `1` - withdraw" + }, + { + "key": "beginTime", + "value": "1626144956000", + "disabled": true + }, + { + "key": "endTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "page", + "value": "1", + "description": "Default 1", + "disabled": true + }, + { + "key": "rows", + "value": "300", + "description": "Default 100, max 500", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "- If beginTime and endTime are not sent, the recent 30-day data will be returned.\n\nWeight(IP): 1" + }, + "response": [] + } + ], + "description": "Fiat Endpoints" + }, + { + "name": "Futures", + "item": [ + { + "name": "New Future Account Transfer (USER_DATA)", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/futures/transfer?asset=&amount=&type=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "futures", "transfer"], + "query": [ + { + "key": "asset", + "value": "", + "description": "The asset being transferred, e.g., USDT" + }, + { + "key": "amount", + "value": "", + "description": "The amount to be transferred" + }, + { + "key": "type", + "value": "", + "description": "1: transfer from spot account to USDT-Ⓜ futures account. 2: transfer from USDT-Ⓜ futures account to spot account. 3: transfer from spot account to COIN-Ⓜ futures account. 4: transfer from COIN-Ⓜ futures account to spot account." + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Execute transfer between spot account and futures account.\n\nWeight(IP): 1" + }, + "response": [] + }, + { + "name": "Get Future Account Transaction History List (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/futures/transfer?asset=&startTime=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "futures", "transfer"], + "query": [ + { + "key": "asset", + "value": "" + }, + { + "key": "startTime", + "value": "" + }, + { + "key": "endTime", + "value": "", + "disabled": true + }, + { + "key": "current", + "value": "", + "description": "Currently querying page. Start from 1. Default:1", + "disabled": true + }, + { + "key": "size", + "value": "", + "description": "Default:10 Max:100", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Weight(IP): 10" + }, + "response": [] + }, + { + "name": "Cross-Collateral Borrow History (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/futures/loan/borrow/history?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "futures", "loan", "borrow", "history"], + "query": [ + { + "key": "coin", + "value": null, + "disabled": true + }, + { + "key": "startTime", + "value": "", + "disabled": true + }, + { + "key": "endTime", + "value": "", + "disabled": true + }, + { + "key": "limit", + "value": "", + "description": "default 500, max 1000", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Weight(IP): 10" + }, + "response": [] + }, + { + "name": "Cross-Collateral Repayment History (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/futures/loan/repay/history?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "futures", "loan", "repay", "history"], + "query": [ + { + "key": "coin", + "value": "", + "disabled": true + }, + { + "key": "startTime", + "value": "", + "disabled": true + }, + { + "key": "endTime", + "value": "", + "disabled": true + }, + { + "key": "limit", + "value": "", + "description": "default 500, max 1000", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Get Cross-Collateral Repayment History." + }, + "response": [] + }, + { + "name": "Cross-Collateral Wallet V2 (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v2/futures/loan/wallet?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v2", "futures", "loan", "wallet"], + "query": [ + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Get Cross-Collateral Wallet V2." + }, + "response": [] + }, + { + "name": "Adjust Cross-Collateral LTV History (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/futures/loan/adjustCollateral/history?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": [ + "sapi", + "v1", + "futures", + "loan", + "adjustCollateral", + "history" + ], + "query": [ + { + "key": "loanCoin", + "value": "", + "disabled": true + }, + { + "key": "collateralCoin", + "value": "", + "disabled": true + }, + { + "key": "startTime", + "value": "", + "disabled": true + }, + { + "key": "endTime", + "value": "", + "disabled": true + }, + { + "key": "limit", + "value": "", + "description": "default 500, max 1000", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Get Adjust Cross-Collateral LTV History." + }, + "response": [] + }, + { + "name": "Cross-Collateral Liquidation History (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/futures/loan/liquidationHistory?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "futures", "loan", "liquidationHistory"], + "query": [ + { + "key": "loanCoin", + "value": "", + "disabled": true + }, + { + "key": "collateralCoin", + "value": "", + "disabled": true + }, + { + "key": "startTime", + "value": "", + "disabled": true + }, + { + "key": "endTime", + "value": "", + "disabled": true + }, + { + "key": "limit", + "value": "", + "description": "default 500, max 1000", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Get Cross-Collateral Liquidation History." + }, + "response": [] + }, + { + "name": "Cross-Collateral Interest History (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/futures/loan/interestHistory?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "futures", "loan", "interestHistory"], + "query": [ + { + "key": "collateralCoin", + "value": "", + "disabled": true + }, + { + "key": "startTime", + "value": "", + "disabled": true + }, + { + "key": "endTime", + "value": "", + "disabled": true + }, + { + "key": "current", + "value": "", + "description": "Currently querying page. Start from 1. Default:1", + "disabled": true + }, + { + "key": "limit", + "value": "", + "description": "Default:500 Max:1000", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + } + }, + "response": [] + } + ] + }, + { + "name": "Futures Algo", + "item": [ + { + "name": "Volume Participation New Order (TRADE)", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/algo/futures/newOrderVp?symbol=&side=SELL&quantity=&urgency=LOW×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "algo", "futures", "newOrderVp"], + "query": [ + { + "key": "symbol", + "value": "", + "description": "Trading symbol eg. BTCUSDT" + }, + { + "key": "side", + "value": "SELL", + "description": "Trading side ( BUY or SELL )" + }, + { + "key": "positionSide", + "value": "", + "description": "Default BOTH for One-way Mode ; LONG or SHORT for Hedge Mode. It must be sent in Hedge Mode.", + "disabled": true + }, + { + "key": "quantity", + "value": "", + "description": "Quantity of base asset; The notional (quantity * mark price(base asset)) must be more than the equivalent of 10,000 USDT and less than the equivalent of 1,000,000 USDT." + }, + { + "key": "urgency", + "value": "LOW", + "description": "Represent the relative speed of the current execution; ENUM: LOW, MEDIUM, HIGH." + }, + { + "key": "clientAlgoId", + "value": "", + "description": "A unique id among Algo orders (length should be 32 characters), If it is not sent, we will give default value.", + "disabled": true + }, + { + "key": "reduceOnly", + "value": "", + "description": "\"true\" or \"false\". Default \"false\"; Cannot be sent in Hedge Mode; Cannot be sent when you open a position.", + "disabled": true + }, + { + "key": "limitPrice", + "value": "", + "description": "Limit price of the order; If it is not sent, will place order by market price by default.", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Send in a VP new order. Only support on USDⓈ-M Contracts.\n\nWeight(IP): 3000\n\n- Max open orders allowed: 10 orders.\n- Leverage of symbols and position mode will be the same as your futures account settings. You can set up through the trading page or fapi.\n- Receiving \"success\": true does not mean that your order will be executed. Please use the query order endpoints(GET sapi/v1/algo/futures/openOrders or GET sapi/v1/algo/futures/historicalOrders) to check the order status. For example: Your futures balance is insufficient, or open position with reduce only or position side is inconsistent with your own setting. In these cases you will receive \"success\": true, but the order status will be expired after we check it." + }, + "response": [] + }, + { + "name": "Time-Weighted Average Price New Order (TRADE)", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/algo/futures/newOrderTwap?symbol=&side=&quantity=&duration=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "algo", "futures", "newOrderTwap"], + "query": [ + { + "key": "symbol", + "value": "", + "description": "Trading symbol eg. BTCUSDT" + }, + { + "key": "side", + "value": "", + "description": "Trading side ( BUY or SELL )" + }, + { + "key": "positionSide", + "value": "", + "description": "Default BOTH for One-way Mode ; LONG or SHORT for Hedge Mode. It must be sent in Hedge Mode.", + "disabled": true + }, + { + "key": "quantity", + "value": "", + "description": "Quantity of base asset; The notional (quantity * mark price(base asset)) must be more than the equivalent of 10,000 USDT and less than the equivalent of 1,000,000 USDT" + }, + { + "key": "duration", + "value": "", + "description": "Duration for TWAP orders in seconds. [300, 86400];Less than 5min => defaults to 5 min; Greater than 24h => defaults to 24h" + }, + { + "key": "clientAlgoId", + "value": "", + "description": "A unique id among Algo orders (length should be 32 characters), If it is not sent, we will give default value", + "disabled": true + }, + { + "key": "reduceOnly", + "value": "", + "description": "`true` or `false`. Default `false`; Cannot be sent in Hedge Mode; Cannot be sent when you open a position", + "disabled": true + }, + { + "key": "limitPrice", + "value": "", + "description": "Limit price of the order; If it is not sent, will place order by market price by default", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Send in a Twap new order. Only support on USDⓈ-M Contracts.\n\nWeight(UID): 3000" + }, + "response": [] + }, + { + "name": "Cancel Algo Order (TRADE)", + "request": { + "method": "DELETE", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/algo/futures/order?algoId=14511×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "algo", "futures", "order"], + "query": [ + { + "key": "algoId", + "value": "14511" + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Cancel an active order.\n\nWeight(IP): 1" + }, + "response": [] + }, + { + "name": "Query Current Algo Open Orders (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/algo/futures/openOrders?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "algo", "futures", "openOrders"], + "query": [ + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Weight(IP): 1" + }, + "response": [] + }, + { + "name": "Query Historical Algo Orders (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/algo/futures/historicalOrders?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "algo", "futures", "historicalOrders"], + "query": [ + { + "key": "symbol", + "value": "", + "description": "Trading symbol eg. BTCUSDT", + "disabled": true + }, + { + "key": "side", + "value": "", + "description": "BUY or SELL", + "disabled": true + }, + { + "key": "startTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "endTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "page", + "value": "", + "description": "Default is 1", + "disabled": true + }, + { + "key": "pageSize", + "value": "", + "description": "MIN 1, MAX 100; Default 100", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Weight(IP): 1" + }, + "response": [] + }, + { + "name": "Query Sub Orders (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/algo/futures/subOrders?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "algo", "futures", "subOrders"], + "query": [ + { + "key": "algoId", + "value": "13723", + "disabled": true + }, + { + "key": "page", + "value": "", + "description": "Default is 1", + "disabled": true + }, + { + "key": "pageSize", + "value": "", + "description": "MIN 1, MAX 100; Default 100", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Get respective sub orders for a specified algoId\n\nWeight(IP): 1" + }, + "response": [] + } + ] + }, + { + "name": "Gift Card", + "item": [ + { + "name": "Create a Binance Code (USER_DATA)", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/giftcard/createCode?token=&amount=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "giftcard", "createCode"], + "query": [ + { + "key": "token", + "value": "", + "description": "The coin type contained in the Binance Code" + }, + { + "key": "amount", + "value": "", + "description": "The amount of the coin" + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "This API is for creating a Binance Code. To get started with, please make sure:\n\n- You have a Binance account\n- You have passed kyc\n- You have a sufficient balance in your Binance funding wallet\n- You need Enable Withdrawals for the API Key which requests this endpoint.\n\nDaily creation volume: 2 BTC / 24H Daily creation times: 200 Codes / 24H\n\nWeight(IP): 1" + }, + "response": [] + }, + { + "name": "Redeem a Binance Code (USER_DATA)", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/giftcard/redeemCode?code=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "giftcard", "redeemCode"], + "query": [ + { + "key": "code", + "value": "", + "description": "Binance Code" + }, + { + "key": "externalUid", + "value": "", + "description": "Each external unique ID represents a unique user on the partner platform. The function helps you to identify the redemption behavior of different users, such as redemption frequency and amount. It also helps risk and limit control of a single account, such as daily limit on redemption volume, frequency, and incorrect number of entries. This will also prevent a single user account reach the partner's daily redemption limits. We strongly recommend you to use this feature and transfer us the User ID of your users if you have different users redeeming Binance codes on your platform. To protect user data privacy, you may choose to transfer the user id in any desired format (max. 400 characters).", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "This API is for redeeming the Binance Code. Once redeemed, the coins will be deposited in your funding wallet.\n\nPlease note that if you enter the wrong code 5 times within 24 hours, you will no longer be able to redeem any Binance Code that day.\n\nWeight(IP): 1" + }, + "response": [] + }, + { + "name": "Buy a Binance Code (TRADE)", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/giftcard/buyCode?baseToken=&faceToken=&baseTokenAmount×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "giftcard", "buyCode"], + "query": [ + { + "key": "baseToken", + "value": "", + "description": "The token you want to pay, example: BUSD" + }, + { + "key": "faceToken", + "value": "", + "description": "The token you want to buy, example: BNB. If faceToken = baseToken, it's the same as createCode endpoint." + }, + { + "key": "baseTokenAmount", + "value": null, + "description": "The base token asset quantity, example : 1.002" + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "This API is for redeeming the Binance Code. Once redeemed, the coins will be deposited in your funding wallet.\n\nPlease note that if you enter the wrong code 5 times within 24 hours, you will no longer be able to redeem any Binance Code that day.\n\nWeight(IP): 1" + }, + "response": [] + }, + { + "name": "Verify a Binance Code (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/giftcard/verify?referenceNo=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "giftcard", "verify"], + "query": [ + { + "key": "referenceNo", + "value": "", + "description": "reference number" + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "This API is for verifying whether the Binance Code is valid or not by entering Binance Code or reference number.\n\nPlease note that if you enter the wrong binance code 5 times within an hour, you will no longer be able to verify any binance code for that hour.\n\nWeight(IP): 1" + }, + "response": [] + }, + { + "name": "Fetch Token Limit (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/giftcard/buyCode/token-limit?baseToken=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "giftcard", "buyCode", "token-limit"], + "query": [ + { + "key": "baseToken", + "value": "", + "description": "The token you want to pay, example: BUSD" + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "This API is for verifying whether the Binance Code is valid or not by entering Binance Code or reference number.\n\nPlease note that if you enter the wrong binance code 5 times within an hour, you will no longer be able to verify any binance code for that hour.\n\nWeight(IP): 1" + }, + "response": [] + }, + { + "name": "Fetch RSA Public Key (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/giftcard/cryptography/rsa-public-key?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": [ + "sapi", + "v1", + "giftcard", + "cryptography", + "rsa-public-key" + ], + "query": [ + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "This API is for fetching the RSA Public Key.\nThis RSA Public key will be used to encrypt the card code.\nPlease note that the RSA Public key fetched is valid only for the current day.\n\nWeight(IP): 1" + }, + "response": [] + } + ], + "description": "Gift Card Endpoints" + }, + { + "name": "Margin", + "item": [ + { + "name": "Cross Margin Account Transfer (MARGIN)", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/margin/transfer?asset=BTC&amount=1.01&type=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "margin", "transfer"], + "query": [ + { + "key": "asset", + "value": "BTC" + }, + { + "key": "amount", + "value": "1.01" + }, + { + "key": "type", + "value": "", + "description": "* `1` - transfer from main account to margin account\n* `2` - transfer from margin account to main account" + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Execute transfer between spot account and cross margin account.\n\nWeight(IP): 600" + }, + "response": [] + }, + { + "name": "Get Cross Margin Transfer History (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/margin/transfer?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "margin", "transfer"], + "query": [ + { + "key": "asset", + "value": "BNB", + "disabled": true + }, + { + "key": "type", + "value": "", + "description": "Transfer Type", + "disabled": true + }, + { + "key": "startTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "endTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "current", + "value": "1", + "description": "Current querying page. Start from 1. Default:1", + "disabled": true + }, + { + "key": "size", + "value": "100", + "description": "Default:10 Max:100", + "disabled": true + }, + { + "key": "archived", + "value": "", + "description": "Default: false. Set to true for archived data from 6 months ago", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "- Response in descending order\n- Returns data for last 7 days by default\n- Set `archived` to `true` to query data from 6 months ago\n\nWeight(IP): 1" + }, + "response": [] + }, + { + "name": "Margin Account Borrow (MARGIN)", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/margin/loan?asset=BTC&amount=1.01×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "margin", "loan"], + "query": [ + { + "key": "asset", + "value": "BTC" + }, + { + "key": "isIsolated", + "value": "", + "description": "* `TRUE` - For isolated margin\n* `FALSE` - Default, not for isolated margin", + "disabled": true + }, + { + "key": "symbol", + "value": "BNBUSDT", + "description": "Trading symbol, e.g. BNBUSDT", + "disabled": true + }, + { + "key": "amount", + "value": "1.01" + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Apply for a loan.\n\n- If \"isIsolated\" = \"TRUE\", \"symbol\" must be sent\n- \"isIsolated\" = \"FALSE\" for crossed margin loan\n\nWeight(UID): 3000" + }, + "response": [] + }, + { + "name": "Query Loan Record (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/margin/loan?asset=BTC×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "margin", "loan"], + "query": [ + { + "key": "asset", + "value": "BTC" + }, + { + "key": "isolatedSymbol", + "value": "", + "description": "Isolated symbol", + "disabled": true + }, + { + "key": "txId", + "value": "123456789", + "description": "the tranId in `POST /sapi/v1/margin/loan`", + "disabled": true + }, + { + "key": "startTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "endTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "current", + "value": "1", + "description": "Current querying page. Start from 1. Default:1", + "disabled": true + }, + { + "key": "size", + "value": "100", + "description": "Default:10 Max:100", + "disabled": true + }, + { + "key": "archived", + "value": "", + "description": "Default: false. Set to true for archived data from 6 months ago", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "- `txId` or `startTime` must be sent. `txId` takes precedence.\n- Response in descending order\n- If `isolatedSymbol` is not sent, crossed margin data will be returned\n- Set `archived` to `true` to query data from 6 months ago\n\nWeight(IP): 10" + }, + "response": [] + }, + { + "name": "Margin Account Repay (MARGIN)", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/margin/repay?asset=BTC&amount=1.01×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "margin", "repay"], + "query": [ + { + "key": "asset", + "value": "BTC" + }, + { + "key": "isIsolated", + "value": "", + "description": "* `TRUE` - For isolated margin\n* `FALSE` - Default, not for isolated margin", + "disabled": true + }, + { + "key": "symbol", + "value": "BNBUSDT", + "description": "Trading symbol, e.g. BNBUSDT", + "disabled": true + }, + { + "key": "amount", + "value": "1.01" + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Repay loan for margin account.\n\n- If \"isIsolated\" = \"TRUE\", \"symbol\" must be sent\n- \"isIsolated\" = \"FALSE\" for crossed margin repay\n\nWeight(IP): 3000" + }, + "response": [] + }, + { + "name": "Query Repay Record (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/margin/repay?asset=BTC×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "margin", "repay"], + "query": [ + { + "key": "asset", + "value": "BTC" + }, + { + "key": "isolatedSymbol", + "value": "", + "description": "Isolated symbol", + "disabled": true + }, + { + "key": "txId", + "value": "2970933056", + "description": "the tranId in `POST /sapi/v1/margin/repay`", + "disabled": true + }, + { + "key": "startTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "endTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "current", + "value": "1", + "description": "Current querying page. Start from 1. Default:1", + "disabled": true + }, + { + "key": "size", + "value": "100", + "description": "Default:10 Max:100", + "disabled": true + }, + { + "key": "archived", + "value": "", + "description": "Default: false. Set to true for archived data from 6 months ago", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "- `txId` or `startTime` must be sent. `txId` takes precedence.\n- Response in descending order\n- If `isolatedSymbol` is not sent, crossed margin data will be returned\n- Set `archived` to `true` to query data from 6 months ago\n\nWeight(IP): 10" + }, + "response": [] + }, + { + "name": "Query Margin Asset (MARKET_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/margin/asset?asset=BTC", + "host": ["{{url}}"], + "path": ["sapi", "v1", "margin", "asset"], + "query": [ + { + "key": "asset", + "value": "BTC" + } + ] + }, + "description": "Weight(IP): 10" + }, + "response": [] + }, + { + "name": "Query Cross Margin Pair (MARKET_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/margin/pair?symbol=BNBUSDT", + "host": ["{{url}}"], + "path": ["sapi", "v1", "margin", "pair"], + "query": [ + { + "key": "symbol", + "value": "BNBUSDT", + "description": "Trading symbol, e.g. BNBUSDT" + } + ] + }, + "description": "Weight(IP): 10" + }, + "response": [] + }, + { + "name": "Get All Margin Assets (MARKET_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/margin/allAssets", + "host": ["{{url}}"], + "path": ["sapi", "v1", "margin", "allAssets"] + }, + "description": "Weight(IP): 1" + }, + "response": [] + }, + { + "name": "Get All Cross Margin Pairs (MARKET_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/margin/allPairs", + "host": ["{{url}}"], + "path": ["sapi", "v1", "margin", "allPairs"] + }, + "description": "Weight(IP): 1" + }, + "response": [] + }, + { + "name": "Query Margin PriceIndex (MARKET_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/margin/priceIndex?symbol=BNBUSDT", + "host": ["{{url}}"], + "path": ["sapi", "v1", "margin", "priceIndex"], + "query": [ + { + "key": "symbol", + "value": "BNBUSDT", + "description": "Trading symbol, e.g. BNBUSDT" + } + ] + }, + "description": "Weight(IP): 10" + }, + "response": [] + }, + { + "name": "Query Margin Account's Order (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/margin/order?symbol=BNBUSDT×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "margin", "order"], + "query": [ + { + "key": "symbol", + "value": "BNBUSDT", + "description": "Trading symbol, e.g. BNBUSDT" + }, + { + "key": "isIsolated", + "value": "", + "description": "* `TRUE` - For isolated margin\n* `FALSE` - Default, not for isolated margin", + "disabled": true + }, + { + "key": "orderId", + "value": "", + "description": "Order id", + "disabled": true + }, + { + "key": "origClientOrderId", + "value": "", + "description": "Order id from client", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "- Either `orderId` or `origClientOrderId` must be sent.\n- For some historical orders `cummulativeQuoteQty` will be < 0, meaning the data is not available at this time.\n\nWeight(IP): 10" + }, + "response": [] + }, + { + "name": "Margin Account New Order (TRADE)", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/margin/order?symbol=BNBUSDT&side=SELL&type=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "margin", "order"], + "query": [ + { + "key": "symbol", + "value": "BNBUSDT", + "description": "Trading symbol, e.g. BNBUSDT" + }, + { + "key": "isIsolated", + "value": "", + "description": "* `TRUE` - For isolated margin\n* `FALSE` - Default, not for isolated margin", + "disabled": true + }, + { + "key": "side", + "value": "SELL" + }, + { + "key": "type", + "value": "", + "description": "Order type" + }, + { + "key": "quantity", + "value": "", + "disabled": true + }, + { + "key": "quoteOrderQty", + "value": "", + "description": "Quote quantity", + "disabled": true + }, + { + "key": "price", + "value": "", + "description": "Order price", + "disabled": true + }, + { + "key": "stopPrice", + "value": "20.01", + "description": "Used with STOP_LOSS, STOP_LOSS_LIMIT, TAKE_PROFIT, and TAKE_PROFIT_LIMIT orders.", + "disabled": true + }, + { + "key": "newClientOrderId", + "value": "", + "description": "Used to uniquely identify this cancel. Automatically generated by default", + "disabled": true + }, + { + "key": "icebergQty", + "value": "", + "description": "Used with LIMIT, STOP_LOSS_LIMIT, and TAKE_PROFIT_LIMIT to create an iceberg order.", + "disabled": true + }, + { + "key": "newOrderRespType", + "value": "", + "description": "Set the response JSON.", + "disabled": true + }, + { + "key": "sideEffectType", + "value": "", + "description": "Default `NO_SIDE_EFFECT`", + "disabled": true + }, + { + "key": "timeInForce", + "value": "", + "description": "Order time in force", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Post a new order for margin account.\n\nWeight(UID): 6" + }, + "response": [] + }, + { + "name": "Margin Account Cancel Order (TRADE)", + "request": { + "method": "DELETE", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/margin/order?symbol=BNBUSDT×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "margin", "order"], + "query": [ + { + "key": "symbol", + "value": "BNBUSDT", + "description": "Trading symbol, e.g. BNBUSDT" + }, + { + "key": "isIsolated", + "value": "", + "description": "* `TRUE` - For isolated margin\n* `FALSE` - Default, not for isolated margin", + "disabled": true + }, + { + "key": "orderId", + "value": "", + "description": "Order id", + "disabled": true + }, + { + "key": "origClientOrderId", + "value": "", + "description": "Order id from client", + "disabled": true + }, + { + "key": "newClientOrderId", + "value": "", + "description": "Used to uniquely identify this cancel. Automatically generated by default", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Cancel an active order for margin account.\n\nEither `orderId` or `origClientOrderId` must be sent.\n\nWeight(IP): 10" + }, + "response": [] + }, + { + "name": "Get Interest History (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/margin/interestHistory?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "margin", "interestHistory"], + "query": [ + { + "key": "asset", + "value": "BNB", + "disabled": true + }, + { + "key": "isolatedSymbol", + "value": "", + "description": "Isolated symbol", + "disabled": true + }, + { + "key": "startTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "endTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "current", + "value": "1", + "description": "Current querying page. Start from 1. Default:1", + "disabled": true + }, + { + "key": "size", + "value": "100", + "description": "Default:10 Max:100", + "disabled": true + }, + { + "key": "archived", + "value": "", + "description": "Default: false. Set to true for archived data from 6 months ago", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "- Response in descending order\n- If `isolatedSymbol` is not sent, crossed margin data will be returned\n- Set `archived` to `true` to query data from 6 months ago\n- `type` in response has 4 enums:\n - `PERIODIC` interest charged per hour\n - `ON_BORROW` first interest charged on borrow\n - `PERIODIC_CONVERTED` interest charged per hour converted into BNB\n - `ON_BORROW_CONVERTED` first interest charged on borrow converted into BNB\n\nWeight(IP): 1" + }, + "response": [] + }, + { + "name": "Get Force Liquidation Record (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/margin/forceLiquidationRec?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "margin", "forceLiquidationRec"], + "query": [ + { + "key": "startTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "endTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "isolatedSymbol", + "value": "", + "description": "Isolated symbol", + "disabled": true + }, + { + "key": "current", + "value": "1", + "description": "Current querying page. Start from 1. Default:1", + "disabled": true + }, + { + "key": "size", + "value": "100", + "description": "Default:10 Max:100", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "- Response in descending order\n\nWeight(IP): 1" + }, + "response": [] + }, + { + "name": "Query Cross Margin Account Details (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/margin/account?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "margin", "account"], + "query": [ + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Weight(IP): 10" + }, + "response": [] + }, + { + "name": "Query Margin Account's Open Orders (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/margin/openOrders?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "margin", "openOrders"], + "query": [ + { + "key": "symbol", + "value": "BNBUSDT", + "description": "Trading symbol, e.g. BNBUSDT", + "disabled": true + }, + { + "key": "isIsolated", + "value": "", + "description": "* `TRUE` - For isolated margin\n* `FALSE` - Default, not for isolated margin", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "- If the `symbol` is not sent, orders for all symbols will be returned in an array.\n- When all symbols are returned, the number of requests counted against the rate limiter is equal to the number of symbols currently trading on the exchange\n- If isIsolated =\"TRUE\", symbol must be sent.\n\nWeight(IP): 10" + }, + "response": [] + }, + { + "name": "Margin Account Cancel all Open Orders on a Symbol (TRADE)", + "request": { + "method": "DELETE", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/margin/openOrders?symbol=BNBUSDT×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "margin", "openOrders"], + "query": [ + { + "key": "symbol", + "value": "BNBUSDT", + "description": "Trading symbol, e.g. BNBUSDT" + }, + { + "key": "isIsolated", + "value": "", + "description": "* `TRUE` - For isolated margin\n* `FALSE` - Default, not for isolated margin", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "- Cancels all active orders on a symbol for margin account.\n- This includes OCO orders.\n\nWeight(IP): 1\n" + }, + "response": [] + }, + { + "name": "Query Margin Account's All Orders (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/margin/allOrders?symbol=BNBUSDT×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "margin", "allOrders"], + "query": [ + { + "key": "symbol", + "value": "BNBUSDT", + "description": "Trading symbol, e.g. BNBUSDT" + }, + { + "key": "isIsolated", + "value": "", + "description": "* `TRUE` - For isolated margin\n* `FALSE` - Default, not for isolated margin", + "disabled": true + }, + { + "key": "orderId", + "value": "", + "description": "Order id", + "disabled": true + }, + { + "key": "startTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "endTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "limit", + "value": "500", + "description": "Default 500; max 1000.", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "- If `orderId` is set, it will get orders >= that orderId. Otherwise most recent orders are returned.\n- For some historical orders `cummulativeQuoteQty` will be < 0, meaning the data is not available at this time.\n\nWeight(IP): 200\n\nRequest Limit: 60 times/min per IP" + }, + "response": [] + }, + { + "name": "Margin Account New OCO (TRADE)", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/margin/order/oco?symbol=BNBUSDT&side=SELL&quantity=&price=&stopPrice=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "margin", "order", "oco"], + "query": [ + { + "key": "symbol", + "value": "BNBUSDT", + "description": "Trading symbol, e.g. BNBUSDT" + }, + { + "key": "isIsolated", + "value": "", + "description": "* `TRUE` - For isolated margin\n* `FALSE` - Default, not for isolated margin", + "disabled": true + }, + { + "key": "listClientOrderId", + "value": "", + "description": "A unique Id for the entire orderList", + "disabled": true + }, + { + "key": "side", + "value": "SELL" + }, + { + "key": "quantity", + "value": "" + }, + { + "key": "limitClientOrderId", + "value": "", + "description": "A unique Id for the limit order", + "disabled": true + }, + { + "key": "price", + "value": "", + "description": "Order price" + }, + { + "key": "limitIcebergQty", + "value": "", + "disabled": true + }, + { + "key": "stopClientOrderId", + "value": "", + "description": "A unique Id for the stop loss/stop loss limit leg", + "disabled": true + }, + { + "key": "stopPrice", + "value": "" + }, + { + "key": "stopLimitPrice", + "value": "", + "description": "If provided, stopLimitTimeInForce is required.", + "disabled": true + }, + { + "key": "stopIcebergQty", + "value": "", + "disabled": true + }, + { + "key": "stopLimitTimeInForce", + "value": "", + "disabled": true + }, + { + "key": "newOrderRespType", + "value": "", + "description": "Set the response JSON.", + "disabled": true + }, + { + "key": "sideEffectType", + "value": "", + "description": "Default `NO_SIDE_EFFECT`", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Send in a new OCO for a margin account\n\n- Price Restrictions:\n - SELL: Limit Price > Last Price > Stop Price\n - BUY: Limit Price < Last Price < Stop Price\n- Quantity Restrictions:\n - Both legs must have the same quantity\n - ICEBERG quantities however do not have to be the same.\n- Order Rate Limit\n - OCO counts as 2 orders against the order rate limit.\n\nWeight(UID): 6" + }, + "response": [] + }, + { + "name": "Query Margin Account's OCO (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/margin/orderList?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "margin", "orderList"], + "query": [ + { + "key": "isIsolated", + "value": "", + "description": "* `TRUE` - For isolated margin\n* `FALSE` - Default, not for isolated margin", + "disabled": true + }, + { + "key": "symbol", + "value": "", + "description": "Mandatory for isolated margin, not supported for cross margin", + "disabled": true + }, + { + "key": "orderListId", + "value": "", + "description": "Order list id", + "disabled": true + }, + { + "key": "origClientOrderId", + "value": "", + "description": "Order id from client", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Retrieves a specific OCO based on provided optional parameters\n\n- Either `orderListId` or `origClientOrderId` must be provided\n\nWeight(IP): 10" + }, + "response": [] + }, + { + "name": "Margin Account Cancel OCO (TRADE)", + "request": { + "method": "DELETE", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/margin/orderList?symbol=BNBUSDT×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "margin", "orderList"], + "query": [ + { + "key": "symbol", + "value": "BNBUSDT", + "description": "Trading symbol, e.g. BNBUSDT" + }, + { + "key": "isIsolated", + "value": "", + "description": "* `TRUE` - For isolated margin\n* `FALSE` - Default, not for isolated margin", + "disabled": true + }, + { + "key": "orderListId", + "value": "", + "description": "Order list id", + "disabled": true + }, + { + "key": "listClientOrderId", + "value": "", + "description": "A unique Id for the entire orderList", + "disabled": true + }, + { + "key": "newClientOrderId", + "value": "", + "description": "Used to uniquely identify this cancel. Automatically generated by default", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Cancel an entire Order List for a margin account\n\n- Canceling an individual leg will cancel the entire OCO\n- Either `orderListId` or `listClientOrderId` must be provided\n\nWeight(UID): 1" + }, + "response": [] + }, + { + "name": "Query Margin Account's all OCO (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/margin/allOrderList?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "margin", "allOrderList"], + "query": [ + { + "key": "isIsolated", + "value": "", + "description": "* `TRUE` - For isolated margin\n* `FALSE` - Default, not for isolated margin", + "disabled": true + }, + { + "key": "symbol", + "value": "", + "description": "Mandatory for isolated margin, not supported for cross margin", + "disabled": true + }, + { + "key": "fromId", + "value": "", + "description": "If supplied, neither `startTime` or `endTime` can be provided", + "disabled": true + }, + { + "key": "startTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "endTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "limit", + "value": "", + "description": "Default Value: 500; Max Value: 1000", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Retrieves all OCO for a specific margin account based on provided optional parameters\n\nWeight(IP): 200" + }, + "response": [] + }, + { + "name": "Query Margin Account's Open OCO (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/margin/openOrderList?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "margin", "openOrderList"], + "query": [ + { + "key": "isIsolated", + "value": "", + "description": "* `TRUE` - For isolated margin\n* `FALSE` - Default, not for isolated margin", + "disabled": true + }, + { + "key": "symbol", + "value": "", + "description": "Mandatory for isolated margin, not supported for cross margin", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Weight(IP): 10" + }, + "response": [] + }, + { + "name": "Query Margin Account's Trade List (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/margin/myTrades?symbol=BNBUSDT×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "margin", "myTrades"], + "query": [ + { + "key": "symbol", + "value": "BNBUSDT", + "description": "Trading symbol, e.g. BNBUSDT" + }, + { + "key": "isIsolated", + "value": "", + "description": "* `TRUE` - For isolated margin\n* `FALSE` - Default, not for isolated margin", + "disabled": true + }, + { + "key": "startTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "endTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "fromId", + "value": "", + "description": "Trade id to fetch from. Default gets most recent trades.", + "disabled": true + }, + { + "key": "limit", + "value": "500", + "description": "Default 500; max 1000.", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "- If `fromId` is set, it will get orders >= that `fromId`. Otherwise most recent trades are returned.\n\nWeight(IP): 10" + }, + "response": [] + }, + { + "name": "Query Max Borrow (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/margin/maxBorrowable?asset=BTC×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "margin", "maxBorrowable"], + "query": [ + { + "key": "asset", + "value": "BTC" + }, + { + "key": "isolatedSymbol", + "value": "", + "description": "Isolated symbol", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "- If `isolatedSymbol` is not sent, crossed margin data will be sent.\n- `borrowLimit` is also available from https://www.binance.com/en/margin-fee\n\nWeight(IP): 50" + }, + "response": [] + }, + { + "name": "Query Max Transfer-Out Amount (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/margin/maxTransferable?asset=BTC×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "margin", "maxTransferable"], + "query": [ + { + "key": "asset", + "value": "BTC" + }, + { + "key": "isolatedSymbol", + "value": "", + "description": "Isolated symbol", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "- If `isolatedSymbol` is not sent, crossed margin data will be sent.\n\nWeight(IP): 50" + }, + "response": [] + }, + { + "name": "Get Isolated Margin Transfer History (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/margin/isolated/transfer?symbol=BNBUSDT×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "margin", "isolated", "transfer"], + "query": [ + { + "key": "asset", + "value": "BNB", + "disabled": true + }, + { + "key": "symbol", + "value": "BNBUSDT", + "description": "Trading symbol, e.g. BNBUSDT" + }, + { + "key": "transFrom", + "value": "SPOT", + "disabled": true + }, + { + "key": "transTo", + "value": "ISOLATED_MARGIN", + "disabled": true + }, + { + "key": "startTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "endTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "current", + "value": "1", + "description": "Current querying page. Start from 1. Default:1", + "disabled": true + }, + { + "key": "size", + "value": "100", + "description": "Default:10 Max:100", + "disabled": true + }, + { + "key": "archived", + "value": "", + "description": "Default: false. Set to true for archived data from 6 months ago", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Weight(IP): 1" + }, + "response": [] + }, + { + "name": "Get Summary of Margin account (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/margin/tradeCoeff?email=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "margin", "tradeCoeff"], + "query": [ + { + "key": "email", + "value": "" + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "- If `isolatedSymbol` is not sent, crossed margin data will be sent.\n\nWeight(IP): 50" + }, + "response": [] + }, + { + "name": "Isolated Margin Account Transfer (MARGIN)", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/margin/isolated/transfer?asset=BTC&symbol=BNBUSDT&transFrom=SPOT&transTo=ISOLATED_MARGIN&amount=1.01×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "margin", "isolated", "transfer"], + "query": [ + { + "key": "asset", + "value": "BTC" + }, + { + "key": "symbol", + "value": "BNBUSDT", + "description": "Trading symbol, e.g. BNBUSDT" + }, + { + "key": "transFrom", + "value": "SPOT" + }, + { + "key": "transTo", + "value": "ISOLATED_MARGIN" + }, + { + "key": "amount", + "value": "1.01" + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Weight(UID): 600" + }, + "response": [] + }, + { + "name": "Query Isolated Margin Account Info (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/margin/isolated/account?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "margin", "isolated", "account"], + "query": [ + { + "key": "symbols", + "value": "BTCUSDT,BNBUSDT,ADAUSDT", + "description": "Max 5 symbols can be sent; separated by ','", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "- If \"symbols\" is not sent, all isolated assets will be returned.\n- If \"symbols\" is sent, only the isolated assets of the sent symbols will be returned.\n\nWeight(IP): 10" + }, + "response": [] + }, + { + "name": "Disable Isolated Margin Account (TRADE)", + "request": { + "method": "DELETE", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/margin/isolated/account?symbol=BNBUSDT×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "margin", "isolated", "account"], + "query": [ + { + "key": "symbol", + "value": "BNBUSDT", + "description": "Trading symbol, e.g. BNBUSDT" + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Disable isolated margin account for a specific symbol. Each trading pair can only be deactivated once every 24 hours .\n\nWeight(UID): 300" + }, + "response": [] + }, + { + "name": "Enable Isolated Margin Account (TRADE)", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/margin/isolated/account?symbol=BNBUSDT×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "margin", "isolated", "account"], + "query": [ + { + "key": "symbol", + "value": "BNBUSDT", + "description": "Trading symbol, e.g. BNBUSDT" + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Enable isolated margin account for a specific symbol.\n\nWeight(UID): 300" + }, + "response": [] + }, + { + "name": "Query Enabled Isolated Margin Account Limit (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/margin/isolated/accountLimit?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "margin", "isolated", "accountLimit"], + "query": [ + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Query enabled isolated margin account limit.\n\nWeight(IP): 1" + }, + "response": [] + }, + { + "name": "Query Isolated Margin Symbol (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/margin/isolated/pair?symbol=BNBUSDT×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "margin", "isolated", "pair"], + "query": [ + { + "key": "symbol", + "value": "BNBUSDT", + "description": "Trading symbol, e.g. BNBUSDT" + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Weight(IP): 10" + }, + "response": [] + }, + { + "name": "Get All Isolated Margin Symbol (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/margin/isolated/allPairs?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "margin", "isolated", "allPairs"], + "query": [ + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Weight(IP): 10" + }, + "response": [] + }, + { + "name": "Toggle BNB Burn On Spot Trade And Margin Interest (USER_DATA)", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/bnbBurn?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "bnbBurn"], + "query": [ + { + "key": "spotBNBBurn", + "value": "true", + "description": "Determines whether to use BNB to pay for trading fees on SPOT", + "disabled": true + }, + { + "key": "interestBNBBurn", + "value": "false", + "description": "Determines whether to use BNB to pay for margin loan's interest", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "- \"spotBNBBurn\" and \"interestBNBBurn\" should be sent at least one.\n\nWeight(IP): 1" + }, + "response": [] + }, + { + "name": "Get BNB Burn Status (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/bnbBurn?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "bnbBurn"], + "query": [ + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Weight(IP): 1" + }, + "response": [] + }, + { + "name": "Query Margin Interest Rate History (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/margin/interestRateHistory?asset=BTC×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "margin", "interestRateHistory"], + "query": [ + { + "key": "asset", + "value": "BTC" + }, + { + "key": "vipLevel", + "value": "", + "description": "Defaults to user's vip level", + "disabled": true + }, + { + "key": "startTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "endTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "The max interval between startTime and endTime is 30 days.\n\nWeight(IP): 1" + }, + "response": [] + }, + { + "name": "Query Cross Margin Fee Data (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/margin/crossMarginData?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "margin", "crossMarginData"], + "query": [ + { + "key": "vipLevel", + "value": "", + "description": "Defaults to user's vip level", + "disabled": true + }, + { + "key": "coin", + "value": "BNB", + "description": "Coin name", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Get cross margin fee data collection with any vip level or user's current specific data as https://www.binance.com/en/margin-fee\n\nWeight(IP): 1 when coin is specified; 5 when the coin parameter is omitted" + }, + "response": [] + }, + { + "name": "Query Isolated Margin Fee Data (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/margin/isolatedMarginData?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "margin", "isolatedMarginData"], + "query": [ + { + "key": "vipLevel", + "value": "", + "description": "Defaults to user's vip level", + "disabled": true + }, + { + "key": "symbol", + "value": "BNBUSDT", + "description": "Trading symbol, e.g. BNBUSDT", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Get isolated margin fee data collection with any vip level or user's current specific data as https://www.binance.com/en/margin-fee\n\nWeight(IP): 1 when a single is specified; 10 when the symbol parameter is omitted" + }, + "response": [] + }, + { + "name": "Query Isolated Margin Tier Data (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/margin/isolatedMarginTier?symbol=BNBUSDT×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "margin", "isolatedMarginTier"], + "query": [ + { + "key": "symbol", + "value": "BNBUSDT", + "description": "Trading symbol, e.g. BNBUSDT" + }, + { + "key": "tier", + "value": "1", + "description": "All margin tier data will be returned if tier is omitted", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Get isolated margin tier data collection with any tier as https://www.binance.com/en/margin-data\n\nWeight(IP): 1" + }, + "response": [] + }, + { + "name": "Query Current Margin Order Count Usage (TRADE)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/margin/rateLimit/order?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "margin", "rateLimit", "order"], + "query": [ + { + "key": "isIsolated", + "value": "", + "description": "* `TRUE` - For isolated margin\n* `FALSE` - Default, not for isolated margin", + "disabled": true + }, + { + "key": "symbol", + "value": "", + "description": "isolated symbol, mandatory for isolated margin", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Displays the user's current margin order count usage for all intervals.\n\nWeight(IP): 20" + }, + "response": [] + }, + { + "name": "Margin Dustlog (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/margin/dribblet?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "margin", "dribblet"], + "query": [ + { + "key": "startTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "endTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Query the historical information of user's margin account small-value asset conversion BNB.\n\nWeight(IP): 1" + }, + "response": [] + } + ], + "description": "Margin Account/Trade" + }, + { + "name": "Market", + "item": [ + { + "name": "Test Connectivity", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + } + ], + "url": { + "raw": "{{url}}/api/v3/ping", + "host": ["{{url}}"], + "path": ["api", "v3", "ping"] + }, + "description": "Test connectivity to the Rest API.\n\nWeight(IP): 1" + }, + "response": [] + }, + { + "name": "Check Server Time", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + } + ], + "url": { + "raw": "{{url}}/api/v3/time", + "host": ["{{url}}"], + "path": ["api", "v3", "time"] + }, + "description": "Test connectivity to the Rest API and get the current server time.\n\nWeight(IP): 1" + }, + "response": [] + }, + { + "name": "Exchange Information", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + } + ], + "url": { + "raw": "{{url}}/api/v3/exchangeInfo", + "host": ["{{url}}"], + "path": ["api", "v3", "exchangeInfo"], + "query": [ + { + "key": "symbol", + "value": "BNBUSDT", + "description": "Trading symbol, e.g. BNBUSDT", + "disabled": true + }, + { + "key": "symbols", + "value": "[\"BTCUSDT\",\"BNBBTC\"]", + "disabled": true + }, + { + "key": "permissions", + "value": "", + "description": "Display symbols with the permissions matching provided parameter. (eg.SPOT, MARGIN, LEVERAGED)", + "disabled": true + } + ] + }, + "description": "Current exchange trading rules and symbol information\n\n- If any symbol provided in either symbol or symbols do not exist, the endpoint will throw an error.\n\nWeight(IP): 10" + }, + "response": [] + }, + { + "name": "Order Book", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + } + ], + "url": { + "raw": "{{url}}/api/v3/depth?symbol=BNBUSDT", + "host": ["{{url}}"], + "path": ["api", "v3", "depth"], + "query": [ + { + "key": "symbol", + "value": "BNBUSDT", + "description": "Trading symbol, e.g. BNBUSDT" + }, + { + "key": "limit", + "value": "100", + "description": "If limit > 5000, then the response will truncate to 5000", + "disabled": true + } + ] + }, + "description": "| Limit | Weight(IP) |\n|---------------------|-------------|\n| 1-100 | 1 |\n| 101-500 | 5 |\n| 501-1000 | 10 |\n| 1001-5000 | 50 |" + }, + "response": [] + }, + { + "name": "Recent Trades List", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + } + ], + "url": { + "raw": "{{url}}/api/v3/trades?symbol=BNBUSDT", + "host": ["{{url}}"], + "path": ["api", "v3", "trades"], + "query": [ + { + "key": "symbol", + "value": "BNBUSDT", + "description": "Trading symbol, e.g. BNBUSDT" + }, + { + "key": "limit", + "value": "500", + "description": "Default 500; max 1000.", + "disabled": true + } + ] + }, + "description": "Get recent trades.\n\nWeight(IP): 1" + }, + "response": [] + }, + { + "name": "Old Trade Lookup (MARKET_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/api/v3/historicalTrades?symbol=BNBUSDT", + "host": ["{{url}}"], + "path": ["api", "v3", "historicalTrades"], + "query": [ + { + "key": "symbol", + "value": "BNBUSDT", + "description": "Trading symbol, e.g. BNBUSDT" + }, + { + "key": "limit", + "value": "500", + "description": "Default 500; max 1000.", + "disabled": true + }, + { + "key": "fromId", + "value": "", + "description": "Trade id to fetch from. Default gets most recent trades.", + "disabled": true + } + ] + }, + "description": "Get older market trades.\n\nWeight(IP): 5" + }, + "response": [] + }, + { + "name": "Compressed/Aggregate Trades List", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + } + ], + "url": { + "raw": "{{url}}/api/v3/aggTrades?symbol=BNBUSDT", + "host": ["{{url}}"], + "path": ["api", "v3", "aggTrades"], + "query": [ + { + "key": "symbol", + "value": "BNBUSDT", + "description": "Trading symbol, e.g. BNBUSDT" + }, + { + "key": "fromId", + "value": "", + "description": "Trade id to fetch from. Default gets most recent trades.", + "disabled": true + }, + { + "key": "startTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "endTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "limit", + "value": "500", + "description": "Default 500; max 1000.", + "disabled": true + } + ] + }, + "description": "Get compressed, aggregate trades. Trades that fill at the time, from the same order, with the same price will have the quantity aggregated.\n- If `startTime` and `endTime` are sent, time between startTime and endTime must be less than 1 hour.\n- If `fromId`, `startTime`, and `endTime` are not sent, the most recent aggregate trades will be returned.\n\nWeight(IP): 1" + }, + "response": [] + }, + { + "name": "Kline/Candlestick Data", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + } + ], + "url": { + "raw": "{{url}}/api/v3/klines?symbol=BNBUSDT&interval=", + "host": ["{{url}}"], + "path": ["api", "v3", "klines"], + "query": [ + { + "key": "symbol", + "value": "BNBUSDT", + "description": "Trading symbol, e.g. BNBUSDT" + }, + { + "key": "interval", + "value": "", + "description": "kline intervals" + }, + { + "key": "startTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "endTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "limit", + "value": "500", + "description": "Default 500; max 1000.", + "disabled": true + } + ] + }, + "description": "Kline/candlestick bars for a symbol.\nKlines are uniquely identified by their open time.\n\n- If `startTime` and `endTime` are not sent, the most recent klines are returned.\n\nWeight(IP): 1" + }, + "response": [] + }, + { + "name": "UIKlines", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + } + ], + "url": { + "raw": "{{url}}/api/v3/uiKlines?symbol=BNBUSDT&interval=", + "host": ["{{url}}"], + "path": ["api", "v3", "uiKlines"], + "query": [ + { + "key": "symbol", + "value": "BNBUSDT" + }, + { + "key": "interval", + "value": "", + "description": "kline intervals" + }, + { + "key": "startTime", + "value": "", + "disabled": true + }, + { + "key": "endTime", + "value": "", + "disabled": true + }, + { + "key": "limit", + "value": "500", + "description": "Default 500; max 1000.", + "disabled": true + } + ] + }, + "description": "The request is similar to klines having the same parameters and response.\n\nuiKlines return modified kline data, optimized for presentation of candlestick charts." + }, + "response": [] + }, + { + "name": "Current Average Price", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + } + ], + "url": { + "raw": "{{url}}/api/v3/avgPrice?symbol=BNBUSDT", + "host": ["{{url}}"], + "path": ["api", "v3", "avgPrice"], + "query": [ + { + "key": "symbol", + "value": "BNBUSDT", + "description": "Trading symbol, e.g. BNBUSDT" + } + ] + }, + "description": "Current average price for a symbol.\n\nWeight(IP): 1" + }, + "response": [] + }, + { + "name": "24hr Ticker Price Change Statistics", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + } + ], + "url": { + "raw": "{{url}}/api/v3/ticker/24hr", + "host": ["{{url}}"], + "path": ["api", "v3", "ticker", "24hr"], + "query": [ + { + "key": "symbol", + "value": "BNBUSDT", + "description": "Trading symbol, e.g. BNBUSDT", + "disabled": true + }, + { + "key": "symbols", + "value": "", + "disabled": true + }, + { + "key": "type", + "value": "BNBUSDT", + "description": "Supported values: FULL or MINI.\nIf none provided, the default is FULL", + "disabled": true + } + ] + }, + "description": "24 hour rolling window price change statistics. Careful when accessing this with no symbol.\n\n- If the symbol is not sent, tickers for all symbols will be returned in an array.\n\nWeight(IP):\n- `1` for a single symbol;\n- `40` when the symbol parameter is omitted;" + }, + "response": [] + }, + { + "name": "Symbol Price Ticker", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + } + ], + "url": { + "raw": "{{url}}/api/v3/ticker/price", + "host": ["{{url}}"], + "path": ["api", "v3", "ticker", "price"], + "query": [ + { + "key": "symbol", + "value": "BNBUSDT", + "description": "Trading symbol, e.g. BNBUSDT", + "disabled": true + }, + { + "key": "symbols", + "value": "", + "disabled": true + } + ] + }, + "description": "Latest price for a symbol or symbols.\n\n- If the symbol is not sent, prices for all symbols will be returned in an array.\n\nWeight(IP):\n- `1` for a single symbol;\n- `2` when the symbol parameter is omitted;" + }, + "response": [] + }, + { + "name": "Symbol Order Book Ticker", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + } + ], + "url": { + "raw": "{{url}}/api/v3/ticker/bookTicker", + "host": ["{{url}}"], + "path": ["api", "v3", "ticker", "bookTicker"], + "query": [ + { + "key": "symbol", + "value": "BNBUSDT", + "description": "Trading symbol, e.g. BNBUSDT", + "disabled": true + }, + { + "key": "symbols", + "value": "", + "disabled": true + } + ] + }, + "description": "Best price/qty on the order book for a symbol or symbols.\n\n- If the symbol is not sent, bookTickers for all symbols will be returned in an array.\n\nWeight(IP):\n- `1` for a single symbol;\n- `2` when the symbol parameter is omitted;" + }, + "response": [] + }, + { + "name": "Rolling window price change statistics", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + } + ], + "url": { + "raw": "{{url}}/api/v3/ticker", + "host": ["{{url}}"], + "path": ["api", "v3", "ticker"], + "query": [ + { + "key": "symbol", + "value": "BNBUSDT", + "description": "Trading symbol, e.g. BNBUSDT", + "disabled": true + }, + { + "key": "symbols", + "value": "", + "description": "Either symbol or symbols must be provided\nExamples of accepted format for the symbols parameter: [\"BTCUSDT\",\"BNBUSDT\"] or %5B%22BTCUSDT%22,%22BNBUSDT%22%5D.\n\nThe maximum number of symbols allowed in a request is 100.", + "disabled": true + }, + { + "key": "windowSize", + "value": "", + "description": "Defaults to 1d if no parameter provided.\nSupported windowSize values:\n1m,2m....59m for minutes\n1h, 2h....23h - for hours\n1d...7d - for days.\n\nUnits cannot be combined (e.g. 1d2h is not allowed)", + "disabled": true + }, + { + "key": "type", + "value": "", + "description": "Supported values: FULL or MINI.\nIf none provided, the default is FULL", + "disabled": true + } + ] + }, + "description": "The window used to compute statistics is typically slightly wider than requested windowSize.\n\nopenTime for /api/v3/ticker always starts on a minute, while the closeTime is the current time of the request. As such, the effective window might be up to 1 minute wider than requested.\n\nE.g. If the closeTime is 1641287867099 (January 04, 2022 09:17:47:099 UTC) , and the windowSize is 1d. the openTime will be: 1641201420000 (January 3, 2022, 09:17:00 UTC)\n\nWeight(IP): 2 for each requested symbol regardless of windowSize.\n\nThe weight for this request will cap at 100 once the number of symbols in the request is more than 50." + }, + "response": [] + } + ], + "description": "Market Data" + }, + { + "name": "Mining", + "item": [ + { + "name": "Acquiring Algorithm (MARKET_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/mining/pub/algoList", + "host": ["{{url}}"], + "path": ["sapi", "v1", "mining", "pub", "algoList"] + }, + "description": "Weight(IP): 1" + }, + "response": [] + }, + { + "name": "Acquiring CoinName (MARKET_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/mining/pub/coinList", + "host": ["{{url}}"], + "path": ["sapi", "v1", "mining", "pub", "coinList"] + }, + "description": "Weight(IP): 1" + }, + "response": [] + }, + { + "name": "Request for Detail Miner List (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/mining/worker/detail?algo=&userName=&workerName=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "mining", "worker", "detail"], + "query": [ + { + "key": "algo", + "value": "", + "description": "Algorithm(sha256)" + }, + { + "key": "userName", + "value": "", + "description": "Mining Account" + }, + { + "key": "workerName", + "value": "", + "description": "Miner’s name" + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Weight(IP): 5" + }, + "response": [] + }, + { + "name": "Request for Miner List (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/mining/worker/list?algo=&userName=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "mining", "worker", "list"], + "query": [ + { + "key": "algo", + "value": "", + "description": "Algorithm(sha256)" + }, + { + "key": "userName", + "value": "", + "description": "Mining Account" + }, + { + "key": "pageIndex", + "value": "", + "description": "Page number, default is first page, start form 1", + "disabled": true + }, + { + "key": "sort", + "value": "", + "description": "sort sequence(default=0)0 positive sequence, 1 negative sequence", + "disabled": true + }, + { + "key": "sortColumn", + "value": "", + "description": "Sort by( default 1): 1: miner name, 2: real-time computing power, 3: daily average computing power, 4: real-time rejection rate, 5: last submission time", + "disabled": true + }, + { + "key": "workerStatus", + "value": "", + "description": "miners status(default=0)0 all, 1 valid, 2 invalid, 3 failure", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Weight(IP): 5" + }, + "response": [] + }, + { + "name": "Earnings List (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/mining/payment/list?algo=&userName=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "mining", "payment", "list"], + "query": [ + { + "key": "algo", + "value": "", + "description": "Algorithm(sha256)" + }, + { + "key": "userName", + "value": "", + "description": "Mining Account" + }, + { + "key": "coin", + "value": "BNB", + "description": "Coin name", + "disabled": true + }, + { + "key": "startDate", + "value": "", + "description": "Search date, millisecond timestamp, while empty query all", + "disabled": true + }, + { + "key": "endDate", + "value": "", + "description": "Search date, millisecond timestamp, while empty query all", + "disabled": true + }, + { + "key": "pageIndex", + "value": "", + "description": "Page number, default is first page, start form 1", + "disabled": true + }, + { + "key": "pageSize", + "value": "", + "description": "Number of pages, minimum 10, maximum 200", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Weight(IP): 5" + }, + "response": [] + }, + { + "name": "Extra Bonus List (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/mining/payment/other?algo=&userName=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "mining", "payment", "other"], + "query": [ + { + "key": "algo", + "value": "", + "description": "Algorithm(sha256)" + }, + { + "key": "userName", + "value": "", + "description": "Mining Account" + }, + { + "key": "coin", + "value": "BNB", + "description": "Coin name", + "disabled": true + }, + { + "key": "startDate", + "value": "", + "description": "Search date, millisecond timestamp, while empty query all", + "disabled": true + }, + { + "key": "endDate", + "value": "", + "description": "Search date, millisecond timestamp, while empty query all", + "disabled": true + }, + { + "key": "pageIndex", + "value": "", + "description": "Page number, default is first page, start form 1", + "disabled": true + }, + { + "key": "pageSize", + "value": "", + "description": "Number of pages, minimum 10, maximum 200", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Weight(IP): 5" + }, + "response": [] + }, + { + "name": "Hashrate Resale List (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/mining/hash-transfer/config/details/list?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": [ + "sapi", + "v1", + "mining", + "hash-transfer", + "config", + "details", + "list" + ], + "query": [ + { + "key": "pageIndex", + "value": "", + "description": "Page number, default is first page, start form 1", + "disabled": true + }, + { + "key": "pageSize", + "value": "", + "description": "Number of pages, minimum 10, maximum 200", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Weight(IP): 5" + }, + "response": [] + }, + { + "name": "Hashrate Resale Detail (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/mining/hash-transfer/profit/details?configId=&userName=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": [ + "sapi", + "v1", + "mining", + "hash-transfer", + "profit", + "details" + ], + "query": [ + { + "key": "configId", + "value": "", + "description": "Mining ID" + }, + { + "key": "userName", + "value": "", + "description": "Mining Account" + }, + { + "key": "pageIndex", + "value": "", + "description": "Page number, default is first page, start form 1", + "disabled": true + }, + { + "key": "pageSize", + "value": "", + "description": "Number of pages, minimum 10, maximum 200", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Weight(IP): 5" + }, + "response": [] + }, + { + "name": "Hashrate Resale Request (USER_DATA)", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/mining/hash-transfer/config?userName=&algo=&toPoolUser=&hashRate=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "mining", "hash-transfer", "config"], + "query": [ + { + "key": "userName", + "value": "", + "description": "Mining Account" + }, + { + "key": "algo", + "value": "", + "description": "Algorithm(sha256)" + }, + { + "key": "startDate", + "value": "", + "description": "Search date, millisecond timestamp, while empty query all", + "disabled": true + }, + { + "key": "endDate", + "value": "", + "description": "Search date, millisecond timestamp, while empty query all", + "disabled": true + }, + { + "key": "toPoolUser", + "value": "", + "description": "Mining Account" + }, + { + "key": "hashRate", + "value": "", + "description": "Resale hashrate h/s must be transferred (BTC is greater than 500000000000 ETH is greater than 500000)" + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Weight(IP): 5" + }, + "response": [] + }, + { + "name": "Cancel hashrate resale configuration (USER_DATA)", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/mining/hash-transfer/config/cancel?configId=&userName=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": [ + "sapi", + "v1", + "mining", + "hash-transfer", + "config", + "cancel" + ], + "query": [ + { + "key": "configId", + "value": "", + "description": "Mining ID" + }, + { + "key": "userName", + "value": "", + "description": "Mining Account" + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Weight(IP): 5" + }, + "response": [] + }, + { + "name": "Statistic List (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/mining/statistics/user/status?algo=&userName=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "mining", "statistics", "user", "status"], + "query": [ + { + "key": "algo", + "value": "", + "description": "Algorithm(sha256)" + }, + { + "key": "userName", + "value": "", + "description": "Mining Account" + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Weight(IP): 5" + }, + "response": [] + }, + { + "name": "Account List (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/mining/statistics/user/list?algo=&userName=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "mining", "statistics", "user", "list"], + "query": [ + { + "key": "algo", + "value": "", + "description": "Algorithm(sha256)" + }, + { + "key": "userName", + "value": "", + "description": "Mining Account" + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Weight(IP): 5" + }, + "response": [] + }, + { + "name": "Mining Account Earning (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/mining/payment/uid?algo=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "mining", "payment", "uid"], + "query": [ + { + "key": "algo", + "value": "", + "description": "Algorithm(sha256)" + }, + { + "key": "startDate", + "value": "", + "description": "Search date, millisecond timestamp, while empty query all", + "disabled": true + }, + { + "key": "endDate", + "value": "", + "description": "Search date, millisecond timestamp, while empty query all", + "disabled": true + }, + { + "key": "pageIndex", + "value": "", + "description": "Page number, default is first page, start form 1", + "disabled": true + }, + { + "key": "pageSize", + "value": "", + "description": "Number of pages, minimum 10, maximum 200", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Weight(IP): 5" + }, + "response": [] + } + ], + "description": "Mining Endpoints" + }, + { + "name": "NFT", + "item": [ + { + "name": "Get NFT Transaction History (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/nft/history/transactions?orderType=1×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "nft", "history", "transactions"], + "query": [ + { + "key": "orderType", + "value": "1", + "description": "0: purchase order, 1: sell order, 2: royalty income, 3: primary market order, 4: mint fee" + }, + { + "key": "startTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "endTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "limit", + "value": "50", + "description": "Default 50, Max 50", + "disabled": true + }, + { + "key": "page", + "value": "1", + "description": "Default 1", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "- The max interval between startTime and endTime is 90 days.\n- If startTime and endTime are not sent, the recent 7 days' data will be returned.\n\nWeight(UID): 3000" + }, + "response": [] + }, + { + "name": "Get NFT Deposit History (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/nft/history/deposit?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "nft", "history", "deposit"], + "query": [ + { + "key": "startTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "endTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "limit", + "value": "50", + "description": "Default 50, Max 50", + "disabled": true + }, + { + "key": "page", + "value": "1", + "description": "Default 1", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "- The max interval between startTime and endTime is 90 days.\n- If startTime and endTime are not sent, the recent 7 days' data will be returned.\n\nWeight(UID): 3000" + }, + "response": [] + }, + { + "name": "Get NFT Withdraw History (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/nft/history/withdraw?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "nft", "history", "withdraw"], + "query": [ + { + "key": "startTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "endTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "limit", + "value": "50", + "description": "Default 50, Max 50", + "disabled": true + }, + { + "key": "page", + "value": "1", + "description": "Default 1", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "- The max interval between startTime and endTime is 90 days.\n- If startTime and endTime are not sent, the recent 7 days' data will be returned.\n\nWeight(UID): 3000" + }, + "response": [] + }, + { + "name": "Get NFT Asset (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/nft/user/getAsset?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "nft", "user", "getAsset"], + "query": [ + { + "key": "limit", + "value": "50", + "description": "Default 50, Max 50", + "disabled": true + }, + { + "key": "page", + "value": "1", + "description": "Default 1", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Weight(UID): 3000" + }, + "response": [] + } + ], + "description": "NFT Endpoints" + }, + { + "name": "Pay", + "item": [ + { + "name": "Get Pay Trade History (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/pay/transactions?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "pay", "transactions"], + "query": [ + { + "key": "startTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "endTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "limit", + "value": "100", + "description": "default 100, max 100", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "- If startTimestamp and endTimestamp are not sent, the recent 90 days' data will be returned.\n- The max interval between startTimestamp and endTimestamp is 90 days.\n- Support for querying orders within the last 18 months.\n\nWeight(UID): 3000" + }, + "response": [] + } + ], + "description": "Pay Endpoints" + }, + { + "name": "Portfolio Margin", + "item": [ + { + "name": "Get Portfolio Margin Account Info (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/portfolio/account?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "portfolio", "account"], + "query": [ + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Weight(IP): 1" + }, + "response": [] + }, + { + "name": "Portfolio Margin Collateral Rate (MARKET_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/portfolio/collateralRate", + "host": ["{{url}}"], + "path": ["sapi", "v1", "portfolio", "collateralRate"] + }, + "description": "Portfolio Margin Collateral Rate.\n\nWeight(IP): 50" + }, + "response": [] + }, + { + "name": "Query Portfolio Margin Bankruptcy Loan Amount (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/portfolio/pmLoan?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "portfolio", "pmLoan"], + "query": [ + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Query Portfolio Margin Bankruptcy Loan Amount.\n\nWeight(UID): 500" + }, + "response": [] + }, + { + "name": "Portfolio Margin Bankruptcy Loan Repay (USER_DATA)", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/portfolio/repay?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "portfolio", "repay"], + "query": [ + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Repay Portfolio Margin Bankruptcy Loan.\n\nWeight(UID): 3000" + }, + "response": [] + } + ], + "description": "The Binance Portfolio Margin Program is a cross-asset margin program supporting consolidated margin balance across trading products with over 200+ effective crypto collaterals. It is designed for professional traders, market makers, and institutional users looking to actively trade & hedge cross-asset and optimize risk-management in a consolidated setup." + }, + { + "name": "Rebate", + "item": [ + { + "name": "Get Spot Rebate History Records (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/rebate/taxQuery?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "rebate", "taxQuery"], + "query": [ + { + "key": "startTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "endTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "page", + "value": "1", + "description": "default 1", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "- The max interval between startTime and endTime is 90 days.\n- If startTime and endTime are not sent, the recent 7 days' data will be returned.\n- The earliest startTime is supported on June 10, 2020\n\nWeight(UID): 3000" + }, + "response": [] + } + ], + "description": "Rebate Endpoints" + }, + { + "name": "Savings", + "item": [ + { + "name": "Get Flexible Product List (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/lending/daily/product/list?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "lending", "daily", "product", "list"], + "query": [ + { + "key": "status", + "value": "", + "description": "Default `ALL`", + "disabled": true + }, + { + "key": "featured", + "value": "", + "description": "Default `ALL`", + "disabled": true + }, + { + "key": "current", + "value": "1", + "description": "Current querying page. Start from 1. Default:1", + "disabled": true + }, + { + "key": "size", + "value": "100", + "description": "Default:10 Max:100", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Weight(IP): 1" + }, + "response": [] + }, + { + "name": "Get Left Daily Purchase Quota of Flexible Product (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/lending/daily/userLeftQuota?productId=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "lending", "daily", "userLeftQuota"], + "query": [ + { + "key": "productId", + "value": "" + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Weight(IP): 1" + }, + "response": [] + }, + { + "name": "Purchase Flexible Product (USER_DATA)", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/lending/daily/purchase?productId=&amount=1.01×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "lending", "daily", "purchase"], + "query": [ + { + "key": "productId", + "value": "" + }, + { + "key": "amount", + "value": "1.01" + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Weight(IP): 1" + }, + "response": [] + }, + { + "name": "Get Left Daily Redemption Quota of Flexible Product (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/lending/daily/userRedemptionQuota?productId=&type=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "lending", "daily", "userRedemptionQuota"], + "query": [ + { + "key": "productId", + "value": "" + }, + { + "key": "type", + "value": "", + "description": "\"FAST\", \"NORMAL\"" + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Weight(IP): 1" + }, + "response": [] + }, + { + "name": "Redeem Flexible Product (USER_DATA)", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/lending/daily/redeem?productId=&amount=1.01&type=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "lending", "daily", "redeem"], + "query": [ + { + "key": "productId", + "value": "" + }, + { + "key": "amount", + "value": "1.01" + }, + { + "key": "type", + "value": "", + "description": "\"FAST\", \"NORMAL\"" + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Weight(IP): 1" + }, + "response": [] + }, + { + "name": "Get Flexible Product Position (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/lending/daily/token/position?asset=BTC×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "lending", "daily", "token", "position"], + "query": [ + { + "key": "asset", + "value": "BTC" + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Weight(IP): 1" + }, + "response": [] + }, + { + "name": "Get Fixed and Activity Project List (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/lending/project/list?type=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "lending", "project", "list"], + "query": [ + { + "key": "asset", + "value": "BNB", + "disabled": true + }, + { + "key": "type", + "value": "", + "description": "\"ACTIVITY\", \"CUSTOMIZED_FIXED\"" + }, + { + "key": "status", + "value": "", + "description": "Default `ALL`", + "disabled": true + }, + { + "key": "isSortAsc", + "value": "", + "description": "default \"true\"", + "disabled": true + }, + { + "key": "sortBy", + "value": "", + "description": "Default `START_TIME`", + "disabled": true + }, + { + "key": "current", + "value": "1", + "description": "Current querying page. Start from 1. Default:1", + "disabled": true + }, + { + "key": "size", + "value": "100", + "description": "Default:10 Max:100", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Weight(IP): 1" + }, + "response": [] + }, + { + "name": "Purchase Fixed/Activity Project (USER_DATA)", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/lending/customizedFixed/purchase?projectId=&lot=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "lending", "customizedFixed", "purchase"], + "query": [ + { + "key": "projectId", + "value": "" + }, + { + "key": "lot", + "value": "" + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Weight(IP): 1" + }, + "response": [] + }, + { + "name": "Get Fixed/Activity Project Position (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/lending/project/position/list?asset=BTC×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "lending", "project", "position", "list"], + "query": [ + { + "key": "asset", + "value": "BTC" + }, + { + "key": "projectId", + "value": "", + "disabled": true + }, + { + "key": "status", + "value": "", + "description": "Default `ALL`", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Weight(IP): 1" + }, + "response": [] + }, + { + "name": "Lending Account (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/lending/union/account?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "lending", "union", "account"], + "query": [ + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Weight(IP): 1" + }, + "response": [] + }, + { + "name": "Get Purchase Record (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/lending/union/purchaseRecord?lendingType=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "lending", "union", "purchaseRecord"], + "query": [ + { + "key": "lendingType", + "value": "", + "description": "* `DAILY` - for flexible\n* `ACTIVITY` - for activity\n* `CUSTOMIZED_FIXED` for fixed" + }, + { + "key": "asset", + "value": "BNB", + "disabled": true + }, + { + "key": "startTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "endTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "current", + "value": "1", + "description": "Current querying page. Start from 1. Default:1", + "disabled": true + }, + { + "key": "size", + "value": "100", + "description": "Default:10 Max:100", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "- The time between startTime and endTime cannot be longer than 30 days.\n- If startTime and endTime are both not sent, then the last 30 days' data will be returned.\n\nWeigh(IP): 1" + }, + "response": [] + }, + { + "name": "Get Redemption Record (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/lending/union/redemptionRecord?lendingType=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "lending", "union", "redemptionRecord"], + "query": [ + { + "key": "lendingType", + "value": "", + "description": "* `DAILY` - for flexible\n* `ACTIVITY` - for activity\n* `CUSTOMIZED_FIXED` for fixed" + }, + { + "key": "asset", + "value": "BNB", + "disabled": true + }, + { + "key": "startTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "endTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "current", + "value": "1", + "description": "Current querying page. Start from 1. Default:1", + "disabled": true + }, + { + "key": "size", + "value": "100", + "description": "Default:10 Max:100", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "- The time between startTime and endTime cannot be longer than 30 days.\n- If startTime and endTime are both not sent, then the last 30 days' data will be returned.\n\nWeight(IP): 1" + }, + "response": [] + }, + { + "name": "Get Interest History (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/lending/union/interestHistory?lendingType=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "lending", "union", "interestHistory"], + "query": [ + { + "key": "lendingType", + "value": "", + "description": "* `DAILY` - for flexible\n* `ACTIVITY` - for activity\n* `CUSTOMIZED_FIXED` for fixed" + }, + { + "key": "asset", + "value": "BNB", + "disabled": true + }, + { + "key": "startTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "endTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "current", + "value": "1", + "description": "Current querying page. Start from 1. Default:1", + "disabled": true + }, + { + "key": "size", + "value": "100", + "description": "Default:10 Max:100", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "- The time between startTime and endTime cannot be longer than 30 days.\n- If startTime and endTime are both not sent, then the last 30 days' data will be returned.\n\nWeight(IP): 1" + }, + "response": [] + }, + { + "name": "Change Fixed/Activity Position to Daily Position (USER_DATA)", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/lending/positionChanged?projectId=&lot=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "lending", "positionChanged"], + "query": [ + { + "key": "projectId", + "value": "" + }, + { + "key": "lot", + "value": "" + }, + { + "key": "positionId", + "value": "", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "- PositionId is mandatory parameter for fixed position.\n\nWeight(IP): 1" + }, + "response": [] + } + ], + "description": "Savings Endpoints" + }, + { + "name": "Staking", + "item": [ + { + "name": "Get Staking Product List (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/staking/productList?product=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "staking", "productList"], + "query": [ + { + "key": "product", + "value": "", + "description": "* `STAKING` - for Locked Staking\n* `F_DEFI` - for flexible DeFi Staking\n* `L_DEFI` - for locked DeFi Staking" + }, + { + "key": "asset", + "value": "", + "disabled": true + }, + { + "key": "current", + "value": "", + "description": "Currently querying page. Start from 1. Default:1", + "disabled": true + }, + { + "key": "size", + "value": "", + "description": "Default:10, Max:100", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Get available Staking product list.\n\nWeight(IP): 1" + }, + "response": [] + }, + { + "name": "Purchase Staking Product (USER_DATA)", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/staking/purchase?product=&productId=&amount=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "staking", "purchase"], + "query": [ + { + "key": "product", + "value": "", + "description": "* `STAKING` - for Locked Staking\n* `F_DEFI` - for flexible DeFi Staking\n* `L_DEFI` - for locked DeFi Staking" + }, + { + "key": "productId", + "value": "" + }, + { + "key": "amount", + "value": "" + }, + { + "key": "renewable", + "value": "", + "description": "true or false, default false. Active if product is `STAKING` or `L_DEFI`", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Weight(IP): 1" + }, + "response": [] + }, + { + "name": "Redeem Staking Product (USER_DATA)", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/staking/redeem?product=&productId=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "staking", "redeem"], + "query": [ + { + "key": "product", + "value": "", + "description": "* `STAKING` - for Locked Staking\n* `F_DEFI` - for flexible DeFi Staking\n* `L_DEFI` - for locked DeFi Staking" + }, + { + "key": "positionId", + "value": "", + "description": "Mandatory if product is `STAKING` or `L_DEFI`", + "disabled": true + }, + { + "key": "productId", + "value": "" + }, + { + "key": "amount", + "value": "", + "description": "Mandatory if product is `F_DEFI`", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Redeem Staking product. Locked staking and Locked DeFI staking belong to early redemption, redeeming in advance will result in loss of interest that you have earned.\n\nWeight(IP): 1" + }, + "response": [] + }, + { + "name": "Get Staking Product Position (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/staking/position?product=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "staking", "position"], + "query": [ + { + "key": "product", + "value": "", + "description": "* `STAKING` - for Locked Staking\n* `F_DEFI` - for flexible DeFi Staking\n* `L_DEFI` - for locked DeFi Staking" + }, + { + "key": "productId", + "value": "", + "disabled": true + }, + { + "key": "asset", + "value": "", + "disabled": true + }, + { + "key": "current", + "value": "", + "description": "Currently querying the page. Start from 1. Default:1", + "disabled": true + }, + { + "key": "size", + "value": "", + "description": "Default:10, Max:100", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Weight(IP): 1" + }, + "response": [] + }, + { + "name": "Get Staking History (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/staking/stakingRecord?product=&txnType=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "staking", "stakingRecord"], + "query": [ + { + "key": "product", + "value": "", + "description": "* `STAKING` - for Locked Staking\n* `F_DEFI` - for flexible DeFi Staking\n* `L_DEFI` - for locked DeFi Staking" + }, + { + "key": "txnType", + "value": "", + "description": "`SUBSCRIPTION`, `REDEMPTION`, `INTEREST`" + }, + { + "key": "asset", + "value": "", + "disabled": true + }, + { + "key": "startTime", + "value": "", + "disabled": true + }, + { + "key": "endTime", + "value": "", + "disabled": true + }, + { + "key": "current", + "value": "", + "description": "Currently querying the page. Start from 1. Default:1", + "disabled": true + }, + { + "key": "size", + "value": "", + "description": "Default:10, Max:100", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Weight(IP): 1" + }, + "response": [] + }, + { + "name": "Set Auto Staking (USER_DATA)", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/staking/setAutoStaking?product=&positionId=&renewable=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "staking", "setAutoStaking"], + "query": [ + { + "key": "product", + "value": "", + "description": "* `STAKING` - for Locked Staking\n* `L_DEFI` - for locked DeFi Staking" + }, + { + "key": "positionId", + "value": "" + }, + { + "key": "renewable", + "value": "", + "description": "true or false" + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Set auto staking on Locked Staking or Locked DeFi Staking\n\nWeight(IP): 1" + }, + "response": [] + }, + { + "name": "Get Personal Left Quota of Staking Product (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/staking/personalLeftQuota?product=&productId=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "staking", "personalLeftQuota"], + "query": [ + { + "key": "product", + "value": "", + "description": "* `STAKING` - for Locked Staking\n* `F_DEFI` - for flexible DeFi Staking\n* `L_DEFI` - for locked DeFi Staking" + }, + { + "key": "productId", + "value": "" + }, + { + "key": "recvWindow", + "value": "", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Weight(IP): 1" + }, + "response": [] + } + ] + }, + { + "name": "Sub-Account", + "item": [ + { + "name": "Create a Virtual Sub-account (For Master Account)", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/sub-account/virtualSubAccount?subAccountString=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "sub-account", "virtualSubAccount"], + "query": [ + { + "key": "subAccountString", + "value": "", + "description": "Please input a string. We will create a virtual email using that string for you to register" + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "- This request will generate a virtual sub account under your master account.\n- You need to enable \"trade\" option for the api key which requests this endpoint.\n\nWeight(IP): 1" + }, + "response": [] + }, + { + "name": "Query Sub-account List (For Master Account)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/sub-account/list?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "sub-account", "list"], + "query": [ + { + "key": "email", + "value": "", + "description": "Sub-account email", + "disabled": true + }, + { + "key": "isFreeze", + "value": "", + "disabled": true + }, + { + "key": "page", + "value": "1", + "description": "Default 1", + "disabled": true + }, + { + "key": "limit", + "value": "1", + "description": "Default 1; max 200", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Weight(IP): 1" + }, + "response": [] + }, + { + "name": "Query Sub-account Spot Asset Transfer History (For Master Account)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/sub-account/sub/transfer/history?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": [ + "sapi", + "v1", + "sub-account", + "sub", + "transfer", + "history" + ], + "query": [ + { + "key": "fromEmail", + "value": "", + "description": "Sub-account email", + "disabled": true + }, + { + "key": "toEmail", + "value": "", + "description": "Sub-account email", + "disabled": true + }, + { + "key": "startTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "endTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "page", + "value": "1", + "description": "Default 1", + "disabled": true + }, + { + "key": "limit", + "value": "1", + "description": "Default 1", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "- fromEmail and toEmail cannot be sent at the same time.\n- Return fromEmail equal master account email by default.\n\nWeight(IP): 1" + }, + "response": [] + }, + { + "name": "Query Sub-account Futures Asset Transfer History (For Master Account)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/sub-account/futures/internalTransfer?email=&futuresType=2×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": [ + "sapi", + "v1", + "sub-account", + "futures", + "internalTransfer" + ], + "query": [ + { + "key": "email", + "value": "", + "description": "Sub-account email" + }, + { + "key": "futuresType", + "value": "2", + "description": "1:USDT-margined Futures, 2: Coin-margined Futures" + }, + { + "key": "startTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "endTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "page", + "value": "1", + "description": "Default 1", + "disabled": true + }, + { + "key": "limit", + "value": "", + "description": "Default value: 50, Max value: 500", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Weight(IP): 1" + }, + "response": [] + }, + { + "name": "Sub-account Futures Asset Transfer (For Master Account)", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/sub-account/futures/internalTransfer?fromEmail=&toEmail=&futuresType=2&asset=BTC&amount=1.01×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": [ + "sapi", + "v1", + "sub-account", + "futures", + "internalTransfer" + ], + "query": [ + { + "key": "fromEmail", + "value": "", + "description": "Sender email" + }, + { + "key": "toEmail", + "value": "", + "description": "Recipient email" + }, + { + "key": "futuresType", + "value": "2", + "description": "1:USDT-margined Futures,2: Coin-margined Futures" + }, + { + "key": "asset", + "value": "BTC" + }, + { + "key": "amount", + "value": "1.01" + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "- Master account can transfer max 2000 times a minute\n\nWeight(IP): 1" + }, + "response": [] + }, + { + "name": "Query Sub-account Assets (For Master Account)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v3/sub-account/assets?email=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v3", "sub-account", "assets"], + "query": [ + { + "key": "email", + "value": "", + "description": "Sub-account email" + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Fetch sub-account assets\n\nWeight(IP): 1" + }, + "response": [] + }, + { + "name": "Query Sub-account Spot Assets Summary (For Master Account)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/sub-account/spotSummary?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "sub-account", "spotSummary"], + "query": [ + { + "key": "email", + "value": "", + "description": "Sub-account email", + "disabled": true + }, + { + "key": "page", + "value": "1", + "description": "Default 1", + "disabled": true + }, + { + "key": "size", + "value": "", + "description": "Default:10 Max:20", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Get BTC valued asset summary of subaccounts.\n\nWeight(IP): 1" + }, + "response": [] + }, + { + "name": "Get Sub-account Deposit Address (For Master Account)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/capital/deposit/subAddress?email=&coin=BNB×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "capital", "deposit", "subAddress"], + "query": [ + { + "key": "email", + "value": "", + "description": "Sub-account email" + }, + { + "key": "coin", + "value": "BNB", + "description": "Coin name" + }, + { + "key": "network", + "value": "", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Fetch sub-account deposit address\n\nWeight(IP): 1" + }, + "response": [] + }, + { + "name": "Get Sub-account Deposit History (For Master Account)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/capital/deposit/subHisrec?email=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "capital", "deposit", "subHisrec"], + "query": [ + { + "key": "email", + "value": "", + "description": "Sub-account email" + }, + { + "key": "coin", + "value": "BNB", + "description": "Coin name", + "disabled": true + }, + { + "key": "status", + "value": "", + "description": "0(0:pending,6: credited but cannot withdraw, 1:success)", + "disabled": true + }, + { + "key": "startTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "endTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "limit", + "value": "", + "disabled": true + }, + { + "key": "offset", + "value": "", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Fetch sub-account deposit history\n\nWeight(IP): 1" + }, + "response": [] + }, + { + "name": "Get Sub-account's Status on Margin/Futures (For Master Account)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/sub-account/status?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "sub-account", "status"], + "query": [ + { + "key": "email", + "value": "", + "description": "Sub-account email", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "- If no `email` sent, all sub-accounts' information will be returned.\n\nWeight(IP): 10" + }, + "response": [] + }, + { + "name": "Enable Margin for Sub-account (For Master Account)", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/sub-account/margin/enable?email=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "sub-account", "margin", "enable"], + "query": [ + { + "key": "email", + "value": "", + "description": "Sub-account email" + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Weight(IP): 1" + }, + "response": [] + }, + { + "name": "Get Detail on Sub-account's Margin Account (For Master Account)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/sub-account/margin/account?email=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "sub-account", "margin", "account"], + "query": [ + { + "key": "email", + "value": "", + "description": "Sub-account email" + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Weight(IP): 10" + }, + "response": [] + }, + { + "name": "Get Summary of Sub-account's Margin Account (For Master Account)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/sub-account/margin/accountSummary?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "sub-account", "margin", "accountSummary"], + "query": [ + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Weight(IP): 10" + }, + "response": [] + }, + { + "name": "Enable Futures for Sub-account (For Master Account)", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/sub-account/futures/enable?email=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "sub-account", "futures", "enable"], + "query": [ + { + "key": "email", + "value": "", + "description": "Sub-account email" + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Weight(IP): 1" + }, + "response": [] + }, + { + "name": "Get Detail on Sub-account's Futures Account (For Master Account)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/sub-account/futures/account?email=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "sub-account", "futures", "account"], + "query": [ + { + "key": "email", + "value": "", + "description": "Sub-account email" + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Weight(IP): 10" + }, + "response": [] + }, + { + "name": "Get Summary of Sub-account's Futures Account (For Master Account)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/sub-account/futures/accountSummary?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": [ + "sapi", + "v1", + "sub-account", + "futures", + "accountSummary" + ], + "query": [ + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Weight(IP): 1" + }, + "response": [] + }, + { + "name": "Get Futures Position-Risk of Sub-account (For Master Account)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/sub-account/futures/positionRisk?email=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "sub-account", "futures", "positionRisk"], + "query": [ + { + "key": "email", + "value": "", + "description": "Sub-account email" + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Weight(IP): 10" + }, + "response": [] + }, + { + "name": "Futures Transfer for Sub-account (For Master Account)", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/sub-account/futures/transfer?email=&asset=BTC&amount=1.01&type=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "sub-account", "futures", "transfer"], + "query": [ + { + "key": "email", + "value": "", + "description": "Sub-account email" + }, + { + "key": "asset", + "value": "BTC" + }, + { + "key": "amount", + "value": "1.01" + }, + { + "key": "type", + "value": "", + "description": "* `1` - transfer from subaccount's spot account to its USDT-margined futures account\n* `2` - transfer from subaccount's USDT-margined futures account to its spot account\n* `3` - transfer from subaccount's spot account to its COIN-margined futures account\n* `4` - transfer from subaccount's COIN-margined futures account to its spot account" + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Weight(IP): 1" + }, + "response": [] + }, + { + "name": "Margin Transfer for Sub-account (For Master Account)", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/sub-account/margin/transfer?email=&asset=BTC&amount=1.01&type=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "sub-account", "margin", "transfer"], + "query": [ + { + "key": "email", + "value": "", + "description": "Sub-account email" + }, + { + "key": "asset", + "value": "BTC" + }, + { + "key": "amount", + "value": "1.01" + }, + { + "key": "type", + "value": "", + "description": "* `1` - transfer from subaccount's spot account to margin account\n* `2` - transfer from subaccount's margin account to its spot account" + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Weight(IP): 1" + }, + "response": [] + }, + { + "name": "Transfer to Sub-account of Same Master (For Sub-account)", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/sub-account/transfer/subToSub?toEmail=&asset=BTC&amount=1.01×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "sub-account", "transfer", "subToSub"], + "query": [ + { + "key": "toEmail", + "value": "", + "description": "Recipient email" + }, + { + "key": "asset", + "value": "BTC" + }, + { + "key": "amount", + "value": "1.01" + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Weight(IP): 1" + }, + "response": [] + }, + { + "name": "Transfer to Master (For Sub-account)", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/sub-account/transfer/subToMaster?asset=BTC&amount=1.01×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "sub-account", "transfer", "subToMaster"], + "query": [ + { + "key": "asset", + "value": "BTC" + }, + { + "key": "amount", + "value": "1.01" + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Weight(IP): 1" + }, + "response": [] + }, + { + "name": "Sub-account Transfer History (For Sub-account)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/sub-account/transfer/subUserHistory?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": [ + "sapi", + "v1", + "sub-account", + "transfer", + "subUserHistory" + ], + "query": [ + { + "key": "asset", + "value": "BNB", + "disabled": true + }, + { + "key": "type", + "value": "", + "description": "* `1` - transfer in\n* `2` - transfer out", + "disabled": true + }, + { + "key": "startTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "endTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "limit", + "value": "500", + "description": "Default 500; max 1000.", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "- If `type` is not sent, the records of type 2: transfer out will be returned by default.\n- If `startTime` and `endTime` are not sent, the recent 30-day data will be returned.\n\nWeight(IP): 1" + }, + "response": [] + }, + { + "name": "Query Universal Transfer History (For Master Account)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/sub-account/universalTransfer?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "sub-account", "universalTransfer"], + "query": [ + { + "key": "fromEmail", + "value": "", + "description": "Sub-account email", + "disabled": true + }, + { + "key": "toEmail", + "value": "", + "description": "Sub-account email", + "disabled": true + }, + { + "key": "clientTranId", + "value": "", + "disabled": true + }, + { + "key": "startTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "endTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "page", + "value": "1", + "description": "Default 1", + "disabled": true + }, + { + "key": "limit", + "value": "", + "description": "Default 500, Max 500", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "- `fromEmail` and `toEmail` cannot be sent at the same time.\n- Return `fromEmail` equal master account email by default.\n- The query time period must be less then 30 days.\n- If startTime and endTime not sent, return records of the last 30 days by default.\n\nWeight(IP): 1" + }, + "response": [] + }, + { + "name": "Universal Transfer (For Master Account)", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/sub-account/universalTransfer?fromAccountType=&toAccountType=&asset=BTC&amount=1.01×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "sub-account", "universalTransfer"], + "query": [ + { + "key": "fromEmail", + "value": "", + "description": "Sub-account email", + "disabled": true + }, + { + "key": "toEmail", + "value": "", + "description": "Sub-account email", + "disabled": true + }, + { + "key": "fromAccountType", + "value": "" + }, + { + "key": "toAccountType", + "value": "" + }, + { + "key": "clientTranId", + "value": "", + "disabled": true + }, + { + "key": "symbol", + "value": "", + "description": "Only supported under ISOLATED_MARGIN type", + "disabled": true + }, + { + "key": "asset", + "value": "BTC" + }, + { + "key": "amount", + "value": "1.01" + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "- You need to enable \"internal transfer\" option for the api key which requests this endpoint.\n- Transfer from master account by default if fromEmail is not sent.\n- Transfer to master account by default if toEmail is not sent.\n- Transfer between futures accounts is not supported.\n\nWeight(IP): 1" + }, + "response": [] + }, + { + "name": "Get Detail on Sub-account's Futures Account V2 (For Master Account)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v2/sub-account/futures/account?email=&futuresType=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v2", "sub-account", "futures", "account"], + "query": [ + { + "key": "email", + "value": "", + "description": "Sub-account email" + }, + { + "key": "futuresType", + "value": "", + "description": "* `1` - USDT Margined Futures\n* `2` - COIN Margined Futures" + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Weight(IP): 1" + }, + "response": [] + }, + { + "name": "Get Summary of Sub-account's Futures Account V2 (For Master Account)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v2/sub-account/futures/accountSummary?futuresType=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": [ + "sapi", + "v2", + "sub-account", + "futures", + "accountSummary" + ], + "query": [ + { + "key": "futuresType", + "value": "", + "description": "* `1` - USDT Margined Futures\n* `2` - COIN Margined Futures" + }, + { + "key": "page", + "value": "1", + "description": "Default 1", + "disabled": true + }, + { + "key": "limit", + "value": "", + "description": "Default 10, Max 20", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Weight(IP): 10" + }, + "response": [] + }, + { + "name": "Get Futures Position-Risk of Sub-account V2 (For Master Account)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v2/sub-account/futures/positionRisk?email=&futuresType=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v2", "sub-account", "futures", "positionRisk"], + "query": [ + { + "key": "email", + "value": "", + "description": "Sub-account email" + }, + { + "key": "futuresType", + "value": "", + "description": "* `1` - USDT Margined Futures\n* `2` - COIN Margined Futures" + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Weight(IP): 1" + }, + "response": [] + }, + { + "name": "Enable Leverage Token for Sub-account (For Master Account)", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/sub-account/blvt/enable?email=&enableBlvt=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "sub-account", "blvt", "enable"], + "query": [ + { + "key": "email", + "value": "", + "description": "Sub-account email" + }, + { + "key": "enableBlvt", + "value": "", + "description": "Only true for now" + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Weight(IP): 1" + }, + "response": [] + }, + { + "name": "Deposit assets into the managed sub-account (For Investor Master Account)", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/managed-subaccount/deposit?toEmail=&asset=BTC&amount=1.01×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "managed-subaccount", "deposit"], + "query": [ + { + "key": "toEmail", + "value": "", + "description": "Recipient email" + }, + { + "key": "asset", + "value": "BTC" + }, + { + "key": "amount", + "value": "1.01" + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Weight(IP): 1" + }, + "response": [] + }, + { + "name": "Query managed sub-account asset details (For Investor Master Account)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/managed-subaccount/asset?email=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "managed-subaccount", "asset"], + "query": [ + { + "key": "email", + "value": "", + "description": "Sub-account email" + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Weight(IP): 1" + }, + "response": [] + }, + { + "name": "Withdrawl assets from the managed sub-account (For Investor Master Account)", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/managed-subaccount/withdraw?fromEmail=&asset=BTC&amount=1.01×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "managed-subaccount", "withdraw"], + "query": [ + { + "key": "fromEmail", + "value": "", + "description": "Sender email" + }, + { + "key": "asset", + "value": "BTC" + }, + { + "key": "amount", + "value": "1.01" + }, + { + "key": "transferDate", + "value": "", + "description": "Withdrawals is automatically occur on the transfer date(UTC0). If a date is not selected, the withdrawal occurs right now", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Weight(IP): 1" + }, + "response": [] + }, + { + "name": "Query managed sub-account snapshot (For Investor Master Account)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/managed-subaccount/accountSnapshot?email=testaccount@email.com&type=SPOT×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "managed-subaccount", "accountSnapshot"], + "query": [ + { + "key": "email", + "value": "testaccount@email.com" + }, + { + "key": "type", + "value": "SPOT", + "description": "\"SPOT\", \"MARGIN\"(cross), \"FUTURES\"(UM)" + }, + { + "key": "startTime", + "value": "", + "disabled": true + }, + { + "key": "endTime", + "value": "", + "disabled": true + }, + { + "key": "limit", + "value": "", + "description": "min 7, max 30, default 7", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "- The query time period must be less then 30 days\n- Support query within the last one month only\n- If `startTime` and `endTime` not sent, return records of the last 7 days by default\n\nWeight(IP): 2400" + }, + "response": [] + }, + { + "name": "Enable or Disable IP Restriction for a Sub-account API Key (For Master Account)", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/sub-account/subAccountApi/ipRestriction?email=&subAccountApiKey=&ipRestrict=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": [ + "sapi", + "v1", + "sub-account", + "subAccountApi", + "ipRestriction" + ], + "query": [ + { + "key": "email", + "value": "", + "description": "Sub-account email" + }, + { + "key": "subAccountApiKey", + "value": "" + }, + { + "key": "ipRestrict", + "value": "", + "description": "true or false" + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + }, + { + "key": "thirdParty", + "value": "", + "description": "Third Party", + "disabled": true + } + ] + }, + "description": "Weight(UID): 3000" + }, + "response": [] + }, + { + "name": "Get IP Restriction for a Sub-account API Key (For Master Account)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/sub-account/subAccountApi/ipRestriction?email=&subAccountApiKey=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": [ + "sapi", + "v1", + "sub-account", + "subAccountApi", + "ipRestriction" + ], + "query": [ + { + "key": "email", + "value": "", + "description": "Sub-account email" + }, + { + "key": "subAccountApiKey", + "value": "" + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Weight(UID): 3000" + }, + "response": [] + }, + { + "name": "Add IP List for a Sub-account API Key (For Master Account)", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/sub-account/subAccountApi/ipRestriction/ipList?email=&subAccountApiKey=&ipAddress=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": [ + "sapi", + "v1", + "sub-account", + "subAccountApi", + "ipRestriction", + "ipList" + ], + "query": [ + { + "key": "email", + "value": "", + "description": "Sub-account email" + }, + { + "key": "subAccountApiKey", + "value": "" + }, + { + "key": "ipAddress", + "value": "", + "description": "Can be added in batches, separated by commas" + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + }, + { + "key": "thirdPartyName", + "value": "", + "description": "Third Party Name", + "disabled": true + } + ] + }, + "description": "Before the usage of this endpoint, please ensure `POST /sapi/v1/sub-account/subAccountApi/ipRestriction` was used to enable the IP restriction.\n\nWeight(UID): 3000" + }, + "response": [] + }, + { + "name": "Delete IP List for a Sub-account API Key (For Master Account)", + "request": { + "method": "DELETE", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/sub-account/subAccountApi/ipRestriction/ipList?email=&subAccountApiKey=&ipAddress=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": [ + "sapi", + "v1", + "sub-account", + "subAccountApi", + "ipRestriction", + "ipList" + ], + "query": [ + { + "key": "email", + "value": "", + "description": "Sub-account email" + }, + { + "key": "subAccountApiKey", + "value": "" + }, + { + "key": "ipAddress", + "value": "", + "description": "Can be added in batches, separated by commas" + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + }, + { + "key": "thirdPartyName", + "value": "", + "description": "Third Party Name", + "disabled": true + } + ] + }, + "description": "Weight(UID): 3000" + }, + "response": [] + }, + { + "name": "Query Sub-Account API key Third Party IP whitelist (For Master Account)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/sub-account/apiRestrictions/ipRestriction/thirdPartyList?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": [ + "sapi", + "v1", + "sub-account", + "apiRestrictions", + "ipRestriction", + "thirdPartyList" + ], + "query": [ + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Weight(UID): 3000" + }, + "response": [] + }, + { + "name": "Update IP Restriction for Sub-Account API key (For Master Account)", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v2/sub-account/subAccountApi/ipRestriction?email=&subAccountApiKey=&status=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": [ + "sapi", + "v2", + "sub-account", + "subAccountApi", + "ipRestriction" + ], + "query": [ + { + "key": "email", + "value": "", + "description": "Sub-account email" + }, + { + "key": "subAccountApiKey", + "value": "" + }, + { + "key": "status", + "value": "", + "description": "IP Restriction status. 1 = IP Unrestricted. 2 = Restrict access to trusted IPs only. 3 = Restrict access to users' trusted third party IPs only" + }, + { + "key": "thirdPartyName", + "value": "", + "description": "Insert Name of a Third Party", + "disabled": true + }, + { + "key": "ipAddress", + "value": "", + "description": "Insert static IP in batch, separated by commas.", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Before the usage of this endpoint, please ensure `POST /sapi/v1/sub-account/subAccountApi/ipRestriction` was used to enable the IP restriction.\n\nWeight(UID): 3000" + }, + "response": [] + } + ], + "description": "Sub-account Endpoints" + }, + { + "name": "Trade", + "item": [ + { + "name": "Test New Order (TRADE)", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/api/v3/order/test?symbol=BNBUSDT&side=SELL&type=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["api", "v3", "order", "test"], + "query": [ + { + "key": "symbol", + "value": "BNBUSDT", + "description": "Trading symbol, e.g. BNBUSDT" + }, + { + "key": "side", + "value": "SELL" + }, + { + "key": "type", + "value": "", + "description": "Order type" + }, + { + "key": "timeInForce", + "value": "", + "description": "Order time in force", + "disabled": true + }, + { + "key": "quantity", + "value": "", + "description": "Order quantity", + "disabled": true + }, + { + "key": "quoteOrderQty", + "value": "", + "description": "Quote quantity", + "disabled": true + }, + { + "key": "price", + "value": "", + "description": "Order price", + "disabled": true + }, + { + "key": "newClientOrderId", + "value": "", + "description": "A unique id among open orders. Automatically generated if not sent.", + "disabled": true + }, + { + "key": "strategyId", + "value": "", + "disabled": true + }, + { + "key": "strategyType", + "value": "", + "description": "The value cannot be less than 1000000", + "disabled": true + }, + { + "key": "stopPrice", + "value": "20.01", + "description": "Used with STOP_LOSS, STOP_LOSS_LIMIT, TAKE_PROFIT, and TAKE_PROFIT_LIMIT orders.", + "disabled": true + }, + { + "key": "trailingDelta", + "value": "", + "description": "Used with STOP_LOSS, STOP_LOSS_LIMIT, TAKE_PROFIT, and TAKE_PROFIT_LIMIT orders.", + "disabled": true + }, + { + "key": "icebergQty", + "value": "", + "description": "Used with LIMIT, STOP_LOSS_LIMIT, and TAKE_PROFIT_LIMIT to create an iceberg order.", + "disabled": true + }, + { + "key": "newOrderRespType", + "value": "", + "description": "Set the response JSON. MARKET and LIMIT order types default to FULL, all other orders default to ACK.", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Test new order creation and signature/recvWindow long.\nCreates and validates a new order but does not send it into the matching engine.\n\nWeight(IP): 1" + }, + "response": [] + }, + { + "name": "Query Order (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/api/v3/order?symbol=BNBUSDT×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["api", "v3", "order"], + "query": [ + { + "key": "symbol", + "value": "BNBUSDT", + "description": "Trading symbol, e.g. BNBUSDT" + }, + { + "key": "orderId", + "value": "", + "description": "Order id", + "disabled": true + }, + { + "key": "origClientOrderId", + "value": "", + "description": "Order id from client", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Check an order's status.\n\n- Either `orderId` or `origClientOrderId` must be sent.\n- For some historical orders `cummulativeQuoteQty` will be < 0, meaning the data is not available at this time.\n\nWeight(IP): 2" + }, + "response": [] + }, + { + "name": "Cancel an Existing Order and Send a New Order (TRADE)", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/api/v3/order/cancelReplace?symbol=BNBUSDT&side=SELL&type=&cancelReplaceMode=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["api", "v3", "order", "cancelReplace"], + "query": [ + { + "key": "symbol", + "value": "BNBUSDT", + "description": "Trading symbol, e.g. BNBUSDT" + }, + { + "key": "side", + "value": "SELL" + }, + { + "key": "type", + "value": "", + "description": "Order type" + }, + { + "key": "cancelReplaceMode", + "value": "", + "description": "- `STOP_ON_FAILURE` If the cancel request fails, the new order placement will not be attempted.\n- `ALLOW_FAILURES` If new order placement will be attempted even if cancel request fails." + }, + { + "key": "timeInForce", + "value": "", + "description": "Order time in force", + "disabled": true + }, + { + "key": "quantity", + "value": "", + "description": "Order quantity", + "disabled": true + }, + { + "key": "quoteOrderQty", + "value": "", + "description": "Quote quantity", + "disabled": true + }, + { + "key": "price", + "value": "", + "description": "Order price", + "disabled": true + }, + { + "key": "cancelNewClientOrderId", + "value": "", + "description": "Used to uniquely identify this cancel. Automatically generated by default", + "disabled": true + }, + { + "key": "cancelOrigClientOrderId", + "value": "", + "description": "Either the cancelOrigClientOrderId or cancelOrderId must be provided. If both are provided, cancelOrderId takes precedence.", + "disabled": true + }, + { + "key": "cancelOrderId", + "value": "", + "description": "Either the cancelOrigClientOrderId or cancelOrderId must be provided. If both are provided, cancelOrderId takes precedence.", + "disabled": true + }, + { + "key": "newClientOrderId", + "value": "", + "description": "Used to identify the new order. Automatically generated by default", + "disabled": true + }, + { + "key": "strategyId", + "value": "", + "disabled": true + }, + { + "key": "strategyType", + "value": "", + "description": "The value cannot be less than 1000000", + "disabled": true + }, + { + "key": "stopPrice", + "value": "20.01", + "description": "Used with STOP_LOSS, STOP_LOSS_LIMIT, TAKE_PROFIT, and TAKE_PROFIT_LIMIT orders.", + "disabled": true + }, + { + "key": "trailingDelta", + "value": "", + "description": "Used with STOP_LOSS, STOP_LOSS_LIMIT, TAKE_PROFIT, and TAKE_PROFIT_LIMIT orders.", + "disabled": true + }, + { + "key": "icebergQty", + "value": "", + "description": "Used with LIMIT, STOP_LOSS_LIMIT, and TAKE_PROFIT_LIMIT to create an iceberg order.", + "disabled": true + }, + { + "key": "newOrderRespType", + "value": "", + "description": "Set the response JSON. MARKET and LIMIT order types default to FULL, all other orders default to ACK.", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Cancels an existing order and places a new order on the same symbol.\n\nFilters are evaluated before the cancel order is placed.\n\nIf the new order placement is successfully sent to the engine, the order count will increase by 1.\n\nWeight(IP): 1" + }, + "response": [] + }, + { + "name": "New Order (TRADE)", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/api/v3/order?symbol=BNBUSDT&side=SELL&type=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["api", "v3", "order"], + "query": [ + { + "key": "symbol", + "value": "BNBUSDT", + "description": "Trading symbol, e.g. BNBUSDT" + }, + { + "key": "side", + "value": "SELL" + }, + { + "key": "type", + "value": "", + "description": "Order type" + }, + { + "key": "timeInForce", + "value": "", + "description": "Order time in force", + "disabled": true + }, + { + "key": "quantity", + "value": "", + "description": "Order quantity", + "disabled": true + }, + { + "key": "quoteOrderQty", + "value": "", + "description": "Quote quantity", + "disabled": true + }, + { + "key": "price", + "value": "", + "description": "Order price", + "disabled": true + }, + { + "key": "newClientOrderId", + "value": "", + "description": "A unique id among open orders. Automatically generated if not sent.", + "disabled": true + }, + { + "key": "strategyId", + "value": "", + "disabled": true + }, + { + "key": "strategyType", + "value": "", + "description": "The value cannot be less than 1000000", + "disabled": true + }, + { + "key": "stopPrice", + "value": "20.01", + "description": "Used with STOP_LOSS, STOP_LOSS_LIMIT, TAKE_PROFIT, and TAKE_PROFIT_LIMIT orders.", + "disabled": true + }, + { + "key": "trailingDelta", + "value": "", + "description": "Used with STOP_LOSS, STOP_LOSS_LIMIT, TAKE_PROFIT, and TAKE_PROFIT_LIMIT orders.", + "disabled": true + }, + { + "key": "icebergQty", + "value": "", + "description": "Used with LIMIT, STOP_LOSS_LIMIT, and TAKE_PROFIT_LIMIT to create an iceberg order.", + "disabled": true + }, + { + "key": "newOrderRespType", + "value": "", + "description": "Set the response JSON. MARKET and LIMIT order types default to FULL, all other orders default to ACK.", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Send in a new order.\n\n- `LIMIT_MAKER` are `LIMIT` orders that will be rejected if they would immediately match and trade as a taker.\n- `STOP_LOSS` and `TAKE_PROFIT` will execute a `MARKET` order when the `stopPrice` is reached.\n- Any `LIMIT` or `LIMIT_MAKER` type order can be made an iceberg order by sending an `icebergQty`.\n- Any order with an `icebergQty` MUST have `timeInForce` set to `GTC`.\n- `MARKET` orders using `quantity` specifies how much a user wants to buy or sell based on the market price.\n- `MARKET` orders using `quoteOrderQty` specifies the amount the user wants to spend (when buying) or receive (when selling) of the quote asset; the correct quantity will be determined based on the market liquidity and `quoteOrderQty`.\n- `MARKET` orders using `quoteOrderQty` will not break `LOT_SIZE` filter rules; the order will execute a quantity that will have the notional value as close as possible to `quoteOrderQty`.\n- same `newClientOrderId` can be accepted only when the previous one is filled, otherwise the order will be rejected.\n\nTrigger order price rules against market price for both `MARKET` and `LIMIT` versions:\n\n- Price above market price: `STOP_LOSS` `BUY`, `TAKE_PROFIT` `SELL`\n- Price below market price: `STOP_LOSS` `SELL`, `TAKE_PROFIT` `BUY`\n\n\nWeight(IP): 1" + }, + "response": [] + }, + { + "name": "Cancel Order (TRADE)", + "request": { + "method": "DELETE", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/api/v3/order?symbol=BNBUSDT×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["api", "v3", "order"], + "query": [ + { + "key": "symbol", + "value": "BNBUSDT", + "description": "Trading symbol, e.g. BNBUSDT" + }, + { + "key": "orderId", + "value": "", + "description": "Order id", + "disabled": true + }, + { + "key": "origClientOrderId", + "value": "", + "description": "Order id from client", + "disabled": true + }, + { + "key": "newClientOrderId", + "value": "", + "description": "Used to uniquely identify this cancel. Automatically generated by default", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Cancel an active order.\n\nEither `orderId` or `origClientOrderId` must be sent.\n\nWeight(IP): 1" + }, + "response": [] + }, + { + "name": "Current Open Orders (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/api/v3/openOrders?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["api", "v3", "openOrders"], + "query": [ + { + "key": "symbol", + "value": "BNBUSDT", + "description": "Trading symbol, e.g. BNBUSDT", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Get all open orders on a symbol. Careful when accessing this with no symbol.\n\nWeight(IP):\n- `3` for a single symbol;\n- `40` when the symbol parameter is omitted;" + }, + "response": [] + }, + { + "name": "Cancel all Open Orders on a Symbol (TRADE)", + "request": { + "method": "DELETE", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/api/v3/openOrders?symbol=BNBUSDT×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["api", "v3", "openOrders"], + "query": [ + { + "key": "symbol", + "value": "BNBUSDT", + "description": "Trading symbol, e.g. BNBUSDT" + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Cancels all active orders on a symbol.\nThis includes OCO orders.\n\nWeight(IP): 1" + }, + "response": [] + }, + { + "name": "All Orders (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/api/v3/allOrders?symbol=BNBUSDT×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["api", "v3", "allOrders"], + "query": [ + { + "key": "symbol", + "value": "BNBUSDT", + "description": "Trading symbol, e.g. BNBUSDT" + }, + { + "key": "orderId", + "value": "", + "description": "Order id", + "disabled": true + }, + { + "key": "startTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "endTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "limit", + "value": "500", + "description": "Default 500; max 1000.", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Get all account orders; active, canceled, or filled..\n\n- If `orderId` is set, it will get orders >= that `orderId`. Otherwise most recent orders are returned.\n- For some historical orders `cummulativeQuoteQty` will be < 0, meaning the data is not available at this time.\n- If `startTime` and/or `endTime` provided, `orderId` is not required\n\nWeight(IP): 10" + }, + "response": [] + }, + { + "name": "New OCO (TRADE)", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/api/v3/order/oco?symbol=BNBUSDT&side=SELL&quantity=&price=&stopPrice=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["api", "v3", "order", "oco"], + "query": [ + { + "key": "symbol", + "value": "BNBUSDT", + "description": "Trading symbol, e.g. BNBUSDT" + }, + { + "key": "listClientOrderId", + "value": "", + "description": "A unique Id for the entire orderList", + "disabled": true + }, + { + "key": "side", + "value": "SELL" + }, + { + "key": "quantity", + "value": "" + }, + { + "key": "limitClientOrderId", + "value": "", + "description": "A unique Id for the limit order", + "disabled": true + }, + { + "key": "limitStrategyId", + "value": "", + "disabled": true + }, + { + "key": "limitStrategyType", + "value": "", + "description": "The value cannot be less than 1000000", + "disabled": true + }, + { + "key": "price", + "value": "", + "description": "Order price" + }, + { + "key": "limitIcebergQty", + "value": "", + "disabled": true + }, + { + "key": "trailingDelta", + "value": "", + "disabled": true + }, + { + "key": "stopClientOrderId", + "value": "", + "description": "A unique Id for the stop loss/stop loss limit leg", + "disabled": true + }, + { + "key": "stopPrice", + "value": "" + }, + { + "key": "stopStrategyId", + "value": "", + "disabled": true + }, + { + "key": "stopStrategyType", + "value": "", + "description": "The value cannot be less than 1000000", + "disabled": true + }, + { + "key": "stopLimitPrice", + "value": "", + "description": "If provided, stopLimitTimeInForce is required.", + "disabled": true + }, + { + "key": "stopIcebergQty", + "value": "", + "disabled": true + }, + { + "key": "stopLimitTimeInForce", + "value": "", + "disabled": true + }, + { + "key": "newOrderRespType", + "value": "", + "description": "Set the response JSON.", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Send in a new OCO\n\n- Price Restrictions:\n - `SELL`: Limit Price > Last Price > Stop Price\n - `BUY`: Limit Price < Last Price < Stop Price\n- Quantity Restrictions:\n - Both legs must have the same quantity\n - `ICEBERG` quantities however do not have to be the same\n- Order Rate Limit\n - `OCO` counts as 2 orders against the order rate limit.\n \nWeight(IP): 1" + }, + "response": [] + }, + { + "name": "Query OCO (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/api/v3/orderList?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["api", "v3", "orderList"], + "query": [ + { + "key": "orderListId", + "value": "", + "description": "Order list id", + "disabled": true + }, + { + "key": "origClientOrderId", + "value": "", + "description": "Order id from client", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Retrieves a specific OCO based on provided optional parameters\n\nWeight(IP): 2" + }, + "response": [] + }, + { + "name": "Cancel OCO (TRADE)", + "request": { + "method": "DELETE", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/api/v3/orderList?symbol=BNBUSDT×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["api", "v3", "orderList"], + "query": [ + { + "key": "symbol", + "value": "BNBUSDT", + "description": "Trading symbol, e.g. BNBUSDT" + }, + { + "key": "orderListId", + "value": "", + "description": "Order list id", + "disabled": true + }, + { + "key": "listClientOrderId", + "value": "", + "description": "A unique Id for the entire orderList", + "disabled": true + }, + { + "key": "newClientOrderId", + "value": "", + "description": "Used to uniquely identify this cancel. Automatically generated by default", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Cancel an entire Order List\n\nCanceling an individual leg will cancel the entire OCO\n\nWeight(IP): 1" + }, + "response": [] + }, + { + "name": "Query all OCO (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/api/v3/allOrderList?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["api", "v3", "allOrderList"], + "query": [ + { + "key": "fromId", + "value": "", + "description": "Trade id to fetch from. Default gets most recent trades.", + "disabled": true + }, + { + "key": "startTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "endTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "limit", + "value": "500", + "description": "Default 500; max 1000.", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Retrieves all OCO based on provided optional parameters\n\nWeight(IP): 10" + }, + "response": [] + }, + { + "name": "Query Open OCO (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/api/v3/openOrderList?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["api", "v3", "openOrderList"], + "query": [ + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Weight(IP): 3" + }, + "response": [] + }, + { + "name": "Account Information (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/api/v3/account?recvWindow=5000×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["api", "v3", "account"], + "query": [ + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000" + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Get current account information.\n\nWeight(IP): 10" + }, + "response": [] + }, + { + "name": "Account Trade List (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/api/v3/myTrades?symbol=BNBUSDT×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["api", "v3", "myTrades"], + "query": [ + { + "key": "symbol", + "value": "BNBUSDT", + "description": "Trading symbol, e.g. BNBUSDT" + }, + { + "key": "orderId", + "value": "", + "description": "This can only be used in combination with symbol.", + "disabled": true + }, + { + "key": "startTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "endTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "fromId", + "value": "", + "description": "Trade id to fetch from. Default gets most recent trades.", + "disabled": true + }, + { + "key": "limit", + "value": "500", + "description": "Default 500; max 1000.", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Get trades for a specific account and symbol.\n\nIf `fromId` is set, it will get id >= that `fromId`. Otherwise most recent orders are returned.\n\nWeight(IP): 10" + }, + "response": [] + }, + { + "name": "Query Current Order Count Usage (TRADE)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/api/v3/rateLimit/order?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["api", "v3", "rateLimit", "order"], + "query": [ + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Displays the user's current order count usage for all intervals.\n\nWeight(IP): 20" + }, + "response": [] + } + ], + "description": "Account/Trade" + }, + { + "name": "User Data Stream", + "item": [ + { + "name": "Spot", + "item": [ + { + "name": "Create a ListenKey (USER_STREAM)", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/api/v3/userDataStream", + "host": ["{{url}}"], + "path": ["api", "v3", "userDataStream"] + }, + "description": "Start a new user data stream.\nThe stream will close after 60 minutes unless a keepalive is sent. If the account has an active `listenKey`, that `listenKey` will be returned and its validity will be extended for 60 minutes.\n\nWeight: 1" + }, + "response": [] + }, + { + "name": "Ping/Keep-alive a ListenKey (USER_STREAM)", + "request": { + "method": "PUT", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/api/v3/userDataStream?listenKey=listen-key", + "host": ["{{url}}"], + "path": ["api", "v3", "userDataStream"], + "query": [ + { + "key": "listenKey", + "value": "listen-key", + "description": "User websocket listen key" + } + ] + }, + "description": "Keepalive a user data stream to prevent a time out. User data streams will close after 60 minutes. It's recommended to send a ping about every 30 minutes.\n\nWeight: 1" + }, + "response": [] + }, + { + "name": "Close a ListenKey (USER_STREAM)", + "request": { + "method": "DELETE", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/api/v3/userDataStream?listenKey=listen-key", + "host": ["{{url}}"], + "path": ["api", "v3", "userDataStream"], + "query": [ + { + "key": "listenKey", + "value": "listen-key", + "description": "User websocket listen key" + } + ] + }, + "description": "Close out a user data stream.\n\nWeight: 1" + }, + "response": [] + } + ], + "description": "User Data Stream" + }, + { + "name": "Cross Margin", + "item": [ + { + "name": "Create a ListenKey (USER_STREAM)", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/userDataStream", + "host": ["{{url}}"], + "path": ["sapi", "v1", "userDataStream"] + }, + "description": "Start a new user data stream.\nThe stream will close after 60 minutes unless a keepalive is sent. If the account has an active `listenKey`, that `listenKey` will be returned and its validity will be extended for 60 minutes.\n\nWeight: 1" + }, + "response": [] + }, + { + "name": "Ping/Keep-alive a ListenKey (USER_STREAM)", + "request": { + "method": "PUT", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/userDataStream?listenKey=listen-key", + "host": ["{{url}}"], + "path": ["sapi", "v1", "userDataStream"], + "query": [ + { + "key": "listenKey", + "value": "listen-key", + "description": "User websocket listen key" + } + ] + }, + "description": "Keepalive a user data stream to prevent a time out. User data streams will close after 60 minutes. It's recommended to send a ping about every 30 minutes.\n\nWeight: 1" + }, + "response": [] + }, + { + "name": "Close a ListenKey (USER_STREAM)", + "request": { + "method": "DELETE", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/userDataStream?listenKey=listen-key", + "host": ["{{url}}"], + "path": ["sapi", "v1", "userDataStream"], + "query": [ + { + "key": "listenKey", + "value": "listen-key", + "description": "User websocket listen key" + } + ] + }, + "description": "Close out a user data stream.\n\nWeight: 1" + }, + "response": [] + } + ], + "description": "Margin User Data Stream" + }, + { + "name": "Isolated Margin", + "item": [ + { + "name": "Generate a Listen Key (USER_STREAM)", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/userDataStream/isolated?symbol=BTCUSDT", + "host": ["{{url}}"], + "path": ["sapi", "v1", "userDataStream", "isolated"], + "query": [ + { + "key": "symbol", + "value": "BTCUSDT" + } + ] + }, + "description": "Start a new user data stream.\nThe stream will close after 60 minutes unless a keepalive is sent. If the account has an active `listenKey`, that `listenKey` will be returned and its validity will be extended for 60 minutes.\n\nWeight: 1" + }, + "response": [] + }, + { + "name": "Ping/Keep-alive a Listen Key (USER_STREAM)", + "request": { + "method": "PUT", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/userDataStream/isolated?symbol=BTCUSDT&listenKey=listen-key", + "host": ["{{url}}"], + "path": ["sapi", "v1", "userDataStream", "isolated"], + "query": [ + { + "key": "symbol", + "value": "BTCUSDT" + }, + { + "key": "listenKey", + "value": "listen-key", + "description": "User websocket listen key" + } + ] + }, + "description": "Keepalive a user data stream to prevent a time out. User data streams will close after 60 minutes. It's recommended to send a ping about every 30 minutes.\n\nWeight: 1" + }, + "response": [] + }, + { + "name": "Close a ListenKey (USER_STREAM)", + "request": { + "method": "DELETE", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/userDataStream/isolated?symbol=BTCUSDT&listenKey=listen-key", + "host": ["{{url}}"], + "path": ["sapi", "v1", "userDataStream", "isolated"], + "query": [ + { + "key": "symbol", + "value": "BTCUSDT" + }, + { + "key": "listenKey", + "value": "listen-key", + "description": "User websocket listen key" + } + ] + }, + "description": "Close out a user data stream.\n\nWeight: 1" + }, + "response": [] + } + ], + "description": "Isolated User Data Stream" + } + ] + }, + { + "name": "Wallet", + "item": [ + { + "name": "System Status (System)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/system/status", + "host": ["{{url}}"], + "path": ["sapi", "v1", "system", "status"] + }, + "description": "Fetch system status.\n\nWeight(IP): 1" + }, + "response": [] + }, + { + "name": "All Coins' Information (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/capital/config/getall?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "capital", "config", "getall"], + "query": [ + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Get information of coins (available for deposit and withdraw) for user.\n\nWeight(IP): 10" + }, + "response": [] + }, + { + "name": "Daily Account Snapshot (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/accountSnapshot?type=SPOT×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "accountSnapshot"], + "query": [ + { + "key": "type", + "value": "SPOT", + "description": "\"SPOT\", \"MARGIN\", \"FUTURES\"" + }, + { + "key": "startTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "endTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "limit", + "value": "", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "- The query time period must be less than 30 days\n- Support query within the last one month only\n- If startTimeand endTime not sent, return records of the last 7 days by default\n\nWeight(IP): 2400" + }, + "response": [] + }, + { + "name": "Disable Fast Withdraw Switch (USER_DATA)", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/account/disableFastWithdrawSwitch?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "account", "disableFastWithdrawSwitch"], + "query": [ + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "- This request will disable fastwithdraw switch under your account.\n- You need to enable \"trade\" option for the api key which requests this endpoint.\n\nWeight(IP): 1" + }, + "response": [] + }, + { + "name": "Enable Fast Withdraw Switch (USER_DATA)", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/account/enableFastWithdrawSwitch?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "account", "enableFastWithdrawSwitch"], + "query": [ + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "- This request will enable fastwithdraw switch under your account. You need to enable \"trade\" option for the api key which requests this endpoint.\n- When Fast Withdraw Switch is on, transferring funds to a Binance account will be done instantly. There is no on-chain transaction, no transaction ID and no withdrawal fee.\n\nWeight(IP): 1" + }, + "response": [] + }, + { + "name": "Withdraw (USER_DATA)", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/capital/withdraw/apply?coin=BNB&address=&amount=1.01×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "capital", "withdraw", "apply"], + "query": [ + { + "key": "coin", + "value": "BNB", + "description": "Coin name" + }, + { + "key": "withdrawOrderId", + "value": "", + "description": "Client id for withdraw", + "disabled": true + }, + { + "key": "network", + "value": "", + "description": "Get the value from `GET /sapi/v1/capital/config/getall`", + "disabled": true + }, + { + "key": "address", + "value": "" + }, + { + "key": "addressTag", + "value": "", + "description": "Secondary address identifier for coins like XRP,XMR etc.", + "disabled": true + }, + { + "key": "amount", + "value": "1.01" + }, + { + "key": "transactionFeeFlag", + "value": "", + "description": "When making internal transfer\n- `true` -> returning the fee to the destination account;\n- `false` -> returning the fee back to the departure account.", + "disabled": true + }, + { + "key": "name", + "value": "", + "disabled": true + }, + { + "key": "walletType", + "value": "", + "description": "The wallet type for withdraw,0-Spot wallet, 1- Funding wallet. Default is Spot wallet", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Submit a withdraw request.\n\n- If `network` not send, return with default network of the coin.\n- You can get `network` and `isDefault` in `networkList` of a coin in the response of `Get /sapi/v1/capital/config/getall (HMAC SHA256)`.\n\nWeight(IP): 1" + }, + "response": [] + }, + { + "name": "Deposit History (supporting network) (User Data)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/capital/deposit/hisrec?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "capital", "deposit", "hisrec"], + "query": [ + { + "key": "coin", + "value": "BNB", + "description": "Coin name", + "disabled": true + }, + { + "key": "status", + "value": "", + "description": "* `0` - pending\n* `6` - credited but cannot withdraw\n* `1` - success", + "disabled": true + }, + { + "key": "startTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "endTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "offset", + "value": "", + "disabled": true + }, + { + "key": "limit", + "value": "500", + "description": "Default 500; max 1000.", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Fetch deposit history.\n\n- Please notice the default `startTime` and `endTime` to make sure that time interval is within 0-90 days.\n- If both `startTime` and `endTime` are sent, time between `startTime` and `endTime` must be less than 90 days.\n\nWeight(IP): 1" + }, + "response": [] + }, + { + "name": "Withdraw History (supporting network) (User Data)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/capital/withdraw/history?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "capital", "withdraw", "history"], + "query": [ + { + "key": "coin", + "value": "BNB", + "description": "Coin name", + "disabled": true + }, + { + "key": "withdrawOrderId", + "value": "", + "disabled": true + }, + { + "key": "status", + "value": "", + "description": "* `0` - Email Sent\n* `1` - Cancelled\n* `2` - Awaiting Approval\n* `3` - Rejected\n* `4` - Processing\n* `5` - Failure\n* `6` - Completed", + "disabled": true + }, + { + "key": "startTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "endTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "offset", + "value": "", + "disabled": true + }, + { + "key": "limit", + "value": "500", + "description": "Default 500; max 1000.", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Fetch withdraw history.\n\n- `network` may not be in the response for old withdraw.\n- Please notice the default `startTime` and `endTime` to make sure that time interval is within 0-90 days.\n- If both `startTime` and `endTime` are sent, time between `startTime` and `endTime` must be less than 90 days\n\nWeight(IP): 1" + }, + "response": [] + }, + { + "name": "Deposit Address (supporting network) (User Data)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/capital/deposit/address?coin=BNB×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "capital", "deposit", "address"], + "query": [ + { + "key": "coin", + "value": "BNB", + "description": "Coin name" + }, + { + "key": "network", + "value": "ETH", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Fetch deposit address with network.\n\n- If network is not send, return with default network of the coin.\n- You can get network and isDefault in networkList in the response of Get /sapi/v1/capital/config/getall (HMAC SHA256).\n\nWeight(IP): 10" + }, + "response": [] + }, + { + "name": "Account Status (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/account/status?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "account", "status"], + "query": [ + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Fetch account status detail.\n\nWeight(IP): 1" + }, + "response": [] + }, + { + "name": "Account API Trading Status (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/account/apiTradingStatus?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "account", "apiTradingStatus"], + "query": [ + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Fetch account API trading status with details.\n\nWeight(IP): 1" + }, + "response": [] + }, + { + "name": "DustLog (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/asset/dribblet?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "asset", "dribblet"], + "query": [ + { + "key": "startTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "endTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Weight(IP): 1" + }, + "response": [] + }, + { + "name": "Get Assets That Can Be Converted Into BNB (USER_DATA)", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/asset/dust-btc?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "asset", "dust-btc"], + "query": [ + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Weight(IP): 1" + }, + "response": [] + }, + { + "name": "Dust Transfer (USER_DATA)", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/asset/dust?asset=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "asset", "dust"], + "query": [ + { + "key": "asset", + "value": "", + "description": "The asset being converted. For example, asset=BTC&asset=USDT" + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Convert dust assets to BNB.\n\nWeight(UID): 10" + }, + "response": [] + }, + { + "name": "Asset Dividend Record (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/asset/assetDividend?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "asset", "assetDividend"], + "query": [ + { + "key": "asset", + "value": "BNB", + "disabled": true + }, + { + "key": "startTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "endTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "limit", + "value": "", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Query asset Dividend Record\n\nWeight(IP): 10" + }, + "response": [] + }, + { + "name": "Asset Detail (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/asset/assetDetail?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "asset", "assetDetail"], + "query": [ + { + "key": "asset", + "value": "BNB", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Fetch details of assets supported on Binance.\n\n- Please get network and other deposit or withdraw details from `GET /sapi/v1/capital/config/getall`.\n\nWeight(IP): 1" + }, + "response": [] + }, + { + "name": "Trade Fee (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/asset/tradeFee?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "asset", "tradeFee"], + "query": [ + { + "key": "symbol", + "value": "BNBUSDT", + "description": "Trading symbol, e.g. BNBUSDT", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Fetch trade fee\n\nWeight(IP): 1" + }, + "response": [] + }, + { + "name": "Query User Universal Transfer History (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/asset/transfer?type=MAIN_UMFUTURE×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "asset", "transfer"], + "query": [ + { + "key": "type", + "value": "MAIN_UMFUTURE", + "description": "Universal transfer type" + }, + { + "key": "startTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "endTime", + "value": "", + "description": "UTC timestamp in ms", + "disabled": true + }, + { + "key": "current", + "value": "1", + "description": "Current querying page. Start from 1. Default:1", + "disabled": true + }, + { + "key": "size", + "value": "100", + "description": "Default:10 Max:100", + "disabled": true + }, + { + "key": "fromSymbol", + "value": "BNBUSDT", + "description": "Must be sent when type are ISOLATEDMARGIN_MARGIN and ISOLATEDMARGIN_ISOLATEDMARGIN", + "disabled": true + }, + { + "key": "toSymbol", + "value": "BNBUSDT", + "description": "Must be sent when type are MARGIN_ISOLATEDMARGIN and ISOLATEDMARGIN_ISOLATEDMARGIN", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "- `fromSymbol` must be sent when type are ISOLATEDMARGIN_MARGIN and ISOLATEDMARGIN_ISOLATEDMARGIN\n- `toSymbol` must be sent when type are MARGIN_ISOLATEDMARGIN and ISOLATEDMARGIN_ISOLATEDMARGIN\n- Support query within the last 6 months only\n- If `startTime` and `endTime` not sent, return records of the last 7 days by default\n\nWeight(IP): 1" + }, + "response": [] + }, + { + "name": "User Universal Transfer (USER_DATA)", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/asset/transfer?type=MAIN_UMFUTURE&asset=BTC&amount=1.01×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "asset", "transfer"], + "query": [ + { + "key": "type", + "value": "MAIN_UMFUTURE", + "description": "Universal transfer type" + }, + { + "key": "asset", + "value": "BTC" + }, + { + "key": "amount", + "value": "1.01" + }, + { + "key": "fromSymbol", + "value": "BNBUSDT", + "description": "Must be sent when type are ISOLATEDMARGIN_MARGIN and ISOLATEDMARGIN_ISOLATEDMARGIN", + "disabled": true + }, + { + "key": "toSymbol", + "value": "BNBUSDT", + "description": "Must be sent when type are MARGIN_ISOLATEDMARGIN and ISOLATEDMARGIN_ISOLATEDMARGIN", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "You need to enable `Permits Universal Transfer` option for the api key which requests this endpoint.\n\n- `fromSymbol` must be sent when type are ISOLATEDMARGIN_MARGIN and ISOLATEDMARGIN_ISOLATEDMARGIN\n- `toSymbol` must be sent when type are MARGIN_ISOLATEDMARGIN and ISOLATEDMARGIN_ISOLATEDMARGIN\n\nENUM of transfer types:\n- MAIN_UMFUTURE Spot account transfer to USDⓈ-M Futures account\n- MAIN_CMFUTURE Spot account transfer to COIN-M Futures account\n- MAIN_MARGIN Spot account transfer to Margin(cross)account\n- UMFUTURE_MAIN USDⓈ-M Futures account transfer to Spot account\n- UMFUTURE_MARGIN USDⓈ-M Futures account transfer to Margin(cross)account\n- CMFUTURE_MAIN COIN-M Futures account transfer to Spot account\n- CMFUTURE_MARGIN COIN-M Futures account transfer to Margin(cross) account\n- MARGIN_MAIN Margin(cross)account transfer to Spot account\n- MARGIN_UMFUTURE Margin(cross)account transfer to USDⓈ-M Futures\n- MARGIN_CMFUTURE Margin(cross)account transfer to COIN-M Futures\n- ISOLATEDMARGIN_MARGIN Isolated margin account transfer to Margin(cross) account\n- MARGIN_ISOLATEDMARGIN Margin(cross) account transfer to Isolated margin account\n- ISOLATEDMARGIN_ISOLATEDMARGIN Isolated margin account transfer to Isolated margin account\n- MAIN_FUNDING Spot account transfer to Funding account\n- FUNDING_MAIN Funding account transfer to Spot account\n- FUNDING_UMFUTURE Funding account transfer to UMFUTURE account\n- UMFUTURE_FUNDING UMFUTURE account transfer to Funding account\n- MARGIN_FUNDING MARGIN account transfer to Funding account\n- FUNDING_MARGIN Funding account transfer to Margin account\n- FUNDING_CMFUTURE Funding account transfer to CMFUTURE account\n- CMFUTURE_FUNDING CMFUTURE account transfer to Funding account\n\nWeight(IP): 1" + }, + "response": [] + }, + { + "name": "Funding Wallet (USER_DATA)", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/asset/get-funding-asset?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "asset", "get-funding-asset"], + "query": [ + { + "key": "asset", + "value": "BNB", + "disabled": true + }, + { + "key": "needBtcValuation", + "value": "", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "- Currently supports querying the following business assets:Binance Pay, Binance Card, Binance Gift Card, Stock Token\n\nWeight(IP): 1" + }, + "response": [] + }, + { + "name": "User Asset (USER_DATA)", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v3/asset/getUserAsset?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v3", "asset", "getUserAsset"], + "query": [ + { + "key": "asset", + "value": "BNB", + "description": "If asset is blank, then query all positive assets user have.", + "disabled": true + }, + { + "key": "needBtcValuation", + "value": "", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Get user assets, just for positive data.\n\nWeight(IP): 5" + }, + "response": [] + }, + { + "name": "Get API Key Permission (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/account/apiRestrictions?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "account", "apiRestrictions"], + "query": [ + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Weight(IP): 1" + }, + "response": [] + }, + { + "name": "BUSD Convert (TRADE)", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/asset/convert-transfer?clientTranId=&asset=BNB&amount=&targetAsset=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "asset", "convert-transfer"], + "query": [ + { + "key": "clientTranId", + "value": "", + "description": "The unique user-defined transaction id, min length 20" + }, + { + "key": "asset", + "value": "BNB", + "description": "The current asset" + }, + { + "key": "amount", + "value": "", + "description": "The amount must be positive number" + }, + { + "key": "targetAsset", + "value": "", + "description": "Target asset you want to convert" + }, + { + "key": "accountType", + "value": "", + "description": "Only MAIN and CARD, default MAIN", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Get user assets, just for positive data.\n\nWeight(IP): 5" + }, + "response": [] + }, + { + "name": "BUSD Convert History (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/asset/convert-transfer/queryByPage?startTime=&endTime=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": [ + "sapi", + "v1", + "asset", + "convert-transfer", + "queryByPage" + ], + "query": [ + { + "key": "tranId", + "value": "", + "description": "The transaction id", + "disabled": true + }, + { + "key": "clientTranId", + "value": "", + "description": "The user-defined transaction id", + "disabled": true + }, + { + "key": "asset", + "value": "BNB", + "description": "The current asset", + "disabled": true + }, + { + "key": "startTime", + "value": "", + "description": "inclusive, unit: ms" + }, + { + "key": "endTime", + "value": "", + "description": "exclusive, unit: ms" + }, + { + "key": "accountType", + "value": "", + "description": "Only MAIN and CARD, default MAIN", + "disabled": true + }, + { + "key": "current", + "value": "", + "description": "current page, default 1, the min value is 1", + "disabled": true + }, + { + "key": "size", + "value": "", + "description": "page size, default 10, the max value is 100", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Get user assets, just for positive data.\n\nWeight(IP): 5" + }, + "response": [] + }, + { + "name": "Get Cloud-Mining payment and refund history (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/asset/ledger-transfer/cloud-mining/queryByPage?startTime=&endTime=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": [ + "sapi", + "v1", + "asset", + "ledger-transfer", + "cloud-mining", + "queryByPage" + ], + "query": [ + { + "key": "tranId", + "value": "", + "description": "The transaction id", + "disabled": true + }, + { + "key": "clientTranId", + "value": "", + "description": "The unique flag", + "disabled": true + }, + { + "key": "asset", + "value": "BNB", + "description": "If it is blank, we will query all assets", + "disabled": true + }, + { + "key": "startTime", + "value": "", + "description": "inclusive, unit: ms" + }, + { + "key": "endTime", + "value": "", + "description": "exclusive, unit: ms" + }, + { + "key": "current", + "value": "", + "description": "current page, default 1, the min value is 1", + "disabled": true + }, + { + "key": "size", + "value": "", + "description": "page size, default 10, the max value is 100", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "Get user assets, just for positive data.\n\nWeight(IP): 5" + }, + "response": [] + } + ], + "description": "Wallet Endpoints" + }, + { + "name": "VIP Loans", + "item": [ + { + "name": "Get VIP Loan Ongoing Orders (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/loan/vip/ongoing/orders?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "loan", "vip", "ongoing", "orders"], + "query": [ + { + "key": "orderId", + "value": "", + "disabled": true + }, + { + "key": "collateralAccountId", + "value": "", + "disabled": true + }, + { + "key": "loanCoin", + "value": "", + "disabled": true + }, + { + "key": "collateralCoin", + "value": "", + "disabled": true + }, + { + "key": "current", + "value": "1", + "description": "Currently querying page. Start from 1, Default:1, Max: 1000.", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "- If startTime and endTime are not sent, the recent 7-day data will be returned.\n- The max interval between startTime and endTime is 30 days.\n\nWeight(UID): 6000" + }, + "response": [] + }, + { + "name": "VIP Loan Repay (TRADE)", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/loan/vip/repay?orderId=&amount=×tamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "loan", "vip", "repay"], + "query": [ + { + "key": "orderId", + "value": "" + }, + { + "key": "amount", + "value": "" + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "- If startTime and endTime are not sent, the recent 7-day data will be returned.\n- The max interval between startTime and endTime is 30 days.\n\nWeight(UID): 6000" + }, + "response": [] + }, + { + "name": "Get VIP Loan Repayment History (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/loan/vip/repay/history?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "loan", "vip", "repay", "history"], + "query": [ + { + "key": "orderId", + "value": "", + "disabled": true + }, + { + "key": "loanCoin", + "value": "", + "disabled": true + }, + { + "key": "startTime", + "value": "", + "disabled": true + }, + { + "key": "endTime", + "value": null, + "disabled": true + }, + { + "key": "current", + "value": "1", + "description": "Currently querying page. Start from 1, Default:1, Max: 1000.", + "disabled": true + }, + { + "key": "limit", + "value": "10", + "description": "Default: 10, Max: 100", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "- If startTime and endTime are not sent, the recent 7-day data will be returned.\n- The max interval between startTime and endTime is 30 days.\n\nWeight(UID): 6000" + }, + "response": [] + }, + { + "name": "Check Locked Value of VIP Collateral Account (USER_DATA)", + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "X-MBX-APIKEY", + "value": "{{binance-api-key}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/sapi/v1/loan/vip/collateral/account?timestamp={{timestamp}}&signature={{signature}}", + "host": ["{{url}}"], + "path": ["sapi", "v1", "loan", "vip", "collateral", "account"], + "query": [ + { + "key": "orderId", + "value": "", + "disabled": true + }, + { + "key": "collateralAccountId", + "value": "", + "disabled": true + }, + { + "key": "recvWindow", + "value": "5000", + "description": "The value cannot be greater than 60000", + "disabled": true + }, + { + "key": "timestamp", + "value": "{{timestamp}}", + "description": "UTC timestamp in ms" + }, + { + "key": "signature", + "value": "{{signature}}", + "description": "Signature" + } + ] + }, + "description": "- If startTime and endTime are not sent, the recent 7-day data will be returned.\n- The max interval between startTime and endTime is 30 days.\n\nWeight(UID): 6000" + }, + "response": [] + } + ] + } + ], + "event": [ + { + "listen": "prerequest", + "script": { + "type": "text/javascript", + "exec": [ + "const ts = Date.now();", + "pm.environment.set(\"timestamp\", ts);", + "", + "let paramsObject = {};", + "", + "const binance_api_secret = pm.environment.get(\"binance-api-secret\");", + "", + "const parameters = pm.request.url.query;", + "", + "parameters.map((param) => {", + " if (param.key != 'signature' && ", + " !is_empty(param.value) &&", + " !is_disabled(param.disabled)) {", + " paramsObject[param.key] = param.value;", + " //console.log(encodeURIComponent(param.value));", + " //pm.environment.set(param.key, encodeURIComponent(param.value));", + " }", + "})", + " ", + "Object.assign(paramsObject, {'timestamp': ts});", + "", + "if (binance_api_secret) {", + " const queryString = Object.keys(paramsObject).map((key) => {", + " return `${key}=${paramsObject[key]}`;", + " }).join('&');", + " console.log(queryString);", + " const signature = CryptoJS.HmacSHA256(queryString, binance_api_secret).toString();", + " pm.environment.set(\"signature\", signature);", + "}", + "", + "", + "function is_disabled(str) {", + " return str == true;", + "}", + "", + "function is_empty(str) {", + " if (typeof str == 'undefined' ||", + " !str || ", + " str.length === 0 || ", + " str === \"\" ||", + " !/[^\\s]/.test(str) ||", + " /^\\s*$/.test(str) ||", + " str.replace(/\\s/g,\"\") === \"\")", + " {", + " return true;", + " }", + " else", + " {", + " return false;", + " }", + "}" + ] + } + }, + { + "listen": "test", + "script": { + "type": "text/javascript", + "exec": [""] + } + } + ] +} diff --git a/lib/binance/docs_parser.ex b/lib/binance/docs_parser.ex new file mode 100644 index 0000000..ec05bc9 --- /dev/null +++ b/lib/binance/docs_parser.ex @@ -0,0 +1,95 @@ +defmodule Binance.DocsParser do + defp normalize_entry_item(%{ + "name" => name, + "request" => %{ + "method" => method, + "url" => %{"path" => path, "query" => query} + } + }) do + params = query |> Enum.map(&parse_params/1) + + %{ + method: String.to_atom(method |> String.downcase()), + name: name, + query: params, + path: path, + needs_auth?: Enum.find(params, nil, &(&1.name == "signature")) != nil + } + end + + # no query version + defp normalize_entry_item( + %{ + "name" => name, + "request" => %{ + "method" => method, + "url" => %{"path" => path} + } + } = rest + ) do + Map.put( + rest, + "request", + Map.put(rest["request"], "url", Map.put(rest["request"]["url"], "query", [])) + ) + |> normalize_entry_item() + end + + defp normalize_entry_item(%{ + "item" => item + }) do + item + |> Enum.map(&normalize_entry_item/1) + end + + defp normalize_entry(%{"name" => name, "item" => %{"item" => item}}) do + IO.inspect(item) + + %{ + items: item |> Enum.map(&normalize_entry_item/1) |> List.flatten(), + group: name + } + end + + defp normalize_entry(%{"name" => name, "item" => item}) do + %{ + items: item |> Enum.map(&normalize_entry_item/1) |> List.flatten(), + group: name + } + end + + def get_documentation do + File.read!("#{__DIR__}/docs/spot.json") + |> Poison.decode!() + |> Map.get("item") + # don't care about anything besides the items + |> Enum.map(&normalize_entry/1) + |> List.flatten() + end + + def modularize_name(name) do + Regex.replace(~r/-/, name, "_") + |> String.replace(" ", "_") + |> String.replace("(", "") + |> String.replace(")", "") + |> String.replace("/", "") + |> String.capitalize() + |> String.to_atom() + |> (&Module.concat(Binance2, &1)).() + end + + def functionize_name(%{method: method, path: path}) do + api_path = Enum.take(path, -2) |> Enum.join("_") |> String.downcase() |> String.to_atom() + + "#{String.downcase(Atom.to_string(method))}_#{api_path}" + |> String.to_atom() + end + + defp parse_params(%{"key" => key} = args) do + %{ + name: key, + description: Map.get(args, "description", ""), + optional: Map.get(args, "disabled", false) + } + end +end diff --git a/lib/binance/rest/http_client.ex b/lib/binance/rest/http_client.ex index 4e3dc83..1942a9b 100644 --- a/lib/binance/rest/http_client.ex +++ b/lib/binance/rest/http_client.ex @@ -77,13 +77,42 @@ defmodule Binance.Rest.HTTPClient do body = "#{argument_string}&signature=#{signature}" - case apply(HTTPoison, method, [ - "#{@endpoint}#{url}", - body, - [ - {"X-MBX-APIKEY", Application.get_env(:binance, :api_key)} - ] - ]) do + url = + case method do + :get -> + "#{@endpoint}#{url}?#{body}" + + _ -> + "#{@endpoint}#{url}" + end + + IO.puts(body) + IO.puts(method) + IO.puts("#{url}") + + IO.inspect([ + {"X-MBX-APIKEY", Application.get_env(:binance, :api_key)} + ]) + + case method do + :get -> + HTTPoison.get( + url, + [ + {"X-MBX-APIKEY", Application.get_env(:binance, :api_key)} + ] + ) + + _ -> + apply(HTTPoison, method, [ + url, + body, + [ + {"X-MBX-APIKEY", Application.get_env(:binance, :api_key)} + ] + ]) + end + |> case do {:error, err} -> {:error, {:http_error, err}} @@ -183,11 +212,12 @@ defmodule Binance.Rest.HTTPClient do |> Enum.join("&") end - # TODO: remove when we require OTP 22.1 - if Code.ensure_loaded?(:crypto) and function_exported?(:crypto, :mac, 4) do - defp generate_signature(digest, key, argument_string), do: :crypto.mac(:hmac, digest, key, argument_string) - else - defp generate_signature(digest, key, argument_string), do: :crypto.hmac(digest, key, argument_string) - end - + # TODO: remove when we require OTP 22.1 + if Code.ensure_loaded?(:crypto) and function_exported?(:crypto, :mac, 4) do + defp generate_signature(digest, key, argument_string), + do: :crypto.mac(:hmac, digest, key, argument_string) + else + defp generate_signature(digest, key, argument_string), + do: :crypto.hmac(digest, key, argument_string) + end end diff --git a/lib/binance2.ex b/lib/binance2.ex new file mode 100644 index 0000000..fde567f --- /dev/null +++ b/lib/binance2.ex @@ -0,0 +1,91 @@ +defmodule Binance2 do +end + +docs = Binance.DocsParser.get_documentation() + +docs +|> Enum.each(fn api_group -> + IO.puts("parsing group: #{api_group.group}") + + defmodule Binance.DocsParser.modularize_name(api_group.group) do + alias Binance.Rest.HTTPClient + + api_group.items + |> Enum.each(fn item -> + method = item.method + path = item.path + params = item.query + name = item.name + url = "/" <> Path.join(path) + needs_auth = item.needs_auth? + + mandatory_params = + Enum.filter(params, fn param -> + param.optional == false + end) + |> Enum.map(fn param -> + %{name: param.name, description: param.description} + end) + |> Enum.filter(&(&1.name != "timestamp")) + |> Enum.filter(&(&1.name != "signature")) + + optional_params = + Enum.filter(params, fn param -> + param.optional == true + end) + |> Enum.map(fn param -> + %{name: param.name, description: param.description} + end) + |> Enum.filter(&(&1.name != "timestamp")) + |> Enum.filter(&(&1.name != "signature")) + + # generate mandatory params + arg_names = + mandatory_params + |> Enum.map(&(Map.get(&1, :name) |> String.to_atom() |> Macro.var(nil))) + + @doc """ + METHOD: #{method} + + PATH: #{inspect(path)} + + URL: #{url} + + needs auth: #{inspect(needs_auth)} + + Mandatory params: #{inspect(mandatory_params)} + + Optional params: #{inspect(optional_params)} + """ + def unquote(Binance.DocsParser.functionize_name(item))(unquote_splicing(arg_names)) do + binding = binding() + + IO.puts("API call: #{unquote(method)} " <> unquote(url)) + IO.puts("binding:") + IO.inspect(binding) + + args = %{ + timestamp: :os.system_time(:millisecond) + } + + if unquote(needs_auth) do + case HTTPClient.signed_request_binance(unquote(url), args, unquote(method)) do + {:ok, %{"code" => code, "msg" => msg}} -> + {:error, {:binance_error, %{code: code, msg: msg}}} + + data -> + data + end + else + case HTTPClient.unsigned_request_binance(unquote(url), args, unquote(method)) do + {:ok, %{"code" => code, "msg" => msg}} -> + {:error, {:binance_error, %{code: code, msg: msg}}} + + data -> + data + end + end + end + end) + end +end) From 00512c966261c4967472a4a303df4b5b70ba5be9 Mon Sep 17 00:00:00 2001 From: David Mohl Date: Sat, 1 Jul 2023 19:56:19 +1000 Subject: [PATCH 02/25] Add docs and typespecs --- lib/binance/docs_parser.ex | 42 ++++++++++--------- lib/binance2.ex | 83 ++++++++++++++++++++++++++++++++------ 2 files changed, 94 insertions(+), 31 deletions(-) diff --git a/lib/binance/docs_parser.ex b/lib/binance/docs_parser.ex index ec05bc9..692287a 100644 --- a/lib/binance/docs_parser.ex +++ b/lib/binance/docs_parser.ex @@ -1,11 +1,13 @@ defmodule Binance.DocsParser do - defp normalize_entry_item(%{ - "name" => name, - "request" => %{ - "method" => method, - "url" => %{"path" => path, "query" => query} - } - }) do + defp normalize_entry_item( + %{ + "name" => name, + "request" => %{ + "method" => method, + "url" => %{"path" => path, "query" => query} + } + } = args + ) do params = query |> Enum.map(&parse_params/1) %{ @@ -13,7 +15,9 @@ defmodule Binance.DocsParser do name: name, query: params, path: path, - needs_auth?: Enum.find(params, nil, &(&1.name == "signature")) != nil + needs_auth?: Enum.find(params, nil, &(&1.name == "signature")) != nil, + unique_key: "#{String.downcase(method)}_#{Enum.join(path, "_")}", + description: Map.get(args["request"], "description", "") } end @@ -42,18 +46,18 @@ defmodule Binance.DocsParser do |> Enum.map(&normalize_entry_item/1) end - defp normalize_entry(%{"name" => name, "item" => %{"item" => item}}) do - IO.inspect(item) - - %{ - items: item |> Enum.map(&normalize_entry_item/1) |> List.flatten(), - group: name - } - end - defp normalize_entry(%{"name" => name, "item" => item}) do %{ - items: item |> Enum.map(&normalize_entry_item/1) |> List.flatten(), + items: + item + |> Enum.map(&normalize_entry_item/1) + |> List.flatten() + # remove duplicates + |> Enum.reduce(%{}, fn item, acc -> + IO.puts(item.unique_key) + Map.put(acc, item.unique_key, item) + end) + |> Map.values(), group: name } end @@ -79,7 +83,7 @@ defmodule Binance.DocsParser do end def functionize_name(%{method: method, path: path}) do - api_path = Enum.take(path, -2) |> Enum.join("_") |> String.downcase() |> String.to_atom() + api_path = path |> Enum.join("_") |> String.downcase() |> String.to_atom() "#{String.downcase(Atom.to_string(method))}_#{api_path}" |> String.to_atom() diff --git a/lib/binance2.ex b/lib/binance2.ex index fde567f..50b796a 100644 --- a/lib/binance2.ex +++ b/lib/binance2.ex @@ -18,6 +18,7 @@ docs name = item.name url = "/" <> Path.join(path) needs_auth = item.needs_auth? + description = item.description mandatory_params = Enum.filter(params, fn param -> @@ -44,32 +45,90 @@ docs mandatory_params |> Enum.map(&(Map.get(&1, :name) |> String.to_atom() |> Macro.var(nil))) + spec = + mandatory_params + |> Enum.map(fn item -> quote do: any() end) + + optional_args = + optional_params + |> Enum.reduce([], fn item, acc -> + name = item.name + + case acc do + [] -> + quote do: {unquote(String.to_atom(name)), any()} + + val -> + quote do: + {unquote(String.to_atom(name)), any()} + | unquote(val) + end + end) + |> case do + [] -> [] + e -> [e] + end + @doc """ - METHOD: #{method} + #{name} - PATH: #{inspect(path)} + #{description} - URL: #{url} + Details: - needs auth: #{inspect(needs_auth)} + - METHOD: #{method} + - URL: #{url} - Mandatory params: #{inspect(mandatory_params)} + Mandatory params: - Optional params: #{inspect(optional_params)} + #{Enum.map(mandatory_params, fn item -> "- #{item.name} - #{item.description}" end) |> Enum.join("\n")} + + Optional params: + + #{Enum.map(optional_params, fn item -> "- #{item.name} - #{item.description}" end) |> Enum.join("\n")} """ - def unquote(Binance.DocsParser.functionize_name(item))(unquote_splicing(arg_names)) do + + # fx without opts + @spec unquote(Binance.DocsParser.functionize_name(item))(unquote_splicing(spec)) :: + {:ok, any()} | {:error, any()} + + # fx with opts + @spec unquote(Binance.DocsParser.functionize_name(item))( + unquote_splicing(spec), + unquote(optional_args) + ) :: + {:ok, any()} | {:error, any()} + + def unquote(Binance.DocsParser.functionize_name(item))( + unquote_splicing(arg_names), + opts \\ [] + ) do binding = binding() + # merge all passed args together, so opts + passed + all_passed_args = Keyword.merge(binding, opts) |> Keyword.drop([:opts]) + IO.puts("API call: #{unquote(method)} " <> unquote(url)) IO.puts("binding:") IO.inspect(binding) + IO.puts("passed args:") + IO.inspect(all_passed_args) + + adjusted_args = + case Keyword.has_key?(all_passed_args, :timestamp) do + false -> + Keyword.put_new(all_passed_args, :timestamp, :os.system_time(:millisecond)) + + true -> + all_passed_args + end + |> Enum.into(%{}) - args = %{ - timestamp: :os.system_time(:millisecond) - } + IO.puts("adjusted args:") + IO.inspect(all_passed_args) if unquote(needs_auth) do - case HTTPClient.signed_request_binance(unquote(url), args, unquote(method)) do + case HTTPClient.signed_request_binance(unquote(url), adjusted_args, unquote(method)) do {:ok, %{"code" => code, "msg" => msg}} -> {:error, {:binance_error, %{code: code, msg: msg}}} @@ -77,7 +136,7 @@ docs data end else - case HTTPClient.unsigned_request_binance(unquote(url), args, unquote(method)) do + case HTTPClient.unsigned_request_binance(unquote(url), adjusted_args, unquote(method)) do {:ok, %{"code" => code, "msg" => msg}} -> {:error, {:binance_error, %{code: code, msg: msg}}} From 8163289166c67acc7fb12e7841d081d19721dd64 Mon Sep 17 00:00:00 2001 From: David Mohl Date: Sat, 1 Jul 2023 20:10:59 +1000 Subject: [PATCH 03/25] Generate nicer function names --- lib/binance/docs_parser.ex | 26 +++++++++++++++++++++++--- lib/binance2.ex | 11 +++++++---- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/lib/binance/docs_parser.ex b/lib/binance/docs_parser.ex index 692287a..46a164a 100644 --- a/lib/binance/docs_parser.ex +++ b/lib/binance/docs_parser.ex @@ -1,4 +1,23 @@ defmodule Binance.DocsParser do + defp gen_fx_name(path, method) do + # find everything in the path after v1/v2/v3 + path_name = + path + |> Enum.reverse() + |> Enum.take_while(fn item -> + !(String.length(item) == 2 && String.starts_with?(item, "v")) + end) + |> Enum.reverse() + |> Enum.join("_") + |> Macro.underscore() + |> String.replace("-", "_") + + method = method |> String.downcase() + + "#{method}_#{path_name}" + |> String.to_atom() + end + defp normalize_entry_item( %{ "name" => name, @@ -17,7 +36,8 @@ defmodule Binance.DocsParser do path: path, needs_auth?: Enum.find(params, nil, &(&1.name == "signature")) != nil, unique_key: "#{String.downcase(method)}_#{Enum.join(path, "_")}", - description: Map.get(args["request"], "description", "") + description: Map.get(args["request"], "description", ""), + fx_name: gen_fx_name(path, method) } end @@ -54,8 +74,8 @@ defmodule Binance.DocsParser do |> List.flatten() # remove duplicates |> Enum.reduce(%{}, fn item, acc -> - IO.puts(item.unique_key) - Map.put(acc, item.unique_key, item) + IO.puts(item.fx_name) + Map.put(acc, item.fx_name, item) end) |> Map.values(), group: name diff --git a/lib/binance2.ex b/lib/binance2.ex index 50b796a..1941b63 100644 --- a/lib/binance2.ex +++ b/lib/binance2.ex @@ -19,6 +19,9 @@ docs url = "/" <> Path.join(path) needs_auth = item.needs_auth? description = item.description + fx_name = item.fx_name + + IO.puts("generating #{fx_name} (#{url})") mandatory_params = Enum.filter(params, fn param -> @@ -47,7 +50,7 @@ docs spec = mandatory_params - |> Enum.map(fn item -> quote do: any() end) + |> Enum.map(fn _item -> quote do: any() end) optional_args = optional_params @@ -89,17 +92,17 @@ docs """ # fx without opts - @spec unquote(Binance.DocsParser.functionize_name(item))(unquote_splicing(spec)) :: + @spec unquote(fx_name)(unquote_splicing(spec)) :: {:ok, any()} | {:error, any()} # fx with opts - @spec unquote(Binance.DocsParser.functionize_name(item))( + @spec unquote(fx_name)( unquote_splicing(spec), unquote(optional_args) ) :: {:ok, any()} | {:error, any()} - def unquote(Binance.DocsParser.functionize_name(item))( + def unquote(fx_name)( unquote_splicing(arg_names), opts \\ [] ) do From ffe5a12691a6113c8f440ffa5e0e12c06dad17ae Mon Sep 17 00:00:00 2001 From: David Mohl Date: Sat, 1 Jul 2023 20:24:47 +1000 Subject: [PATCH 04/25] Only add timestamp when it's required --- lib/binance/docs_parser.ex | 6 +++++- lib/binance2.ex | 16 ++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/lib/binance/docs_parser.ex b/lib/binance/docs_parser.ex index 46a164a..bfd5588 100644 --- a/lib/binance/docs_parser.ex +++ b/lib/binance/docs_parser.ex @@ -35,6 +35,7 @@ defmodule Binance.DocsParser do query: params, path: path, needs_auth?: Enum.find(params, nil, &(&1.name == "signature")) != nil, + needs_timestamp?: Enum.find(params, nil, &(&1.name == "timestamp")) != nil, unique_key: "#{String.downcase(method)}_#{Enum.join(path, "_")}", description: Map.get(args["request"], "description", ""), fx_name: gen_fx_name(path, method) @@ -74,7 +75,10 @@ defmodule Binance.DocsParser do |> List.flatten() # remove duplicates |> Enum.reduce(%{}, fn item, acc -> - IO.puts(item.fx_name) + if Map.has_key?(acc, item.fx_name) do + IO.puts("overwriting: #{item.fx_name}") + end + Map.put(acc, item.fx_name, item) end) |> Map.values(), diff --git a/lib/binance2.ex b/lib/binance2.ex index 1941b63..65f9297 100644 --- a/lib/binance2.ex +++ b/lib/binance2.ex @@ -18,10 +18,11 @@ docs name = item.name url = "/" <> Path.join(path) needs_auth = item.needs_auth? + needs_timestamp = item.needs_timestamp? description = item.description fx_name = item.fx_name - IO.puts("generating #{fx_name} (#{url})") + IO.puts(" generating #{fx_name} (#{url})") mandatory_params = Enum.filter(params, fn param -> @@ -117,13 +118,20 @@ docs IO.puts("passed args:") IO.inspect(all_passed_args) + # if the call requires a timestamp, we add it adjusted_args = - case Keyword.has_key?(all_passed_args, :timestamp) do + case unquote(needs_timestamp) do false -> - Keyword.put_new(all_passed_args, :timestamp, :os.system_time(:millisecond)) + all_passed_args true -> - all_passed_args + case Keyword.has_key?(all_passed_args, :timestamp) do + false -> + Keyword.put_new(all_passed_args, :timestamp, :os.system_time(:millisecond)) + + true -> + all_passed_args + end end |> Enum.into(%{}) From 63557b61c5c31390079ab86a290d62aeb10a3991 Mon Sep 17 00:00:00 2001 From: David Mohl Date: Sat, 1 Jul 2023 20:28:00 +1000 Subject: [PATCH 05/25] Rename Binance2 -> Binance --- lib/binance.ex | 899 ++++++------------------------------- lib/binance/docs_parser.ex | 4 +- lib/binance2.ex | 161 ------- lib/binance_old.ex | 786 ++++++++++++++++++++++++++++++++ 4 files changed, 926 insertions(+), 924 deletions(-) delete mode 100644 lib/binance2.ex create mode 100644 lib/binance_old.ex diff --git a/lib/binance.ex b/lib/binance.ex index c6708da..4f92d0a 100644 --- a/lib/binance.ex +++ b/lib/binance.ex @@ -1,786 +1,161 @@ defmodule Binance do - alias Binance.Rest.HTTPClient - - # Server - - @doc """ - Pings binance API. Returns `{:ok, %{}}` if successful, `{:error, reason}` otherwise - """ - def ping() do - HTTPClient.get_binance("/api/v3/ping") - end - - @doc """ - Get binance server time in unix epoch. - - Returns `{:ok, time}` if successful, `{:error, reason}` otherwise - - ## Example - ``` - {:ok, 1515390701097} - ``` - - """ - def get_server_time() do - case HTTPClient.get_binance("/api/v3/time") do - {:ok, %{"serverTime" => time}} -> {:ok, time} - err -> err - end - end - - def get_exchange_info() do - case HTTPClient.get_binance("/api/v3/exchangeInfo") do - {:ok, data} -> {:ok, Binance.ExchangeInfo.new(data)} - err -> err - end - end - - @doc """ - Get historical trades - https://binance-docs.github.io/apidocs/spot/en/#old-trade-lookup - - Returns `{:ok, [%Binance.HistoricalTrade{}]}` or `{:error, reason}`. - - ## Example - {:ok, - [%Binance.HistoricalTrade{ - id: 192180149, - is_best_match: true, - is_buyer_maker: true, - price: "1.79878000", - qty: "55.50000000", - quote_qty: "99.83229000", - time: 1618341167715 - }] - } - """ - def get_historical_trades(symbol, limit, from_id) - when is_binary(symbol) and is_integer(limit) do - arguments = - %{ - symbol: symbol, - limit: limit - } - |> Map.merge( - unless( - is_nil(from_id), - do: %{fromId: from_id}, - else: %{} - ) - ) - - case HTTPClient.unsigned_request_binance( - "/api/v3/historicalTrades", - arguments, - :get - ) do - {:ok, data} -> - {:ok, Enum.map(data, &Binance.HistoricalTrade.new(&1))} - - {:error, err} -> - err - end - end - - # Ticker - - @doc """ - Get all symbols and current prices listed in binance - - Returns `{:ok, [%Binance.SymbolPrice{}]}` or `{:error, reason}`. - - ## Example - ``` - {:ok, - [%Binance.SymbolPrice{price: "0.07579300", symbol: "ETHBTC"}, - %Binance.SymbolPrice{price: "0.01670200", symbol: "LTCBTC"}, - %Binance.SymbolPrice{price: "0.00114550", symbol: "BNBBTC"}, - %Binance.SymbolPrice{price: "0.00640000", symbol: "NEOBTC"}, - %Binance.SymbolPrice{price: "0.00030000", symbol: "123456"}, - %Binance.SymbolPrice{price: "0.04895000", symbol: "QTUMETH"}, - ...]} - ``` - """ - def get_all_prices() do - case HTTPClient.get_binance("/api/v3/ticker/price") do - {:ok, data} -> - {:ok, Enum.map(data, &Binance.SymbolPrice.new(&1))} - - err -> - err - end - end - - @doc """ - Retrieves the current ticker information for the given trade pair. - - Symbol can be a binance symbol in the form of `"ETHBTC"` or `%Binance.TradePair{}`. - - Returns `{:ok, %Binance.Ticker{}}` or `{:error, reason}` - - ## Example - ``` - {:ok, - %Binance.Ticker{ask_price: "0.07548800", bid_price: "0.07542100", - close_time: 1515391124878, count: 661676, first_id: 16797673, - high_price: "0.07948000", last_id: 17459348, last_price: "0.07542000", - low_price: "0.06330000", open_price: "0.06593800", open_time: 1515304724878, - prev_close_price: "0.06593800", price_change: "0.00948200", - price_change_percent: "14.380", volume: "507770.18500000", - weighted_avg_price: "0.06946930"}} - ``` - """ - def get_ticker(%Binance.TradePair{} = symbol) do - case find_symbol(symbol) do - {:ok, binance_symbol} -> get_ticker(binance_symbol) - e -> e - end - end - - def get_ticker(symbol) when is_binary(symbol) do - case HTTPClient.get_binance("/api/v3/ticker/24hr?symbol=#{symbol}") do - {:ok, data} -> {:ok, Binance.Ticker.new(data)} - err -> err - end - end - - @doc """ - Retrieves klines for a symbol, provided a given interval, e.g. "1h". - - Function can also take in a 'limit' argument to reduce the number of intervals. - - Returns `{:ok, [%Binance.Kline{}]` or `{:error, reason}` - - ## Example - ``` - {:ok, - [ - %Binance.Kline{ - close: "0.16527000", - close_time: 1617861599999, - high: "0.17100000", - ignore: "0", - low: "0.16352000", - number_of_trades: 16167, - open: "0.17088000", - open_time: 1617858000000, - quote_asset_volume: "7713624.32966000", - taker_buy_base_asset_volume: "22020677.70000000", - taker_buy_quote_asset_volume: "3668705.43042700", - volume: "46282422.20000000" - }, - %Binance.Kline{ - ... - ``` - """ - - def get_klines(symbol, interval, limit \\ 500) when is_binary(symbol) do - case HTTPClient.get_binance( - "/api/v3/klines?symbol=#{symbol}&interval=#{interval}&limit=#{limit}" - ) do - {:ok, data} -> - {:ok, Enum.map(data, &Binance.Kline.new(&1))} - - err -> - err - end - end - - @doc """ - Retrieves the bids & asks of the order book up to the depth for the given symbol - - Returns `{:ok, %{bids: [...], asks: [...], lastUpdateId: 12345}}` or `{:error, reason}` - - ## Example - ``` - {:ok, - %Binance.OrderBook{ - asks: [ - ["8400.00000000", "2.04078100", []], - ["8405.35000000", "0.50354700", []], - ["8406.00000000", "0.32769800", []], - ["8406.33000000", "0.00239000", []], - ["8406.51000000", "0.03241000", []] - ], - bids: [ - ["8393.00000000", "0.20453200", []], - ["8392.57000000", "0.02639000", []], - ["8392.00000000", "1.40893300", []], - ["8390.09000000", "0.07047100", []], - ["8388.72000000", "0.04577400", []] - ], - last_update_id: 113634395 - } - } - ``` - """ - def get_depth(symbol, limit) do - case HTTPClient.get_binance("/api/v3/depth?symbol=#{symbol}&limit=#{limit}") do - {:ok, data} -> {:ok, Binance.OrderBook.new(data)} - err -> err - end - end - - @doc """ - Fetches system status. - - Returns `{:ok, %Binance.SystemStatus{}}` or `{:error, reason}`. - """ - def get_system_status() do - case HTTPClient.get_binance("/sapi/v1/system/status") do - {:ok, data} -> {:ok, Binance.SystemStatus.new(data)} - error -> error - end - end - - # Account - - @doc """ - Fetches user account from binance - - Returns `{:ok, %Binance.Account{}}` or `{:error, reason}`. - - In the case of a error on binance, for example with invalid parameters, `{:error, {:binance_error, %{code: code, msg: msg}}}` will be returned. - - Please read https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md#account-information-user_data to understand API - """ - - def get_account() do - api_key = Application.get_env(:binance, :api_key) - secret_key = Application.get_env(:binance, :secret_key) - - case HTTPClient.get_binance("/api/v3/account", %{}, secret_key, api_key) do - {:ok, data} -> {:ok, Binance.Account.new(data)} - error -> error - end - end - - # User data streams - - @doc """ - Creates a socket listen key that later can be used as parameter to listen for - user related events. - - Returns `{:ok, %Binance.DataStream{}}` or `{:error, reason}`. - - ## Example - ``` - {:ok, - %Binance.DataStream{ - listen_key: "pqia91ma19a5s61cv6a81va65sdf19v8a65a1a5s61cv6a81va65sdf19v8a65a1" - } - } - ``` - - For more context please read https://github.com/binance/binance-spot-api-docs/blob/master/user-data-stream.md#create-a-listenkey - - """ - def create_listen_key() do - case HTTPClient.unsigned_request_binance("/api/v3/userDataStream", "", :post) do - {:ok, data} -> {:ok, Binance.DataStream.new(data)} - error -> error - end - end - - @doc """ - Socket listen key expires after 30 minutes withouth a pong response, this - allows keeping it alive. - - Returns `{:ok, %{}}` or `{:error, reason}`. - - For more context please read https://github.com/binance/binance-spot-api-docs/blob/master/user-data-stream.md#pingkeep-alive-a-listenkey - - """ - def keep_alive_listen_key(key) do - case HTTPClient.unsigned_request_binance( - "/api/v3/userDataStream", - "listenKey=#{key}", - :put - ) do - {:ok, data} -> {:ok, data} - error -> error - end - end - - @doc """ - Closes/disables the listen key. To be used when you stop listening to the - stream. - - Returns `{:ok, %{}}` or `{:error, reason}`. - - For more context please read https://github.com/binance/binance-spot-api-docs/blob/master/user-data-stream.md#close-a-listenkey - - """ - def close_listen_key(key) do - case HTTPClient.unsigned_request_binance( - "/api/v3/userDataStream?listenKey=#{key}", - nil, - :delete - ) do - {:ok, data} -> {:ok, data} - error -> error - end - end - - # Order - - @doc """ - Creates a new order on binance - - Returns `{:ok, %{}}` or `{:error, reason}`. - - In the case of a error on binance, for example with invalid parameters, `{:error, {:binance_error, %{code: code, msg: msg}}}` will be returned. - - Please read https://www.binance.com/restapipub.html#user-content-account-endpoints to understand all the parameters - """ - def create_order( - symbol, - side, - type, - quantity, - price \\ nil, - time_in_force \\ nil, - new_client_order_id \\ nil, - stop_price \\ nil, - iceberg_quantity \\ nil, - receiving_window \\ 1000, - timestamp \\ nil - ) do - timestamp = - case timestamp do - # timestamp needs to be in milliseconds - nil -> - :os.system_time(:millisecond) - - t -> - t - end - - arguments = - %{ - symbol: symbol, - side: side, - type: type, - quantity: quantity, - timestamp: timestamp, - recvWindow: receiving_window - } - |> Map.merge( - unless( - is_nil(new_client_order_id), - do: %{newClientOrderId: new_client_order_id}, - else: %{} - ) - ) - |> Map.merge( - unless(is_nil(stop_price), do: %{stopPrice: format_price(stop_price)}, else: %{}) - ) - |> Map.merge( - unless(is_nil(iceberg_quantity), do: %{icebergQty: iceberg_quantity}, else: %{}) - ) - |> Map.merge(unless(is_nil(time_in_force), do: %{timeInForce: time_in_force}, else: %{})) - |> Map.merge(unless(is_nil(price), do: %{price: format_price(price)}, else: %{})) - - case HTTPClient.signed_request_binance("/api/v3/order", arguments, :post) do - {:ok, %{"code" => code, "msg" => msg}} -> - {:error, {:binance_error, %{code: code, msg: msg}}} - - data -> - data - end - end - - @doc """ - Creates a new **limit** **buy** order - - Symbol can be a binance symbol in the form of `"ETHBTC"` or `%Binance.TradePair{}`. - - Returns `{:ok, %{}}` or `{:error, reason}` - """ - def order_limit_buy(symbol, quantity, price, time_in_force \\ "GTC") - - def order_limit_buy( - %Binance.TradePair{from: from, to: to} = symbol, - quantity, - price, - time_in_force - ) - when is_number(quantity) - when is_number(price) - when is_binary(from) - when is_binary(to) do - case find_symbol(symbol) do - {:ok, binance_symbol} -> order_limit_buy(binance_symbol, quantity, price, time_in_force) - e -> e - end - end - - def order_limit_buy(symbol, quantity, price, time_in_force) - when is_binary(symbol) - when is_number(quantity) - when is_number(price) do - create_order(symbol, "BUY", "LIMIT", quantity, price, time_in_force) - |> parse_order_response - end - - @doc """ - Creates a new **limit** **sell** order - - Symbol can be a binance symbol in the form of `"ETHBTC"` or `%Binance.TradePair{}`. - - Returns `{:ok, %{}}` or `{:error, reason}` - """ - def order_limit_sell(symbol, quantity, price, time_in_force \\ "GTC") - - def order_limit_sell( - %Binance.TradePair{from: from, to: to} = symbol, - quantity, - price, - time_in_force - ) - when is_number(quantity) - when is_number(price) - when is_binary(from) - when is_binary(to) do - case find_symbol(symbol) do - {:ok, binance_symbol} -> order_limit_sell(binance_symbol, quantity, price, time_in_force) - e -> e - end - end - - def order_limit_sell(symbol, quantity, price, time_in_force) - when is_binary(symbol) - when is_number(quantity) - when is_number(price) do - create_order(symbol, "SELL", "LIMIT", quantity, price, time_in_force) - |> parse_order_response - end - - @doc """ - Creates a new **market** **buy** order - - Symbol can be a binance symbol in the form of `"ETHBTC"` or `%Binance.TradePair{}`. - - Returns `{:ok, %{}}` or `{:error, reason}` - """ - def order_market_buy(%Binance.TradePair{from: from, to: to} = symbol, quantity) - when is_number(quantity) - when is_binary(from) - when is_binary(to) do - case find_symbol(symbol) do - {:ok, binance_symbol} -> order_market_buy(binance_symbol, quantity) - e -> e - end - end - - def order_market_buy(symbol, quantity) - when is_binary(symbol) - when is_number(quantity) do - create_order(symbol, "BUY", "MARKET", quantity) - end - - @doc """ - Creates a new **market** **sell** order - - Symbol can be a binance symbol in the form of `"ETHBTC"` or `%Binance.TradePair{}`. - - Returns `{:ok, %{}}` or `{:error, reason}` - """ - def order_market_sell(%Binance.TradePair{from: from, to: to} = symbol, quantity) - when is_number(quantity) - when is_binary(from) - when is_binary(to) do - case find_symbol(symbol) do - {:ok, binance_symbol} -> order_market_sell(binance_symbol, quantity) - e -> e - end - end - - def order_market_sell(symbol, quantity) - when is_binary(symbol) - when is_number(quantity) do - create_order(symbol, "SELL", "MARKET", quantity) - end - - defp parse_order_response({:ok, response}) do - {:ok, Binance.OrderResponse.new(response)} - end - - defp parse_order_response({ - :error, - { - :binance_error, - %{code: -2010, msg: "Account has insufficient balance for requested action."} = reason - } - }) do - {:error, %Binance.InsufficientBalanceError{reason: reason}} - end - - # Misc - - defp format_price(num) when is_float(num), do: :erlang.float_to_binary(num, [{:decimals, 8}]) - defp format_price(num) when is_integer(num), do: inspect(num) - defp format_price(num) when is_binary(num), do: num - - @doc """ - Searches and normalizes the symbol as it is listed on binance. - - To retrieve this information, a request to the binance API is done. The result is then **cached** to ensure the request is done only once. - - Order of which symbol comes first, and case sensitivity does not matter. - - Returns `{:ok, "SYMBOL"}` if successfully, or `{:error, reason}` otherwise. - - ## Examples - These 3 calls will result in the same result string: - ``` - find_symbol(%Binance.TradePair{from: "ETH", to: "REQ"}) - ``` - ``` - find_symbol(%Binance.TradePair{from: "REQ", to: "ETH"}) - ``` - ``` - find_symbol(%Binance.TradePair{from: "rEq", to: "eTH"}) - ``` - - Result: `{:ok, "REQETH"}` +end - """ - def find_symbol(%Binance.TradePair{from: from, to: to} = tp) - when is_binary(from) - when is_binary(to) do - case Binance.SymbolCache.get() do - # cache hit - {:ok, data} -> - from = String.upcase(from) - to = String.upcase(to) +docs = Binance.DocsParser.get_documentation() + +docs +|> Enum.each(fn api_group -> + IO.puts("parsing group: #{api_group.group}") + + defmodule Binance.DocsParser.modularize_name(api_group.group) do + alias Binance.Rest.HTTPClient + + api_group.items + |> Enum.each(fn item -> + method = item.method + path = item.path + params = item.query + name = item.name + url = "/" <> Path.join(path) + needs_auth = item.needs_auth? + needs_timestamp = item.needs_timestamp? + description = item.description + fx_name = item.fx_name + + IO.puts(" generating #{fx_name} (#{url})") + + mandatory_params = + Enum.filter(params, fn param -> + param.optional == false + end) + |> Enum.map(fn param -> + %{name: param.name, description: param.description} + end) + |> Enum.filter(&(&1.name != "timestamp")) + |> Enum.filter(&(&1.name != "signature")) + + optional_params = + Enum.filter(params, fn param -> + param.optional == true + end) + |> Enum.map(fn param -> + %{name: param.name, description: param.description} + end) + |> Enum.filter(&(&1.name != "timestamp")) + |> Enum.filter(&(&1.name != "signature")) + + # generate mandatory params + arg_names = + mandatory_params + |> Enum.map(&(Map.get(&1, :name) |> String.to_atom() |> Macro.var(nil))) + + spec = + mandatory_params + |> Enum.map(fn _item -> quote do: any() end) + + optional_args = + optional_params + |> Enum.reduce([], fn item, acc -> + name = item.name + + case acc do + [] -> + quote do: {unquote(String.to_atom(name)), any()} + + val -> + quote do: + {unquote(String.to_atom(name)), any()} + | unquote(val) + end + end) + |> case do + [] -> [] + e -> [e] + end - found = Enum.filter(data, &Enum.member?([from <> to, to <> from], &1)) + @doc """ + #{name} - case Enum.count(found) do - 1 -> {:ok, found |> List.first()} - 0 -> {:error, :symbol_not_found} - end + #{description} - # cache miss - {:error, :not_initialized} -> - case get_all_prices() do - {:ok, price_data} -> - price_data - |> Enum.map(fn x -> x.symbol end) - |> Binance.SymbolCache.store() + Details: - find_symbol(tp) + - METHOD: #{method} + - URL: #{url} - err -> - err - end + Mandatory params: - err -> - err - end - end + #{Enum.map(mandatory_params, fn item -> "- #{item.name} - #{item.description}" end) |> Enum.join("\n")} - # Open orders - - @doc """ - Get all open orders, alternatively open orders by symbol - - Returns `{:ok, [%Binance.Order{}]}` or `{:error, reason}`. - - Weight: 1 for a single symbol; 40 when the symbol parameter is omitted - - ## Example - ``` - {:ok, - [%Binance.Order{price: "0.1", origQty: "1.0", executedQty: "0.0", ...}, - %Binance.Order{...}, - %Binance.Order{...}, - %Binance.Order{...}, - %Binance.Order{...}, - %Binance.Order{...}, - ...]} - ``` - """ - def get_open_orders() do - api_key = Application.get_env(:binance, :api_key) - secret_key = Application.get_env(:binance, :secret_key) - - case HTTPClient.get_binance("/api/v3/openOrders", %{}, secret_key, api_key) do - {:ok, data} -> {:ok, Enum.map(data, &Binance.Order.new(&1))} - err -> err - end - end + Optional params: - def get_open_orders(%Binance.TradePair{} = symbol) do - case find_symbol(symbol) do - {:ok, binance_symbol} -> get_open_orders(binance_symbol) - e -> e - end - end + #{Enum.map(optional_params, fn item -> "- #{item.name} - #{item.description}" end) |> Enum.join("\n")} + """ - def get_open_orders(symbol) when is_binary(symbol) do - api_key = Application.get_env(:binance, :api_key) - secret_key = Application.get_env(:binance, :secret_key) + # fx without opts + @spec unquote(fx_name)(unquote_splicing(spec)) :: + {:ok, any()} | {:error, any()} - case HTTPClient.get_binance("/api/v3/openOrders", %{:symbol => symbol}, secret_key, api_key) do - {:ok, data} -> {:ok, Enum.map(data, &Binance.Order.new(&1))} - err -> err - end - end + # fx with opts + @spec unquote(fx_name)( + unquote_splicing(spec), + unquote(optional_args) + ) :: + {:ok, any()} | {:error, any()} - # Order + def unquote(fx_name)( + unquote_splicing(arg_names), + opts \\ [] + ) do + binding = binding() - @doc """ - Get order by symbol, timestamp and either orderId or origClientOrderId are mandatory + # merge all passed args together, so opts + passed + all_passed_args = Keyword.merge(binding, opts) |> Keyword.drop([:opts]) - Returns `{:ok, [%Binance.Order{}]}` or `{:error, reason}`. + IO.puts("API call: #{unquote(method)} " <> unquote(url)) + IO.puts("binding:") + IO.inspect(binding) + IO.puts("passed args:") + IO.inspect(all_passed_args) - Weight: 1 + # if the call requires a timestamp, we add it + adjusted_args = + case unquote(needs_timestamp) do + false -> + all_passed_args - ## Example - ``` - {:ok, %Binance.Order{price: "0.1", origQty: "1.0", executedQty: "0.0", ...}} - ``` + true -> + case Keyword.has_key?(all_passed_args, :timestamp) do + false -> + Keyword.put_new(all_passed_args, :timestamp, :os.system_time(:millisecond)) - Info: https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md#query-order-user_data - """ - def get_order( - symbol, - timestamp, - order_id \\ nil, - orig_client_order_id \\ nil, - recv_window \\ nil - ) do - case is_binary(symbol) do - true -> - fetch_order(symbol, timestamp, order_id, orig_client_order_id, recv_window) + true -> + all_passed_args + end + end + |> Enum.into(%{}) - false -> - case find_symbol(symbol) do - {:ok, binance_symbol} -> - fetch_order(binance_symbol, timestamp, order_id, orig_client_order_id, recv_window) + IO.puts("adjusted args:") + IO.inspect(all_passed_args) - e -> - e - end - end - end + if unquote(needs_auth) do + case HTTPClient.signed_request_binance(unquote(url), adjusted_args, unquote(method)) do + {:ok, %{"code" => code, "msg" => msg}} -> + {:error, {:binance_error, %{code: code, msg: msg}}} - def fetch_order(symbol, timestamp, order_id, orig_client_order_id, recv_window) - when is_binary(symbol) - when is_integer(timestamp) - when is_integer(order_id) or is_binary(orig_client_order_id) do - api_key = Application.get_env(:binance, :api_key) - secret_key = Application.get_env(:binance, :secret_key) - - arguments = - %{ - symbol: symbol, - timestamp: timestamp - } - |> Map.merge(unless(is_nil(order_id), do: %{orderId: order_id}, else: %{})) - |> Map.merge( - unless( - is_nil(orig_client_order_id), - do: %{origClientOrderId: orig_client_order_id}, - else: %{} - ) - ) - |> Map.merge(unless(is_nil(recv_window), do: %{recvWindow: recv_window}, else: %{})) - - case HTTPClient.get_binance("/api/v3/order", arguments, secret_key, api_key) do - {:ok, data} -> {:ok, Binance.Order.new(data)} - err -> err - end - end + data -> + data + end + else + case HTTPClient.unsigned_request_binance(unquote(url), adjusted_args, unquote(method)) do + {:ok, %{"code" => code, "msg" => msg}} -> + {:error, {:binance_error, %{code: code, msg: msg}}} - @doc """ - Cancel an active order.. - - Symbol and either orderId or origClientOrderId must be sent. - - Returns `{:ok, %Binance.Order{}}` or `{:error, reason}`. - - Weight: 1 - - Info: https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md#cancel-order-trade - """ - def cancel_order( - symbol, - timestamp, - order_id \\ nil, - orig_client_order_id \\ nil, - new_client_order_id \\ nil, - recv_window \\ nil - ) do - case is_binary(symbol) do - true -> - cancel_order_( - symbol, - timestamp, - order_id, - orig_client_order_id, - new_client_order_id, - recv_window - ) - - false -> - case find_symbol(symbol) do - {:ok, binance_symbol} -> - cancel_order_( - binance_symbol, - timestamp, - order_id, - orig_client_order_id, - new_client_order_id, - recv_window - ) - - e -> - e + data -> + data + end end - end - end - - defp cancel_order_( - symbol, - timestamp, - order_id, - orig_client_order_id, - new_client_order_id, - recv_window - ) - when is_binary(symbol) - when is_integer(timestamp) - when is_integer(order_id) or is_binary(orig_client_order_id) do - api_key = Application.get_env(:binance, :api_key) - secret_key = Application.get_env(:binance, :secret_key) - - arguments = - %{ - symbol: symbol, - timestamp: timestamp - } - |> Map.merge(unless(is_nil(order_id), do: %{orderId: order_id}, else: %{})) - |> Map.merge( - unless( - is_nil(orig_client_order_id), - do: %{origClientOrderId: orig_client_order_id}, - else: %{} - ) - ) - |> Map.merge( - unless(is_nil(new_client_order_id), - do: %{newClientOrderId: new_client_order_id}, - else: %{} - ) - ) - |> Map.merge(unless(is_nil(recv_window), do: %{recvWindow: recv_window}, else: %{})) - - case HTTPClient.delete_binance("/api/v3/order", arguments, secret_key, api_key) do - {:ok, data} -> {:ok, Binance.Order.new(data)} - err -> err - end + end + end) end -end +end) diff --git a/lib/binance/docs_parser.ex b/lib/binance/docs_parser.ex index bfd5588..28d0474 100644 --- a/lib/binance/docs_parser.ex +++ b/lib/binance/docs_parser.ex @@ -1,4 +1,6 @@ defmodule Binance.DocsParser do + @moduledoc false + defp gen_fx_name(path, method) do # find everything in the path after v1/v2/v3 path_name = @@ -103,7 +105,7 @@ defmodule Binance.DocsParser do |> String.replace("/", "") |> String.capitalize() |> String.to_atom() - |> (&Module.concat(Binance2, &1)).() + |> (&Module.concat(Binance, &1)).() end def functionize_name(%{method: method, path: path}) do diff --git a/lib/binance2.ex b/lib/binance2.ex deleted file mode 100644 index 65f9297..0000000 --- a/lib/binance2.ex +++ /dev/null @@ -1,161 +0,0 @@ -defmodule Binance2 do -end - -docs = Binance.DocsParser.get_documentation() - -docs -|> Enum.each(fn api_group -> - IO.puts("parsing group: #{api_group.group}") - - defmodule Binance.DocsParser.modularize_name(api_group.group) do - alias Binance.Rest.HTTPClient - - api_group.items - |> Enum.each(fn item -> - method = item.method - path = item.path - params = item.query - name = item.name - url = "/" <> Path.join(path) - needs_auth = item.needs_auth? - needs_timestamp = item.needs_timestamp? - description = item.description - fx_name = item.fx_name - - IO.puts(" generating #{fx_name} (#{url})") - - mandatory_params = - Enum.filter(params, fn param -> - param.optional == false - end) - |> Enum.map(fn param -> - %{name: param.name, description: param.description} - end) - |> Enum.filter(&(&1.name != "timestamp")) - |> Enum.filter(&(&1.name != "signature")) - - optional_params = - Enum.filter(params, fn param -> - param.optional == true - end) - |> Enum.map(fn param -> - %{name: param.name, description: param.description} - end) - |> Enum.filter(&(&1.name != "timestamp")) - |> Enum.filter(&(&1.name != "signature")) - - # generate mandatory params - arg_names = - mandatory_params - |> Enum.map(&(Map.get(&1, :name) |> String.to_atom() |> Macro.var(nil))) - - spec = - mandatory_params - |> Enum.map(fn _item -> quote do: any() end) - - optional_args = - optional_params - |> Enum.reduce([], fn item, acc -> - name = item.name - - case acc do - [] -> - quote do: {unquote(String.to_atom(name)), any()} - - val -> - quote do: - {unquote(String.to_atom(name)), any()} - | unquote(val) - end - end) - |> case do - [] -> [] - e -> [e] - end - - @doc """ - #{name} - - #{description} - - Details: - - - METHOD: #{method} - - URL: #{url} - - Mandatory params: - - #{Enum.map(mandatory_params, fn item -> "- #{item.name} - #{item.description}" end) |> Enum.join("\n")} - - Optional params: - - #{Enum.map(optional_params, fn item -> "- #{item.name} - #{item.description}" end) |> Enum.join("\n")} - """ - - # fx without opts - @spec unquote(fx_name)(unquote_splicing(spec)) :: - {:ok, any()} | {:error, any()} - - # fx with opts - @spec unquote(fx_name)( - unquote_splicing(spec), - unquote(optional_args) - ) :: - {:ok, any()} | {:error, any()} - - def unquote(fx_name)( - unquote_splicing(arg_names), - opts \\ [] - ) do - binding = binding() - - # merge all passed args together, so opts + passed - all_passed_args = Keyword.merge(binding, opts) |> Keyword.drop([:opts]) - - IO.puts("API call: #{unquote(method)} " <> unquote(url)) - IO.puts("binding:") - IO.inspect(binding) - IO.puts("passed args:") - IO.inspect(all_passed_args) - - # if the call requires a timestamp, we add it - adjusted_args = - case unquote(needs_timestamp) do - false -> - all_passed_args - - true -> - case Keyword.has_key?(all_passed_args, :timestamp) do - false -> - Keyword.put_new(all_passed_args, :timestamp, :os.system_time(:millisecond)) - - true -> - all_passed_args - end - end - |> Enum.into(%{}) - - IO.puts("adjusted args:") - IO.inspect(all_passed_args) - - if unquote(needs_auth) do - case HTTPClient.signed_request_binance(unquote(url), adjusted_args, unquote(method)) do - {:ok, %{"code" => code, "msg" => msg}} -> - {:error, {:binance_error, %{code: code, msg: msg}}} - - data -> - data - end - else - case HTTPClient.unsigned_request_binance(unquote(url), adjusted_args, unquote(method)) do - {:ok, %{"code" => code, "msg" => msg}} -> - {:error, {:binance_error, %{code: code, msg: msg}}} - - data -> - data - end - end - end - end) - end -end) diff --git a/lib/binance_old.ex b/lib/binance_old.ex new file mode 100644 index 0000000..93707f8 --- /dev/null +++ b/lib/binance_old.ex @@ -0,0 +1,786 @@ +defmodule BinanceOld do + alias Binance.Rest.HTTPClient + + # Server + + @doc """ + Pings binance API. Returns `{:ok, %{}}` if successful, `{:error, reason}` otherwise + """ + def ping() do + HTTPClient.get_binance("/api/v3/ping") + end + + @doc """ + Get binance server time in unix epoch. + + Returns `{:ok, time}` if successful, `{:error, reason}` otherwise + + ## Example + ``` + {:ok, 1515390701097} + ``` + + """ + def get_server_time() do + case HTTPClient.get_binance("/api/v3/time") do + {:ok, %{"serverTime" => time}} -> {:ok, time} + err -> err + end + end + + def get_exchange_info() do + case HTTPClient.get_binance("/api/v3/exchangeInfo") do + {:ok, data} -> {:ok, Binance.ExchangeInfo.new(data)} + err -> err + end + end + + @doc """ + Get historical trades + https://binance-docs.github.io/apidocs/spot/en/#old-trade-lookup + + Returns `{:ok, [%Binance.HistoricalTrade{}]}` or `{:error, reason}`. + + ## Example + {:ok, + [%Binance.HistoricalTrade{ + id: 192180149, + is_best_match: true, + is_buyer_maker: true, + price: "1.79878000", + qty: "55.50000000", + quote_qty: "99.83229000", + time: 1618341167715 + }] + } + """ + def get_historical_trades(symbol, limit, from_id) + when is_binary(symbol) and is_integer(limit) do + arguments = + %{ + symbol: symbol, + limit: limit + } + |> Map.merge( + unless( + is_nil(from_id), + do: %{fromId: from_id}, + else: %{} + ) + ) + + case HTTPClient.unsigned_request_binance( + "/api/v3/historicalTrades", + arguments, + :get + ) do + {:ok, data} -> + {:ok, Enum.map(data, &Binance.HistoricalTrade.new(&1))} + + {:error, err} -> + err + end + end + + # Ticker + + @doc """ + Get all symbols and current prices listed in binance + + Returns `{:ok, [%Binance.SymbolPrice{}]}` or `{:error, reason}`. + + ## Example + ``` + {:ok, + [%Binance.SymbolPrice{price: "0.07579300", symbol: "ETHBTC"}, + %Binance.SymbolPrice{price: "0.01670200", symbol: "LTCBTC"}, + %Binance.SymbolPrice{price: "0.00114550", symbol: "BNBBTC"}, + %Binance.SymbolPrice{price: "0.00640000", symbol: "NEOBTC"}, + %Binance.SymbolPrice{price: "0.00030000", symbol: "123456"}, + %Binance.SymbolPrice{price: "0.04895000", symbol: "QTUMETH"}, + ...]} + ``` + """ + def get_all_prices() do + case HTTPClient.get_binance("/api/v3/ticker/price") do + {:ok, data} -> + {:ok, Enum.map(data, &Binance.SymbolPrice.new(&1))} + + err -> + err + end + end + + @doc """ + Retrieves the current ticker information for the given trade pair. + + Symbol can be a binance symbol in the form of `"ETHBTC"` or `%Binance.TradePair{}`. + + Returns `{:ok, %Binance.Ticker{}}` or `{:error, reason}` + + ## Example + ``` + {:ok, + %Binance.Ticker{ask_price: "0.07548800", bid_price: "0.07542100", + close_time: 1515391124878, count: 661676, first_id: 16797673, + high_price: "0.07948000", last_id: 17459348, last_price: "0.07542000", + low_price: "0.06330000", open_price: "0.06593800", open_time: 1515304724878, + prev_close_price: "0.06593800", price_change: "0.00948200", + price_change_percent: "14.380", volume: "507770.18500000", + weighted_avg_price: "0.06946930"}} + ``` + """ + def get_ticker(%Binance.TradePair{} = symbol) do + case find_symbol(symbol) do + {:ok, binance_symbol} -> get_ticker(binance_symbol) + e -> e + end + end + + def get_ticker(symbol) when is_binary(symbol) do + case HTTPClient.get_binance("/api/v3/ticker/24hr?symbol=#{symbol}") do + {:ok, data} -> {:ok, Binance.Ticker.new(data)} + err -> err + end + end + + @doc """ + Retrieves klines for a symbol, provided a given interval, e.g. "1h". + + Function can also take in a 'limit' argument to reduce the number of intervals. + + Returns `{:ok, [%Binance.Kline{}]` or `{:error, reason}` + + ## Example + ``` + {:ok, + [ + %Binance.Kline{ + close: "0.16527000", + close_time: 1617861599999, + high: "0.17100000", + ignore: "0", + low: "0.16352000", + number_of_trades: 16167, + open: "0.17088000", + open_time: 1617858000000, + quote_asset_volume: "7713624.32966000", + taker_buy_base_asset_volume: "22020677.70000000", + taker_buy_quote_asset_volume: "3668705.43042700", + volume: "46282422.20000000" + }, + %Binance.Kline{ + ... + ``` + """ + + def get_klines(symbol, interval, limit \\ 500) when is_binary(symbol) do + case HTTPClient.get_binance( + "/api/v3/klines?symbol=#{symbol}&interval=#{interval}&limit=#{limit}" + ) do + {:ok, data} -> + {:ok, Enum.map(data, &Binance.Kline.new(&1))} + + err -> + err + end + end + + @doc """ + Retrieves the bids & asks of the order book up to the depth for the given symbol + + Returns `{:ok, %{bids: [...], asks: [...], lastUpdateId: 12345}}` or `{:error, reason}` + + ## Example + ``` + {:ok, + %Binance.OrderBook{ + asks: [ + ["8400.00000000", "2.04078100", []], + ["8405.35000000", "0.50354700", []], + ["8406.00000000", "0.32769800", []], + ["8406.33000000", "0.00239000", []], + ["8406.51000000", "0.03241000", []] + ], + bids: [ + ["8393.00000000", "0.20453200", []], + ["8392.57000000", "0.02639000", []], + ["8392.00000000", "1.40893300", []], + ["8390.09000000", "0.07047100", []], + ["8388.72000000", "0.04577400", []] + ], + last_update_id: 113634395 + } + } + ``` + """ + def get_depth(symbol, limit) do + case HTTPClient.get_binance("/api/v3/depth?symbol=#{symbol}&limit=#{limit}") do + {:ok, data} -> {:ok, Binance.OrderBook.new(data)} + err -> err + end + end + + @doc """ + Fetches system status. + + Returns `{:ok, %Binance.SystemStatus{}}` or `{:error, reason}`. + """ + def get_system_status() do + case HTTPClient.get_binance("/sapi/v1/system/status") do + {:ok, data} -> {:ok, Binance.SystemStatus.new(data)} + error -> error + end + end + + # Account + + @doc """ + Fetches user account from binance + + Returns `{:ok, %Binance.Account{}}` or `{:error, reason}`. + + In the case of a error on binance, for example with invalid parameters, `{:error, {:binance_error, %{code: code, msg: msg}}}` will be returned. + + Please read https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md#account-information-user_data to understand API + """ + + def get_account() do + api_key = Application.get_env(:binance, :api_key) + secret_key = Application.get_env(:binance, :secret_key) + + case HTTPClient.get_binance("/api/v3/account", %{}, secret_key, api_key) do + {:ok, data} -> {:ok, Binance.Account.new(data)} + error -> error + end + end + + # User data streams + + @doc """ + Creates a socket listen key that later can be used as parameter to listen for + user related events. + + Returns `{:ok, %Binance.DataStream{}}` or `{:error, reason}`. + + ## Example + ``` + {:ok, + %Binance.DataStream{ + listen_key: "pqia91ma19a5s61cv6a81va65sdf19v8a65a1a5s61cv6a81va65sdf19v8a65a1" + } + } + ``` + + For more context please read https://github.com/binance/binance-spot-api-docs/blob/master/user-data-stream.md#create-a-listenkey + + """ + def create_listen_key() do + case HTTPClient.unsigned_request_binance("/api/v3/userDataStream", "", :post) do + {:ok, data} -> {:ok, Binance.DataStream.new(data)} + error -> error + end + end + + @doc """ + Socket listen key expires after 30 minutes withouth a pong response, this + allows keeping it alive. + + Returns `{:ok, %{}}` or `{:error, reason}`. + + For more context please read https://github.com/binance/binance-spot-api-docs/blob/master/user-data-stream.md#pingkeep-alive-a-listenkey + + """ + def keep_alive_listen_key(key) do + case HTTPClient.unsigned_request_binance( + "/api/v3/userDataStream", + "listenKey=#{key}", + :put + ) do + {:ok, data} -> {:ok, data} + error -> error + end + end + + @doc """ + Closes/disables the listen key. To be used when you stop listening to the + stream. + + Returns `{:ok, %{}}` or `{:error, reason}`. + + For more context please read https://github.com/binance/binance-spot-api-docs/blob/master/user-data-stream.md#close-a-listenkey + + """ + def close_listen_key(key) do + case HTTPClient.unsigned_request_binance( + "/api/v3/userDataStream?listenKey=#{key}", + nil, + :delete + ) do + {:ok, data} -> {:ok, data} + error -> error + end + end + + # Order + + @doc """ + Creates a new order on binance + + Returns `{:ok, %{}}` or `{:error, reason}`. + + In the case of a error on binance, for example with invalid parameters, `{:error, {:binance_error, %{code: code, msg: msg}}}` will be returned. + + Please read https://www.binance.com/restapipub.html#user-content-account-endpoints to understand all the parameters + """ + def create_order( + symbol, + side, + type, + quantity, + price \\ nil, + time_in_force \\ nil, + new_client_order_id \\ nil, + stop_price \\ nil, + iceberg_quantity \\ nil, + receiving_window \\ 1000, + timestamp \\ nil + ) do + timestamp = + case timestamp do + # timestamp needs to be in milliseconds + nil -> + :os.system_time(:millisecond) + + t -> + t + end + + arguments = + %{ + symbol: symbol, + side: side, + type: type, + quantity: quantity, + timestamp: timestamp, + recvWindow: receiving_window + } + |> Map.merge( + unless( + is_nil(new_client_order_id), + do: %{newClientOrderId: new_client_order_id}, + else: %{} + ) + ) + |> Map.merge( + unless(is_nil(stop_price), do: %{stopPrice: format_price(stop_price)}, else: %{}) + ) + |> Map.merge( + unless(is_nil(iceberg_quantity), do: %{icebergQty: iceberg_quantity}, else: %{}) + ) + |> Map.merge(unless(is_nil(time_in_force), do: %{timeInForce: time_in_force}, else: %{})) + |> Map.merge(unless(is_nil(price), do: %{price: format_price(price)}, else: %{})) + + case HTTPClient.signed_request_binance("/api/v3/order", arguments, :post) do + {:ok, %{"code" => code, "msg" => msg}} -> + {:error, {:binance_error, %{code: code, msg: msg}}} + + data -> + data + end + end + + @doc """ + Creates a new **limit** **buy** order + + Symbol can be a binance symbol in the form of `"ETHBTC"` or `%Binance.TradePair{}`. + + Returns `{:ok, %{}}` or `{:error, reason}` + """ + def order_limit_buy(symbol, quantity, price, time_in_force \\ "GTC") + + def order_limit_buy( + %Binance.TradePair{from: from, to: to} = symbol, + quantity, + price, + time_in_force + ) + when is_number(quantity) + when is_number(price) + when is_binary(from) + when is_binary(to) do + case find_symbol(symbol) do + {:ok, binance_symbol} -> order_limit_buy(binance_symbol, quantity, price, time_in_force) + e -> e + end + end + + def order_limit_buy(symbol, quantity, price, time_in_force) + when is_binary(symbol) + when is_number(quantity) + when is_number(price) do + create_order(symbol, "BUY", "LIMIT", quantity, price, time_in_force) + |> parse_order_response + end + + @doc """ + Creates a new **limit** **sell** order + + Symbol can be a binance symbol in the form of `"ETHBTC"` or `%Binance.TradePair{}`. + + Returns `{:ok, %{}}` or `{:error, reason}` + """ + def order_limit_sell(symbol, quantity, price, time_in_force \\ "GTC") + + def order_limit_sell( + %Binance.TradePair{from: from, to: to} = symbol, + quantity, + price, + time_in_force + ) + when is_number(quantity) + when is_number(price) + when is_binary(from) + when is_binary(to) do + case find_symbol(symbol) do + {:ok, binance_symbol} -> order_limit_sell(binance_symbol, quantity, price, time_in_force) + e -> e + end + end + + def order_limit_sell(symbol, quantity, price, time_in_force) + when is_binary(symbol) + when is_number(quantity) + when is_number(price) do + create_order(symbol, "SELL", "LIMIT", quantity, price, time_in_force) + |> parse_order_response + end + + @doc """ + Creates a new **market** **buy** order + + Symbol can be a binance symbol in the form of `"ETHBTC"` or `%Binance.TradePair{}`. + + Returns `{:ok, %{}}` or `{:error, reason}` + """ + def order_market_buy(%Binance.TradePair{from: from, to: to} = symbol, quantity) + when is_number(quantity) + when is_binary(from) + when is_binary(to) do + case find_symbol(symbol) do + {:ok, binance_symbol} -> order_market_buy(binance_symbol, quantity) + e -> e + end + end + + def order_market_buy(symbol, quantity) + when is_binary(symbol) + when is_number(quantity) do + create_order(symbol, "BUY", "MARKET", quantity) + end + + @doc """ + Creates a new **market** **sell** order + + Symbol can be a binance symbol in the form of `"ETHBTC"` or `%Binance.TradePair{}`. + + Returns `{:ok, %{}}` or `{:error, reason}` + """ + def order_market_sell(%Binance.TradePair{from: from, to: to} = symbol, quantity) + when is_number(quantity) + when is_binary(from) + when is_binary(to) do + case find_symbol(symbol) do + {:ok, binance_symbol} -> order_market_sell(binance_symbol, quantity) + e -> e + end + end + + def order_market_sell(symbol, quantity) + when is_binary(symbol) + when is_number(quantity) do + create_order(symbol, "SELL", "MARKET", quantity) + end + + defp parse_order_response({:ok, response}) do + {:ok, Binance.OrderResponse.new(response)} + end + + defp parse_order_response({ + :error, + { + :binance_error, + %{code: -2010, msg: "Account has insufficient balance for requested action."} = reason + } + }) do + {:error, %Binance.InsufficientBalanceError{reason: reason}} + end + + # Misc + + defp format_price(num) when is_float(num), do: :erlang.float_to_binary(num, [{:decimals, 8}]) + defp format_price(num) when is_integer(num), do: inspect(num) + defp format_price(num) when is_binary(num), do: num + + @doc """ + Searches and normalizes the symbol as it is listed on binance. + + To retrieve this information, a request to the binance API is done. The result is then **cached** to ensure the request is done only once. + + Order of which symbol comes first, and case sensitivity does not matter. + + Returns `{:ok, "SYMBOL"}` if successfully, or `{:error, reason}` otherwise. + + ## Examples + These 3 calls will result in the same result string: + ``` + find_symbol(%Binance.TradePair{from: "ETH", to: "REQ"}) + ``` + ``` + find_symbol(%Binance.TradePair{from: "REQ", to: "ETH"}) + ``` + ``` + find_symbol(%Binance.TradePair{from: "rEq", to: "eTH"}) + ``` + + Result: `{:ok, "REQETH"}` + + """ + def find_symbol(%Binance.TradePair{from: from, to: to} = tp) + when is_binary(from) + when is_binary(to) do + case Binance.SymbolCache.get() do + # cache hit + {:ok, data} -> + from = String.upcase(from) + to = String.upcase(to) + + found = Enum.filter(data, &Enum.member?([from <> to, to <> from], &1)) + + case Enum.count(found) do + 1 -> {:ok, found |> List.first()} + 0 -> {:error, :symbol_not_found} + end + + # cache miss + {:error, :not_initialized} -> + case get_all_prices() do + {:ok, price_data} -> + price_data + |> Enum.map(fn x -> x.symbol end) + |> Binance.SymbolCache.store() + + find_symbol(tp) + + err -> + err + end + + err -> + err + end + end + + # Open orders + + @doc """ + Get all open orders, alternatively open orders by symbol + + Returns `{:ok, [%Binance.Order{}]}` or `{:error, reason}`. + + Weight: 1 for a single symbol; 40 when the symbol parameter is omitted + + ## Example + ``` + {:ok, + [%Binance.Order{price: "0.1", origQty: "1.0", executedQty: "0.0", ...}, + %Binance.Order{...}, + %Binance.Order{...}, + %Binance.Order{...}, + %Binance.Order{...}, + %Binance.Order{...}, + ...]} + ``` + """ + def get_open_orders() do + api_key = Application.get_env(:binance, :api_key) + secret_key = Application.get_env(:binance, :secret_key) + + case HTTPClient.get_binance("/api/v3/openOrders", %{}, secret_key, api_key) do + {:ok, data} -> {:ok, Enum.map(data, &Binance.Order.new(&1))} + err -> err + end + end + + def get_open_orders(%Binance.TradePair{} = symbol) do + case find_symbol(symbol) do + {:ok, binance_symbol} -> get_open_orders(binance_symbol) + e -> e + end + end + + def get_open_orders(symbol) when is_binary(symbol) do + api_key = Application.get_env(:binance, :api_key) + secret_key = Application.get_env(:binance, :secret_key) + + case HTTPClient.get_binance("/api/v3/openOrders", %{:symbol => symbol}, secret_key, api_key) do + {:ok, data} -> {:ok, Enum.map(data, &Binance.Order.new(&1))} + err -> err + end + end + + # Order + + @doc """ + Get order by symbol, timestamp and either orderId or origClientOrderId are mandatory + + Returns `{:ok, [%Binance.Order{}]}` or `{:error, reason}`. + + Weight: 1 + + ## Example + ``` + {:ok, %Binance.Order{price: "0.1", origQty: "1.0", executedQty: "0.0", ...}} + ``` + + Info: https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md#query-order-user_data + """ + def get_order( + symbol, + timestamp, + order_id \\ nil, + orig_client_order_id \\ nil, + recv_window \\ nil + ) do + case is_binary(symbol) do + true -> + fetch_order(symbol, timestamp, order_id, orig_client_order_id, recv_window) + + false -> + case find_symbol(symbol) do + {:ok, binance_symbol} -> + fetch_order(binance_symbol, timestamp, order_id, orig_client_order_id, recv_window) + + e -> + e + end + end + end + + def fetch_order(symbol, timestamp, order_id, orig_client_order_id, recv_window) + when is_binary(symbol) + when is_integer(timestamp) + when is_integer(order_id) or is_binary(orig_client_order_id) do + api_key = Application.get_env(:binance, :api_key) + secret_key = Application.get_env(:binance, :secret_key) + + arguments = + %{ + symbol: symbol, + timestamp: timestamp + } + |> Map.merge(unless(is_nil(order_id), do: %{orderId: order_id}, else: %{})) + |> Map.merge( + unless( + is_nil(orig_client_order_id), + do: %{origClientOrderId: orig_client_order_id}, + else: %{} + ) + ) + |> Map.merge(unless(is_nil(recv_window), do: %{recvWindow: recv_window}, else: %{})) + + case HTTPClient.get_binance("/api/v3/order", arguments, secret_key, api_key) do + {:ok, data} -> {:ok, Binance.Order.new(data)} + err -> err + end + end + + @doc """ + Cancel an active order.. + + Symbol and either orderId or origClientOrderId must be sent. + + Returns `{:ok, %Binance.Order{}}` or `{:error, reason}`. + + Weight: 1 + + Info: https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md#cancel-order-trade + """ + def cancel_order( + symbol, + timestamp, + order_id \\ nil, + orig_client_order_id \\ nil, + new_client_order_id \\ nil, + recv_window \\ nil + ) do + case is_binary(symbol) do + true -> + cancel_order_( + symbol, + timestamp, + order_id, + orig_client_order_id, + new_client_order_id, + recv_window + ) + + false -> + case find_symbol(symbol) do + {:ok, binance_symbol} -> + cancel_order_( + binance_symbol, + timestamp, + order_id, + orig_client_order_id, + new_client_order_id, + recv_window + ) + + e -> + e + end + end + end + + defp cancel_order_( + symbol, + timestamp, + order_id, + orig_client_order_id, + new_client_order_id, + recv_window + ) + when is_binary(symbol) + when is_integer(timestamp) + when is_integer(order_id) or is_binary(orig_client_order_id) do + api_key = Application.get_env(:binance, :api_key) + secret_key = Application.get_env(:binance, :secret_key) + + arguments = + %{ + symbol: symbol, + timestamp: timestamp + } + |> Map.merge(unless(is_nil(order_id), do: %{orderId: order_id}, else: %{})) + |> Map.merge( + unless( + is_nil(orig_client_order_id), + do: %{origClientOrderId: orig_client_order_id}, + else: %{} + ) + ) + |> Map.merge( + unless(is_nil(new_client_order_id), + do: %{newClientOrderId: new_client_order_id}, + else: %{} + ) + ) + |> Map.merge(unless(is_nil(recv_window), do: %{recvWindow: recv_window}, else: %{})) + + case HTTPClient.delete_binance("/api/v3/order", arguments, secret_key, api_key) do + {:ok, data} -> {:ok, Binance.Order.new(data)} + err -> err + end + end +end From d0d92badf88a8508640c655952b2a73c97c6f3d5 Mon Sep 17 00:00:00 2001 From: David Mohl Date: Sat, 1 Jul 2023 21:37:43 +1000 Subject: [PATCH 06/25] Add response struct mapping --- lib/binance.ex | 56 +++++++++++++------ lib/binance/docs_parser.ex | 2 +- lib/binance/response_mapping.ex | 15 +++++ lib/binance/{ => structs}/account.ex | 0 lib/binance/{ => structs}/data_stream.ex | 0 lib/binance/{ => structs}/exchange_info.ex | 0 lib/binance/{ => structs}/historical_trade.ex | 0 .../insufficient_balance_error.ex | 0 lib/binance/{ => structs}/kline.ex | 4 +- lib/binance/{ => structs}/order.ex | 0 lib/binance/{ => structs}/order_book.ex | 0 lib/binance/{ => structs}/order_response.ex | 0 lib/binance/{ => structs}/supervisor.ex | 0 lib/binance/{ => structs}/symbol_cache.ex | 0 lib/binance/{ => structs}/symbol_price.ex | 0 lib/binance/{ => structs}/system_status.ex | 0 lib/binance/{ => structs}/ticker.ex | 0 lib/binance/{ => structs}/trade_pair.ex | 0 18 files changed, 57 insertions(+), 20 deletions(-) create mode 100644 lib/binance/response_mapping.ex rename lib/binance/{ => structs}/account.ex (100%) rename lib/binance/{ => structs}/data_stream.ex (100%) rename lib/binance/{ => structs}/exchange_info.ex (100%) rename lib/binance/{ => structs}/historical_trade.ex (100%) rename lib/binance/{ => structs}/insufficient_balance_error.ex (100%) rename lib/binance/{ => structs}/kline.ex (94%) rename lib/binance/{ => structs}/order.ex (100%) rename lib/binance/{ => structs}/order_book.ex (100%) rename lib/binance/{ => structs}/order_response.ex (100%) rename lib/binance/{ => structs}/supervisor.ex (100%) rename lib/binance/{ => structs}/symbol_cache.ex (100%) rename lib/binance/{ => structs}/symbol_price.ex (100%) rename lib/binance/{ => structs}/system_status.ex (100%) rename lib/binance/{ => structs}/ticker.ex (100%) rename lib/binance/{ => structs}/trade_pair.ex (100%) diff --git a/lib/binance.ex b/lib/binance.ex index 4f92d0a..1d1042f 100644 --- a/lib/binance.ex +++ b/lib/binance.ex @@ -21,8 +21,9 @@ docs needs_timestamp = item.needs_timestamp? description = item.description fx_name = item.fx_name + path_key = item.path_key - IO.puts(" generating #{fx_name} (#{url})") + IO.puts(" generating #{fx_name} (#{path_key})") mandatory_params = Enum.filter(params, fn param -> @@ -113,6 +114,7 @@ docs all_passed_args = Keyword.merge(binding, opts) |> Keyword.drop([:opts]) IO.puts("API call: #{unquote(method)} " <> unquote(url)) + IO.puts("resp struct for pathkey #{unquote(path_key)}") IO.puts("binding:") IO.inspect(binding) IO.puts("passed args:") @@ -138,22 +140,42 @@ docs IO.puts("adjusted args:") IO.inspect(all_passed_args) - if unquote(needs_auth) do - case HTTPClient.signed_request_binance(unquote(url), adjusted_args, unquote(method)) do - {:ok, %{"code" => code, "msg" => msg}} -> - {:error, {:binance_error, %{code: code, msg: msg}}} - - data -> - data - end - else - case HTTPClient.unsigned_request_binance(unquote(url), adjusted_args, unquote(method)) do - {:ok, %{"code" => code, "msg" => msg}} -> - {:error, {:binance_error, %{code: code, msg: msg}}} - - data -> - data - end + case unquote(needs_auth) do + true -> + case HTTPClient.signed_request_binance(unquote(url), adjusted_args, unquote(method)) do + {:ok, %{"code" => code, "msg" => msg}} -> + {:error, {:binance_error, %{code: code, msg: msg}}} + + data -> + data + end + + false -> + case HTTPClient.unsigned_request_binance( + unquote(url), + adjusted_args, + unquote(method) + ) do + {:ok, %{"code" => code, "msg" => msg}} -> + {:error, {:binance_error, %{code: code, msg: msg}}} + + data -> + data + end + end + |> case do + {:ok, data} -> + # try to find a response mapped struct + case Binance.ResponseMapping.lookup(unquote(path_key)) do + nil -> + {:ok, data} + + struct_name -> + {:ok, struct_name.new(data)} + end + + e -> + e end end end) diff --git a/lib/binance/docs_parser.ex b/lib/binance/docs_parser.ex index 28d0474..7554be0 100644 --- a/lib/binance/docs_parser.ex +++ b/lib/binance/docs_parser.ex @@ -38,8 +38,8 @@ defmodule Binance.DocsParser do path: path, needs_auth?: Enum.find(params, nil, &(&1.name == "signature")) != nil, needs_timestamp?: Enum.find(params, nil, &(&1.name == "timestamp")) != nil, - unique_key: "#{String.downcase(method)}_#{Enum.join(path, "_")}", description: Map.get(args["request"], "description", ""), + path_key: "#{String.downcase(method)}:/#{Enum.join(path, "/")}", fx_name: gen_fx_name(path, method) } end diff --git a/lib/binance/response_mapping.ex b/lib/binance/response_mapping.ex new file mode 100644 index 0000000..73d6f32 --- /dev/null +++ b/lib/binance/response_mapping.ex @@ -0,0 +1,15 @@ +defmodule Binance.ResponseMapping do + @moduledoc false + + def lookup(path_key) do + mappings = %{ + "get:/api/v3/klines" => Binance.Structs.Kline + } + + found = Map.get(mappings, path_key, nil) + + IO.puts("lookup for #{path_key} -- #{inspect(found)}") + + found + end +end diff --git a/lib/binance/account.ex b/lib/binance/structs/account.ex similarity index 100% rename from lib/binance/account.ex rename to lib/binance/structs/account.ex diff --git a/lib/binance/data_stream.ex b/lib/binance/structs/data_stream.ex similarity index 100% rename from lib/binance/data_stream.ex rename to lib/binance/structs/data_stream.ex diff --git a/lib/binance/exchange_info.ex b/lib/binance/structs/exchange_info.ex similarity index 100% rename from lib/binance/exchange_info.ex rename to lib/binance/structs/exchange_info.ex diff --git a/lib/binance/historical_trade.ex b/lib/binance/structs/historical_trade.ex similarity index 100% rename from lib/binance/historical_trade.ex rename to lib/binance/structs/historical_trade.ex diff --git a/lib/binance/insufficient_balance_error.ex b/lib/binance/structs/insufficient_balance_error.ex similarity index 100% rename from lib/binance/insufficient_balance_error.ex rename to lib/binance/structs/insufficient_balance_error.ex diff --git a/lib/binance/kline.ex b/lib/binance/structs/kline.ex similarity index 94% rename from lib/binance/kline.ex rename to lib/binance/structs/kline.ex index b78077f..c4d5ae2 100644 --- a/lib/binance/kline.ex +++ b/lib/binance/structs/kline.ex @@ -1,4 +1,4 @@ -defmodule Binance.Kline do +defmodule Binance.Structs.Kline do @moduledoc """ Struct for representing a result row as returned by /api/v3/kline @@ -36,7 +36,7 @@ defmodule Binance.Kline do ] def new(list) do - %Binance.Kline{ + %Binance.Structs.Kline{ open_time: Enum.at(list, 0), open: Enum.at(list, 1), high: Enum.at(list, 2), diff --git a/lib/binance/order.ex b/lib/binance/structs/order.ex similarity index 100% rename from lib/binance/order.ex rename to lib/binance/structs/order.ex diff --git a/lib/binance/order_book.ex b/lib/binance/structs/order_book.ex similarity index 100% rename from lib/binance/order_book.ex rename to lib/binance/structs/order_book.ex diff --git a/lib/binance/order_response.ex b/lib/binance/structs/order_response.ex similarity index 100% rename from lib/binance/order_response.ex rename to lib/binance/structs/order_response.ex diff --git a/lib/binance/supervisor.ex b/lib/binance/structs/supervisor.ex similarity index 100% rename from lib/binance/supervisor.ex rename to lib/binance/structs/supervisor.ex diff --git a/lib/binance/symbol_cache.ex b/lib/binance/structs/symbol_cache.ex similarity index 100% rename from lib/binance/symbol_cache.ex rename to lib/binance/structs/symbol_cache.ex diff --git a/lib/binance/symbol_price.ex b/lib/binance/structs/symbol_price.ex similarity index 100% rename from lib/binance/symbol_price.ex rename to lib/binance/structs/symbol_price.ex diff --git a/lib/binance/system_status.ex b/lib/binance/structs/system_status.ex similarity index 100% rename from lib/binance/system_status.ex rename to lib/binance/structs/system_status.ex diff --git a/lib/binance/ticker.ex b/lib/binance/structs/ticker.ex similarity index 100% rename from lib/binance/ticker.ex rename to lib/binance/structs/ticker.ex diff --git a/lib/binance/trade_pair.ex b/lib/binance/structs/trade_pair.ex similarity index 100% rename from lib/binance/trade_pair.ex rename to lib/binance/structs/trade_pair.ex From 7e1fa914565542a01f7f712ca2158cd553d49ea4 Mon Sep 17 00:00:00 2001 From: David Mohl Date: Sat, 1 Jul 2023 22:20:29 +1000 Subject: [PATCH 07/25] Allow passing of timestamp into optional args --- lib/binance.ex | 11 +++++++++-- lib/binance/response_mapping.ex | 9 +++------ lib/binance/structs/account.ex | 2 +- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/lib/binance.ex b/lib/binance.ex index 1d1042f..223e775 100644 --- a/lib/binance.ex +++ b/lib/binance.ex @@ -42,8 +42,15 @@ docs |> Enum.map(fn param -> %{name: param.name, description: param.description} end) - |> Enum.filter(&(&1.name != "timestamp")) - |> Enum.filter(&(&1.name != "signature")) + + optional_params = + case needs_timestamp do + true -> + [%{name: "timestamp", description: "timestamp"} | optional_params] + + _ -> + optional_params + end # generate mandatory params arg_names = diff --git a/lib/binance/response_mapping.ex b/lib/binance/response_mapping.ex index 73d6f32..fdd4c0e 100644 --- a/lib/binance/response_mapping.ex +++ b/lib/binance/response_mapping.ex @@ -3,13 +3,10 @@ defmodule Binance.ResponseMapping do def lookup(path_key) do mappings = %{ - "get:/api/v3/klines" => Binance.Structs.Kline + "get:/api/v3/klines" => Binance.Structs.Kline, + "get:/api/v3/account" => Binance.Structs.Account } - found = Map.get(mappings, path_key, nil) - - IO.puts("lookup for #{path_key} -- #{inspect(found)}") - - found + Map.get(mappings, path_key, nil) end end diff --git a/lib/binance/structs/account.ex b/lib/binance/structs/account.ex index f91b0b8..0a4134f 100644 --- a/lib/binance/structs/account.ex +++ b/lib/binance/structs/account.ex @@ -1,4 +1,4 @@ -defmodule Binance.Account do +defmodule Binance.Structs.Account do @moduledoc """ Struct for representing a result row as returned by /api/v3/account From 31c309db493521eeb87c2377af79e90310188ae4 Mon Sep 17 00:00:00 2001 From: David Mohl Date: Sat, 1 Jul 2023 22:44:41 +1000 Subject: [PATCH 08/25] Migrate first 3 tests to new API --- config/config.exs | 2 +- lib/binance/response_mapping.ex | 4 +++- lib/binance/rest/http_client.ex | 15 +++++++++++++-- lib/binance/structs/historical_trade.ex | 2 +- lib/binance/structs/server_time.ex | 5 +++++ test/binance_test.exs | 12 ++++++------ 6 files changed, 29 insertions(+), 11 deletions(-) create mode 100644 lib/binance/structs/server_time.ex diff --git a/config/config.exs b/config/config.exs index 55be3ca..c380895 100644 --- a/config/config.exs +++ b/config/config.exs @@ -1,6 +1,6 @@ # This file is responsible for configuring your application # and its dependencies with the aid of the Mix.Config module. -use Mix.Config +import Config config :binance, api_key: "", diff --git a/lib/binance/response_mapping.ex b/lib/binance/response_mapping.ex index fdd4c0e..b1a7cca 100644 --- a/lib/binance/response_mapping.ex +++ b/lib/binance/response_mapping.ex @@ -4,7 +4,9 @@ defmodule Binance.ResponseMapping do def lookup(path_key) do mappings = %{ "get:/api/v3/klines" => Binance.Structs.Kline, - "get:/api/v3/account" => Binance.Structs.Account + "get:/api/v3/account" => Binance.Structs.Account, + "get:/api/v3/time" => Binance.Structs.ServerTime, + "get:/api/v3/historicalTrades" => Binance.Structs.HistoricalTrade } Map.get(mappings, path_key, nil) diff --git a/lib/binance/rest/http_client.ex b/lib/binance/rest/http_client.ex index 1942a9b..1dfe63e 100644 --- a/lib/binance/rest/http_client.ex +++ b/lib/binance/rest/http_client.ex @@ -80,7 +80,11 @@ defmodule Binance.Rest.HTTPClient do url = case method do :get -> - "#{@endpoint}#{url}?#{body}" + if body != "" do + "#{@endpoint}#{url}?#{body}" + else + "#{@endpoint}#{url}" + end _ -> "#{@endpoint}#{url}" @@ -158,8 +162,15 @@ defmodule Binance.Rest.HTTPClient do data |> prepare_query_params() + url = + if argument_string != "" do + "#{@endpoint}#{url}" <> "?#{argument_string}" + else + "#{@endpoint}#{url}" + end + apply(HTTPoison, :get, [ - "#{@endpoint}#{url}" <> "?#{argument_string}", + url, headers ]) end diff --git a/lib/binance/structs/historical_trade.ex b/lib/binance/structs/historical_trade.ex index 62481eb..71156db 100644 --- a/lib/binance/structs/historical_trade.ex +++ b/lib/binance/structs/historical_trade.ex @@ -1,4 +1,4 @@ -defmodule Binance.HistoricalTrade do +defmodule Binance.Structs.HistoricalTrade do @moduledoc """ Struct for representing the result returned by /api/v3/historicalTrades """ diff --git a/lib/binance/structs/server_time.ex b/lib/binance/structs/server_time.ex new file mode 100644 index 0000000..45fbbf7 --- /dev/null +++ b/lib/binance/structs/server_time.ex @@ -0,0 +1,5 @@ +defmodule Binance.Structs.ServerTime do + def new(%{"serverTime" => time}) do + time + end +end diff --git a/test/binance_test.exs b/test/binance_test.exs index 7d8ee93..c5ce6a8 100644 --- a/test/binance_test.exs +++ b/test/binance_test.exs @@ -9,20 +9,20 @@ defmodule BinanceTest do test "ping returns an empty map" do use_cassette "ping_ok" do - assert Binance.ping() == {:ok, %{}} + assert Binance.Market.get_ping() == {:ok, %{}} end end test "get_server_time success return an ok, time tuple" do use_cassette "get_server_time_ok" do - assert Binance.get_server_time() == {:ok, 1_616_592_268_319} + assert Binance.Market.get_server_time() == {:ok, 1_616_592_268_319} end end test "get_historical_trades success returns the latest trades" do use_cassette "get_historical_trades_ok" do - assert {:ok, response} = Binance.get_historical_trades("XRPUSDT", 1, nil) - assert [%Binance.HistoricalTrade{} | _tail] = response + assert {:ok, response} = Binance.Market.get_historical_trades("XRPUSDT", 1, nil) + assert [%Binance.Structs.HistoricalTrade{} | _tail] = response end use_cassette "get_historical_trades_from_id_ok" do @@ -170,7 +170,7 @@ defmodule BinanceTest do { :ok, [ - %Binance.Kline{ + %Binance.Structs.Kline{ close: "0.00349500", close_time: 1_616_029_199_999, high: "0.00350000", @@ -184,7 +184,7 @@ defmodule BinanceTest do taker_buy_quote_asset_volume: "16.87297134", volume: "10438.37000000" }, - %Binance.Kline{ + %Binance.Structs.Kline{ close: "0.00347900", close_time: 1_616_032_799_999, high: "0.00349700", From 34d424279cdb460c2fbf5812732ae3a44614b02a Mon Sep 17 00:00:00 2001 From: David Mohl Date: Sun, 2 Jul 2023 18:51:07 +1000 Subject: [PATCH 09/25] Backport most tests and response structs --- lib/binance.ex | 23 +- lib/binance/response_mapping.ex | 13 +- lib/binance/responses/historical_trades.ex | 5 + lib/binance/responses/klines.ex | 5 + lib/binance/responses/open_orders.ex | 5 + lib/binance/responses/orders.ex | 5 + lib/binance/responses/ticker_price.ex | 5 + lib/binance/rest/http_client.ex | 23 +- lib/binance/structs/exchange_info.ex | 2 +- lib/binance/structs/historical_trade.ex | 4 + lib/binance/structs/order.ex | 2 +- lib/binance/structs/order_book.ex | 2 +- lib/binance/structs/order_response.ex | 2 +- lib/binance/structs/symbol_price.ex | 2 +- lib/binance/structs/system_status.ex | 2 +- lib/binance/structs/ticker.ex | 2 +- lib/binance/structs/trade_pair.ex | 13 - lib/binance/typer.ex | 27 + lib/binance_old.ex | 1572 ++++++++++---------- test/binance_test.exs | 183 +-- 20 files changed, 971 insertions(+), 926 deletions(-) create mode 100644 lib/binance/responses/historical_trades.ex create mode 100644 lib/binance/responses/klines.ex create mode 100644 lib/binance/responses/open_orders.ex create mode 100644 lib/binance/responses/orders.ex create mode 100644 lib/binance/responses/ticker_price.ex delete mode 100644 lib/binance/structs/trade_pair.ex create mode 100644 lib/binance/typer.ex diff --git a/lib/binance.ex b/lib/binance.ex index 223e775..3e5704a 100644 --- a/lib/binance.ex +++ b/lib/binance.ex @@ -1,4 +1,9 @@ defmodule Binance do + defmodule Helper do + def format_price(num) when is_float(num), do: :erlang.float_to_binary(num, [{:decimals, 8}]) + def format_price(num) when is_integer(num), do: inspect(num) + def format_price(num) when is_binary(num), do: num + end end docs = Binance.DocsParser.get_documentation() @@ -121,11 +126,6 @@ docs all_passed_args = Keyword.merge(binding, opts) |> Keyword.drop([:opts]) IO.puts("API call: #{unquote(method)} " <> unquote(url)) - IO.puts("resp struct for pathkey #{unquote(path_key)}") - IO.puts("binding:") - IO.inspect(binding) - IO.puts("passed args:") - IO.inspect(all_passed_args) # if the call requires a timestamp, we add it adjusted_args = @@ -142,11 +142,18 @@ docs all_passed_args end end + # special handling for certain parameters like price: + |> Enum.map(fn {k, v} -> + case k do + :price -> + {k, Binance.Helper.format_price(v)} + + _ -> + {k, v} + end + end) |> Enum.into(%{}) - IO.puts("adjusted args:") - IO.inspect(all_passed_args) - case unquote(needs_auth) do true -> case HTTPClient.signed_request_binance(unquote(url), adjusted_args, unquote(method)) do diff --git a/lib/binance/response_mapping.ex b/lib/binance/response_mapping.ex index b1a7cca..3d47212 100644 --- a/lib/binance/response_mapping.ex +++ b/lib/binance/response_mapping.ex @@ -3,10 +3,19 @@ defmodule Binance.ResponseMapping do def lookup(path_key) do mappings = %{ - "get:/api/v3/klines" => Binance.Structs.Kline, + "get:/api/v3/klines" => Binance.Responses.Klines, "get:/api/v3/account" => Binance.Structs.Account, "get:/api/v3/time" => Binance.Structs.ServerTime, - "get:/api/v3/historicalTrades" => Binance.Structs.HistoricalTrade + "get:/api/v3/historicalTrades" => Binance.Responses.HistoricalTrades, + "get:/api/v3/depth" => Binance.Structs.OrderBook, + "post:/api/v3/order" => Binance.Structs.OrderResponse, + "delete:/api/v3/order" => Binance.Structs.Order, + "get:/api/v3/openOrders" => Binance.Responses.OpenOrders, + "get:/sapi/v1/system/status" => Binance.Structs.SystemStatus, + "get:/api/v3/ticker" => Binance.Structs.Ticker, + "get:/api/v3/ticker/24hr" => Binance.Structs.Ticker, + "get:/api/v3/ticker/price" => Binance.Responses.TickerPrice, + "get:/api/v3/exchangeInfo" => Binance.Structs.ExchangeInfo } Map.get(mappings, path_key, nil) diff --git a/lib/binance/responses/historical_trades.ex b/lib/binance/responses/historical_trades.ex new file mode 100644 index 0000000..7ab57cc --- /dev/null +++ b/lib/binance/responses/historical_trades.ex @@ -0,0 +1,5 @@ +defmodule Binance.Responses.HistoricalTrades do + def new(data) do + Enum.map(data, &Binance.Structs.HistoricalTrade.new(&1)) + end +end diff --git a/lib/binance/responses/klines.ex b/lib/binance/responses/klines.ex new file mode 100644 index 0000000..8ce9737 --- /dev/null +++ b/lib/binance/responses/klines.ex @@ -0,0 +1,5 @@ +defmodule Binance.Responses.Klines do + def new(data) do + Enum.map(data, &Binance.Structs.Kline.new/1) + end +end diff --git a/lib/binance/responses/open_orders.ex b/lib/binance/responses/open_orders.ex new file mode 100644 index 0000000..4b6e500 --- /dev/null +++ b/lib/binance/responses/open_orders.ex @@ -0,0 +1,5 @@ +defmodule Binance.Responses.OpenOrders do + def new(data) do + Enum.map(data, &Binance.Structs.Order.new(&1)) + end +end diff --git a/lib/binance/responses/orders.ex b/lib/binance/responses/orders.ex new file mode 100644 index 0000000..7237c4c --- /dev/null +++ b/lib/binance/responses/orders.ex @@ -0,0 +1,5 @@ +defmodule Binance.Structs.Orders do + def new(data) do + Enum.map(data, &Binance.Structs.OrderResponse.new(&1)) + end +end diff --git a/lib/binance/responses/ticker_price.ex b/lib/binance/responses/ticker_price.ex new file mode 100644 index 0000000..a519954 --- /dev/null +++ b/lib/binance/responses/ticker_price.ex @@ -0,0 +1,5 @@ +defmodule Binance.Responses.TickerPrice do + def new(data) do + Enum.map(data, &Binance.Structs.SymbolPrice.new(&1)) + end +end diff --git a/lib/binance/rest/http_client.ex b/lib/binance/rest/http_client.ex index 1dfe63e..dcf1372 100644 --- a/lib/binance/rest/http_client.ex +++ b/lib/binance/rest/http_client.ex @@ -86,18 +86,17 @@ defmodule Binance.Rest.HTTPClient do "#{@endpoint}#{url}" end + :delete -> + if body != "" do + "#{@endpoint}#{url}?#{body}" + else + "#{@endpoint}#{url}" + end + _ -> "#{@endpoint}#{url}" end - IO.puts(body) - IO.puts(method) - IO.puts("#{url}") - - IO.inspect([ - {"X-MBX-APIKEY", Application.get_env(:binance, :api_key)} - ]) - case method do :get -> HTTPoison.get( @@ -107,6 +106,14 @@ defmodule Binance.Rest.HTTPClient do ] ) + :delete -> + HTTPoison.delete( + url, + [ + {"X-MBX-APIKEY", Application.get_env(:binance, :api_key)} + ] + ) + _ -> apply(HTTPoison, method, [ url, diff --git a/lib/binance/structs/exchange_info.ex b/lib/binance/structs/exchange_info.ex index d07f6eb..40921bd 100644 --- a/lib/binance/structs/exchange_info.ex +++ b/lib/binance/structs/exchange_info.ex @@ -1,4 +1,4 @@ -defmodule Binance.ExchangeInfo do +defmodule Binance.Structs.ExchangeInfo do @moduledoc """ Struct for representing the result returned by /api/v1/exchangeInfo """ diff --git a/lib/binance/structs/historical_trade.ex b/lib/binance/structs/historical_trade.ex index 71156db..8feb95a 100644 --- a/lib/binance/structs/historical_trade.ex +++ b/lib/binance/structs/historical_trade.ex @@ -14,4 +14,8 @@ defmodule Binance.Structs.HistoricalTrade do ] use ExConstructor + + def from_response(data) do + Enum.map(data, &new(&1)) + end end diff --git a/lib/binance/structs/order.ex b/lib/binance/structs/order.ex index e931190..5fbe5dc 100644 --- a/lib/binance/structs/order.ex +++ b/lib/binance/structs/order.ex @@ -1,4 +1,4 @@ -defmodule Binance.Order do +defmodule Binance.Structs.Order do @moduledoc """ Struct for representing the result returned by /api/v3/openOrders """ diff --git a/lib/binance/structs/order_book.ex b/lib/binance/structs/order_book.ex index 012e35b..1985b1d 100644 --- a/lib/binance/structs/order_book.ex +++ b/lib/binance/structs/order_book.ex @@ -1,4 +1,4 @@ -defmodule Binance.OrderBook do +defmodule Binance.Structs.OrderBook do @moduledoc """ Struct for representing the result returned by /api/v1/depth """ diff --git a/lib/binance/structs/order_response.ex b/lib/binance/structs/order_response.ex index 9f0226d..f72cfdf 100644 --- a/lib/binance/structs/order_response.ex +++ b/lib/binance/structs/order_response.ex @@ -1,4 +1,4 @@ -defmodule Binance.OrderResponse do +defmodule Binance.Structs.OrderResponse do @moduledoc """ Response tructure for POST /api/v3/order endpoint. All prices and quantities are string representation of floats with 8 decimals (eg: "orig_qty": "10.00000000") diff --git a/lib/binance/structs/symbol_price.ex b/lib/binance/structs/symbol_price.ex index 2d0096c..a6fb2d9 100644 --- a/lib/binance/structs/symbol_price.ex +++ b/lib/binance/structs/symbol_price.ex @@ -1,4 +1,4 @@ -defmodule Binance.SymbolPrice do +defmodule Binance.Structs.SymbolPrice do @moduledoc """ Struct for representing a result row as returned by /api/v1/ticker/allPrices diff --git a/lib/binance/structs/system_status.ex b/lib/binance/structs/system_status.ex index e0233a0..6fcfd41 100644 --- a/lib/binance/structs/system_status.ex +++ b/lib/binance/structs/system_status.ex @@ -1,4 +1,4 @@ -defmodule Binance.SystemStatus do +defmodule Binance.Structs.SystemStatus do @moduledoc """ Struct for representing the result returned by /wapi/v3/systemStatus.html diff --git a/lib/binance/structs/ticker.ex b/lib/binance/structs/ticker.ex index 9e9bd4c..7377a8c 100644 --- a/lib/binance/structs/ticker.ex +++ b/lib/binance/structs/ticker.ex @@ -1,4 +1,4 @@ -defmodule Binance.Ticker do +defmodule Binance.Structs.Ticker do @moduledoc """ Struct for representing a result row as returned by /api/v1/ticker/24hr diff --git a/lib/binance/structs/trade_pair.ex b/lib/binance/structs/trade_pair.ex deleted file mode 100644 index 2bcdb09..0000000 --- a/lib/binance/structs/trade_pair.ex +++ /dev/null @@ -1,13 +0,0 @@ -defmodule Binance.TradePair do - @moduledoc """ - Struct for representing a normalized trade pair. - - ``` - @enforce_keys [:from, :to] - defstruct @enforce_keys - ``` - """ - - @enforce_keys [:from, :to] - defstruct @enforce_keys -end diff --git a/lib/binance/typer.ex b/lib/binance/typer.ex new file mode 100644 index 0000000..fba0a7b --- /dev/null +++ b/lib/binance/typer.ex @@ -0,0 +1,27 @@ +defmodule Binance.Typer do + defmacro __using__(_opts) do + quote do + # IO.inspect(unquote(__MODULE__).__struct__()) + # get struct fields + # types = + # __MODULE__.__struct__() + # |> Map.from_struct() + # |> Map.keys() + # |> Enum.reduce([], fn field, acc -> + # case acc do + # [] -> + # quote do: {field, any()} + + # val -> + # quote do: + # {field, any()} + # | unquote(val) + # end + # end) + + # @type t :: %__MODULE__{ + # types + # } + end + end +end diff --git a/lib/binance_old.ex b/lib/binance_old.ex index 93707f8..273ff96 100644 --- a/lib/binance_old.ex +++ b/lib/binance_old.ex @@ -1,786 +1,786 @@ -defmodule BinanceOld do - alias Binance.Rest.HTTPClient - - # Server - - @doc """ - Pings binance API. Returns `{:ok, %{}}` if successful, `{:error, reason}` otherwise - """ - def ping() do - HTTPClient.get_binance("/api/v3/ping") - end - - @doc """ - Get binance server time in unix epoch. - - Returns `{:ok, time}` if successful, `{:error, reason}` otherwise - - ## Example - ``` - {:ok, 1515390701097} - ``` - - """ - def get_server_time() do - case HTTPClient.get_binance("/api/v3/time") do - {:ok, %{"serverTime" => time}} -> {:ok, time} - err -> err - end - end - - def get_exchange_info() do - case HTTPClient.get_binance("/api/v3/exchangeInfo") do - {:ok, data} -> {:ok, Binance.ExchangeInfo.new(data)} - err -> err - end - end - - @doc """ - Get historical trades - https://binance-docs.github.io/apidocs/spot/en/#old-trade-lookup - - Returns `{:ok, [%Binance.HistoricalTrade{}]}` or `{:error, reason}`. - - ## Example - {:ok, - [%Binance.HistoricalTrade{ - id: 192180149, - is_best_match: true, - is_buyer_maker: true, - price: "1.79878000", - qty: "55.50000000", - quote_qty: "99.83229000", - time: 1618341167715 - }] - } - """ - def get_historical_trades(symbol, limit, from_id) - when is_binary(symbol) and is_integer(limit) do - arguments = - %{ - symbol: symbol, - limit: limit - } - |> Map.merge( - unless( - is_nil(from_id), - do: %{fromId: from_id}, - else: %{} - ) - ) - - case HTTPClient.unsigned_request_binance( - "/api/v3/historicalTrades", - arguments, - :get - ) do - {:ok, data} -> - {:ok, Enum.map(data, &Binance.HistoricalTrade.new(&1))} - - {:error, err} -> - err - end - end - - # Ticker - - @doc """ - Get all symbols and current prices listed in binance - - Returns `{:ok, [%Binance.SymbolPrice{}]}` or `{:error, reason}`. - - ## Example - ``` - {:ok, - [%Binance.SymbolPrice{price: "0.07579300", symbol: "ETHBTC"}, - %Binance.SymbolPrice{price: "0.01670200", symbol: "LTCBTC"}, - %Binance.SymbolPrice{price: "0.00114550", symbol: "BNBBTC"}, - %Binance.SymbolPrice{price: "0.00640000", symbol: "NEOBTC"}, - %Binance.SymbolPrice{price: "0.00030000", symbol: "123456"}, - %Binance.SymbolPrice{price: "0.04895000", symbol: "QTUMETH"}, - ...]} - ``` - """ - def get_all_prices() do - case HTTPClient.get_binance("/api/v3/ticker/price") do - {:ok, data} -> - {:ok, Enum.map(data, &Binance.SymbolPrice.new(&1))} - - err -> - err - end - end - - @doc """ - Retrieves the current ticker information for the given trade pair. - - Symbol can be a binance symbol in the form of `"ETHBTC"` or `%Binance.TradePair{}`. - - Returns `{:ok, %Binance.Ticker{}}` or `{:error, reason}` - - ## Example - ``` - {:ok, - %Binance.Ticker{ask_price: "0.07548800", bid_price: "0.07542100", - close_time: 1515391124878, count: 661676, first_id: 16797673, - high_price: "0.07948000", last_id: 17459348, last_price: "0.07542000", - low_price: "0.06330000", open_price: "0.06593800", open_time: 1515304724878, - prev_close_price: "0.06593800", price_change: "0.00948200", - price_change_percent: "14.380", volume: "507770.18500000", - weighted_avg_price: "0.06946930"}} - ``` - """ - def get_ticker(%Binance.TradePair{} = symbol) do - case find_symbol(symbol) do - {:ok, binance_symbol} -> get_ticker(binance_symbol) - e -> e - end - end - - def get_ticker(symbol) when is_binary(symbol) do - case HTTPClient.get_binance("/api/v3/ticker/24hr?symbol=#{symbol}") do - {:ok, data} -> {:ok, Binance.Ticker.new(data)} - err -> err - end - end - - @doc """ - Retrieves klines for a symbol, provided a given interval, e.g. "1h". - - Function can also take in a 'limit' argument to reduce the number of intervals. - - Returns `{:ok, [%Binance.Kline{}]` or `{:error, reason}` - - ## Example - ``` - {:ok, - [ - %Binance.Kline{ - close: "0.16527000", - close_time: 1617861599999, - high: "0.17100000", - ignore: "0", - low: "0.16352000", - number_of_trades: 16167, - open: "0.17088000", - open_time: 1617858000000, - quote_asset_volume: "7713624.32966000", - taker_buy_base_asset_volume: "22020677.70000000", - taker_buy_quote_asset_volume: "3668705.43042700", - volume: "46282422.20000000" - }, - %Binance.Kline{ - ... - ``` - """ - - def get_klines(symbol, interval, limit \\ 500) when is_binary(symbol) do - case HTTPClient.get_binance( - "/api/v3/klines?symbol=#{symbol}&interval=#{interval}&limit=#{limit}" - ) do - {:ok, data} -> - {:ok, Enum.map(data, &Binance.Kline.new(&1))} - - err -> - err - end - end - - @doc """ - Retrieves the bids & asks of the order book up to the depth for the given symbol - - Returns `{:ok, %{bids: [...], asks: [...], lastUpdateId: 12345}}` or `{:error, reason}` - - ## Example - ``` - {:ok, - %Binance.OrderBook{ - asks: [ - ["8400.00000000", "2.04078100", []], - ["8405.35000000", "0.50354700", []], - ["8406.00000000", "0.32769800", []], - ["8406.33000000", "0.00239000", []], - ["8406.51000000", "0.03241000", []] - ], - bids: [ - ["8393.00000000", "0.20453200", []], - ["8392.57000000", "0.02639000", []], - ["8392.00000000", "1.40893300", []], - ["8390.09000000", "0.07047100", []], - ["8388.72000000", "0.04577400", []] - ], - last_update_id: 113634395 - } - } - ``` - """ - def get_depth(symbol, limit) do - case HTTPClient.get_binance("/api/v3/depth?symbol=#{symbol}&limit=#{limit}") do - {:ok, data} -> {:ok, Binance.OrderBook.new(data)} - err -> err - end - end - - @doc """ - Fetches system status. - - Returns `{:ok, %Binance.SystemStatus{}}` or `{:error, reason}`. - """ - def get_system_status() do - case HTTPClient.get_binance("/sapi/v1/system/status") do - {:ok, data} -> {:ok, Binance.SystemStatus.new(data)} - error -> error - end - end - - # Account - - @doc """ - Fetches user account from binance - - Returns `{:ok, %Binance.Account{}}` or `{:error, reason}`. - - In the case of a error on binance, for example with invalid parameters, `{:error, {:binance_error, %{code: code, msg: msg}}}` will be returned. - - Please read https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md#account-information-user_data to understand API - """ - - def get_account() do - api_key = Application.get_env(:binance, :api_key) - secret_key = Application.get_env(:binance, :secret_key) - - case HTTPClient.get_binance("/api/v3/account", %{}, secret_key, api_key) do - {:ok, data} -> {:ok, Binance.Account.new(data)} - error -> error - end - end - - # User data streams - - @doc """ - Creates a socket listen key that later can be used as parameter to listen for - user related events. - - Returns `{:ok, %Binance.DataStream{}}` or `{:error, reason}`. - - ## Example - ``` - {:ok, - %Binance.DataStream{ - listen_key: "pqia91ma19a5s61cv6a81va65sdf19v8a65a1a5s61cv6a81va65sdf19v8a65a1" - } - } - ``` - - For more context please read https://github.com/binance/binance-spot-api-docs/blob/master/user-data-stream.md#create-a-listenkey - - """ - def create_listen_key() do - case HTTPClient.unsigned_request_binance("/api/v3/userDataStream", "", :post) do - {:ok, data} -> {:ok, Binance.DataStream.new(data)} - error -> error - end - end - - @doc """ - Socket listen key expires after 30 minutes withouth a pong response, this - allows keeping it alive. - - Returns `{:ok, %{}}` or `{:error, reason}`. - - For more context please read https://github.com/binance/binance-spot-api-docs/blob/master/user-data-stream.md#pingkeep-alive-a-listenkey - - """ - def keep_alive_listen_key(key) do - case HTTPClient.unsigned_request_binance( - "/api/v3/userDataStream", - "listenKey=#{key}", - :put - ) do - {:ok, data} -> {:ok, data} - error -> error - end - end - - @doc """ - Closes/disables the listen key. To be used when you stop listening to the - stream. - - Returns `{:ok, %{}}` or `{:error, reason}`. - - For more context please read https://github.com/binance/binance-spot-api-docs/blob/master/user-data-stream.md#close-a-listenkey - - """ - def close_listen_key(key) do - case HTTPClient.unsigned_request_binance( - "/api/v3/userDataStream?listenKey=#{key}", - nil, - :delete - ) do - {:ok, data} -> {:ok, data} - error -> error - end - end - - # Order - - @doc """ - Creates a new order on binance - - Returns `{:ok, %{}}` or `{:error, reason}`. - - In the case of a error on binance, for example with invalid parameters, `{:error, {:binance_error, %{code: code, msg: msg}}}` will be returned. - - Please read https://www.binance.com/restapipub.html#user-content-account-endpoints to understand all the parameters - """ - def create_order( - symbol, - side, - type, - quantity, - price \\ nil, - time_in_force \\ nil, - new_client_order_id \\ nil, - stop_price \\ nil, - iceberg_quantity \\ nil, - receiving_window \\ 1000, - timestamp \\ nil - ) do - timestamp = - case timestamp do - # timestamp needs to be in milliseconds - nil -> - :os.system_time(:millisecond) - - t -> - t - end - - arguments = - %{ - symbol: symbol, - side: side, - type: type, - quantity: quantity, - timestamp: timestamp, - recvWindow: receiving_window - } - |> Map.merge( - unless( - is_nil(new_client_order_id), - do: %{newClientOrderId: new_client_order_id}, - else: %{} - ) - ) - |> Map.merge( - unless(is_nil(stop_price), do: %{stopPrice: format_price(stop_price)}, else: %{}) - ) - |> Map.merge( - unless(is_nil(iceberg_quantity), do: %{icebergQty: iceberg_quantity}, else: %{}) - ) - |> Map.merge(unless(is_nil(time_in_force), do: %{timeInForce: time_in_force}, else: %{})) - |> Map.merge(unless(is_nil(price), do: %{price: format_price(price)}, else: %{})) - - case HTTPClient.signed_request_binance("/api/v3/order", arguments, :post) do - {:ok, %{"code" => code, "msg" => msg}} -> - {:error, {:binance_error, %{code: code, msg: msg}}} - - data -> - data - end - end - - @doc """ - Creates a new **limit** **buy** order - - Symbol can be a binance symbol in the form of `"ETHBTC"` or `%Binance.TradePair{}`. - - Returns `{:ok, %{}}` or `{:error, reason}` - """ - def order_limit_buy(symbol, quantity, price, time_in_force \\ "GTC") - - def order_limit_buy( - %Binance.TradePair{from: from, to: to} = symbol, - quantity, - price, - time_in_force - ) - when is_number(quantity) - when is_number(price) - when is_binary(from) - when is_binary(to) do - case find_symbol(symbol) do - {:ok, binance_symbol} -> order_limit_buy(binance_symbol, quantity, price, time_in_force) - e -> e - end - end - - def order_limit_buy(symbol, quantity, price, time_in_force) - when is_binary(symbol) - when is_number(quantity) - when is_number(price) do - create_order(symbol, "BUY", "LIMIT", quantity, price, time_in_force) - |> parse_order_response - end - - @doc """ - Creates a new **limit** **sell** order - - Symbol can be a binance symbol in the form of `"ETHBTC"` or `%Binance.TradePair{}`. - - Returns `{:ok, %{}}` or `{:error, reason}` - """ - def order_limit_sell(symbol, quantity, price, time_in_force \\ "GTC") - - def order_limit_sell( - %Binance.TradePair{from: from, to: to} = symbol, - quantity, - price, - time_in_force - ) - when is_number(quantity) - when is_number(price) - when is_binary(from) - when is_binary(to) do - case find_symbol(symbol) do - {:ok, binance_symbol} -> order_limit_sell(binance_symbol, quantity, price, time_in_force) - e -> e - end - end - - def order_limit_sell(symbol, quantity, price, time_in_force) - when is_binary(symbol) - when is_number(quantity) - when is_number(price) do - create_order(symbol, "SELL", "LIMIT", quantity, price, time_in_force) - |> parse_order_response - end - - @doc """ - Creates a new **market** **buy** order - - Symbol can be a binance symbol in the form of `"ETHBTC"` or `%Binance.TradePair{}`. - - Returns `{:ok, %{}}` or `{:error, reason}` - """ - def order_market_buy(%Binance.TradePair{from: from, to: to} = symbol, quantity) - when is_number(quantity) - when is_binary(from) - when is_binary(to) do - case find_symbol(symbol) do - {:ok, binance_symbol} -> order_market_buy(binance_symbol, quantity) - e -> e - end - end - - def order_market_buy(symbol, quantity) - when is_binary(symbol) - when is_number(quantity) do - create_order(symbol, "BUY", "MARKET", quantity) - end - - @doc """ - Creates a new **market** **sell** order - - Symbol can be a binance symbol in the form of `"ETHBTC"` or `%Binance.TradePair{}`. - - Returns `{:ok, %{}}` or `{:error, reason}` - """ - def order_market_sell(%Binance.TradePair{from: from, to: to} = symbol, quantity) - when is_number(quantity) - when is_binary(from) - when is_binary(to) do - case find_symbol(symbol) do - {:ok, binance_symbol} -> order_market_sell(binance_symbol, quantity) - e -> e - end - end - - def order_market_sell(symbol, quantity) - when is_binary(symbol) - when is_number(quantity) do - create_order(symbol, "SELL", "MARKET", quantity) - end - - defp parse_order_response({:ok, response}) do - {:ok, Binance.OrderResponse.new(response)} - end - - defp parse_order_response({ - :error, - { - :binance_error, - %{code: -2010, msg: "Account has insufficient balance for requested action."} = reason - } - }) do - {:error, %Binance.InsufficientBalanceError{reason: reason}} - end - - # Misc - - defp format_price(num) when is_float(num), do: :erlang.float_to_binary(num, [{:decimals, 8}]) - defp format_price(num) when is_integer(num), do: inspect(num) - defp format_price(num) when is_binary(num), do: num - - @doc """ - Searches and normalizes the symbol as it is listed on binance. - - To retrieve this information, a request to the binance API is done. The result is then **cached** to ensure the request is done only once. - - Order of which symbol comes first, and case sensitivity does not matter. - - Returns `{:ok, "SYMBOL"}` if successfully, or `{:error, reason}` otherwise. - - ## Examples - These 3 calls will result in the same result string: - ``` - find_symbol(%Binance.TradePair{from: "ETH", to: "REQ"}) - ``` - ``` - find_symbol(%Binance.TradePair{from: "REQ", to: "ETH"}) - ``` - ``` - find_symbol(%Binance.TradePair{from: "rEq", to: "eTH"}) - ``` - - Result: `{:ok, "REQETH"}` - - """ - def find_symbol(%Binance.TradePair{from: from, to: to} = tp) - when is_binary(from) - when is_binary(to) do - case Binance.SymbolCache.get() do - # cache hit - {:ok, data} -> - from = String.upcase(from) - to = String.upcase(to) - - found = Enum.filter(data, &Enum.member?([from <> to, to <> from], &1)) - - case Enum.count(found) do - 1 -> {:ok, found |> List.first()} - 0 -> {:error, :symbol_not_found} - end - - # cache miss - {:error, :not_initialized} -> - case get_all_prices() do - {:ok, price_data} -> - price_data - |> Enum.map(fn x -> x.symbol end) - |> Binance.SymbolCache.store() - - find_symbol(tp) - - err -> - err - end - - err -> - err - end - end - - # Open orders - - @doc """ - Get all open orders, alternatively open orders by symbol - - Returns `{:ok, [%Binance.Order{}]}` or `{:error, reason}`. - - Weight: 1 for a single symbol; 40 when the symbol parameter is omitted - - ## Example - ``` - {:ok, - [%Binance.Order{price: "0.1", origQty: "1.0", executedQty: "0.0", ...}, - %Binance.Order{...}, - %Binance.Order{...}, - %Binance.Order{...}, - %Binance.Order{...}, - %Binance.Order{...}, - ...]} - ``` - """ - def get_open_orders() do - api_key = Application.get_env(:binance, :api_key) - secret_key = Application.get_env(:binance, :secret_key) - - case HTTPClient.get_binance("/api/v3/openOrders", %{}, secret_key, api_key) do - {:ok, data} -> {:ok, Enum.map(data, &Binance.Order.new(&1))} - err -> err - end - end - - def get_open_orders(%Binance.TradePair{} = symbol) do - case find_symbol(symbol) do - {:ok, binance_symbol} -> get_open_orders(binance_symbol) - e -> e - end - end - - def get_open_orders(symbol) when is_binary(symbol) do - api_key = Application.get_env(:binance, :api_key) - secret_key = Application.get_env(:binance, :secret_key) - - case HTTPClient.get_binance("/api/v3/openOrders", %{:symbol => symbol}, secret_key, api_key) do - {:ok, data} -> {:ok, Enum.map(data, &Binance.Order.new(&1))} - err -> err - end - end - - # Order - - @doc """ - Get order by symbol, timestamp and either orderId or origClientOrderId are mandatory - - Returns `{:ok, [%Binance.Order{}]}` or `{:error, reason}`. - - Weight: 1 - - ## Example - ``` - {:ok, %Binance.Order{price: "0.1", origQty: "1.0", executedQty: "0.0", ...}} - ``` - - Info: https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md#query-order-user_data - """ - def get_order( - symbol, - timestamp, - order_id \\ nil, - orig_client_order_id \\ nil, - recv_window \\ nil - ) do - case is_binary(symbol) do - true -> - fetch_order(symbol, timestamp, order_id, orig_client_order_id, recv_window) - - false -> - case find_symbol(symbol) do - {:ok, binance_symbol} -> - fetch_order(binance_symbol, timestamp, order_id, orig_client_order_id, recv_window) - - e -> - e - end - end - end - - def fetch_order(symbol, timestamp, order_id, orig_client_order_id, recv_window) - when is_binary(symbol) - when is_integer(timestamp) - when is_integer(order_id) or is_binary(orig_client_order_id) do - api_key = Application.get_env(:binance, :api_key) - secret_key = Application.get_env(:binance, :secret_key) - - arguments = - %{ - symbol: symbol, - timestamp: timestamp - } - |> Map.merge(unless(is_nil(order_id), do: %{orderId: order_id}, else: %{})) - |> Map.merge( - unless( - is_nil(orig_client_order_id), - do: %{origClientOrderId: orig_client_order_id}, - else: %{} - ) - ) - |> Map.merge(unless(is_nil(recv_window), do: %{recvWindow: recv_window}, else: %{})) - - case HTTPClient.get_binance("/api/v3/order", arguments, secret_key, api_key) do - {:ok, data} -> {:ok, Binance.Order.new(data)} - err -> err - end - end - - @doc """ - Cancel an active order.. - - Symbol and either orderId or origClientOrderId must be sent. - - Returns `{:ok, %Binance.Order{}}` or `{:error, reason}`. - - Weight: 1 - - Info: https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md#cancel-order-trade - """ - def cancel_order( - symbol, - timestamp, - order_id \\ nil, - orig_client_order_id \\ nil, - new_client_order_id \\ nil, - recv_window \\ nil - ) do - case is_binary(symbol) do - true -> - cancel_order_( - symbol, - timestamp, - order_id, - orig_client_order_id, - new_client_order_id, - recv_window - ) - - false -> - case find_symbol(symbol) do - {:ok, binance_symbol} -> - cancel_order_( - binance_symbol, - timestamp, - order_id, - orig_client_order_id, - new_client_order_id, - recv_window - ) - - e -> - e - end - end - end - - defp cancel_order_( - symbol, - timestamp, - order_id, - orig_client_order_id, - new_client_order_id, - recv_window - ) - when is_binary(symbol) - when is_integer(timestamp) - when is_integer(order_id) or is_binary(orig_client_order_id) do - api_key = Application.get_env(:binance, :api_key) - secret_key = Application.get_env(:binance, :secret_key) - - arguments = - %{ - symbol: symbol, - timestamp: timestamp - } - |> Map.merge(unless(is_nil(order_id), do: %{orderId: order_id}, else: %{})) - |> Map.merge( - unless( - is_nil(orig_client_order_id), - do: %{origClientOrderId: orig_client_order_id}, - else: %{} - ) - ) - |> Map.merge( - unless(is_nil(new_client_order_id), - do: %{newClientOrderId: new_client_order_id}, - else: %{} - ) - ) - |> Map.merge(unless(is_nil(recv_window), do: %{recvWindow: recv_window}, else: %{})) - - case HTTPClient.delete_binance("/api/v3/order", arguments, secret_key, api_key) do - {:ok, data} -> {:ok, Binance.Order.new(data)} - err -> err - end - end -end +# defmodule BinanceOld do +# alias Binance.Rest.HTTPClient + +# # Server + +# @doc """ +# Pings binance API. Returns `{:ok, %{}}` if successful, `{:error, reason}` otherwise +# """ +# def ping() do +# HTTPClient.get_binance("/api/v3/ping") +# end + +# @doc """ +# Get binance server time in unix epoch. + +# Returns `{:ok, time}` if successful, `{:error, reason}` otherwise + +# ## Example +# ``` +# {:ok, 1515390701097} +# ``` + +# """ +# def get_server_time() do +# case HTTPClient.get_binance("/api/v3/time") do +# {:ok, %{"serverTime" => time}} -> {:ok, time} +# err -> err +# end +# end + +# def get_exchange_info() do +# case HTTPClient.get_binance("/api/v3/exchangeInfo") do +# {:ok, data} -> {:ok, Binance.ExchangeInfo.new(data)} +# err -> err +# end +# end + +# @doc """ +# Get historical trades +# https://binance-docs.github.io/apidocs/spot/en/#old-trade-lookup + +# Returns `{:ok, [%Binance.HistoricalTrade{}]}` or `{:error, reason}`. + +# ## Example +# {:ok, +# [%Binance.HistoricalTrade{ +# id: 192180149, +# is_best_match: true, +# is_buyer_maker: true, +# price: "1.79878000", +# qty: "55.50000000", +# quote_qty: "99.83229000", +# time: 1618341167715 +# }] +# } +# """ +# def get_historical_trades(symbol, limit, from_id) +# when is_binary(symbol) and is_integer(limit) do +# arguments = +# %{ +# symbol: symbol, +# limit: limit +# } +# |> Map.merge( +# unless( +# is_nil(from_id), +# do: %{fromId: from_id}, +# else: %{} +# ) +# ) + +# case HTTPClient.unsigned_request_binance( +# "/api/v3/historicalTrades", +# arguments, +# :get +# ) do +# {:ok, data} -> +# {:ok, Enum.map(data, &Binance.HistoricalTrade.new(&1))} + +# {:error, err} -> +# err +# end +# end + +# # Ticker + +# @doc """ +# Get all symbols and current prices listed in binance + +# Returns `{:ok, [%Binance.SymbolPrice{}]}` or `{:error, reason}`. + +# ## Example +# ``` +# {:ok, +# [%Binance.SymbolPrice{price: "0.07579300", symbol: "ETHBTC"}, +# %Binance.SymbolPrice{price: "0.01670200", symbol: "LTCBTC"}, +# %Binance.SymbolPrice{price: "0.00114550", symbol: "BNBBTC"}, +# %Binance.SymbolPrice{price: "0.00640000", symbol: "NEOBTC"}, +# %Binance.SymbolPrice{price: "0.00030000", symbol: "123456"}, +# %Binance.SymbolPrice{price: "0.04895000", symbol: "QTUMETH"}, +# ...]} +# ``` +# """ +# def get_all_prices() do +# case HTTPClient.get_binance("/api/v3/ticker/price") do +# {:ok, data} -> +# {:ok, Enum.map(data, &Binance.SymbolPrice.new(&1))} + +# err -> +# err +# end +# end + +# @doc """ +# Retrieves the current ticker information for the given trade pair. + +# Symbol can be a binance symbol in the form of `"ETHBTC"` or `%Binance.TradePair{}`. + +# Returns `{:ok, %Binance.Ticker{}}` or `{:error, reason}` + +# ## Example +# ``` +# {:ok, +# %Binance.Ticker{ask_price: "0.07548800", bid_price: "0.07542100", +# close_time: 1515391124878, count: 661676, first_id: 16797673, +# high_price: "0.07948000", last_id: 17459348, last_price: "0.07542000", +# low_price: "0.06330000", open_price: "0.06593800", open_time: 1515304724878, +# prev_close_price: "0.06593800", price_change: "0.00948200", +# price_change_percent: "14.380", volume: "507770.18500000", +# weighted_avg_price: "0.06946930"}} +# ``` +# """ +# def get_ticker(%Binance.TradePair{} = symbol) do +# case find_symbol(symbol) do +# {:ok, binance_symbol} -> get_ticker(binance_symbol) +# e -> e +# end +# end + +# def get_ticker(symbol) when is_binary(symbol) do +# case HTTPClient.get_binance("/api/v3/ticker/24hr?symbol=#{symbol}") do +# {:ok, data} -> {:ok, Binance.Ticker.new(data)} +# err -> err +# end +# end + +# @doc """ +# Retrieves klines for a symbol, provided a given interval, e.g. "1h". + +# Function can also take in a 'limit' argument to reduce the number of intervals. + +# Returns `{:ok, [%Binance.Kline{}]` or `{:error, reason}` + +# ## Example +# ``` +# {:ok, +# [ +# %Binance.Kline{ +# close: "0.16527000", +# close_time: 1617861599999, +# high: "0.17100000", +# ignore: "0", +# low: "0.16352000", +# number_of_trades: 16167, +# open: "0.17088000", +# open_time: 1617858000000, +# quote_asset_volume: "7713624.32966000", +# taker_buy_base_asset_volume: "22020677.70000000", +# taker_buy_quote_asset_volume: "3668705.43042700", +# volume: "46282422.20000000" +# }, +# %Binance.Kline{ +# ... +# ``` +# """ + +# def get_klines(symbol, interval, limit \\ 500) when is_binary(symbol) do +# case HTTPClient.get_binance( +# "/api/v3/klines?symbol=#{symbol}&interval=#{interval}&limit=#{limit}" +# ) do +# {:ok, data} -> +# {:ok, Enum.map(data, &Binance.Kline.new(&1))} + +# err -> +# err +# end +# end + +# @doc """ +# Retrieves the bids & asks of the order book up to the depth for the given symbol + +# Returns `{:ok, %{bids: [...], asks: [...], lastUpdateId: 12345}}` or `{:error, reason}` + +# ## Example +# ``` +# {:ok, +# %Binance.OrderBook{ +# asks: [ +# ["8400.00000000", "2.04078100", []], +# ["8405.35000000", "0.50354700", []], +# ["8406.00000000", "0.32769800", []], +# ["8406.33000000", "0.00239000", []], +# ["8406.51000000", "0.03241000", []] +# ], +# bids: [ +# ["8393.00000000", "0.20453200", []], +# ["8392.57000000", "0.02639000", []], +# ["8392.00000000", "1.40893300", []], +# ["8390.09000000", "0.07047100", []], +# ["8388.72000000", "0.04577400", []] +# ], +# last_update_id: 113634395 +# } +# } +# ``` +# """ +# def get_depth(symbol, limit) do +# case HTTPClient.get_binance("/api/v3/depth?symbol=#{symbol}&limit=#{limit}") do +# {:ok, data} -> {:ok, Binance.OrderBook.new(data)} +# err -> err +# end +# end + +# @doc """ +# Fetches system status. + +# Returns `{:ok, %Binance.SystemStatus{}}` or `{:error, reason}`. +# """ +# def get_system_status() do +# case HTTPClient.get_binance("/sapi/v1/system/status") do +# {:ok, data} -> {:ok, Binance.SystemStatus.new(data)} +# error -> error +# end +# end + +# # Account + +# @doc """ +# Fetches user account from binance + +# Returns `{:ok, %Binance.Account{}}` or `{:error, reason}`. + +# In the case of a error on binance, for example with invalid parameters, `{:error, {:binance_error, %{code: code, msg: msg}}}` will be returned. + +# Please read https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md#account-information-user_data to understand API +# """ + +# def get_account() do +# api_key = Application.get_env(:binance, :api_key) +# secret_key = Application.get_env(:binance, :secret_key) + +# case HTTPClient.get_binance("/api/v3/account", %{}, secret_key, api_key) do +# {:ok, data} -> {:ok, Binance.Account.new(data)} +# error -> error +# end +# end + +# # User data streams + +# @doc """ +# Creates a socket listen key that later can be used as parameter to listen for +# user related events. + +# Returns `{:ok, %Binance.DataStream{}}` or `{:error, reason}`. + +# ## Example +# ``` +# {:ok, +# %Binance.DataStream{ +# listen_key: "pqia91ma19a5s61cv6a81va65sdf19v8a65a1a5s61cv6a81va65sdf19v8a65a1" +# } +# } +# ``` + +# For more context please read https://github.com/binance/binance-spot-api-docs/blob/master/user-data-stream.md#create-a-listenkey + +# """ +# def create_listen_key() do +# case HTTPClient.unsigned_request_binance("/api/v3/userDataStream", "", :post) do +# {:ok, data} -> {:ok, Binance.DataStream.new(data)} +# error -> error +# end +# end + +# @doc """ +# Socket listen key expires after 30 minutes withouth a pong response, this +# allows keeping it alive. + +# Returns `{:ok, %{}}` or `{:error, reason}`. + +# For more context please read https://github.com/binance/binance-spot-api-docs/blob/master/user-data-stream.md#pingkeep-alive-a-listenkey + +# """ +# def keep_alive_listen_key(key) do +# case HTTPClient.unsigned_request_binance( +# "/api/v3/userDataStream", +# "listenKey=#{key}", +# :put +# ) do +# {:ok, data} -> {:ok, data} +# error -> error +# end +# end + +# @doc """ +# Closes/disables the listen key. To be used when you stop listening to the +# stream. + +# Returns `{:ok, %{}}` or `{:error, reason}`. + +# For more context please read https://github.com/binance/binance-spot-api-docs/blob/master/user-data-stream.md#close-a-listenkey + +# """ +# def close_listen_key(key) do +# case HTTPClient.unsigned_request_binance( +# "/api/v3/userDataStream?listenKey=#{key}", +# nil, +# :delete +# ) do +# {:ok, data} -> {:ok, data} +# error -> error +# end +# end + +# # Order + +# @doc """ +# Creates a new order on binance + +# Returns `{:ok, %{}}` or `{:error, reason}`. + +# In the case of a error on binance, for example with invalid parameters, `{:error, {:binance_error, %{code: code, msg: msg}}}` will be returned. + +# Please read https://www.binance.com/restapipub.html#user-content-account-endpoints to understand all the parameters +# """ +# def create_order( +# symbol, +# side, +# type, +# quantity, +# price \\ nil, +# time_in_force \\ nil, +# new_client_order_id \\ nil, +# stop_price \\ nil, +# iceberg_quantity \\ nil, +# receiving_window \\ 1000, +# timestamp \\ nil +# ) do +# timestamp = +# case timestamp do +# # timestamp needs to be in milliseconds +# nil -> +# :os.system_time(:millisecond) + +# t -> +# t +# end + +# arguments = +# %{ +# symbol: symbol, +# side: side, +# type: type, +# quantity: quantity, +# timestamp: timestamp, +# recvWindow: receiving_window +# } +# |> Map.merge( +# unless( +# is_nil(new_client_order_id), +# do: %{newClientOrderId: new_client_order_id}, +# else: %{} +# ) +# ) +# |> Map.merge( +# unless(is_nil(stop_price), do: %{stopPrice: format_price(stop_price)}, else: %{}) +# ) +# |> Map.merge( +# unless(is_nil(iceberg_quantity), do: %{icebergQty: iceberg_quantity}, else: %{}) +# ) +# |> Map.merge(unless(is_nil(time_in_force), do: %{timeInForce: time_in_force}, else: %{})) +# |> Map.merge(unless(is_nil(price), do: %{price: format_price(price)}, else: %{})) + +# case HTTPClient.signed_request_binance("/api/v3/order", arguments, :post) do +# {:ok, %{"code" => code, "msg" => msg}} -> +# {:error, {:binance_error, %{code: code, msg: msg}}} + +# data -> +# data +# end +# end + +# @doc """ +# Creates a new **limit** **buy** order + +# Symbol can be a binance symbol in the form of `"ETHBTC"` or `%Binance.TradePair{}`. + +# Returns `{:ok, %{}}` or `{:error, reason}` +# """ +# def order_limit_buy(symbol, quantity, price, time_in_force \\ "GTC") + +# def order_limit_buy( +# %Binance.TradePair{from: from, to: to} = symbol, +# quantity, +# price, +# time_in_force +# ) +# when is_number(quantity) +# when is_number(price) +# when is_binary(from) +# when is_binary(to) do +# case find_symbol(symbol) do +# {:ok, binance_symbol} -> order_limit_buy(binance_symbol, quantity, price, time_in_force) +# e -> e +# end +# end + +# def order_limit_buy(symbol, quantity, price, time_in_force) +# when is_binary(symbol) +# when is_number(quantity) +# when is_number(price) do +# create_order(symbol, "BUY", "LIMIT", quantity, price, time_in_force) +# |> parse_order_response +# end + +# @doc """ +# Creates a new **limit** **sell** order + +# Symbol can be a binance symbol in the form of `"ETHBTC"` or `%Binance.TradePair{}`. + +# Returns `{:ok, %{}}` or `{:error, reason}` +# """ +# def order_limit_sell(symbol, quantity, price, time_in_force \\ "GTC") + +# def order_limit_sell( +# %Binance.TradePair{from: from, to: to} = symbol, +# quantity, +# price, +# time_in_force +# ) +# when is_number(quantity) +# when is_number(price) +# when is_binary(from) +# when is_binary(to) do +# case find_symbol(symbol) do +# {:ok, binance_symbol} -> order_limit_sell(binance_symbol, quantity, price, time_in_force) +# e -> e +# end +# end + +# def order_limit_sell(symbol, quantity, price, time_in_force) +# when is_binary(symbol) +# when is_number(quantity) +# when is_number(price) do +# create_order(symbol, "SELL", "LIMIT", quantity, price, time_in_force) +# |> parse_order_response +# end + +# @doc """ +# Creates a new **market** **buy** order + +# Symbol can be a binance symbol in the form of `"ETHBTC"` or `%Binance.TradePair{}`. + +# Returns `{:ok, %{}}` or `{:error, reason}` +# """ +# def order_market_buy(%Binance.TradePair{from: from, to: to} = symbol, quantity) +# when is_number(quantity) +# when is_binary(from) +# when is_binary(to) do +# case find_symbol(symbol) do +# {:ok, binance_symbol} -> order_market_buy(binance_symbol, quantity) +# e -> e +# end +# end + +# def order_market_buy(symbol, quantity) +# when is_binary(symbol) +# when is_number(quantity) do +# create_order(symbol, "BUY", "MARKET", quantity) +# end + +# @doc """ +# Creates a new **market** **sell** order + +# Symbol can be a binance symbol in the form of `"ETHBTC"` or `%Binance.TradePair{}`. + +# Returns `{:ok, %{}}` or `{:error, reason}` +# """ +# def order_market_sell(%Binance.TradePair{from: from, to: to} = symbol, quantity) +# when is_number(quantity) +# when is_binary(from) +# when is_binary(to) do +# case find_symbol(symbol) do +# {:ok, binance_symbol} -> order_market_sell(binance_symbol, quantity) +# e -> e +# end +# end + +# def order_market_sell(symbol, quantity) +# when is_binary(symbol) +# when is_number(quantity) do +# create_order(symbol, "SELL", "MARKET", quantity) +# end + +# defp parse_order_response({:ok, response}) do +# {:ok, Binance.OrderResponse.new(response)} +# end + +# defp parse_order_response({ +# :error, +# { +# :binance_error, +# %{code: -2010, msg: "Account has insufficient balance for requested action."} = reason +# } +# }) do +# {:error, %Binance.InsufficientBalanceError{reason: reason}} +# end + +# # Misc + +# defp format_price(num) when is_float(num), do: :erlang.float_to_binary(num, [{:decimals, 8}]) +# defp format_price(num) when is_integer(num), do: inspect(num) +# defp format_price(num) when is_binary(num), do: num + +# @doc """ +# Searches and normalizes the symbol as it is listed on binance. + +# To retrieve this information, a request to the binance API is done. The result is then **cached** to ensure the request is done only once. + +# Order of which symbol comes first, and case sensitivity does not matter. + +# Returns `{:ok, "SYMBOL"}` if successfully, or `{:error, reason}` otherwise. + +# ## Examples +# These 3 calls will result in the same result string: +# ``` +# find_symbol(%Binance.TradePair{from: "ETH", to: "REQ"}) +# ``` +# ``` +# find_symbol(%Binance.TradePair{from: "REQ", to: "ETH"}) +# ``` +# ``` +# find_symbol(%Binance.TradePair{from: "rEq", to: "eTH"}) +# ``` + +# Result: `{:ok, "REQETH"}` + +# """ +# def find_symbol(%Binance.TradePair{from: from, to: to} = tp) +# when is_binary(from) +# when is_binary(to) do +# case Binance.SymbolCache.get() do +# # cache hit +# {:ok, data} -> +# from = String.upcase(from) +# to = String.upcase(to) + +# found = Enum.filter(data, &Enum.member?([from <> to, to <> from], &1)) + +# case Enum.count(found) do +# 1 -> {:ok, found |> List.first()} +# 0 -> {:error, :symbol_not_found} +# end + +# # cache miss +# {:error, :not_initialized} -> +# case get_all_prices() do +# {:ok, price_data} -> +# price_data +# |> Enum.map(fn x -> x.symbol end) +# |> Binance.SymbolCache.store() + +# find_symbol(tp) + +# err -> +# err +# end + +# err -> +# err +# end +# end + +# # Open orders + +# @doc """ +# Get all open orders, alternatively open orders by symbol + +# Returns `{:ok, [%Binance.Order{}]}` or `{:error, reason}`. + +# Weight: 1 for a single symbol; 40 when the symbol parameter is omitted + +# ## Example +# ``` +# {:ok, +# [%Binance.Order{price: "0.1", origQty: "1.0", executedQty: "0.0", ...}, +# %Binance.Order{...}, +# %Binance.Order{...}, +# %Binance.Order{...}, +# %Binance.Order{...}, +# %Binance.Order{...}, +# ...]} +# ``` +# """ +# def get_open_orders() do +# api_key = Application.get_env(:binance, :api_key) +# secret_key = Application.get_env(:binance, :secret_key) + +# case HTTPClient.get_binance("/api/v3/openOrders", %{}, secret_key, api_key) do +# {:ok, data} -> {:ok, Enum.map(data, &Binance.Order.new(&1))} +# err -> err +# end +# end + +# def get_open_orders(%Binance.TradePair{} = symbol) do +# case find_symbol(symbol) do +# {:ok, binance_symbol} -> get_open_orders(binance_symbol) +# e -> e +# end +# end + +# def get_open_orders(symbol) when is_binary(symbol) do +# api_key = Application.get_env(:binance, :api_key) +# secret_key = Application.get_env(:binance, :secret_key) + +# case HTTPClient.get_binance("/api/v3/openOrders", %{:symbol => symbol}, secret_key, api_key) do +# {:ok, data} -> {:ok, Enum.map(data, &Binance.Order.new(&1))} +# err -> err +# end +# end + +# # Order + +# @doc """ +# Get order by symbol, timestamp and either orderId or origClientOrderId are mandatory + +# Returns `{:ok, [%Binance.Order{}]}` or `{:error, reason}`. + +# Weight: 1 + +# ## Example +# ``` +# {:ok, %Binance.Order{price: "0.1", origQty: "1.0", executedQty: "0.0", ...}} +# ``` + +# Info: https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md#query-order-user_data +# """ +# def get_order( +# symbol, +# timestamp, +# order_id \\ nil, +# orig_client_order_id \\ nil, +# recv_window \\ nil +# ) do +# case is_binary(symbol) do +# true -> +# fetch_order(symbol, timestamp, order_id, orig_client_order_id, recv_window) + +# false -> +# case find_symbol(symbol) do +# {:ok, binance_symbol} -> +# fetch_order(binance_symbol, timestamp, order_id, orig_client_order_id, recv_window) + +# e -> +# e +# end +# end +# end + +# def fetch_order(symbol, timestamp, order_id, orig_client_order_id, recv_window) +# when is_binary(symbol) +# when is_integer(timestamp) +# when is_integer(order_id) or is_binary(orig_client_order_id) do +# api_key = Application.get_env(:binance, :api_key) +# secret_key = Application.get_env(:binance, :secret_key) + +# arguments = +# %{ +# symbol: symbol, +# timestamp: timestamp +# } +# |> Map.merge(unless(is_nil(order_id), do: %{orderId: order_id}, else: %{})) +# |> Map.merge( +# unless( +# is_nil(orig_client_order_id), +# do: %{origClientOrderId: orig_client_order_id}, +# else: %{} +# ) +# ) +# |> Map.merge(unless(is_nil(recv_window), do: %{recvWindow: recv_window}, else: %{})) + +# case HTTPClient.get_binance("/api/v3/order", arguments, secret_key, api_key) do +# {:ok, data} -> {:ok, Binance.Order.new(data)} +# err -> err +# end +# end + +# @doc """ +# Cancel an active order.. + +# Symbol and either orderId or origClientOrderId must be sent. + +# Returns `{:ok, %Binance.Order{}}` or `{:error, reason}`. + +# Weight: 1 + +# Info: https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md#cancel-order-trade +# """ +# def cancel_order( +# symbol, +# timestamp, +# order_id \\ nil, +# orig_client_order_id \\ nil, +# new_client_order_id \\ nil, +# recv_window \\ nil +# ) do +# case is_binary(symbol) do +# true -> +# cancel_order_( +# symbol, +# timestamp, +# order_id, +# orig_client_order_id, +# new_client_order_id, +# recv_window +# ) + +# false -> +# case find_symbol(symbol) do +# {:ok, binance_symbol} -> +# cancel_order_( +# binance_symbol, +# timestamp, +# order_id, +# orig_client_order_id, +# new_client_order_id, +# recv_window +# ) + +# e -> +# e +# end +# end +# end + +# defp cancel_order_( +# symbol, +# timestamp, +# order_id, +# orig_client_order_id, +# new_client_order_id, +# recv_window +# ) +# when is_binary(symbol) +# when is_integer(timestamp) +# when is_integer(order_id) or is_binary(orig_client_order_id) do +# api_key = Application.get_env(:binance, :api_key) +# secret_key = Application.get_env(:binance, :secret_key) + +# arguments = +# %{ +# symbol: symbol, +# timestamp: timestamp +# } +# |> Map.merge(unless(is_nil(order_id), do: %{orderId: order_id}, else: %{})) +# |> Map.merge( +# unless( +# is_nil(orig_client_order_id), +# do: %{origClientOrderId: orig_client_order_id}, +# else: %{} +# ) +# ) +# |> Map.merge( +# unless(is_nil(new_client_order_id), +# do: %{newClientOrderId: new_client_order_id}, +# else: %{} +# ) +# ) +# |> Map.merge(unless(is_nil(recv_window), do: %{recvWindow: recv_window}, else: %{})) + +# case HTTPClient.delete_binance("/api/v3/order", arguments, secret_key, api_key) do +# {:ok, data} -> {:ok, Binance.Order.new(data)} +# err -> err +# end +# end +# end diff --git a/test/binance_test.exs b/test/binance_test.exs index c5ce6a8..b738c88 100644 --- a/test/binance_test.exs +++ b/test/binance_test.exs @@ -15,25 +15,27 @@ defmodule BinanceTest do test "get_server_time success return an ok, time tuple" do use_cassette "get_server_time_ok" do - assert Binance.Market.get_server_time() == {:ok, 1_616_592_268_319} + assert Binance.Market.get_time() == {:ok, 1_616_592_268_319} end end test "get_historical_trades success returns the latest trades" do use_cassette "get_historical_trades_ok" do - assert {:ok, response} = Binance.Market.get_historical_trades("XRPUSDT", 1, nil) + assert {:ok, response} = Binance.Market.get_historical_trades("XRPUSDT", limit: 1) assert [%Binance.Structs.HistoricalTrade{} | _tail] = response end use_cassette "get_historical_trades_from_id_ok" do - assert {:ok, response} = Binance.get_historical_trades("XRPUSDT", 1, 28457) - assert [%Binance.HistoricalTrade{} | _tail] = response + assert {:ok, response} = + Binance.Market.get_historical_trades("XRPUSDT", limit: 1, fromId: 28457) + + assert [%Binance.Structs.HistoricalTrade{} | _tail] = response end end test "get_exchange_info success returns the trading rules and symbol information" do use_cassette "get_exchange_info_ok" do - assert {:ok, %Binance.ExchangeInfo{} = info} = Binance.get_exchange_info() + assert {:ok, %Binance.Structs.ExchangeInfo{} = info} = Binance.Market.get_exchange_info() assert info.timezone == "UTC" assert info.server_time != nil @@ -125,15 +127,18 @@ defmodule BinanceTest do test "get_system_status success returns the system status" do use_cassette "get_system_status_ok" do - assert {:ok, response} = Binance.get_system_status() - assert %Binance.SystemStatus{status: 0, msg: "normal"} == response + assert {:ok, response} = Binance.Wallet.get_system_status() + assert %Binance.Structs.SystemStatus{status: 0, msg: "normal"} == response end end test "get_all_prices returns a list of prices for every symbol" do use_cassette "get_all_prices_ok" do - assert {:ok, symbol_prices} = Binance.get_all_prices() - assert [%Binance.SymbolPrice{price: "0.03040500", symbol: "ETHBTC"} | _tail] = symbol_prices + assert {:ok, symbol_prices} = Binance.Market.get_ticker_price() + + assert [%Binance.Structs.SymbolPrice{price: "0.03040500", symbol: "ETHBTC"} | _tail] = + symbol_prices + assert symbol_prices |> Enum.count() == 1363 end end @@ -143,21 +148,21 @@ defmodule BinanceTest do use_cassette "get_ticker_ok" do assert { :ok, - %Binance.Ticker{ + %Binance.Structs.Ticker{ ask_price: "0.00344600", bid_price: "0.00344400", close_time: 1_616_593_123_159, count: 65580 } - } = Binance.get_ticker("LTCBTC") + } = Binance.Market.get_ticker(symbol: "LTCBTC") end end test "returns an error tuple when the symbol doesn't exist" do use_cassette "get_ticker_error" do - assert Binance.get_ticker("IDONTEXIST") == { + assert Binance.Market.get_ticker_24hr(symbol: "IDONTEXIST") == { :error, - %{"code" => -1121, "msg" => "Invalid symbol."} + {:binance_error, %{code: -1121, msg: "Invalid symbol."}} } end end @@ -166,7 +171,7 @@ defmodule BinanceTest do describe ".get_klines" do test "returns the klines for a given symbol and interval" do use_cassette "get_klines_ok" do - assert Binance.get_klines("LTCBTC", "1h") == + assert Binance.Market.get_klines("LTCBTC", "1h") == { :ok, [ @@ -205,8 +210,8 @@ defmodule BinanceTest do test "returns error with invalid interval" do use_cassette "get_klines_interval_err" do - assert Binance.get_klines("LTCBTC", "1") == - {:error, %{"code" => -1120, "msg" => "Invalid interval."}} + assert Binance.Market.get_klines("LTCBTC", "1") == + {:error, {:binance_error, %{code: -1120, msg: "Invalid interval."}}} end end end @@ -214,9 +219,9 @@ defmodule BinanceTest do describe ".get_depth" do test "returns the bids & asks up to the given depth" do use_cassette "get_depth_ok" do - assert Binance.get_depth("BTCUSDT", 5) == { + assert Binance.Market.get_depth("BTCUSDT", limit: 5) == { :ok, - %Binance.OrderBook{ + %Binance.Structs.OrderBook{ asks: [ ["56905.88000000", "0.01215200"], ["56906.08000000", "0.52000000"], @@ -239,9 +244,9 @@ defmodule BinanceTest do test "returns an error tuple when the symbol doesn't exist" do use_cassette "get_depth_error" do - assert Binance.get_depth("IDONTEXIST", 1000) == { + assert Binance.Market.get_depth("IDONTEXIST", limit: 1000) == { :error, - %{"code" => -1121, "msg" => "Invalid symbol."} + {:binance_error, %{code: -1121, msg: "Invalid symbol."}} } end end @@ -250,8 +255,8 @@ defmodule BinanceTest do describe ".order_limit_buy" do test "creates an order with a duration of good til cancel by default" do use_cassette "order_limit_buy_good_til_cancel_default_duration_success" do - assert {:ok, %Binance.OrderResponse{} = response} = - Binance.order_limit_buy("LTCBTC", 0.1, 0.01) + assert {:ok, %Binance.Structs.OrderResponse{} = response} = + Binance.Trade.post_order("LTCBTC", "BUY", "LIMIT", quantity: 0.1, price: 0.01) assert response.client_order_id == "9kITBshSwrClye1HJcLM3j" assert response.executed_qty == "0.00000000" @@ -269,8 +274,8 @@ defmodule BinanceTest do test "creates an order with a duration of good til cancel by default(string quantity and price)" do use_cassette "order_limit_buy_good_til_cancel_default_duration_success" do - assert {:ok, %Binance.OrderResponse{} = response} = - Binance.order_limit_buy("LTCBTC", "0.1", "0.01") + assert {:ok, %Binance.Structs.OrderResponse{} = response} = + Binance.Trade.post_order("LTCBTC", "BUY", "LIMIT", quantity: 0.1, price: 0.01) assert response.client_order_id == "9kITBshSwrClye1HJcLM3j" assert response.executed_qty == "0.00000000" @@ -288,8 +293,12 @@ defmodule BinanceTest do test "can create an order with a fill or kill duration" do use_cassette "order_limit_buy_fill_or_kill_success" do - assert {:ok, %Binance.OrderResponse{} = response} = - Binance.order_limit_buy("LTCBTC", 0.1, 0.01, "FOK") + assert {:ok, %Binance.Structs.OrderResponse{} = response} = + Binance.Trade.post_order("LTCBTC", "BUY", "LIMIT", + quantity: 0.1, + price: 0.01, + timeInForce: "FOK" + ) assert response.client_order_id == "dY67P33S4IxPnJGx5EtuSf" assert response.executed_qty == "0.00000000" @@ -307,8 +316,12 @@ defmodule BinanceTest do test "can create an order with am immediate or cancel duration" do use_cassette "order_limit_buy_immediate_or_cancel_success" do - assert {:ok, %Binance.OrderResponse{} = response} = - Binance.order_limit_buy("LTCBTC", 0.1, 0.01, "IOC") + assert {:ok, %Binance.Structs.OrderResponse{} = response} = + Binance.Trade.post_order("LTCBTC", "BUY", "LIMIT", + quantity: 0.1, + price: 0.01, + timeInForce: "IOC" + ) assert response.client_order_id == "zyMyhtRENlvFHrl4CitDe0" assert response.executed_qty == "0.00000000" @@ -326,7 +339,12 @@ defmodule BinanceTest do test "returns an insufficient balance error tuple" do use_cassette "order_limit_buy_error_insufficient_balance" do - assert {:error, reason} = Binance.order_limit_buy("LTCBTC", 10_000, 0.001, "FOK") + assert {:error, reason} = + Binance.Trade.post_order("LTCBTC", "BUY", "LIMIT", + quantity: 10_000, + price: 0.001, + timeInForce: "FOK" + ) assert reason == %Binance.InsufficientBalanceError{ reason: %{ @@ -344,8 +362,11 @@ defmodule BinanceTest do end use_cassette "order_limit_buy_very_low_price", custom_matchers: [matches_price] do - assert {:ok, %Binance.OrderResponse{} = response} = - Binance.order_limit_buy("DOGEBTC", 100, 0.000001) + assert {:ok, %Binance.Structs.OrderResponse{} = response} = + Binance.Trade.post_order("DOGEBTC", "BUY", "LIMIT", + quantity: 100, + price: 0.000001 + ) assert response.client_order_id == "cyNmMk8rcgunB0REmUlbyv" assert response.executed_qty == "0.00000000" @@ -365,8 +386,11 @@ defmodule BinanceTest do describe ".order_limit_sell" do test "creates an order with a duration of good til cancel by default" do use_cassette "order_limit_sell_good_til_cancel_default_duration_success" do - assert {:ok, %Binance.OrderResponse{} = response} = - Binance.order_limit_sell("BTCUSDT", 0.001, 50_000) + assert {:ok, %Binance.Structs.OrderResponse{} = response} = + Binance.Trade.post_order("BTCUSDT", "SELL", "LIMIT", + quantity: 0.001, + price: 50_000 + ) assert response.client_order_id == "9UFMPloZsQ3eshCx66PVqD" assert response.executed_qty == "0.00000000" @@ -384,8 +408,12 @@ defmodule BinanceTest do test "can create an order with a fill or kill duration" do use_cassette "order_limit_sell_fill_or_kill_success" do - assert {:ok, %Binance.OrderResponse{} = response} = - Binance.order_limit_sell("BTCUSDT", 0.001, 50_000, "FOK") + assert {:ok, %Binance.Structs.OrderResponse{} = response} = + Binance.Trade.post_order("BTCUSDT", "SELL", "LIMIT", + quantity: 0.001, + price: 50_000, + timeInForce: "FOK" + ) assert response.client_order_id == "lKYECwEPSTPzurwx6emuN2" assert response.executed_qty == "0.00000000" @@ -403,8 +431,12 @@ defmodule BinanceTest do test "can create an order with am immediate or cancel duration" do use_cassette "order_limit_sell_immediate_or_cancel_success" do - assert {:ok, %Binance.OrderResponse{} = response} = - Binance.order_limit_sell("BTCUSDT", 0.001, 50_000, "IOC") + assert {:ok, %Binance.Structs.OrderResponse{} = response} = + Binance.Trade.post_order("BTCUSDT", "SELL", "LIMIT", + quantity: 0.001, + price: 50_000, + timeInForce: "IOC" + ) assert response.client_order_id == "roSkLhwX9KCgYqr4yFPx1V" assert response.executed_qty == "0.00000000" @@ -424,8 +456,8 @@ defmodule BinanceTest do describe ".get_open_orders" do test "when called without symbol returns all open orders for all symbols" do use_cassette "get_open_orders_without_symbol_success" do - assert {:ok, [%Binance.Order{} = order_1, %Binance.Order{} = order_2]} = - Binance.get_open_orders() + assert {:ok, [%Binance.Structs.Order{} = order_1, %Binance.Structs.Order{} = order_2]} = + Binance.Trade.get_open_orders() # open order 1 @@ -469,31 +501,8 @@ defmodule BinanceTest do test "when called with symbol returns all open orders for that symbols(string)" do use_cassette "get_open_orders_with_symbol_string_success" do - assert {:ok, [%Binance.Order{} = result]} = Binance.get_open_orders("WABIBTC") - - assert result.client_order_id == "web_db04d8a507f14135a9a9d4467bc541a1" - assert result.cummulative_quote_qty == "0.00000000" - assert result.executed_qty == "0.00000000" - assert result.iceberg_qty == "0.00000000" - assert result.is_working == true - assert result.order_id == 42_240_233 - assert result.orig_qty == "215.00000000" - assert result.price == "0.00064200" - assert result.side == "SELL" - assert result.status == "NEW" - assert result.stop_price == "0.00000000" - assert result.symbol == "WABIBTC" - assert result.time == 1_556_710_717_616 - assert result.time_in_force == "GTC" - assert result.type == "LIMIT" - assert result.update_time == 1_556_710_717_616 - end - end - - test "when called with symbol returns all open orders for that symbols(TradePair struct)" do - use_cassette "get_open_orders_with_trade_pair_struct_string_success" do - assert {:ok, [%Binance.Order{} = result]} = - Binance.get_open_orders(%Binance.TradePair{:from => "WABI", :to => "BTC"}) + assert {:ok, [%Binance.Structs.Order{} = result]} = + Binance.Trade.get_open_orders(symbol: "WABIBTC") assert result.client_order_id == "web_db04d8a507f14135a9a9d4467bc541a1" assert result.cummulative_quote_qty == "0.00000000" @@ -516,41 +525,12 @@ defmodule BinanceTest do end describe ".cancel_order" do - test "when called with symbol(struct), orderId and timestamp cancels order" do - use_cassette "cancel_order_by_struct_symbol_orderId_and_timestamp_success" do - assert {:ok, %Binance.Order{} = order} = - Binance.cancel_order( - %Binance.TradePair{:from => "XRP", :to => "USDT"}, - 1_564_000_518_279, - 212_213_771 - ) - - assert order.client_order_id == "iBz2JsX9hCsR6LRv6lqKld" - assert order.cummulative_quote_qty == "0.00000000" - assert order.executed_qty == "0.00000000" - assert order.iceberg_qty == nil - assert order.is_working == nil - assert order.order_id == 212_213_771 - assert order.orig_qty == "100.00000000" - assert order.price == "0.30000000" - assert order.side == "BUY" - assert order.status == "CANCELED" - assert order.stop_price == nil - assert order.symbol == "XRPUSDT" - assert order.time == nil - assert order.time_in_force == "GTC" - assert order.type == "LIMIT" - assert order.update_time == nil - end - end - test "when called with symbol(string), orderId and timestamp cancels order" do use_cassette "cancel_order_by_symbol_string_orderid_and_timestamp_success" do - assert {:ok, %Binance.Order{} = order} = - Binance.cancel_order( - "XRPUSDT", - 1_564_000_518_279, - 212_213_771 + assert {:ok, %Binance.Structs.Order{} = order} = + Binance.Trade.delete_order("XRPUSDT", + timestamp: 1_564_000_518_279, + orderId: 212_213_771 ) assert order.client_order_id == "iBz2JsX9hCsR6LRv6lqKld" @@ -574,12 +554,11 @@ defmodule BinanceTest do test "when called with symbol(string), clientOrderId and timestamp cancels order" do use_cassette "cancel_order_by_symbol_string_clientOrderId_and_timestamp_success" do - assert {:ok, %Binance.Order{} = order} = - Binance.cancel_order( + assert {:ok, %Binance.Structs.Order{} = order} = + Binance.Trade.delete_order( "XRPUSDT", - 1_564_000_518_279, - nil, - "ZM1ReQ1ZwiVoaGgcJcumhH" + timestamp: 1_564_000_518_279, + origClientOrderId: "ZM1ReQ1ZwiVoaGgcJcumhH" ) assert order.client_order_id == "gKMdjRw8fDkpObd0fXjCRZ" From 53333ecec843d0390750396566de827b7e60d721 Mon Sep 17 00:00:00 2001 From: David Mohl Date: Sun, 2 Jul 2023 19:17:03 +1000 Subject: [PATCH 10/25] Backport InsufficientBalanceError --- lib/binance.ex | 15 +++++++++++---- lib/binance/errors/insufficient_balance_error.ex | 4 ++++ lib/binance/structs/insufficient_balance_error.ex | 4 ---- test/binance_test.exs | 12 ++++++------ 4 files changed, 21 insertions(+), 14 deletions(-) create mode 100644 lib/binance/errors/insufficient_balance_error.ex delete mode 100644 lib/binance/structs/insufficient_balance_error.ex diff --git a/lib/binance.ex b/lib/binance.ex index 3e5704a..de6d06d 100644 --- a/lib/binance.ex +++ b/lib/binance.ex @@ -3,6 +3,13 @@ defmodule Binance do def format_price(num) when is_float(num), do: :erlang.float_to_binary(num, [{:decimals, 8}]) def format_price(num) when is_integer(num), do: inspect(num) def format_price(num) when is_binary(num), do: num + + def format_error(%{"code" => -2010, "msg" => msg}), + do: {:binance_error, %Binance.Errors.InsufficientBalanceError{code: -2010, msg: msg}} + + def format_error(%{"code" => code, "msg" => msg}) do + {:binance_error, %{code: code, msg: msg}} + end end end @@ -157,8 +164,8 @@ docs case unquote(needs_auth) do true -> case HTTPClient.signed_request_binance(unquote(url), adjusted_args, unquote(method)) do - {:ok, %{"code" => code, "msg" => msg}} -> - {:error, {:binance_error, %{code: code, msg: msg}}} + {:ok, %{"code" => _code, "msg" => _msg} = err} -> + {:error, Binance.Helper.format_error(err)} data -> data @@ -170,8 +177,8 @@ docs adjusted_args, unquote(method) ) do - {:ok, %{"code" => code, "msg" => msg}} -> - {:error, {:binance_error, %{code: code, msg: msg}}} + {:ok, %{"code" => _code, "msg" => _msg} = err} -> + {:error, Binance.Helper.format_error(err)} data -> data diff --git a/lib/binance/errors/insufficient_balance_error.ex b/lib/binance/errors/insufficient_balance_error.ex new file mode 100644 index 0000000..1e806cf --- /dev/null +++ b/lib/binance/errors/insufficient_balance_error.ex @@ -0,0 +1,4 @@ +defmodule Binance.Errors.InsufficientBalanceError do + @enforce_keys [:code, :msg] + defstruct [:code, :msg] +end diff --git a/lib/binance/structs/insufficient_balance_error.ex b/lib/binance/structs/insufficient_balance_error.ex deleted file mode 100644 index d7d26a1..0000000 --- a/lib/binance/structs/insufficient_balance_error.ex +++ /dev/null @@ -1,4 +0,0 @@ -defmodule Binance.InsufficientBalanceError do - @enforce_keys [:reason] - defstruct [:reason] -end diff --git a/test/binance_test.exs b/test/binance_test.exs index b738c88..10bc036 100644 --- a/test/binance_test.exs +++ b/test/binance_test.exs @@ -346,12 +346,12 @@ defmodule BinanceTest do timeInForce: "FOK" ) - assert reason == %Binance.InsufficientBalanceError{ - reason: %{ - code: -2010, - msg: "Account has insufficient balance for requested action." - } - } + assert reason == + {:binance_error, + %Binance.Errors.InsufficientBalanceError{ + code: -2010, + msg: "Account has insufficient balance for requested action." + }} end end From 087a868fd8efc580a151ba55c98386e0eb76cd6f Mon Sep 17 00:00:00 2001 From: David Mohl Date: Sun, 2 Jul 2023 19:17:52 +1000 Subject: [PATCH 11/25] Fix ticker call using wrong API --- test/binance_test.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/binance_test.exs b/test/binance_test.exs index 10bc036..4335f5e 100644 --- a/test/binance_test.exs +++ b/test/binance_test.exs @@ -154,7 +154,7 @@ defmodule BinanceTest do close_time: 1_616_593_123_159, count: 65580 } - } = Binance.Market.get_ticker(symbol: "LTCBTC") + } = Binance.Market.get_ticker_24hr(symbol: "LTCBTC") end end From 943c01fea0c2307482ab50c4027460d9992c7b7b Mon Sep 17 00:00:00 2001 From: David Mohl Date: Sun, 2 Jul 2023 19:38:19 +1000 Subject: [PATCH 12/25] Update README to v2, remove debug log --- README.md | 424 ++++++++++++++++++++++++++++++++++++++++++++++--- lib/binance.ex | 9 +- 2 files changed, 406 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 17e6ff1..472a785 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ Elixir wrapper for interacting with the [Binance API](https://github.com/binance/binance-spot-api-docs). +**NOTE: v2 is a full rewrite that's now fully auto-generated from the Binance docs. There are breaking changes. If you don't need any of the new endpoints, stick to v1.** + ## Installation 1. The package can be installed by adding `binance` to your list of dependencies in `mix.exs`: @@ -24,45 +26,421 @@ config :binance, end_point: "https://api.binance.us" # Add for the US API end point. The default is for "https://api.binance.com" ``` +## Features + +- Fully autogenerated from Binance documentation using metaprogramming +- Mandatory parameters are parsed into function arguments, optional parameters into `opts` in true elixir fashion +- Nice docs and typespecs (although currently with `any()`) for all endpoints: + +``` +iex(24)> h Binance.Trade.post_order + + def post_order(symbol, side, type, opts \\ []) + + @spec post_order(any(), any(), any(), + recvWindow: any(), + newOrderRespType: any(), + icebergQty: any(), + trailingDelta: any(), + stopPrice: any(), + strategyType: any(), + strategyId: any(), + newClientOrderId: any(), + price: any(), + quoteOrderQty: any(), + quantity: any(), + timeInForce: any(), + timestamp: any() + ) :: {:ok, any()} | {:error, any()} + +New Order (TRADE) + +Send in a new order. + + • LIMIT_MAKER are LIMIT orders that will be rejected if they would + immediately match and trade as a taker. + • STOP_LOSS and TAKE_PROFIT will execute a MARKET order when the + stopPrice is reached. + • Any LIMIT or LIMIT_MAKER type order can be made an iceberg order by + sending an icebergQty. + • Any order with an icebergQty MUST have timeInForce set to GTC. + • MARKET orders using quantity specifies how much a user wants to buy or + sell based on the market price. + • MARKET orders using quoteOrderQty specifies the amount the user wants + to spend (when buying) or receive (when selling) of the quote asset; the + correct quantity will be determined based on the market liquidity and + quoteOrderQty. + • MARKET orders using quoteOrderQty will not break LOT_SIZE filter rules; + the order will execute a quantity that will have the notional value as + close as possible to quoteOrderQty. + • same newClientOrderId can be accepted only when the previous one is + filled, otherwise the order will be rejected. + +Trigger order price rules against market price for both MARKET and LIMIT +versions: + + • Price above market price: STOP_LOSS BUY, TAKE_PROFIT SELL + • Price below market price: STOP_LOSS SELL, TAKE_PROFIT BUY + +Weight(IP): 1 + +Details: + + • METHOD: post + • URL: /api/v3/order + +Mandatory params: + + • symbol - Trading symbol, e.g. BNBUSDT + • side - + • type - Order type + +Optional params: + + • timestamp - timestamp + • timeInForce - Order time in force + • quantity - Order quantity + • quoteOrderQty - Quote quantity + • price - Order price + • newClientOrderId - A unique id among open orders. Automatically + generated if not sent. + • strategyId - + • strategyType - The value cannot be less than 1000000 + • stopPrice - Used with STOP_LOSS, STOP_LOSS_LIMIT, TAKE_PROFIT, and + TAKE_PROFIT_LIMIT orders. + • trailingDelta - Used with STOP_LOSS, STOP_LOSS_LIMIT, TAKE_PROFIT, and + TAKE_PROFIT_LIMIT orders. + • icebergQty - Used with LIMIT, STOP_LOSS_LIMIT, and TAKE_PROFIT_LIMIT to + create an iceberg order. + • newOrderRespType - Set the response JSON. MARKET and LIMIT order types + default to FULL, all other orders default to ACK. + • recvWindow - The value cannot be greater than 60000 +``` + +### Supported endpoints + +### Group: BLVT +- get_blvt_redeem_record (get:/sapi/v1/blvt/redeem/record) +- get_blvt_subscribe_record (get:/sapi/v1/blvt/subscribe/record) +- get_blvt_token_info (get:/sapi/v1/blvt/tokenInfo) +- get_blvt_user_limit (get:/sapi/v1/blvt/userLimit) +- post_blvt_redeem (post:/sapi/v1/blvt/redeem) +- post_blvt_subscribe (post:/sapi/v1/blvt/subscribe) +### Group: BSwap +- get_bswap_add_liquidity_preview (get:/sapi/v1/bswap/addLiquidityPreview) +- get_bswap_claimed_history (get:/sapi/v1/bswap/claimedHistory) +- get_bswap_liquidity (get:/sapi/v1/bswap/liquidity) +- get_bswap_liquidity_ops (get:/sapi/v1/bswap/liquidityOps) +- get_bswap_pool_configure (get:/sapi/v1/bswap/poolConfigure) +- get_bswap_pools (get:/sapi/v1/bswap/pools) +- get_bswap_quote (get:/sapi/v1/bswap/quote) +- get_bswap_remove_liquidity_preview (get:/sapi/v1/bswap/removeLiquidityPreview) +- get_bswap_swap (get:/sapi/v1/bswap/swap) +- get_bswap_unclaimed_rewards (get:/sapi/v1/bswap/unclaimedRewards) +- post_bswap_claim_rewards (post:/sapi/v1/bswap/claimRewards) +- post_bswap_liquidity_add (post:/sapi/v1/bswap/liquidityAdd) +- post_bswap_liquidity_remove (post:/sapi/v1/bswap/liquidityRemove) +- post_bswap_swap (post:/sapi/v1/bswap/swap) +### Group: C2C +- get_c2c_order_match_list_user_order_history (get:/sapi/v1/c2c/orderMatch/listUserOrderHistory) +### Group: Convert +- get_convert_asset_info (get:/sapi/v1/convert/assetInfo) +- get_convert_exchange_info (get:/sapi/v1/convert/exchangeInfo) +- get_convert_order_status (get:/sapi/v1/convert/orderStatus) +- get_convert_trade_flow (get:/sapi/v1/convert/tradeFlow) +- post_convert_accept_quote (post:/sapi/v1/convert/acceptQuote) +- post_convert_get_quote (post:/sapi/v1/convert/getQuote) +### Group: Crypto Loans +- get_loan_borrow_history (get:/sapi/v1/loan/borrow/history) +- get_loan_collateral_data (get:/sapi/v1/loan/collateral/data) +- get_loan_income (get:/sapi/v1/loan/income) +- get_loan_loanable_data (get:/sapi/v1/loan/loanable/data) +- get_loan_ltv_adjustment_history (get:/sapi/v1/loan/ltv/adjustment/history) +- get_loan_ongoing_orders (get:/sapi/v1/loan/ongoing/orders) +- get_loan_repay_collateral_rate (get:/sapi/v1/loan/repay/collateral/rate) +- get_loan_repay_history (get:/sapi/v1/loan/repay/history) +- post_loan_adjust_ltv (post:/sapi/v1/loan/adjust/ltv) +- post_loan_borrow (post:/sapi/v1/loan/borrow) +- post_loan_customize_margin_call (post:/sapi/v1/loan/customize/margin_call) +- post_loan_repay (post:/sapi/v1/loan/repay) +### Group: Fiat +- get_fiat_orders (get:/sapi/v1/fiat/orders) +- get_fiat_payments (get:/sapi/v1/fiat/payments) +### Group: Futures +- get_futures_loan_adjust_collateral_history (get:/sapi/v1/futures/loan/adjustCollateral/history) +- get_futures_loan_borrow_history (get:/sapi/v1/futures/loan/borrow/history) +- get_futures_loan_interest_history (get:/sapi/v1/futures/loan/interestHistory) +- get_futures_loan_liquidation_history (get:/sapi/v1/futures/loan/liquidationHistory) +- get_futures_loan_repay_history (get:/sapi/v1/futures/loan/repay/history) +- get_futures_loan_wallet (get:/sapi/v2/futures/loan/wallet) +- get_futures_transfer (get:/sapi/v1/futures/transfer) +- post_futures_transfer (post:/sapi/v1/futures/transfer) +### Group: Futures Algo +- delete_algo_futures_order (delete:/sapi/v1/algo/futures/order) +- get_algo_futures_historical_orders (get:/sapi/v1/algo/futures/historicalOrders) +- get_algo_futures_open_orders (get:/sapi/v1/algo/futures/openOrders) +- get_algo_futures_sub_orders (get:/sapi/v1/algo/futures/subOrders) +- post_algo_futures_new_order_twap (post:/sapi/v1/algo/futures/newOrderTwap) +- post_algo_futures_new_order_vp (post:/sapi/v1/algo/futures/newOrderVp) +### Group: Gift Card +- get_giftcard_buy_code_token_limit (get:/sapi/v1/giftcard/buyCode/token-limit) +- get_giftcard_cryptography_rsa_public_key (get:/sapi/v1/giftcard/cryptography/rsa-public-key) +- get_giftcard_verify (get:/sapi/v1/giftcard/verify) +- post_giftcard_buy_code (post:/sapi/v1/giftcard/buyCode) +- post_giftcard_create_code (post:/sapi/v1/giftcard/createCode) +- post_giftcard_redeem_code (post:/sapi/v1/giftcard/redeemCode) +### Group: Margin +- delete_margin_order_list (delete:/sapi/v1/margin/orderList) +- post_margin_isolated_account (post:/sapi/v1/margin/isolated/account) +- get_margin_open_order_list (get:/sapi/v1/margin/openOrderList) +- get_margin_max_borrowable (get:/sapi/v1/margin/maxBorrowable) +- post_margin_order_oco (post:/sapi/v1/margin/order/oco) +- get_margin_max_transferable (get:/sapi/v1/margin/maxTransferable) +- get_margin_interest_rate_history (get:/sapi/v1/margin/interestRateHistory) +- get_margin_interest_history (get:/sapi/v1/margin/interestHistory) +- get_margin_my_trades (get:/sapi/v1/margin/myTrades) +- get_margin_transfer (get:/sapi/v1/margin/transfer) +- post_margin_isolated_transfer (post:/sapi/v1/margin/isolated/transfer) +- post_margin_loan (post:/sapi/v1/margin/loan) +- get_margin_loan (get:/sapi/v1/margin/loan) +- get_margin_account (get:/sapi/v1/margin/account) +- get_margin_isolated_transfer (get:/sapi/v1/margin/isolated/transfer) +- get_margin_isolated_pair (get:/sapi/v1/margin/isolated/pair) +- get_margin_isolated_margin_data (get:/sapi/v1/margin/isolatedMarginData) +- post_margin_transfer (post:/sapi/v1/margin/transfer) +- post_margin_order (post:/sapi/v1/margin/order) +- get_margin_order_list (get:/sapi/v1/margin/orderList) +- get_margin_order (get:/sapi/v1/margin/order) +- get_bnb_burn (get:/sapi/v1/bnbBurn) +- get_margin_all_assets (get:/sapi/v1/margin/allAssets) +- get_margin_all_orders (get:/sapi/v1/margin/allOrders) +- get_margin_isolated_account (get:/sapi/v1/margin/isolated/account) +- get_margin_force_liquidation_rec (get:/sapi/v1/margin/forceLiquidationRec) +- post_bnb_burn (post:/sapi/v1/bnbBurn) +- post_margin_repay (post:/sapi/v1/margin/repay) +- delete_margin_open_orders (delete:/sapi/v1/margin/openOrders) +- get_margin_pair (get:/sapi/v1/margin/pair) +- get_margin_all_pairs (get:/sapi/v1/margin/allPairs) +- get_margin_price_index (get:/sapi/v1/margin/priceIndex) +- get_margin_trade_coeff (get:/sapi/v1/margin/tradeCoeff) +- get_margin_isolated_margin_tier (get:/sapi/v1/margin/isolatedMarginTier) +- get_margin_dribblet (get:/sapi/v1/margin/dribblet) +- get_margin_repay (get:/sapi/v1/margin/repay) +- get_margin_cross_margin_data (get:/sapi/v1/margin/crossMarginData) +- delete_margin_order (delete:/sapi/v1/margin/order) +- get_margin_all_order_list (get:/sapi/v1/margin/allOrderList) +- get_margin_isolated_account_limit (get:/sapi/v1/margin/isolated/accountLimit) +- get_margin_isolated_all_pairs (get:/sapi/v1/margin/isolated/allPairs) +- get_margin_asset (get:/sapi/v1/margin/asset) +- get_margin_rate_limit_order (get:/sapi/v1/margin/rateLimit/order) +- get_margin_open_orders (get:/sapi/v1/margin/openOrders) +- delete_margin_isolated_account (delete:/sapi/v1/margin/isolated/account) +### Group: Market +- get_agg_trades (get:/api/v3/aggTrades) +- get_avg_price (get:/api/v3/avgPrice) +- get_depth (get:/api/v3/depth) +- get_exchange_info (get:/api/v3/exchangeInfo) +- get_historical_trades (get:/api/v3/historicalTrades) +- get_klines (get:/api/v3/klines) +- get_ping (get:/api/v3/ping) +- get_ticker (get:/api/v3/ticker) +- get_ticker_24hr (get:/api/v3/ticker/24hr) +- get_ticker_book_ticker (get:/api/v3/ticker/bookTicker) +- get_ticker_price (get:/api/v3/ticker/price) +- get_time (get:/api/v3/time) +- get_trades (get:/api/v3/trades) +- get_ui_klines (get:/api/v3/uiKlines) +### Group: Mining +- get_mining_hash_transfer_config_details_list (get:/sapi/v1/mining/hash-transfer/config/details/list) +- get_mining_hash_transfer_profit_details (get:/sapi/v1/mining/hash-transfer/profit/details) +- get_mining_payment_list (get:/sapi/v1/mining/payment/list) +- get_mining_payment_other (get:/sapi/v1/mining/payment/other) +- get_mining_payment_uid (get:/sapi/v1/mining/payment/uid) +- get_mining_pub_algo_list (get:/sapi/v1/mining/pub/algoList) +- get_mining_pub_coin_list (get:/sapi/v1/mining/pub/coinList) +- get_mining_statistics_user_list (get:/sapi/v1/mining/statistics/user/list) +- get_mining_statistics_user_status (get:/sapi/v1/mining/statistics/user/status) +- get_mining_worker_detail (get:/sapi/v1/mining/worker/detail) +- get_mining_worker_list (get:/sapi/v1/mining/worker/list) +- post_mining_hash_transfer_config (post:/sapi/v1/mining/hash-transfer/config) +- post_mining_hash_transfer_config_cancel (post:/sapi/v1/mining/hash-transfer/config/cancel) +### Group: NFT +- get_nft_history_deposit (get:/sapi/v1/nft/history/deposit) +- get_nft_history_transactions (get:/sapi/v1/nft/history/transactions) +- get_nft_history_withdraw (get:/sapi/v1/nft/history/withdraw) +- get_nft_user_get_asset (get:/sapi/v1/nft/user/getAsset) +### Group: Pay +- get_pay_transactions (get:/sapi/v1/pay/transactions) +### Group: Portfolio Margin +- get_portfolio_account (get:/sapi/v1/portfolio/account) +- get_portfolio_collateral_rate (get:/sapi/v1/portfolio/collateralRate) +- get_portfolio_pm_loan (get:/sapi/v1/portfolio/pmLoan) +- post_portfolio_repay (post:/sapi/v1/portfolio/repay) +### Group: Rebate +- get_rebate_tax_query (get:/sapi/v1/rebate/taxQuery) +### Group: Savings +- get_lending_daily_product_list (get:/sapi/v1/lending/daily/product/list) +- get_lending_daily_token_position (get:/sapi/v1/lending/daily/token/position) +- get_lending_daily_user_left_quota (get:/sapi/v1/lending/daily/userLeftQuota) +- get_lending_daily_user_redemption_quota (get:/sapi/v1/lending/daily/userRedemptionQuota) +- get_lending_project_list (get:/sapi/v1/lending/project/list) +- get_lending_project_position_list (get:/sapi/v1/lending/project/position/list) +- get_lending_union_account (get:/sapi/v1/lending/union/account) +- get_lending_union_interest_history (get:/sapi/v1/lending/union/interestHistory) +- get_lending_union_purchase_record (get:/sapi/v1/lending/union/purchaseRecord) +- get_lending_union_redemption_record (get:/sapi/v1/lending/union/redemptionRecord) +- post_lending_customized_fixed_purchase (post:/sapi/v1/lending/customizedFixed/purchase) +- post_lending_daily_purchase (post:/sapi/v1/lending/daily/purchase) +- post_lending_daily_redeem (post:/sapi/v1/lending/daily/redeem) +- post_lending_position_changed (post:/sapi/v1/lending/positionChanged) +### Group: Staking +- get_staking_personal_left_quota (get:/sapi/v1/staking/personalLeftQuota) +- get_staking_position (get:/sapi/v1/staking/position) +- get_staking_product_list (get:/sapi/v1/staking/productList) +- get_staking_staking_record (get:/sapi/v1/staking/stakingRecord) +- post_staking_purchase (post:/sapi/v1/staking/purchase) +- post_staking_redeem (post:/sapi/v1/staking/redeem) +- post_staking_set_auto_staking (post:/sapi/v1/staking/setAutoStaking) +### Group: Sub-Account +- post_sub_account_transfer_sub_to_master (post:/sapi/v1/sub-account/transfer/subToMaster) +- get_sub_account_futures_position_risk (get:/sapi/v2/sub-account/futures/positionRisk) +- post_sub_account_margin_enable (post:/sapi/v1/sub-account/margin/enable) +- get_sub_account_transfer_sub_user_history (get:/sapi/v1/sub-account/transfer/subUserHistory) +- get_capital_deposit_sub_address (get:/sapi/v1/capital/deposit/subAddress) +- get_sub_account_futures_internal_transfer (get:/sapi/v1/sub-account/futures/internalTransfer) +- get_sub_account_margin_account_summary (get:/sapi/v1/sub-account/margin/accountSummary) +- post_sub_account_futures_transfer (post:/sapi/v1/sub-account/futures/transfer) +- get_sub_account_assets (get:/sapi/v3/sub-account/assets) +- post_sub_account_margin_transfer (post:/sapi/v1/sub-account/margin/transfer) +- get_sub_account_sub_transfer_history (get:/sapi/v1/sub-account/sub/transfer/history) +- get_managed_subaccount_asset (get:/sapi/v1/managed-subaccount/asset) +- get_managed_subaccount_account_snapshot (get:/sapi/v1/managed-subaccount/accountSnapshot) +- post_sub_account_universal_transfer (post:/sapi/v1/sub-account/universalTransfer) +- post_sub_account_futures_internal_transfer (post:/sapi/v1/sub-account/futures/internalTransfer) +- get_sub_account_list (get:/sapi/v1/sub-account/list) +- post_sub_account_sub_account_api_ip_restriction_ip_list (post:/sapi/v1/sub-account/subAccountApi/ipRestriction/ipList) +- get_sub_account_sub_account_api_ip_restriction (get:/sapi/v1/sub-account/subAccountApi/ipRestriction) +- post_managed_subaccount_deposit (post:/sapi/v1/managed-subaccount/deposit) +- get_sub_account_spot_summary (get:/sapi/v1/sub-account/spotSummary) +- get_sub_account_api_restrictions_ip_restriction_third_party_list (get:/sapi/v1/sub-account/apiRestrictions/ipRestriction/thirdPartyList) +- post_sub_account_virtual_sub_account (post:/sapi/v1/sub-account/virtualSubAccount) +- get_sub_account_universal_transfer (get:/sapi/v1/sub-account/universalTransfer) +- post_managed_subaccount_withdraw (post:/sapi/v1/managed-subaccount/withdraw) +- post_sub_account_sub_account_api_ip_restriction (post:/sapi/v2/sub-account/subAccountApi/ipRestriction) +- get_sub_account_status (get:/sapi/v1/sub-account/status) +- delete_sub_account_sub_account_api_ip_restriction_ip_list (delete:/sapi/v1/sub-account/subAccountApi/ipRestriction/ipList) +- post_sub_account_blvt_enable (post:/sapi/v1/sub-account/blvt/enable) +- get_sub_account_futures_account (get:/sapi/v2/sub-account/futures/account) +- get_capital_deposit_sub_hisrec (get:/sapi/v1/capital/deposit/subHisrec) +- get_sub_account_margin_account (get:/sapi/v1/sub-account/margin/account) +- get_sub_account_futures_account_summary (get:/sapi/v2/sub-account/futures/accountSummary) +- post_sub_account_transfer_sub_to_sub (post:/sapi/v1/sub-account/transfer/subToSub) +- post_sub_account_futures_enable (post:/sapi/v1/sub-account/futures/enable) +### Group: Trade +- delete_open_orders (delete:/api/v3/openOrders) +- delete_order (delete:/api/v3/order) +- delete_order_list (delete:/api/v3/orderList) +- get_account (get:/api/v3/account) +- get_all_order_list (get:/api/v3/allOrderList) +- get_all_orders (get:/api/v3/allOrders) +- get_my_trades (get:/api/v3/myTrades) +- get_open_order_list (get:/api/v3/openOrderList) +- get_open_orders (get:/api/v3/openOrders) +- get_order (get:/api/v3/order) +- get_order_list (get:/api/v3/orderList) +- get_rate_limit_order (get:/api/v3/rateLimit/order) +- post_order (post:/api/v3/order) +- post_order_cancel_replace (post:/api/v3/order/cancelReplace) +- post_order_oco (post:/api/v3/order/oco) +- post_order_test (post:/api/v3/order/test) +### Group: User Data Stream +- delete_user_data_stream (delete:/sapi/v1/userDataStream) +- delete_user_data_stream_isolated (delete:/sapi/v1/userDataStream/isolated) +- post_user_data_stream (post:/sapi/v1/userDataStream) +- post_user_data_stream_isolated (post:/sapi/v1/userDataStream/isolated) +- put_user_data_stream (put:/sapi/v1/userDataStream) +- put_user_data_stream_isolated (put:/sapi/v1/userDataStream/isolated) +### Group: Wallet +- get_account_api_restrictions (get:/sapi/v1/account/apiRestrictions) +- get_account_api_trading_status (get:/sapi/v1/account/apiTradingStatus) +- get_account_snapshot (get:/sapi/v1/accountSnapshot) +- get_account_status (get:/sapi/v1/account/status) +- get_asset_asset_detail (get:/sapi/v1/asset/assetDetail) +- get_asset_asset_dividend (get:/sapi/v1/asset/assetDividend) +- get_asset_convert_transfer_query_by_page (get:/sapi/v1/asset/convert-transfer/queryByPage) +- get_asset_dribblet (get:/sapi/v1/asset/dribblet) +- get_asset_ledger_transfer_cloud_mining_query_by_page (get:/sapi/v1/asset/ledger-transfer/cloud-mining/queryByPage) +- get_asset_trade_fee (get:/sapi/v1/asset/tradeFee) +- get_asset_transfer (get:/sapi/v1/asset/transfer) +- get_capital_config_getall (get:/sapi/v1/capital/config/getall) +- get_capital_deposit_address (get:/sapi/v1/capital/deposit/address) +- get_capital_deposit_hisrec (get:/sapi/v1/capital/deposit/hisrec) +- get_capital_withdraw_history (get:/sapi/v1/capital/withdraw/history) +- get_system_status (get:/sapi/v1/system/status) +- post_account_disable_fast_withdraw_switch (post:/sapi/v1/account/disableFastWithdrawSwitch) +- post_account_enable_fast_withdraw_switch (post:/sapi/v1/account/enableFastWithdrawSwitch) +- post_asset_convert_transfer (post:/sapi/v1/asset/convert-transfer) +- post_asset_dust (post:/sapi/v1/asset/dust) +- post_asset_dust_btc (post:/sapi/v1/asset/dust-btc) +- post_asset_get_funding_asset (post:/sapi/v1/asset/get-funding-asset) +- post_asset_get_user_asset (post:/sapi/v3/asset/getUserAsset) +- post_asset_transfer (post:/sapi/v1/asset/transfer) +- post_capital_withdraw_apply (post:/sapi/v1/capital/withdraw/apply) +### Group: VIP Loans +- get_loan_vip_collateral_account (get:/sapi/v1/loan/vip/collateral/account) +- get_loan_vip_ongoing_orders (get:/sapi/v1/loan/vip/ongoing/orders) +- get_loan_vip_repay_history (get:/sapi/v1/loan/vip/repay/history) +- post_loan_vip_repay (post:/sapi/v1/loan/vip/repay) + +## Caveats + +- Most endpoints don't have proper response structs assigned to them yet due to them not being available in the docs, this will change over time +- Typespec for arguments is currently `any()`, same reason: lack of types in the definition used + ## Usage Documentation available at [https://hexdocs.pm/binance](https://hexdocs.pm/binance). -Get all prices +### Get all prices ``` -iex> Binance.get_all_prices +iex> Binance.Market.get_ticker_price {:ok, - [%Binance.SymbolPrice{price: "0.07718300", symbol: "ETHBTC"}, - %Binance.SymbolPrice{price: "0.01675400", symbol: "LTCBTC"}, - %Binance.SymbolPrice{price: "0.00114690", symbol: "BNBBTC"}, - %Binance.SymbolPrice{price: "0.00655900", symbol: "NEOBTC"}, - %Binance.SymbolPrice{price: "0.00030000", symbol: "123456"}, - %Binance.SymbolPrice{price: "0.04754000", symbol: "QTUMETH"}, - %Binance.SymbolPrice{price: "0.00778500", symbol: "EOSETH"} - ...]} + [ + %Binance.Structs.SymbolPrice{symbol: "ETHBTC", price: "0.06275000"}, + %Binance.Structs.SymbolPrice{symbol: "LTCBTC", price: "0.00363100"}, + %Binance.Structs.SymbolPrice{symbol: "BNBBTC", price: "0.00804100"}, + %Binance.Structs.SymbolPrice{symbol: "NEOBTC", price: "0.00031420"}, + %Binance.Structs.SymbolPrice{symbol: "QTUMETH", price: "0.00147800"}, + %Binance.Structs.SymbolPrice{symbol: "EOSETH", price: "0.00039460"}, + %Binance.Structs.SymbolPrice{symbol: "SNTETH", price: "0.00001240"}, + %Binance.Structs.SymbolPrice{symbol: "BNTETH", price: "0.00020200"}, + %Binance.Structs.SymbolPrice{symbol: "BCCBTC", price: "0.07908100"}, + %Binance.Structs.SymbolPrice{symbol: "GASBTC", price: "0.00008800"}, + %Binance.Structs.SymbolPrice{symbol: "BNBETH", price: "0.12810000"}, + %Binance.Structs.SymbolPrice{symbol: "BTCUSDT", price: "30526.74000000"}, + %Binance.Structs.SymbolPrice{symbol: "ETHUSDT", price: "1915.16000000"}, + ... + ]} + ``` -Buy 100 REQ for the current market price +### Buy 0.01 BNB for the current market price ``` -iex> Binance.order_market_buy("REQETH", 100) -{:ok, %{}} +iex> Binance.Trade.post_order "BNBUSDT", "BUY", "MARKET", quantity: 0.01 ``` -## Trade pair normalization - -For convenience, all functions that require a symbol in the form of "ETHBTC" also accept a -`%Binance.TradePair{}` struct in the form of `%Binance.TradePair{from: "ETH", to: "BTC"}`. The order of symbols in `%Binance.TradePair{}` does not matter. All symbols are also case insensitive. - -`Binance.find_symbol/1` will return the correct string representation as it is listed on binance +### Earn +#### Get all earn positions +```elixir +iex> Binance.Staking.get_staking_position "STAKING" ``` -Binance.find_symbol(%Binance.TradePair{from: "ReQ", to: "eTH"}) -{:ok, "REQETH"} -Binance.find_symbol(%Binance.TradePair{from: "ETH", to: "REQ"}) -{:ok, "REQETH"} +#### Get all earn products +```elixir +iex> Binance.Staking.get_staking_product_list "STAKING" ``` ## License diff --git a/lib/binance.ex b/lib/binance.ex index de6d06d..95c9691 100644 --- a/lib/binance.ex +++ b/lib/binance.ex @@ -4,6 +4,9 @@ defmodule Binance do def format_price(num) when is_integer(num), do: inspect(num) def format_price(num) when is_binary(num), do: num + @doc """ + Either returns a specific error (if we have one), or formats as generic {:binance_error, xxx} + """ def format_error(%{"code" => -2010, "msg" => msg}), do: {:binance_error, %Binance.Errors.InsufficientBalanceError{code: -2010, msg: msg}} @@ -17,7 +20,7 @@ docs = Binance.DocsParser.get_documentation() docs |> Enum.each(fn api_group -> - IO.puts("parsing group: #{api_group.group}") + # IO.puts("### Group: #{api_group.group}") defmodule Binance.DocsParser.modularize_name(api_group.group) do alias Binance.Rest.HTTPClient @@ -35,7 +38,7 @@ docs fx_name = item.fx_name path_key = item.path_key - IO.puts(" generating #{fx_name} (#{path_key})") + # IO.puts("- #{fx_name} (#{path_key})") mandatory_params = Enum.filter(params, fn param -> @@ -132,8 +135,6 @@ docs # merge all passed args together, so opts + passed all_passed_args = Keyword.merge(binding, opts) |> Keyword.drop([:opts]) - IO.puts("API call: #{unquote(method)} " <> unquote(url)) - # if the call requires a timestamp, we add it adjusted_args = case unquote(needs_timestamp) do From 58235827c62eda8671b0321bd47f1d09e5760716 Mon Sep 17 00:00:00 2001 From: David Mohl Date: Sun, 2 Jul 2023 19:58:18 +1000 Subject: [PATCH 13/25] Add mapping for DataStream, handle empty body --- lib/binance.ex | 5 +++++ lib/binance/docs_parser.ex | 7 ++++--- lib/binance/response_mapping.ex | 3 ++- lib/binance/structs/data_stream.ex | 2 +- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/binance.ex b/lib/binance.ex index 95c9691..448369a 100644 --- a/lib/binance.ex +++ b/lib/binance.ex @@ -161,6 +161,11 @@ docs end end) |> Enum.into(%{}) + # if no parameters set, set body to "" + |> case do + %{} -> "" + a -> a + end case unquote(needs_auth) do true -> diff --git a/lib/binance/docs_parser.ex b/lib/binance/docs_parser.ex index 7554be0..6325666 100644 --- a/lib/binance/docs_parser.ex +++ b/lib/binance/docs_parser.ex @@ -77,9 +77,9 @@ defmodule Binance.DocsParser do |> List.flatten() # remove duplicates |> Enum.reduce(%{}, fn item, acc -> - if Map.has_key?(acc, item.fx_name) do - IO.puts("overwriting: #{item.fx_name}") - end + # if Map.has_key?(acc, item.fx_name) do + # IO.puts("overwriting: #{item.fx_name}") + # end Map.put(acc, item.fx_name, item) end) @@ -104,6 +104,7 @@ defmodule Binance.DocsParser do |> String.replace(")", "") |> String.replace("/", "") |> String.capitalize() + |> Macro.camelize() |> String.to_atom() |> (&Module.concat(Binance, &1)).() end diff --git a/lib/binance/response_mapping.ex b/lib/binance/response_mapping.ex index 3d47212..f9dbf51 100644 --- a/lib/binance/response_mapping.ex +++ b/lib/binance/response_mapping.ex @@ -15,7 +15,8 @@ defmodule Binance.ResponseMapping do "get:/api/v3/ticker" => Binance.Structs.Ticker, "get:/api/v3/ticker/24hr" => Binance.Structs.Ticker, "get:/api/v3/ticker/price" => Binance.Responses.TickerPrice, - "get:/api/v3/exchangeInfo" => Binance.Structs.ExchangeInfo + "get:/api/v3/exchangeInfo" => Binance.Structs.ExchangeInfo, + "post:/api/v3/userDataStream" => Binance.Structs.DataStream } Map.get(mappings, path_key, nil) diff --git a/lib/binance/structs/data_stream.ex b/lib/binance/structs/data_stream.ex index e17af05..eac2f46 100644 --- a/lib/binance/structs/data_stream.ex +++ b/lib/binance/structs/data_stream.ex @@ -1,4 +1,4 @@ -defmodule Binance.DataStream do +defmodule Binance.Structs.DataStream do @moduledoc """ Struct for representing a user data stream. From 36efc9064eb71ee5806de57b1165700500103ad1 Mon Sep 17 00:00:00 2001 From: David Mohl Date: Sun, 2 Jul 2023 20:12:27 +1000 Subject: [PATCH 14/25] Fix empty params handling --- lib/binance.ex | 5 ----- lib/binance/rest/http_client.ex | 12 ++++++++++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/binance.ex b/lib/binance.ex index 448369a..95c9691 100644 --- a/lib/binance.ex +++ b/lib/binance.ex @@ -161,11 +161,6 @@ docs end end) |> Enum.into(%{}) - # if no parameters set, set body to "" - |> case do - %{} -> "" - a -> a - end case unquote(needs_auth) do true -> diff --git a/lib/binance/rest/http_client.ex b/lib/binance/rest/http_client.ex index dcf1372..a6f86f9 100644 --- a/lib/binance/rest/http_client.ex +++ b/lib/binance/rest/http_client.ex @@ -157,6 +157,14 @@ defmodule Binance.Rest.HTTPClient do end end + defp do_unsigned_request(url, nil, :post, headers) do + apply(HTTPoison, :post, [ + "#{@endpoint}#{url}", + "", + headers + ]) + end + defp do_unsigned_request(url, nil, method, headers) do apply(HTTPoison, method, [ "#{@endpoint}#{url}", @@ -164,6 +172,10 @@ defmodule Binance.Rest.HTTPClient do ]) end + defp do_unsigned_request(url, %{}, method, headers) do + do_unsigned_request(url, nil, method, headers) + end + defp do_unsigned_request(url, data, :get, headers) do argument_string = data From 17139b7aa600c038ccfea94eda511e7b9ed44e2d Mon Sep 17 00:00:00 2001 From: David Mohl Date: Sun, 2 Jul 2023 20:24:36 +1000 Subject: [PATCH 15/25] Unify signed/unsigned request methods --- lib/binance/rest/http_client.ex | 122 ++++++-------------------------- 1 file changed, 21 insertions(+), 101 deletions(-) diff --git a/lib/binance/rest/http_client.ex b/lib/binance/rest/http_client.ex index a6f86f9..6be48ea 100644 --- a/lib/binance/rest/http_client.ex +++ b/lib/binance/rest/http_client.ex @@ -1,36 +1,6 @@ defmodule Binance.Rest.HTTPClient do @endpoint Application.get_env(:binance, :end_point, "https://api.binance.com") - def get_binance(url, headers \\ []) do - HTTPoison.get("#{@endpoint}#{url}", headers) - |> parse_response - end - - def delete_binance(url, headers \\ []) do - HTTPoison.delete("#{@endpoint}#{url}", headers) - |> parse_response - end - - def get_binance(url, params, secret_key, api_key) do - case prepare_request(url, params, secret_key, api_key) do - {:error, _} = error -> - error - - {:ok, url, headers} -> - get_binance(url, headers) - end - end - - def delete_binance(url, params, secret_key, api_key) do - case prepare_request(url, params, secret_key, api_key) do - {:error, _} = error -> - error - - {:ok, url, headers} -> - delete_binance(url, headers) - end - end - defp prepare_request(url, params, secret_key, api_key) do case validate_credentials(secret_key, api_key) do {:error, _} = error -> @@ -61,22 +31,7 @@ defmodule Binance.Rest.HTTPClient do end end - def signed_request_binance(url, params, method) do - argument_string = - params - |> prepare_query_params() - - # generate signature - signature = - generate_signature( - :sha256, - Application.get_env(:binance, :secret_key), - argument_string - ) - |> Base.encode16() - - body = "#{argument_string}&signature=#{signature}" - + defp request_binance(url, body, method) do url = case method do :get -> @@ -135,71 +90,36 @@ defmodule Binance.Rest.HTTPClient do end end - @doc """ - You need to send an empty body and the api key - to be able to create a new listening key. - - """ - def unsigned_request_binance(url, data, method) do - headers = [ - {"X-MBX-APIKEY", Application.get_env(:binance, :api_key)} - ] - - case do_unsigned_request(url, data, method, headers) do - {:error, err} -> - {:error, {:http_error, err}} + def signed_request_binance(url, params, method) do + argument_string = + params + |> prepare_query_params() - {:ok, response} -> - case Poison.decode(response.body) do - {:ok, data} -> {:ok, data} - {:error, err} -> {:error, {:poison_decode_error, err}} - end - end - end + # generate signature + signature = + generate_signature( + :sha256, + Application.get_env(:binance, :secret_key), + argument_string + ) + |> Base.encode16() - defp do_unsigned_request(url, nil, :post, headers) do - apply(HTTPoison, :post, [ - "#{@endpoint}#{url}", - "", - headers - ]) - end + body = "#{argument_string}&signature=#{signature}" - defp do_unsigned_request(url, nil, method, headers) do - apply(HTTPoison, method, [ - "#{@endpoint}#{url}", - headers - ]) + request_binance(url, body, method) end - defp do_unsigned_request(url, %{}, method, headers) do - do_unsigned_request(url, nil, method, headers) - end + @doc """ + You need to send an empty body and the api key + to be able to create a new listening key. - defp do_unsigned_request(url, data, :get, headers) do + """ + def unsigned_request_binance(url, data, method) do argument_string = data |> prepare_query_params() - url = - if argument_string != "" do - "#{@endpoint}#{url}" <> "?#{argument_string}" - else - "#{@endpoint}#{url}" - end - - apply(HTTPoison, :get, [ - url, - headers - ]) - end - - defp do_unsigned_request(url, body, method, headers) do - apply(HTTPoison, method, [ - "#{@endpoint}#{url}", - body, - headers - ]) + request_binance(url, argument_string, method) end defp validate_credentials(nil, nil), From 8fc3e33c8a5d6cbd76df7c197273505098ee51ea Mon Sep 17 00:00:00 2001 From: David Mohl Date: Sun, 2 Jul 2023 20:33:35 +1000 Subject: [PATCH 16/25] Convert all returned map keys into atoms --- lib/binance.ex | 19 ++++++++++++++++++- lib/binance/response_mapping.ex | 4 ++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/binance.ex b/lib/binance.ex index 95c9691..ef6fa1c 100644 --- a/lib/binance.ex +++ b/lib/binance.ex @@ -13,6 +13,23 @@ defmodule Binance do def format_error(%{"code" => code, "msg" => msg}) do {:binance_error, %{code: code, msg: msg}} end + + @doc """ + Converts a map with string keys into a map with atoms + + This is considered unsafe since atoms are never garbage collected and can cause a memory leak + """ + def keys_to_atoms(string_key_map) when is_map(string_key_map) do + for {key, val} <- string_key_map, + into: %{}, + do: { + String.to_atom(key), + keys_to_atoms(val) + } + end + + def keys_to_atoms(value) when is_list(value), do: Enum.map(value, &keys_to_atoms/1) + def keys_to_atoms(value), do: value end end @@ -190,7 +207,7 @@ docs # try to find a response mapped struct case Binance.ResponseMapping.lookup(unquote(path_key)) do nil -> - {:ok, data} + {:ok, Binance.Helper.keys_to_atoms(data)} struct_name -> {:ok, struct_name.new(data)} diff --git a/lib/binance/response_mapping.ex b/lib/binance/response_mapping.ex index f9dbf51..239cf8b 100644 --- a/lib/binance/response_mapping.ex +++ b/lib/binance/response_mapping.ex @@ -1,6 +1,10 @@ defmodule Binance.ResponseMapping do @moduledoc false + # Maps APIs to specific structs + # The struct needs to have a .new() method that takes the data returned on successful API call by Binance. .new() was chosen as this is used by ExConstructor by default + # Some APIs return a list of things and not a single struct, the initializers for those are in Binance.Responses.X which then returns a list of Binance.Structs.X + def lookup(path_key) do mappings = %{ "get:/api/v3/klines" => Binance.Responses.Klines, From 515b1da1f0f823f486567f268f12dee7063a1b96 Mon Sep 17 00:00:00 2001 From: David Mohl Date: Sun, 2 Jul 2023 20:43:34 +1000 Subject: [PATCH 17/25] Add moduledoc from description --- lib/binance.ex | 4 ++++ lib/binance/docs_parser.ex | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/binance.ex b/lib/binance.ex index ef6fa1c..f6ba311 100644 --- a/lib/binance.ex +++ b/lib/binance.ex @@ -42,6 +42,10 @@ docs defmodule Binance.DocsParser.modularize_name(api_group.group) do alias Binance.Rest.HTTPClient + @moduledoc """ + #{api_group.description} + """ + api_group.items |> Enum.each(fn item -> method = item.method diff --git a/lib/binance/docs_parser.ex b/lib/binance/docs_parser.ex index 6325666..e69b662 100644 --- a/lib/binance/docs_parser.ex +++ b/lib/binance/docs_parser.ex @@ -69,7 +69,7 @@ defmodule Binance.DocsParser do |> Enum.map(&normalize_entry_item/1) end - defp normalize_entry(%{"name" => name, "item" => item}) do + defp normalize_entry(%{"name" => name, "item" => item} = args) do %{ items: item @@ -84,7 +84,8 @@ defmodule Binance.DocsParser do Map.put(acc, item.fx_name, item) end) |> Map.values(), - group: name + group: name, + description: Map.get(args, "description", "") } end From 6da66361217df5bc9c7dd17f3a11f1ee2e7c0d42 Mon Sep 17 00:00:00 2001 From: David Mohl Date: Sun, 2 Jul 2023 20:44:08 +1000 Subject: [PATCH 18/25] Update note about battle-tested-ness --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 472a785..e462506 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Elixir wrapper for interacting with the [Binance API](https://github.com/binance/binance-spot-api-docs). -**NOTE: v2 is a full rewrite that's now fully auto-generated from the Binance docs. There are breaking changes. If you don't need any of the new endpoints, stick to v1.** +**NOTE: v2 is a full rewrite that's now fully auto-generated from the Binance docs. There are breaking changes, and it's not as battle-tested as v1 yet. If you don't need any of the new endpoints, stick to v1.** ## Installation From df31bf17d95d66b4bbab6ebd95b025d925d3e2d9 Mon Sep 17 00:00:00 2001 From: David Mohl Date: Sun, 2 Jul 2023 20:46:17 +1000 Subject: [PATCH 19/25] Remove typer --- lib/binance/typer.ex | 27 --------------------------- 1 file changed, 27 deletions(-) delete mode 100644 lib/binance/typer.ex diff --git a/lib/binance/typer.ex b/lib/binance/typer.ex deleted file mode 100644 index fba0a7b..0000000 --- a/lib/binance/typer.ex +++ /dev/null @@ -1,27 +0,0 @@ -defmodule Binance.Typer do - defmacro __using__(_opts) do - quote do - # IO.inspect(unquote(__MODULE__).__struct__()) - # get struct fields - # types = - # __MODULE__.__struct__() - # |> Map.from_struct() - # |> Map.keys() - # |> Enum.reduce([], fn field, acc -> - # case acc do - # [] -> - # quote do: {field, any()} - - # val -> - # quote do: - # {field, any()} - # | unquote(val) - # end - # end) - - # @type t :: %__MODULE__{ - # types - # } - end - end -end From 25d8aea5ea3d9fcddb02cd725ea08108a82fbac9 Mon Sep 17 00:00:00 2001 From: David Mohl Date: Sun, 2 Jul 2023 21:40:42 +1000 Subject: [PATCH 20/25] Fix issue where certain requests come back as "not authorized" Due to missing timestamp/signature in the query. There were even more issues when certain parameters are in the body vs in the query Looking at the postman collection, it just sends everything in the query so that looks to be okay? --- lib/binance/rest/http_client.ex | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/lib/binance/rest/http_client.ex b/lib/binance/rest/http_client.ex index 6be48ea..f9b10cd 100644 --- a/lib/binance/rest/http_client.ex +++ b/lib/binance/rest/http_client.ex @@ -32,30 +32,19 @@ defmodule Binance.Rest.HTTPClient do end defp request_binance(url, body, method) do + url = URI.parse("#{@endpoint}#{url}") + url = - case method do - :get -> - if body != "" do - "#{@endpoint}#{url}?#{body}" - else - "#{@endpoint}#{url}" - end - - :delete -> - if body != "" do - "#{@endpoint}#{url}?#{body}" - else - "#{@endpoint}#{url}" - end - - _ -> - "#{@endpoint}#{url}" + if body != "" do + URI.append_query(url, body) + else + url end case method do :get -> HTTPoison.get( - url, + URI.to_string(url), [ {"X-MBX-APIKEY", Application.get_env(:binance, :api_key)} ] @@ -63,7 +52,7 @@ defmodule Binance.Rest.HTTPClient do :delete -> HTTPoison.delete( - url, + URI.to_string(url), [ {"X-MBX-APIKEY", Application.get_env(:binance, :api_key)} ] @@ -71,7 +60,7 @@ defmodule Binance.Rest.HTTPClient do _ -> apply(HTTPoison, method, [ - url, + URI.to_string(url), body, [ {"X-MBX-APIKEY", Application.get_env(:binance, :api_key)} From 6b3da94656612d5bfbe829c35daecc7af0737ea5 Mon Sep 17 00:00:00 2001 From: David Mohl Date: Tue, 4 Jul 2023 12:32:05 +1000 Subject: [PATCH 21/25] Add example for redeeming assets, add link to v1 --- README.md | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e462506..e105ce6 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Elixir wrapper for interacting with the [Binance API](https://github.com/binance/binance-spot-api-docs). -**NOTE: v2 is a full rewrite that's now fully auto-generated from the Binance docs. There are breaking changes, and it's not as battle-tested as v1 yet. If you don't need any of the new endpoints, stick to v1.** +**NOTE: v2 is a full rewrite that's now fully auto-generated from the Binance docs. There are breaking changes, and it's not as battle-tested as v1 yet. If you don't need any of the new endpoints, [stick to v1](https://github.com/dvcrn/binance.ex/tree/master).** ## Installation @@ -431,7 +431,7 @@ iex> Binance.Market.get_ticker_price iex> Binance.Trade.post_order "BNBUSDT", "BUY", "MARKET", quantity: 0.01 ``` -### Earn +### Earn #### Get all earn positions ```elixir @@ -443,6 +443,18 @@ iex> Binance.Staking.get_staking_position "STAKING" iex> Binance.Staking.get_staking_product_list "STAKING" ``` +#### Redeem all flexible staked assets + +```elixir +with {:ok, positions} <- Binance.Savings.get_lending_daily_token_position("") do + positions + |> Enum.map( + &Binance.Savings.post_lending_daily_redeem(&1.productId, &1.totalAmount, "FAST" + ) + ) +end +``` + ## License MIT From c3af60e4550110205fd300c6c786bc51f9a5d703 Mon Sep 17 00:00:00 2001 From: David Mohl Date: Tue, 4 Jul 2023 12:34:52 +1000 Subject: [PATCH 22/25] Prepare publish of 2.0.0-beta.1 --- README.md | 9 +++++++-- mix.exs | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e105ce6..94e6d98 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,11 @@ # binance.ex -Elixir wrapper for interacting with the [Binance API](https://github.com/binance/binance-spot-api-docs). +[![Hex.pm Version](https://img.shields.io/hexpm/v/binance)](https://hex.pm/packages/binance) +[![Hex Docs](https://img.shields.io/badge/hex-docs-lightgreen.svg)](https://hexdocs.pm/binance) +[![Hex.pm Download Total](https://img.shields.io/hexpm/dt/binance)](https://hex.pm/packages/binance) + + +Unofficial Elixir wrapper for interacting with the [Binance API](https://github.com/binance/binance-spot-api-docs). **NOTE: v2 is a full rewrite that's now fully auto-generated from the Binance docs. There are breaking changes, and it's not as battle-tested as v1 yet. If you don't need any of the new endpoints, [stick to v1](https://github.com/dvcrn/binance.ex/tree/master).** @@ -11,7 +16,7 @@ Elixir wrapper for interacting with the [Binance API](https://github.com/binance ```elixir def deps do [ - {:binance, "~> 1.0"} + {:binance, "~> 2.0.0-beta.1"} ] end ``` diff --git a/mix.exs b/mix.exs index 5b0be89..cb222d4 100644 --- a/mix.exs +++ b/mix.exs @@ -4,7 +4,7 @@ defmodule Binance.MixProject do def project do [ app: :binance, - version: "1.0.4", + version: "2.0.0-beta.1", elixir: "~> 1.7", start_permanent: Mix.env() == :prod, description: description(), From c874d1a034cc89b2ad86c7b23fc1ddc026abff57 Mon Sep 17 00:00:00 2001 From: David Mohl Date: Tue, 4 Jul 2023 12:46:03 +1000 Subject: [PATCH 23/25] Add instruction about selecting correct version --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 94e6d98..70dbdb0 100644 --- a/README.md +++ b/README.md @@ -404,7 +404,7 @@ Optional params: ## Usage -Documentation available at [https://hexdocs.pm/binance](https://hexdocs.pm/binance). +Documentation available at [https://hexdocs.pm/binance](https://hexdocs.pm/binance) (make sure you have 2.0.0 selected) ### Get all prices From 52c90d08604ecf5bc6ddc55e09e1c8c3abc81b10 Mon Sep 17 00:00:00 2001 From: David Mohl Date: Fri, 7 Jul 2023 16:15:29 +1000 Subject: [PATCH 24/25] Update README link to v1 to point to v1/ branch --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 70dbdb0..1e05d92 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Unofficial Elixir wrapper for interacting with the [Binance API](https://github.com/binance/binance-spot-api-docs). -**NOTE: v2 is a full rewrite that's now fully auto-generated from the Binance docs. There are breaking changes, and it's not as battle-tested as v1 yet. If you don't need any of the new endpoints, [stick to v1](https://github.com/dvcrn/binance.ex/tree/master).** +**NOTE: v2 is a full rewrite that's now fully auto-generated from the Binance docs. There are breaking changes, and it's not as battle-tested as v1 yet. If you don't need any of the new endpoints, [stick to v1](https://github.com/dvcrn/binance.ex/tree/v1) for now.** ## Installation From da76fb0e390e81f79507c6bd60f72cdb8ca9c03f Mon Sep 17 00:00:00 2001 From: David Mohl Date: Fri, 7 Jul 2023 16:16:00 +1000 Subject: [PATCH 25/25] Remove beta flag --- README.md | 2 +- mix.exs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1e05d92..d838298 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Unofficial Elixir wrapper for interacting with the [Binance API](https://github. ```elixir def deps do [ - {:binance, "~> 2.0.0-beta.1"} + {:binance, "~> 2.0.0"} ] end ``` diff --git a/mix.exs b/mix.exs index cb222d4..b362f98 100644 --- a/mix.exs +++ b/mix.exs @@ -4,7 +4,7 @@ defmodule Binance.MixProject do def project do [ app: :binance, - version: "2.0.0-beta.1", + version: "2.0.0", elixir: "~> 1.7", start_permanent: Mix.env() == :prod, description: description(),