gloomberb 0.7.4 → 0.8.0

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 (1293) hide show
  1. package/README.md +27 -6
  2. package/package.json +2 -3
  3. package/src/api-client/auth.ts +167 -0
  4. package/src/api-client/chat.ts +116 -0
  5. package/src/api-client/data.ts +177 -0
  6. package/src/api-client/errors.ts +28 -0
  7. package/src/api-client/index.test.ts +675 -0
  8. package/src/api-client/index.ts +384 -0
  9. package/src/api-client/normalizers.ts +61 -0
  10. package/src/api-client/paths.ts +173 -0
  11. package/src/api-client/request.ts +124 -0
  12. package/src/api-client/socket.ts +483 -0
  13. package/src/api-client/types.ts +490 -0
  14. package/src/app/app-bootstrap-state.test.ts +157 -0
  15. package/src/app/app-bootstrap-state.ts +134 -0
  16. package/src/app/global-shortcuts.test.tsx +166 -0
  17. package/src/app/global-shortcuts.ts +126 -0
  18. package/src/app/pane-runtime/index.tsx +297 -0
  19. package/src/app/pane-runtime/layout-placement.ts +73 -0
  20. package/src/app/pane-runtime/pane-settings-runtime.tsx +67 -0
  21. package/src/app/pane-runtime/pane-template-runtime.ts +110 -0
  22. package/src/app/pane-runtime/plugin-bindings.ts +231 -0
  23. package/src/app/pane-runtime/ticker-inspector-runtime.ts +167 -0
  24. package/src/app/pane-runtime/ticker-open-runtime.ts +144 -0
  25. package/src/app/pane-template-dialog-wizard.tsx +52 -0
  26. package/src/app/runtime/broker-import.ts +109 -0
  27. package/src/app/runtime/desktop-menu.ts +74 -0
  28. package/src/app/runtime/plugin-bindings.ts +246 -0
  29. package/src/app/runtime/startup.ts +126 -0
  30. package/src/app/runtime/ticker-refresh.ts +249 -0
  31. package/src/app/runtime/update.ts +86 -0
  32. package/src/app.tsx +110 -1461
  33. package/src/brokers/broker-portfolio-sync.ts +186 -0
  34. package/src/brokers/broker-ticker-sync.ts +141 -0
  35. package/src/brokers/profile-form.ts +2 -2
  36. package/src/brokers/remote-broker-adapter.ts +3 -2
  37. package/src/brokers/sync-broker-instance.test.ts +140 -0
  38. package/src/brokers/sync-broker-instance.ts +60 -181
  39. package/src/capabilities/types.ts +4 -4
  40. package/src/cli/commands/search.ts +1 -1
  41. package/src/cli/commands/ticker.ts +3 -3
  42. package/src/cli/context.ts +1 -1
  43. package/src/cli/desktop-pane-shot.ts +305 -0
  44. package/src/cli/helpers.ts +1 -1
  45. package/src/cli/index.ts +34 -0
  46. package/src/cli/pane-functions/catalog.ts +243 -0
  47. package/src/cli/pane-functions/data.ts +78 -0
  48. package/src/cli/pane-functions/discovery.ts +113 -0
  49. package/src/cli/pane-functions/index.test.ts +114 -0
  50. package/src/cli/pane-functions/index.ts +112 -0
  51. package/src/cli/pane-functions/options.ts +249 -0
  52. package/src/cli/pane-functions/report.ts +180 -0
  53. package/src/cli/pane-functions/resolver.ts +96 -0
  54. package/src/cli/pane-functions/screenshot.ts +113 -0
  55. package/src/cli/registry.ts +3 -2
  56. package/src/cli/ticker-resolution.ts +1 -1
  57. package/src/cli.test.ts +1 -1
  58. package/src/components/chart/bar-chart-renderer.test.ts +53 -0
  59. package/src/components/chart/bar-chart-renderer.ts +190 -0
  60. package/src/components/chart/comparison/data.test.ts +105 -0
  61. package/src/components/chart/comparison/data.ts +279 -0
  62. package/src/components/chart/comparison/renderer.test.ts +187 -0
  63. package/src/components/chart/comparison/renderer.ts +283 -0
  64. package/src/components/chart/comparison/scene.ts +178 -0
  65. package/src/components/chart/comparison-stock-chart/axis-width.ts +99 -0
  66. package/src/components/chart/comparison-stock-chart/canvas.ts +148 -0
  67. package/src/components/chart/comparison-stock-chart/controls.ts +252 -0
  68. package/src/components/chart/comparison-stock-chart/helpers.ts +133 -0
  69. package/src/components/chart/comparison-stock-chart/interactions.ts +202 -0
  70. package/src/components/chart/comparison-stock-chart/layout-metrics.ts +62 -0
  71. package/src/components/chart/comparison-stock-chart/layout.tsx +155 -0
  72. package/src/components/chart/comparison-stock-chart/legend.tsx +73 -0
  73. package/src/components/chart/comparison-stock-chart/native-surfaces.ts +89 -0
  74. package/src/components/chart/comparison-stock-chart/render-data.ts +198 -0
  75. package/src/components/chart/comparison-stock-chart/render-output.ts +145 -0
  76. package/src/components/chart/comparison-stock-chart/selection-runtime.ts +111 -0
  77. package/src/components/chart/comparison-stock-chart/sources.ts +47 -0
  78. package/src/components/chart/comparison-stock-chart/surface-runtime.ts +159 -0
  79. package/src/components/chart/comparison-stock-chart/toolbar.tsx +107 -0
  80. package/src/components/chart/comparison-stock-chart/types.ts +22 -0
  81. package/src/components/chart/comparison-stock-chart/view.tsx +524 -0
  82. package/src/components/chart/comparison-stock-chart/viewport-runtime.ts +239 -0
  83. package/src/components/chart/comparison-stock-chart.tsx +12 -2028
  84. package/src/components/chart/core/axis-format.ts +147 -0
  85. package/src/components/chart/core/axis-measure.ts +33 -0
  86. package/src/components/chart/core/controller.test.ts +157 -0
  87. package/src/components/chart/core/controller.ts +349 -0
  88. package/src/components/chart/core/data.ts +94 -0
  89. package/src/components/chart/core/date-window.ts +392 -0
  90. package/src/components/chart/core/index.test.ts +1007 -0
  91. package/src/components/chart/core/indicator-selector.tsx +75 -0
  92. package/src/components/chart/core/keyboard.ts +15 -0
  93. package/src/components/chart/core/palette.ts +60 -0
  94. package/src/components/chart/core/pane-settings.test.ts +25 -0
  95. package/src/components/chart/core/pane-settings.ts +82 -0
  96. package/src/components/chart/core/pointer.ts +292 -0
  97. package/src/components/chart/core/projection.ts +333 -0
  98. package/src/components/chart/core/render-utils.ts +4 -0
  99. package/src/components/chart/core/renderer.ts +249 -0
  100. package/src/components/chart/core/resolution.test.ts +99 -0
  101. package/src/components/chart/core/resolution.ts +380 -0
  102. package/src/components/chart/core/scene.ts +180 -0
  103. package/src/components/chart/core/scroll.test.ts +70 -0
  104. package/src/components/chart/core/scroll.ts +104 -0
  105. package/src/components/chart/core/time-axis.ts +330 -0
  106. package/src/components/chart/core/types.ts +124 -0
  107. package/src/components/chart/core/viewport.test.ts +29 -0
  108. package/src/components/chart/core/viewport.ts +51 -0
  109. package/src/components/chart/core/window-viewport.test.ts +69 -0
  110. package/src/components/chart/core/window-viewport.ts +162 -0
  111. package/src/components/chart/display-cursor.ts +153 -0
  112. package/src/components/chart/market-session.ts +1 -1
  113. package/src/components/chart/multi-line/renderer.test.ts +83 -0
  114. package/src/components/chart/multi-line/renderer.ts +160 -0
  115. package/src/components/chart/multi-line/scene.ts +188 -0
  116. package/src/components/chart/native/canvas-bitmaps.ts +140 -0
  117. package/src/components/chart/native/chart-rasterizer.ts +18 -865
  118. package/src/components/chart/native/kitty/adapter.ts +9 -0
  119. package/src/components/chart/native/kitty/index.test.ts +752 -0
  120. package/src/components/chart/native/kitty/manager.ts +142 -0
  121. package/src/components/chart/native/kitty/support.ts +70 -0
  122. package/src/components/chart/native/raster/comparison-chart.ts +162 -0
  123. package/src/components/chart/native/raster/crosshair.ts +51 -0
  124. package/src/components/chart/native/raster/layout.ts +136 -0
  125. package/src/components/chart/native/raster/placement.ts +132 -0
  126. package/src/components/chart/native/raster/price-chart.ts +244 -0
  127. package/src/components/chart/native/raster/primitives.ts +154 -0
  128. package/src/components/chart/native/raster/types.ts +41 -0
  129. package/src/components/chart/native/renderer-selection.ts +81 -1
  130. package/src/components/chart/native/surface/hooks.ts +137 -0
  131. package/src/components/chart/native/surface/manager.ts +225 -0
  132. package/src/components/chart/native/surface/rendering.ts +211 -0
  133. package/src/components/chart/native/surface/sync.ts +34 -0
  134. package/src/components/chart/native/surface/visibility.ts +48 -0
  135. package/src/components/chart/price-axis-labels.tsx +4 -4
  136. package/src/components/chart/rendering/chart-draw.ts +270 -0
  137. package/src/components/chart/rendering/geometry.ts +95 -0
  138. package/src/components/chart/rendering/pixel-buffer.ts +267 -0
  139. package/src/components/chart/scatter-chart-renderer.test.ts +31 -0
  140. package/src/components/chart/scatter-chart-renderer.ts +223 -0
  141. package/src/components/chart/static/bar-chart-surface.tsx +85 -0
  142. package/src/components/chart/static/chart/bitmap.ts +50 -0
  143. package/src/components/chart/static/chart/surface.test.tsx +51 -0
  144. package/src/components/chart/static/chart/surface.tsx +181 -0
  145. package/src/components/chart/static/multi-line-chart-surface.tsx +180 -0
  146. package/src/components/chart/static/scatter-chart-surface.tsx +83 -0
  147. package/src/components/chart/stock-chart/auto.ts +216 -0
  148. package/src/components/chart/stock-chart/axis-width.ts +146 -0
  149. package/src/components/chart/stock-chart/bitmaps.ts +22 -0
  150. package/src/components/chart/stock-chart/canvas.ts +202 -0
  151. package/src/components/chart/stock-chart/controls.tsx +149 -0
  152. package/src/components/chart/stock-chart/cursor.ts +60 -0
  153. package/src/components/chart/stock-chart/data-runtime.ts +129 -0
  154. package/src/components/chart/stock-chart/footer.ts +248 -0
  155. package/src/components/chart/stock-chart/geometry.ts +160 -0
  156. package/src/components/chart/stock-chart/index.test.ts +500 -0
  157. package/src/components/chart/stock-chart/index.tsx +29 -0
  158. package/src/components/chart/stock-chart/indicators.ts +226 -0
  159. package/src/components/chart/stock-chart/interaction-runtime.ts +44 -0
  160. package/src/components/chart/stock-chart/interactions.ts +300 -0
  161. package/src/components/chart/stock-chart/keyboard.ts +373 -0
  162. package/src/components/chart/stock-chart/layout-metrics.ts +62 -0
  163. package/src/components/chart/stock-chart/layout.tsx +177 -0
  164. package/src/components/chart/stock-chart/native-surfaces.ts +121 -0
  165. package/src/components/chart/stock-chart/presentation.ts +67 -0
  166. package/src/components/chart/stock-chart/renderer-switch.test.tsx +263 -0
  167. package/src/components/chart/stock-chart/rendering/bounds.ts +116 -0
  168. package/src/components/chart/stock-chart/rendering/candidates.ts +145 -0
  169. package/src/components/chart/stock-chart/rendering/data.ts +370 -0
  170. package/src/components/chart/stock-chart/rendering/invalidation.ts +68 -0
  171. package/src/components/chart/stock-chart/rendering/output.ts +304 -0
  172. package/src/components/chart/stock-chart/rendering/planning.ts +122 -0
  173. package/src/components/chart/stock-chart/rendering/projection.test.tsx +98 -0
  174. package/src/components/chart/stock-chart/rendering/projection.ts +112 -0
  175. package/src/components/chart/stock-chart/rendering/state.test.ts +70 -0
  176. package/src/components/chart/stock-chart/rendering/state.ts +283 -0
  177. package/src/components/chart/stock-chart/requests.ts +337 -0
  178. package/src/components/chart/stock-chart/resolution-support.ts +96 -0
  179. package/src/components/chart/stock-chart/resolved/runtime.ts +289 -0
  180. package/src/components/chart/stock-chart/resolved.tsx +345 -0
  181. package/src/components/chart/stock-chart/settings.ts +77 -0
  182. package/src/components/chart/stock-chart/surface-runtime.ts +62 -0
  183. package/src/components/chart/stock-chart/types.ts +25 -0
  184. package/src/components/chart/stock-chart/view.tsx +155 -0
  185. package/src/components/chart/stock-chart/viewport/effects.ts +296 -0
  186. package/src/components/chart/stock-chart/viewport/index.ts +144 -0
  187. package/src/components/chart/stock-chart/viewport/runtime.ts +375 -0
  188. package/src/components/chart/time-axis-label.tsx +4 -3
  189. package/src/components/command-bar/action-runtime.ts +326 -0
  190. package/src/components/command-bar/commands/collection.ts +214 -0
  191. package/src/components/command-bar/commands/direct/index.ts +266 -0
  192. package/src/components/command-bar/commands/direct/runtime.ts +168 -0
  193. package/src/components/command-bar/commands/plugin/actions.ts +171 -0
  194. package/src/components/command-bar/commands/plugin/items.ts +166 -0
  195. package/src/components/command-bar/commands/registry.ts +263 -0
  196. package/src/components/command-bar/helpers.test.ts +13 -21
  197. package/src/components/command-bar/helpers.ts +51 -272
  198. package/src/components/command-bar/keyboard-handlers.ts +306 -0
  199. package/src/components/command-bar/keyboard-shortcuts.ts +204 -0
  200. package/src/components/command-bar/layout-items/current-layout.ts +120 -0
  201. package/src/components/command-bar/layout-items/focused-pane.ts +143 -0
  202. package/src/components/command-bar/layout-items/types.ts +25 -0
  203. package/src/components/command-bar/layout-items/window-mode.ts +72 -0
  204. package/src/components/command-bar/layout-items.ts +93 -0
  205. package/src/components/command-bar/list/model.ts +81 -0
  206. package/src/components/command-bar/list/navigation.ts +125 -0
  207. package/src/components/command-bar/list/view.tsx +316 -0
  208. package/src/components/command-bar/multi-select-picker.tsx +219 -0
  209. package/src/components/command-bar/multi-select-runtime.ts +91 -0
  210. package/src/components/command-bar/pane-actions.ts +124 -0
  211. package/src/components/command-bar/pane-settings.ts +227 -0
  212. package/src/components/command-bar/pane-templates/items.ts +203 -0
  213. package/src/components/command-bar/pane-templates/workflow-route.ts +81 -0
  214. package/src/components/command-bar/pane-templates/workflow.ts +282 -0
  215. package/src/components/command-bar/panel/body.tsx +311 -0
  216. package/src/components/command-bar/panel/index.tsx +196 -0
  217. package/src/components/command-bar/panel/layout.ts +117 -0
  218. package/src/components/command-bar/panel/runtime.ts +280 -0
  219. package/src/components/command-bar/panel/state.ts +138 -0
  220. package/src/components/command-bar/panel/types.ts +78 -0
  221. package/src/components/command-bar/picker-activation.ts +126 -0
  222. package/src/components/command-bar/routes/root/command-items.ts +176 -0
  223. package/src/components/command-bar/routes/root/provider-search.ts +200 -0
  224. package/src/components/command-bar/routes/root/results.ts +233 -0
  225. package/src/components/command-bar/routes/root/runtime.ts +315 -0
  226. package/src/components/command-bar/routes/root/selection.ts +228 -0
  227. package/src/components/command-bar/routes/root/shortcut-feedback.ts +108 -0
  228. package/src/components/command-bar/routes/root/shortcut-items.ts +159 -0
  229. package/src/components/command-bar/routes/root/shortcuts.test.ts +151 -0
  230. package/src/components/command-bar/routes/root/shortcuts.ts +188 -0
  231. package/src/components/command-bar/routes/ticker-search/actions.ts +142 -0
  232. package/src/components/command-bar/routes/ticker-search/results.ts +94 -0
  233. package/src/components/command-bar/routes/ticker-search/route.ts +151 -0
  234. package/src/components/command-bar/routing/actions.ts +299 -0
  235. package/src/components/command-bar/routing/confirm.ts +91 -0
  236. package/src/components/command-bar/routing/effects.ts +82 -0
  237. package/src/components/command-bar/routing/launch-request.ts +59 -0
  238. package/src/components/command-bar/routing/list-state.ts +242 -0
  239. package/src/components/command-bar/routing/navigation-state.ts +147 -0
  240. package/src/components/command-bar/selection-runtime.ts +291 -0
  241. package/src/components/command-bar/surface/environment.ts +124 -0
  242. package/src/components/command-bar/surface/index.test.tsx +864 -0
  243. package/src/components/command-bar/surface/index.tsx +344 -0
  244. package/src/components/command-bar/surface/pane.test.tsx +703 -0
  245. package/src/components/command-bar/surface/portfolio.test.tsx +452 -0
  246. package/src/components/command-bar/surface/test-harness.tsx +403 -0
  247. package/src/components/command-bar/theme-preview.ts +84 -0
  248. package/src/components/command-bar/view-model.test.ts +3 -3
  249. package/src/components/command-bar/view-model.ts +7 -6
  250. package/src/components/command-bar/workflow/alert.ts +164 -0
  251. package/src/components/command-bar/workflow/body.tsx +179 -0
  252. package/src/components/command-bar/workflow/broker.ts +158 -0
  253. package/src/components/command-bar/workflow/builtin.ts +134 -0
  254. package/src/components/command-bar/workflow/collection-actions.ts +257 -0
  255. package/src/components/command-bar/workflow/coordinator.ts +193 -0
  256. package/src/components/command-bar/workflow/field-row.tsx +214 -0
  257. package/src/components/command-bar/workflow/fields.ts +230 -0
  258. package/src/components/command-bar/workflow/ops.test.ts +197 -0
  259. package/src/components/command-bar/workflow/ops.ts +268 -0
  260. package/src/components/command-bar/workflow/route-actions.ts +232 -0
  261. package/src/components/command-bar/workflow/route-builder.ts +56 -0
  262. package/src/components/command-bar/workflow/runtime.ts +234 -0
  263. package/src/components/command-bar/workflow/submit.ts +213 -0
  264. package/src/components/command-bar/workflow/tickers.ts +214 -0
  265. package/src/components/command-bar/workflow/types.ts +127 -0
  266. package/src/components/data-table/stack-view.test.tsx +218 -0
  267. package/src/components/data-table/stack-view.tsx +59 -0
  268. package/src/components/data-table/view.test.tsx +254 -0
  269. package/src/components/data-table/view.tsx +306 -0
  270. package/src/components/feed-data-table/stack-view.test.tsx +148 -0
  271. package/src/components/feed-data-table/stack-view.tsx +359 -0
  272. package/src/components/index.ts +14 -14
  273. package/src/components/input-search-bar.tsx +94 -0
  274. package/src/components/layout/detached-pane-shell.tsx +22 -16
  275. package/src/components/layout/floating-pane.tsx +19 -24
  276. package/src/components/layout/header.tsx +9 -21
  277. package/src/components/layout/pane/content.test.tsx +64 -0
  278. package/src/components/layout/pane/content.tsx +44 -0
  279. package/src/components/layout/pane/cycle-order.test.ts +30 -0
  280. package/src/components/layout/pane/cycle-order.ts +32 -0
  281. package/src/components/layout/pane/footer/index.test.tsx +131 -0
  282. package/src/components/layout/pane/footer/index.tsx +246 -0
  283. package/src/components/layout/pane/footer/model.ts +99 -0
  284. package/src/components/layout/pane/footer/registration.tsx +114 -0
  285. package/src/components/layout/pane/frame.tsx +55 -0
  286. package/src/components/layout/pane/header.test.tsx +39 -0
  287. package/src/components/layout/pane/header.tsx +252 -0
  288. package/src/components/layout/pane/index.tsx +105 -0
  289. package/src/components/layout/pane/keyboard-scroll.test.tsx +146 -0
  290. package/src/components/layout/pane/sizing.ts +66 -0
  291. package/src/components/layout/pane/title.ts +38 -0
  292. package/src/components/layout/shell/action-menu-overlay.tsx +72 -0
  293. package/src/components/layout/shell/active-drag.ts +221 -0
  294. package/src/components/layout/shell/chrome.ts +8 -0
  295. package/src/components/layout/shell/drag/index.ts +432 -0
  296. package/src/components/layout/shell/drag/overlays.tsx +78 -0
  297. package/src/components/layout/shell/drag/runtime.ts +264 -0
  298. package/src/components/layout/shell/index.test.tsx +788 -0
  299. package/src/components/layout/shell/index.tsx +451 -0
  300. package/src/components/layout/shell/layout-state.ts +97 -0
  301. package/src/components/layout/shell/menu.ts +152 -0
  302. package/src/components/layout/shell/native/pointer-runtime.ts +184 -0
  303. package/src/components/layout/shell/native/surfaces.ts +127 -0
  304. package/src/components/layout/shell/native/window-state.ts +208 -0
  305. package/src/components/layout/shell/pane/actions.ts +129 -0
  306. package/src/components/layout/shell/pane/layers.tsx +234 -0
  307. package/src/components/layout/shell/pane/management-shortcuts.ts +114 -0
  308. package/src/components/layout/shell/shortcuts.ts +47 -0
  309. package/src/components/layout/shell/terminal-pointer-runtime.ts +326 -0
  310. package/src/components/layout/shell/window-mode/index.ts +253 -0
  311. package/src/components/layout/shell/window-mode/overlays.tsx +208 -0
  312. package/src/components/layout/status-bar.test.tsx +1 -101
  313. package/src/components/layout/status-bar.tsx +1 -1
  314. package/src/components/layout/window-edit/mode.test.ts +55 -0
  315. package/src/components/layout/window-edit/mode.ts +422 -0
  316. package/src/components/layout/window-edit/presentation.ts +123 -0
  317. package/src/components/layout/window-edit/status.tsx +101 -0
  318. package/src/components/markdown-text.tsx +3 -3
  319. package/src/components/onboarding/onboarding-steps.tsx +248 -0
  320. package/src/components/onboarding/onboarding-wizard.tsx +97 -1035
  321. package/src/components/onboarding/portfolio-step/broker-fields-panel.tsx +144 -0
  322. package/src/components/onboarding/portfolio-step/broker-setup-panel.tsx +97 -0
  323. package/src/components/onboarding/portfolio-step/broker-sync-panel.tsx +42 -0
  324. package/src/components/onboarding/portfolio-step/choose-panel.tsx +42 -0
  325. package/src/components/onboarding/portfolio-step/index.tsx +70 -0
  326. package/src/components/onboarding/portfolio-step/manual-name-panel.tsx +62 -0
  327. package/src/components/onboarding/portfolio-step/types.ts +25 -0
  328. package/src/components/onboarding/portfolio-step/utils.ts +15 -0
  329. package/src/components/onboarding/wizard-broker-sync.ts +230 -0
  330. package/src/components/onboarding/wizard-keyboard.ts +264 -0
  331. package/src/components/onboarding/wizard-model.ts +21 -0
  332. package/src/components/pane-settings-dialog/desktop.tsx +315 -0
  333. package/src/components/pane-settings-dialog/field-dialogs.tsx +213 -0
  334. package/src/components/pane-settings-dialog/tui.tsx +73 -0
  335. package/src/components/pane-settings-dialog/value.ts +36 -0
  336. package/src/components/pane-settings-dialog.tsx +18 -622
  337. package/src/components/pane-template-wizard.tsx +1 -1
  338. package/src/components/price-selector-dialog.tsx +2 -2
  339. package/src/components/price-sparkline/bitmap.ts +150 -0
  340. package/src/components/price-sparkline/index.ts +46 -0
  341. package/src/components/price-sparkline/model.ts +119 -0
  342. package/src/components/price-sparkline/view.tsx +214 -0
  343. package/src/components/quote-flash.ts +103 -0
  344. package/src/components/speedometer-gauge/desktop.tsx +151 -0
  345. package/src/components/speedometer-gauge/index.tsx +44 -0
  346. package/src/components/speedometer-gauge/model.ts +60 -0
  347. package/src/components/speedometer-gauge/terminal.tsx +261 -0
  348. package/src/components/ticker/badge/format.ts +42 -0
  349. package/src/components/ticker/badge/index.tsx +100 -0
  350. package/src/components/ticker/badge/list.tsx +57 -0
  351. package/src/components/ticker/badge/text.test.tsx +223 -0
  352. package/src/components/ticker/badge/text.tsx +156 -0
  353. package/src/components/ticker/list-table-view.tsx +297 -0
  354. package/src/components/ticker/list-table.test.tsx +177 -0
  355. package/src/components/toggle-list.tsx +1 -1
  356. package/src/components/ui/data-table/index.tsx +26 -0
  357. package/src/components/ui/data-table/opentui/index.tsx +467 -0
  358. package/src/components/ui/data-table/opentui/model.test.ts +47 -0
  359. package/src/components/ui/data-table/opentui/model.ts +66 -0
  360. package/src/components/ui/data-table/types.ts +81 -0
  361. package/src/components/ui/index.ts +1 -3
  362. package/src/components/ui/multi-select/dialog.tsx +336 -0
  363. package/src/components/ui/native-select.tsx +1 -1
  364. package/src/components/ui/shortcut-hint.tsx +1 -1
  365. package/src/components/ui/tabs.tsx +11 -5
  366. package/src/components/ui/toggle.tsx +1 -1
  367. package/src/components/ui/ui.test.tsx +3 -75
  368. package/src/components/use-external-link-footer.ts +1 -1
  369. package/src/core/app-services.ts +3 -0
  370. package/src/core/state/app/layout-reducer.ts +196 -0
  371. package/src/core/state/app/layout.ts +406 -0
  372. package/src/core/state/app/state.ts +340 -0
  373. package/src/core/state/app/types.ts +116 -0
  374. package/src/core/state/session-persistence.ts +1 -1
  375. package/src/data/app-persistence.ts +1 -1
  376. package/src/data/config/layout.ts +227 -0
  377. package/src/data/config/store/index.test.ts +500 -0
  378. package/src/data/config/store/index.ts +64 -0
  379. package/src/data/config/store/node.ts +101 -0
  380. package/src/data/config/store/normalize.ts +403 -0
  381. package/src/data/plugin-state-store.ts +3 -3
  382. package/src/data/resource-store.ts +3 -3
  383. package/src/data/session-store.ts +3 -3
  384. package/src/data/sqlite/cache.test.ts +151 -0
  385. package/src/data/sqlite/database.ts +68 -0
  386. package/src/data/sqlite/json.ts +16 -0
  387. package/src/data/sqlite/retry.test.ts +63 -0
  388. package/src/data/ticker-repository.ts +1 -1
  389. package/src/data/ticker-store.ts +2 -2
  390. package/src/market-data/coordinator/auxiliary.ts +252 -0
  391. package/src/market-data/coordinator/chart.ts +141 -0
  392. package/src/market-data/coordinator/entries.ts +129 -0
  393. package/src/market-data/coordinator/events.ts +74 -0
  394. package/src/market-data/coordinator/financials.ts +281 -0
  395. package/src/market-data/coordinator/index.test.ts +840 -0
  396. package/src/market-data/coordinator/index.ts +388 -0
  397. package/src/market-data/coordinator/quotes.ts +329 -0
  398. package/src/market-data/coordinator/subscriptions.test.ts +209 -0
  399. package/src/market-data/hooks.test.tsx +42 -1
  400. package/src/market-data/hooks.tsx +83 -18
  401. package/src/market-data/market/format.test.ts +109 -0
  402. package/src/market-data/market/format.ts +293 -0
  403. package/src/market-data/market/freshness.ts +140 -0
  404. package/src/market-data/market/status.ts +112 -0
  405. package/src/market-data/quotes/contributions.ts +194 -0
  406. package/src/market-data/quotes/freshness.test.ts +150 -0
  407. package/src/market-data/quotes/freshness.ts +36 -0
  408. package/src/market-data/quotes/resolution.test.ts +277 -0
  409. package/src/market-data/quotes/resolution.ts +468 -0
  410. package/src/market-data/quotes/time.test.ts +34 -0
  411. package/src/market-data/quotes/time.ts +59 -0
  412. package/src/market-data/request-types.ts +10 -3
  413. package/src/market-data/result-types.ts +3 -3
  414. package/src/market-data/selectors.ts +2 -2
  415. package/src/news/aggregator.ts +29 -219
  416. package/src/news/news-model.ts +208 -0
  417. package/src/news/ticker-symbols.ts +1 -1
  418. package/src/news/types.ts +3 -3
  419. package/src/plugins/builtin/account-management/footer.ts +39 -0
  420. package/src/plugins/builtin/account-management/form-components.tsx +162 -0
  421. package/src/plugins/builtin/account-management/keyboard.ts +90 -0
  422. package/src/plugins/builtin/account-management/model.ts +97 -0
  423. package/src/plugins/builtin/account-management/pane.tsx +389 -0
  424. package/src/plugins/builtin/account-management/password-dialog.tsx +125 -0
  425. package/src/plugins/builtin/ai/ask-ai-detail-tab.tsx +6 -6
  426. package/src/plugins/builtin/ai/ask-ai.test.tsx +305 -0
  427. package/src/plugins/builtin/ai/index.tsx +4 -4
  428. package/src/plugins/builtin/ai/providers.ts +1 -1
  429. package/src/plugins/builtin/ai/runner.ts +1 -0
  430. package/src/plugins/builtin/ai/screener/action-bar.tsx +58 -0
  431. package/src/plugins/builtin/ai/screener/contract.test.ts +117 -0
  432. package/src/plugins/builtin/ai/screener/contract.ts +174 -0
  433. package/src/plugins/builtin/ai/screener/editor-runtime.ts +110 -0
  434. package/src/plugins/builtin/ai/screener/editor.tsx +125 -0
  435. package/src/plugins/builtin/ai/screener/footer.ts +93 -0
  436. package/src/plugins/builtin/ai/screener/keyboard.ts +90 -0
  437. package/src/plugins/builtin/ai/screener/market-runtime.ts +99 -0
  438. package/src/plugins/builtin/ai/screener/model.ts +107 -0
  439. package/src/plugins/builtin/ai/screener/pane.test.tsx +348 -0
  440. package/src/plugins/builtin/ai/screener/pane.tsx +412 -0
  441. package/src/plugins/builtin/ai/screener/results-view.tsx +169 -0
  442. package/src/plugins/builtin/ai/screener/results.ts +139 -0
  443. package/src/plugins/builtin/ai/screener/runner.ts +144 -0
  444. package/src/plugins/builtin/ai/screener/tabs-bar.tsx +65 -0
  445. package/src/plugins/builtin/ai/settings.ts +3 -3
  446. package/src/plugins/builtin/ai/ticker-context.ts +1 -1
  447. package/src/plugins/builtin/alerts/command.ts +86 -0
  448. package/src/plugins/builtin/alerts/constants.ts +3 -0
  449. package/src/plugins/builtin/alerts/format.ts +68 -0
  450. package/src/plugins/builtin/alerts/index.test.tsx +5 -4
  451. package/src/plugins/builtin/alerts/index.tsx +18 -473
  452. package/src/plugins/builtin/alerts/pane.tsx +304 -0
  453. package/src/plugins/builtin/alerts/quotes.ts +57 -0
  454. package/src/plugins/builtin/alerts/storage.ts +20 -0
  455. package/src/plugins/builtin/analytics/broker-performance.ts +142 -0
  456. package/src/plugins/builtin/analytics/display.ts +44 -0
  457. package/src/plugins/builtin/analytics/index.test.tsx +144 -5
  458. package/src/plugins/builtin/analytics/index.tsx +108 -468
  459. package/src/plugins/builtin/analytics/metrics.ts +1 -1
  460. package/src/plugins/builtin/analytics/pane-model.ts +297 -0
  461. package/src/plugins/builtin/analytics/portfolio-selection.ts +10 -0
  462. package/src/plugins/builtin/analytics/sector-model.ts +172 -0
  463. package/src/plugins/builtin/analytics/view.tsx +207 -0
  464. package/src/plugins/builtin/broker-manager/detail.tsx +232 -0
  465. package/src/plugins/builtin/broker-manager/footer.ts +62 -0
  466. package/src/plugins/builtin/broker-manager/index.test.tsx +3 -3
  467. package/src/plugins/builtin/broker-manager/index.tsx +125 -527
  468. package/src/plugins/builtin/broker-manager/keyboard.ts +104 -0
  469. package/src/plugins/builtin/broker-manager/model.test.ts +39 -1
  470. package/src/plugins/builtin/broker-manager/model.ts +14 -8
  471. package/src/plugins/builtin/broker-manager/pane-actions.tsx +181 -0
  472. package/src/plugins/builtin/broker-manager/table.ts +86 -0
  473. package/src/plugins/builtin/buildout/cells.tsx +203 -0
  474. package/src/plugins/builtin/buildout/data-runtime.ts +238 -0
  475. package/src/plugins/builtin/buildout/detail/company.tsx +219 -0
  476. package/src/plugins/builtin/buildout/detail/index.tsx +105 -0
  477. package/src/plugins/builtin/buildout/detail/intel.tsx +61 -0
  478. package/src/plugins/builtin/buildout/detail/satellite-images.tsx +80 -0
  479. package/src/plugins/builtin/buildout/detail/site.tsx +142 -0
  480. package/src/plugins/builtin/buildout/detail/ui.tsx +355 -0
  481. package/src/plugins/builtin/buildout/detail/values.ts +67 -0
  482. package/src/plugins/builtin/buildout/format.ts +163 -0
  483. package/src/plugins/builtin/buildout/model/index.ts +135 -0
  484. package/src/plugins/builtin/buildout/model/normalizers.ts +396 -0
  485. package/src/plugins/builtin/buildout/model/types.ts +318 -0
  486. package/src/plugins/builtin/buildout/pane/header.tsx +55 -0
  487. package/src/plugins/builtin/buildout/pane/index.tsx +405 -0
  488. package/src/plugins/builtin/buildout/pane/status.tsx +84 -0
  489. package/src/plugins/builtin/buildout/table-model.ts +367 -0
  490. package/src/plugins/builtin/changelog/index.tsx +370 -0
  491. package/src/plugins/builtin/chat/channels.ts +157 -0
  492. package/src/plugins/builtin/chat/chat.test.tsx +1048 -0
  493. package/src/plugins/builtin/chat/composer-commands.test.ts +30 -0
  494. package/src/plugins/builtin/chat/composer-commands.ts +34 -0
  495. package/src/plugins/builtin/chat/content/channel-navigation.ts +157 -0
  496. package/src/plugins/builtin/chat/content/composer-runtime.ts +251 -0
  497. package/src/plugins/builtin/chat/content/composer.tsx +148 -0
  498. package/src/plugins/builtin/chat/content/index.tsx +407 -0
  499. package/src/plugins/builtin/chat/content/layout-metrics.ts +72 -0
  500. package/src/plugins/builtin/chat/content/scroll.ts +278 -0
  501. package/src/plugins/builtin/chat/content/selection-runtime.ts +66 -0
  502. package/src/plugins/builtin/chat/content/shortcuts.ts +212 -0
  503. package/src/plugins/builtin/chat/content/snapshot.ts +154 -0
  504. package/src/plugins/builtin/chat/content/transcript.tsx +155 -0
  505. package/src/plugins/builtin/chat/content/types.ts +26 -0
  506. package/src/plugins/builtin/chat/content/user-map.ts +21 -0
  507. package/src/plugins/builtin/chat/controller/channel-actions.ts +87 -0
  508. package/src/plugins/builtin/chat/controller/channels.ts +159 -0
  509. package/src/plugins/builtin/chat/controller/connections.ts +90 -0
  510. package/src/plugins/builtin/chat/controller/draft-sync.ts +41 -0
  511. package/src/plugins/builtin/chat/controller/fetch.ts +83 -0
  512. package/src/plugins/builtin/chat/controller/index.ts +488 -0
  513. package/src/plugins/builtin/chat/controller/lifecycle.ts +141 -0
  514. package/src/plugins/builtin/chat/controller/message-loading.ts +97 -0
  515. package/src/plugins/builtin/chat/controller/messages.ts +173 -0
  516. package/src/plugins/builtin/chat/controller/notifications.ts +56 -0
  517. package/src/plugins/builtin/chat/controller/persistence.ts +166 -0
  518. package/src/plugins/builtin/chat/controller/realtime.ts +91 -0
  519. package/src/plugins/builtin/chat/controller/send.ts +89 -0
  520. package/src/plugins/builtin/chat/controller/session-runtime.ts +156 -0
  521. package/src/plugins/builtin/chat/controller/session.ts +39 -0
  522. package/src/plugins/builtin/chat/controller/state.ts +162 -0
  523. package/src/plugins/builtin/chat/controller/storage.ts +136 -0
  524. package/src/plugins/builtin/chat/controller/utils.ts +75 -0
  525. package/src/plugins/builtin/chat/controller/view.ts +96 -0
  526. package/src/plugins/builtin/chat/controller.test.ts +1302 -0
  527. package/src/plugins/builtin/chat/index.tsx +4 -0
  528. package/src/plugins/builtin/chat/layout.ts +330 -0
  529. package/src/plugins/builtin/chat/message/action-chip.tsx +38 -0
  530. package/src/plugins/builtin/chat/message/desktop.tsx +158 -0
  531. package/src/plugins/builtin/chat/message/inline-tokens.tsx +118 -0
  532. package/src/plugins/builtin/chat/message/profile-popover.tsx +72 -0
  533. package/src/plugins/builtin/chat/message/render-state.ts +67 -0
  534. package/src/plugins/builtin/chat/message/terminal.tsx +132 -0
  535. package/src/plugins/builtin/chat/message/types.ts +18 -0
  536. package/src/plugins/builtin/chat/pane.tsx +100 -0
  537. package/src/plugins/builtin/chat/profile-popover.ts +49 -0
  538. package/src/plugins/builtin/chat/sidebar.test.tsx +455 -0
  539. package/src/plugins/builtin/chat/sidebar.tsx +296 -0
  540. package/src/plugins/builtin/chat/status-widget.tsx +103 -0
  541. package/src/plugins/builtin/chat/test-harness.tsx +212 -0
  542. package/src/plugins/builtin/cloud/auth-actions.tsx +72 -0
  543. package/src/plugins/builtin/cloud/auth-commands.ts +115 -0
  544. package/src/plugins/builtin/cloud/index.tsx +11 -0
  545. package/src/plugins/builtin/cloud/plugin.tsx +185 -0
  546. package/src/plugins/builtin/cloud-tweets/footer.ts +40 -0
  547. package/src/plugins/builtin/cloud-tweets/index.ts +1 -0
  548. package/src/plugins/builtin/cloud-tweets/keyboard.ts +65 -0
  549. package/src/plugins/builtin/cloud-tweets/model.ts +257 -0
  550. package/src/plugins/builtin/cloud-tweets/pane.tsx +318 -0
  551. package/src/plugins/builtin/cloud-tweets/registration.ts +87 -0
  552. package/src/plugins/builtin/cloud-tweets/search-bar.tsx +49 -0
  553. package/src/plugins/builtin/cloud-tweets/table.tsx +331 -0
  554. package/src/plugins/builtin/comparison-chart/index.test.tsx +645 -0
  555. package/src/plugins/builtin/comparison-chart/index.tsx +194 -0
  556. package/src/plugins/builtin/congress-trades/detail.tsx +154 -0
  557. package/src/plugins/builtin/congress-trades/footer.ts +67 -0
  558. package/src/plugins/builtin/congress-trades/keyboard.ts +112 -0
  559. package/src/plugins/builtin/congress-trades/model.ts +224 -0
  560. package/src/plugins/builtin/congress-trades/pane.tsx +331 -0
  561. package/src/plugins/builtin/congress-trades/table.tsx +84 -0
  562. package/src/plugins/builtin/correlation/compute.ts +0 -7
  563. package/src/plugins/builtin/correlation/index.test.tsx +5 -5
  564. package/src/plugins/builtin/correlation/index.tsx +36 -208
  565. package/src/plugins/builtin/correlation/matrix/model.ts +155 -0
  566. package/src/plugins/builtin/correlation/matrix/symbol-cell.tsx +56 -0
  567. package/src/plugins/builtin/correlation/relationship/controls.tsx +53 -0
  568. package/src/plugins/builtin/correlation/relationship/history.ts +72 -0
  569. package/src/plugins/builtin/correlation/relationship/model.ts +279 -0
  570. package/src/plugins/builtin/correlation/relationship/pane.tsx +359 -0
  571. package/src/plugins/builtin/correlation/relationship/view-model.ts +120 -0
  572. package/src/plugins/builtin/correlation/settings.ts +6 -6
  573. package/src/plugins/builtin/debug/index.tsx +365 -0
  574. package/src/plugins/builtin/earnings/data/cache.test.ts +94 -0
  575. package/src/plugins/builtin/earnings/data/cache.ts +145 -0
  576. package/src/plugins/builtin/earnings/data/data.test.ts +90 -0
  577. package/src/plugins/builtin/earnings/data/data.ts +115 -0
  578. package/src/plugins/builtin/earnings/index.test.ts +12 -0
  579. package/src/plugins/builtin/earnings/index.tsx +74 -266
  580. package/src/plugins/builtin/earnings/model.ts +82 -0
  581. package/src/plugins/builtin/earnings/table.ts +206 -0
  582. package/src/plugins/builtin/econ/calendar-model.test.ts +48 -0
  583. package/src/plugins/builtin/econ/calendar-model.ts +217 -0
  584. package/src/plugins/builtin/econ/calendar-source.ts +1 -1
  585. package/src/plugins/builtin/econ/detail-view.tsx +319 -0
  586. package/src/plugins/builtin/econ/fred-cache.test.ts +58 -0
  587. package/src/plugins/builtin/econ/fred-cache.ts +106 -0
  588. package/src/plugins/builtin/econ/fred-series-map.ts +0 -4
  589. package/src/plugins/builtin/econ/index.tsx +46 -474
  590. package/src/plugins/builtin/fear-greed/cache.test.ts +75 -0
  591. package/src/plugins/builtin/fear-greed/cache.ts +142 -0
  592. package/src/plugins/builtin/fear-greed/charts.tsx +305 -0
  593. package/src/plugins/builtin/fear-greed/data.test.ts +72 -0
  594. package/src/plugins/builtin/fear-greed/data.ts +370 -0
  595. package/src/plugins/builtin/fear-greed/format.ts +96 -0
  596. package/src/plugins/builtin/fear-greed/index.tsx +13 -555
  597. package/src/plugins/builtin/fear-greed/pane.tsx +169 -0
  598. package/src/plugins/builtin/fx-matrix/index.tsx +1 -1
  599. package/src/plugins/builtin/fx-matrix/pairs.ts +0 -22
  600. package/src/plugins/builtin/help/components.tsx +92 -0
  601. package/src/plugins/builtin/help/index.test.tsx +167 -0
  602. package/src/plugins/builtin/help/index.tsx +256 -0
  603. package/src/plugins/builtin/help/shortcut-model.ts +145 -0
  604. package/src/plugins/builtin/holders/format.ts +44 -0
  605. package/src/plugins/builtin/holders/index.test.ts +1 -46
  606. package/src/plugins/builtin/holders/index.tsx +3 -955
  607. package/src/plugins/builtin/holders/pane.tsx +331 -0
  608. package/src/plugins/builtin/holders/table-model.ts +84 -0
  609. package/src/plugins/builtin/holders/thirteenf-match.ts +76 -0
  610. package/src/plugins/builtin/holders/treemap-layout.ts +231 -0
  611. package/src/plugins/builtin/holders/treemap.tsx +318 -0
  612. package/src/plugins/builtin/holders/types.ts +51 -0
  613. package/src/plugins/builtin/insider/index.tsx +5 -5
  614. package/src/plugins/builtin/layout-manager/index.tsx +247 -0
  615. package/src/plugins/builtin/market-movers/index.tsx +44 -282
  616. package/src/plugins/builtin/market-movers/model.ts +146 -0
  617. package/src/plugins/builtin/market-movers/screener.test.ts +31 -1
  618. package/src/plugins/builtin/market-movers/screener.ts +106 -12
  619. package/src/plugins/builtin/market-movers/table.ts +95 -0
  620. package/src/plugins/builtin/news/index.tsx +194 -0
  621. package/src/plugins/builtin/news/wire/breaking/notifications.test.ts +98 -0
  622. package/src/plugins/builtin/news/wire/breaking/notifications.ts +110 -0
  623. package/src/plugins/builtin/news/wire/breaking/pane.test.tsx +156 -0
  624. package/src/plugins/builtin/news/wire/breaking/pane.tsx +68 -0
  625. package/src/plugins/builtin/news/wire/categories.ts +114 -0
  626. package/src/plugins/builtin/news/wire/default-feeds.ts +3 -0
  627. package/src/plugins/builtin/news/wire/feed-config.test.ts +90 -0
  628. package/src/plugins/builtin/news/wire/feed-config.ts +216 -0
  629. package/src/plugins/builtin/news/wire/index.tsx +129 -0
  630. package/src/plugins/builtin/news/wire/industry-pane.tsx +126 -0
  631. package/src/plugins/builtin/news/wire/news/detail-view.tsx +306 -0
  632. package/src/plugins/builtin/news/wire/news/footer.ts +77 -0
  633. package/src/plugins/builtin/news/wire/news/preset-pane.tsx +98 -0
  634. package/src/plugins/builtin/news/wire/news/query-presets.ts +40 -0
  635. package/src/plugins/builtin/news/wire/news/table.test.tsx +157 -0
  636. package/src/plugins/builtin/news/wire/news/table.tsx +270 -0
  637. package/src/plugins/builtin/news/wire/persisted-articles.ts +98 -0
  638. package/src/plugins/builtin/news/wire/read-state.ts +76 -0
  639. package/src/plugins/builtin/news/wire/rss/parser.test.ts +116 -0
  640. package/src/plugins/builtin/news/wire/rss/parser.ts +213 -0
  641. package/src/plugins/builtin/news/wire/rss/source.test.ts +104 -0
  642. package/src/plugins/builtin/news/wire/rss/source.ts +181 -0
  643. package/src/plugins/builtin/notes/index.tsx +49 -0
  644. package/src/plugins/builtin/notes/markdown-note-preview.tsx +39 -0
  645. package/src/plugins/builtin/notes/model.ts +36 -0
  646. package/src/plugins/builtin/notes/quick-notes-pane.tsx +334 -0
  647. package/src/plugins/builtin/notes/text-state.ts +11 -0
  648. package/src/plugins/builtin/notes/ticker-notes-tab.tsx +112 -0
  649. package/src/plugins/builtin/options/index.tsx +44 -0
  650. package/src/plugins/builtin/options/table.ts +209 -0
  651. package/src/plugins/builtin/options/types.ts +33 -0
  652. package/src/plugins/builtin/options/view.test.tsx +185 -0
  653. package/src/plugins/builtin/options/view.tsx +264 -0
  654. package/src/plugins/builtin/plugin-groups.ts +25 -5
  655. package/src/plugins/builtin/portfolio-list/account-metrics.test.ts +50 -0
  656. package/src/plugins/builtin/portfolio-list/account-metrics.ts +46 -0
  657. package/src/plugins/builtin/portfolio-list/cli/portfolio-command.ts +224 -0
  658. package/src/plugins/builtin/portfolio-list/cli/render.ts +203 -0
  659. package/src/plugins/builtin/portfolio-list/cli/shared.ts +21 -0
  660. package/src/plugins/builtin/portfolio-list/cli/watchlist-command.ts +224 -0
  661. package/src/plugins/builtin/portfolio-list/column-values.ts +284 -0
  662. package/src/plugins/builtin/portfolio-list/command-bar.ts +1 -1
  663. package/src/plugins/builtin/portfolio-list/header.tsx +7 -98
  664. package/src/plugins/builtin/portfolio-list/index.test.ts +133 -0
  665. package/src/plugins/builtin/portfolio-list/index.tsx +2 -1
  666. package/src/plugins/builtin/portfolio-list/metrics.test.ts +242 -0
  667. package/src/plugins/builtin/portfolio-list/metrics.ts +5 -462
  668. package/src/plugins/builtin/portfolio-list/pane/data.ts +171 -0
  669. package/src/plugins/builtin/portfolio-list/pane/index.test.tsx +1267 -0
  670. package/src/plugins/builtin/portfolio-list/pane/index.tsx +385 -0
  671. package/src/plugins/builtin/portfolio-list/pane/streaming.ts +159 -0
  672. package/src/plugins/builtin/portfolio-list/position-metrics.ts +123 -0
  673. package/src/plugins/builtin/portfolio-list/quick-add/index.tsx +326 -0
  674. package/src/plugins/builtin/portfolio-list/quick-add/resolution.ts +135 -0
  675. package/src/plugins/builtin/portfolio-list/settings.ts +5 -3
  676. package/src/plugins/builtin/portfolio-list/summary/index.test.ts +126 -0
  677. package/src/plugins/builtin/portfolio-list/summary/index.tsx +392 -0
  678. package/src/plugins/builtin/portfolio-list/summary/totals.ts +86 -0
  679. package/src/plugins/builtin/portfolio-list/table.tsx +1 -1
  680. package/src/plugins/builtin/portfolio-list/use-throttled-cursor-symbol.ts +1 -1
  681. package/src/plugins/builtin/research/analyst-pane.tsx +383 -0
  682. package/src/plugins/builtin/research/corporate-actions-pane.tsx +413 -0
  683. package/src/plugins/builtin/research/index.test.ts +248 -2
  684. package/src/plugins/builtin/research/index.tsx +30 -760
  685. package/src/plugins/builtin/research/relative-valuation-pane.tsx +189 -0
  686. package/src/plugins/builtin/sec/filing-display.tsx +84 -0
  687. package/src/plugins/builtin/sec/index.tsx +342 -0
  688. package/src/plugins/builtin/sectors/index.tsx +27 -234
  689. package/src/plugins/builtin/sectors/sector-data.ts +0 -2
  690. package/src/plugins/builtin/sectors/sector-model.ts +221 -0
  691. package/src/plugins/builtin/shared/table-pane.ts +31 -0
  692. package/src/plugins/builtin/shared/ticker-request.ts +70 -0
  693. package/src/plugins/builtin/shared/ticker-surface.test.ts +57 -0
  694. package/src/plugins/builtin/shared/ticker-surface.ts +113 -0
  695. package/src/plugins/builtin/thirteenf/api.test.ts +58 -0
  696. package/src/plugins/builtin/thirteenf/api.ts +375 -0
  697. package/src/plugins/builtin/thirteenf/data.test.ts +95 -0
  698. package/src/plugins/builtin/thirteenf/data.ts +210 -0
  699. package/src/plugins/builtin/thirteenf/format.ts +55 -0
  700. package/src/plugins/builtin/thirteenf/index.tsx +80 -0
  701. package/src/plugins/builtin/thirteenf/model.test.ts +156 -0
  702. package/src/plugins/builtin/thirteenf/model.ts +618 -0
  703. package/src/plugins/builtin/thirteenf/pane.test.tsx +328 -0
  704. package/src/plugins/builtin/thirteenf/pane.tsx +826 -0
  705. package/src/plugins/builtin/thirteenf/table.ts +212 -0
  706. package/src/plugins/builtin/thirteenf/types.ts +187 -0
  707. package/src/plugins/builtin/ticker-detail/chart-pane.tsx +91 -0
  708. package/src/plugins/builtin/ticker-detail/chart-tab-switch.test.tsx +282 -0
  709. package/src/plugins/builtin/ticker-detail/chart-tab.tsx +3 -5
  710. package/src/plugins/builtin/ticker-detail/data-panes/fundamental-graph/content.tsx +158 -0
  711. package/src/plugins/builtin/ticker-detail/data-panes/fundamental-graph/data.ts +62 -0
  712. package/src/plugins/builtin/ticker-detail/data-panes/fundamental-graph/model.ts +234 -0
  713. package/src/plugins/builtin/ticker-detail/data-panes/fundamental-graph/settings.ts +44 -0
  714. package/src/plugins/builtin/ticker-detail/data-panes/fundamental-graph/types.ts +51 -0
  715. package/src/plugins/builtin/ticker-detail/data-panes/fundamental-graph.tsx +135 -0
  716. package/src/plugins/builtin/ticker-detail/data-panes/historical-prices.tsx +192 -0
  717. package/src/plugins/builtin/ticker-detail/data-panes/provider-search.tsx +172 -0
  718. package/src/plugins/builtin/ticker-detail/data-panes.test.ts +110 -0
  719. package/src/plugins/builtin/ticker-detail/financials/aggregation.ts +203 -0
  720. package/src/plugins/builtin/ticker-detail/financials/model.test.ts +84 -0
  721. package/src/plugins/builtin/ticker-detail/financials/model.ts +364 -0
  722. package/src/plugins/builtin/ticker-detail/financials/pane.tsx +27 -0
  723. package/src/plugins/builtin/ticker-detail/financials/schema.ts +392 -0
  724. package/src/plugins/builtin/ticker-detail/financials/tab.tsx +438 -0
  725. package/src/plugins/builtin/ticker-detail/index.test.tsx +780 -0
  726. package/src/plugins/builtin/ticker-detail/index.tsx +174 -17
  727. package/src/plugins/builtin/ticker-detail/overview/components.tsx +240 -0
  728. package/src/plugins/builtin/ticker-detail/overview/model.ts +168 -0
  729. package/src/plugins/builtin/ticker-detail/overview/pane.tsx +14 -0
  730. package/src/plugins/builtin/ticker-detail/overview/types.ts +17 -0
  731. package/src/plugins/builtin/ticker-detail/overview-tab.tsx +27 -392
  732. package/src/plugins/builtin/ticker-detail/pane.tsx +24 -136
  733. package/src/plugins/builtin/ticker-detail/quote-monitor/card.tsx +330 -0
  734. package/src/plugins/builtin/ticker-detail/quote-monitor/index.test.tsx +292 -0
  735. package/src/plugins/builtin/ticker-detail/quote-monitor/index.tsx +180 -0
  736. package/src/plugins/builtin/ticker-detail/settings.ts +39 -33
  737. package/src/plugins/builtin/world-indices/footer.ts +28 -0
  738. package/src/plugins/builtin/world-indices/index.tsx +25 -218
  739. package/src/plugins/builtin/world-indices/model.ts +120 -0
  740. package/src/plugins/builtin/world-indices/table.tsx +96 -0
  741. package/src/plugins/builtin/yahoo/index.ts +72 -0
  742. package/src/plugins/builtin/yield-curve/index.tsx +5 -5
  743. package/src/plugins/builtin/yield-curve/treasury-data.ts +1 -1
  744. package/src/plugins/catalog-ui.ts +7 -9
  745. package/src/plugins/catalog.ts +1 -1
  746. package/src/plugins/ibkr/account-cache.ts +2 -10
  747. package/src/plugins/ibkr/broker-adapter.ts +10 -4
  748. package/src/plugins/ibkr/config.ts +5 -24
  749. package/src/plugins/ibkr/dialogs.tsx +0 -1
  750. package/src/plugins/ibkr/flex/index.test.ts +236 -0
  751. package/src/plugins/ibkr/flex/index.ts +337 -0
  752. package/src/plugins/ibkr/flex/statement-client.ts +181 -0
  753. package/src/plugins/ibkr/gateway/account-loaders.ts +266 -0
  754. package/src/plugins/ibkr/gateway/account-summary.ts +163 -0
  755. package/src/plugins/ibkr/gateway/client-lock.ts +154 -0
  756. package/src/plugins/ibkr/gateway/connection-events.ts +114 -0
  757. package/src/plugins/ibkr/gateway/connection.ts +152 -0
  758. package/src/plugins/ibkr/gateway/contracts.ts +132 -0
  759. package/src/plugins/ibkr/gateway/fundamentals.ts +83 -0
  760. package/src/plugins/ibkr/gateway/helpers.ts +33 -0
  761. package/src/plugins/ibkr/gateway/history-requests.ts +158 -0
  762. package/src/plugins/ibkr/gateway/history.ts +120 -0
  763. package/src/plugins/ibkr/gateway/instrument-lookup.ts +117 -0
  764. package/src/plugins/ibkr/gateway/market-data.ts +338 -0
  765. package/src/plugins/ibkr/gateway/order-execution.ts +218 -0
  766. package/src/plugins/ibkr/gateway/orders.ts +63 -0
  767. package/src/plugins/ibkr/gateway/price-normalization.test.ts +44 -0
  768. package/src/plugins/ibkr/gateway/price-normalization.ts +50 -0
  769. package/src/plugins/ibkr/gateway/quote-stream-controller.ts +203 -0
  770. package/src/plugins/ibkr/gateway/quote-stream.ts +171 -0
  771. package/src/plugins/ibkr/gateway/selection.ts +51 -0
  772. package/src/plugins/ibkr/gateway/service/index.test.ts +614 -0
  773. package/src/plugins/ibkr/gateway/service/index.ts +432 -0
  774. package/src/plugins/ibkr/gateway/service/lifecycle.ts +191 -0
  775. package/src/plugins/ibkr/gateway/service/manager.ts +52 -0
  776. package/src/plugins/ibkr/gateway/service/market-data.ts +48 -0
  777. package/src/plugins/ibkr/gateway/service/native.ts +543 -0
  778. package/src/plugins/ibkr/gateway/timeouts.ts +13 -0
  779. package/src/plugins/ibkr/gateway/types.ts +27 -0
  780. package/src/plugins/ibkr/hash.ts +8 -0
  781. package/src/plugins/ibkr/index.test.tsx +1 -12
  782. package/src/plugins/ibkr/index.tsx +8 -9
  783. package/src/plugins/ibkr/instance-selection.test.ts +2 -2
  784. package/src/plugins/ibkr/instance-selection.ts +1 -1
  785. package/src/plugins/ibkr/portfolio-performance.test.ts +32 -0
  786. package/src/plugins/ibkr/portfolio-performance.ts +129 -0
  787. package/src/plugins/ibkr/trade/badge.tsx +28 -0
  788. package/src/plugins/ibkr/trade/dialogs.tsx +44 -0
  789. package/src/plugins/ibkr/trade/preview-panel.tsx +130 -0
  790. package/src/plugins/ibkr/trade/tab/actions.tsx +443 -0
  791. package/src/plugins/ibkr/trade/tab/field-editors.tsx +79 -0
  792. package/src/plugins/ibkr/trade/tab/footer.ts +67 -0
  793. package/src/plugins/ibkr/trade/tab/header.tsx +167 -0
  794. package/src/plugins/ibkr/trade/tab/index.test.tsx +178 -0
  795. package/src/plugins/ibkr/trade/tab/index.tsx +302 -0
  796. package/src/plugins/ibkr/trade/tab/model.ts +159 -0
  797. package/src/plugins/ibkr/trade/tab/order-request.ts +64 -0
  798. package/src/plugins/ibkr/trade/tab/shortcuts.ts +89 -0
  799. package/src/plugins/ibkr/trade/tab/state-sync.ts +86 -0
  800. package/src/plugins/ibkr/trade/ticket-panel.tsx +301 -0
  801. package/src/plugins/ibkr/trade/utils.test.ts +175 -0
  802. package/src/plugins/ibkr/trade/utils.ts +150 -0
  803. package/src/plugins/ibkr/trading/pane-view.tsx +175 -0
  804. package/src/plugins/ibkr/trading/pane.tsx +332 -0
  805. package/src/plugins/ibkr/trading/state.test.ts +109 -0
  806. package/src/plugins/ibkr/trading/state.ts +335 -0
  807. package/src/plugins/pane-manager/dock-tree.ts +282 -0
  808. package/src/plugins/pane-manager/docking.ts +202 -0
  809. package/src/plugins/pane-manager/floating-actions.ts +158 -0
  810. package/src/plugins/pane-manager/floating.ts +76 -0
  811. package/src/plugins/pane-manager/gridlock-inference.ts +126 -0
  812. package/src/plugins/pane-manager/gridlock.ts +34 -0
  813. package/src/plugins/pane-manager/layout-state.ts +160 -0
  814. package/src/plugins/pane-manager/queries.ts +75 -0
  815. package/src/plugins/pane-manager/types.ts +24 -0
  816. package/src/plugins/pane-manager.test.ts +110 -4
  817. package/src/plugins/pane-manager.ts +57 -1035
  818. package/src/plugins/prediction-markets/chart.test.tsx +2 -2
  819. package/src/plugins/prediction-markets/controller/catalog.ts +317 -0
  820. package/src/plugins/prediction-markets/controller/data.ts +171 -0
  821. package/src/plugins/prediction-markets/controller/detail.ts +243 -0
  822. package/src/plugins/prediction-markets/controller/effects.ts +253 -0
  823. package/src/plugins/prediction-markets/controller/index.ts +374 -0
  824. package/src/plugins/prediction-markets/controller/keyboard.ts +220 -0
  825. package/src/plugins/prediction-markets/controller/live-updates.ts +85 -0
  826. package/src/plugins/prediction-markets/controller/selection.ts +59 -0
  827. package/src/plugins/prediction-markets/controller/status.ts +104 -0
  828. package/src/plugins/prediction-markets/detail/outcomes.tsx +1 -1
  829. package/src/plugins/prediction-markets/metrics.ts +4 -14
  830. package/src/plugins/prediction-markets/navigation.ts +0 -13
  831. package/src/plugins/prediction-markets/pane.test.tsx +2 -198
  832. package/src/plugins/prediction-markets/plugin.test.tsx +2 -2
  833. package/src/plugins/prediction-markets/services/fetch.ts +1 -5
  834. package/src/plugins/prediction-markets/services/kalshi/adapter.ts +299 -0
  835. package/src/plugins/prediction-markets/services/kalshi/normalize.ts +209 -0
  836. package/src/plugins/prediction-markets/services/kalshi/types.ts +89 -0
  837. package/src/plugins/prediction-markets/services/polymarket/adapter.ts +134 -0
  838. package/src/plugins/prediction-markets/services/polymarket/detail.ts +307 -0
  839. package/src/plugins/prediction-markets/services/polymarket/normalize.ts +239 -0
  840. package/src/plugins/prediction-markets/services/polymarket/types.ts +66 -0
  841. package/src/plugins/prediction-markets/services/polymarket/ws.ts +128 -0
  842. package/src/plugins/prediction-markets/test-helpers.tsx +12 -76
  843. package/src/plugins/prediction-markets/types.ts +2 -2
  844. package/src/plugins/registry/context-menu.ts +36 -0
  845. package/src/plugins/registry/context.ts +196 -0
  846. package/src/plugins/registry/contributions.ts +174 -0
  847. package/src/plugins/registry/index.test.ts +362 -0
  848. package/src/plugins/registry/index.ts +474 -0
  849. package/src/plugins/registry/pane-settings.ts +105 -0
  850. package/src/plugins/registry/plugin-state.ts +123 -0
  851. package/src/plugins/registry/shared.ts +34 -0
  852. package/src/plugins/registry/slots.ts +70 -0
  853. package/src/plugins/runtime/context.tsx +115 -0
  854. package/src/plugins/runtime/index.test.tsx +328 -0
  855. package/src/plugins/runtime/index.tsx +111 -0
  856. package/src/plugins/runtime/state.ts +275 -0
  857. package/src/plugins/ticker-navigation.test.ts +23 -2
  858. package/src/plugins/ticker-navigation.ts +9 -3
  859. package/src/react/input.test.ts +29 -0
  860. package/src/react/input.ts +9 -0
  861. package/src/renderers/electrobun/bun/application-menu/click.test.ts +50 -0
  862. package/src/renderers/electrobun/bun/application-menu/click.ts +58 -0
  863. package/src/renderers/electrobun/bun/application-menu/index.ts +123 -0
  864. package/src/renderers/electrobun/bun/context-menu/click.test.ts +67 -0
  865. package/src/renderers/electrobun/bun/context-menu/normalize.test.ts +52 -0
  866. package/src/renderers/electrobun/bun/context-menu/normalize.ts +67 -0
  867. package/src/renderers/electrobun/bun/core-capabilities.ts +3 -0
  868. package/src/renderers/electrobun/bun/desktop/backend-requests.ts +163 -0
  869. package/src/renderers/electrobun/bun/desktop/capability-bridge.ts +93 -0
  870. package/src/renderers/electrobun/bun/desktop/detached-windows.ts +263 -0
  871. package/src/renderers/electrobun/bun/desktop/host-requests.ts +114 -0
  872. package/src/renderers/electrobun/bun/desktop/http-fetch.ts +56 -0
  873. package/src/renderers/electrobun/bun/desktop/initialization.ts +139 -0
  874. package/src/renderers/electrobun/bun/desktop/plugin-state.ts +92 -0
  875. package/src/renderers/electrobun/bun/desktop/relaunch.ts +48 -0
  876. package/src/renderers/electrobun/bun/desktop/rpc-registry.ts +43 -0
  877. package/src/renderers/electrobun/bun/desktop/state-broadcaster.ts +76 -0
  878. package/src/renderers/electrobun/bun/desktop/update.ts +162 -0
  879. package/src/renderers/electrobun/bun/desktop/window-events.ts +49 -0
  880. package/src/renderers/electrobun/bun/desktop/workspace/index.test.ts +63 -0
  881. package/src/renderers/electrobun/bun/desktop/workspace/index.ts +180 -0
  882. package/src/renderers/electrobun/bun/desktop/workspace/requests.ts +97 -0
  883. package/src/renderers/electrobun/bun/index.ts +191 -947
  884. package/src/renderers/electrobun/bun/tui-entry.ts +6 -0
  885. package/src/renderers/electrobun/bun/window/focus.ts +37 -0
  886. package/src/renderers/electrobun/bun/window/frame.test.ts +40 -0
  887. package/src/renderers/electrobun/shared/protocol.ts +9 -2
  888. package/src/renderers/electrobun/view/app-services.ts +4 -375
  889. package/src/renderers/electrobun/view/backend-rpc.ts +5 -0
  890. package/src/renderers/electrobun/view/build-assets.ts +117 -0
  891. package/src/renderers/electrobun/view/cli-pane-shot-entry.tsx +398 -0
  892. package/src/renderers/electrobun/view/config-host.ts +1 -1
  893. package/src/renderers/electrobun/view/context-menu.test.ts +10 -4
  894. package/src/renderers/electrobun/view/context-menu.ts +1 -1
  895. package/src/renderers/electrobun/view/data-table/dom.ts +211 -0
  896. package/src/renderers/electrobun/view/data-table/index.tsx +358 -0
  897. package/src/renderers/electrobun/view/data-table/row.tsx +335 -0
  898. package/src/renderers/electrobun/view/desktop/control-styles.ts +77 -0
  899. package/src/renderers/electrobun/view/desktop/controls.tsx +421 -0
  900. package/src/renderers/electrobun/view/desktop/list-view.tsx +200 -0
  901. package/src/renderers/electrobun/view/desktop/window/bridge.ts +70 -0
  902. package/src/renderers/electrobun/view/desktop/window/snapshot.test.ts +57 -0
  903. package/src/renderers/electrobun/view/desktop/window/snapshot.ts +41 -0
  904. package/src/renderers/electrobun/view/fatal-screen.tsx +118 -0
  905. package/src/renderers/electrobun/view/host/box.tsx +160 -0
  906. package/src/renderers/electrobun/view/host/chart-surface.tsx +142 -0
  907. package/src/renderers/electrobun/view/host/input.tsx +294 -0
  908. package/src/renderers/electrobun/view/host/mouse.ts +139 -0
  909. package/src/renderers/electrobun/view/host/native.ts +49 -0
  910. package/src/renderers/electrobun/view/host/scroll-box.tsx +276 -0
  911. package/src/renderers/electrobun/view/host/style.ts +124 -0
  912. package/src/renderers/electrobun/view/host/tabs.tsx +255 -0
  913. package/src/renderers/electrobun/view/host/text.tsx +121 -0
  914. package/src/renderers/electrobun/view/http-fetch.ts +1 -1
  915. package/src/renderers/electrobun/view/input-host.tsx +12 -1
  916. package/src/renderers/electrobun/view/main.tsx +45 -26
  917. package/src/renderers/electrobun/view/native-stubs/backend-rpc.ts +59 -0
  918. package/src/renderers/electrobun/view/native-stubs/chart/kitty-support.ts +9 -0
  919. package/src/renderers/electrobun/view/remote/asset-data-client.ts +201 -0
  920. package/src/renderers/electrobun/view/remote/persistence.ts +158 -0
  921. package/src/renderers/electrobun/view/remote/ticker-repository.ts +26 -0
  922. package/src/renderers/electrobun/view/styles.css +91 -4
  923. package/src/renderers/electrobun/view/ui-host.tsx +22 -1469
  924. package/src/renderers/opentui/chart-surface.tsx +4 -5
  925. package/src/renderers/opentui/host.tsx +30 -4
  926. package/src/renderers/opentui/image/loader.test.ts +25 -0
  927. package/src/renderers/opentui/image/loader.ts +105 -0
  928. package/src/renderers/opentui/image/surface.tsx +266 -0
  929. package/src/renderers/opentui/input-host.tsx +12 -1
  930. package/src/renderers/opentui/start.tsx +2 -2
  931. package/src/renderers/opentui/test-utils.tsx +2 -2
  932. package/src/renderers/opentui/ui-host.tsx +1 -1
  933. package/src/sources/gloomberb-cloud/index.test.ts +660 -0
  934. package/src/sources/gloomberb-cloud/index.ts +444 -0
  935. package/src/sources/gloomberb-cloud/news.ts +127 -0
  936. package/src/sources/gloomberb-cloud/normalizers.ts +354 -0
  937. package/src/sources/provider-errors.ts +8 -2
  938. package/src/sources/provider-router/batches.ts +170 -0
  939. package/src/sources/provider-router/brokers.ts +114 -0
  940. package/src/sources/provider-router/cache.ts +171 -0
  941. package/src/sources/provider-router/cached-financials.test.ts +498 -0
  942. package/src/sources/provider-router/document-routes.ts +153 -0
  943. package/src/sources/provider-router/financial-routes.ts +225 -0
  944. package/src/sources/provider-router/financials.ts +259 -0
  945. package/src/sources/provider-router/history.test.ts +383 -0
  946. package/src/sources/provider-router/history.ts +448 -0
  947. package/src/sources/provider-router/index.test.ts +1438 -0
  948. package/src/sources/provider-router/index.ts +389 -0
  949. package/src/sources/provider-router/news.ts +36 -0
  950. package/src/sources/provider-router/primary.ts +164 -0
  951. package/src/sources/provider-router/route-types.ts +34 -0
  952. package/src/sources/provider-router/routing.ts +58 -0
  953. package/src/sources/provider-router/search.ts +183 -0
  954. package/src/sources/provider-router/sources.ts +55 -0
  955. package/src/sources/provider-router/streaming.ts +92 -0
  956. package/src/sources/provider-router/supplemental.ts +373 -0
  957. package/src/sources/provider-router/test-support.ts +136 -0
  958. package/src/sources/sec-edgar/content.ts +211 -0
  959. package/src/sources/sec-edgar.ts +9 -217
  960. package/src/sources/yahoo-finance/financials.ts +339 -0
  961. package/src/sources/yahoo-finance/history.ts +106 -0
  962. package/src/sources/yahoo-finance/http.ts +100 -0
  963. package/src/sources/yahoo-finance/mappers.ts +409 -0
  964. package/src/sources/yahoo-finance/options.ts +134 -0
  965. package/src/sources/yahoo-finance/quote-summary.ts +210 -0
  966. package/src/sources/yahoo-finance/requests.ts +192 -0
  967. package/src/sources/yahoo-finance/snapshots.ts +236 -0
  968. package/src/sources/yahoo-finance/symbols.ts +102 -0
  969. package/src/sources/yahoo-finance/types.ts +167 -0
  970. package/src/sources/yahoo-finance.test.ts +116 -12
  971. package/src/sources/yahoo-finance.ts +115 -1408
  972. package/src/state/app/activity.test.ts +41 -0
  973. package/src/state/app/activity.ts +106 -0
  974. package/src/state/app/bootstrap.test.ts +498 -0
  975. package/src/state/app/bootstrap.ts +412 -0
  976. package/src/state/app/context/index.test.ts +564 -0
  977. package/src/state/app/context/index.test.tsx +193 -0
  978. package/src/state/app/context/index.tsx +476 -0
  979. package/src/state/app/context/selector.test.tsx +291 -0
  980. package/src/state/config-save-scheduler.ts +2 -6
  981. package/src/state/hooks/inline-tickers.test.tsx +123 -0
  982. package/src/state/hooks/inline-tickers.ts +212 -0
  983. package/src/state/hooks/quote-streaming.test.ts +31 -0
  984. package/src/state/hooks/quote-streaming.test.tsx +70 -0
  985. package/src/state/hooks/quote-streaming.ts +92 -0
  986. package/src/state/hooks/session-snapshot.ts +99 -0
  987. package/src/state/pane-scroll-registry.tsx +1 -1
  988. package/src/state/selectors-ui.ts +1 -1
  989. package/src/state/selectors.ts +1 -1
  990. package/src/test-support/plugin-persistence.ts +112 -0
  991. package/src/test-support/plugin-runtime.ts +2 -1
  992. package/src/theme/colors.ts +23 -9
  993. package/src/theme/themes.test.ts +15 -0
  994. package/src/tickers/list.test.ts +16 -0
  995. package/src/tickers/open-target.ts +77 -0
  996. package/src/tickers/search/index.test.ts +252 -0
  997. package/src/tickers/search/index.ts +367 -0
  998. package/src/tickers/search/ranking.ts +387 -0
  999. package/src/tickers/search/result.ts +27 -0
  1000. package/src/tickers/search/types.ts +41 -0
  1001. package/src/tickers/search/upsert.ts +91 -0
  1002. package/src/tickers/tokenizer.test.ts +31 -0
  1003. package/src/tickers/tokenizer.ts +37 -0
  1004. package/src/types/broker.ts +12 -4
  1005. package/src/types/config.ts +42 -23
  1006. package/src/types/context-menu.ts +1 -1
  1007. package/src/types/data-provider.ts +2 -2
  1008. package/src/types/desktop-window.ts +1 -1
  1009. package/src/types/financials.ts +109 -4
  1010. package/src/types/news-source.ts +0 -1
  1011. package/src/types/persistence.ts +1 -1
  1012. package/src/types/plugin.ts +37 -21
  1013. package/src/types/ticker.ts +1 -0
  1014. package/src/types/trading.ts +23 -1
  1015. package/src/ui/context-menu.tsx +6 -5
  1016. package/src/ui/dialog.tsx +6 -3
  1017. package/src/ui/host.tsx +10 -10
  1018. package/src/ui/index.tsx +14 -33
  1019. package/src/updater/github-releases.test.ts +41 -0
  1020. package/src/updater/github-releases.ts +73 -0
  1021. package/src/updater.test.ts +21 -0
  1022. package/src/updater.ts +10 -3
  1023. package/src/utils/back-navigation.ts +2 -2
  1024. package/src/utils/cli-output.ts +4 -4
  1025. package/src/utils/currency-units.test.ts +23 -1
  1026. package/src/utils/currency-units.ts +56 -0
  1027. package/src/utils/datetime-format.ts +40 -0
  1028. package/src/utils/dom-screenshot.ts +2 -2
  1029. package/src/utils/double-escape-close.ts +1 -1
  1030. package/src/utils/exchanges.ts +2 -2
  1031. package/src/utils/format.ts +0 -7
  1032. package/src/utils/fuzzy-search.ts +1 -1
  1033. package/src/utils/inline-content-tokenizer.test.ts +11 -2
  1034. package/src/utils/inline-content-tokenizer.ts +33 -12
  1035. package/src/utils/keyboard.ts +1 -1
  1036. package/src/utils/link-tokenizer.ts +2 -2
  1037. package/src/utils/options.ts +1 -1
  1038. package/src/utils/price-history.test.ts +20 -0
  1039. package/src/utils/price-history.ts +24 -2
  1040. package/src/utils/relative-time.ts +8 -0
  1041. package/src/utils/selection-clipboard.ts +1 -1
  1042. package/src/utils/shortcut-labels.ts +2 -2
  1043. package/src/utils/sort-values.ts +17 -0
  1044. package/src/utils/terminal-input-reset.ts +1 -1
  1045. package/src/utils/text-wrap.ts +20 -0
  1046. package/src/version.ts +1 -1
  1047. package/src/components/chart/chart-controller.test.ts +0 -110
  1048. package/src/components/chart/chart-controller.ts +0 -650
  1049. package/src/components/chart/chart-data.ts +0 -350
  1050. package/src/components/chart/chart-indicator-selector.tsx +0 -75
  1051. package/src/components/chart/chart-pane-settings.ts +0 -37
  1052. package/src/components/chart/chart-renderer.ts +0 -1562
  1053. package/src/components/chart/chart-resolution.test.ts +0 -87
  1054. package/src/components/chart/chart-resolution.ts +0 -405
  1055. package/src/components/chart/chart-scroll.test.ts +0 -70
  1056. package/src/components/chart/chart-scroll.ts +0 -104
  1057. package/src/components/chart/chart-types.ts +0 -119
  1058. package/src/components/chart/chart-viewport.test.ts +0 -29
  1059. package/src/components/chart/chart-viewport.ts +0 -50
  1060. package/src/components/chart/chart.test.ts +0 -922
  1061. package/src/components/chart/comparison-chart-data.test.ts +0 -105
  1062. package/src/components/chart/comparison-chart-data.ts +0 -292
  1063. package/src/components/chart/comparison-chart-renderer.test.ts +0 -187
  1064. package/src/components/chart/comparison-chart-renderer.ts +0 -437
  1065. package/src/components/chart/native/kitty-adapter.ts +0 -9
  1066. package/src/components/chart/native/kitty-manager.ts +0 -142
  1067. package/src/components/chart/native/kitty-support.ts +0 -71
  1068. package/src/components/chart/native/kitty.test.ts +0 -728
  1069. package/src/components/chart/native/surface-manager.ts +0 -225
  1070. package/src/components/chart/native/surface-sync.ts +0 -34
  1071. package/src/components/chart/native/surface-visibility.ts +0 -48
  1072. package/src/components/chart/static-chart-surface.test.tsx +0 -51
  1073. package/src/components/chart/static-chart-surface.tsx +0 -217
  1074. package/src/components/chart/stock-chart-renderer-switch.test.tsx +0 -1323
  1075. package/src/components/chart/stock-chart.test.ts +0 -330
  1076. package/src/components/chart/stock-chart.tsx +0 -4148
  1077. package/src/components/command-bar/__snapshots__/command-bar.test.tsx.snap +0 -109
  1078. package/src/components/command-bar/command-bar.test.tsx +0 -3244
  1079. package/src/components/command-bar/command-bar.tsx +0 -5868
  1080. package/src/components/command-bar/command-registry.ts +0 -267
  1081. package/src/components/command-bar/confirm-body.tsx +0 -51
  1082. package/src/components/command-bar/list-model.ts +0 -80
  1083. package/src/components/command-bar/pane-template-display.ts +0 -8
  1084. package/src/components/command-bar/root-shortcuts.ts +0 -188
  1085. package/src/components/command-bar/workflow-ops.test.ts +0 -144
  1086. package/src/components/command-bar/workflow-ops.ts +0 -459
  1087. package/src/components/command-bar/workflow-types.ts +0 -127
  1088. package/src/components/data-table-stack-view.test.tsx +0 -241
  1089. package/src/components/data-table-stack-view.tsx +0 -59
  1090. package/src/components/data-table-view.test.tsx +0 -211
  1091. package/src/components/data-table-view.tsx +0 -244
  1092. package/src/components/feed-data-table-stack-view.test.tsx +0 -225
  1093. package/src/components/feed-data-table-stack-view.tsx +0 -359
  1094. package/src/components/layout/pane-content.test.tsx +0 -64
  1095. package/src/components/layout/pane-content.tsx +0 -44
  1096. package/src/components/layout/pane-cycle-order.test.ts +0 -30
  1097. package/src/components/layout/pane-cycle-order.ts +0 -32
  1098. package/src/components/layout/pane-footer.test.tsx +0 -195
  1099. package/src/components/layout/pane-footer.tsx +0 -432
  1100. package/src/components/layout/pane-header.test.tsx +0 -39
  1101. package/src/components/layout/pane-header.tsx +0 -248
  1102. package/src/components/layout/pane-keyboard-scroll.test.tsx +0 -226
  1103. package/src/components/layout/pane-sizing.ts +0 -34
  1104. package/src/components/layout/pane-title.ts +0 -38
  1105. package/src/components/layout/pane.tsx +0 -129
  1106. package/src/components/layout/shell.test.tsx +0 -1427
  1107. package/src/components/layout/shell.tsx +0 -1912
  1108. package/src/components/price-sparkline-view.tsx +0 -463
  1109. package/src/components/price-sparkline.ts +0 -46
  1110. package/src/components/speedometer-gauge.test.tsx +0 -45
  1111. package/src/components/speedometer-gauge.tsx +0 -562
  1112. package/src/components/ticker-badge-list.tsx +0 -53
  1113. package/src/components/ticker-badge-text.test.tsx +0 -253
  1114. package/src/components/ticker-badge-text.tsx +0 -113
  1115. package/src/components/ticker-badge.tsx +0 -109
  1116. package/src/components/ticker-list-table-view.tsx +0 -233
  1117. package/src/components/ticker-list-table.test.tsx +0 -210
  1118. package/src/components/ticker-list-table.tsx +0 -458
  1119. package/src/components/ui/data-table.tsx +0 -522
  1120. package/src/components/ui/multi-select-dialog.tsx +0 -336
  1121. package/src/core/state/app-state.ts +0 -1009
  1122. package/src/data/config-layout.ts +0 -225
  1123. package/src/data/config-store-node.ts +0 -478
  1124. package/src/data/config-store.test.ts +0 -481
  1125. package/src/data/config-store.ts +0 -64
  1126. package/src/data/sqlite-cache.test.ts +0 -151
  1127. package/src/data/sqlite-database.ts +0 -68
  1128. package/src/data/sqlite-json.ts +0 -16
  1129. package/src/data/sqlite-retry.test.ts +0 -63
  1130. package/src/market-data/coordinator-subscriptions.test.ts +0 -209
  1131. package/src/market-data/coordinator.test.ts +0 -830
  1132. package/src/market-data/coordinator.ts +0 -1155
  1133. package/src/plugins/builtin/ai/screener-contract.test.ts +0 -117
  1134. package/src/plugins/builtin/ai/screener-contract.ts +0 -174
  1135. package/src/plugins/builtin/ai/screener-pane.test.tsx +0 -348
  1136. package/src/plugins/builtin/ai/screener-pane.tsx +0 -1118
  1137. package/src/plugins/builtin/ai/utils.ts +0 -1
  1138. package/src/plugins/builtin/ask-ai.test.tsx +0 -348
  1139. package/src/plugins/builtin/chat-controller.test.ts +0 -1376
  1140. package/src/plugins/builtin/chat-controller.ts +0 -1248
  1141. package/src/plugins/builtin/chat.test.tsx +0 -2245
  1142. package/src/plugins/builtin/chat.tsx +0 -2267
  1143. package/src/plugins/builtin/cloud-auth-actions.tsx +0 -72
  1144. package/src/plugins/builtin/cloud-tweets.tsx +0 -896
  1145. package/src/plugins/builtin/comparison-chart.test.tsx +0 -532
  1146. package/src/plugins/builtin/comparison-chart.tsx +0 -194
  1147. package/src/plugins/builtin/debug.tsx +0 -365
  1148. package/src/plugins/builtin/earnings/earnings-cache.test.ts +0 -181
  1149. package/src/plugins/builtin/earnings/earnings-cache.ts +0 -145
  1150. package/src/plugins/builtin/earnings/earnings-data.test.ts +0 -90
  1151. package/src/plugins/builtin/earnings/earnings-data.ts +0 -115
  1152. package/src/plugins/builtin/fear-greed/fear-greed-data.test.ts +0 -72
  1153. package/src/plugins/builtin/fear-greed/fear-greed-data.ts +0 -366
  1154. package/src/plugins/builtin/help.test.tsx +0 -166
  1155. package/src/plugins/builtin/help.tsx +0 -450
  1156. package/src/plugins/builtin/layout-manager.tsx +0 -247
  1157. package/src/plugins/builtin/manual-entry.tsx +0 -25
  1158. package/src/plugins/builtin/news-wire/breaking-notifications.test.ts +0 -98
  1159. package/src/plugins/builtin/news-wire/breaking-notifications.ts +0 -110
  1160. package/src/plugins/builtin/news-wire/breaking-pane.test.tsx +0 -156
  1161. package/src/plugins/builtin/news-wire/breaking-pane.tsx +0 -68
  1162. package/src/plugins/builtin/news-wire/categories.ts +0 -114
  1163. package/src/plugins/builtin/news-wire/default-feeds.ts +0 -3
  1164. package/src/plugins/builtin/news-wire/feed-config.test.ts +0 -90
  1165. package/src/plugins/builtin/news-wire/feed-config.ts +0 -216
  1166. package/src/plugins/builtin/news-wire/index.tsx +0 -129
  1167. package/src/plugins/builtin/news-wire/industry-pane.tsx +0 -126
  1168. package/src/plugins/builtin/news-wire/news-detail-view.tsx +0 -299
  1169. package/src/plugins/builtin/news-wire/news-footer.ts +0 -28
  1170. package/src/plugins/builtin/news-wire/news-preset-pane.tsx +0 -98
  1171. package/src/plugins/builtin/news-wire/news-query-presets.ts +0 -40
  1172. package/src/plugins/builtin/news-wire/news-table.test.tsx +0 -206
  1173. package/src/plugins/builtin/news-wire/news-table.tsx +0 -296
  1174. package/src/plugins/builtin/news-wire/persisted-articles.ts +0 -98
  1175. package/src/plugins/builtin/news-wire/read-state.ts +0 -76
  1176. package/src/plugins/builtin/news-wire/rss-parser.test.ts +0 -184
  1177. package/src/plugins/builtin/news-wire/rss-parser.ts +0 -213
  1178. package/src/plugins/builtin/news-wire/rss-source.test.ts +0 -159
  1179. package/src/plugins/builtin/news-wire/rss-source.ts +0 -181
  1180. package/src/plugins/builtin/news.tsx +0 -194
  1181. package/src/plugins/builtin/notes.tsx +0 -561
  1182. package/src/plugins/builtin/options.test.tsx +0 -241
  1183. package/src/plugins/builtin/options.tsx +0 -542
  1184. package/src/plugins/builtin/portfolio-list/cli/commands.ts +0 -657
  1185. package/src/plugins/builtin/portfolio-list/pane.tsx +0 -724
  1186. package/src/plugins/builtin/portfolio-list/quick-add.tsx +0 -422
  1187. package/src/plugins/builtin/portfolio-list/summary.tsx +0 -275
  1188. package/src/plugins/builtin/portfolio-list.test.ts +0 -133
  1189. package/src/plugins/builtin/portfolio-list.test.tsx +0 -1535
  1190. package/src/plugins/builtin/portfolio-metrics.test.ts +0 -236
  1191. package/src/plugins/builtin/quote-monitor.test.tsx +0 -222
  1192. package/src/plugins/builtin/sec-filing-display.tsx +0 -84
  1193. package/src/plugins/builtin/sec.tsx +0 -342
  1194. package/src/plugins/builtin/ticker-detail/financials-tab.tsx +0 -461
  1195. package/src/plugins/builtin/ticker-detail/quote-monitor.tsx +0 -479
  1196. package/src/plugins/builtin/ticker-detail-chart-tab-switch.test.tsx +0 -269
  1197. package/src/plugins/builtin/ticker-detail.test.tsx +0 -888
  1198. package/src/plugins/builtin/ticker-surface.ts +0 -68
  1199. package/src/plugins/builtin/yahoo.ts +0 -72
  1200. package/src/plugins/catalog-ui.test.ts +0 -24
  1201. package/src/plugins/ibkr/__snapshots__/trade-tab.test.tsx.snap +0 -35
  1202. package/src/plugins/ibkr/flex.test.ts +0 -162
  1203. package/src/plugins/ibkr/flex.ts +0 -371
  1204. package/src/plugins/ibkr/gateway-helpers.ts +0 -33
  1205. package/src/plugins/ibkr/gateway-selection.ts +0 -51
  1206. package/src/plugins/ibkr/gateway-service-native.ts +0 -2377
  1207. package/src/plugins/ibkr/gateway-service.test.ts +0 -584
  1208. package/src/plugins/ibkr/gateway-service.ts +0 -433
  1209. package/src/plugins/ibkr/gateway-types.ts +0 -27
  1210. package/src/plugins/ibkr/price-normalization.test.ts +0 -33
  1211. package/src/plugins/ibkr/price-normalization.ts +0 -60
  1212. package/src/plugins/ibkr/trade-badge.tsx +0 -28
  1213. package/src/plugins/ibkr/trade-tab.test.tsx +0 -276
  1214. package/src/plugins/ibkr/trade-tab.tsx +0 -1117
  1215. package/src/plugins/ibkr/trade-utils.test.ts +0 -175
  1216. package/src/plugins/ibkr/trade-utils.ts +0 -150
  1217. package/src/plugins/ibkr/trading-pane.tsx +0 -474
  1218. package/src/plugins/ibkr/trading-state.test.ts +0 -109
  1219. package/src/plugins/ibkr/trading-state.ts +0 -339
  1220. package/src/plugins/plugin-runtime.test.tsx +0 -323
  1221. package/src/plugins/plugin-runtime.tsx +0 -433
  1222. package/src/plugins/prediction-markets/controller-data.ts +0 -785
  1223. package/src/plugins/prediction-markets/controller.ts +0 -659
  1224. package/src/plugins/prediction-markets/services/kalshi-adapter.ts +0 -572
  1225. package/src/plugins/prediction-markets/services/polymarket-adapter.ts +0 -696
  1226. package/src/plugins/prediction-markets/services/polymarket-ws.ts +0 -128
  1227. package/src/plugins/registry.test.ts +0 -362
  1228. package/src/plugins/registry.ts +0 -854
  1229. package/src/renderers/electrobun/bun/application-menu-click.test.ts +0 -50
  1230. package/src/renderers/electrobun/bun/application-menu-click.ts +0 -58
  1231. package/src/renderers/electrobun/bun/application-menu.ts +0 -123
  1232. package/src/renderers/electrobun/bun/context-menu-click.test.ts +0 -67
  1233. package/src/renderers/electrobun/bun/context-menu-normalize.test.ts +0 -52
  1234. package/src/renderers/electrobun/bun/context-menu-normalize.ts +0 -67
  1235. package/src/renderers/electrobun/bun/desktop-workspace.test.ts +0 -63
  1236. package/src/renderers/electrobun/bun/desktop-workspace.ts +0 -180
  1237. package/src/renderers/electrobun/bun/window-focus.ts +0 -37
  1238. package/src/renderers/electrobun/bun/window-frame.test.ts +0 -40
  1239. package/src/renderers/electrobun/view/data-table.tsx +0 -810
  1240. package/src/renderers/electrobun/view/desktop-controls.tsx +0 -673
  1241. package/src/renderers/electrobun/view/desktop-window-bridge.ts +0 -70
  1242. package/src/renderers/electrobun/view/desktop-window-snapshot.test.ts +0 -57
  1243. package/src/renderers/electrobun/view/desktop-window-snapshot.ts +0 -41
  1244. package/src/renderers/electrobun/view/native-stubs/chart-kitty-support.ts +0 -9
  1245. package/src/renderers/opentui/image-loader.test.ts +0 -25
  1246. package/src/renderers/opentui/image-loader.ts +0 -105
  1247. package/src/renderers/opentui/image-surface.tsx +0 -266
  1248. package/src/sources/gloomberb-cloud.test.ts +0 -637
  1249. package/src/sources/gloomberb-cloud.ts +0 -828
  1250. package/src/sources/provider-router.test.ts +0 -2600
  1251. package/src/sources/provider-router.ts +0 -2231
  1252. package/src/state/app-activity.test.ts +0 -41
  1253. package/src/state/app-activity.ts +0 -106
  1254. package/src/state/app-bootstrap.test.ts +0 -498
  1255. package/src/state/app-bootstrap.ts +0 -411
  1256. package/src/state/app-context-selector.test.tsx +0 -369
  1257. package/src/state/app-context.test.ts +0 -670
  1258. package/src/state/app-context.test.tsx +0 -193
  1259. package/src/state/app-context.tsx +0 -485
  1260. package/src/state/use-inline-tickers.test.tsx +0 -73
  1261. package/src/state/use-inline-tickers.ts +0 -188
  1262. package/src/state/use-quote-streaming.test.ts +0 -31
  1263. package/src/state/use-quote-streaming.test.tsx +0 -70
  1264. package/src/state/use-quote-streaming.ts +0 -92
  1265. package/src/state/use-session-snapshot.ts +0 -99
  1266. package/src/utils/api-client.test.ts +0 -603
  1267. package/src/utils/api-client.ts +0 -1379
  1268. package/src/utils/market-format.test.ts +0 -109
  1269. package/src/utils/market-format.ts +0 -299
  1270. package/src/utils/market-status.ts +0 -141
  1271. package/src/utils/quote-freshness.test.ts +0 -150
  1272. package/src/utils/quote-freshness.ts +0 -145
  1273. package/src/utils/quote-resolution.test.ts +0 -277
  1274. package/src/utils/quote-resolution.ts +0 -642
  1275. package/src/utils/quote-time.test.ts +0 -34
  1276. package/src/utils/quote-time.ts +0 -59
  1277. package/src/utils/ticker-list.test.ts +0 -16
  1278. package/src/utils/ticker-search.test.ts +0 -227
  1279. package/src/utils/ticker-search.ts +0 -855
  1280. package/src/utils/ticker-tokenizer.test.ts +0 -31
  1281. package/src/utils/ticker-tokenizer.ts +0 -37
  1282. /package/src/components/chart/native/{kitty-protocol.ts → kitty/protocol.ts} +0 -0
  1283. /package/src/components/ui/{multi-select.ts → multi-select/index.ts} +0 -0
  1284. /package/src/data/{sqlite-retry.ts → sqlite/retry.ts} +0 -0
  1285. /package/src/plugins/builtin/{news-wire → news/wire}/hash.ts +0 -0
  1286. /package/src/plugins/builtin/{news-wire → news/wire}/read-state.test.ts +0 -0
  1287. /package/src/plugins/builtin/{notes-files.ts → notes/files.ts} +0 -0
  1288. /package/src/renderers/electrobun/bun/{context-menu-click.ts → context-menu/click.ts} +0 -0
  1289. /package/src/renderers/electrobun/bun/{window-frame.ts → window/frame.ts} +0 -0
  1290. /package/src/renderers/electrobun/view/native-stubs/{chart-surface-manager.ts → chart/surface-manager.ts} +0 -0
  1291. /package/src/renderers/electrobun/view/native-stubs/{chart-surface-sync.ts → chart/surface-sync.ts} +0 -0
  1292. /package/src/{utils/ticker-list.ts → tickers/list.ts} +0 -0
  1293. /package/src/{utils/ticker-metadata.ts → tickers/metadata.ts} +0 -0
@@ -1,2600 +0,0 @@
1
- import { afterEach, describe, expect, test } from "bun:test";
2
- import { existsSync, rmSync } from "fs";
3
- import { tmpdir } from "os";
4
- import { join } from "path";
5
- import { AppPersistence } from "../data/app-persistence";
6
- import { AssetDataRouter } from "./provider-router";
7
- import { assetDataProvider } from "../capabilities";
8
- import type { BrokerAdapter } from "../types/broker";
9
- import type { DataProvider, QuoteSubscriptionTarget } from "../types/data-provider";
10
- import type { CapabilityRouteSource } from "../types/capability-route-source";
11
- import type { NewsArticle } from "../news/types";
12
- import { cloneLayout, CURRENT_CONFIG_VERSION, DEFAULT_LAYOUT } from "../types/config";
13
-
14
- const originalConsoleError = console.error;
15
- const tempPaths: string[] = [];
16
-
17
- function createTempDbPath(name: string): string {
18
- const path = join(tmpdir(), `gloomberb-provider-router-${name}-${Date.now()}-${Math.random().toString(36).slice(2)}.db`);
19
- tempPaths.push(path);
20
- return path;
21
- }
22
-
23
- afterEach(() => {
24
- console.error = originalConsoleError;
25
- for (const path of tempPaths.splice(0)) {
26
- if (existsSync(path)) rmSync(path, { force: true });
27
- }
28
- });
29
-
30
- const fallbackProvider: DataProvider = {
31
- id: "fallback",
32
- name: "Fallback",
33
- async getTickerFinancials() {
34
- return { annualStatements: [], quarterlyStatements: [], priceHistory: [] };
35
- },
36
- async getQuote() {
37
- return {
38
- symbol: "AAPL",
39
- price: 100,
40
- currency: "USD",
41
- change: 0,
42
- changePercent: 0,
43
- lastUpdated: Date.now(),
44
- };
45
- },
46
- async getExchangeRate() {
47
- return 1;
48
- },
49
- async search() {
50
- return [];
51
- },
52
- async getArticleSummary() {
53
- return null;
54
- },
55
- async getPriceHistory() {
56
- return [];
57
- },
58
- };
59
-
60
- function makeArticle(id: string): NewsArticle {
61
- return {
62
- id,
63
- title: id,
64
- url: `https://example.com/${id}`,
65
- source: "Test",
66
- publishedAt: new Date(),
67
- topic: "general",
68
- topics: ["general"],
69
- sectors: [],
70
- categories: [],
71
- tickers: [],
72
- scores: {
73
- importance: 50,
74
- urgency: 0,
75
- marketImpact: 50,
76
- novelty: 0,
77
- confidence: 0,
78
- },
79
- importance: 50,
80
- isBreaking: false,
81
- isDeveloping: false,
82
- };
83
- }
84
-
85
- describe("AssetDataRouter", () => {
86
- test("serves USD exchange rate locally without provider revalidation", async () => {
87
- let providerCalls = 0;
88
- const router = new AssetDataRouter({
89
- ...fallbackProvider,
90
- async getExchangeRate() {
91
- providerCalls += 1;
92
- return 1;
93
- },
94
- });
95
-
96
- const rate = await router.getExchangeRate("usd");
97
- await Promise.resolve();
98
-
99
- expect(rate).toBe(1);
100
- expect(providerCalls).toBe(0);
101
- });
102
-
103
- test("routes market calls only through sources with market capability", async () => {
104
- const newsOnlySource: CapabilityRouteSource = {
105
- id: "news-only",
106
- name: "News Only",
107
- priority: 1,
108
- news: {
109
- fetchNews: async () => {
110
- throw new Error("news-only source should not handle market requests");
111
- },
112
- },
113
- };
114
- const marketSource: CapabilityRouteSource = {
115
- id: "market-source",
116
- name: "Market Source",
117
- priority: 10,
118
- market: {
119
- ...fallbackProvider,
120
- id: "market-source",
121
- name: "Market Source",
122
- async getQuote(symbol) {
123
- return {
124
- symbol,
125
- providerId: "market-source",
126
- price: 250,
127
- currency: "USD",
128
- change: 1,
129
- changePercent: 0.4,
130
- lastUpdated: Date.now(),
131
- };
132
- },
133
- },
134
- };
135
-
136
- const router = new AssetDataRouter(fallbackProvider, [newsOnlySource, marketSource]);
137
-
138
- const quote = await router.getQuote("AAPL", "NASDAQ");
139
-
140
- expect(quote.providerId).toBe("market-source");
141
- expect(quote.price).toBe(250);
142
- });
143
-
144
- test("routes news calls only through sources with news capability", async () => {
145
- const article = makeArticle("source-news");
146
- const marketOnlySource: CapabilityRouteSource = {
147
- id: "market-only",
148
- name: "Market Only",
149
- priority: 1,
150
- market: {
151
- ...fallbackProvider,
152
- id: "market-only",
153
- name: "Market Only",
154
- },
155
- };
156
- const newsSource: CapabilityRouteSource = {
157
- id: "news-source",
158
- name: "News Source",
159
- priority: 10,
160
- news: {
161
- fetchNews: async () => [article],
162
- },
163
- };
164
- const router = new AssetDataRouter(null, [marketOnlySource, newsSource]);
165
-
166
- const articles = await router.getNews({ feed: "latest", limit: 10 });
167
-
168
- expect(articles).toEqual([article]);
169
- });
170
-
171
- test("falls back to later providers when holder data is empty", async () => {
172
- const cloudProvider: DataProvider = {
173
- ...fallbackProvider,
174
- id: "cloud",
175
- name: "Cloud",
176
- priority: 100,
177
- async getHolders(symbol) {
178
- return {
179
- providerId: "cloud",
180
- symbol,
181
- holders: [],
182
- };
183
- },
184
- };
185
- const yahooProvider: DataProvider = {
186
- ...fallbackProvider,
187
- id: "yahoo",
188
- name: "Yahoo",
189
- priority: 1000,
190
- async getHolders(symbol) {
191
- return {
192
- providerId: "yahoo",
193
- symbol,
194
- currency: "USD",
195
- holders: [{
196
- providerId: "yahoo",
197
- ownerType: "institution",
198
- name: "Vanguard Group Inc",
199
- shares: 1_200_000_000,
200
- value: 250_000_000_000,
201
- percentHeld: 0.08,
202
- changePercent: 0.02,
203
- }],
204
- };
205
- },
206
- };
207
-
208
- const router = new AssetDataRouter(yahooProvider, [cloudProvider]);
209
- const holders = await router.getHolders("AAPL", "NASDAQ");
210
-
211
- expect(holders.providerId).toBe("yahoo");
212
- expect(holders.holders[0]?.name).toBe("Vanguard Group Inc");
213
- });
214
-
215
- test("falls back to later analyst providers when rating targets are missing", async () => {
216
- const cloudProvider: DataProvider = {
217
- ...fallbackProvider,
218
- id: "cloud",
219
- name: "Cloud",
220
- priority: 100,
221
- async getAnalystResearch(symbol) {
222
- return {
223
- providerId: "cloud",
224
- symbol,
225
- ratings: [{ date: "2026-05-01", firm: "Cloud Firm", action: "Raises", current: "Buy", prior: "Buy" }],
226
- recommendations: [],
227
- earningsEstimates: [],
228
- revenueEstimates: [],
229
- };
230
- },
231
- };
232
- const yahooProvider: DataProvider = {
233
- ...fallbackProvider,
234
- id: "yahoo",
235
- name: "Yahoo",
236
- priority: 1000,
237
- async getAnalystResearch(symbol) {
238
- return {
239
- providerId: "yahoo",
240
- symbol,
241
- ratings: [{
242
- date: "2026-05-01",
243
- firm: "Yahoo Firm",
244
- action: "Raises",
245
- current: "Buy",
246
- prior: "Buy",
247
- currentPriceTarget: 680,
248
- priorPriceTarget: 595,
249
- }],
250
- recommendations: [],
251
- earningsEstimates: [],
252
- revenueEstimates: [],
253
- };
254
- },
255
- };
256
-
257
- const router = new AssetDataRouter(yahooProvider, [cloudProvider]);
258
- const research = await router.getAnalystResearch("AAPL", "NASDAQ");
259
-
260
- expect(research.providerId).toBe("yahoo");
261
- expect(research.ratings[0]?.currentPriceTarget).toBe(680);
262
- expect(research.ratings[0]?.priorPriceTarget).toBe(595);
263
- });
264
-
265
- test("prefers cached analyst records with rating targets", async () => {
266
- const dbPath = createTempDbPath("cached-analyst-targets");
267
- const persistence = new AppPersistence(dbPath);
268
- const cloudProvider: DataProvider = {
269
- ...fallbackProvider,
270
- id: "cloud",
271
- name: "Cloud",
272
- priority: 100,
273
- async getAnalystResearch(symbol) {
274
- return {
275
- providerId: "cloud",
276
- symbol,
277
- ratings: [{ date: "2026-05-01", firm: "Cloud Firm", action: "Raises", current: "Buy", prior: "Buy" }],
278
- recommendations: [],
279
- earningsEstimates: [],
280
- revenueEstimates: [],
281
- };
282
- },
283
- };
284
- const yahooProvider: DataProvider = {
285
- ...fallbackProvider,
286
- id: "yahoo",
287
- name: "Yahoo",
288
- priority: 1000,
289
- async getAnalystResearch(symbol) {
290
- return {
291
- providerId: "yahoo",
292
- symbol,
293
- ratings: [{
294
- date: "2026-05-01",
295
- firm: "Yahoo Firm",
296
- action: "Raises",
297
- current: "Buy",
298
- prior: "Buy",
299
- currentPriceTarget: 680,
300
- priorPriceTarget: 595,
301
- }],
302
- recommendations: [],
303
- earningsEstimates: [],
304
- revenueEstimates: [],
305
- };
306
- },
307
- };
308
- const unavailableProvider = (id: string, priority: number): DataProvider => ({
309
- ...fallbackProvider,
310
- id,
311
- name: id,
312
- priority,
313
- async getAnalystResearch() {
314
- throw new Error(`${id} should not be fetched`);
315
- },
316
- });
317
-
318
- try {
319
- const seedRouter = new AssetDataRouter(yahooProvider, [cloudProvider], persistence.resources);
320
- await seedRouter.getAnalystResearch("AAPL", "NASDAQ");
321
-
322
- const cachedRouter = new AssetDataRouter(
323
- unavailableProvider("yahoo", 1000),
324
- [unavailableProvider("cloud", 100)],
325
- persistence.resources,
326
- );
327
- const research = await cachedRouter.getAnalystResearch("AAPL", "NASDAQ");
328
-
329
- expect(research.providerId).toBe("yahoo");
330
- expect(research.ratings[0]?.currentPriceTarget).toBe(680);
331
- expect(research.ratings[0]?.priorPriceTarget).toBe(595);
332
- } finally {
333
- persistence.close();
334
- }
335
- });
336
-
337
- test("prefers broker quotes over fallback quotes", async () => {
338
- const router = new AssetDataRouter(fallbackProvider);
339
- const broker: BrokerAdapter = {
340
- id: "ibkr",
341
- name: "IBKR",
342
- configSchema: [],
343
- async validate() {
344
- return true;
345
- },
346
- async importPositions() {
347
- return [];
348
- },
349
- async getQuote() {
350
- return {
351
- symbol: "AAPL",
352
- price: 123.45,
353
- currency: "USD",
354
- change: 1,
355
- changePercent: 0.8,
356
- lastUpdated: Date.now(),
357
- };
358
- },
359
- };
360
-
361
- router.attachRegistry({
362
- brokers: new Map([["ibkr", broker]]),
363
- getEnabledCapabilities: () => [],
364
- } as any);
365
- router.setConfigAccessor(() => ({
366
- dataDir: "",
367
- configVersion: CURRENT_CONFIG_VERSION,
368
- baseCurrency: "USD",
369
- refreshIntervalMinutes: 30,
370
- portfolios: [],
371
- watchlists: [],
372
- columns: [],
373
- layout: cloneLayout(DEFAULT_LAYOUT),
374
- layouts: [{ name: "Default", layout: cloneLayout(DEFAULT_LAYOUT) }],
375
- activeLayoutIndex: 0,
376
- brokerInstances: [{
377
- id: "ibkr-work",
378
- brokerType: "ibkr",
379
- label: "Work",
380
- connectionMode: "gateway",
381
- config: { connectionMode: "gateway", gateway: { host: "127.0.0.1", port: 4002, clientId: 1 } },
382
- enabled: true,
383
- }],
384
- plugins: [],
385
- disabledPlugins: [],
386
- theme: "amber",
387
- chartPreferences: {
388
- defaultRenderMode: "area",
389
- renderer: "auto",
390
- },
391
- recentTickers: [],
392
- }));
393
-
394
- const quote = await router.getQuote("AAPL", "NASDAQ", { brokerId: "ibkr", brokerInstanceId: "ibkr-work" });
395
- expect(quote.price).toBe(123.45);
396
- });
397
-
398
- test("falls back to provider quotes when a broker mark is stale", async () => {
399
- const fixedNow = Date.parse("2026-05-13T21:00:00Z");
400
- const realDateNow = Date.now;
401
- Date.now = () => fixedNow;
402
- try {
403
- const yahooProvider: DataProvider = {
404
- ...fallbackProvider,
405
- id: "yahoo",
406
- name: "Yahoo",
407
- async getQuote(symbol) {
408
- return {
409
- symbol,
410
- providerId: "yahoo",
411
- price: 50_500,
412
- currency: "JPY",
413
- change: 4400,
414
- changePercent: 9.54,
415
- lastUpdated: Date.parse("2026-05-13T06:24:00Z"),
416
- listingExchangeName: "JPX",
417
- marketState: "CLOSED",
418
- dataSource: "delayed",
419
- };
420
- },
421
- };
422
- const router = new AssetDataRouter(yahooProvider);
423
- const broker: BrokerAdapter = {
424
- id: "ibkr",
425
- name: "IBKR",
426
- configSchema: [],
427
- async validate() {
428
- return true;
429
- },
430
- async importPositions() {
431
- return [];
432
- },
433
- async getQuote() {
434
- return {
435
- symbol: "285A.T",
436
- providerId: "ibkr",
437
- price: 46_100,
438
- currency: "JPY",
439
- change: 0,
440
- changePercent: 0,
441
- lastUpdated: Date.parse("2026-05-08T06:00:00Z"),
442
- dataSource: "delayed",
443
- };
444
- },
445
- };
446
-
447
- router.attachRegistry({
448
- brokers: new Map([["ibkr", broker]]),
449
- getEnabledCapabilities: () => [],
450
- } as any);
451
- router.setConfigAccessor(() => ({
452
- dataDir: "",
453
- configVersion: CURRENT_CONFIG_VERSION,
454
- baseCurrency: "USD",
455
- refreshIntervalMinutes: 30,
456
- portfolios: [],
457
- watchlists: [],
458
- columns: [],
459
- layout: cloneLayout(DEFAULT_LAYOUT),
460
- layouts: [{ name: "Default", layout: cloneLayout(DEFAULT_LAYOUT) }],
461
- activeLayoutIndex: 0,
462
- brokerInstances: [{
463
- id: "ibkr-work",
464
- brokerType: "ibkr",
465
- label: "Work",
466
- connectionMode: "gateway",
467
- config: { connectionMode: "gateway", gateway: { host: "127.0.0.1", port: 4002, clientId: 1 } },
468
- enabled: true,
469
- }],
470
- plugins: [],
471
- disabledPlugins: [],
472
- theme: "amber",
473
- chartPreferences: {
474
- defaultRenderMode: "area",
475
- renderer: "auto",
476
- },
477
- recentTickers: [],
478
- }));
479
-
480
- const quote = await router.getQuote("285A.T", "TSEJ", { brokerId: "ibkr", brokerInstanceId: "ibkr-work" });
481
- expect(quote.providerId).toBe("yahoo");
482
- expect(quote.price).toBe(50_500);
483
- } finally {
484
- Date.now = realDateNow;
485
- }
486
- });
487
-
488
- test("prefers the requested broker instance in search results", async () => {
489
- const router = new AssetDataRouter(fallbackProvider);
490
- const broker: BrokerAdapter = {
491
- id: "ibkr",
492
- name: "IBKR",
493
- configSchema: [],
494
- async validate() {
495
- return true;
496
- },
497
- async importPositions() {
498
- return [];
499
- },
500
- async searchInstruments(_query, instance) {
501
- return [{
502
- providerId: "ibkr",
503
- symbol: instance.label === "Work" ? "AAPL" : "MSFT",
504
- name: `${instance.label} contract`,
505
- exchange: "NASDAQ",
506
- type: "STK",
507
- brokerContract: {
508
- brokerId: "ibkr",
509
- symbol: instance.label === "Work" ? "AAPL" : "MSFT",
510
- exchange: "SMART",
511
- },
512
- }];
513
- },
514
- };
515
-
516
- router.attachRegistry({
517
- brokers: new Map([["ibkr", broker]]),
518
- getEnabledCapabilities: () => [],
519
- } as any);
520
- router.setConfigAccessor(() => ({
521
- dataDir: "",
522
- configVersion: CURRENT_CONFIG_VERSION,
523
- baseCurrency: "USD",
524
- refreshIntervalMinutes: 30,
525
- portfolios: [],
526
- watchlists: [],
527
- columns: [],
528
- layout: cloneLayout(DEFAULT_LAYOUT),
529
- layouts: [{ name: "Default", layout: cloneLayout(DEFAULT_LAYOUT) }],
530
- activeLayoutIndex: 0,
531
- brokerInstances: [
532
- {
533
- id: "ibkr-work",
534
- brokerType: "ibkr",
535
- label: "Work",
536
- connectionMode: "gateway",
537
- config: { connectionMode: "gateway", gateway: { host: "127.0.0.1", port: 4002, clientId: 1 } },
538
- enabled: true,
539
- },
540
- {
541
- id: "ibkr-personal",
542
- brokerType: "ibkr",
543
- label: "Personal",
544
- connectionMode: "gateway",
545
- config: { connectionMode: "gateway", gateway: { host: "127.0.0.1", port: 4003, clientId: 2 } },
546
- enabled: true,
547
- },
548
- ],
549
- plugins: [],
550
- disabledPlugins: [],
551
- theme: "amber",
552
- chartPreferences: {
553
- defaultRenderMode: "area",
554
- renderer: "auto",
555
- },
556
- recentTickers: [],
557
- }));
558
-
559
- const results = await router.search("AAPL", { preferBroker: true, brokerInstanceId: "ibkr-work" });
560
- expect(results[0]?.brokerInstanceId).toBe("ibkr-work");
561
- expect(results[0]?.brokerLabel).toBe("Work");
562
- expect(results[0]?.brokerContract?.brokerInstanceId).toBe("ibkr-work");
563
- });
564
-
565
- test("keeps the richer search result when providers return the same instrument", async () => {
566
- const broker: BrokerAdapter = {
567
- id: "ibkr",
568
- name: "IBKR",
569
- configSchema: [],
570
- async validate() {
571
- return true;
572
- },
573
- async importPositions() {
574
- return [];
575
- },
576
- async searchInstruments() {
577
- return [{
578
- providerId: "ibkr",
579
- symbol: "AAPL",
580
- name: "Apple Inc",
581
- exchange: "NASDAQ",
582
- type: "STK",
583
- brokerLabel: "Work",
584
- brokerContract: {
585
- brokerId: "ibkr",
586
- brokerInstanceId: "ibkr-work",
587
- symbol: "AAPL",
588
- localSymbol: "AAPL",
589
- exchange: "SMART",
590
- },
591
- }];
592
- },
593
- };
594
- const provider: DataProvider = {
595
- ...fallbackProvider,
596
- id: "yahoo",
597
- name: "Yahoo",
598
- async search() {
599
- return [{
600
- providerId: "yahoo",
601
- symbol: "AAPL",
602
- name: "Apple",
603
- exchange: "NASDAQ",
604
- type: "STK",
605
- }];
606
- },
607
- };
608
- const router = new AssetDataRouter(fallbackProvider, [provider]);
609
-
610
- router.attachRegistry({
611
- brokers: new Map([["ibkr", broker]]),
612
- getEnabledCapabilities: () => [],
613
- } as any);
614
- router.setConfigAccessor(() => ({
615
- dataDir: "",
616
- configVersion: CURRENT_CONFIG_VERSION,
617
- baseCurrency: "USD",
618
- refreshIntervalMinutes: 30,
619
- portfolios: [],
620
- watchlists: [],
621
- columns: [],
622
- layout: cloneLayout(DEFAULT_LAYOUT),
623
- layouts: [{ name: "Default", layout: cloneLayout(DEFAULT_LAYOUT) }],
624
- activeLayoutIndex: 0,
625
- brokerInstances: [{
626
- id: "ibkr-work",
627
- brokerType: "ibkr",
628
- label: "Work",
629
- connectionMode: "gateway",
630
- config: { connectionMode: "gateway", gateway: { host: "127.0.0.1", port: 4002, clientId: 1 } },
631
- enabled: true,
632
- }],
633
- plugins: [],
634
- disabledPlugins: [],
635
- theme: "amber",
636
- chartPreferences: {
637
- defaultRenderMode: "area",
638
- renderer: "auto",
639
- },
640
- recentTickers: [],
641
- }));
642
-
643
- const results = await router.search("AAPL", { preferBroker: true, brokerInstanceId: "ibkr-work" });
644
- expect(results).toHaveLength(1);
645
- expect(results[0]?.providerId).toBe("ibkr");
646
- expect(results[0]?.brokerContract?.localSymbol).toBe("AAPL");
647
- });
648
-
649
- test("ignores disabled plugin sources when the registry filters them out", async () => {
650
- const router = new AssetDataRouter(fallbackProvider);
651
- router.attachRegistry({
652
- brokers: new Map(),
653
- getEnabledCapabilities: () => [],
654
- } as any);
655
-
656
- const quote = await router.getQuote("AAPL", "NASDAQ");
657
- expect(quote.price).toBe(100);
658
- expect(quote.providerId).toBeUndefined();
659
- });
660
-
661
- test("does not search fallback providers when the preferred provider returns results", async () => {
662
- let cloudCalls = 0;
663
- let yahooCalls = 0;
664
- const cloudProvider: DataProvider = {
665
- ...fallbackProvider,
666
- id: "cloud",
667
- name: "Cloud",
668
- priority: 100,
669
- async search() {
670
- cloudCalls += 1;
671
- return [{ providerId: "cloud", symbol: "SEC0", name: "iShares ETF", exchange: "XETRA", type: "ETF" }];
672
- },
673
- };
674
- const yahooProvider: DataProvider = {
675
- ...fallbackProvider,
676
- id: "yahoo",
677
- name: "Yahoo",
678
- priority: 1000,
679
- async search() {
680
- yahooCalls += 1;
681
- return [{ providerId: "yahoo", symbol: "SEC0", name: "iShares ETF", exchange: "XETRA", type: "ETF" }];
682
- },
683
- };
684
-
685
- const router = new AssetDataRouter(yahooProvider, [cloudProvider]);
686
- const results = await router.search("SEC0");
687
-
688
- expect(results[0]?.providerId).toBe("cloud");
689
- expect(cloudCalls).toBe(1);
690
- expect(yahooCalls).toBe(0);
691
- });
692
-
693
- test("routes through registered asset-data capabilities", async () => {
694
- const cloudProvider: DataProvider = {
695
- ...fallbackProvider,
696
- id: "cloud",
697
- name: "Cloud",
698
- priority: 10,
699
- async getQuote() {
700
- return {
701
- symbol: "AAPL",
702
- providerId: "cloud",
703
- price: 125,
704
- currency: "USD",
705
- change: 1,
706
- changePercent: 0.8,
707
- lastUpdated: Date.now(),
708
- };
709
- },
710
- };
711
- const router = new AssetDataRouter(fallbackProvider);
712
- router.attachRegistry({
713
- brokers: new Map(),
714
- getEnabledCapabilities: (kind?: string) => (
715
- kind === "asset-data" ? [assetDataProvider(cloudProvider)] : []
716
- ),
717
- } as any);
718
-
719
- const quote = await router.getQuote("AAPL", "NASDAQ");
720
- expect(quote.price).toBe(125);
721
- expect(quote.providerId).toBe("cloud");
722
- });
723
-
724
- test("falls back when the preferred provider returns a stale quote", async () => {
725
- const fixedNow = Date.parse("2026-05-13T21:00:00Z");
726
- const realDateNow = Date.now;
727
- Date.now = () => fixedNow;
728
- try {
729
- const yahooProvider: DataProvider = {
730
- ...fallbackProvider,
731
- id: "yahoo",
732
- name: "Yahoo",
733
- async getQuote(symbol) {
734
- return {
735
- symbol,
736
- providerId: "yahoo",
737
- price: 168,
738
- currency: "TWD",
739
- change: 1,
740
- changePercent: 0.6,
741
- lastUpdated: Date.parse("2026-05-13T05:30:00Z"),
742
- listingExchangeName: "TWSE",
743
- marketState: "CLOSED",
744
- dataSource: "delayed",
745
- };
746
- },
747
- };
748
- const cloudProvider: DataProvider = {
749
- ...fallbackProvider,
750
- id: "gloomberb-cloud",
751
- name: "Cloud",
752
- priority: 100,
753
- async getQuote(symbol) {
754
- return {
755
- symbol,
756
- providerId: "gloomberb-cloud",
757
- price: 150,
758
- currency: "TWD",
759
- change: 0,
760
- changePercent: 0,
761
- lastUpdated: Date.parse("2026-05-08T06:00:00Z"),
762
- listingExchangeName: "TWSE",
763
- marketState: "CLOSED",
764
- dataSource: "delayed",
765
- };
766
- },
767
- async getQuotesBatch(targets) {
768
- return targets.map((target) => ({
769
- target,
770
- quote: {
771
- symbol: target.symbol,
772
- providerId: "gloomberb-cloud",
773
- price: 150,
774
- currency: "TWD",
775
- change: 0,
776
- changePercent: 0,
777
- lastUpdated: Date.parse("2026-05-08T06:00:00Z"),
778
- listingExchangeName: "TWSE",
779
- marketState: "CLOSED",
780
- dataSource: "delayed",
781
- },
782
- }));
783
- },
784
- };
785
- const router = new AssetDataRouter(yahooProvider, [cloudProvider]);
786
-
787
- const quote = await router.getQuote("2337", "TWSE");
788
- expect(quote.providerId).toBe("yahoo");
789
- expect(quote.price).toBe(168);
790
-
791
- const [batch] = await router.getQuotesBatch([{ symbol: "2337", exchange: "TWSE" }], { forceRefresh: true });
792
- expect(batch?.quote?.providerId).toBe("yahoo");
793
- expect(batch?.quote?.price).toBe(168);
794
- } finally {
795
- Date.now = realDateNow;
796
- }
797
- });
798
-
799
- test("prefers provider quote streams when one is available", () => {
800
- const brokerTargets: QuoteSubscriptionTarget[] = [];
801
- const providerTargets: QuoteSubscriptionTarget[] = [];
802
- let brokerUnsubscribed = 0;
803
- let providerUnsubscribed = 0;
804
-
805
- const broker: BrokerAdapter = {
806
- id: "ibkr",
807
- name: "IBKR",
808
- configSchema: [],
809
- async validate() {
810
- return true;
811
- },
812
- async importPositions() {
813
- return [];
814
- },
815
- subscribeQuotes(_instance, targets, onQuote) {
816
- brokerTargets.push(...targets);
817
- onQuote(targets[0]!, {
818
- symbol: "AAPL",
819
- price: 123.45,
820
- currency: "USD",
821
- change: 1,
822
- changePercent: 0.8,
823
- lastUpdated: Date.now(),
824
- });
825
- return () => {
826
- brokerUnsubscribed += 1;
827
- };
828
- },
829
- };
830
- const streamingProvider: DataProvider = {
831
- ...fallbackProvider,
832
- id: "cloud",
833
- name: "Cloud",
834
- subscribeQuotes(targets, onQuote) {
835
- providerTargets.push(...targets);
836
- onQuote(targets[0]!, {
837
- symbol: "MSFT",
838
- price: 456.78,
839
- currency: "USD",
840
- change: 2,
841
- changePercent: 0.4,
842
- lastUpdated: Date.now(),
843
- });
844
- return () => {
845
- providerUnsubscribed += 1;
846
- };
847
- },
848
- };
849
-
850
- const router = new AssetDataRouter(fallbackProvider, [streamingProvider]);
851
- router.attachRegistry({
852
- brokers: new Map([["ibkr", broker]]),
853
- getEnabledCapabilities: () => [],
854
- } as any);
855
- router.setConfigAccessor(() => ({
856
- dataDir: "",
857
- configVersion: CURRENT_CONFIG_VERSION,
858
- baseCurrency: "USD",
859
- refreshIntervalMinutes: 30,
860
- portfolios: [],
861
- watchlists: [],
862
- columns: [],
863
- layout: cloneLayout(DEFAULT_LAYOUT),
864
- layouts: [{ name: "Default", layout: cloneLayout(DEFAULT_LAYOUT) }],
865
- activeLayoutIndex: 0,
866
- brokerInstances: [{
867
- id: "ibkr-work",
868
- brokerType: "ibkr",
869
- label: "Work",
870
- connectionMode: "gateway",
871
- config: {},
872
- enabled: true,
873
- }],
874
- plugins: [],
875
- disabledPlugins: [],
876
- theme: "amber",
877
- chartPreferences: {
878
- defaultRenderMode: "area",
879
- renderer: "auto",
880
- },
881
- recentTickers: [],
882
- }));
883
-
884
- const seenSymbols: string[] = [];
885
- const unsubscribe = router.subscribeQuotes([
886
- {
887
- symbol: "AAPL",
888
- exchange: "NASDAQ",
889
- context: {
890
- brokerId: "ibkr",
891
- brokerInstanceId: "ibkr-work",
892
- },
893
- },
894
- {
895
- symbol: "MSFT",
896
- exchange: "NASDAQ",
897
- },
898
- ], (target) => {
899
- seenSymbols.push(target.symbol);
900
- });
901
-
902
- expect(brokerTargets).toEqual([]);
903
- expect(providerTargets).toEqual([
904
- {
905
- symbol: "AAPL",
906
- exchange: "NASDAQ",
907
- context: {
908
- brokerId: "ibkr",
909
- brokerInstanceId: "ibkr-work",
910
- },
911
- },
912
- {
913
- symbol: "MSFT",
914
- exchange: "NASDAQ",
915
- },
916
- ]);
917
- expect(seenSymbols).toEqual(["AAPL"]);
918
-
919
- unsubscribe();
920
- expect(brokerUnsubscribed).toBe(0);
921
- expect(providerUnsubscribed).toBe(1);
922
- });
923
-
924
- test("can force broker-linked targets onto provider streaming", () => {
925
- const brokerTargets: QuoteSubscriptionTarget[] = [];
926
- const providerTargets: QuoteSubscriptionTarget[] = [];
927
-
928
- const broker: BrokerAdapter = {
929
- id: "ibkr",
930
- name: "IBKR",
931
- configSchema: [],
932
- async validate() {
933
- return true;
934
- },
935
- async importPositions() {
936
- return [];
937
- },
938
- subscribeQuotes(_instance, targets) {
939
- brokerTargets.push(...targets);
940
- return () => {};
941
- },
942
- };
943
- const streamingProvider: DataProvider = {
944
- ...fallbackProvider,
945
- id: "cloud",
946
- name: "Cloud",
947
- subscribeQuotes(targets) {
948
- providerTargets.push(...targets);
949
- return () => {};
950
- },
951
- };
952
-
953
- const router = new AssetDataRouter(fallbackProvider, [streamingProvider]);
954
- router.attachRegistry({
955
- brokers: new Map([["ibkr", broker]]),
956
- getEnabledCapabilities: () => [],
957
- } as any);
958
- router.setConfigAccessor(() => ({
959
- dataDir: "",
960
- configVersion: CURRENT_CONFIG_VERSION,
961
- baseCurrency: "USD",
962
- refreshIntervalMinutes: 30,
963
- portfolios: [],
964
- watchlists: [],
965
- columns: [],
966
- layout: cloneLayout(DEFAULT_LAYOUT),
967
- layouts: [{ name: "Default", layout: cloneLayout(DEFAULT_LAYOUT) }],
968
- activeLayoutIndex: 0,
969
- brokerInstances: [{
970
- id: "ibkr-work",
971
- brokerType: "ibkr",
972
- label: "Work",
973
- connectionMode: "gateway",
974
- config: {},
975
- enabled: true,
976
- }],
977
- plugins: [],
978
- disabledPlugins: [],
979
- theme: "amber",
980
- chartPreferences: {
981
- defaultRenderMode: "area",
982
- renderer: "auto",
983
- },
984
- recentTickers: [],
985
- }));
986
-
987
- const unsubscribe = router.subscribeQuotes([{
988
- symbol: "AAPL",
989
- exchange: "NASDAQ",
990
- route: "provider",
991
- context: {
992
- brokerId: "ibkr",
993
- brokerInstanceId: "ibkr-work",
994
- },
995
- }], () => {});
996
-
997
- expect(brokerTargets).toEqual([]);
998
- expect(providerTargets).toEqual([{
999
- symbol: "AAPL",
1000
- exchange: "NASDAQ",
1001
- route: "provider",
1002
- context: {
1003
- brokerId: "ibkr",
1004
- brokerInstanceId: "ibkr-work",
1005
- },
1006
- }]);
1007
-
1008
- unsubscribe();
1009
- });
1010
-
1011
- test("returns quote-only financials for option tickers when snapshots are unavailable", async () => {
1012
- const router = new AssetDataRouter({
1013
- ...fallbackProvider,
1014
- async getTickerFinancials() {
1015
- return { annualStatements: [], quarterlyStatements: [], priceHistory: [] };
1016
- },
1017
- async getQuote(ticker) {
1018
- return {
1019
- symbol: ticker,
1020
- price: 252.375,
1021
- currency: "USD",
1022
- change: 1.5,
1023
- changePercent: 0.6,
1024
- bid: 250.25,
1025
- ask: 254.5,
1026
- mark: 252.375,
1027
- lastUpdated: Date.now(),
1028
- providerId: "gloomberb-cloud",
1029
- dataSource: "delayed",
1030
- };
1031
- },
1032
- });
1033
-
1034
- const financials = await router.getTickerFinancials("AMD 270917C00230000");
1035
-
1036
- expect(financials.quote?.symbol).toBe("AMD 270917C00230000");
1037
- expect(financials.quote?.mark).toBe(252.375);
1038
- expect(financials.annualStatements).toEqual([]);
1039
- expect(financials.priceHistory).toEqual([]);
1040
- });
1041
-
1042
- test("merges cached broker financials with cached fallback fundamentals", async () => {
1043
- const dbPath = createTempDbPath("cache-merge");
1044
- const persistence = new AppPersistence(dbPath);
1045
- const providerCalls = { broker: 0, fallback: 0 };
1046
- const router = new AssetDataRouter({
1047
- ...fallbackProvider,
1048
- async getTickerFinancials() {
1049
- providerCalls.fallback += 1;
1050
- return {
1051
- annualStatements: [{ date: "2025-12-31", totalRevenue: 1000 }],
1052
- quarterlyStatements: [{ date: "2025-12-31", totalRevenue: 250 }],
1053
- priceHistory: [],
1054
- fundamentals: { revenue: 1000, netIncome: 200 },
1055
- };
1056
- },
1057
- }, [], persistence.resources);
1058
- const broker: BrokerAdapter = {
1059
- id: "ibkr",
1060
- name: "IBKR",
1061
- configSchema: [],
1062
- async validate() {
1063
- return true;
1064
- },
1065
- async importPositions() {
1066
- return [];
1067
- },
1068
- async getTickerFinancials() {
1069
- providerCalls.broker += 1;
1070
- return {
1071
- annualStatements: [],
1072
- quarterlyStatements: [],
1073
- priceHistory: [],
1074
- quote: {
1075
- symbol: "AAPL",
1076
- price: 125,
1077
- currency: "USD",
1078
- change: 2,
1079
- changePercent: 1.6,
1080
- lastUpdated: Date.now(),
1081
- },
1082
- fundamentals: {},
1083
- };
1084
- },
1085
- };
1086
-
1087
- router.attachRegistry({
1088
- brokers: new Map([["ibkr", broker]]),
1089
- getEnabledCapabilities: () => [],
1090
- } as any);
1091
- router.setConfigAccessor(() => ({
1092
- dataDir: "",
1093
- configVersion: CURRENT_CONFIG_VERSION,
1094
- baseCurrency: "USD",
1095
- refreshIntervalMinutes: 30,
1096
- portfolios: [],
1097
- watchlists: [],
1098
- columns: [],
1099
- layout: cloneLayout(DEFAULT_LAYOUT),
1100
- layouts: [{ name: "Default", layout: cloneLayout(DEFAULT_LAYOUT) }],
1101
- activeLayoutIndex: 0,
1102
- brokerInstances: [{
1103
- id: "ibkr-work",
1104
- brokerType: "ibkr",
1105
- label: "Work",
1106
- connectionMode: "gateway",
1107
- config: {},
1108
- enabled: true,
1109
- }],
1110
- plugins: [],
1111
- disabledPlugins: [],
1112
- theme: "amber",
1113
- chartPreferences: {
1114
- defaultRenderMode: "area",
1115
- renderer: "auto",
1116
- },
1117
- recentTickers: [],
1118
- }));
1119
-
1120
- const merged = await router.getTickerFinancials("AAPL", "NASDAQ", {
1121
- brokerId: "ibkr",
1122
- brokerInstanceId: "ibkr-work",
1123
- });
1124
- expect(merged.quote?.price).toBe(125);
1125
- expect(merged.fundamentals?.revenue).toBe(1000);
1126
- expect(providerCalls.broker).toBe(1);
1127
- expect(providerCalls.fallback).toBe(1);
1128
-
1129
- const cached = router.getCachedFinancialsForTargets([{
1130
- symbol: "AAPL",
1131
- exchange: "NASDAQ",
1132
- brokerId: "ibkr",
1133
- brokerInstanceId: "ibkr-work",
1134
- }], { allowExpired: true });
1135
- expect(cached.get("AAPL")?.quote?.price).toBe(125);
1136
- expect(cached.get("AAPL")?.fundamentals?.revenue).toBe(1000);
1137
- persistence.close();
1138
- });
1139
-
1140
- test("keeps broker price authority when a fallback quote is off by a likely 100x unit mismatch", async () => {
1141
- const router = new AssetDataRouter({
1142
- ...fallbackProvider,
1143
- async getTickerFinancials() {
1144
- return {
1145
- annualStatements: [],
1146
- quarterlyStatements: [],
1147
- priceHistory: [{ date: new Date("2026-03-28T00:00:00Z"), close: 0.245 }],
1148
- quote: {
1149
- symbol: "IQE.L",
1150
- providerId: "yahoo",
1151
- price: 0.245,
1152
- currency: "GBP",
1153
- change: -0.021,
1154
- changePercent: -7.89,
1155
- lastUpdated: Date.now(),
1156
- dataSource: "delayed",
1157
- },
1158
- fundamentals: { revenue: 1000 },
1159
- };
1160
- },
1161
- });
1162
- const broker: BrokerAdapter = {
1163
- id: "ibkr",
1164
- name: "IBKR",
1165
- configSchema: [],
1166
- async validate() {
1167
- return true;
1168
- },
1169
- async importPositions() {
1170
- return [];
1171
- },
1172
- async getTickerFinancials() {
1173
- return {
1174
- annualStatements: [],
1175
- quarterlyStatements: [],
1176
- priceHistory: [{ date: new Date("2026-03-28T00:00:00Z"), close: 24.5 }],
1177
- quote: {
1178
- symbol: "IQE",
1179
- providerId: "ibkr",
1180
- price: 24.5,
1181
- currency: "GBP",
1182
- change: -2.1,
1183
- changePercent: -7.89,
1184
- lastUpdated: Date.now(),
1185
- dataSource: "live",
1186
- },
1187
- fundamentals: { netIncome: 200 },
1188
- };
1189
- },
1190
- };
1191
-
1192
- router.attachRegistry({
1193
- brokers: new Map([["ibkr", broker]]),
1194
- getEnabledCapabilities: () => [],
1195
- } as any);
1196
- router.setConfigAccessor(() => ({
1197
- dataDir: "",
1198
- configVersion: CURRENT_CONFIG_VERSION,
1199
- baseCurrency: "USD",
1200
- refreshIntervalMinutes: 30,
1201
- portfolios: [],
1202
- watchlists: [],
1203
- columns: [],
1204
- layout: cloneLayout(DEFAULT_LAYOUT),
1205
- layouts: [{ name: "Default", layout: cloneLayout(DEFAULT_LAYOUT) }],
1206
- activeLayoutIndex: 0,
1207
- brokerInstances: [{
1208
- id: "ibkr-work",
1209
- brokerType: "ibkr",
1210
- label: "Work",
1211
- connectionMode: "gateway",
1212
- config: {},
1213
- enabled: true,
1214
- }],
1215
- plugins: [],
1216
- disabledPlugins: [],
1217
- theme: "amber",
1218
- chartPreferences: {
1219
- defaultRenderMode: "area",
1220
- renderer: "auto",
1221
- },
1222
- recentTickers: [],
1223
- }));
1224
-
1225
- const merged = await router.getTickerFinancials("IQE", "LSE", {
1226
- brokerId: "ibkr",
1227
- brokerInstanceId: "ibkr-work",
1228
- });
1229
-
1230
- expect(merged.quote?.price).toBe(24.5);
1231
- expect(merged.quote?.provenance?.rejectedPriceProviders).toContain("yahoo");
1232
- expect(merged.priceHistory[0]?.close).toBe(0.245);
1233
- expect(merged.fundamentals?.netIncome).toBe(200);
1234
- });
1235
-
1236
- test("preserves fallback profile data when broker already has fundamentals", async () => {
1237
- const router = new AssetDataRouter({
1238
- ...fallbackProvider,
1239
- async getTickerFinancials() {
1240
- return {
1241
- annualStatements: [],
1242
- quarterlyStatements: [],
1243
- priceHistory: [],
1244
- profile: {
1245
- description: "Builds hardware and software.",
1246
- sector: "Technology",
1247
- industry: "Consumer Electronics",
1248
- },
1249
- };
1250
- },
1251
- });
1252
- const broker: BrokerAdapter = {
1253
- id: "ibkr",
1254
- name: "IBKR",
1255
- configSchema: [],
1256
- async validate() {
1257
- return true;
1258
- },
1259
- async importPositions() {
1260
- return [];
1261
- },
1262
- async getTickerFinancials() {
1263
- return {
1264
- annualStatements: [],
1265
- quarterlyStatements: [],
1266
- priceHistory: [],
1267
- fundamentals: { revenue: 1000, netIncome: 200 },
1268
- };
1269
- },
1270
- };
1271
-
1272
- router.attachRegistry({
1273
- brokers: new Map([["ibkr", broker]]),
1274
- getEnabledCapabilities: () => [],
1275
- } as any);
1276
- router.setConfigAccessor(() => ({
1277
- dataDir: "",
1278
- configVersion: CURRENT_CONFIG_VERSION,
1279
- baseCurrency: "USD",
1280
- refreshIntervalMinutes: 30,
1281
- portfolios: [],
1282
- watchlists: [],
1283
- columns: [],
1284
- layout: cloneLayout(DEFAULT_LAYOUT),
1285
- layouts: [{ name: "Default", layout: cloneLayout(DEFAULT_LAYOUT) }],
1286
- activeLayoutIndex: 0,
1287
- brokerInstances: [{
1288
- id: "ibkr-work",
1289
- brokerType: "ibkr",
1290
- label: "Work",
1291
- connectionMode: "gateway",
1292
- config: {},
1293
- enabled: true,
1294
- }],
1295
- plugins: [],
1296
- disabledPlugins: [],
1297
- theme: "amber",
1298
- chartPreferences: {
1299
- defaultRenderMode: "area",
1300
- renderer: "auto",
1301
- },
1302
- recentTickers: [],
1303
- }));
1304
-
1305
- const merged = await router.getTickerFinancials("AAPL", "NASDAQ", {
1306
- brokerId: "ibkr",
1307
- brokerInstanceId: "ibkr-work",
1308
- });
1309
- expect(merged.fundamentals?.revenue).toBe(1000);
1310
- expect(merged.profile?.description).toBe("Builds hardware and software.");
1311
- expect(merged.profile?.sector).toBe("Technology");
1312
- });
1313
-
1314
- test("uses the preferred provider financials without merging fallback providers", async () => {
1315
- const cloudProvider: DataProvider = {
1316
- ...fallbackProvider,
1317
- id: "cloud",
1318
- name: "Cloud",
1319
- priority: 100,
1320
- async getTickerFinancials() {
1321
- return {
1322
- annualStatements: [],
1323
- quarterlyStatements: [],
1324
- priceHistory: [],
1325
- quote: {
1326
- symbol: "AAPL",
1327
- price: 125,
1328
- currency: "USD",
1329
- change: 2,
1330
- changePercent: 1.6,
1331
- lastUpdated: Date.now(),
1332
- },
1333
- fundamentals: {
1334
- trailingPE: 25,
1335
- },
1336
- };
1337
- },
1338
- };
1339
- let yahooCalls = 0;
1340
- const yahooProvider: DataProvider = {
1341
- ...fallbackProvider,
1342
- id: "yahoo",
1343
- name: "Yahoo",
1344
- priority: 1000,
1345
- async getTickerFinancials() {
1346
- yahooCalls += 1;
1347
- return {
1348
- annualStatements: [],
1349
- quarterlyStatements: [],
1350
- priceHistory: [{ date: new Date("2026-03-28T00:00:00Z"), close: 124 }],
1351
- quote: {
1352
- symbol: "AAPL",
1353
- price: 124,
1354
- currency: "USD",
1355
- change: 1,
1356
- changePercent: 0.8,
1357
- marketCap: 2_000_000_000,
1358
- lastUpdated: Date.now(),
1359
- },
1360
- fundamentals: {
1361
- forwardPE: 22,
1362
- },
1363
- };
1364
- },
1365
- };
1366
-
1367
- const router = new AssetDataRouter(yahooProvider, [cloudProvider]);
1368
- const merged = await router.getTickerFinancials("AAPL", "NASDAQ");
1369
-
1370
- expect(merged.quote?.price).toBe(125);
1371
- expect(merged.quote?.marketCap).toBeUndefined();
1372
- expect(merged.fundamentals?.trailingPE).toBe(25);
1373
- expect(merged.fundamentals?.forwardPE).toBeUndefined();
1374
- expect(merged.priceHistory).toEqual([]);
1375
- expect(yahooCalls).toBe(0);
1376
- });
1377
-
1378
- test("caches the preferred provider financial snapshot without merging fallback snapshots", async () => {
1379
- const dbPath = createTempDbPath("cached-provider-financial-preferred");
1380
- const persistence = new AppPersistence(dbPath);
1381
-
1382
- const cloudProvider: DataProvider = {
1383
- ...fallbackProvider,
1384
- id: "cloud",
1385
- name: "Cloud",
1386
- priority: 100,
1387
- async getTickerFinancials() {
1388
- return {
1389
- annualStatements: [],
1390
- quarterlyStatements: [],
1391
- priceHistory: [],
1392
- quote: {
1393
- symbol: "AAPL",
1394
- price: 125,
1395
- currency: "USD",
1396
- change: 2,
1397
- changePercent: 1.6,
1398
- lastUpdated: Date.now(),
1399
- },
1400
- fundamentals: {
1401
- trailingPE: 25,
1402
- },
1403
- profile: {
1404
- sector: "Technology",
1405
- },
1406
- };
1407
- },
1408
- };
1409
- const yahooProvider: DataProvider = {
1410
- ...fallbackProvider,
1411
- id: "yahoo",
1412
- name: "Yahoo",
1413
- priority: 1000,
1414
- async getTickerFinancials() {
1415
- return {
1416
- annualStatements: [],
1417
- quarterlyStatements: [],
1418
- priceHistory: [{ date: new Date("2026-03-28T00:00:00Z"), close: 124 }],
1419
- quote: {
1420
- symbol: "AAPL",
1421
- price: 124,
1422
- currency: "USD",
1423
- change: 1,
1424
- changePercent: 0.8,
1425
- marketCap: 2_000_000_000,
1426
- lastUpdated: Date.now(),
1427
- },
1428
- fundamentals: {
1429
- forwardPE: 22,
1430
- },
1431
- };
1432
- },
1433
- };
1434
-
1435
- const seedRouter = new AssetDataRouter(yahooProvider, [cloudProvider], persistence.resources);
1436
- const seeded = await seedRouter.getTickerFinancials("AAPL", "NASDAQ");
1437
- expect(seeded.quote?.price).toBe(125);
1438
- expect(seeded.quote?.marketCap).toBeUndefined();
1439
-
1440
- let cloudCalls = 0;
1441
- let yahooCalls = 0;
1442
- const cachedRouter = new AssetDataRouter({
1443
- ...yahooProvider,
1444
- async getTickerFinancials() {
1445
- yahooCalls += 1;
1446
- throw new Error("expected cached yahoo financials");
1447
- },
1448
- }, [{
1449
- ...cloudProvider,
1450
- async getTickerFinancials() {
1451
- cloudCalls += 1;
1452
- throw new Error("expected cached cloud financials");
1453
- },
1454
- }], persistence.resources);
1455
-
1456
- const cached = await cachedRouter.getTickerFinancials("AAPL", "NASDAQ");
1457
-
1458
- expect(cloudCalls).toBe(0);
1459
- expect(yahooCalls).toBe(0);
1460
- expect(cached.quote?.price).toBe(125);
1461
- expect(cached.quote?.marketCap).toBeUndefined();
1462
- expect(cached.fundamentals?.trailingPE).toBe(25);
1463
- expect(cached.fundamentals?.forwardPE).toBeUndefined();
1464
- expect(cached.profile?.sector).toBe("Technology");
1465
- expect(cached.priceHistory).toEqual([]);
1466
-
1467
- persistence.close();
1468
- });
1469
-
1470
- test("refreshes missing profile data even when cached financials exist", async () => {
1471
- const dbPath = createTempDbPath("cache-profile-refresh");
1472
- const persistence = new AppPersistence(dbPath);
1473
-
1474
- const broker: BrokerAdapter = {
1475
- id: "ibkr",
1476
- name: "IBKR",
1477
- configSchema: [],
1478
- async validate() {
1479
- return true;
1480
- },
1481
- async importPositions() {
1482
- return [];
1483
- },
1484
- async getTickerFinancials() {
1485
- return {
1486
- annualStatements: [],
1487
- quarterlyStatements: [],
1488
- priceHistory: [],
1489
- fundamentals: { revenue: 1000, netIncome: 200 },
1490
- };
1491
- },
1492
- };
1493
-
1494
- const config = {
1495
- dataDir: "",
1496
- configVersion: CURRENT_CONFIG_VERSION,
1497
- baseCurrency: "USD",
1498
- refreshIntervalMinutes: 30,
1499
- portfolios: [],
1500
- watchlists: [],
1501
- columns: [],
1502
- layout: cloneLayout(DEFAULT_LAYOUT),
1503
- layouts: [{ name: "Default", layout: cloneLayout(DEFAULT_LAYOUT) }],
1504
- activeLayoutIndex: 0,
1505
- brokerInstances: [{
1506
- id: "ibkr-work",
1507
- brokerType: "ibkr",
1508
- label: "Work",
1509
- connectionMode: "gateway",
1510
- config: {},
1511
- enabled: true,
1512
- }],
1513
- plugins: [],
1514
- disabledPlugins: [],
1515
- theme: "amber",
1516
- chartPreferences: {
1517
- defaultRenderMode: "area",
1518
- renderer: "auto",
1519
- },
1520
- recentTickers: [],
1521
- };
1522
-
1523
- const seedRouter = new AssetDataRouter({
1524
- ...fallbackProvider,
1525
- async getTickerFinancials() {
1526
- return {
1527
- annualStatements: [],
1528
- quarterlyStatements: [],
1529
- priceHistory: [],
1530
- };
1531
- },
1532
- }, [], persistence.resources);
1533
- seedRouter.attachRegistry({
1534
- brokers: new Map([["ibkr", broker]]),
1535
- getEnabledCapabilities: () => [],
1536
- } as any);
1537
- seedRouter.setConfigAccessor(() => config);
1538
-
1539
- const seeded = await seedRouter.getTickerFinancials("PSTG", "NYSE", {
1540
- brokerId: "ibkr",
1541
- brokerInstanceId: "ibkr-work",
1542
- });
1543
- expect(seeded.profile).toBeUndefined();
1544
-
1545
- const refreshedRouter = new AssetDataRouter({
1546
- ...fallbackProvider,
1547
- async getTickerFinancials() {
1548
- return {
1549
- annualStatements: [],
1550
- quarterlyStatements: [],
1551
- priceHistory: [],
1552
- profile: {
1553
- description: "Provides enterprise data storage platforms.",
1554
- sector: "Technology",
1555
- industry: "Computer Hardware",
1556
- },
1557
- };
1558
- },
1559
- }, [], persistence.resources);
1560
- refreshedRouter.attachRegistry({
1561
- brokers: new Map([["ibkr", broker]]),
1562
- getEnabledCapabilities: () => [],
1563
- } as any);
1564
- refreshedRouter.setConfigAccessor(() => config);
1565
-
1566
- const refreshed = await refreshedRouter.getTickerFinancials("PSTG", "NYSE", {
1567
- brokerId: "ibkr",
1568
- brokerInstanceId: "ibkr-work",
1569
- });
1570
- expect(refreshed.fundamentals?.revenue).toBe(1000);
1571
- expect(refreshed.profile?.description).toBe("Provides enterprise data storage platforms.");
1572
-
1573
- persistence.close();
1574
- });
1575
-
1576
- test("does not reuse another broker instance's financials when a specific instance is requested", async () => {
1577
- const dbPath = createTempDbPath("instance-scoped-financials");
1578
- const persistence = new AppPersistence(dbPath);
1579
- const router = new AssetDataRouter({
1580
- ...fallbackProvider,
1581
- async getTickerFinancials() {
1582
- return {
1583
- annualStatements: [],
1584
- quarterlyStatements: [],
1585
- priceHistory: [],
1586
- quote: {
1587
- symbol: "IQE.L",
1588
- providerId: "yahoo",
1589
- price: 0.245,
1590
- currency: "GBP",
1591
- change: 0,
1592
- changePercent: 0,
1593
- lastUpdated: Date.now(),
1594
- dataSource: "delayed",
1595
- },
1596
- };
1597
- },
1598
- }, [], persistence.resources);
1599
- const broker: BrokerAdapter = {
1600
- id: "ibkr",
1601
- name: "IBKR",
1602
- configSchema: [],
1603
- async validate() {
1604
- return true;
1605
- },
1606
- async importPositions() {
1607
- return [];
1608
- },
1609
- async getTickerFinancials(_ticker, instance) {
1610
- if (instance.id === "ibkr-flex") {
1611
- throw new Error("Gateway mode is required for broker market data");
1612
- }
1613
- return {
1614
- annualStatements: [],
1615
- quarterlyStatements: [],
1616
- priceHistory: [],
1617
- quote: {
1618
- symbol: "IQE",
1619
- providerId: "ibkr",
1620
- price: 24.5,
1621
- currency: "GBP",
1622
- change: 0,
1623
- changePercent: 0,
1624
- lastUpdated: Date.now(),
1625
- dataSource: "live",
1626
- },
1627
- };
1628
- },
1629
- };
1630
-
1631
- router.attachRegistry({
1632
- brokers: new Map([["ibkr", broker]]),
1633
- getEnabledCapabilities: () => [],
1634
- } as any);
1635
- router.setConfigAccessor(() => ({
1636
- dataDir: "",
1637
- configVersion: CURRENT_CONFIG_VERSION,
1638
- baseCurrency: "USD",
1639
- refreshIntervalMinutes: 30,
1640
- portfolios: [],
1641
- watchlists: [],
1642
- columns: [],
1643
- layout: cloneLayout(DEFAULT_LAYOUT),
1644
- layouts: [{ name: "Default", layout: cloneLayout(DEFAULT_LAYOUT) }],
1645
- activeLayoutIndex: 0,
1646
- brokerInstances: [
1647
- {
1648
- id: "ibkr-flex",
1649
- brokerType: "ibkr",
1650
- label: "Flex",
1651
- connectionMode: "flex",
1652
- config: {},
1653
- enabled: true,
1654
- },
1655
- {
1656
- id: "ibkr-live",
1657
- brokerType: "ibkr",
1658
- label: "Live",
1659
- connectionMode: "gateway",
1660
- config: {},
1661
- enabled: true,
1662
- },
1663
- ],
1664
- plugins: [],
1665
- disabledPlugins: [],
1666
- theme: "amber",
1667
- chartPreferences: {
1668
- defaultRenderMode: "area",
1669
- renderer: "auto",
1670
- },
1671
- recentTickers: [],
1672
- }));
1673
-
1674
- const live = await router.getTickerFinancials("IQE", "LSE", {
1675
- brokerId: "ibkr",
1676
- brokerInstanceId: "ibkr-live",
1677
- });
1678
- expect(live.quote?.price).toBe(24.5);
1679
-
1680
- const flex = await router.getTickerFinancials("IQE", "LSE", {
1681
- brokerId: "ibkr",
1682
- brokerInstanceId: "ibkr-flex",
1683
- });
1684
- expect(flex.quote?.price).toBe(0.245);
1685
-
1686
- const cached = router.getCachedFinancialsForTargets([{
1687
- symbol: "IQE",
1688
- exchange: "LSE",
1689
- brokerId: "ibkr",
1690
- brokerInstanceId: "ibkr-flex",
1691
- }], { allowExpired: true });
1692
- expect(cached.get("IQE")?.quote?.price).toBe(0.245);
1693
-
1694
- persistence.close();
1695
- });
1696
-
1697
- test("returns merged cached provider financials on cold start when sub-unit quotes exist", async () => {
1698
- const dbPath = createTempDbPath("cached-sub-unit-financials");
1699
- const persistence = new AppPersistence(dbPath);
1700
- const now = Date.now();
1701
-
1702
- persistence.resources.set(
1703
- {
1704
- namespace: "market",
1705
- kind: "financials",
1706
- entityKey: "contract:14075064",
1707
- variantKey: "exchange=LSE",
1708
- sourceKey: "provider:gloomberb-cloud",
1709
- },
1710
- {
1711
- annualStatements: [],
1712
- quarterlyStatements: [],
1713
- priceHistory: [],
1714
- quote: {
1715
- symbol: "IQE",
1716
- price: 23.1,
1717
- currency: "GBp",
1718
- change: -1.4,
1719
- changePercent: -5.71,
1720
- previousClose: 24.5,
1721
- lastUpdated: now,
1722
- dataSource: "delayed",
1723
- },
1724
- profile: {
1725
- description: "Cloud profile",
1726
- },
1727
- },
1728
- {
1729
- cachePolicy: { staleMs: 60_000, expireMs: 60_000 },
1730
- fetchedAt: now,
1731
- },
1732
- );
1733
- persistence.resources.set(
1734
- {
1735
- namespace: "market",
1736
- kind: "financials",
1737
- entityKey: "contract:14075064",
1738
- variantKey: "exchange=LSE",
1739
- sourceKey: "provider:yahoo",
1740
- },
1741
- {
1742
- annualStatements: [],
1743
- quarterlyStatements: [],
1744
- priceHistory: [],
1745
- quote: {
1746
- symbol: "IQE.L",
1747
- providerId: "yahoo",
1748
- price: 0.231,
1749
- currency: "GBP",
1750
- change: -0.014,
1751
- changePercent: -5.71,
1752
- previousClose: 0.245,
1753
- lastUpdated: now,
1754
- dataSource: "delayed",
1755
- },
1756
- fundamentals: {
1757
- revenue: 1000,
1758
- },
1759
- },
1760
- {
1761
- cachePolicy: { staleMs: 60_000, expireMs: 60_000 },
1762
- fetchedAt: now,
1763
- },
1764
- );
1765
-
1766
- const yahooProvider: DataProvider = {
1767
- ...fallbackProvider,
1768
- id: "yahoo",
1769
- name: "Yahoo",
1770
- priority: 200,
1771
- async getTickerFinancials() {
1772
- throw new Error("should not fetch yahoo financials");
1773
- },
1774
- };
1775
- const cloudProvider: DataProvider = {
1776
- ...fallbackProvider,
1777
- id: "gloomberb-cloud",
1778
- name: "Cloud",
1779
- priority: 100,
1780
- async getTickerFinancials() {
1781
- throw new Error("should not fetch cloud financials");
1782
- },
1783
- };
1784
- const router = new AssetDataRouter(yahooProvider, [cloudProvider], persistence.resources);
1785
-
1786
- const financials = await router.getTickerFinancials("IQE", "LSE", {
1787
- instrument: {
1788
- brokerId: "ibkr",
1789
- brokerInstanceId: "ibkr-personal",
1790
- conId: 14075064,
1791
- symbol: "IQE",
1792
- },
1793
- });
1794
-
1795
- expect(financials.quote?.price).toBe(0.231);
1796
- expect(financials.quote?.currency).toBe("GBP");
1797
- expect(financials.fundamentals?.revenue).toBe(1000);
1798
- expect(financials.profile?.description).toBe("Cloud profile");
1799
-
1800
- persistence.close();
1801
- });
1802
-
1803
- test("drops stale cached cloud quotes while preserving cached cloud fundamentals", () => {
1804
- const dbPath = createTempDbPath("stale-cloud-cached-financials");
1805
- const persistence = new AppPersistence(dbPath);
1806
- const now = Date.now();
1807
- const previousSession = now - 24 * 60 * 60_000;
1808
-
1809
- persistence.resources.set(
1810
- {
1811
- namespace: "market",
1812
- kind: "financials",
1813
- entityKey: "HY9H",
1814
- variantKey: "exchange=FWB2",
1815
- sourceKey: "provider:gloomberb-cloud",
1816
- },
1817
- {
1818
- annualStatements: [],
1819
- quarterlyStatements: [],
1820
- priceHistory: [],
1821
- quote: {
1822
- symbol: "HY9H",
1823
- price: 528,
1824
- currency: "EUR",
1825
- change: 28,
1826
- changePercent: 5.6,
1827
- lastUpdated: previousSession,
1828
- marketState: "REGULAR",
1829
- exchangeName: "FWB2",
1830
- listingExchangeName: "FWB2",
1831
- providerId: "gloomberb-cloud",
1832
- dataSource: "delayed",
1833
- },
1834
- fundamentals: {
1835
- revenue: 1234,
1836
- },
1837
- profile: {
1838
- description: "Cloud profile",
1839
- },
1840
- },
1841
- {
1842
- cachePolicy: { staleMs: 60_000, expireMs: 60_000 },
1843
- fetchedAt: now,
1844
- },
1845
- );
1846
- persistence.resources.set(
1847
- {
1848
- namespace: "market",
1849
- kind: "financials",
1850
- entityKey: "HY9H",
1851
- variantKey: "exchange=FWB2",
1852
- sourceKey: "provider:yahoo",
1853
- },
1854
- {
1855
- annualStatements: [],
1856
- quarterlyStatements: [],
1857
- priceHistory: [],
1858
- quote: {
1859
- symbol: "HY9H.F",
1860
- price: 596,
1861
- currency: "EUR",
1862
- change: 68,
1863
- changePercent: 12.88,
1864
- lastUpdated: now,
1865
- marketState: "REGULAR",
1866
- exchangeName: "FWB2",
1867
- listingExchangeName: "FWB2",
1868
- providerId: "yahoo",
1869
- dataSource: "delayed",
1870
- },
1871
- },
1872
- {
1873
- cachePolicy: { staleMs: 60_000, expireMs: 60_000 },
1874
- fetchedAt: now,
1875
- },
1876
- );
1877
-
1878
- const router = new AssetDataRouter({
1879
- ...fallbackProvider,
1880
- id: "yahoo",
1881
- name: "Yahoo",
1882
- async getTickerFinancials() {
1883
- throw new Error("should not fetch financials");
1884
- },
1885
- }, [{
1886
- ...fallbackProvider,
1887
- id: "gloomberb-cloud",
1888
- name: "Cloud",
1889
- priority: 100,
1890
- async getTickerFinancials() {
1891
- throw new Error("should not fetch financials");
1892
- },
1893
- }], persistence.resources);
1894
-
1895
- const cached = router.getCachedFinancialsForTargets([{
1896
- symbol: "HY9H",
1897
- exchange: "FWB2",
1898
- }], { allowExpired: true });
1899
-
1900
- expect(cached.get("HY9H")?.quote?.providerId).toBe("yahoo");
1901
- expect(cached.get("HY9H")?.quote?.price).toBe(596);
1902
- expect(cached.get("HY9H")?.fundamentals?.revenue).toBe(1234);
1903
- expect(cached.get("HY9H")?.profile?.description).toBe("Cloud profile");
1904
-
1905
- persistence.close();
1906
- });
1907
-
1908
- test("drops cached premarket cloud quotes that lack an active-session price", () => {
1909
- const dbPath = createTempDbPath("stale-cloud-premarket-cache");
1910
- const persistence = new AppPersistence(dbPath);
1911
- const now = Date.now();
1912
-
1913
- persistence.resources.set(
1914
- {
1915
- namespace: "market",
1916
- kind: "financials",
1917
- entityKey: "AMD",
1918
- variantKey: "exchange=NASDAQ",
1919
- sourceKey: "provider:gloomberb-cloud",
1920
- },
1921
- {
1922
- annualStatements: [],
1923
- quarterlyStatements: [],
1924
- priceHistory: [],
1925
- quote: {
1926
- symbol: "AMD",
1927
- price: 221.53,
1928
- currency: "USD",
1929
- change: 1.35,
1930
- changePercent: 0.61,
1931
- lastUpdated: now,
1932
- marketState: "PRE",
1933
- exchangeName: "NASDAQ",
1934
- listingExchangeName: "NASDAQ",
1935
- providerId: "gloomberb-cloud",
1936
- dataSource: "delayed",
1937
- },
1938
- },
1939
- {
1940
- cachePolicy: { staleMs: 60_000, expireMs: 60_000 },
1941
- fetchedAt: now,
1942
- },
1943
- );
1944
- persistence.resources.set(
1945
- {
1946
- namespace: "market",
1947
- kind: "financials",
1948
- entityKey: "AMD",
1949
- variantKey: "exchange=NASDAQ",
1950
- sourceKey: "provider:yahoo",
1951
- },
1952
- {
1953
- annualStatements: [],
1954
- quarterlyStatements: [],
1955
- priceHistory: [],
1956
- quote: {
1957
- symbol: "AMD",
1958
- price: 221.53,
1959
- currency: "USD",
1960
- change: 1.35,
1961
- changePercent: 0.61,
1962
- lastUpdated: now,
1963
- marketState: "PRE",
1964
- preMarketPrice: 231,
1965
- preMarketChange: 9.47,
1966
- preMarketChangePercent: 4.27,
1967
- exchangeName: "NASDAQ",
1968
- listingExchangeName: "NASDAQ",
1969
- providerId: "yahoo",
1970
- dataSource: "delayed",
1971
- },
1972
- },
1973
- {
1974
- cachePolicy: { staleMs: 60_000, expireMs: 60_000 },
1975
- fetchedAt: now,
1976
- },
1977
- );
1978
-
1979
- const router = new AssetDataRouter({
1980
- ...fallbackProvider,
1981
- id: "yahoo",
1982
- name: "Yahoo",
1983
- async getTickerFinancials() {
1984
- throw new Error("should not fetch financials");
1985
- },
1986
- }, [{
1987
- ...fallbackProvider,
1988
- id: "gloomberb-cloud",
1989
- name: "Cloud",
1990
- priority: 100,
1991
- async getTickerFinancials() {
1992
- throw new Error("should not fetch financials");
1993
- },
1994
- }], persistence.resources);
1995
-
1996
- const cached = router.getCachedFinancialsForTargets([{
1997
- symbol: "AMD",
1998
- exchange: "NASDAQ",
1999
- }], { allowExpired: true });
2000
-
2001
- expect(cached.get("AMD")?.quote?.providerId).toBe("yahoo");
2002
- expect(cached.get("AMD")?.quote?.preMarketPrice).toBe(231);
2003
-
2004
- persistence.close();
2005
- });
2006
-
2007
- test("keeps stale cached quotes only for startup cache priming", () => {
2008
- const dbPath = createTempDbPath("startup-stale-quote-prime");
2009
- const persistence = new AppPersistence(dbPath);
2010
- const now = Date.now();
2011
-
2012
- persistence.resources.set(
2013
- {
2014
- namespace: "market",
2015
- kind: "financials",
2016
- entityKey: "OLD",
2017
- variantKey: "exchange=NASDAQ",
2018
- sourceKey: "provider:gloomberb-cloud",
2019
- },
2020
- {
2021
- annualStatements: [],
2022
- quarterlyStatements: [],
2023
- priceHistory: [],
2024
- quote: {
2025
- symbol: "OLD",
2026
- price: 42,
2027
- currency: "USD",
2028
- change: -1,
2029
- changePercent: -2.33,
2030
- lastUpdated: Date.UTC(2020, 0, 2),
2031
- marketState: "REGULAR",
2032
- exchangeName: "NASDAQ",
2033
- listingExchangeName: "NASDAQ",
2034
- providerId: "gloomberb-cloud",
2035
- dataSource: "delayed",
2036
- },
2037
- fundamentals: {
2038
- trailingPE: 12,
2039
- },
2040
- },
2041
- {
2042
- cachePolicy: { staleMs: 60_000, expireMs: 60_000 },
2043
- fetchedAt: now,
2044
- },
2045
- );
2046
-
2047
- const router = new AssetDataRouter({
2048
- ...fallbackProvider,
2049
- id: "gloomberb-cloud",
2050
- name: "Cloud",
2051
- async getTickerFinancials() {
2052
- throw new Error("should not fetch financials");
2053
- },
2054
- }, [], persistence.resources);
2055
-
2056
- const normal = router.getCachedFinancialsForTargets([{ symbol: "OLD", exchange: "NASDAQ" }], { allowExpired: true });
2057
- expect(normal.get("OLD")?.quote).toBeUndefined();
2058
- expect(normal.get("OLD")?.fundamentals?.trailingPE).toBe(12);
2059
-
2060
- const startup = router.getCachedFinancialsForTargets(
2061
- [{ symbol: "OLD", exchange: "NASDAQ" }],
2062
- { allowExpired: true, includeStaleQuotes: true },
2063
- );
2064
- expect(startup.get("OLD")?.quote?.changePercent).toBe(-2.33);
2065
- expect(startup.get("OLD")?.fundamentals?.trailingPE).toBe(12);
2066
-
2067
- persistence.close();
2068
- });
2069
-
2070
- test("derives cached market cap from quote price and shares outstanding", () => {
2071
- const dbPath = createTempDbPath("cached-derived-market-cap");
2072
- const persistence = new AppPersistence(dbPath);
2073
- const now = Date.now();
2074
-
2075
- persistence.resources.set(
2076
- {
2077
- namespace: "market",
2078
- kind: "financials",
2079
- entityKey: "AMD",
2080
- variantKey: "exchange=NASDAQ",
2081
- sourceKey: "provider:gloomberb-cloud",
2082
- },
2083
- {
2084
- annualStatements: [],
2085
- quarterlyStatements: [],
2086
- priceHistory: [],
2087
- quote: {
2088
- symbol: "AMD",
2089
- price: 445.38,
2090
- currency: "USD",
2091
- change: -2.91,
2092
- changePercent: -0.65,
2093
- lastUpdated: now,
2094
- marketState: "REGULAR",
2095
- exchangeName: "NASDAQ",
2096
- listingExchangeName: "NASDAQ",
2097
- providerId: "gloomberb-cloud",
2098
- dataSource: "delayed",
2099
- },
2100
- fundamentals: {
2101
- sharesOutstanding: 1_630_000_000,
2102
- },
2103
- },
2104
- {
2105
- cachePolicy: { staleMs: 60_000, expireMs: 60_000 },
2106
- fetchedAt: now,
2107
- },
2108
- );
2109
-
2110
- const router = new AssetDataRouter({
2111
- ...fallbackProvider,
2112
- id: "gloomberb-cloud",
2113
- name: "Cloud",
2114
- async getTickerFinancials() {
2115
- throw new Error("should not fetch financials");
2116
- },
2117
- }, [], persistence.resources);
2118
-
2119
- const cached = router.getCachedFinancialsForTargets([{ symbol: "AMD", exchange: "NASDAQ" }], {
2120
- allowExpired: true,
2121
- includeStaleQuotes: true,
2122
- });
2123
- expect(cached.get("AMD")?.quote?.marketCap).toBeCloseTo(725_969_400_000);
2124
-
2125
- persistence.close();
2126
- });
2127
-
2128
- test("uses symbol provider cache for broker-linked startup targets", () => {
2129
- const dbPath = createTempDbPath("cached-symbol-fallback-for-contract");
2130
- const persistence = new AppPersistence(dbPath);
2131
- const now = Date.now();
2132
- const old = now - 3 * 24 * 60 * 60_000;
2133
-
2134
- persistence.resources.set(
2135
- {
2136
- namespace: "market",
2137
- kind: "financials",
2138
- entityKey: "contract:14015423",
2139
- variantKey: "exchange=JPX",
2140
- sourceKey: "provider:yahoo",
2141
- },
2142
- {
2143
- annualStatements: [],
2144
- quarterlyStatements: [],
2145
- priceHistory: [],
2146
- quote: {
2147
- symbol: "4092.T",
2148
- providerId: "yahoo",
2149
- price: 3770,
2150
- currency: "JPY",
2151
- change: 145,
2152
- changePercent: 4,
2153
- lastUpdated: old,
2154
- marketState: "CLOSED",
2155
- exchangeName: "JPX",
2156
- listingExchangeName: "JPX",
2157
- },
2158
- },
2159
- {
2160
- cachePolicy: { staleMs: 60_000, expireMs: 7 * 24 * 60 * 60_000 },
2161
- fetchedAt: old,
2162
- },
2163
- );
2164
- persistence.resources.set(
2165
- {
2166
- namespace: "market",
2167
- kind: "financials",
2168
- entityKey: "4092.T",
2169
- variantKey: "exchange=JPX",
2170
- sourceKey: "provider:yahoo",
2171
- },
2172
- {
2173
- annualStatements: [],
2174
- quarterlyStatements: [],
2175
- priceHistory: [],
2176
- quote: {
2177
- symbol: "4092.T",
2178
- providerId: "yahoo",
2179
- price: 3925,
2180
- currency: "JPY",
2181
- change: 20,
2182
- changePercent: 0.51,
2183
- lastUpdated: now,
2184
- marketState: "CLOSED",
2185
- exchangeName: "JPX",
2186
- listingExchangeName: "JPX",
2187
- },
2188
- },
2189
- {
2190
- cachePolicy: { staleMs: 60_000, expireMs: 7 * 24 * 60 * 60_000 },
2191
- fetchedAt: now,
2192
- },
2193
- );
2194
-
2195
- const router = new AssetDataRouter({
2196
- ...fallbackProvider,
2197
- id: "yahoo",
2198
- name: "Yahoo",
2199
- async getTickerFinancials() {
2200
- throw new Error("should not fetch financials");
2201
- },
2202
- }, [], persistence.resources);
2203
-
2204
- const cached = router.getCachedFinancialsForTargets([{
2205
- symbol: "4092.T",
2206
- exchange: "JPX",
2207
- instrument: {
2208
- brokerId: "ibkr",
2209
- brokerInstanceId: "ibkr-live",
2210
- conId: 14015423,
2211
- symbol: "4092.T",
2212
- },
2213
- }], { allowExpired: true, includeStaleQuotes: true });
2214
-
2215
- expect(cached.get("4092.T")?.quote?.price).toBe(3925);
2216
- expect(cached.get("4092.T")?.quote?.changePercent).toBe(0.51);
2217
-
2218
- persistence.close();
2219
- });
2220
-
2221
- test("overlays standalone quote cache on stale financial snapshots during startup priming", () => {
2222
- const dbPath = createTempDbPath("cached-quote-over-financial-snapshot");
2223
- const persistence = new AppPersistence(dbPath);
2224
- const now = Date.parse("2026-05-13T21:00:00Z");
2225
- const old = Date.parse("2026-05-09T14:13:30Z");
2226
-
2227
- persistence.resources.set(
2228
- {
2229
- namespace: "market",
2230
- kind: "financials",
2231
- entityKey: "contract:14016494",
2232
- variantKey: "exchange=JPX",
2233
- sourceKey: "provider:yahoo",
2234
- },
2235
- {
2236
- annualStatements: [],
2237
- quarterlyStatements: [],
2238
- priceHistory: [],
2239
- quote: {
2240
- symbol: "6315.T",
2241
- providerId: "yahoo",
2242
- price: 3380,
2243
- currency: "JPY",
2244
- change: 75,
2245
- changePercent: 2.27,
2246
- lastUpdated: old,
2247
- marketState: "CLOSED",
2248
- exchangeName: "JPX",
2249
- listingExchangeName: "JPX",
2250
- },
2251
- fundamentals: {
2252
- sharesOutstanding: 75_000_462,
2253
- trailingPE: 37.2,
2254
- },
2255
- },
2256
- {
2257
- cachePolicy: { staleMs: 60_000, expireMs: 7 * 24 * 60 * 60_000 },
2258
- fetchedAt: old,
2259
- },
2260
- );
2261
- persistence.resources.set(
2262
- {
2263
- namespace: "market",
2264
- kind: "quote",
2265
- entityKey: "contract:14016494",
2266
- variantKey: "exchange=JPX",
2267
- sourceKey: "provider:yahoo",
2268
- },
2269
- {
2270
- symbol: "6315.T",
2271
- providerId: "yahoo",
2272
- price: 2688,
2273
- currency: "JPY",
2274
- change: 13,
2275
- changePercent: 0.49,
2276
- lastUpdated: now,
2277
- marketState: "CLOSED",
2278
- exchangeName: "JPX",
2279
- listingExchangeName: "JPX",
2280
- },
2281
- {
2282
- cachePolicy: { staleMs: 60_000, expireMs: 7 * 24 * 60 * 60_000 },
2283
- fetchedAt: now,
2284
- },
2285
- );
2286
-
2287
- const router = new AssetDataRouter({
2288
- ...fallbackProvider,
2289
- id: "yahoo",
2290
- name: "Yahoo",
2291
- async getTickerFinancials() {
2292
- throw new Error("should not fetch financials");
2293
- },
2294
- }, [], persistence.resources);
2295
-
2296
- const cached = router.getCachedFinancialsForTargets([{
2297
- symbol: "6315.T",
2298
- exchange: "JPX",
2299
- instrument: {
2300
- brokerId: "ibkr",
2301
- brokerInstanceId: "ibkr-live",
2302
- conId: 14016494,
2303
- symbol: "6315.T",
2304
- },
2305
- }], { allowExpired: true, includeStaleQuotes: true });
2306
-
2307
- expect(cached.get("6315.T")?.quote?.price).toBe(2688);
2308
- expect(cached.get("6315.T")?.quote?.changePercent).toBe(0.49);
2309
- expect(cached.get("6315.T")?.quote?.marketCap).toBe(201_601_241_856);
2310
- expect(cached.get("6315.T")?.fundamentals?.trailingPE).toBe(37.2);
2311
-
2312
- persistence.close();
2313
- });
2314
-
2315
- test("does not log expected provider misses for missing chart data", async () => {
2316
- const noisyProvider: DataProvider = {
2317
- ...fallbackProvider,
2318
- id: "yahoo",
2319
- name: "Yahoo",
2320
- async getPriceHistory() {
2321
- throw new Error('[404] {"chart":{"result":null,"error":{"code":"Not Found","description":"No data found, symbol may be delisted"}}}');
2322
- },
2323
- };
2324
- const router = new AssetDataRouter(fallbackProvider, [noisyProvider]);
2325
- const logged: unknown[][] = [];
2326
- console.error = (...args: unknown[]) => {
2327
- logged.push(args);
2328
- };
2329
-
2330
- const history = await router.getPriceHistory("BAD", "NASDAQ", "1Y");
2331
-
2332
- expect(history).toEqual([]);
2333
- expect(logged).toHaveLength(0);
2334
- });
2335
-
2336
- test("falls back to later providers when the preferred chart source is empty", async () => {
2337
- const dbPath = createTempDbPath("chart-fallback");
2338
- const persistence = new AppPersistence(dbPath);
2339
-
2340
- const cloudProvider: DataProvider = {
2341
- ...fallbackProvider,
2342
- id: "cloud",
2343
- name: "Cloud",
2344
- priority: 100,
2345
- async getPriceHistory() {
2346
- return [];
2347
- },
2348
- };
2349
- const yahooProvider: DataProvider = {
2350
- ...fallbackProvider,
2351
- id: "yahoo",
2352
- name: "Yahoo",
2353
- priority: 1000,
2354
- async getPriceHistory() {
2355
- return [{ date: new Date("2026-03-28T00:00:00Z"), close: 101 }];
2356
- },
2357
- };
2358
-
2359
- const seedRouter = new AssetDataRouter(yahooProvider, [cloudProvider], persistence.resources);
2360
- const seeded = await seedRouter.getPriceHistory("AAPL", "NASDAQ", "1Y");
2361
- expect(seeded[0]?.close).toBe(101);
2362
-
2363
- const cachedRouter = new AssetDataRouter(yahooProvider, [cloudProvider], persistence.resources);
2364
- const cached = await cachedRouter.getPriceHistory("AAPL", "NASDAQ", "1Y");
2365
- expect(cached[0]?.close).toBe(101);
2366
-
2367
- persistence.close();
2368
- });
2369
-
2370
- test("sorts reversed chart history into chronological order", async () => {
2371
- const router = new AssetDataRouter({
2372
- ...fallbackProvider,
2373
- id: "cloud",
2374
- name: "Cloud",
2375
- async getPriceHistory() {
2376
- return [
2377
- { date: new Date("2026-03-29T00:00:00Z"), close: 103 },
2378
- { date: new Date("2026-03-27T00:00:00Z"), close: 101 },
2379
- { date: new Date("2026-03-28T00:00:00Z"), close: 102 },
2380
- ];
2381
- },
2382
- });
2383
-
2384
- const history = await router.getPriceHistory("AAPL", "NASDAQ", "1Y");
2385
-
2386
- expect(history.map((point) => point.close)).toEqual([101, 102, 103]);
2387
- });
2388
-
2389
- test("ignores poisoned cached chart history and refetches clean data", async () => {
2390
- const dbPath = createTempDbPath("poisoned-chart-cache");
2391
- const persistence = new AppPersistence(dbPath);
2392
-
2393
- persistence.resources.set(
2394
- {
2395
- namespace: "market",
2396
- kind: "price-history",
2397
- entityKey: "AAPL",
2398
- variantKey: "exchange=NASDAQ;range=1Y",
2399
- sourceKey: "provider:yahoo",
2400
- },
2401
- [
2402
- { date: null as any, close: 101 },
2403
- { date: null as any, close: 102 },
2404
- ],
2405
- {
2406
- cachePolicy: { staleMs: 60_000, expireMs: 60_000 },
2407
- },
2408
- );
2409
-
2410
- let providerCalls = 0;
2411
- const router = new AssetDataRouter({
2412
- ...fallbackProvider,
2413
- id: "yahoo",
2414
- name: "Yahoo",
2415
- async getPriceHistory() {
2416
- providerCalls += 1;
2417
- return [
2418
- { date: new Date("2026-03-27T00:00:00Z"), close: 201 },
2419
- { date: new Date("2026-03-28T00:00:00Z"), close: 202 },
2420
- ];
2421
- },
2422
- }, [], persistence.resources);
2423
-
2424
- const history = await router.getPriceHistory("AAPL", "NASDAQ", "1Y");
2425
-
2426
- expect(providerCalls).toBe(1);
2427
- expect(history.map((point) => point.close)).toEqual([201, 202]);
2428
-
2429
- persistence.close();
2430
- });
2431
-
2432
- test("bypasses cached financials on explicit refresh requests", async () => {
2433
- const dbPath = createTempDbPath("forced-financial-refresh");
2434
- const persistence = new AppPersistence(dbPath);
2435
-
2436
- const seedRouter = new AssetDataRouter({
2437
- ...fallbackProvider,
2438
- async getTickerFinancials() {
2439
- return {
2440
- annualStatements: [],
2441
- quarterlyStatements: [],
2442
- priceHistory: [{ date: new Date("2026-03-27T00:00:00Z"), close: 101 }],
2443
- quote: {
2444
- symbol: "AAPL",
2445
- price: 101,
2446
- currency: "USD",
2447
- change: 1,
2448
- changePercent: 1,
2449
- lastUpdated: Date.now(),
2450
- },
2451
- };
2452
- },
2453
- }, [], persistence.resources);
2454
- await seedRouter.getTickerFinancials("AAPL", "NASDAQ");
2455
-
2456
- let providerCalls = 0;
2457
- const refreshRouter = new AssetDataRouter({
2458
- ...fallbackProvider,
2459
- async getTickerFinancials() {
2460
- providerCalls += 1;
2461
- return {
2462
- annualStatements: [],
2463
- quarterlyStatements: [],
2464
- priceHistory: [{ date: new Date("2026-03-28T00:00:00Z"), close: 202 }],
2465
- quote: {
2466
- symbol: "AAPL",
2467
- price: 202,
2468
- currency: "USD",
2469
- change: 2,
2470
- changePercent: 1,
2471
- lastUpdated: Date.now(),
2472
- },
2473
- };
2474
- },
2475
- }, [], persistence.resources);
2476
-
2477
- const refreshed = await refreshRouter.getTickerFinancials("AAPL", "NASDAQ", { cacheMode: "refresh" });
2478
-
2479
- expect(providerCalls).toBe(1);
2480
- expect(refreshed.quote?.price).toBe(202);
2481
- expect(refreshed.priceHistory[0]?.close).toBe(202);
2482
-
2483
- persistence.close();
2484
- });
2485
-
2486
- test("refreshes stale cached chart history before falling back to cache", async () => {
2487
- const dbPath = createTempDbPath("stale-chart-refresh");
2488
- const persistence = new AppPersistence(dbPath);
2489
-
2490
- const seedRouter = new AssetDataRouter({
2491
- ...fallbackProvider,
2492
- async getPriceHistory() {
2493
- return [{ date: new Date("2026-03-27T00:00:00Z"), close: 101 }];
2494
- },
2495
- }, [], persistence.resources);
2496
- await seedRouter.getPriceHistory("AAPL", "NASDAQ", "1Y");
2497
-
2498
- persistence.database.connection
2499
- .query("UPDATE resource_cache SET stale_at = ? WHERE namespace = ? AND kind = ? AND entity_key = ?")
2500
- .run(Date.now() - 1, "market", "price-history", "AAPL");
2501
-
2502
- let providerCalls = 0;
2503
- const refreshRouter = new AssetDataRouter({
2504
- ...fallbackProvider,
2505
- async getPriceHistory() {
2506
- providerCalls += 1;
2507
- return [{ date: new Date("2026-03-28T00:00:00Z"), close: 202 }];
2508
- },
2509
- }, [], persistence.resources);
2510
-
2511
- const history = await refreshRouter.getPriceHistory("AAPL", "NASDAQ", "1Y");
2512
-
2513
- expect(providerCalls).toBe(1);
2514
- expect(history[0]?.close).toBe(202);
2515
-
2516
- persistence.close();
2517
- });
2518
-
2519
- test("falls back to later providers for fixed-resolution chart history", async () => {
2520
- const cloudProvider: DataProvider = {
2521
- ...fallbackProvider,
2522
- id: "cloud",
2523
- name: "Cloud",
2524
- priority: 100,
2525
- async getPriceHistoryForResolution() {
2526
- return [];
2527
- },
2528
- };
2529
- const yahooProvider: DataProvider = {
2530
- ...fallbackProvider,
2531
- id: "yahoo",
2532
- name: "Yahoo",
2533
- priority: 1000,
2534
- async getPriceHistoryForResolution() {
2535
- return [{ date: new Date("2026-03-28T00:00:00Z"), close: 102 }];
2536
- },
2537
- };
2538
-
2539
- const router = new AssetDataRouter(yahooProvider, [cloudProvider]);
2540
- const history = await router.getPriceHistoryForResolution("AAPL", "NASDAQ", "1Y", "1d");
2541
-
2542
- expect(history[0]?.close).toBe(102);
2543
- });
2544
-
2545
- test("returns normalized manual chart resolution capabilities", async () => {
2546
- const cloudProvider: DataProvider = {
2547
- ...fallbackProvider,
2548
- id: "cloud",
2549
- name: "Cloud",
2550
- priority: 100,
2551
- async getChartResolutionCapabilities() {
2552
- return [];
2553
- },
2554
- };
2555
- const yahooProvider: DataProvider = {
2556
- ...fallbackProvider,
2557
- id: "yahoo",
2558
- name: "Yahoo",
2559
- priority: 1000,
2560
- async getChartResolutionCapabilities() {
2561
- return ["1wk", "auto", "1d", "bogus"];
2562
- },
2563
- };
2564
-
2565
- const router = new AssetDataRouter(yahooProvider, [cloudProvider]);
2566
- expect(await router.getChartResolutionCapabilities("AAPL", "NASDAQ")).toEqual(["1d", "1wk"]);
2567
- });
2568
-
2569
- test("falls back to later providers when detailed chart history is empty", async () => {
2570
- const cloudProvider: DataProvider = {
2571
- ...fallbackProvider,
2572
- id: "cloud",
2573
- name: "Cloud",
2574
- priority: 100,
2575
- async getDetailedPriceHistory() {
2576
- return [];
2577
- },
2578
- };
2579
- const yahooProvider: DataProvider = {
2580
- ...fallbackProvider,
2581
- id: "yahoo",
2582
- name: "Yahoo",
2583
- priority: 1000,
2584
- async getDetailedPriceHistory() {
2585
- return [{ date: new Date("2026-03-28T10:00:00Z"), close: 102 }];
2586
- },
2587
- };
2588
-
2589
- const router = new AssetDataRouter(yahooProvider, [cloudProvider]);
2590
- const history = await router.getDetailedPriceHistory(
2591
- "AAPL",
2592
- "NASDAQ",
2593
- new Date("2026-03-28T09:30:00Z"),
2594
- new Date("2026-03-28T16:00:00Z"),
2595
- "15m",
2596
- );
2597
-
2598
- expect(history[0]?.close).toBe(102);
2599
- });
2600
- });