@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,402 +0,0 @@
1
- import { describe, it, expect, vi } from 'vitest';
2
- import { CandleEngine } from '../CandleEngine';
3
- import type { CandleBar, RawOHLCV, UpdateResult, GapInfo } from '../CandleEngine';
4
- import { timeframeToMs, getBucketStart } from '../timeframeUtils';
5
- import { getMissingBarCount, mergeBars } from '../mergeUtils';
6
-
7
- // ─── Helpers ─────────────────────────────────────────────────────────────────
8
-
9
- /** Build a minimal raw bar with time in seconds. */
10
- function rawBar(
11
- timeSec: number,
12
- open: number,
13
- high: number,
14
- low: number,
15
- close: number,
16
- volume = 1,
17
- isClosed = false,
18
- ): RawOHLCV {
19
- return { time: timeSec, open, high, low, close, volume, isClosed };
20
- }
21
-
22
- /** Build a raw bar with time in milliseconds. */
23
- function rawBarMs(timeSec: number, open: number, high: number, low: number, close: number): RawOHLCV {
24
- return { time: timeSec * 1000, open, high, low, close, volume: 1 };
25
- }
26
-
27
- // 1-minute boundary: 2024-07-03T10:00:00Z = 1719997200 seconds
28
- const T0 = 1_719_997_200;
29
- const T1 = T0 + 60;
30
- const T2 = T0 + 120;
31
- const T3 = T0 + 180;
32
- const T4 = T0 + 240;
33
-
34
- // ─── 1. Same-candle update ────────────────────────────────────────────────────
35
-
36
- describe('same-candle update (3 ticks, same bucket)', () => {
37
- it('produces exactly one candle with correct O/H/L/C', () => {
38
- const engine = new CandleEngine();
39
- engine.initialize([], '1m');
40
-
41
- engine.applyLiveUpdate(rawBar(T0, 100, 105, 98, 103));
42
- engine.applyLiveUpdate(rawBar(T0, 100, 108, 96, 107)); // high rises, low drops
43
- engine.applyLiveUpdate(rawBar(T0, 100, 107, 97, 106)); // high recedes — not applied
44
-
45
- expect(engine.getBars().length).toBe(1);
46
-
47
- const bar = engine.getLastBar()!;
48
- expect(bar.open).toBe(100); // open preserved from first tick
49
- expect(bar.high).toBe(108); // max of all ticks
50
- expect(bar.low).toBe(96); // min of all ticks
51
- expect(bar.close).toBe(106); // close from latest tick
52
- });
53
-
54
- it('returns UpdateResult type "update" for same-candle ticks', () => {
55
- const engine = new CandleEngine();
56
- engine.initialize([], '1m');
57
-
58
- const r1 = engine.applyLiveUpdate(rawBar(T0, 100, 100, 100, 100));
59
- const r2 = engine.applyLiveUpdate(rawBar(T0, 100, 110, 90, 105));
60
-
61
- expect(r1.type).toBe('append'); // first tick is an append
62
- expect(r2.type).toBe('update');
63
- });
64
-
65
- it('high can never decrease within a candle', () => {
66
- const engine = new CandleEngine();
67
- engine.initialize([], '1m');
68
-
69
- engine.applyLiveUpdate(rawBar(T0, 50, 120, 40, 100));
70
- engine.applyLiveUpdate(rawBar(T0, 50, 80, 60, 90)); // high=80 < 120
71
-
72
- expect(engine.getLastBar()!.high).toBe(120);
73
- });
74
-
75
- it('low can never increase within a candle', () => {
76
- const engine = new CandleEngine();
77
- engine.initialize([], '1m');
78
-
79
- engine.applyLiveUpdate(rawBar(T0, 50, 120, 40, 100));
80
- engine.applyLiveUpdate(rawBar(T0, 50, 110, 75, 105)); // low=75 > 40
81
-
82
- expect(engine.getLastBar()!.low).toBe(40);
83
- });
84
- });
85
-
86
- // ─── 2. New-candle append ─────────────────────────────────────────────────────
87
-
88
- describe('new-candle append (time advances)', () => {
89
- it('appends a second candle and marks first as closed', () => {
90
- const engine = new CandleEngine();
91
- engine.initialize([], '1m');
92
-
93
- engine.applyLiveUpdate(rawBar(T0, 100, 105, 98, 103));
94
- const result = engine.applyLiveUpdate(rawBar(T1, 103, 110, 101, 108));
95
-
96
- expect(result.type).toBe('append');
97
- expect(engine.getBars().length).toBe(2);
98
- expect(engine.getBars()[0]!.isClosed).toBe(true);
99
- expect(engine.getBars()[1]!.isClosed).toBe(false);
100
- });
101
-
102
- it('appended candle uses the new tick\'s open price', () => {
103
- const engine = new CandleEngine();
104
- engine.initialize([], '1m');
105
-
106
- engine.applyLiveUpdate(rawBar(T0, 100, 105, 98, 103));
107
- engine.applyLiveUpdate(rawBar(T1, 200, 210, 195, 205));
108
-
109
- expect(engine.getBars()[1]!.open).toBe(200);
110
- });
111
- });
112
-
113
- // ─── 3. Out-of-order discard ──────────────────────────────────────────────────
114
-
115
- describe('out-of-order ticks', () => {
116
- it('discards ticks older than the current live candle', () => {
117
- const engine = new CandleEngine();
118
- engine.initialize([], '1m');
119
-
120
- engine.applyLiveUpdate(rawBar(T1, 103, 110, 100, 107)); // at T1
121
- const result = engine.applyLiveUpdate(rawBar(T0, 100, 120, 95, 115)); // T0 < T1
122
-
123
- expect(result.type).toBe('ignore');
124
- expect(engine.getBars().length).toBe(1);
125
- expect(engine.getLastBar()!.time).toBe(T1);
126
- });
127
-
128
- it('does not change any OHLCV values after discarding', () => {
129
- const engine = new CandleEngine();
130
- engine.initialize([], '1m');
131
-
132
- engine.applyLiveUpdate(rawBar(T1, 103, 110, 100, 107));
133
- const snapBefore = { ...engine.getLastBar()! };
134
-
135
- engine.applyLiveUpdate(rawBar(T0, 999, 999, 1, 999));
136
-
137
- expect(engine.getLastBar()!.open).toBe(snapBefore.open);
138
- expect(engine.getLastBar()!.high).toBe(snapBefore.high);
139
- expect(engine.getLastBar()!.low).toBe(snapBefore.low);
140
- expect(engine.getLastBar()!.close).toBe(snapBefore.close);
141
- });
142
- });
143
-
144
- // ─── 4. Gap detection ─────────────────────────────────────────────────────────
145
-
146
- describe('gap detection', () => {
147
- it('fires onGapDetected when a bucket is skipped', () => {
148
- const gaps: GapInfo[] = [];
149
-
150
- const engine = new CandleEngine({ onGapDetected: (g) => gaps.push(g) });
151
- engine.initialize([], '1m');
152
-
153
- engine.applyLiveUpdate(rawBar(T0, 100, 105, 98, 103));
154
- // Jump 3 minutes — T1 and T2 are missing
155
- engine.applyLiveUpdate(rawBar(T3, 110, 115, 108, 113));
156
-
157
- expect(gaps.length).toBe(1);
158
- expect(gaps[0]!.missingCount).toBe(2);
159
- expect(gaps[0]!.fromTimeMs).toBe(T0 * 1000);
160
- expect(gaps[0]!.toTimeMs).toBe(T3 * 1000);
161
- });
162
-
163
- it('returns UpdateResult type "gap" when a gap occurs', () => {
164
- const engine = new CandleEngine();
165
- engine.initialize([], '1m');
166
-
167
- engine.applyLiveUpdate(rawBar(T0, 100, 105, 98, 103));
168
- const result = engine.applyLiveUpdate(rawBar(T4, 103, 108, 101, 106));
169
-
170
- expect(result.type).toBe('gap');
171
- if (result.type === 'gap') {
172
- expect(result.missingCount).toBe(3);
173
- }
174
- });
175
-
176
- it('does not fire onGapDetected for consecutive candles', () => {
177
- const gapFn = vi.fn();
178
- const engine = new CandleEngine({ onGapDetected: gapFn });
179
- engine.initialize([], '1m');
180
-
181
- engine.applyLiveUpdate(rawBar(T0, 100, 105, 98, 103));
182
- engine.applyLiveUpdate(rawBar(T1, 103, 108, 101, 106));
183
-
184
- expect(gapFn).not.toHaveBeenCalled();
185
- });
186
- });
187
-
188
- // ─── 5. Reconnect reconciliation ─────────────────────────────────────────────
189
-
190
- describe('handleReconnect', () => {
191
- it('deduplicates bars correctly when there is overlap', () => {
192
- const engine = new CandleEngine();
193
- engine.initialize([
194
- rawBar(T0, 100, 105, 98, 103, 10, true),
195
- rawBar(T1, 103, 108, 101, 106, 12, true),
196
- rawBar(T2, 106, 110, 104, 109, 8, false), // live
197
- ], '1m');
198
-
199
- // Reconnect brings T1 and T2 with corrected values
200
- engine.handleReconnect([
201
- rawBar(T1, 103, 112, 99, 111, 15, true), // corrected T1
202
- rawBar(T2, 106, 111, 103, 110, 9, false), // corrected T2 (live)
203
- ]);
204
-
205
- expect(engine.getBars().length).toBe(3);
206
- expect(engine.getBars()[1]!.high).toBe(112); // T1 updated
207
- expect(engine.getBars()[2]!.high).toBe(111); // T2 updated
208
- });
209
-
210
- it('fires onResync after handleReconnect', () => {
211
- const resyncFn = vi.fn();
212
- const engine = new CandleEngine({ onResync: resyncFn });
213
- engine.initialize([rawBar(T0, 100, 105, 98, 103)], '1m');
214
-
215
- engine.handleReconnect([rawBar(T0, 100, 107, 96, 104)]);
216
-
217
- expect(resyncFn).toHaveBeenCalledOnce();
218
- });
219
- });
220
-
221
- // ─── 6. ms → s timestamp conversion ─────────────────────────────────────────
222
-
223
- describe('millisecond vs second timestamp normalisation', () => {
224
- it('converts ms timestamps to seconds correctly', () => {
225
- const engine = new CandleEngine();
226
- engine.initialize([], '1m');
227
-
228
- // T0 in ms
229
- engine.applyLiveUpdate(rawBarMs(T0, 100, 105, 98, 103));
230
-
231
- const bar = engine.getLastBar()!;
232
- expect(bar.time).toBe(T0); // chart field = seconds
233
- expect(bar.timeMs).toBe(T0 * 1000); // engine field = ms
234
- });
235
-
236
- it('handles both ms and s inputs in the same session without corruption', () => {
237
- const engine = new CandleEngine();
238
- engine.initialize([], '1m');
239
-
240
- engine.applyLiveUpdate(rawBarMs(T0, 100, 105, 98, 103)); // ms
241
- engine.applyLiveUpdate(rawBar(T0, 100, 110, 95, 108)); // seconds, same bucket
242
-
243
- expect(engine.getBars().length).toBe(1); // same bucket → still one candle
244
- expect(engine.getLastBar()!.high).toBe(110);
245
- });
246
-
247
- it('floors ms timestamp to candle boundary', () => {
248
- const engine = new CandleEngine();
249
- engine.initialize([], '1m');
250
-
251
- // T0 + 30s (mid-candle) in ms → should still map to T0 bucket
252
- engine.applyLiveUpdate({ time: (T0 + 30) * 1000, open: 100, high: 105, low: 98, close: 103 });
253
-
254
- expect(engine.getLastBar()!.time).toBe(T0);
255
- });
256
- });
257
-
258
- // ─── 7. Custom timeframe aggregation (timeframeUtils) ────────────────────────
259
-
260
- describe('timeframeUtils helpers', () => {
261
- it('timeframeToMs returns correct durations', () => {
262
- expect(timeframeToMs('1m')).toBe(60_000);
263
- expect(timeframeToMs('5m')).toBe(300_000);
264
- expect(timeframeToMs('1h')).toBe(3_600_000);
265
- expect(timeframeToMs('4h')).toBe(14_400_000);
266
- expect(timeframeToMs('1d')).toBe(86_400_000);
267
- // 1w and 1M are calendar timeframes — no fixed ms duration.
268
- // timeframeUtils returns the 60_000 compat fallback so CandleEngine
269
- // always receives a finite number (calendar alignment is handled separately).
270
- expect(timeframeToMs('1w')).toBe(60_000);
271
- });
272
-
273
- it('timeframeToMs falls back to 60_000 for unknown labels', () => {
274
- // '3h' and '8h' are orphaned (excluded from canonical registry) → 60_000 fallback.
275
- // '2m' is now registered (120_000) — use genuinely unknown keys here.
276
- expect(timeframeToMs('3h')).toBe(60_000);
277
- expect(timeframeToMs('')).toBe(60_000);
278
- });
279
-
280
- it('getBucketStart floors to candle boundary', () => {
281
- expect(getBucketStart(62_000, 60_000)).toBe(60_000); // 1m01s → 1m00s
282
- expect(getBucketStart(3_720_000, 3_600_000)).toBe(3_600_000); // 1h02m → 1h00m
283
- expect(getBucketStart(0, 60_000)).toBe(0);
284
- });
285
-
286
- it('5m candle engine buckets a mid-bar tick to the 5m open', () => {
287
- const engine = new CandleEngine();
288
- engine.initialize([], '5m');
289
-
290
- const T5m = getBucketStart(T0 * 1000, timeframeToMs('5m')); // floor T0 to 5m
291
- const mid = T5m / 1000 + 120; // 2 minutes into the 5m bucket
292
-
293
- engine.applyLiveUpdate({ time: mid, open: 50, high: 55, low: 48, close: 52 });
294
-
295
- expect(engine.getLastBar()!.timeMs).toBe(T5m);
296
- });
297
- });
298
-
299
- // ─── 8. mergeUtils helpers ────────────────────────────────────────────────────
300
-
301
- describe('mergeUtils helpers', () => {
302
- const makeBar = (timeSec: number, close: number, isClosed: boolean): CandleBar => ({
303
- timeMs: timeSec * 1000,
304
- time: timeSec,
305
- open: 100, high: 110, low: 90, close,
306
- volume: 1, isClosed,
307
- });
308
-
309
- it('getMissingBarCount returns 0 for consecutive bars', () => {
310
- expect(getMissingBarCount(T0 * 1000, T1 * 1000, 60_000)).toBe(0);
311
- });
312
-
313
- it('getMissingBarCount returns correct count for gap', () => {
314
- expect(getMissingBarCount(T0 * 1000, T3 * 1000, 60_000)).toBe(2); // T1 and T2
315
- expect(getMissingBarCount(T0 * 1000, T4 * 1000, 60_000)).toBe(3); // T1, T2, T3
316
- });
317
-
318
- it('mergeBars deduplicates by timeMs with incoming winning', () => {
319
- const existing = [makeBar(T0, 103, true), makeBar(T1, 106, true)];
320
- const incoming = [makeBar(T1, 999, true), makeBar(T2, 110, false)]; // T1 override
321
-
322
- const merged = mergeBars(existing, incoming);
323
-
324
- expect(merged.length).toBe(3);
325
- expect(merged[1]!.close).toBe(999); // incoming wins for closed bar
326
- expect(merged[2]!.time).toBe(T2);
327
- });
328
-
329
- it('mergeBars preserves existing live candle when incoming is also live and same time', () => {
330
- const existing = [makeBar(T0, 103, false)]; // live, close=103
331
- const incoming = [makeBar(T0, 107, false)]; // fresher live tick, close=107
332
-
333
- const merged = mergeBars(existing, incoming);
334
-
335
- // Live bar: incoming wins because it is the freshest tick
336
- expect(merged[0]!.close).toBe(107);
337
- });
338
-
339
- it('mergeBars sorts output by timeMs', () => {
340
- const bars = [makeBar(T2, 100, true), makeBar(T0, 100, true), makeBar(T1, 100, true)];
341
- const sorted = mergeBars(bars, []);
342
- expect(sorted.map(b => b.time)).toEqual([T0, T1, T2]);
343
- });
344
- });
345
-
346
- // ─── 9. backfillGap ───────────────────────────────────────────────────────────
347
-
348
- describe('backfillGap', () => {
349
- it('fills missing buckets and fires onResync', () => {
350
- const resyncFn = vi.fn();
351
-
352
- const engine = new CandleEngine({ onResync: resyncFn });
353
- engine.initialize([
354
- rawBar(T0, 100, 105, 98, 103),
355
- rawBar(T3, 110, 115, 108, 113), // gap: T1, T2 missing
356
- ], '1m');
357
-
358
- engine.backfillGap([
359
- rawBar(T1, 103, 108, 101, 106),
360
- rawBar(T2, 106, 110, 104, 109),
361
- ]);
362
-
363
- expect(engine.getBars().length).toBe(4);
364
- expect(resyncFn).toHaveBeenCalledOnce();
365
-
366
- const times = engine.getBars().map(b => b.time);
367
- expect(times).toEqual([T0, T1, T2, T3]);
368
- });
369
- });
370
-
371
- // ─── 10. CandleEngine lifecycle ──────────────────────────────────────────────
372
-
373
- describe('lifecycle', () => {
374
- it('reset() clears all bars', () => {
375
- const engine = new CandleEngine();
376
- engine.initialize([rawBar(T0, 100, 105, 98, 103)], '1m');
377
-
378
- engine.reset();
379
-
380
- expect(engine.getBars().length).toBe(0);
381
- expect(engine.getLastBar()).toBeNull();
382
- });
383
-
384
- it('handles initialize() with empty history', () => {
385
- const engine = new CandleEngine();
386
- engine.initialize([], '1m');
387
-
388
- expect(engine.getBars().length).toBe(0);
389
- expect(engine.getLastBar()).toBeNull();
390
- });
391
-
392
- it('handles duplicate historical bars (keeps last per timeMs)', () => {
393
- const engine = new CandleEngine();
394
- engine.initialize([
395
- rawBar(T0, 100, 105, 98, 103),
396
- rawBar(T0, 100, 110, 96, 108), // same time, last should win
397
- ], '1m');
398
-
399
- expect(engine.getBars().length).toBe(1);
400
- expect(engine.getLastBar()!.high).toBe(110);
401
- });
402
- });
@@ -1,172 +0,0 @@
1
- /**
2
- * Candle Invariant Guards
3
- *
4
- * Defensive assertions for the CandleEngine update pipeline.
5
- * All guards are no-ops in production (`NODE_ENV === 'production'`).
6
- *
7
- * Design principles:
8
- * - Each guard checks exactly ONE invariant and logs a descriptive warning.
9
- * - Guards never throw by default — they warn so streaming data is never blocked.
10
- * - Call sites pass a `context` string that identifies where the check ran.
11
- * - A test harness can replace `_reporter` to assert on violations.
12
- *
13
- * Usage:
14
- * import { assertOhlcRelationships, assertNotFinalized } from './candleInvariants';
15
- */
16
-
17
- import type { CandleBar } from './CandleEngine';
18
- import { getCalendarBucketStart } from './timeframeUtils';
19
-
20
- // ─── Reporter (swappable in tests) ───────────────────────────────────────────
21
-
22
- /** Called for every invariant violation. Replaced in unit tests. */
23
- export let _reporter: (message: string) => void = (msg) => console.warn(msg);
24
-
25
- /** Replace the violation reporter (for unit-test assertions). */
26
- export function _setReporter(fn: (message: string) => void): void {
27
- _reporter = fn;
28
- }
29
-
30
- /** Re-install the default console.warn reporter. */
31
- export function _resetReporter(): void {
32
- _reporter = (msg) => console.warn(msg);
33
- }
34
-
35
- // ─── Dev guard ───────────────────────────────────────────────────────────────
36
-
37
- function isDevMode(): boolean {
38
- // Access process via globalThis to avoid relying on @types/node in browser builds
39
- const nodeEnv = (globalThis as { process?: { env?: { NODE_ENV?: string } } })
40
- .process?.env?.['NODE_ENV'];
41
- return nodeEnv !== 'production';
42
- }
43
-
44
- function violation(context: string, message: string): void {
45
- _reporter(`[CANDLE_INVARIANT] ${context}: ${message}`);
46
- }
47
-
48
- // ─── Guards ───────────────────────────────────────────────────────────────────
49
-
50
- /**
51
- * Verify that `high >= open, close, low` and `low <= open, close`.
52
- *
53
- * Floats from external feeds can occasionally violate these due to rounding.
54
- * This guard surfaces them immediately rather than silently corrupting the chart.
55
- */
56
- export function assertOhlcRelationships(bar: CandleBar, context: string): void {
57
- if (!isDevMode()) return;
58
-
59
- const { open, high, low, close, timeMs } = bar;
60
-
61
- if (high < open) violation(context, `high(${high}) < open(${open}) at timeMs=${timeMs}`);
62
- if (high < close) violation(context, `high(${high}) < close(${close}) at timeMs=${timeMs}`);
63
- if (high < low) violation(context, `high(${high}) < low(${low}) at timeMs=${timeMs}`);
64
- if (low > open) violation(context, `low(${low}) > open(${open}) at timeMs=${timeMs}`);
65
- if (low > close) violation(context, `low(${low}) > close(${close}) at timeMs=${timeMs}`);
66
- }
67
-
68
- /**
69
- * Verify that `bar.timeMs` is exactly equal to the candle-open boundary for the
70
- * given timeframe. If it is not, `normalizeOhlcv` or `getCalendarBucketStart`
71
- * has a bug.
72
- */
73
- export function assertBucketAlignment(bar: CandleBar, tf: string, context: string): void {
74
- if (!isDevMode()) return;
75
-
76
- const expected = getCalendarBucketStart(bar.timeMs, tf);
77
- if (bar.timeMs !== expected) {
78
- violation(
79
- context,
80
- `timeMs(${bar.timeMs}) ≠ bucketStart(${expected}) for tf=${tf} ` +
81
- `(delta=${bar.timeMs - expected} ms)`,
82
- );
83
- }
84
- }
85
-
86
- /**
87
- * Verify that we are NOT about to mutate a candle that has already been finalised
88
- * (`isClosed === true`). Mutating a closed candle corrupts the historical record.
89
- *
90
- * Triggers on: same-bucket update landing on a bar already marked closed.
91
- */
92
- export function assertNotFinalized(bar: CandleBar, context: string): void {
93
- if (!isDevMode()) return;
94
-
95
- if (bar.isClosed) {
96
- violation(
97
- context,
98
- `attempted to mutate a finalized (isClosed=true) candle at timeMs=${bar.timeMs}`,
99
- );
100
- }
101
- }
102
-
103
- /**
104
- * Verify that a same-bucket update did NOT silently overwrite the candle's `open`.
105
- *
106
- * The first tick's open is authoritative; subsequent updates for the same bucket
107
- * must preserve it. Call this AFTER the in-place mutation with the captured
108
- * `prevOpen` value.
109
- */
110
- export function assertOpenImmutability(
111
- prevOpen: number,
112
- bar: CandleBar,
113
- context: string,
114
- ): void {
115
- if (!isDevMode()) return;
116
-
117
- if (bar.open !== prevOpen) {
118
- violation(
119
- context,
120
- `open changed from ${prevOpen} → ${bar.open} on same-bucket update ` +
121
- `at timeMs=${bar.timeMs} — first-tick open is authoritative`,
122
- );
123
- }
124
- }
125
-
126
- /**
127
- * Verify that a same-bucket update does NOT append a new bar instead of
128
- * updating the existing one.
129
- *
130
- * Call after an in-place update with the pre- and post-update bar counts.
131
- */
132
- export function assertNoDuplicateAppend(
133
- prevCount: number,
134
- nextCount: number,
135
- context: string,
136
- ): void {
137
- if (!isDevMode()) return;
138
-
139
- if (nextCount > prevCount) {
140
- violation(
141
- context,
142
- `same-bucket update incremented bar count from ${prevCount} → ${nextCount} ` +
143
- `(should have updated in-place, not appended)`,
144
- );
145
- }
146
- }
147
-
148
- /**
149
- * Verify that a new-bucket append does NOT reduce the bar count or silently
150
- * overwrite a finalized candle (would require bar count to stay the same while
151
- * the last bar's timeMs changes, which the engine never does).
152
- *
153
- * Call after appending a new bar with the previous last bar for comparison.
154
- */
155
- export function assertFinalizedUnchanged(
156
- prevLastBar: Readonly<CandleBar>,
157
- currentBars: readonly CandleBar[],
158
- context: string,
159
- ): void {
160
- if (!isDevMode()) return;
161
-
162
- const prevIndex = currentBars.findIndex(b => b.timeMs === prevLastBar.timeMs);
163
- if (prevIndex === -1) return; // bar may have been legitimately removed by merge
164
-
165
- const preserved = currentBars[prevIndex]!;
166
- if (!preserved.isClosed) {
167
- violation(
168
- context,
169
- `bar at timeMs=${prevLastBar.timeMs} should be isClosed=true after new-bucket append`,
170
- );
171
- }
172
- }
@@ -1,118 +0,0 @@
1
- /**
2
- * Timeframe utilities — thin compatibility wrappers over `@forgecharts/shared/time`.
3
- *
4
- * All bucket-alignment logic now lives in the canonical shared module.
5
- * These exports keep the existing `CandleEngine` and `DatafeedConnector` import
6
- * surface stable while delegating every calculation to the single source of truth.
7
- *
8
- * Migration note:
9
- * New code should import directly from `@forgecharts/shared/time`:
10
- * import { getBucketStart, getWeekBucketStart, getMonthBucketStart } from '@forgecharts/shared/time';
11
- *
12
- * Legacy imports from this file continue to work unchanged.
13
- */
14
-
15
- import {
16
- getBucketStart as sharedGetBucketStart,
17
- timeframeToMs as sharedTimeframeToMs,
18
- } from '@forgecharts/shared/time';
19
-
20
- // ─── timeframeToMs ────────────────────────────────────────────────────────────
21
-
22
- /**
23
- * Convert a timeframe label to its duration in milliseconds.
24
- *
25
- * Returns `60_000` (1 minute) for calendar timeframes (`1w`, `1M`) and unknown
26
- * labels — preserving the previous behaviour that `CandleEngine` depended on.
27
- * New code should use `sharedTimeframeToMs` (which returns `null` for those
28
- * cases) and handle `null` explicitly.
29
- *
30
- * @example
31
- * timeframeToMs('1m') // → 60_000
32
- * timeframeToMs('4h') // → 14_400_000
33
- * timeframeToMs('1w') // → 60_000 (calendar — no fixed duration; fallback)
34
- */
35
- export function timeframeToMs(timeframe: string): number {
36
- return sharedTimeframeToMs(timeframe) ?? 60_000;
37
- }
38
-
39
- // ─── getBucketStart (interval-based) ─────────────────────────────────────────
40
-
41
- /**
42
- * Floor a millisecond timestamp to the start of its fixed-interval bucket.
43
- *
44
- * This overload takes an explicit `intervalMs` and is used internally by
45
- * `aggregateToBucket` for sub-daily custom timeframe synthesis.
46
- *
47
- * For timeframe-label–based alignment (including 1w / 1M calendar logic)
48
- * use `getCalendarBucketStart` or import `getBucketStart` from `@forgecharts/shared`.
49
- *
50
- * @example
51
- * getBucketStart(62_000, 60_000) // → 60_000
52
- * getBucketStart(3_720_000, 3_600_000) // → 3_600_000
53
- */
54
- export function getBucketStart(timeMs: number, intervalMs: number): number {
55
- return Math.floor(timeMs / intervalMs) * intervalMs;
56
- }
57
-
58
- // ─── getCalendarBucketStart ───────────────────────────────────────────────────
59
-
60
- /**
61
- * Floor a millisecond timestamp to the candle-open boundary for the given
62
- * timeframe label, with correct calendar alignment:
63
- *
64
- * `1w` — Monday-aligned week (ISO 8601, UTC) via `getWeekBucketStart`
65
- * `1M` — first of calendar month, UTC via `getMonthBucketStart`
66
- * all others — plain epoch-floor via `getBucketStart`
67
- *
68
- * Delegates entirely to the canonical shared module.
69
- */
70
- export function getCalendarBucketStart(timeMs: number, tf: string): number {
71
- return sharedGetBucketStart(timeMs, tf);
72
- }
73
-
74
- // ─── aggregateToBucket ────────────────────────────────────────────────────────
75
-
76
- /**
77
- * Build a custom timeframe by aggregating base-timeframe candles into larger buckets.
78
- * Returns the aggregated candles for all buckets covered by `subBars`.
79
- *
80
- * This is the building block for synthesising e.g. 3m from 1m feeds.
81
- *
82
- * @param subBars Candles from the base timeframe, sorted ascending by timeMs.
83
- * @param targetMs Target timeframe duration in ms (e.g. 180_000 for 3m).
84
- *
85
- * @throws {Error} If `targetMs` corresponds to a calendar-irregular timeframe
86
- * (`1w` / `1M`). Use `getCalendarBucketStart` for those directly.
87
- */
88
- export function aggregateToBucket(
89
- subBars: ReadonlyArray<{
90
- timeMs: number; open: number; high: number; low: number; close: number; volume: number;
91
- }>,
92
- targetMs: number,
93
- ): Array<{ timeMs: number; open: number; high: number; low: number; close: number; volume: number }> {
94
- // 1w is 7 days exactly; 1M has no fixed duration and can never equal a targetMs.
95
- // Guard prevents accidentally using fixed-interval bucketing for weekly candles
96
- // where DST can make weeks slightly unequal (though UTC avoids this).
97
- const WEEK_MS = 7 * 24 * 60 * 60 * 1000; // 604_800_000
98
- if (targetMs === WEEK_MS) {
99
- throw new Error('aggregateToBucket: use getCalendarBucketStart for 1w/1M aggregation');
100
- }
101
-
102
- const buckets = new Map<number, { timeMs: number; open: number; high: number; low: number; close: number; volume: number }>();
103
-
104
- for (const bar of subBars) {
105
- const bucket = getBucketStart(bar.timeMs, targetMs);
106
- const existing = buckets.get(bucket);
107
- if (!existing) {
108
- buckets.set(bucket, { timeMs: bucket, open: bar.open, high: bar.high, low: bar.low, close: bar.close, volume: bar.volume });
109
- } else {
110
- existing.high = Math.max(existing.high, bar.high);
111
- existing.low = Math.min(existing.low, bar.low);
112
- existing.close = bar.close;
113
- existing.volume += bar.volume;
114
- }
115
- }
116
-
117
- return Array.from(buckets.values()).sort((a, b) => a.timeMs - b.timeMs);
118
- }