bybit-api icon indicating copy to clipboard operation
bybit-api copied to clipboard

Not understandable error

Open oDYRASH opened this issue 3 years ago • 2 comments

Hello there,

I'm facing this error while runing this code :

const { SpotClient } = require('bybit-api'); const ByBitSpotClient = new SpotClient();

ByBitSpotClient.getCandles({ symbol: 'BTCUSDT'}).then(res => console.log('Nb 5minutes candles :',res.result.length))

//////////////////////////ERROR///////////////////////////////// node:internal/process/promises:279 triggerUncaughtException(err, true /* fromPromise */); ^

[UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "#<Object>".] { code: 'ERR_UNHANDLED_REJECTION' }

oDYRASH avatar Oct 18 '22 17:10 oDYRASH

I don't see the actual error there so I can't help with that but you should always add a .catch( error => console.log( error.message )) after a .then(...)

Promise.then(...).catch(...)

Then you'll see the error message and be able to debug it easier.

Your-Name-Here avatar Oct 18 '22 18:10 Your-Name-Here

Hello,

As @Your-Name-Here said, an unhandled promise rejection happens when you're missing a catch handler.

Also, if you're looking to use bybit's spot apis, I really recommend using SpotClientV3 instead of SpotClient. It uses their newer V3 APIs (you should consider the SpotClient with the v1 APIs deprecated).

This also applies for the websocket client, where you should use the spotv3 market instead of spot. Example here: https://github.com/tiagosiebler/bybit-api/blob/master/examples/ws-public.ts#L19

tiagosiebler avatar Oct 18 '22 19:10 tiagosiebler

Thank for your help, I find a solution !

oDYRASH avatar Oct 23 '22 09:10 oDYRASH