Closing Open positions on Binance
Question:
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!
Answers:
Also, when it is FILLED, my understanding is that a POSITION is being created (Long or Short)
As far as I know, Binance does not provide semantics for position (in terms of trading). Such abstractions are usually implemented for derivatives (e.g. futures) when it comes to currency markets, since currencies buying-and-selling-to-make-profit is not their only use.
On Binance, and most other cryptocurrency exchanges, you are making spot transactions, i.e. giving some amount of a currency to receive some amount of another currency. Plain and simple.
You may abstract positions yourself though, but that may involve much more work especially considering heterogeneous chains of transaction (e.g. BTC -> ETH -> USDT -> BTC
), partial fills, etc.
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
Spot trading doesn’t have positions like other instruments do because you are settling the trade immediately. When you place an order to buy btc using usdt and it becomes FILLED, that btc is immediately credited to your account.
if you sell usdt to buy btc then You should sell your btc to “close” the position.
The closet way to list a of “open spot positions” in the way you are thinking about it would be to get your balances via GET api/v3/account.
Quoted from the link below :
https://dev.binance.vision/t/closing-positions/221
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!
Also, when it is FILLED, my understanding is that a POSITION is being created (Long or Short)
As far as I know, Binance does not provide semantics for position (in terms of trading). Such abstractions are usually implemented for derivatives (e.g. futures) when it comes to currency markets, since currencies buying-and-selling-to-make-profit is not their only use.
On Binance, and most other cryptocurrency exchanges, you are making spot transactions, i.e. giving some amount of a currency to receive some amount of another currency. Plain and simple.
You may abstract positions yourself though, but that may involve much more work especially considering heterogeneous chains of transaction (e.g. BTC -> ETH -> USDT -> BTC
), partial fills, etc.
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
Spot trading doesn’t have positions like other instruments do because you are settling the trade immediately. When you place an order to buy btc using usdt and it becomes FILLED, that btc is immediately credited to your account.
if you sell usdt to buy btc then You should sell your btc to “close” the position.
The closet way to list a of “open spot positions” in the way you are thinking about it would be to get your balances via GET api/v3/account.
Quoted from the link below :
https://dev.binance.vision/t/closing-positions/221