binance-api-node
Advanced tools
Comparing version 0.0.1 to 0.1.0
@@ -146,5 +146,5 @@ 'use strict'; | ||
var newPayload = payload.type === 'MARKET' ? _extends({}, payload, { price: 0 }) : payload; | ||
var newPayload = payload.type !== 'MARKET' ? _extends({ timeInForce: 'GTC' }, payload) : payload; | ||
return checkParams('order', newPayload, ['symbol', 'side', 'quantity']) && pCall(url, _extends({ type: 'LIMIT', timeInForce: 'GTC' }, newPayload), 'POST'); | ||
return checkParams('order', newPayload, ['symbol', 'side', 'quantity']) && pCall(url, _extends({ type: 'LIMIT' }, newPayload), 'POST'); | ||
}; | ||
@@ -151,0 +151,0 @@ |
@@ -13,2 +13,6 @@ 'use strict'; | ||
var _lodash = require('lodash.zipobject'); | ||
var _lodash2 = _interopRequireDefault(_lodash); | ||
var _http = require('./http'); | ||
@@ -24,54 +28,73 @@ | ||
var depth = function depth(symbol, cb) { | ||
var w = new _ws2.default(BASE + '/' + symbol.toLowerCase() + '@depth'); | ||
w.on('message', function (msg) { | ||
var _JSON$parse = JSON.parse(msg), | ||
eventType = _JSON$parse.e, | ||
eventTime = _JSON$parse.E, | ||
symbol = _JSON$parse.s, | ||
updateId = _JSON$parse.u, | ||
bidDepth = _JSON$parse.b, | ||
askDepth = _JSON$parse.a; | ||
var depth = function depth(payload, cb) { | ||
return (Array.isArray(payload) ? payload : [payload]).forEach(function (symbol) { | ||
var w = new _ws2.default(BASE + '/' + symbol.toLowerCase() + '@depth'); | ||
w.on('message', function (msg) { | ||
var _JSON$parse = JSON.parse(msg), | ||
eventType = _JSON$parse.e, | ||
eventTime = _JSON$parse.E, | ||
symbol = _JSON$parse.s, | ||
updateId = _JSON$parse.u, | ||
bidDepth = _JSON$parse.b, | ||
askDepth = _JSON$parse.a; | ||
cb({ eventType: eventType, eventTime: eventTime, symbol: symbol, updateId: updateId, bidDepth: bidDepth, askDepth: askDepth }); | ||
cb({ | ||
eventType: eventType, | ||
eventTime: eventTime, | ||
symbol: symbol, | ||
updateId: updateId, | ||
bidDepth: bidDepth.map(function (b) { | ||
return (0, _lodash2.default)(['price', 'quantity'], b); | ||
}), | ||
askDepth: askDepth.map(function (a) { | ||
return (0, _lodash2.default)(['price', 'quantity'], a); | ||
}) | ||
}); | ||
}); | ||
}); | ||
}; | ||
var candles = function candles(symbol, interval, cb) { | ||
var w = new _ws2.default(BASE + '/' + symbol.toLowerCase() + '@kline_' + interval); | ||
w.on('message', function (msg) { | ||
var _JSON$parse2 = JSON.parse(msg), | ||
eventType = _JSON$parse2.e, | ||
eventTime = _JSON$parse2.E, | ||
symbol = _JSON$parse2.s, | ||
tick = _JSON$parse2.k; | ||
var candles = function candles(payload, interval, cb) { | ||
if (!interval || !cb) { | ||
throw new Error('Please pass a symbol, interval and callback.'); | ||
} | ||
var open = tick.o, | ||
high = tick.h, | ||
low = tick.l, | ||
close = tick.c, | ||
volume = tick.v, | ||
trades = tick.n, | ||
interval = tick.i, | ||
isFinal = tick.x, | ||
quoteVolume = tick.q, | ||
buyVolume = tick.V, | ||
quoteBuyVolume = tick.Q; | ||
;(Array.isArray(payload) ? payload : [payload]).forEach(function (symbol) { | ||
var w = new _ws2.default(BASE + '/' + symbol.toLowerCase() + '@kline_' + interval); | ||
w.on('message', function (msg) { | ||
var _JSON$parse2 = JSON.parse(msg), | ||
eventType = _JSON$parse2.e, | ||
eventTime = _JSON$parse2.E, | ||
symbol = _JSON$parse2.s, | ||
tick = _JSON$parse2.k; | ||
var open = tick.o, | ||
high = tick.h, | ||
low = tick.l, | ||
close = tick.c, | ||
volume = tick.v, | ||
trades = tick.n, | ||
interval = tick.i, | ||
isFinal = tick.x, | ||
quoteVolume = tick.q, | ||
buyVolume = tick.V, | ||
quoteBuyVolume = tick.Q; | ||
cb({ | ||
eventType: eventType, | ||
eventTime: eventTime, | ||
symbol: symbol, | ||
open: open, | ||
high: high, | ||
low: low, | ||
close: close, | ||
volume: volume, | ||
trades: trades, | ||
interval: interval, | ||
isFinal: isFinal, | ||
quoteVolume: quoteVolume, | ||
buyVolume: buyVolume, | ||
quoteBuyVolume: quoteBuyVolume | ||
cb({ | ||
eventType: eventType, | ||
eventTime: eventTime, | ||
symbol: symbol, | ||
open: open, | ||
high: high, | ||
low: low, | ||
close: close, | ||
volume: volume, | ||
trades: trades, | ||
interval: interval, | ||
isFinal: isFinal, | ||
quoteVolume: quoteVolume, | ||
buyVolume: buyVolume, | ||
quoteBuyVolume: quoteBuyVolume | ||
}); | ||
}); | ||
@@ -81,22 +104,24 @@ }); | ||
var trades = function trades(symbol, cb) { | ||
var w = new _ws2.default(BASE + '/' + symbol.toLowerCase() + '@aggTrades'); | ||
w.on('message', function (msg) { | ||
var _JSON$parse3 = JSON.parse(msg), | ||
eventType = _JSON$parse3.e, | ||
eventTime = _JSON$parse3.E, | ||
symbol = _JSON$parse3.s, | ||
price = _JSON$parse3.p, | ||
quantity = _JSON$parse3.q, | ||
maker = _JSON$parse3.m, | ||
tradeId = _JSON$parse3.a; | ||
var trades = function trades(payload, cb) { | ||
return (Array.isArray(payload) ? payload : [payload]).forEach(function (symbol) { | ||
var w = new _ws2.default(BASE + '/' + symbol.toLowerCase() + '@aggTrade'); | ||
w.on('message', function (msg) { | ||
var _JSON$parse3 = JSON.parse(msg), | ||
eventType = _JSON$parse3.e, | ||
eventTime = _JSON$parse3.E, | ||
symbol = _JSON$parse3.s, | ||
price = _JSON$parse3.p, | ||
quantity = _JSON$parse3.q, | ||
maker = _JSON$parse3.m, | ||
tradeId = _JSON$parse3.a; | ||
cb({ | ||
eventType: eventType, | ||
eventTime: eventTime, | ||
symbol: symbol, | ||
price: price, | ||
quantity: quantity, | ||
maker: maker, | ||
tradeId: tradeId | ||
cb({ | ||
eventType: eventType, | ||
eventTime: eventTime, | ||
symbol: symbol, | ||
price: price, | ||
quantity: quantity, | ||
maker: maker, | ||
tradeId: tradeId | ||
}); | ||
}); | ||
@@ -151,3 +176,3 @@ }); | ||
getDataStream().then(function (_ref) { | ||
return getDataStream().then(function (_ref) { | ||
var listenKey = _ref.listenKey; | ||
@@ -154,0 +179,0 @@ |
{ | ||
"name": "binance-api-node", | ||
"version": "0.0.1", | ||
"version": "0.1.0", | ||
"description": "A node API wrapper for Binance", | ||
@@ -27,2 +27,3 @@ "main": "dist", | ||
"coveralls": "^3.0.0", | ||
"dotenv": "^4.0.0", | ||
"eslint": "^4.9.0", | ||
@@ -39,2 +40,5 @@ "eslint-config-prettier": "^2.6.0", | ||
], | ||
"files": [ | ||
"test/index.js" | ||
], | ||
"babel": "inherit" | ||
@@ -41,0 +45,0 @@ }, |
155
README.md
@@ -5,3 +5,3 @@ # binance-api-node [![Build](https://img.shields.io/travis/HyperCubeProject/binance-api-node.svg?style=flat-square)](https://travis-ci.org/HyperCubeProject/binance-api-node) [![Coverage](https://img.shields.io/coveralls/HyperCubeProject/binance-api-node.svg?style=flat-square)](https://coveralls.io/github/HyperCubeProject/binance-api-node) | ||
Note: This wrapper uses Promises, if they are not supported on your, you might | ||
Note: This wrapper uses Promises, if they are not supported in your environment, you might | ||
want to add [a polyfill](https://github.com/stefanpenner/es6-promise) for them. | ||
@@ -135,3 +135,3 @@ | ||
|symbol|String|true| | ||
|interval|String|false|`5m`|`1m`, `3m`, `5m`, `15m`, `30m`, `1h`, `2h`, `4h`, `6h`, `8h`, `12h`, `1d`, `3d`, `1w`, `1M`| | ||
|interval|String|false|`5m`|`1m`, `3m`, `5m`, `15m`, `30m`, `1h`, `2h`,<br>`4h`, `6h`, `8h`, `12h`, `1d`, `3d`, `1w`, `1M`| | ||
|limit|Number|false|`500`|Max `500`| | ||
@@ -358,2 +358,17 @@ |startTime|Number|false| | ||
```js | ||
{ | ||
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 | ||
} | ||
``` | ||
@@ -434,2 +449,17 @@ | ||
```js | ||
[{ | ||
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 | ||
}] | ||
``` | ||
@@ -444,3 +474,3 @@ | ||
```js | ||
console.log(await client.openOrders()) | ||
console.log(await client.accountInfo()) | ||
``` | ||
@@ -456,2 +486,15 @@ | ||
```js | ||
{ | ||
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' }, | ||
] | ||
} | ||
``` | ||
@@ -482,2 +525,14 @@ | ||
```js | ||
[{ | ||
id: 9960, | ||
orderId: 191939, | ||
price: '0.00138000', | ||
qty: '10.00000000', | ||
commission: '0.00001380', | ||
commissionAsset: 'ETH', | ||
time: 1508611114735, | ||
isBuyer: false, | ||
isMaker: false, | ||
isBestMatch: true | ||
}] | ||
``` | ||
@@ -491,3 +546,4 @@ | ||
Live depth market data feed for a given symbol. | ||
Live depth market data feed. The first parameter can either | ||
be a single symbol string or an array of symbols. | ||
@@ -500,5 +556,28 @@ ```js | ||
<details> | ||
<summary>Output</summary> | ||
```js | ||
{ | ||
eventType: 'depthUpdate', | ||
eventTime: 1508612956950, | ||
symbol: 'ETHBTC', | ||
updateId: 18331140, | ||
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> | ||
#### candles | ||
Live candle data feed for a given symbol and interval. | ||
Live candle data feed for a given interval. You can pass either a symbol string | ||
or a symbol array. | ||
@@ -511,8 +590,32 @@ ```js | ||
<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> | ||
#### trades | ||
Live trade data feed for a given symbol. | ||
Live trade data feed. Pass either a single symbol string or an array of symbols. | ||
```js | ||
client.ws.trades('ETHBTC', trade => { | ||
client.ws.trades(['ETHBTC', 'BNBBTC'], trade => { | ||
console.log(trade) | ||
@@ -522,2 +625,19 @@ }) | ||
<details> | ||
<summary>Output</summary> | ||
```js | ||
{ | ||
eventType: 'aggTrade', | ||
eventTime: 1508614495052, | ||
symbol: 'ETHBTC', | ||
price: '0.04923600', | ||
quantity: '3.43500000', | ||
maker: false, | ||
tradeId: 2148226 | ||
} | ||
``` | ||
</details> | ||
#### user | ||
@@ -530,3 +650,3 @@ | ||
```js | ||
const clean = client.ws.user(msg => { | ||
const clean = await client.ws.user(msg => { | ||
console.log(msg) | ||
@@ -536,3 +656,20 @@ }) | ||
Note that this method returns a `clean` callback, that will clear | ||
Note that this method returns a promise returning a `clean` callback, that will clear | ||
the keep-alive interval and close the data stream. | ||
<details> | ||
<summary>Output</summary> | ||
```js | ||
{ | ||
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' }, | ||
] | ||
} | ||
``` | ||
</details> |
@@ -129,7 +129,7 @@ import crypto from 'crypto' | ||
const order = (pCall, payload = {}, url) => { | ||
const newPayload = payload.type === 'MARKET' ? { ...payload, price: 0 } : payload | ||
const newPayload = payload.type !== 'MARKET' ? { timeInForce: 'GTC', ...payload } : payload | ||
return ( | ||
checkParams('order', newPayload, ['symbol', 'side', 'quantity']) && | ||
pCall(url, { type: 'LIMIT', timeInForce: 'GTC', ...newPayload }, 'POST') | ||
pCall(url, { type: 'LIMIT', ...newPayload }, 'POST') | ||
) | ||
@@ -136,0 +136,0 @@ } |
import WebSocket from 'ws' | ||
import zip from 'lodash.zipobject' | ||
@@ -7,51 +8,65 @@ import httpMethods from 'http' | ||
const depth = (symbol, cb) => { | ||
const w = new WebSocket(`${BASE}/${symbol.toLowerCase()}@depth`) | ||
w.on('message', msg => { | ||
const { | ||
e: eventType, | ||
E: eventTime, | ||
s: symbol, | ||
u: updateId, | ||
b: bidDepth, | ||
a: askDepth, | ||
} = JSON.parse(msg) | ||
const depth = (payload, cb) => | ||
(Array.isArray(payload) ? payload : [payload]).forEach(symbol => { | ||
const w = new WebSocket(`${BASE}/${symbol.toLowerCase()}@depth`) | ||
w.on('message', msg => { | ||
const { | ||
e: eventType, | ||
E: eventTime, | ||
s: symbol, | ||
u: updateId, | ||
b: bidDepth, | ||
a: askDepth, | ||
} = JSON.parse(msg) | ||
cb({ eventType, eventTime, symbol, updateId, bidDepth, askDepth }) | ||
cb({ | ||
eventType, | ||
eventTime, | ||
symbol, | ||
updateId, | ||
bidDepth: bidDepth.map(b => zip(['price', 'quantity'], b)), | ||
askDepth: askDepth.map(a => zip(['price', 'quantity'], a)), | ||
}) | ||
}) | ||
}) | ||
} | ||
const candles = (symbol, interval, cb) => { | ||
const w = new WebSocket(`${BASE}/${symbol.toLowerCase()}@kline_${interval}`) | ||
w.on('message', msg => { | ||
const { e: eventType, E: eventTime, s: symbol, k: tick } = JSON.parse(msg) | ||
const { | ||
o: open, | ||
h: high, | ||
l: low, | ||
c: close, | ||
v: volume, | ||
n: trades, | ||
i: interval, | ||
x: isFinal, | ||
q: quoteVolume, | ||
V: buyVolume, | ||
Q: quoteBuyVolume, | ||
} = tick | ||
const candles = (payload, interval, cb) => { | ||
if (!interval || !cb) { | ||
throw new Error('Please pass a symbol, interval and callback.') | ||
} | ||
cb({ | ||
eventType, | ||
eventTime, | ||
symbol, | ||
open, | ||
high, | ||
low, | ||
close, | ||
volume, | ||
trades, | ||
interval, | ||
isFinal, | ||
quoteVolume, | ||
buyVolume, | ||
quoteBuyVolume, | ||
;(Array.isArray(payload) ? payload : [payload]).forEach(symbol => { | ||
const w = new WebSocket(`${BASE}/${symbol.toLowerCase()}@kline_${interval}`) | ||
w.on('message', msg => { | ||
const { e: eventType, E: eventTime, s: symbol, k: tick } = JSON.parse(msg) | ||
const { | ||
o: open, | ||
h: high, | ||
l: low, | ||
c: close, | ||
v: volume, | ||
n: trades, | ||
i: interval, | ||
x: isFinal, | ||
q: quoteVolume, | ||
V: buyVolume, | ||
Q: quoteBuyVolume, | ||
} = tick | ||
cb({ | ||
eventType, | ||
eventTime, | ||
symbol, | ||
open, | ||
high, | ||
low, | ||
close, | ||
volume, | ||
trades, | ||
interval, | ||
isFinal, | ||
quoteVolume, | ||
buyVolume, | ||
quoteBuyVolume, | ||
}) | ||
}) | ||
@@ -61,26 +76,27 @@ }) | ||
const trades = (symbol, cb) => { | ||
const w = new WebSocket(`${BASE}/${symbol.toLowerCase()}@aggTrades`) | ||
w.on('message', msg => { | ||
const { | ||
e: eventType, | ||
E: eventTime, | ||
s: symbol, | ||
p: price, | ||
q: quantity, | ||
m: maker, | ||
a: tradeId, | ||
} = JSON.parse(msg) | ||
const trades = (payload, cb) => | ||
(Array.isArray(payload) ? payload : [payload]).forEach(symbol => { | ||
const w = new WebSocket(`${BASE}/${symbol.toLowerCase()}@aggTrade`) | ||
w.on('message', msg => { | ||
const { | ||
e: eventType, | ||
E: eventTime, | ||
s: symbol, | ||
p: price, | ||
q: quantity, | ||
m: maker, | ||
a: tradeId, | ||
} = JSON.parse(msg) | ||
cb({ | ||
eventType, | ||
eventTime, | ||
symbol, | ||
price, | ||
quantity, | ||
maker, | ||
tradeId, | ||
cb({ | ||
eventType, | ||
eventTime, | ||
symbol, | ||
price, | ||
quantity, | ||
maker, | ||
tradeId, | ||
}) | ||
}) | ||
}) | ||
} | ||
@@ -124,3 +140,3 @@ const userTransforms = { | ||
getDataStream().then(({ listenKey }) => { | ||
return getDataStream().then(({ listenKey }) => { | ||
const w = new WebSocket(`${BASE}/${listenKey}`) | ||
@@ -127,0 +143,0 @@ w.on('message', msg => { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
191040
739
663
6
14