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=30) 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) 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)