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

Implement upcoming V5 TPSL changes #261

Closed tiagosiebler closed 1 year ago

tiagosiebler commented 1 year ago

To further optimize users' trading experience, Bybit will upgrade the Take Profit/Stop Loss (TP/SL) feature of openAPI for USDT Perpetual, Inverse and USDC Contracts. This upgrade will be implemented on May 23 2023, 3AM UTC.

For details, please refer to https://announcements.bybit.com/en-US/article/derivatives-upgrade-of-take-profit-stop-loss-feature-blt741d9e5777be1c7e/ (already effective on WEB and APP). One thing has to be attention that openAPI does not support setting the trigger price of TP/SL orders by ROI or P&L.

The feature has been already available on testnet, feel free to have a try. https://bybit-exchange.github.io/docs/pilot-feature#new-tpsl

Below are openAPI changes:

  1. Place order: /v5/order/create, /contract/v3/private/order/create add request params: tpslMode, tpLimitPrice, slLimitPrice, tpOrderType, slOrderType

  2. Get open order: /v5/order/realtime, /contract/v3/private/order/unfilled-orders add response params: tpslMode, tpLimitPrice, slLimitPrice

  3. Get order history: /v5/order/history, /contract/v3/private/order/list add response params: tpslMode, tpLimitPrice, slLimitPrice

  4. Amend order: /v5/order/amend, /contract/v3/private/order/replace add request params: tpLimitPrice, slLimitPrice

  5. Get position info: /v5/position/list, /contract/v3/private/position/list tpslMode depreciated, always return 'Full' for Perpetual and Futures

  6. Set trading stop: /v5/position/trading-stop, /contract/v3/private/position/trading-stop add request params: tpslMode, tpLimitPrice, slLimitPrice, tpOrderType, slOrderType

  7. Websocket - Order stream (v5 / Contract v3): add response params: tpslMode, tpLimitPrice, slLimitPrice

  8. Websocket - Position stream (v5 / Contract v3) tpslMode depreciated, always return 'Full' for Perpetual and Futures

Haffelchen commented 1 year ago

Are there already plans on when this feature will be implemented in your API? Or is it already and I just missed it?

brlocky commented 1 year ago

@tiagosiebler

Can you try to add this endpoint, it gives the default trade setup for each coin.

https://api2-2-testnet.bybit.com/contract/v5/position/base-info?_sp_category=fbu&_sp_business=usdt

tiagosiebler commented 1 year ago

I'm checking all of this today and will add anything that's missing @Haffelchen @brlocky

tiagosiebler commented 1 year ago

Hey @brlocky - is that endpoint in the API docs? I don't see it anywhere

tiagosiebler commented 1 year ago

Are there already plans on when this feature will be implemented in your API? Or is it already and I just missed it?

@Haffelchen Hello, the next release will include these changes (via #267 - still WIP and checking things).

Haffelchen commented 1 year ago

Are there already plans on when this feature will be implemented in your API? Or is it already and I just missed it?

@Haffelchen Hello, the next release will include these changes (via #267 - still WIP and checking things).

Sounds good, thanks :) In the meantime I was able to already use the new parameters by just passing them anyways :D

brlocky commented 1 year ago

Hey @brlocky - is that endpoint in the API docs? I don't see it anywhere

Hi @tiagosiebler, Its not on the API docs, i found it when debug ByBit requests. Would be useful to avoid 1 request each time the symbol changes.

tiagosiebler commented 1 year ago

Hey @brlocky - is that endpoint in the API docs? I don't see it anywhere

Hi @tiagosiebler, Its not on the API docs, i found it when debug ByBit requests. Would be useful to avoid 1 request each time the symbol changes.

I see - do you have a list of params and values that it accepts? You could try using getPrivate(url, objectWithParams) on the rest client (e.g. RestClientV5) to try a raw request against it. If it's not documented, it might be that the signature auth mechanism doesn't work there.

If it does work there, I don't mind adding undocumented apis to the SDK as long as it's clearly warned that the endpoint is undocumented and may stop working at any time.

brlocky commented 1 year ago

Hey @brlocky - is that endpoint in the API docs? I don't see it anywhere

Hi @tiagosiebler, Its not on the API docs, i found it when debug ByBit requests. Would be useful to avoid 1 request each time the symbol changes.

I see - do you have a list of params and values that it accepts? You could try using getPrivate(url, objectWithParams) on the rest client (e.g. RestClientV5) to try a raw request against it. If it's not documented, it might be that the signature auth mechanism doesn't work there.

If it does work there, I don't mind adding undocumented apis to the SDK as long as it's clearly warned that the endpoint is undocumented and may stop working at any time.

Im skipping it for now once is not documented.