binance-exchange / node-binance-api

Node Binance API is an asynchronous node.js library for the Binance API designed to be easy to use.
MIT License
528 stars 144 forks source link

Market Depth Chart - Total Orders #111

Closed amelenetwork closed 6 years ago

amelenetwork commented 6 years ago

Hello there...

This is not looks like issue but I don't know how can I do that . I hope anybody can answer to me.

On binance.com web site there is showing Depth Chart, there is total orders explaining on chart . You can check screen shot .

https://prnt.sc/inh55f

I need like this chart , Im getting data with;

binance.websockets.depthCache('BTCUSDT', (symbol, depth) => { ...... ...... });

But there is answer just price and quantity orders .

I'i doing SUM all BID or ASK orders then , step by step MINUS last one BACK to FORWARD .

It's looks like for me very "primitive" . Not looks like instant and taking time and cost .

Is there any good and modern option to get data MARKET DEPTH CHART ?

How can i do that ?

Thank you so much....

jaggedsoft commented 6 years ago

For this type of chart bids/asks are cumulative. So you add the btc value

image view code on jsfiddle

I have a websocket function to return the values in cumulative format I get the data like this:

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:bids, asks:asks};
    // save information to json file
    file.writeFile("json/depth/"+symbol+".json", JSON.stringify(output, null, 4), (err)=>{});
});
amelenetwork commented 6 years ago

You are amazing my friend .

Thank you so much !

jaggedsoft commented 6 years ago

Good luck! I just realized highcharts data needs to be in array format So you will need to do this instead:

let output = {bids:binance.array(bids), asks:binance.array(asks)};
amelenetwork commented 6 years ago

Thank you my friend .

i appreciate your help !