SAHMK CLI Quick Start
Get instant Saudi stock market data from your terminal. The SAHMK CLI lets you fetch quotes, check market summaries, research companies, and stream real-time prices without writing a single line of code.
1. Installation
The SAHMK CLI is included with the Python SDK:
pip install -U sahmkAfter installation, the sahmk command is available in your terminal.
2. API Key Setup
Get your free key at sahmk.sa/developers.
Option 1: Environment Variable (Recommended)
export SAHMK_API_KEY="your_api_key_here"Add this to your ~/.bashrc or ~/.zshrc for persistence.
Option 2: Pass with Every Command
sahmk quote 2222 --api-key your_api_key_here3. Your First Command
Fetch a stock quote for Aramco (symbol: 2222):
sahmk quote 2222{
"symbol": "2222",
"name_en": "Saudi Arabian Oil Co",
"price": 25.86,
"change": 0.18,
"change_percent": 0.7,
"volume": 9803705,
"value": 252308343.0,
"liquidity": {
"inflow_value": 184950463.03,
"outflow_value": 67357881.91,
"net_value": 117592581.12
}
}Use --compact for single-line output, perfect for piping:
sahmk quote 2222 --compact4. Market Commands
Market Summary (TASI Index)
sahmk market summaryTop Gainers and Losers
sahmk market gainers --limit 5
sahmk market losers --limit 5Volume and Value Leaders
sahmk market volume --limit 10
sahmk market value --limit 10Sector Performance
sahmk market sectors5. Stock Data Commands
Batch Quotes (Starter+)
sahmk quotes 2222,1120,4191Historical OHLCV (Starter+)
sahmk historical 2222 --from 2026-01-01 --to 2026-01-31 --interval 1dInterval options: 1d (daily), 1w (weekly), 1m (monthly).
Company Profile (Free+)
sahmk company 2222Returns fundamentals, technicals, valuation, and analyst data (tiered by plan).
Financial Statements (Starter+)
sahmk financials 2222Returns income statements, balance sheets, and cash flows.
Dividend History (Starter+)
sahmk dividends 2222Returns trailing yield, upcoming distributions, and payment history.
Stock Events (Pro+)
sahmk events --symbol 2222 --limit 10Returns AI-generated event summaries. Omit --symbol for all recent events.
6. Real-Time Streaming (Pro+)
Stream live quote updates via WebSocket:
sahmk stream 2222,1120Quotes print as JSON lines to stdout, connection status goes to stderr. Press Ctrl+C to stop.
{"symbol":"2222","price":25.86,"change":0.18,"change_percent":0.7,"volume":9803705}
{"symbol":"1120","price":108.6,"change":0.2,"change_percent":0.18,"volume":3250100}7. Pro Tips
- →Shell scripting: Pipe
--compactoutput tojqfor filtering:
sahmk quote 2222 --compact | jq '.price'- →Watch mode: Monitor a stock with periodic refresh:
watch -n 30 sahmk quote 2222- →Batch scripting: Combine with shell loops:
for sym in 2222 1120 7010; do sahmk quote $sym --compact; done- →Error output: Errors go to stderr as JSON — your scripts won't break:
sahmk quote INVALID 2>/dev/null || echo "failed"Command Reference
| Command | Description | Plan |
|---|---|---|
| sahmk quote <symbol> | Single stock quote | Free |
| sahmk quotes <sym,sym,...> | Multiple quotes (comma-separated) | Starter+ |
| sahmk market summary | TASI index summary | Free |
| sahmk market gainers | Top gaining stocks | Free |
| sahmk market losers | Top losing stocks | Free |
| sahmk market volume | Volume leaders | Free |
| sahmk market value | Value leaders (SAR) | Free |
| sahmk market sectors | Sector performance | Free |
| sahmk historical <symbol> | Historical OHLCV data | Starter+ |
| sahmk company <symbol> | Company profile & fundamentals | Free+ |
| sahmk financials <symbol> | Financial statements | Starter+ |
| sahmk dividends <symbol> | Dividend history & yield | Starter+ |
| sahmk events | AI-generated stock events | Pro+ |
| sahmk stream <sym,sym,...> | Real-time WebSocket stream | Pro+ |
All commands support --compact for machine-readable output.
Start exploring from your terminal
Get your free API key and query Tadawul data with simple commands. No code required.