mirror of
https://ghfast.top/https://github.com/aeroxw/easy_tdx_max.git
synced 2026-09-12 16:54:20 +08:00
feat: 增加全市场涨跌统计功能并更新特性文档
1. 核心模型:增加 MarketStat dataclass。 2. 客户端 API:TdxClient 和 AsyncTdxClient 增加 get_market_stat() 方法。 3. 实现细节:基于通达信统计指数 880005 解析上涨、下跌、平盘及成交额数据。 4. 文档更新:README.md 特性章节添加保活机制与全市场统计说明。
This commit is contained in:
@@ -12,6 +12,8 @@ pytdx 年久失修:多处已知解析 bug、Python 2 包袱、无类型注解
|
||||
- **高可用传输**:同步/异步均支持 `ping_all()`、`from_best_host()`、断线自动重连
|
||||
- **修复 pytdx 已知 bug**(见下文)
|
||||
- **保留原始字节**:每条数据记录含 `_raw: bytes`,未知字段以 `unknown_N` 命名而非丢弃
|
||||
- **保活心跳机制**:`AsyncTdxClient` 自动发送心跳包,确保长连接生产环境稳定性
|
||||
- **全市场涨跌统计**:一键获取全 A 股涨/跌/平家数及总成交额
|
||||
- **离线 + 本地传输回归测试**:覆盖解析、异步并发串行化、超时、自动重连与坏包处理
|
||||
|
||||
## 安装
|
||||
|
||||
@@ -23,6 +23,7 @@ from .models.enums import KlineCategory, Market
|
||||
from .models.finance import CompanyInfoCategory, FinanceInfo, TdxBlock, XdxrRecord
|
||||
from .models.quote import SecurityQuote
|
||||
from .models.security import SecurityInfo
|
||||
from .models.stats import MarketStat
|
||||
from .models.timeseries import MinuteBar, TransactionRecord
|
||||
from .transport.async_ import AsyncTdxConnection
|
||||
from .transport.sync import KNOWN_HOSTS, TdxConnection, ping_all
|
||||
@@ -269,6 +270,22 @@ class TdxClient:
|
||||
break
|
||||
return bytes(full_data)
|
||||
|
||||
def get_market_stat(self) -> MarketStat:
|
||||
"""获取 A 股全市场涨跌统计概况。"""
|
||||
# 通达信中 880005 是行情统计代码
|
||||
quotes = self.get_security_quotes([(Market.SH, "880005")])
|
||||
if not quotes:
|
||||
raise RuntimeError("无法获取市场统计数据")
|
||||
q = quotes[0]
|
||||
return MarketStat(
|
||||
up_count=int(q.price),
|
||||
down_count=int(q.pre_close),
|
||||
neutral_count=int(q.open),
|
||||
total_count=int(q.high),
|
||||
total_amount=q.amount,
|
||||
total_volume=q.vol,
|
||||
)
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 异步客户端
|
||||
@@ -493,3 +510,18 @@ class AsyncTdxClient:
|
||||
break
|
||||
return bytes(full_data)
|
||||
|
||||
async def get_market_stat(self) -> MarketStat:
|
||||
"""获取 A 股全市场涨跌统计概况。"""
|
||||
quotes = await self.get_security_quotes([(Market.SH, "880005")])
|
||||
if not quotes:
|
||||
raise RuntimeError("无法获取市场统计数据")
|
||||
q = quotes[0]
|
||||
return MarketStat(
|
||||
up_count=int(q.price),
|
||||
down_count=int(q.pre_close),
|
||||
neutral_count=int(q.open),
|
||||
total_count=int(q.high),
|
||||
total_amount=q.amount,
|
||||
total_volume=q.vol,
|
||||
)
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
"""验证市场概况模型。"""
|
||||
from dataclasses import dataclass
|
||||
|
||||
@dataclass
|
||||
class MarketStat:
|
||||
"""全市场涨跌统计概况。"""
|
||||
up_count: int # 上涨家数
|
||||
down_count: int # 下跌家数
|
||||
neutral_count: int # 平盘家数
|
||||
total_count: int # 总家数
|
||||
total_amount: float # 总成交额
|
||||
total_volume: float # 总成交量
|
||||
Reference in New Issue
Block a user