Longbridge Terminal: AI-Native Trading CLI
Longbridge Terminal is a Rust AI-native trading CLI with real-time market data, portfolio management, and TUI for trading.
Do you want to trade stocks from your terminal without opening a browser? Longbridge Terminal is a CLI tool built in Rust that lets you access market data, manage your portfolio, and execute trades directly from the command line. It’s specifically designed to work with AI agents, making automated trading easier than ever.
Why Longbridge Terminal?#
Traditional stock trading typically requires:
- Web browser: Open app, login, navigate through multiple screens
- Mobile app: Slow, not convenient for complex tasks
- Spreadsheet: Manual updates, not real-time
- Custom API: Write your own code, manage authentication
Longbridge Terminal solves these problems by providing a comprehensive CLI:
- Real-time data: Quotes, depth, K-lines, options, warrants
- Full trading: Buy, sell, cancel, modify orders
- Portfolio management: Assets, positions, P/L tracking
- AI-friendly: JSON output, tool-calling ready
- Interactive TUI: Full-screen interface for monitoring
What is Longbridge Terminal?#
Think of Longbridge Terminal as a “swiss army knife” for stock trading. It’s a CLI that covers every Longbridge OpenAPI endpoint:
- 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
Built with Rust using:
- Ratatui: TUI rendering framework
- Tokio: Async runtime
- Bevy ECS: Entity-Component-System architecture
- Longbridge SDK: Official OpenAPI SDK
Installation#
Installation is simple - just one command:
brew install --cask longbridge/tap/longbridge-terminalbashOr use the 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#
Uses OAuth 2.0 - no manual token management required:
longbridge auth login # Opens browser for OAuth and saves token
longbridge auth logout # Clear saved token
longbridge check # Verify token, region, and API connectivitybashThe CLI automatically detects your region (China Mainland uses .cn endpoints, others use global).
CLI Usage#
Command structure:
longbridge <command> [options]bashAll commands support --format json for machine-readable output:
longbridge quote TSLA.US --format json
longbridge positions --format json | jq '.[] | {symbol, quantity}'bashQuotes - Market Data#
# 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 - Execute Trades#
[!WARNING] Order commands are always dry-run on first run. They only preview, don’t actually place orders. You need to run again with
--execute <CODE>to actually 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 - Asset Management#
# Asset overview
longbridge assets
# Portfolio overview
longbridge portfolio
# Current positions
longbridge positions
# Fund positions
longbridge fund-positions
# Profit analysis
longbridge profit-analysisbashFundamentals - Financial Analysis#
# 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 - Interactive Interface#
For real-time monitoring with a beautiful interface:
longbridge tuibashFeatures:
- Real-time watchlist
- Candlestick charts
- Portfolio view
- Stock search
- Vim-like keybindings
- Mouse support
AI Chat - LongbridgeAI#
Chat with AI for market analysis:
longbridge aibashFeatures:
- Streaming answers with Markdown
- Charts and tables
- Live quote cards
- Command palette
- Multi-line input
- Session persistence
Architecture#
Embedding in Other Apps#
To integrate Longbridge Terminal into other apps (desktop widgets, dashboards):
longbridge servebashThis opens a JSON-RPC 2.0 server on 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 is specifically designed for AI agents. Install the skill:
npx skills add longbridge/developersbashClaude can query market data, run technical analysis, and manage trades:
claude> Show me TSLA and NVDA performance over the last 5 daystextClaude will automatically run the necessary CLI commands and return results.
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:3bashComparison with Other Solutions#
| Feature | Longbridge Terminal | Web App | Mobile App | Custom API |
|---|---|---|---|---|
| Language | Rust CLI | Web | Mobile | Custom |
| Real-time data | ✓ | ✓ | ✓ | ✓ |
| Scripting | ✓ | ✗ | ✗ | ✓ |
| AI integration | ✓ | ✗ | ✗ | Optional |
| TUI interface | ✓ | ✗ | ✗ | ✗ |
| Offline capability | Limited | ✗ | Limited | ✓ |
| Learning curve | Medium | Low | Low | High |
When to Use Longbridge Terminal?#
Use when:
- You prefer working in the terminal
- Need scripting for automated trading
- Want to integrate with AI agents
- Need real-time monitoring with TUI
- Are a developer or power user
Don’t use when:
- You’re new to trading
- Need a simple GUI
- Not familiar with command line
- Only need basic trading features
Conclusion#
Longbridge Terminal is a powerful tool for traders and developers who want to manage trading from the terminal. With the combination of CLI commands, TUI interface, and AI integration, it provides flexibility not available in web apps or mobile apps. If you’re a terminal user and want to trade stocks efficiently, Longbridge Terminal is worth considering.