a-share-real-time-dataFetch China A-share stock market data (bars, realtime quotes, tick-by-tick transactions) via mootdx/TDX protocol. Use when working with Chinese stock data, mootdx library, TDX quotes, intraday minute bars, transaction history, or real-time A-share market data.
Install via ClawdBot CLI:
clawdbot install wangdinglu/a-share-real-time-dataA wrapper around the mootdx library (TDX protocol) for fetching China A-share market data including K-line bars, real-time quotes, and tick-by-tick transaction records.
pip install mootdx
mootdxdepends ontdxpyinternally. Both are installed together.
python scripts/setup_and_verify.py # Install + verify + connectivity test
python scripts/setup_and_verify.py --check # Verify only (skip install)
python scripts/setup_and_verify.py --demo # Full API demo with real output
The --demo mode exercises every major API and prints real data — useful as a runnable reference for correct calling patterns.
| Session | Time |
|---------|------|
| Morning | 09:30 - 11:30 (120 min) |
| Lunch break | 11:30 - 13:00 |
| Afternoon | 13:00 - 15:00 (120 min) |
| Total | 240 trading minutes/day |
Problem: mootdx / tdxpy has a built-in time_frame() check that blocks API calls outside trading hours. On servers with non-Beijing timezone, this breaks even during valid trading hours.
Solution: Monkey-patch tdxpy.hq.time_frame to always return True:
import tdxpy.hq
tdxpy.hq.time_frame = lambda: True
This patch is applied automatically during MootdxClient.init(). Without it, transactions() and transaction() calls will silently return empty results outside detected trading hours.
When querying historical data, always check if a date is a trading day. Non-trading days (weekends, holidays) have no data. The client uses TradingCalendarStrategy.is_trading_day(date_str) for this — you must have a trading calendar service available.
| Parameter | Format | Example |
|-----------|--------|---------|
| date | YYYYMMDD | "20250210" |
| time | HH:MM:SS or HH:MM | "10:30:00" or "10:30" |
mootdx uses pure numeric codes (TDX format). Convert from standard format:
| Standard Format | TDX Format | Market |
|----------------|------------|--------|
| 000001.SZ | 000001 | Shenzhen |
| 600300.SH | 600300 | Shanghai |
| 300750.SZ | 300750 | Shenzhen (ChiNext) |
| 688001.SH | 688001 | Shanghai (STAR) |
Conversion: Strip the .SH / .SZ / .BJ suffix.
Important: mootdx does NOT support Beijing Stock Exchange (.BJ) stocks. Filter them out before calling.
from mootdx.quotes import Quotes
client = Quotes.factory(market='std')
get_bars() — K-Line / Candlestick DataFetch historical or real-time K-line bars.
await client.get_bars(
stock_code="000001.SZ", # Standard format (auto-converted)
frequency=7, # K-line period (see table below)
offset=240, # Number of bars to fetch
date="20250210", # Optional: specific date (YYYYMMDD)
time="10:30:00", # Optional: specific time (HH:MM:SS)
filter_by_time=True # Filter to closest bar matching time
)
Frequency codes:
| Code | Period |
|------|--------|
| 7 | 1-minute bars |
| 8 | 1-minute bars (alternative) |
| 4 | Daily bars |
| 9 | Daily bars (alternative) |
Return format (list of dicts):
{
"stock_code": "000001.SZ",
"datetime": "2025-02-10 10:30:00",
"open": 12.50,
"high": 12.65,
"low": 12.45,
"close": 12.60,
"vol": 150000.0,
"amount": 1890000.0
}
Start position calculation: For historical dates, the start parameter is calculated as the number of trading minutes (for 1-min bars) or trading days (for daily bars) between now and the target datetime. This accounts for:
get_realtime_quote() — Single Stock Real-Time Quoteawait client.get_realtime_quote(stock_code="000001.SZ")
Returns (dict): Price, OHLC, volume, amount, and full Level-2 order book (5-level bid/ask):
{
"stock_code": "000001.SZ",
"price": 12.60,
"last_close": 12.50,
"open": 12.45, "high": 12.65, "low": 12.40,
"volume": 5000000, "amount": 63000000,
"bid1": 12.59, "bid2": 12.58, ..., "bid5": 12.55,
"ask1": 12.60, "ask2": 12.61, ..., "ask5": 12.65,
"bid_vol1": 500, ..., "ask_vol5": 300,
"pct_chg": 0.8
}
get_realtime_quotes() — Batch Real-Time QuotesNative batch interface — much faster than looping get_realtime_quote().
await client.get_realtime_quotes(["000001.SZ", "600300.SH", "300750.SZ"])
Returns (list of dicts):
{
"stock_code": "000001.SZ",
"trade_date": "2025-02-10",
"open": 12.45, "high": 12.65, "low": 12.40, "close": 12.60,
"pre_close": 12.50,
"change": 0.15,
"pct_chg": 1.2048,
"vol": 5000000.0,
"amount": 63000000.0,
"is_realtime": true
}
pct_chg is calculated from today's open price, not previous close.
get_batch_bars() — Batch K-Line DataParallel fetch K-line bars for multiple stocks with concurrency control.
await client.get_batch_bars(
stock_codes=["000001.SZ", "600300.SH"],
date="20250210",
time="10:30:00",
max_concurrent=10
)
Returns: Dict[str, List[Dict]] — {stock_code: [bar_data, ...]}
get_transactions_history() — Historical Tick DataTick-by-tick transaction records for a specific historical date.
await client.get_transactions_history(
stock_code="000001.SZ",
date="20250210", # Required: YYYYMMDD
start=0,
offset=1000
)
Returns (list of dicts):
{
"stock_code": "000001.SZ",
"time": "09:30:05",
"price": 12.50,
"vol": 100,
"buyorsell": 0, # 0=buy, 1=sell, 2=neutral
"num": 5, # Number of trades in this tick
"volume": 100
}
get_transactions_realtime() — Real-Time Tick DataToday's live tick-by-tick transaction stream.
await client.get_transactions_realtime(
stock_code="000001.SZ",
start=0,
offset=1000
)
Same return format as get_transactions_history().
get_transactions_with_fallback() — Tick Data with FallbackTries real-time first, falls back to today's historical data if empty.
await client.get_transactions_with_fallback(
stock_code="000001.SZ",
start=0, offset=1000,
use_history_fallback=True
)
If using mootdx directly without the wrapper:
from mootdx.quotes import Quotes
client = Quotes.factory(market='std')
# K-line bars
df = client.bars(symbol="000001", frequency=7, start=0, offset=240)
# Real-time quotes (supports list of symbols for batch)
df = client.quotes(symbol="000001")
df = client.quotes(symbol=["000001", "600300"])
# Historical transactions
df = client.transactions(symbol="000001", start=0, offset=1000, date="20250210")
# Real-time transactions
df = client.transaction(symbol="000001", start=0, offset=1000)
All raw APIs return pandas DataFrames.
time_frame patch (see above).BJ codes are NOT supported — always filter them outGenerated Feb 25, 2026
Developers can use this skill to fetch 1-minute K-line bars for multiple A-share stocks to backtest intraday trading strategies. It supports historical date queries with proper trading calendar checks, enabling simulation of strategies based on price movements and volume during trading hours.
Build a dashboard that displays real-time quotes for a watchlist of A-share stocks, including price, bid-ask spreads, and volume. The batch real-time quotes API allows efficient updates without rate limiting, ideal for traders or financial analysts monitoring live market conditions.
Researchers can retrieve daily or minute-level historical stock data to analyze trends, volatility, or correlations in the Chinese stock market. The skill handles date formatting and trading day validation, ensuring accurate data collection for academic or institutional studies.
Integrate this skill into an automated trading system to fetch real-time quotes and transaction data for executing trades based on predefined algorithms. The timezone patch ensures reliable API access during Beijing trading hours, critical for low-latency applications.
Use the skill to periodically fetch real-time or historical data for a portfolio of A-share stocks, calculating returns and performance metrics. Batch APIs enable efficient data retrieval for multiple stocks, supporting tools used by investment managers or individual investors.
Offer a subscription-based platform that provides real-time and historical A-share market data to clients such as hedge funds or retail investors. Revenue is generated through tiered pricing based on data access levels, API call volumes, and additional analytics features.
Develop custom data feed solutions for financial institutions needing tailored A-share data, such as banks or brokerages. Revenue comes from one-time setup fees and ongoing maintenance contracts, leveraging the skill's ability to handle batch queries and real-time updates.
Create educational apps or courses that use real and historical A-share data to teach trading concepts. Revenue is generated through course sales, app subscriptions, or freemium models, utilizing the skill's demo scripts and clear API documentation for learner engagement.
💬 Integration Tip
Always apply the timezone patch during client initialization to bypass trading hour restrictions, and verify stock codes are in TDX format by stripping suffixes like .SH or .SZ before API calls.
Analyze stocks and cryptocurrencies using Yahoo Finance data. Supports portfolio management, watchlists with alerts, dividend analysis, 8-dimension stock scoring, viral trend detection (Hot Scanner), and rumor/early signal detection. Use for stock analysis, portfolio tracking, earnings reactions, crypto monitoring, trending stocks, or finding rumors before they hit mainstream.
Get stock prices, quotes, fundamentals, earnings, options, dividends, and analyst ratings using Yahoo Finance. Uses yfinance library - no API key required.
Yahoo Finance (yfinance) powered stock analysis skill: quotes, fundamentals, ASCII trends, high-resolution charts (RSI/MACD/BB/VWAP/ATR), plus optional web a...
Become an autonomous prediction market trader on Polymarket with AI-powered analysis and a performance-backed token on Base. Trade real markets, build a track record, and let the buyback flywheel run.
Get cryptocurrency token price and generate candlestick charts via CoinGecko API or Hyperliquid API. Use when user asks for token price, crypto price, price chart, or cryptocurrency market data.
Trade and monitor Hyperliquid perpetual futures. Check balances, view positions with P&L, place/cancel orders, execute market trades. Use when the user asks about Hyperliquid trading, portfolio status, crypto positions, or wants to execute trades on Hyperliquid.