# Market Data

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

- Skill: `lisonevf/market-data` (Agent Skill)
- Install (CLI): `npx skillmds@latest add lisonevf/market-data`
- Raw SKILL.md: https://api.skillmd.com/api/skills/lisonevf/market-data/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: lisonevf (https://skillmd.com/u/lisonevf)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/lisonevf/market-data

---


# 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

```python
from pytdx2.client.quotationClient import QuotationClient
from pytdx2.const import MARKET, PERIOD

client = QuotationClient()
client.connect().login()
# Daily K-line for 平安银行
klines = client.get_KLine_data(MARKET.SZ, "000001", PERIOD.DAY, start=0, count=800)
# Real-time quotes for a batch
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

