Reputation: 93
I use the binance.client package to interact with the Binance API. There is a need to get active futures positions. That is, positions that are open, but there were no deals to close them. Everything I could find in the documentation returns the history of transactions, that is, it is impossible to tell from them whether all positions were closed or only part of them.
client.get_all_orders(symbol)
client.get_all_margin_orders(symbol)
Return this:
[]
[]
client.futures_get_all_orders(symbol)
Returns a list containing both purchase and sale positions. Therefore, it is impossible to say with certainty for what amount there is an open position now. An example of such data:
[{'orderId': 4438, 'symbol': 'BTCUSDT', 'status': 'FILLED', 'clientOrderId': 'XY7J7nhdGPWi6mu', 'price': '0', 'avgPrice': '37179.70000', 'origQty': '0.001', 'executedQty': '0.001', 'cumQuote': '37.17870', 'timeInForce': 'GTC', 'type': 'MARKET', 'reduceOnly': False, 'closePosition': False, 'side': 'BUY', 'positionSide': 'LONG', 'stopPrice': '0', 'workingType': 'CONTRACT_PRICE', 'priceProtect': False, 'origType': 'MARKET', 'time': 164549023, 'updateTime': 164549023},
{'orderId': 3458, 'symbol': 'BTCUSDT', 'status': 'FILLED', 'clientOrderId': '1zpqZVxYgYyfD', 'price': '0', 'avgPrice': '37219.90000', 'origQty': '0.001', 'executedQty': '0.001', 'cumQuote': '37.21890', 'timeInForce': 'GTC', 'type': 'MARKET', 'reduceOnly': True, 'closePosition': False, 'side': 'SELL', 'positionSide': 'LONG', 'stopPrice': '0', 'workingType': 'CONTRACT_PRICE', 'priceProtect': False, 'origType': 'MARKET', 'time': 16454903, 'updateTime': 16454903},
{'orderId': 4396, 'symbol': 'BTCUSDT', 'status': 'FILLED', 'clientOrderId': 'iKlNyjk7yaKtBo', 'price': '0', 'avgPrice': '36854.30000', 'origQty': '0.001', 'executedQty': '0.001', 'cumQuote': '36.74630', 'timeInForce': 'GTC', 'type': 'MARKET', 'reduceOnly': False, 'closePosition': False, 'side': 'BUY', 'positionSide': 'LONG', 'stopPrice': '0', 'workingType': 'CONTRACT_PRICE', 'priceProtect': False, 'origType': 'MARKET', 'time': 164551553, 'updateTime': 164551553}]
Upvotes: 0
Views: 4067
Reputation: 11
.get_position
https://github.com/Binance-
docs/Binance_Futures_python/blob/master/example/trade/get_position.py
Upvotes: 1