Skip to content

Add WebSocket real-time quote subscription support#2

Draft
Claude wants to merge 3 commits intomainfrom
claude/subscribe-to-quote-updates
Draft

Add WebSocket real-time quote subscription support#2
Claude wants to merge 3 commits intomainfrom
claude/subscribe-to-quote-updates

Conversation

@Claude
Copy link
Contributor

@Claude Claude AI commented Feb 12, 2026

Implements WebSocket-based quote subscriptions for efficient real-time market data updates, as an alternative to the existing poll-based track file approach.

Changes

  • New subscription manager (internal/market/subscribe.go)

    • Manages WebSocket quote subscriptions via QuoteContext.Subscribe()
    • Handles real-time push callbacks with OnQuote() handler
    • Thread-safe subscription state tracking
    • Automatically updates overview.json and overview.txt on price changes
  • File-based subscription interface

    • quote/subscribe/ - Create files to subscribe (e.g., touch quote/subscribe/AAPL.US)
    • quote/unsubscribe/ - Create files to unsubscribe
    • Controller processes requests each polling cycle and cleans up files after processing
  • Controller integration

    • Initialize subscription manager on startup
    • Process subscription requests in main control loop alongside existing track-based polling
    • Both methods coexist without interference
  • Documentation improvements

    • Added pagination examples for viewing large data files to prevent context window overflow
    • Includes jq slicing for K-line arrays, tail/head/sed for beancount ledger
    • Clarifies which files are small (safe for cat) vs large (require pagination)

Usage

# Subscribe to real-time quotes
touch fs/quote/subscribe/AAPL.US
touch fs/quote/subscribe/700.HK

# Quotes auto-update on price changes
cat fs/quote/hold/AAPL.US/overview.json

# View large files with pagination
jq '.[0:10]' fs/quote/hold/AAPL.US/D.json      # First 10 K-lines
tail -50 fs/trade/beancount.txt                 # Last 50 ledger entries

# Unsubscribe when done
touch fs/quote/unsubscribe/AAPL.US

WebSocket subscription provides low-latency real-time updates for monitoring positions and watchlists, while track files remain available for one-shot fetches of historical data (K-lines, intraday).

- Create subscription manager for WebSocket-based quote push
- Add subscribe/unsubscribe directories for file-based subscription control
- Integrate subscription processing into controller main loop
- Update README with WebSocket subscription documentation

Co-authored-by: JetSquirrel <20291255+JetSquirrel@users.noreply.github.com>
@Claude Claude AI changed the title [WIP] Add quote subscription via WebSocket Add WebSocket real-time quote subscription support Feb 12, 2026
@Claude Claude AI requested a review from JetSquirrel February 12, 2026 06:06

通过 WebSocket 订阅后,行情数据会自动实时更新,无需手动触发:

```bash
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果文件中堆积了很多数据,模型在查看的时候,会全部 stdout 出来,然后把上下文窗口占满

应该是由分页机制,cat 设置数据长度 limit,可以通过参数查看下一页

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added pagination examples throughout the documentation to prevent context overflow:

  • K-line data: jq '.[0:10]' file.json for slicing arrays
  • Beancount ledger: tail -50, head -50, sed -n '100,150p' for viewing ranges
  • PnL/Portfolio: jq '.positions[0:5]' when many holdings

Small files like overview.json are noted as safe for direct cat viewing.

Commit: 9d894ab

@JetSquirrel
Copy link
Owner

@claude[agent]

- Add jq slicing examples for K-line and historical data
- Add tail/head/sed examples for beancount.txt ledger
- Add pagination for pnl.json and portfolio.json when many positions
- Clarify which files are small vs large to guide appropriate viewing methods

Co-authored-by: JetSquirrel <20291255+JetSquirrel@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments