Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

binance-api-node

Package Overview
Dependencies
Maintainers
1
Versions
180
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

binance-api-node - npm Package Compare versions

Comparing version 0.10.17 to 0.10.18

60

dist/http-client.js

@@ -28,2 +28,7 @@ "use strict";

};
var info = {
spot: {},
futures: {}
};
/**

@@ -33,3 +38,2 @@ * Build query string for uri encoded url based on json object

var makeQueryString = function makeQueryString(q) {

@@ -41,2 +45,29 @@ return q ? "?".concat(Object.keys(q).map(function (k) {

/**
* Get API limits info from headers
*/
var headersMapping = {
'x-mbx-used-weight-1m': 'usedWeigh1m',
'x-mbx-order-count-10s': 'orderCount10s',
'x-mbx-order-count-1m': 'orderCount1m',
'x-mbx-order-count-1h': 'orderCount1h',
'x-response-time': 'responseTime'
};
var responseHandler = function responseHandler(res) {
if (!res.headers || !res.url) {
return;
}
var marketName = res.url.includes(FUTURES) ? 'futures' : 'spot';
Object.keys(headersMapping).forEach(function (key) {
var outKey = headersMapping[key];
if (res.headers.has(key)) {
info[marketName][outKey] = res.headers.get(key);
}
});
};
/**
* Finalize API response

@@ -48,3 +79,5 @@ */

return call.then(function (res) {
// If response is ok, we can safely assume it is valid JSON
// Get API limits info from headers
responseHandler(res); // If response is ok, we can safely assume it is valid JSON
if (res.ok) {

@@ -304,2 +337,5 @@ return res.json();

return {
getInfo: function getInfo() {
return info;
},
ping: function ping() {

@@ -535,2 +571,5 @@ return pubCall('/api/v3/ping').then(function () {

},
futuresAllOrders: function futuresAllOrders(payload) {
return privCall('/fapi/v1/allOrders', payload);
},
futuresPositionRisk: function futuresPositionRisk(payload) {

@@ -542,4 +581,7 @@ return privCall('/fapi/v2/positionRisk', payload);

},
futuresUserTrades: function futuresUserTrades(payload) {
return privCall('/fapi/v1/userTrades', payload);
},
futuresPositionMode: function futuresPositionMode(payload) {
return privCall('/fapi/v1/positionSide/dual', payload, 'GET');
return privCall('/fapi/v1/positionSide/dual', payload);
},

@@ -551,2 +593,14 @@ futuresPositionModeChange: function futuresPositionModeChange(payload) {

return privCall('/fapi/v1/leverage', payload, 'POST');
},
futuresMarginType: function futuresMarginType(payload) {
return privCall('/fapi/v1/marginType', payload, 'POST');
},
futuresPositionMargin: function futuresPositionMargin(payload) {
return privCall('/fapi/v1/positionMargin', payload, 'POST');
},
futuresMarginHistory: function futuresMarginHistory(payload) {
return privCall('/fapi/v1/positionMargin/history', payload);
},
futuresIncome: function futuresIncome(payload) {
return privCall('/fapi/v1/income', payload);
}

@@ -553,0 +607,0 @@ };

422

dist/websocket.js

@@ -45,29 +45,45 @@ "use strict";

var depthTransform = function depthTransform(m) {
return {
eventType: m.e,
eventTime: m.E,
symbol: m.s,
firstUpdateId: m.U,
finalUpdateId: m.u,
bidDepth: m.b.map(function (b) {
return (0, _lodash.default)(['price', 'quantity'], b);
}),
askDepth: m.a.map(function (a) {
return (0, _lodash.default)(['price', 'quantity'], a);
})
};
};
var futuresDepthTransform = function futuresDepthTransform(m) {
return {
eventType: m.e,
eventTime: m.E,
transactionTime: m.T,
symbol: m.s,
firstUpdateId: m.U,
finalUpdateId: m.u,
prevFinalUpdateId: m.pu,
bidDepth: m.b.map(function (b) {
return (0, _lodash.default)(['price', 'quantity'], b);
}),
askDepth: m.a.map(function (a) {
return (0, _lodash.default)(['price', 'quantity'], a);
})
};
};
var depth = function depth(payload, cb) {
var transform = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
var variator = arguments.length > 3 ? arguments[3] : undefined;
var cache = (Array.isArray(payload) ? payload : [payload]).map(function (symbol) {
var w = (0, _openWebsocket.default)("".concat(BASE, "/").concat(symbol.toLowerCase(), "@depth"));
var w = (0, _openWebsocket.default)("".concat(variator === 'futures' ? FUTURES : BASE, "/").concat(symbol.toLowerCase(), "@depth"));
w.onmessage = function (msg) {
var _JSON$parse = JSON.parse(msg.data),
eventType = _JSON$parse.e,
eventTime = _JSON$parse.E,
symbol = _JSON$parse.s,
firstUpdateId = _JSON$parse.U,
finalUpdateId = _JSON$parse.u,
bidDepth = _JSON$parse.b,
askDepth = _JSON$parse.a;
cb({
eventType: eventType,
eventTime: eventTime,
symbol: symbol,
firstUpdateId: firstUpdateId,
finalUpdateId: finalUpdateId,
bidDepth: bidDepth.map(function (b) {
return (0, _lodash.default)(['price', 'quantity'], b);
}),
askDepth: askDepth.map(function (a) {
return (0, _lodash.default)(['price', 'quantity'], a);
})
});
var obj = JSON.parse(msg.data);
cb(transform ? variator === 'futures' ? futuresDepthTransform(obj) : depthTransform(obj) : obj);
};

@@ -86,25 +102,46 @@

var partialDepthTransform = function partialDepthTransform(symbol, level, m) {
return {
symbol: symbol,
level: level,
lastUpdateId: m.lastUpdateId,
bids: m.bids.map(function (b) {
return (0, _lodash.default)(['price', 'quantity'], b);
}),
asks: m.asks.map(function (a) {
return (0, _lodash.default)(['price', 'quantity'], a);
})
};
};
var futuresPartDepthTransform = function futuresPartDepthTransform(level, m) {
return {
level: level,
eventType: m.e,
eventTime: m.E,
transactionTime: m.T,
symbol: m.s,
firstUpdateId: m.U,
finalUpdateId: m.u,
prevFinalUpdateId: m.pu,
bidDepth: m.b.map(function (b) {
return (0, _lodash.default)(['price', 'quantity'], b);
}),
askDepth: m.a.map(function (a) {
return (0, _lodash.default)(['price', 'quantity'], a);
})
};
};
var partialDepth = function partialDepth(payload, cb) {
var transform = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
var variator = arguments.length > 3 ? arguments[3] : undefined;
var cache = (Array.isArray(payload) ? payload : [payload]).map(function (_ref) {
var symbol = _ref.symbol,
level = _ref.level;
var w = (0, _openWebsocket.default)("".concat(BASE, "/").concat(symbol.toLowerCase(), "@depth").concat(level));
var w = (0, _openWebsocket.default)("".concat(variator === 'futures' ? FUTURES : BASE, "/").concat(symbol.toLowerCase(), "@depth").concat(level));
w.onmessage = function (msg) {
var _JSON$parse2 = JSON.parse(msg.data),
lastUpdateId = _JSON$parse2.lastUpdateId,
bids = _JSON$parse2.bids,
asks = _JSON$parse2.asks;
cb({
symbol: symbol,
level: level,
lastUpdateId: lastUpdateId,
bids: bids.map(function (b) {
return (0, _lodash.default)(['price', 'quantity'], b);
}),
asks: asks.map(function (a) {
return (0, _lodash.default)(['price', 'quantity'], a);
})
});
var obj = JSON.parse(msg.data);
cb(transform ? variator === 'futures' ? futuresPartDepthTransform(level, obj) : partialDepthTransform(symbol, level, obj) : obj);
};

@@ -124,2 +161,5 @@

var candles = function candles(payload, interval, cb) {
var transform = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
var variator = arguments.length > 4 ? arguments[4] : undefined;
if (!interval || !cb) {

@@ -130,11 +170,10 @@ throw new Error('Please pass a symbol, interval and callback.');

var cache = (Array.isArray(payload) ? payload : [payload]).map(function (symbol) {
var w = (0, _openWebsocket.default)("".concat(BASE, "/").concat(symbol.toLowerCase(), "@kline_").concat(interval));
var w = (0, _openWebsocket.default)("".concat(variator === 'futures' ? FUTURES : BASE, "/").concat(symbol.toLowerCase(), "@kline_").concat(interval));
w.onmessage = function (msg) {
var _JSON$parse3 = JSON.parse(msg.data),
eventType = _JSON$parse3.e,
eventTime = _JSON$parse3.E,
symbol = _JSON$parse3.s,
tick = _JSON$parse3.k;
var obj = JSON.parse(msg.data);
var eventType = obj.e,
eventTime = obj.E,
symbol = obj.s,
tick = obj.k;
var startTime = tick.t,

@@ -155,3 +194,3 @@ closeTime = tick.T,

quoteBuyVolume = tick.Q;
cb({
cb(transform ? {
eventType: eventType,

@@ -175,3 +214,3 @@ eventTime: eventTime,

quoteBuyVolume: quoteBuyVolume
});
} : obj);
};

@@ -218,8 +257,34 @@

var futuresTickerTransform = function futuresTickerTransform(m) {
return {
eventType: m.e,
eventTime: m.E,
symbol: m.s,
priceChange: m.p,
priceChangePercent: m.P,
weightedAvg: m.w,
curDayClose: m.c,
closeTradeQuantity: m.Q,
open: m.o,
high: m.h,
low: m.l,
volume: m.v,
volumeQuote: m.q,
openTime: m.O,
closeTime: m.C,
firstTradeId: m.F,
lastTradeId: m.L,
totalTrades: m.n
};
};
var ticker = function ticker(payload, cb) {
var transform = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
var variator = arguments.length > 3 ? arguments[3] : undefined;
var cache = (Array.isArray(payload) ? payload : [payload]).map(function (symbol) {
var w = (0, _openWebsocket.default)("".concat(BASE, "/").concat(symbol.toLowerCase(), "@ticker"));
var w = (0, _openWebsocket.default)("".concat(variator === 'futures' ? FUTURES : BASE, "/").concat(symbol.toLowerCase(), "@ticker"));
w.onmessage = function (msg) {
cb(tickerTransform(JSON.parse(msg.data)));
var obj = JSON.parse(msg.data);
cb(transform ? variator === 'futures' ? futuresTickerTransform(obj) : tickerTransform(obj) : obj);
};

@@ -239,9 +304,13 @@

var allTickers = function allTickers(cb) {
var w = new _openWebsocket.default("".concat(BASE, "/!ticker@arr"));
var transform = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
var variator = arguments.length > 2 ? arguments[2] : undefined;
var w = new _openWebsocket.default("".concat(variator === 'futures' ? FUTURES : BASE, "/!ticker@arr"));
w.onmessage = function (msg) {
var arr = JSON.parse(msg.data);
cb(arr.map(function (m) {
cb(transform ? variator === 'futures' ? arr.map(function (m) {
return futuresTickerTransform(m);
}) : arr.map(function (m) {
return tickerTransform(m);
}));
}) : arr);
};

@@ -256,33 +325,42 @@

var aggTradesInternal = function aggTradesInternal(payload, cb) {
var aggTradesTransform = function aggTradesTransform(m) {
return {
eventType: m.e,
eventTime: m.E,
timestamp: m.T,
symbol: m.s,
price: m.p,
quantity: m.q,
isBuyerMaker: m.m,
wasBestPrice: m.M,
aggId: m.a,
firstId: m.f,
lastId: m.l
};
};
var futuresAggTradesTransform = function futuresAggTradesTransform(m) {
return {
eventType: m.e,
eventTime: m.E,
symbol: m.s,
aggId: m.a,
price: m.p,
quantity: m.q,
firstId: m.f,
lastId: m.l,
timestamp: m.T,
isBuyerMaker: m.m
};
};
var aggTrades = function aggTrades(payload, cb) {
var transform = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
var variator = arguments.length > 3 ? arguments[3] : undefined;
var cache = (Array.isArray(payload) ? payload : [payload]).map(function (symbol) {
var w = (0, _openWebsocket.default)("".concat(BASE, "/").concat(symbol.toLowerCase(), "@aggTrade"));
var w = (0, _openWebsocket.default)("".concat(variator === 'futures' ? FUTURES : BASE, "/").concat(symbol.toLowerCase(), "@aggTrade"));
w.onmessage = function (msg) {
var _JSON$parse4 = JSON.parse(msg.data),
eventType = _JSON$parse4.e,
eventTime = _JSON$parse4.E,
timestamp = _JSON$parse4.T,
symbol = _JSON$parse4.s,
price = _JSON$parse4.p,
quantity = _JSON$parse4.q,
isBuyerMaker = _JSON$parse4.m,
wasBestPrice = _JSON$parse4.M,
aggId = _JSON$parse4.a,
firstId = _JSON$parse4.f,
lastId = _JSON$parse4.l;
cb({
eventType: eventType,
eventTime: eventTime,
aggId: aggId,
price: price,
quantity: quantity,
firstId: firstId,
lastId: lastId,
timestamp: timestamp,
symbol: symbol,
isBuyerMaker: isBuyerMaker,
wasBestPrice: wasBestPrice
});
var obj = JSON.parse(msg.data);
cb(transform ? variator === 'futures' ? futuresAggTradesTransform(obj) : aggTradesTransform(obj) : obj);
};

@@ -301,3 +379,20 @@

var tradesInternal = function tradesInternal(payload, cb) {
var tradesTransform = function tradesTransform(m) {
return {
eventType: m.e,
eventTime: m.E,
tradeTime: m.T,
symbol: m.s,
price: m.p,
quantity: m.q,
isBuyerMaker: m.m,
maker: m.M,
tradeId: m.t,
buyerOrderId: m.b,
sellerOrderId: m.a
};
};
var trades = function trades(payload, cb) {
var transform = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
var cache = (Array.isArray(payload) ? payload : [payload]).map(function (symbol) {

@@ -307,28 +402,4 @@ var w = (0, _openWebsocket.default)("".concat(BASE, "/").concat(symbol.toLowerCase(), "@trade"));

w.onmessage = function (msg) {
var _JSON$parse5 = JSON.parse(msg.data),
eventType = _JSON$parse5.e,
eventTime = _JSON$parse5.E,
tradeTime = _JSON$parse5.T,
symbol = _JSON$parse5.s,
price = _JSON$parse5.p,
quantity = _JSON$parse5.q,
isBuyerMaker = _JSON$parse5.m,
maker = _JSON$parse5.M,
tradeId = _JSON$parse5.t,
sellerOrderId = _JSON$parse5.a,
buyerOrderId = _JSON$parse5.b;
cb({
eventType: eventType,
eventTime: eventTime,
tradeTime: tradeTime,
symbol: symbol,
price: price,
quantity: quantity,
isBuyerMaker: isBuyerMaker,
maker: maker,
tradeId: tradeId,
buyerOrderId: buyerOrderId,
sellerOrderId: sellerOrderId
});
var obj = JSON.parse(msg.data);
cb(transform ? tradesTransform(obj) : obj);
};

@@ -347,10 +418,2 @@

var aggTrades = function aggTrades(payload, cb) {
return aggTradesInternal(payload, cb);
};
var trades = function trades(payload, cb) {
return tradesInternal(payload, cb);
};
var userTransforms = {

@@ -443,11 +506,106 @@ // https://github.com/binance-exchange/binance-official-api-docs/blob/master/user-data-stream.md#balance-update

};
var futuresUserTransforms = {
// https://binance-docs.github.io/apidocs/futures/en/#event-margin-call
MARGIN_CALL: function MARGIN_CALL(m) {
return {
eventTime: m.E,
crossWalletBalance: m.cw,
eventType: 'MARGIN_CALL',
positions: m.p.reduce(function (out, cur) {
out[cur.a] = {
symbol: cur.s,
positionSide: cur.ps,
positionAmount: cur.pa,
marginType: cur.mt,
isolatedWallet: cur.iw,
markPrice: cur.mp,
unrealizedPnL: cur.up,
maintenanceMarginRequired: cur.mm
};
return out;
}, {})
};
},
// https://binance-docs.github.io/apidocs/futures/en/#event-balance-and-position-update
ACCOUNT_UPDATE: function ACCOUNT_UPDATE(m) {
return {
eventTime: m.E,
transactionTime: m.T,
eventType: 'ACCOUNT_UPDATE',
eventReasonType: m.a.m,
balances: m.a.B.reduce(function (out, cur) {
out[cur.a] = {
asset: cur.a,
walletBalance: cur.wb,
crossWalletBalance: cur.cw
};
return out;
}, {}),
positions: m.a.P.reduce(function (out, cur) {
out[cur.a] = {
symbol: cur.s,
positionAmount: cur.pa,
entryPrice: cur.ep,
accumulatedRealized: cur.cr,
unrealizedPnL: cur.up,
marginType: cur.mt,
isolatedWallet: cur.iw,
positionSide: cur.ps
};
return out;
}, {})
};
},
// https://binance-docs.github.io/apidocs/futures/en/#event-order-update
ORDER_TRADE_UPDATE: function ORDER_TRADE_UPDATE(m) {
return {
eventType: 'ORDER_TRADE_UPDATE',
eventTime: m.E,
transactionTime: m.T,
symbol: m.o.s,
clientOrderId: m.o.c,
side: m.o.S,
orderType: m.o.o,
timeInForce: m.o.f,
quantity: m.o.q,
price: m.o.p,
averagePrice: m.o.ap,
stopPrice: m.o.sp,
executionType: m.o.x,
orderStatus: m.o.X,
orderId: m.o.i,
lastTradeQuantity: m.o.l,
totalTradeQuantity: m.o.z,
priceLastTrade: m.o.L,
commissionAsset: m.o.N,
commission: m.o.n,
orderTime: m.o.T,
tradeId: m.o.t,
bidsNotional: m.o.b,
asksNotional: m.o.a,
isMaker: m.o.m,
isReduceOnly: m.o.R,
workingType: m.o.wt,
originalOrderType: m.o.ot,
positionSide: m.o.ps,
closePosition: m.o.cp,
activationPrice: m.o.AP,
callbackRate: m.o.cr,
realizedProfit: m.o.rp
};
}
};
var userEventHandler = function userEventHandler(cb) {
var transform = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
var variator = arguments.length > 2 ? arguments[2] : undefined;
return function (msg) {
var _JSON$parse6 = JSON.parse(msg.data),
type = _JSON$parse6.e,
rest = _objectWithoutProperties(_JSON$parse6, ["e"]);
var _JSON$parse = JSON.parse(msg.data),
type = _JSON$parse.e,
rest = _objectWithoutProperties(_JSON$parse, ["e"]);
cb(userTransforms[type] ? userTransforms[type](rest) : _objectSpread({
cb(variator === 'futures' ? transform && futuresUserTransforms[type] ? futuresUserTransforms[type](rest) : _objectSpread({
type: type
}, rest) : transform && userTransforms[type] ? userTransforms[type](rest) : _objectSpread({
type: type
}, rest));

@@ -481,3 +639,3 @@ };

var user = function user(opts, variator) {
return function (cb) {
return function (cb, transform) {
var _getStreamMethods = getStreamMethods(opts, variator),

@@ -535,3 +693,3 @@ _getStreamMethods2 = _slicedToArray(_getStreamMethods, 3),

w.onmessage = function (msg) {
return userEventHandler(cb)(msg);
return userEventHandler(cb, transform, variator)(msg);
};

@@ -573,2 +731,20 @@

marginUser: user(opts, 'margin'),
futuresDepth: function futuresDepth(payload, cb, transform) {
return depth(payload, cb, transform, 'futures');
},
futuresPartialDepth: function futuresPartialDepth(payload, cb, transform) {
return partialDepth(payload, cb, transform, 'futures');
},
futuresCandles: function futuresCandles(payload, interval, cb, transform) {
return candles(payload, interval, cb, transform, 'futures');
},
futuresTicker: function futuresTicker(payload, cb, transform) {
return ticker(payload, cb, transform, 'futures');
},
futuresAllTickers: function futuresAllTickers(cb, transform) {
return allTickers(cb, transform, 'futures');
},
futuresAggTrades: function futuresAggTrades(payload, cb, transform) {
return aggTrades(payload, cb, transform, 'futures');
},
futuresUser: user(opts, 'futures')

@@ -575,0 +751,0 @@ };

{
"name": "binance-api-node",
"version": "0.10.17",
"version": "0.10.18",
"description": "A node API wrapper for Binance",

@@ -5,0 +5,0 @@ "main": "dist",

@@ -45,3 +45,2 @@ # binance-api-node [![build](https://img.shields.io/travis/Ashlar/binance-api-node/master.svg?style=flat-square)](https://travis-ci.org/Ashlar/binance-api-node) [![cover](https://img.shields.io/coveralls/github/Ashlar/binance-api-node/master?style=flat-square)](https://coveralls.io/github/Ashlar/binance-api-node?branch=master) [![bnb](https://img.shields.io/badge/binance-winner-yellow.svg?style=flat-square)](https://github.com/binance-exchange/binance-api-node)

### Table of Contents
- [Public REST Endpoints](#public-rest-endpoints)

@@ -97,4 +96,10 @@ - [ping](#ping)

- [futuresGetOrder](#futuresGetOrder)
- [futuresAllOrders](#futuresAllOrders)
- [futuresAccountBalance](#futuresAccountBalance)
- [futuresUserTrades](#futuresUserTrades)
- [futuresLeverage](#futuresLeverage)
- [futuresMarginType](#futuresMarginType)
- [futuresPositionMargin](#futuresPositionMargin)
- [futuresMarginHistory](#futuresMarginHistory)
- [futuresIncome](#futuresIncome)
- [Websockets](#websockets)

@@ -109,2 +114,12 @@ - [depth](#depth)

- [user](#user)
- [Futures Websockets](#futuresWebsockets)
- [futuresDepth](#futuresDepth)
- [futuresPartialDepth](#futuresPartialdepth)
- [futuresTicker](#futuresTicker)
- [futuresAllTickers](#futuresAlltickers)
- [futuresCandles](#futuresCandles)
- [futuresAggTrades](#futuresAggtrades)
- [futuresUser](#futuresUser)
- [Common](#common)
- [getInfo](#getInfo)
- [ErrorCodes](#errorcodes)

@@ -1690,3 +1705,2 @@

- These orders will not be found

@@ -1706,3 +1720,3 @@ - order status is CANCELED or EXPIRED, <b>AND</b>

Either orderId or origClientOrderId must be sent.
Either <b>orderId</b> or <b>origClientOrderId</b> must be sent.

@@ -1714,3 +1728,3 @@ ```js

orderId: 50167927,
}),
})
)

@@ -1751,3 +1765,68 @@ ```

#### futuresAllOrders
Get all account orders; active, canceled, or filled.
- These orders will not be found
- order status is CANCELED or EXPIRED, <b>AND</b>
- order has NO filled trade, <b>AND</b>
- created time + 7 days < current time
| Name | Type | Mandatory | Description |
| ----------------- | ------ | -------- | ---------------------- |
| symbol | STRING | YES | The pair name |
| orderId | LONG | NO | |
| startTime | LONG | NO | |
| endTime | LONG | NO | |
| limit | INT | NO | Default 500; max 1000. |
| recvWindow | LONG | NO | |
If <b>orderId</b> is set, it will get orders >= that <b>orderId</b>. Otherwise most recent orders are returned.
```js
console.log(
await client.futuresAllOrders({
symbol: 'BNBETH',
orderId: 50167927,
startTime: 1579276756075,
limit: 700,
})
)
```
<details>
<summary>Output</summary>
```js
[
{
"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
}
]
```
</details>
#### futuresLeverage

@@ -1769,3 +1848,3 @@

leverage: 21,
}),
})
)

@@ -1786,2 +1865,173 @@ ```

#### futuresMarginType
Change margin type.
| Name | Type | Mandatory | Description |
| ----------------- | ------ | -------- | ----------------- |
| symbol | STRING | YES | The pair name |
| marginType | ENUM | YES | ISOLATED, CROSSED |
| recvWindow | LONG | NO | |
```js
console.log(
await client.futuresMarginType({
symbol: 'BTCUSDT',
marginType: 'ISOLATED',
})
)
```
<details>
<summary>Output</summary>
```js
{
"code": 200,
"msg": "success"
}
```
</details>
#### futuresPositionMargin
Modify isolated position margin.
| Name | Type | Mandatory | Description |
| ----------------- | ------- | -------- | ------------------------------------------------- |
| symbol | STRING | YES | The pair name |
| positionSide | ENUM | NO | Default BOTH for One-way Mode; <br>LONG or SHORT for Hedge Mode. <br>It must be sent with Hedge Mode. |
| amount | DECIMAL | YES | |
| type | INT | YES | 1: Add position margin,2: Reduce position margin |
| recvWindow | LONG | NO | |
Only for isolated symbol.
```js
console.log(
await client.futuresPositionMargin({
symbol: 'BTCUSDT',
amount: 100,
type: 1,
})
)
```
<details>
<summary>Output</summary>
```js
{
"amount": 100.0,
"code": 200,
"msg": "Successfully modify position margin.",
"type": 1
}
```
</details>
#### futuresMarginHistory
Get position margin change history.
| Name | Type | Mandatory | Description |
| ----------------- | ------ | -------- | ------------------------------------------------- |
| symbol | STRING | YES | The pair name |
| type | INT | NO | 1: Add position margin,2: Reduce position margin |
| startTime | LONG | NO | |
| endTime | LONG | NO | |
| limit | INT | NO | Default 500; |
| recvWindow | LONG | NO | |
```js
console.log(
await client.futuresMarginHistory({
symbol: 'BTCUSDT',
type: 1,
startTime: 1579276756075,
limit: 700,
})
)
```
<details>
<summary>Output</summary>
```js
[
{
"amount": "23.36332311",
"asset": "USDT",
"symbol": "BTCUSDT",
"time": 1578047897183,
"type": 1,
"positionSide": "BOTH"
},
{
"amount": "100",
"asset": "USDT",
"symbol": "BTCUSDT",
"time": 1578047900425,
"type": 1,
"positionSide": "LONG"
}
]
```
</details>
#### futuresIncome
Get income history.
| Name | Type | Mandatory | Description |
| ----------------- | ------ | -------- | ------------------------------------------------- |
| symbol | STRING | NO | The pair name |
| incomeType | STRING | NO | "TRANSFER","WELCOME_BONUS", "REALIZED_PNL",<br>"FUNDING_FEE", "COMMISSION", and "INSURANCE_CLEAR" |
| startTime | LONG | NO | Timestamp in ms to get funding from INCLUSIVE. |
| endTime | LONG | NO | Timestamp in ms to get funding until INCLUSIVE. |
| limit | INT | NO | Default 100; max 1000 |
| recvWindow | LONG | NO | |
- If incomeType is not sent, all kinds of flow will be returned
- "trandId" is unique in the same incomeType for a user
```js
console.log(
await client.futuresIncome({
symbol: 'BTCUSDT',
startTime: 1579276756075,
limit: 700,
})
)
```
<details>
<summary>Output</summary>
```js
[
{
"symbol": "", // trade symbol, if existing
"incomeType": "TRANSFER", // income type
"income": "-0.37500000", // income amount
"asset": "USDT", // income asset
"info":"TRANSFER", // extra information
"time": 1570608000000,
"tranId":"9689322392", // transaction id
"tradeId":"" // trade id, if existing
},
{
"symbol": "BTCUSDT",
"incomeType": "COMMISSION",
"income": "-0.01000000",
"asset": "USDT",
"info":"COMMISSION",
"time": 1570636800000,
"tranId":"9689322392",
"tradeId":"2059192"
}
]
```
</details>
#### futuresAccountBalance

@@ -1814,2 +2064,49 @@

#### futuresUserTrades
Get trades for a specific account and symbol.
```js
console.log(
await client.futuresUserTrades({
symbol: 'ETHBTC',
}),
)
```
| Param | Type | Mandatory | Description |
| ---------- | ------ | --------- | -------------------------------------------------------- |
| symbol | STRING | YES | |
| startTime | LONG | NO | |
| endTime | LONG | NO | |
| limit | INT | NO | Default 500; max 1000. |
| fromId | LONG | NO | Trade id to fetch from. Default gets most recent trades. |
| recvWindow | LONG | NO | |
<details>
<summary>Output</summary>
```js
[
{
"buyer": false,
"commission": "-0.07819010",
"commissionAsset": "USDT",
"id": 698759,
"maker": false,
"orderId": 25851813,
"price": "7819.01",
"qty": "0.002",
"quoteQty": "15.63802",
"realizedPnl": "-0.91539999",
"side": "SELL",
"positionSide": "SHORT",
"symbol": "BTCUSDT",
"time": 1569514978020
}
]
```
</details>
### WebSockets

@@ -2057,10 +2354,9 @@

There is also two equivalent functions to query either the margin or futures wallet:
There is also equivalent function to query the margin wallet:
```js
client.ws.marginUser()
client.ws.futuresUser()
```
Note that these methods all return a promise which will resolve the `clean` callback.
Note that this method return a promise which will resolve the `clean` callback.

@@ -2084,2 +2380,318 @@ <details>

### Futures WebSockets
Every websocket utility returns a function you can call to close the opened
connection and avoid memory issues.
```js
const clean = client.ws.futuresDepth('ETHBTC', depth => {
console.log(depth)
})
// After you're done
clean()
```
Each websocket utility supports the ability to get a clean callback without data transformation, for this, pass the third attribute FALSE.
```js
const clean = client.ws.futuresDepth('ETHBTC', depth => {
console.log(depth)
}, false)
```
<details>
<summary>Output</summary>
```js
{
"e": "depthUpdate", // Event type
"E": 123456789, // Event time
"T": 123456788, // transaction time
"s": "BTCUSDT", // Symbol
"U": 157, // First update ID in event
"u": 160, // Final update ID in event
"pu": 149, // Final update Id in last stream(ie `u` in last stream)
"b": [ // Bids to be updated
[
"0.0024", // Price level to be updated
"10" // Quantity
]
],
"a": [ // Asks to be updated
[
"0.0026", // Price level to be updated
"100" // Quantity
]
]
}
```
</details>
#### futuresDepth
Live futuresDepth market data feed. The first parameter can either
be a single symbol string or an array of symbols.
```js
client.ws.futuresDepth('ETHBTC', depth => {
console.log(depth)
})
```
<details>
<summary>Output</summary>
```js
{
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' }
]
}
```
</details>
#### futuresPartialDepth
Top levels bids and asks, pushed every second. Valid levels are 5, 10, or 20.
Accepts an array of objects for multiple depths.
```js
client.ws.futuresPartialDepth({ symbol: 'ETHBTC', level: 10 }, depth => {
console.log(depth)
})
```
<details>
<summary>Output</summary>
```js
{
eventType: 'depthUpdate',
eventTime: 1508612956950,
symbol: 'ETHBTC',
level: 10,
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' }
]
}
```
</details>
#### futuresTicker
24hr Ticker statistics for a symbol pushed every 500ms. Accepts an array of symbols.
```js
client.ws.futuresTicker('HSRETH', ticker => {
console.log(ticker)
})
```
<details>
<summary>Output</summary>
```js
{
eventType: '24hrTicker',
eventTime: 123456789,
symbol: 'BTCUSDT',
priceChange: '0.0015',
priceChangePercent: '250.00',
weightedAvg: '0.0018',
curDayClose: '0.0025',
closeTradeQuantity: '10',
open: '0.0010',
high: '0.0025',
low: '0.0010',
volume: '10000',
volumeQuote: '18',
openTime: 0,
closeTime: 86400000,
firstTradeId: 0,
lastTradeId: 18150,
totalTrades: 18151,
}
```
</details>
#### futuresAllTickers
Retrieves all the tickers.
```js
client.ws.futuresAllTickers(tickers => {
console.log(tickers)
})
```
#### futuresCandles
Live candle data feed for a given interval. You can pass either a symbol string
or a symbol array.
```js
client.ws.futuresCandles('ETHBTC', '1m', candle => {
console.log(candle)
})
```
<details>
<summary>Output</summary>
```js
{
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'
}
```
</details>
#### futuresAggTrades
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 every 100 milliseconds.
```js
client.ws.futuresAggTrades(['ETHBTC', 'BNBBTC'], trade => {
console.log(trade)
})
```
<details>
<summary>Output</summary>
```js
{
eventType: 'aggTrade',
eventTime: 1508614495052,
aggId: 2148226,
price: '0.04923600',
quantity: '3.43500000',
firstId: 37856,
lastId: 37904,
timestamp: 1508614495050,
symbol: 'ETHBTC',
isBuyerMaker: false,
}
```
</details>
#### futuresUser
Live user messages data feed.
**Requires authentication**
```js
const futuresUser = await client.ws.futuresUser(msg => {
console.log(msg)
})
```
<details>
<summary>Output</summary>
```js
{
eventTime: 1564745798939,
transactionTime: 1564745798938,
eventType: 'ACCOUNT_UPDATE',
eventReasonType: 'ORDER',
balances: [
{
asset:'USDT',
walletBalance:'122624.12345678',
crossWalletBalance:'100.12345678'
},
{
asset:'BNB',
walletBalance:'1.00000000',
crossWalletBalance:'0.00000000'
}
],
positions: [
{
symbol:'BTCUSDT',
positionAmount:'0',
entryPrice:'0.00000',
accumulatedRealized:'200',
unrealizedPnL:'0',
marginType:'isolated',
isolatedWallet:'0.00000000',
positionSide:'BOTH'
},
{
symbol:'BTCUSDT',
positionAmount:'20',
entryPrice:'6563.66500',
accumulatedRealized:'0',
unrealizedPnL:'2850.21200',
marginType:'isolated',
isolatedWallet:'13200.70726908',
positionSide:'LONG'
}
],
}
```
</details>
#### Common
#### getInfo
To get information about limits from response headers call getInfo()
```js
const binanceInfo = client.getInfo()
```
<details>
<summary>Output</summary>
```js
{
futures: {
futuresLatency: "2ms",
orderCount1m: "10",
usedWeigh1m: "1",
},
spot: {
orderCount1d: "347",
orderCount10s: "1",
usedWeigh1m: "15",
}
}
```
</details>
### ErrorCodes

@@ -2086,0 +2698,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc