Skip to main content

🇨🇳 China Stock Data

一个现代化的中国股市数据获取库

Python Version PyPI Version License Tests Coverage Docs

🚀 快速开始 • 📖 在线文档 • 💡 示例 • 🤝 贡献


✨ 功能特性

🎯 智能数据获取 - 基于 AkShare 的现代化封装
⚡ 智能缓存机制 - 交易时间感知的数据缓存,提升访问效率
🔄 数据持久化 - 自动数据存储与管理,减少重复请求
📊 多维度分析 - 支持个股、指数、市场情绪等多角度数据
🛡️ 类型安全 - 完整的类型提示,IDE友好的开发体验
🧪 测试覆盖 - 95%+ 测试覆盖率,可靠稳定

🚀 快速开始

安装

pip install china_stock_data

30秒快速体验

from china_stock_data import StockData, StockMarket

# 获取股票数据
stock = StockData("000001", days=30)  # 平安银行最近30天
price_data = stock.get_data("kline")
print(f"最新价格: ¥{price_data['收盘'].iloc[-1]:.2f}")

# 获取市场数据
market = StockMarket("000300")  # 沪深300指数
components = market.get_data("index_components")
print(f"成分股数量: {len(components)}")

💡 使用示例

📈 个股分析

# 技术分析
stock = StockData("600519")  # 贵州茅台
kline = stock.get_data("kline")
realtime = stock.get_data("realtime")

# 计算移动平均线
kline['MA20'] = kline['收盘'].rolling(20).mean()

# 获取公司信息
info = stock.get_data("info")

🏢 市场分析

# 市场情绪分析
market = StockMarket()
sentiment = market.get_data("sentiment")
index_list = market.get_data("index_list")

# 指数成分股分析
csi300 = StockMarket("000300")
components = csi300.get_data("index_components")

📊 批量分析

# 投资组合分析
symbols = ["000001", "000002", "600519"]
portfolio = {}

for symbol in symbols:
    stock = StockData(symbol, days=252)
    data = stock.get_data("kline")
    portfolio[symbol] = data['收盘']

# 计算相关性、收益率等...

📁 项目结构

china_stock_data/
├── 📦 fetchers/              # 数据获取器 (按类别组织)
│   ├── 📈 stock/            # 个股数据获取器
│   ├── 📊 index/            # 指数数据获取器
│   ├── 🏢 market/           # 市场数据获取器
│   └── 🔧 base_fetcher.py   # 基础获取器
├── 💾 persistent_dict.py     # 数据持久化
├── ⏰ trading_time_checker.py # 交易时间管理
├── 📈 stock_data.py         # 个股数据类
├── 🏢 stock_market.py       # 市场数据类
└── 📝 examples/             # 使用示例
    ├── quick_start.ipynb    # 5分钟快速入门
    ├── professional_analysis.ipynb  # 专业技术分析
    └── portfolio_analysis.ipynb     # 投资组合管理

🎓 学习资源

📚 完整示例教程

🛠️ 开发

环境设置

# 克隆仓库
git clone https://github.com/sjzsdu/china_stock_data.git
cd china_stock_data

# 安装依赖 (推荐使用 Poetry)
poetry install

# 运行测试
poetry run pytest

API 参考

StockData

方法 说明 示例
get_data("kline") 获取K线数据 历史价格、成交量
get_data("realtime") 获取实时数据 当前价格、买卖盘
get_data("info") 获取基本信息 公司概况、财务指标
get_data("chip") 获取筹码分布 持仓成本分布

StockMarket

方法 说明 示例
get_data("index_components") 指数成分股 沪深300成分股列表
get_data("index_list") 指数列表 所有可用指数
get_data("sentiment") 市场情绪 情绪指标数据
get_data("us_index") 美股指数 道琼斯、纳斯达克

🤝 贡献

我们欢迎各种形式的贡献!

🐛 发现了问题? 提交 Issue
💡 有好想法? 发起讨论
🔧 想要改进? 提交 Pull Request

贡献步骤

  1. 🍴 Fork 本仓库
  2. 🌟 创建特性分支: git checkout -b feature/amazing-feature
  3. 💻 编写代码并添加测试
  4. ✅ 确保测试通过: poetry run pytest
  5. 📝 提交更改: git commit -m 'Add amazing feature'
  6. 🚀 推送分支: git push origin feature/amazing-feature
  7. 🔄 创建 Pull Request

📞 支持

📄 许可证

本项目采用 MIT 许可证。

🙏 致谢

  • 感谢 AkShare 提供的数据接口
  • 感谢所有贡献者的支持与帮助

⭐ 如果这个项目对你有帮助,请给我们一个星标!

⭐ Star • 👀 Watch • 🍴 Fork

Metadata

Release files for china_stock_data 0.2.2

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

Source distribution (sdist)

Source distribution for china_stock_data 0.2.2
File Size Uploaded Provenance
china_stock_data-0.2.2.tar.gz 19.4 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for china_stock_data 0.2.2
File Interpreter ABI Platform
china_stock_data-0.2.2-py3-none-any.whl Python 3 none any Details

Total release size: 56.0 kB

Release files / china_stock_data-0.2.2.tar.gz

Download URL china_stock_data-0.2.2.tar.gz
Size 19.4 kB
Tags Source
SHA-256 checksum
How to use checksums
5dd4a1c02568861b8526e10e295077daead7c5d8cb00039fc6a7aae936577cfb
BLAKE2b-256 checksum
How to use checksums
19f04896c3a984ded2ae28c04d7584e378b12d6886f72a3501f5a7ee2f943944
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.2.1 CPython/3.12.11 Linux/6.11.0-1018-azure

Release files / china_stock_data-0.2.2-py3-none-any.whl

Download URL china_stock_data-0.2.2-py3-none-any.whl
Size 36.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
853479f20c2ad9bbed57f04cb886e60ed4a999b7b3f9d81bd82ad9f44d85d658
BLAKE2b-256 checksum
How to use checksums
14c9d8e9c1f2a4d60b6ab987ae878853c4a89269a39050c42efef5d59858823c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.2.1 CPython/3.12.11 Linux/6.11.0-1018-azure

Security for china_stock_data 0.2.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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