Longbridge Terminal: CLI giao dịch thông minh
Longbridge Terminal là CLI Rust giao dịch AI-native với dữ liệu thị trường real-time, portfolio, và giao dịch TUI.
Bạn có muốn giao dịch chứng khoán từ terminal mà không cần mở trình duyệt? Longbridge Terminal là một công cụ CLI được xây dựng bằng Rust giúp bạn truy cập dữ liệu thị trường, quản lý portfolio, và thực hiện giao dịch trực tiếp từ command line. Đặc biệt, nó được thiết kế để làm việc với AI agents, làm cho giao dịch tự động trở nên dễ dàng hơn bao giờ hết.
Tại sao cần Longbridge Terminal?#
Giao dịch chứng khoán truyền thường yêu cầu:
- Trình duyệt web: Mở app, đăng nhập, navigate qua nhiều màn hình
- Mobile app: Chậm, không tiện cho công việc phức tạp
- Spreadsheet: Manual update, không real-time
- API riêng: Phải tự viết code, quản lý authentication
Longbridge Terminal giải quyết这些问题 bằng cách cung cấp một CLI toàn năng:
- Dữ liệu real-time: Quotes, depth, K-lines, options, warrants
- Giao dịch đầy đủ: Buy, sell, cancel, modify orders
- Portfolio management: Assets, positions, P/L tracking
- AI-friendly: JSON output, tool-calling ready
- TUI interactive: Full-screen interface cho monitoring
Longbridge Terminal là gì?#
Hãy tưởng tượng Longbridge Terminal như một “swiss army knife” cho giao dịch chứng khoán. Nó là một CLI bao phủ mọi endpoint của Longbridge OpenAPI:
- Market Data: Real-time quotes, depth, K-lines, options, warrants
- Portfolio: Account balances, stock positions, fund positions
- Trading: Order submission, modification, cancellation, execution history
- Fundamentals: Financial reports, analyst ratings, valuation
- News & Signals: News articles, regulatory filings, strategy signals
Xây dựng bằng Rust với:
- Ratatui: TUI rendering framework
- Tokio: Async runtime
- Bevy ECS: Entity-Component-System architecture
- Longbridge SDK: Official OpenAPI SDK
Cài đặt#
Cài đặt rất đơn giản - chỉ cần một lệnh:
brew install --cask longbridge/tap/longbridge-terminalbashHoặc dùng install script:
curl -sSL https://github.com/longbridge/longbridge-terminal/raw/main/install | shbashWindows:
iwr https://github.com/longbridge/longbridge-terminal/raw/main/install.ps1 | iexpowershellAuthentication#
Sử dụng OAuth 2.0 - không cần quản lý token thủ công:
longbridge auth login # Mở browser để OAuth và lưu token
longbridge auth logout # Xóa token đã lưu
longbridge check # Kiểm tra token, region, và kết nối APIbashCLI tự động detect region của bạn (China Mainland dùng .cn endpoints, khác dùng global).
CLI Usage#
Cấu trúc lệnh:
longbridge <command> [options]bashTất cả commands hỗ trợ --format json cho output machine-readable:
longbridge quote TSLA.US --format json
longbridge positions --format json | jq '.[] | {symbol, quantity}'bashQuotes - Dữ liệu thị trường#
# Real-time quotes
longbridge quote TSLA.US 700.HK
# Level 2 order book depth
longbridge depth TSLA.US
# K-line (candlestick) data
longbridge kline TSLA.US --period day
# Intraday price and volume
longbridge intraday TSLA.US
# Static reference info
longbridge static TSLA.US NVDA.USbashOutput example:
$ longbridge static TSLA.US NVDA.US
| Symbol | Last | Prev Close | Open | High | Low | Volume | Turnover | Status |
|---------|---------|------------|---------|---------|---------|-----------|-----------------|--------|
| TSLA.US | 395.560 | 391.200 | 396.220 | 403.730 | 394.420 | 58068343 | 23138752546.000 | Normal |
| NVDA.US | 183.220 | 180.250 | 182.970 | 188.880 | 181.410 | 217307380 | 40023702698.000 | Normal |bashTrading - Giao dịch#
[!WARNING] Lệnh order luôn dry-run lần đầu. Nó chỉ preview, không thực sự place order. Bạn cần chạy lại với
--execute <CODE>để thực sự execute.
# Preview buy order
longbridge order buy TSLA.US 100 --price 250.00
# Actually place it (use the code from preview)
longbridge order buy TSLA.US 100 --price 250.00 --execute 123
# Preview sell order
longbridge order sell TSLA.US 100 --price 260.00
# Cancel order
longbridge order cancel <order_id> --execute 456
# View today's orders
longbridge order
# Historical orders
longbridge order --history --start 2024-01-01bashPortfolio - Quản lý tài sản#
# Asset overview
longbridge assets
# Portfolio overview
longbridge portfolio
# Current positions
longbridge positions
# Fund positions
longbridge fund-positions
# Profit analysis
longbridge profit-analysisbashFundamentals - Phân tích tài chính#
# Financial reports
longbridge financial-report AAPL.US --kind IS
# Analyst ratings
longbridge institution-rating AAPL.US
# Valuation
longbridge valuation AAPL.US --indicator pe
# Dividend history
longbridge dividend AAPL.USbashTUI - Giao diện tương tác#
Để monitoring real-time với giao diện đẹp:
longbridge tuibashFeatures:
- Real-time watchlist
- Candlestick charts
- Portfolio view
- Stock search
- Vim-like keybindings
- Mouse support
AI Chat - LongbridgeAI#
Chat với AI để phân tích thị trường:
longbridge aibashFeatures:
- Streaming answers with Markdown
- Charts và tables
- Live quote cards
- Command palette
- Multi-line input
- Session persistence
Kiến trúc#
Embedding trong ứng dụng khác#
Để tích hợp Longbridge Terminal vào app khác (desktop widgets, dashboards):
longbridge servebashProcess này mở JSON-RPC 2.0 server trên stdin/stdout:
→ {"jsonrpc":"2.0","id":1,"method":"quote.quote","params":{"symbols":["700.HK"]}}
← {"jsonrpc":"2.0","id":1,"result":[{"symbol":"700.HK","last_done":"445.600", ...}]}
→ {"jsonrpc":"2.0","id":2,"method":"quote.subscribe","params":{"symbols":["700.HK"]}}
← {"jsonrpc":"2.0","id":2","result":{"subscribed":[{"symbol":"700.HK"}]}}
← {"jsonrpc":"2.0","method":"quote.updated","params":{"symbol":"700.HK","last_done":"446.000"}}jsonAI Agent Integration#
Longbridge Terminal được thiết kế đặc biệt cho AI agents. Cài đặt skill:
npx skills add longbridge/developersbashClaude có thể query market data, run technical analysis, và manage trades:
claude> Show me TSLA and NVDA performance over the last 5 daystextClaude sẽ tự động chạy các lệnh CLI cần thiết và trả về kết quả.
Shell Completion#
Enable tab-completion:
source <(longbridge completion bash)bashsource <(longbridge completion zsh)bashlongbridge completion fish | sourcebashAdvanced Features#
Grid Trading#
Automated trading strategy:
# Preview grid strategy
longbridge grid submit 700.HK --base-price 300 --upper-price 360 --lower-price 240 \
--trigger-type percent --trigger-up 2 --trigger-down 2 --quantity 100
# Actually submit
longbridge grid submit 700.HK --base-price 300 ... --execute 123bashRecurring Investment (DCA)#
Auto-invest regularly:
# Create weekly DCA plan
longbridge dca create TSLA.US --amount 500 --frequency weekly --day-of-week mon
# View all plans
longbridge dca
# Pause plan
longbridge dca pause <PLAN_ID>bashStock Screener#
Find stocks matching criteria:
# List strategies
longbridge screener strategies
# Run custom filter
longbridge screener search --market HK --filter filter_marketcap:100:1000 --filter filter_divyld:3bashSo sánh với các giải pháp khác#
| Tính năng | Longbridge Terminal | Web App | Mobile App | Custom API |
|---|---|---|---|---|
| Ngôn ngữ | Rust CLI | Web | Mobile | Custom |
| Real-time data | ✓ | ✓ | ✓ | ✓ |
| Scripting | ✓ | ✗ | ✗ | ✓ |
| AI integration | ✓ | ✗ | ✗ | Tùy |
| TUI interface | ✓ | ✗ | ✗ | ✗ |
| Offline capability | Limited | ✗ | Limited | ✓ |
| Learning curve | Medium | Low | Low | High |
Khi nào nên dùng Longbridge Terminal?#
Nên dùng khi:
- Bạn thích làm việc trong terminal
- Cần scripting cho automated trading
- Muốn integrate với AI agents
- Cần real-time monitoring với TUI
- Là developer hoặc power user
Không nên dùng khi:
- Bạn mới bắt đầu giao dịch
- Cần GUI đơn giản
- Không quen với command line
- Chỉ cần basic trading features
Kết luận#
Longbridge Terminal là một công cụ mạnh mẽ cho traders và developers muốn quản lý giao dịch từ terminal. Với sự kết hợp giữa CLI commands, TUI interface, và AI integration, nó cung cấp flexibility không có trong web apps hay mobile apps. Nếu bạn là terminal user và muốn giao dịch chứng khoán một cách efficient, Longbridge Terminal là lựa chọn đáng cân nhắc.