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

How to send data from server to client through WS #219

Closed denis0826 closed 6 years ago

denis0826 commented 6 years ago

Short Description:

Platform:

node version:

code

const SocketServer = require('ws').Server;
const binance = require('node-binance-api');
const wss = new SocketServer({ server });

wss.on('connection', function connection(ws) {

 binance.websockets.depthCache(symbol, (symbol, depth) => {
   ...
   if(ws.readyState === 1 ){
    ws.send(JSON.stringify(binanceData)); 
   }
  ...
  })

});

result

[0] C:\Users\ASUS\Desktop\REACT\marketMakerBot\node_modules\node-binance-api\node-binance-api.js:1638
[0]                         context.messageQueue = context.messageQueue.filter(depth => depth.u > context.snapshotUpdateId);
[0]                                                                     ^
[0]
[0] TypeError: Cannot read property 'filter' of undefined
[0]     at C:\Users\ASUS\Desktop\REACT\marketMakerBot\node_modules\node-binance-api\node-binance-api.js:1638:69
[0]     at Request._callback (C:\Users\ASUS\Desktop\REACT\marketMakerBot\node_modules\node-binance-api\node-binance-api.js:110:14)
[0]     at Request.self.callback (C:\Users\ASUS\Desktop\REACT\marketMakerBot\node_modules\request\request.js:185:22)
[0]     at Request.emit (events.js:160:13)
[0]     at Request.<anonymous> (C:\Users\ASUS\Desktop\REACT\marketMakerBot\node_modules\request\request.js:1157:10)
[0]     at Request.emit (events.js:160:13)
[0]     at IncomingMessage.<anonymous> (C:\Users\ASUS\Desktop\REACT\marketMakerBot\node_modules\request\request.js:1079:12)
[0]     at Object.onceWrapper (events.js:255:19)
[0]     at IncomingMessage.emit (events.js:165:20)
[0]     at endReadableNT (_stream_readable.js:1101:12)
dmzoneill commented 6 years ago

hey

you are using an old version of the API, please upgrade, this bug was fixed a number of versions back, i believe

thanks

https://github.com/jaggedsoft/node-binance-api/blob/2c79f587ebf37fd21522c6276bff551851411ee5/node-binance-api.js#L1638