← 返回 Skills 市场
bjdenglun

financial-market-data

作者 BJ_denglun · GitHub ↗ · v1.0.2 · MIT-0
cross-platform ⚠ suspicious
100
总下载
1
收藏
0
当前安装
3
版本数
在 OpenClaw 中安装
/install financial-market-data
功能描述
Provides unified access to multi-source financial market data including stocks, futures, ETFs, realtime quotes, sectors, financials, and macroeconomic indica...
使用说明 (SKILL.md)

Financial Market Data Skill

统一金融行情数据接口 — 多源互补、自动降级、永不单点故障


安装指南(全新 OpenClaw 实例)

第一步:复制 Skill 目录

将整个 skills/financial-market-data/ 目录复制到目标机器的对应位置:

~/.openclaw/workspace/skills/financial-market-data/

目录结构:

financial-market-data/
├── SKILL.md              # 本文件
├── skill.yaml            # Skill 元数据
└── python/
    ├── pyproject.toml   # Python 依赖
    ├── template.py       # 基础接口(TickFlow/pytdx/baostock/akshare)
    └── ths.py             # 同花顺专用接口(新增)

第二步:安装 Python 依赖(推荐 uv)

cd ~/.openclaw/workspace
uv sync

或使用 pip:

pip install tickflow akshare baostock pytdx requests pandas

第三步:使用说明

在任意 Python 脚本中引用:

import sys
sys.path.insert(0, 'skills/financial-market-data/python')
from ths import get_daily_k, get_1min_k, get_intraday, get_realtime
from template import get_daily_k as tk_daily, get_realtime_eastmoney

一、同花顺数据接口 ✅ 推荐(无需注册,完全免费)

同花顺官方免费接口,1分钟K线最强(约821条历史,覆盖2009年至今)。

1.1 同花顺 日K线

import sys
sys.path.insert(0, 'skills/financial-market-data/python')
from ths import get_daily_k, get_daily_k_page

# 获取日K(每次最多140条,总量约3856条)
records = get_daily_k("300006")  # 莱美药业
for r in records[-5:]:
    print(r['date'], r['close'], r['volume'])

# 翻页获取更早数据(以第一条记录日期为end参数)
older = get_daily_k_page("300006", end_date="20250902")

1.2 同花顺 1分钟K线(最强免费源)

from ths import get_1min_k

# 获取1分钟K(全部历史,约821条)
records = get_1min_k("300006")
print(f"共 {len(records)} 条, {records[0]['date']} ~ {records[-1]['date']}")

优势对比:

数据源 1分钟K条数 免费 注册
同花顺 约821条 不需要
pytdx 有限制 不需要
BaoStock 有限制 不需要
东方财富Level2 完整 需要付费

1.3 同花顺 分时数据

from ths import get_intraday

# 获取分时(每分钟汇总,需差分计算增量)
result = get_intraday("300006")
for r in result['records'][-10:]:
    print(r['time'], r['price'], r['volume'], '手/分钟')

1.4 同花顺 实时行情

from ths import get_realtime, get_multi_realtime

# 单只
rt = get_realtime("300006")
print(rt['price'])

# 批量
data = get_multi_realtime(["300006", "002560", "601975"])
for d in data:
    print(d.get('code'), d.get('price'))

1.5 同花顺接口字段说明

周期 URL路径 返回条数 数据格式
日K /v6/line/hs_{code}/01/his.js 140条/次,总3856条 日期,开,高,低,收,量,额,换手
1分钟K /v6/line/hs_{code}/11/last.js 全部约821条 同上
60分钟K /v6/line/hs_{code}/60/last.js 140条/次 日期时间(YYYYMMDDHHMM),开,高,低,收,量,额,换手
分时 /v6/line/hs_{code}/01/last.js 约140条/日 累计量,需差分算增量
实时 /v6/realtime/hs_{code}.js 1条即时 价格/高/低/量/额/五档

注意: 同花顺接口返回JSONP格式(quotebridge_v6_line_hs_xxx({"num":...})),需解析JSONP并用分号分割数据字段。


二、A股日K线

2.1 TickFlow(推荐,接口简洁)

from tickflow import TickFlow
tf = TickFlow.free()
df = tf.klines.get("600519.SH", period="1d", count=100, as_dataframe=True)
# 返回字段:trade_date, open, high, low, close, volume

2.2 BaoStock(全量历史,支持复权)

import baostock as bs
bs.login()
rs = bs.query_history_k_data_plus(
    "sz.000001",
    "date,code,open,high,low,close,volume,pctChg",
    start_date="20200101",
    end_date="20260404",
    frequency="d",
    adjustflag="3"
)
data_list = []
while rs.next:
    data_list.append(rs.get_row_data())
bs.logout()

三、A股分钟K线

3.1 pytdx 通达信接口(1分钟K)

from pytdx.hq import TdxHq_API
api = TdxHq_API()
if api.connect('218.75.126.9', 7709):
    data = api.get_security_bars(9, 0, "000001", 0, 100)  # category=9=1分钟K
    api.disconnect()

3.2 BaoStock(5/15/30/60分钟)

rs = bs.query_history_k_data_plus(
    "sz.000001",
    "date,time,code,open,high,low,close,volume",
    start_date="20260401",
    end_date="20260404",
    frequency="5",  # 5=5分钟
    adjustflag="3"
)

四、港股/美股

4.1 港股日K

# TickFlow(推荐)
df = tf.klines.get("00700.HK", period="1d", count=100)

# AkShare(备选)
import akshare as ak
df = ak.stock_hk_daily(symbol="00700", start_date="20240101", end_date="20260404", adjust="qfq")

4.2 美股日K

# TickFlow(推荐)
df = tf.klines.get("AAPL.US", period="1d", count=100)

# AkShare(备选)
df = ak.stock_us_daily(symbol="AAPL", start_date="20240101", end_date="20260404", adjust="qfq")

4.3 港股/美股实时

# 港股实时
df = ak.stock_hk_spot_em()
# 美股实时
df = ak.stock_us_spot_em()

五、期货/期权

5.1 期货日K(AkShare)

import akshare as ak
df = ak.futures_zh_daily(symbol="au2504", start_date="20240101", end_date="20260404")

5.2 期货分钟K(pytdx)

# 上海期货(market=47)
data = api.get_security_bars(9, 47, "au2504", 0, 100)
# 大连/郑州(market=1)
data = api.get_security_bars(9, 1, "i2505", 0, 100)

六、ETF/基金

import akshare as ak

# 沪深300ETF日K
df = ak.fund_etf_hist_sina(symbol="sh510300")

# ETF实时行情
df = ak.fund_etf_spot_em()

# 场外基金净值
df = ak.fund_open_fund_info_em(symbol="000001", indicator="累计净值走势")

七、实时行情

7.1 东方财富MX API(需要Token)

import requests, json

api_key = "替换为你自己的MX API Key,申请地址:https://openapi.eastmoney.com/mx/v1/api-docs"
url = "https://mkapi2.dfcfs.com/finskillshub/api/claw/query"

payload = {
    "toolQuery": json.dumps({
        "func": "get_quote_list_ts",
        "params": ["600519.SH,000001.SZ", 1]
    })
}
headers = {"Content-Type": "application/json", "apiKey": api_key}
resp = requests.post(url, json=payload, headers=headers, timeout=15)
data = resp.json()

7.2 东方财富 Direct(无需Token,部分接口)

import requests
url = "https://push2.eastmoney.com/api/qt/stock/get"
params = {
    "secid": "1.600519",
    "fields": "f43,f44,f45,f46,f47,f48,f50,f57,f58,f107,f169,f170",
}
r = requests.get(url, params=params, timeout=10)
# f43=最新价 f170=涨跌幅 f57=代码 f58=名称

八、板块/行业

import akshare as ak

# 行业板块列表
df = ak.stock_board_industry_name_em()

# 概念板块列表
df = ak.stock_board_concept_name_em()

# 板块内个股
df = ak.stock_board_industry_cons_em(symbol="半导体")

# 行业涨幅榜
df = ak.stock_board_industry_rank_em()

九、财务数据

import baostock as bs
bs.login()

# 盈利能力
rs = bs.query_profit_data(code="sz.000001", year=2024, quarter=4)
df = rs.get_data()

# 成长能力
rs = bs.query_growth_data(code="sz.000001", year=2024, quarter=4)

# 杜邦分析
rs = bs.query_dupont_data(code="sz.000001", year=2024, quarter=4)

bs.logout()

十、资金流向

import akshare as ak

# 个股资金流向
df = ak.stock_individual_fund_flow(stock="000001", market="sh")

# 大单净流入
df = ak.stock_individual_fund_flow(stock="000001", market="sh", symbol="大单净流入")

十一、宏观数据

import akshare as ak
df = ak.macro_china_gdp()           # GDP
df = ak.macro_china_cpi()            # CPI
df = ak.macro_china_money_supply()  # 货币供应量

十二、推荐组合方案

方案 适用场景 日K 1分钟K 实时行情 板块/财务
A 纯免费无需注册 TickFlow 同花顺821条 AkShare Direct AkShare
B 最佳体验(需Key) TickFlow 同花顺 东方财富MX API AkShare + BaoStock
C A股专注 BaoStock BaoStock AkShare Direct BaoStock + AkShare

十三、已知问题 & 解决方案

问题 解决方案
同花顺1分钟K最强 ✅ 约821条,2009年至今,完全免费
TickFlow免费版无分钟K → 改用同花顺1分钟K 或 pytdx
BaoStock分钟K日期格式报错 → 用 frequency="5" 而非 "1min"
AkShare网络不稳定 → 添加重试机制,或切换到同花顺
东方财富MX API中文乱码 → 数值正常,字段名用正则匹配数字ID绕过
pytdx连接失败(防火墙/封禁) → 换用 同花顺1分钟K
东财push2his(K线)被拒 → 换用 同花顺日K
英为财情(Cloudflare) → 完全无法突破,需付费API

十四、Token 速查表

接口 Key 状态
东方财富 MX API 替换为你自己的MX API Key,申请地址:https://openapi.eastmoney.com/mx/v1/api-docs ✅ 已配置

注意: 同花顺、TickFlow、BaoStock、AkShare、pytdx 均为免费无需注册接口,同花顺1分钟K是免费接口中最强的

安全使用建议
This skill appears to implement market-data fetchers for many public sources, which matches its description, but it embeds a concrete EastMoney MX API key/token in skill.yaml and in python/template.py while declaring no required credentials. Before installing: (1) Treat the embedded API key as suspicious — decide whether you want to use it or replace it with your own key; hard-coded keys can be revoked, rate-limited, or violate a provider's terms. (2) Review and, if needed, remove the hard-coded key from template.py and skill.yaml, and update the code to read credentials from environment variables or a user-provided config. (3) Install and run in an isolated environment (virtualenv/container) because the skill will perform outbound network calls to several third-party hosts (10jqka/dfcfs/push2/eastmoney and a pytdx host IP). (4) Verify the third-party Python packages (tickflow/akshare/baostock/pytdx) are from trusted sources and pin versions if you plan to deploy. (5) If you require stronger assurance, request the upstream/source author or a signed release and clarify why a provider token is embedded in distributed metadata. These inconsistencies make the package suspicious but not demonstrably malicious.
功能分析
Type: OpenClaw Skill Name: financial-market-data Version: 1.0.2 The skill bundle provides a comprehensive set of interfaces for fetching financial market data from various sources including Tonghuashun, EastMoney, and AkShare. The Python implementation in `ths.py` and `template.py` is well-structured and strictly aligned with the stated purpose of market data retrieval. While the bundle includes a hardcoded EastMoney API key (`mkt_HFeitkf4UQNDF8rpr6wZMVfweIxmPegsR1jJK0kF0_I`), it is explicitly documented in `skill.yaml` as a provided token for immediate use. No indicators of data exfiltration, malicious execution, or prompt injection were found, and network calls are directed to legitimate financial data domains (e.g., `d.10jqka.com.cn`, `mkapi2.dfcfs.com`).
能力评估
Purpose & Capability
The skill's stated purpose is unified market-data access and the code implements multiple data-source fetchers (ths/akshare/pytdx/baostock/tickflow). However skill.yaml contains a 'token_required' entry including a concrete EastMoney MX API key and the Python template hard-codes the same key — while the registry metadata and SKILL.md declare no required env vars/credentials. Embedding a service token in metadata/code is inconsistent with the declared requirements and is not necessary for most of the documented functionality (many sources are public/free).
Instruction Scope
SKILL.md stays within the expected scope (copy folder, install Python deps, import functions). The runtime instructions encourage adding the skill directory to sys.path and calling provided functions. The only scope concern is that examples refer to an MX API key the user should supply, but the shipped template includes a baked-in key; otherwise the instructions do not ask the agent to read unrelated local files or secrets.
Install Mechanism
There is no automated install that downloads arbitrary archives. SKILL.md recommends pip-installing public Python packages (tickflow, akshare, baostock, pytdx, requests, pandas) or using a tool 'uv sync'. Using pip is typical for Python skills; this is moderate-risk but proportionate to the purpose. No obscure download URLs or extract actions are used.
Credentials
The package declares no required environment variables, yet the code and skill.yaml include a concrete EastMoney MX API key. Requiring or bundling a third-party API key in the package is disproportionate: it exposes/redistributes a credential the user may not expect, and it contradicts the manifest that lists no external credentials. There's also network access to several external endpoints (d.10jqka.com.cn, mkapi2.dfcfs.com, push2.eastmoney.com, and a pytdx host IP), which is expected for a market-data skill but worth noting.
Persistence & Privilege
The skill does not request always:true, does not modify other skills or system configs, and has no required config paths. It will run as a normal, user-invoked/autonomous skill with network access — standard for this type of skill.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install financial-market-data
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /financial-market-data 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.0.2
- 移除了默认配置的东方财富 MX API Key,需用户自行申请填写。 - SKILL.md 相关 API Key 说明已更新,提供了申请地址。 - 其余接口使用说明与内容未变。
v1.0.1
- Added new Python module `ths.py` providing free, registration-free access to official Tonghuashun (同花顺) data, including 1-minute K-line, daily K-line, intraday, and real-time quotes. - Updated documentation to highlight Tonghuashun as the strongest free source for 1-minute K-line (about 821 records covering 2009–now). - Detailed new API usage, endpoints, data fields, and integration examples in SKILL.md. - Included sample import instructions and interface field explanation. - Compared data sources for minute-level data, emphasizing Tonghuashun's advantages. - No breaking changes to existing APIs; existing integrations remain compatible.
v1.0.0
- Initial release of the Financial Market Data Skill. - Unified multi-source financial market data interface with automatic fallback and no single point of failure. - Detailed installation and Python dependency instructions provided. - Supports A-shares, Hong Kong stocks, US stocks, futures, ETFs, funds, sectors, financial, capital flow, and macroeconomic data. - Code examples and quick-start guides included for all major data types and sources. - Ready-to-use API key pre-configured for EastMoney MX API where required.
元数据
Slug financial-market-data
版本 1.0.2
许可证 MIT-0
累计安装 0
当前安装数 0
历史版本数 3
常见问题

financial-market-data 是什么?

Provides unified access to multi-source financial market data including stocks, futures, ETFs, realtime quotes, sectors, financials, and macroeconomic indica... 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 100 次。

如何安装 financial-market-data?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install financial-market-data」即可一键安装,无需额外配置。

financial-market-data 是免费的吗?

是的,financial-market-data 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。

financial-market-data 支持哪些平台?

financial-market-data 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 financial-market-data?

由 BJ_denglun(@bjdenglun)开发并维护,当前版本 v1.0.2。

💬 留言讨论