From 6629b318e14d36e65952bdfa1baf71f72d3f377c Mon Sep 17 00:00:00 2001 From: aaron <> Date: Sun, 4 May 2025 10:59:16 +0800 Subject: [PATCH] update --- cryptoai/config/config.yaml | 2 +- cryptoai/monitor_endpoint.py | 23 ++++ cryptoai/monitors/technical_indicators.py | 138 ++++++++++++++++++++++ docker-compose.yml | 2 +- 4 files changed, 163 insertions(+), 2 deletions(-) create mode 100644 cryptoai/monitors/technical_indicators.py diff --git a/cryptoai/config/config.yaml b/cryptoai/config/config.yaml index ec24ba8..810b16e 100644 --- a/cryptoai/config/config.yaml +++ b/cryptoai/config/config.yaml @@ -72,7 +72,7 @@ discord: crypto_webhook_url: "https://discord.com/api/webhooks/1286585288986198048/iQ-yr26ViW45GM48ql8rPu70Iumqcmn_XXAmxAcKGeiQBmTQoDPeq-TmlChvIHkw_HJ-" gold_webhook_url: "https://discord.com/api/webhooks/1367341235987021914/XVcjs6ZAZad3ZezzuudyiK_KqNUowqz2o2NJPdvwWY_EvwZVJcnVHq5M0-RQhkKV-FEQ" volume_growup_webhook_url: "https://discord.com/api/webhooks/1368217200023961631/yl_zZK865YLNpq7F7ISwPa6ztXEjU8_V646XxL95RF7PIGEFoLCTa_dTiabkfUaUvme0" - + technical_indicators_webhook_url: "https://discord.com/api/webhooks/1368420664767287296/96aYVXPfQdv0KE6BKCZJ6w4M60jNMpwyXfDm05THa7oaknnOxhWTV5t6hO9wqw3TwyNs" # 数据库配置 database: diff --git a/cryptoai/monitor_endpoint.py b/cryptoai/monitor_endpoint.py index 31ab0cd..1bed216 100644 --- a/cryptoai/monitor_endpoint.py +++ b/cryptoai/monitor_endpoint.py @@ -1,5 +1,6 @@ from cryptoai.monitors.volume_growup import VolumeGrowupMonitor +from cryptoai.monitors.technical_indicators import TechnicalIndicatorsMonitor import schedule @@ -7,12 +8,34 @@ def run_monitor(): volume_growup_monitor = VolumeGrowupMonitor() # volume_growup_monitor.run(time_interval="5m") + technical_indicators_monitor = TechnicalIndicatorsMonitor() + # technical_indicators_monitor.run(time_interval="15m") + + # return + try: print("☕️ 加密货币监控程序已启动") + + # 5分钟监控,交易量增长 times = [":00", ":05", ":10", ":15", ":20", ":25", ":30", ":35", ":40", ":45", ":50", ":55"] for time in times: schedule.every().hour.at(time).do(volume_growup_monitor.run, time_interval="5m") + + # 15分钟监控,技术指标 + times = [":00", ":15", ":30", ":45"] + for time in times: + schedule.every().hour.at(time).do(technical_indicators_monitor.run, time_interval="15m") + + # 1小时监控,技术指标 + schedule.every().hour.at(":00").do(technical_indicators_monitor.run, time_interval="1h") + + # 4小时监控,技术指标 + times = ["00:00", "04:00", "08:00", "12:00", "16:00", "20:00"] + for time in times: + schedule.every().day.at(time).do(technical_indicators_monitor.run, time_interval="4h") + + while True: schedule.run_pending() import time diff --git a/cryptoai/monitors/technical_indicators.py b/cryptoai/monitors/technical_indicators.py new file mode 100644 index 0000000..de375f4 --- /dev/null +++ b/cryptoai/monitors/technical_indicators.py @@ -0,0 +1,138 @@ + +from cryptoai.api.binance_api import BinanceAPI +from cryptoai.utils.config_loader import ConfigLoader +import logging +from datetime import datetime, timedelta +from cryptoai.models.data_processor import DataProcessor +from cryptoai.utils.discord_bot import DiscordBot +import time +import pandas as pd + +logger = logging.getLogger(__name__) +logger.setLevel(logging.DEBUG) + +class TechnicalIndicatorsMonitor: + """ + 成交量增长监控 + """ + def __init__(self): + self.config_loader = ConfigLoader() + self.binance_config = self.config_loader.get_binance_config() + self.discord_config = self.config_loader.get_discord_config() + self.binance_api = BinanceAPI( + api_key=self.binance_config['api_key'], + api_secret=self.binance_config['api_secret'], + test_mode=self.binance_config['test_mode'] + ) + + self.discord_bot = DiscordBot( + webhook_url=self.discord_config['technical_indicators_webhook_url'] + ) + + def run(self, time_interval: str = "1h"): + binance_symbols = self.binance_api.get_all_symbols() + + # 计算开始时间 + start_time = datetime.now() - timedelta(days=1) # 3天前 + start_str = start_time.strftime("%Y-%m-%d") + + # 获取所有symbol的klines 数据 + for symbol in binance_symbols: + data = self.binance_api.get_historical_klines(symbol, time_interval, start_str) + + data_processor = DataProcessor() + processed_data = data_processor.preprocess_market_data(symbol, data) + + # RSI超卖超买 + self.monitor_rsi(processed_data, symbol, time_interval) + + # 布林带 + self.monitor_bollinger(processed_data, symbol, time_interval) + + # # MACD + # self.monitor_macd(processed_data, symbol, time_interval) + + + time.sleep(1) + + def monitor_bollinger(self, processed_data: pd.DataFrame, symbol: str, time_interval: str): + # 布林带 + upper = processed_data['Bollinger_Upper'].iloc[-1] + lower = processed_data['Bollinger_Lower'].iloc[-1] + close = processed_data['close'].iloc[-1] + + notify = False + # 超买超卖 + if close > upper: + result = "触及BOLL上轨" + notify = True + elif close < lower: + result = "触及BOLL下轨" + notify = True + else: + result = "正常" + + if notify: + # 构建技术指标提醒消息 + message = f"""## 🚨 【{symbol}】BOLL指标提醒 + +**周期**: `{time_interval}` +**布林带**: **{result}** + +**时间**: `{datetime.now().strftime('%Y-%m-%d %H:%M:%S')}` +""" + self.discord_bot.send_message(message) + + def monitor_rsi(self, processed_data: pd.DataFrame, symbol: str, time_interval: str): + # 超买超卖 + signal = processed_data['RSI'].iloc[-1] + notify = False + + if signal > 70: + result = "RSI超买" + notify = True + elif signal < 30: + result = "RSI超卖" + notify = True + else: + result = "正常" + + if notify: + # 构建技术指标提醒消息 + message = f"""## 🚨 【{symbol}】RSI指标提醒 + +**周期**: `{time_interval}` +**RSI**: `{signal:.2f}` + +**结果**: **{result}** + +**时间**: `{datetime.now().strftime('%Y-%m-%d %H:%M:%S')}` +""" + self.discord_bot.send_message(message) + + def monitor_macd(self, processed_data: pd.DataFrame, symbol: str, time_interval: str): + # MACD 金叉死叉 + signal = processed_data['MACD_Signal'].iloc[-1] + notify = False + + if signal > 0: + result = "MACD金叉" + notify = True + elif signal < 0: + result = "MACD死叉" + notify = True + else: + result = "正常" + + if notify: + # 构建技术指标提醒消息 + message = f"""## 🚨 【{symbol}】MACD指标提醒 + +**周期**: `{time_interval}` +**MACD**: `{signal:.2f}` + +**结果**: **{result}** + +**时间**: `{datetime.now().strftime('%Y-%m-%d %H:%M:%S')}` +""" + self.discord_bot.send_message(message) diff --git a/docker-compose.yml b/docker-compose.yml index 5899822..993a754 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -18,7 +18,7 @@ services: cryptoai-monitor: build: . container_name: cryptoai-monitor - image: cryptoai-monitor:0.0.6 + image: cryptoai-monitor:0.0.7 restart: always command: python run_monitor.py environment: