Unified wrapper around pytdx-style market data APIs.
Project description
zsdtdx
zsdtdx 是面向 A 股/期货行情场景的 Python 封装库,基于 pytdx 生态提供统一 API、连接池、重试和并行抓取能力。
安装
pip install zsdtdx
simple_api 快速开始
1) sync 模式(阻塞返回)
import queue as py_queue
from zsdtdx import StockKlineTask, get_client, get_stock_kline
with get_client() as client:
q = py_queue.Queue()
payloads = get_stock_kline(
task=[
StockKlineTask(code="600000", freq="d", start_time="2026-02-01", end_time="2026-02-14"),
{"code": "000001", "freq": "60", "start_time": "2026-02-01", "end_time": "2026-02-14"},
],
queue=q,
mode="sync",
)
print(f"sync payload count: {len(payloads)}")
2) async 模式(队列实时消费)
from zsdtdx import get_client, get_stock_kline
with get_client() as client:
job = get_stock_kline(
task=[{"code": "600000", "freq": "d", "start_time": "2026-02-01", "end_time": "2026-02-14"}],
mode="async",
)
while True:
event = job.queue.get(timeout=20)
if event.get("event") == "done":
break
# event="data" 时:按 task/rows/error 实时处理
print(event.get("task"), event.get("error"))
# 等待后台任务结束并传播异常
job.result()
关键行为说明
- 时间窗口按闭区间
[start_time, end_time]处理。 - 股票 task 日期输入会自动补全为:
start_time:09:30:00end_time:16:00:00
- 期货时间窗口日期输入会自动补全为:
start_time:09:00:00end_time:15:00:00
get_stock_kline仅接受task列表(元素为StockKlineTask或dict)。- 队列事件结构:
- 数据事件:
{"event":"data","task":{...},"rows":[...],"error":str|None,"worker_pid":int} - 完成事件:
{"event":"done","total_tasks":...,"success_tasks":...,"failed_tasks":...}
- 数据事件:
并行模型(task 链路)
chunk:同code+freq的任务集合,内部按start_time升序执行。bundle:提交给单个进程池 future 的 chunk 批次。- async(多进程):
- 父进程将 bundle 提交给
ProcessPoolExecutor。 - worker 进程内再以
ThreadPoolExecutor并发 chunk(上限由task_chunk_inproc_future_workers控制)。 - 队列结果以“bundle 回收”为触发点写入(非 worker 内单 chunk 直接跨进程推送)。
- 父进程将 bundle 提交给
- sync(单进程):
- 不启用多进程时,在主进程内直接并发 chunk future。
配置说明
- 默认读取包内
config.yaml。 - 可显式指定配置路径:
from zsdtdx import get_client
with get_client(config_path=r"D:\\configs\\zsdtdx.yaml") as client:
...
- 常用并行配置位于
config.yaml.parallel:task_chunk_cache_min_taskstask_chunk_inproc_future_workerstask_chunk_max_inflight_multiplierchunk_reconnect_on_unavailablechunk_reconnect_max_attemptsauto_prewarm_on_asyncauto_prewarm_require_all_workersauto_prewarm_timeout_secondsauto_prewarm_max_roundsauto_prewarm_spread_standard_hosts
API 概览
get_clientget_supported_marketsget_stock_code_nameget_all_future_listget_stock_klineget_future_klineget_company_infoget_stock_latest_priceget_future_latest_priceget_runtime_failuresget_runtime_metadata
运行环境与依赖
- Python:
>=3.10 - 依赖:
pandas、PyYAML、six、psutil
开发文档
HANDOFF.mdPERFORMANCE_REPORT.mdexamples/
许可证与来源
- 许可证:
MIT(见LICENSE) - 第三方归属:见
THIRD_PARTY_NOTICES.md
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
zsdtdx-1.1.0.tar.gz
(91.6 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
zsdtdx-1.1.0-py3-none-any.whl
(124.1 kB
view details)
File details
Details for the file zsdtdx-1.1.0.tar.gz.
File metadata
- Download URL: zsdtdx-1.1.0.tar.gz
- Upload date:
- Size: 91.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b034fab2e677a2647f060f38a6ddfa5ff53b3647462628b664a3e97417b474c9
|
|
| MD5 |
6419303dab8e8fb5c71504f0933a176b
|
|
| BLAKE2b-256 |
dd559bd1d59932f272734135015e7d87041c463ebc82d9c8235662a35716caaf
|
File details
Details for the file zsdtdx-1.1.0-py3-none-any.whl.
File metadata
- Download URL: zsdtdx-1.1.0-py3-none-any.whl
- Upload date:
- Size: 124.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f44b934357b8f15df56ed2358be8b844aa8a7cbe90f33638f7c188ce745fa6ab
|
|
| MD5 |
1a2e444bfb7c53ed06bab5bbf27e4fcf
|
|
| BLAKE2b-256 |
1019a05d843152c6f1fac724a3c903fb493f86d23124f495c0d44c7254f6d538
|