I used your code: def signalgenerator(df, symbol): if df is None or len(df) < 2: return…
- User
I used your code: def signal_generator(df, symbol): if df is None or len(df) < 2: return ''
code# Retrieve depth data depth_data = client.depth(symbol=symbol) bid_depth = depth_data['bids'] ask_depth = depth_data['asks'] # Check if bid and ask depths are not empty if not bid_depth or not ask_depth: return '' buy_price = float(bid_depth[0][0]) sell_price = float(ask_depth[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 buy_qty = sum(float(bid[1]) for bid in bid_depth) sell_qty = sum(float(ask[1]) for ask in ask_depth) # Find the top and bottom prices top_prices = [] bottom_prices = [] for bid in bid_depth: price = float(bid[0]) if price > sell_price: top_prices.append(price) for ask in ask_depth: price = float(ask[0]) if price < buy_price: bottom_prices.append(price) # Determine the current position if top_prices and mark_price >= max(top_prices): return 'sell' elif bottom_prices and mark_price <= min(bottom_prices): return 'buy' else: return ''But it doesn't give me any signals
- Assistant
The code you provided seems to be a signal generator function, which aims to generate trading signals based on depth data and current market prices. However, it's difficult to determine why you're not receiving any signals without further information about the input data and the intended behavior of the function.
Here are a few suggestions to troubleshoot the issue:
-
Check the input data: Make sure that the DataFrame (
df) and the symbol provided to the function are correct and contain the necessary depth data. -
Verify the connection: Ensure that you have a valid connection to the API and that you can retrieve the depth data and market prices successfully. You can try printing the retrieved data to verify its correctness.
-
Examine the logic: Review the logic of the signal generation process to ensure that it aligns with your desired behavior. Consider whether the conditions for determining the current position (
'sell'or'buy') are appropriate for your specific trading strategy.
-