CCXT ByBit Close Position

Viewed 1813

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?

1 Answers

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

Related