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 = [] # Retrieve depth data threshold = 0.1 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 = float(bid_depth[0][1]) if bid_depth else 0.0 sell_qty = float(ask_depth[0][1]) if ask_depth else 0.0 if sell_qty > (buy_qty * (1 + threshold)): signal.append('sell') elif buy_qty > (sell_qty * (1 + threshold)): signal.append('buy') else: signal.append('') if not signal: # If signal list is empty signal.append('') # Append an empty string return signalBut it doesn't return me '' in terminal
- Assistant
There could be several reasons why the code is not returning an empty string in the terminal. Here are a few things you can check:
-
Check if the
dfparameter passed to thesignal_generatorfunction isNoneor has a length less than 2. If either of these conditions is true, the function will simply return an empty string, which might explain why you're not seeing any output in the terminal. -
Ensure that the
symbolvariable used in the code is defined and that yourclientobject has the necessary methods (depthandticker_price) to retrieve the required data. If these variables or methods are not defined correctly, it may result in an error or incorrect data. -
Double-check that the API you are using is returning the expected data in the
depth_dataandmark_price_datavariables. You can print the values of these variables to verify if the data is being retrieved correctly. -
Make sure that you are calling the
signal_generatorfunction correctly and providing a valid parameter when invoking it.
-