Closed t-westwood closed 6 years ago
the files would be individual like writing to file for candlestick data etc
something like the code below, but to filter through all symbols? (and to save them to individual files)
binance.websockets.depthCache(["BTCUSDT"], function(symbol, depth) { let max = 10; // Only show the 10 best bids / asks (optional) let bids = binance.sortBids(depth.bids, max); let asks = binance.sortAsks(depth.asks, max); console.log(binance.reverse(asks)); // print asks console.log("ask: ", binance.first(asks)); console.log("bid: ", binance.first(bids)); console.log(bids); // print bids });
Yes you could do something like this
binance.prevDay(false, (error, prevDay) => {
let markets = [];
for ( let obj of prevDay ) {
markets.push(obj.symbol);
console.log(obj.symbol+" volume:"+obj.volume+" change: "+obj.priceChangePercent+"%");
}
// if there are problems here then some delay needs to be added before opening too many of these at once
binance.websockets.depthCache(markets, function(symbol, depth) {
let maximum = Infinity;
let baseValue = "cumulative"; // for charts
let bids = binance.sortBids(depth.bids, maximum, baseValue);
let asks = binance.sortAsks(depth.asks, maximum, baseValue);
console.log(symbol+" bids", bids);
console.log(symbol+" asks", asks);
let output = {
bids: binance.array(bids),
asks: binance.array(asks).reverse()
};
fs.writeFile("json/depth/"+symbol+".json", JSON.stringify(output, null, 4), function(err){});
});
});
Cheers bro!
No problem, just a note: "cumulative" is for drawing depth charts.
You can remove baseValue
entirely if that's not what you want.
https://github.com/jaggedsoft/node-binance-api/wiki/Converting-Depth-Data-to-Array
When running the code above, you was right, there was DEPTH CACHE OUT OF SYNC !!' ] errors popping up, but i changed the maximum's to 15 and no problems ;)
And to your above reply, i was only after the 15 bid/asks either side of the current price. I will have a play around with it.
Thanks again!
Hi dude,
When I use the code you gave me, after running it the once, I seem to be getting some kind of IP ban (i think (when i go to binance.com on my phone or via app, no data available, and when I try to run the websocket again i get the error below))
Should I add some kind of delay after a full cycle (when all currencies have been checked)? I'm only running this one websocket. To be honest i'm not too sure how the request's work with a websocket.
TypeError: prevDay is not iterable
at binance.prevDay (C:\Users\user\Documents\bot\testDepth.js:6:19)
at C:\Users\user\Documents\bot\node_modules\node-binance-api\node-binance-api.js:696:49
at Request._callback (C:\Users\user\Documents\bot\node_modules\node-binance-api\node-binance-api.js:63:24)
at Request.self.callback (C:\Users\user\Documents\bot\node_modules\request\request.js:186:22)
at emitTwo (events.js:126:13)
at Request.emit (events.js:214:7)
at Request.
Maybe I should have the websocket search /BTC symbols only, i'm guessing the requests then would be halved? Thanks JS
Hi JaggedSoft,
I was wondering if there was a way to websocket all currencies for the market depth and save the results to file?
Cheers bro