sammchardy / python-binance

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

Cannot retrieve the type of the current position in OneWayMode #914

Open sh1l0n opened 3 years ago

sh1l0n commented 3 years ago

futures_position_information

If the user is in One-Way-Mode cannot know if the current position is LONG or SHORT. In Hedge-Mode its displayed.

Is any way to know it in OWM?

Karlheinzniebuhr commented 2 years ago

Here is an explanation but I wasn't able to apply it yet to python-binance. Did you solve it?

sh1l0n commented 2 years ago

Yes, but I used another library https://github.com/m4st3rb0ts/Binance_Futures_python

Simply call client.get_position_v2()

Karlheinzniebuhr commented 2 years ago

I ended up deducing the position side like this

# check if position is long or short
info = client.futures_position_information(symbol=symbol)

entryPrice = float(info[0]['entryPrice'])
markPrice = float(info[0]['markPrice'])
unRealizedProfit = float(info[0]['unRealizedProfit'])
quantity = abs(float(info[0]['positionAmt']))

positionSide = ''
if(entryPrice < markPrice):
    if(unRealizedProfit > 0):
        positionSide = 'long'
    if(unRealizedProfit < 0):
        positionSide = 'short'

if(entryPrice > markPrice):
    if(unRealizedProfit < 0):
        positionSide = 'long'
    if(unRealizedProfit > 0):
        positionSide = 'short'

print(f'positionSide: {positionSide}\n')