@openfinclaw/openfinclaw-strategy 2026.3.14 → 2026.3.26
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.
- package/README.md +34 -38
- package/index.ts +12 -872
- package/openclaw.plugin.json +2 -2
- package/package.json +1 -1
- package/skills/openfinclaw/SKILL.md +25 -34
- package/skills/price-check/SKILL.md +69 -4
- package/skills/strategy-builder/SKILL.md +42 -42
- package/skills/strategy-pack/SKILL.md +5 -5
- package/src/cli.ts +2 -2
- package/src/config.ts +1 -1
- package/src/datahub/client.ts +1 -1
- package/src/datahub/tools.ts +347 -0
- package/src/strategy/client.ts +44 -0
- package/src/{fork.ts → strategy/fork.ts} +11 -10
- package/src/{strategy-storage.ts → strategy/storage.ts} +5 -6
- package/src/strategy/tools.ts +521 -0
- package/src/{validate.ts → strategy/validate.ts} +2 -34
- package/skills/cross-asset-lite/SKILL.md +0 -95
- package/skills/crypto-altseason/SKILL.md +0 -122
- package/skills/crypto-funding-arb/SKILL.md +0 -88
- package/skills/crypto-stablecoin-flow/SKILL.md +0 -103
- package/skills/quick-quote/SKILL.md +0 -59
- package/src/strategy-storage.test.ts +0 -109
- package/src/validate.test.ts +0 -841
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Strategy package validation for Findoo Backtest Agent (FEP v2.0).
|
|
3
3
|
* Validates fep.yaml structure, strategy script safety, and required fields.
|
|
4
|
-
* @module openfinclaw/validate
|
|
5
4
|
*/
|
|
6
5
|
import { readFile } from "node:fs/promises";
|
|
7
6
|
import path from "node:path";
|
|
8
|
-
import type { FepV2Style, FepV2Timeframe } from "
|
|
7
|
+
import type { FepV2Style, FepV2Timeframe } from "../types.js";
|
|
9
8
|
|
|
10
9
|
/** FEP 版本常量 */
|
|
11
10
|
const FEP_VERSION = "2.0";
|
|
@@ -223,7 +222,6 @@ function validateSymbol(symbol: string): { valid: boolean; market?: string } {
|
|
|
223
222
|
|
|
224
223
|
/**
|
|
225
224
|
* 提取 YAML 块内容
|
|
226
|
-
* 提取指定块名下的所有内容(缩进的子行)
|
|
227
225
|
*/
|
|
228
226
|
function extractYamlBlock(yamlContent: string, blockName: string): string {
|
|
229
227
|
const lines = yamlContent.split("\n");
|
|
@@ -287,7 +285,6 @@ function validateFepYaml(
|
|
|
287
285
|
): { hasUniverse: boolean } {
|
|
288
286
|
let hasUniverse = false;
|
|
289
287
|
|
|
290
|
-
// 检查 fep 版本
|
|
291
288
|
const fepMatch = /^\s*fep\s*:\s*["']?([^"'\s]+)["']?/m.exec(fepStr);
|
|
292
289
|
if (!fepMatch) {
|
|
293
290
|
errors.push("fep.yaml 必须包含 'fep:' 版本声明(例如 fep: \"2.0\")");
|
|
@@ -297,13 +294,11 @@ function validateFepYaml(
|
|
|
297
294
|
);
|
|
298
295
|
}
|
|
299
296
|
|
|
300
|
-
// ── identity 验证 ──
|
|
301
297
|
if (!hasField(fepStr, "identity")) {
|
|
302
298
|
errors.push("fep.yaml 必须包含 'identity:' 节");
|
|
303
299
|
} else {
|
|
304
300
|
const identityBlock = extractYamlBlock(fepStr, "identity");
|
|
305
301
|
|
|
306
|
-
// 必填字段检查
|
|
307
302
|
const requiredIdentityFields = [
|
|
308
303
|
{ field: "id", message: "策略唯一标识" },
|
|
309
304
|
{ field: "name", message: "策略显示名称" },
|
|
@@ -324,7 +319,6 @@ function validateFepYaml(
|
|
|
324
319
|
}
|
|
325
320
|
}
|
|
326
321
|
|
|
327
|
-
// author.name 必填
|
|
328
322
|
if (!hasField(identityBlock, "author")) {
|
|
329
323
|
errors.push("fep.yaml identity 必须包含 'author' 节");
|
|
330
324
|
} else {
|
|
@@ -334,7 +328,6 @@ function validateFepYaml(
|
|
|
334
328
|
}
|
|
335
329
|
}
|
|
336
330
|
|
|
337
|
-
// style 枚举验证
|
|
338
331
|
const styleValue = getFieldValue(identityBlock, "style");
|
|
339
332
|
if (styleValue) {
|
|
340
333
|
const cleanedStyle = styleValue.replace(/["']/g, "");
|
|
@@ -343,7 +336,6 @@ function validateFepYaml(
|
|
|
343
336
|
}
|
|
344
337
|
}
|
|
345
338
|
|
|
346
|
-
// visibility 枚举验证
|
|
347
339
|
const visibilityValue = getFieldValue(identityBlock, "visibility");
|
|
348
340
|
if (visibilityValue) {
|
|
349
341
|
const cleanedVisibility = visibilityValue.replace(/["']/g, "");
|
|
@@ -354,23 +346,20 @@ function validateFepYaml(
|
|
|
354
346
|
}
|
|
355
347
|
}
|
|
356
348
|
|
|
357
|
-
// license 枚举验证
|
|
358
349
|
const licenseValue = getFieldValue(identityBlock, "license");
|
|
359
350
|
if (licenseValue) {
|
|
360
351
|
const cleanedLicense = licenseValue.replace(/["']/g, "");
|
|
361
352
|
if (!VALID_LICENSES.includes(cleanedLicense)) {
|
|
362
|
-
warnings.push(`fep.yaml
|
|
353
|
+
warnings.push(`fep.yaml identity.license 建议: ${VALID_LICENSES.join(", ")}`);
|
|
363
354
|
}
|
|
364
355
|
}
|
|
365
356
|
|
|
366
|
-
// tags 格式验证
|
|
367
357
|
const tagsValue = getFieldValue(identityBlock, "tags");
|
|
368
358
|
if (tagsValue && !tagsValue.startsWith("[")) {
|
|
369
359
|
warnings.push("identity.tags 应使用行内数组格式,如: tags: [trend, btc, crypto]");
|
|
370
360
|
}
|
|
371
361
|
}
|
|
372
362
|
|
|
373
|
-
// ── technical 验证(可选,有默认值)──
|
|
374
363
|
if (hasField(fepStr, "technical")) {
|
|
375
364
|
const technicalBlock = extractYamlBlock(fepStr, "technical");
|
|
376
365
|
|
|
@@ -385,13 +374,11 @@ function validateFepYaml(
|
|
|
385
374
|
}
|
|
386
375
|
}
|
|
387
376
|
|
|
388
|
-
// ── backtest 验证(必填)──
|
|
389
377
|
if (!hasField(fepStr, "backtest")) {
|
|
390
378
|
errors.push("fep.yaml 必须包含 'backtest:' 节");
|
|
391
379
|
} else {
|
|
392
380
|
const backtestBlock = extractYamlBlock(fepStr, "backtest");
|
|
393
381
|
|
|
394
|
-
// symbol 必填
|
|
395
382
|
if (!hasField(backtestBlock, "symbol")) {
|
|
396
383
|
errors.push("fep.yaml backtest 必须包含 'symbol'(交易品种)");
|
|
397
384
|
} else {
|
|
@@ -405,7 +392,6 @@ function validateFepYaml(
|
|
|
405
392
|
}
|
|
406
393
|
}
|
|
407
394
|
|
|
408
|
-
// defaultPeriod 必填
|
|
409
395
|
if (!hasField(backtestBlock, "defaultPeriod")) {
|
|
410
396
|
errors.push("fep.yaml backtest 必须包含 'defaultPeriod'");
|
|
411
397
|
} else {
|
|
@@ -418,12 +404,10 @@ function validateFepYaml(
|
|
|
418
404
|
}
|
|
419
405
|
}
|
|
420
406
|
|
|
421
|
-
// initialCapital 必填
|
|
422
407
|
if (!hasField(backtestBlock, "initialCapital")) {
|
|
423
408
|
errors.push("fep.yaml backtest 必须包含 'initialCapital'(初始资金)");
|
|
424
409
|
}
|
|
425
410
|
|
|
426
|
-
// timeframe 枚举验证(可选)
|
|
427
411
|
const timeframeValue = getFieldValue(backtestBlock, "timeframe");
|
|
428
412
|
if (timeframeValue) {
|
|
429
413
|
const cleanedTimeframe = timeframeValue.replace(/["']/g, "");
|
|
@@ -432,7 +416,6 @@ function validateFepYaml(
|
|
|
432
416
|
}
|
|
433
417
|
}
|
|
434
418
|
|
|
435
|
-
// universe 检测
|
|
436
419
|
if (hasField(backtestBlock, "universe")) {
|
|
437
420
|
hasUniverse = true;
|
|
438
421
|
const universeBlock = extractYamlBlock(backtestBlock, "universe");
|
|
@@ -441,7 +424,6 @@ function validateFepYaml(
|
|
|
441
424
|
}
|
|
442
425
|
}
|
|
443
426
|
|
|
444
|
-
// rebalance 验证(可选)
|
|
445
427
|
if (hasField(backtestBlock, "rebalance")) {
|
|
446
428
|
const rebalanceBlock = extractYamlBlock(backtestBlock, "rebalance");
|
|
447
429
|
const freqValue = getFieldValue(rebalanceBlock, "frequency");
|
|
@@ -454,7 +436,6 @@ function validateFepYaml(
|
|
|
454
436
|
}
|
|
455
437
|
}
|
|
456
438
|
|
|
457
|
-
// ── risk 验证(可选)──
|
|
458
439
|
if (hasField(fepStr, "risk")) {
|
|
459
440
|
const riskBlock = extractYamlBlock(fepStr, "risk");
|
|
460
441
|
const thresholdValue = getFieldValue(riskBlock, "maxDrawdownThreshold");
|
|
@@ -466,7 +447,6 @@ function validateFepYaml(
|
|
|
466
447
|
}
|
|
467
448
|
}
|
|
468
449
|
|
|
469
|
-
// ── paper 验证(可选)──
|
|
470
450
|
if (hasField(fepStr, "paper")) {
|
|
471
451
|
const paperBlock = extractYamlBlock(fepStr, "paper");
|
|
472
452
|
const barIntervalValue = getFieldValue(paperBlock, "barIntervalSeconds");
|
|
@@ -492,7 +472,6 @@ function validateStrategyScript(
|
|
|
492
472
|
): void {
|
|
493
473
|
const codeWithoutComments = removePythonComments(scriptStr);
|
|
494
474
|
|
|
495
|
-
// 检查策略函数
|
|
496
475
|
const hasCompute =
|
|
497
476
|
/\bdef\s+compute\s*\(\s*data\s*\)/.test(scriptStr) ||
|
|
498
477
|
/\bdef\s+compute\s*\(\s*data\s*,\s*context\s*(?:=\s*None)?\s*\)/.test(scriptStr);
|
|
@@ -502,22 +481,18 @@ function validateStrategyScript(
|
|
|
502
481
|
errors.push("scripts/strategy.py 必须定义 compute(data) 或 select(universe) 函数");
|
|
503
482
|
}
|
|
504
483
|
|
|
505
|
-
// 如果有 universe 配置,推荐使用 select
|
|
506
484
|
if (hasUniverse && !hasSelect) {
|
|
507
485
|
warnings.push("backtest 配置了 universe,建议使用 select(universe) 函数实现多标的策略");
|
|
508
486
|
}
|
|
509
487
|
|
|
510
|
-
// 如果没有 universe 但使用 select,给出警告
|
|
511
488
|
if (!hasUniverse && hasSelect && !hasCompute) {
|
|
512
489
|
warnings.push("使用 select(universe) 函数时,建议在 backtest 中配置 universe");
|
|
513
490
|
}
|
|
514
491
|
|
|
515
|
-
// 检查返回值结构(简单检查)
|
|
516
492
|
if (hasCompute && !/\baction\b/.test(scriptStr)) {
|
|
517
493
|
warnings.push("compute(data) 返回值应包含 action 字段(buy/sell/hold/target)");
|
|
518
494
|
}
|
|
519
495
|
|
|
520
|
-
// 检查禁止的 import
|
|
521
496
|
for (const pattern of FORBIDDEN_IMPORT_PATTERNS) {
|
|
522
497
|
if (pattern.test(scriptStr)) {
|
|
523
498
|
const match = pattern.exec(scriptStr);
|
|
@@ -526,7 +501,6 @@ function validateStrategyScript(
|
|
|
526
501
|
}
|
|
527
502
|
}
|
|
528
503
|
|
|
529
|
-
// 检查禁止的函数调用(忽略注释)
|
|
530
504
|
for (const pattern of FORBIDDEN_CALL_PATTERNS) {
|
|
531
505
|
if (pattern.test(codeWithoutComments)) {
|
|
532
506
|
const match = pattern.exec(codeWithoutComments);
|
|
@@ -535,7 +509,6 @@ function validateStrategyScript(
|
|
|
535
509
|
}
|
|
536
510
|
}
|
|
537
511
|
|
|
538
|
-
// 检查破坏回测一致性的模式(忽略注释)
|
|
539
512
|
for (const pattern of BACKTEST_BREAKING_PATTERNS) {
|
|
540
513
|
if (pattern.test(codeWithoutComments)) {
|
|
541
514
|
const match = pattern.exec(codeWithoutComments);
|
|
@@ -549,8 +522,6 @@ function validateStrategyScript(
|
|
|
549
522
|
|
|
550
523
|
/**
|
|
551
524
|
* 验证策略包目录(FEP v2.0)
|
|
552
|
-
* @param dirPath 策略包目录路径
|
|
553
|
-
* @returns 验证结果
|
|
554
525
|
*/
|
|
555
526
|
export async function validateStrategyPackage(dirPath: string): Promise<ValidateResult> {
|
|
556
527
|
const errors: string[] = [];
|
|
@@ -561,7 +532,6 @@ export async function validateStrategyPackage(dirPath: string): Promise<Validate
|
|
|
561
532
|
const scriptDir = path.join(normalizedDir, "scripts");
|
|
562
533
|
const strategyPath = path.join(scriptDir, "strategy.py");
|
|
563
534
|
|
|
564
|
-
// ── 检查必需文件 ──
|
|
565
535
|
let fepContent: string;
|
|
566
536
|
try {
|
|
567
537
|
const raw = await readFile(fepPath, "utf-8");
|
|
@@ -580,10 +550,8 @@ export async function validateStrategyPackage(dirPath: string): Promise<Validate
|
|
|
580
550
|
return { valid: false, errors };
|
|
581
551
|
}
|
|
582
552
|
|
|
583
|
-
// ── 验证 fep.yaml ──
|
|
584
553
|
const { hasUniverse } = validateFepYaml(fepContent, errors, warnings);
|
|
585
554
|
|
|
586
|
-
// ── 验证 strategy.py ──
|
|
587
555
|
validateStrategyScript(strategyContent, hasUniverse, errors, warnings);
|
|
588
556
|
|
|
589
557
|
return {
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: fin-cross-asset-lite
|
|
3
|
-
description: "Cross-asset price comparison and trend analysis — compare crypto, stocks, indices side by side. Use when user asks to compare multiple assets, wants to know which performed better, or asks about relative strength between markets. Works with price/kline data only (no fundamentals)."
|
|
4
|
-
metadata:
|
|
5
|
-
{ "openclaw": { "emoji": "⚖️", "requires": { "extensions": ["openfinclaw"] } } }
|
|
6
|
-
---
|
|
7
|
-
|
|
8
|
-
# Cross-Asset Lite — 多资产价格对比
|
|
9
|
-
|
|
10
|
-
用价格数据做跨市场对比 — BTC vs 黄金、茅台 vs 腾讯、加密 vs A 股。
|
|
11
|
-
|
|
12
|
-
## Tools
|
|
13
|
-
|
|
14
|
-
### fin_compare — 并排对比(核心)
|
|
15
|
-
|
|
16
|
-
| Parameter | Type | Required | Example |
|
|
17
|
-
| --------- | ------ | -------- | --------------------------- |
|
|
18
|
-
| symbols | string | Yes | BTC/USDT,ETH/USDT,600519.SH |
|
|
19
|
-
|
|
20
|
-
返回每个资产的最新价格 + 周涨跌幅。最多 5 个资产。
|
|
21
|
-
|
|
22
|
-
### fin_kline — K 线趋势
|
|
23
|
-
|
|
24
|
-
| Parameter | Type | Required | Default | Example |
|
|
25
|
-
| --------- | ------ | -------- | ------- | -------- |
|
|
26
|
-
| symbol | string | Yes | — | BTC/USDT |
|
|
27
|
-
| market | string | No | auto | crypto |
|
|
28
|
-
| limit | number | No | 30 | 7 |
|
|
29
|
-
|
|
30
|
-
### fin_price — 单资产查价
|
|
31
|
-
|
|
32
|
-
| Parameter | Type | Required | Example |
|
|
33
|
-
| --------- | ------ | -------- | -------- |
|
|
34
|
-
| symbol | string | Yes | BTC/USDT |
|
|
35
|
-
| market | string | No | auto |
|
|
36
|
-
|
|
37
|
-
## Analysis Framework
|
|
38
|
-
|
|
39
|
-
### Step 1: 数据获取
|
|
40
|
-
|
|
41
|
-
```
|
|
42
|
-
fin_compare(symbols="资产A,资产B,资产C")
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
### Step 2: 趋势对比
|
|
46
|
-
|
|
47
|
-
对每个资产分别获取 K 线,计算:
|
|
48
|
-
|
|
49
|
-
- 周涨跌幅(已在 fin_compare 返回)
|
|
50
|
-
- 月涨跌幅(fin_kline limit=30,取首尾价格计算)
|
|
51
|
-
- 波动率(K 线日收益率标准差 × √252)
|
|
52
|
-
|
|
53
|
-
### Step 3: 相对强弱判断
|
|
54
|
-
|
|
55
|
-
| 场景 | 判断逻辑 |
|
|
56
|
-
| ------------ | ------------------------------- |
|
|
57
|
-
| A涨B跌 | A 相对强势,资金可能从 B 流向 A |
|
|
58
|
-
| 同涨 A > B | A 弹性更大,risk-on 环境 |
|
|
59
|
-
| 同跌 A < B | A 防御性更强 |
|
|
60
|
-
| 两者相关性高 | 可能受同一宏观因子驱动 |
|
|
61
|
-
|
|
62
|
-
### Step 4: 输出模板
|
|
63
|
-
|
|
64
|
-
```markdown
|
|
65
|
-
## 资产对比(截至 YYYY-MM-DD)
|
|
66
|
-
|
|
67
|
-
| 资产 | 最新价 | 周涨跌 | 月涨跌 | 判断 |
|
|
68
|
-
| ---- | ------ | ------ | ------ | ---- |
|
|
69
|
-
| BTC | $XX | +X.X% | +X.X% | 强势 |
|
|
70
|
-
| ETH | $XX | +X.X% | +X.X% | 跟涨 |
|
|
71
|
-
| 茅台 | ¥XX | -X.X% | -X.X% | 弱势 |
|
|
72
|
-
|
|
73
|
-
**结论**: [一句话总结相对强弱和可能原因]
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
## Common Comparison Pairs
|
|
77
|
-
|
|
78
|
-
| 场景 | Symbols |
|
|
79
|
-
| ------------ | ----------------------------------- |
|
|
80
|
-
| 加密双雄 | BTC/USDT,ETH/USDT |
|
|
81
|
-
| 加密 vs 传统 | BTC/USDT,600519.SH,AAPL |
|
|
82
|
-
| 白酒双雄 | 600519.SH,000858.SZ |
|
|
83
|
-
| 中美科技 | 00700.HK,AAPL |
|
|
84
|
-
| 加密生态 | BTC/USDT,ETH/USDT,SOL/USDT,BNB/USDT |
|
|
85
|
-
|
|
86
|
-
## Examples
|
|
87
|
-
|
|
88
|
-
**用户:** BTC 和 ETH 最近谁涨得多?
|
|
89
|
-
**流程:** `fin_compare(symbols="BTC/USDT,ETH/USDT")` → 对比表格
|
|
90
|
-
|
|
91
|
-
**用户:** 比较一下茅台和腾讯
|
|
92
|
-
**流程:** `fin_compare(symbols="600519.SH,00700.HK")` → 价格+周涨跌
|
|
93
|
-
|
|
94
|
-
**用户:** 加密和 A 股最近走势相反吗?
|
|
95
|
-
**流程:** `fin_compare(symbols="BTC/USDT,000300.SH")` + `fin_kline` 各取 30 天 → 趋势对比分析
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: fin-crypto-altseason
|
|
3
|
-
description: "Crypto altseason timing — BTC dominance trend, Altseason Index (Top 50 vs BTC), ETH/BTC ratio, category rotation radar, capital rotation ladder (BTC→ETH→large ALT→mid-cap→meme). Use when: user asks about altseason, BTC dominance direction, ETH/BTC ratio, altcoin rotation, or 'should I switch from BTC to alts'. NOT for: BTC cycle analysis (use fin-crypto-btc-cycle), single coin lookup (use fin-crypto), DeFi yields (use fin-crypto-defi-yield), funding rate arbitrage (use fin-crypto-funding-arb)."
|
|
4
|
-
metadata:
|
|
5
|
-
{ "openclaw": { "emoji": "🔄", "requires": { "extensions": ["openfinclaw"] } } }
|
|
6
|
-
---
|
|
7
|
-
|
|
8
|
-
# Crypto Altseason Timing
|
|
9
|
-
|
|
10
|
-
BTC dominance is the traffic light for altseason. This skill turns "feels like alts are pumping" into a quantifiable, actionable rotation timing system.
|
|
11
|
-
|
|
12
|
-
## When to Use
|
|
13
|
-
|
|
14
|
-
- "现在是山寨季吗" / "Is it altseason?"
|
|
15
|
-
- "BTC dominance 在下降意味着什么" / "BTC dominance is dropping, what does it mean?"
|
|
16
|
-
- "ETH/BTC 汇率怎么看" / "How is ETH/BTC doing?"
|
|
17
|
-
- "该从 BTC 换到山寨了吗" / "Should I rotate from BTC to alts?"
|
|
18
|
-
- "哪个赛道最近涨得好" / "Which crypto sector is pumping?"
|
|
19
|
-
|
|
20
|
-
## Tools & Parameters
|
|
21
|
-
|
|
22
|
-
### fin_crypto — Core data
|
|
23
|
-
|
|
24
|
-
| Parameter | Type | Required | Format | Default | Example |
|
|
25
|
-
| --------- | ------ | -------- | ------------------- | ------- | ----------------- |
|
|
26
|
-
| endpoint | string | Yes | see endpoints below | — | coin/global_stats |
|
|
27
|
-
| symbol | string | Depends | pair / coin ID | — | ETH/BTC |
|
|
28
|
-
| limit | number | No | 1-250 | 100 | 50 |
|
|
29
|
-
|
|
30
|
-
#### Key Endpoints
|
|
31
|
-
|
|
32
|
-
| endpoint | Description | Example |
|
|
33
|
-
| --------------------- | ---------------------------- | -------------------------------------------------------------------- |
|
|
34
|
-
| `coin/global_stats` | BTC dominance (current snap) | `fin_crypto(endpoint="coin/global_stats")` |
|
|
35
|
-
| `coin/market` | Top N coins by market cap | `fin_crypto(endpoint="coin/market", limit=50)` |
|
|
36
|
-
| `coin/categories` | Category/sector 7d% rankings | `fin_crypto(endpoint="coin/categories")` |
|
|
37
|
-
| `coin/trending` | Trending / hot coins | `fin_crypto(endpoint="coin/trending")` |
|
|
38
|
-
| `market/funding_rate` | Funding rate (sentiment) | `fin_crypto(endpoint="market/funding_rate", symbol="ETH/USDT:USDT")` |
|
|
39
|
-
|
|
40
|
-
## Altseason Analysis Pattern
|
|
41
|
-
|
|
42
|
-
### 1. BTC Dominance Assessment
|
|
43
|
-
|
|
44
|
-
1. **BTC Dominance snapshot** `fin_crypto(endpoint="coin/global_stats")` — Get current btc_dominance %
|
|
45
|
-
- 💡 BTC dominance is the single most important altseason indicator
|
|
46
|
-
|
|
47
|
-
2. **BTC + market context** `fin_crypto(endpoint="coin/market", limit=50)` — Top 50 coin performance
|
|
48
|
-
- Calculate: how many of Top 50 (excluding stablecoins) outperformed BTC over 7d/30d
|
|
49
|
-
|
|
50
|
-
### 2. Altseason Index (Self-Calculated)
|
|
51
|
-
|
|
52
|
-
```
|
|
53
|
-
Count coins in Top 50 (excluding stablecoins + wrapped tokens) that outperformed BTC in 7d return.
|
|
54
|
-
Altseason Index = outperformers / eligible_count × 100
|
|
55
|
-
|
|
56
|
-
Interpretation:
|
|
57
|
-
> 75% = Altseason confirmed (strong rotation out of BTC)
|
|
58
|
-
50-75% = Transitional (rotation beginning)
|
|
59
|
-
25-50% = Neutral (mixed signals)
|
|
60
|
-
< 25% = Bitcoin Season (BTC dominates, alts lag)
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
### 3. Rotation Ladder Detection
|
|
64
|
-
|
|
65
|
-
```
|
|
66
|
-
BTC → ETH → Large ALT → Mid-cap ALT → Meme → TOP signal
|
|
67
|
-
|
|
68
|
-
Step 1: fin_kline(symbol="ETH/BTC", market="crypto", limit=30) → ETH/BTC trend
|
|
69
|
-
Step 2: fin_crypto(coin/market, limit=50) → stratify by market cap tiers:
|
|
70
|
-
- Tier 1 (>$50B): BTC, ETH
|
|
71
|
-
- Tier 2 ($10-50B): SOL, BNB, XRP, ADA, AVAX, DOT
|
|
72
|
-
- Tier 3 ($1-10B): mid-cap alts
|
|
73
|
-
- Tier 4 (<$1B): small-cap / meme
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
### 4. Altseason Health Check (Composite)
|
|
77
|
-
|
|
78
|
-
```
|
|
79
|
-
Combine signals into a composite score (0-5):
|
|
80
|
-
|
|
81
|
-
1. BTC dom trending down (7d) .............. +1
|
|
82
|
-
2. Altseason Index > 50% ................... +1
|
|
83
|
-
3. ETH/BTC in uptrend (above 20d SMA) ...... +1
|
|
84
|
-
4. Top category 7d% > +15% ................. +1
|
|
85
|
-
5. Meme category NOT leading ............... +1
|
|
86
|
-
|
|
87
|
-
Score interpretation:
|
|
88
|
-
5/5 = Strong healthy altseason (rotate aggressively)
|
|
89
|
-
3-4 = Altseason developing (start positioning)
|
|
90
|
-
1-2 = Early / mixed signals (selective, stick to large caps)
|
|
91
|
-
0 = Bitcoin Season (stay in BTC or sidelines)
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
## Signal Quick-Reference
|
|
95
|
-
|
|
96
|
-
### BTC Dominance + BTC Price Matrix
|
|
97
|
-
|
|
98
|
-
| BTC Dominance | BTC Price | Signal | Action |
|
|
99
|
-
| ------------- | --------- | --------------- | ------------------------------------- |
|
|
100
|
-
| dom ↓ | BTC ↑ | Altseason onset | Rotate BTC → ETH → ALT progressively |
|
|
101
|
-
| dom ↓ | BTC ↓ | Panic exit | Risk-off, move to stablecoins |
|
|
102
|
-
| dom ↑ | BTC ↑ | Bitcoin Season | Concentrate in BTC, trim alts |
|
|
103
|
-
| dom ↑ | BTC ↓ | ALT hemorrhage | Worst scenario for alts, full defense |
|
|
104
|
-
|
|
105
|
-
Threshold: dom 7d change > ±0.5% = trend signal; > ±2% = strong signal.
|
|
106
|
-
|
|
107
|
-
## Response Guidelines
|
|
108
|
-
|
|
109
|
-
### Number Formats
|
|
110
|
-
|
|
111
|
-
- BTC dominance: 54.3% (1 decimal)
|
|
112
|
-
- Altseason Index: 68% (integer)
|
|
113
|
-
- ETH/BTC ratio: 0.0542 (4 decimals)
|
|
114
|
-
- Category 7d%: +28.5% / -3.2% (always with +/- sign, 1 decimal)
|
|
115
|
-
|
|
116
|
-
### Must Include
|
|
117
|
-
|
|
118
|
-
- Data timestamp ("Data as of YYYY-MM-DD")
|
|
119
|
-
- Current BTC dominance with directional context
|
|
120
|
-
- Altseason Index score with interpretation
|
|
121
|
-
- Rotation ladder current phase
|
|
122
|
-
- At least one ⚠️ risk signal assessment
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: fin-crypto-funding-arb
|
|
3
|
-
description: "Crypto funding rate arbitrage — perpetual funding rates, delta-neutral yield, cross-exchange rate spread, annualized return calculator. Use when: user asks about funding rate, delta-neutral strategy, basis trading, perpetual vs spot arb, or CeFi yield. NOT for: DeFi yields (use fin-crypto-defi-yield), spot trading (use fin-crypto), macro rates (use fin-macro)."
|
|
4
|
-
metadata:
|
|
5
|
-
{ "openclaw": { "emoji": "🔄", "requires": { "extensions": ["openfinclaw"] } } }
|
|
6
|
-
---
|
|
7
|
-
|
|
8
|
-
# Crypto Funding Rate Arbitrage
|
|
9
|
-
|
|
10
|
-
永续合约资金费率套利分析 — Delta 中性策略的收益计算、风险监控与跨交易所利差发现。
|
|
11
|
-
|
|
12
|
-
> **核心逻辑:** 永续合约每 8h 结算 funding rate。当 funding > 0 时,做多付费给做空方。Delta 中性策略 = 现货买入 + 永续做空,锁定 funding 收益,无方向性风险。
|
|
13
|
-
|
|
14
|
-
## When to Use
|
|
15
|
-
|
|
16
|
-
- "BTC 资金费率多少" / "BTC funding rate"
|
|
17
|
-
- "哪些币 funding rate 最高" / "top funding rate coins"
|
|
18
|
-
- "funding 套利能赚多少" / "funding arb yield"
|
|
19
|
-
- "现在做 delta 中性策略合适吗" / "delta neutral strategy"
|
|
20
|
-
- "Binance 和 OKX funding 差多少" / "cross-exchange funding spread"
|
|
21
|
-
|
|
22
|
-
## Tools & Parameters
|
|
23
|
-
|
|
24
|
-
### fin_crypto — Funding & Market Data
|
|
25
|
-
|
|
26
|
-
| Parameter | Type | Required | Format | Default | Example |
|
|
27
|
-
| --------- | ------ | -------- | ------------------- | ------- | ------------------- |
|
|
28
|
-
| endpoint | string | Yes | see endpoints below | — | market/funding_rate |
|
|
29
|
-
| symbol | string | Depends | pair format | — | BTC/USDT:USDT |
|
|
30
|
-
| limit | number | No | 1-250 | 100 | 20 |
|
|
31
|
-
|
|
32
|
-
#### Endpoints
|
|
33
|
-
|
|
34
|
-
| endpoint | Description | Example |
|
|
35
|
-
| --------------------- | --------------------------- | -------------------------------------------------------------------- |
|
|
36
|
-
| `market/funding_rate` | Perpetual funding rate + OI | `fin_crypto(endpoint="market/funding_rate", symbol="BTC/USDT:USDT")` |
|
|
37
|
-
| `market/ticker` | Spot price snapshot | `fin_crypto(endpoint="market/ticker", symbol="BTC/USDT")` |
|
|
38
|
-
| `market/tickers` | All tickers (scan) | `fin_crypto(endpoint="market/tickers")` |
|
|
39
|
-
| `market/orderbook` | Order book depth | `fin_crypto(endpoint="market/orderbook", symbol="BTC/USDT")` |
|
|
40
|
-
|
|
41
|
-
## Funding Rate Arbitrage Analysis Pattern
|
|
42
|
-
|
|
43
|
-
1. **Funding Rate Scan** `fin_crypto(market/funding_rate, symbol="BTC/USDT:USDT")` — 获取目标币种当前 funding rate + OI
|
|
44
|
-
- ⚠️ 如果 funding > +0.10%/8h → 多头极度拥挤,套利收益高但清算瀑布风险也高
|
|
45
|
-
- ⚠️ 如果 funding < -0.05%/8h → 空头拥挤,反向套利(现货做空 + 永续做多)但执行难度大
|
|
46
|
-
|
|
47
|
-
2. **Spot Price Baseline** `fin_crypto(market/ticker, symbol="BTC/USDT")` — 现货价格基准
|
|
48
|
-
- 💡 计算 basis = (永续价 - 现货价) / 现货价 × 100%。正 basis + 正 funding = 做空端有利
|
|
49
|
-
|
|
50
|
-
3. **Annualized Return Calculation** — 核心输出
|
|
51
|
-
```
|
|
52
|
-
8h rate → Daily = rate × 3
|
|
53
|
-
Annual = rate × 3 × 365
|
|
54
|
-
Net annual = annual - (maker_fee × 2 × 365) - slippage_estimate
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
4. **Liquidity Assessment** `fin_crypto(market/orderbook, symbol="BTC/USDT")` — 执行成本评估
|
|
58
|
-
- ⚠️ 如果 spread > 0.1% → 大仓位进出滑点显著,套利净收益打折
|
|
59
|
-
- ⚠️ 如果 orderbook depth < $500K within 0.1% → 流动性不足,不适合大额套利
|
|
60
|
-
|
|
61
|
-
## Signal Quick-Reference
|
|
62
|
-
|
|
63
|
-
### Funding Rate Signals
|
|
64
|
-
|
|
65
|
-
| Funding Rate (8h) | Annualized | Signal | Action |
|
|
66
|
-
| ----------------- | ---------- | ------------- | ------------------------------------------ |
|
|
67
|
-
| > +0.15% | > 55% | Extreme long | High yield but squeeze risk; size down |
|
|
68
|
-
| +0.05% ~ +0.15% | 18-55% | Sweet spot | Best risk-adjusted arb window |
|
|
69
|
-
| +0.01% ~ +0.05% | 4-18% | Marginal | Only worth it for large capital + low fees |
|
|
70
|
-
| -0.01% ~ +0.01% | < 4% | Neutral | Not actionable |
|
|
71
|
-
| < -0.05% | — | Short squeeze | Consider reverse arb (risky) |
|
|
72
|
-
|
|
73
|
-
## Response Guidelines
|
|
74
|
-
|
|
75
|
-
### Number Formatting
|
|
76
|
-
|
|
77
|
-
- Funding rate: 4 decimal places per period (+0.0800%/8h)
|
|
78
|
-
- Annualized yield: 1 decimal place (35.0% annualized)
|
|
79
|
-
- BTC price: to integer ($67,432)
|
|
80
|
-
- OI / Volume: $B/$M notation ($4.2B OI)
|
|
81
|
-
- Basis: 2 decimal places (+0.12%)
|
|
82
|
-
|
|
83
|
-
### Must Include
|
|
84
|
-
|
|
85
|
-
- Funding rate period (8h/4h/1h) — never show rate without period
|
|
86
|
-
- Net yield after fees (maker fee typically 0.02%, taker 0.05%)
|
|
87
|
-
- Risk tier classification (low/medium/high/extreme)
|
|
88
|
-
- Data timestamp ("funding rate as of 2026-03-07 08:00 UTC")
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: fin-crypto-stablecoin-flow
|
|
3
|
-
description: "Stablecoin capital flow analysis — USDT/USDC/DAI market cap trends, 4-week rolling inflow as leading indicator, chain distribution (ETH/Tron/BSC), stablecoin-to-total-market ratio. Use when: user asks about stablecoin supply, capital inflow/outflow, OTC demand, USDT vs USDC comparison, or whether money is entering crypto. NOT for: individual coin analysis (use fin-crypto), DeFi yield farming (use fin-crypto), macro rates (use fin-macro)."
|
|
4
|
-
metadata:
|
|
5
|
-
{ "openclaw": { "emoji": "💵", "requires": { "extensions": ["openfinclaw"] } } }
|
|
6
|
-
---
|
|
7
|
-
|
|
8
|
-
# Stablecoin Capital Flow Analysis
|
|
9
|
-
|
|
10
|
-
Stablecoins = crypto market's M2 money supply. Track stablecoin flows as a **2-4 week leading indicator** for BTC and altcoin price direction.
|
|
11
|
-
|
|
12
|
-
> **Core thesis:** Capital enters crypto in three steps: fiat -> stablecoin -> BTC/altcoin. Stablecoin supply changes signal capital intent before price moves.
|
|
13
|
-
|
|
14
|
-
## When to Use
|
|
15
|
-
|
|
16
|
-
- "USDT 市值在增长吗" / "Is USDT market cap growing"
|
|
17
|
-
- "稳定币总量是多少" / "Total stablecoin supply"
|
|
18
|
-
- "场外资金在进场吗" / "Is money flowing into crypto"
|
|
19
|
-
- "USDT 和 USDC 有什么区别" / "USDT vs USDC comparison"
|
|
20
|
-
- "稳定币在哪条链上最多" / "Which chain has the most stablecoins"
|
|
21
|
-
- "现在是入场好时机吗" / "Is this a good time to enter crypto"
|
|
22
|
-
|
|
23
|
-
## When NOT to Use
|
|
24
|
-
|
|
25
|
-
- Individual coin price/analysis (BTC/ETH/SOL) -> use `/fin-crypto`
|
|
26
|
-
- DeFi protocol TVL/yields -> use `/fin-crypto`
|
|
27
|
-
- CEX trading (orderbook/funding rate) -> use `/fin-crypto`
|
|
28
|
-
- Macro interest rates/treasury yields -> use `/fin-macro`
|
|
29
|
-
- A-share/US equity -> use `/fin-a-share` or `/fin-us-equity`
|
|
30
|
-
|
|
31
|
-
## Tools & Parameters
|
|
32
|
-
|
|
33
|
-
### fin_crypto
|
|
34
|
-
|
|
35
|
-
| Parameter | Type | Required | Format | Default | Example |
|
|
36
|
-
| --------- | ------ | -------- | ------------------- | ------- | ---------------- |
|
|
37
|
-
| endpoint | string | Yes | see endpoints below | — | defi/stablecoins |
|
|
38
|
-
| symbol | string | Depends | coin ID / pair | — | bitcoin |
|
|
39
|
-
| limit | number | No | 1-250 | 100 | 20 |
|
|
40
|
-
|
|
41
|
-
#### Key Endpoints
|
|
42
|
-
|
|
43
|
-
| endpoint | Description | Example |
|
|
44
|
-
| ------------------- | ------------------------------------------------ | ---------------------------------------------- |
|
|
45
|
-
| `defi/stablecoins` | All stablecoins: market cap + chain distribution | `fin_crypto(endpoint="defi/stablecoins")` |
|
|
46
|
-
| `coin/global_stats` | Total crypto market cap (for ratio calc) | `fin_crypto(endpoint="coin/global_stats")` |
|
|
47
|
-
| `coin/market` | Top coins by market cap (BTC price ref) | `fin_crypto(endpoint="coin/market", limit=10)` |
|
|
48
|
-
| `defi/chains` | Per-chain TVL (cross-validate fund flow) | `fin_crypto(endpoint="defi/chains")` |
|
|
49
|
-
| `defi/bridges` | Cross-chain bridge volumes (migration) | `fin_crypto(endpoint="defi/bridges")` |
|
|
50
|
-
|
|
51
|
-
## Stablecoin Flow Analysis Pattern
|
|
52
|
-
|
|
53
|
-
1. **Stablecoin Supply Snapshot** `fin_crypto(endpoint="defi/stablecoins")` — Total supply + per-coin breakdown
|
|
54
|
-
- Key fields: total mcap, USDT mcap, USDC mcap, DAI mcap, chain distribution per coin
|
|
55
|
-
- ⚠️ If total stablecoin mcap < previous known value -> capital outflow signal, check severity
|
|
56
|
-
- 💡 USDT growth = primarily Asian retail/OTC inflow; USDC growth = institutional/DeFi allocation
|
|
57
|
-
|
|
58
|
-
2. **Total Market Context** `fin_crypto(endpoint="coin/global_stats")` — Crypto total market cap + BTC dominance
|
|
59
|
-
- Calculate: stablecoin_ratio = total_stablecoin_mcap / total_crypto_mcap
|
|
60
|
-
- ⚠️ Ratio rising (e.g., 9% -> 12%) = capital retreating to sidelines (defensive)
|
|
61
|
-
- ⚠️ Ratio falling (e.g., 12% -> 9%) = capital deploying into risk assets (offensive)
|
|
62
|
-
|
|
63
|
-
3. **Chain Distribution Analysis** `fin_crypto(endpoint="defi/stablecoins")` — Per-chain stablecoin breakdown
|
|
64
|
-
- Ethereum = institutional DeFi + lending protocols
|
|
65
|
-
- Tron = Asian OTC + cross-border remittance + retail
|
|
66
|
-
- BSC = retail DeFi + gaming
|
|
67
|
-
- Arbitrum/Base = L2 DeFi migration
|
|
68
|
-
- ⚠️ If Tron USDT growing fastest -> Asian retail surge (historically bullish for BTC in 2-4 weeks)
|
|
69
|
-
|
|
70
|
-
4. **Capital Flow Verdict** — Synthesize all signals
|
|
71
|
-
- Strong inflow: 4w total increase > $2B + ratio declining + Tron USDT growing
|
|
72
|
-
- Neutral: 4w change < $1B absolute, ratio stable
|
|
73
|
-
- Outflow warning: 4w decrease > $1B + ratio rising + BTC price declining
|
|
74
|
-
|
|
75
|
-
## Leading Indicator Framework
|
|
76
|
-
|
|
77
|
-
### 4-Week Rolling Change Thresholds
|
|
78
|
-
|
|
79
|
-
| 4-Week Change | Signal | Historical BTC 30d Avg | Action |
|
|
80
|
-
| ------------- | ---------------- | ---------------------- | ----------------------------- |
|
|
81
|
-
| > +$3B | Strong inflow | +15% | Bullish positioning warranted |
|
|
82
|
-
| +$1B to +$3B | Moderate inflow | +8% | Cautiously optimistic |
|
|
83
|
-
| -$1B to +$1B | Neutral | +2% | No directional signal |
|
|
84
|
-
| -$3B to -$1B | Moderate outflow | -5% | Reduce leverage, raise cash |
|
|
85
|
-
| < -$3B | Capital flight | -12% | Defensive mode, max caution |
|
|
86
|
-
|
|
87
|
-
## Response Guidelines
|
|
88
|
-
|
|
89
|
-
### Number Formats
|
|
90
|
-
|
|
91
|
-
- Stablecoin market cap: $168.2B (use $B for billions, $M for millions)
|
|
92
|
-
- Supply changes: +$1.8B / -$500M (always show +/- sign)
|
|
93
|
-
- Ratios: 9.8% (1 decimal place)
|
|
94
|
-
- BTC price: to nearest dollar ($67,432)
|
|
95
|
-
- Chain distribution: percentages with 1 decimal (Ethereum 45.2%, Tron 31.8%)
|
|
96
|
-
|
|
97
|
-
### Must Include
|
|
98
|
-
|
|
99
|
-
- Data timestamp ("Data as of YYYY-MM-DD")
|
|
100
|
-
- Top 3 stablecoins by market cap with individual figures
|
|
101
|
-
- Stablecoin/total crypto market cap ratio
|
|
102
|
-
- Chain distribution for at least top 3 chains
|
|
103
|
-
- Always end with a directional verdict: bullish / neutral / bearish with confidence level
|