From 5f91c8cba64a25115eb86e3466f0da77e2c87b23 Mon Sep 17 00:00:00 2001 From: "Gergely Szell (sethyx)" Date: Sat, 13 Jan 2018 14:54:51 +0100 Subject: [PATCH 1/2] Added optional params to get candlestick data This is useful if someone wants to import data from earlier back in time. Also removed the default 5m interval (regular parameters (callback) should not come after default ones). This might break functionality for people who relied on the default interval. --- README.md | 7 +++++-- node-binance-api.js | 5 +++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 66e4f225..8642bb96 100644 --- a/README.md +++ b/README.md @@ -1220,14 +1220,17 @@ binance.prevDay("BNBBTC", function(prevDay, symbol) { ``` #### Get Kline/candlestick data for a symbol +You can use the optional API parameters for getting historical candlesticks, these are useful if you want to import data from earlier back in time. +Optional parameters: limit (max/default 500), startTime, endTime. + ```javascript -// Periods: 1m,3m,5m,15m,30m,1h,2h,4h,6h,8h,12h,1d,3d,1w,1M +// Intervals: 1m,3m,5m,15m,30m,1h,2h,4h,6h,8h,12h,1d,3d,1w,1M binance.candlesticks("BNBBTC", "5m", function(ticks, symbol) { console.log("candlesticks()", ticks); let last_tick = ticks[ticks.length - 1]; let [time, open, high, low, close, volume, closeTime, assetVolume, trades, buyBaseVolume, buyAssetVolume, ignored] = last_tick; console.log(symbol+" last close: "+close); -}); +}, {limit: 500, endTime: 1514764800000}); ``` # WebSockets Implementation diff --git a/node-binance-api.js b/node-binance-api.js index 3e6e0d26..77d195f2 100644 --- a/node-binance-api.js +++ b/node-binance-api.js @@ -605,8 +605,9 @@ Move this to a future release v0.4.0 } return {open:open, high:high, low:low, close:close, volume:volume}; }, - candlesticks: function(symbol, interval = '5m', callback) { //1m,3m,5m,15m,30m,1h,2h,4h,6h,8h,12h,1d,3d,1w,1M - publicRequest(base+'v1/klines', {symbol:symbol, interval:interval}, function(data) { + candlesticks: function(symbol, interval, callback, options = {limit:500}) { // additional options: startTime, endTime + let params = Object.assign({symbol:symbol, interval:interval}, options); + publicRequest(base+'v1/klines', params, function(data) { return callback.call(this, data, symbol); }); }, From 2433bdd6a34feba785c7bc89bcf1f90d031816c3 Mon Sep 17 00:00:00 2001 From: Jon Eyrick Date: Mon, 15 Jan 2018 04:01:27 -0800 Subject: [PATCH 2/2] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 355907be..47e8d376 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "node-binance-api", - "version": "0.3.8", + "version": "0.3.9", "description": "Binance API for node https://github.com/jaggedsoft/node-binance-api", "main": "node-binance-api.js", "dependencies": {