mirror of
https://ghfast.top/https://github.com/aeroxw/easy_tdx_max.git
synced 2026-09-12 21:34:21 +08:00
- Add MacClient/AsyncMacClient with full MAC protocol support (quotes, kline with adjustment, tick charts, transactions, boards, capital flow, auction, unusual, symbol info, server info) - Add MacExClient/AsyncMacExClient for extended markets (HK, US, futures) - Add UnifiedTdxClient auto-routing between A-share and extended markets - Add `easy-tdx` CLI tool with JSON default output, Agent-friendly - Add field bitmap protocol for custom quote field selection - Fix quote-list missing fields (default to BASIC+VOLUME preset) - Add config.py with centralized host management and auto-discovery - Add 50+ examples covering all APIs (01-20) - Rewrite README with CLI-first, Agent-friendly documentation - Bump version to 1.1.0 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
38 lines
922 B
Python
38 lines
922 B
Python
"""CLI 连接工厂:延迟创建 MAC 客户端。"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from collections.abc import Generator
|
|
from contextlib import contextmanager
|
|
|
|
from ..ex.mac_client import MacExClient
|
|
from ..mac.client import MacClient
|
|
|
|
|
|
@contextmanager
|
|
def get_mac_client() -> Generator[MacClient, None, None]:
|
|
"""创建 MAC 客户端上下文(自动选最快服务器)。
|
|
|
|
使用方式::
|
|
|
|
with get_mac_client() as client:
|
|
df = client.get_stock_kline(...)
|
|
"""
|
|
client = MacClient.from_best_host()
|
|
try:
|
|
client.connect()
|
|
yield client
|
|
finally:
|
|
client.close()
|
|
|
|
|
|
@contextmanager
|
|
def get_mac_ex_client() -> Generator[MacExClient, None, None]:
|
|
"""创建扩展市场 MAC 客户端上下文(端口 7727)。"""
|
|
client = MacExClient.from_best_host()
|
|
try:
|
|
client.connect()
|
|
yield client
|
|
finally:
|
|
client.close()
|