I used this code : def signalgenerator(df): if df is None or len(df) < 2: return ''…
- User
I used this code :
def signal_generator(df): if df is None or len(df) < 2: return ''
signal = [] shabat = [] # 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 for buy_price in bid_depth: order_price = float(buy_price[0]) # Update the order_price assignment executed_orders_qty = order_price == mark_price # Subtract executed order quantity from buy_qty buy_result = buy_qty - executed_orders_qty for sell_price in ask_depth: order_price = float(sell_price[0]) # Update the order_price assignment executed_orders_qty = order_price == mark_price # Subtract executed order quantity from buy_qty sell_result = sell_qty - executed_orders_qty 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 if (sell_result > (1 + threshold) > buy_qty) and (sell_price < mark_price - price_threshold): signal.append('sell') elif (buy_result > (1 + threshold) > sell_qty) and (buy_price > mark_price + price_threshold): signal.append('buy') else: signal.append('') if signal == ['sell'] and ((sell_result < 0.01 + buy_qty) and (sell_price > mark_price)): shabat.append('') elif signal == ['buy'] and ((buy_result < 0.01 + sell_qty) and (buy_price < mark_price)): shabat.append('') return shabatBut it dosn't give me any signals
- Assistant
There could be several reasons why you're not getting any signals from this code. Here are a few potential issues to consider:
-
Data availability: Ensure that the
dfvariable is a valid DataFrame object with the necessary data for signal generation. If it's empty or doesn't contain the required information, the function may return an empty string as specified in the code. -
Data retrieval: Check if you are successfully retrieving the depth data, bid depth, ask depth, buy price, sell price, mark price, and mark price data change from the API. It's possible that there may be an error in retrieving this data, causing the signal generation logic to fail.
-
Threshold values: Confirm that the threshold values (such as
threshold,mark_price_percent, andprice_threshold) are correctly set based on your specific requirements. If these values are not properly configured, it could affect the signal generation conditions and lead to no signals being generated.
-