How to get the pnl in realtime (websocket) on a open position ?

Hello,
I am working with future APIs.
I was wondering if it was possible to retrieve the PnL and the margin ratio on a current position via websocket streaming?

If it’s not possible, the only way to get it would be to get the price of the asset in parallel and calculate locally the PnL with the entry price of our position, right?

I’m currently using this stream :


But I receive messages only when a new position is added, or when a position is closed. I also expected to receive messages about the PnL update as well.

How is it posiible that such. renowned exchange leaves the critical part of a trade to a rest call that will probably create delays in calculations.

didtn it make sense to you guys to include this as part of the sockestreams ?

Unrealized PNL keeps changing. If you want to get it, read this https://binance-docs.github.io/apidocs/futures/en/#position-information-v2-user_data and call rest api.

Regarding MR, it equals maintenance margin/margin balance. You can read this - https://binance-docs.github.io/apidocs/futures/en/#account-information-v2-user_data and call the API to retrieve that data

Yes I am aware that it is possible to retrieve this information via the REST api, but the ideal in my case would have been via websocket. I need to display this information on a web platform, the user must be able to see in real time his gains and losses.

I don’t think calling the endpoint via the REST api every second is the ideal solution, so I think I just have to calculate all this information locally, right?

For example, if the user is in a BTC/USDT position, I have to subscribe via websocket and get the market price updates, then get the entry price of the current position, and calculate the PnL with these two variables. Do you see a better alternative?
Thank you very much

1 Like

I’m in the same situation, did you find a solution?

1 Like

As specified above I did it like this:
“For example, if the user have a BTC/USDT position, I have to subscribe via websocket and get the market price updates, then get the entry price of the current position, and calculate the PnL with these two variables”

1 Like

That’d be your best option