ViewBlock / binance-api-node

:chart: A complete and heavily tested wrapper with typings for the Binance API.
654 stars 495 forks source link

How do you get the current position info for future account? #634

Closed Sailendrakc closed 1 year ago

Sailendrakc commented 1 year ago

This is more of a question at this point. I was trying to get the information about current position I am in and there are no any existing methods for it. There is one websocket method called "futureUser" which logs all the activities.

const futuresUser = await client.ws.futuresUser(msg => {
  console.log(msg)
});

But this will only fire if i open or close a position and there is some change in position. I wont be able to retrive my current position with this.

Any workaround or suggestion would be helpful.

Sailendrakc commented 1 year ago

Found the solution.

There is a function called "futuresAccountInfo()". It will have all the information. It is not in the docs but there are lot of other helpful functions when you look in actual code. I found this function inside http-client.js as this query was more http request related than websocket related.

Usage:

let res = await client.futuresAccountInfo();
console.log(res); // res.positions has all available position of every pairs. It will have lof of empty positions, 
//just filter for pairs you need.