I'm LongbridgeAI, I can summarize articles.基于长桥 Python SDK,全自动交易 QQQ 0DTE 虚值期权。回测 761 笔/2.3 年,胜率 75.8%。
本系统仅供参考学习部署,具体交易策略还需要自己优化。
全自动交易 QQQ 当日到期(0DTE)虚值期权,每天美东 09:35-15:50 期间自动检测信号、下单、持仓管理、平仓。
两条信号路径同时运行:
1. 趋势突破(顺势)
2. 衰竭反转(逆势)
动态止盈:
风控:
| 指标 | 数值 |
|---|---|
| 总交易 | 761 笔 / 2.3 年 |
| 胜率 | 75.8% |
| 总收益 | +3111% |
| 年化收益 | 354.8% |
| 最大回撤 | 25.19% |
pip install longbridge flask numpy scipy
git clone https://github.com/1797346220/qqq-trading-system.git cd qqq-trading-system
APP_KEYAPP_SECRETACCESS_TOKEN在项目目录创建 .env 文件,填入你自己的密钥:
LONGPORT_APP_KEY=你的 APP_KEY LONGPORT_APP_SECRET=你的 APP_SECRET LONGPORT_ACCESS_TOKEN=你的 ACCESS_TOKEN
⚠️ 重要:.env 文件绝对不能提交到 Git!
import os with open('.env') as f: for line in f: line = line.strip() if '=' in line and not line.startswith('#'): k, v = line.split('=', 1) os.environ.setdefault(k.strip(), v.strip().strip('"')) from longbridge.openapi import Config, QuoteContext config = Config.from_apikey_env() ctx = QuoteContext(config) quotes = ctx.quote(['QQQ.US']) print(f"QQQ: ${float(quotes[0].last_done):.2f}")
如果输出 QQQ 价格,说明密钥配置成功。
# 终端 1:启动交易引擎 PYTHONUNBUFFERED=1 python live_trader.py # 终端 2:启动 Web 仪表盘 PYTHONUNBUFFERED=1 python trader_web.py
# 后台启动交易引擎 nohup PYTHONUNBUFFERED=1 python live_trader.py > trader.log 2>&1 & # 后台启动 Web 仪表盘 nohup PYTHONUNBUFFERED=1 python trader_web.py > web.log 2>&1 &
python watchdog.py
watchdog 会自动管理 live_trader.py 的生命周期,崩溃后自动重启。
ps aux | grep -E 'live_trader|trader_web' | grep -v grep
应该看到两个 Python 进程在运行。
python -c " import json d = json.load(open('state.json')) print(f'连接: {d[\"connected\"]}') print(f'运行: {d[\"running\"]}') print(f'K 线数: {d[\"candle_count\"]}') "
浏览器打开 http://127.0.0.1:8080
| 文件 | 说明 |
|---|---|
live_trader.py | 核心交易引擎 |
trader_web.py | Web 仪表盘 |
watchdog.py | 守护进程 |
update_gist.py | 同步交易记录 |
.env | 密钥配置(不入库) |
state.json | 实时状态(自动生成) |
today.csv | 当日 K 线(自动生成) |
records/*.json | 交易记录(自动生成) |
pip install longbridge
检查:
.env 文件是否存在且格式正确LONGPORT_* 不是 LONGBRIDGE_*Config.from_apikey_env() 不是 Config.from_env()检查:
检查:
如需调整策略,修改 live_trader.py 中的 CONFIG:
CONFIG = { 'sl': 0.25, # 止损 25% 'lookback': 5, # 突破窗口 5 根 K 线 'vol_mult': 0.8, # 量能倍数 'min_body': 0.0003, # K 线实体 0.03% 'max_trades': 8, # 日最大交易 'start_time': '09:35', # 入场开始(美东) 'end_time': '15:50', # 入场结束(美东) # ... 其他参数见代码注释 }
⚠️ 修改后必须同步修改 trader_web.py 中的 CONFIG,然后重启两个进程。
https://github.com/1797346220/qqq-trading-system
本系统仅供学习研究使用。期权交易具有高风险,可能导致本金损失。作者不对使用本系统产生的任何损失负责。
$XIAOMI-W(01810.HK) $Invesco QQQ Trust(QQQ.US)
The copyright of this article belongs to the original author/organization.
The views expressed herein are solely those of the author and do not reflect the stance of the platform. The content is intended for investment reference purposes only and shall not be considered as investment advice. Please contact us if you have any questions or suggestions regarding the content services provided by the platform.
