I used this code: def signalgenerator(df): "Shalom. Signals are from here !" if df is…
- User
I used this code: def signal_generator(df): "Shalom. Signals are from here !" if df is None or len(df) < 2: return ''
signal = [] final_signal = [] exit = [] mark_price_data = client.ticker_price(symbol=symbol) mp = float(mark_price_data['price']) if 'price' in mark_price_data else 0.0 mark_price_data_change = client.ticker_24hr_price_change(symbol=symbol) mark_price_percent = float(mark_price_data_change['priceChangePercent']) if 'priceChangePercent' in mark_price_data_change else 0.0 # Retrieve depth data depth_data = client.depth(symbol=symbol) bids = depth_data['bids'] asks = depth_data['asks'] buy_price = float(bids[0][0]) if bids else 0.0 sell_price = float(asks[0][0]) if asks else 0.0 buy_qty = round(sum(float(bid[1]) for bid in bids), 0) sell_qty = round(sum(float(ask[1]) for ask in asks), 0) # Calculate the threshold for order price deviation if mark_price_percent > 2: pth = 9 / 100 elif mark_price_percent < -2: pth = 9 / 100 else: pth = 9 / 100 if mark_price_percent > 2: th = 20000 elif mark_price_percent < -2: th = 20000 else: th = 13000 #Main Signal if ((((buy_qty > th) > (sell_qty < th))) and (buy_price > mp + pth)): signal.append('buy') elif ((((sell_qty > th) > (buy_qty < th))) and (sell_price < mp - pth)): signal.append('sell') else: signal.append('') #Signal confirmation if signal == ['buy'] and not (((buy_qty < th) < (sell_qty > th)) and (buy_price < mp + pth)): final_signal.append('buy') elif signal == ['sell'] and not (((sell_qty < th) < (buy_qty > th)) and (sell_price > mp - pth)): final_signal.append('sell') else: final_signal.append('') if final_signal == ['buy'] and (((buy_qty < th) < (sell_qty > th)) and (buy_price < mp + pth)): exit.append('buy_exit') elif final_signal == ['sell'] and (((sell_qty < th) < (buy_qty > th)) and (sell_price > mp - pth)): exit.append('sell_exit') else: exit.append('') samerkh = final_signal and exit return samerkhBut will it give me signals or no ?
- Assistant
Based on the provided code, the function
signal_generator(df)will generate signals depending on the conditions defined within the code. It seems to implement a logic for buying and selling based on certain thresholds and market price changes.However, it is important to note that the code depends on the values of
symbol,client, and the data in thedfvariable which are not provided in the code snippet. Additionally, there may be other dependencies on external libraries or modules that are not visible in the code snippet.Therefore, without the complete code and the necessary input data, it is not possible to determine if the function will give you the desired signals or not.
- User
But it can give me signals or no
- Assistant
Yes, the
signal_generator(df)function is designed to generate signals based on the provided conditions and input data.If the function is called with a valid dataframe (
df) and all the necessary dependencies and variables are properly defined, it should be able to generate signals. However, it is important to note that the accuracy and reliability of the generated signals will depend on the logic and conditions implemented in the code, as well as the quality and relevance of the input data.It is recommended to thoroughly test the function with different input scenarios and evaluate the accuracy of the generated signals before relying on them for any trading decisions.