Binance US Client (WIP)
Install
# NPM npm i binance-us # Yarn yarn add binance-us
Getting Started
Importing
modules
// Authenticatedconst key = 'xV7WDC9IbREgZ...'const secret = 'KvBlbigseoZcv...'const client = key secret // Publicconst client =
commonjs
const BinanceUS = // Authenticatedconst key = 'xV7WDC9IbREgZ...'const secret = 'KvBlbigseoZcv...'const client = // Publicconst client =
Usage
async/await
const response = await clientconsole
callback
client
Table of Contents
- Public REST Endpoints
- Protected REST Endpoints
- Market Data
- Order
- new order
- test new order
- lookup order
- cancel order
- open orders
- all orders
- OCO
- new OCO
- cancel OCO
- lookup OCO
- all OCOs
- open OCOs
- Account
- account information
- account trades
- WebSocket...
ping
Test connectivity to the API.
Weight: 1
console
Response
{}
time
Current server time.
Weight: 1
console
Response
serverTime: 1578369719229
exchangeInfo
Current exchange trading rules and symbol information.
Weight: 1
console
Response
timezone: "UTC" serverTime: 1578375682742 rateLimits: rateLimitType: "REQUEST_WEIGHT" interval: "MINUTE" intervalNum: 1 limit: 1200 rateLimitType: "ORDERS" interval: "SECOND" intervalNum: 10 limit: 100 rateLimitType: "ORDERS" interval: "DAY" intervalNum: 1 limit: 200000 exchangeFilters: symbols: symbol: "BTCUSD" status: "TRADING" baseAsset: "BTC" baseAssetPrecision: 8 quoteAsset: "USD" quotePrecision: 4 baseCommissionPrecision: 8 quoteCommissionPrecision: 2 orderTypes: "LIMIT" "LIMIT_MAKER" "MARKET" "STOP_LOSS_LIMIT" "TAKE_PROFIT_LIMIT" icebergAllowed: true ocoAllowed: true isSpotTradingAllowed: true isMarginTradingAllowed: false filters: filterType: "PRICE_FILTER" minPrice: "0.0100" maxPrice: "100000.0000" tickSize: "0.0100" filterType: "PERCENT_PRICE" multiplierUp: "5" multiplierDown: "0.2" avgPriceMins: 5 filterType: "LOT_SIZE" minQty: "0.00000100" maxQty: "9000.00000000" stepSize: "0.00000100"
book
Order book.
Weight:
Limit | Weight |
---|---|
5,10,20,50,100 | 1 |
500 | 5 |
1000 | 10 |
5000 | 50 |
Parameters
Name | Type | Mandatory | Default | Description |
---|---|---|---|---|
symbol | string | YES | N/A | |
limit | number | NO | 100 | valid:[5,10,20,50,100,500,1000,5000] |
const symbol = 'BTCUSD'const limit = 500 consoleconsole
Response
lastUpdateId: 1027024 bids: price: "4.00000000" quantity: "431.00000000" asks: price: "4.00000200" quantity: "12.00000000"
trades
Recent trades.
Weight: 1
Parameters
Name | Type | Mandatory | Default | Description |
---|---|---|---|---|
symbol | string | YES | N/A | |
limit | number | NO | 500 | max: 1000 |
const symbol = 'BTCUSD'const limit = 850 consoleconsole
Response
; id: 28457 price: '4.00000100' quantity: '12.00000000' quoteQuantity: '48.000012' time: 1499865549590 isBuyerMaker: true isBestMatch: true
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 | Default | Description |
---|---|---|---|---|
symbol | string | YES | N/A | |
limit | number | NO | 500 | max: 1000 |
fromId | number | NO | N/A | ID to get aggregate trades from INCLUSIVE |
startTime | number | NO | N/A | Timestamp in ms to get aggregate trades from INCLUSIVE |
endTime | number | NO | N/A | Timestamp in ms to get aggregate trades until INCLUSIVE |
- If both
startTime
andendTime
are sent, time betweenstartTime
andendTime
must be less than 1 hour. - If
fromId
,startTime
, andendTime
are not sent, the most recent aggregate trades will be returned.
const symbol = 'BTCUSD'const limit = 625 consoleconsole
Response
; id: 26129 price: '0.01633102' quantity: '4.70443515' firstId: 27781 lastId: 27781 time: 1498793709153 isBuyerMaker: true isBestMatch: true
candles
Kline/candlestick bars for a symbol. Candlesticks are uniquely identified by their open time.
Weight: 1
Parameters
Name | Type | Mandatory | Default | Description |
---|---|---|---|---|
symbol | string | YES | N/A | |
interval | enum | YES | N/A | 1m,3m,5m,15m,30m,1h,2h,4h,6h,8h,12h,1d,3d,1w,1M |
startTime | number | NO | N/A | |
endTime | number | NO | N/A | |
limit | number | NO | 500 | max: 1000 |
- If
startTime
andendTime
are not sent, the most recent candlesticks are returned.
const symbol = 'BTCUSD'const interval = CandlestickIntervalFIFTEEN_MINUTESconst limit = 920 consoleconsole
Response
; openTime: 1499040000000 open: '0.01634790' high: '0.80000000' low: '0.01575800' close: '0.01577100' volume: '148976.11427815' closeTime: 1499644799999 quoteVolume: '2434.19055334' trades: 308 takerBuyVolume: '1756.87402397' tackerBuyQuoteVolume: '28.46694368'
avgPrice
Current average price for a symbol.
Weight: 1
Parameters
Name | Type | Mandatory | Default | Description |
---|---|---|---|---|
symbol | string | YES | N/A |
const symbol = 'BTCUSD' console
Response
minutes: 5 price: "9.35751834"
ticker24Hour
24 hour rolling window 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 | Default | Description |
---|---|---|---|---|
symbol | string | NO | N/A |
const symbol = 'BTCUSD' console // weight: 40console // weight: 1
Response
; symbol: 'BNBBTC' priceChange: '-94.99999800' priceChangePercent: '-95.960' weightedAvgPrice: '0.29628482' prevClosePrice: '0.10002000' lastPrice: '4.00000200' lastQuantity: '200.00000000' bidPrice: '4.00000000' askPrice: '4.00000200' openPrice: '99.00000000' highPrice: '100.00000000' lowPrice: '0.10000000' volume: '8913.30000000' quoteVolume: '15.30000000' openTime: 1499783499040 closeTime: 1499869899040 firstId: 28385 lastId: 28460 trades: 76
tickerPrice
Latest price for a symbol or symbols.
Weight: 1 for a single symbol; 2 when the symbol parameter is omitted
Parameters
Name | Type | Mandatory | Default | Description |
---|---|---|---|---|
symbol | string | NO | N/A |
const symbol = 'BTCUSD' console // weight: 2console // weight: 1
Response
; symbol: 'LTCBTC' price: '4.00000200'
tickerBook
Best price/quantity on the order book for a symbol or symbols.
Weight: 1 for a single symbol; 2 when the symbol parameter is omitted
Parameters
Name | Type | Mandatory | Default | Description |
---|---|---|---|---|
symbol | string | NO | N/A |
const symbol = 'BTCUSD' console // weight: 2console // weight: 1
Response
; symbol: 'LTCBTC' bidPrice: '4.00000000' bidQuantity: '431.00000000' askPrice: '4.00000200' askQuantity: '9.00000000'
historicalTrades
Get older trades.
Key Required
Weight: 5
Parameters
Name | Type | Mandatory | Default | Description |
---|---|---|---|---|
symbol | string | NO | N/A | |
limit | number | NO | 500 | max: 1000 |
fromId | number | NO | N/A | TradeId to fetch from. Default gets most recent trades. |
const symbol = 'BTCUSD'const limit = 100 consoleconsole
Response
id: 28457 price: '4.00000100' quantity: '12.00000000' quoteQuantity: '48.000012' time: 1499865549590 isBuyerMaker: true isBestMatch: true
License
This project is licensed under the ISC License - see the LICENSE file for details