Skip to main content

Quant Data SDK

PyPI License: MIT Tests Python

Official Python SDK for Quant Data API.

A 股行情、财务、行业、因子数据的官方 Python SDK。


✨ Features

  • 🚀 一行代码获取 A 股数据
  • 🤖 AI 代码生成(自然语言 → 策略代码)
  • 🔐 自动处理 API Key 认证
  • 🔁 内置重试、超时、错误处理
  • 📝 完整的类型提示(type hints)
  • 📦 支持上下文管理器(with 语法)
  • 🆓 支持匿名调用(无需注册)

📦 Installation

pip install zizhenghua-quant

🚀 Quick Start

1. 获取 API Key(可选)

匿名也能用,但限额较低。注册后可获得更高限额。

  1. 访问 https://zizhenghua.com 注册账号
  2. 登录后进入「账号设置」→「API Key 管理」
  3. 点击「+ 创建新 Key」,复制保存(只显示一次)

2. 调用

from quant_data_sdk import QuantDataClient

# 匿名(30 次/天 AI,10 次/分钟数据)
client = QuantDataClient()

# 或注册(100 次/天 AI,1000 次/天数据)
client = QuantDataClient(api_key="your_api_key_here")

# 获取贵州茅台实时行情
data = client.stock.get_realtime("600519")
print(data)

📖 使用示例

数据接口

from quant_data_sdk import QuantDataClient

client = QuantDataClient(api_key="your_key")

# 实时行情
data = client.stock.get_realtime("600519")

# K 线
kline = client.stock.get_kline("600519", "2024-01-01", "2024-12-31")

# 多条件选股
stocks = client.stock.filter_stocks(minTurnover=5, minRoe=15)

# 市场统计
stats = client.market.get_stats()

# 行业数据
sectors = client.sector.get_performance()

# 财务指标
fin = client.fin.get_latest("600519")

# 多因子排名
ranking = client.factor.get_ranking(topN=20)

AI 代码生成

# 通用方法
result = client.ai.generate_code(
    prompt="我想查看茅台23年到25年的布林带回测情况",
    language="python"
)
code = client.ai.extract_code(result["raw"])

# 快捷方法
client.ai.generate_bollinger("600519", "2023-01-01", "2025-12-31")
client.ai.generate_ma_cross("600519", "2023-01-01", "2025-12-31", fast=5, slow=20)
client.ai.generate_rsi("600519", "2023-01-01", "2025-12-31", oversold=30, overbought=70)
client.ai.generate_macd("600519", "2023-01-01", "2025-12-31")
client.ai.generate_kdj("600519", "2023-01-01", "2025-12-31")

上下文管理器

with QuantDataClient(api_key="your_key") as client:
    data = client.stock.get_realtime("600519")
    print(data)
# 自动关闭

自定义 base URL

# 本地开发
client = QuantDataClient(
    api_key="your_key",
    base_url="http://127.0.0.1:8080/api"
)

📊 限流

用户 数据接口 AI 接口
匿名 10 次/分钟,10,000 行/分钟 30 次/天
注册 300 次/分钟,600,000 行/分钟,1000 次/天 100 次/天

超限时抛 RateLimitError,并提示注册。


❌ 错误处理

from quant_data_sdk import QuantDataClient
from quant_data_sdk.exceptions import (
    AuthenticationError,
    RateLimitError,
    NotFoundError,
    ValidationError,
)

client = QuantDataClient(api_key="your_key")

try:
    data = client.stock.get_realtime("600519")
except AuthenticationError as e:
    print(f"认证失败: {e}")
except RateLimitError as e:
    print(f"限流: {e}")
except NotFoundError as e:
    print(f"资源不存在: {e}")
except ValidationError as e:
    print(f"参数错误: {e}")

📚 Documentation


🤝 Contributing

See CONTRIBUTING.md.


📄 License

MIT


⚠️ Disclaimer

数据仅供量化学习与策略回测研究之用,不构成任何投资建议。

AI 生成的代码不保证正确性,请自行检查后再使用。

Release files for zizhenghua-quant 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for zizhenghua-quant 1.0.0
File Size Uploaded
zizhenghua_quant-1.0.0.tar.gz 14.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for zizhenghua-quant 1.0.0
File Interpreter ABI Platform
zizhenghua_quant-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 28.3 kB

Release files / zizhenghua_quant-1.0.0.tar.gz

Download URL zizhenghua_quant-1.0.0.tar.gz
Size 14.3 kB
Tags Source
SHA-256 checksum
How to use checksums
5d509bc4dc0598af310a0bd2d893c9a0542335fb28c45f19a31be234b90e76dd
BLAKE2b-256 checksum
How to use checksums
96c3a17b525ab6e5c061bbb6b0a373ca19d21ac28f3516a7586bbd2b66e8d8eb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.10

Release files / zizhenghua_quant-1.0.0-py3-none-any.whl

Download URL zizhenghua_quant-1.0.0-py3-none-any.whl
Size 14.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ec20bed319c4104e2a74e96a170baad03cf87f82a5a9e93ed93b034af11e7f4c
BLAKE2b-256 checksum
How to use checksums
0d32249bfc3e55beb0dc9fcfe824fb285a9edcea1ebeb12f79b7ed93451a00b6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.10

Release history Release notifications | RSS feed

1.2.0

2 release files

1.1.0

2 release files

This release

1.0.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page