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 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: signals.append('bullish') elif sell_qty > buy_qty: signals.append('bearish') if signals == 'bullish' and float(mark_price) < buy_price: return 'buy' elif signals == 'bearish' and float(mark_price) > sell_price: return 'sell' else: return ''But it deosn't give me any signals
- Assistant
There seems to be an issue with your code. It looks like you are comparing
signalslist with the strings'bullish'and'bearish'using the equality operator (==). However,signalsis a list, so the comparison will always returnFalse.To fix this issue, you can change the comparison to check if
'bullish'or'bearish'are present in thesignalslist using theinoperator.Here's the updated 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 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: signals.append('bullish') elif sell_qty > buy_qty: signals.append('bearish') if 'bullish' in signals and float(mark_price) < buy_price: return 'buy' elif 'bearish' in signals and float(mark_price) > sell_price: return 'sell' else: return ''Make sure you have defined the
symbolandmark_pricevariables with appropriate values before calling thesignal_generatorfunction. - User
I used your code, but I getting ERROR: Traceback (most recent call last): File "c:\Users\Alan.vscode\jew_bot\jew_bot\jew_bot.py", line 169, in signals = signal_generator(df) ^^^^^^^^^^^^^^^^^^^^ File "c:\Users\Alan.vscode\jew_bot\jew_bot\jew_bot.py", line 147, in signal_generator if 'bullish' in signals and float(mark_price) < buy_price: ^^^^^^^^^^^^^^^^^ TypeError: float() argument must be a string or a real number, not 'dict'
- Assistant
The error message suggests that the
mark_pricevariable is of typedictinstead of a string or number. This is likely causing thefloat()function to throw aTypeError.To fix this issue, you need to ensure that the
mark_pricevariable is assigned a valid value before calling thesignal_generatorfunction. Check if you are correctly defining and initializing themark_pricevariable.Here's an example of how you can assign a dummy value to
mark_pricefor testing purposes:mark_price = 123.45 # Assign a dummy value # Call the signal_generator function with the appropriate inputs signals = signal_generator(df)Make sure to replace
123.45with the actual desired value ofmark_price.Additionally, ensure that the
symbolvariable is also defined and contains the correct symbol for fetching the depth data. - User
Am I need to remove brakets and float
- Assistant
Yes, if you are retrieving the
mark_pricevalue from a dictionary object, you don't need thefloat()function and brackets aroundmark_price.Here's the modified 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 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: signals.append('bullish') elif sell_qty > buy_qty: signals.append('bearish') if 'bullish' in signals and mark_price < buy_price: return 'buy' elif 'bearish' in signals and mark_price > sell_price: return 'sell' else: return ''Make sure that the
mark_pricevariable is properly assigned with the appropriate value before calling thesignal_generatorfunction.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.