I used your code: def signalgenerator(df): if df is None or len(df) < 2: return ''…
- User
I used your code: def signal_generator(df): if df is None or len(df) < 2: return ''
signals = [] # Retrieve depth data 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 buy_qty = sum(float(bid[1]) for bid in bid_depth) sell_qty = sum(float(ask[1]) for ask in ask_depth) if buy_qty > sell_qty and buy_qty > mark_price: signals.append('sell') elif sell_qty > buy_qty and sell_qty > mark_price: signals.append('buy') if 'buy' in signals: return 'buy' elif 'sell' in signals: return 'sell' else: return ''But it giveing me only signal to sell
- Assistant
There could be a few reasons why the code is only returning signals to sell. Here are some potential issues to consider:
-
Data issue: Check if the depth data, bid_depth, ask_depth, and mark_price_data are being correctly retrieved and updated. Additionally, ensure that the data returned is in the expected format.
-
Logic issue: Verify if the logic for determining buy and sell signals is correct. Double-check the conditions used to append signals to the signals list. It's possible that the conditions are not being met for buy signals, resulting in only sell signals being appended to the list.
-
Symbol issue: Confirm that the correct symbol is being used when fetching depth data and ticker price. Make sure the symbol is the same as the one used in the client functions.
By reviewing these areas, you should be able to identify and resolve the issue causing the code to only generate sell signals.
-
- User
Lets tolk about logic issue , where is problem ? It need to give me signals to buy and sell
- Assistant
The logic issue in your code seems to be in the if conditions used to determine whether to append 'buy' or 'sell' signals to the signals list. Currently, the conditions check if the buy_qty is greater than the sell_qty and also greater than the mark_price for a 'sell' signal, and vice versa for a 'buy' signal.
However, this logic may not accurately capture the intention of your strategy. Here are a couple of potential fixes:
-
Update the conditions:
- To generate a 'sell' signal, you could check if the sell_qty is greater than the buy_qty, and also greater than the mark_price.
- To generate a 'buy' signal, you could check if the buy_qty is greater than the sell_qty, and also greater than the mark_price.
This way, the condition for generating each signal is independent of the other. The current logic might be causing the 'buy' condition to never be met, resulting in only 'sell' signals being appended to the list.
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.