python-binance icon indicating copy to clipboard operation
python-binance copied to clipboard

Cannot retrieve the type of the current position in OneWayMode

Open sh1l0n opened this issue 3 years ago • 3 comments

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?

sh1l0n avatar Jun 08 '21 21:06 sh1l0n

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

Karlheinzniebuhr avatar Jun 16 '22 19:06 Karlheinzniebuhr

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

Simply call client.get_position_v2()

sh1l0n avatar Jun 16 '22 21:06 sh1l0n

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')

Karlheinzniebuhr avatar Jun 17 '22 02:06 Karlheinzniebuhr