@dshtrading/kit-global 0.4.0
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/LICENSE +75 -0
- package/assets/skills/global-risk-checklist.md +45 -0
- package/assets/skills/indicator-authoring.md +230 -0
- package/assets/skills/knowledge-curation.md +100 -0
- package/assets/skills/trading-notes-setup.md +91 -0
- package/assets/skills/trading-strategy-paradigms.md +65 -0
- package/lib/index.d.ts +19 -0
- package/lib/index.js +139 -0
- package/package.json +37 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
Copyright (c) 2026 zhu1090093659 (dsh-trading)
|
|
2
|
+
|
|
3
|
+
# PolyForm Noncommercial License 1.0.0
|
|
4
|
+
|
|
5
|
+
<https://polyformproject.org/licenses/noncommercial/1.0.0>
|
|
6
|
+
|
|
7
|
+
## Acceptance
|
|
8
|
+
|
|
9
|
+
In order to get any license under these terms, you must agree to them as both strict obligations and conditions to all your licenses.
|
|
10
|
+
|
|
11
|
+
## Copyright License
|
|
12
|
+
|
|
13
|
+
The licensor grants you a copyright license for the software to do everything you might do with the software that would otherwise infringe the licensor's copyright in it for any permitted purpose. However, you may only distribute the software according to [Distribution License](#distribution-license) and make changes or new works based on the software according to [Changes and New Works License](#changes-and-new-works-license).
|
|
14
|
+
|
|
15
|
+
## Distribution License
|
|
16
|
+
|
|
17
|
+
The licensor grants you an additional copyright license to distribute copies of the software. Your license to distribute covers distributing the software with changes and new works permitted by [Changes and New Works License](#changes-and-new-works-license).
|
|
18
|
+
|
|
19
|
+
## Notices
|
|
20
|
+
|
|
21
|
+
You must ensure that anyone who gets a copy of any part of the software from you also gets a copy of these terms or the URL for them above, as well as copies of any plain-text lines beginning with `Required Notice:` that the licensor provided with the software. For example:
|
|
22
|
+
|
|
23
|
+
> Required Notice: Copyright Yoyodyne, Inc. (http://example.com)
|
|
24
|
+
|
|
25
|
+
## Changes and New Works License
|
|
26
|
+
|
|
27
|
+
The licensor grants you an additional copyright license to make changes and new works based on the software for any permitted purpose.
|
|
28
|
+
|
|
29
|
+
## Patent License
|
|
30
|
+
|
|
31
|
+
The licensor grants you a patent license for the software that covers patent claims the licensor can license, or becomes able to license, that you would infringe by using the software.
|
|
32
|
+
|
|
33
|
+
## Noncommercial Purposes
|
|
34
|
+
|
|
35
|
+
Any noncommercial purpose is a permitted purpose.
|
|
36
|
+
|
|
37
|
+
## Personal Uses
|
|
38
|
+
|
|
39
|
+
Personal use for research, experiment, and testing for the benefit of public knowledge, personal study, private entertainment, hobby projects, amateur pursuits, or religious observance, without any anticipated commercial application, is use for a permitted purpose.
|
|
40
|
+
|
|
41
|
+
## Noncommercial Organizations
|
|
42
|
+
|
|
43
|
+
Use by any charitable organization, educational institution, public research organization, public safety or health organization, environmental protection organization, or government institution is use for a permitted purpose regardless of the source of funding or obligations resulting from the funding.
|
|
44
|
+
|
|
45
|
+
## Fair Use
|
|
46
|
+
|
|
47
|
+
You may have "fair use" rights for the software under the law. These terms do not limit them.
|
|
48
|
+
|
|
49
|
+
## No Other Rights
|
|
50
|
+
|
|
51
|
+
These terms do not allow you to sublicense or transfer any of your licenses to anyone else, or prevent the licensor from granting licenses to anyone else. These terms do not imply any other licenses.
|
|
52
|
+
|
|
53
|
+
## Patent Defense
|
|
54
|
+
|
|
55
|
+
If you make any written claim that the software infringes or contributes to infringement of any patent, your patent license for the software granted under these terms ends immediately. If your company makes such a claim, your patent license ends immediately for work on behalf of your company.
|
|
56
|
+
|
|
57
|
+
## Violations
|
|
58
|
+
|
|
59
|
+
The first time you are notified in writing that you have violated any of these terms, or done anything with the software not covered by your licenses, your licenses can nonetheless continue if you come into full compliance with these terms, and take practical steps to correct past violations, within 32 days of receiving notice. Otherwise, all your licenses end immediately.
|
|
60
|
+
|
|
61
|
+
## No Liability
|
|
62
|
+
|
|
63
|
+
***As far as the law allows, the software comes as is, without any warranty or condition, and the licensor will not be liable to you for any damages arising out of these terms or the use or nature of the software, under any kind of legal claim.***
|
|
64
|
+
|
|
65
|
+
## Definitions
|
|
66
|
+
|
|
67
|
+
The **licensor** is the individual or entity offering these terms, and the **software** is the software the licensor makes available under these terms.
|
|
68
|
+
|
|
69
|
+
**You** refers to the individual or entity agreeing to these terms.
|
|
70
|
+
|
|
71
|
+
**Your company** is any legal entity, sole proprietorship, or other kind of organization that you work for, plus all organizations that have control over, are under the control of, or are under common control with that organization. **Control** means ownership of substantially all the assets of an entity, or the power to direct its management and policies by vote, contract, or otherwise. Control can be direct or indirect.
|
|
72
|
+
|
|
73
|
+
**Your licenses** are all the licenses granted to you for the software under these terms.
|
|
74
|
+
|
|
75
|
+
**Use** means anything you do with the software requiring one of your licenses.
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# 全球品种交易风控检查清单(global-risk-checklist)
|
|
2
|
+
|
|
3
|
+
适用范围:全球市场品种——现货贵金属(XAUUSD 等)、能源(WTI/USOIL)、外汇主流货币对、
|
|
4
|
+
全球股指(SPX 等)。开仓前逐项核对;任何一项不通过即不入场,并将未通过项写入交易计划的
|
|
5
|
+
风险栏。数据来源约定:行情与品种名册以金十连接器(global_quote / global_klines /
|
|
6
|
+
global_instruments,GUI 经 tradingGlobalMarketData 路由)返回为准;本清单不构成投资建议。
|
|
7
|
+
|
|
8
|
+
**依据闸门(先过)**:每条开仓理由必须能指回锚点(工具名 + 参数 + 数值 + 数据时间 / 公告或章节 / facts 条目 / 知识卡 id + updatedAt)。只有 C/D/E 级来源、或写不出锚点的理由,按证据不足处理(insufficient),不得作为入场依据。
|
|
9
|
+
|
|
10
|
+
## 1. 杠杆与保证金(仅适用于杠杆账户)
|
|
11
|
+
|
|
12
|
+
- [ ] 现货金/原油/外汇在券商侧通常是保证金交易:先确认自己账户的实际杠杆倍数与保证金要求,按「价格 x 合约规模 x 保证金率」算出单笔占用。
|
|
13
|
+
- [ ] 单品种占用保证金不超过账户权益的 20%;全组合合计不超过 50%。
|
|
14
|
+
- [ ] 名义杠杆写明倍数;10 倍以上必须给强制减仓触发线。
|
|
15
|
+
- [ ] 浮亏按名义价值放大:写明价格反向波动 1% / 3% / 5% 时对应的亏损金额。
|
|
16
|
+
|
|
17
|
+
## 2. 强平与隔夜利息
|
|
18
|
+
|
|
19
|
+
- [ ] 用当前保证金率倒算强平价并写进计划;杠杆头寸隔夜是常态风险,不是例外。
|
|
20
|
+
- [ ] 外汇与贵金属杠杆头寸有隔夜利息(swap/展期成本):持仓跨日先确认多空方向的费率,长周期持仓把累计展期成本计入盈亏平衡点。
|
|
21
|
+
- [ ] 账户风险度(占用保证金/权益)超过 70% 停止加仓,超过 80% 主动减仓,不等强平。
|
|
22
|
+
|
|
23
|
+
## 3. 交易时段与跳空
|
|
24
|
+
|
|
25
|
+
- [ ] 全球品种近似连续交易(周一 06:00 — 周六 05:00,北京时间),但流动性分亚/欧/美三盘:美盘活跃、亚盘早期与两盘交界点差明显放大,市价单按盘口价差折算滑点后再评估。
|
|
26
|
+
- [ ] 每日收盘休市段(北京时间 05:00-06:00)前后流动性枯竭:避免临休市挂新仓。
|
|
27
|
+
- [ ] 周末与节假日休市是跳空高发窗口:周一开盘跳空穿越止损单是常态,按跳空 2% 压力测试最大亏损;重大地缘/数据事件前(如非农、FOMC、OPEC 会议)评估是否减仓过周末。
|
|
28
|
+
|
|
29
|
+
## 4. 事件与数据驱动波动
|
|
30
|
+
|
|
31
|
+
- [ ] 金十财经日历(econ_calendar)核对持仓期内的重大数据发布:非农、CPI、FOMC、GDP 等发布瞬间点差急剧放大且滑点失控,数据行情前不新开市价单。
|
|
32
|
+
- [ ] 原油核对 OPEC+ 会议、EIA 库存时点;贵金属核对实际利率与美元指数联动;黄金与美元/实际利率强负相关,不要用单一品种观点对冲另一品种的美元敞口。
|
|
33
|
+
- [ ] 相关性 ≠ 同一性:做多黄金同时对冲美元空头,要写明相关性假设与失效条件(相关系数漂移即失效)。
|
|
34
|
+
|
|
35
|
+
## 5. 美元计价与汇率
|
|
36
|
+
|
|
37
|
+
- [ ] 全球品种报价以美元计价(client 台账 global → USD):非美元账户核对折算汇率与换汇成本,台账基准币切换(USD/CNY/HKD)不改变品种本身盈亏。
|
|
38
|
+
- [ ] 以 CNY/HKD 思考盈亏时,叠加人民币/港币对美元波动:品种盈利可能被汇率回吐,反之亦然。
|
|
39
|
+
|
|
40
|
+
## 6. 品种与数据面核对(连接器能力边界)
|
|
41
|
+
|
|
42
|
+
- [ ] 金十源只有分钟 K 线且单窗口 100 根(本仓最多拼 300 分钟):GUI 只上 1m/5m/15m,日线及以上显式报错——长周期结构与历史回测需另行取数,不得用分钟数据冒充日线。
|
|
43
|
+
- [ ] 闭市返回空 K 线序列是真实语义(≠ 故障):周末/节假日取数为空不作为「数据源坏了」重试。
|
|
44
|
+
- [ ] 现货价 ≠ 期货价:XAUUSD 是现货金,与 COMEX 期金存在基差;USOIL 是 WTI,与布伦特价差独立存在,跨市场套利先核对合约口径。
|
|
45
|
+
- [ ] 本市场为纯数据面(无下单/账户工具):任何真实交易走券商侧人工流程,agent 输出仅作计划与提醒,dry-run 语义。
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
# 指标创作指南(Indicator Authoring Guide)
|
|
2
|
+
|
|
3
|
+
当用户在会话列中用自然语言提出编写或添加技术指标的需求时(例如:"帮我写一个 TD9 指标"、"帮我写一个 SuperTrend 指标"、"给 OBV 加一个 34 天均线"),请遵循本指南生成符合 `@dshtrading/indicators` 契约规范的 JavaScript 纯函数代码,并调用 `indicator_author` 工具进行沙箱校验与落库。
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 1. 核心契约与计算模型
|
|
8
|
+
|
|
9
|
+
技术指标是纯数据与纯函数的契约对象:
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
export interface IndicatorDefinition {
|
|
13
|
+
id: string // 唯一 ID,如 "td9"、"supertrend"、"custom_rsi"(小写字母数字下划线,2-32 字符)
|
|
14
|
+
title: string // 显示名称,如 "TD9"、"SuperTrend"(1-32 字符)
|
|
15
|
+
pane: 'main' | 'sub' // 归属:"main" 主图叠加 或 "sub" 独立副图
|
|
16
|
+
params: IndicatorParamSpec[] // 参数列表配置(0-8 个)
|
|
17
|
+
compute(bars: readonly Kline[], params: Record<string, number>): IndicatorOutput[]
|
|
18
|
+
}
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### 输入 `bars`(K 线数组)
|
|
22
|
+
每根 K 线包含:
|
|
23
|
+
- `openTime`: number(毫秒时间戳)
|
|
24
|
+
- `open`: number(开盘价)
|
|
25
|
+
- `high`: number(最高价)
|
|
26
|
+
- `low`: number(最低价)
|
|
27
|
+
- `close`: number(收盘价)
|
|
28
|
+
- `volume`: number(成交量)
|
|
29
|
+
|
|
30
|
+
### 输出 `IndicatorOutput[]`(序列数组)
|
|
31
|
+
每个输出序列包含:
|
|
32
|
+
- `key`: string(系列名称,如 `'TD_BUY'`、`'SUPERTREND'`、`'OBV_MA'`)
|
|
33
|
+
- `kind`: `'line'` | `'histogram'`
|
|
34
|
+
- `color`: string(如 `'#e64545'`(涨红)、`'#2ba471'`(跌绿)、`'#3b82f6'`(蓝)、`'#e6a23c'`(橙))
|
|
35
|
+
- `values`: `Array<number | undefined>`
|
|
36
|
+
- `histogramBySign`?: boolean(柱状图专用:为 true 时正值着红、负值着绿)
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## 2. 编写黄金铁律(必须遵守)
|
|
41
|
+
|
|
42
|
+
1. **长度严格对齐**:`output.values.length` **必须严格等于** `bars.length`!
|
|
43
|
+
2. **warm-up 必须用 `undefined`**:历史数据不足以计算的前 N 根 K 线,对应位置的值必须填 `undefined`,图表引擎会自动将其作为未准备就绪点跳过渲染。
|
|
44
|
+
3. **数值必须有限(Finite)**:严禁在 `values` 中出现 `NaN`、`Infinity`、`null` 或字符串。除法操作必须做防除零保护(如 `denominator === 0 ? 0 : numerator / denominator`)。
|
|
45
|
+
4. **纯函数与零副作用**:`compute` 必须是无状态的纯函数,不得访问 `window`、`document` 或外部全局可变状态。
|
|
46
|
+
5. **红涨绿跌 Token 约定**:中国市场规范下,多头/上涨/买点使用红色系(如 `#e64545`),空头/下跌/卖点使用绿色系(如 `#2ba471`)。
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
## 3. 三大富途牛牛同款生产级范例
|
|
51
|
+
|
|
52
|
+
### 范例一:TD9(汤姆·狄马克九转序列,主图叠加)
|
|
53
|
+
|
|
54
|
+
连续 9 根收盘价低于 4 根前收盘价触发买入九转(看多转折),连续 9 根高于 4 根前触发卖出九转。
|
|
55
|
+
|
|
56
|
+
```javascript
|
|
57
|
+
(bars) => {
|
|
58
|
+
const len = bars.length;
|
|
59
|
+
const buySetup = new Array(len).fill(undefined);
|
|
60
|
+
const sellSetup = new Array(len).fill(undefined);
|
|
61
|
+
let buyCount = 0;
|
|
62
|
+
let sellCount = 0;
|
|
63
|
+
|
|
64
|
+
for (let i = 0; i < len; i++) {
|
|
65
|
+
if (i < 4) continue;
|
|
66
|
+
const currentClose = bars[i].close;
|
|
67
|
+
const close4Ago = bars[i - 4].close;
|
|
68
|
+
|
|
69
|
+
if (currentClose < close4Ago) {
|
|
70
|
+
buyCount += 1;
|
|
71
|
+
sellCount = 0;
|
|
72
|
+
buySetup[i] = buyCount;
|
|
73
|
+
} else if (currentClose > close4Ago) {
|
|
74
|
+
sellCount += 1;
|
|
75
|
+
buyCount = 0;
|
|
76
|
+
sellSetup[i] = sellCount;
|
|
77
|
+
} else {
|
|
78
|
+
buyCount = 0;
|
|
79
|
+
sellCount = 0;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return [
|
|
84
|
+
{ key: 'TD_BUY', kind: 'line', color: '#2ba471', values: buySetup },
|
|
85
|
+
{ key: 'TD_SELL', kind: 'line', color: '#e64545', values: sellSetup },
|
|
86
|
+
];
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
---
|
|
91
|
+
|
|
92
|
+
### 范例二:SuperTrend(超级趋势指标,主图叠加)
|
|
93
|
+
|
|
94
|
+
基于 ATR 与倍数构建的动态趋势跟踪通道与止损线。
|
|
95
|
+
|
|
96
|
+
```javascript
|
|
97
|
+
(bars, params) => {
|
|
98
|
+
const period = Math.max(1, Math.round(params.period ?? 10));
|
|
99
|
+
const multiplier = Number(params.multiplier ?? 3);
|
|
100
|
+
const len = bars.length;
|
|
101
|
+
|
|
102
|
+
const upperBand = new Array(len).fill(undefined);
|
|
103
|
+
const lowerBand = new Array(len).fill(undefined);
|
|
104
|
+
const supertrend = new Array(len).fill(undefined);
|
|
105
|
+
|
|
106
|
+
// 1. 计算 True Range
|
|
107
|
+
const tr = new Array(len);
|
|
108
|
+
tr[0] = bars[0].high - bars[0].low;
|
|
109
|
+
for (let i = 1; i < len; i++) {
|
|
110
|
+
const hl = bars[i].high - bars[i].low;
|
|
111
|
+
const hc = Math.abs(bars[i].high - bars[i - 1].close);
|
|
112
|
+
const lc = Math.abs(bars[i].low - bars[i - 1].close);
|
|
113
|
+
tr[i] = Math.max(hl, hc, lc);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// 2. 计算 ATR 与 SuperTrend 轨迹
|
|
117
|
+
let atrSum = 0;
|
|
118
|
+
let trend = 1;
|
|
119
|
+
|
|
120
|
+
for (let i = 0; i < len; i++) {
|
|
121
|
+
atrSum += tr[i];
|
|
122
|
+
if (i >= period) atrSum -= tr[i - period];
|
|
123
|
+
|
|
124
|
+
if (i < period - 1) continue;
|
|
125
|
+
|
|
126
|
+
const currentAtr = atrSum / period;
|
|
127
|
+
const hl2 = (bars[i].high + bars[i].low) / 2;
|
|
128
|
+
let basicUpper = hl2 + multiplier * currentAtr;
|
|
129
|
+
let basicLower = hl2 - multiplier * currentAtr;
|
|
130
|
+
|
|
131
|
+
if (i > 0 && lowerBand[i - 1] !== undefined) {
|
|
132
|
+
if (basicLower < lowerBand[i - 1] && bars[i - 1].close > lowerBand[i - 1]) {
|
|
133
|
+
basicLower = lowerBand[i - 1];
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
if (i > 0 && upperBand[i - 1] !== undefined) {
|
|
137
|
+
if (basicUpper > upperBand[i - 1] && bars[i - 1].close < upperBand[i - 1]) {
|
|
138
|
+
basicUpper = upperBand[i - 1];
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
lowerBand[i] = basicLower;
|
|
143
|
+
upperBand[i] = basicUpper;
|
|
144
|
+
|
|
145
|
+
if (i > 0 && supertrend[i - 1] !== undefined) {
|
|
146
|
+
if (trend === 1 && bars[i].close < lowerBand[i]) {
|
|
147
|
+
trend = -1;
|
|
148
|
+
} else if (trend === -1 && bars[i].close > upperBand[i]) {
|
|
149
|
+
trend = 1;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
supertrend[i] = trend === 1 ? lowerBand[i] : upperBand[i];
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
return [
|
|
157
|
+
{ key: 'SUPERTREND', kind: 'line', color: '#3b82f6', values: supertrend }
|
|
158
|
+
];
|
|
159
|
+
}
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
---
|
|
163
|
+
|
|
164
|
+
### 范例三:OBV + MA34(能量潮 + 34 天均线,副图指标)
|
|
165
|
+
|
|
166
|
+
量价配合指标,结合累积成交量与平滑均线研判多空力量。
|
|
167
|
+
|
|
168
|
+
```javascript
|
|
169
|
+
(bars, params) => {
|
|
170
|
+
const maPeriod = Math.max(1, Math.round(params.period ?? 34));
|
|
171
|
+
const len = bars.length;
|
|
172
|
+
const obv = new Array(len);
|
|
173
|
+
const obvMa = new Array(len).fill(undefined);
|
|
174
|
+
|
|
175
|
+
obv[0] = 0;
|
|
176
|
+
for (let i = 1; i < len; i++) {
|
|
177
|
+
if (bars[i].close > bars[i - 1].close) {
|
|
178
|
+
obv[i] = obv[i - 1] + bars[i].volume;
|
|
179
|
+
} else if (bars[i].close < bars[i - 1].close) {
|
|
180
|
+
obv[i] = obv[i - 1] - bars[i].volume;
|
|
181
|
+
} else {
|
|
182
|
+
obv[i] = obv[i - 1];
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
let sum = 0;
|
|
187
|
+
for (let i = 0; i < len; i++) {
|
|
188
|
+
sum += obv[i];
|
|
189
|
+
if (i >= maPeriod) sum -= obv[i - maPeriod];
|
|
190
|
+
if (i >= maPeriod - 1) {
|
|
191
|
+
obvMa[i] = sum / maPeriod;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
return [
|
|
196
|
+
{ key: 'OBV', kind: 'line', color: '#e6a23c', values: obv },
|
|
197
|
+
{ key: 'OBV_MA', kind: 'line', color: '#409eff', values: obvMa },
|
|
198
|
+
];
|
|
199
|
+
}
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
---
|
|
203
|
+
|
|
204
|
+
## 4. 工具调用范式
|
|
205
|
+
|
|
206
|
+
生成代码后,直接调用 `indicator_author` 工具:
|
|
207
|
+
|
|
208
|
+
```json
|
|
209
|
+
{
|
|
210
|
+
"id": "td9",
|
|
211
|
+
"title": "TD9",
|
|
212
|
+
"pane": "main",
|
|
213
|
+
"computeSource": "(bars) => { ... }",
|
|
214
|
+
"description": "汤姆狄马克九转序列指标"
|
|
215
|
+
}
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
若工具返回 `Validation failed`,请根据返回的具体报错信息调整代码(如修复长度不对齐、NaN 防护等)后重新尝试,直至落库成功。
|
|
219
|
+
|
|
220
|
+
### 4.1 创作即上图(可选一步到位)
|
|
221
|
+
|
|
222
|
+
`indicator_author` 支持可选参数 `activate`(布尔,默认 false):置 true 时指标通过校验落库后会立即按 schema 默认参数挂上用户当前图表(GUI 经 SSE 即时点亮),无需再调 `indicator_activate`。适合「帮我写个 XXX 并加到图上」这类一句话需求;仅落库不上图的需求保持缺省。
|
|
223
|
+
|
|
224
|
+
### 4.2 图表挂载管理(indicator_list / indicator_activate / indicator_deactivate)
|
|
225
|
+
|
|
226
|
+
- `indicator_list`:枚举全部可用指标——预置与自定义(id/title/pane/参数 schema/描述)及当前激活名册(含生效参数)。创作前查重、挂载前选 id 与参数时先调它。
|
|
227
|
+
- `indicator_activate`:把指标挂上用户图表。`id` 必须是预置或已创作落库的自定义指标;可选 `paramsJson`(JSON 对象,如 `{"period":14}`)覆写参数默认值,越界自动收敛到 min/max,缺失键取默认值。重复挂载同 id 即更新参数(每 id 至多一个实例)。
|
|
228
|
+
- `indicator_deactivate`:从图上摘除一个实例(定义仍在指标库);彻底删除自定义指标定义用 `indicator_delete`。
|
|
229
|
+
|
|
230
|
+
典型链路:`indicator_list` 查重 → `indicator_author`(或带 `activate: true` 一步上图)→ 需要调参时 `indicator_activate` + `paramsJson` → `indicator_deactivate` 摘除。
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: knowledge-curation
|
|
3
|
+
description: 财经观点沉淀与知识库策展指南:基于 Content Insight 事实核查产物,规范化提取知识卡片字段、受控词表对齐、查重与关联建立,通过 knowledge_ingest 工具入库。
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# 财经观点沉淀与知识库策展指南(knowledge-curation)
|
|
7
|
+
|
|
8
|
+
本技能指导 Agent 将经过事实核查的财经视频(B站)或深度文章(微信公众号)观点,转化为结构化知识卡片并录入本地个人知识库,以力导图谱形式沉淀为可复用的交易研究资产。
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## 1. 目标与范围
|
|
13
|
+
|
|
14
|
+
### 什么时候执行入库
|
|
15
|
+
- **显式触发**:用户在对话中明确要求「沉淀/入库/收藏/记录到知识库/保存这张卡片」;
|
|
16
|
+
- **主动建议**:当 Agent 运用 `content-insight` 技能完成了一次高质量的视频或文章深度分析并产出事实核查报告后,在回答末尾主动向用户建议:「是否需要将本篇核心观点与核查结论沉淀到知识库?」。用户确认后即可调用工具入库。
|
|
17
|
+
|
|
18
|
+
### 什么时候不入库
|
|
19
|
+
- 用户仅询问「这个视频讲了什么」或「帮我快速总结一下」,未表达沉淀意向;
|
|
20
|
+
- 素材属于纯情绪宣泄、无实质逻辑链条或事实核查评级为不可信(无有效干货)。
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## 2. 前置依赖(严格核查原则)
|
|
25
|
+
|
|
26
|
+
**无核查,不入库**:
|
|
27
|
+
- 严禁未经 `content-insight` 事实核查直接录入原始观点;
|
|
28
|
+
- 卡片的 `credibility`(内容可信度)评级必须严格基于事实核查三桶(✅ 证实 / ⚠️ 有出入 / ❓ 无法核实)的综合结论定级:
|
|
29
|
+
- `high`:核心事实与数据均有权威源证实,推理链条严密;
|
|
30
|
+
- `medium`:核心逻辑有参考价值,但部分数据存在滞后或口误出入;
|
|
31
|
+
- `low`:存在重大关键事实失准或关键数据无法核实。
|
|
32
|
+
|
|
33
|
+
> **分层说明(勿混用)**:卡片 `factCheck` 三桶是**素材级**核查记录(这条声称被核实到什么程度);结论级证据契约的 `supported` / `contradicted` / `mixed` / `insufficient` 四态是**结论级**判定(这条结论能否成立)。卡片字段不因四态改名;引用卡片时按证据契约归入 C/D 级线索,不得单独支撑 `supported` 结论。
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
## 3. 标准策展 SOP
|
|
38
|
+
|
|
39
|
+
### 第一步:提取卡片结构化字段
|
|
40
|
+
根据 `content-insight` 产出的分析报告,提炼以下标准字段:
|
|
41
|
+
- `title`:卡片主题(精炼概括核心逻辑,如「高股息资产在低利率环境下的防御逻辑」);
|
|
42
|
+
- `summary`:合并 2-4 条核心论点的一句话概述(图谱 hover 提示文案);
|
|
43
|
+
- `source`:`type`(bilibili / wechat / manual)、`url`、`author`、`publishedAt`;
|
|
44
|
+
- `credibility`:`high` / `medium` / `low`;
|
|
45
|
+
- `coreClaims`:核心论点列表(保留原作者的推理链条,避免断章取义);
|
|
46
|
+
- `factCheck`:`{ verified: [...], discrepancies: [...], unverifiable: [...] }`;
|
|
47
|
+
- `takeaways`:提炼出的可复用通用分析框架或方法论;
|
|
48
|
+
- `boundaries`:原作者论点的适用边界、失效情景与潜在陷阱;
|
|
49
|
+
- `tags`:受控主题标签列表(见下文标准词表);
|
|
50
|
+
- `tickers`:可选关联标的代码(市场规范词汇,如 `BTCUSDT`、`600519.SH`、`AAPL`)。
|
|
51
|
+
|
|
52
|
+
### 第二步:对齐受控主题词表(Controlled Vocabulary)
|
|
53
|
+
为确保力导图谱能够准确聚合主题簇,标签优先在受控词表中选取(单张卡片 2-4 个标签为宜):
|
|
54
|
+
- **宏观与政策**:`宏观`、`货币政策`、`财政政策`、`通胀`、`利率`、`流动性`
|
|
55
|
+
- **策略与风格**:`高股息`、`红利策略`、`成长股`、`价值投资`、`周期`、`动量`、`均值回归`
|
|
56
|
+
- **行业与赛道**:`半导体`、`消费`、`金融`、`大宗商品`、`新能源`、`加密资产`、`AI算力`
|
|
57
|
+
- **风控与心智**:`仓位管理`、`止损纪律`、`认知偏差`、`周期拐点`、`黑天鹅防范`
|
|
58
|
+
|
|
59
|
+
> *注:如需引入词表外的新标签,需向用户说明该标签的分类理由。*
|
|
60
|
+
|
|
61
|
+
### 第三步:查重与关联发现
|
|
62
|
+
1. 调用 `knowledge_search`:
|
|
63
|
+
- 先以 `sourceUrl` 或核心关键词检索,检查是否已有同源或同主题卡片;
|
|
64
|
+
- 查看检索到的已有卡片,寻找是否存在论点呼应、正反对比或同类经验的卡片 ID;
|
|
65
|
+
2. 构造 `related` 数组:将发现的有价值关联卡片 ID(如 `kc_01j...`)填入 `related` 字段,以在图谱中建立显式关联连线。
|
|
66
|
+
|
|
67
|
+
### 第四步:调用 `knowledge_ingest` 工具入库
|
|
68
|
+
将准备好的 JSON 参数传入 `knowledge_ingest` 工具执行入库。
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
## 4. 证伪下架与删除(Retraction SOP)
|
|
73
|
+
|
|
74
|
+
知识卡片既是研究资产也是负债:被证伪的观点留在库里,召回时会持续污染分析。当用户指出某张卡片的核心论点被事实证伪、来源撤稿或存在重大错误时,按下架流程处理:
|
|
75
|
+
|
|
76
|
+
1. **定位确认**:调 `knowledge_search`(按主题/标的/作者)或 `knowledge_get`(已有 id 时)取出候选卡片,向用户复述卡片标题与核心论点并确认下架对象——不凭模糊记忆直接删;
|
|
77
|
+
2. **执行删除**:调 `knowledge_delete`(带 `reason`,如「核心论点被 XX 数据证伪」「来源撤稿」);工具自动清理其他卡片指向本卡片的 `related` 引用,并在输出中回显被删卡片的论点留痕;
|
|
78
|
+
3. **沉淀元知识**:证伪结论本身是有价值的元知识——记入交易日志(agent 轨);若用户同意,可另立一张 `manual` 卡片记录「该观点为何被证伪」(credibility 按核查结论定级),防止同类观点再次误导;
|
|
79
|
+
4. **作者降权提示**:同一来源反复出现被证伪内容时,在回复中明确提示后续引用该作者的卡片需整体降权。
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
## 5. 输出契约
|
|
84
|
+
|
|
85
|
+
入库成功后,向用户输出清晰的入库汇报:
|
|
86
|
+
1. **入库状态**:新建成功 / 更新已有卡片;
|
|
87
|
+
2. **卡片信息**:卡片标题 + 卡片 ID(`kc_...`) + 主题标签 + 可信度评级;
|
|
88
|
+
3. **图谱关联**:明确列出与知识库中哪些既有卡片建立了关联(例如「已与《煤炭行业资本开支周期研判》建立关联」);
|
|
89
|
+
4. **浏览提示**:提示用户可在中栏「知识库」Tab 中查看力导图谱可视化。
|
|
90
|
+
|
|
91
|
+
下架成功后,向用户输出:已删除的卡片标题 + id + 删除原因 + 受影响(清理引用)的卡片清单,以及证伪结论的留痕去向(交易日志/新卡片)。
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
## 6. 风控与立场红线
|
|
96
|
+
|
|
97
|
+
1. **转述不等于背书**:入库内容是「原作者观点的结构化提炼与核查记录」,绝不代表平台或 Agent 对该投资观点的认同;
|
|
98
|
+
2. **免责提示**:知识库全部卡片均为研究辅助资料,**明示不构成任何投资建议**;
|
|
99
|
+
3. **杜绝自动爬取**:严禁未经用户交互授权后台自动批量抓取外部订阅源;
|
|
100
|
+
4. **铁律遵循**:严格遵守 dsh-trading 铁律(知识沉淀不包含私钥/凭据,不直接触发任何实盘交易)。
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: trading-notes-setup
|
|
3
|
+
description: 交易日志(trading journal)建立与记录规范:检查/创建工作区 `.trading-journal/` 双轨目录(agent 轨 + human 轨),分别记录 agent 与人类各自的操作(做了什么)。会话启动检查发现工作区没有交易日志目录时调用本技能建立骨架;用户要求建立或查看交易日志时调用;记录条目格式以本技能为权威来源。
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# 交易日志建立与记录规范(trading-notes-setup)
|
|
7
|
+
|
|
8
|
+
## 1. 目标与适用范围(Goal & Scope)
|
|
9
|
+
|
|
10
|
+
- **适用**:任何交易工作区的操作留痕——agent 做了什么、人做了什么,各自一轨、append-only、按月滚动,事后可追溯谁在什么时候动了什么。
|
|
11
|
+
- **非适用**:行情快照、持仓明细等易过期数据(那是工具输出,不进日志);决策的 why 与放弃了什么(归工作区已有的决策记录体系,如 Agent Note——日志只记"做了什么",不与决策记录重复)。
|
|
12
|
+
|
|
13
|
+
## 2. 首次建立:目录骨架(Setup SOP)
|
|
14
|
+
|
|
15
|
+
会话启动检查或用户要求时,先确认当前工作目录下 `.trading-journal/` 是否存在:
|
|
16
|
+
|
|
17
|
+
- **不存在**:先向用户说明本工作区尚未建立交易日志、拟创建的结构,征得同意后创建以下骨架(目录已存在对应文件时跳过,绝不覆盖已有内容):
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
.trading-journal/
|
|
21
|
+
├── AGENTS.md # agent 守则:知识召回先行 + 日志纪律指针(内容模板见下)
|
|
22
|
+
├── README.md # 本工作区日志规则速览(谁写哪轨、格式、归档,人可读)
|
|
23
|
+
├── agent/
|
|
24
|
+
│ └── YYYY-MM.md # agent 操作轨(当月流水,agent 写)
|
|
25
|
+
├── human/
|
|
26
|
+
│ └── YYYY-MM.md # 人类操作轨(当月流水,agent 代记或用户手写)
|
|
27
|
+
└── archive/ # 归档区(旧月文件移入,封存不改)
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
建成后向用户报告路径与轨语义,并把本次会话的首条记录写入(见 §4)。
|
|
31
|
+
|
|
32
|
+
**`AGENTS.md` 内容模板**(原样写入;已有该文件时跳过,绝不覆盖):
|
|
33
|
+
|
|
34
|
+
```markdown
|
|
35
|
+
# 交易工作区 Agent 守则
|
|
36
|
+
|
|
37
|
+
本文件随交易日志骨架创建,对在本工作区工作的 agent 生效。
|
|
38
|
+
|
|
39
|
+
## 知识召回先行(分析工作流必经)
|
|
40
|
+
|
|
41
|
+
- 对任何标的、行业或宏观主题做正式分析前,先调 `knowledge_search` 检索本地知识库
|
|
42
|
+
(按标的代码、行业与主题标签),命中的知识卡片作为线索证据纳入分析,并标注卡片
|
|
43
|
+
id 便于溯源;没命中也如实说明"知识库无相关沉淀";
|
|
44
|
+
- 卡片是"别人观点的结构化转述":转述≠背书,只作线索证据,不得替代原始披露与权威
|
|
45
|
+
数据;对外明示不构成投资建议;
|
|
46
|
+
- 注意卡片 `updatedAt` 与素材发布时间:宏观/政策类观点过期即降权,不得当作当前
|
|
47
|
+
事实引用;
|
|
48
|
+
- 分析中形成新的可复用结论时,按 knowledge-curation skill 建议用户沉淀入库
|
|
49
|
+
(先 `knowledge_search` 查重,再 `knowledge_ingest`)。
|
|
50
|
+
|
|
51
|
+
## 日志纪律
|
|
52
|
+
|
|
53
|
+
- 双轨语义、条目格式与归档规则以 trading-notes-setup skill 为权威来源;
|
|
54
|
+
- 本目录内一切写入遵守 append-only:只追加当月流水,不改历史条目,归档后封存。
|
|
55
|
+
```
|
|
56
|
+
- **已存在**:不重建;向用户简报现状(已有月份文件数、最近一条记录日期),转 §4 日常纪律。
|
|
57
|
+
|
|
58
|
+
## 3. 双轨语义与取舍(What to Record)
|
|
59
|
+
|
|
60
|
+
| 轨 | 写什么 | 谁来写 |
|
|
61
|
+
|---|---|---|
|
|
62
|
+
| `agent/` | agent 主动执行的操作:下单/撤单/改单(**含 dry-run,一律标注**)、风控清单拦截、设置或连接器变更、重要分析产出(交易计划/报告,引用标题+结论一句话,不贴全文) | agent |
|
|
63
|
+
| `human/` | 人的决定与手工操作:审批面放行/拒绝、liveTrading 开关变更、行情源/交易所切换、GUI 手动下单、用户明确交代的交易决策 | agent 得知时**代记**(条目尾注 `(代记)` 并注明来源:用户口述/审批面/GUI 观察);用户也可自己写 |
|
|
64
|
+
|
|
65
|
+
**不写**:每条 ticker/K 线查询(噪音)、密钥/账户号/API key 等敏感信息、整段对话粘贴。拿不准是否值得记时:改变状态的操作记,纯查询不记。
|
|
66
|
+
|
|
67
|
+
## 4. 条目格式契约(Output Format Contract)
|
|
68
|
+
|
|
69
|
+
月度文件 `YYYY-MM.md` 顶部一行说明轨语义,正文按日分节、时间升序追加:
|
|
70
|
+
|
|
71
|
+
```markdown
|
|
72
|
+
# agent 轨 · 2026-09(append-only;格式见 trading-notes-setup)
|
|
73
|
+
|
|
74
|
+
## 2026-09-02
|
|
75
|
+
|
|
76
|
+
- 14:32 crypto_place_order BTCUSDT limit 0.01 @ 60000(dry-run)→ 模拟成交
|
|
77
|
+
- 15:02 【实盘确认】OKX BTC-USDT-SWAP 开多 1 张 @ 市价
|
|
78
|
+
- 触发:用户在审批面明确放行(crypto-risk-checklist 已过)
|
|
79
|
+
- 结果:订单 OKX-xxx,成交均价 60,050(代记,来源:审批面)
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
- 普通操作:一行 bullet,`- HH:MM 做了什么(关键参数与结果)`。
|
|
83
|
+
- 重要操作(实盘单、闸门拦截、设置变更、用户重大决定):bullet 之下缩进 `- 触发:` / `- 结果:` 两行;结果必须落到具体数值或订单号,禁止模糊代词。
|
|
84
|
+
- 时间用本地时间 `HH:MM`;跨市场会话在条目里带市场词(如 `crypto`/`us`)。
|
|
85
|
+
|
|
86
|
+
## 5. 日常纪律与归档(Risk & Maintenance)
|
|
87
|
+
|
|
88
|
+
- 会话内出现值得记录的操作,**当场追加**到当月对应轨文件(不留到"最后一起写",会丢);月度文件不存在时按 `YYYY-MM.md` 新建。
|
|
89
|
+
- 月末跨月自然开新文件;跨年或用户要求时,把旧月文件原样移入 `archive/`,封存后不再修改。
|
|
90
|
+
- 工作区若是 git 仓库,建议把日志随常规变更提交(操作史有审计价值);是否提交由用户决定。
|
|
91
|
+
- 与审批闸门的关系:日志是**事后留痕**,不替代、不延迟任何 dry-run/审批闸门流程;先闸门后记账。
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: trading-strategy-paradigms
|
|
3
|
+
description: 经典交易策略参考范式指南:提供短线(唐奇安突破/RSI极值回归)、波段(EMA双均线/布林带下轨回归)、长线(200日均线基线/12月动量)6大策略原理、参数调优、8项回测指标研读与风险防范 SOP。
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# 交易策略参考范式与回测研读指南(Trading Strategy Paradigms & Backtest SOP)
|
|
7
|
+
|
|
8
|
+
当用户在会话中咨询交易策略构思、参数调优、历史表现验证或回测指标解读时,请遵循本 SOP 为用户提供客观、专业、带依据与风险边界的策略参考。
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## 1. 策略三分类与 6 大参考范式
|
|
13
|
+
|
|
14
|
+
系统内置三类共 6 个经典参考策略(纯函数计算、零外部随机依赖):
|
|
15
|
+
|
|
16
|
+
| 周期分类 | 策略 ID | 核心逻辑 | 适用行情 | 潜在风险与失效边界 |
|
|
17
|
+
| :--- | :--- | :--- | :--- | :--- |
|
|
18
|
+
| **短线** | `donchian-breakout` | 突破前 N1 根高点买入,跌破前 N2 根低点离场 | 单边爆发趋势市 | 震荡市频繁假突破追高止损 |
|
|
19
|
+
| **短线** | `rsi-reversion` | RSI(2) < 10 极端超卖抄底,> 60 反弹止盈 | 宽幅箱体震荡市 | 单边暴跌行情中越跌越买左侧接飞刀 |
|
|
20
|
+
| **波段** | `ema-crossover` | 快线 EMA20 金叉慢线 EMA60 做多,死叉平仓 | 中级波段趋势行情 | 窄幅盘整期间均线反复缠绕产生摩擦成本 |
|
|
21
|
+
| **波段** | `bollinger-reversion` | 跌破布林下轨做多,反弹至中轨(基准均线)止盈 | 均值回归与通道震荡 | 趋势加速破位时下轨失守 |
|
|
22
|
+
| **长线** | `sma-baseline` | 收盘站上 SMA200 牛市均线做多,跌破空仓避险 | 长期宏观周期牛熊切换 | 长期牛熊分界线附近频繁震荡穿越 |
|
|
23
|
+
| **长线** | `momentum-12m` | 过去 12 个月动量为正且站上年线做多,转负平仓 | 大周期强动量资产 | 拐点滞后,无法在最高点逃顶 |
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## 2. 8 项核心回测指标研读标准
|
|
28
|
+
|
|
29
|
+
在为用户分析策略回测报告时,必须结合以下 8 项标准指标进行立体研读,严禁单一吹捧累计收益率:
|
|
30
|
+
|
|
31
|
+
1. **累计收益率 (Total Return)**:回测全周期内账户总净值增长比例。
|
|
32
|
+
2. **复合年化收益率 (CAGR)**:几何平均年化回报,用于消除不同回测时长的时间偏差。
|
|
33
|
+
3. **最大回撤 (Max Drawdown)**:从历史最高净值点到最低点的最大下跌幅度。**核心风控指标**:评估策略在最坏情景下的心理承受极限。
|
|
34
|
+
4. **夏普比率 (Sharpe Ratio)**:超额收益与波动率的比值(年化),大于 1.0 为优良,大于 2.0 为极其优秀。
|
|
35
|
+
5. **胜率 (Win Rate)**:盈利交易笔数 / 总交易笔数。趋势跟踪策略胜率通常仅 35%~45%(靠大盈小亏),均值回归策略胜率通常 60%~75%(靠高频小赢)。
|
|
36
|
+
6. **盈亏比 (Profit Factor)**:总盈利金额 / 总亏损金额。健康策略应 $\ge 1.5$。
|
|
37
|
+
7. **交易总笔数 (Trade Count)**:样本量。若交易笔数 $< 10$ 笔,回测指标统计显著性不足,警惕幸存者偏差。
|
|
38
|
+
8. **市场暴露度 (Exposure)**:持仓时间占回测总周期的百分比。低暴露度(如 20%~40%)意味着大部分时间空仓观望,资金利用效率与避险能力强。
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## 3. 回测与实盘差异分析(反方情景)
|
|
43
|
+
|
|
44
|
+
引导用户理解回测与实盘交易之间的天然摩擦:
|
|
45
|
+
1. **滑点与流动性冲击**:回测默认使用次根 Bar 开盘价成交,实盘中大单可能造成显著冲击成本;
|
|
46
|
+
2. **幸存者偏差与过拟合**:针对特定历史 K 线反复调整参数得到的“完美曲线”在未来样本外往往迅速失效;
|
|
47
|
+
3. **持仓心理成本**:长达数月的回撤期在回测中仅是曲线的一段波谷,但在实盘中极易引发人为干预导致策略变形。
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
## 4. 建议沟通范式(五段论)
|
|
52
|
+
|
|
53
|
+
在与用户对话讨论策略时,采用五段论结构:
|
|
54
|
+
1. **策略定位与适用假设**:说明策略是属于趋势跟踪还是均值回归,适合哪种市场状态;
|
|
55
|
+
2. **参数设定与敏感度**:解释各参数的物理意义,避免极限参数过度拟合;
|
|
56
|
+
3. **历史表现与回测解读**:列出收益、回撤、胜率与盈亏比等关键数字;
|
|
57
|
+
4. **反方情景与极端风险**:指出若市场风格切换(如从单边转为剧烈震荡),该策略将如何亏损;
|
|
58
|
+
5. **风险提示与安全闸门**:明确提示实盘仍需人工审核与风险把控。
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
## 5. 铁律红线与免责声明
|
|
63
|
+
|
|
64
|
+
1. **实盘安全铁律**:策略层输出仅为数学信号与历史模拟分析,**严禁任何实盘自动化托管与私自下单循环**;任何交易必须通过 Base 统一审批闸门与显式人工确认。
|
|
65
|
+
2. **免责提示**:历史回测收益不代表未来实际收益,策略分析内容仅供参考,不构成任何实质性投资建议。
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import Schema from "@deepseek-ai/schemastery";
|
|
2
|
+
import { SkillProvider } from "@deepseek-ai/dsh-skill";
|
|
3
|
+
import { Context } from "@deepseek-ai/cordis";
|
|
4
|
+
//#region src/index.d.ts
|
|
5
|
+
declare const provider: SkillProvider;
|
|
6
|
+
interface Config {
|
|
7
|
+
dryRun: boolean;
|
|
8
|
+
liveTrading: boolean;
|
|
9
|
+
/** 角色预设按需收窄技能面;字段缺席保持全量捆绑目录,显式空数组才表示不下发任何技能。 */
|
|
10
|
+
skills?: string[] | null;
|
|
11
|
+
}
|
|
12
|
+
declare const Config: Schema<Config>;
|
|
13
|
+
declare const inject: string[];
|
|
14
|
+
declare const name = "dsh-trading-global-kit";
|
|
15
|
+
/** 白名单视图:未知名 fail-fast 不静默缩面;白名单外的 get 拒绝分发。 */
|
|
16
|
+
declare function providerForSkills(allowed?: readonly string[] | null): SkillProvider;
|
|
17
|
+
declare function apply(ctx: Context, config: Config): void;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { Config, apply, inject, name, provider, providerForSkills };
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
import Schema from "@deepseek-ai/schemastery";
|
|
4
|
+
import { BUNDLED_SKILL_RANK } from "@deepseek-ai/dsh-skill";
|
|
5
|
+
//#region src/index.ts
|
|
6
|
+
/**
|
|
7
|
+
* 全球品种工具箱插件(dsh-trading global 切片,market-group 平权)。
|
|
8
|
+
*
|
|
9
|
+
* 能力面:skill provider —— global-risk-checklist(现货贵金属/原油/外汇/全球指数的
|
|
10
|
+
* 杠杆与保证金、隔夜利息、休市跳空、数据行情波动、美元计价风控)加与其他市场 kit
|
|
11
|
+
* 同款的共享技能目录(indicator-authoring / trading-strategy-paradigms
|
|
12
|
+
* / knowledge-curation / trading-notes-setup):base 的 role-skill 白名单按
|
|
13
|
+
* `[<market>-risk-checklist, 共享技能…]` 生成,kit 少提供一项即 apply 期 fail-fast。
|
|
14
|
+
* 行情数据由 @dshtrading/connector-jin10 承载(tradingGlobalMarketData),
|
|
15
|
+
* 本插件不重复 provide。
|
|
16
|
+
*
|
|
17
|
+
* @module @dshtrading/kit-global
|
|
18
|
+
*/
|
|
19
|
+
const PROVIDER_NAME = "dsh-trading-global";
|
|
20
|
+
const SKILL_BODY_URL = new URL("../assets/skills/global-risk-checklist.md", import.meta.url);
|
|
21
|
+
const AUTHORING_BODY_URL = new URL("../assets/skills/indicator-authoring.md", import.meta.url);
|
|
22
|
+
const STRATEGY_BODY_URL = new URL("../assets/skills/trading-strategy-paradigms.md", import.meta.url);
|
|
23
|
+
const KNOWLEDGE_CURATION_BODY_URL = new URL("../assets/skills/knowledge-curation.md", import.meta.url);
|
|
24
|
+
const JOURNAL_BODY_URL = new URL("../assets/skills/trading-notes-setup.md", import.meta.url);
|
|
25
|
+
const RESOURCE_BASE = {
|
|
26
|
+
kind: "directory",
|
|
27
|
+
path: fileURLToPath(new URL("../assets/skills/", import.meta.url))
|
|
28
|
+
};
|
|
29
|
+
const RISK_CHECKLIST_CANDIDATE = {
|
|
30
|
+
name: "global-risk-checklist",
|
|
31
|
+
description: "全球品种交易风控检查清单:开仓前逐项核对杠杆与保证金、隔夜利息与强平、休市跳空(每日 05:00-06:00 与周末)、数据行情波动(非农/FOMC/OPEC)、美元计价与汇率回吐,覆盖现货贵金属/原油/外汇/全球指数。",
|
|
32
|
+
invocation: {
|
|
33
|
+
modelInvocable: true,
|
|
34
|
+
userInvocable: true
|
|
35
|
+
},
|
|
36
|
+
provider: PROVIDER_NAME,
|
|
37
|
+
source: "bundled",
|
|
38
|
+
resourceBase: RESOURCE_BASE,
|
|
39
|
+
rank: BUNDLED_SKILL_RANK,
|
|
40
|
+
locator: SKILL_BODY_URL
|
|
41
|
+
};
|
|
42
|
+
const SKILL_CANDIDATES = [
|
|
43
|
+
RISK_CHECKLIST_CANDIDATE,
|
|
44
|
+
{
|
|
45
|
+
name: "indicator-authoring",
|
|
46
|
+
description: "自定义技术指标创作指南:根据用户自然语言需求生成符合契约的指标代码(TD9/SuperTrend/OBV+MA等),并通过 indicator_author 工具验证与落库。",
|
|
47
|
+
invocation: {
|
|
48
|
+
modelInvocable: true,
|
|
49
|
+
userInvocable: true
|
|
50
|
+
},
|
|
51
|
+
provider: PROVIDER_NAME,
|
|
52
|
+
source: "bundled",
|
|
53
|
+
resourceBase: RESOURCE_BASE,
|
|
54
|
+
rank: BUNDLED_SKILL_RANK,
|
|
55
|
+
locator: AUTHORING_BODY_URL
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
name: "trading-strategy-paradigms",
|
|
59
|
+
description: "经典交易策略参考范式指南:提供短线(唐奇安突破/RSI极值回归)、波段(EMA双均线/布林带下轨回归)、长线(200日均线基线/12月动量)6大策略原理、参数调优、8项回测指标研读与风险防范 SOP。",
|
|
60
|
+
invocation: {
|
|
61
|
+
modelInvocable: true,
|
|
62
|
+
userInvocable: true
|
|
63
|
+
},
|
|
64
|
+
provider: PROVIDER_NAME,
|
|
65
|
+
source: "bundled",
|
|
66
|
+
resourceBase: RESOURCE_BASE,
|
|
67
|
+
rank: BUNDLED_SKILL_RANK,
|
|
68
|
+
locator: STRATEGY_BODY_URL
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
name: "knowledge-curation",
|
|
72
|
+
description: "财经观点沉淀与知识库策展指南:基于 Content Insight 事实核查产物,规范化提取知识卡片字段、受控词表对齐、查重与关联建立,通过 knowledge_ingest 工具入库。",
|
|
73
|
+
invocation: {
|
|
74
|
+
modelInvocable: true,
|
|
75
|
+
userInvocable: true
|
|
76
|
+
},
|
|
77
|
+
provider: PROVIDER_NAME,
|
|
78
|
+
source: "bundled",
|
|
79
|
+
resourceBase: RESOURCE_BASE,
|
|
80
|
+
rank: BUNDLED_SKILL_RANK,
|
|
81
|
+
locator: KNOWLEDGE_CURATION_BODY_URL
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
name: "trading-notes-setup",
|
|
85
|
+
description: "交易日志建立与记录规范:检查/创建工作区 .trading-journal/ 双轨目录(agent 轨 + human 轨),分别记录 agent 与人类各自的操作。会话启动检查发现工作区没有交易日志目录时调用本技能建立骨架;记录条目格式以本技能为权威。",
|
|
86
|
+
invocation: {
|
|
87
|
+
modelInvocable: true,
|
|
88
|
+
userInvocable: true
|
|
89
|
+
},
|
|
90
|
+
provider: PROVIDER_NAME,
|
|
91
|
+
source: "bundled",
|
|
92
|
+
resourceBase: RESOURCE_BASE,
|
|
93
|
+
rank: BUNDLED_SKILL_RANK,
|
|
94
|
+
locator: JOURNAL_BODY_URL
|
|
95
|
+
}
|
|
96
|
+
];
|
|
97
|
+
const provider = {
|
|
98
|
+
name: PROVIDER_NAME,
|
|
99
|
+
list: () => Promise.resolve(SKILL_CANDIDATES),
|
|
100
|
+
async get(candidate, _options) {
|
|
101
|
+
const target = SKILL_CANDIDATES.find((c) => c.name === candidate.name) ?? RISK_CHECKLIST_CANDIDATE;
|
|
102
|
+
return {
|
|
103
|
+
name: target.name,
|
|
104
|
+
description: target.description,
|
|
105
|
+
invocation: target.invocation,
|
|
106
|
+
provider: target.provider,
|
|
107
|
+
source: target.source,
|
|
108
|
+
resourceBase: RESOURCE_BASE,
|
|
109
|
+
content: await readFile(target.locator, "utf8")
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
const Config = Schema.object({
|
|
114
|
+
dryRun: Schema.boolean().default(true),
|
|
115
|
+
liveTrading: Schema.boolean().default(false),
|
|
116
|
+
skills: Schema.union([Schema.array(Schema.string()), Schema.const(null)]).default(null)
|
|
117
|
+
});
|
|
118
|
+
const inject = ["skills"];
|
|
119
|
+
const name = "dsh-trading-global-kit";
|
|
120
|
+
/** 白名单视图:未知名 fail-fast 不静默缩面;白名单外的 get 拒绝分发。 */
|
|
121
|
+
function providerForSkills(allowed) {
|
|
122
|
+
if (!allowed) return provider;
|
|
123
|
+
const unknown = allowed.filter((name) => !SKILL_CANDIDATES.some((c) => c.name === name));
|
|
124
|
+
if (unknown.length > 0) throw new Error(`[${PROVIDER_NAME}] unknown skills in whitelist: ${unknown.join(", ")}`);
|
|
125
|
+
const active = SKILL_CANDIDATES.filter((c) => allowed.includes(c.name));
|
|
126
|
+
return {
|
|
127
|
+
name: provider.name,
|
|
128
|
+
list: () => Promise.resolve(active),
|
|
129
|
+
async get(candidate, options) {
|
|
130
|
+
if (!active.some((c) => c.name === candidate.name)) throw new Error(`[${PROVIDER_NAME}] skill not in whitelist: ${candidate.name}`);
|
|
131
|
+
return provider.get(candidate, options);
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
function apply(ctx, config) {
|
|
136
|
+
ctx.skills.registerProvider(() => providerForSkills(config.skills));
|
|
137
|
+
}
|
|
138
|
+
//#endregion
|
|
139
|
+
export { Config, apply, inject, name, provider, providerForSkills };
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dshtrading/kit-global",
|
|
3
|
+
"description": "Global instruments toolkit plugin for dsh-trading: global risk checklist skill provider (leverage/swap/overnight-gap/event-driven-volatility/USD-denomination for spot metals, oil, FX and global indices); runs as a global-trader preset row (session-scoped)",
|
|
4
|
+
"version": "0.4.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "lib/index.js",
|
|
7
|
+
"types": "./lib/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./lib/index.d.ts",
|
|
11
|
+
"default": "./lib/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./package.json": "./package.json"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"lib",
|
|
17
|
+
"assets"
|
|
18
|
+
],
|
|
19
|
+
"license": "PolyForm-Noncommercial-1.0.0",
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@dshtrading/api": "0.4.0"
|
|
22
|
+
},
|
|
23
|
+
"peerDependencies": {
|
|
24
|
+
"@deepseek-ai/cordis": ">=4.0.0",
|
|
25
|
+
"@deepseek-ai/dsh-skill": ">=0.1.5-rc.1",
|
|
26
|
+
"@deepseek-ai/dsh-tools": ">=0.1.5-rc.1",
|
|
27
|
+
"@deepseek-ai/schemastery": ">=3.18.0"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"tsdown": "^0.22.0",
|
|
31
|
+
"vitest": "^3.0.0"
|
|
32
|
+
},
|
|
33
|
+
"scripts": {
|
|
34
|
+
"build": "tsdown",
|
|
35
|
+
"test": "vitest run"
|
|
36
|
+
}
|
|
37
|
+
}
|