tiagosiebler / bybit-api

Node.js SDK for the Bybit APIs and WebSockets, with TypeScript & browser support.
https://www.npmjs.com/package/bybit-api
MIT License
244 stars 80 forks source link

Not understandable error #185

Closed oDYRASH closed 1 year ago

oDYRASH commented 1 year ago

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 "#".] { code: 'ERR_UNHANDLED_REJECTION' }

Your-Name-Here commented 1 year ago

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.

tiagosiebler commented 1 year ago

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

oDYRASH commented 1 year ago

Thank for your help, I find a solution !