@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,191 +0,0 @@
1
- /**
2
- * Backward compatibility — unit tests
3
- *
4
- * Verifies that the introduction of licensing, unmanaged mode, and managed
5
- * foundations does NOT break the existing SDK contract:
6
- *
7
- * 1. All expected exports exist and have the correct shape/type
8
- * 2. CandleEngine works unchanged (no side-effects from new code)
9
- * 3. Default mode is unmanaged (safe default — nothing breaks by default)
10
- * 4. The RapidAPI datafeed path is unaffected (DatafeedConnector still exports)
11
- * 5. New modules export correctly from the package root (index.ts)
12
- */
13
-
14
- import { describe, it, expect, beforeEach } from 'vitest';
15
- import { LicenseManager } from '../licensing/LicenseManager';
16
- import { CandleEngine } from '../engine/CandleEngine';
17
- import type { RawOHLCV } from '../engine/CandleEngine';
18
-
19
- // ─── License cleanup ──────────────────────────────────────────────────────────
20
-
21
- beforeEach(() => {
22
- LicenseManager.getInstance().clear();
23
- });
24
-
25
- // ─── Existing exports remain intact ──────────────────────────────────────────
26
-
27
- describe('Backward compatibility — SDK exports', () => {
28
- it('CandleEngine is exported', async () => {
29
- const mod = await import('../engine/CandleEngine');
30
- expect(mod.CandleEngine).toBeDefined();
31
- expect(typeof mod.CandleEngine).toBe('function');
32
- });
33
-
34
- it('timeframeToMs and getBucketStart are exported', async () => {
35
- const mod = await import('../engine/timeframeUtils');
36
- expect(typeof mod.timeframeToMs).toBe('function');
37
- expect(typeof mod.getBucketStart).toBe('function');
38
- });
39
-
40
- it('LicenseManager is exported', async () => {
41
- const mod = await import('../licensing/LicenseManager');
42
- expect(mod.LicenseManager).toBeDefined();
43
- });
44
-
45
- it('ChartRuntimeResolver is exported', async () => {
46
- const mod = await import('../licensing/ChartRuntimeResolver');
47
- expect(mod.ChartRuntimeResolver).toBeDefined();
48
- expect(typeof mod.isManagedMode).toBe('function');
49
- expect(typeof mod.isUnmanagedMode).toBe('function');
50
- expect(typeof mod.canRenderOrderEntry).toBe('function');
51
- expect(typeof mod.canRenderManagedTradingControls).toBe('function');
52
- expect(typeof mod.canRenderExternalOverlayOnlyMode).toBe('function');
53
- });
54
-
55
- it('TradingOverlayStore is exported', async () => {
56
- const mod = await import('../trading/TradingOverlayStore');
57
- expect(mod.TradingOverlayStore).toBeDefined();
58
- expect(typeof mod.TradingOverlayStore).toBe('function');
59
- });
60
-
61
- it('UnmanagedIngestion is exported', async () => {
62
- const mod = await import('../trading/UnmanagedIngestion');
63
- expect(mod.UnmanagedIngestion).toBeDefined();
64
- expect(typeof mod.UnmanagedIngestion).toBe('function');
65
- });
66
-
67
- it('ManagedTradingController is exported', async () => {
68
- const mod = await import('../trading/managed/ManagedTradingController');
69
- expect(mod.ManagedTradingController).toBeDefined();
70
- expect(typeof mod.ManagedTradingController).toBe('function');
71
- });
72
-
73
- it('DatafeedConnector is exported (default RapidAPI path intact)', async () => {
74
- const mod = await import('../datafeed/DatafeedConnector');
75
- expect(mod.DatafeedConnector).toBeDefined();
76
- expect(typeof mod.DatafeedConnector).toBe('function');
77
- });
78
- });
79
-
80
- // ─── CandleEngine unchanged ───────────────────────────────────────────────────
81
-
82
- describe('Backward compatibility — CandleEngine still works with no license', () => {
83
- // T0 = 2024-07-03T10:00:00Z in seconds
84
- const T0 = 1_719_997_200;
85
- const T1 = T0 + 60;
86
-
87
- function raw(time: number, close: number): RawOHLCV {
88
- return { time, open: 100, high: close + 5, low: close - 5, close, volume: 1 };
89
- }
90
-
91
- it('can be instantiated and used without any license', () => {
92
- const engine = new CandleEngine();
93
- expect(() => engine.initialize([], '1m')).not.toThrow();
94
- });
95
-
96
- it('basic OHLCV update works — no licensing side-effects', () => {
97
- const engine = new CandleEngine();
98
- engine.initialize([], '1m');
99
-
100
- engine.applyLiveUpdate(raw(T0, 100));
101
- engine.applyLiveUpdate(raw(T0, 105));
102
- engine.applyLiveUpdate(raw(T1, 110));
103
-
104
- expect(engine.getBars()).toHaveLength(2);
105
- expect(engine.getBars()[0]!.close).toBe(105);
106
- expect(engine.getBars()[1]!.close).toBe(110);
107
- });
108
-
109
- it('initialize() resets state completely', () => {
110
- const engine = new CandleEngine();
111
- engine.initialize([], '1m');
112
- engine.applyLiveUpdate(raw(T0, 100));
113
- engine.initialize([], '5m');
114
- expect(engine.getBars()).toHaveLength(0);
115
- });
116
- });
117
-
118
- // ─── Default license mode — safe unmanaged defaults ──────────────────────────
119
-
120
- describe('Backward compatibility — default mode is unmanaged', () => {
121
- it('LicenseManager.getMode() returns unmanaged with no license', () => {
122
- const lm = LicenseManager.getInstance();
123
- expect(lm.getMode()).toBe('unmanaged');
124
- expect(lm.getLicense()).toBeNull();
125
- });
126
-
127
- it('isUnmanagedMode() is true with no license', async () => {
128
- const { isUnmanagedMode } = await import('../licensing/ChartRuntimeResolver');
129
- expect(isUnmanagedMode()).toBe(true);
130
- });
131
-
132
- it('isManagedMode() is false with no license', async () => {
133
- const { isManagedMode } = await import('../licensing/ChartRuntimeResolver');
134
- expect(isManagedMode()).toBe(false);
135
- });
136
-
137
- it('canRenderCandles() is true with no license', async () => {
138
- const { canRenderCandles } = await import('../licensing/ChartRuntimeResolver');
139
- expect(canRenderCandles()).toBe(true);
140
- });
141
-
142
- it('canRenderorderEntry() is false with no license', async () => {
143
- const { canRenderOrderEntry } = await import('../licensing/ChartRuntimeResolver');
144
- expect(canRenderOrderEntry()).toBe(false);
145
- });
146
-
147
- it('canRenderManagedTradingControls() is false with no license', async () => {
148
- const { canRenderManagedTradingControls } = await import('../licensing/ChartRuntimeResolver');
149
- expect(canRenderManagedTradingControls()).toBe(false);
150
- });
151
- });
152
-
153
- // ─── Unmanaged ingestion is additive — does not replace the existing datafeed ─
154
-
155
- describe('Backward compatibility — unmanaged ingestion is opt-in and additive', () => {
156
- it('UnmanagedIngestion can be instantiated without affecting CandleEngine state', async () => {
157
- const standaloneEngine = new CandleEngine();
158
- standaloneEngine.initialize([], '1m');
159
-
160
- // Creating an UnmanagedIngestion constructs its OWN internal CandleEngine
161
- const { UnmanagedIngestion } = await import('../trading/UnmanagedIngestion');
162
- const ing = new UnmanagedIngestion('1m');
163
-
164
- // The standalone engine is still clean
165
- expect(standaloneEngine.getBars()).toHaveLength(0);
166
- // The ingestion engine also starts empty
167
- expect(ing.getBars()).toHaveLength(0);
168
- });
169
-
170
- it('DatafeedConnector can still be constructed independently', async () => {
171
- const { DatafeedConnector } = await import('../datafeed/DatafeedConnector');
172
- const mockDatafeed = {
173
- getHistoricalBars: () => Promise.resolve({ bars: [], noData: true }),
174
- subscribeBars: () => {},
175
- unsubscribeBars: () => {},
176
- };
177
- const mockSeries = {
178
- setData: () => {},
179
- update: () => {},
180
- data: () => [],
181
- applyOptions: () => {},
182
- options: () => ({} as never),
183
- };
184
- const mockCallbacks = {
185
- onLoading: () => {},
186
- onLoaded: () => {},
187
- onError: () => {},
188
- };
189
- expect(() => new DatafeedConnector(mockDatafeed, mockSeries, mockCallbacks)).not.toThrow();
190
- });
191
- });
@@ -1,500 +0,0 @@
1
- /**
2
- * Candle Invariant Tests
3
- *
4
- * Verifies that the invariant guards in `candleInvariants.ts` fire correctly,
5
- * and that `CandleEngine.applyLiveUpdate` maintains all invariants during
6
- * normal operation (no warnings) and surfaces violations during abnormal
7
- * conditions (mocked guard paths).
8
- *
9
- * Test categories:
10
- * 1. assertOhlcRelationships — each OHLC violation is detected independently
11
- * 2. assertBucketAlignment — misaligned timestamps are caught
12
- * 3. assertNotFinalized — mutating a closed bar triggers the guard
13
- * 4. assertOpenImmutability — open-price overwrite is detected
14
- * 5. assertNoDuplicateAppend — same-bucket spurious append is detected
15
- * 6. assertFinalizedUnchanged — new-bucket finalisation is verified
16
- * 7. CandleEngine integration — no spurious warnings during correct operation
17
- * 8. barDivergenceCheck — compareSources and formatReport
18
- */
19
-
20
- import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
21
- import {
22
- assertOhlcRelationships,
23
- assertBucketAlignment,
24
- assertNotFinalized,
25
- assertOpenImmutability,
26
- assertNoDuplicateAppend,
27
- assertFinalizedUnchanged,
28
- _setReporter,
29
- _resetReporter,
30
- } from '../engine/candleInvariants';
31
- import type { CandleBar } from '../engine/CandleEngine';
32
- import { CandleEngine } from '../engine/CandleEngine';
33
- import type { RawOHLCV } from '../engine/CandleEngine';
34
- import {
35
- compareSources,
36
- checkAllSources,
37
- formatReport,
38
- } from '../tools/barDivergenceCheck';
39
- import type { SourceBars } from '../tools/barDivergenceCheck';
40
-
41
- // ─── Reporter harness ─────────────────────────────────────────────────────────
42
-
43
- /**
44
- * During tests we capture invariant violation messages instead of printing
45
- * them to console. This lets us assert on the exact message content.
46
- */
47
- let violations: string[] = [];
48
-
49
- beforeEach(() => {
50
- violations = [];
51
- _setReporter((msg) => violations.push(msg));
52
- });
53
-
54
- afterEach(() => {
55
- _resetReporter();
56
- });
57
-
58
- // ─── Fixtures ─────────────────────────────────────────────────────────────────
59
-
60
- /** Build a valid, closed CandleBar. */
61
- function validBar(overrides: Partial<CandleBar> = {}): CandleBar {
62
- return {
63
- timeMs: 60_000,
64
- time: 60,
65
- open: 100,
66
- high: 110,
67
- low: 90,
68
- close: 105,
69
- volume: 1,
70
- isClosed: true,
71
- ...overrides,
72
- };
73
- }
74
-
75
- /** Unix seconds helper. */
76
- const sec = (iso: string): number => new Date(iso).getTime() / 1000;
77
-
78
- /** Build a minimal RawOHLCV tick for the engine. */
79
- function tick(
80
- timeSec: number,
81
- open = 100, high = 110, low = 90, close = 105, volume = 1,
82
- ): RawOHLCV {
83
- return { time: timeSec, open, high, low, close, volume };
84
- }
85
-
86
- // ─── 1. assertOhlcRelationships ───────────────────────────────────────────────
87
-
88
- describe('assertOhlcRelationships', () => {
89
- it('passes for a valid OHLC bar with no violations', () => {
90
- assertOhlcRelationships(validBar(), 'test');
91
- expect(violations).toHaveLength(0);
92
- });
93
-
94
- it('detects high < open', () => {
95
- assertOhlcRelationships(validBar({ open: 120, high: 110 }), 'ctx');
96
- expect(violations.some(v => v.includes('high') && v.includes('open'))).toBe(true);
97
- });
98
-
99
- it('detects high < close', () => {
100
- assertOhlcRelationships(validBar({ close: 120, high: 110 }), 'ctx');
101
- expect(violations.some(v => v.includes('high') && v.includes('close'))).toBe(true);
102
- });
103
-
104
- it('detects high < low', () => {
105
- assertOhlcRelationships(validBar({ high: 80, low: 90 }), 'ctx');
106
- expect(violations.some(v => v.includes('high') && v.includes('low'))).toBe(true);
107
- });
108
-
109
- it('detects low > open', () => {
110
- assertOhlcRelationships(validBar({ open: 80, low: 90 }), 'ctx');
111
- expect(violations.some(v => v.includes('low') && v.includes('open'))).toBe(true);
112
- });
113
-
114
- it('detects low > close', () => {
115
- assertOhlcRelationships(validBar({ close: 80, low: 90 }), 'ctx');
116
- expect(violations.some(v => v.includes('low') && v.includes('close'))).toBe(true);
117
- });
118
-
119
- it('open === high === low === close is valid (doji candle)', () => {
120
- assertOhlcRelationships(validBar({ open: 100, high: 100, low: 100, close: 100 }), 'ctx');
121
- expect(violations).toHaveLength(0);
122
- });
123
-
124
- it('includes context and timeMs in violation message', () => {
125
- assertOhlcRelationships(validBar({ open: 120, high: 110, timeMs: 99_000 }), 'myCtx');
126
- expect(violations[0]).toContain('[CANDLE_INVARIANT]');
127
- expect(violations[0]).toContain('myCtx');
128
- expect(violations[0]).toContain('99000');
129
- });
130
- });
131
-
132
- // ─── 2. assertBucketAlignment ─────────────────────────────────────────────────
133
-
134
- describe('assertBucketAlignment', () => {
135
- it('passes when timeMs is exactly on the 1m boundary', () => {
136
- // 60_000 ms = exactly 1 minute from epoch — valid 1m bucket start
137
- assertBucketAlignment(validBar({ timeMs: 60_000, time: 60 }), '1m', 'test');
138
- expect(violations).toHaveLength(0);
139
- });
140
-
141
- it('detects timeMs not on a 1m boundary', () => {
142
- // 62_500 ms is NOT on a 60_000-ms boundary
143
- assertBucketAlignment(validBar({ timeMs: 62_500, time: 62 }), '1m', 'test');
144
- expect(violations.length).toBeGreaterThan(0);
145
- expect(violations[0]).toContain('timeMs');
146
- });
147
-
148
- it('passes for 1h boundary', () => {
149
- const hourStart = new Date('2025-03-09T14:00:00Z').getTime();
150
- assertBucketAlignment(validBar({ timeMs: hourStart, time: hourStart / 1000 }), '1h', 'test');
151
- expect(violations).toHaveLength(0);
152
- });
153
-
154
- it('detects misaligned 1h timestamp (30 min off)', () => {
155
- const thirtyMin = new Date('2025-03-09T14:30:00Z').getTime();
156
- assertBucketAlignment(validBar({ timeMs: thirtyMin, time: thirtyMin / 1000 }), '1h', 'test');
157
- expect(violations.length).toBeGreaterThan(0);
158
- });
159
-
160
- it('passes for a Monday 00:00 UTC timestamp with 1w', () => {
161
- const monday = new Date('2025-03-03T00:00:00Z').getTime();
162
- assertBucketAlignment(validBar({ timeMs: monday, time: monday / 1000 }), '1w', 'test');
163
- expect(violations).toHaveLength(0);
164
- });
165
-
166
- it('detects misaligned 1w timestamp (mid-week)', () => {
167
- const wednesday = new Date('2025-03-05T12:00:00Z').getTime();
168
- assertBucketAlignment(validBar({ timeMs: wednesday, time: wednesday / 1000 }), '1w', 'test');
169
- expect(violations.length).toBeGreaterThan(0);
170
- });
171
-
172
- it('passes for first-of-month timestamp with 1M', () => {
173
- const monthStart = new Date('2025-03-01T00:00:00Z').getTime();
174
- assertBucketAlignment(validBar({ timeMs: monthStart, time: monthStart / 1000 }), '1M', 'test');
175
- expect(violations).toHaveLength(0);
176
- });
177
-
178
- it('detects mid-month timestamp with 1M', () => {
179
- const midMonth = new Date('2025-03-15T00:00:00Z').getTime();
180
- assertBucketAlignment(validBar({ timeMs: midMonth, time: midMonth / 1000 }), '1M', 'test');
181
- expect(violations.length).toBeGreaterThan(0);
182
- });
183
- });
184
-
185
- // ─── 3. assertNotFinalized ────────────────────────────────────────────────────
186
-
187
- describe('assertNotFinalized', () => {
188
- it('passes for an open (live) candle', () => {
189
- assertNotFinalized(validBar({ isClosed: false }), 'test');
190
- expect(violations).toHaveLength(0);
191
- });
192
-
193
- it('fires for a closed candle', () => {
194
- assertNotFinalized(validBar({ isClosed: true }), 'test');
195
- expect(violations.length).toBeGreaterThan(0);
196
- expect(violations[0]).toContain('finalized');
197
- });
198
-
199
- it('violation message contains context and timeMs', () => {
200
- assertNotFinalized(validBar({ isClosed: true, timeMs: 180_000 }), 'liveUpdate');
201
- expect(violations[0]).toContain('liveUpdate');
202
- expect(violations[0]).toContain('180000');
203
- });
204
- });
205
-
206
- // ─── 4. assertOpenImmutability ────────────────────────────────────────────────
207
-
208
- describe('assertOpenImmutability', () => {
209
- it('passes when open is unchanged', () => {
210
- const bar = validBar({ open: 100 });
211
- assertOpenImmutability(100, bar, 'test');
212
- expect(violations).toHaveLength(0);
213
- });
214
-
215
- it('fires when open changed', () => {
216
- const bar = validBar({ open: 200 });
217
- assertOpenImmutability(100, bar, 'ctx');
218
- expect(violations.length).toBeGreaterThan(0);
219
- expect(violations[0]).toContain('open');
220
- });
221
-
222
- it('violation message shows previous and new open', () => {
223
- const bar = validBar({ open: 200, timeMs: 120_000 });
224
- assertOpenImmutability(100, bar, 'ctx');
225
- expect(violations[0]).toContain('100');
226
- expect(violations[0]).toContain('200');
227
- expect(violations[0]).toContain('120000');
228
- });
229
- });
230
-
231
- // ─── 5. assertNoDuplicateAppend ───────────────────────────────────────────────
232
-
233
- describe('assertNoDuplicateAppend', () => {
234
- it('passes when count is unchanged', () => {
235
- assertNoDuplicateAppend(5, 5, 'test');
236
- expect(violations).toHaveLength(0);
237
- });
238
-
239
- it('fires when count increased (spurious append)', () => {
240
- assertNoDuplicateAppend(5, 6, 'ctx');
241
- expect(violations.length).toBeGreaterThan(0);
242
- expect(violations[0]).toContain('same-bucket');
243
- });
244
- });
245
-
246
- // ─── 6. assertFinalizedUnchanged ─────────────────────────────────────────────
247
-
248
- describe('assertFinalizedUnchanged', () => {
249
- it('passes when the previous bar is now isClosed', () => {
250
- const prev = validBar({ timeMs: 60_000, isClosed: false });
251
- const current: CandleBar[] = [
252
- { ...prev, isClosed: true },
253
- validBar({ timeMs: 120_000, isClosed: false }),
254
- ];
255
- assertFinalizedUnchanged(prev, current, 'test');
256
- expect(violations).toHaveLength(0);
257
- });
258
-
259
- it('fires when the previous bar is still open after a new-bucket append', () => {
260
- const prev = validBar({ timeMs: 60_000, isClosed: false });
261
- const current: CandleBar[] = [
262
- { ...prev, isClosed: false }, // not closed — violation
263
- validBar({ timeMs: 120_000, isClosed: false }),
264
- ];
265
- assertFinalizedUnchanged(prev, current, 'test');
266
- expect(violations.length).toBeGreaterThan(0);
267
- expect(violations[0]).toContain('isClosed');
268
- });
269
-
270
- it('passes when the bar was removed (e.g. after a merge)', () => {
271
- const prev = validBar({ timeMs: 60_000 });
272
- // prev is not in `current` at all — should not fire
273
- assertFinalizedUnchanged(prev, [], 'test');
274
- expect(violations).toHaveLength(0);
275
- });
276
- });
277
-
278
- // ─── 7. CandleEngine integration — no spurious warnings ──────────────────────
279
-
280
- describe('CandleEngine integration — clean operation produces no violations', () => {
281
- const TF = '1m';
282
- const T0 = sec('2025-03-09T14:00:00Z');
283
- const T1 = sec('2025-03-09T14:01:00Z');
284
- const T2 = sec('2025-03-09T14:02:00Z');
285
-
286
- it('single tick produces no invariant violations', () => {
287
- const engine = new CandleEngine();
288
- engine.initialize([], TF as any);
289
- engine.applyLiveUpdate(tick(T0, 100, 110, 90, 105));
290
- expect(violations).toHaveLength(0);
291
- });
292
-
293
- it('same-bucket updates produce no violations', () => {
294
- const engine = new CandleEngine();
295
- engine.initialize([], TF as any);
296
- engine.applyLiveUpdate(tick(T0, 100, 110, 90, 105));
297
- engine.applyLiveUpdate(tick(T0 + 30, 100, 120, 85, 115));
298
- engine.applyLiveUpdate(tick(T0 + 45, 100, 120, 85, 112));
299
- expect(violations).toHaveLength(0);
300
- });
301
-
302
- it('new-bucket append produces no violations', () => {
303
- const engine = new CandleEngine();
304
- engine.initialize([], TF as any);
305
- engine.applyLiveUpdate(tick(T0, 100, 110, 90, 105));
306
- engine.applyLiveUpdate(tick(T1, 106, 120, 100, 115));
307
- engine.applyLiveUpdate(tick(T2, 116, 125, 110, 120));
308
- expect(violations).toHaveLength(0);
309
- });
310
-
311
- it('backfillGap produces no violations', () => {
312
- const T4 = sec('2025-03-09T14:04:00Z');
313
- const engine = new CandleEngine();
314
- engine.initialize([tick(T0, 100, 110, 90, 105)], TF as any);
315
- engine.applyLiveUpdate(tick(T4, 130, 140, 120, 135));
316
- engine.backfillGap([
317
- tick(T1, 106, 115, 100, 112),
318
- tick(T2, 112, 118, 105, 116),
319
- ]);
320
- expect(violations).toHaveLength(0);
321
- });
322
-
323
- it('handleReconnect produces no violations', () => {
324
- const engine = new CandleEngine();
325
- engine.initialize([
326
- tick(T0, 100, 110, 90, 105),
327
- tick(T1, 106, 112, 100, 110),
328
- ], TF as any);
329
- engine.handleReconnect([
330
- tick(T0, 100, 115, 88, 112),
331
- tick(T1, 106, 118, 96, 115),
332
- ]);
333
- expect(violations).toHaveLength(0);
334
- });
335
-
336
- it('weekly timeframe: calendar-aligned ticks produce no violations', () => {
337
- const MONDAY = sec('2025-03-03T00:00:00Z');
338
- const WEDNESDAY = sec('2025-03-05T12:00:00Z');
339
- const FRIDAY = sec('2025-03-07T18:00:00Z');
340
-
341
- const engine = new CandleEngine();
342
- engine.initialize([], '1w' as any);
343
-
344
- engine.applyLiveUpdate(tick(MONDAY, 40000, 42000, 39000, 41000));
345
- // Wed and Fri are in the same 1w bucket — updates only
346
- engine.applyLiveUpdate(tick(WEDNESDAY, 40000, 45000, 38000, 44000));
347
- engine.applyLiveUpdate(tick(FRIDAY, 40000, 46000, 37500, 43000));
348
-
349
- expect(violations).toHaveLength(0);
350
- expect(engine.getBars().length).toBe(1); // still the same weekly candle
351
- });
352
-
353
- it('monthly timeframe: calendar-aligned ticks produce no violations', () => {
354
- const MAR_01 = sec('2025-03-01T00:00:00Z');
355
- const MAR_15 = sec('2025-03-15T12:00:00Z');
356
- const APR_01 = sec('2025-04-01T00:00:00Z');
357
-
358
- const engine = new CandleEngine();
359
- engine.initialize([], '1M' as any);
360
-
361
- engine.applyLiveUpdate(tick(MAR_01, 40000, 42000, 39000, 41000));
362
- engine.applyLiveUpdate(tick(MAR_15, 40000, 45000, 38000, 44000)); // same month
363
- engine.applyLiveUpdate(tick(APR_01, 44000, 46000, 43000, 45000));// new month
364
-
365
- expect(violations).toHaveLength(0);
366
- expect(engine.getBars().length).toBe(2); // March + April
367
- });
368
- });
369
-
370
- // ─── 8. barDivergenceCheck ────────────────────────────────────────────────────
371
-
372
- describe('compareSources — identical sources', () => {
373
- const BARS: SourceBars = {
374
- source: 'provider',
375
- bars: [
376
- { time: 1_000_000, open: 100, high: 110, low: 90, close: 105 },
377
- { time: 1_000_060, open: 105, high: 115, low: 100, close: 112 },
378
- { time: 1_000_120, open: 112, high: 120, low: 108, close: 118 },
379
- ],
380
- };
381
- const DB_BARS: SourceBars = { source: 'database', bars: BARS.bars };
382
-
383
- it('returns diverged=false when both sources are identical', () => {
384
- const report = compareSources(BARS, DB_BARS, '1m', 'BTC', 1_000_000, 1_000_180);
385
- expect(report.diverged).toBe(false);
386
- expect(report.totalMismatches).toBe(0);
387
- expect(report.firstMismatch).toBeNull();
388
- });
389
-
390
- it('correct source counts', () => {
391
- const report = compareSources(BARS, DB_BARS, '1m', 'BTC', 1_000_000, 1_000_180);
392
- expect(report.sourceACount).toBe(3);
393
- expect(report.sourceBCount).toBe(3);
394
- });
395
- });
396
-
397
- describe('compareSources — OHLC divergence', () => {
398
- it('detects first high mismatch and reports field name', () => {
399
- const provider: SourceBars = {
400
- source: 'provider',
401
- bars: [
402
- { time: 1_000_000, open: 100, high: 110, low: 90, close: 105 },
403
- { time: 1_000_060, open: 105, high: 115, low: 100, close: 112 },
404
- ],
405
- };
406
- const db: SourceBars = {
407
- source: 'database',
408
- bars: [
409
- { time: 1_000_000, open: 100, high: 110, low: 90, close: 105 },
410
- { time: 1_000_060, open: 105, high: 999, low: 100, close: 112 }, // high differs
411
- ],
412
- };
413
- const report = compareSources(provider, db, '1m', 'BTC', 1_000_000, 1_000_120);
414
- expect(report.diverged).toBe(true);
415
- expect(report.firstMismatch).not.toBeNull();
416
- expect(report.firstMismatch!.time).toBe(1_000_060);
417
- expect(report.firstMismatch!.differences.some(d => d.field === 'high')).toBe(true);
418
- });
419
-
420
- it('detects missing bar in one source', () => {
421
- const provider: SourceBars = {
422
- source: 'provider',
423
- bars: [
424
- { time: 1_000_000, open: 100, high: 110, low: 90, close: 105 },
425
- { time: 1_000_060, open: 105, high: 115, low: 100, close: 112 },
426
- ],
427
- };
428
- const db: SourceBars = {
429
- source: 'database',
430
- bars: [
431
- { time: 1_000_000, open: 100, high: 110, low: 90, close: 105 },
432
- // 1_000_060 is missing
433
- ],
434
- };
435
- const report = compareSources(provider, db, '1m', 'BTC', 1_000_000, 1_000_120);
436
- expect(report.diverged).toBe(true);
437
- expect(report.firstMismatch!.time).toBe(1_000_060);
438
- expect(report.firstMismatch!.notes.some(n => n.includes('missing'))).toBe(true);
439
- });
440
-
441
- it('reports first mismatch in time order even if later mismatches exist', () => {
442
- const provider: SourceBars = {
443
- source: 'provider',
444
- bars: [
445
- { time: 1_000_000, open: 100, high: 200, low: 90, close: 150 }, // high differs
446
- { time: 1_000_060, open: 105, high: 300, low: 100, close: 200 }, // high also differs
447
- ],
448
- };
449
- const db: SourceBars = {
450
- source: 'database',
451
- bars: [
452
- { time: 1_000_000, open: 100, high: 110, low: 90, close: 150 },
453
- { time: 1_000_060, open: 105, high: 115, low: 100, close: 200 },
454
- ],
455
- };
456
- const report = compareSources(provider, db, '1m', 'BTC', 1_000_000, 1_000_120);
457
- expect(report.firstMismatch!.time).toBe(1_000_000); // oldest first
458
- expect(report.totalMismatches).toBe(2);
459
- });
460
- });
461
-
462
- describe('checkAllSources', () => {
463
- it('produces N*(N-1)/2 pairwise reports', () => {
464
- const sources = [
465
- { source: 'provider' as const, bars: [] },
466
- { source: 'database' as const, bars: [] },
467
- { source: 'sdk' as const, bars: [] },
468
- ];
469
- const reports = checkAllSources(sources, 'BTC', '1h', 0, 100_000);
470
- expect(reports.length).toBe(3); // C(3,2) = 3
471
- });
472
- });
473
-
474
- describe('formatReport', () => {
475
- it('includes IDENTICAL when no divergence', () => {
476
- const bars: SourceBars = {
477
- source: 'provider',
478
- bars: [{ time: 1_000_000, open: 100, high: 110, low: 90, close: 105 }],
479
- };
480
- const report = compareSources(bars, { source: 'database', bars: bars.bars }, '1m', 'BTC', 1_000_000, 1_000_060);
481
- const text = formatReport(report);
482
- expect(text).toContain('IDENTICAL');
483
- });
484
-
485
- it('includes DIVERGED and mismatch details when sources differ', () => {
486
- const provider: SourceBars = {
487
- source: 'provider',
488
- bars: [{ time: 1_000_000, open: 100, high: 999, low: 90, close: 105 }],
489
- };
490
- const db: SourceBars = {
491
- source: 'database',
492
- bars: [{ time: 1_000_000, open: 100, high: 110, low: 90, close: 105 }],
493
- };
494
- const report = compareSources(provider, db, '1m', 'BTC', 1_000_000, 1_000_060);
495
- const text = formatReport(report);
496
- expect(text).toContain('DIVERGED');
497
- expect(text).toContain('1000000'); // time
498
- expect(text).toContain('high');
499
- });
500
- });