DeviaVir / zenbot

Zenbot is a command-line cryptocurrency trading bot using Node.js and MongoDB.
MIT License
8.21k stars 2.04k forks source link

Crash when unable to get the account balance. #2738

Open carlospaulino opened 2 years ago

carlospaulino commented 2 years ago

System information

Describe the problem

Sometimes, when the bot tries to get the latest balance from Kraken, the connection times out. When this happens, the bot crashes because the syncBalance function tries to destructure the quote property from an undefined value. So far, I've noticed that this only occurs when connected to Kraken.

Source code / Error logs

getBalance error:
RequestError: Timeout awaiting 'request' for 5000ms
    at ClientRequest.<anonymous> (/path/zenbot/node_modules/got/dist/source/core/index.js:956:65)
    at Object.onceWrapper (node:events:436:26)
    at ClientRequest.emit (node:events:341:22)
    at ClientRequest.origin.emit (/path/zenbot/node_modules/@szmarczak/http-timer/dist/source/index.js:39:20)
    at TLSSocket.socketErrorListener (node:_http_client:478:9)
    at TLSSocket.emit (node:events:329:20)
    at emitErrorNT (node:internal/streams/destroy:188:8)
    at emitErrorCloseNT (node:internal/streams/destroy:153:3)
    at processTicksAndRejections (node:internal/process/task_queues:80:21)
    at Timeout.timeoutHandler [as _onTimeout] (/path/zenbot/node_modules/got/dist/source/core/utils/timed-out.js:36:25)
    at listOnTimeout (node:internal/timers:558:17)
    at processTimers (node:internal/timers:499:7) {
  name: 'TimeoutError',
  code: 'ETIMEDOUT',
  timings: {
    start: 1626104365616,
    socket: 1626104365616,
    lookup: 1626104365617,
    connect: undefined,
    secureConnect: undefined,
    upload: undefined,
    response: undefined,
    end: undefined,
    error: 1626104370617,
    abort: undefined,
    phases: {
      wait: 0,
      dns: 1,
      tcp: undefined,
      tls: undefined,
      request: undefined,
      firstByte: undefined,
      download: undefined,
      total: 5001
    }
  },
  event: 'request'
}
/path/zenbot/lib/engine.js:378
    syncBalance(function (err, { quote }) {
                                 ^

TypeError: Cannot destructure property 'quote' of 'undefined' as it is undefined.
    at /path/zenbot/lib/engine.js:378:34
    at /path/zenbot/lib/engine.js:224:23
    at /path/zenbot/extensions/exchanges/kraken/exchange.js:155:18
    at /path/zenbot/node_modules/kraken-api/kraken.js:176:23
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (node:internal/process/task_queues:93:5)
carlospaulino commented 2 years ago

I am going to open a PR to address this issue.

Ayush-projects commented 2 years ago

Can i work on this issue?

carlospaulino commented 2 years ago

Can I work on this issue?

Of course, I've been swamped by work and haven't got the chance to address this issue.