Skip to main content

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

Project description

qdata-quote

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

安装

pip install qdata-quote

快速开始

from qdata_quote import QuoteService, get_stock_codes

# 获取全市场股票代码(首次从网络获取约 4 秒,后续读缓存 <1ms)
codes = get_stock_codes()

service = QuoteService()
service.set_stock_codes(codes)

# 同步获取指定股票行情
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 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:
    service.set_stock_codes(get_stock_codes())
    df = service.get_all_sync()

# 异步
async with QuoteService() as service:
    service.set_stock_codes(get_stock_codes())
    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.1.tar.gz (125.8 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.1-py3-none-any.whl (13.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: qdata_quote-0.3.1.tar.gz
  • Upload date:
  • Size: 125.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for qdata_quote-0.3.1.tar.gz
Algorithm Hash digest
SHA256 3eba341451b6a876317bbc1a293666d9a44f9347af0f28d338322c4fa7e36cf5
MD5 cb106b139184d0e9426d52f249f4b777
BLAKE2b-256 055f8ed31355b40d55f3b106155b20eb92109c65e4136505a029c4b638c5c104

See more details on using hashes here.

File details

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

File metadata

  • Download URL: qdata_quote-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 13.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for qdata_quote-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 87f553901fabcfa9db0d79c88a99f1c99d92917734b95eba61cc0c983690bfef
MD5 8b10ff2ccf31355d49d7bde740c256e9
BLAKE2b-256 add7a281b1519208b4790940db32af01d98d51549d0e95616422996da740c2bb

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