blog.dopana

Quay lại

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:

macOS/Linux
brew install --cask longbridge/tap/longbridge-terminal
bash

Hoặc dùng install script:

macOS/Linux
curl -sSL https://github.com/longbridge/longbridge-terminal/raw/main/install | sh
bash

Windows:

iwr https://github.com/longbridge/longbridge-terminal/raw/main/install.ps1 | iex
powershell

Authentication#

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 API
bash

CLI 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]
bash

Tất cả commands hỗ trợ --format json cho output machine-readable:

longbridge quote TSLA.US --format json
longbridge positions --format json | jq '.[] | {symbol, quantity}'
bash

Quotes - 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.US
bash

Output 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 |
bash

Trading - 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.

Portfolio - 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-analysis
bash

Fundamentals - 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.US
bash

TUI - Giao diện tương tác#

Để monitoring real-time với giao diện đẹp:

longbridge tui
bash

Features:

  • 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 ai
bash

Features:

  • Streaming answers with Markdown
  • Charts và tables
  • Live quote cards
  • Command palette
  • Multi-line input
  • Session persistence

Kiến trúc#

Longbridge TerminalCLI CommandsTUI InterfaceAI ChatJSON-RPC ServerQuote APITrade APIFundamentals APIRatatui TUIReal-time WebSocketLongbridgeAIMarkdown RenderingExternal AppsJSON-RPC 2.0Longbridge SDK

Embedding trong ứng dụng khác#

Để tích hợp Longbridge Terminal vào app khác (desktop widgets, dashboards):

longbridge serve
bash

Process 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"}}
json

AI Agent Integration#

Longbridge Terminal được thiết kế đặc biệt cho AI agents. Cài đặt skill:

npx skills add longbridge/developers
bash

Claude có thể query market data, run technical analysis, và manage trades:

claude> Show me TSLA and NVDA performance over the last 5 days
text

Claude 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:

Bash
source <(longbridge completion bash)
bash
Zsh
source <(longbridge completion zsh)
bash
Fish
longbridge completion fish | source
bash

Advanced 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 123
bash

Recurring 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>
bash

Stock 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:3
bash

So sánh với các giải pháp khác#

Tính năngLongbridge TerminalWeb AppMobile AppCustom API
Ngôn ngữRust CLIWebMobileCustom
Real-time data✓✓✓✓
Scripting✓✗✗✓
AI integration✓✗✗Tùy
TUI interface✓✗✗✗
Offline capabilityLimited✗Limited✓
Learning curveMediumLowLowHigh

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.

References#