Files
Hermes-Skills/longbridge-cli/references/generic-stock-query.md
T
mikeandClaude 32d5d7dc0b feat(longbridge): complete 602315 bypass + CLI helper + stock_t脚本
新增:
- references/cli-unicode-table-parsing.md - CLI 表格 ┃ vs │ Unicode 解析
- references/cron-wrapper-multi-token-pitfall.md - cron script 字段不支持空格
- references/generic-stock-query.md - 通用 stock_t.py 持仓查询
- references/longportapp-cn-endpoints.md - Python SDK 走 longportapp.cn vs CLI 走 longbridge.com
- references/sdk-vs-cli-domain-routing.md - SDK/CLI 域名路由差异
- scripts/longbridge_cli_helper.py - SDK 兼容层, 内部走 CLI (绕 602315)
- scripts/stock_t.py - 通用持仓查询脚本 (不限定股票)

修改:
- longbridge-cli/SKILL.md + references/longbridge-602315-bypass.md
- longbridge-python-sdk/SKILL.md: 增 cn endpoint 说明
- intraday-trading/SKILL.md

关键发现:
1. Python SDK 用 openapi.longportapp.cn (阿里云深圳), CLI 用 openapi.longbridge.com (AWS 香港)
2. 两个不同域名, 不同 endpoint, 都需 LONGBRIDGE_HTTP_URL=https://openapi.longbridge.com 强制覆盖
3. CLI 默认不读 HTTP_PROXY env, 必须用 proxychains4 OS 层拦截
4. 完整链路: LONGBRIDGE_HTTP_URL=.com + LONGBRIDGE_REGION=ap + proxychains4 + Clash 香港节点
5. Yahoo Finance 备用数据源 (CLI 拿不到 K线)
6. CLI 表格用 ┃ (header) 和 │ (data) 两种 Unicode 字符, parser 要兼容

订单实测:
- RGTI.US 1股@15.40: 下单 1259694819492519936, 撤单成功
- 9988.HK 200股@112.70: Rejected (余额或限额)
- 1810.HK 1200股@25.98: Rejected (同上)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-07-09 18:19:58 +08:00

2.9 KiB

Generic Stock Position Query (stock_t.py)

Per-symbol ad-hoc query tool for any LongBridge holding — no hardcoded symbol. Lives at ~/.hermes/scripts/stock_t.py.

Why this exists

Earlier rgti_auto_t.py was RGTI-specific. When user asked to check UNH, AMD, or 3416.HK, that script refused. The generic version accepts the symbol as a CLI arg and supports both invocation orders:

# Format A: command then symbol
python3 stock_t.py status RGTI.US
python3 stock_t.py plan UNH.US
python3 stock_t.py cancel SOXS.US
python3 stock_t.py list

# Format B: symbol then command (also supported)
python3 stock_t.py RGTI.US status

Usage

Always wrap in proxychains4 (for env + region override) before any call:

LONGBRIDGE_REGION=ap \
proxychains4 -f ~/.proxychains/proxychains.conf \
  python3 ~/.hermes/scripts/stock_t.py status <SYMBOL>
Command What it does Side effects
list All positions, total value read-only
status <SYM> Quote + position + today's orders for SYM read-only
plan <SYM> T-plan with buy/sell trigger levels read-only
cancel <SYM> Cancel all open orders for SYM mutates orders
execute / auto Placeholder (TODO) — currently just prints manual command none

Per-symbol config (optional)

stock_t.py looks for ~/.hermes/scripts/<symbol>_t_config.json (e.g. rgti_us_t_config.json). Schema:

{
  "trade_qty": 30,
  "buy_levels":  [18.50, 18.00, 17.50],
  "sell_levels": [20.50, 21.00, 21.50],
  "spread_buffer": 0.10
}

Without this file, plan shows generic placeholders. State file ~/.hermes/scripts/<symbol>_t_state.json is auto-managed by future execute/auto implementations.

Pitfalls

  • Status/plan always read-only. They never place orders. If a user asks "what should I do", answer with a plan output + a proposed longbridge CLI command for them to copy-paste, not an auto-execution.
  • Symbol format must be canonical: RGTI.US, UNH.US, 3416.HK, 823.HK. The script uppercases the input but does not auto-suffix .US or .HK — wrong format returns empty position silently.
  • 602315 bypass is required: The script sets LONGBRIDGE_REGION=ap internally, but it still needs to run under proxychains4 for the TCP routing to actually reach the AWS endpoint. Running it bare will hang on quote() / stock_positions() and eventually fail.

How to extend execute / auto

These are TODO. The pattern (when implemented) should be:

  1. Load stock_t.py config for the symbol.
  2. Read current position from stock_positions().
  3. Compare current price to buy/sell levels.
  4. If a level is hit and we don't already have a working order at that level, place a limit order via submit_order().
  5. Persist to state file so we don't re-place the same order on next tick.

The 602315 bypass must be in place for the auto-execute path to work. See longbridge-602315-bypass.md for the recipe.