trading: 日内T/长桥/六合彩文档与脚本 + quant-factor-mining 新目录

This commit is contained in:
2026-09-25 01:25:38 +08:00
parent 734b168082
commit 3f17a4eb1f
23 changed files with 1821 additions and 376 deletions
+50
View File
@@ -394,6 +394,56 @@ resp = trade_ctx.submit_order(
- **🔴 [2026-07-05 做T方向] 做T=低吸高抛,不是低抛高吸。低吸=跌到支撑位买入,高抛=涨到阻力位卖出。不能随便市价卖出就叫"做T"。减仓和做T是两回事:减仓是降低风险敞口,做T是利用波动降低成本。
- **🔴 [2026-07-09 LongPort 没有 SL/TP/conditional algo 端点] LongPort OpenAPI 不支持挂止损单 / 止盈单 / 条件单.** `longport.TradeContext` 只暴露 `submit_order` / `cancel_order` / `today_orders` / `history_orders` / `order_detail` / `replace_order` / `set_on_order_changed`, 没有 `submit_algo_order` 或 `submit_conditional_order`. CLI 二进制同样: 所有 `/v1/trade/order-algo` / `/v1/trade/orderAlgo` / `/v1/trade/algo` 路径都是 404. **别照搬 OKX 的 `private_post_trade_order_algo` 逻辑到长桥** - 那是 OKX 专属. 长桥只能下普通限价/市价单, "止损"必须用 Day 单(time_in_force=Day)靠收盘自动取消, 或手动/CLI 下反向 limit 单. 详见 `references/longbridge-algo-order-not-supported.md`.
### 🆕 [2026-08-20 期权 (Options) / 窝轮 (Warrants) — 与 SL/TP 无关, 长桥是支持的]
**重要区分**: SL/TP algo 单不支持 **≠** 期权/窝轮不支持. LongPort OpenAPI **完整支持美股期权 + 港股窝轮** (2026-08-20 调研确认). skill 之前没说期权能力, 容易让人误判"长桥什么都干不了".
**QuoteContext 期权/窝轮端点 (Python SDK, 验证可用)**:
```python
from longport import openapi
cfg = openapi.Config.from_env()
ctx = openapi.QuoteContext(config=cfg)
# 美股期权: 查可用到期日列表
dates = ctx.option_chain_expiry_date_list("AAPL.US") # → [date, ...]
# 美股期权: 某到期日的全行权价链 (含 bid/ask/last/greeks)
chain = ctx.option_chain_info_by_date("AAPL.US", date_obj)
# 美股期权: 实时报价 (传 option symbol, 不是 underlying)
quotes = ctx.option_quote(["AAPL230616C150000.US"])
# 港股窝轮 (牛熊证)
warrants = ctx.warrant_list("9988.HK")
w_quote = ctx.warrant_quote(["warrant_symbol.HK"])
issuers = ctx.warrant_issuers()
```
**下单**: 期权用同一个 `trade_ctx.submit_order(symbol, ...)`, **symbol 格式** = `underlying.YYMMDD[C|P]strike.market` (例 `AAPL230616C150000.US` = AAPL 2023-06-16 Call 行权价 $150). 限价/市价/Day TIF 都支持, **仍然没有 SL/TP**.
**坑**:
- 期权 symbol 手写极易错, 必须先 `option_chain_expiry_date_list` + `option_chain_info_by_date` 查真实 symbol 再传 `submit_order`
- 港股窝轮 symbol 必须从 `warrant_list` 取, 手动写易错 (窝轮有发行商 + 多个同名轮, 必须按 list 选)
- **行情延迟**: US options 走 LV1 (Nasdaq Basic 同级别), 价格可能 15min 延迟, 日内交易不靠谱; 中长线分析 OK
- **权限差异**: LongPort 选项 API 实际权限按账户订阅, US LV1 默认有, 部分高级 Greeks (Vanna/Charm) 需订阅. 401/403 时降级为本地 BSM 计算
- **不支持多腿组合**: 没有 combo / spread 下单端点, Iron Condor 等必须分 4 笔单腿
- **下单前必查** `account_balance.buy_power` — 期权 nominal 价值高, 单张 AAPL 230616C150 可能面值 $5000+
**应用场景 (实测可行的)**:
- 美股 covered call (持正股卖 call): 用 `option_chain_info_by_date` 找 OTM call, `submit_order` sell 1 张
- Cash-secured put: `option_chain_info_by_date` 找 OTM put, `submit_order` buy 1 张
- Protective put (持正股买 put): 同上 buy put
- 港股牛熊证: `warrant_list` 选 → `warrant_quote` 看价 → `submit_order` (牛熊证自带 SL/TP, 不需要 algo)
**典型工作流** (用户说"看 AAPL options"或"卖 covered call"):
1. `option_chain_expiry_date_list("AAPL.US")` → 选到期日
2. `option_chain_info_by_date("AAPL.US", date)` → 找 OTM call, 筛 bid/ask spread 窄 + IV 合理
3. 评估: 行权价比现价高多少? 时间衰减? 隐含波动率 vs 历史?
4. 用户确认后 `submit_order(symbol="AAPL...C...", side=openapi.OrderSide.Sell, ...)`
5. 推送订单 ID + 立即反查 status (沿用 v4.5.51 status-check 规则)
**未做但应该有的**: 完整 longbridge 期权 skill 没建. 这次只 patch 这条说明, 实际 skill 留待用户决定要不要建 (如果要做, 起名 `us-stock-options-trading` 或 `longbridge-options`, 不要起名 `fix-options-2026-08-20` 这种 session 名字).
- **🔴 [2026-07-10 假阳性成功推送] 任何订单推送前必须反查 status,不能信 stdout.** 现象: cron 推送 `📊 HK 1810.HK ✅ 下单成功: 1260056765857271808`,实际 `orders --json` 查 `status: "OrderStatus.Rejected"`. 根因: `submit_order` / `execute_order` 返回 order_id 只代表"已发请求",不代表"已成交". **反查 status 规则**:
- `closed` / `filled` → 推 "✅ 下单成功"
- `Rejected` → 推 "❌ 下单被拒: {id} (查长桥 App 或 `orders --json` 看 reason)"