jaggedsoft / node-binance-api

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

Error in displaying different cryptocurrencies -- depthCache #239

Closed marccasco closed 6 years ago

marccasco commented 6 years ago

Title

Short Description:

Platform:

node version:

Long descrption

code

binance.websockets.depthCache([coin], (symbol, depth) => {
        let bids = binance.sortBids(depth.bids);
        let asks = binance.sortAsks(depth.asks);
        demanda = binance.first(bids);
        oferta = binance.first(asks);
        socket.emit('preuoferta', {number: oferta});
        socket.broadcast.emit('preuoferta', {number: oferta});
        socket.emit('preudemanda', {number: demanda});
        socket.broadcast.emit('preudemanda', {number: demanda});
      }); 

result

**I add, that when visualizing in the html, I see the two intertwined in the same field.**

Thank you very much and sorry for the inconvenience

marccasco commented 6 years ago

I add:

I'm trying to do it with the prevDay, and closing the connection and neither.

Example: binance.websockets.terminate ('ethbtc @ ticker');

Answer: ['WebSocket closed: ethbtc @ ticker (1006)']

But the same thing keeps happening to me,

Thank you.

jaggedsoft commented 6 years ago

I can not reproduce your issue, sorry. Here is what I do:

  1. Subscribe to websocket depth cache for the symbols you are interested in
  2. Write to json every update
  3. View json files in your webserver
binance.websockets.depthCache(['BTCUSDT', 'BNBBTC'], (symbol, depth) => {
    const limit = 500;
        // Note: 'cumulative' is meant for drawing a depth chart, remove if you want it just like the order book
    let bids = binance.sortBids(depth.bids, limit, 'cumulative');
    let asks = binance.sortAsks(depth.asks, limit, 'cumulative');
    console.log(bids,asks);
    //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)};
    //console.log(symbol,output);

    // save information to json file
    fs.writeFile("json/depth/"+symbol+".json", JSON.stringify(output, null, 4), (err)=>{});
});

Using prevDay to get information on all symbols

binance.prevDay(false, (error, prevDay) => {
    for ( let obj of prevDay ) {
        let symbol = obj.symbol;
        console.log(symbol+" volume:"+obj.volume+" change: "+obj.priceChangePercent+"%");
    }
    fs.writeFile("json/prevDay.json", JSON.stringify(prevDay, null, 4), (err)=>{});
});