Bybit CCXT - Take Profit by Percentage

253 Views Asked by At

I'm trying to setup a simple take profit percentage 1% above the entry price.

I know how to code a successfully working defined "fixed price" take profit, where you state the 'actual take profit price', but what I want is to replace that with a command that places the take profit 1% greater than the buy entry option.

I'll post the three methods I've been trying below.

# Fetch market price for the ticker
    markets = bybit.load_markets(True)
    ticker_info = bybit.fetch_ticker(ticker)
    price = ticker_info['last']

**then calling it**

order = bybit.create_order(
            ticker,
            amount=amount,
            type='Market',
            side='buy',
            params={
                'reduce_only': False,
                'position_idx': 1,
                'tradeMode': 1,
                'cross': True,
                'buyLeverage': 7,
                'take_profit': round(price * 1.01, 2)
            }

This is the second route I tried to take when the above wouldn't work. This time, I tried to execute two orders.

     # Market Buy Order
        order = bybit.create_order(
            ticker,
            amount=amount,
            type='Market',
            side='buy',
            params={
                'reduce_only': False,
                'position_idx': 1,
                'tradeMode': 1,
                'cross': True,
                'buyLeverage': 7
            }
        )
    
        # Limit Sell Order, 1% above entry
        price = order['price'] * 1.01
        sell_order = bybit.create_order(
            ticker,
            amount=amount,
            type='Limit',
            side='sell',
            price=price,
            params={
                'reduce_only': True,
                'position_idx': 1,
                'tradeMode': 1,
                'cross': True,
                'sellLeverage': 7
                'time_in_force': 'GTC',
                'reduce_only': False,
                'close_on_trigger': True,
            }
        )
    
        return sell_order
    

Finally, and I've tried this:

     # Fetch market price for the ticker
        ticker_info = await bybit.fetch_ticker(ticker)
        price = ticker_info['last']
        
        # Trade Parameters
        params={
            'reduce_only': False,
            'position_idx': 1,
            'trade_mode': 'cross',  
            'leverage': 7,
            'tp_trigger_by': 'LastPrice',  
            'tp_price': round(price * 1.01, 2),
        }
        
        # Market Buy Order
        order = await bybit.create_order(
            symbol=ticker,
            amount=amount,
            type='market',
            side='buy',
            params=params
        )
        
        return order
0

There are 0 best solutions below