@quantlife/qlchart 0.0.1
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/.idea/QLChart.iml +12 -0
- package/.idea/modules.xml +8 -0
- package/.idea/vcs.xml +6 -0
- package/README.md +75 -0
- package/demo/App.css +213 -0
- package/demo/App.tsx +46 -0
- package/demo/components/ControlPanel.tsx +13 -0
- package/demo/components/DemoNav.tsx +27 -0
- package/demo/index.html +16 -0
- package/demo/main.tsx +10 -0
- package/demo/pages/BasicChartDemo.tsx +61 -0
- package/demo/pages/DrawingDemo.tsx +22 -0
- package/demo/pages/IndicatorDemo.tsx +22 -0
- package/demo/pages/LayoutDemo.tsx +35 -0
- package/demo/pages/MultiPeriodDemo.tsx +31 -0
- package/demo/pages/ReplayDemo.tsx +195 -0
- package/demo/pages/SaveDemo.tsx +27 -0
- package/demo/pages/ThemeDemo.tsx +29 -0
- package/demo/standalone-demo.html +597 -0
- package/demo/vite.config.demo.ts +17 -0
- package/dist/index.d.ts +1973 -0
- package/dist/qlchart.js +23169 -0
- package/dist/style.css +1 -0
- package/doc/api/indicator-data-processor.md +35 -0
- package/doc/api-reference/.nojekyll +1 -0
- package/doc/api-reference/assets/hierarchy.js +1 -0
- package/doc/api-reference/assets/highlight.css +43 -0
- package/doc/api-reference/assets/icons.js +18 -0
- package/doc/api-reference/assets/icons.svg +1 -0
- package/doc/api-reference/assets/main.js +60 -0
- package/doc/api-reference/assets/navigation.js +1 -0
- package/doc/api-reference/assets/search.js +1 -0
- package/doc/api-reference/assets/style.css +1611 -0
- package/doc/api-reference/classes/ChartManager.html +16 -0
- package/doc/api-reference/classes/DataManager.html +13 -0
- package/doc/api-reference/classes/DrawingAdapter.html +64 -0
- package/doc/api-reference/classes/DrawingPersistence.html +21 -0
- package/doc/api-reference/classes/EventManager.html +12 -0
- package/doc/api-reference/classes/HollowCandlestickSeries.html +22 -0
- package/doc/api-reference/classes/IndicatorRenderer.html +20 -0
- package/doc/api-reference/classes/KlineReplay.html +31 -0
- package/doc/api-reference/classes/MockDataService.html +13 -0
- package/doc/api-reference/classes/MockIndicatorService.html +4 -0
- package/doc/api-reference/classes/OverlayIndicator.html +11 -0
- package/doc/api-reference/classes/PaneIndicator.html +16 -0
- package/doc/api-reference/classes/PaneManager.html +24 -0
- package/doc/api-reference/classes/RealtimeDataFeed.html +22 -0
- package/doc/api-reference/classes/RenkoSeries.html +22 -0
- package/doc/api-reference/classes/ScreenshotUtil.html +10 -0
- package/doc/api-reference/classes/SeriesManager.html +30 -0
- package/doc/api-reference/classes/ThemeManager.html +18 -0
- package/doc/api-reference/enums/ChartEvent.html +12 -0
- package/doc/api-reference/enums/IndicatorType.html +4 -0
- package/doc/api-reference/enums/SeriesType.html +13 -0
- package/doc/api-reference/functions/ChartFunctionMenu.html +1 -0
- package/doc/api-reference/functions/DrawingModule.html +8 -0
- package/doc/api-reference/functions/IndicatorPanel.html +2 -0
- package/doc/api-reference/functions/IndicatorTag.html +2 -0
- package/doc/api-reference/functions/KlineTypeSelector.html +1 -0
- package/doc/api-reference/functions/LayoutSwitcher.html +1 -0
- package/doc/api-reference/functions/PeriodSelector.html +1 -0
- package/doc/api-reference/functions/QLChartLayout.html +1 -0
- package/doc/api-reference/functions/QLChartPanel.html +10 -0
- package/doc/api-reference/functions/QLChartProvider.html +2 -0
- package/doc/api-reference/functions/QLToolbar.html +1 -0
- package/doc/api-reference/functions/ReplayController.html +1 -0
- package/doc/api-reference/functions/TimeBarModule.html +4 -0
- package/doc/api-reference/functions/TimeRangeSelector.html +1 -0
- package/doc/api-reference/functions/createIndicatorConfig.html +2 -0
- package/doc/api-reference/functions/getToolConfig.html +2 -0
- package/doc/api-reference/functions/getToolsByCategory.html +2 -0
- package/doc/api-reference/functions/getToolsByPriority.html +2 -0
- package/doc/api-reference/functions/mapLibTypeToOurs.html +2 -0
- package/doc/api-reference/functions/mapToolTypeToLib.html +3 -0
- package/doc/api-reference/functions/transformCandlestickData.html +3 -0
- package/doc/api-reference/functions/transformIndicatorData.html +2 -0
- package/doc/api-reference/functions/transformVolumeData.html +3 -0
- package/doc/api-reference/functions/useChart.html +4 -0
- package/doc/api-reference/functions/useChartStore.html +8 -0
- package/doc/api-reference/functions/useCrosshairSync.html +8 -0
- package/doc/api-reference/functions/useDrawingModule.html +1 -0
- package/doc/api-reference/functions/useDrawingStore.html +8 -0
- package/doc/api-reference/functions/useIndicatorStore.html +8 -0
- package/doc/api-reference/functions/useQLChartConfig.html +2 -0
- package/doc/api-reference/functions/useReplayStore.html +8 -0
- package/doc/api-reference/functions/useTheme.html +2 -0
- package/doc/api-reference/functions/useTimeBarStore.html +8 -0
- package/doc/api-reference/index.html +1 -0
- package/doc/api-reference/interfaces/CandlestickData.html +7 -0
- package/doc/api-reference/interfaces/CandlestickRawData.html +8 -0
- package/doc/api-reference/interfaces/ChartFunctionMenuProps.html +2 -0
- package/doc/api-reference/interfaces/ChartManagerCreateOptions.html +4 -0
- package/doc/api-reference/interfaces/ChartOptions.html +8 -0
- package/doc/api-reference/interfaces/ChartRequestParams.html +8 -0
- package/doc/api-reference/interfaces/ChartResponse.html +5 -0
- package/doc/api-reference/interfaces/ChartState.html +24 -0
- package/doc/api-reference/interfaces/ChartThemeOptions.html +5 -0
- package/doc/api-reference/interfaces/CrosshairData.html +5 -0
- package/doc/api-reference/interfaces/DrawingModuleProps.html +5 -0
- package/doc/api-reference/interfaces/DrawingState.html +48 -0
- package/doc/api-reference/interfaces/HistogramData.html +5 -0
- package/doc/api-reference/interfaces/HollowCandlestickData.html +14 -0
- package/doc/api-reference/interfaces/IndicatorConfig.html +11 -0
- package/doc/api-reference/interfaces/IndicatorDataPoint.html +4 -0
- package/doc/api-reference/interfaces/IndicatorDataResponse.html +5 -0
- package/doc/api-reference/interfaces/IndicatorDefinition.html +9 -0
- package/doc/api-reference/interfaces/IndicatorPanelProps.html +3 -0
- package/doc/api-reference/interfaces/IndicatorParamDef.html +8 -0
- package/doc/api-reference/interfaces/IndicatorRawData.html +4 -0
- package/doc/api-reference/interfaces/IndicatorState.html +19 -0
- package/doc/api-reference/interfaces/IndicatorTagProps.html +2 -0
- package/doc/api-reference/interfaces/KlineReplayOptions.html +4 -0
- package/doc/api-reference/interfaces/LayoutSwitcherProps.html +3 -0
- package/doc/api-reference/interfaces/LineData.html +4 -0
- package/doc/api-reference/interfaces/MockDataConfig.html +8 -0
- package/doc/api-reference/interfaces/MockIndicatorConfig.html +5 -0
- package/doc/api-reference/interfaces/PairInfo.html +6 -0
- package/doc/api-reference/interfaces/PaneInfo.html +6 -0
- package/doc/api-reference/interfaces/PanelConfig.html +9 -0
- package/doc/api-reference/interfaces/PersistenceConfig.html +12 -0
- package/doc/api-reference/interfaces/QLChartConfig.html +18 -0
- package/doc/api-reference/interfaces/QLChartLayoutProps.html +9 -0
- package/doc/api-reference/interfaces/QLChartPanelProps.html +13 -0
- package/doc/api-reference/interfaces/QLChartPanelRef.html +14 -0
- package/doc/api-reference/interfaces/QLToolbarProps.html +7 -0
- package/doc/api-reference/interfaces/RealtimeCandle.html +9 -0
- package/doc/api-reference/interfaces/RealtimeSubscribeFn.html +2 -0
- package/doc/api-reference/interfaces/RenkoData.html +16 -0
- package/doc/api-reference/interfaces/ReplayControllerProps.html +2 -0
- package/doc/api-reference/interfaces/ReplayState.html +19 -0
- package/doc/api-reference/interfaces/ThemeConfig.html +14 -0
- package/doc/api-reference/interfaces/TimeBarModuleProps.html +5 -0
- package/doc/api-reference/interfaces/TimeBarState.html +13 -0
- package/doc/api-reference/interfaces/UseChartReturn.html +4 -0
- package/doc/api-reference/interfaces/UseDrawingModuleOptions.html +11 -0
- package/doc/api-reference/interfaces/UseDrawingModuleReturn.html +6 -0
- package/doc/api-reference/interfaces/UseThemeReturn.html +5 -0
- package/doc/api-reference/types/EventHandler.html +2 -0
- package/doc/api-reference/types/FetchFn.html +2 -0
- package/doc/api-reference/types/LayoutMode.html +2 -0
- package/doc/api-reference/types/MarketTrend.html +2 -0
- package/doc/api-reference/types/ThemePreset.html +2 -0
- package/doc/api-reference/variables/BUILTIN_INDICATORS.html +2 -0
- package/doc/api-reference/variables/CATEGORY_LABELS.html +2 -0
- package/doc/api-reference/variables/DRAWING_TOOLS.html +3 -0
- package/doc/api-reference/variables/MARKET_PRESETS.html +1 -0
- package/doc/api-reference/variables/PAIR_PRESETS.html +1 -0
- package/doc/api-reference/variables/darkPreset.html +1 -0
- package/doc/api-reference/variables/lightPreset.html +1 -0
- package/doc/components/drawing-module.md +24 -0
- package/doc/components/indicator-list-panel.md +24 -0
- package/doc/components/indicator-panel.md +17 -0
- package/doc/components/pane-divider.md +25 -0
- package/doc/components/qlchart-layout.md +30 -0
- package/doc/components/qlchart-panel.md +93 -0
- package/doc/components/qlchart-provider.md +73 -0
- package/doc/components/qltoolbar.md +17 -0
- package/doc/components/replay-controller.md +23 -0
- package/doc/components/timebar-module.md +13 -0
- package/doc/core/chart-manager.md +14 -0
- package/doc/core/data-manager.md +33 -0
- package/doc/core/event-manager.md +26 -0
- package/doc/core/pane-manager.md +13 -0
- package/doc/core/series-manager.md +19 -0
- package/doc/core/theme-manager.md +21 -0
- package/doc/examples/basic-chart.md +24 -0
- package/doc/examples/data-format-guide.md +119 -0
- package/doc/examples/drawing-tools.md +30 -0
- package/doc/examples/indicator-properties.md +34 -0
- package/doc/examples/multi-pane.md +24 -0
- package/doc/examples/multi-panel.md +23 -0
- package/doc/examples/realtime-data.md +147 -0
- package/doc/examples/standalone-js.md +333 -0
- package/doc/guide/architecture.md +87 -0
- package/doc/guide/data-flow.md +310 -0
- package/doc/guide/deployment.md +59 -0
- package/doc/guide/drawing-properties.md +40 -0
- package/doc/guide/getting-started.md +94 -0
- package/doc/guide/pane-system.md +47 -0
- package/doc/guide/theme-switching.md +58 -0
- package/doc/hooks/use-chart.md +20 -0
- package/doc/hooks/use-crosshair-sync.md +14 -0
- package/doc/hooks/use-drawing-module.md +43 -0
- package/doc/hooks/use-theme.md +15 -0
- package/doc/index.md +33 -0
- package/doc/plugins/drawing/overview.md +36 -0
- package/doc/plugins/drawing/persistence.md +42 -0
- package/doc/plugins/drawing/tool-registry.md +29 -0
- package/doc/plugins/hollow-candlestick.md +18 -0
- package/doc/plugins/indicators.md +28 -0
- package/doc/plugins/renko.md +17 -0
- package/doc/plugins/replay.md +21 -0
- package/doc/plugins/screenshot.md +20 -0
- package/docs/api.md +94 -0
- package/package.json +54 -0
- package/python/qlchart/__init__.py +9 -0
- package/python/qlchart/__pycache__/__init__.cpython-311.pyc +0 -0
- package/python/qlchart/__pycache__/chart.cpython-311.pyc +0 -0
- package/python/qlchart/chart.py +333 -0
- package/python/qlchart/templates/chart_template.html +304 -0
- package/python/requirements.txt +1 -0
- package/python/setup.py +18 -0
- package/python/tests/__init__.py +1 -0
- package/python/tests/__pycache__/__init__.cpython-311.pyc +0 -0
- package/python/tests/__pycache__/test_chart.cpython-311-pytest-8.3.3.pyc +0 -0
- package/python/tests/test_chart.py +114 -0
- package/quantlife-qlchart-0.0.1.tgz +0 -0
- package/src/api/chartApi.ts +30 -0
- package/src/api/indicatorApi.ts +27 -0
- package/src/components/ChartFunctionMenu.tsx +64 -0
- package/src/components/PaneChartPanel.tsx +116 -0
- package/src/components/PaneDivider.tsx +66 -0
- package/src/components/QLChartLayout.tsx +151 -0
- package/src/components/QLChartPanel.tsx +560 -0
- package/src/components/QLChartProvider.tsx +90 -0
- package/src/components/context-menu/ChartContextMenu.tsx +139 -0
- package/src/components/context-menu/index.ts +2 -0
- package/src/components/drawing/DrawingModule.tsx +36 -0
- package/src/components/drawing/DrawingPropertyPanel.tsx +347 -0
- package/src/components/drawing/DrawingToolbar.tsx +305 -0
- package/src/components/drawing/index.ts +5 -0
- package/src/components/index.ts +43 -0
- package/src/components/indicator/IndicatorListPanel.tsx +94 -0
- package/src/components/indicator/IndicatorModal.tsx +171 -0
- package/src/components/indicator/IndicatorPanel.tsx +9 -0
- package/src/components/indicator/IndicatorPropertyPanel.tsx +130 -0
- package/src/components/indicator/IndicatorTag.tsx +173 -0
- package/src/components/indicator/index.ts +4 -0
- package/src/components/replay/ReplayController.css +97 -0
- package/src/components/replay/ReplayController.tsx +138 -0
- package/src/components/timebar/TimeBarModule.tsx +30 -0
- package/src/components/timebar/TimeRangeSelector.tsx +96 -0
- package/src/components/timebar/index.ts +3 -0
- package/src/components/toolbar/GlobalToolbar.tsx +58 -0
- package/src/components/toolbar/KlineTypeSelector.tsx +123 -0
- package/src/components/toolbar/LayoutSwitcher.tsx +45 -0
- package/src/components/toolbar/PeriodSelector.tsx +35 -0
- package/src/components/toolbar/QLToolbar.tsx +71 -0
- package/src/components/toolbar/TimeRangeSelector.tsx +89 -0
- package/src/components/ui/Modal.tsx +67 -0
- package/src/core/ChartManager.ts +95 -0
- package/src/core/DataManager.ts +427 -0
- package/src/core/EventManager.ts +63 -0
- package/src/core/IndicatorDataProcessor.ts +104 -0
- package/src/core/PaneManager.ts +121 -0
- package/src/core/RealtimeDataFeed.ts +110 -0
- package/src/core/SeriesManager.ts +210 -0
- package/src/core/ThemeManager.ts +59 -0
- package/src/core/index.ts +10 -0
- package/src/css.d.ts +4 -0
- package/src/hooks/useChart.ts +62 -0
- package/src/hooks/useCrosshairSync.ts +109 -0
- package/src/hooks/useDrawingModule.ts +475 -0
- package/src/hooks/useTheme.ts +31 -0
- package/src/index.ts +170 -0
- package/src/mock/MockDataService.ts +102 -0
- package/src/mock/MockIndicatorService.ts +40 -0
- package/src/mock/index.ts +5 -0
- package/src/mock/presets.ts +16 -0
- package/src/plugins/drawing/DrawingAdapter.ts +1762 -0
- package/src/plugins/drawing/DrawingPersistence.ts +273 -0
- package/src/plugins/drawing/DrawingPropertyTemplates.ts +327 -0
- package/src/plugins/drawing/DrawingSharedService.ts +125 -0
- package/src/plugins/drawing/DrawingToolRegistry.ts +684 -0
- package/src/plugins/drawing/TextLabelOverlay.ts +101 -0
- package/src/plugins/drawing/colorUtils.ts +53 -0
- package/src/plugins/drawing/index.ts +10 -0
- package/src/plugins/drawing/lineStyleMap.ts +46 -0
- package/src/plugins/drawing/migration.ts +105 -0
- package/src/plugins/drawing/patterns/PatternDefinitions.ts +57 -0
- package/src/plugins/drawing/patterns/index.ts +2 -0
- package/src/plugins/drawing/periodUtils.ts +51 -0
- package/src/plugins/indicators/AutoIndicatorRenderer.ts +204 -0
- package/src/plugins/indicators/IndicatorRenderer.ts +350 -0
- package/src/plugins/indicators/OverlayIndicator.ts +114 -0
- package/src/plugins/indicators/PaneIndicator.ts +137 -0
- package/src/plugins/indicators/index.ts +4 -0
- package/src/plugins/replay/KlineReplay.ts +163 -0
- package/src/plugins/replay/index.ts +2 -0
- package/src/plugins/screenshot/ScreenshotUtil.ts +123 -0
- package/src/plugins/screenshot/index.ts +1 -0
- package/src/plugins/series/HollowCandlestickSeries.ts +111 -0
- package/src/plugins/series/RenkoSeries.ts +104 -0
- package/src/plugins/series/VolumeCandlestickSeries.ts +127 -0
- package/src/plugins/series/index.ts +6 -0
- package/src/standalone.ts +386 -0
- package/src/store/useChartStore.ts +101 -0
- package/src/store/useDrawingStore.ts +135 -0
- package/src/store/useIndicatorStore.ts +100 -0
- package/src/store/usePanelRegistry.ts +50 -0
- package/src/store/useReplayStore.ts +42 -0
- package/src/store/useTimeBarStore.ts +34 -0
- package/src/styles/chart.css +312 -0
- package/src/styles/components.css +184 -0
- package/src/styles/context-menu.css +60 -0
- package/src/styles/drawing.css +524 -0
- package/src/styles/indicator-modal.css +216 -0
- package/src/styles/indicator-tag.css +210 -0
- package/src/styles/pane-chart.css +9 -0
- package/src/styles/responsive.css +71 -0
- package/src/styles/themes/dark.css +63 -0
- package/src/styles/themes/light.css +61 -0
- package/src/styles/toolbar.css +129 -0
- package/src/types/api.ts +36 -0
- package/src/types/chart.ts +44 -0
- package/src/types/drawing.ts +265 -0
- package/src/types/index.ts +40 -0
- package/src/types/indicator.ts +344 -0
- package/src/types/series.ts +53 -0
- package/src/types/theme.ts +48 -0
- package/src/utils/dataTransformer.ts +63 -0
- package/src/utils/heikinAshi.ts +41 -0
- package/src/utils/index.ts +3 -0
- package/src/utils/lineBreak.ts +88 -0
- package/src/utils/themePresets.ts +69 -0
- package/src/utils/timeFormatter.ts +29 -0
- package/src/utils/timeScaleUtils.ts +68 -0
- package/tsconfig.json +21 -0
- package/typedoc.json +10 -0
- package/vite.config.standalone.ts +31 -0
- package/vite.config.ts +24 -0
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
// ── 2.2 指标总览API:搜索与查询类型 ──
|
|
2
|
+
|
|
3
|
+
/** 指标搜索查询参数 */
|
|
4
|
+
export interface IndicatorSearchQuery {
|
|
5
|
+
keyword?: string;
|
|
6
|
+
category?: string;
|
|
7
|
+
displayType?: 'overlay' | 'pane';
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// ── 2.3 指标自动渲染:数据驱动渲染协议 ──
|
|
11
|
+
|
|
12
|
+
/** 指标渲染描述(后端返回,前端自动渲染) */
|
|
13
|
+
export interface IndicatorRenderSpec {
|
|
14
|
+
/** 指标唯一key */
|
|
15
|
+
key: string;
|
|
16
|
+
/** 显示名称 */
|
|
17
|
+
label: string;
|
|
18
|
+
/** 渲染位置 */
|
|
19
|
+
placement: 'overlay' | 'pane';
|
|
20
|
+
/** 副图高度比例(仅pane,默认0.2) */
|
|
21
|
+
paneHeightRatio?: number;
|
|
22
|
+
/** 线条定义 */
|
|
23
|
+
lines: IndicatorLineSpec[];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** 指标线条渲染定义 */
|
|
27
|
+
export interface IndicatorLineSpec {
|
|
28
|
+
/** 数据字段名(对应 indicatorData 中的 key) */
|
|
29
|
+
field: string;
|
|
30
|
+
/** 显示名称 */
|
|
31
|
+
label: string;
|
|
32
|
+
/** 渲染类型 */
|
|
33
|
+
type: 'line' | 'histogram' | 'area';
|
|
34
|
+
/** 颜色 */
|
|
35
|
+
color: string;
|
|
36
|
+
/** 线宽(默认1) */
|
|
37
|
+
lineWidth?: number;
|
|
38
|
+
/** 柱状图正值颜色(仅 histogram) */
|
|
39
|
+
positiveColor?: string;
|
|
40
|
+
/** 柱状图负值颜色(仅 histogram) */
|
|
41
|
+
negativeColor?: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** K线 + 指标合并数据响应(后端可在 ChartFetchResult 中附带) */
|
|
45
|
+
export interface ChartDataWithIndicators {
|
|
46
|
+
/** K线数据 */
|
|
47
|
+
candlesticks: import('./series.js').CandlestickRawData[];
|
|
48
|
+
/** 指标渲染描述列表 */
|
|
49
|
+
indicatorSpecs?: IndicatorRenderSpec[];
|
|
50
|
+
/** 指标数据,key 对应 IndicatorRenderSpec.key */
|
|
51
|
+
indicatorData?: Record<string, Array<{
|
|
52
|
+
time: number;
|
|
53
|
+
values: Record<string, number>;
|
|
54
|
+
}>>;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** 指标显示类型 */
|
|
58
|
+
export enum IndicatorType {
|
|
59
|
+
Overlay = 'overlay', // 主图叠加
|
|
60
|
+
Pane = 'pane', // 副图(独立面板)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* 指标显示类型(v2新架构)
|
|
65
|
+
*/
|
|
66
|
+
export enum IndicatorDisplayType {
|
|
67
|
+
/** 主图叠加(如MA、EMA、BOLL) */
|
|
68
|
+
Overlay = 'overlay',
|
|
69
|
+
/** 主图背景(如成交量Volume) */
|
|
70
|
+
Background = 'background',
|
|
71
|
+
/** 副图指标(如MACD、RSI、KDJ) */
|
|
72
|
+
Pane = 'pane',
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* 单条指标线定义(v2新架构)
|
|
77
|
+
* 一个指标(如MACD)可能包含多条线(DIF、DEA、MACD柱)
|
|
78
|
+
*/
|
|
79
|
+
export interface IndicatorLineDef {
|
|
80
|
+
/** 线的唯一key(如 'dif', 'dea', 'macd') */
|
|
81
|
+
key: string;
|
|
82
|
+
/** 显示名称(如 'DIF') */
|
|
83
|
+
label: string;
|
|
84
|
+
/** 该线的数据在data二维数组的每行中的列索引 */
|
|
85
|
+
dataIndex: number;
|
|
86
|
+
/** 渲染类型 */
|
|
87
|
+
renderType: 'line' | 'histogram' | 'area';
|
|
88
|
+
/** 默认颜色 */
|
|
89
|
+
color: string;
|
|
90
|
+
/** 线宽(默认1) */
|
|
91
|
+
lineWidth?: number;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* 指标元信息(v2新架构)
|
|
96
|
+
*/
|
|
97
|
+
export interface IndicatorMeta {
|
|
98
|
+
/** 指标唯一标识(如 'MACD') */
|
|
99
|
+
key: string;
|
|
100
|
+
/** 显示名称(如 'MACD(12,26,9)') */
|
|
101
|
+
label: string;
|
|
102
|
+
/** 显示类型:主图叠加 / 主图背景 / 副图 */
|
|
103
|
+
displayType: IndicatorDisplayType;
|
|
104
|
+
/** 该指标包含的所有线 */
|
|
105
|
+
lines: IndicatorLineDef[];
|
|
106
|
+
/** 指标参数 */
|
|
107
|
+
params?: Record<string, number>;
|
|
108
|
+
/** 副图高度占比(仅displayType=pane时生效,默认0.2 = 20%) */
|
|
109
|
+
paneHeightRatio?: number;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* 图表数据响应(v2新架构)
|
|
114
|
+
* 后端计算所有指标,前端只渲染
|
|
115
|
+
*/
|
|
116
|
+
export interface ChartDataResponse {
|
|
117
|
+
/** K线时间戳数组(毫秒) */
|
|
118
|
+
timestamps: number[];
|
|
119
|
+
/** 二维数据数组:每行是一个时间点的所有值 */
|
|
120
|
+
data: number[][];
|
|
121
|
+
/** 指标元信息列表 */
|
|
122
|
+
indicators: IndicatorMeta[];
|
|
123
|
+
/** 默认OHLC在data行中的列索引 */
|
|
124
|
+
ohlcIndex: {
|
|
125
|
+
open: number;
|
|
126
|
+
high: number;
|
|
127
|
+
low: number;
|
|
128
|
+
close: number;
|
|
129
|
+
volume: number;
|
|
130
|
+
};
|
|
131
|
+
/** 数据版本(2=新格式,缺省或1=旧格式) */
|
|
132
|
+
version?: number;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* 后端返回的指标列表项模板
|
|
137
|
+
*/
|
|
138
|
+
export interface IndicatorTemplate {
|
|
139
|
+
/** 指标唯一标识 */
|
|
140
|
+
key: string;
|
|
141
|
+
/** 显示名称 */
|
|
142
|
+
label: string;
|
|
143
|
+
/** 简短描述 */
|
|
144
|
+
description: string;
|
|
145
|
+
/** 显示类型 */
|
|
146
|
+
displayType: IndicatorDisplayType;
|
|
147
|
+
/** 分类(如 '趋势', '震荡', '成交量', '通道') */
|
|
148
|
+
category: string;
|
|
149
|
+
/** 默认参数 */
|
|
150
|
+
defaultParams: Record<string, number>;
|
|
151
|
+
/** 参数定义(用户可调整) */
|
|
152
|
+
paramDefs: IndicatorParamDef[];
|
|
153
|
+
/** 包含的线条定义 */
|
|
154
|
+
lines: IndicatorLineDef[];
|
|
155
|
+
/** 默认副图高度比例(仅pane类型) */
|
|
156
|
+
paneHeightRatio?: number;
|
|
157
|
+
/** 是否内置(vs自定义) */
|
|
158
|
+
builtin: boolean;
|
|
159
|
+
/** 图标(emoji或CSS class) */
|
|
160
|
+
icon?: string;
|
|
161
|
+
/** 排序权重 */
|
|
162
|
+
sortOrder?: number;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* 后端返回的指标列表响应
|
|
167
|
+
*/
|
|
168
|
+
export interface IndicatorListResponse {
|
|
169
|
+
/** 可用指标列表 */
|
|
170
|
+
indicators: IndicatorTemplate[];
|
|
171
|
+
/** 用户已添加的指标(上次会话状态) */
|
|
172
|
+
activeIndicators?: ActiveIndicatorConfig[];
|
|
173
|
+
/** 指标分类列表(用于面板分类筛选) */
|
|
174
|
+
categories?: string[];
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* 用户激活的指标配置
|
|
179
|
+
*/
|
|
180
|
+
export interface ActiveIndicatorConfig {
|
|
181
|
+
/** 对应IndicatorTemplate.key */
|
|
182
|
+
key: string;
|
|
183
|
+
/** 用户自定义参数(覆盖defaultParams) */
|
|
184
|
+
params: Record<string, number>;
|
|
185
|
+
/** 是否可见 */
|
|
186
|
+
visible: boolean;
|
|
187
|
+
/** 用户自定义样式(覆盖lines中的默认颜色) */
|
|
188
|
+
styleOverrides?: Record<string, string>;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/** 指标参数定义 */
|
|
192
|
+
export interface IndicatorParamDef {
|
|
193
|
+
name: string;
|
|
194
|
+
label: string;
|
|
195
|
+
defaultValue: number;
|
|
196
|
+
min?: number;
|
|
197
|
+
max?: number;
|
|
198
|
+
step?: number;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/** 活跃指标配置 */
|
|
202
|
+
export interface IndicatorConfig {
|
|
203
|
+
id: string;
|
|
204
|
+
name: string;
|
|
205
|
+
label: string;
|
|
206
|
+
type: IndicatorType;
|
|
207
|
+
params: Record<string, number>;
|
|
208
|
+
visible: boolean;
|
|
209
|
+
color?: string;
|
|
210
|
+
seriesIds: string[];
|
|
211
|
+
paneIndex?: number;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/** 指标数据响应(API返回) */
|
|
215
|
+
export interface IndicatorDataResponse {
|
|
216
|
+
name: string;
|
|
217
|
+
params: Record<string, number>;
|
|
218
|
+
data: IndicatorDataPoint[];
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/** 单条指标数据 */
|
|
222
|
+
export interface IndicatorDataPoint {
|
|
223
|
+
time: number; // 毫秒时间戳
|
|
224
|
+
values: Record<string, number>;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/** 指标定义(注册表) */
|
|
228
|
+
export interface IndicatorDefinition {
|
|
229
|
+
name: string;
|
|
230
|
+
label: string;
|
|
231
|
+
type: IndicatorType;
|
|
232
|
+
defaultParams: Record<string, number>;
|
|
233
|
+
paramDefs: IndicatorParamDef[];
|
|
234
|
+
description: string;
|
|
235
|
+
colors: string[];
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/** 内置指标定义 */
|
|
239
|
+
export const BUILTIN_INDICATORS: IndicatorDefinition[] = [
|
|
240
|
+
// === 主图叠加指标 ===
|
|
241
|
+
{
|
|
242
|
+
name: 'MA',
|
|
243
|
+
label: 'MA 移动平均线',
|
|
244
|
+
type: IndicatorType.Overlay,
|
|
245
|
+
defaultParams: { period: 5 },
|
|
246
|
+
paramDefs: [
|
|
247
|
+
{ name: 'period', label: '周期', defaultValue: 5, min: 2, max: 500, step: 1 },
|
|
248
|
+
],
|
|
249
|
+
description: '简单移动平均线',
|
|
250
|
+
colors: ['#FF6D00'],
|
|
251
|
+
},
|
|
252
|
+
{
|
|
253
|
+
name: 'EMA',
|
|
254
|
+
label: 'EMA 指数移动平均线',
|
|
255
|
+
type: IndicatorType.Overlay,
|
|
256
|
+
defaultParams: { period: 12 },
|
|
257
|
+
paramDefs: [
|
|
258
|
+
{ name: 'period', label: '周期', defaultValue: 12, min: 2, max: 500, step: 1 },
|
|
259
|
+
],
|
|
260
|
+
description: '指数移动平均线',
|
|
261
|
+
colors: ['#2962FF'],
|
|
262
|
+
},
|
|
263
|
+
{
|
|
264
|
+
name: 'BOLL',
|
|
265
|
+
label: 'BOLL 布林带',
|
|
266
|
+
type: IndicatorType.Overlay,
|
|
267
|
+
defaultParams: { period: 20, stdDev: 2 },
|
|
268
|
+
paramDefs: [
|
|
269
|
+
{ name: 'period', label: '周期', defaultValue: 20, min: 2, max: 200, step: 1 },
|
|
270
|
+
{ name: 'stdDev', label: '标准差倍数', defaultValue: 2, min: 0.5, max: 5, step: 0.1 },
|
|
271
|
+
],
|
|
272
|
+
description: '布林带指标',
|
|
273
|
+
colors: ['#FF6D00', '#2962FF', '#FF6D00'],
|
|
274
|
+
},
|
|
275
|
+
// === 副图指标 ===
|
|
276
|
+
{
|
|
277
|
+
name: 'MACD',
|
|
278
|
+
label: 'MACD 指数平滑异同',
|
|
279
|
+
type: IndicatorType.Pane,
|
|
280
|
+
defaultParams: { fastPeriod: 12, slowPeriod: 26, signalPeriod: 9 },
|
|
281
|
+
paramDefs: [
|
|
282
|
+
{ name: 'fastPeriod', label: '快线周期', defaultValue: 12, min: 2, max: 100, step: 1 },
|
|
283
|
+
{ name: 'slowPeriod', label: '慢线周期', defaultValue: 26, min: 2, max: 200, step: 1 },
|
|
284
|
+
{ name: 'signalPeriod', label: '信号线周期', defaultValue: 9, min: 2, max: 100, step: 1 },
|
|
285
|
+
],
|
|
286
|
+
description: 'MACD指标',
|
|
287
|
+
colors: ['#2962FF', '#FF6D00', '#26a69a'],
|
|
288
|
+
},
|
|
289
|
+
{
|
|
290
|
+
name: 'RSI',
|
|
291
|
+
label: 'RSI 相对强弱指标',
|
|
292
|
+
type: IndicatorType.Pane,
|
|
293
|
+
defaultParams: { period: 14 },
|
|
294
|
+
paramDefs: [
|
|
295
|
+
{ name: 'period', label: '周期', defaultValue: 14, min: 2, max: 100, step: 1 },
|
|
296
|
+
],
|
|
297
|
+
description: '相对强弱指标',
|
|
298
|
+
colors: ['#AB47BC'],
|
|
299
|
+
},
|
|
300
|
+
{
|
|
301
|
+
name: 'KDJ',
|
|
302
|
+
label: 'KDJ 随机指标',
|
|
303
|
+
type: IndicatorType.Pane,
|
|
304
|
+
defaultParams: { kPeriod: 9, dPeriod: 3, jPeriod: 3 },
|
|
305
|
+
paramDefs: [
|
|
306
|
+
{ name: 'kPeriod', label: 'K周期', defaultValue: 9, min: 2, max: 100, step: 1 },
|
|
307
|
+
{ name: 'dPeriod', label: 'D周期', defaultValue: 3, min: 2, max: 50, step: 1 },
|
|
308
|
+
{ name: 'jPeriod', label: 'J周期', defaultValue: 3, min: 2, max: 50, step: 1 },
|
|
309
|
+
],
|
|
310
|
+
description: 'KDJ随机指标',
|
|
311
|
+
colors: ['#FFFFFF', '#FFFF00', '#FF00FF'],
|
|
312
|
+
},
|
|
313
|
+
{
|
|
314
|
+
name: 'CCI',
|
|
315
|
+
label: 'CCI 商品通道指标',
|
|
316
|
+
type: IndicatorType.Pane,
|
|
317
|
+
defaultParams: { period: 14 },
|
|
318
|
+
paramDefs: [
|
|
319
|
+
{ name: 'period', label: '周期', defaultValue: 14, min: 2, max: 100, step: 1 },
|
|
320
|
+
],
|
|
321
|
+
description: '商品通道指标',
|
|
322
|
+
colors: ['#00E676'],
|
|
323
|
+
},
|
|
324
|
+
{
|
|
325
|
+
name: 'ATR',
|
|
326
|
+
label: 'ATR 真实波幅',
|
|
327
|
+
type: IndicatorType.Pane,
|
|
328
|
+
defaultParams: { period: 14 },
|
|
329
|
+
paramDefs: [
|
|
330
|
+
{ name: 'period', label: '周期', defaultValue: 14, min: 2, max: 100, step: 1 },
|
|
331
|
+
],
|
|
332
|
+
description: '平均真实波幅',
|
|
333
|
+
colors: ['#FF9800'],
|
|
334
|
+
},
|
|
335
|
+
{
|
|
336
|
+
name: 'OBV',
|
|
337
|
+
label: 'OBV 能量潮',
|
|
338
|
+
type: IndicatorType.Pane,
|
|
339
|
+
defaultParams: {},
|
|
340
|
+
paramDefs: [],
|
|
341
|
+
description: '能量潮指标',
|
|
342
|
+
colors: ['#26a69a'],
|
|
343
|
+
},
|
|
344
|
+
];
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/** 序列类型枚举 */
|
|
2
|
+
export enum SeriesType {
|
|
3
|
+
Candlestick = 'candlestick',
|
|
4
|
+
Bar = 'bar',
|
|
5
|
+
Line = 'line',
|
|
6
|
+
Area = 'area',
|
|
7
|
+
Baseline = 'baseline',
|
|
8
|
+
Histogram = 'histogram',
|
|
9
|
+
// 自定义类型
|
|
10
|
+
HollowCandlestick = 'hollow-candlestick',
|
|
11
|
+
VolumeCandlestick = 'volume-candlestick',
|
|
12
|
+
HeikinAshi = 'heikin-ashi',
|
|
13
|
+
Renko = 'renko',
|
|
14
|
+
LineBreak = 'line-break',
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** K线数据(API返回的原始格式) */
|
|
18
|
+
export interface CandlestickRawData {
|
|
19
|
+
time: number; // 毫秒时间戳
|
|
20
|
+
open: number;
|
|
21
|
+
high: number;
|
|
22
|
+
low: number;
|
|
23
|
+
close: number;
|
|
24
|
+
volume?: number;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** LWC K线数据 */
|
|
28
|
+
export interface CandlestickData {
|
|
29
|
+
time: number; // 秒级时间戳
|
|
30
|
+
open: number;
|
|
31
|
+
high: number;
|
|
32
|
+
low: number;
|
|
33
|
+
close: number;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** LWC 成交量数据 */
|
|
37
|
+
export interface HistogramData {
|
|
38
|
+
time: number;
|
|
39
|
+
value: number;
|
|
40
|
+
color?: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** LWC 线数据 */
|
|
44
|
+
export interface LineData {
|
|
45
|
+
time: number;
|
|
46
|
+
value: number;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** 指标数据(API返回) */
|
|
50
|
+
export interface IndicatorRawData {
|
|
51
|
+
time: number; // 毫秒时间戳
|
|
52
|
+
value: number;
|
|
53
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { DeepPartial } from 'lightweight-charts';
|
|
2
|
+
|
|
3
|
+
/** 图表主题选项(映射到LWC的theme相关选项) */
|
|
4
|
+
export interface ChartThemeOptions {
|
|
5
|
+
layout: {
|
|
6
|
+
background: { color: string };
|
|
7
|
+
textColor: string;
|
|
8
|
+
};
|
|
9
|
+
grid: {
|
|
10
|
+
vertLines: { color: string };
|
|
11
|
+
horzLines: { color: string };
|
|
12
|
+
};
|
|
13
|
+
crosshair?: {
|
|
14
|
+
mode?: number; // CrosshairMode.Normal = 0, CrosshairMode.Magnet = 1
|
|
15
|
+
vertLine?: { color?: string; labelBackgroundColor?: string };
|
|
16
|
+
horzLine?: { color?: string; labelBackgroundColor?: string };
|
|
17
|
+
};
|
|
18
|
+
/** ★ V3: 时间格式化配置 */
|
|
19
|
+
localization?: {
|
|
20
|
+
timeFormatter?: (time: import('lightweight-charts').Time) => string;
|
|
21
|
+
dateFormat?: string;
|
|
22
|
+
};
|
|
23
|
+
/** ★ V3: 时间轴配置 */
|
|
24
|
+
timeScale?: {
|
|
25
|
+
timeVisible?: boolean;
|
|
26
|
+
secondsVisible?: boolean;
|
|
27
|
+
tickMarkFormatter?: (time: import('lightweight-charts').Time, tickMarkType: number, locale: string) => string;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** 主题预设名称 */
|
|
32
|
+
export type ThemePreset = 'dark' | 'light';
|
|
33
|
+
|
|
34
|
+
/** 主题配置 */
|
|
35
|
+
export interface ThemeConfig {
|
|
36
|
+
name: ThemePreset;
|
|
37
|
+
chart: ChartThemeOptions;
|
|
38
|
+
/** 涨色 */
|
|
39
|
+
upColor: string;
|
|
40
|
+
/** 跌色 */
|
|
41
|
+
downColor: string;
|
|
42
|
+
/** 工具栏背景色 */
|
|
43
|
+
toolbarBg: string;
|
|
44
|
+
/** 工具栏文字色 */
|
|
45
|
+
toolbarText: string;
|
|
46
|
+
/** 工具栏按钮激活色 */
|
|
47
|
+
toolbarActiveBg: string;
|
|
48
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { UTCTimestamp } from 'lightweight-charts';
|
|
2
|
+
import type {
|
|
3
|
+
CandlestickRawData,
|
|
4
|
+
IndicatorRawData,
|
|
5
|
+
} from '../types/index.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 将API返回的K线原始数据转换为LWC CandlestickData[]
|
|
9
|
+
* 注意:time从毫秒转秒
|
|
10
|
+
*/
|
|
11
|
+
export function transformCandlestickData(apiData: CandlestickRawData[]) {
|
|
12
|
+
return apiData
|
|
13
|
+
.map((item) => ({
|
|
14
|
+
time: (item.time / 1000) as UTCTimestamp,
|
|
15
|
+
open: item.open,
|
|
16
|
+
high: item.high,
|
|
17
|
+
low: item.low,
|
|
18
|
+
close: item.close,
|
|
19
|
+
}))
|
|
20
|
+
.sort((a, b) => (a.time as number) - (b.time as number));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* 将API返回的K线数据转换为LWC HistogramData[](成交量)
|
|
25
|
+
* 涨绿跌红
|
|
26
|
+
*/
|
|
27
|
+
export function transformVolumeData(apiData: CandlestickRawData[]) {
|
|
28
|
+
return apiData
|
|
29
|
+
.map((item) => ({
|
|
30
|
+
time: (item.time / 1000) as UTCTimestamp,
|
|
31
|
+
value: item.volume ?? 0,
|
|
32
|
+
color: item.close >= item.open ? 'rgba(38, 166, 154, 0.35)' : 'rgba(239, 83, 80, 0.35)',
|
|
33
|
+
}))
|
|
34
|
+
.sort((a, b) => (a.time as number) - (b.time as number));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* 将API返回的K线数据转换为VolumeCandlestickData[](含volume字段)
|
|
39
|
+
*/
|
|
40
|
+
export function transformVolumeCandlestickData(apiData: CandlestickRawData[]) {
|
|
41
|
+
return apiData
|
|
42
|
+
.map((item) => ({
|
|
43
|
+
time: (item.time / 1000) as UTCTimestamp,
|
|
44
|
+
open: item.open,
|
|
45
|
+
high: item.high,
|
|
46
|
+
low: item.low,
|
|
47
|
+
close: item.close,
|
|
48
|
+
volume: item.volume ?? 0,
|
|
49
|
+
}))
|
|
50
|
+
.sort((a, b) => (a.time as number) - (b.time as number));
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* 将API返回的指标数据转换为LWC LineData[]
|
|
55
|
+
*/
|
|
56
|
+
export function transformIndicatorData(apiData: IndicatorRawData[]) {
|
|
57
|
+
return apiData
|
|
58
|
+
.map((item) => ({
|
|
59
|
+
time: (item.time / 1000) as UTCTimestamp,
|
|
60
|
+
value: item.value,
|
|
61
|
+
}))
|
|
62
|
+
.sort((a, b) => (a.time as number) - (b.time as number));
|
|
63
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 平均K线(Heikin Ashi)数据预处理
|
|
3
|
+
* HA只是OHLC值的重计算,渲染逻辑复用CandlestickSeries
|
|
4
|
+
*/
|
|
5
|
+
import type { CandlestickData } from '../types/index.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 将标准K线数据转换为平均K线
|
|
9
|
+
* 算法:
|
|
10
|
+
* HA_CLOSE = (open + high + low + close) / 4
|
|
11
|
+
* HA_OPEN = (prev_HA_open + prev_HA_close) / 2
|
|
12
|
+
* HA_HIGH = max(high, HA_open, HA_close)
|
|
13
|
+
* HA_LOW = min(low, HA_open, HA_close)
|
|
14
|
+
*/
|
|
15
|
+
export function transformToHeikinAshi(data: CandlestickData[]): CandlestickData[] {
|
|
16
|
+
if (data.length === 0) return [];
|
|
17
|
+
|
|
18
|
+
const result: CandlestickData[] = [];
|
|
19
|
+
let prevOpen = data[0].open;
|
|
20
|
+
let prevClose = data[0].close;
|
|
21
|
+
|
|
22
|
+
for (const bar of data) {
|
|
23
|
+
const haClose = (bar.open + bar.high + bar.low + bar.close) / 4;
|
|
24
|
+
const haOpen = (prevOpen + prevClose) / 2;
|
|
25
|
+
const haHigh = Math.max(bar.high, haOpen, haClose);
|
|
26
|
+
const haLow = Math.min(bar.low, haOpen, haClose);
|
|
27
|
+
|
|
28
|
+
result.push({
|
|
29
|
+
time: bar.time,
|
|
30
|
+
open: haOpen,
|
|
31
|
+
high: haHigh,
|
|
32
|
+
low: haLow,
|
|
33
|
+
close: haClose,
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
prevOpen = haOpen;
|
|
37
|
+
prevClose = haClose;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return result;
|
|
41
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { transformCandlestickData, transformVolumeData, transformIndicatorData } from './dataTransformer.js';
|
|
2
|
+
export { darkPreset, lightPreset } from './themePresets.js';
|
|
3
|
+
export { getPeriodInterval, generateFutureWhitespace, calcFuturePointCount } from './timeScaleUtils.js';
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 线形反转(Line Break)数据预处理
|
|
3
|
+
* 三线反转算法输出为标准 CandlestickData 格式,复用 CandlestickSeries 渲染
|
|
4
|
+
*/
|
|
5
|
+
import type { CandlestickData } from '../types/index.js';
|
|
6
|
+
|
|
7
|
+
interface LineBreakBar {
|
|
8
|
+
time: number;
|
|
9
|
+
open: number;
|
|
10
|
+
high: number;
|
|
11
|
+
low: number;
|
|
12
|
+
close: number;
|
|
13
|
+
direction: 'up' | 'down';
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* 将标准K线数据转换为线形反转数据
|
|
18
|
+
*
|
|
19
|
+
* @param data 原始K线数据
|
|
20
|
+
* @param period 反转周期(默认3线反转)
|
|
21
|
+
*/
|
|
22
|
+
export function transformToLineBreak(
|
|
23
|
+
data: CandlestickData[],
|
|
24
|
+
period: number = 3,
|
|
25
|
+
): CandlestickData[] {
|
|
26
|
+
if (data.length < period) return data;
|
|
27
|
+
|
|
28
|
+
const lines: LineBreakBar[] = [];
|
|
29
|
+
|
|
30
|
+
// 初始化:前N根直接作为初始线
|
|
31
|
+
for (let i = 0; i < period; i++) {
|
|
32
|
+
const bar = data[i];
|
|
33
|
+
const direction: 'up' | 'down' = bar.close >= bar.open ? 'up' : 'down';
|
|
34
|
+
lines.push({
|
|
35
|
+
time: bar.time,
|
|
36
|
+
open: bar.open,
|
|
37
|
+
high: bar.high,
|
|
38
|
+
low: bar.low,
|
|
39
|
+
close: bar.close,
|
|
40
|
+
direction,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// 从第N根开始应用线形反转规则
|
|
45
|
+
for (let i = period; i < data.length; i++) {
|
|
46
|
+
const bar = data[i];
|
|
47
|
+
const recentLines = lines.slice(-period);
|
|
48
|
+
|
|
49
|
+
if (bar.close > Math.max(...recentLines.map(l => l.high))) {
|
|
50
|
+
// 突破最高点 → 上涨线
|
|
51
|
+
const prevLine = lines[lines.length - 1];
|
|
52
|
+
lines.push({
|
|
53
|
+
time: bar.time,
|
|
54
|
+
open: prevLine.close,
|
|
55
|
+
high: bar.high,
|
|
56
|
+
low: Math.min(bar.low, prevLine.close),
|
|
57
|
+
close: bar.close,
|
|
58
|
+
direction: 'up',
|
|
59
|
+
});
|
|
60
|
+
} else if (bar.close < Math.min(...recentLines.map(l => l.low))) {
|
|
61
|
+
// 跌破最低点 → 下跌线
|
|
62
|
+
const prevLine = lines[lines.length - 1];
|
|
63
|
+
lines.push({
|
|
64
|
+
time: bar.time,
|
|
65
|
+
open: prevLine.close,
|
|
66
|
+
high: Math.max(bar.high, prevLine.close),
|
|
67
|
+
low: bar.low,
|
|
68
|
+
close: bar.close,
|
|
69
|
+
direction: 'down',
|
|
70
|
+
});
|
|
71
|
+
} else {
|
|
72
|
+
// 未突破 → 延续上一根线的方向,更新close
|
|
73
|
+
const lastLine = lines[lines.length - 1];
|
|
74
|
+
lastLine.close = bar.close;
|
|
75
|
+
lastLine.high = Math.max(lastLine.high, bar.high);
|
|
76
|
+
lastLine.low = Math.min(lastLine.low, bar.low);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// 转换为 CandlestickData 格式
|
|
81
|
+
return lines.map(l => ({
|
|
82
|
+
time: l.time,
|
|
83
|
+
open: l.open,
|
|
84
|
+
high: l.high,
|
|
85
|
+
low: l.low,
|
|
86
|
+
close: l.close,
|
|
87
|
+
}));
|
|
88
|
+
}
|