tiagosiebler / bybit-api

Node.js SDK for the Bybit APIs and WebSockets, with TypeScript & browser support.

Home Page:https://www.npmjs.com/package/bybit-api

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Question: is there a ContractClient.getPositions() equivalence for v5 ?

Badisi opened this issue · comments

commented

I'm looking for a way to get all the opened positions.
I've managed to get it working with ContractClient.getPositions() but can't find the equivalent in v5.
I've also spotted that bybit application is calling /contract/v5/position/list-all but couldn't find it in your code.
Is this api missing ?
Thanks!

commented

Where do you see list-all? This is the only endpoint I see for getting positions in v5:
https://bybit-exchange.github.io/docs/v5/position

Looking at the v5 rest client, I see I've mapped this to getPositionInfo():
https://github.com/tiagosiebler/bybit-api/blob/master/src/rest-client-v5.ts#L504

I realise I should have been consistent here with the naming, but seems some things did slip through the cracks! Either way, I think this is what you're looking for?

commented

As I didn't find the API I was looking for in v5, I had a look at the network from the testnet site.
That's where I found the list-all query.
But it's true that there is no such api in their doc either.
Screen Shot 2023-05-10 at 10 48 30

The difference between ContractClient.getPositions() and RestClientV5.getPositionInfo() is that the former can return the complete list of positions whereas the latter return an error. Either symbol or settleCoin is required. Which means that in normal account you can never get the complete list. And to be honest the API is named get Position(singular) Info so it makes completely sense.
Screen Shot 2023-05-10 at 10 54 26

The naming is consistent with their doc (expect maybe for other APIs like submitOrder instead of placeOrder, but that's another story). In this particular case I just have the feeling it is a missing API from their doc..

commented

Ah, the website does use a number of APIs that are not available for normal API usage (signed requests are not used for auth, they use cookies and session tokens/jwts instead). Not very usable and not designed to be used directly outside the website, unfortunately. Though if you find a reliable way to use them without fearing session expiry, I'd love to hear it!

Regarding settle coin, not sure if there's a misunderstanding but this is actually the base pair. E.g. if you're trading symbols paired with USDT, your settle coin would be USDT and you'd then see all positions you currently have for USDT. I do think this still gives you the functionality you're looking for. So you can still query all positions on the account, while being limited to a sub-group on the settle coin shared by those positions.

In case you aren't familiar with it, bybit also has a very active API-support group on telegram:
https://t.me/BybitAPI

While you're definitely asking in the right place for SDK-level questions (which endpoints map to what), their telegram group is also a great place to ask workflow and API usage questions, as well as voicing concerns & feedback.

commented

Thanks for the answer !
I'll stick with the settleCoin option then.
And nice work btw 😉