"""TDX 行情客户端 — 连接通达信行情服务器获取实时数据 小小莫: 1. pip install opentdx 2. 在 config.py 中填入招商证券行情主站IP 3. 实现下面的方法 4. 运行 test_tdx_connect.py 验证 """ # ═══════════════════════════════════════════ # 配置区 — 请替换为你的招商证券行情主站IP # ═══════════════════════════════════════════ from .config import MARKET_SERVERS, HK_STOCKS class TDXClient: """通达信行情客户端封装 用法: client = TDXClient() client.connect("113.105.73.88", 7709) data = client.get_hk_quotes() client.close() """ def __init__(self): self.client = None def connect(self, ip: str, port: int = 7709): """连接到通达信行情服务器""" # TODO: 小小莫实现 # from opentdx.client.macExtendedClient import MacExtendedClient # self.client = MacExtendedClient() # self.client.connect(ip, port) raise NotImplementedError("由小小莫实现") def get_hk_quote(self, market_code: int, code: str) -> dict: """获取单只港股实时报价 Args: market_code: 港股主板=31 code: 如 "00700" Returns: {"code": "00700", "name": "腾讯控股", "price": 463.6, "change_pct": 1.55, "high": 468.0, "low": 460.2, ...} """ raise NotImplementedError("由小小莫实现") def get_hk_quotes(self, codes: list = None) -> list: """批量获取港股实时报价""" if codes is None: codes = [(31, code) for _, code in HK_STOCKS] raise NotImplementedError("由小小莫实现") def close(self): if self.client: try: self.client.disconnect() except Exception: pass self.client = None