Skip to content

Instantly share code, notes, and snippets.

@modster
Last active October 6, 2019 03:06
Show Gist options
  • Save modster/057c44412439659fa77191cd03ad6a60 to your computer and use it in GitHub Desktop.
Save modster/057c44412439659fa77191cd03ad6a60 to your computer and use it in GitHub Desktop.
Highchart market depth binance-node-api
// by jaggedsoft https://github.com/binance-exchange/node-binance-api/issues/111#issuecomment-370715955
const file = require('fs');
binance.websockets.depthCache(['BTCUSDT','BNBBTC'], (symbol, depth) => {
const limit = 1000;
let bids = binance.sortBids(depth.bids, limit, 'cumulative');
let asks = binance.sortAsks(depth.asks, limit, 'cumulative');
console.log(symbol+" depth cache update");
console.log("best bid: "+binance.first(bids));
console.log("best ask: "+binance.first(asks));
let output = {bids:binance.array(bids), asks:binance.array(asks)};
// save information to json file
file.writeFile("json/depth/"+symbol+".json", JSON.stringify(output, null, 4), (err)=>{});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment