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
259 stars 83 forks source link

Socket / Webhook notification upon opened trade? #253

Closed mmaestrini closed 1 year ago

mmaestrini commented 1 year ago

Hi everyone,

is it possible to get a notification whether via socket/webhook whenever a trade is opened?

I guess currently what I would have done is just ping the open orders with some regularity (every couple of seconds i guess).. Any help is appreciated :)

tiagosiebler commented 1 year ago

Hi @mmaestrini

Yes, pretty much all the major exchanges have websocket topics for this. For bybit, take a look at this example with the WebsocketClient in the SDK: https://github.com/tiagosiebler/bybit-api/blob/master/examples/ws-private-v5.ts

The calls to subscribeV5() subscribe to different topics. You can see a list of topics in bybit's api docs - e.g. you'll probably want the position or execution topic: https://bybit-exchange.github.io/docs/v5/websocket/private/position

Events on all subscribed topics come through the 'update' event in the ws client: https://github.com/tiagosiebler/bybit-api/blob/master/examples/ws-private-v5.ts#L35-L38

tiagosiebler commented 1 year ago

Will close this for now. If there's further questions or if you notice any issues, feel free to open a new issue. Thanks!

mmaestrini commented 1 year ago

Hey Tiago! thanks a ton, found it !

Appreciate the help!