Skip to main content

A cryptocurrency trading info package

Project description

CryptoService

一个高性能的Python加密货币数据处理包,专注于币安市场数据的获取、存储和分析。

✨ 核心功能

  • 🚀 高性能异步:全面支持async/await,高效处理大量数据
  • 📊 全面数据覆盖:现货、永续合约、历史K线、实时WebSocket
  • 💾 智能存储:SQLite数据库 + 文件导出,支持增量更新
  • 🔧 开箱即用:完整的类型提示、错误处理和重试机制
  • 📈 数据处理:内置数据转换、验证和分析工具

📦 安装

pip install cryptoservice

🚀 快速开始

1. 环境配置

# .env 文件
BINANCE_API_KEY=your_api_key
BINANCE_API_SECRET=your_api_secret

2. 基本使用

import asyncio
from cryptoservice import MarketDataService

async def main():
    # 创建服务实例
    service = MarketDataService()

    # 获取实时行情
    ticker = await service.get_ticker("BTCUSDT")
    print(f"BTC价格: {ticker.price}")

    # 下载历史数据
    await service.download_klines("BTCUSDT", "1d", "2024-01-01", "2024-12-31")

asyncio.run(main())

📋 完整工作流程演示

demo/ 目录提供了完整的端到端工作流程示例,从定义交易宇宙到数据分析的全流程:

# 步骤1: 定义交易宇宙(筛选符合条件的交易对)
python demo/define_universe.py

# 步骤2: 下载历史数据到数据库(增量模式)
python demo/download_data.py

# 步骤3: 导出数据到numpy/CSV格式
python demo/export_data.py

# 额外: WebSocket实时数据流
python demo/websocket.py

演示脚本说明

  • define_universe.py: 定义加密货币交易宇宙,根据成交量、存续期等条件筛选交易对
  • download_data.py: 批量下载历史K线数据和市场指标(资金费率、持仓量、多空比例)
  • export_data.py: 导出数据为numpy数组格式,便于量化分析和机器学习
  • websocket.py: WebSocket客户端示例,展示实时数据流处理

详细使用说明请参考 demo/README.md

🛠️ 开发环境

# 克隆项目
git clone https://github.com/ppmina/xdata.git
cd xdata

# 安装uv(推荐)
./scripts/setup_uv.sh  # macOS/Linux
# 或 .\scripts\setup_uv.ps1  # Windows

# 安装依赖
uv pip install -e ".[dev-all]"

# 激活环境
source .venv/bin/activate

常用命令

pytest                    # 运行测试
ruff format              # 格式化代码
ruff check --fix         # 检查并修复
mypy src/cryptoservice   # 类型检查
mkdocs serve            # 本地文档

🚢 发布流程(main release)

个人维护时推荐手动准备版本,并由 GitHub Actions 负责最终构建/发布:

  1. 确保工作区干净并切到 main 分支。
  2. 运行 python3 scripts/prepare_release.py 1.12.0 --auto --push(替换为目标版本),脚本会从 main 检出新分支 release/v1.12.0,同步更新版本号,生成最新的 CHANGELOG.md 段落,执行 pytest,提交 chore: release v1.12.0、创建 v1.12.0 标签,并将分支和标签推送到远端。若只想本地检查,可省略 --push;如无需运行测试可加 --skip-tests;也可通过 --base / --release-branch 定制分支名称。
  3. Release 工作流会在标签推送后自动运行测试、构建以及(若配置了 PYPI_API_TOKEN)上传到 PyPI;也可以在 GitHub Actions 中手动触发该工作流只做验证。

若只想更新版本号,可使用 --skip-changelog 跳过自动生成的变更记录;(#123) 的提交引用会自动转为 GitHub PR 链接。

📚 文档

完整文档:https://ppmina.github.io/Xdata/

🤝 贡献

  1. Fork项目并创建分支:git checkout -b feature/your-feature
  2. 遵循Conventional Commits规范
  3. 提交Pull Request

提交类型:feat | fix | docs | style | refactor | perf | test | chore

📄 许可证

MIT License

📞 联系

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cryptoservice-1.19.2.tar.gz (103.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cryptoservice-1.19.2-py3-none-any.whl (139.0 kB view details)

Uploaded Python 3

File details

Details for the file cryptoservice-1.19.2.tar.gz.

File metadata

  • Download URL: cryptoservice-1.19.2.tar.gz
  • Upload date:
  • Size: 103.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for cryptoservice-1.19.2.tar.gz
Algorithm Hash digest
SHA256 50164da21923b7a4904686ba10fed673b758ffe95244c300563b11e370c841c9
MD5 1c98e033bdb81e25261cf837ad22cbab
BLAKE2b-256 1709e9ef03456d1a6e1d037a9c3355d1fdebdc4e4657feabc50dc6055c892497

See more details on using hashes here.

Provenance

The following attestation bundles were made for cryptoservice-1.19.2.tar.gz:

Publisher: release.yml on ppmina/Xdata

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cryptoservice-1.19.2-py3-none-any.whl.

File metadata

  • Download URL: cryptoservice-1.19.2-py3-none-any.whl
  • Upload date:
  • Size: 139.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for cryptoservice-1.19.2-py3-none-any.whl
Algorithm Hash digest
SHA256 14bf834450834f3b5ccdff5562913de250518031665ed42a78751bf09d157b19
MD5 05e8c33f97ca842e4b26d97d069ad255
BLAKE2b-256 84b4b75a11f1836c7adc8fb48ba70d8814bb5c05c1ac8d2b741d69b6f4355b59

See more details on using hashes here.

Provenance

The following attestation bundles were made for cryptoservice-1.19.2-py3-none-any.whl:

Publisher: release.yml on ppmina/Xdata

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page