pythonbotsccxtbybitpython-bybit

Create market order on Bybit using CCXT with SL and TP using python?


Does anyone have an example of how to create a market order with take profit and stop loss?

I have been through the docs and because this is the first time i've done anything like this I don't really get it!

I have everything working except for actually placing the order!!

I can't get the stop loss to work, my active market order won't close

    symbol = 'BTC/USDT:USDT'
    sl = 20950
    
    params = dict(
        reduce_only = True,            
        leverage=1,
        stop_px = sl)

    order = exchange.create_order(symbol=symbol, type='limit', side='sell', amount=0.01, price=21100, params=params)

Solution

  • CCXT is currently adding support for stopLossPrice and takeProfitPrice

    You can create an order with a stop loss and take profit tied to the order like

    exchange.create_order(
        symbol='BTC/USDT:USDT',
        type='limit',
        side='sell',
        amount=0.01,
        price=21100,
        params={
            'leverage': 1,
            'stopLossPrice': 20950,
            'takeProfitPrice': 21950,
        },
    )