| name | market-data |
| description | Fetches and processes real-time and historical stock market data from TDX protocol servers. Provides K-line data at multiple intervals, real-time quotes, and market overviews. Trigger when the user requests stock prices, market data, or financial instrument data. |
| metadata | {"hermes":{"tags":["market-data","tdx","stock","kline","quotes"],"category":"trading","requires_toolsets":["terminal"]}} |
Market Data
Fetches stock market data from TDX (通达信) protocol servers.
Real Code Reference
tradinglearn/pytdx2/client/quotationClient.py — QuotationClient with get_KLine_data(), get_security_quotes(), etc.
tradinglearn/pytdx2/client/baseStockClient.py — BaseStockClient socket layer with auto-retry
tradinglearn/pytdx2/const.py — MARKET, CATEGORY, PERIOD enums, 43+ server hosts
Capabilities
- Real-time quotes:
get_security_quotes() / get_security_quotes_details() (with 5-level depth)
- K-line (OHLCV) data:
get_KLine_data(market, code, period, start, count) — 1min to yearly
- Market categories: Shanghai A, Shenzhen A, Growth Enterprise, Beijing A; futures, options, HK stocks
- Market overview:
get_top_stock_board(category) — top gainers/losers/amplitude, get_index_info()
Typical Workflow
from pytdx2.client.quotationClient import QuotationClient
from pytdx2.const import MARKET, PERIOD
client = QuotationClient()
client.connect().login()
klines = client.get_KLine_data(MARKET.SZ, "000001", PERIOD.DAY, start=0, count=800)
quotes = client.get_security_quotes(["000001", "000002"])
client.disconnect()
Notes
- K-line prices divided by 1000; quote prices divided by 100
- Always call
client.disconnect() — sockets leak otherwise
data_fetcher.py wraps this with retry logic and DataFrame normalization