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 = client.ticker_price(symbol=symbol) 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 ''But I getting ERROR: Traceback (most recent call last): File "c:\Users\Alan.vscode\jew_bot\jew_bot\jew_bot.py", line 167, 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 being a string or a real number.To fix this issue, you need to ensure that
mark_priceis assigned the correct value. It seems like you are using theclient.ticker_price()function to retrieve the mark price. Make sure to check the documentation or the implementation of this function to ensure it returns a float.For example, you could modify your code as follows:
mark_price_data = client.ticker_price(symbol=symbol) mark_price = float(mark_price_data['price']) if 'price' in mark_price_data else 0.0This assumes that the
client.ticker_price()function returns a dictionary with a key called'price'that holds the mark price value. If the key does not exist, it setsmark_priceto 0.0. Adjust this logic based on the actual response format from the API you are using.With this fix, the
mark_pricevariable should now be a float, and the error should be resolved.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.