I used this code: 

def signal_generator(df):
    if df is None or len(df) < 2:
        return ''
    
    signal = []
    final_signal = []
    exit = []
    sell_result = 0.0
    buy_result = 0.0

    mark_price_data = client.ticker_price(symbol=symbol)
    mp = 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


    # Retrieve depth data
    depth_data = client.depth(symbol=symbol)
    
    bids = depth_data['bids']
    bid_prices = [float(bid[0]) for bid in bids]
    highest_bid_price = max(bid_prices)
    lowest_bid_price = min(bid_prices)
    b_l = lowest_bid_price > mark_price + (mark_price / 100)
    b_h = highest_bid_price > mark_price + ((mark_price / 100) * 2)

    asks = depth_data['asks']
    ask_prices = [float(ask[0]) for ask in asks]
    highest_ask_price = max(ask_prices)
    lowest_ask_price = min(ask_prices)
    s_l = lowest_ask_price < mark_price - ((mark_price / 100) * 2)
    s_h = highest_ask_price < mark_price - (mark_price / 100)

    y_qty = round(sum(float(bid[1]) for bid in bids), 0)
    l_qty = round(sum(float(ask[1]) for ask in asks), 0)

    #Quantity
    for bid in bids:
        price_buy = float(bid[0])
        qty_buy = float(bid[1])
        if not price_buy < mark_price + (mark_price / 100):
            buy_qty = y_qty - qty_buy

    for ask in asks:
        price_sell = float(ask[0])
        qty_sell = float(ask[1])
        if not price_sell > mark_price - (mark_price / 100):
            sell_qty = l_qty - qty_sell

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

    # Subtract quantity if bid price is the same as mark price
    for bid in bids:
        price_buy = float(bid[0])
        qty_buy = float(bid[1])
        if price_buy == mark_price:
            buy_result = buy_qty - qty_buy
        br = buy_result

    # Subtract quantity if bid price is the same as mark price
    for ask in asks:
        price_sell = float(ask[0])
        qty_sell = float(ask[1])
        if price_sell == mark_price:
            sell_result = sell_qty - qty_sell
        sr = sell_result
    
    if mark_price_percent > 2:
        th = 20000
    elif mark_price_percent < -2:
        th = 20000
    else:
        th = 15000
        
    #Main Signal
    if (((buy_qty > th) > (sell_qty < th)) and (b_l > mp + pth)):
        signal.append('buy')
    elif (((sell_qty > th) > (buy_qty < th)) and (s_h < mp - pth)):
        signal.append('sell')
    else:
        signal.append('')

    #Signal confirmation
    if signal == ['buy'] and not (((br < th) < sell_qty) and (b_l < mp + pth)):
        final_signal.append('buy')
    elif signal == ['sell'] and not (((sr < th) < buy_qty) and (s_h > mp - pth)):
        final_signal.append('sell')
    else:
        final_signal.append('')

    #Exit
    if final_signal == ['buy'] and (((br < th) < sell_qty) and (b_h < mp + pth)):
        exit.append('buy_exit')
    elif final_signal == ['sell'] and (((sr < th) < buy_qty) and (s_l > mp - pth)):
        exit.append('sell_exit')
    else:
        exit.append('')

    samerkh = exit and final_signal

    return samerkh


But terminal returned me: Traceback (most recent call last):
  File "c:\Users\Alan\.vscode\jew_bot\jew_bot\jew_bot.py", line 230, in <module>
    signals = signal_generator(df)
              ^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\Alan\.vscode\jew_bot\jew_bot\jew_bot.py", line 138, in signal_generator        
    buy_result = buy_qty - qty_buy
                 ^^^^^^^
UnboundLocalError: cannot access local variable 'buy_qty' where it is not associated with a value