mirror of
https://ghfast.top/https://github.com/aeroxw/easy_tdx_max.git
synced 2026-09-12 20:24:19 +08:00
经三轮代码审计后的综合质量加固版本,覆盖协议核心层、数据正确性、 错误处理、测试真实度与可维护性。761 单测全绿(+58),ruff/mypy 全过。 主要修复: - 离线 .day 写入原子化(fsync + _repair_tail + 读取校验,CQS 守住) - 回测止损前视偏差(延迟下一根开盘 + 跳空保护) - VWAP 权重索引 / bar_time fail-fast / 绩效除零保护 - 闭包绑定 / 路径穿越 / naive datetime 跨时区 / ruff UP038 重构: - 抽 AsyncHeartbeatMixin 收敛 4 处心跳副本(12→1) - 统一 _RETRY_DELAYS 退避序列 / scanner 失败可观测性 新增 5 个测试文件 + 公共 API 类型契约,CI 加 Windows 矩阵 + trusted publishing 签名 + 锁文件。 详见 CHANGELOG.md
126 lines
2.8 KiB
Python
126 lines
2.8 KiB
Python
"""easy_tdx — 通达信 TCP 协议 A 股行情数据客户端。
|
|
|
|
快速开始::
|
|
|
|
from easy_tdx import TdxClient, Market, KlineCategory
|
|
|
|
with TdxClient("180.153.18.170") as c:
|
|
count = c.get_security_count(Market.SH)
|
|
bars = c.get_security_bars(Market.SH, "600000", KlineCategory.DAY, 0, 5)
|
|
|
|
asyncio 版本::
|
|
|
|
import asyncio
|
|
from easy_tdx import AsyncTdxClient, Market, KlineCategory
|
|
|
|
async def main():
|
|
async with AsyncTdxClient("180.153.18.170") as c:
|
|
bars = await c.get_security_bars(Market.SH, "600000", KlineCategory.DAY, 0, 5)
|
|
|
|
asyncio.run(main())
|
|
"""
|
|
|
|
from .client import AsyncTdxClient, TdxClient
|
|
from .config import save_best_ex_host, save_best_host
|
|
from .ex.client import AsyncExTdxClient, ExTdxClient
|
|
from .ex.mac_client import AsyncMacExClient, MacExClient
|
|
from .ex.models import KNOWN_EX_HOSTS
|
|
from .exceptions import TdxCommandError, TdxConnectionError, TdxDecodeError, TdxError
|
|
from .mac.client import AsyncMacClient, MacClient
|
|
from .mac.enums import (
|
|
Adjust,
|
|
BoardType,
|
|
Category,
|
|
ExMarket,
|
|
FilterType,
|
|
Period,
|
|
SortOrder,
|
|
SortType,
|
|
)
|
|
from .models import (
|
|
XDXR_CATEGORY_NAMES,
|
|
CompanyInfoCategory,
|
|
FinanceInfo,
|
|
FinancialFileInfo,
|
|
FinancialRecord,
|
|
FundFlow,
|
|
HistoricalFundFlow,
|
|
KlineCategory,
|
|
Market,
|
|
MarketStat,
|
|
MinuteBar,
|
|
SecurityBar,
|
|
SecurityInfo,
|
|
SecurityQuote,
|
|
TdxBlock,
|
|
TransactionRecord,
|
|
XdxrRecord,
|
|
)
|
|
from .transport.sync import CALC_HOSTS, KNOWN_HOSTS, MAC_HOSTS, ping_all, ping_mac_all
|
|
from .unified import AsyncUnifiedTdxClient, UnifiedTdxClient
|
|
|
|
__all__ = [
|
|
# 客户端
|
|
"TdxClient",
|
|
"AsyncTdxClient",
|
|
"MacClient",
|
|
"AsyncMacClient",
|
|
"MacExClient",
|
|
"AsyncMacExClient",
|
|
"UnifiedTdxClient",
|
|
"AsyncUnifiedTdxClient",
|
|
# 枚举
|
|
"Market",
|
|
"KlineCategory",
|
|
"Adjust",
|
|
"BoardType",
|
|
"Category",
|
|
"ExMarket",
|
|
"FilterType",
|
|
"Period",
|
|
"SortOrder",
|
|
"SortType",
|
|
# 数据模型
|
|
"SecurityBar",
|
|
"SecurityQuote",
|
|
"SecurityInfo",
|
|
"MinuteBar",
|
|
"TransactionRecord",
|
|
"XdxrRecord",
|
|
"XDXR_CATEGORY_NAMES",
|
|
"FinanceInfo",
|
|
"CompanyInfoCategory",
|
|
"FinancialFileInfo",
|
|
"FinancialRecord",
|
|
"TdxBlock",
|
|
"MarketStat",
|
|
"FundFlow",
|
|
"HistoricalFundFlow",
|
|
# 异常
|
|
"TdxError",
|
|
"TdxConnectionError",
|
|
"TdxDecodeError",
|
|
"TdxCommandError",
|
|
# 扩展行情
|
|
"ExTdxClient",
|
|
"AsyncExTdxClient",
|
|
"KNOWN_EX_HOSTS",
|
|
# 工具
|
|
"ping_all",
|
|
"ping_mac_all",
|
|
"KNOWN_HOSTS",
|
|
"CALC_HOSTS",
|
|
"MAC_HOSTS",
|
|
"save_best_host",
|
|
"save_best_ex_host",
|
|
]
|
|
|
|
|
|
def _get_version() -> str:
|
|
from importlib.metadata import version
|
|
|
|
return version("easy-tdx")
|
|
|
|
|
|
__version__ = _get_version()
|