I used this code: 
df = client.depth(symbol=symbol)

def signal_generator(df):
    if df is None or len(df) < 2:
        return ''
    
    signal = []

    # Retrieve depth data
    threshold = 0.35
    depth_data = client.depth(symbol=symbol)
    bid_depth = depth_data['bids']
    ask_depth = depth_data['asks']
    buy_price = float(bid_depth[0][0]) if bid_depth else 0.0
    sell_price = float(ask_depth[0][0]) if ask_depth else 0.0
    mark_price_data = client.ticker_price(symbol=symbol)
    mark_price = float(mark_price_data['price']) if 'price' in mark_price_data else 0.0
    mark_price_data_change = client.ticker_24hr_price_change(symbol=symbol)
    mark_price_percent = float(mark_price_data_change['priceChangePercent']) if 'priceChangePercent' in mark_price_data_change else 0.0

    buy_qty = float(bid_depth[0][1]) if bid_depth else 0.0
    sell_qty = float(ask_depth[0][1]) if ask_depth else 0.0

    # Calculate the threshold for order price deviation
    if mark_price_percent > 2:
        price_threshold = 5 / 100
    elif mark_price_percent < -2:
        price_threshold = 5 / 100
    else:
        price_threshold = 4 / 100

    if (sell_qty > (1 + threshold) > buy_qty) and (sell_price < mark_price - price_threshold):
        signal.append('sell')
    elif (buy_qty > (1 + threshold) > sell_qty) and (buy_price > mark_price + price_threshold):
        signal.append('buy')
    else:
        signal.append('')

    return signal
    
secret_key = API_KEY_BINANCE
access_key = API_SECRET_BINANCE

lookback = 10080
active_signal = None
buy_entry_price = None 
sell_entry_price = None

import binance

def calculate_percentage_difference_buy(entry_price, exit_price):
    result = exit_price - entry_price
    price_result = entry_price / 100 
    final_result = result / price_result
    result = final_result * 50
    return result

def calculate_percentage_difference_sell(sell_entry_price, sell_exit_price):
    percentage_difference = sell_entry_price - sell_exit_price
    price_result = sell_entry_price / 100  # price result = 1%
    price_percent_difference = percentage_difference / price_result
    result = price_percent_difference * 50
    return result

while True:
    if df is not None:
        quantity = bch_amount_rounded
        signals = signal_generator(df)
        mark_price_data = client.ticker_price(symbol=symbol)
        mark_price = float(mark_price_data['price']) if 'price' in mark_price_data else 0.0
        if signals == ['buy'] or signals == ['sell']:
            print(f"The signal time is: {dt.datetime.now().strftime('%Y-%m-%d %H:%M:%S')}, Price {mark_price} - Signals: {signals}")

            if 'buy' in signals and active_signal != 'buy':
                try:
                    active_signal = 'buy'
                    buy_entry_price = mark_price  # Record the Buy entry price
                    print(f"Buy Entry Price: {buy_entry_price}")
                    # Execute Buy orders here
                    client.new_order(symbol=symbol, side='BUY', type='MARKET', quantity=quantity)
                    client.new_order(symbol=symbol, side='BUY', type='MARKET', quantity=quantity)
                    print("Long order executed!")
                except binance.error.ClientError as e:
                    print(f"Error executing long order: ")

                if sell_entry_price is not None and buy_entry_price is not None:
                    sell_exit_price = mark_price
                    difference_sell = calculate_percentage_difference_sell(sell_entry_price, sell_exit_price)
                    profit_sell = difference_sell 
                    total_profit_sell = profit_sell
                    profit_sell_percent = total_profit_sell - 4
                    print(f"sell entry price {sell_entry_price}, sell exit price {sell_exit_price} , Sell P&L: {round(total_profit_sell, 2)}%   with fee {round(profit_sell_percent, 2)}%")
                else:
                    print("Sell Entry price or Buy Entry price is not defined.")

            elif 'sell' in signals and active_signal != 'sell':
                try:
                    active_signal = 'sell'
                    sell_entry_price = mark_price  # Record the sell entry price
                    print(f"Sell Entry Price: {sell_entry_price}")
                    # Execute sell orders here
                    client.new_order(symbol=symbol, side='SELL', type='MARKET', quantity=quantity)
                    client.new_order(symbol=symbol, side='SELL', type='MARKET', quantity=quantity)
                    print("Short order executed!")
                except binance.error.ClientError as e:
                    print(f"Error executing short order: ")
                if buy_entry_price is not None and sell_entry_price is not None:
                    buy_exit_price = mark_price
                    difference_buy = calculate_percentage_difference_buy(buy_entry_price, buy_exit_price)
                    profit_buy = difference_buy 
                    total_profit_buy = profit_buy
                    profit_buy_percent = total_profit_buy - 4
                    print(f"buy entry price {buy_entry_price}, buy exit price: {sell_entry_price}, Buy P&L: {round(total_profit_buy, 2)}%   with fee {round(profit_buy_percent, 2)}%")
                else:
                    print("Buy Entry price or Sell Entry price is not defined.")

    time.sleep(1)