简体   繁体   中英

how can I close position on OKX V5 based on CCXT Python?

I use this fuction : exchange.create_order(t[0][1], 'market', 'sell', 1, params={'reduceOnly': True}) can close positon on FTX, but I don't find the right way to deal on OKX exchange. Could you please let me know how to close postion on OKX?

OKX requires some specific parameters in order to open or close a position. Please check out this simple example:

Opening a long position:


symbol = "LTC/USDT:USDT" 
side = 'buy'
type = 'market'
amount = 1
price = None

exchange_params = {
  'tdMode': 'cross' # margin: is required to be either "isolated" or "cross",
  'posSide': 'long' # direction either long or short
}

open_position = exchange.create_order(symbol, type, side, amount, price, exchange_params)

After executing the snippet above a position in that market will be opened, if we want to close it we just need to issue an order in the opposite direction, something like this:

side = 'sell' # opposite side
exchange_params = {
  'tdMode': 'cross' # margin: is required to be either "isolated" or "cross",
  'posSide': 'long' # opposite direction now
}

# symbol, amount, type remain the same in this case

close_position = exchange.create_order(symbol, type, side, amount, price, exchange_params)

Let me know if you need any other clarification!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM