Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CCXT ByBit Close Position

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?

like image 787
Mohammad Adam Avatar asked Oct 16 '25 03:10

Mohammad Adam


1 Answers

Add reduceOnly to params to exit out of a futures order

symbol = 'SOLUSDT'
trade_res = exchange.create_order(symbol, amount=1, type='Market', side='sell', params={'reduceOnly': true})
like image 200
Sam Avatar answered Oct 18 '25 19:10

Sam