2.1 KiB
Tencent Realtime Quotes Design
Date: 2026-07-08
Goal
Add Tencent A-share quote integration so the GUI holdings table displays realtime prices from http://qt.gtimg.cn/q=<symbol>.
The first implementation is manual refresh only. It does not auto-refresh, generate buy/sell grid orders, or overwrite user-entered manual prices.
Confirmed Decision
Use Tencent's quote endpoint directly. Example:
http://qt.gtimg.cn/q=sz000001
The response is GBK/GB18030 encoded and shaped like:
v_sz000001="51~平安银行~000001~10.60~10.47~10.44~...";
The parser will use these fields:
1: name2: code3: current price4: previous close5: open30: quote time31: price change32: change percent33: high34: low
Design
Add a market package with a Tencent quote client. The client converts local instrument codes into Tencent symbols:
- Already prefixed
shorsz: keep as-is. - Codes starting with
6,5, or9: usesh. - Codes starting with
0,1,2, or3: usesz.
TradingService keeps an in-memory quote cache. When the user clicks refresh in the GUI, the service fetches quotes for all active instruments and stores them in memory.
Position calculations will prefer prices in this order:
- Tencent realtime quote
- Manual price
- Last trade price
- Empty value
The holdings table and account summary will immediately reflect quote prices after refresh. Quote prices are not persisted to SQLite in this step, so stale prices do not silently survive app restarts.
Error Handling
- If one symbol fails, the refresh reports the error and keeps existing data unchanged.
- Empty or malformed Tencent responses raise a quote-specific error.
- A zero or missing current price is ignored for that symbol.
- Network timeouts use a short timeout so the GUI does not hang for long.
Testing
- Unit-test Tencent response parsing with a fixture response.
- Unit-test symbol inference.
- Unit-test position calculations with a realtime quote overriding manual price.
- Unit-test service quote refresh using a fake quote provider.
- Keep existing GUI smoke tests passing.