Skip to main content

A cryptocurrency trading info package

Project description

Crypto Service

一个基于 Python 的加密货币数据处理工具包,专注于数据获取、处理和分析。

功能特点

  • 支持币安的现货和永续合约数据获取
  • 高效的数据缓存和存储机制
  • 完整的类型提示和错误处理
  • 支持自定义数据格式和存储方式
  • 持续集成和自动发布

安装

pip install cryptoservice

快速开始

  1. 设置环境变量:
# 在 .env 文件中设置
BINANCE_API_KEY=your_api_key
BINANCE_API_SECRET=your_api_secret
  1. 基本使用:
from dotenv import load_dotenv
import os
from cryptoservice import MarketDataService
from cryptoservice.models import SortBy, Freq, HistoricalKlinesType

# 加载环境变量
load_dotenv()
api_key = os.getenv("BINANCE_API_KEY")
api_secret = os.getenv("BINANCE_API_SECRET")

# 创建服务实例
service = MarketDataService(api_key, api_secret)

# 获取单个交易对的行情数据
ticker = service.get_symbol_ticker("BTCUSDT")

# 获取排名靠前的币种数据
top_coins = service.get_top_coins(
    limit=10,
    sort_by=SortBy.QUOTE_VOLUME,
    quote_asset="USDT"
)

# 获取市场概况
summary = service.get_market_summary(interval=Freq.d1)

# 获取历史K线数据
klines = service.get_historical_klines(
    symbol="BTCUSDT",
    start_time="20240101",
    end_time="20240102",
    interval=Freq.h1,
    klines_type=HistoricalKlinesType.SPOT
)

# 获取永续合约数据
perpetual_data = service.get_perpetual_data(
    symbols=["BTCUSDT", "ETHUSDT"],
    start_time="20240101",
    end_time="20240102",
    freq=Freq.h1,
    store=True,  # 是否存储数据
    market="SWAP",
    features=["cls", "hgh", "low", "opn", "vwap", "vol"]
)

开发环境设置

  1. 克隆仓库:
git clone https://github.com/Mrzai/cryptoservice.git
cd cryptoservice
  1. 安装所有开发依赖:
pip install -e ".[dev-all]"  # 安装所有开发依赖
  1. 安装 pre-commit hooks:
pre-commit install

贡献指南

  1. Fork 项目
  2. 创建功能分支:git checkout -b feature/new-feature
  3. 提交更改:git commit -m 'feat: add new feature'
  4. 推送分支:git push origin feature/new-feature
  5. 提交 Pull Request

提交信息必须遵循 Conventional Commits 规范:

  • feat: 新功能
  • fix: 修复问题
  • docs: 文档更新
  • style: 代码格式调整
  • refactor: 代码重构
  • perf: 性能优化
  • test: 测试相关
  • chore: 构建过程或辅助工具的变动

许可证

MIT License

联系方式

提交规范

提交信息必须遵循以下格式:

<type>(<scope>): <subject>

<body>

<footer>

例如:

# 新功能
feat(market): add historical data support

Added support for fetching historical market data
with customizable time ranges and intervals.

# 修复bug
fix(cache): resolve memory leak issue

Fixed memory leak in cache manager when handling
large datasets.

# 文档更新
docs(readme): update installation guide

Updated installation instructions to include
new development dependencies.

提交类型必须是以下之一:

  • feat: 新功能
  • fix: 修复问题
  • docs: 文档更新
  • style: 代码格式调整
  • refactor: 代码重构
  • perf: 性能优化
  • test: 测试相关
  • chore: 构建过程或辅助工具
  • revert: 回退
  • ci: CI/CD相关
  • build: 构建系统

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-0.2.1.tar.gz (3.5 kB view details)

Uploaded Source

Built Distribution

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

cryptoservice-0.2.1-py3-none-any.whl (3.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: cryptoservice-0.2.1.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.15

File hashes

Hashes for cryptoservice-0.2.1.tar.gz
Algorithm Hash digest
SHA256 9c1a93028b3df85999a5d0b053fb6cec556bb52e62d1a4f3a43bdb879489a8a6
MD5 66e36490178fa5cf58fd3e48f9867db6
BLAKE2b-256 88af41836a1bbb2e36d776be221e5a02cea9043d872130bc57ca113ee4200450

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cryptoservice-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 3.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.15

File hashes

Hashes for cryptoservice-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 37e3d3dd6852e57e2ab9ccdfac51853855b467628a873437f58b4eb6e0216720
MD5 10afe7d50913b1c63c14bf1ab11e3b9e
BLAKE2b-256 fc29e896fb0999958cbc727b1c393964db43fe31fb04f17a3e7d5037993b4605

See more details on using hashes here.

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