mirror of
https://ghfast.top/https://github.com/aeroxw/easy-tdx.git
synced 2026-09-12 18:04:16 +08:00
- Add example scripts for all API categories (connection, market info, kline, minute, transaction, finance, block, fund flow) - Fix GetIndexBarsCmd: index bar records have 4 extra bytes (advance/ decline counts) that were not consumed, causing pos drift and corrupted dates/volumes for all records after the first - Fix price_limits.py example (SecurityQuote has no name attr) - Fix finance_info.py display (scientific notation -> formatted numbers) - Add PostToolUse ruff hook (scripts/ruff_hook.py) Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
25 lines
750 B
Python
25 lines
750 B
Python
"""演示:异步客户端连接与基本用法。"""
|
|
|
|
import asyncio
|
|
from xmtdx import AsyncTdxClient, Market, KlineCategory
|
|
|
|
|
|
async def main():
|
|
# 手动指定服务器
|
|
async with AsyncTdxClient("180.153.18.170") as c:
|
|
count = await c.get_security_count(Market.SH)
|
|
print(f"沪市证券总数: {count}")
|
|
|
|
# 自动优选服务器
|
|
async with AsyncTdxClient.from_best_host() as c:
|
|
bars = await c.get_security_bars(
|
|
Market.SH, "600000", KlineCategory.DAY, 0, 5
|
|
)
|
|
for bar in bars:
|
|
print(f"{bar.year}-{bar.month:02d}-{bar.day:02d} "
|
|
f"开:{bar.open:.2f} 高:{bar.high:.2f} "
|
|
f"低:{bar.low:.2f} 收:{bar.close:.2f}")
|
|
|
|
|
|
asyncio.run(main())
|