@openfinclaw/findoo-datahub-plugin 2026.3.2 → 2026.3.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/DESIGN.md +492 -151
  2. package/_vendor/claude-skills-finance/SKILL.md +192 -0
  3. package/_vendor/claude-skills-finance/assets/dcf_analysis_template.md +184 -0
  4. package/_vendor/claude-skills-finance/assets/expected_output.json +161 -0
  5. package/_vendor/claude-skills-finance/assets/forecast_report_template.md +177 -0
  6. package/_vendor/claude-skills-finance/assets/sample_financial_data.json +219 -0
  7. package/_vendor/claude-skills-finance/assets/variance_report_template.md +122 -0
  8. package/_vendor/claude-skills-finance/references/financial-ratios-guide.md +396 -0
  9. package/_vendor/claude-skills-finance/references/forecasting-best-practices.md +294 -0
  10. package/_vendor/claude-skills-finance/references/valuation-methodology.md +255 -0
  11. package/_vendor/claude-skills-finance/scripts/budget_variance_analyzer.py +406 -0
  12. package/_vendor/claude-skills-finance/scripts/dcf_valuation.py +449 -0
  13. package/_vendor/claude-skills-finance/scripts/forecast_builder.py +494 -0
  14. package/_vendor/claude-skills-finance/scripts/ratio_calculator.py +432 -0
  15. package/index.ts +332 -14
  16. package/openclaw.plugin.json +2 -2
  17. package/package.json +1 -1
  18. package/references/cn-market-specifics.md +165 -0
  19. package/references/crypto-analysis.md +635 -0
  20. package/references/financial-ratios-cn.md +452 -0
  21. package/references/hk-market-specifics.md +166 -0
  22. package/references/macro-cycle-cn.md +409 -0
  23. package/references/valuation-cn.md +427 -0
  24. package/skills/README.md +294 -0
  25. package/skills/a-concept-cycle/skill.md +200 -0
  26. package/skills/a-convertible-arb/skill.md +294 -0
  27. package/skills/a-dividend-king/skill.md +187 -0
  28. package/skills/a-earnings-season/skill.md +221 -0
  29. package/skills/a-index-timer/skill.md +192 -0
  30. package/skills/a-ipo-new/skill.md +297 -0
  31. package/skills/a-northbound-decoder/skill.md +185 -0
  32. package/skills/a-quant-board/skill.md +286 -0
  33. package/skills/a-share/skill.md +347 -0
  34. package/skills/a-share-radar/skill.md +185 -0
  35. package/skills/cross-asset/skill.md +202 -0
  36. package/skills/crypto/skill.md +269 -0
  37. package/skills/crypto-altseason/skill.md +208 -0
  38. package/skills/crypto-btc-cycle/skill.md +231 -0
  39. package/skills/crypto-defi-yield/skill.md +181 -0
  40. package/skills/crypto-funding-arb/skill.md +158 -0
  41. package/skills/crypto-stablecoin-flow/skill.md +149 -0
  42. package/skills/data-query/skill.md +124 -30
  43. package/skills/derivatives/skill.md +188 -35
  44. package/skills/etf-fund/skill.md +216 -0
  45. package/skills/factor-screen/skill.md +186 -0
  46. package/skills/hk-china-internet/skill.md +190 -0
  47. package/skills/hk-dividend-harvest/skill.md +192 -0
  48. package/skills/hk-hsi-pulse/skill.md +154 -0
  49. package/skills/hk-southbound-alpha/skill.md +163 -0
  50. package/skills/hk-stock/skill.md +295 -0
  51. package/skills/macro/skill.md +244 -53
  52. package/skills/risk-monitor/skill.md +171 -0
  53. package/skills/us-dividend/skill.md +162 -0
  54. package/skills/us-earnings/skill.md +149 -0
  55. package/skills/us-equity/skill.md +235 -0
  56. package/skills/us-etf/skill.md +261 -0
  57. package/skills/us-sector-rotation/skill.md +223 -0
  58. package/src/config.ts +4 -5
  59. package/src/datahub-client.test.ts +4 -7
  60. package/src/datahub-client.ts +6 -1
  61. package/src/register-tools.ts +720 -0
  62. package/src/tool-helpers.ts +89 -0
  63. package/test/e2e/l3-gateway-bootstrap.live.test.ts +339 -0
  64. package/test/e2e/l4-skill-tool-chain.live.test.ts +465 -0
  65. package/skills/crypto-defi/skill.md +0 -69
  66. package/skills/equity/skill.md +0 -64
  67. package/skills/market-radar/skill.md +0 -47
package/DESIGN.md CHANGED
@@ -1,157 +1,532 @@
1
- # Findoo DataHub Plugin — 设计哲学与使用指南
1
+ # Findoo DataHub Plugin — 完整设计方案
2
2
 
3
- ## 一句话定位
3
+ ## 一、定位
4
4
 
5
- **一个 DataHub 端点,覆盖全部金融市场** 插件不生产数据,只做 DataHub 的智能前端。
5
+ **OpenFinClaw 的统一金融数据层** — 一个薄客户端对接自建 OpenBB DataHub 服务,一组凭据覆盖 **171 个唯一端点**、**7 个上游 Provider**、**9 大资产类别**。插件不生产数据,只做 DataHub 的智能前端 + 本地缓存 + AI 工具注册。
6
+
7
+ ```
8
+ 用户对话 / fin-* 扩展
9
+ |
10
+ v
11
+ findoo-datahub-plugin (薄客户端 ~700 LOC)
12
+ |-- 11 AI Tools (LLM 直接调用)
13
+ |-- 2 Services (供 trader-plugin 等消费)
14
+ |-- SQLite OHLCV 缓存 (增量更新)
15
+ +-- RegimeDetector (SMA/ATR 趋势判定)
16
+ |
17
+ v
18
+ DataHub REST API (http://43.134.61.136:8088)
19
+ |-- Swagger UI: /docs
20
+ |-- Basic Auth: admin:<key>
21
+ +-- 171 endpoints -> 7 providers
22
+ |-- tushare (119 eps) -- A股/港股/期货/宏观/指数
23
+ |-- massive (33 eps) -- 美股/加密/FX/期权
24
+ |-- yfinance (29 eps) -- 美股/ETF/加密
25
+ |-- defillama(10 eps) -- DeFi TVL/Yields/Stablecoins
26
+ |-- ccxt (7 eps) -- CEX 实时行情/深度/Funding
27
+ |-- coingecko(6 eps) -- 市值/热搜/全球统计
28
+ +-- worldbank(5 eps) -- GDP/人口/通胀/自定义指标
29
+ ```
6
30
 
7
31
  ---
8
32
 
9
- ## 设计哲学
33
+ ## 二、DataHub 后端端点全景 (171 唯一端点)
34
+
35
+ | 类别 | 端点数 | 主要 Provider | 代表性 API |
36
+ | --------------- | ------ | -------------------------------------- | ------------------------------------------------------------------------ |
37
+ | **equity** | **86** | tushare(56), massive(17), yfinance(18) | price/historical, fundamental/income, moneyflow, flow/hsgt, hk/\*, us/\* |
38
+ | **crypto** | **23** | ccxt(7), coingecko(6), defillama(10) | market/ticker, defi/protocols, coin/market |
39
+ | **economy** | **21** | tushare(16), worldbank(5), massive(2) | gdp/real, cpi, shibor, treasury_cn/us |
40
+ | **derivatives** | **12** | tushare(10), massive(1), yfinance(2) | futures/holding, options/chains, convertible |
41
+ | **index** | **12** | tushare(8), massive(3), yfinance(2) | constituents, thematic/ths\_\*, daily_basic |
42
+ | **etf** | **9** | tushare(8), yfinance(2) | fund/portfolio, fund/manager, nav |
43
+ | **fixedincome** | **4** | tushare(4) | rate/shibor, rate/libor, rate/hibor |
44
+ | **currency** | **3** | massive(2), yfinance(1), tushare(1) | price/historical, snapshots |
45
+ | **news** | **1** | massive + yfinance + tushare | company news |
46
+
47
+ Tushare 贡献 119/209 (57%) 的 provider-endpoint 映射,是中国市场数据的绝对主力。
48
+
49
+ ### 完整端点清单 (按类别)
50
+
51
+ <details>
52
+ <summary>equity (86 endpoints)</summary>
53
+
54
+ | Endpoint | Provider(s) |
55
+ | ---------------------------------------- | -------------------------- |
56
+ | /equity/calendar/earnings | massive |
57
+ | /equity/calendar/ipo | massive |
58
+ | /equity/compare/peers | massive |
59
+ | /equity/concept/concept_detail | tushare |
60
+ | /equity/concept/concept_list | tushare |
61
+ | /equity/discovery/active | massive, yfinance |
62
+ | /equity/discovery/aggressive_small_caps | yfinance |
63
+ | /equity/discovery/gainers | massive, yfinance |
64
+ | /equity/discovery/growth_tech | yfinance |
65
+ | /equity/discovery/losers | massive, yfinance |
66
+ | /equity/discovery/name_change | tushare |
67
+ | /equity/discovery/new_share | tushare |
68
+ | /equity/discovery/undervalued_growth | yfinance |
69
+ | /equity/discovery/undervalued_large_caps | yfinance |
70
+ | /equity/estimates/consensus | yfinance |
71
+ | /equity/flow/ggt_daily | tushare |
72
+ | /equity/flow/ggt_monthly | tushare |
73
+ | /equity/flow/ggt_top10 | tushare |
74
+ | /equity/flow/hs_const | tushare |
75
+ | /equity/flow/hsgt_flow | tushare |
76
+ | /equity/flow/hsgt_top10 | tushare |
77
+ | /equity/fundamental/adj_factor | tushare |
78
+ | /equity/fundamental/backup_daily | tushare |
79
+ | /equity/fundamental/balance | massive, yfinance, tushare |
80
+ | /equity/fundamental/balance_vip | tushare |
81
+ | /equity/fundamental/cash | massive, yfinance, tushare |
82
+ | /equity/fundamental/cashflow_vip | tushare |
83
+ | /equity/fundamental/dividend_detail | tushare |
84
+ | /equity/fundamental/dividends | massive, yfinance, tushare |
85
+ | /equity/fundamental/earnings_forecast | tushare |
86
+ | /equity/fundamental/financial_audit | tushare |
87
+ | /equity/fundamental/financial_express | tushare |
88
+ | /equity/fundamental/forecast_vip | tushare |
89
+ | /equity/fundamental/historical_splits | massive |
90
+ | /equity/fundamental/income | massive, yfinance, tushare |
91
+ | /equity/fundamental/income_vip | tushare |
92
+ | /equity/fundamental/management | yfinance |
93
+ | /equity/fundamental/metrics | massive, yfinance |
94
+ | /equity/fundamental/ratios | tushare |
95
+ | /equity/fundamental/revenue_per_segment | tushare |
96
+ | /equity/fundamental/revenue_segment_vip | tushare |
97
+ | /equity/fundamental/stock_factor | tushare |
98
+ | /equity/hk/adj_factor | tushare |
99
+ | /equity/hk/balancesheet | tushare |
100
+ | /equity/hk/basic | tushare |
101
+ | /equity/hk/cashflow | tushare |
102
+ | /equity/hk/fina_indicator | tushare |
103
+ | /equity/hk/hold | tushare |
104
+ | /equity/hk/income | tushare |
105
+ | /equity/hk/trade_cal | tushare |
106
+ | /equity/margin/detail | tushare |
107
+ | /equity/margin/summary | tushare |
108
+ | /equity/margin/trading | tushare |
109
+ | /equity/market/limit_list | tushare |
110
+ | /equity/market/stock_limit | tushare |
111
+ | /equity/market/suspend | tushare |
112
+ | /equity/market/top_inst | tushare |
113
+ | /equity/market/top_list | tushare |
114
+ | /equity/market/trade_calendar | massive, tushare |
115
+ | /equity/market_snapshots | massive |
116
+ | /equity/moneyflow/block_trade | tushare |
117
+ | /equity/moneyflow/individual | tushare |
118
+ | /equity/moneyflow/industry | tushare |
119
+ | /equity/ownership/holder_number | tushare |
120
+ | /equity/ownership/major_holders | tushare |
121
+ | /equity/ownership/repurchase | tushare |
122
+ | /equity/ownership/share_float | tushare |
123
+ | /equity/ownership/share_statistics | massive, yfinance |
124
+ | /equity/ownership/shareholder_trade | tushare |
125
+ | /equity/ownership/top10_float_holders | tushare |
126
+ | /equity/ownership/top10_holders | tushare |
127
+ | /equity/pledge/detail | tushare |
128
+ | /equity/pledge/stat | tushare |
129
+ | /equity/price/historical | massive, yfinance, tushare |
130
+ | /equity/price/quote | massive, yfinance, tushare |
131
+ | /equity/profile | massive, yfinance, tushare |
132
+ | /equity/screener | yfinance |
133
+ | /equity/search | massive, tushare |
134
+ | /equity/shorts/short_volume | massive |
135
+ | /equity/us/adj_factor | tushare |
136
+ | /equity/us/balancesheet | tushare |
137
+ | /equity/us/basic | tushare |
138
+ | /equity/us/cashflow | tushare |
139
+ | /equity/us/fina_indicator | tushare |
140
+ | /equity/us/income | tushare |
141
+ | /equity/us/trade_cal | tushare |
142
+
143
+ </details>
144
+
145
+ <details>
146
+ <summary>crypto (23 endpoints)</summary>
147
+
148
+ | Endpoint | Provider(s) |
149
+ | --------------------------- | ----------------------- |
150
+ | /crypto/coin/categories | coingecko |
151
+ | /crypto/coin/global_stats | coingecko |
152
+ | /crypto/coin/historical | coingecko |
153
+ | /crypto/coin/info | coingecko |
154
+ | /crypto/coin/market | coingecko |
155
+ | /crypto/coin/trending | coingecko |
156
+ | /crypto/defi/bridges | defillama |
157
+ | /crypto/defi/chains | defillama |
158
+ | /crypto/defi/coin_prices | defillama |
159
+ | /crypto/defi/dex_volumes | defillama |
160
+ | /crypto/defi/fees | defillama |
161
+ | /crypto/defi/protocol_tvl | defillama |
162
+ | /crypto/defi/protocols | defillama |
163
+ | /crypto/defi/stablecoins | defillama |
164
+ | /crypto/defi/tvl_historical | defillama |
165
+ | /crypto/defi/yields | defillama |
166
+ | /crypto/market/funding_rate | ccxt |
167
+ | /crypto/market/orderbook | ccxt |
168
+ | /crypto/market/ticker | ccxt |
169
+ | /crypto/market/tickers | ccxt |
170
+ | /crypto/market/trades | ccxt |
171
+ | /crypto/price/historical | ccxt, massive, yfinance |
172
+ | /crypto/search | ccxt, massive |
173
+
174
+ </details>
175
+
176
+ <details>
177
+ <summary>economy (21 endpoints)</summary>
178
+
179
+ | Endpoint | Provider(s) |
180
+ | ----------------------------- | ---------------- |
181
+ | /economy/calendar | tushare |
182
+ | /economy/cpi | massive, tushare |
183
+ | /economy/gdp/real | tushare |
184
+ | /economy/hibor | tushare |
185
+ | /economy/index_global | tushare |
186
+ | /economy/libor | tushare |
187
+ | /economy/money_supply | tushare |
188
+ | /economy/pmi | tushare |
189
+ | /economy/ppi | tushare |
190
+ | /economy/shibor | tushare |
191
+ | /economy/shibor_lpr | tushare |
192
+ | /economy/shibor_quote | tushare |
193
+ | /economy/social_financing | tushare |
194
+ | /economy/treasury_cn | tushare |
195
+ | /economy/treasury_us | massive, tushare |
196
+ | /economy/worldbank/country | worldbank |
197
+ | /economy/worldbank/gdp | worldbank |
198
+ | /economy/worldbank/indicator | worldbank |
199
+ | /economy/worldbank/inflation | worldbank |
200
+ | /economy/worldbank/population | worldbank |
201
+ | /economy/wz_index | tushare |
202
+
203
+ </details>
204
+
205
+ <details>
206
+ <summary>derivatives (12), index (12), etf (9), fixedincome (4), currency (3), news (1)</summary>
207
+
208
+ **derivatives (12)**
209
+
210
+ | Endpoint | Provider(s) |
211
+ | ------------------------------- | ----------------- |
212
+ | /derivatives/convertible/basic | tushare |
213
+ | /derivatives/convertible/daily | tushare |
214
+ | /derivatives/futures/curve | massive, yfinance |
215
+ | /derivatives/futures/historical | yfinance, tushare |
216
+ | /derivatives/futures/holding | tushare |
217
+ | /derivatives/futures/info | tushare |
218
+ | /derivatives/futures/mapping | tushare |
219
+ | /derivatives/futures/settle | tushare |
220
+ | /derivatives/futures/warehouse | tushare |
221
+ | /derivatives/options/basic | tushare |
222
+ | /derivatives/options/chains | massive, yfinance |
223
+ | /derivatives/options/daily | tushare |
224
+
225
+ **index (12)**
226
+
227
+ | Endpoint | Provider(s) |
228
+ | -------------------------- | -------------------------- |
229
+ | /index/available | massive, yfinance |
230
+ | /index/classify | tushare |
231
+ | /index/constituents | tushare |
232
+ | /index/daily_basic | tushare |
233
+ | /index/global_index | tushare |
234
+ | /index/info | tushare |
235
+ | /index/members | tushare |
236
+ | /index/price/historical | massive, yfinance, tushare |
237
+ | /index/snapshots | massive |
238
+ | /index/thematic/ths_daily | tushare |
239
+ | /index/thematic/ths_index | tushare |
240
+ | /index/thematic/ths_member | tushare |
241
+
242
+ **etf (9)**
243
+
244
+ | Endpoint | Provider(s) |
245
+ | ------------------- | ----------------- |
246
+ | /etf/fund/adj_nav | tushare |
247
+ | /etf/fund/dividends | tushare |
248
+ | /etf/fund/manager | tushare |
249
+ | /etf/fund/portfolio | tushare |
250
+ | /etf/fund/share | tushare |
251
+ | /etf/historical | yfinance, tushare |
252
+ | /etf/info | yfinance, tushare |
253
+ | /etf/nav | tushare |
254
+ | /etf/search | tushare |
255
+
256
+ **fixedincome (4)**
257
+
258
+ | Endpoint | Provider(s) |
259
+ | ---------------------------- | ----------- |
260
+ | /fixedincome/rate/hibor | tushare |
261
+ | /fixedincome/rate/libor | tushare |
262
+ | /fixedincome/rate/shibor | tushare |
263
+ | /fixedincome/rate/shibor_lpr | tushare |
264
+
265
+ **currency (3)**
266
+
267
+ | Endpoint | Provider(s) |
268
+ | -------------------------- | -------------------------- |
269
+ | /currency/price/historical | massive, yfinance, tushare |
270
+ | /currency/search | massive |
271
+ | /currency/snapshots | massive |
272
+
273
+ **news (1)**
274
+
275
+ | Endpoint | Provider(s) |
276
+ | ------------- | -------------------------- |
277
+ | /news/company | massive, yfinance, tushare |
278
+
279
+ </details>
10
280
 
11
- ### 1. 单一数据源 (Single Source of Truth)
281
+ ---
12
282
 
13
- 所有金融数据(A 股、港股、美股、加密货币、宏观经济、衍生品、指数、ETF)统一走 DataHub REST API。
14
- 插件本身不调用 Tushare、CoinGecko、DefiLlama、Yahoo Finance 的 API —— 这些 provider 的编排和路由在 DataHub 服务端完成。
283
+ ## 三、插件代码架构
15
284
 
16
285
  ```
17
- 用户请求 AI Tool → DataHubClient → DataHub REST → 38+ provider
18
- ├── Tushare (A/HK)
19
- ├── yfinance (US)
20
- ├── CCXT (Crypto)
21
- ├── CoinGecko
22
- ├── DefiLlama
23
- ├── WorldBank
24
- └── ...
286
+ findoo-datahub-plugin/ # ~700 LOC 核心代码
287
+ |-- index.ts # 671 LOC -- 插件入口
288
+ | |-- 11 AI Tools 注册 (registerTool)
289
+ | |-- 2 Services 注册 (registerService)
290
+ | +-- dataProvider 内联对象
291
+ |-- openclaw.plugin.json # 元数据 + configSchema
292
+ |-- package.json # deps: yahoo-finance2
293
+ |-- DESIGN.md # 本文档
294
+ |
295
+ |-- src/
296
+ | |-- config.ts # 52 LOC -- 配置解析
297
+ | | +-- pluginConfig > env > 内置默认值 (3 级回退)
298
+ | |-- datahub-client.ts # 213 LOC -- DataHub REST 客户端
299
+ | | |-- query(path, params) -- 通用查询
300
+ | | |-- equity/crypto/economy/... -- 8 个 category helper
301
+ | | |-- ta(indicator, params) -- 技术分析
302
+ | | |-- getOHLCV(params) -- 标准化 K 线
303
+ | | |-- getTicker(symbol, market) -- 标准化 Ticker
304
+ | | +-- detectEquityProvider(sym) -- A/HK->tushare, US->massive
305
+ | |-- ohlcv-cache.ts # 119 LOC -- SQLite 本地缓存
306
+ | | |-- upsertBatch() -- INSERT OR REPLACE 批量写入
307
+ | | |-- query(sym, mkt, tf, since?) -- 范围查询
308
+ | | +-- getRange() -- 返回已缓存的时间区间
309
+ | |-- regime-detector.ts # 74 LOC -- 市场趋势检测
310
+ | | +-- detect(ohlcv[]) -> bull|bear|sideways|volatile|crisis
311
+ | | |-- drawdown > 30% -> crisis
312
+ | | |-- ATR% > 4% -> volatile
313
+ | | |-- SMA50 > SMA200 + close > SMA50 -> bull
314
+ | | |-- SMA50 < SMA200 + close < SMA50 -> bear
315
+ | | +-- else -> sideways
316
+ | |-- types.ts # 32 LOC -- OHLCV/Ticker/MarketRegime
317
+ | |
318
+ | |-- unified-provider.ts # 124 LOC -- 统一路由器 [当前未使用]
319
+ | |-- adapters/
320
+ | | |-- crypto-adapter.ts # 104 LOC -- CCXT 适配 [当前未使用]
321
+ | | |-- equity-adapter.ts # 12 LOC -- 接口定义
322
+ | | +-- yahoo-adapter.ts # 111 LOC -- Yahoo 适配 [当前未使用]
323
+ | |
324
+ | |-- datahub-client.test.ts # 46 tests (13 unit + 33 live)
325
+ | +-- integration.live.test.ts
326
+ |
327
+ +-- skills/ # 6 个 Claude 场景化技能
328
+ |-- equity/skill.md -- 股票研究 8 步深度分析
329
+ |-- crypto-defi/skill.md -- 加密 + DeFi 全球概览
330
+ |-- derivatives/skill.md -- 期货期权可转债分析
331
+ |-- macro/skill.md -- 宏观经济利率汇率
332
+ |-- a-share-radar/skill.md -- 龙虎榜/北向/融资盘后复盘
333
+ +-- data-query/skill.md -- 172 端点通用查询后备
25
334
  ```
26
335
 
27
- 好处:
336
+ ---
337
+
338
+ ## 四、11 个 AI Tools 详解
339
+
340
+ ### A. 按市场分类的 6 个专用工具
341
+
342
+ | Tool | 目标市场 | endpoint 枚举数 | 典型问答 |
343
+ | ----------------- | ---------------- | --------------- | --------------------------------- |
344
+ | `fin_stock` | A/港/美股 | 12 | "茅台最近行情"、"AAPL 利润表" |
345
+ | `fin_index` | 指数/ETF/基金 | 6 | "沪深300成分股"、"同花顺概念指数" |
346
+ | `fin_macro` | 宏观/利率/FX | 17 | "中国CPI趋势"、"中美利差" |
347
+ | `fin_derivatives` | 期货/期权/可转债 | 11 | "螺纹钢持仓"、"50ETF 期权链" |
348
+ | `fin_crypto` | 加密 + DeFi | 19 | "BTC 行情"、"DeFi TVL 排名" |
349
+ | `fin_market` | 市场监控 | 16 | "今日龙虎榜"、"北向资金流向" |
28
350
 
29
- - 插件零外部依赖(不需要 ccxt、yahoo-finance2 npm 包)
30
- - 新增 provider 只需 DataHub 端升级,插件无需改动
31
- - 统一认证模型(一组 Basic Auth 凭据覆盖 172 个端点)
351
+ ### B. 基础设施类 5 个工具
32
352
 
33
- ### 2. 零配置即用 (Zero-Config)
353
+ | Tool | 功能 | 用途 |
354
+ | ------------------ | -------------------------------------- | -------------------------------- |
355
+ | `fin_query` | 直通 171 端点的原始查询 | 其他 tool 未覆盖的端点后备 |
356
+ | `fin_data_ohlcv` | 带 SQLite 缓存的 OHLCV | 策略回测、技术分析、进化引擎 |
357
+ | `fin_data_regime` | 市场趋势检测 | 进化引擎判断行情、策略选型 |
358
+ | `fin_ta` | 技术指标计算 (SMA/EMA/RSI/MACD/BBands) | DataHub 服务端计算,减少本地负载 |
359
+ | `fin_data_markets` | 支持的市场列表 | LLM 能力发现 |
34
360
 
35
- 内置默认凭据(公共 DataHub 实例),安装后立刻可用,无需注册 API key:
361
+ ### Tool 注册模式
362
+
363
+ 每个 tool 遵循统一模式:
36
364
 
37
365
  ```typescript
38
- // 默认配置 — 开箱即用
39
- const DEFAULT_DATAHUB_URL = "http://43.134.61.136:8088";
40
- const DEFAULT_DATAHUB_USERNAME = "admin";
41
- const DEFAULT_DATAHUB_PASSWORD = "98ffa5c5-1ec6-4735-8e0c-715a5eca1a8d";
366
+ api.registerTool({
367
+ name: "fin_xxx",
368
+ label: "人类可读名",
369
+ description: "LLM 理解的能力描述",
370
+ parameters: Type.Object({
371
+ endpoint: Type.Unsafe<string>({ type: "string", enum: [...] }),
372
+ symbol: Type.Optional(Type.String()),
373
+ // ...
374
+ }),
375
+ async execute(_toolCallId, params) {
376
+ const results = await client.category(endpoint, queryParams);
377
+ return json({ success: true, endpoint, count, results });
378
+ }
379
+ }, { names: ["fin_xxx"] });
42
380
  ```
43
381
 
44
- 三种覆盖方式(优先级从高到低):
382
+ 关键设计决策:
45
383
 
46
- 1. 插件配置(`openclaw config set plugins.findoo-datahub-plugin.datahubApiUrl "..."`)
47
- 2. 环境变量(`DATAHUB_API_URL`、`DATAHUB_USERNAME`、`DATAHUB_PASSWORD`)
48
- 3. 内置默认值
384
+ - **`endpoint` 用 `Type.Unsafe` + `enum`** 绕开 TypeBox Union 限制,让 LLM 看到可选值列表
385
+ - **每个 tool 覆盖一个资产大类** — 而非 171 个独立 tool,避免 LLM 选择困难
386
+ - **`fin_query` 作为逃逸舱** — 任何 endpoint 都可直通
49
387
 
50
- ### 3. 薄客户端 (Thin Client)
388
+ ---
51
389
 
52
- `DataHubClient` 只有 ~200 行代码:
390
+ ## 五、2 Service 注册(跨扩展数据共享)
53
391
 
54
- - 一个通用 `query(path, params)` 方法
55
- - 8 category helper(`equity()`, `crypto()`, `economy()` 等)— 纯路径前缀封装
56
- - 2 个 typed method(`getOHLCV()`, `getTicker()`)— 标准化 OHLCV/Ticker 结构
57
- - 智能 provider 选择(`detectEquityProvider`):A 股/港股 → tushare,美股 → yfinance
392
+ ```typescript
393
+ // fin-data-provider -- trader-plugin 的数据基础设施
394
+ api.registerService({
395
+ id: "fin-data-provider",
396
+ instance: {
397
+ getOHLCV(params) // -> OHLCV[] (带 SQLite 缓存)
398
+ getTicker(symbol, mkt) // -> Ticker
399
+ detectRegime(params) // -> MarketRegime
400
+ getSupportedMarkets() // -> MarketInfo[]
401
+ }
402
+ });
58
403
 
59
- ### 4. 本地缓存加速 (Cache-First OHLCV)
404
+ // fin-regime-detector -- 进化引擎使用
405
+ api.registerService({
406
+ id: "fin-regime-detector",
407
+ instance: regimeDetector // .detect(ohlcv[]) -> MarketRegime
408
+ });
409
+ ```
60
410
 
61
- OHLCV 数据使用本地 SQLite 缓存(`~/.openfinclaw/state/findoo-ohlcv-cache.sqlite`):
411
+ 消费方示例(在 findoo-trader-plugin 中):
62
412
 
63
- ```
64
- 请求 OHLCV 命中缓存?→ Yes → 直接返回
65
- No → DataHub 取数 → 写入缓存 → 返回
413
+ ```typescript
414
+ const dp = runtime.getService("fin-data-provider");
415
+ const ohlcv = await dp.instance.getOHLCV({
416
+ symbol: "BTC/USDT",
417
+ market: "crypto",
418
+ timeframe: "1h",
419
+ limit: 300,
420
+ });
66
421
  ```
67
422
 
68
- 增量更新策略:缓存记录每个 symbol/market/timeframe 的时间范围,只请求缺失的部分。
69
-
70
- ### 5. 服务注册 (Service Registration)
423
+ ---
71
424
 
72
- 暴露 2 个服务供其他 `fin-*` 扩展使用:
425
+ ## 六、本地缓存策略 (Cache-First OHLCV)
73
426
 
74
- | Service ID | 接口 | 用途 |
75
- | --------------------- | ---------------------------------------------------------------------- | ---------------------------------- |
76
- | `fin-data-provider` | `getOHLCV()`, `getTicker()`, `detectRegime()`, `getSupportedMarkets()` | 策略引擎、模拟盘、基金经理获取行情 |
77
- | `fin-regime-detector` | `detect(ohlcv[])` | 进化引擎判断市场状态 |
427
+ ```
428
+ 请求 getOHLCV(BTC/USDT, crypto, 1h, limit=300)
429
+ |
430
+ |-- cache.getRange() -> 有缓存?
431
+ | |-- YES -> cache.query() 够用?
432
+ | | |-- YES -> 直接返回
433
+ | | +-- NO -> DataHub 取增量 -> upsertBatch -> 返回 cache.query()
434
+ | +-- NO -> DataHub 全量 -> upsertBatch -> 返回
435
+ |
436
+ +-- 存储: ~/.openfinclaw/state/findoo-ohlcv-cache.sqlite
437
+ Schema: (symbol, market, timeframe, timestamp) PK
438
+ + open, high, low, close, volume
439
+ ```
78
440
 
79
- 这意味着插件不仅是用户对话的工具,也是整个量化交易系统的数据层基础设施。
441
+ 好处:**相同 symbol+timeframe 的重复请求零网络开销**,回测时效果尤为明显。
80
442
 
81
443
  ---
82
444
 
83
- ## 架构总览
84
-
85
- ```
86
- findoo-datahub-plugin/
87
- ├── index.ts # 插件入口:注册 10 AI tools + 2 个 services
88
- ├── openclaw.plugin.json # 插件元数据 + 配置 schema
89
- ├── package.json
90
- ├── skills/ # 6 个 Claude 技能文件
91
- │ ├── equity/ # 股票研究
92
- │ ├── crypto-defi/ # 加密货币 + DeFi
93
- │ ├── derivatives/ # 衍生品(期货/期权/可转债)
94
- │ ├── macro/ # 宏观经济
95
- │ ├── market-radar/ # 市场雷达
96
- │ └── data-query/ # 原始数据查询
97
- └── src/
98
- ├── config.ts # 配置解析(48 LOC)
99
- ├── datahub-client.ts # DataHub REST 客户端(208 LOC)
100
- ├── ohlcv-cache.ts # SQLite OHLCV 缓存
101
- ├── regime-detector.ts # 市场趋势检测(SMA/ATR)
102
- ├── types.ts # 类型定义(re-export from fin-shared-types)
103
- └── datahub-client.test.ts # 46 个测试
104
- ```
445
+ ## 七、6 个 Claude Skills (场景化提示)
446
+
447
+ | Skill | 核心指导 | 分析模式 |
448
+ | ----------------- | ------------------------------------------------------------ | ------------------------------ |
449
+ | **equity** | 8 步深度分析:价格->盈利->现金->估值->技术->资金->筹码->宏观 | OCF/NI < 0.8 警示利润质量 |
450
+ | **crypto-defi** | 全局->市值->热点->DeFi->链上格局 | BTC dominance > 60% 时山寨承压 |
451
+ | **derivatives** | 合约->价格->持仓->结算->仓单 | P/C Ratio, 转股溢价率分档 |
452
+ | **macro** | 增长->通胀->制造业->流动性->政策->债市 | 中美利差交叉对比 |
453
+ | **a-share-radar** | 盘后复盘 5 步:涨跌->龙虎榜->板块->北向->融资 | 涨停>100+北向>50亿=强势信号 |
454
+ | **data-query** | 172 端点分类表 + regime 检测使用指南 | 通用后备 |
105
455
 
106
456
  ---
107
457
 
108
- ## 10 AI Tools
458
+ ## 八、配置体系 (URL 内置,API Key 必须配置)
109
459
 
110
- ### 按市场分类
460
+ ```
461
+ 内置写死:
462
+ datahubApiUrl: http://43.134.61.136:8088 (不需要配置)
463
+ datahubUsername: admin (不需要配置)
464
+ requestTimeoutMs: 30000 (可选覆盖)
111
465
 
112
- | # | Tool | 覆盖范围 | 典型问题 |
113
- | --- | ----------------- | -------------------------------- | ------------------------------- |
114
- | 1 | `fin_stock` | A 股/港股/美股行情、财务、资金流 | "茅台最新股价"、"AAPL 利润表" |
115
- | 2 | `fin_index` | 指数/ETF/基金 | "沪深 300 成分股"、"50ETF 净值" |
116
- | 3 | `fin_macro` | GDP/CPI/PMI/利率/汇率/世行 | "中国 CPI 趋势"、"美债收益率" |
117
- | 4 | `fin_derivatives` | 期货/期权/可转债 | "螺纹钢持仓"、"AAPL 期权链" |
118
- | 5 | `fin_crypto` | 加密货币行情 + DeFi 协议 | "BTC 行情"、"DeFi TVL 排名" |
119
- | 6 | `fin_market` | 龙虎榜/涨跌停/融资融券/北向资金 | "今日龙虎榜"、"北向资金流向" |
466
+ 必须配置:
467
+ datahubApiKey: <用户的 DataHub API Key>
120
468
 
121
- ### 基础设施类
469
+ 未配置 API Key 时:
470
+ 插件 register() 打印警告并跳过所有 tool/service 注册
471
+ ```
122
472
 
123
- | # | Tool | 功能 | 场景 |
124
- | --- | ------------------ | ----------------------- | ---------------------- |
125
- | 7 | `fin_query` | 直通 172 端点的原始查询 | 其他 tool 未覆盖的端点 |
126
- | 8 | `fin_data_ohlcv` | 带缓存的 OHLCV K 线 | 策略回测、技术分析 |
127
- | 9 | `fin_data_regime` | 市场趋势检测 | 进化引擎判断当前行情 |
128
- | 10 | `fin_data_markets` | 支持的市场列表 | 能力发现 |
473
+ 配置方式 (优先级从高到低):
129
474
 
130
- ---
475
+ ```bash
476
+ # 方式 A: 配置文件 (推荐)
477
+ openclaw config set plugins.findoo-datahub-plugin.datahubApiKey "your-api-key"
131
478
 
132
- ## 使用方式
479
+ # 方式 B: 环境变量
480
+ export DATAHUB_API_KEY="your-api-key"
481
+ # 或
482
+ export DATAHUB_PASSWORD="your-api-key"
483
+ export OPENFINCLAW_DATAHUB_PASSWORD="your-api-key"
484
+ ```
485
+
486
+ 可选覆盖 (自建 DataHub 实例):
487
+
488
+ ```bash
489
+ openclaw config set plugins.findoo-datahub-plugin.datahubApiUrl "http://your-host:8088"
490
+ openclaw config set plugins.findoo-datahub-plugin.datahubUsername "your-user"
491
+ ```
133
492
 
134
- ### 1. 安装(零配置)
493
+ ---
135
494
 
136
- 插件随 OpenFinClaw 自动加载。默认使用公共 DataHub,无需任何配置。
495
+ ## 九、测试覆盖
137
496
 
138
- ### 2. 自定义 DataHub 实例
497
+ | 层级 | 数量 | 内容 |
498
+ | -------- | ---- | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
499
+ | Unit | 13 | OHLCVCache CRUD(6) + RegimeDetector(6) + Client 构造(1) |
500
+ | Live E2E | 33 | 真实 DataHub 调用:equity(8) + economy(6) + crypto(3) + index(3) + etf(2) + derivatives(3) + currency(1) + OHLCV(2) + ticker(1) + 全链路 pipeline(1) |
501
+ | 跳过条件 | -- | `DATAHUB_SKIP_LIVE=1` 跳过 Live 测试 |
139
502
 
140
- 如果你自建了 OpenBB DataHub:
503
+ 运行测试:
141
504
 
142
505
  ```bash
143
- # 方式 A: 配置文件
144
- openclaw config set plugins.findoo-datahub-plugin.datahubApiUrl "http://localhost:8088"
145
- openclaw config set plugins.findoo-datahub-plugin.datahubUsername "myuser"
146
- openclaw config set plugins.findoo-datahub-plugin.datahubPassword "mypass"
506
+ # 全量测试(含 live DataHub 连接)
507
+ pnpm test extensions/findoo-datahub-plugin
147
508
 
148
- # 方式 B: 环境变量
149
- export DATAHUB_API_URL="http://localhost:8088"
150
- export DATAHUB_USERNAME="myuser"
151
- export DATAHUB_PASSWORD="mypass"
509
+ # 跳过 live 测试
510
+ DATAHUB_SKIP_LIVE=1 pnpm test extensions/findoo-datahub-plugin
152
511
  ```
153
512
 
154
- ### 3. 对话示例
513
+ ---
514
+
515
+ ## 十、已知问题 & 待改进
516
+
517
+ | # | 问题 | 影响 | 建议 |
518
+ | --- | -------------------------------------------- | -------------------------------------------------------------- | ------------------------------------------------------- |
519
+ | 1 | `UnifiedDataProvider` + `adapters/` 是死代码 | index.ts 直接内联 dataProvider,免费回退模式(CCXT/Yahoo)未接入 | 要么激活,要么清理 |
520
+ | 2 | `yahoo-finance2` 在 dependencies 但未使用 | 增加安装体积 | 若不启用免费模式可移除 |
521
+ | 3 | DataHub 单点故障 | 公共实例挂了则所有数据调用失败 | 接入 UnifiedDataProvider 做本地回退 |
522
+ | 4 | 插件被双重加载 | `extensions/` + `~/.openfinclaw/extensions/` 各加载一次 | 清理 `~/.openfinclaw/extensions/findoo-datahub-plugin/` |
523
+ | 5 | fixedincome 4 个端点未暴露 | DataHub 有但 plugin 没有对应 tool/enum | 加到 `fin_macro` 或 `fin_query` 的文档中 |
524
+ | 6 | `fin_ta` 编号注释跳跃 | Tool 11 在 Tool 10 前面,仅影响可读性 | 重排注释 |
525
+ | 7 | 无 WebSocket 实时行情 | 只有 REST 轮询 | DataHub 支持后接入 |
526
+
527
+ ---
528
+
529
+ ## 十一、对话示例
155
530
 
156
531
  ```
157
532
  用户: 茅台最近一个月行情
@@ -165,70 +540,36 @@ AI: (调用 fin_macro, endpoint=cpi) + (调用 fin_macro, endpoint=ppi)
165
540
 
166
541
  用户: 螺纹钢期货持仓分析
167
542
  AI: (调用 fin_derivatives, symbol=RB2501.SHF, endpoint=futures/holding)
168
- ```
169
543
 
170
- ### 4. 作为数据层供其他扩展使用
544
+ 用户: BTC/USDT 当前市场趋势
545
+ AI: (调用 fin_data_regime, symbol=BTC/USDT, market=crypto)
171
546
 
172
- 其他 `fin-*` 扩展通过服务注册表访问数据:
547
+ 用户: AAPL RSI 指标
548
+ AI: (调用 fin_ta, symbol=AAPL, indicator=rsi)
173
549
 
174
- ```typescript
175
- // fin-strategy-engine 或 fin-fund-manager 中
176
- const dp = api.getService("fin-data-provider");
177
- const ohlcv = await dp.instance.getOHLCV({
178
- symbol: "BTC/USDT",
179
- market: "crypto",
180
- timeframe: "1h",
181
- limit: 300,
182
- });
183
- ```
184
-
185
- ---
186
-
187
- ## DataHub 端点分类 (172 总计)
188
-
189
- | 分类 | 端点数 | 主要 Provider | 代表性 API |
190
- | ----------- | ------ | -------------------------- | ----------------------------------------------- |
191
- | Equity | 83 | Tushare, yfinance, Polygon | price/historical, fundamental/income, moneyflow |
192
- | Crypto | 23 | CCXT, CoinGecko, DefiLlama | market/ticker, defi/protocols, coin/market |
193
- | Economy | 21 | Tushare, WorldBank | gdp/real, cpi, shibor, treasury |
194
- | Derivatives | 13 | Tushare | futures/holding, options/chains |
195
- | Index | 12 | Tushare | price/historical, constituents, thematic |
196
- | ETF/Fund | 9 | Tushare, yfinance | etf/historical, fund/portfolio |
197
- | Currency | 6 | Polygon, fixer | fx/historical, fx/snapshots |
198
- | Coverage | 5 | (meta) | providers, endpoints |
199
-
200
- ---
201
-
202
- ## 测试
203
-
204
- ```bash
205
- # 全量测试(含 live DataHub 连接)
206
- pnpm test extensions/findoo-datahub-plugin
207
-
208
- # 跳过 live 测试
209
- DATAHUB_SKIP_LIVE=1 pnpm test extensions/findoo-datahub-plugin
550
+ 用户: 今日北向资金流向
551
+ AI: (调用 fin_market, endpoint=flow/hsgt_flow)
210
552
  ```
211
553
 
212
- 46 个测试:DataHubClient API、OHLCV 缓存、provider 检测、配置解析、Live E2E。
213
-
214
554
  ---
215
555
 
216
- ## 与旧架构的对比
556
+ ## 十二、与旧架构的对比
217
557
 
218
558
  | 维度 | 旧 (fin-data-bus + fin-data-hub) | 新 (findoo-datahub-plugin) |
219
559
  | ---------------- | ----------------------------------- | -------------------------- |
220
560
  | 代码量 | ~1200 LOC (两个扩展) | ~700 LOC (单扩展) |
221
561
  | 外部 npm 依赖 | ccxt, yahoo-finance2, coingecko-api | 无(仅 DataHub REST) |
222
562
  | API key 管理 | 每个 provider 单独配置 | 一组凭据覆盖全部 |
223
- | 新 provider 接入 | 写 adapter 改路由 测试 | DataHub 端增加,插件不动 |
224
- | AI Tools | 分散在两个扩展 | 统一 10 个 tool |
225
- | 缓存 | 有(OHLCVCache| 保留(SQLite|
226
- | 市场趋势 | RegimeDetector | 保留(SMA/ATR|
563
+ | 新 provider 接入 | 写 adapter -> 改路由 -> 测试 | DataHub 端增加,插件不动 |
564
+ | AI Tools | 分散在两个扩展 | 统一 11 个 tool |
565
+ | 缓存 | OHLCVCache | 保留 (SQLite) |
566
+ | 市场趋势 | RegimeDetector | 保留 (SMA/ATR) |
227
567
 
228
568
  ---
229
569
 
230
- ## 未来计划
570
+ ## 十三、未来计划
231
571
 
232
- - **Lite 版本**: 无需 DataHub 的轻量模式,直接调用免费 APICCXT + Yahoo + CoinGecko
572
+ - **Lite 版本**: 激活 UnifiedDataProvider,无需 DataHub 的轻量模式直接调用免费 API (CCXT + Yahoo + CoinGecko)
233
573
  - **WebSocket 实时**: DataHub 支持后接入实时行情推送
234
574
  - **自定义 Provider 路由**: 允许用户指定特定 symbol 走特定 provider
575
+ - **缓存 TTL**: 为不同 timeframe 设置不同的缓存过期策略