Closing Open positions on Binance

12,568

Solution 1

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.

Solution 2

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

Share:
12,568
Casey Harrils
Author by

Casey Harrils

Currently engaging in my interests (Blockchain and Swing Trading). For Blockchain, working with DEFI and Full Stack technologies (ex: Docker, Python, Angular). With Swing Trading, I have a preference for using tools and indicators based on the use of Fibonacci (i.e. God's number: .618 / 1.618 ). Using a lot of Pinescript. During my past lives, I wrote code for NASA (saw lots of launches). I also lived in Europe for while (working at an IT company). During those times, my focus was on databases development/administration (ex: Oracle) and performance tuning ERP packages (ex: SAP).

Updated on June 17, 2022

Comments

  • Casey Harrils
    Casey Harrils about 2 years

    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!

  • Casey Harrils
    Casey Harrils about 4 years
    Thanks, I had started to see that
  • soung
    soung about 3 years
    I think TAKE_PROFIT_MARKET and STOP_MARKET are both Market order. can we close position with maker order type using closePosition ?