Skip to main content

A-Query Open API Python SDK - A股20年全量数据查询服务

Project description


title: A-Query Open API emoji: 📊 colorFrom: blue colorTo: green sdk: docker pinned: false

A-Query Open API

A股20年全量数据查询服务 - 统一API接口

项目概述

基于Hugging Face数据集构建的A股数据查询服务,提供统一、高效、易用的数据查询接口。

数据范围: 2000年-2026年,覆盖全部A股上市公司
数据来源: Tushare Pro
存储位置: Hugging Face Datasets

快速开始

1. 安装客户端

pip install pandas requests
# 然后将client文件夹复制到你的项目中

2. 使用Python SDK

from client import AQueryClient

# 初始化客户端
client = AQueryClient(token="your_token")

# 查询股票基础信息
df = client.stock_basic(market="主板")
print(df.head())

# 查询个股历史数据
df = client.daily_history(
    ts_code="000001.SZ",
    start_date=20240101,
    end_date=20241231,
    fields=["trade_date", "open", "close", "vol", "pe"]
)
print(df)

# 查询某日全市场数据
df = client.daily_all(
    trade_date=20240320,
    fields=["ts_code", "close", "pe", "net_mf_amount"]
)
print(df.head(10))

3. HTTP API调用

curl -X POST https://your-space.hf.space/api/v1/query \
  -H "Content-Type: application/json" \
  -H "X-Token: your_token" \
  -d '{
    "api_name": "daily_history",
    "params": {
      "ts_code": "000001.SZ",
      "start_date": 20240101,
      "end_date": 20240131
    },
    "fields": "trade_date,open,high,low,close,vol"
  }'

支持的API列表

api_name 数据集 说明 主要参数
stock_basic A_meta_info 股票基础信息 ts_code, market
trade_cal A_meta_info 交易日历 start_date, end_date
company_info A_meta_info 公司信息 ts_code
industry_sw A_meta_info 申万行业映射 ts_code, industry_level
industry_sw_class A_meta_info 申万行业分类 level
fina_indicator A_meta_info 财务指标 ts_code, end_date
daily A_by_date 日线行情 ts_code, trade_date, start_date, end_date
daily_all A_by_date 某日全市场 trade_date
daily_history A_by_code 个股历史 ts_code, start_date, end_date

统一接口规范

请求格式

{
  "api_name": "daily_history",
  "token": "your_token",
  "params": {
    "ts_code": "000001.SZ",
    "start_date": 20240101,
    "end_date": 20241231
  },
  "fields": "trade_date,open,close,vol"
}

响应格式

{
  "code": 0,
  "msg": "success",
  "data": {
    "fields": ["trade_date", "open", "close", "vol"],
    "items": [
      [20240102, 9.5, 9.7, 1000000],
      [20240103, 9.7, 9.8, 1200000]
    ],
    "count": 2,
    "has_more": false
  },
  "request_id": "req_abc123"
}

本地部署

1. 克隆项目

git clone <repository-url>
cd a-query

2. 安装依赖

pip install -r requirements.txt

3. 运行服务

python -m uvicorn app.main:app --host 0.0.0.0 --port 7860 --reload

4. Docker部署

docker build -t aquery-api .
docker run -p 7860:7860 aquery-api

Hugging Face Space部署

  1. 在Hugging Face创建新的Space,选择Docker模板
  2. 将代码推送到Space仓库
  3. 配置环境变量(如果需要)
  4. 访问Space URL查看API文档

查询示例

示例1: 获取某股票历史数据

df = client.daily_history(
    ts_code="000001.SZ",
    start_date=20240101,
    end_date=20241231
)

示例2: 获取某日全市场数据

df = client.daily_all(
    trade_date=20240320,
    fields=["ts_code", "close", "pe", "net_mf_amount", "total_mv"]
)

示例3: 条件选股

# 查询某日PE<20且净流入>1亿的股票
df = client.daily_all(trade_date=20240320)
df = df[(df['pe'] < 20) & (df['net_mf_amount'] > 1e8)]

示例4: 获取财务指标

df = client.fina_indicator(
    ts_code="000001.SZ",
    fields=["end_date", "roe", "eps", "grossprofit_margin"]
)

性能指标

场景 数据量 响应时间
股票基础信息 5,200条 < 50ms
个股全历史 5,000条 < 200ms
单日全市场 5,200条 < 100ms
时间段截面 100万条 < 2s

项目结构

.
├── app/                    # FastAPI服务端
│   ├── main.py            # 应用入口
│   ├── core/              # 配置、认证
│   ├── routers/           # API路由
│   └── services/          # 查询服务
├── client/                 # Python SDK
│   └── aquery.py         # 客户端实现
├── tests/                  # 测试
├── Dockerfile             # 容器配置
├── requirements.txt       # Python依赖
└── README.md              # 本文档

技术栈

  • FastAPI: 高性能Web框架
  • DuckDB: 嵌入式OLAP查询引擎
  • Polars: 极速数据处理
  • Hugging Face Datasets: 数据存储

许可证

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

aquery_sdk-1.0.1.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

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

aquery_sdk-1.0.1-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file aquery_sdk-1.0.1.tar.gz.

File metadata

  • Download URL: aquery_sdk-1.0.1.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for aquery_sdk-1.0.1.tar.gz
Algorithm Hash digest
SHA256 471b46563677249b8f80e6e11cd6f2123009a81d32d5c70935752a174ec06628
MD5 44b765468c30c9d9f63265cc4c005021
BLAKE2b-256 3a0047987385c58ceee71e9a6000644309217feab1ec9c930004ae3660757276

See more details on using hashes here.

File details

Details for the file aquery_sdk-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: aquery_sdk-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 8.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for aquery_sdk-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 532b9abccfd659a3a8a9cd2ec057d7283cbd74ce81e4e3d460ca915c29c740c9
MD5 3913bb791f6ed16f70d57bd57e05e055
BLAKE2b-256 c764e9cf9383558fdf1419016153747c06c2b56fb4e5c498382d3c215af85180

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