@forgecharts/sdk 1.1.27 → 1.1.29

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.
Files changed (356) hide show
  1. package/dist/__tests__/backwardCompatibility.test.d.ts +14 -0
  2. package/dist/__tests__/backwardCompatibility.test.d.ts.map +1 -0
  3. package/dist/__tests__/candleInvariant.test.d.ts +20 -0
  4. package/dist/__tests__/candleInvariant.test.d.ts.map +1 -0
  5. package/dist/__tests__/public-api-surface.d.ts +13 -0
  6. package/dist/__tests__/public-api-surface.d.ts.map +1 -0
  7. package/dist/__tests__/timeframeBoundary.test.d.ts +17 -0
  8. package/dist/__tests__/timeframeBoundary.test.d.ts.map +1 -0
  9. package/dist/api/DrawingManager.d.ts +20 -0
  10. package/dist/api/DrawingManager.d.ts.map +1 -0
  11. package/dist/api/EventBus.d.ts +19 -0
  12. package/dist/api/EventBus.d.ts.map +1 -0
  13. package/dist/api/IndicatorDAG.d.ts +85 -0
  14. package/dist/api/IndicatorDAG.d.ts.map +1 -0
  15. package/dist/api/IndicatorRegistry.d.ts +22 -0
  16. package/dist/api/IndicatorRegistry.d.ts.map +1 -0
  17. package/dist/api/LayoutManager.d.ts +30 -0
  18. package/dist/api/LayoutManager.d.ts.map +1 -0
  19. package/dist/api/PaneManager.d.ts +42 -0
  20. package/dist/api/PaneManager.d.ts.map +1 -0
  21. package/dist/api/ReferenceAPI.d.ts +78 -0
  22. package/dist/api/ReferenceAPI.d.ts.map +1 -0
  23. package/dist/api/TChart.d.ts +345 -0
  24. package/dist/api/TChart.d.ts.map +1 -0
  25. package/{src/api/createChart.ts → dist/api/createChart.d.ts} +2 -7
  26. package/dist/api/createChart.d.ts.map +1 -0
  27. package/dist/api/drawing tools/fib gann menu/fibRetracement.d.ts +4 -0
  28. package/dist/api/drawing tools/fib gann menu/fibRetracement.d.ts.map +1 -0
  29. package/dist/api/drawing tools/lines menu/crossLine.d.ts +4 -0
  30. package/dist/api/drawing tools/lines menu/crossLine.d.ts.map +1 -0
  31. package/dist/api/drawing tools/lines menu/disjointChannel.d.ts +17 -0
  32. package/dist/api/drawing tools/lines menu/disjointChannel.d.ts.map +1 -0
  33. package/dist/api/drawing tools/lines menu/extendedLine.d.ts +4 -0
  34. package/dist/api/drawing tools/lines menu/extendedLine.d.ts.map +1 -0
  35. package/dist/api/drawing tools/lines menu/flatTopBottom.d.ts +4 -0
  36. package/dist/api/drawing tools/lines menu/flatTopBottom.d.ts.map +1 -0
  37. package/dist/api/drawing tools/lines menu/horizontal.d.ts +4 -0
  38. package/dist/api/drawing tools/lines menu/horizontal.d.ts.map +1 -0
  39. package/dist/api/drawing tools/lines menu/horizontalRay.d.ts +4 -0
  40. package/dist/api/drawing tools/lines menu/horizontalRay.d.ts.map +1 -0
  41. package/dist/api/drawing tools/lines menu/infoLine.d.ts +4 -0
  42. package/dist/api/drawing tools/lines menu/infoLine.d.ts.map +1 -0
  43. package/dist/api/drawing tools/lines menu/insidePitchfork.d.ts +4 -0
  44. package/dist/api/drawing tools/lines menu/insidePitchfork.d.ts.map +1 -0
  45. package/dist/api/drawing tools/lines menu/modifiedSchiffPitchfork.d.ts +4 -0
  46. package/dist/api/drawing tools/lines menu/modifiedSchiffPitchfork.d.ts.map +1 -0
  47. package/dist/api/drawing tools/lines menu/parallelChannel.d.ts +4 -0
  48. package/dist/api/drawing tools/lines menu/parallelChannel.d.ts.map +1 -0
  49. package/dist/api/drawing tools/lines menu/pitchfork.d.ts +4 -0
  50. package/dist/api/drawing tools/lines menu/pitchfork.d.ts.map +1 -0
  51. package/dist/api/drawing tools/lines menu/ray.d.ts +4 -0
  52. package/dist/api/drawing tools/lines menu/ray.d.ts.map +1 -0
  53. package/dist/api/drawing tools/lines menu/regressionTrend.d.ts +4 -0
  54. package/dist/api/drawing tools/lines menu/regressionTrend.d.ts.map +1 -0
  55. package/dist/api/drawing tools/lines menu/schiffPitchfork.d.ts +4 -0
  56. package/dist/api/drawing tools/lines menu/schiffPitchfork.d.ts.map +1 -0
  57. package/dist/api/drawing tools/lines menu/trendAngle.d.ts +4 -0
  58. package/dist/api/drawing tools/lines menu/trendAngle.d.ts.map +1 -0
  59. package/dist/api/drawing tools/lines menu/trendline.d.ts +4 -0
  60. package/dist/api/drawing tools/lines menu/trendline.d.ts.map +1 -0
  61. package/dist/api/drawing tools/lines menu/vertical.d.ts +4 -0
  62. package/dist/api/drawing tools/lines menu/vertical.d.ts.map +1 -0
  63. package/{src/api/drawing tools/pointers menu/crosshair.ts → dist/api/drawing tools/pointers menu/crosshair.d.ts } +8 -9
  64. package/dist/api/drawing tools/pointers menu/crosshair.d.ts.map +1 -0
  65. package/dist/api/drawing tools/pointers menu/cursor.d.ts +15 -0
  66. package/dist/api/drawing tools/pointers menu/cursor.d.ts.map +1 -0
  67. package/{src/api/drawing tools/pointers menu/demonstration.ts → dist/api/drawing tools/pointers menu/demonstration.d.ts } +12 -17
  68. package/dist/api/drawing tools/pointers menu/demonstration.d.ts.map +1 -0
  69. package/{src/api/drawing tools/pointers menu/dot.ts → dist/api/drawing tools/pointers menu/dot.d.ts } +10 -13
  70. package/dist/api/drawing tools/pointers menu/dot.d.ts.map +1 -0
  71. package/dist/api/drawing tools/shapes menu/rectangle.d.ts +4 -0
  72. package/dist/api/drawing tools/shapes menu/rectangle.d.ts.map +1 -0
  73. package/dist/api/drawing tools/shapes menu/text.d.ts +4 -0
  74. package/dist/api/drawing tools/shapes menu/text.d.ts.map +1 -0
  75. package/dist/api/drawingUtils.d.ts +22 -0
  76. package/dist/api/drawingUtils.d.ts.map +1 -0
  77. package/dist/core/CanvasLayer.d.ts +26 -0
  78. package/dist/core/CanvasLayer.d.ts.map +1 -0
  79. package/dist/core/Chart.d.ts +164 -0
  80. package/dist/core/Chart.d.ts.map +1 -0
  81. package/dist/core/CoordTransform.d.ts +168 -0
  82. package/dist/core/CoordTransform.d.ts.map +1 -0
  83. package/dist/core/Crosshair.d.ts +30 -0
  84. package/dist/core/Crosshair.d.ts.map +1 -0
  85. package/dist/core/IndicatorEngine.d.ts +51 -0
  86. package/dist/core/IndicatorEngine.d.ts.map +1 -0
  87. package/dist/core/InteractionManager.d.ts +197 -0
  88. package/dist/core/InteractionManager.d.ts.map +1 -0
  89. package/dist/core/PriceScale.d.ts +27 -0
  90. package/dist/core/PriceScale.d.ts.map +1 -0
  91. package/dist/core/Series.d.ts +40 -0
  92. package/dist/core/Series.d.ts.map +1 -0
  93. package/dist/core/TimeScale.d.ts +43 -0
  94. package/dist/core/TimeScale.d.ts.map +1 -0
  95. package/dist/datafeed/DatafeedConnector.d.ts +89 -0
  96. package/dist/datafeed/DatafeedConnector.d.ts.map +1 -0
  97. package/dist/engine/CandleEngine.d.ts +207 -0
  98. package/dist/engine/CandleEngine.d.ts.map +1 -0
  99. package/dist/engine/__tests__/CandleEngine.test.d.ts +2 -0
  100. package/dist/engine/__tests__/CandleEngine.test.d.ts.map +1 -0
  101. package/dist/engine/candleInvariants.d.ts +66 -0
  102. package/dist/engine/candleInvariants.d.ts.map +1 -0
  103. package/{src/engine/mergeUtils.ts → dist/engine/mergeUtils.d.ts} +15 -52
  104. package/dist/engine/mergeUtils.d.ts.map +1 -0
  105. package/dist/engine/timeframeUtils.d.ts +80 -0
  106. package/dist/engine/timeframeUtils.d.ts.map +1 -0
  107. package/dist/index.d.ts +40 -0
  108. package/dist/index.d.ts.map +1 -0
  109. package/dist/index.js +8101 -0
  110. package/dist/index.js.map +1 -0
  111. package/{src/internal.ts → dist/internal.d.ts} +1 -13
  112. package/dist/internal.d.ts.map +1 -0
  113. package/dist/internal.js +8852 -0
  114. package/dist/internal.js.map +1 -0
  115. package/dist/licensing/ChartRuntimeResolver.d.ts +233 -0
  116. package/dist/licensing/ChartRuntimeResolver.d.ts.map +1 -0
  117. package/dist/licensing/LicenseManager.d.ts +55 -0
  118. package/dist/licensing/LicenseManager.d.ts.map +1 -0
  119. package/dist/licensing/__tests__/ChartRuntimeResolver.test.d.ts +13 -0
  120. package/dist/licensing/__tests__/ChartRuntimeResolver.test.d.ts.map +1 -0
  121. package/dist/licensing/__tests__/LicenseManager.test.d.ts +12 -0
  122. package/dist/licensing/__tests__/LicenseManager.test.d.ts.map +1 -0
  123. package/dist/licensing/licenseTypes.d.ts +18 -0
  124. package/dist/licensing/licenseTypes.d.ts.map +1 -0
  125. package/dist/pine/PineCompiler.d.ts +35 -0
  126. package/dist/pine/PineCompiler.d.ts.map +1 -0
  127. package/dist/pine/diagnostics.d.ts +20 -0
  128. package/dist/pine/diagnostics.d.ts.map +1 -0
  129. package/{src/pine/index.ts → dist/pine/index.d.ts} +4 -3
  130. package/dist/pine/index.d.ts.map +1 -0
  131. package/dist/pine/pine-ast.d.ts +142 -0
  132. package/dist/pine/pine-ast.d.ts.map +1 -0
  133. package/dist/pine/pine-lexer.d.ts +41 -0
  134. package/dist/pine/pine-lexer.d.ts.map +1 -0
  135. package/dist/pine/pine-parser.d.ts +51 -0
  136. package/dist/pine/pine-parser.d.ts.map +1 -0
  137. package/dist/pine/pine-transpiler.d.ts +33 -0
  138. package/dist/pine/pine-transpiler.d.ts.map +1 -0
  139. package/dist/pixi/LayerName.d.ts +18 -0
  140. package/dist/pixi/LayerName.d.ts.map +1 -0
  141. package/dist/pixi/PixiCandlestickRenderer.d.ts +23 -0
  142. package/dist/pixi/PixiCandlestickRenderer.d.ts.map +1 -0
  143. package/dist/pixi/PixiChart.d.ts +72 -0
  144. package/dist/pixi/PixiChart.d.ts.map +1 -0
  145. package/dist/pixi/PixiCrosshairRenderer.d.ts +29 -0
  146. package/dist/pixi/PixiCrosshairRenderer.d.ts.map +1 -0
  147. package/dist/pixi/PixiDrawingRenderer.d.ts +17 -0
  148. package/dist/pixi/PixiDrawingRenderer.d.ts.map +1 -0
  149. package/dist/pixi/PixiGridRenderer.d.ts +22 -0
  150. package/dist/pixi/PixiGridRenderer.d.ts.map +1 -0
  151. package/dist/pixi/PixiLayerManager.d.ts +56 -0
  152. package/dist/pixi/PixiLayerManager.d.ts.map +1 -0
  153. package/dist/react/canvas/ChartCanvas.d.ts +85 -0
  154. package/dist/react/canvas/ChartCanvas.d.ts.map +1 -0
  155. package/dist/react/canvas/ChartContextMenu.d.ts +18 -0
  156. package/dist/react/canvas/ChartContextMenu.d.ts.map +1 -0
  157. package/dist/react/canvas/ChartSettingsDialog.d.ts +25 -0
  158. package/dist/react/canvas/ChartSettingsDialog.d.ts.map +1 -0
  159. package/dist/react/canvas/IndicatorLabel.d.ts +21 -0
  160. package/dist/react/canvas/IndicatorLabel.d.ts.map +1 -0
  161. package/dist/react/canvas/IndicatorPane.d.ts +32 -0
  162. package/dist/react/canvas/IndicatorPane.d.ts.map +1 -0
  163. package/dist/react/canvas/PointerOverlay.d.ts +23 -0
  164. package/dist/react/canvas/PointerOverlay.d.ts.map +1 -0
  165. package/dist/react/canvas/toolbars/LeftToolbar.d.ts +19 -0
  166. package/dist/react/canvas/toolbars/LeftToolbar.d.ts.map +1 -0
  167. package/dist/react/hooks/useChartCapabilities.d.ts +21 -0
  168. package/dist/react/hooks/useChartCapabilities.d.ts.map +1 -0
  169. package/{src/react/index.ts → dist/react/index.d.ts} +2 -23
  170. package/dist/react/index.d.ts.map +1 -0
  171. package/dist/react/index.js +11559 -0
  172. package/dist/react/index.js.map +1 -0
  173. package/{src/react/internal.ts → dist/react/internal.d.ts} +2 -26
  174. package/dist/react/internal.d.ts.map +1 -0
  175. package/dist/react/internal.js +12148 -0
  176. package/dist/react/internal.js.map +1 -0
  177. package/dist/react/shell/ManagedAppShell.d.ts +91 -0
  178. package/dist/react/shell/ManagedAppShell.d.ts.map +1 -0
  179. package/dist/react/trading/TradingBridge.d.ts +86 -0
  180. package/dist/react/trading/TradingBridge.d.ts.map +1 -0
  181. package/dist/react/workspace/ChartWorkspace.d.ts +73 -0
  182. package/dist/react/workspace/ChartWorkspace.d.ts.map +1 -0
  183. package/dist/react/workspace/FloatingPanel.d.ts +18 -0
  184. package/dist/react/workspace/FloatingPanel.d.ts.map +1 -0
  185. package/dist/react/workspace/IndicatorsDialog.d.ts +8 -0
  186. package/dist/react/workspace/IndicatorsDialog.d.ts.map +1 -0
  187. package/dist/react/workspace/LayoutMenu.d.ts +33 -0
  188. package/dist/react/workspace/LayoutMenu.d.ts.map +1 -0
  189. package/dist/react/workspace/SymbolSearchDialog.d.ts +10 -0
  190. package/dist/react/workspace/SymbolSearchDialog.d.ts.map +1 -0
  191. package/dist/react/workspace/TabBar.d.ts +17 -0
  192. package/dist/react/workspace/TabBar.d.ts.map +1 -0
  193. package/dist/react/workspace/toolbars/BottomToolbar.d.ts +19 -0
  194. package/dist/react/workspace/toolbars/BottomToolbar.d.ts.map +1 -0
  195. package/dist/react/workspace/toolbars/RightToolbar.d.ts +8 -0
  196. package/dist/react/workspace/toolbars/RightToolbar.d.ts.map +1 -0
  197. package/dist/react/workspace/toolbars/TopToolbar.d.ts +41 -0
  198. package/dist/react/workspace/toolbars/TopToolbar.d.ts.map +1 -0
  199. package/dist/renderers/CandlestickRenderer.d.ts +13 -0
  200. package/dist/renderers/CandlestickRenderer.d.ts.map +1 -0
  201. package/dist/renderers/HistogramRenderer.d.ts +11 -0
  202. package/dist/renderers/HistogramRenderer.d.ts.map +1 -0
  203. package/dist/renderers/LineRenderer.d.ts +12 -0
  204. package/dist/renderers/LineRenderer.d.ts.map +1 -0
  205. package/dist/theme/colors.d.ts +4 -0
  206. package/dist/theme/colors.d.ts.map +1 -0
  207. package/dist/tools/barDivergenceCheck.d.ts +120 -0
  208. package/dist/tools/barDivergenceCheck.d.ts.map +1 -0
  209. package/dist/trading/TradingOverlayStore.d.ts +86 -0
  210. package/dist/trading/TradingOverlayStore.d.ts.map +1 -0
  211. package/dist/trading/UnmanagedIngestion.d.ts +91 -0
  212. package/dist/trading/UnmanagedIngestion.d.ts.map +1 -0
  213. package/dist/trading/__tests__/ManagedTradingController.test.d.ts +18 -0
  214. package/dist/trading/__tests__/ManagedTradingController.test.d.ts.map +1 -0
  215. package/dist/trading/__tests__/TradingOverlayStore.test.d.ts +16 -0
  216. package/dist/trading/__tests__/TradingOverlayStore.test.d.ts.map +1 -0
  217. package/dist/trading/__tests__/UnmanagedIngestion.test.d.ts +16 -0
  218. package/dist/trading/__tests__/UnmanagedIngestion.test.d.ts.map +1 -0
  219. package/dist/trading/managed/ManagedTradingController.d.ts +110 -0
  220. package/dist/trading/managed/ManagedTradingController.d.ts.map +1 -0
  221. package/dist/trading/managed/managedCapabilities.d.ts +45 -0
  222. package/dist/trading/managed/managedCapabilities.d.ts.map +1 -0
  223. package/dist/trading/managed/managedTypes.d.ts +122 -0
  224. package/dist/trading/managed/managedTypes.d.ts.map +1 -0
  225. package/dist/trading/tradingTypes.d.ts +89 -0
  226. package/dist/trading/tradingTypes.d.ts.map +1 -0
  227. package/dist/tscript/TScriptIndicator.d.ts +41 -0
  228. package/dist/tscript/TScriptIndicator.d.ts.map +1 -0
  229. package/dist/tscript/ast.d.ts +89 -0
  230. package/dist/tscript/ast.d.ts.map +1 -0
  231. package/dist/tscript/lexer.d.ts +36 -0
  232. package/dist/tscript/lexer.d.ts.map +1 -0
  233. package/dist/tscript/parser.d.ts +50 -0
  234. package/dist/tscript/parser.d.ts.map +1 -0
  235. package/dist/tscript/runtime.d.ts +123 -0
  236. package/dist/tscript/runtime.d.ts.map +1 -0
  237. package/dist/tscript/series.d.ts +49 -0
  238. package/dist/tscript/series.d.ts.map +1 -0
  239. package/dist/types/IChart.d.ts +48 -0
  240. package/dist/types/IChart.d.ts.map +1 -0
  241. package/{src/types/IRenderer.ts → dist/types/IRenderer.d.ts} +2 -8
  242. package/dist/types/IRenderer.d.ts.map +1 -0
  243. package/dist/types/ISeries.d.ts +26 -0
  244. package/dist/types/ISeries.d.ts.map +1 -0
  245. package/package.json +5 -1
  246. package/src/__tests__/backwardCompatibility.test.ts +0 -191
  247. package/src/__tests__/candleInvariant.test.ts +0 -500
  248. package/src/__tests__/public-api-surface.ts +0 -76
  249. package/src/__tests__/timeframeBoundary.test.ts +0 -583
  250. package/src/api/DrawingManager.ts +0 -188
  251. package/src/api/EventBus.ts +0 -53
  252. package/src/api/IndicatorDAG.ts +0 -389
  253. package/src/api/IndicatorRegistry.ts +0 -47
  254. package/src/api/LayoutManager.ts +0 -72
  255. package/src/api/PaneManager.ts +0 -129
  256. package/src/api/ReferenceAPI.ts +0 -195
  257. package/src/api/TChart.ts +0 -881
  258. package/src/api/drawing tools/fib gann menu/fibRetracement.ts +0 -27
  259. package/src/api/drawing tools/lines menu/crossLine.ts +0 -21
  260. package/src/api/drawing tools/lines menu/disjointChannel.ts +0 -74
  261. package/src/api/drawing tools/lines menu/extendedLine.ts +0 -22
  262. package/src/api/drawing tools/lines menu/flatTopBottom.ts +0 -45
  263. package/src/api/drawing tools/lines menu/horizontal.ts +0 -24
  264. package/src/api/drawing tools/lines menu/horizontalRay.ts +0 -25
  265. package/src/api/drawing tools/lines menu/infoLine.ts +0 -127
  266. package/src/api/drawing tools/lines menu/insidePitchfork.ts +0 -21
  267. package/src/api/drawing tools/lines menu/modifiedSchiffPitchfork.ts +0 -18
  268. package/src/api/drawing tools/lines menu/parallelChannel.ts +0 -47
  269. package/src/api/drawing tools/lines menu/pitchfork.ts +0 -15
  270. package/src/api/drawing tools/lines menu/ray.ts +0 -28
  271. package/src/api/drawing tools/lines menu/regressionTrend.ts +0 -157
  272. package/src/api/drawing tools/lines menu/schiffPitchfork.ts +0 -18
  273. package/src/api/drawing tools/lines menu/trendAngle.ts +0 -64
  274. package/src/api/drawing tools/lines menu/trendline.ts +0 -16
  275. package/src/api/drawing tools/lines menu/vertical.ts +0 -16
  276. package/src/api/drawing tools/pointers menu/cursor.ts +0 -16
  277. package/src/api/drawing tools/shapes menu/rectangle.ts +0 -24
  278. package/src/api/drawing tools/shapes menu/text.ts +0 -30
  279. package/src/api/drawingUtils.ts +0 -82
  280. package/src/core/CanvasLayer.ts +0 -77
  281. package/src/core/Chart.ts +0 -917
  282. package/src/core/CoordTransform.ts +0 -282
  283. package/src/core/Crosshair.ts +0 -207
  284. package/src/core/IndicatorEngine.ts +0 -216
  285. package/src/core/InteractionManager.ts +0 -899
  286. package/src/core/PriceScale.ts +0 -133
  287. package/src/core/Series.ts +0 -132
  288. package/src/core/TimeScale.ts +0 -175
  289. package/src/datafeed/DatafeedConnector.ts +0 -300
  290. package/src/engine/CandleEngine.ts +0 -458
  291. package/src/engine/__tests__/CandleEngine.test.ts +0 -402
  292. package/src/engine/candleInvariants.ts +0 -172
  293. package/src/engine/timeframeUtils.ts +0 -118
  294. package/src/index.ts +0 -190
  295. package/src/licensing/ChartRuntimeResolver.ts +0 -380
  296. package/src/licensing/LicenseManager.ts +0 -131
  297. package/src/licensing/__tests__/ChartRuntimeResolver.test.ts +0 -207
  298. package/src/licensing/__tests__/LicenseManager.test.ts +0 -180
  299. package/src/licensing/licenseTypes.ts +0 -19
  300. package/src/pine/PineCompiler.ts +0 -68
  301. package/src/pine/diagnostics.ts +0 -30
  302. package/src/pine/pine-ast.ts +0 -163
  303. package/src/pine/pine-lexer.ts +0 -265
  304. package/src/pine/pine-parser.ts +0 -439
  305. package/src/pine/pine-transpiler.ts +0 -301
  306. package/src/pixi/LayerName.ts +0 -35
  307. package/src/pixi/PixiCandlestickRenderer.ts +0 -125
  308. package/src/pixi/PixiChart.ts +0 -425
  309. package/src/pixi/PixiCrosshairRenderer.ts +0 -134
  310. package/src/pixi/PixiDrawingRenderer.ts +0 -121
  311. package/src/pixi/PixiGridRenderer.ts +0 -136
  312. package/src/pixi/PixiLayerManager.ts +0 -102
  313. package/src/react/canvas/ChartCanvas.tsx +0 -984
  314. package/src/react/canvas/ChartContextMenu.tsx +0 -60
  315. package/src/react/canvas/ChartSettingsDialog.tsx +0 -133
  316. package/src/react/canvas/IndicatorLabel.tsx +0 -347
  317. package/src/react/canvas/IndicatorPane.tsx +0 -503
  318. package/src/react/canvas/PointerOverlay.tsx +0 -126
  319. package/src/react/canvas/toolbars/LeftToolbar.tsx +0 -1096
  320. package/src/react/hooks/useChartCapabilities.ts +0 -76
  321. package/src/react/shell/ManagedAppShell.tsx +0 -699
  322. package/src/react/trading/TradingBridge.ts +0 -156
  323. package/src/react/workspace/ChartWorkspace.tsx +0 -228
  324. package/src/react/workspace/FloatingPanel.tsx +0 -131
  325. package/src/react/workspace/IndicatorsDialog.tsx +0 -246
  326. package/src/react/workspace/LayoutMenu.tsx +0 -345
  327. package/src/react/workspace/SymbolSearchDialog.tsx +0 -377
  328. package/src/react/workspace/TabBar.tsx +0 -87
  329. package/src/react/workspace/toolbars/BottomToolbar.tsx +0 -372
  330. package/src/react/workspace/toolbars/RightToolbar.tsx +0 -46
  331. package/src/react/workspace/toolbars/TopToolbar.tsx +0 -431
  332. package/src/renderers/CandlestickRenderer.ts +0 -130
  333. package/src/renderers/HistogramRenderer.ts +0 -63
  334. package/src/renderers/LineRenderer.ts +0 -77
  335. package/src/theme/colors.ts +0 -21
  336. package/src/tools/barDivergenceCheck.ts +0 -305
  337. package/src/trading/TradingOverlayStore.ts +0 -161
  338. package/src/trading/UnmanagedIngestion.ts +0 -156
  339. package/src/trading/__tests__/ManagedTradingController.test.ts +0 -338
  340. package/src/trading/__tests__/TradingOverlayStore.test.ts +0 -323
  341. package/src/trading/__tests__/UnmanagedIngestion.test.ts +0 -205
  342. package/src/trading/managed/ManagedTradingController.ts +0 -292
  343. package/src/trading/managed/managedCapabilities.ts +0 -98
  344. package/src/trading/managed/managedTypes.ts +0 -151
  345. package/src/trading/tradingTypes.ts +0 -135
  346. package/src/tscript/TScriptIndicator.ts +0 -54
  347. package/src/tscript/ast.ts +0 -105
  348. package/src/tscript/lexer.ts +0 -190
  349. package/src/tscript/parser.ts +0 -334
  350. package/src/tscript/runtime.ts +0 -525
  351. package/src/tscript/series.ts +0 -84
  352. package/src/types/IChart.ts +0 -56
  353. package/src/types/ISeries.ts +0 -30
  354. package/tsconfig.json +0 -23
  355. package/tsup.config.ts +0 -16
  356. package/vitest.config.ts +0 -25
@@ -1,188 +0,0 @@
1
- import type { Drawing, OHLCV } from '@forgecharts/types';
2
- import type { CoordTransform } from '../core/CoordTransform';
3
- import { HANDLE_HALF, HANDLE_FILL, HANDLE_STROKE } from './drawingUtils';
4
-
5
- let _counter = 0;
6
- function nextId(): string {
7
- return `drawing_${(++_counter).toString().padStart(4, '0')}`;
8
- }
9
-
10
- // ─── Lines menu ───────────────────────────────────────────────────────────────
11
- import { renderTrendline } from './drawing tools/lines menu/trendline';
12
- import { renderRay } from './drawing tools/lines menu/ray';
13
- import { renderInfoLine } from './drawing tools/lines menu/infoLine';
14
- import { renderExtendedLine } from './drawing tools/lines menu/extendedLine';
15
- import { renderTrendAngle } from './drawing tools/lines menu/trendAngle';
16
- import { renderHorizontal } from './drawing tools/lines menu/horizontal';
17
- import { renderVertical } from './drawing tools/lines menu/vertical';
18
- import { renderHorizontalRay } from './drawing tools/lines menu/horizontalRay';
19
- import { renderCrossLine } from './drawing tools/lines menu/crossLine';
20
- // Channels
21
- import { renderParallelChannel } from './drawing tools/lines menu/parallelChannel';
22
- import { renderRegressionTrend } from './drawing tools/lines menu/regressionTrend';
23
- import { renderFlatTopBottom } from './drawing tools/lines menu/flatTopBottom';
24
- import { renderDisjointChannel } from './drawing tools/lines menu/disjointChannel';
25
- // Pitchforks
26
- import { renderPitchfork } from './drawing tools/lines menu/pitchfork';
27
- import { renderSchiffPitchfork } from './drawing tools/lines menu/schiffPitchfork';
28
- import { renderModifiedSchiffPitchfork } from './drawing tools/lines menu/modifiedSchiffPitchfork';
29
- import { renderInsidePitchfork } from './drawing tools/lines menu/insidePitchfork';
30
-
31
- // ─── Shapes menu ─────────────────────────────────────────────────────────────
32
- import { renderRectangle } from './drawing tools/shapes menu/rectangle';
33
- import { renderText } from './drawing tools/shapes menu/text';
34
-
35
- // ─── Fib & Gann menu ─────────────────────────────────────────────────────────
36
- import { renderFibRetracement } from './drawing tools/fib gann menu/fibRetracement';
37
-
38
- // ─── Internal dispatch ────────────────────────────────────────────────────────
39
-
40
- function _renderOne(ctx: CanvasRenderingContext2D, d: Drawing, t: CoordTransform, interval = '1h', candles: readonly OHLCV[] = []): void {
41
- switch (d.type) {
42
- // ── Lines menu ────────────────────────────────────────────────────────
43
- case 'trendline': renderTrendline(ctx, d, t); break;
44
- case 'ray': renderRay(ctx, d, t); break;
45
- case 'infoLine': renderInfoLine(ctx, d, t, interval); break;
46
- case 'extendedLine': renderExtendedLine(ctx, d, t); break;
47
- case 'trendAngle': renderTrendAngle(ctx, d, t); break;
48
- case 'horizontal': renderHorizontal(ctx, d, t); break;
49
- case 'vertical': renderVertical(ctx, d, t); break;
50
- case 'horizontalRay': renderHorizontalRay(ctx, d, t); break;
51
- case 'crossLine': renderCrossLine(ctx, d, t); break;
52
- // Channels
53
- case 'parallelChannel': renderParallelChannel(ctx, d, t); break;
54
- case 'regressionTrend': renderRegressionTrend(ctx, d, t, candles); break;
55
- case 'flatTopBottom': renderFlatTopBottom(ctx, d, t); break;
56
- case 'disjointChannel': renderDisjointChannel(ctx, d, t); break;
57
- // Pitchforks
58
- case 'pitchfork': renderPitchfork(ctx, d, t); break;
59
- case 'schiffPitchfork': renderSchiffPitchfork(ctx, d, t); break;
60
- case 'modifiedSchiffPitchfork': renderModifiedSchiffPitchfork(ctx, d, t); break;
61
- case 'insidePitchfork': renderInsidePitchfork(ctx, d, t); break;
62
- // ── Shapes menu ───────────────────────────────────────────────────────
63
- case 'rectangle': renderRectangle(ctx, d, t); break;
64
- case 'text': renderText(ctx, d, t); break;
65
- // ── Fib & Gann menu ───────────────────────────────────────────────────
66
- case 'fibRetracement': renderFibRetracement(ctx, d, t); break;
67
- }
68
- }
69
-
70
- function _renderHandles(ctx: CanvasRenderingContext2D, d: Drawing, t: CoordTransform): void {
71
- ctx.save();
72
- ctx.setLineDash([]);
73
- ctx.lineWidth = 1.5;
74
- for (const p of d.points) {
75
- const px = t.timeToX(p.time);
76
- const py = t.priceToY(p.price);
77
- ctx.fillStyle = HANDLE_FILL;
78
- ctx.strokeStyle = HANDLE_STROKE;
79
- ctx.beginPath();
80
- ctx.rect(px - HANDLE_HALF, py - HANDLE_HALF, HANDLE_HALF * 2, HANDLE_HALF * 2);
81
- ctx.fill();
82
- ctx.stroke();
83
- }
84
- ctx.restore();
85
- }
86
-
87
- // ─── Public API ────────────────────────────────────────────────────────────────
88
-
89
- export class DrawingManager {
90
- private readonly _map = new Map<string, Drawing>();
91
-
92
- // ─── CRUD ──────────────────────────────────────────────────────────────────
93
-
94
- add(drawing: Omit<Drawing, 'id'>): string {
95
- const id = nextId();
96
- this._map.set(id, { ...drawing, id });
97
- return id;
98
- }
99
-
100
- remove(id: string): boolean {
101
- return this._map.delete(id);
102
- }
103
-
104
- update(
105
- id: string,
106
- patches: Partial<Pick<Drawing, 'points' | 'color' | 'text' | 'visible' | 'lineWidth' | 'fillColor' | 'fillOpacity' | 'deviationMultiplier'>>,
107
- ): boolean {
108
- const d = this._map.get(id);
109
- if (!d) return false;
110
- this._map.set(id, { ...d, ...patches });
111
- return true;
112
- }
113
-
114
- get(id: string): Drawing | undefined {
115
- return this._map.get(id);
116
- }
117
-
118
- has(id: string): boolean {
119
- return this._map.has(id);
120
- }
121
-
122
- all(): readonly Drawing[] {
123
- return [...this._map.values()];
124
- }
125
-
126
- clear(): void {
127
- this._map.clear();
128
- }
129
-
130
- // ─── Rendering ─────────────────────────────────────────────────────────────
131
-
132
- render(
133
- ctx: CanvasRenderingContext2D,
134
- transform: CoordTransform,
135
- selectedId: string | null = null,
136
- interval = '1h',
137
- candles: readonly OHLCV[] = [],
138
- ): void {
139
- ctx.save();
140
- for (const d of this._map.values()) {
141
- if (d.visible === false) continue;
142
- ctx.strokeStyle = d.color ?? '#2196f3';
143
- ctx.lineWidth = d.lineWidth ?? 1.5;
144
- ctx.setLineDash([]);
145
- ctx.globalAlpha = 1;
146
- _renderOne(ctx, d, transform, interval, candles);
147
- if (d.id === selectedId) {
148
- // Heavier highlight pass
149
- ctx.save();
150
- ctx.strokeStyle = d.color ?? '#2196f3';
151
- ctx.lineWidth = (d.lineWidth ?? 1.5) + 1;
152
- ctx.globalAlpha = 0.4;
153
- _renderOne(ctx, d, transform, interval, candles);
154
- ctx.restore();
155
- _renderHandles(ctx, d, transform);
156
- }
157
- }
158
- ctx.restore();
159
- }
160
-
161
- renderPreview(
162
- ctx: CanvasRenderingContext2D,
163
- transform: CoordTransform,
164
- draft: Omit<Drawing, 'id'>,
165
- interval = '1h',
166
- candles: readonly OHLCV[] = [],
167
- ): void {
168
- const d = { id: '__preview__', ...draft } as Drawing;
169
- ctx.save();
170
- ctx.globalAlpha = 0.65;
171
- ctx.setLineDash([6, 4]);
172
- ctx.strokeStyle = d.color ?? '#2196f3';
173
- ctx.lineWidth = d.lineWidth ?? 1.5;
174
- _renderOne(ctx, d, transform, interval, candles);
175
- ctx.restore();
176
- }
177
-
178
- /** Returns anchor pixel positions — used by InteractionManager for handle hit-testing. */
179
- static anchorPixels(
180
- d: Drawing,
181
- transform: CoordTransform,
182
- ): Array<{ x: number; y: number }> {
183
- return d.points.map((p) => ({
184
- x: transform.timeToX(p.time),
185
- y: transform.priceToY(p.price),
186
- }));
187
- }
188
- }
@@ -1,53 +0,0 @@
1
- import type { ChartEventMap } from '@forgecharts/types';
2
-
3
- type Handler<T> = (payload: T) => void;
4
-
5
- /**
6
- * EventBus — internal typed pub/sub used by TChart.
7
- *
8
- * All event keys are constrained to `keyof ChartEventMap`, giving
9
- * full type inference on payload shapes at every call site.
10
- */
11
- export class EventBus {
12
- private readonly _listeners = new Map<
13
- keyof ChartEventMap,
14
- Set<Handler<unknown>>
15
- >();
16
-
17
- on<K extends keyof ChartEventMap>(event: K, handler: Handler<ChartEventMap[K]>): void {
18
- if (!this._listeners.has(event)) {
19
- this._listeners.set(event, new Set());
20
- }
21
- this._listeners.get(event)!.add(handler as Handler<unknown>);
22
- }
23
-
24
- off<K extends keyof ChartEventMap>(event: K, handler: Handler<ChartEventMap[K]>): void {
25
- this._listeners.get(event)?.delete(handler as Handler<unknown>);
26
- }
27
-
28
- once<K extends keyof ChartEventMap>(event: K, handler: Handler<ChartEventMap[K]>): void {
29
- const wrapper = (payload: ChartEventMap[K]): void => {
30
- handler(payload);
31
- this.off(event, wrapper);
32
- };
33
- this.on(event, wrapper);
34
- }
35
-
36
- emit<K extends keyof ChartEventMap>(event: K, payload: ChartEventMap[K]): void {
37
- const handlers = this._listeners.get(event);
38
- if (!handlers) return;
39
- for (const h of handlers) {
40
- try {
41
- (h as Handler<ChartEventMap[K]>)(payload);
42
- } catch (err) {
43
- // Prevent one bad handler from breaking the others
44
- console.error(`[ForgeCharts] Unhandled error in "${event}" listener`, err);
45
- }
46
- }
47
- }
48
-
49
- /** Removes all listeners — called on chart destruction. */
50
- clear(): void {
51
- this._listeners.clear();
52
- }
53
- }
@@ -1,389 +0,0 @@
1
- /**
2
- * IndicatorDAG — Directed Acyclic Graph for indicator computation.
3
- *
4
- * Allows indicators to be chained: e.g. EMA can consume SMA's output instead
5
- * of raw OHLCV prices. Circular dependencies are rejected at registration time.
6
- * Results are cached and recomputed only when inputs actually change.
7
- *
8
- * Incremental fast-path: when a single bar is appended, SMA and EMA extend
9
- * their result by exactly one point in O(1) time.
10
- *
11
- * @example
12
- * ```ts
13
- * const dag = new IndicatorDAG();
14
- * dag.addNode('sma1', { type: 'sma', params: { period: 20 } });
15
- * dag.addNode('ema1', { type: 'ema', params: { period: 10 }, sourceId: 'sma1' });
16
- *
17
- * dag.execute(bars); // SMA first, then EMA(SMA)
18
- * const result = dag.getResult('ema1'); // { kind: 'series', points: [...] }
19
- * ```
20
- */
21
-
22
- import type { OHLCV, IndicatorConfig, PriceField } from '@forgecharts/types';
23
- import type { IndicatorPoint, MACDPoint } from '../core/IndicatorEngine';
24
- import {
25
- extractField,
26
- computeSMAFromSeries,
27
- computeEMAFromSeries,
28
- computeWMAFromSeries,
29
- computeRSI,
30
- computeMACD,
31
- computeVolume,
32
- } from '../core/IndicatorEngine';
33
- import { TScriptIndicator } from '../tscript/TScriptIndicator';
34
-
35
- // ─── Public result type ────────────────────────────────────────────────────────
36
-
37
- /** Computed output of a single DAG node. */
38
- export type DAGResult =
39
- | { readonly kind: 'series'; readonly points: readonly IndicatorPoint[] }
40
- | { readonly kind: 'macd'; readonly points: readonly MACDPoint[] };
41
-
42
- // ─── Internal ─────────────────────────────────────────────────────────────────
43
-
44
- type Node = {
45
- id: string;
46
- config: IndicatorConfig;
47
- result: DAGResult | null;
48
- /** `bars.length` at the last successful execution. */
49
- lastBarsLen: number;
50
- /** Source `IndicatorPoint[]` length at the last successful execution. */
51
- lastInputLen: number;
52
- /** Close price of the last bar at the last successful execution — detects forming-bar live ticks. */
53
- lastBarClose: number;
54
- dirty: boolean;
55
- /** Compiled TScript instance (only for type === 'script'). */
56
- scriptRuntime?: TScriptIndicator;
57
- };
58
-
59
- function _configEqual(a: IndicatorConfig, b: IndicatorConfig): boolean {
60
- return (
61
- a.type === b.type &&
62
- a.sourceId === b.sourceId &&
63
- a.sourceField === b.sourceField &&
64
- JSON.stringify(a.params) === JSON.stringify(b.params)
65
- );
66
- }
67
-
68
- // ─── IndicatorDAG ─────────────────────────────────────────────────────────────
69
-
70
- export class IndicatorDAG {
71
- private readonly _nodes = new Map<string, Node>();
72
-
73
- // ─── Registration ───────────────────────────────────────────────────────────
74
-
75
- /**
76
- * Registers a node for `id`.
77
- * If the node already exists its config is updated if changed.
78
- * Throws `'[IndicatorDAG] Circular dependency detected'` if adding `id`
79
- * would form a cycle.
80
- */
81
- addNode(id: string, config: IndicatorConfig): void {
82
- const existing = this._nodes.get(id);
83
- if (existing) {
84
- if (!_configEqual(existing.config, config)) {
85
- existing.config = config;
86
- existing.dirty = true;
87
- existing.result = null;
88
- this._markDependentsDirty(id);
89
- }
90
- return;
91
- }
92
-
93
- this._nodes.set(id, {
94
- id,
95
- config,
96
- result: null,
97
- lastBarsLen: -1,
98
- lastInputLen: -1,
99
- lastBarClose: NaN,
100
- dirty: true,
101
- });
102
-
103
- // Validate immediately — undo and rethrow if a cycle is formed.
104
- try {
105
- this._topoSort();
106
- } catch (e) {
107
- this._nodes.delete(id);
108
- throw e;
109
- }
110
- }
111
-
112
- /** Removes `id` and marks any indicators that depended on it as dirty. */
113
- removeNode(id: string): void {
114
- this._nodes.delete(id);
115
- this._markDependentsDirty(id);
116
- }
117
-
118
- /**
119
- * Syncs the DAG to exactly the provided indicator list.
120
- * Adds new nodes, removes obsolete ones, updates changed configs.
121
- * Throws if the resulting graph contains a cycle.
122
- */
123
- sync(
124
- indicators: ReadonlyArray<{ readonly id: string; readonly config: IndicatorConfig }>,
125
- ): void {
126
- const incoming = new Set(indicators.map((i) => i.id));
127
-
128
- // Remove nodes no longer present.
129
- for (const id of [...this._nodes.keys()]) {
130
- if (!incoming.has(id)) {
131
- this._nodes.delete(id);
132
- this._markDependentsDirty(id);
133
- }
134
- }
135
-
136
- // Add or refresh nodes.
137
- for (const { id, config } of indicators) {
138
- const node = this._nodes.get(id);
139
- if (!node) {
140
- this._nodes.set(id, {
141
- id,
142
- config,
143
- result: null,
144
- lastBarsLen: -1,
145
- lastInputLen: -1,
146
- lastBarClose: NaN,
147
- dirty: true,
148
- });
149
- } else if (!_configEqual(node.config, config)) {
150
- node.config = config;
151
- node.dirty = true;
152
- node.result = null;
153
- this._markDependentsDirty(id);
154
- }
155
- }
156
-
157
- // Validate the whole graph (after all additions) — throws on cycle.
158
- this._topoSort();
159
- }
160
-
161
- // ─── Execution ──────────────────────────────────────────────────────────────
162
-
163
- /**
164
- * Runs all dirty nodes in topological order.
165
- *
166
- * When the OHLCV array grew by exactly one bar since a node's last run and
167
- * its input series also grew by one, SMA and EMA use an O(1) incremental
168
- * append path. All other types fall back to a full recompute.
169
- *
170
- * @returns `true` if any node was executed.
171
- */
172
- execute(bars: readonly OHLCV[]): boolean {
173
- const order = this._topoSort();
174
- let executed = false;
175
-
176
- for (const id of order) {
177
- const node = this._nodes.get(id)!;
178
- if (!this._needsRun(node, bars)) continue;
179
-
180
- executed = true;
181
- const input = this._resolveSource(node, bars);
182
-
183
- const canIncremental =
184
- node.result !== null &&
185
- node.result.kind === 'series' &&
186
- node.result.points.length > 0 &&
187
- input.length === node.lastInputLen + 1 &&
188
- bars.length === node.lastBarsLen + 1;
189
-
190
- node.result = canIncremental
191
- ? this._appendOne(node, input, node.result!.points as readonly IndicatorPoint[], bars)
192
- : this._computeFull(node, input, bars);
193
-
194
- node.dirty = false;
195
- node.lastBarsLen = bars.length;
196
- node.lastInputLen = input.length;
197
- node.lastBarClose = bars.length > 0 ? bars[bars.length - 1]!.close : NaN;
198
- }
199
-
200
- return executed;
201
- }
202
-
203
- /** Forces every node to recompute on the next `execute()` call. */
204
- invalidateAll(): void {
205
- for (const node of this._nodes.values()) {
206
- node.dirty = true;
207
- }
208
- }
209
-
210
- isDirty(): boolean {
211
- return [...this._nodes.values()].some((n) => n.dirty);
212
- }
213
-
214
- // ─── Results ────────────────────────────────────────────────────────────────
215
-
216
- getResult(id: string): DAGResult | null {
217
- return this._nodes.get(id)?.result ?? null;
218
- }
219
-
220
- getAllResults(): ReadonlyMap<string, DAGResult> {
221
- const out = new Map<string, DAGResult>();
222
- for (const [id, node] of this._nodes) {
223
- if (node.result !== null) out.set(id, node.result);
224
- }
225
- return out;
226
- }
227
-
228
- // ─── Topological sort (Kahn's algorithm) ────────────────────────────────────
229
-
230
- /**
231
- * Returns node ids in topological execution order.
232
- * Throws `'[IndicatorDAG] Circular dependency detected'` when a cycle exists.
233
- */
234
- private _topoSort(): string[] {
235
- const inDeg = new Map<string, number>();
236
- const adj = new Map<string, string[]>(); // sourceId → dependent ids
237
-
238
- for (const node of this._nodes.values()) {
239
- if (!inDeg.has(node.id)) inDeg.set(node.id, 0);
240
- const src = node.config.sourceId;
241
- if (src !== undefined && this._nodes.has(src)) {
242
- if (!adj.has(src)) adj.set(src, []);
243
- adj.get(src)!.push(node.id);
244
- inDeg.set(node.id, (inDeg.get(node.id) ?? 0) + 1);
245
- }
246
- }
247
-
248
- const queue = [...this._nodes.keys()].filter((id) => (inDeg.get(id) ?? 0) === 0);
249
- const order: string[] = [];
250
-
251
- while (queue.length > 0) {
252
- const curr = queue.shift()!;
253
- order.push(curr);
254
- for (const dep of adj.get(curr) ?? []) {
255
- const d = (inDeg.get(dep) ?? 0) - 1;
256
- inDeg.set(dep, d);
257
- if (d === 0) queue.push(dep);
258
- }
259
- }
260
-
261
- if (order.length !== this._nodes.size) {
262
- throw new Error('[IndicatorDAG] Circular dependency detected');
263
- }
264
- return order;
265
- }
266
-
267
- // ─── Private helpers ────────────────────────────────────────────────────────
268
-
269
- private _needsRun(node: Node, bars: readonly OHLCV[]): boolean {
270
- if (node.dirty || node.result === null) return true;
271
- if (bars.length !== node.lastBarsLen) return true;
272
- // Rerun when the forming bar's close has changed (live WS tick updating in-place).
273
- if (bars.length > 0 && bars[bars.length - 1]!.close !== node.lastBarClose) return true;
274
- // Rerun if the source indicator has newer data.
275
- const srcId = node.config.sourceId;
276
- if (srcId !== undefined) {
277
- const src = this._nodes.get(srcId);
278
- if (src && src.lastBarsLen !== node.lastBarsLen) return true;
279
- }
280
- return false;
281
- }
282
-
283
- /** Returns the ordered input series for `node` — either from a source indicator or raw price field. */
284
- private _resolveSource(node: Node, bars: readonly OHLCV[]): readonly IndicatorPoint[] {
285
- const srcId = node.config.sourceId;
286
- if (srcId !== undefined) {
287
- const src = this._nodes.get(srcId);
288
- if (src?.result?.kind === 'series') return src.result.points;
289
- // Source is missing, MACD, or not yet computed — fall through to raw bars.
290
- }
291
- const field: PriceField = node.config.sourceField ?? 'close';
292
- return bars.map((b) => ({ time: b.time, value: extractField(b, field) }));
293
- }
294
-
295
- /** Full recompute of a node's result. */
296
- private _computeFull(
297
- node: Node,
298
- input: readonly IndicatorPoint[],
299
- bars: readonly OHLCV[],
300
- ): DAGResult {
301
- const p = (node.config.params ?? {}) as Record<string, number>;
302
- switch (node.config.type) {
303
- case 'sma':
304
- return { kind: 'series', points: computeSMAFromSeries(input, p['period'] ?? 20) };
305
- case 'ema':
306
- return { kind: 'series', points: computeEMAFromSeries(input, p['period'] ?? 20) };
307
- case 'wma':
308
- return { kind: 'series', points: computeWMAFromSeries(input, p['period'] ?? 20) };
309
- case 'rsi':
310
- return { kind: 'series', points: computeRSI(bars, p['period'] ?? 14) };
311
- case 'volume':
312
- return { kind: 'series', points: computeVolume(bars) };
313
- case 'macd':
314
- return {
315
- kind: 'macd',
316
- points: computeMACD(bars, p['fast'] ?? 12, p['slow'] ?? 26, p['signal'] ?? 9),
317
- };
318
- case 'bbands': {
319
- // Bollinger Bands — represented as three series; store middle band as primary.
320
- const period = p['period'] ?? 20;
321
- const sma = computeSMAFromSeries(input, period);
322
- return { kind: 'series', points: sma }; // renderer handles bbands specially
323
- }
324
- case 'script': {
325
- const src = node.config.script;
326
- if (!src) return { kind: 'series', points: [] };
327
- // Compile once, reuse across bars.
328
- if (!node.scriptRuntime) {
329
- node.scriptRuntime = new TScriptIndicator(src);
330
- }
331
- const plots = node.scriptRuntime.run(bars);
332
- // First plot() call becomes the primary series.
333
- return { kind: 'series', points: plots[0] ?? [] };
334
- }
335
- default:
336
- // Identity passthrough for unknown / future types.
337
- return { kind: 'series', points: [...input] };
338
- }
339
- }
340
-
341
- /**
342
- * O(1) append of a single new point.
343
- * Only called when `canIncremental` is true (input grew by exactly one element).
344
- * Falls back to `_computeFull` for types that have no O(1) path.
345
- */
346
- private _appendOne(
347
- node: Node,
348
- input: readonly IndicatorPoint[],
349
- prev: readonly IndicatorPoint[],
350
- bars: readonly OHLCV[],
351
- ): DAGResult {
352
- const p = (node.config.params ?? {}) as Record<string, number>;
353
- const last = input[input.length - 1]!;
354
-
355
- switch (node.config.type) {
356
- case 'sma': {
357
- const period = p['period'] ?? 20;
358
- if (input.length < period || prev.length === 0) {
359
- return this._computeFull(node, input, bars);
360
- }
361
- // O(1): newSMA = (prevSMA * period - outgoing + incoming) / period
362
- const prevSMA = prev[prev.length - 1]!.value;
363
- const outgoing = input[input.length - 1 - period]?.value ?? 0;
364
- const newValue = (prevSMA * period - outgoing + last.value) / period;
365
- return { kind: 'series', points: [...prev, { time: last.time, value: newValue }] };
366
- }
367
- case 'ema': {
368
- const period = p['period'] ?? 20;
369
- const k = 2 / (period + 1);
370
- const prevEMA = prev[prev.length - 1]!.value;
371
- const newValue = last.value * k + prevEMA * (1 - k);
372
- return { kind: 'series', points: [...prev, { time: last.time, value: newValue }] };
373
- }
374
- default:
375
- return this._computeFull(node, input, bars);
376
- }
377
- }
378
-
379
- /** Recursively marks all indicators that depend on `sourceId` as dirty. */
380
- private _markDependentsDirty(sourceId: string): void {
381
- for (const node of this._nodes.values()) {
382
- if (node.config.sourceId === sourceId && !node.dirty) {
383
- node.dirty = true;
384
- node.result = null;
385
- this._markDependentsDirty(node.id);
386
- }
387
- }
388
- }
389
- }
@@ -1,47 +0,0 @@
1
- import type { IndicatorConfig, IndicatorInstance } from '@forgecharts/types';
2
-
3
- let _counter = 0;
4
- function nextId(): string {
5
- return `indicator_${(++_counter).toString().padStart(4, '0')}`;
6
- }
7
-
8
- /**
9
- * IndicatorRegistry — tracks active indicator instances for a chart.
10
- * Rendering is a separate concern (handled by sub-pane renderers, out of SDK scope).
11
- */
12
- export class IndicatorRegistry {
13
- private readonly _map = new Map<string, IndicatorInstance>();
14
-
15
- /**
16
- * Registers a new indicator and returns its opaque id.
17
- */
18
- add(config: IndicatorConfig): string {
19
- const id = nextId();
20
- this._map.set(id, { id, config });
21
- return id;
22
- }
23
-
24
- /**
25
- * Removes an indicator by id.
26
- * @returns `true` if the indicator existed and was removed.
27
- */
28
- remove(id: string): boolean {
29
- return this._map.delete(id);
30
- }
31
-
32
- get(id: string): IndicatorInstance | undefined {
33
- return this._map.get(id);
34
- }
35
-
36
- has(id: string): boolean {
37
- return this._map.has(id);
38
- }
39
-
40
- all(): readonly IndicatorInstance[] {
41
- return [...this._map.values()];
42
- }
43
-
44
- clear(): void {
45
- this._map.clear();
46
- }
47
- }