From d356bf86c0a38e4e54152d124be38525cfcb155e Mon Sep 17 00:00:00 2001 From: JayRen Date: Mon, 3 Jul 2023 22:56:24 +0800 Subject: [PATCH] updated signals - MACD message --- signals/macd.py | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/signals/macd.py b/signals/macd.py index 1ac0d47..e8e7c8c 100644 --- a/signals/macd.py +++ b/signals/macd.py @@ -5,7 +5,8 @@ import tg import datetime import setting import db -import signal_builder +import signals.signal_builder as signal_builder + def check_macd(data): close_prices = np.array([float(entry[4]) for entry in data]) @@ -15,18 +16,18 @@ def check_macd(data): slow_period = 26 signal_period = 9 - print(close_prices[-1], close_prices[-2], close_prices[-3], close_prices[-4]) + # print(close_prices[-1], close_prices[-2], close_prices[-3], close_prices[-4]) # 计算MACD指标 macd - DIF; macdsignal - DEA; macdhist- 柱状线 macd, macd_signal, macd_hist = talib.MACD(close_prices, fastperiod=fast_period, slowperiod=slow_period, signalperiod=signal_period) - print("MACD:", round(macd[-1], 2)) - print("Signal:", round(macd_signal[-1], 2)) - print("Histogram:", round(macd_hist[-1], 2)) - print("----------") - print("MACD:", round(macd[-2], 2)) - print("Signal:", round(macd_signal[-2], 2)) - print("Histogram:", round(macd_hist[-2], 2)) + # print("MACD:", round(macd[-1], 2)) + # print("Signal:", round(macd_signal[-1], 2)) + # print("Histogram:", round(macd_hist[-1], 2)) + # print("----------") + # print("MACD:", round(macd[-2], 2)) + # print("Signal:", round(macd_signal[-2], 2)) + # print("Histogram:", round(macd_hist[-2], 2)) return macd, macd_signal, macd_hist @@ -58,19 +59,18 @@ def run(symbol, interval): text = "" data = {} if signal == 1 or signal == 2: - text = signal_builder.signal_text(symbol, interval, "MACD","【多】") - + text = signal_builder.signal_text(symbol, interval, "MACD", "【多】" if signal == 1 else "【强多】") data = {"type": 2, "symbol": symbol, "interval": interval, "signal": signal} if signal == 3 or signal == 4: - text = signal_builder.signal_text(symbol, interval, "MACD","【空】") + text = signal_builder.signal_text(symbol, interval, "MACD", "【空】" if signal == 3 else "【强空】") data = {"type": 2, "symbol": symbol, "interval": interval, "signal": signal} if text != "": signals = db.get_list('signals', f'symbol="{symbol}" and `interval`="{interval}"') for s in signals: print(s) - db.execute_sql(f'delete from signals where `id`={s["id"]}') - - db.insert(data, 'signals') - print(text) - tg.send_message(setting.chat_id, text) + if s["signal"] != data["signal"]: + db.execute_sql(f'delete from signals where `id`={s["id"]}') + db.insert(data, 'signals') + print(text) + tg.send_message(setting.chat_id, text)