Skip to main content

实时行情采集服务,支持新浪和腾讯数据源

Project description

qdata-quote

实时 A 股行情采集服务,支持新浪和腾讯两个数据源。性能超越 easyquotation 约 8-10%。

安装

pip install qdata-quote

快速开始

from qdata_quote import QuoteService

# 默认加载全市场股票列表(初始化时自动从网络刷新)
service = QuoteService()

# 同步获取指定股票行情
df = service.get_real_sync(["000001", "600000"])
print(df)

# 同步获取全市场行情快照
df_all = service.get_all_sync()

# 异步获取(高性能路径)
import asyncio
df = asyncio.run(service.get_real(["000001", "600000"]))
df_all = asyncio.run(service.get_all())

自定义股票列表

from qdata_quote import QuoteService

# 传入自定义股票列表(不会自动刷新)
service = QuoteService(codes=["000001", "600000", "300750"])

# 随时替换股票列表(切换为自定义模式,不再接受 refresh)
service.set_stock_codes(["000001", "600000"])

# 刷新全市场股票列表(仅在使用默认列表时生效)
service.refresh_stock_codes()

获取股票代码

from qdata_quote import get_stock_codes

# 读取缓存(如果没有缓存则自动获取)
codes = get_stock_codes()

# 强制从网络刷新
codes = get_stock_codes(refresh=True)

缓存文件位置:~/.qdata_quote/stock_codes.json

数据源

支持两个数据源,通过 source 参数指定:

# 新浪源(默认)
df = service.get_real_sync(["000001"], source="sina")

# 腾讯源(字段更丰富)
df = service.get_real_sync(["000001"], source="tencent")
数据源 每批数量 特点
sina 800 只/批 速度快,基础字段齐全
tencent 60 只/批 额外提供涨跌、市盈率、市值、量比等

返回格式

返回统一的 pandas.DataFrame,index 为带市场前缀的股票代码(如 sh600000sz000001)。

字段列表

字段 类型 新浪 腾讯 说明
code str 股票代码(index)
name str 股票名称
open float 开盘价
close float 昨收价
now float 当前价
high float 最高价
low float 最低价
buy float - 买一价
sell float - 卖一价
volume float 成交量(股)
turnover float 成交额(元)
bid1 ~ bid5 float 买一到买五价
bid1_volume ~ bid5_volume float 买一到买五量(股)
ask1 ~ ask5 float 卖一到卖五价
ask1_volume ~ ask5_volume float 卖一到卖五量(股)
datetime str 行情时间
change float - 涨跌额
change_pct float - 涨跌幅(%)
amplitude float - 振幅
pe_dynamic float - 动态市盈率
pe_static float - 静态市盈率
pb float - 市净率
total_market_cap float - 总市值
circulating_market_cap float - 流通市值
volume_ratio float - 量比
bid_ask_ratio float - 委比
avg_price float - 均价
limit_up float - 涨停价
limit_down float - 跌停价

✅ 表示有数据,- 表示 NaN。腾讯源提供更丰富的衍生指标。

会话管理

建议使用上下文管理器复用连接,在频繁轮询场景下性能更佳:

# 同步
with QuoteService() as service:
    df = service.get_all_sync()

# 异步
async with QuoteService() as service:
    df = await service.get_all()

性能对比

与 easyquotation 对比(5500+ 只股票):

数据源 easyquotation qdata_quote sync qdata_quote async
新浪 ~710ms ~640ms ~640ms
腾讯 ~1830ms ~1720ms ~1680ms
  • 同步引擎:requests + ThreadPoolExecutor 并发请求
  • 异步引擎:aiohttp + asyncio.gather 并发请求
  • 解析优化:文本合并后一次性正则匹配,元组直接构建 DataFrame

运行基准测试

python -m qdata_quote.bench

依赖

  • Python >= 3.10
  • requests >= 2.28
  • aiohttp >= 3.9
  • pandas >= 2.0

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

qdata_quote-0.3.4.tar.gz (126.4 kB view details)

Uploaded Source

Built Distribution

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

qdata_quote-0.3.4-py3-none-any.whl (13.2 kB view details)

Uploaded Python 3

File details

Details for the file qdata_quote-0.3.4.tar.gz.

File metadata

  • Download URL: qdata_quote-0.3.4.tar.gz
  • Upload date:
  • Size: 126.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for qdata_quote-0.3.4.tar.gz
Algorithm Hash digest
SHA256 612ddd5b982232133f03639b62c4218a41b9792a2c87edda8b5450ab4d3857c9
MD5 785745fec77cc4c533bd8cff6752427b
BLAKE2b-256 07d9b993538ffd8786a69e72710836006a4881ee58a7ea06cdcecdbeb7cac33a

See more details on using hashes here.

File details

Details for the file qdata_quote-0.3.4-py3-none-any.whl.

File metadata

  • Download URL: qdata_quote-0.3.4-py3-none-any.whl
  • Upload date:
  • Size: 13.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for qdata_quote-0.3.4-py3-none-any.whl
Algorithm Hash digest
SHA256 04409b99c829a75bb8ba7ab3b52e1e3128d21068895079b0d26da1423fae85e8
MD5 e01c728ae9ac50b156344e21d40c9505
BLAKE2b-256 db57e95ea77659650198478c2fd1ef5e2d8fafade11542ab0c8b920d256e1fe7

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