sammchardy / python-binance

Binance Exchange API python implementation for automated trading
https://python-binance.readthedocs.io/en/latest/
MIT License
5.89k stars 2.2k forks source link

Futures USDM - Unrealized Profit doesn't match. #1096

Open kevinyin9 opened 2 years ago

kevinyin9 commented 2 years ago

I am trading a specific pair multiple times and record the orderId.

Then, use these orderIds to get entry price (avgPrice) to calculate the unrealized profit.

My calculation formula is: (currentPrice - avgPrice) positionAmt positionSide

But the calculation result does not match the unRealizedProfit in futures_position_information().

No matter the currentPrice is markPrice or indexPrice, the results are unmatched. Sometimes the calculation results are even different from the positive and negative signs.

If you need, I can give some detail example.

Environment (please complete the following information):

Aarron-shaw commented 2 years ago

use

`def get_profit(price,current,qty, side ):

if side == 'BUY':

    profit = (current - price) * qty

if side == 'SELL':

    profit = (price - current) * qty

return profit

`

kevinyin9 commented 2 years ago

Thanks for replying.

But in my formula: (currentPrice - avgPrice) positionAmt positionSide.

I’ve already considered the position side, which would be 1 if it is buyside else -1.