@363045841yyt/klinechart-core 0.8.2 → 0.8.4
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/dist/controllers/createChartController.d.ts +1 -1
- package/dist/controllers/createChartController.d.ts.map +1 -1
- package/dist/controllers/createChartController.js +34 -1
- package/dist/controllers/createChartController.js.map +1 -1
- package/dist/controllers/index.d.ts +1 -0
- package/dist/controllers/index.d.ts.map +1 -1
- package/dist/controllers/index.js +1 -0
- package/dist/controllers/index.js.map +1 -1
- package/dist/controllers/types.d.ts +17 -1
- package/dist/controllers/types.d.ts.map +1 -1
- package/dist/data-fetchers/baostock.d.ts +9 -2
- package/dist/data-fetchers/baostock.d.ts.map +1 -1
- package/dist/data-fetchers/baostock.js +78 -9
- package/dist/data-fetchers/baostock.js.map +1 -1
- package/dist/data-fetchers/fetcherDefinitionRegistry.d.ts +13 -0
- package/dist/data-fetchers/fetcherDefinitionRegistry.d.ts.map +1 -0
- package/dist/data-fetchers/fetcherDefinitionRegistry.js +36 -0
- package/dist/data-fetchers/fetcherDefinitionRegistry.js.map +1 -0
- package/dist/data-fetchers/gotdx.d.ts +9 -2
- package/dist/data-fetchers/gotdx.d.ts.map +1 -1
- package/dist/data-fetchers/gotdx.js +72 -5
- package/dist/data-fetchers/gotdx.js.map +1 -1
- package/dist/data-fetchers/hundred-mock.d.ts +9 -2
- package/dist/data-fetchers/hundred-mock.d.ts.map +1 -1
- package/dist/data-fetchers/hundred-mock.js +66 -4
- package/dist/data-fetchers/hundred-mock.js.map +1 -1
- package/dist/data-fetchers/index.d.ts +7 -5
- package/dist/data-fetchers/index.d.ts.map +1 -1
- package/dist/data-fetchers/index.js +6 -5
- package/dist/data-fetchers/index.js.map +1 -1
- package/dist/data-fetchers/router.d.ts.map +1 -1
- package/dist/data-fetchers/router.js +14 -18
- package/dist/data-fetchers/router.js.map +1 -1
- package/dist/data-fetchers/thousand-mock.d.ts +9 -2
- package/dist/data-fetchers/thousand-mock.d.ts.map +1 -1
- package/dist/data-fetchers/thousand-mock.js +66 -4
- package/dist/data-fetchers/thousand-mock.js.map +1 -1
- package/dist/data-fetchers/tradingview.d.ts +9 -2
- package/dist/data-fetchers/tradingview.d.ts.map +1 -1
- package/dist/data-fetchers/tradingview.js +73 -9
- package/dist/data-fetchers/tradingview.js.map +1 -1
- package/dist/data-fetchers/types.d.ts +21 -0
- package/dist/data-fetchers/types.d.ts.map +1 -0
- package/dist/data-fetchers/types.js +2 -0
- package/dist/data-fetchers/types.js.map +1 -0
- package/dist/engine/indicators/registerBuiltins.d.ts +2 -40
- package/dist/engine/indicators/registerBuiltins.d.ts.map +1 -1
- package/dist/engine/indicators/registerBuiltins.js +55 -42
- package/dist/engine/indicators/registerBuiltins.js.map +1 -1
- package/dist/engine/renderers/Indicator/ichimoku.d.ts.map +1 -1
- package/dist/engine/renderers/Indicator/ichimoku.js +8 -5
- package/dist/engine/renderers/Indicator/ichimoku.js.map +1 -1
- package/dist/engine/renderers/Indicator/index.d.ts +0 -39
- package/dist/engine/renderers/Indicator/index.d.ts.map +1 -1
- package/dist/engine/renderers/Indicator/index.js +0 -78
- package/dist/engine/renderers/Indicator/index.js.map +1 -1
- package/dist/engine/renderers/Indicator/indicatorCatalog.d.ts +1 -3
- package/dist/engine/renderers/Indicator/indicatorCatalog.d.ts.map +1 -1
- package/dist/engine/renderers/Indicator/indicatorCatalog.js +27 -17
- package/dist/engine/renderers/Indicator/indicatorCatalog.js.map +1 -1
- package/dist/engine/renderers/Indicator/sar.d.ts.map +1 -1
- package/dist/engine/renderers/Indicator/sar.js +3 -3
- package/dist/engine/renderers/Indicator/sar.js.map +1 -1
- package/dist/engine/renderers/Indicator/supertrend.d.ts.map +1 -1
- package/dist/engine/renderers/Indicator/supertrend.js +3 -3
- package/dist/engine/renderers/Indicator/supertrend.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/mcp/chartBridge.d.ts +47 -0
- package/dist/mcp/chartBridge.d.ts.map +1 -0
- package/dist/mcp/chartBridge.js +167 -0
- package/dist/mcp/chartBridge.js.map +1 -0
- package/dist/mcp/index.d.ts +3 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +2 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/mcp/types.d.ts +17 -0
- package/dist/mcp/types.d.ts.map +1 -0
- package/dist/mcp/types.js +2 -0
- package/dist/mcp/types.js.map +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/src/controllers/createChartController.ts +38 -1
- package/src/controllers/index.ts +1 -0
- package/src/controllers/types.ts +10 -1
- package/src/data-fetchers/__tests__/fetcherRegistry.test.ts +192 -0
- package/src/data-fetchers/baostock.ts +54 -22
- package/src/data-fetchers/fetcherDefinitionRegistry.ts +50 -0
- package/src/data-fetchers/gotdx.ts +28 -6
- package/src/data-fetchers/hundred-mock.ts +21 -4
- package/src/data-fetchers/index.ts +19 -5
- package/src/data-fetchers/router.ts +27 -18
- package/src/data-fetchers/thousand-mock.ts +21 -4
- package/src/data-fetchers/tradingview.ts +30 -11
- package/src/data-fetchers/types.ts +27 -0
- package/src/engine/__tests__/chart.dpr.test.ts +6 -1
- package/src/engine/indicators/__tests__/chartIndicatorManager.test.ts +6 -1
- package/src/engine/indicators/__tests__/registerBuiltins.test.ts +6 -2
- package/src/engine/indicators/__tests__/scheduler.test.ts +8 -3
- package/src/engine/indicators/__tests__/stateComposer.test.ts +6 -2
- package/src/engine/indicators/registerBuiltins.ts +58 -42
- package/src/engine/renderers/Indicator/__tests__/createSubIndicatorRenderer.test.ts +6 -2
- package/src/engine/renderers/Indicator/ichimoku.ts +10 -4
- package/src/engine/renderers/Indicator/index.ts +0 -92
- package/src/engine/renderers/Indicator/indicatorCatalog.ts +28 -19
- package/src/engine/renderers/Indicator/sar.ts +3 -3
- package/src/engine/renderers/Indicator/supertrend.ts +3 -4
- package/src/index.ts +1 -0
- package/src/mcp/chartBridge.ts +220 -0
- package/src/mcp/index.ts +2 -0
- package/src/mcp/types.ts +19 -0
- package/src/version.ts +1 -1
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { KLineData } from '../controllers/types'
|
|
2
|
+
|
|
3
|
+
export type FetchConfig = {
|
|
4
|
+
symbol: string
|
|
5
|
+
startDate: string
|
|
6
|
+
endDate: string
|
|
7
|
+
period: string
|
|
8
|
+
adjust: string
|
|
9
|
+
exchange?: string
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export type DataFetcherFn = (
|
|
13
|
+
source: string,
|
|
14
|
+
config: FetchConfig,
|
|
15
|
+
) => Promise<ReadonlyArray<KLineData>>
|
|
16
|
+
|
|
17
|
+
export interface DataFetcherDefinitionConfig {
|
|
18
|
+
name: string
|
|
19
|
+
displayName: string
|
|
20
|
+
description?: string
|
|
21
|
+
version?: string
|
|
22
|
+
capabilities?: string[]
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface DataFetcherDefinition extends DataFetcherDefinitionConfig {
|
|
26
|
+
fetcher: DataFetcherFn
|
|
27
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// @vitest-environment jsdom
|
|
2
|
-
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
2
|
+
import { afterEach, beforeEach, beforeAll, describe, expect, it, vi } from 'vitest'
|
|
3
3
|
import { Chart, type ChartDom, type ChartOptions } from '@/core/chart'
|
|
4
|
+
import { loadBuiltinIndicators } from '../indicators/registerBuiltins'
|
|
4
5
|
|
|
5
6
|
class ResizeObserverMock {
|
|
6
7
|
static instances: ResizeObserverMock[] = []
|
|
@@ -106,6 +107,10 @@ describe('Chart DPR pipeline', () => {
|
|
|
106
107
|
const originalDevicePixelRatio = window.devicePixelRatio
|
|
107
108
|
const originalGetContext = HTMLCanvasElement.prototype.getContext
|
|
108
109
|
|
|
110
|
+
beforeAll(async () => {
|
|
111
|
+
await loadBuiltinIndicators()
|
|
112
|
+
})
|
|
113
|
+
|
|
109
114
|
beforeEach(() => {
|
|
110
115
|
ResizeObserverMock.reset()
|
|
111
116
|
globalThis.ResizeObserver = ResizeObserverMock as unknown as typeof ResizeObserver
|
|
@@ -1,9 +1,14 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
|
1
|
+
import { describe, it, expect, vi, beforeAll, beforeEach } from 'vitest'
|
|
2
2
|
import { ChartIndicatorManager, type IndicatorDependencies } from '../chartIndicatorManager'
|
|
3
3
|
import { createPluginHost } from '../../../plugin/PluginHost'
|
|
4
4
|
import { createSignal } from '../../../reactivity/signal'
|
|
5
5
|
import type { VisibleRange } from '../../layout/pane'
|
|
6
6
|
import { UpdateLevel } from '../../layout/pane'
|
|
7
|
+
import { loadBuiltinIndicators } from '../registerBuiltins'
|
|
8
|
+
|
|
9
|
+
beforeAll(async () => {
|
|
10
|
+
await loadBuiltinIndicators()
|
|
11
|
+
})
|
|
7
12
|
|
|
8
13
|
function createMockDeps() {
|
|
9
14
|
const rendererMap = new Map<string, any>()
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
import { describe, expect, it, vi } from 'vitest'
|
|
1
|
+
import { describe, expect, it, vi, beforeAll } from 'vitest'
|
|
2
2
|
import { getRegisteredIndicatorDefinition } from '../indicatorDefinitionRegistry'
|
|
3
|
-
import { getBuiltinIndicatorDefinitions } from '../registerBuiltins'
|
|
3
|
+
import { getBuiltinIndicatorDefinitions, loadBuiltinIndicators } from '../registerBuiltins'
|
|
4
|
+
|
|
5
|
+
beforeAll(async () => {
|
|
6
|
+
await loadBuiltinIndicators()
|
|
7
|
+
})
|
|
4
8
|
|
|
5
9
|
describe('builtin indicator registration', () => {
|
|
6
10
|
it('loads all builtin indicator definitions through decorators', () => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
|
1
|
+
import { describe, it, expect, vi, beforeEach, beforeAll } from 'vitest'
|
|
2
2
|
import { IndicatorScheduler } from '../scheduler'
|
|
3
|
-
import { getBuiltinIndicatorDefinitions } from '../registerBuiltins'
|
|
3
|
+
import { getBuiltinIndicatorDefinitions, loadBuiltinIndicators } from '../registerBuiltins'
|
|
4
4
|
import { MA_STATE_KEY, EMPTY_MA_STATE, type MARenderState } from '../maState'
|
|
5
5
|
import { BOLL_STATE_KEY, EMPTY_BOLL_STATE, type BOLLRenderState } from '../bollState'
|
|
6
6
|
import { EXPMA_STATE_KEY, EMPTY_EXPMA_STATE, type EXPMARenderState } from '../expmaState'
|
|
@@ -16,7 +16,12 @@ function applyMainResult(key: string): NonNullable<IndicatorMetadata['applyResul
|
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
let builtinDefinitionsByName: Map<string, IndicatorMetadata>
|
|
20
|
+
|
|
21
|
+
beforeAll(async () => {
|
|
22
|
+
await loadBuiltinIndicators()
|
|
23
|
+
builtinDefinitionsByName = new Map(getBuiltinIndicatorDefinitions().map((definition) => [definition.name, definition]))
|
|
24
|
+
})
|
|
20
25
|
|
|
21
26
|
function getBuiltinTestIndicator(name: string): IndicatorMetadata {
|
|
22
27
|
const definition = builtinDefinitionsByName.get(name)
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
import { describe, expect, it, vi } from 'vitest'
|
|
1
|
+
import { describe, expect, it, vi, beforeAll } from 'vitest'
|
|
2
2
|
import type { IndicatorMetadata } from '../indicatorMetadata'
|
|
3
3
|
import { composeRenderStates, composeVisibleSubIndicatorStates, computeMainIndicatorPriceRange } from '../stateComposer'
|
|
4
4
|
import type { IndicatorSeriesBundle } from '../workerProtocol'
|
|
5
|
-
import '../registerBuiltins'
|
|
6
5
|
import { getRegisteredIndicatorDefinition } from '../indicatorDefinitionRegistry'
|
|
6
|
+
import { loadBuiltinIndicators } from '../registerBuiltins'
|
|
7
|
+
|
|
8
|
+
beforeAll(async () => {
|
|
9
|
+
await loadBuiltinIndicators()
|
|
10
|
+
})
|
|
7
11
|
|
|
8
12
|
function createBundle(): IndicatorSeriesBundle {
|
|
9
13
|
return {
|
|
@@ -1,47 +1,63 @@
|
|
|
1
|
-
import '../renderers/subVolume'
|
|
2
|
-
import '../renderers/Indicator/atr'
|
|
3
|
-
import '../renderers/Indicator/boll'
|
|
4
|
-
import '../renderers/Indicator/cci'
|
|
5
|
-
import '../renderers/Indicator/chaikinVol'
|
|
6
|
-
import '../renderers/Indicator/cmf'
|
|
7
|
-
import '../renderers/Indicator/dema'
|
|
8
|
-
import '../renderers/Indicator/donchian'
|
|
9
|
-
import '../renderers/Indicator/ene'
|
|
10
|
-
import '../renderers/Indicator/expma'
|
|
11
|
-
import '../renderers/Indicator/fastk'
|
|
12
|
-
import '../renderers/Indicator/fib'
|
|
13
|
-
import '../renderers/Indicator/hma'
|
|
14
|
-
import '../renderers/Indicator/hv'
|
|
15
|
-
import '../renderers/Indicator/ichimoku'
|
|
16
|
-
import '../renderers/Indicator/kama'
|
|
17
|
-
import '../renderers/Indicator/keltner'
|
|
18
|
-
import '../renderers/Indicator/kst'
|
|
19
|
-
import '../renderers/Indicator/ma'
|
|
20
|
-
import '../renderers/Indicator/macd'
|
|
21
|
-
import '../renderers/Indicator/mfi'
|
|
22
|
-
import '../renderers/Indicator/mom'
|
|
23
|
-
import '../renderers/Indicator/obv'
|
|
24
|
-
import '../renderers/Indicator/parkinson'
|
|
25
|
-
import '../renderers/Indicator/pivot'
|
|
26
|
-
import '../renderers/Indicator/pvt'
|
|
27
|
-
import '../renderers/Indicator/roc'
|
|
28
|
-
import '../renderers/Indicator/rsi'
|
|
29
|
-
import '../renderers/Indicator/sar'
|
|
30
|
-
import '../renderers/Indicator/stoch'
|
|
31
|
-
import '../renderers/Indicator/structure'
|
|
32
|
-
import '../renderers/Indicator/supertrend'
|
|
33
|
-
import '../renderers/Indicator/tema'
|
|
34
|
-
import '../renderers/Indicator/trix'
|
|
35
|
-
import '../renderers/Indicator/vma'
|
|
36
|
-
import '../renderers/Indicator/volumeProfile'
|
|
37
|
-
import '../renderers/Indicator/vwap'
|
|
38
|
-
import '../renderers/Indicator/wma'
|
|
39
|
-
import '../renderers/Indicator/wmsr'
|
|
40
|
-
import '../renderers/Indicator/zones'
|
|
41
1
|
import { getRegisteredIndicatorDefinitions } from './indicatorDefinitionRegistry'
|
|
42
2
|
|
|
43
|
-
|
|
3
|
+
let loaded = false
|
|
4
|
+
|
|
5
|
+
export async function loadBuiltinIndicators(): Promise<void> {
|
|
6
|
+
if (loaded) return
|
|
7
|
+
await Promise.all([
|
|
8
|
+
import('../renderers/subVolume'),
|
|
9
|
+
import('../renderers/Indicator/atr'),
|
|
10
|
+
import('../renderers/Indicator/boll'),
|
|
11
|
+
import('../renderers/Indicator/cci'),
|
|
12
|
+
import('../renderers/Indicator/chaikinVol'),
|
|
13
|
+
import('../renderers/Indicator/cmf'),
|
|
14
|
+
import('../renderers/Indicator/dema'),
|
|
15
|
+
import('../renderers/Indicator/donchian'),
|
|
16
|
+
import('../renderers/Indicator/ene'),
|
|
17
|
+
import('../renderers/Indicator/expma'),
|
|
18
|
+
import('../renderers/Indicator/fastk'),
|
|
19
|
+
import('../renderers/Indicator/fib'),
|
|
20
|
+
import('../renderers/Indicator/hma'),
|
|
21
|
+
import('../renderers/Indicator/hv'),
|
|
22
|
+
import('../renderers/Indicator/ichimoku'),
|
|
23
|
+
import('../renderers/Indicator/kama'),
|
|
24
|
+
import('../renderers/Indicator/keltner'),
|
|
25
|
+
import('../renderers/Indicator/kst'),
|
|
26
|
+
import('../renderers/Indicator/ma'),
|
|
27
|
+
import('../renderers/Indicator/macd'),
|
|
28
|
+
import('../renderers/Indicator/mfi'),
|
|
29
|
+
import('../renderers/Indicator/mom'),
|
|
30
|
+
import('../renderers/Indicator/obv'),
|
|
31
|
+
import('../renderers/Indicator/parkinson'),
|
|
32
|
+
import('../renderers/Indicator/pivot'),
|
|
33
|
+
import('../renderers/Indicator/pvt'),
|
|
34
|
+
import('../renderers/Indicator/roc'),
|
|
35
|
+
import('../renderers/Indicator/rsi'),
|
|
36
|
+
import('../renderers/Indicator/sar'),
|
|
37
|
+
import('../renderers/Indicator/stoch'),
|
|
38
|
+
import('../renderers/Indicator/structure'),
|
|
39
|
+
import('../renderers/Indicator/supertrend'),
|
|
40
|
+
import('../renderers/Indicator/tema'),
|
|
41
|
+
import('../renderers/Indicator/trix'),
|
|
42
|
+
import('../renderers/Indicator/vma'),
|
|
43
|
+
import('../renderers/Indicator/volumeProfile'),
|
|
44
|
+
import('../renderers/Indicator/vwap'),
|
|
45
|
+
import('../renderers/Indicator/wma'),
|
|
46
|
+
import('../renderers/Indicator/wmsr'),
|
|
47
|
+
import('../renderers/Indicator/zones'),
|
|
48
|
+
])
|
|
49
|
+
loaded = true
|
|
50
|
+
}
|
|
44
51
|
|
|
45
52
|
export function getBuiltinIndicatorDefinitions() {
|
|
46
|
-
|
|
53
|
+
if (!loaded) {
|
|
54
|
+
throw new Error(
|
|
55
|
+
'Builtin indicators not loaded yet. Call await loadBuiltinIndicators() first.',
|
|
56
|
+
)
|
|
57
|
+
}
|
|
58
|
+
return getRegisteredIndicatorDefinitions()
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function isBuiltinIndicatorsLoaded(): boolean {
|
|
62
|
+
return loaded
|
|
47
63
|
}
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import { describe, expect, it, vi } from 'vitest'
|
|
1
|
+
import { describe, expect, it, vi, beforeAll } from 'vitest'
|
|
2
2
|
import type { RendererPluginWithHost } from '../../../../plugin'
|
|
3
3
|
import { IndicatorRegistry } from '../../../indicators/indicatorRegistry'
|
|
4
|
-
import { getBuiltinIndicatorDefinitions } from '../../../indicators/registerBuiltins'
|
|
4
|
+
import { getBuiltinIndicatorDefinitions, loadBuiltinIndicators } from '../../../indicators/registerBuiltins'
|
|
5
5
|
import type { IndicatorMetadata } from '../../../indicators/indicatorMetadata'
|
|
6
6
|
import { createSubIndicatorRenderer } from '../index'
|
|
7
7
|
|
|
8
|
+
beforeAll(async () => {
|
|
9
|
+
await loadBuiltinIndicators()
|
|
10
|
+
})
|
|
11
|
+
|
|
8
12
|
function createRenderer(name: string): RendererPluginWithHost {
|
|
9
13
|
return {
|
|
10
14
|
name,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { RendererPluginWithHost, RenderContext, PluginHost } from '../../../plugin'
|
|
2
2
|
import { RENDERER_PRIORITY } from '../../../plugin'
|
|
3
|
+
import { resolveThemeColors } from '../../../tokens'
|
|
3
4
|
import type { KLineData } from '../../../types/price'
|
|
4
5
|
import type { IchimokuRenderState } from '../../indicators/ichimokuState'
|
|
5
6
|
import { createIchimokuStateKey, EMPTY_ICHIMOKU_STATE } from '../../indicators/ichimokuState'
|
|
@@ -14,8 +15,6 @@ const KIJUN_COLOR = '#2563eb'
|
|
|
14
15
|
const SPAN_A_COLOR = '#16a34a'
|
|
15
16
|
const SPAN_B_COLOR = '#dc2626'
|
|
16
17
|
const CHIKOU_COLOR = '#7c3aed'
|
|
17
|
-
const CLOUD_BULL = 'rgba(34, 197, 94, 0.15)'
|
|
18
|
-
const CLOUD_BEAR = 'rgba(239, 68, 68, 0.15)'
|
|
19
18
|
|
|
20
19
|
type Point = { x: number; y: number }
|
|
21
20
|
|
|
@@ -58,6 +57,7 @@ export function createIchimokuRendererPlugin(options: IchimokuRendererOptions =
|
|
|
58
57
|
|
|
59
58
|
draw(context: RenderContext) {
|
|
60
59
|
const { ctx, pane, range, scrollLeft, kLineCenters, lineWebGLSurface } = context
|
|
60
|
+
const colors = resolveThemeColors(context.theme, context.isAsiaMarket, context.colorPresetSettings)
|
|
61
61
|
const stateKey = resolveKey()
|
|
62
62
|
if (!stateKey) return
|
|
63
63
|
const state = pluginHost?.getSharedState<IchimokuRenderState>(stateKey)
|
|
@@ -94,7 +94,7 @@ export function createIchimokuRendererPlugin(options: IchimokuRendererOptions =
|
|
|
94
94
|
if (params.showCloud && cloudSegs.length >= 2) {
|
|
95
95
|
ctx.save()
|
|
96
96
|
ctx.translate(-scrollLeft, 0)
|
|
97
|
-
fillCloud(ctx, cloudSegs)
|
|
97
|
+
fillCloud(ctx, cloudSegs, colors.candleUpBody, colors.candleDownBody)
|
|
98
98
|
ctx.restore()
|
|
99
99
|
}
|
|
100
100
|
|
|
@@ -153,11 +153,16 @@ function drawLine(ctx: CanvasRenderingContext2D, pts: Point[], color: string): v
|
|
|
153
153
|
function fillCloud(
|
|
154
154
|
ctx: CanvasRenderingContext2D,
|
|
155
155
|
segs: { x: number; ya: number; yb: number; bull: boolean }[],
|
|
156
|
+
bullColor: string,
|
|
157
|
+
bearColor: string,
|
|
158
|
+
alpha = 0.15,
|
|
156
159
|
): void {
|
|
160
|
+
ctx.save()
|
|
161
|
+
ctx.globalAlpha = alpha
|
|
157
162
|
for (let i = 0; i < segs.length - 1; i++) {
|
|
158
163
|
const a = segs[i]!
|
|
159
164
|
const b = segs[i + 1]!
|
|
160
|
-
ctx.fillStyle = a.bull ?
|
|
165
|
+
ctx.fillStyle = a.bull ? bullColor : bearColor
|
|
161
166
|
ctx.beginPath()
|
|
162
167
|
ctx.moveTo(a.x, a.ya)
|
|
163
168
|
ctx.lineTo(b.x, b.ya)
|
|
@@ -166,6 +171,7 @@ function fillCloud(
|
|
|
166
171
|
ctx.closePath()
|
|
167
172
|
ctx.fill()
|
|
168
173
|
}
|
|
174
|
+
ctx.restore()
|
|
169
175
|
}
|
|
170
176
|
|
|
171
177
|
export function getIchimokuTitleInfo(
|
|
@@ -5,101 +5,9 @@
|
|
|
5
5
|
import type { RendererPlugin } from '../../../plugin'
|
|
6
6
|
import type { IndicatorMetadata } from '../../indicators/indicatorMetadata'
|
|
7
7
|
|
|
8
|
-
// MA 均线
|
|
9
|
-
export { createMARendererPlugin, type MAFlags, getMATitleInfo } from './ma'
|
|
10
|
-
|
|
11
|
-
// BOLL 布林带
|
|
12
|
-
export { createBOLLRendererPlugin } from './boll'
|
|
13
|
-
|
|
14
|
-
// EXPMA 指数平滑移动平均线
|
|
15
|
-
export { createEXPMARendererPlugin } from './expma'
|
|
16
|
-
|
|
17
|
-
// ENE 轨道线
|
|
18
|
-
export { createENERendererPlugin } from './ene'
|
|
19
|
-
|
|
20
8
|
// 主图指标图例(统一管理 MA、BOLL 等)
|
|
21
9
|
export { createMainIndicatorLegendRendererPlugin } from './mainIndicatorLegend'
|
|
22
10
|
|
|
23
|
-
// MACD
|
|
24
|
-
export { createMACDRendererPlugin, calcMACDAtIndex, type MACDConfig, type MACDRendererOptions, getMACDTitleInfo } from './macd'
|
|
25
|
-
|
|
26
|
-
// RSI 相对强弱指标
|
|
27
|
-
export { createRSIRendererPlugin, type RSIRendererOptions, getRSITitleInfo } from './rsi'
|
|
28
|
-
|
|
29
|
-
// CCI 顺势指标
|
|
30
|
-
export { createCCIRendererPlugin, type CCIRendererOptions, getCCITitleInfo } from './cci'
|
|
31
|
-
|
|
32
|
-
// STOCH 随机指标
|
|
33
|
-
export { createSTOCHRendererPlugin, type STOCHRendererOptions, getSTOCHTitleInfo } from './stoch'
|
|
34
|
-
|
|
35
|
-
// MOM 动量指标
|
|
36
|
-
export { createMOMRendererPlugin, type MOMRendererOptions, getMOMTitleInfo } from './mom'
|
|
37
|
-
|
|
38
|
-
// WMSR 威廉指标
|
|
39
|
-
export { createWMSRRendererPlugin, type WMSRRendererOptions, getWMSRTitleInfo } from './wmsr'
|
|
40
|
-
|
|
41
|
-
// KST 确知指标
|
|
42
|
-
export { createKSTRendererPlugin, type KSTRendererOptions, getKSTTitleInfo } from './kst'
|
|
43
|
-
|
|
44
|
-
// FASTK 快速随机指标
|
|
45
|
-
export { createFASTKRendererPlugin, type FASTKRendererOptions, getFASTKTitleInfo } from './fastk'
|
|
46
|
-
|
|
47
|
-
// ATR 平均真实波幅
|
|
48
|
-
export { createATRRendererPlugin, type ATRRendererOptions, getATRTitleInfo } from './atr'
|
|
49
|
-
|
|
50
|
-
// WMA 加权移动平均
|
|
51
|
-
export { createWMARendererPlugin, getWMATitleInfo } from './wma'
|
|
52
|
-
// DEMA 双指数移动平均
|
|
53
|
-
export { createDEMARendererPlugin, getDEMATitleInfo } from './dema'
|
|
54
|
-
// TEMA 三指数移动平均
|
|
55
|
-
export { createTEMARendererPlugin, getTEMATitleInfo } from './tema'
|
|
56
|
-
// HMA 赫尔移动平均
|
|
57
|
-
export { createHMARendererPlugin, getHMATitleInfo } from './hma'
|
|
58
|
-
// KAMA 考夫曼自适应移动平均
|
|
59
|
-
export { createKAMARendererPlugin, getKAMATitleInfo } from './kama'
|
|
60
|
-
// SAR 抛物线转向
|
|
61
|
-
export { createSARRendererPlugin, getSARTitleInfo } from './sar'
|
|
62
|
-
// SuperTrend 超级趋势
|
|
63
|
-
export { createSuperTrendRendererPlugin, getSuperTrendTitleInfo } from './supertrend'
|
|
64
|
-
// Keltner 肯特纳通道
|
|
65
|
-
export { createKeltnerRendererPlugin, getKeltnerTitleInfo } from './keltner'
|
|
66
|
-
// Donchian 唐奇安通道
|
|
67
|
-
export { createDonchianRendererPlugin, getDonchianTitleInfo } from './donchian'
|
|
68
|
-
// Ichimoku 一目均衡表
|
|
69
|
-
export { createIchimokuRendererPlugin, getIchimokuTitleInfo } from './ichimoku'
|
|
70
|
-
// ROC 变化率
|
|
71
|
-
export { createROCRendererPlugin, getROCTitleInfo } from './roc'
|
|
72
|
-
// TRIX 三重指数平滑平均
|
|
73
|
-
export { createTRIXRendererPlugin, getTRIXTitleInfo } from './trix'
|
|
74
|
-
// HV 历史波动率
|
|
75
|
-
export { createHVRendererPlugin, getHVTitleInfo } from './hv'
|
|
76
|
-
// Parkinson 帕金森波动率
|
|
77
|
-
export { createParkinsonRendererPlugin, getParkinsonTitleInfo } from './parkinson'
|
|
78
|
-
// Chaikin Vol 蔡金波动率
|
|
79
|
-
export { createChaikinVolRendererPlugin, getChaikinVolTitleInfo } from './chaikinVol'
|
|
80
|
-
// VMA 成交量移动平均
|
|
81
|
-
export { createVMARendererPlugin, getVMATitleInfo } from './vma'
|
|
82
|
-
// OBV 能量潮
|
|
83
|
-
export { createOBVRendererPlugin, getOBVTitleInfo } from './obv'
|
|
84
|
-
// PVT 价量趋势
|
|
85
|
-
export { createPVTRendererPlugin, getPVTTitleInfo } from './pvt'
|
|
86
|
-
// VWAP 成交量加权均价
|
|
87
|
-
export { createVWAPRendererPlugin, getVWAPTitleInfo } from './vwap'
|
|
88
|
-
// CMF 蔡金资金流
|
|
89
|
-
export { createCMFRendererPlugin, getCMFTitleInfo } from './cmf'
|
|
90
|
-
// MFI 资金流量指数
|
|
91
|
-
export { createMFIRendererPlugin, getMFITitleInfo } from './mfi'
|
|
92
|
-
// Pivot Points 枢轴点
|
|
93
|
-
export { createPivotRendererPlugin, getPivotTitleInfo } from './pivot'
|
|
94
|
-
// Fibonacci 斐波那契
|
|
95
|
-
export { createFibRendererPlugin, getFibTitleInfo } from './fib'
|
|
96
|
-
// SMC Structure 结构
|
|
97
|
-
export { createStructureRendererPlugin, getStructureTitleInfo } from './structure'
|
|
98
|
-
// SMC Zones 区域
|
|
99
|
-
export { createZonesRendererPlugin, getZonesTitleInfo } from './zones'
|
|
100
|
-
// Volume Profile 成交量分布
|
|
101
|
-
export { createVolumeProfileRendererPlugin, getVolumeProfileTitleInfo } from './volumeProfile'
|
|
102
|
-
|
|
103
11
|
/**
|
|
104
12
|
* 副图指标类型
|
|
105
13
|
*/
|
|
@@ -315,29 +315,38 @@ const uiMeta: Record<string, {
|
|
|
315
315
|
},
|
|
316
316
|
}
|
|
317
317
|
|
|
318
|
-
|
|
319
|
-
return getRegisteredIndicatorDefinitions().map((def) => {
|
|
320
|
-
const key = normalizeId(def.name)
|
|
321
|
-
const ui = uiMeta[key]
|
|
322
|
-
return {
|
|
323
|
-
id: def.displayName.toUpperCase(),
|
|
324
|
-
label: def.displayName,
|
|
325
|
-
name: ui?.name ?? def.displayName,
|
|
326
|
-
pane: def.category === 'main' || def.allowMainPane ? 'main' : 'sub',
|
|
327
|
-
description: ui?.description,
|
|
328
|
-
params: ui?.params,
|
|
329
|
-
}
|
|
330
|
-
})
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
export const allIndicators: Indicator[] = buildAllIndicators()
|
|
318
|
+
let _allIndicators: Indicator[] | null = null
|
|
334
319
|
|
|
335
|
-
|
|
336
|
-
|
|
320
|
+
function rebuildIfStale(): Indicator[] {
|
|
321
|
+
if (_allIndicators === null || getRegisteredIndicatorDefinitions().length !== _allIndicators.length) {
|
|
322
|
+
_allIndicators = getRegisteredIndicatorDefinitions()
|
|
323
|
+
.map((def) => {
|
|
324
|
+
const key = normalizeId(def.name)
|
|
325
|
+
const ui = uiMeta[key]
|
|
326
|
+
return {
|
|
327
|
+
id: def.displayName.toUpperCase(),
|
|
328
|
+
label: def.displayName,
|
|
329
|
+
name: ui?.name ?? def.displayName,
|
|
330
|
+
pane: (def.category === 'main' || def.allowMainPane ? 'main' : 'sub') as Indicator['pane'],
|
|
331
|
+
description: ui?.description,
|
|
332
|
+
params: ui?.params,
|
|
333
|
+
}
|
|
334
|
+
})
|
|
335
|
+
.sort((a, b) => {
|
|
336
|
+
const paneOrder = a.pane === 'main' ? 0 : 1
|
|
337
|
+
const paneOrderB = b.pane === 'main' ? 0 : 1
|
|
338
|
+
return paneOrder - paneOrderB || a.label.localeCompare(b.label)
|
|
339
|
+
})
|
|
340
|
+
}
|
|
341
|
+
return _allIndicators ?? []
|
|
342
|
+
}
|
|
343
|
+
export function allIndicators(): Indicator[] {
|
|
344
|
+
return rebuildIfStale()
|
|
345
|
+
}
|
|
337
346
|
|
|
338
347
|
export function findIndicator(id: string): Indicator | undefined {
|
|
339
348
|
const norm = normalizeId(id)
|
|
340
|
-
return
|
|
349
|
+
return rebuildIfStale().find((i) => normalizeId(i.id) === norm || normalizeId(i.label) === norm)
|
|
341
350
|
}
|
|
342
351
|
|
|
343
352
|
export function isSubIndicatorId(id: string): boolean {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { RendererPluginWithHost, RenderContext, PluginHost } from '../../../plugin'
|
|
2
2
|
import { RENDERER_PRIORITY } from '../../../plugin'
|
|
3
|
+
import { resolveThemeColors } from '../../../tokens'
|
|
3
4
|
import type { KLineData } from '../../../types/price'
|
|
4
5
|
import type { SARRenderState } from '../../indicators/sarState'
|
|
5
6
|
import { createSARStateKey, EMPTY_SAR_STATE } from '../../indicators/sarState'
|
|
@@ -9,8 +10,6 @@ import type { IndicatorScheduler, SARSchedulerConfig } from '../../indicators/sc
|
|
|
9
10
|
import { calcSARData } from '../../indicators/calculators'
|
|
10
11
|
import { createValuePointVisibleStateComposer } from '../../indicators/visibleStateComposers'
|
|
11
12
|
|
|
12
|
-
const SAR_UP_COLOR = '#22c55e'
|
|
13
|
-
const SAR_DOWN_COLOR = '#ef4444'
|
|
14
13
|
const DOT_RADIUS = 1.5
|
|
15
14
|
const TAU = Math.PI * 2
|
|
16
15
|
|
|
@@ -59,6 +58,7 @@ export function createSARRendererPlugin(options: SARRendererOptions = {}): Rende
|
|
|
59
58
|
|
|
60
59
|
draw(context: RenderContext) {
|
|
61
60
|
const { ctx, pane, range, scrollLeft, kLineCenters } = context
|
|
61
|
+
const colors = resolveThemeColors(context.theme, context.isAsiaMarket, context.colorPresetSettings)
|
|
62
62
|
|
|
63
63
|
const stateKey = resolveKey()
|
|
64
64
|
if (!stateKey) return
|
|
@@ -77,7 +77,7 @@ export function createSARRendererPlugin(options: SARRendererOptions = {}): Rende
|
|
|
77
77
|
const centerX = kLineCenters[i - range.start]
|
|
78
78
|
if (centerX === undefined) continue
|
|
79
79
|
const y = pane.yAxis.priceToY(point.value)
|
|
80
|
-
ctx.fillStyle = point.trend === 'up' ?
|
|
80
|
+
ctx.fillStyle = point.trend === 'up' ? colors.candleUpBody : colors.candleDownBody
|
|
81
81
|
ctx.beginPath()
|
|
82
82
|
ctx.arc(centerX, y, DOT_RADIUS, 0, TAU)
|
|
83
83
|
ctx.fill()
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { RendererPluginWithHost, RenderContext, PluginHost } from '../../../plugin'
|
|
2
2
|
import { RENDERER_PRIORITY } from '../../../plugin'
|
|
3
|
+
import { resolveThemeColors } from '../../../tokens'
|
|
3
4
|
import type { KLineData } from '../../../types/price'
|
|
4
5
|
import type { SuperTrendRenderState } from '../../indicators/supertrendState'
|
|
5
6
|
import { createSuperTrendStateKey, EMPTY_SUPERTREND_STATE } from '../../indicators/supertrendState'
|
|
@@ -9,9 +10,6 @@ import type { IndicatorScheduler, SuperTrendSchedulerConfig } from '../../indica
|
|
|
9
10
|
import { calcSuperTrendData } from '../../indicators/calculators'
|
|
10
11
|
import { createValuePointVisibleStateComposer } from '../../indicators/visibleStateComposers'
|
|
11
12
|
|
|
12
|
-
const ST_UP_COLOR = '#22c55e'
|
|
13
|
-
const ST_DOWN_COLOR = '#ef4444'
|
|
14
|
-
|
|
15
13
|
export interface SuperTrendRendererOptions {
|
|
16
14
|
paneId?: string
|
|
17
15
|
}
|
|
@@ -51,6 +49,7 @@ export function createSuperTrendRendererPlugin(options: SuperTrendRendererOption
|
|
|
51
49
|
|
|
52
50
|
draw(context: RenderContext) {
|
|
53
51
|
const { ctx, pane, range, scrollLeft, kLineCenters } = context
|
|
52
|
+
const colors = resolveThemeColors(context.theme, context.isAsiaMarket, context.colorPresetSettings)
|
|
54
53
|
const stateKey = resolveKey()
|
|
55
54
|
if (!stateKey) return
|
|
56
55
|
const state = pluginHost?.getSharedState<SuperTrendRenderState>(stateKey)
|
|
@@ -77,7 +76,7 @@ export function createSuperTrendRendererPlugin(options: SuperTrendRendererOption
|
|
|
77
76
|
const y = pane.yAxis.priceToY(point.value)
|
|
78
77
|
|
|
79
78
|
if (prevX !== null && prevTrend === point.trend) {
|
|
80
|
-
ctx.strokeStyle = point.trend === 'up' ?
|
|
79
|
+
ctx.strokeStyle = point.trend === 'up' ? colors.candleUpBody : colors.candleDownBody
|
|
81
80
|
ctx.beginPath()
|
|
82
81
|
ctx.moveTo(prevX, prevY!)
|
|
83
82
|
ctx.lineTo(centerX, y)
|