【Python量化实战 #07】Python获取个股资金流向与公告数据:监控骨架
短线研究里,「涨跌」之外还要看「资金是否跟上」。本文是「Python量化实战」第 7 篇:用 stock_transaction 看资金流向,用 stock_announcement 拉取交易所公告,做基础监控骨架。
Playground 在线试调:https://www.mairuiapi.com/playground
文档:https://www.mairuiapi.com/hsdata · 分析数据
环境准备
pip install mairui pandas
接口细节:https://github.com/MaiRuiApi/mairui
个股资金流向
import os
import pandas as pd
from mairui import Client
licence = os.environ.get("MAIRUI_LICENCE", "your_licence")
code = "000001.SZ"
with Client(licence=licence) as api:
flow = api.stock_transaction(code, lt=30)
df = pd.DataFrame(flow or [])
print(df.columns.tolist())
print(df.tail())
lt=30 表示只要最近若干条;完整区间可用 st/et(以文档为准)。
交易所公告
with Client(licence=licence) as api:
anns = api.stock_announcement(code, lt=20)
ann_df = pd.DataFrame(anns or [])
print(ann_df.head())
# 可按标题关键词粗筛,例如含「业绩」「回购」等(字段名以返回为准)
组合:流向 + 公告日
# 思路:公告密集日,对照同期资金流向是否放大
# 具体日期字段对齐后,再用 merge / 分组统计
print("flow_rows", len(df), "ann_rows", len(ann_df))
避坑
- 代码格式(6 位 vs
000001.SZ)按接口要求选择。 - 公告文本编码与字段因接口而异,先打印样例。
- 本文数据示例结构供学习,不构成投资建议。
下一篇:分红与股息率筛选。继续体验 Playground。
麦蕊智数 · Python量化实战 #07



