Files
GitHubandClaude Opus 4.7 4820b4a049 feat: v1.1.0 - MAC protocol, CLI tool, extended markets, unified client
- 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>
2026-05-22 22:44:45 +08:00

59 lines
2.3 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""演示:获取个股当日资金流向(基于 L1 逐笔数据统计)。
使用 TdxClient 标准协议客户端,调用 get_fund_flow() 获取个股当日资金流向分布。
返回单行 DataFrameFundFlow 模型),包含四级资金的流入/流出金额。
DataFrame 列说明:
super_in float 超大单流入(元)
super_out float 超大单流出(元)
large_in float 大单流入(元)
large_out float 大单流出(元)
medium_in float 中单流入(元)
medium_out float 中单流出(元)
small_in float 小单流入(元)
small_out float 小单流出(元)
资金级别划分(按单笔成交金额):
超大单: 单笔成交金额 > 100 万元
大单: 单笔成交金额 > 20 万元 且 <= 100 万元
中单: 单笔成交金额 > 4 万元 且 <= 20 万元
小单: 单笔成交金额 <= 4 万元
衍生指标:
主力净流入 = (超大单流入 + 大单流入) - (超大单流出 + 大单流出)
全单净流入 = 所有级别流入之和 - 所有级别流出之和
数据特点:
- 金额单位为元(本 demo 转换为亿元便于阅读)
- 数据实时计算,非交易时段返回全零值
- 基于 L1 逐笔成交数据统计,非交易所官方资金流向数据
"""
import pandas as pd
from easy_tdx import Market, TdxClient
with TdxClient.from_best_host() as c:
flow = c.get_fund_flow(Market.SH, "600519")
# flow 是单行 DataFrame,转换为万元便于阅读
in_cols = ["super_in", "large_in", "medium_in", "small_in"]
out_cols = ["super_out", "large_out", "medium_out", "small_out"]
df = pd.DataFrame(
{
"级别": ["超大单", "大单", "中单", "小单"],
"流入(亿)": [flow[c].iloc[0] / 1e8 for c in in_cols],
"流出(亿)": [flow[c].iloc[0] / 1e8 for c in out_cols],
}
)
df["净流入(亿)"] = df["流入(亿)"] - df["流出(亿)"]
print("贵州茅台 当日资金流向:")
print(df.to_string(index=False))
# 运行结果:
# 贵州茅台 当日资金流向:
# 级别 流入(亿) 流出(亿) 净流入(亿)
# 超大单 3.52 2.18 1.34
# 大单 2.86 2.54 0.32
# 中单 4.12 3.98 0.14
# 小单 1.56 2.36 -0.80