tiagosiebler / binance

Node.js & JavaScript SDK for Binance REST APIs & WebSockets, with TypeScript & browser support, integration tests, beautification & more.
MIT License
763 stars 265 forks source link

onUserData example not properly working. #98

Closed thisisloze closed 3 years ago

thisisloze commented 3 years ago

I have tried the onUserData example in the manual. This is the message I get after I have connected to the ws. Here is my code: const binanceWS = new api.BinanceWS(true); const ret = binanceWS .onUserData( this.binance, data => { //console.log(data); }, 60000 ) // Optional, how often the keep alive should be sent in milliseconds .then(ws => { console.log(ws) });

Here is what happens.

WebSocket { _events: [Object: null prototype] { message: [Function], error: [Function] }, _eventsCount: 2, _maxListeners: undefined, readyState: 0, bytesReceived: 0, extensions: {}, protocol: '', _binaryType: 'nodebuffer', _finalize: [Function: bound finalize], _closeFrameReceived: false, _closeFrameSent: false, _closeMessage: '', _closeTimer: null, _finalized: false, _closeCode: 1006, _receiver: null, _sender: null, _socket: null, _ultron: null, protocolVersion: 13, _isServer: false, url: 'wss://stream.binance.com:9443/ws/6ios2GAP9wkLT8IjkxMuzQNSpgH7kBuCf1a1oxxIQ5fVFIoQcySeYmfnEf5D', _req: ClientRequest { _events: [Object: null prototype] { socket: [Function], error: [Function], response: [Function], upgrade: [Function] }, _eventsCount: 4, _maxListeners: undefined,

 I have left it open while I made some trades to see if there was any messages sent. There was not.
theNodeMan commented 3 years ago

Same here.

At first I though it was not communicating with the testnet and updated lib/ws.js to be able to set the testnet endpoints, but the issue reproduced in both cases

baseUrl = 'wss://stream.binance.com:9443/ws/', combinedBaseUrl = 'wss://stream.binance.com:9443/stream?streams='

and

baseUrl: 'wss://testnet.binance.vision/ws', combinedBaseUrl: 'wss://testnet.binance.vision/stream?streams'

Part of ws.js

class BinanceWS { constructor({ beautify = true, baseUrl = 'wss://stream.binance.com:9443/ws/', combinedBaseUrl = 'wss://stream.binance.com:9443/stream?streams=' }) { this._baseUrl = baseUrl; this._combinedBaseUrl = combinedBaseUrl; this._sockets = {}; this._beautifier = new Beautifier(); this._beautify = beautify;

tiagosiebler commented 3 years ago

Fixed in #122 - check the example here: https://github.com/tiagosiebler/binance/blob/v2.0.0/beta/examples/ws-userdata.ts