Search code examples
pythonbinance

Closing Open positions on Binance


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!


Solution

  • 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.