askmike / gekko

A bitcoin trading bot written in node - https://gekko.wizb.it/
MIT License
10.07k stars 3.95k forks source link

Error handling Binance API response #1673

Closed ansonphong closed 6 years ago

ansonphong commented 6 years ago

Note: for support questions, please join our Discord server

After running smooth for about an hour, this error happened and Node crashed:

2018-01-12 10:55:23 (DEBUG):    Requested XRP/BTC trade data from Binance ...
C:\...\gekko\exchanges\binance.js:62
    if(!_.isEmpty(body.code)) {
                       ^

TypeError: Cannot read property 'code' of undefined
    at C:\...\gekko\exchanges\binance.js:62:24
    at Request.request [as _callback] (C:\...\gekko\node_modules\binance\lib\rest.js:66:21)
    at self.callback (C:\...\gekko\node_modules\request\request.js:188:22)
    at emitOne (events.js:116:13)
    at Request.emit (events.js:211:7)
    at Request.onRequestError (C:\...\gekko\node_modules\request\request.js:884:8)
    at emitOne (events.js:121:20)
    at ClientRequest.emit (events.js:211:7)
    at TLSSocket.socketErrorListener (_http_client.js:387:9)
    at emitOne (events.js:116:13)

I think this could be due to the Binance API call giving an undefined response, we might want to first check that the body is defined before processing it.

ipansensoy commented 6 years ago

is there any update about this error?

cmroche commented 6 years ago

It's possible that the Binance module changed something about their error handling again, I'll check it out over the weekend.

If that is the case, running npm install binance@1.0.2 should work around the issue for now.

cmroche commented 6 years ago

Ok actually this was simpler than that, a missing null check. I'll push a fix shortly.

ansonphong commented 6 years ago

Thanks @cmroche, yes that's how I ended up fixing it locally.