本文介绍币安Binance API

General API Information

  • The base endpoint is: https://api.binance.com
  • All endpoints return either a JSON object or array.
  • Data is returned in ascending order. Oldest first, newest last.
  • All time and timestamp related fields are in milliseconds.
  • HTTP 4XX return codes are used for for malformed requests; the issue is on the sender's side.
  • HTTP 429 return code is used when breaking a request rate limit.
  • HTTP 418 return code is used when an IP has been auto-banned for continuing to send requests after receiving 429codes.
  • HTTP 5XX return codes are used for internal errors; the issue is on Binance's side. It is important to NOT treat this as a failure operation; the execution status is UNKNOWN and could have been a success.
  • Any endpoint can return an ERROR; the error payload is as follows:
  1. {
  2. "code": -1121,
  3. "msg": "Invalid symbol."
  4. }
  • Specific error codes and messages defined in another document.
  • For GET endpoints, parameters must be sent as a query string.
  • For POSTPUT, and DELETE endpoints, the parameters may be sent as a query string or in the request body with content type application/x-www-form-urlencoded. You may mix parameters between both the query string and request body if you wish to do so.
  • Parameters may be sent in any order.
  • If a parameter sent in both the query string and request body, the query string parameter will be used.

LIMITS

  • The /api/v1/exchangeInfo rateLimits array contains objects related to the exchange's REQUEST_WEIGHT and ORDERrate limits.
  • A 429 will be returned when either rate limit is violated.
  • Each route has a weight which determines for the number of requests each endpoint counts for. Heavier endpoints and endpoints that do operations on multiple symbols will have a heavier weight.
  • When a 429 is recieved, it's your obligation as an API to back off and not spam the API.
  • Repeatedly violating rate limits and/or failing to back off after receiving 429s will result in an automated IP ban (http status 418).
  • IP bans are tracked and scale in duration for repeat offenders, from 2 minutes to 3 days.

Endpoint security type

  • Each endpoint has a security type that determines the how you will interact with it.
  • API-keys are passed into the Rest API via the X-MBX-APIKEY header.
  • API-keys and secret-keys are case sensitive.
  • API-keys can be configured to only access certain types of secure endpoints. For example, one API-key could be used for TRADE only, while another API-key can access everything except for TRADE routes.
  • By default, API-keys can access all secure routes.
Security Type Description
NONE Endpoint can be accessed freely.
TRADE Endpoint requires sending a valid API-Key and signature.
USER_DATA Endpoint requires sending a valid API-Key and signature.
USER_STREAM Endpoint requires sending a valid API-Key.
MARKET_DATA Endpoint requires sending a valid API-Key.
  • TRADE and USER_DATA endpoints are SIGNED endpoints.

SIGNED (TRADE and USER_DATA) Endpoint security

  • SIGNED endpoints require an additional parameter, signature, to be sent in the query string or request body.
  • Endpoints use HMAC SHA256 signatures. The HMAC SHA256 signature is a keyed HMAC SHA256 operation. Use your secretKey as the key and totalParams as the value for the HMAC operation.
  • The signature is not case sensitive.
  • totalParams is defined as the query string concatenated with the request body.

Timing security

  • SIGNED endpoint also requires a parameter, timestamp, to be sent which should be the millisecond timestamp of when the request was created and sent.
  • An additional parameter, recvWindow, may be sent to specify the number of milliseconds after timestamp the request is valid for. If recvWindow is not sent, it defaults to 5000.
  • The logic is as follows:
    1. if (timestamp < (serverTime + 1000) && (serverTime - timestamp) <= recvWindow) {
    2. // process request
    3. } else {
    4. // reject request
    5. }

Serious trading is about timing. Networks can be unstable and unreliable, which can lead to requests taking varying amounts of time to reach the servers. With recvWindow, you can specify that the request must be processed within a certain number of milliseconds or be rejected by the server.

It recommended to use a small recvWindow of 5000 or less!

SIGNED Endpoint Examples for POST /api/v1/order

Here is a step-by-step example of how to send a vaild signed payload from the Linux command line using echoopenssl, and curl.

Key Value
apiKey vmPUZE6mv9SD5VNHk4HlWFsOr6aKE2zvsw0MuIgwCIPy6utIco14y7Ju91duEh8A
secretKey NhqPtmdSJYdKjVHjA7PZj4Mge3R5YNiP1e3UZjInClVN65XAbvqqM6A7H5fATj0j
Parameter Value
symbol LTCBTC
side BUY
type LIMIT
timeInForce GTC
quantity 1
price 0.1
recvWindow 5000
timestamp 1499827319559

Example 1: As a query string

  • queryString:symbol=LTCBTC&side=BUY&type=LIMIT&timeInForce=GTC&quantity=1&price=0.1&recvWindow=5000&timestamp=1499827319559

  • HMAC SHA256 signature:

    1. [linux]$ echo -n "symbol=LTCBTC&side=BUY&type=LIMIT&timeInForce=GTC&quantity=1&price=0.1&recvWindow=5000&timestamp=1499827319559" | openssl dgst -sha256 -hmac "NhqPtmdSJYdKjVHjA7PZj4Mge3R5YNiP1e3UZjInClVN65XAbvqqM6A7H5fATj0j"
    2. (stdin)= c8db56825ae71d6d79447849e617115f4a920fa2acdcab2b053c4b2838bd6b71
  • curl command:

    1. (HMAC SHA256)
    2. [linux]$ curl -H "X-MBX-APIKEY: vmPUZE6mv9SD5VNHk4HlWFsOr6aKE2zvsw0MuIgwCIPy6utIco14y7Ju91duEh8A" -X POST 'https://api.binance.com/api/v3/order?symbol=LTCBTC&side=BUY&type=LIMIT&timeInForce=GTC&quantity=1&price=0.1&recvWindow=5000&timestamp=1499827319559&signature=c8db56825ae71d6d79447849e617115f4a920fa2acdcab2b053c4b2838bd6b71'

Example 2: As a request body

  • requestBody:symbol=LTCBTC&side=BUY&type=LIMIT&timeInForce=GTC&quantity=1&price=0.1&recvWindow=5000&timestamp=1499827319559

  • HMAC SHA256 signature:

    1. [linux]$ echo -n "symbol=LTCBTC&side=BUY&type=LIMIT&timeInForce=GTC&quantity=1&price=0.1&recvWindow=5000&timestamp=1499827319559" | openssl dgst -sha256 -hmac "NhqPtmdSJYdKjVHjA7PZj4Mge3R5YNiP1e3UZjInClVN65XAbvqqM6A7H5fATj0j"
    2. (stdin)= c8db56825ae71d6d79447849e617115f4a920fa2acdcab2b053c4b2838bd6b71
  • curl command:

    1. (HMAC SHA256)
    2. [linux]$ curl -H "X-MBX-APIKEY: vmPUZE6mv9SD5VNHk4HlWFsOr6aKE2zvsw0MuIgwCIPy6utIco14y7Ju91duEh8A" -X POST 'https://api.binance.com/api/v3/order' -d 'symbol=LTCBTC&side=BUY&type=LIMIT&timeInForce=GTC&quantity=1&price=0.1&recvWindow=5000&timestamp=1499827319559&signature=c8db56825ae71d6d79447849e617115f4a920fa2acdcab2b053c4b2838bd6b71'

Example 3: Mixed query string and request body

  • queryString: symbol=LTCBTC&side=BUY&type=LIMIT&timeInForce=GTC

  • requestBody: quantity=1&price=0.1&recvWindow=5000&timestamp=1499827319559

  • HMAC SHA256 signature:

    1. [linux]$ echo -n "symbol=LTCBTC&side=BUY&type=LIMIT&timeInForce=GTCquantity=1&price=0.1&recvWindow=5000&timestamp=1499827319559" | openssl dgst -sha256 -hmac "NhqPtmdSJYdKjVHjA7PZj4Mge3R5YNiP1e3UZjInClVN65XAbvqqM6A7H5fATj0j"
    2. (stdin)= 0fd168b8ddb4876a0358a8d14d0c9f3da0e9b20c5d52b2a00fcf7d1c602f9a77
  • curl command:

    1. (HMAC SHA256)
    2. [linux]$ curl -H "X-MBX-APIKEY: vmPUZE6mv9SD5VNHk4HlWFsOr6aKE2zvsw0MuIgwCIPy6utIco14y7Ju91duEh8A" -X POST 'https://api.binance.com/api/v3/order?symbol=LTCBTC&side=BUY&type=LIMIT&timeInForce=GTC' -d 'quantity=1&price=0.1&recvWindow=5000&timestamp=1499827319559&signature=0fd168b8ddb4876a0358a8d14d0c9f3da0e9b20c5d52b2a00fcf7d1c602f9a77'

Note that the signature is different in example 3. There is no & between "GTC" and "quantity=1".

Public API Endpoints

Terminology

  • base asset refers to the asset that is the quantity of a symbol.
  • quote asset refers to the asset that is the price of a symbol.

ENUM definitions

Symbol status:

  • PRE_TRADING
  • TRADING
  • POST_TRADING
  • END_OF_DAY
  • HALT
  • AUCTION_MATCH
  • BREAK

Symbol type:

  • SPOT

Order status:

  • NEW
  • PARTIALLY_FILLED
  • FILLED
  • CANCELED
  • PENDING_CANCEL (currently unused)
  • REJECTED
  • EXPIRED

Order types:

  • LIMIT
  • MARKET
  • STOP_LOSS
  • STOP_LOSS_LIMIT
  • TAKE_PROFIT
  • TAKE_PROFIT_LIMIT
  • LIMIT_MAKER

Order side:

  • BUY
  • SELL

Time in force:

  • GTC
  • IOC
  • FOK

Kline/Candlestick chart intervals:

m -> minutes; h -> hours; d -> days; w -> weeks; M -> months

  • 1m
  • 3m
  • 5m
  • 15m
  • 30m
  • 1h
  • 2h
  • 4h
  • 6h
  • 8h
  • 12h
  • 1d
  • 3d
  • 1w
  • 1M

Rate limiters (rateLimitType)

  • REQUESTS_WEIGHT
  • ORDERS

Rate limit intervals

  • SECOND
  • MINUTE
  • DAY

General endpoints

Test connectivity

  1. GET /api/v1/ping

Test connectivity to the Rest API.

Weight: 1

Parameters: NONE

Response:

  1. {}

Check server time

  1. GET /api/v1/time

Test connectivity to the Rest API and get the current server time.

Weight: 1

Parameters: NONE

Response:

  1. {
  2. "serverTime": 1499827319559
  3. }

Exchange information

  1. GET /api/v1/exchangeInfo

Current exchange trading rules and symbol information

Weight: 1

Parameters: NONE

Response:

  1. {
  2. "timezone": "UTC",
  3. "serverTime": 1508631584636,
  4. "rateLimits": [{
  5. "rateLimitType": "REQUESTS_WEIGHT",
  6. "interval": "MINUTE",
  7. "limit": 1200
  8. },
  9. {
  10. "rateLimitType": "ORDERS",
  11. "interval": "SECOND",
  12. "limit": 10
  13. },
  14. {
  15. "rateLimitType": "ORDERS",
  16. "interval": "DAY",
  17. "limit": 100000
  18. }
  19. ],
  20. "exchangeFilters": [],
  21. "symbols": [{
  22. "symbol": "ETHBTC",
  23. "status": "TRADING",
  24. "baseAsset": "ETH",
  25. "baseAssetPrecision": 8,
  26. "quoteAsset": "BTC",
  27. "quotePrecision": 8,
  28. "orderTypes": ["LIMIT", "MARKET"],
  29. "icebergAllowed": false,
  30. "filters": [{
  31. "filterType": "PRICE_FILTER",
  32. "minPrice": "0.00000100",
  33. "maxPrice": "100000.00000000",
  34. "tickSize": "0.00000100"
  35. }, {
  36. "filterType": "LOT_SIZE",
  37. "minQty": "0.00100000",
  38. "maxQty": "100000.00000000",
  39. "stepSize": "0.00100000"
  40. }, {
  41. "filterType": "MIN_NOTIONAL",
  42. "minNotional": "0.00100000"
  43. }]
  44. }]
  45. }

Market Data endpoints

Order book

  1. GET /api/v1/depth

Weight: Adjusted based on the limit:

Limit Weight
5, 10, 20, 50, 100 1
500 5
1000 10

Parameters:

Name Type Mandatory Description
symbol STRING YES  
limit INT NO Default 100; max 1000. Valid limits:[5, 10, 20, 50, 100, 500, 1000]

Caution: setting limit=0 can return a lot of data.

Response:

  1. {
  2. "lastUpdateId": 1027024,
  3. "bids": [
  4. [
  5. "4.00000000", // PRICE
  6. "431.00000000", // QTY
  7. [] // Ignore.
  8. ]
  9. ],
  10. "asks": [
  11. [
  12. "4.00000200",
  13. "12.00000000",
  14. []
  15. ]
  16. ]
  17. }

Recent trades list

  1. GET /api/v1/trades

Get recent trades (up to last 500).

Weight: 1

Parameters:

Name Type Mandatory Description
symbol STRING YES  
limit INT NO Default 500; max 1000.

Response:

  1. [
  2. {
  3. "id": 28457,
  4. "price": "4.00000100",
  5. "qty": "12.00000000",
  6. "time": 1499865549590,
  7. "isBuyerMaker": true,
  8. "isBestMatch": true
  9. }
  10. ]

Old trade lookup (MARKET_DATA)

  1. GET /api/v1/historicalTrades

Get older trades.

Weight: 5

Parameters:

Name Type Mandatory Description
symbol STRING YES  
limit INT NO Default 500; max 1000.
fromId LONG NO TradeId to fetch from. Default gets most recent trades.

Response:

  1. [
  2. {
  3. "id": 28457,
  4. "price": "4.00000100",
  5. "qty": "12.00000000",
  6. "time": 1499865549590,
  7. "isBuyerMaker": true,
  8. "isBestMatch": true
  9. }
  10. ]

Compressed/Aggregate trades list

  1. GET /api/v1/aggTrades

Get compressed, aggregate trades. Trades that fill at the time, from the same order, with the same price will have the quantity aggregated.

Weight: 1

Parameters:

Name Type Mandatory Description
symbol STRING YES  
fromId LONG NO ID to get aggregate trades from INCLUSIVE.
startTime LONG NO Timestamp in ms to get aggregate trades from INCLUSIVE.
endTime LONG NO Timestamp in ms to get aggregate trades until INCLUSIVE.
limit INT NO Default 500; max 1000.
  • If both startTime and endTime are sent, time between startTime and endTime must be less than 1 hour.
  • If fromId, startTime, and endTime are not sent, the most recent aggregate trades will be returned.

Response:

  1. [
  2. {
  3. "a": 26129, // Aggregate tradeId
  4. "p": "0.01633102", // Price
  5. "q": "4.70443515", // Quantity
  6. "f": 27781, // First tradeId
  7. "l": 27781, // Last tradeId
  8. "T": 1498793709153, // Timestamp
  9. "m": true, // Was the buyer the maker?
  10. "M": true // Was the trade the best price match?
  11. }
  12. ]

Kline/Candlestick data

  1. GET /api/v1/klines

Kline/candlestick bars for a symbol. Klines are uniquely identified by their open time.

Weight: 1

Parameters:

Name Type Mandatory Description
symbol STRING YES  
interval ENUM YES  
startTime LONG NO  
endTime LONG NO  
limit INT NO Default 500; max 1000.
  • If startTime and endTime are not sent, the most recent klines are returned.

Response:

  1. [
  2. [
  3. 1499040000000, // Open time
  4. "0.01634790", // Open
  5. "0.80000000", // High
  6. "0.01575800", // Low
  7. "0.01577100", // Close
  8. "148976.11427815", // Volume
  9. 1499644799999, // Close time
  10. "2434.19055334", // Quote asset volume
  11. 308, // Number of trades
  12. "1756.87402397", // Taker buy base asset volume
  13. "28.46694368", // Taker buy quote asset volume
  14. "17928899.62484339" // Ignore.
  15. ]
  16. ]

24hr ticker price change statistics

  1. GET /api/v1/ticker/24hr

24 hour price change statistics. Careful when accessing this with no symbol.

Weight: 1 for a single symbol; 40 when the symbol parameter is omitted

Parameters:

Name Type Mandatory Description
symbol STRING NO  
  • If the symbol is not sent, tickers for all symbols will be returned in an array.

Response:

  1. {
  2. "symbol": "BNBBTC",
  3. "priceChange": "-94.99999800",
  4. "priceChangePercent": "-95.960",
  5. "weightedAvgPrice": "0.29628482",
  6. "prevClosePrice": "0.10002000",
  7. "lastPrice": "4.00000200",
  8. "lastQty": "200.00000000",
  9. "bidPrice": "4.00000000",
  10. "askPrice": "4.00000200",
  11. "openPrice": "99.00000000",
  12. "highPrice": "100.00000000",
  13. "lowPrice": "0.10000000",
  14. "volume": "8913.30000000",
  15. "quoteVolume": "15.30000000",
  16. "openTime": 1499783499040,
  17. "closeTime": 1499869899040,
  18. "firstId": 28385, // First tradeId
  19. "lastId": 28460, // Last tradeId
  20. "count": 76 // Trade count
  21. }

OR

  1. [
  2. {
  3. "symbol": "BNBBTC",
  4. "priceChange": "-94.99999800",
  5. "priceChangePercent": "-95.960",
  6. "weightedAvgPrice": "0.29628482",
  7. "prevClosePrice": "0.10002000",
  8. "lastPrice": "4.00000200",
  9. "lastQty": "200.00000000",
  10. "bidPrice": "4.00000000",
  11. "askPrice": "4.00000200",
  12. "openPrice": "99.00000000",
  13. "highPrice": "100.00000000",
  14. "lowPrice": "0.10000000",
  15. "volume": "8913.30000000",
  16. "quoteVolume": "15.30000000",
  17. "openTime": 1499783499040,
  18. "closeTime": 1499869899040,
  19. "firstId": 28385, // First tradeId
  20. "lastId": 28460, // Last tradeId
  21. "count": 76 // Trade count
  22. }
  23. ]

Symbol price ticker

  1. GET /api/v3/ticker/price

Latest price for a symbol or symbols.

Weight: 1

Parameters:

Name Type Mandatory Description
symbol STRING NO  
  • If the symbol is not sent, prices for all symbols will be returned in an array.

Response:

  1. {
  2. "symbol": "LTCBTC",
  3. "price": "4.00000200"
  4. }

OR

  1. [
  2. {
  3. "symbol": "LTCBTC",
  4. "price": "4.00000200"
  5. },
  6. {
  7. "symbol": "ETHBTC",
  8. "price": "0.07946600"
  9. }
  10. ]

Symbol order book ticker

  1. GET /api/v3/ticker/bookTicker

Best price/qty on the order book for a symbol or symbols.

Weight: 1

Parameters:

Name Type Mandatory Description
symbol STRING NO  
  • If the symbol is not sent, bookTickers for all symbols will be returned in an array.

Response:

  1. {
  2. "symbol": "LTCBTC",
  3. "bidPrice": "4.00000000",
  4. "bidQty": "431.00000000",
  5. "askPrice": "4.00000200",
  6. "askQty": "9.00000000"
  7. }

OR

  1. [
  2. {
  3. "symbol": "LTCBTC",
  4. "bidPrice": "4.00000000",
  5. "bidQty": "431.00000000",
  6. "askPrice": "4.00000200",
  7. "askQty": "9.00000000"
  8. },
  9. {
  10. "symbol": "ETHBTC",
  11. "bidPrice": "0.07946700",
  12. "bidQty": "9.00000000",
  13. "askPrice": "100000.00000000",
  14. "askQty": "1000.00000000"
  15. }
  16. ]

Account endpoints

New order (TRADE)

  1. POST /api/v3/order (HMAC SHA256)

Send in a new order.

Weight: 1

Parameters:

Name Type Mandatory Description
symbol STRING YES  
side ENUM YES  
type ENUM YES  
timeInForce ENUM NO  
quantity DECIMAL YES  
price DECIMAL NO  
newClientOrderId STRING NO A unique id for the order. Automatically generated if not sent.
stopPrice DECIMAL NO Used with STOP_LOSSSTOP_LOSS_LIMITTAKE_PROFIT, and TAKE_PROFIT_LIMIT orders.
icebergQty DECIMAL NO Used with LIMITSTOP_LOSS_LIMIT, and TAKE_PROFIT_LIMIT to create an iceberg order.
newOrderRespType ENUM NO Set the response JSON. ACKRESULT, or FULLMARKET and LIMITorder types default to FULL, all other orders default to ACK.
recvWindow LONG NO  
timestamp LONG YES  

Additional mandatory parameters based on type:

Type Additional mandatory parameters
LIMIT timeInForcequantityprice
MARKET quantity
STOP_LOSS quantitystopPrice
STOP_LOSS_LIMIT timeInForcequantitypricestopPrice
TAKE_PROFIT quantitystopPrice
TAKE_PROFIT_LIMIT timeInForcequantitypricestopPrice
LIMIT_MAKER quantityprice

Other info:

  • 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.

Trigger order price rules against market price for both MARKET and LIMIT versions:

  • Price above market price: STOP_LOSS BUYTAKE_PROFIT SELL
  • Price below market price: STOP_LOSS SELLTAKE_PROFIT BUY

Response ACK:

  1. {
  2. "symbol": "BTCUSDT",
  3. "orderId": 28,
  4. "clientOrderId": "6gCrw2kRUAF9CvJDGP16IP",
  5. "transactTime": 1507725176595
  6. }

Response RESULT:

  1. {
  2. "symbol": "BTCUSDT",
  3. "orderId": 28,
  4. "clientOrderId": "6gCrw2kRUAF9CvJDGP16IP",
  5. "transactTime": 1507725176595,
  6. "price": "1.00000000",
  7. "origQty": "10.00000000",
  8. "executedQty": "10.00000000",
  9. "cummulativeQuoteQty": "10.00000000",
  10. "status": "FILLED",
  11. "timeInForce": "GTC",
  12. "type": "MARKET",
  13. "side": "SELL"
  14. }

Response FULL:

  1. {
  2. "symbol": "BTCUSDT",
  3. "orderId": 28,
  4. "clientOrderId": "6gCrw2kRUAF9CvJDGP16IP",
  5. "transactTime": 1507725176595,
  6. "price": "1.00000000",
  7. "origQty": "10.00000000",
  8. "executedQty": "10.00000000",
  9. "cummulativeQuoteQty": "10.00000000",
  10. "status": "FILLED",
  11. "timeInForce": "GTC",
  12. "type": "MARKET",
  13. "side": "SELL",
  14. "fills": [
  15. {
  16. "price": "4000.00000000",
  17. "qty": "1.00000000",
  18. "commission": "4.00000000",
  19. "commissionAsset": "USDT"
  20. },
  21. {
  22. "price": "3999.00000000",
  23. "qty": "5.00000000",
  24. "commission": "19.99500000",
  25. "commissionAsset": "USDT"
  26. },
  27. {
  28. "price": "3998.00000000",
  29. "qty": "2.00000000",
  30. "commission": "7.99600000",
  31. "commissionAsset": "USDT"
  32. },
  33. {
  34. "price": "3997.00000000",
  35. "qty": "1.00000000",
  36. "commission": "3.99700000",
  37. "commissionAsset": "USDT"
  38. },
  39. {
  40. "price": "3995.00000000",
  41. "qty": "1.00000000",
  42. "commission": "3.99500000",
  43. "commissionAsset": "USDT"
  44. }
  45. ]
  46. }

Test new order (TRADE)

  1. POST /api/v3/order/test (HMAC SHA256)

Test new order creation and signature/recvWindow long. Creates and validates a new order but does not send it into the matching engine.

Weight: 1

Parameters:

Same as POST /api/v3/order

Response:

  1. {}

Query order (USER_DATA)

  1. GET /api/v3/order (HMAC SHA256)

Check an order's status.

Weight: 1

Parameters:

Name Type Mandatory Description
symbol STRING YES  
orderId LONG NO  
origClientOrderId STRING NO  
recvWindow LONG NO  
timestamp LONG YES  

Notes:

  • Either orderId or origClientOrderId must be sent.
  • For some historical orders cummulativeQuoteQty will be < 0, meaning the data is not available at this time.

Response:

  1. {
  2. "symbol": "LTCBTC",
  3. "orderId": 1,
  4. "clientOrderId": "myOrder1",
  5. "price": "0.1",
  6. "origQty": "1.0",
  7. "executedQty": "0.0",
  8. "cummulativeQuoteQty": "0.0",
  9. "status": "NEW",
  10. "timeInForce": "GTC",
  11. "type": "LIMIT",
  12. "side": "BUY",
  13. "stopPrice": "0.0",
  14. "icebergQty": "0.0",
  15. "time": 1499827319559,
  16. "updateTime": 1499827319559,
  17. "isWorking": true
  18. }

Cancel order (TRADE)

  1. DELETE /api/v3/order (HMAC SHA256)

Cancel an active order.

Weight: 1

Parameters:

Name Type Mandatory Description
symbol STRING YES  
orderId LONG NO  
origClientOrderId STRING NO  
newClientOrderId STRING NO Used to uniquely identify this cancel. Automatically generated by default.
recvWindow LONG NO  
timestamp LONG YES  

Either orderId or origClientOrderId must be sent.

Response:

  1. {
  2. "symbol": "LTCBTC",
  3. "origClientOrderId": "myOrder1",
  4. "orderId": 1,
  5. "clientOrderId": "cancelMyOrder1"
  6. }

Current open orders (USER_DATA)

  1. GET /api/v3/openOrders (HMAC SHA256)

Get all open orders on a symbol. Careful when accessing this with no symbol.

Weight: 1 for a single symbol; 40 when the symbol parameter is omitted

Parameters:

Name Type Mandatory Description
symbol STRING NO  
recvWindow LONG NO  
timestamp LONG YES  
  • If the symbol is not sent, orders for all symbols will be returned in an array.
  • 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.

Response:

  1. [
  2. {
  3. "symbol": "LTCBTC",
  4. "orderId": 1,
  5. "clientOrderId": "myOrder1",
  6. "price": "0.1",
  7. "origQty": "1.0",
  8. "executedQty": "0.0",
  9. "cummulativeQuoteQty": "0.0",
  10. "status": "NEW",
  11. "timeInForce": "GTC",
  12. "type": "LIMIT",
  13. "side": "BUY",
  14. "stopPrice": "0.0",
  15. "icebergQty": "0.0",
  16. "time": 1499827319559,
  17. "updateTime": 1499827319559,
  18. "isWorking": true
  19. }
  20. ]

All orders (USER_DATA)

  1. GET /api/v3/allOrders (HMAC SHA256)

Get all account orders; active, canceled, or filled.

Weight: 5 with symbol

Parameters:

Name Type Mandatory Description
symbol STRING YES  
orderId LONG NO  
startTime LONG NO  
endTime LONG NO  
limit INT NO Default 500; max 1000.
recvWindow LONG NO  
timestamp LONG YES  

Notes:

  • If orderId is set, it will get orders >= that orderId. Otherwise most recent orders are returned.
  • For some historical orders cummulativeQuoteQty will be < 0, meaning the data is not available at this time.

Response:

  1. [
  2. {
  3. "symbol": "LTCBTC",
  4. "orderId": 1,
  5. "clientOrderId": "myOrder1",
  6. "price": "0.1",
  7. "origQty": "1.0",
  8. "executedQty": "0.0",
  9. "cummulativeQuoteQty": "0.0",
  10. "status": "NEW",
  11. "timeInForce": "GTC",
  12. "type": "LIMIT",
  13. "side": "BUY",
  14. "stopPrice": "0.0",
  15. "icebergQty": "0.0",
  16. "time": 1499827319559,
  17. "updateTime": 1499827319559,
  18. "isWorking": true
  19. }
  20. ]

Account information (USER_DATA)

  1. GET /api/v3/account (HMAC SHA256)

Get current account information.

Weight: 5

Parameters:

Name Type Mandatory Description
recvWindow LONG NO  
timestamp LONG YES  

Response:

  1. {
  2. "makerCommission": 15,
  3. "takerCommission": 15,
  4. "buyerCommission": 0,
  5. "sellerCommission": 0,
  6. "canTrade": true,
  7. "canWithdraw": true,
  8. "canDeposit": true,
  9. "updateTime": 123456789,
  10. "balances": [
  11. {
  12. "asset": "BTC",
  13. "free": "4723846.89208129",
  14. "locked": "0.00000000"
  15. },
  16. {
  17. "asset": "LTC",
  18. "free": "4763368.68006011",
  19. "locked": "0.00000000"
  20. }
  21. ]
  22. }

Account trade list (USER_DATA)

  1. GET /api/v3/myTrades (HMAC SHA256)

Get trades for a specific account and symbol.

Weight: 5 with symbol

Parameters:

Name Type Mandatory Description
symbol STRING YES  
startTime LONG NO  
endTime LONG NO  
fromId LONG NO TradeId to fetch from. Default gets most recent trades.
limit INT NO Default 500; max 1000.
recvWindow LONG NO  
timestamp LONG YES  

Notes:

  • If fromId is set, it will get orders >= that fromId. Otherwise most recent orders are returned.

Response:

  1. [
  2. {
  3. "symbol": "BNBBTC",
  4. "id": 28457,
  5. "orderId": 100234,
  6. "price": "4.00000100",
  7. "qty": "12.00000000",
  8. "commission": "10.10000000",
  9. "commissionAsset": "BNB",
  10. "time": 1499865549590,
  11. "isBuyer": true,
  12. "isMaker": false,
  13. "isBestMatch": true
  14. }
  15. ]

User data stream endpoints

Specifics on how user data streams work is in another document.

Start user data stream (USER_STREAM)

  1. POST /api/v1/userDataStream

Start a new user data stream. The stream will close after 60 minutes unless a keepalive is sent.

Weight: 1

Parameters: NONE

Response:

  1. {
  2. "listenKey": "pqia91ma19a5s61cv6a81va65sdf19v8a65a1a5s61cv6a81va65sdf19v8a65a1"
  3. }

Keepalive user data stream (USER_STREAM)

  1. PUT /api/v1/userDataStream

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.

Weight: 1

Parameters:

Name Type Mandatory Description
listenKey STRING YES  

Response:

  1. {}

Close user data stream (USER_STREAM)

  1. DELETE /api/v1/userDataStream

Close out a user data stream.

Weight: 1

Parameters:

Name Type Mandatory Description
listenKey STRING YES  

Response:

  1. {}

Filters

Filters define trading rules on a symbol or an exchange. Filters come in two forms: symbol filters and exchange filters.

Symbol filters

PRICE_FILTER

The PRICE_FILTER defines the price rules for a symbol. There are 3 parts:

  • minPrice defines the minimum price/stopPrice allowed.
  • maxPrice defines the maximum price/stopPrice allowed.
  • tickSize defines the intervals that a price/stopPrice can be increased/decreased by.

In order to pass the price filter, the following must be true for price/stopPrice:

  • price >= minPrice
  • price <= maxPrice
  • (price-minPrice) % tickSize == 0

/exchangeInfo format:

  1. {
  2. "filterType": "PRICE_FILTER",
  3. "minPrice": "0.00000100",
  4. "maxPrice": "100000.00000000",
  5. "tickSize": "0.00000100"
  6. }

LOT_SIZE

The LOT_SIZE filter defines the quantity (aka "lots" in auction terms) rules for a symbol. There are 3 parts:

  • minQty defines the minimum quantity/icebergQty allowed.
  • maxQty defines the maximum quantity/icebergQty allowed.
  • stepSize defines the intervals that a quantity/icebergQty can be increased/decreased by.

In order to pass the lot size, the following must be true for quantity/icebergQty:

  • quantity >= minQty
  • quantity <= maxQty
  • (quantity-minQty) % stepSize == 0

/exchangeInfo format:

  1. {
  2. "filterType": "LOT_SIZE",
  3. "minQty": "0.00100000",
  4. "maxQty": "100000.00000000",
  5. "stepSize": "0.00100000"
  6. }

MIN_NOTIONAL

The MIN_NOTIONAL filter defines the minimum notional value allowed for an order on a symbol. An order's notional value is the price * quantity.

/exchangeInfo format:

  1. {
  2. "filterType": "MIN_NOTIONAL",
  3. "minNotional": "0.00100000"
  4. }

MAX_NUM_ORDERS

The MAX_NUM_ORDERS filter defines the maximum number of orders an account is allowed to have open on a symbol. Note that both "algo" orders and normal orders are counted for this filter.

/exchangeInfo format:

  1. {
  2. "filterType": "MAX_NUM_ORDERS",
  3. "limit": 25
  4. }

MAX_NUM_ALGO_ORDERS

The MAX_ALGO_ORDERS filter defines the maximum number of "algo" orders an account is allowed to have open on a symbol. "Algo" orders are STOP_LOSSSTOP_LOSS_LIMITTAKE_PROFIT, and TAKE_PROFIT_LIMIT orders.

/exchangeInfo format:

  1. {
  2. "filterType": "MAX_NUM_ALGO_ORDERS",
  3. "maxNumAlgoOrders": 5
  4. }

ICEBERG_PARTS

The ICEBERG_PARTS filter defines the maximum parts an iceberg order can have. The number of ICEBERG_PARTS is defined as CEIL(qty / icebergQty).

/exchangeInfo format:

  1. {
  2. "filterType": "ICEBERG_PARTS",
  3. "limit": 10
  4. }

Exchange Filters

EXCHANGE_MAX_NUM_ORDERS

The MAX_NUM_ORDERS filter defines the maximum number of orders an account is allowed to have open on the exchange. Note that both "algo" orders and normal orders are counted for this filter.

/exchangeInfo format:

  1. {
  2. "filterType": "EXCHANGE_MAX_NUM_ORDERS",
  3. "limit": 1000
  4. }

EXCHANGE_MAX_NUM_ALGO_ORDERS

The MAX_ALGO_ORDERS filter defines the maximum number of "algo" orders an account is allowed to have open on the exchange. "Algo" orders are STOP_LOSSSTOP_LOSS_LIMITTAKE_PROFIT, and TAKE_PROFIT_LIMIT orders.

/exchangeInfo format:

  1. {
  2. "filterType": "EXCHANGE_MAX_NUM_ALGO_ORDERS",
  3. "limit": 200
  4. }

币安Binance API的更多相关文章

  1. 币安Binance API Websocket

    本文介绍币安Binance API Websocket General WSS information The base endpoint is: wss://stream.binance.com:9 ...

  2. ImCash:币安下架BSV之辩:规则、中立与去中心化

    一种看法是:一个引用价格数据和执行交易的加密货币交易所,其业务决策往往是在链外发生的,不受制于严格的.类似于准宪法的链上规则的约束,加密货币交易所可以拒绝任何人喜欢的价格和交易,而且这样做并不会损害底 ...

  3. python安装包API文档

    在python开发过程中,经常会使用第三方包,或者内置的包. 那么这些包,具体有哪些选项,有哪些方法,你知道吗?下面介绍一种万能方法. 使用命令:<注意,命令里python显示的API版本是根据 ...

  4. 各大知名区块链交易所链接及API文档链接

    区块链交易所链接 火币网(Huobi):https://www.huobi.br.com/zh-cn/ API文档:https://github.com/huobiapi/API_Docs/wiki ...

  5. AI趋势量化系统(Binance升级版)

    更多精彩内容,欢迎关注公众号:数量技术宅,也可添加技术宅个人微信号:sljsz01,与我交流. B圈大跌行情,如何应对? 近期,伴随着美联储持续的加息进程,数字货币市场不论是市场焦点LUNA,还是BT ...

  6. 火币网现货API[Python3版]

    火币 期货 现货 API [Python3版] 一.Util.py,基础类,包括参数配置.签名,HTTP 请求方法,发送信息到API #coding=utf-8 import hashlib impo ...

  7. 网友"就像一支烟"山寨币分析估值方法

    [注:素材取自QQ群,2017年12月28日的聊天记录."就像一支烟"分享了自己的山寨币分析估值方法.因为删去了其他人的聊天记录,部分文字可能断章取义,仅供参考,具体情况请自行分析 ...

  8. OTCBTC上线币币交易

    我们在这里很高兴的宣布,OTCBTC 的币币交易区,即将在 2018/01/11 于 08:00 上线. 这个币币交易区,将会跟所有现有的交易所很不一样,我们将开放用户自主上币,且所有品种不收任何上架 ...

  9. OKEX API

    本文介绍OKEX API Rest 开始使用 REST,即Representational State Transfer的缩写,是目前最流行的一种互联网软件架构.它结构清晰.符合标准.易于理解.扩展方 ...

随机推荐

  1. 【内网渗透笔记】Windows2008 R2搭建域控制器

    0x00 前言 将网络中的多台计算机逻辑上组织到一起,进行集中管理,这种区别于工作组的逻辑环境叫做域(domain).域是日常计算机管理的一种很有效手段,因此,域控制器自然而然就在成域环境中最重要的角 ...

  2. WAF Bypass 笔记(SQL注入篇)

    0x01 背景 waf Bypass 笔记 0x02 服务器特性 1.%特性(ASP+IIS) 在asp+iis的环境中存在一个特性,就是特殊符号%,在该环境下当们我输入s%elect的时候,在WAF ...

  3. 文件名过滤器FilenameFilter的用法

    Java.io.FilenameFilter是文件名过滤器,用来过滤不符合规格的文件名,并返回合格的文件: 实例1,匹配指定字符结尾的文件 package cn.test; import java.i ...

  4. [Ubuntu] APT - Advanced Packaging Tool 简明指南

    Advanced Packaging Tool,一般简称为apt,是Debian GNU/Linux distribution及其变体版本中与核心库一道处理软件的安装和卸载. Ubuntu是Debia ...

  5. (iOS)使用auto layout进行复杂布局时,UILabel的相关trick

    本文转载至 http://blog.csdn.net/madongchunqiu/article/details/47960745  本文首发于CSDN:http://blog.csdn.net/ma ...

  6. rabbitMQ常用的命令

    rabbitMQ常用的命令 启动监控管理器:rabbitmq-plugins enable rabbitmq_management 关闭监控管理器:rabbitmq-plugins disable r ...

  7. Java单播、广播、多播(组播)

    一.通信方式分类 在当前的网络通信中有三种通信模式:单播.广播和多播(组播),其中多播出现时间最晚,同时具备单播和广播的优点. 单播:单台主机与单台主机之间的通信 广播:当台主机与网络中的所有主机通信 ...

  8. SQL Server Profiler工具【转】

    一.SQL Profiler工具简介 转自:http://www.cnblogs.com/kissdodog/p/3398523.html SQL Profiler是一个图形界面和一组系统存储过程,其 ...

  9. 跟我一起写Makefile:使用函数

    跟我一起写Makefile:使用函数 两个排版不一样 书籍下载 书籍下载

  10. 题目1441:人见人爱 A ^ B(二分求幂)

    题目链接:http://ac.jobdu.com/problem.php?pid=1441 详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus 参考代码: ...