Skip to main content

infra-data-client — InfraX data-service 官方 Python SDK

InfraX data-service(统一市场数据微服务,/bars / /factors/* / /snapshots / /ticker / /symbols/* / /stats / /health)的官方 Python 客户端。B 端(AItrader 侧)用这一个类替换各自重复实现的 data_client.py / factor_client.py,收敛鉴权、TLS、限流、时间换算口径。

  • 版本:0.2.0(SemVer;契约变更走 minor,bug 修复走 patch,AItrader 侧升级 SDK 即可,无需改业务代码)
  • 依赖:requests>=2.25(Python ≥ 3.9)

安装

# 本地构建安装
cd projects/data/sdk/python
pip install .

# 或直接 git 引用(发布到私有源后改用 pip install infra-data-client)
pip install "git+https://<你的仓库>/infraX-1.git#subdirectory=projects/data/sdk/python"

# 开发模式(改代码即生效)
pip install -e .

快速开始

from infra_data_client import InfraDataClient

client = InfraDataClient(
    base_url="http://127.0.0.1:9112",   # 生产经 nginx 前缀如 https://host/api/data 亦可
    api_key="infrax-bridge-...",         # X-Service-Key 自动携带(DS-12)
    verify=False,                        # 生产证书暂不可信时关闭校验
)

# K 线(start/end 秒或毫秒均可,自动归一化)
bars = client.get_bars("BTC/USDT", timeframe="1h", limit=10)

# 最新因子(含 DS-13 ML 因子)
factors = client.get_current_factors("BTC,ETH")

# 实时报价
ticker = client.get_ticker("BTC/USDT", market_type="swap")

# 符号解析 / 搜索
resolved = client.resolve_symbol("BTC")
hits = client.search_symbols("btc", market="crypto", limit=10)

API 一览

方法 端点 说明
get_bars(symbol, timeframe, market_type, start, end, limit) GET /bars OHLCV + 指标 + 外部因子,ts 毫秒升序
get_factor_catalog() GET /factors/catalog 因子目录(含 ML category="ml")
get_current_factors(symbols, category) GET /factors/current 最新因子(symbols 支持 "BTC,ETH"["BTC","ETH"]
get_history_factors(symbol, timeframe, ids, start, end, limit) GET /factors/history 逐 bar 因子历史(asof 对齐,回测无未来函数)
get_snapshots(snapshot_type) GET /snapshots 板块快照(heatmap/calendar/crypto_prices/indices/tvl/volatility/us_indicators/earnings/onchain/commodities/forex_pairs/market_overview)
get_ticker(symbol, market_type, exchange_id, market) GET /ticker 实时报价
get_ml_predictions(model, symbol, start, end, limit) GET /ml/predictions P2 模型预测快照(优先路径,30min 落库);model=bolt|moirai|timesfm,无快照返回 None
resolve_symbol(symbol, market) GET /symbol/resolve 符号解析(全市场,DS-11)
search_symbols(keyword, market, limit) GET /symbols/search 符号模糊搜索(DS-9)
get_broker_market_policy() GET /policy/broker-market 券商市场策略
get_stats() GET /stats 数据库统计
health() GET /health 健康检查(免鉴权)

核心能力

  • 鉴权内置api_key 自动写入 X-Service-Key 请求头(DS-12 契约),调用方零配置。
  • TLS 可配置verify=False 应对生产证书不可信现状(同时抑制 InsecureRequestWarning)。
  • 429 限流重试:命中 429 自动重试,优先 Retry-After 头,无则指数退避 backoff * 2^attemptmax_retries=0 关闭重试。
  • fail-silent(默认开):网络错误 / 非 2xx(401/404/500…)返回 None,业务不中断;fail_silent=False 时抛 InfraDataError(status, message) 便于排查。
  • 时间单位归一化start/end 传秒或毫秒均可(≥10^12 视为毫秒),SDK 统一换算后上送。
  • 类型注解:全部方法与返回类型标注,IDE 与静态检查友好;Client 支持上下文管理器(自动关闭连接池)。

示例

cd projects/data/sdk/python
python examples/quickstart.py --base-url http://127.0.0.1:9112 --api-key <KEY>
python examples/ml_predictions_integration.py --symbol BTC/USDT --model bolt \
    --data-url http://127.0.0.1:9112 --data-key <KEY> --ml-url http://43.156.25.197:9120

发布(SemVer)

cd projects/data/sdk/python
pip install build
python -m build        # 产出 dist/infra_data_client-0.2.0-*.whl / .tar.gz
# 上传到私有 pip 源,或直接分发 wheel

契约变更规范:新增端点/参数 → minor;修复行为 → patch;破坏性变更 → major。

Download files

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

Source Distribution

infra_data_client-0.2.0.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

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

infra_data_client-0.2.0-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file infra_data_client-0.2.0.tar.gz.

File metadata

  • Download URL: infra_data_client-0.2.0.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.3

File hashes

Hashes for infra_data_client-0.2.0.tar.gz
Algorithm Hash digest
SHA256 f364abd31aae71f9d772b6330f5540c5b2649bad92ff093ef594fa406dd44965
MD5 743788eb0c5c1afa64af83c8234afbfd
BLAKE2b-256 f61ddd6704a89f6dd79415e8306bc1df0cf2968ea16f1d24f049e8aff6079eb9

See more details on using hashes here.

File details

Details for the file infra_data_client-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for infra_data_client-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 713a613dbb6ef970f908b658af474a33efbd61c9b66438980fc981a21745cb7c
MD5 bbc5d477581d9541778fb5dcbac11d4e
BLAKE2b-256 4b38bf71b4c51f9d75a1925fa008d3446d6bf2e1c32b2b5ee5737d1c96a5a977

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 Sentry Error logging StatusPage Status page