From 3a6d211132b4ae97457cb0a1fbe8d9f42f3dc1aa Mon Sep 17 00:00:00 2001 From: Zolzolwik Date: Tue, 5 Dec 2017 09:46:34 +0000 Subject: [PATCH 1/3] Added callback in done after subscribe --- node.bittrex.api.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/node.bittrex.api.js b/node.bittrex.api.js index 861b839..ab9d134 100644 --- a/node.bittrex.api.js +++ b/node.bittrex.api.js @@ -165,6 +165,7 @@ var NodeBittrexApi = function() { var websocketGlobalTickerCallback; var websocketMarkets = []; var websocketMarketsCallback; + var websocketMarketSubscribeDoneCallback; var connectws = function(callback, force) { if (wsclient && !force && callback) { @@ -256,6 +257,9 @@ var NodeBittrexApi = function() { if (result === true) { ((opts.verbose) ? console.log('Subscribed to ' + market) : ''); + if (websocketMarketSubscribeDoneCallback) { + websocketMarketSubscribeDoneCallback(market); + } } }); }); @@ -315,7 +319,8 @@ var NodeBittrexApi = function() { setMessageReceivedWs(); }); }, - subscribe: function(markets, callback) { + subscribe: function(markets, callback, doneCallback) { + websocketMarketSubscribeDoneCallback = doneCallback; connectws(function() { websocketMarkets = markets; websocketMarketsCallback = callback; From 9f460d676ad14dd92ca0d05b00a68017f237f9a4 Mon Sep 17 00:00:00 2001 From: zolzolwik <34268113+zolzolwik@users.noreply.github.com> Date: Tue, 5 Dec 2017 09:53:41 +0000 Subject: [PATCH 2/3] Update README.md Update README.md to include callback in 'done' function after subscribe which will allow to get order book after subscribe to market updates as suggested in https://github.com/n0mad01/node.bittrex.api/files/1104308/WebSocketAPI_MarketTracking.docx --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index cd03c27..d834f77 100644 --- a/README.md +++ b/README.md @@ -164,7 +164,12 @@ bittrex.options({ console.log('Market Update for '+ data_for.MarketName, data_for); }); } - }); + }, function(market) { + console.log('bittrex.getOrderBook now to keep in sync') + bittrex.getorderbook({ market : market, depth : 10, type : 'both' }, function( data, err ) { + console.log( data ); + }); + }; }, onDisconnect: function() { console.log('Websocket disconnected'); From 55574e0a132ff514f4154f2accb181ac6ecba642 Mon Sep 17 00:00:00 2001 From: zolzolwik <34268113+zolzolwik@users.noreply.github.com> Date: Tue, 5 Dec 2017 10:16:33 +0000 Subject: [PATCH 3/3] Update README.md Update README.md to include callback in 'done' function after subscribe which will allow to get order book after subscribe to market updates as suggested in https://github.com/n0mad01/node.bittrex.api/files/1104308/WebSocketAPI_MarketTracking.docx --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d834f77..b44553d 100644 --- a/README.md +++ b/README.md @@ -169,7 +169,7 @@ bittrex.options({ bittrex.getorderbook({ market : market, depth : 10, type : 'both' }, function( data, err ) { console.log( data ); }); - }; + }); }, onDisconnect: function() { console.log('Websocket disconnected'); @@ -218,6 +218,11 @@ bittrex.websockets.subscribe(['BTC-ETH','BTC-SC','BTC-ZEN'], function(data, clie console.log('Market Update for '+ data_for.MarketName, data_for); }); } +}, function(market) { + console.log('bittrex.getOrderBook now to keep in sync') + bittrex.getorderbook({ market : market, depth : 10, type : 'both' }, function( data, err ) { + console.log( data ); + }); }); ```