$npx -y skills add algoderiv/agent-skills --skill wtpyWonderTrader/wtpy 量化交易开发综合指南,整合官方文档、社区笔记与实践案例。涵盖 wtpy Python 框架与 WonderTrader C++ 核心的策略开发、回测、仿真、实盘、数据管理、监控运维全流程。
| 1 | # WonderTrader/wtpy Development Guide |
| 2 | |
| 3 | 综合 WonderTrader 官方文档(Read the Docs)、社区学习笔记(WonderTrader-Learning-Notes)和非官方整理文档(docs_wondertrader)三大来源,为 wtpy/WonderTrader 量化交易开发提供一站式参考。 |
| 4 | |
| 5 | ## When to Use This Skill |
| 6 | |
| 7 | This skill should be triggered when: |
| 8 | - 使用 wtpy (WonderTrader Python 框架) 开发量化策略 |
| 9 | - 使用 WonderTrader C++ 核心进行高频/极速交易开发 |
| 10 | - 配置和运行 CTA/SEL/HFT/UFT 引擎 |
| 11 | - 进行策略回测、仿真交易或实盘交易 |
| 12 | - 处理行情数据(DSB/CSV 转换、数据录制、历史数据管理) |
| 13 | - 配置和使用 WtMonSvr 监控服务或 WtStudio |
| 14 | - 对接 CTP/openctp/XTP 等交易和行情接口 |
| 15 | - 开发自定义执行器(ExtExecuter)或行情解析器(ExtParser) |
| 16 | - 排查 WonderTrader 常见问题(编译、配置、运行) |
| 17 | |
| 18 | ## Quick Reference |
| 19 | |
| 20 | ### Installation |
| 21 | ```bash |
| 22 | pip install wtpy --upgrade |
| 23 | ``` |
| 24 | |
| 25 | ### Backtest (CTA) |
| 26 | ```python |
| 27 | from wtpy import WtBtEngine, EngineType |
| 28 | from wtpy.apps import WtBtAnalyst |
| 29 | |
| 30 | engine = WtBtEngine(EngineType.ET_CTA) |
| 31 | engine.init('../common/', "configbt.yaml") |
| 32 | engine.configBacktest(202201100930, 202202011500) |
| 33 | engine.commitBTConfig() |
| 34 | |
| 35 | straInfo = StraDualThrust(name='pydt_cu', code="SHFE.cu.HOT", |
| 36 | barCnt=50, period="m5", days=30, k1=0.1, k2=0.1, isForStk=False) |
| 37 | engine.set_cta_strategy(straInfo) |
| 38 | engine.run_backtest() |
| 39 | |
| 40 | analyst = WtBtAnalyst() |
| 41 | analyst.add_strategy("pydt_cu", folder="./outputs_bt/pydt_cu/", |
| 42 | init_capital=500000, rf=0.02, annual_trading_days=240) |
| 43 | analyst.run() |
| 44 | engine.release_backtest() |
| 45 | ``` |
| 46 | |
| 47 | ### Live Trading (CTA) |
| 48 | ```python |
| 49 | from wtpy import WtEngine, EngineType |
| 50 | |
| 51 | env = WtEngine(EngineType.ET_CTA) |
| 52 | env.init('../common/', "config.yaml") |
| 53 | straInfo = StraDualThrust(name='pydt_au', code="SHFE.au.HOT", |
| 54 | barCnt=50, period="m5", days=30, k1=0.2, k2=0.2, isForStk=False) |
| 55 | env.add_cta_strategy(straInfo) |
| 56 | env.run() |
| 57 | ``` |
| 58 | |
| 59 | ### Contract Code Format |
| 60 | - 期货合约: `CFFEX.IF.2306` |
| 61 | - 期货主力: `CFFEX.IF.HOT` |
| 62 | - 商品期权: `CFFEX.IO2007.C.4000` |
| 63 | - 股票: `SSE.STK.600000` |
| 64 | - ETF期权: `SSE.ETFO.10003961` |
| 65 | |
| 66 | ### Trading Engines |
| 67 | | 引擎 | 适用场景 | 驱动方式 | 延迟 | |
| 68 | |------|---------|---------|------| |
| 69 | | CTA | 少标的择时/套利 | 事件+时间 | ~70μs (Python) | |
| 70 | | SEL | 多因子选股 | 时间(异步) | - | |
| 71 | | HFT | 高频交易 | 事件 | 1-2μs | |
| 72 | | UFT | 超高频(仅C++) | 事件 | <200ns | |
| 73 | |
| 74 | ## Reference Files |
| 75 | |
| 76 | This skill includes comprehensive documentation in `references/`: |
| 77 | |
| 78 | ### Getting Started & Architecture |
| 79 | - **getting-started-official.md** - 官方快速入门(安装、demo运行、回测分析) |
| 80 | - **getting-started-notes.md** - 社区学习笔记(版本选择、策略编写、环境部署、回测与实盘详解) |
| 81 | - **architecture.md** - 架构分析(信号与交易解耦、策略组、风控管理) |
| 82 | |
| 83 | ### Strategy Development |
| 84 | - **strategies.md** - 经典策略实现(DualThrust、ATR、菲阿里四价、空中花园等) |
| 85 | - **api.md** - 策略 API 详解(数据接口、交易接口、信号接口)及行情/交易接口对接 |
| 86 | |
| 87 | ### Configuration & Data |
| 88 | - **configuration.md** - 配置文件详解(configbt.yaml、config.yaml、actpolicy.yaml、executers.yaml 等) |
| 89 | - **data-tools.md** - 数据工具(WtDataHelper、CSV/DSB 转换、Tick数据处理) |
| 90 | - **data-management.md** - 数据管理(WtDtServo、ExtDataLoader/Dumper、历史数据处理、WtDHFactory) |
| 91 | |
| 92 | ### Advanced Development |
| 93 | - **advanced.md** - 进阶开发(ExtParser、ExtExecuter、C++开发环境搭建、自定义数据存储) |
| 94 | - **wtcpp-modules.md** - C++ 模块详解(QuoteFactory、CTA/HFT仿真、下单流程、配置文件源码分析) |
| 95 | - **source-analysis.md** - 源码解析(回测框架、执行单元、HFT引擎、CTA引擎、信号执行流程) |
| 96 | |
| 97 | ### Operations & Troubleshooting |
| 98 | - **tools-console.md** - Web 控制台与 WtStudio 使用手册(监控、调度、回测查看、参数优化) |
| 99 | - **faq.md** - 常见问题(引擎选择、合约代码规则、openctp 对接、CTA 下单接口详解) |
| 100 | |
| 101 | ## Documentation Sources |
| 102 | |
| 103 | | Source | Type | Pages | URL | |
| 104 | |--------|------|-------|-----| |
| 105 | | WonderTrader 官方文档 | Official (RTD) | 53 | https://wtdocs.readthedocs.io/zh/latest/ | |
| 106 | | WonderTrader 学习笔记 | Community | 75 | https://zzzzhej.github.io/WonderTrader-Learning-Notes/ | |
| 107 | | WonderTrader 非官方文档 | Unofficial | 27 | https://dumengru.github.io/docs_wondertrader/ | |
| 108 | |
| 109 | ## Key Resources |
| 110 | |
| 111 | - **GitHub (C++):** https://github.com/wondertrader/wondertrader |
| 112 | - **GitHub (Python):** https://github.com/wondertrader/wtpy |
| 113 | - **PyPI:** https://pypi.org/project/wtpy/ |
| 114 | - **QQ群:** 610730738 |
| 115 | |
| 116 | ## Notes |
| 117 | |
| 118 | - This skill was consolidated from three separate documentation sources |
| 119 | - Reference files preserve the original structure and code examples |
| 120 | - Content is primarily in Chinese (中文), matching the original documentation |
| 121 | - Code examples include both Python (wtpy) and C++ (WonderTrader core) implementations |