Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
binance-api-node
Advanced tools
A complete API wrapper for the Binance API.
Note: This wrapper uses Promises, if they are not supported in your environment, you might want to add a polyfill for them.
For PRs or issues, head over to the source repository.
yarn add binance-api-node
Import the module and create a new client. Passing api keys is optional only if you don't plan on doing authenticated calls. You can create an api key here.
import Binance from 'binance-api-node'
const client = Binance()
// Authenticated client, can make signed calls
const client2 = Binance({
apiKey: 'xxx',
apiSecret: 'xxx',
getTime: xxx, // time generator function, optional, defaults to () => Date.now()
})
client.time().then(time => console.log(time))
If you do not have an appropriate babel config, you will need to use the basic commonjs requires.
const Binance = require('binance-api-node').default
Every REST method returns a Promise, making this library async await ready.
Following examples will use the await
form, which requires some configuration you will have to lookup.
Test connectivity to the API.
console.log(await client.ping())
Test connectivity to the Rest API and get the current server time.
console.log(await client.time())
1508478457643
Get the current exchange trading rules and symbol information.
console.log(await client.exchangeInfo())
{
"timezone": "UTC",
"serverTime": 1508631584636,
"rateLimits": [
{
"rateLimitType": "REQUEST_WEIGHT",
"interval": "MINUTE",
"intervalNum": 1,
"limit": 1200
},
{
"rateLimitType": "ORDERS",
"interval": "SECOND",
"intervalNum": 1,
"limit": 10
},
{
"rateLimitType": "ORDERS",
"interval": "DAY",
"intervalNum": 1,
"limit": 100000
}
],
"exchangeFilters": [],
"symbols": [{
"symbol": "ETHBTC",
"status": "TRADING",
"baseAsset": "ETH",
"baseAssetPrecision": 8,
"quoteAsset": "BTC",
"quotePrecision": 8,
"orderTypes": ["LIMIT", "MARKET"],
"icebergAllowed": false,
"filters": [{
"filterType": "PRICE_FILTER",
"minPrice": "0.00000100",
"maxPrice": "100000.00000000",
"tickSize": "0.00000100"
}, {
"filterType": "LOT_SIZE",
"minQty": "0.00100000",
"maxQty": "100000.00000000",
"stepSize": "0.00100000"
}, {
"filterType": "MIN_NOTIONAL",
"minNotional": "0.00100000"
}]
}]
}
Get the order book for a symbol.
console.log(await client.book({ symbol: 'ETHBTC' }))
Param | Type | Required | Default |
---|---|---|---|
symbol | String | true | |
limit | Number | false | 100 |
{
lastUpdateId: 17647759,
asks:
[
{ price: '0.05411500', quantity: '5.55000000' },
{ price: '0.05416700', quantity: '11.80100000' }
],
bids:
[
{ price: '0.05395500', quantity: '2.70000000' },
{ price: '0.05395100', quantity: '11.84100000' }
]
}
Retrieves Candlestick for a symbol. Candlesticks are uniquely identified by their open time.
console.log(await client.candles({ symbol: 'ETHBTC' }))
Param | Type | Required | Default | Description |
---|---|---|---|---|
symbol | String | true | ||
interval | String | false | 5m | 1m , 3m , 5m , 15m , 30m , 1h , 2h ,4h , 6h , 8h , 12h , 1d , 3d , 1w , 1M |
limit | Number | false | 500 | Max 1000 |
startTime | Number | false | ||
endTime | Number | false |
;[
{
openTime: 1508328900000,
open: '0.05655000',
high: '0.05656500',
low: '0.05613200',
close: '0.05632400',
volume: '68.88800000',
closeTime: 1508329199999,
quoteAssetVolume: '2.29500857',
trades: 85,
baseAssetVolume: '40.61900000',
},
]
Get compressed, aggregate trades. Trades that fill at the time, from the same order, with the same price will have the quantity aggregated.
console.log(await client.aggTrades({ symbol: 'ETHBTC' }))
Param | Type | Required | Default | Description |
---|---|---|---|---|
symbol | String | true | ||
fromId | String | false | ID to get aggregate trades from INCLUSIVE. | |
startTime | Number | false | Timestamp in ms to get aggregate trades from INCLUSIVE. | |
endTime | Number | false | Timestamp in ms to get aggregate trades until INCLUSIVE. | |
limit | Number | false | 500 | Max 500 |
Note: If both startTime
and endTime
are sent, limit
should not be sent AND the distance between startTime
and endTime
must be less than 24 hours.
Note: If frondId
, startTime
, and endTime
are not sent, the most recent aggregate trades will be returned.
;[
{
aggId: 2107132,
symbol: 'ETHBTC',
price: '0.05390400',
quantity: '1.31000000',
firstId: 2215345,
lastId: 2215345,
timestamp: 1508478599481,
isBuyerMaker: true,
wasBestPrice: true,
},
]
Get recent trades of a symbol.
console.log(await client.trades({ symbol: 'ETHBTC' }))
Param | Type | Required | Default | Description |
---|---|---|---|---|
symbol | String | true | ||
limit | Number | false | 500 | Max 500 |
;[
{
id: 28457,
price: '4.00000100',
qty: '12.00000000',
time: 1499865549590,
isBuyerMaker: true,
isBestMatch: true,
},
]
24 hour price change statistics, not providing a symbol will return all tickers and is resource-expensive.
console.log(await client.dailyStats({ symbol: 'ETHBTC' }))
Param | Type | Required |
---|---|---|
symbol | String | false |
{
symbol: 'ETHBTC',
priceChange: '-0.00112000',
priceChangePercent: '-1.751',
weightedAvgPrice: '0.06324784',
prevClosePrice: '0.06397400',
lastPrice: '0.06285500',
lastQty: '0.63500000',
bidPrice: '0.06285500',
bidQty: '0.81900000',
askPrice: '0.06291900',
askQty: '2.93800000',
openPrice: '0.06397500',
highPrice: '0.06419100',
lowPrice: '0.06205300',
volume: '126240.37200000',
quoteVolume: '7984.43091340',
openTime: 1521622289427,
closeTime: 1521708689427,
firstId: 45409308, // First tradeId
lastId: 45724293, // Last tradeId
count: 314986 // Trade count
}
Current average price for a symbol.
console.log(await client.avgPrice({ symbol: 'ETHBTC' }))
Param | Type | Required |
---|---|---|
symbol | String | true |
{
"mins": 5,
"price": "9.35751834"
}
Latest price for a symbol, not providing the symbol will return prices for all symbols.
console.log(await client.prices())
Param | Type | Required |
---|---|---|
symbol | String | false |
{
ETHBTC: '0.05392500',
LTCBTC: '0.01041100',
...
}
Best price/qty on the order book for all symbols.
console.log(await client.allBookTickers())
{
DASHBTC: {
symbol: 'DASHBTC',
bidPrice: '0.04890400',
bidQty: '0.74100000',
askPrice: '0.05230000',
askQty: '0.79900000'
},
DASHETH: {
symbol: 'DASHETH',
bidPrice: '0.89582000',
bidQty: '0.63300000',
askPrice: '1.02328000',
askQty: '0.99900000'
}
...
}
Test connectivity to the API.
console.log(await client.futuresPing())
Test connectivity to the Rest API and get the current server time.
console.log(await client.futuresTime())
1508478457643
Get the current exchange trading rules and symbol information.
console.log(await client.futuresExchangeInfo())
{
"timezone": "UTC",
"serverTime": 1508631584636,
"rateLimits": [
{
"rateLimitType": "REQUEST_WEIGHT",
"interval": "MINUTE",
"intervalNum": 1,
"limit": 1200
},
{
"rateLimitType": "ORDERS",
"interval": "SECOND",
"intervalNum": 1,
"limit": 10
},
{
"rateLimitType": "ORDERS",
"interval": "DAY",
"intervalNum": 1,
"limit": 100000
}
],
"exchangeFilters": [],
"symbols": [...]
}
Get the order book for a symbol.
console.log(await client.futuresBook({ symbol: 'BTCUSDT' }))
Param | Type | Required | Default |
---|---|---|---|
symbol | String | true | |
limit | Number | false | 100 |
{
lastUpdateId: 17647759,
asks:
[
{ price: '8000.05411500', quantity: '54.55000000' },
{ price: '8000.05416700', quantity: '1111.80100000' }
],
bids:
[
{ price: '8000.05395500', quantity: '223.70000000' },
{ price: '8000.05395100', quantity: '1134.84100000' }
]
}
Retrieves Candlestick for a symbol. Candlesticks are uniquely identified by their open time.
console.log(await client.futuresCandles({ symbol: 'BTCUSDT' }))
Param | Type | Required | Default | Description |
---|---|---|---|---|
symbol | String | true | ||
interval | String | false | 5m | 1m , 3m , 5m , 15m , 30m , 1h , 2h ,4h , 6h , 8h , 12h , 1d , 3d , 1w , 1M |
limit | Number | false | 500 | Max 1000 |
startTime | Number | false | ||
endTime | Number | false |
;[
{
openTime: 1508328900000,
open: '0.05655000',
high: '0.05656500',
low: '0.05613200',
close: '0.05632400',
volume: '68.88800000',
closeTime: 1508329199999,
quoteAssetVolume: '2.29500857',
trades: 85,
baseAssetVolume: '40.61900000',
},
]
Get compressed, aggregate trades. Trades that fill at the time, from the same order, with the same price will have the quantity aggregated.
console.log(await client.futuresAggTrades({ symbol: 'ETHBTC' }))
Param | Type | Required | Default | Description |
---|---|---|---|---|
symbol | String | true | ||
fromId | String | false | ID to get aggregate trades from INCLUSIVE. | |
startTime | Number | false | Timestamp in ms to get aggregate trades from INCLUSIVE. | |
endTime | Number | false | Timestamp in ms to get aggregate trades until INCLUSIVE. | |
limit | Number | false | 500 | Max 500 |
Note: If both startTime
and endTime
are sent, limit
should not be sent AND the distance between startTime
and endTime
must be less than 24 hours.
Note: If frondId
, startTime
, and endTime
are not sent, the most recent aggregate trades will be returned.
;[
{
aggId: 2107132,
price: '0.05390400',
quantity: '1.31000000',
firstId: 2215345,
lastId: 2215345,
timestamp: 1508478599481,
isBuyerMaker: true,
wasBestPrice: true,
},
]
Get recent trades of a symbol.
console.log(await client.futuresTrades({ symbol: 'ETHBTC' }))
Param | Type | Required | Default | Description |
---|---|---|---|---|
symbol | String | true | ||
limit | Number | false | 500 | Max 500 |
;[
{
id: 28457,
price: '4.00000100',
qty: '12.00000000',
time: 1499865549590,
isBuyerMaker: true,
isBestMatch: true,
},
]
24 hour price change statistics, not providing a symbol will return all tickers and is resource-expensive.
console.log(await client.futuresDailyStats({ symbol: 'ETHBTC' }))
Param | Type | Required |
---|---|---|
symbol | String | false |
{
symbol: 'BTCUSDT',
priceChange: '-0.00112000',
priceChangePercent: '-1.751',
weightedAvgPrice: '0.06324784',
prevClosePrice: '0.06397400',
lastPrice: '0.06285500',
lastQty: '0.63500000',
bidPrice: '0.06285500',
bidQty: '0.81900000',
askPrice: '0.06291900',
askQty: '2.93800000',
openPrice: '0.06397500',
highPrice: '0.06419100',
lowPrice: '0.06205300',
volume: '126240.37200000',
quoteVolume: '7984.43091340',
openTime: 1521622289427,
closeTime: 1521708689427,
firstId: 45409308, // First tradeId
lastId: 45724293, // Last tradeId
count: 314986 // Trade count
}
Latest price for all symbols.
console.log(await client.futuresPrices())
{
BTCUSDT: '8590.05392500',
ETHUSDT: '154.1100',
...
}
Best price/qty on the order book for all symbols.
console.log(await client.futuresAllBookTickers())
{
BTCUSDT: {
symbol: 'BTCUSDT',
bidPrice: '0.04890400',
bidQty: '0.74100000',
askPrice: '0.05230000',
askQty: '0.79900000'
},
ETHUSDT: {
symbol: 'ETHUSDT',
bidPrice: '0.89582000',
bidQty: '0.63300000',
askPrice: '1.02328000',
askQty: '0.99900000'
}
...
}
Mark Price and Funding Rate.
console.log(await client.futuresMarkPrice())
{
"symbol": "BTCUSDT",
"markPrice": "11012.80409769",
"lastFundingRate": "-0.03750000",
"nextFundingTime": 1562569200000,
"time": 1562566020000
}
Get all Liquidation Orders.
console.log(await client.futuresAllForceOrders())
Param | Type | Required |
---|---|---|
symbol | String | false |
startTime | Long | false |
endTime | Long | false |
limit | Long | false |
;[
{
symbol: 'BTCUSDT', // SYMBOL
price: '7918.33', // ORDER_PRICE
origQty: '0.014', // ORDER_AMOUNT
executedQty: '0.014', // FILLED_AMOUNT
avragePrice: '7918.33', // AVG_PRICE
status: 'FILLED', // STATUS
timeInForce: 'IOC', // TIME_IN_FORCE
type: 'LIMIT',
side: 'SELL', // DIRECTION
time: 1568014460893,
},
]
Note that for all authenticated endpoints, you can pass an extra parameter
useServerTime
set to true
in order to fetch the server time before making
the request.
Creates a new order.
console.log(
await client.order({
symbol: 'XLMETH',
side: 'BUY',
quantity: 100,
price: 0.0002,
}),
)
Param | Type | Required | Default | Description |
---|---|---|---|---|
symbol | String | true | ||
side | String | true | BUY ,SELL | |
type | String | false | LIMIT | LIMIT , MARKET |
quantity | Number | true | ||
price | Number | true | Optional for MARKET orders | |
timeInForce | String | false | GTC | FOK , GTC , IOC |
newClientOrderId | String | false | A unique id for the order. Automatically generated if not sent. | |
stopPrice | Number | false | Used with stop orders | |
newOrderRespType | String | false | RESULT | Returns more complete info of the order. ACK , RESULT , or FULL |
icebergQty | Number | false | Used with iceberg orders | |
recvWindow | Number | false |
Additional mandatory parameters based on type
:
Type | Additional mandatory parameters |
---|---|
LIMIT | timeInForce , quantity , price |
MARKET | quantity |
STOP_LOSS | quantity , stopPrice |
STOP_LOSS_LIMIT | timeInForce , quantity , price , stopPrice |
TAKE_PROFIT | quantity , stopPrice |
TAKE_PROFIT_LIMIT | timeInForce , quantity , price , stopPrice |
LIMIT_MAKER | quantity , price |
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.LIMIT
or LIMIT_MAKER
type order can be made an iceberg order by sending an icebergQty
.icebergQty
MUST have timeInForce
set to GTC
.{
symbol: 'XLMETH',
orderId: 1740797,
clientOrderId: '1XZTVBTGS4K1e',
transactTime: 1514418413947,
price: '0.00020000',
origQty: '100.00000000',
executedQty: '0.00000000',
status: 'NEW',
timeInForce: 'GTC',
type: 'LIMIT',
side: 'BUY'
}
Test new order creation and signature/recvWindow. Creates and validates a new order but does not send it into the matching engine.
Same API as above, but does not return any output on success.
Creates a new OCO order.
console.log(
await client.orderOco({
symbol: 'XLMETH',
side: 'SELL',
quantity: 100,
price: 0.0002,
stopPrice: 0.0001,
stopLimitPrice: 0.0001,
}),
)
Param | Type | Required | Description |
---|---|---|---|
symbol | String | true | |
listClientOrderId | String | false | A unique Id for the entire orderList |
side | String | true | BUY ,SELL |
quantity | Number | true | |
limitClientOrderId | String | false | A unique Id for the limit order |
price | Number | true | |
limitIcebergQty | Number | false | Used to make the LIMIT_MAKER leg an iceberg order. |
stopClientOrderId | String | false | A unique Id for the stop loss/stop loss limit leg |
stopPrice | Number | true | |
stopLimitPrice | Number | false | If provided, stopLimitTimeInForce is required. |
stopIcebergQty | Number | false | Used with STOP_LOSS_LIMIT leg to make an iceberg order. |
stopLimitTimeInForce | String | false | FOK , GTC , IOC |
newOrderRespType | String | false | Returns more complete info of the order. ACK , RESULT , or FULL |
recvWindow | Number | false | The value cannot be greater than 60000 |
Additional Info:
SELL
: Limit Price > Last Price > Stop PriceBUY
: Limit Price < Last Price < Stop PriceICEBERG
quantities however do not have to be the same{
"orderListId": 0,
"contingencyType": "OCO",
"listStatusType": "EXEC_STARTED",
"listOrderStatus": "EXECUTING",
"listClientOrderId": "JYVpp3F0f5CAG15DhtrqLp",
"transactionTime": 1514418413947,
"symbol": "XLMETH",
"orders": [
{
"symbol": "XLMETH",
"orderId": 1740797,
"clientOrderId": "1XZTVBTGS4K1e"
},
{
"symbol": "XLMETH",
"orderId": 1740798,
"clientOrderId": "1XZTVBTGS4K1f"
}
],
"orderReports": [
{
"symbol": "XLMETH",
"orderId": 1740797,
"orderListId": 0,
"clientOrderId": "1XZTVBTGS4K1e",
"transactTime": 1514418413947,
"price": "0.000000",
"origQty": "100",
"executedQty": "0.000000",
"cummulativeQuoteQty": "0.000000",
"status": "NEW",
"timeInForce": "GTC",
"type": "STOP_LOSS",
"side": "SELL",
"stopPrice": "0.0001"
},
{
"symbol": "XLMETH",
"orderId": 1740798,
"orderListId": 0,
"clientOrderId": "1XZTVBTGS4K1f",
"transactTime": 1514418413947,
"price": "0.0002",
"origQty": "100",
"executedQty": "0.000000",
"cummulativeQuoteQty": "0.000000",
"status": "NEW",
"timeInForce": "GTC",
"type": "LIMIT_MAKER",
"side": "SELL"
}
]
}
Check an order's status.
console.log(
await client.getOrder({
symbol: 'BNBETH',
orderId: 50167927,
}),
)
Param | Type | Required | Description |
---|---|---|---|
symbol | String | true | |
orderId | Number | true | Not required if origClientOrderId is used |
origClientOrderId | String | false | |
recvWindow | Number | false |
{
clientOrderId: 'NkQnNkdBV1RGjUALLhAzNy',
cummulativeQuoteQty: '0.16961580',
executedQty: '3.91000000',
icebergQty: '0.00000000',
isWorking: true,
orderId: 50167927,
origQty: '3.91000000',
price: '0.04338000',
side: 'SELL',
status: 'FILLED',
stopPrice: '0.00000000',
symbol: 'BNBETH',
time: 1547075007821,
timeInForce: 'GTC',
type: 'LIMIT',
updateTime: 1547075016737
}
Cancels an active order.
console.log(
await client.cancelOrder({
symbol: 'ETHBTC',
orderId: 1,
}),
)
Param | Type | Required | Description |
---|---|---|---|
symbol | String | true | |
orderId | Number | true | Not required if origClientOrderId is used |
origClientOrderId | String | false | |
newClientOrderId | String | false | Used to uniquely identify this cancel. Automatically generated by default. |
recvWindow | Number | false |
{
symbol: 'ETHBTC',
origClientOrderId: 'bnAoRHgI18gRD80FJmsfNP',
orderId: 1,
clientOrderId: 'RViSsQPTp1v3WmLYpeKT11'
}
Cancels all active orders on a symbol. This includes OCO orders.
console.log(
await client.cancelOpenOrders({
symbol: 'ETHBTC'
}),
)
Param | Type | Required |
---|---|---|
symbol | String | true |
[
{
symbol: 'ETHBTC',
origClientOrderId: 'bnAoRHgI18gRD80FJmsfNP',
orderId: 1,
clientOrderId: 'RViSsQPTp1v3WmLYpeKT11'
},
{
symbol: 'ETHBTC',
origClientOrderId: 'IDbzcGmfwSCKihxILK1snu',
orderId: 2,
clientOrderId: 'HKFcuWAm9euMgRuwVGR8CL'
}
]
Get all open orders on a symbol.
console.log(
await client.openOrders({
symbol: 'XLMBTC',
}),
)
Param | Type | Required |
---|---|---|
symbol | String | true |
recvWindow | Number | false |
;[
{
symbol: 'XLMBTC',
orderId: 11271740,
clientOrderId: 'ekHkROfW98gBN80LTfufQZ',
price: '0.00001081',
origQty: '1331.00000000',
executedQty: '0.00000000',
status: 'NEW',
timeInForce: 'GTC',
type: 'LIMIT',
side: 'BUY',
stopPrice: '0.00000000',
icebergQty: '0.00000000',
time: 1522682290485,
isWorking: true,
},
]
Get all account orders on a symbol; active, canceled, or filled.
console.log(
await client.allOrders({
symbol: 'ETHBTC',
}),
)
Param | Type | Required | Default | Description |
---|---|---|---|---|
symbol | String | true | ||
orderId | Number | false | If set, it will get orders >= that orderId. Otherwise most recent orders are returned. | |
limit | Number | false | 500 | Max 500 |
recvWindow | Number | false |
;[
{
symbol: 'ENGETH',
orderId: 191938,
clientOrderId: '1XZTVBTGS4K1e',
price: '0.00138000',
origQty: '1.00000000',
executedQty: '1.00000000',
status: 'FILLED',
timeInForce: 'GTC',
type: 'LIMIT',
side: 'SELL',
stopPrice: '0.00000000',
icebergQty: '0.00000000',
time: 1508611114735,
isWorking: true,
},
]
Retrieves all OCO based on provided optional parameters
console.log(
await client.allOrdersOCO({
timestamp: 1565245913483,
}),
)
Param | Type | Required | Default | Description |
---|---|---|---|---|
timestamp | Number | true | ||
startTime | Number | false | ||
endTime | Number | false | ||
limit | Integer | false | 500 | Max 1000 |
recvWindow | Number | false | The value cannot be greater than 60000 | |
formId | Number | false | If supplied, neither startTime or endTime can be provided |
;[
{
"orderListId": 29,
"contingencyType": "OCO",
"listStatusType": "EXEC_STARTED",
"listOrderStatus": "EXECUTING",
"listClientOrderId": "amEEAXryFzFwYF1FeRpUoZ",
"transactionTime": 1565245913483,
"symbol": "LTCBTC",
"orders": [
{
"symbol": "LTCBTC",
"orderId": 4,
"clientOrderId": "oD7aesZqjEGlZrbtRpy5zB"
},
{
"symbol": "LTCBTC",
"orderId": 5,
"clientOrderId": "Jr1h6xirOxgeJOUuYQS7V3"
}
]
},
{
"orderListId": 28,
"contingencyType": "OCO",
"listStatusType": "EXEC_STARTED",
"listOrderStatus": "EXECUTING",
"listClientOrderId": "hG7hFNxJV6cZy3Ze4AUT4d",
"transactionTime": 1565245913407,
"symbol": "LTCBTC",
"orders": [
{
"symbol": "LTCBTC",
"orderId": 2,
"clientOrderId": "j6lFOfbmFMRjTYA7rRJ0LP"
},
{
"symbol": "LTCBTC",
"orderId": 3,
"clientOrderId": "z0KCjOdditiLS5ekAFtK81"
}
]
}
]
Get current account information.
console.log(await client.accountInfo())
Param | Type | Required |
---|---|---|
recvWindow | Number | false |
{
makerCommission: 10,
takerCommission: 10,
buyerCommission: 0,
sellerCommission: 0,
canTrade: true,
canWithdraw: true,
canDeposit: true,
balances: [
{ asset: 'BTC', free: '0.00000000', locked: '0.00000000' },
{ asset: 'LTC', free: '0.00000000', locked: '0.00000000' },
]
}
Get trades for the current authenticated account and symbol.
console.log(
await client.myTrades({
symbol: 'ETHBTC',
}),
)
Param | Type | Required | Default | Description |
---|---|---|---|---|
symbol | String | true | ||
limit | Number | false | 500 | Max 500 |
fromId | Number | false | TradeId to fetch from. Default gets most recent trades. | |
recvWindow | Number | false |
;[
{
id: 9960,
orderId: 191939,
price: '0.00138000',
qty: '10.00000000',
commission: '0.00001380',
commissionAsset: 'ETH',
time: 1508611114735,
isBuyer: false,
isMaker: false,
isBestMatch: true,
},
]
Lookup symbol trades history.
console.log(await client.tradesHistory({ symbol: 'ETHBTC' }))
Param | Type | Required | Default | Description |
---|---|---|---|---|
symbol | String | true | ||
limit | Number | false | 500 | Max 500 |
fromId | Number | false | null | TradeId to fetch from. Default gets most recent trades. |
;[
{
id: 28457,
price: '4.00000100',
qty: '12.00000000',
time: 1499865549590,
isBuyerMaker: true,
isBestMatch: true,
},
]
Get the account deposit history.
console.log(await client.depositHistory())
Param | Type | Required | Description |
---|---|---|---|
asset | String | false | |
status | Number | false | 0 (0: pending, 1: success) |
startTime | Number | false | |
endTime | Number | false | |
recvWindow | Number | false |
{
"depositList": [
{
"insertTime": 1508198532000,
"amount": 0.04670582,
"asset": "ETH",
"status": 1
}
],
"success": true
}
Get the account withdraw history.
console.log(await client.withdrawHistory())
Param | Type | Required | Description |
---|---|---|---|
asset | String | false | |
status | Number | false | 0 (0: Email Sent, 1: Cancelled 2: Awaiting Approval, 3: Rejected, 4: Processing, 5: Failure, 6: Completed) |
startTime | Number | false | |
endTime | Number | false | |
recvWindow | Number | false |
{
"withdrawList": [
{
"amount": 1,
"address": "0x6915f16f8791d0a1cc2bf47c13a6b2a92000504b",
"asset": "ETH",
"applyTime": 1508198532000,
"status": 4
},
],
"success": true
}
Triggers the withdraw process (untested for now).
console.log(
await client.withdraw({
asset: 'ETH',
address: '0xfa97c22a03d8522988c709c24283c0918a59c795',
amount: 100,
}),
)
Param | Type | Required | Description |
---|---|---|---|
asset | String | true | |
address | String | true | |
amount | Number | true | |
name | String | false | Description of the address |
recvWindow | Number | false |
{
"msg": "success",
"success": true
}
Retrieve the account deposit address for a specific asset.
console.log(await client.depositAddress({ asset: 'NEO' }))
Param | Type | Required | Description |
---|---|---|---|
asset | String | true | The asset name |
{
address: 'AM6ytPW78KYxQCmU2pHYGcee7GypZ7Yhhc',
addressTag: '',
asset: 'NEO',
success: true,
}
Retrieve the account trade Fee per asset.
console.log(await client.tradeFee())
{
tradeFee: [{
symbol: 'BTC',
maker: 0.0001,
taker: 0.0001,
},
{
symbol: 'LTC',
maker: 0.0001,
taker: 0.0001,
}
...],
success: true,
}
Get information of coins (available for deposit and withdraw) for user.
console.log(await client.capitalConfigs())
[
{
'coin': 'CTR',
'depositAllEnable': false,
'free': '0.00000000',
'freeze': '0.00000000',
'ipoable': '0.00000000',
'ipoing': '0.00000000',
'isLegalMoney': false,
'locked': '0.00000000',
'name': 'Centra',
'networkList': [
{
'addressRegex': '^(0x)[0-9A-Fa-f]{40}$',
'coin': 'CTR',
'depositDesc': 'Delisted, Deposit Suspended',
'depositEnable': false,
'isDefault': true,
'memoRegex': '',
'minConfirm': 12,
'name': 'ERC20',
'network': 'ETH',
'resetAddressStatus': false,
'specialTips': '',
'unLockConfirm': 0,
'withdrawDesc': '',
'withdrawEnable': true,
'withdrawFee': '35.00000000',
'withdrawIntegerMultiple': '0.00000001',
'withdrawMax': '0.00000000',
'withdrawMin': '70.00000000'
}
],
'storage': '0.00000000',
'trading': false,
'withdrawAllEnable': true,
'withdrawing': '0.00000000'
}
]
Fetch deposit address with network.
console.log(await client.capitalDepositAddress({ coin: 'NEO' }))
Param | Type | Required | Description |
---|---|---|---|
coin | String | true | The coin name |
network | String | false | The network name |
{
address: 'AM6ytPW78KYxQCmU2pHYGcee7GypZ7Yhhc',
coin: 'NEO',
tag: '',
url: 'https://neoscan.io/address/AM6ytPW78KYxQCmU2pHYGcee7GypZ7Yhhc'
}
Repay loan for margin account.
console.log(await client.marginRepay({ asset: 'BTC', amount:'0.0001' }));
Param | Type | Required | Description |
---|---|---|---|
asset | String | true | The asset name |
amount | Number | true |
{
"tranId": 100000001 //transaction id
}
Check an order's status.
Name | Type | Mandatory | Description |
---|---|---|---|
symbol | STRING | YES | The pair name |
orderId | LONG | NO | |
origClientOrderId | STRING | NO | |
recvWindow | LONG | NO |
Either orderId or origClientOrderId must be sent.
console.log(
await client.futuresGetOrder({
symbol: 'BNBETH',
orderId: 50167927,
}),
)
{
"avgPrice": "0.00000",
"clientOrderId": "abc",
"cumQuote": "0",
"executedQty": "0",
"orderId": 1917641,
"origQty": "0.40",
"origType": "TRAILING_STOP_MARKET",
"price": "0",
"reduceOnly": false,
"side": "BUY",
"positionSide": "SHORT",
"status": "NEW",
"stopPrice": "9300", // please ignore when order type is TRAILING_STOP_MARKET
"closePosition": false, // if Close-All
"symbol": "BTCUSDT",
"time": 1579276756075, // order time
"timeInForce": "GTC",
"type": "TRAILING_STOP_MARKET",
"activatePrice": "9020", // activation price, only return with TRAILING_STOP_MARKET order
"priceRate": "0.3", // callback rate, only return with TRAILING_STOP_MARKET order
"updateTime": 1579276756075, // update time
"workingType": "CONTRACT_PRICE",
"priceProtect": false // if conditional order trigger is protected
}
Change user's initial leverage of specific symbol market.
Name | Type | Mandatory | Description |
---|---|---|---|
symbol | STRING | YES | The pair name |
leverage | INT | YES | target initial leverage: int from 1 to 125 |
recvWindow | LONG | NO |
console.log(
await client.futuresLeverage({
symbol: 'BTCUSDT',
leverage: 21,
}),
)
{
"leverage": 21,
"maxNotionalValue": "1000000",
"symbol": "BTCUSDT"
}
Get futures account balance
console.log(await client.futuresAccountBalance());
[
{
"accountAlias": "SgsR", // unique account code
"asset": "USDT", // asset name
"balance": "122607.35137903", // wallet balance
"crossWalletBalance": "23.72469206", // crossed wallet balance
"crossUnPnl": "0.00000000" // unrealized profit of crossed positions
"availableBalance": "23.72469206", // available balance
"maxWithdrawAmount": "23.72469206" // maximum amount for transfer out
}
]
Every websocket utility returns a function you can call to close the opened connection and avoid memory issues.
const clean = client.ws.depth('ETHBTC', depth => {
console.log(depth)
})
// After you're done
clean()
Live depth market data feed. The first parameter can either be a single symbol string or an array of symbols.
client.ws.depth('ETHBTC', depth => {
console.log(depth)
})
{
eventType: 'depthUpdate',
eventTime: 1508612956950,
symbol: 'ETHBTC',
firstUpdateId: 18331140,
finalUpdateId: 18331145,
bidDepth: [
{ price: '0.04896500', quantity: '0.00000000' },
{ price: '0.04891100', quantity: '15.00000000' },
{ price: '0.04891000', quantity: '0.00000000' } ],
askDepth: [
{ price: '0.04910600', quantity: '0.00000000' },
{ price: '0.04910700', quantity: '11.24900000' }
]
}
Top levels bids and asks, pushed every second. Valid levels are 5, 10, or 20. Accepts an array of objects for multiple depths.
client.ws.partialDepth({ symbol: 'ETHBTC', level: 10 }, depth => {
console.log(depth)
})
{
symbol: 'ETHBTC',
level: 10,
bids: [
{ price: '0.04896500', quantity: '0.00000000' },
{ price: '0.04891100', quantity: '15.00000000' },
{ price: '0.04891000', quantity: '0.00000000' }
],
asks: [
{ price: '0.04910600', quantity: '0.00000000' },
{ price: '0.04910700', quantity: '11.24900000' }
]
}
24hr Ticker statistics for a symbol pushed every second. Accepts an array of symbols.
client.ws.ticker('HSRETH', ticker => {
console.log(ticker)
})
{
eventType: '24hrTicker',
eventTime: 1514670820924,
symbol: 'HSRETH',
priceChange: '-0.00409700',
priceChangePercent: '-11.307',
weightedAvg: '0.03394946',
prevDayClose: '0.03623500',
curDayClose: '0.03213800',
closeTradeQuantity: '7.02000000',
bestBid: '0.03204200',
bestBidQnt: '78.00000000',
bestAsk: '0.03239800',
bestAskQnt: '7.00000000',
open: '0.03623500',
high: '0.03659900',
low: '0.03126000',
volume: '100605.15000000',
volumeQuote: '3415.49097353',
openTime: 1514584420922,
closeTime: 1514670820922,
firstTradeId: 344803,
lastTradeId: 351380,
totalTrades: 6578
}
Retrieves all the tickers.
client.ws.allTickers(tickers => {
console.log(tickers)
})
Live candle data feed for a given interval. You can pass either a symbol string or a symbol array.
client.ws.candles('ETHBTC', '1m', candle => {
console.log(candle)
})
{
eventType: 'kline',
eventTime: 1508613366276,
symbol: 'ETHBTC',
open: '0.04898000',
high: '0.04902700',
low: '0.04898000',
close: '0.04901900',
volume: '37.89600000',
trades: 30,
interval: '5m',
isFinal: false,
quoteVolume: '1.85728874',
buyVolume: '21.79900000',
quoteBuyVolume: '1.06838790'
}
Live trade data feed. Pass either a single symbol string or an array of symbols. The trade streams push raw trade information; each trade has a unique buyer and seller.
client.ws.trades(['ETHBTC', 'BNBBTC'], trade => {
console.log(trade)
})
{
eventType: 'trade',
eventTime: 1508614495052,
tradeTime: 1508614495050,
symbol: 'ETHBTC',
price: '0.04923600',
quantity: '3.43500000',
isBuyerMaker: true,
maker: true,
tradeId: 2148226,
buyerOrderId: 390876,
sellerOrderId: 390752
}
Live trade data feed. Pass either a single symbol string or an array of symbols. The aggregate trade streams push trade information that is aggregated for a single taker order.
client.ws.aggTrades(['ETHBTC', 'BNBBTC'], trade => {
console.log(trade)
})
{
eventType: 'aggTrade',
eventTime: 1508614495052,
aggId: 2148226,
price: '0.04923600',
quantity: '3.43500000',
firstId: 37856,
lastId: 37904,
timestamp: 1508614495050,
symbol: 'ETHBTC',
isBuyerMaker: false,
wasBestPrice: true
}
Live user messages data feed.
Requires authentication
const clean = await client.ws.user(msg => {
console.log(msg)
})
There is also two equivalent functions to query either the margin or futures wallet:
client.ws.marginUser()
client.ws.futuresUser()
Note that these methods all return a promise which will resolve the clean
callback.
{
eventType: 'account',
eventTime: 1508614885818,
balances: {
'123': { available: '0.00000000', locked: '0.00000000' },
'456': { available: '0.00000000', locked: '0.00000000' },
BTC: { available: '0.00000000', locked: '0.00000000' },
}
}
An utility error code map is also being exported by the package in order for you to make readable conditionals upon specific errors that could occur while using the API.
import Binance, { ErrorCodes } from 'binance-api-node'
console.log(ErrorCodes.INVALID_ORDER_TYPE) // -1116
FAQs
A node API wrapper for Binance
The npm package binance-api-node receives a total of 2,908 weekly downloads. As such, binance-api-node popularity was classified as popular.
We found that binance-api-node demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.