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

getOpenOrders() don't return SL/TP order (limit trigger market Sell) #187

Closed oDYRASH closed 1 year ago

oDYRASH commented 1 year ago

const { SpotClientV3 } = require('bybit-api');

const client = new SpotClientV3({ key: API_KEY, secret: PRIVATE_KEY })

client.getOpenOrders("BTCUSDT").then(res => { console.log(res) }) // { // retCode: 0, // retMsg: 'OK', // result: { list: [] }, // retExtInfo: null, // time: 1666517676056 // }

EVEN IF : It return limit buy order correctly

2nd problem : When I use cancelOrder({orderId:orderId}) with the id of a SL order it return "This ordder doesn't exist"

tiagosiebler commented 1 year ago

I've pushed a fix in v3.1.2 to add the new params to each method. It should be available on npm in a few minutes as soon as the CI run finishes.

Looks like each affected spot v3 endpoint now has a orderCategory parameter. 0 is the default for normal orders, 1 lets you see tp/sl orders (and is required if you want to interact with that order type): https://bybit-exchange.github.io/docs/spot/v3/#t-getactive

In the case of getOpenOrders, I've added a 4th parameter for it. It's a bit awkward on this method since the other params might be optional, so here's how you would set the symbol and order category without setting the rest:

client.getOpenOrders("BTCUSDT", undefined, undefined, 1)

or in a more readable format:

const symbol = "BTCUSDT";
const orderId = undefined;
const limitPerPage = undefined;
const orderCategory = 1;
client.getOpenOrders(symbol, orderId, limitPerPage, orderCategory);
oDYRASH commented 1 year ago

I've pushed a fix in v3.1.2 to add the new params to each method. It should be available on npm in a few minutes as soon as the CI run finishes.

Looks like each affected spot v3 endpoint now has a orderCategory parameter. 0 is the default for normal orders, 1 lets you see tp/sl orders (and is required if you want to interact with that order type): https://bybit-exchange.github.io/docs/spot/v3/#t-getactive

In the case of getOpenOrders, I've added a 4th parameter for it. It's a bit awkward on this method since the other params might be optional, so here's how you would set the symbol and order category without setting the rest:

client.getOpenOrders("BTCUSDT", undefined, undefined, 1)

or in a more readable format:

const symbol = "BTCUSDT";
const orderId = undefined;
const limitPerPage = undefined;
const orderCategory = 1;
client.getOpenOrders(symbol, orderId, limitPerPage, orderCategory);

Hello tiagosiebler,

Thank for this quick reactivity !

code I ran: client.getOpenOrders("BTCUSDT", undefined, undefined, 1).then(res => { console.log(res) })

Error returned:

{ retCode: 10004, retMsg: 'Signature for this request is not valid.', result: null, retExtInfo: null, time: 1666522700485 }

npm version: +-- bybit-api@3.1.2

tiagosiebler commented 1 year ago

Strange, that should have worked since it matches the doc spec: https://bybit-exchange.github.io/docs/spot/v3/#t-getactive

Shouldn't be the undefined params causing the problem, since they're removed from the request before the request is sent: https://github.com/tiagosiebler/bybit-api/blob/master/src/util/BaseRestClient.ts#L184-L188

Will need to investigate...

tiagosiebler commented 1 year ago

Can you try the new param as a string? client.getOpenOrders("BTCUSDT", undefined, undefined, "1")

If you're using typescript, you can cast to any just to test this:

client.getOpenOrders("BTCUSDT", undefined, undefined, "1" as any)
oDYRASH commented 1 year ago

Still not working for me :/ I hope a fixe comming soon, good luck !

tiagosiebler commented 1 year ago

Still not working for me :/ I hope a fixe comming soon, good luck !

I've found the reason. It's related to the signature process. The newer v3 APIs from bybit behave differently about the order of parameters (sorted alphabetically or not) compared to the older APIs.

Fix will be on npm shortly under v3.1.3, as soon as #190 is merged and finishes tests/building. Can you let me know once you've had a chance to test?

oDYRASH commented 1 year ago

Still not working for me :/ I hope a fixe comming soon, good luck !

I've found the reason. It's related to the signature process. The newer v3 APIs from bybit behave differently about the order of parameters (sorted alphabetically or not) compared to the older APIs.

Fix will be on npm shortly under v3.1.3, as soon as #190 is merged and finishes tests/building. Can you let me know once you've had a chance to test?

Well played !

It's now working for me :)

tiagosiebler commented 1 year ago

Well played !

It's now working for me :)

thanks for confirming, glad to hear it