binance-api-node
Advanced tools
Comparing version 0.6.1 to 0.7.0
@@ -36,3 +36,3 @@ 'use strict'; | ||
/** | ||
* Finalize APi response | ||
* Finalize API response | ||
*/ | ||
@@ -39,0 +39,0 @@ var sendResult = function sendResult(call) { |
@@ -10,6 +10,2 @@ 'use strict'; | ||
var _ws = require('ws'); | ||
var _ws2 = _interopRequireDefault(_ws); | ||
var _lodash = require('lodash.zipobject'); | ||
@@ -23,2 +19,6 @@ | ||
var _openWebsocket = require('./open-websocket'); | ||
var _openWebsocket2 = _interopRequireDefault(_openWebsocket); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -32,5 +32,5 @@ | ||
var cache = (Array.isArray(payload) ? payload : [payload]).map(function (symbol) { | ||
var w = new _ws2.default(BASE + '/' + symbol.toLowerCase() + '@depth'); | ||
w.on('message', function (msg) { | ||
var _JSON$parse = JSON.parse(msg), | ||
var w = (0, _openWebsocket2.default)(BASE + '/' + symbol.toLowerCase() + '@depth'); | ||
w.onmessage = function (msg) { | ||
var _JSON$parse = JSON.parse(msg.data), | ||
eventType = _JSON$parse.e, | ||
@@ -57,3 +57,3 @@ eventTime = _JSON$parse.E, | ||
}); | ||
}); | ||
}; | ||
@@ -65,3 +65,3 @@ return w; | ||
return cache.forEach(function (w) { | ||
return w.close(); | ||
return w.close(1000, 'Close handle was called', { keepClosed: true }); | ||
}); | ||
@@ -76,5 +76,5 @@ }; | ||
var w = new _ws2.default(BASE + '/' + symbol.toLowerCase() + '@depth' + level); | ||
w.on('message', function (msg) { | ||
var _JSON$parse2 = JSON.parse(msg), | ||
var w = (0, _openWebsocket2.default)(BASE + '/' + symbol.toLowerCase() + '@depth' + level); | ||
w.onmessage = function (msg) { | ||
var _JSON$parse2 = JSON.parse(msg.data), | ||
lastUpdateId = _JSON$parse2.lastUpdateId, | ||
@@ -95,3 +95,3 @@ bids = _JSON$parse2.bids, | ||
}); | ||
}); | ||
}; | ||
@@ -103,3 +103,3 @@ return w; | ||
return cache.forEach(function (w) { | ||
return w.close(); | ||
return w.close(1000, 'Close handle was called', { keepClosed: true }); | ||
}); | ||
@@ -115,5 +115,5 @@ }; | ||
var cache = (Array.isArray(payload) ? payload : [payload]).map(function (symbol) { | ||
var w = new _ws2.default(BASE + '/' + symbol.toLowerCase() + '@kline_' + interval); | ||
w.on('message', function (msg) { | ||
var _JSON$parse3 = JSON.parse(msg), | ||
var w = (0, _openWebsocket2.default)(BASE + '/' + symbol.toLowerCase() + '@kline_' + interval); | ||
w.onmessage = function (msg) { | ||
var _JSON$parse3 = JSON.parse(msg.data), | ||
eventType = _JSON$parse3.e, | ||
@@ -161,3 +161,3 @@ eventTime = _JSON$parse3.E, | ||
}); | ||
}); | ||
}; | ||
@@ -169,3 +169,3 @@ return w; | ||
return cache.forEach(function (w) { | ||
return w.close(); | ||
return w.close(1000, 'Close handle was called', { keepClosed: true }); | ||
}); | ||
@@ -205,7 +205,7 @@ }; | ||
var cache = (Array.isArray(payload) ? payload : [payload]).map(function (symbol) { | ||
var w = new _ws2.default(BASE + '/' + symbol.toLowerCase() + '@ticker'); | ||
var w = (0, _openWebsocket2.default)(BASE + '/' + symbol.toLowerCase() + '@ticker'); | ||
w.on('message', function (msg) { | ||
cb(tickerTransform(JSON.parse(msg))); | ||
}); | ||
w.onmessage = function (msg) { | ||
cb(tickerTransform(JSON.parse(msg.data))); | ||
}; | ||
@@ -217,3 +217,3 @@ return w; | ||
return cache.forEach(function (w) { | ||
return w.close(); | ||
return w.close(1000, 'Close handle was called', { keepClosed: true }); | ||
}); | ||
@@ -224,13 +224,13 @@ }; | ||
var allTickers = function allTickers(cb) { | ||
var w = new _ws2.default(BASE + '/!ticker@arr'); | ||
var w = new _openWebsocket2.default(BASE + '/!ticker@arr'); | ||
w.on('message', function (msg) { | ||
var arr = JSON.parse(msg); | ||
w.onmessage = function (msg) { | ||
var arr = JSON.parse(msg.data); | ||
cb(arr.map(function (m) { | ||
return tickerTransform(m); | ||
})); | ||
}); | ||
}; | ||
return function () { | ||
return w.close(); | ||
return w.close(1000, 'Close handle was called', { keepClosed: true }); | ||
}; | ||
@@ -241,5 +241,5 @@ }; | ||
var cache = (Array.isArray(payload) ? payload : [payload]).map(function (symbol) { | ||
var w = new _ws2.default(BASE + '/' + symbol.toLowerCase() + '@aggTrade'); | ||
w.on('message', function (msg) { | ||
var _JSON$parse4 = JSON.parse(msg), | ||
var w = (0, _openWebsocket2.default)(BASE + '/' + symbol.toLowerCase() + '@aggTrade'); | ||
w.onmessage = function (msg) { | ||
var _JSON$parse4 = JSON.parse(msg.data), | ||
eventType = _JSON$parse4.e, | ||
@@ -262,3 +262,3 @@ eventTime = _JSON$parse4.E, | ||
}); | ||
}); | ||
}; | ||
@@ -270,3 +270,3 @@ return w; | ||
return cache.forEach(function (w) { | ||
return w.close(); | ||
return w.close(1000, 'Close handle was called', { keepClosed: true }); | ||
}); | ||
@@ -353,4 +353,6 @@ }; | ||
var w = new _ws2.default(BASE + '/' + listenKey); | ||
w.on('message', userEventHandler(cb)); | ||
var w = (0, _openWebsocket2.default)(BASE + '/' + listenKey); | ||
w.onmessage = function () { | ||
return userEventHandler(cb); | ||
}; | ||
@@ -363,3 +365,3 @@ var int = setInterval(keepStreamAlive(keepDataStream, listenKey), 50e3); | ||
closeDataStream({ listenKey: listenKey }); | ||
w.close(); | ||
w.close(1000, 'Close handle was called', { keepClosed: true }); | ||
}; | ||
@@ -366,0 +368,0 @@ }); |
153
index.d.ts
@@ -27,2 +27,4 @@ // tslint:disable:interface-name | ||
accountInfo(): Promise<Account>; | ||
book(options: { symbol: string, limit?: number }): Promise<OrderBook>; | ||
exchangeInfo(): Promise<ExchangeInfo>; | ||
order(options: NewOrder): Promise<Order>; | ||
@@ -32,2 +34,6 @@ prices(): Promise<{ [index: string]: string }>; | ||
ws: WebSocket; | ||
myTrades(options: { symbol: string, limit?: number, fromId?: number }): Promise<MyTrade[]>; | ||
getOrder(options: { symbol: string; orderId: number }): Promise<QueryOrderResult>; | ||
cancelOrder(options: { symbol: string; orderId: number }): Promise<CancelOrderResult>; | ||
openOrders(options: { symbol: string }): Promise<QueryOrderResult[]>; | ||
} | ||
@@ -45,2 +51,112 @@ | ||
export type CandleChartInterval = | ||
| '1m' | ||
| '3m' | ||
| '5m' | ||
| '15m' | ||
| '30m' | ||
| '1h' | ||
| '2h' | ||
| '4h' | ||
| '6h' | ||
| '8h' | ||
| '12h' | ||
| '1d' | ||
| '3d' | ||
| '1w' | ||
| '1M'; | ||
export type RateLimitType = | ||
| 'REQUESTS' | ||
| 'ORDERS'; | ||
export type RateLimitInterval = | ||
| 'SECOND' | ||
| 'MINUTE' | ||
| 'DAY'; | ||
export interface ExchangeInfoRateLimit { | ||
rateLimitType: RateLimitType; | ||
interval: RateLimitInterval; | ||
limit: number; | ||
} | ||
export type ExchangeFilterType = | ||
| 'EXCHANGE_MAX_NUM_ORDERS' | ||
| 'EXCHANGE_MAX_ALGO_ORDERS'; | ||
export interface ExchangeFilter { | ||
filterType: ExchangeFilterType; | ||
limit: number; | ||
} | ||
export type SymbolFilterType = | ||
| 'PRICE_FILTER' | ||
| 'LOT_SIZE' | ||
| 'MIN_NOTIONAL' | ||
| 'MAX_NUM_ORDERS' | ||
| 'MAX_ALGO_ORDERS'; | ||
export interface SymbolPriceFilter { | ||
filterType: SymbolFilterType, | ||
minPrice: string; | ||
maxPrice: string; | ||
tickSize: string; | ||
} | ||
export interface SymbolLotSizeFilter { | ||
filterType: SymbolFilterType, | ||
minQty: string; | ||
maxQty: string; | ||
stepSize: string; | ||
} | ||
export interface SymbolMinNotionalFilter { | ||
filterType: SymbolFilterType; | ||
minNotional: string; | ||
} | ||
export interface SymbolMaxNumOrdersFilter { | ||
filterType: SymbolFilterType; | ||
limit: number; | ||
} | ||
export interface SymbolMaxAlgoOrdersFilter { | ||
filterType: SymbolFilterType; | ||
limit: number; | ||
} | ||
export type SymbolFilter = | ||
| SymbolPriceFilter | ||
| SymbolLotSizeFilter | ||
| SymbolMinNotionalFilter | ||
| SymbolMaxNumOrdersFilter | ||
| SymbolMaxAlgoOrdersFilter; | ||
export interface Symbol { | ||
symbol: string; | ||
status: string; | ||
baseAsset: string; | ||
baseAssetPrecision: number; | ||
quoteAsset: string; | ||
quotePrecision: number; | ||
orderTypes: OrderType[]; | ||
icebergAllowed: boolean; | ||
filters: SymbolFilter[]; | ||
} | ||
export interface ExchangeInfo { | ||
timezone: string; | ||
serverTime: number; | ||
rateLimits: ExchangeInfoRateLimit[]; | ||
exchangeFilters: ExchangeFilter[]; | ||
symbols: Symbol[]; | ||
} | ||
export interface OrderBook { | ||
lastUpdateId: number; | ||
asks: Bid[]; | ||
bids: Bid[]; | ||
} | ||
export interface NewOrder { | ||
@@ -250,2 +366,39 @@ icebergQty?: string; | ||
} | ||
interface MyTrade { | ||
id: number; | ||
orderId: number; | ||
price: string; | ||
qty: string; | ||
commission: string; | ||
commissionAsset: string; | ||
time: number; | ||
isBuyer: boolean; | ||
isMaker: boolean; | ||
isBestMatch: boolean; | ||
} | ||
interface QueryOrderResult { | ||
symbol: string; | ||
orderId: number; | ||
clientOrderId: string; | ||
price: string; | ||
origQty: string; | ||
executedQty: string; | ||
status: OrderStatus; | ||
timeInForce: string; | ||
type: string; | ||
side: string; | ||
stopPrice: string; | ||
icebergQty: string; | ||
time: number; | ||
isWorking: boolean; | ||
} | ||
interface CancelOrderResult { | ||
symbol: string; | ||
origClientOrderId: string; | ||
orderId: number; | ||
clientOrderId: string; | ||
} | ||
} |
{ | ||
"name": "binance-api-node", | ||
"version": "0.6.1", | ||
"version": "0.7.0", | ||
"description": "A node API wrapper for Binance", | ||
@@ -14,5 +14,6 @@ "main": "dist", | ||
"dependencies": { | ||
"html5-websocket": "^2.0.2", | ||
"isomorphic-fetch": "^2.2.1", | ||
"lodash.zipobject": "^4.1.3", | ||
"ws": "^3.2.0" | ||
"reconnecting-websocket": "^3.2.2" | ||
}, | ||
@@ -19,0 +20,0 @@ "devDependencies": { |
@@ -19,3 +19,3 @@ import crypto from 'crypto' | ||
/** | ||
* Finalize APi response | ||
* Finalize API response | ||
*/ | ||
@@ -22,0 +22,0 @@ const sendResult = call => |
@@ -1,5 +0,5 @@ | ||
import WebSocket from 'ws' | ||
import zip from 'lodash.zipobject' | ||
import httpMethods from 'http' | ||
import openWebSocket from 'open-websocket' | ||
@@ -10,4 +10,4 @@ const BASE = 'wss://stream.binance.com:9443/ws' | ||
const cache = (Array.isArray(payload) ? payload : [payload]).map(symbol => { | ||
const w = new WebSocket(`${BASE}/${symbol.toLowerCase()}@depth`) | ||
w.on('message', msg => { | ||
const w = openWebSocket(`${BASE}/${symbol.toLowerCase()}@depth`) | ||
w.onmessage = msg => { | ||
const { | ||
@@ -21,3 +21,3 @@ e: eventType, | ||
a: askDepth, | ||
} = JSON.parse(msg) | ||
} = JSON.parse(msg.data) | ||
@@ -33,3 +33,3 @@ cb({ | ||
}) | ||
}) | ||
} | ||
@@ -39,3 +39,3 @@ return w | ||
return () => cache.forEach(w => w.close()) | ||
return () => cache.forEach(w => w.close(1000, 'Close handle was called', { keepClosed: true })) | ||
} | ||
@@ -45,5 +45,5 @@ | ||
const cache = (Array.isArray(payload) ? payload : [payload]).map(({ symbol, level }) => { | ||
const w = new WebSocket(`${BASE}/${symbol.toLowerCase()}@depth${level}`) | ||
w.on('message', msg => { | ||
const { lastUpdateId, bids, asks } = JSON.parse(msg) | ||
const w = openWebSocket(`${BASE}/${symbol.toLowerCase()}@depth${level}`) | ||
w.onmessage = msg => { | ||
const { lastUpdateId, bids, asks } = JSON.parse(msg.data) | ||
cb({ | ||
@@ -56,3 +56,3 @@ symbol, | ||
}) | ||
}) | ||
} | ||
@@ -62,3 +62,3 @@ return w | ||
return () => cache.forEach(w => w.close()) | ||
return () => cache.forEach(w => w.close(1000, 'Close handle was called', { keepClosed: true })) | ||
} | ||
@@ -72,5 +72,5 @@ | ||
const cache = (Array.isArray(payload) ? payload : [payload]).map(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 w = openWebSocket(`${BASE}/${symbol.toLowerCase()}@kline_${interval}`) | ||
w.onmessage = msg => { | ||
const { e: eventType, E: eventTime, s: symbol, k: tick } = JSON.parse(msg.data) | ||
const { | ||
@@ -114,3 +114,3 @@ t: startTime, | ||
}) | ||
}) | ||
} | ||
@@ -120,3 +120,3 @@ return w | ||
return () => cache.forEach(w => w.close()) | ||
return () => cache.forEach(w => w.close(1000, 'Close handle was called', { keepClosed: true })) | ||
} | ||
@@ -152,7 +152,7 @@ | ||
const cache = (Array.isArray(payload) ? payload : [payload]).map(symbol => { | ||
const w = new WebSocket(`${BASE}/${symbol.toLowerCase()}@ticker`) | ||
const w = openWebSocket(`${BASE}/${symbol.toLowerCase()}@ticker`) | ||
w.on('message', msg => { | ||
cb(tickerTransform(JSON.parse(msg))) | ||
}) | ||
w.onmessage = msg => { | ||
cb(tickerTransform(JSON.parse(msg.data))) | ||
} | ||
@@ -162,14 +162,14 @@ return w | ||
return () => cache.forEach(w => w.close()) | ||
return () => cache.forEach(w => w.close(1000, 'Close handle was called', { keepClosed: true })) | ||
} | ||
const allTickers = cb => { | ||
const w = new WebSocket(`${BASE}/!ticker@arr`) | ||
const w = new openWebSocket(`${BASE}/!ticker@arr`) | ||
w.on('message', msg => { | ||
const arr = JSON.parse(msg) | ||
w.onmessage = msg => { | ||
const arr = JSON.parse(msg.data) | ||
cb(arr.map(m => tickerTransform(m))) | ||
}) | ||
} | ||
return () => w.close() | ||
return () => w.close(1000, 'Close handle was called', { keepClosed: true }) | ||
} | ||
@@ -179,4 +179,4 @@ | ||
const cache = (Array.isArray(payload) ? payload : [payload]).map(symbol => { | ||
const w = new WebSocket(`${BASE}/${symbol.toLowerCase()}@aggTrade`) | ||
w.on('message', msg => { | ||
const w = openWebSocket(`${BASE}/${symbol.toLowerCase()}@aggTrade`) | ||
w.onmessage = msg => { | ||
const { | ||
@@ -190,3 +190,3 @@ e: eventType, | ||
a: tradeId, | ||
} = JSON.parse(msg) | ||
} = JSON.parse(msg.data) | ||
@@ -202,3 +202,3 @@ cb({ | ||
}) | ||
}) | ||
} | ||
@@ -208,3 +208,3 @@ return w | ||
return () => cache.forEach(w => w.close()) | ||
return () => cache.forEach(w => w.close(1000, 'Close handle was called', { keepClosed: true })) | ||
} | ||
@@ -269,4 +269,4 @@ | ||
return getDataStream().then(({ listenKey }) => { | ||
const w = new WebSocket(`${BASE}/${listenKey}`) | ||
w.on('message', userEventHandler(cb)) | ||
const w = openWebSocket(`${BASE}/${listenKey}`) | ||
w.onmessage = () => (userEventHandler(cb)) | ||
@@ -279,3 +279,3 @@ const int = setInterval(keepStreamAlive(keepDataStream, listenKey), 50e3) | ||
closeDataStream({ listenKey }) | ||
w.close() | ||
w.close(1000, 'Close handle was called', { keepClosed: true }) | ||
} | ||
@@ -282,0 +282,0 @@ }) |
@@ -376,1 +376,3 @@ import test from 'ava' | ||
} | ||
require('./websocket-reconnect') |
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
237000
20
1932
4
+ Addedhtml5-websocket@^2.0.2
+ Addedhtml5-websocket@2.0.4(transitive)
+ Addedreconnecting-websocket@3.2.2(transitive)
- Removedws@^3.2.0