4

I am using ccxt to connect to ByBit and create orders.

symbol = 'SOLUSDT'
trade_res = exchange.create_order(symbol, amount=1, type='Market', side='Buy')

The above snippet buys 1 SOL against USDT. When I try to close the position by placing a sell order, I see that ByBit placed another Short position on SOL without closing the Long one (2 positions appear in the console):

enter image description here

How do I close a current position on ByBit using ccxt?

Mohammad Adam
  • 88
  • 1
  • 6

1 Answers1

5

Add reduce_only to params to exit out of a futures order

symbol = 'SOLUSDT'
trade_res = exchange.create_order(symbol, amount=1, type='Market', side='sell', params={'reduce_only': true})

On some exchanges, the parameter is reduceOnly

Sam
  • 1,765
  • 11
  • 82
  • 176