I am using the Binance Python API (Python 3.x)
When one uses the “create_order” functionality, it creates an order on the SPOT exchange with a STATUS of NEW. When it gets filled, the STATUS goes to FILLED.
Also, when it is FILLED, my understanding is that a POSITION is being created (Long or Short)
My question is as follows: What endpoint can I use to get a list of the Open Positions.
Why do I want this? If a Position is on the SELL side, I would like to execute a BUY to close it. If a Position is on the BUY side, I would like to execute a SELL to close it.
Can this be done?
Any help, hints or advice would be ~greatly~ appreciated.
TIA
@michaeldel ETA: I am using this here: https://python-binance.readthedocs.io/en/latest/
For the Orders, I have been following: https://python-binance.readthedocs.io/en/latest/account.html?highlight=orders#orders
Can you note what the equivalent would be the equivalent under this (Python) API?
I have been using: "get_all_orders" with a focus of the "STATUS" being "FILLED". https://python-binance.readthedocs.io/en/latest/binance.html#binance.client.Client.get_all_orders
I was looking for Open Positions (not Orders)
If a BTCUSDT SELL Position that has status=FILLED with a origQty =.20, I want to be able to reverse it with a BUY and a Quantity of .20
If a BTCUSDT BUY Position has status=FILLED and a origQty=.30, I want to be able to reverse it with a SELL and a Quantity of .30
Does this make sense?
Is there a better way to do it? Am I missing something?
Thanks for the input!
For binance futures this feature was added at 2020-05-18!
With the STOP_MARKET
or TAKE_PROFIT_MARKET
you can use closePosition
param!
closePosition=true
As per the change long from the api doc here:
2020-05-18
New parameter closePosition for endpoint POST /fapi/v1/order: If a STOP_MARKET or TAKE_PROFIT_MARKET order with closePosition=true is triggered,all of the current long position( if SELL order) or current short position( if BUY order) will be closed.
New field closePosition in response to endpoints:
- POST /fapi/v1/order
- POST /fapi/v1/batchOrders
- GET /fapi/v1/order
- DELETE /fapi/v1/order
- DELETE /fapi/v1/batchOrders
- GET /fapi/v1/openOrder
- GET /fapi/v1/openOrders
- GET /fapi/v1/allOrders
Check the new order doc description