This commit is contained in:
aaron 2025-05-04 10:59:16 +08:00
parent bbe80661f8
commit 6629b318e1
4 changed files with 163 additions and 2 deletions

View File

@ -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:

View File

@ -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

View File

@ -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)

View File

@ -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: