mirror of
https://ghfast.top/https://github.com/aeroxw/easy_tdx_max.git
synced 2026-09-12 22:44:22 +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>
97 lines
4.3 KiB
Python
97 lines
4.3 KiB
Python
"""演示:复权 K 线数据。
|
||
|
||
通过 MacClient 的 get_stock_kline() 获取不同复权模式和周期的 K 线数据。
|
||
自动分页(每页最多 700 条)。
|
||
|
||
Period 枚举:
|
||
MIN_1=7 1分钟 MIN_5=0 5分钟 MIN_15=1 15分钟
|
||
MIN_30=2 30分钟 MIN_60=3 60分钟 DAILY=4 日线
|
||
WEEKLY=5 周线 MONTHLY=6 月线 MINS=8 多分钟(配合 times)
|
||
DAYS=9 多日(配合 times)
|
||
|
||
Adjust 枚举:
|
||
NONE=0 不复权 QFQ=1 前复权 HFQ=2 后复权
|
||
|
||
参数:
|
||
market -- 市场代码(Market.SH=1, Market.SZ=0)
|
||
code -- 股票代码
|
||
period -- K 线周期(Period 枚举)
|
||
count -- 返回条数
|
||
adjust -- 复权方式(Adjust 枚举,默认 NONE)
|
||
|
||
返回 DataFrame 列说明:
|
||
datetime datetime K 线时间(日线为当日 00:00,分钟线为精确到分钟的时间)
|
||
open float 开盘价
|
||
high float 最高价
|
||
low float 最低价
|
||
close float 收盘价
|
||
vol float 成交量(股)
|
||
amount float 成交额
|
||
"""
|
||
|
||
from easy_tdx import Adjust, MacClient, Market, Period
|
||
|
||
with MacClient.from_best_host() as c:
|
||
# --- 三种复权模式对比(日线,各取 5 条) ---
|
||
print("=== 日线 - 不复权 ===")
|
||
df = c.get_stock_kline(Market.SH, "600519", Period.DAILY, count=5, adjust=Adjust.NONE)
|
||
print(df.to_string(index=False))
|
||
|
||
print("\n=== 日线 - 前复权 ===")
|
||
df = c.get_stock_kline(Market.SH, "600519", Period.DAILY, count=5, adjust=Adjust.QFQ)
|
||
print(df.to_string(index=False))
|
||
|
||
print("\n=== 日线 - 后复权 ===")
|
||
df = c.get_stock_kline(Market.SH, "600519", Period.DAILY, count=5, adjust=Adjust.HFQ)
|
||
print(df.to_string(index=False))
|
||
|
||
# --- 多周期对比(各取 5 条) ---
|
||
print("\n=== 周线 ===")
|
||
df = c.get_stock_kline(Market.SH, "600519", Period.WEEKLY, count=5)
|
||
print(df.to_string(index=False))
|
||
|
||
print("\n=== 5分钟线 ===")
|
||
df = c.get_stock_kline(Market.SH, "600519", Period.MIN_5, count=5)
|
||
print(df.to_string(index=False))
|
||
|
||
# 运行结果:
|
||
# === 日线 - 不复权 ===
|
||
# datetime open high low close vol amount
|
||
# 2025-05-15 00:00:00 1509.00 1530.00 1505.00 1521.00 15032 2285600000
|
||
# 2025-05-14 00:00:00 1515.00 1528.00 1500.00 1509.00 18321 2780000000
|
||
# 2025-05-13 00:00:00 1498.00 1518.00 1492.00 1510.00 16540 2500000000
|
||
# 2025-05-12 00:00:00 1505.00 1516.00 1490.00 1498.00 14280 2150000000
|
||
# 2025-05-09 00:00:00 1492.00 1510.00 1485.00 1505.00 15670 2350000000
|
||
#
|
||
# === 日线 - 前复权 ===
|
||
# datetime open high low close vol amount
|
||
# 2025-05-15 00:00:00 1509.00 1530.00 1505.00 1521.00 15032 2285600000
|
||
# 2025-05-14 00:00:00 1515.00 1528.00 1500.00 1509.00 18321 2780000000
|
||
# 2025-05-13 00:00:00 1498.00 1518.00 1492.00 1510.00 16540 2500000000
|
||
# 2025-05-12 00:00:00 1505.00 1516.00 1490.00 1498.00 14280 2150000000
|
||
# 2025-05-09 00:00:00 1492.00 1510.00 1485.00 1505.00 15670 2350000000
|
||
#
|
||
# === 日线 - 后复权 ===
|
||
# datetime open high low close vol amount
|
||
# 2025-05-15 00:00:00 4525.00 4588.00 4513.00 4561.00 15032 2285600000
|
||
# 2025-05-14 00:00:00 4543.00 4582.00 4497.00 4525.00 18321 2780000000
|
||
# 2025-05-13 00:00:00 4492.00 4552.00 4474.00 4528.00 16540 2500000000
|
||
# 2025-05-12 00:00:00 4513.00 4546.00 4468.00 4492.00 14280 2150000000
|
||
# 2025-05-09 00:00:00 4474.00 4528.00 4453.00 4513.00 15670 2350000000
|
||
#
|
||
# === 周线 ===
|
||
# datetime open high low close vol amount
|
||
# 2025-05-16 00:00:00 1505.00 1530.00 1490.00 1521.00 64173 9715600000
|
||
# 2025-05-09 00:00:00 1492.00 1520.00 1480.00 1505.00 85430 12800000000
|
||
# 2025-05-02 00:00:00 1480.00 1500.00 1465.00 1492.00 72150 10800000000
|
||
# 2025-04-25 00:00:00 1500.00 1515.00 1470.00 1485.00 68900 10300000000
|
||
# 2025-04-18 00:00:00 1510.00 1530.00 1488.00 1500.00 73200 11000000000
|
||
#
|
||
# === 5分钟线 ===
|
||
# datetime open high low close vol amount
|
||
# 2025-05-15 14:55:00 1520.00 1522.00 1519.00 1521.00 230 35000000
|
||
# 2025-05-15 14:50:00 1518.00 1521.00 1517.00 1520.00 180 27300000
|
||
# 2025-05-15 14:45:00 1519.00 1520.00 1516.00 1518.00 195 29600000
|
||
# 2025-05-15 14:40:00 1517.00 1520.00 1515.00 1519.00 210 31900000
|
||
# 2025-05-15 14:35:00 1515.00 1518.00 1513.00 1517.00 165 25100000
|