@363045841yyt/klinechart 0.6.3 → 0.6.6
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 +4 -3
- package/dist/index.cjs +7 -7
- package/dist/index.js +2686 -1672
- package/dist/klinechart.css +1 -1
- package/dist/src/config/chartSettings.d.ts +11 -1
- package/dist/src/core/indicators/calculators.d.ts +140 -0
- package/dist/src/core/indicators/indicator.worker.d.ts +5 -0
- package/dist/src/core/indicators/indicatorRuntime.d.ts +71 -0
- package/dist/src/core/indicators/macdState.d.ts +58 -0
- package/dist/src/core/indicators/scheduler.d.ts +62 -198
- package/dist/src/core/indicators/soa.d.ts +115 -0
- package/dist/src/core/indicators/stateComposer.d.ts +47 -0
- package/dist/src/core/indicators/workerProtocol.d.ts +189 -0
- package/dist/src/core/renderers/Indicator/macd.d.ts +3 -11
- package/dist/src/core/renderers/Indicator/macdLegend.d.ts +5 -3
- package/dist/src/core/renderers/Indicator/rsi.d.ts +10 -0
- package/dist/src/core/renderers/webgl/candleSurface.d.ts +4 -0
- package/dist/src/core/utils/zoom.d.ts +2 -2
- package/dist/src/utils/dateFormat.d.ts +10 -8
- package/package.json +11 -9
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { PluginHost } from '../../plugin';
|
|
2
2
|
import { KLineData } from '../../types/price';
|
|
3
|
+
import { BOLLSchedulerConfig, EXPMASchedulerConfig, ENESchedulerConfig, RSISchedulerConfig, CCISchedulerConfig, STOCHSchedulerConfig, MOMSchedulerConfig, WMSRSchedulerConfig, KSTSchedulerConfig, FASTKSchedulerConfig, MACDSchedulerConfig } from './workerProtocol';
|
|
3
4
|
import { MAFlags } from './calculators';
|
|
4
5
|
/**
|
|
5
6
|
* 可见范围
|
|
@@ -8,259 +9,122 @@ interface VisibleRange {
|
|
|
8
9
|
start: number;
|
|
9
10
|
end: number;
|
|
10
11
|
}
|
|
12
|
+
export type { BOLLSchedulerConfig, EXPMASchedulerConfig, ENESchedulerConfig, RSISchedulerConfig, CCISchedulerConfig, STOCHSchedulerConfig, MOMSchedulerConfig, WMSRSchedulerConfig, KSTSchedulerConfig, FASTKSchedulerConfig, MACDSchedulerConfig, };
|
|
11
13
|
/**
|
|
12
|
-
*
|
|
13
|
-
*/
|
|
14
|
-
export interface BOLLSchedulerConfig {
|
|
15
|
-
period: number;
|
|
16
|
-
multiplier: number;
|
|
17
|
-
showUpper: boolean;
|
|
18
|
-
showMiddle: boolean;
|
|
19
|
-
showLower: boolean;
|
|
20
|
-
showBand: boolean;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* EXPMA 调度器配置
|
|
24
|
-
*/
|
|
25
|
-
export interface EXPMASchedulerConfig {
|
|
26
|
-
fastPeriod: number;
|
|
27
|
-
slowPeriod: number;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* ENE 调度器配置
|
|
31
|
-
*/
|
|
32
|
-
export interface ENESchedulerConfig {
|
|
33
|
-
period: number;
|
|
34
|
-
deviation: number;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* RSI 调度器配置
|
|
38
|
-
*/
|
|
39
|
-
export interface RSISchedulerConfig {
|
|
40
|
-
period1: number;
|
|
41
|
-
period2: number;
|
|
42
|
-
period3: number;
|
|
43
|
-
showRSI1: boolean;
|
|
44
|
-
showRSI2: boolean;
|
|
45
|
-
showRSI3: boolean;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* CCI 调度器配置
|
|
49
|
-
*/
|
|
50
|
-
export interface CCISchedulerConfig {
|
|
51
|
-
period: number;
|
|
52
|
-
showCCI: boolean;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* STOCH 调度器配置
|
|
56
|
-
*/
|
|
57
|
-
export interface STOCHSchedulerConfig {
|
|
58
|
-
n: number;
|
|
59
|
-
m: number;
|
|
60
|
-
showK: boolean;
|
|
61
|
-
showD: boolean;
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* MOM 调度器配置
|
|
65
|
-
*/
|
|
66
|
-
export interface MOMSchedulerConfig {
|
|
67
|
-
period: number;
|
|
68
|
-
showMOM: boolean;
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* WMSR 调度器配置
|
|
72
|
-
*/
|
|
73
|
-
export interface WMSRSchedulerConfig {
|
|
74
|
-
period: number;
|
|
75
|
-
showWMSR: boolean;
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* KST 调度器配置
|
|
79
|
-
*/
|
|
80
|
-
export interface KSTSchedulerConfig {
|
|
81
|
-
roc1: number;
|
|
82
|
-
roc2: number;
|
|
83
|
-
roc3: number;
|
|
84
|
-
roc4: number;
|
|
85
|
-
signalPeriod: number;
|
|
86
|
-
showKST: boolean;
|
|
87
|
-
showSignal: boolean;
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* FASTK 调度器配置
|
|
91
|
-
*/
|
|
92
|
-
export interface FASTKSchedulerConfig {
|
|
93
|
-
period: number;
|
|
94
|
-
showFASTK: boolean;
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* 指标调度器
|
|
98
|
-
*
|
|
99
|
-
* 职责:
|
|
100
|
-
* 1. 维护当前图表激活的指标配置
|
|
101
|
-
* 2. 在数据/视口/配置变更时触发计算
|
|
102
|
-
* 3. 将计算结果写入 StateStore,供渲染器消费
|
|
103
|
-
*
|
|
104
|
-
* 优化策略:
|
|
105
|
-
* - 双脏标记(dirtyData/dirtyRange):数据变更重算 series + 极值,视口变更仅重算极值
|
|
106
|
-
* - cachedSeries 缓存:视口变更时复用已计算的 series,避免 O(n) 重算
|
|
14
|
+
* IndicatorScheduler - 主线程 facade
|
|
107
15
|
*/
|
|
108
16
|
export declare class IndicatorScheduler {
|
|
109
17
|
private pluginHost;
|
|
110
|
-
private currentData;
|
|
111
|
-
private maConfig;
|
|
112
18
|
private visibleRange;
|
|
113
|
-
private cachedSeries;
|
|
114
|
-
private bollConfig;
|
|
115
|
-
private cachedBollSeries;
|
|
116
|
-
private expmaConfig;
|
|
117
|
-
private cachedExpmaSeries;
|
|
118
|
-
private eneConfig;
|
|
119
|
-
private cachedEneSeries;
|
|
120
|
-
private rsiConfig;
|
|
121
|
-
private rsiPaneId;
|
|
122
|
-
private cachedRsiSeries;
|
|
123
|
-
private cciConfig;
|
|
124
|
-
private cciPaneId;
|
|
125
|
-
private cachedCciSeries;
|
|
126
|
-
private stochConfig;
|
|
127
|
-
private stochPaneId;
|
|
128
|
-
private cachedStochSeries;
|
|
129
|
-
private momConfig;
|
|
130
|
-
private momPaneId;
|
|
131
|
-
private cachedMomSeries;
|
|
132
|
-
private wmsrConfig;
|
|
133
|
-
private wmsrPaneId;
|
|
134
|
-
private cachedWmsrSeries;
|
|
135
|
-
private kstConfig;
|
|
136
|
-
private kstPaneId;
|
|
137
|
-
private cachedKstSeries;
|
|
138
|
-
private fastkConfig;
|
|
139
|
-
private fastkPaneId;
|
|
140
|
-
private cachedFastkSeries;
|
|
141
|
-
private dirtyData;
|
|
142
|
-
private dirtyRange;
|
|
143
|
-
private dirtyBollConfig;
|
|
144
|
-
private dirtyExpmaConfig;
|
|
145
|
-
private dirtyEneConfig;
|
|
146
|
-
private dirtyRsiConfig;
|
|
147
|
-
private dirtyCciConfig;
|
|
148
|
-
private dirtyStochConfig;
|
|
149
|
-
private dirtyMomConfig;
|
|
150
|
-
private dirtyWmsrConfig;
|
|
151
|
-
private dirtyKstConfig;
|
|
152
|
-
private dirtyFastkConfig;
|
|
153
|
-
private dirtyRsiState;
|
|
154
|
-
private dirtyCciState;
|
|
155
|
-
private dirtyStochState;
|
|
156
|
-
private dirtyMomState;
|
|
157
|
-
private dirtyWmsrState;
|
|
158
|
-
private dirtyKstState;
|
|
159
|
-
private dirtyFastkState;
|
|
160
|
-
/** 当前激活的主图指标列表 */
|
|
161
19
|
private activeMainIndicators;
|
|
162
|
-
|
|
163
|
-
|
|
20
|
+
private dataVersion;
|
|
21
|
+
private configVersion;
|
|
22
|
+
private requestId;
|
|
23
|
+
private lastAppliedRequestId;
|
|
24
|
+
private currentData;
|
|
25
|
+
private configSnapshot;
|
|
26
|
+
private worker;
|
|
27
|
+
private workerReady;
|
|
28
|
+
private useWorker;
|
|
29
|
+
private pendingRequest;
|
|
30
|
+
private inlineRuntime;
|
|
31
|
+
private latestResult;
|
|
32
|
+
private invalidateCallback;
|
|
33
|
+
constructor();
|
|
34
|
+
/**
|
|
35
|
+
* 设置 PluginHost
|
|
164
36
|
*/
|
|
165
37
|
setPluginHost(host: PluginHost): void;
|
|
166
38
|
/**
|
|
167
|
-
*
|
|
168
|
-
* @param indicators 激活的指标ID列表,如 ['ma', 'boll', 'expma', 'ene']
|
|
39
|
+
* 设置重绘回调
|
|
169
40
|
*/
|
|
170
|
-
|
|
41
|
+
setInvalidateCallback(callback: () => void): void;
|
|
42
|
+
/**
|
|
43
|
+
* 销毁调度器
|
|
44
|
+
*/
|
|
45
|
+
destroy(): void;
|
|
46
|
+
private getDefaultConfig;
|
|
47
|
+
private initBackend;
|
|
48
|
+
private tryInitWorker;
|
|
49
|
+
private initInlineRuntime;
|
|
50
|
+
private fallbackToInline;
|
|
51
|
+
private terminateWorker;
|
|
52
|
+
private handleWorkerMessage;
|
|
53
|
+
private handleSeriesResult;
|
|
54
|
+
private applyResults;
|
|
55
|
+
private updateVisibleStatesOnly;
|
|
171
56
|
/**
|
|
172
57
|
* 数据变更时调用
|
|
173
|
-
* @param data 新的 K 线数据
|
|
174
|
-
* @param visibleRange 当前可见范围
|
|
175
58
|
*/
|
|
176
59
|
update(data: KLineData[], visibleRange: VisibleRange): void;
|
|
177
60
|
/**
|
|
178
|
-
*
|
|
179
|
-
|
|
61
|
+
* 视口变更时调用 - 同步处理,不走 Worker
|
|
62
|
+
*/
|
|
63
|
+
updateVisibleRange(visibleRange: VisibleRange): void;
|
|
64
|
+
/**
|
|
65
|
+
* MA 配置变更
|
|
180
66
|
*/
|
|
181
67
|
updateMAConfig(config: MAFlags): void;
|
|
182
68
|
/**
|
|
183
|
-
* BOLL
|
|
184
|
-
* @param config 新的 BOLL 配置
|
|
69
|
+
* BOLL 配置变更
|
|
185
70
|
*/
|
|
186
71
|
updateBOLLConfig(config: Partial<BOLLSchedulerConfig>): void;
|
|
187
72
|
/**
|
|
188
|
-
* EXPMA
|
|
189
|
-
* @param config 新的 EXPMA 配置
|
|
73
|
+
* EXPMA 配置变更
|
|
190
74
|
*/
|
|
191
75
|
updateEXPMAConfig(config: Partial<EXPMASchedulerConfig>): void;
|
|
192
76
|
/**
|
|
193
|
-
* ENE
|
|
194
|
-
* @param config 新的 ENE 配置
|
|
77
|
+
* ENE 配置变更
|
|
195
78
|
*/
|
|
196
79
|
updateENEConfig(config: Partial<ENESchedulerConfig>): void;
|
|
197
80
|
/**
|
|
198
|
-
* RSI
|
|
199
|
-
* @param config 新的 RSI 配置
|
|
200
|
-
* @param paneId RSI pane ID(可选,默认 'sub_RSI')
|
|
81
|
+
* RSI 配置变更
|
|
201
82
|
*/
|
|
202
83
|
updateRSIConfig(config: Partial<RSISchedulerConfig>, paneId?: string): void;
|
|
203
84
|
/**
|
|
204
|
-
* CCI
|
|
205
|
-
* @param config 新的 CCI 配置
|
|
206
|
-
* @param paneId CCI pane ID(可选,默认 'sub_CCI')
|
|
85
|
+
* CCI 配置变更
|
|
207
86
|
*/
|
|
208
87
|
updateCCIConfig(config: Partial<CCISchedulerConfig>, paneId?: string): void;
|
|
209
88
|
/**
|
|
210
|
-
* STOCH
|
|
211
|
-
* @param config 新的 STOCH 配置
|
|
212
|
-
* @param paneId STOCH pane ID(可选,默认 'sub_STOCH')
|
|
89
|
+
* STOCH 配置变更
|
|
213
90
|
*/
|
|
214
91
|
updateSTOCHConfig(config: Partial<STOCHSchedulerConfig>, paneId?: string): void;
|
|
215
92
|
/**
|
|
216
|
-
* MOM
|
|
217
|
-
* @param config 新的 MOM 配置
|
|
218
|
-
* @param paneId MOM pane ID(可选,默认 'sub_MOM')
|
|
93
|
+
* MOM 配置变更
|
|
219
94
|
*/
|
|
220
95
|
updateMOMConfig(config: Partial<MOMSchedulerConfig>, paneId?: string): void;
|
|
221
96
|
/**
|
|
222
|
-
* WMSR
|
|
223
|
-
* @param config 新的 WMSR 配置
|
|
224
|
-
* @param paneId WMSR pane ID(可选,默认 'sub_WMSR')
|
|
97
|
+
* WMSR 配置变更
|
|
225
98
|
*/
|
|
226
99
|
updateWMSRConfig(config: Partial<WMSRSchedulerConfig>, paneId?: string): void;
|
|
227
100
|
/**
|
|
228
|
-
* KST
|
|
229
|
-
* @param config 新的 KST 配置
|
|
230
|
-
* @param paneId KST pane ID(可选,默认 'sub_KST')
|
|
101
|
+
* KST 配置变更
|
|
231
102
|
*/
|
|
232
103
|
updateKSTConfig(config: Partial<KSTSchedulerConfig>, paneId?: string): void;
|
|
233
104
|
/**
|
|
234
|
-
* FASTK
|
|
235
|
-
* @param config 新的 FASTK 配置
|
|
236
|
-
* @param paneId FASTK pane ID(可选,默认 'sub_FASTK')
|
|
105
|
+
* FASTK 配置变更
|
|
237
106
|
*/
|
|
238
107
|
updateFASTKConfig(config: Partial<FASTKSchedulerConfig>, paneId?: string): void;
|
|
239
108
|
/**
|
|
240
|
-
*
|
|
241
|
-
* @param visibleRange 新的可见范围
|
|
242
|
-
*/
|
|
243
|
-
updateVisibleRange(visibleRange: VisibleRange): void;
|
|
244
|
-
/**
|
|
245
|
-
* 强制全部重算
|
|
109
|
+
* MACD 配置变更
|
|
246
110
|
*/
|
|
247
|
-
|
|
111
|
+
updateMACDConfig(config: Partial<MACDSchedulerConfig>, paneId?: string): void;
|
|
248
112
|
/**
|
|
249
|
-
*
|
|
250
|
-
*
|
|
251
|
-
* 计算流程:
|
|
252
|
-
* 1. 若 dirtyData 或指标配置脏标记,重算对应 series
|
|
253
|
-
* 2. 若任一 series 重算或 dirtyRange,重算所有指标在视口内的极值
|
|
254
|
-
* 3. 写入所有指标的 StateStore
|
|
113
|
+
* 设置当前激活的主图指标
|
|
255
114
|
*/
|
|
256
|
-
|
|
115
|
+
setActiveMainIndicators(indicators: string[]): void;
|
|
257
116
|
/**
|
|
258
|
-
*
|
|
259
|
-
* @returns 主图指标的价格范围,无指标时返回 null
|
|
117
|
+
* 获取主图指标价格范围
|
|
260
118
|
*/
|
|
261
119
|
getMainIndicatorPriceRange(): {
|
|
262
120
|
min: number;
|
|
263
121
|
max: number;
|
|
264
122
|
} | null;
|
|
123
|
+
/**
|
|
124
|
+
* 强制全部重算
|
|
125
|
+
*/
|
|
126
|
+
recompute(): void;
|
|
127
|
+
private triggerRecompute;
|
|
128
|
+
private computeWithWorker;
|
|
129
|
+
private computeWithInline;
|
|
265
130
|
}
|
|
266
|
-
export {};
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { KLineData } from '../../types/price';
|
|
2
|
+
/**
|
|
3
|
+
* KLineData 的 SoA (Structure of Arrays) 布局
|
|
4
|
+
* 用于零拷贝传输到 Web Worker
|
|
5
|
+
*
|
|
6
|
+
* 内存布局:
|
|
7
|
+
* | timestamps | opens | highs | lows | closes | volumes | turnovers |
|
|
8
|
+
* | 8*N | 8*N | 8*N | 8*N | 8*N | 8*N | 8*N |
|
|
9
|
+
*
|
|
10
|
+
* 其中 N 为数据长度,每列 8 字节(Float64)
|
|
11
|
+
*/
|
|
12
|
+
export interface KLineSoALayout {
|
|
13
|
+
/** 底层缓冲区(SharedArrayBuffer 或 ArrayBuffer) */
|
|
14
|
+
buffer: SharedArrayBuffer | ArrayBuffer;
|
|
15
|
+
/** 数据长度 */
|
|
16
|
+
length: number;
|
|
17
|
+
/** 是否使用 SharedArrayBuffer */
|
|
18
|
+
isShared: boolean;
|
|
19
|
+
/** 是否有成交量数据 */
|
|
20
|
+
hasVolume: boolean;
|
|
21
|
+
/** 是否有成交额数据 */
|
|
22
|
+
hasTurnover: boolean;
|
|
23
|
+
/** 时间戳数组(毫秒) */
|
|
24
|
+
timestamps: Float64Array;
|
|
25
|
+
/** 开盘价数组 */
|
|
26
|
+
opens: Float64Array;
|
|
27
|
+
/** 最高价数组 */
|
|
28
|
+
highs: Float64Array;
|
|
29
|
+
/** 最低价数组 */
|
|
30
|
+
lows: Float64Array;
|
|
31
|
+
/** 收盘价数组 */
|
|
32
|
+
closes: Float64Array;
|
|
33
|
+
/** 成交量数组(无值时为 0) */
|
|
34
|
+
volumes: Float64Array;
|
|
35
|
+
/** 成交额数组(无值时为 0) */
|
|
36
|
+
turnovers: Float64Array;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* SharedKLineBuffer - K线数据的 SoA 管理类
|
|
40
|
+
*
|
|
41
|
+
* 提供 AoS (KLineData[]) 与 SoA 布局之间的转换,
|
|
42
|
+
* 支持 SharedArrayBuffer(零拷贝)和 ArrayBuffer(降级)
|
|
43
|
+
*/
|
|
44
|
+
export declare class SharedKLineBuffer {
|
|
45
|
+
/**
|
|
46
|
+
* 检测 SharedArrayBuffer 是否可用
|
|
47
|
+
* 需要页面有 COOP/COEP 头支持
|
|
48
|
+
*/
|
|
49
|
+
static detectSupport(): boolean;
|
|
50
|
+
/**
|
|
51
|
+
* 计算 SoA 布局所需的总字节数
|
|
52
|
+
*/
|
|
53
|
+
static calculateByteLength(length: number): number;
|
|
54
|
+
/**
|
|
55
|
+
* 将 KLineData[] 转换为 SoA 布局
|
|
56
|
+
* @param data K线数据数组(AoS 格式)
|
|
57
|
+
* @param preferShared 是否优先使用 SharedArrayBuffer(默认 true)
|
|
58
|
+
* @returns SoA 布局对象
|
|
59
|
+
*/
|
|
60
|
+
static fromKLineData(data: KLineData[], preferShared?: boolean): KLineSoALayout;
|
|
61
|
+
/**
|
|
62
|
+
* 更新现有 SoA 布局的数据(尽可能复用缓冲区)
|
|
63
|
+
* 如果新数据长度超过原缓冲区,会创建新缓冲区
|
|
64
|
+
*
|
|
65
|
+
* @param layout 现有 SoA 布局
|
|
66
|
+
* @param data 新的 K线数据
|
|
67
|
+
* @returns 更新后的 SoA 布局(可能是新对象)
|
|
68
|
+
*/
|
|
69
|
+
static updateExisting(layout: KLineSoALayout, data: KLineData[]): KLineSoALayout;
|
|
70
|
+
/**
|
|
71
|
+
* 将 SoA 布局转换回 KLineData[](用于测试和兼容性)
|
|
72
|
+
* @param layout SoA 布局
|
|
73
|
+
* @returns K线数据数组
|
|
74
|
+
*/
|
|
75
|
+
static toKLineData(layout: KLineSoALayout): KLineData[];
|
|
76
|
+
/**
|
|
77
|
+
* 创建子视图(用于 Worker 中处理部分数据范围)
|
|
78
|
+
* @param layout 原 SoA 布局
|
|
79
|
+
* @param start 起始索引(包含)
|
|
80
|
+
* @param end 结束索引(不包含)
|
|
81
|
+
* @returns 子视图对象(共享同一缓冲区)
|
|
82
|
+
*/
|
|
83
|
+
static createSubview(layout: KLineSoALayout, start: number, end: number): KLineSoALayout;
|
|
84
|
+
/**
|
|
85
|
+
* 获取缓冲区信息(用于调试和序列化)
|
|
86
|
+
*/
|
|
87
|
+
static getBufferInfo(layout: KLineSoALayout): {
|
|
88
|
+
byteLength: number;
|
|
89
|
+
isShared: boolean;
|
|
90
|
+
length: number;
|
|
91
|
+
columns: string[];
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* 获取 SoA 布局中 closes 列的视图(最常用列)
|
|
96
|
+
* 用于指标计算中快速访问收盘价
|
|
97
|
+
*/
|
|
98
|
+
export declare function getClosesView(layout: KLineSoALayout): Float64Array;
|
|
99
|
+
/**
|
|
100
|
+
* 获取 SoA 布局中 highs/lows 列的视图
|
|
101
|
+
* 用于需要高低价的指标(如 BOLL、STOCH、WMSR)
|
|
102
|
+
*/
|
|
103
|
+
export declare function getHighsLowsViews(layout: KLineSoALayout): {
|
|
104
|
+
highs: Float64Array;
|
|
105
|
+
lows: Float64Array;
|
|
106
|
+
};
|
|
107
|
+
/**
|
|
108
|
+
* 获取 SoA 布局中 OHLC 四价视图
|
|
109
|
+
*/
|
|
110
|
+
export declare function getOHLCViews(layout: KLineSoALayout): {
|
|
111
|
+
opens: Float64Array;
|
|
112
|
+
highs: Float64Array;
|
|
113
|
+
lows: Float64Array;
|
|
114
|
+
closes: Float64Array;
|
|
115
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { MARenderState } from './maState';
|
|
2
|
+
import { BOLLRenderState } from './bollState';
|
|
3
|
+
import { EXPMARenderState } from './expmaState';
|
|
4
|
+
import { ENERenderState } from './eneState';
|
|
5
|
+
import { RSIRenderState } from './rsiState';
|
|
6
|
+
import { CCIRenderState } from './cciState';
|
|
7
|
+
import { STOCHRenderState } from './stochState';
|
|
8
|
+
import { MOMRenderState } from './momState';
|
|
9
|
+
import { WMSRRenderState } from './wmsrState';
|
|
10
|
+
import { KSTRenderState } from './kstState';
|
|
11
|
+
import { FASTKRenderState } from './fastkState';
|
|
12
|
+
import { MACDRenderState } from './macdState';
|
|
13
|
+
import { IndicatorSeriesBundle } from './workerProtocol';
|
|
14
|
+
/**
|
|
15
|
+
* 可见范围
|
|
16
|
+
*/
|
|
17
|
+
interface VisibleRange {
|
|
18
|
+
start: number;
|
|
19
|
+
end: number;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* 从 series bundle 组装所有 render states
|
|
23
|
+
* 同时计算 visibleMin/visibleMax 等派生字段
|
|
24
|
+
*/
|
|
25
|
+
export declare function composeRenderStates(bundle: IndicatorSeriesBundle, visibleRange: VisibleRange, timestamp: number): {
|
|
26
|
+
ma: MARenderState;
|
|
27
|
+
boll: BOLLRenderState;
|
|
28
|
+
expma: EXPMARenderState;
|
|
29
|
+
ene: ENERenderState;
|
|
30
|
+
rsi: RSIRenderState;
|
|
31
|
+
cci: CCIRenderState;
|
|
32
|
+
stoch: STOCHRenderState;
|
|
33
|
+
mom: MOMRenderState;
|
|
34
|
+
wmsr: WMSRRenderState;
|
|
35
|
+
kst: KSTRenderState;
|
|
36
|
+
fastk: FASTKRenderState;
|
|
37
|
+
macd: MACDRenderState;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* 计算主图指标价格范围
|
|
41
|
+
* 用于 Chart.draw() 中的 pane.updateRange
|
|
42
|
+
*/
|
|
43
|
+
export declare function computeMainIndicatorPriceRange(bundle: IndicatorSeriesBundle, visibleRange: VisibleRange, activeMainIndicators: Set<string>): {
|
|
44
|
+
min: number;
|
|
45
|
+
max: number;
|
|
46
|
+
} | null;
|
|
47
|
+
export {};
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { KLineData } from '../../types/price';
|
|
2
|
+
import { MAFlags, BOLLPoint, EXPMAPoint, ENEPoint, STOCHPoint, KSTPoint, MACDPoint } from './calculators';
|
|
3
|
+
export interface BOLLSchedulerConfig {
|
|
4
|
+
period: number;
|
|
5
|
+
multiplier: number;
|
|
6
|
+
showUpper: boolean;
|
|
7
|
+
showMiddle: boolean;
|
|
8
|
+
showLower: boolean;
|
|
9
|
+
showBand: boolean;
|
|
10
|
+
}
|
|
11
|
+
export interface EXPMASchedulerConfig {
|
|
12
|
+
fastPeriod: number;
|
|
13
|
+
slowPeriod: number;
|
|
14
|
+
}
|
|
15
|
+
export interface ENESchedulerConfig {
|
|
16
|
+
period: number;
|
|
17
|
+
deviation: number;
|
|
18
|
+
}
|
|
19
|
+
export interface RSISchedulerConfig {
|
|
20
|
+
period1: number;
|
|
21
|
+
period2: number;
|
|
22
|
+
period3: number;
|
|
23
|
+
showRSI1: boolean;
|
|
24
|
+
showRSI2: boolean;
|
|
25
|
+
showRSI3: boolean;
|
|
26
|
+
}
|
|
27
|
+
export interface CCISchedulerConfig {
|
|
28
|
+
period: number;
|
|
29
|
+
showCCI: boolean;
|
|
30
|
+
}
|
|
31
|
+
export interface STOCHSchedulerConfig {
|
|
32
|
+
n: number;
|
|
33
|
+
m: number;
|
|
34
|
+
showK: boolean;
|
|
35
|
+
showD: boolean;
|
|
36
|
+
}
|
|
37
|
+
export interface MOMSchedulerConfig {
|
|
38
|
+
period: number;
|
|
39
|
+
showMOM: boolean;
|
|
40
|
+
}
|
|
41
|
+
export interface WMSRSchedulerConfig {
|
|
42
|
+
period: number;
|
|
43
|
+
showWMSR: boolean;
|
|
44
|
+
}
|
|
45
|
+
export interface KSTSchedulerConfig {
|
|
46
|
+
roc1: number;
|
|
47
|
+
roc2: number;
|
|
48
|
+
roc3: number;
|
|
49
|
+
roc4: number;
|
|
50
|
+
signalPeriod: number;
|
|
51
|
+
showKST: boolean;
|
|
52
|
+
showSignal: boolean;
|
|
53
|
+
}
|
|
54
|
+
export interface FASTKSchedulerConfig {
|
|
55
|
+
period: number;
|
|
56
|
+
showFASTK: boolean;
|
|
57
|
+
}
|
|
58
|
+
export interface MACDSchedulerConfig {
|
|
59
|
+
fastPeriod: number;
|
|
60
|
+
slowPeriod: number;
|
|
61
|
+
signalPeriod: number;
|
|
62
|
+
showDIF: boolean;
|
|
63
|
+
showDEA: boolean;
|
|
64
|
+
showBAR: boolean;
|
|
65
|
+
}
|
|
66
|
+
export interface InitRequest {
|
|
67
|
+
type: 'init';
|
|
68
|
+
protocolVersion: number;
|
|
69
|
+
}
|
|
70
|
+
export interface SetDataRequest {
|
|
71
|
+
type: 'setData';
|
|
72
|
+
dataVersion: number;
|
|
73
|
+
format: 'aos' | 'soa';
|
|
74
|
+
data: KLineData[];
|
|
75
|
+
}
|
|
76
|
+
export interface SetConfigRequest {
|
|
77
|
+
type: 'setConfig';
|
|
78
|
+
configVersion: number;
|
|
79
|
+
configs: IndicatorConfigSnapshot;
|
|
80
|
+
}
|
|
81
|
+
export interface ComputeSeriesRequest {
|
|
82
|
+
type: 'computeSeries';
|
|
83
|
+
requestId: number;
|
|
84
|
+
dataVersion: number;
|
|
85
|
+
configVersion: number;
|
|
86
|
+
}
|
|
87
|
+
export interface DisposeRequest {
|
|
88
|
+
type: 'dispose';
|
|
89
|
+
}
|
|
90
|
+
export type IndicatorWorkerRequest = InitRequest | SetDataRequest | SetConfigRequest | ComputeSeriesRequest | DisposeRequest;
|
|
91
|
+
export interface ReadyResponse {
|
|
92
|
+
type: 'ready';
|
|
93
|
+
protocolVersion: number;
|
|
94
|
+
}
|
|
95
|
+
export interface SeriesResultResponse {
|
|
96
|
+
type: 'seriesResult';
|
|
97
|
+
requestId: number;
|
|
98
|
+
dataVersion: number;
|
|
99
|
+
configVersion: number;
|
|
100
|
+
results: IndicatorSeriesBundle;
|
|
101
|
+
metrics?: {
|
|
102
|
+
computeMs: number;
|
|
103
|
+
dataLength: number;
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
export interface ErrorResponse {
|
|
107
|
+
type: 'error';
|
|
108
|
+
requestId?: number;
|
|
109
|
+
stage: 'init' | 'setData' | 'setConfig' | 'computeSeries';
|
|
110
|
+
message: string;
|
|
111
|
+
}
|
|
112
|
+
export type IndicatorWorkerResponse = ReadyResponse | SeriesResultResponse | ErrorResponse;
|
|
113
|
+
export interface IndicatorConfigSnapshot {
|
|
114
|
+
ma: MAFlags;
|
|
115
|
+
boll: BOLLSchedulerConfig;
|
|
116
|
+
expma: EXPMASchedulerConfig;
|
|
117
|
+
ene: ENESchedulerConfig;
|
|
118
|
+
rsi: RSISchedulerConfig;
|
|
119
|
+
cci: CCISchedulerConfig;
|
|
120
|
+
stoch: STOCHSchedulerConfig;
|
|
121
|
+
mom: MOMSchedulerConfig;
|
|
122
|
+
wmsr: WMSRSchedulerConfig;
|
|
123
|
+
kst: KSTSchedulerConfig;
|
|
124
|
+
fastk: FASTKSchedulerConfig;
|
|
125
|
+
macd: MACDSchedulerConfig;
|
|
126
|
+
rsiPaneId: string;
|
|
127
|
+
cciPaneId: string;
|
|
128
|
+
stochPaneId: string;
|
|
129
|
+
momPaneId: string;
|
|
130
|
+
wmsrPaneId: string;
|
|
131
|
+
kstPaneId: string;
|
|
132
|
+
fastkPaneId: string;
|
|
133
|
+
macdPaneId: string;
|
|
134
|
+
}
|
|
135
|
+
export interface IndicatorSeriesBundle {
|
|
136
|
+
ma: {
|
|
137
|
+
series: Record<number, (number | undefined)[]>;
|
|
138
|
+
enabledPeriods: number[];
|
|
139
|
+
};
|
|
140
|
+
boll: {
|
|
141
|
+
series: BOLLPoint[];
|
|
142
|
+
params: BOLLSchedulerConfig;
|
|
143
|
+
};
|
|
144
|
+
expma: {
|
|
145
|
+
series: EXPMAPoint[];
|
|
146
|
+
params: EXPMASchedulerConfig;
|
|
147
|
+
};
|
|
148
|
+
ene: {
|
|
149
|
+
series: ENEPoint[];
|
|
150
|
+
params: ENESchedulerConfig;
|
|
151
|
+
};
|
|
152
|
+
rsi: {
|
|
153
|
+
series: Record<number, (number | undefined)[]>;
|
|
154
|
+
enabledPeriods: number[];
|
|
155
|
+
params: RSISchedulerConfig;
|
|
156
|
+
};
|
|
157
|
+
cci: {
|
|
158
|
+
series: (number | undefined)[];
|
|
159
|
+
params: CCISchedulerConfig;
|
|
160
|
+
};
|
|
161
|
+
stoch: {
|
|
162
|
+
series: STOCHPoint[];
|
|
163
|
+
params: STOCHSchedulerConfig;
|
|
164
|
+
};
|
|
165
|
+
mom: {
|
|
166
|
+
series: (number | undefined)[];
|
|
167
|
+
params: MOMSchedulerConfig;
|
|
168
|
+
};
|
|
169
|
+
wmsr: {
|
|
170
|
+
series: (number | undefined)[];
|
|
171
|
+
params: WMSRSchedulerConfig;
|
|
172
|
+
};
|
|
173
|
+
kst: {
|
|
174
|
+
series: KSTPoint[];
|
|
175
|
+
params: KSTSchedulerConfig;
|
|
176
|
+
};
|
|
177
|
+
fastk: {
|
|
178
|
+
series: (number | undefined)[];
|
|
179
|
+
params: FASTKSchedulerConfig;
|
|
180
|
+
};
|
|
181
|
+
macd: {
|
|
182
|
+
series: MACDPoint[];
|
|
183
|
+
params: MACDSchedulerConfig;
|
|
184
|
+
};
|
|
185
|
+
/** 本次计算中实际变更的指标列表 */
|
|
186
|
+
_changed: string[];
|
|
187
|
+
}
|
|
188
|
+
export declare const PROTOCOL_VERSION = 1;
|
|
189
|
+
export declare function isWorkerResponse(msg: unknown): msg is IndicatorWorkerResponse;
|