HighTrade自主交易系统
位置: /Users/traderbot/Documents/highTRADE 用户:traderbot 状态:生产运行✅ (通过launchd编排器+仪表板·禁用Slack机器人) 版本:1.1.0(增强型)
快速开始
cd ~/Documents/highTRADE
# Check system status
python3 hightrade_cmd.py /status
# Run configuration validator
python3 config_validator.py
# View live orchestrator log
tail -f logs/orchestrator_srv_v3.log
# View alert/notification log (replaces Slack alerts)
tail -f logs/slack_notifications.log
# View watchdog activity
tail -f logs/launchd_watchdog.log备注:当前存在松弛警报 已暂停。所有本应发送到Slack的通知都将写入 logs/slack_notifications.log 相反。检查该文件中的交易信号、DEFCON更改和系统事件。v1.1.0的新增功能🎉
第1阶段增强功能(完成)
✅ 配置验证 -所有API和服务的启动健康检查\ ✅ 新闻重复数据删除 -内容相似性检测防止重复新闻膨胀\ ✅ 速率限制 -API调用的指数退避(零数据丢失)\ ✅ 强化退出策略 -5种退出策略与前2种:
- 尾随停车位(距离峰值2%)
- DEFCON恢复退出
- 基于时间的退出(最多72小时)
- 利润目标(+5%)
- 止损(-3%)
📖 看 docs/ENHANCEMENTS_SUMMARY.md 了解详细信息
最近的更新
🌅 日内交易者模块
- 新
day_trader.py该模块添加了Grok驱动的日内策略 - 运行市场前扫描、市场开盘买入、日内退出检查和日终退出支持
- 将会话存储在
day_trade_sessions里面trading_data/trading_history.db - 直接在仪表板中渲染
⚡ Day Trader (Grok) - 即使还没有会话,仪表板现在也会显示日内交易者部分
🧠 Grok深潜
- 高级信号深度分析现在使用Grok本地提示
gemini_analyzer.py - Grok deep-dive现在同时调用xAI Responses API:
- web_search - x_search
- JSON合约仍然与现有的下游管道兼容
- 如果Responses API搜索调用失败,客户端仍会返回到正常的非搜索聊天路径
系统架构
~/Documents/hightrade/
├── Core System
│ ├── hightrade_orchestrator.py # Main monitoring loop
│ ├── slack_bot.py # Slack command listener
│ ├── mcp_server.py # Claude Desktop integration
│ ├── monitoring.py # DEFCON & signal scoring
│ ├── broker_agent.py # Trade decision logic
│ └── logging_config.py # Unified logging system
│
├── News & Signals (Enhanced)
│ ├── news_aggregator.py # Multi-source news (with deduplication)
│ ├── news_deduplicator.py # TF-IDF similarity detection
│ ├── news_sentiment.py # Sentiment analysis
│ └── news_signals.py # News-based signals
│
├── Trading (Enhanced)
│ ├── paper_trading.py # Simulated trading (with enhanced exits)
│ ├── exit_strategies.py # 5 exit strategies with priorities
│ └── live_trading.py # Live trading (future)
│
├── Infrastructure (New)
│ ├── config_validator.py # Startup health checks
│ ├── rate_limiter.py # API rate limiting
│ └── alerts.py # Slack/email/SMS alerts
│
├── Data & Config
│ ├── trading_data/
│ │ ├── trading_history.db # SQLite database
│ │ ├── alert_config.json # Slack/alert settings
│ │ ├── logs/ # All system logs
│ │ └── commands/ # Command IPC files
│ └── docs/
│ ├── ENHANCEMENTS_SUMMARY.md # Phase 1 enhancements
│ ├── MIGRATION_COMPLETE.md # Migration history
│ └── README.md # This file
└── Tests & Utilities
├── create_database.py
├── load_sample_data.py
├── test_paper_trading.py
└── test_claude_feedback.py运行服务
这三个服务都通过launchd运行,并在崩溃时自动重启。看 KEEPALIVE_SETUP.md 了解详情。
./start_with_launchd.sh # Start all three
./stop_launchd.sh # Stop all three
launchctl list | grep hightrade # Check status仪表板(launchd)
- 标签:
com.hightrade2.dashboard - 统一资源定位符: http://localhost:5055 · http://192.168.0.233:5055
- 日志:
logs/dashboard_srv.log
编排员(launchd)
- 标签:
com.hightrade2.orchestrator - 间隔:每15分钟
- 日志:
logs/orchestrator_srv.log
Slack Bot(launchd)
- 标签:
com.hightrade.slackbot - 状态:Disabled(速率受限)--CLI bot暂时保持脱机状态,因此不会处理Slack命令。
- 备注:过去通过Slack发送的警报现在写入
logs/slack_notifications.log,并且通过本地脚本/日志而不是实时Slack进行监控。
MCP服务器(克劳德桌面)
- 路径:
/Users/stantonhigh/Documents/hightrade/mcp_server.py - 配置:
~/Library/Application Support/Claude/claude_desktop_config.json - 状态:由Claude Desktop管理
- 重启:重新启动Claude Desktop以重新加载
命令
CLI命令
cd ~/Documents/hightrade
# System status
python3 hightrade_cmd.py /status
# Portfolio
python3 hightrade_cmd.py /portfolio
# DEFCON details
python3 hightrade_cmd.py /defcon
# Help
python3 hightrade_cmd.py /help
# Day Trader status / control
python3 hightrade_cmd.py /daytrade
# Run a single orchestrator test cycle
python3 hightrade_orchestrator.py test
# Run health check
python3 config_validator.py日内交易者笔记
- Day Trader盘前扫描使用Grok进行实时扫描
web_search和x_search - 扫描只要求一只股票,并返回结构化JSON,其中包含:
- 股票代码 - 催化剂 - 自信 - 止损/止盈/延伸目标 - 论文 - 来源
- Grok深度分析路径与日内交易者路径是分开的,并在新闻信号升高时触发
Slack命令
Slack机器人当前处于离线状态 (价格有限)。这些命令在Slack返回时仍有记录,但现在没有任何东西在监听;相反,请检查 logs/slack_notifications.log 用于警报。 将这些内容发送到机器人本应加入的任何Slack频道、任何组DM或直接发送给机器人:status-系统状态portfolio-查看职位defcon-DEFCON级别详细信息help-所有命令hold-暂停交易yes-批准待处理交易no-拒绝待处理交易
你也可以提到机器人,例如: @HighTrade status
服务管理
# Start / stop all
./start_with_launchd.sh
./stop_launchd.sh
# Check status
launchctl list | grep hightrade
# Restart individual services
launchctl kickstart -k gui/$(id -u)/com.hightrade2.orchestrator
launchctl kickstart -k gui/$(id -u)/com.hightrade2.dashboard
launchctl kickstart -k gui/$(id -u)/com.hightrade.slackbot
# View logs
tail -f logs/orchestrator_srv.log
tail -f logs/dashboard_srv.log
tail -f logs/slack_bot.log监控
启动看门狗
scripts/monitor_hightrade_orchestrator.sh 检查 com.hightrade3.orchestrator 通过 launchctl,重新启动它 kickstart 如果它已经停止,并将带时间戳的条目附加到 logs/launchd_watchdog.log.
目前交付延迟 已暂停。所有警报(交易信号、DEFCON更改、系统事件)都缓冲到 logs/slack_notifications.log 相反。
# Run the watchdog script manually at any time
bash scripts/monitor_hightrade_orchestrator.sh
# Tail watchdog activity
tail -f logs/launchd_watchdog.log
# Tail buffered alerts (replaces Slack)
tail -f logs/slack_notifications.log查看日志
# Live logs
tail -f logs/orchestrator_srv.log
tail -f logs/dashboard_srv.log
tail -f logs/slack_bot.log
# Daily rotating orchestrator log
tail -f logs/hightrade_$(date +%Y%m%d).log
# Watch for rate limit events
grep -i "rate limit" logs/orchestrator_srv.log
# See deduplication stats
grep -i "deduplication" logs/orchestrator_srv.log
# Check exit strategy triggers
grep -E "TRAILING STOP|TIME LIMIT|DEFCON REVERT" logs/orchestrator_srv.log检查数据库
cd ~/Documents/hightrade
python3 -c "
import sqlite3
conn = sqlite3.connect('trading_data/trading_history.db')
cursor = conn.cursor()
cursor.execute('SELECT COUNT(*) FROM trade_records')
print(f'Total trades: {cursor.fetchone()[0]}')
cursor.execute('SELECT COUNT(*) FROM signal_monitoring')
print(f'Signal records: {cursor.fetchone()[0]}')
cursor.execute('SELECT COUNT(*) FROM news_signals')
print(f'News signals: {cursor.fetchone()[0]}')
cursor.execute('SELECT COUNT(*) FROM day_trade_sessions')
print(f'Day trade sessions: {cursor.fetchone()[0]}')
"单次循环测试
使用内置测试模式运行单个监控循环,而无需启动永久前台循环:
cd ~/Documents/hightrade
python3 hightrade_orchestrator.py test这运行:
- 一个完整的监测周期
- 人工智能/新闻分析
- 经纪人/日内交易员检查
- 仪表板刷新
- 状态摘要输出
配置
Slack集成
配置文件: trading_data/alert_config.json
包含:
- 用于发布警报的Webhook URL
- 用于监听命令的Bot令牌
- Socket模式的应用程序令牌(可选)
- 警报阈值(启用DEFCON 2和1)
新闻重复数据删除
配置:In news_config.json (可选)
{
"deduplication": {
"similarity_threshold": 0.6
}
}- 默认阈值:0.6(60%相似性=重复)
- 更低=更严格(捕获的重复项更少)
- 更高=更宽松(假阳性更多)
速率限制
内置默认值:
- Alpha Vantage:每分钟5个请求,延迟12秒
- Reddit:60个请求/分钟,1秒延迟
- 指数回退:2^失败秒(最多5分钟)
退出策略
内置配置:
- 利润目标:+5%
- 止损:-3%
- 尾随止损:距离峰值2%
- 最长保持时间:72小时
- 最小保持时间:1小时
数据库
文件: trading_data/trading_history.db\ 尺寸:约220 KB\ 表格 (共14个):
trade_records-所有纸质交易signal_monitoring-DEFCON历史defcon_history-历史DEFCON水平crisis_events-危机目录news_signals-新闻分析claude_analysis-克劳德反馈market_data,market_signals等等。
依赖项
通过安装 pip3 install --user:
requests-API的HTTP请求slack_sdk-Slack集成yfinance-市场数据feedparser-RSS源解析- 标准库:
sqlite3,logging,pathlib等等。
安全特性
✅ 仅限于纸品交易 -没有真正的金钱风险\ ✅ 需要手动批准 -所有交易都需要 /yes 命令\ ✅ 保守阈值 -仅在DEFCON 2/1交易\ ✅ 位置限制 -最大60%的投资组合风险敞口\ ✅ 5退出策略 -多层风险管理\ ✅ 松弛警报 -实时通知\ ✅ 完成审计跟踪 -记录的每一个决定\ ✅ 配置验证 -捕捉创业中的问题\ ✅ 速率限制 -防止API数据丢失\ ✅ 新闻重复数据删除 -准确的情绪评分
当前状态
跑 python3 hightrade_cmd.py /status 查看:
- DEFCON级别(1-5)
- 信号得分(0-100)
- 市场数据(波动率指数、债券收益率、标准普尔500指数)
- 未结头寸(带退出策略跟踪)
- 待处理交易
- 新闻评分(带重复数据删除功能)
MCP工具(克劳德桌面版)
重新启动Claude Desktop后,以下工具可用:
get_system_status-当前系统状态get_recent_signals-市场信号get_recent_news-新闻分析(重复数据消除)submit_claude_analysis-增强新闻评论get_article_details-完整文章数据get_system_architecture-系统信息
测试与验证
测试新功能
cd ~/Documents/hightrade
# Test config validator
python3 config_validator.py
# Test news deduplicator
python3 news_deduplicator.py
# Test rate limiter
python3 rate_limiter.py
# Test exit strategies
python3 exit_strategies.py集成测试
# Test paper trading with enhanced exits
python3 test_paper_trading.py
# Test Claude feedback system
python3 test_claude_feedback.py故障排除
编排器未运行
launchctl list | grep hightrade # check exit code
tail -f logs/orchestrator_srv.log
launchctl kickstart -k gui/$(id -u)/com.hightrade2.orchestrator
# If exit code 78 persists after kickstart, see KEEPALIVE_SETUP.md (label poisoning)Slack机器人没有响应
launchctl list | grep hightrade # check exit code
tail -f logs/slack_bot.log
launchctl kickstart -k gui/$(id -u)/com.hightrade.slackbot仪表板未加载
lsof -i :5055 # check if port is bound
tail -f logs/dashboard_srv.log
launchctl kickstart -k gui/$(id -u)/com.hightrade2.dashboardMCP服务器不工作
- 检查配置:
cat ~/Library/Application\ Support/Claude/claude_desktop_config.json - 验证路径:
/Users/stantonhigh/Documents/hightrade/mcp_server.py - 重新启动克劳德桌面
- 检查克劳德桌面日志
速率限制错误
# Check rate limiter stats in logs
grep "Rate limit" trading_data/logs/orchestrator_output.log
# If seeing many backoffs, API keys may be rate limited
# Wait for backoff period (shows in logs)新闻重复数据删除不起作用
# Check if deduplicator is loaded
grep "deduplication enabled" trading_data/logs/orchestrator_output.log
# See deduplication stats
grep "Deduplication:" trading_data/logs/orchestrator_output.log性能指标
v1.1.0之前
- 新闻重复数多次
- 速率限制错误导致数据丢失
- 只有两种退出策略(利润目标+止损)
- 启动时不进行健康检查
- 长时间搁置无保护
v1.1.0之后
- 准确的新闻评分(删除重复项)
- 速率限制导致零数据丢失
- 5种具有优先级排序的退出策略
- 启动验证捕获配置问题
- 72小时后自动退出
- DEFCON恢复退出
- 尾随止损保护利润
文档
docs/ENHANCEMENTS_SUMMARY.md-详细介绍第1阶段的增强功能docs/MIGRATION_COMPLETE.md-系统迁移历史README.md-此文件(主要文档)
路线图
第一阶段(完成)✅
- 配置验证
- 新闻重复数据删除
- 速率限制
- 强化退出策略
第二阶段(计划中)📋
- 回溯测试框架
- 性能分析仪表板
- 多时间段分析
- 高级职位规模
______________________________________________________________________
系统状态: ✅ 生产就绪(增强型)\ 最后更新: 2026-02-14\ 版本: 1.1.0\ 增强:完成4/5(80%)
