gloomberb 0.17.6 → 0.18.1

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 (802) hide show
  1. package/README.md +2 -0
  2. package/README.zh-CN.md +2 -0
  3. package/package.json +6 -1
  4. package/patches/electrobun@1.18.1.patch +74 -0
  5. package/src/account/auth-model.ts +3 -2
  6. package/src/account/device-signin-dialog.tsx +38 -13
  7. package/src/account/device-signin.ts +2 -1
  8. package/src/account/upgrade-dialog.tsx +6 -2
  9. package/src/api-client/askg.ts +5 -3
  10. package/src/api-client/bank-figures.ts +73 -0
  11. package/src/api-client/credit-boards.ts +21 -1
  12. package/src/api-client/crypto-markets.ts +88 -1
  13. package/src/api-client/data.ts +104 -4
  14. package/src/api-client/debt-maturities.ts +18 -0
  15. package/src/api-client/equity-screener.ts +3 -0
  16. package/src/api-client/errors.ts +13 -0
  17. package/src/api-client/fund-facts.ts +72 -0
  18. package/src/api-client/futures-curve.ts +26 -3
  19. package/src/api-client/geo.ts +11 -1
  20. package/src/api-client/index.ts +25 -2
  21. package/src/api-client/insider-signals.ts +95 -11
  22. package/src/api-client/market-movers.ts +7 -0
  23. package/src/api-client/normalizers.ts +1 -0
  24. package/src/api-client/paths.ts +20 -1
  25. package/src/api-client/request.ts +11 -3
  26. package/src/api-client/research-activity.ts +15 -8
  27. package/src/api-client/socket.ts +6 -3
  28. package/src/api-client/supply-chain-graph.ts +2 -2
  29. package/src/api-client/supply-chain.ts +8 -0
  30. package/src/api-client/tape.ts +12 -0
  31. package/src/api-client/types.ts +75 -2
  32. package/src/api-client/upgrade-experiment.ts +4 -3
  33. package/src/api-client/wall-experiments.ts +5 -3
  34. package/src/api-client/wall-summary.ts +3 -1
  35. package/src/api-client/web-experiments.ts +5 -2
  36. package/src/api-client/yield-curves.ts +17 -0
  37. package/src/app/command-bar-intro.ts +38 -0
  38. package/src/app/keybindings/actions.ts +1 -1
  39. package/src/app/pane-runtime/pane-template-runtime.ts +35 -7
  40. package/src/app/pane-runtime/plugin-bindings.ts +4 -0
  41. package/src/app/pane-runtime/ticker-open-runtime.ts +4 -14
  42. package/src/app/pane-runtime/ticker-open-target.ts +31 -0
  43. package/src/app/runtime/desktop-deeplink.ts +3 -4
  44. package/src/app/runtime/plugin-bindings.ts +3 -2
  45. package/src/app/runtime/startup.ts +3 -4
  46. package/src/app/runtime/ticker-refresh.ts +13 -12
  47. package/src/app/runtime/update.ts +3 -2
  48. package/src/architecture/core-builtin-allowlist.json +0 -3
  49. package/src/architecture/silent-catch-allowlist.json +3 -0
  50. package/src/architecture/ui-literals-allowlist.json +186 -0
  51. package/src/architecture/ui-tokens-allowlist.json +40 -0
  52. package/src/ask-gloom/pane-context.ts +3 -1
  53. package/src/brokers/signed-in/catalog.ts +2 -1
  54. package/src/brokers/signed-in/client.ts +7 -2
  55. package/src/brokers/signed-in/sign-in-dialog.tsx +120 -26
  56. package/src/brokers/signed-in/sign-in.ts +22 -20
  57. package/src/brokers/sync-broker-instance.ts +2 -1
  58. package/src/capabilities/chart-series.ts +2 -0
  59. package/src/capabilities/registry.ts +1 -3
  60. package/src/cli/bank-section.ts +147 -0
  61. package/src/cli/base-converter.ts +5 -2
  62. package/src/cli/board-coins.ts +70 -0
  63. package/src/cli/commands/fred-series.ts +105 -5
  64. package/src/cli/commands/market.ts +344 -69
  65. package/src/cli/commands/news-search.ts +35 -2
  66. package/src/cli/commands/options-chain.ts +7 -5
  67. package/src/cli/commands/options-leaps.ts +3 -3
  68. package/src/cli/commands/overview.ts +108 -34
  69. package/src/cli/commands/plugins.ts +1 -0
  70. package/src/cli/commands/search.ts +87 -24
  71. package/src/cli/commands/system.ts +5 -2
  72. package/src/cli/commands/ticker.ts +342 -62
  73. package/src/cli/context.ts +2 -1
  74. package/src/cli/desktop-pane-shot.ts +11 -3
  75. package/src/cli/earnings-calendar.ts +2 -1
  76. package/src/cli/errors.ts +10 -0
  77. package/src/cli/export-source.ts +18 -3
  78. package/src/cli/glossary.ts +196 -14
  79. package/src/cli/history-rows.ts +60 -9
  80. package/src/cli/index-roots.ts +26 -0
  81. package/src/cli/index.ts +34 -9
  82. package/src/cli/known-gaps.ts +156 -22
  83. package/src/cli/listing-arg.ts +156 -12
  84. package/src/cli/listing-suggestion.ts +4 -2
  85. package/src/cli/name-entries.ts +76 -0
  86. package/src/cli/not-a-ticker.ts +15 -6
  87. package/src/cli/pane-functions/access-gate.ts +22 -0
  88. package/src/cli/pane-functions/capabilities.ts +62 -4
  89. package/src/cli/pane-functions/catalog.ts +94 -39
  90. package/src/cli/pane-functions/data.ts +6 -5
  91. package/src/cli/pane-functions/discovery.ts +1 -1
  92. package/src/cli/pane-functions/dom.ts +3 -3
  93. package/src/cli/pane-functions/freshness.ts +49 -8
  94. package/src/cli/pane-functions/function-help.ts +17 -14
  95. package/src/cli/pane-functions/headless.ts +177 -42
  96. package/src/cli/pane-functions/index.ts +64 -8
  97. package/src/cli/pane-functions/options.ts +17 -3
  98. package/src/cli/pane-functions/report-notices.ts +17 -3
  99. package/src/cli/pane-functions/resolver.ts +48 -13
  100. package/src/cli/pane-functions/screenshot.ts +124 -23
  101. package/src/cli/pane-functions/shot-options.ts +68 -0
  102. package/src/cli/perpetual-contract.ts +3 -1
  103. package/src/cli/report-tables.ts +10 -2
  104. package/src/cli/staged-tickers.ts +5 -0
  105. package/src/cli/statement-filings.ts +261 -0
  106. package/src/cli/symbol-args.ts +47 -8
  107. package/src/cli/symbol-list.ts +60 -18
  108. package/src/cli/symbol-rows.ts +269 -29
  109. package/src/cli/ticker-resolution.ts +148 -34
  110. package/src/cli/treasury-yields.ts +86 -0
  111. package/src/cli/types.ts +3 -0
  112. package/src/cli/uncovered-instrument.ts +20 -0
  113. package/src/components/chart/composite/axis-overlays.tsx +16 -9
  114. package/src/components/chart/composite/composite-chart.tsx +96 -11
  115. package/src/components/chart/composite/downsample.ts +19 -3
  116. package/src/components/chart/composite/format.ts +3 -0
  117. package/src/components/chart/composite/legend.tsx +155 -76
  118. package/src/components/chart/composite/panel-bitmap.ts +8 -2
  119. package/src/components/chart/composite/panel-surface.tsx +9 -11
  120. package/src/components/chart/composite/price-axis-labels.tsx +2 -1
  121. package/src/components/chart/composite/toolbar.tsx +12 -7
  122. package/src/components/chart/composite/types.ts +10 -0
  123. package/src/components/chart/composite/use-composite-chart-keyboard.ts +28 -1
  124. package/src/components/chart/curve/curve-surface.tsx +1 -1
  125. package/src/components/chart/static/series.ts +39 -0
  126. package/src/components/chart/static/trail-chart-surface.tsx +2 -1
  127. package/src/components/command-bar/commands/collection-list.ts +45 -15
  128. package/src/components/command-bar/commands/collection.ts +10 -3
  129. package/src/components/command-bar/commands/registry.ts +2 -2
  130. package/src/components/command-bar/list/badge.ts +4 -3
  131. package/src/components/command-bar/list/model.ts +5 -0
  132. package/src/components/command-bar/list/view.tsx +1 -1
  133. package/src/components/command-bar/panel/index.tsx +19 -8
  134. package/src/components/command-bar/panel/native-surface.ts +6 -4
  135. package/src/components/command-bar/panel/prompt-example.ts +22 -0
  136. package/src/components/command-bar/routes/root/provider-search.ts +3 -9
  137. package/src/components/command-bar/routes/root/results.ts +13 -0
  138. package/src/components/command-bar/routes/root/start-here.ts +90 -0
  139. package/src/components/command-bar/routes/ticker-search/results.ts +42 -3
  140. package/src/components/command-bar/routes/ticker-search/route.ts +3 -10
  141. package/src/components/command-bar/theme-picker.tsx +3 -1
  142. package/src/components/command-bar/workflow/builtin.ts +5 -1
  143. package/src/components/command-bar/workflow/collection-actions.ts +25 -12
  144. package/src/components/command-bar/workflow/ops.ts +21 -1
  145. package/src/{plugins/builtin/portfolio-list/command-bar.ts → components/command-bar/workflow/portfolio-position.ts} +42 -9
  146. package/src/components/command-bar/workflow/tickers.ts +6 -4
  147. package/src/components/feedback-dialog.tsx +1 -1
  148. package/src/components/form-modal/broker-step.tsx +7 -63
  149. package/src/components/form-modal/content.tsx +7 -2
  150. package/src/components/form-modal/field-row.tsx +6 -8
  151. package/src/components/form-modal/host.tsx +3 -3
  152. package/src/components/form-modal/model.ts +3 -0
  153. package/src/components/form-modal/routes.ts +17 -2
  154. package/src/components/index.ts +6 -6
  155. package/src/components/input-search-bar.tsx +43 -6
  156. package/src/components/layout/detached-pane-shell.tsx +0 -1
  157. package/src/components/layout/floating-pane.tsx +0 -1
  158. package/src/components/layout/header.tsx +8 -7
  159. package/src/components/layout/pane/footer/index.tsx +7 -4
  160. package/src/components/layout/pane/footer/model.ts +28 -2
  161. package/src/components/layout/pane/header.tsx +9 -19
  162. package/src/components/layout/pane/index.tsx +0 -1
  163. package/src/components/layout/pane/instrument-coverage-gate.tsx +57 -0
  164. package/src/components/layout/pane/pane-tabs.tsx +4 -3
  165. package/src/components/layout/pane/sizing.ts +9 -0
  166. package/src/components/layout/pane/ticker-fate-gate.tsx +8 -2
  167. package/src/components/layout/shell/pane/capture.ts +44 -20
  168. package/src/components/layout/status-bar.tsx +3 -6
  169. package/src/components/markdown-text.tsx +17 -2
  170. package/src/components/market-board/index.tsx +19 -8
  171. package/src/components/metric-treemap/heat-surface.tsx +2 -7
  172. package/src/components/onboarding/account-step/qr-panel.tsx +5 -2
  173. package/src/components/onboarding/onboarding-frame.tsx +24 -21
  174. package/src/components/onboarding/portfolio-step/positions-panel.tsx +20 -10
  175. package/src/components/onboarding/wizard-positions.ts +48 -11
  176. package/src/components/pane-settings-dialog/desktop.tsx +12 -50
  177. package/src/components/pane-settings-dialog/field-dialogs.tsx +1 -1
  178. package/src/components/price-performance.tsx +18 -2
  179. package/src/components/reader/article-reader.tsx +11 -10
  180. package/src/components/reader/detail-reader.tsx +9 -5
  181. package/src/components/reader/reader-text.tsx +51 -24
  182. package/src/components/sign-in-code-panel.tsx +129 -75
  183. package/src/components/ticker/badge/index.tsx +2 -1
  184. package/src/components/ui/action-row.tsx +5 -2
  185. package/src/components/ui/audio-player.tsx +70 -0
  186. package/src/components/ui/card.tsx +75 -0
  187. package/src/components/ui/data-table/index.tsx +4 -2
  188. package/src/components/ui/data-table/types.ts +11 -0
  189. package/src/components/ui/detail-scroll-body.tsx +1 -1
  190. package/src/components/ui/dialog-actions.tsx +1 -21
  191. package/src/components/ui/display.tsx +13 -5
  192. package/src/components/ui/external-link.tsx +4 -2
  193. package/src/components/ui/fields.tsx +12 -0
  194. package/src/components/ui/figure.tsx +5 -3
  195. package/src/components/ui/frame.tsx +40 -6
  196. package/src/components/ui/icon.tsx +4 -0
  197. package/src/components/ui/index.ts +4 -1
  198. package/src/components/ui/list-view.tsx +8 -0
  199. package/src/components/ui/prose.tsx +97 -25
  200. package/src/components/ui/query-bar-keys.tsx +3 -1
  201. package/src/components/ui/query-bar.tsx +6 -0
  202. package/src/components/ui/quote.ts +42 -0
  203. package/src/components/ui/range-track.tsx +15 -2
  204. package/src/components/ui/reveal-in-scroll-box.ts +21 -3
  205. package/src/components/ui/select-button.tsx +38 -3
  206. package/src/components/ui/status.tsx +73 -4
  207. package/src/components/ui/table-layout.ts +20 -0
  208. package/src/components/use-pinned-moment.ts +19 -0
  209. package/src/core/app-runtime.ts +2 -2
  210. package/src/core/state/app/instrument.ts +18 -1
  211. package/src/core/state/app/layout.ts +6 -0
  212. package/src/core/state/app/state.ts +14 -2
  213. package/src/data/cached-query.ts +1 -1
  214. package/src/data/config/chart-settings.ts +3 -1
  215. package/src/data/config/home.ts +4 -1
  216. package/src/data/config/store/node.ts +9 -4
  217. package/src/data/config/store/normalize.ts +9 -0
  218. package/src/data/json-storage.ts +6 -3
  219. package/src/data/json-ticker-repository.ts +3 -1
  220. package/src/data/plugin-cache.ts +5 -1
  221. package/src/data/sqlite/json.ts +3 -1
  222. package/src/data/ticker-repository.ts +5 -2
  223. package/src/docs/snapshot.json +52 -17
  224. package/src/feedback/diagnostics.ts +2 -6
  225. package/src/i18n/es.ts +86 -6
  226. package/src/i18n/index.ts +3 -9
  227. package/src/i18n/ja.ts +86 -6
  228. package/src/i18n/ko.ts +86 -6
  229. package/src/i18n/zh-cn.ts +86 -6
  230. package/src/i18n/zh-tw.ts +86 -6
  231. package/src/layout-marketplace/gallery-desktop.tsx +8 -4
  232. package/src/market-data/bars-per-year.ts +43 -0
  233. package/src/market-data/bond-funds.ts +85 -0
  234. package/src/market-data/coordinator/auxiliary.ts +5 -2
  235. package/src/market-data/coordinator/index.ts +6 -5
  236. package/src/market-data/futures-contract.ts +102 -5
  237. package/src/market-data/hooks.tsx +20 -11
  238. package/src/market-data/market/bar-period.ts +36 -0
  239. package/src/market-data/market/format.ts +5 -13
  240. package/src/market-data/market/freshness.ts +1 -3
  241. package/src/market-data/market/index-level.ts +51 -0
  242. package/src/market-data/model-dividend-yield.ts +57 -16
  243. package/src/market-data/quotes/live-valuation.ts +48 -2
  244. package/src/market-data/realized-volatility.ts +16 -7
  245. package/src/market-data/tax-equivalent.ts +344 -0
  246. package/src/news/aggregator.ts +4 -2
  247. package/src/notifications/notification-log.ts +5 -3
  248. package/src/plugins/auto-update-node.ts +1 -0
  249. package/src/plugins/builtin/account-management/footer.ts +1 -1
  250. package/src/plugins/builtin/account-management/keyboard.ts +3 -0
  251. package/src/plugins/builtin/account-management/model.ts +1 -0
  252. package/src/plugins/builtin/account-management/pane.tsx +71 -19
  253. package/src/plugins/builtin/account-management/trial-cancel.ts +40 -0
  254. package/src/plugins/builtin/alerts/cli.ts +7 -18
  255. package/src/plugins/builtin/alerts/constants.ts +8 -0
  256. package/src/plugins/builtin/alerts/event-rows.ts +16 -0
  257. package/src/plugins/builtin/alerts/events-pane.tsx +2 -14
  258. package/src/plugins/builtin/alerts/headless.ts +182 -0
  259. package/src/plugins/builtin/alerts/index.tsx +3 -0
  260. package/src/plugins/builtin/alerts/pane.tsx +1 -7
  261. package/src/plugins/builtin/alerts/storage.ts +17 -1
  262. package/src/plugins/builtin/analytics/index.tsx +7 -2
  263. package/src/plugins/builtin/analytics/metrics.ts +47 -9
  264. package/src/plugins/builtin/analytics/risk-client.ts +44 -11
  265. package/src/plugins/builtin/analytics/risk-fx.ts +61 -0
  266. package/src/plugins/builtin/analytics/risk-headless.ts +24 -3
  267. package/src/plugins/builtin/analytics/risk-math.ts +83 -0
  268. package/src/plugins/builtin/analytics/risk-model.ts +175 -19
  269. package/src/plugins/builtin/analytics/risk-pane.tsx +19 -8
  270. package/src/plugins/builtin/analytics/risk-test-data.ts +3 -0
  271. package/src/plugins/builtin/analytics/sector-model.ts +14 -3
  272. package/src/plugins/builtin/awards/headless.ts +6 -5
  273. package/src/plugins/builtin/awards/index.tsx +1 -1
  274. package/src/plugins/builtin/backtest/client.ts +38 -8
  275. package/src/plugins/builtin/backtest/engine.ts +25 -13
  276. package/src/plugins/builtin/backtest/export.ts +27 -0
  277. package/src/plugins/builtin/backtest/format.ts +19 -3
  278. package/src/plugins/builtin/backtest/headless.ts +42 -28
  279. package/src/plugins/builtin/backtest/index.tsx +3 -0
  280. package/src/plugins/builtin/backtest/pane.tsx +39 -10
  281. package/src/plugins/builtin/backtest/report.ts +160 -0
  282. package/src/plugins/builtin/backtest/rules.ts +2 -0
  283. package/src/plugins/builtin/backtest/window.ts +112 -0
  284. package/src/plugins/builtin/bond-calculator/headless.ts +3 -2
  285. package/src/plugins/builtin/broker-manager/add-flow.tsx +4 -4
  286. package/src/plugins/builtin/catalysts/headless.ts +24 -13
  287. package/src/plugins/builtin/catalysts/index.tsx +4 -2
  288. package/src/plugins/builtin/catalysts/model.ts +18 -1
  289. package/src/plugins/builtin/catalysts/pane.tsx +2 -2
  290. package/src/plugins/builtin/cds/client.ts +28 -5
  291. package/src/plugins/builtin/cds/headless.ts +183 -31
  292. package/src/plugins/builtin/cds/index.tsx +1 -1
  293. package/src/plugins/builtin/cds/model.ts +229 -53
  294. package/src/plugins/builtin/cds/pane.tsx +82 -26
  295. package/src/plugins/builtin/central-bank-rates/headless.ts +1 -1
  296. package/src/plugins/builtin/chart-composer/catalog-inventory.ts +39 -1
  297. package/src/plugins/builtin/chart-composer/chart-spec-edit.ts +77 -0
  298. package/src/plugins/builtin/chart-composer/chart-spec.ts +15 -0
  299. package/src/plugins/builtin/chart-composer/data-catalog-pane.tsx +22 -2
  300. package/src/plugins/builtin/chart-composer/editor/desktop-view.tsx +2 -2
  301. package/src/plugins/builtin/chart-composer/headless-schema.ts +10 -2
  302. package/src/plugins/builtin/chart-composer/headless.ts +99 -21
  303. package/src/plugins/builtin/chart-composer/index.tsx +70 -13
  304. package/src/plugins/builtin/chart-composer/pane.tsx +65 -15
  305. package/src/plugins/builtin/chart-composer/presets.ts +79 -11
  306. package/src/plugins/builtin/chart-composer/series-catalog.ts +50 -14
  307. package/src/plugins/builtin/chart-composer/series-expression.ts +9 -7
  308. package/src/plugins/builtin/chart-composer/series-listings.ts +178 -0
  309. package/src/plugins/builtin/chart-composer/session-range.ts +87 -0
  310. package/src/plugins/builtin/chat/attachments/desktop.tsx +4 -1
  311. package/src/plugins/builtin/chat/content/composer-runtime.ts +49 -14
  312. package/src/plugins/builtin/chat/content/composer.tsx +22 -1
  313. package/src/plugins/builtin/chat/content/index.tsx +35 -5
  314. package/src/plugins/builtin/chat/content/layout-metrics.ts +3 -0
  315. package/src/plugins/builtin/chat/content/shortcuts.ts +32 -13
  316. package/src/plugins/builtin/chat/content/snapshot.ts +29 -6
  317. package/src/plugins/builtin/chat/ghost-user.ts +11 -3
  318. package/src/plugins/builtin/chat/layout.ts +2 -0
  319. package/src/plugins/builtin/chat/message/desktop.tsx +13 -5
  320. package/src/plugins/builtin/chat/message/header.tsx +26 -4
  321. package/src/plugins/builtin/chat/message/pane-chip.tsx +131 -35
  322. package/src/plugins/builtin/chat/message/render-state.ts +28 -1
  323. package/src/plugins/builtin/chat/message/terminal.tsx +9 -3
  324. package/src/plugins/builtin/chat/pane-links/composer.ts +87 -0
  325. package/src/plugins/builtin/chat/pane-links/model.ts +1 -1
  326. package/src/plugins/builtin/chat/share/flow.tsx +9 -73
  327. package/src/plugins/builtin/cloud/askg/controller.ts +5 -3
  328. package/src/plugins/builtin/cloud/askg/executor.ts +3 -1
  329. package/src/plugins/builtin/cloud/askg/lock-note.ts +16 -0
  330. package/src/plugins/builtin/cloud/askg/pane.tsx +6 -2
  331. package/src/plugins/builtin/cloud/auth-actions.tsx +4 -2
  332. package/src/plugins/builtin/cloud/company-picker.tsx +21 -26
  333. package/src/plugins/builtin/cloud/mcp-connect/dialog.tsx +5 -3
  334. package/src/plugins/builtin/cloud/plugin.tsx +2 -0
  335. package/src/plugins/builtin/cloud/team/module.tsx +5 -1
  336. package/src/plugins/builtin/cloud/team/pane-sections.tsx +10 -3
  337. package/src/plugins/builtin/cloud/team/pane.tsx +35 -7
  338. package/src/plugins/builtin/cloud/team/views.ts +11 -4
  339. package/src/plugins/builtin/cloud/terminal-relay/engine.ts +9 -4
  340. package/src/plugins/builtin/cloud/terminal-relay/prompts.tsx +3 -2
  341. package/src/plugins/builtin/cloud/thesis/detail.tsx +2 -1
  342. package/src/plugins/builtin/cloud/thesis/exposure.ts +3 -0
  343. package/src/plugins/builtin/cloud/thesis/prompts.tsx +3 -2
  344. package/src/plugins/builtin/cloud/thesis/ticker-tab.tsx +2 -1
  345. package/src/plugins/builtin/cloud/trial-offer-status-widget.tsx +2 -1
  346. package/src/plugins/builtin/cloud/verification-status-widget.tsx +2 -1
  347. package/src/plugins/builtin/commodities-energy/index.tsx +8 -5
  348. package/src/plugins/builtin/commodities-energy/view-state.ts +11 -0
  349. package/src/plugins/builtin/company-attention/headless.ts +15 -7
  350. package/src/plugins/builtin/company-attention/index.tsx +1 -1
  351. package/src/plugins/builtin/company-attention/model.ts +49 -4
  352. package/src/plugins/builtin/company-attention/pane.tsx +11 -9
  353. package/src/plugins/builtin/company-kpis/headless.ts +4 -3
  354. package/src/plugins/builtin/company-kpis/index.tsx +2 -2
  355. package/src/plugins/builtin/company-kpis/pane.tsx +9 -3
  356. package/src/plugins/builtin/congress-trades/headless.ts +23 -2
  357. package/src/plugins/builtin/correlation/relationship/pane.tsx +18 -46
  358. package/src/plugins/builtin/cot/headless.ts +5 -2
  359. package/src/plugins/builtin/credit-boards/cdx-pane.tsx +41 -13
  360. package/src/plugins/builtin/credit-boards/client.ts +9 -2
  361. package/src/plugins/builtin/credit-boards/headless.ts +93 -27
  362. package/src/plugins/builtin/credit-boards/index.tsx +15 -4
  363. package/src/plugins/builtin/credit-boards/model.ts +105 -6
  364. package/src/plugins/builtin/credit-boards/sovr-pane.tsx +14 -3
  365. package/src/plugins/builtin/credit-documents/detail.tsx +2 -1
  366. package/src/plugins/builtin/credit-documents/index.tsx +3 -0
  367. package/src/plugins/builtin/credit-documents/model.ts +3 -10
  368. package/src/plugins/builtin/crypto-board/client.ts +152 -2
  369. package/src/plugins/builtin/crypto-board/headless.ts +138 -19
  370. package/src/plugins/builtin/crypto-board/index.tsx +5 -3
  371. package/src/plugins/builtin/crypto-board/model.ts +210 -12
  372. package/src/plugins/builtin/crypto-board/pane.tsx +148 -9
  373. package/src/plugins/builtin/crypto-board/series.ts +52 -1
  374. package/src/plugins/builtin/crypto-board/supply.ts +123 -0
  375. package/src/plugins/builtin/custom-view/loader.ts +3 -2
  376. package/src/plugins/builtin/custom-view/pane.tsx +5 -4
  377. package/src/plugins/builtin/custom-view/view-spec.ts +1 -0
  378. package/src/plugins/builtin/debt-maturities/client.ts +54 -1
  379. package/src/plugins/builtin/debt-maturities/headless.ts +27 -3
  380. package/src/plugins/builtin/debt-maturities/index.tsx +2 -0
  381. package/src/plugins/builtin/debt-maturities/model.ts +58 -13
  382. package/src/plugins/builtin/debt-maturities/pane.tsx +47 -7
  383. package/src/plugins/builtin/dividend-yield/client.ts +42 -36
  384. package/src/plugins/builtin/dividend-yield/headless.ts +113 -18
  385. package/src/plugins/builtin/dividend-yield/index.tsx +5 -2
  386. package/src/plugins/builtin/dividend-yield/pane.tsx +37 -13
  387. package/src/plugins/builtin/dividend-yield/provider-client.ts +7 -3
  388. package/src/plugins/builtin/dividend-yield/ranking.ts +187 -0
  389. package/src/plugins/builtin/dividend-yield/reference-price.ts +28 -5
  390. package/src/plugins/builtin/dividend-yield/types.ts +6 -1
  391. package/src/plugins/builtin/dividend-yield/view.ts +1 -1
  392. package/src/plugins/builtin/docs/blocks.tsx +54 -8
  393. package/src/plugins/builtin/docs/pane.tsx +8 -13
  394. package/src/plugins/builtin/earnings/headless.ts +3 -2
  395. package/src/plugins/builtin/earnings-calls/data.ts +51 -0
  396. package/src/plugins/builtin/earnings-calls/headless.ts +7 -0
  397. package/src/plugins/builtin/earnings-calls/index.tsx +1 -0
  398. package/src/plugins/builtin/earnings-calls/model.ts +97 -0
  399. package/src/plugins/builtin/earnings-calls/pane.tsx +107 -7
  400. package/src/plugins/builtin/earnings-calls/transcript-view.tsx +140 -22
  401. package/src/plugins/builtin/earnings-calls/use-call-playback.ts +194 -0
  402. package/src/plugins/builtin/econ/calendar-model.ts +25 -2
  403. package/src/plugins/builtin/econ/calendar-source.ts +35 -0
  404. package/src/plugins/builtin/econ/fred-catalog.ts +6 -2
  405. package/src/plugins/builtin/econ/fred-series-map.ts +12 -1
  406. package/src/plugins/builtin/econ/index.tsx +40 -8
  407. package/src/plugins/builtin/econ-statistics/defs.ts +7 -0
  408. package/src/plugins/builtin/econ-statistics/detail.tsx +8 -1
  409. package/src/plugins/builtin/econ-statistics/headless.ts +26 -5
  410. package/src/plugins/builtin/econ-statistics/pane.tsx +4 -2
  411. package/src/plugins/builtin/econ-statistics/stats.ts +10 -0
  412. package/src/plugins/builtin/econ-statistics/view.ts +19 -0
  413. package/src/plugins/builtin/equity-screener/client.ts +1 -1
  414. package/src/plugins/builtin/equity-screener/model.ts +46 -4
  415. package/src/plugins/builtin/equity-screener/pane.tsx +3 -0
  416. package/src/plugins/builtin/estimate-revisions/client.ts +32 -22
  417. package/src/plugins/builtin/estimate-revisions/headless.ts +1 -0
  418. package/src/plugins/builtin/estimate-revisions/index.tsx +1 -0
  419. package/src/plugins/builtin/estimate-revisions/pane.tsx +5 -3
  420. package/src/plugins/builtin/executives/data.ts +24 -8
  421. package/src/plugins/builtin/executives/index.tsx +3 -18
  422. package/src/plugins/builtin/executives/pane.tsx +34 -10
  423. package/src/plugins/builtin/exposure/editor.tsx +3 -3
  424. package/src/plugins/builtin/fear-greed/index.tsx +9 -0
  425. package/src/plugins/builtin/filing-events/index.tsx +1 -0
  426. package/src/plugins/builtin/futures/index.tsx +2 -2
  427. package/src/plugins/builtin/futures/model.ts +34 -21
  428. package/src/plugins/builtin/futures/table.tsx +1 -1
  429. package/src/plugins/builtin/futures/use-board-terms.ts +2 -2
  430. package/src/plugins/builtin/futures-curve/headless.ts +4 -2
  431. package/src/plugins/builtin/futures-curve/model.ts +5 -7
  432. package/src/plugins/builtin/help/index.tsx +55 -8
  433. package/src/plugins/builtin/help/shortcut-table.tsx +15 -2
  434. package/src/plugins/builtin/holders/headless.ts +12 -0
  435. package/src/plugins/builtin/insider/headless.ts +311 -41
  436. package/src/plugins/builtin/insider/index.tsx +280 -106
  437. package/src/plugins/builtin/insider/insiders.tsx +224 -0
  438. package/src/plugins/builtin/insider/signals-cells.tsx +52 -0
  439. package/src/plugins/builtin/insider/signals-client.ts +135 -11
  440. package/src/plugins/builtin/insider/signals-model.ts +628 -56
  441. package/src/plugins/builtin/insider/signals.tsx +283 -83
  442. package/src/plugins/builtin/ipo-calendar/headless.ts +17 -7
  443. package/src/plugins/builtin/ipo-calendar/index.tsx +23 -3
  444. package/src/plugins/builtin/ipo-calendar/model.ts +84 -36
  445. package/src/plugins/builtin/ipo-calendar/pane.tsx +20 -8
  446. package/src/plugins/builtin/iv-history/headless.ts +2 -0
  447. package/src/plugins/builtin/jobs/headless.ts +1 -0
  448. package/src/plugins/builtin/jobs/index.tsx +1 -0
  449. package/src/plugins/builtin/jodi/headless.ts +2 -0
  450. package/src/plugins/builtin/kelly-sizer/pane.tsx +1 -1
  451. package/src/plugins/builtin/kelly-sizer/portfolio.ts +1 -1
  452. package/src/plugins/builtin/market-heatmap/headless.ts +1 -0
  453. package/src/plugins/builtin/market-heatmap/portfolio.ts +3 -1
  454. package/src/plugins/builtin/market-movers/client.ts +2 -2
  455. package/src/plugins/builtin/market-movers/index.tsx +0 -3
  456. package/src/plugins/builtin/market-movers/session-body.tsx +27 -11
  457. package/src/plugins/builtin/market-movers/session.ts +25 -10
  458. package/src/plugins/builtin/market-valuation/pane.tsx +1 -1
  459. package/src/plugins/builtin/market-valuation/zone-scale/desktop.tsx +31 -57
  460. package/src/plugins/builtin/mna/distress/headless.ts +2 -1
  461. package/src/plugins/builtin/mna/headless.ts +14 -2
  462. package/src/plugins/builtin/mna/index.tsx +1 -0
  463. package/src/plugins/builtin/news/headless.ts +4 -0
  464. package/src/plugins/builtin/news/wire/feed-config.ts +4 -1
  465. package/src/plugins/builtin/news/wire/letters/client.ts +1 -0
  466. package/src/plugins/builtin/news/wire/news/command-bar-search.ts +6 -3
  467. package/src/plugins/builtin/news/wire/news/detail-view.tsx +2 -1
  468. package/src/plugins/builtin/news/wire/news/footer.ts +5 -3
  469. package/src/plugins/builtin/news/wire/news/table.tsx +59 -12
  470. package/src/plugins/builtin/news/wire/rss/feed-xml.ts +6 -1
  471. package/src/plugins/builtin/news/wire/rss/managed-feed.ts +1 -0
  472. package/src/plugins/builtin/notes/cli.ts +39 -10
  473. package/src/plugins/builtin/notes/export.ts +49 -3
  474. package/src/plugins/builtin/notes/files.ts +78 -21
  475. package/src/plugins/builtin/notes/index.tsx +3 -3
  476. package/src/plugins/builtin/notes/migration.ts +18 -6
  477. package/src/plugins/builtin/notes/owner.tsx +3 -2
  478. package/src/plugins/builtin/notes/quick-notes-pane.tsx +48 -12
  479. package/src/plugins/builtin/notes/store.ts +13 -3
  480. package/src/plugins/builtin/options-scenario/client.ts +7 -4
  481. package/src/plugins/builtin/options-scenario/headless.ts +5 -3
  482. package/src/plugins/builtin/pe-band/index.tsx +1 -1
  483. package/src/plugins/builtin/pe-band/model.ts +1 -15
  484. package/src/plugins/builtin/perps/headless.ts +30 -13
  485. package/src/plugins/builtin/perps/model.ts +45 -3
  486. package/src/plugins/builtin/perps/pane.tsx +7 -7
  487. package/src/plugins/builtin/portfolio-list/cell-version.ts +10 -4
  488. package/src/plugins/builtin/portfolio-list/cli/bulk-symbols.ts +133 -18
  489. package/src/plugins/builtin/portfolio-list/cli/portfolio-command.ts +268 -55
  490. package/src/plugins/builtin/portfolio-list/cli/render.ts +401 -48
  491. package/src/plugins/builtin/portfolio-list/cli/shared.ts +8 -2
  492. package/src/plugins/builtin/portfolio-list/cli/watchlist-command.ts +25 -35
  493. package/src/plugins/builtin/portfolio-list/grid.tsx +3 -1
  494. package/src/plugins/builtin/portfolio-list/headless.ts +153 -29
  495. package/src/plugins/builtin/portfolio-list/income.ts +296 -0
  496. package/src/plugins/builtin/portfolio-list/metrics.ts +2 -2
  497. package/src/plugins/builtin/portfolio-list/pane/futures-terms.ts +58 -0
  498. package/src/plugins/builtin/portfolio-list/pane/index.tsx +38 -13
  499. package/src/plugins/builtin/portfolio-list/pane/supplemental.ts +47 -28
  500. package/src/plugins/builtin/portfolio-list/quick-add/index.tsx +3 -2
  501. package/src/plugins/builtin/portfolio-list/quick-add/resolution.ts +10 -3
  502. package/src/plugins/builtin/portfolio-list/summary/index.tsx +36 -5
  503. package/src/plugins/builtin/portfolio-list/summary/live-accounts.ts +42 -7
  504. package/src/plugins/builtin/portfolio-list/summary/totals.ts +31 -3
  505. package/src/plugins/builtin/portfolio-list/table.tsx +25 -5
  506. package/src/plugins/builtin/power/prices-headless.ts +2 -1
  507. package/src/plugins/builtin/realized-vol/chart-model.ts +29 -5
  508. package/src/plugins/builtin/realized-vol/charts.tsx +14 -8
  509. package/src/plugins/builtin/realized-vol/evidence.ts +2 -0
  510. package/src/plugins/builtin/realized-vol/headless.ts +6 -4
  511. package/src/plugins/builtin/realized-vol/model.ts +5 -1
  512. package/src/plugins/builtin/realized-vol/pane.tsx +31 -11
  513. package/src/plugins/builtin/realized-vol/settings.ts +1 -1
  514. package/src/plugins/builtin/research/analyst-headless.ts +4 -0
  515. package/src/plugins/builtin/research/corporate-actions-pane.tsx +2 -0
  516. package/src/plugins/builtin/research/event-model.ts +22 -2
  517. package/src/plugins/builtin/research/headless-schema.ts +1 -0
  518. package/src/plugins/builtin/research/headless.ts +3 -0
  519. package/src/plugins/builtin/research/index.tsx +3 -0
  520. package/src/plugins/builtin/research/relative-valuation-columns.ts +27 -5
  521. package/src/plugins/builtin/research/relative-valuation-headless.ts +2 -0
  522. package/src/plugins/builtin/revenue-breakdown/index.tsx +1 -0
  523. package/src/plugins/builtin/reverse-dcf/headless.ts +9 -6
  524. package/src/plugins/builtin/reverse-dcf/index.tsx +2 -2
  525. package/src/plugins/builtin/reverse-dcf/model.ts +51 -4
  526. package/src/plugins/builtin/reverse-dcf/pane.tsx +23 -10
  527. package/src/plugins/builtin/risk-factors/headless.ts +7 -0
  528. package/src/plugins/builtin/risk-factors/index.tsx +1 -0
  529. package/src/plugins/builtin/scanner/feed.ts +5 -3
  530. package/src/plugins/builtin/scanner/headless.ts +9 -57
  531. package/src/plugins/builtin/scanner/index.ts +1 -2
  532. package/src/plugins/builtin/sec/forms.ts +2 -6
  533. package/src/plugins/builtin/sec/fund-facts-view.tsx +53 -0
  534. package/src/plugins/builtin/sec/fund-facts.ts +328 -0
  535. package/src/plugins/builtin/sec/headless.ts +140 -44
  536. package/src/plugins/builtin/sec/index.tsx +95 -30
  537. package/src/plugins/builtin/sec/model.ts +2 -44
  538. package/src/plugins/builtin/shared/broker-reconnect.ts +105 -0
  539. package/src/plugins/builtin/shared/headless-options.ts +10 -0
  540. package/src/plugins/builtin/shared/locked-rows.tsx +3 -1
  541. package/src/plugins/builtin/shared/move-rank.ts +108 -0
  542. package/src/plugins/builtin/shared/pro-feature-wall.tsx +9 -4
  543. package/src/plugins/builtin/shared/report-freshness.ts +25 -9
  544. package/src/plugins/builtin/shared/scanner-capture.ts +95 -0
  545. package/src/plugins/builtin/shared/treasury-cutoffs.ts +15 -0
  546. package/src/plugins/builtin/shared/use-quote-board.ts +1 -0
  547. package/src/plugins/builtin/shared/volatility/live-session.ts +34 -0
  548. package/src/plugins/builtin/shared/volatility-indices.ts +32 -0
  549. package/src/plugins/builtin/short-interest/headless.ts +3 -0
  550. package/src/plugins/builtin/short-interest/watch-model.ts +2 -2
  551. package/src/plugins/builtin/social-mentions/client.ts +8 -1
  552. package/src/plugins/builtin/social-mentions/pane.tsx +8 -6
  553. package/src/plugins/builtin/supply-chain/client.ts +12 -3
  554. package/src/plugins/builtin/supply-chain/disclosure-quote.tsx +9 -5
  555. package/src/plugins/builtin/supply-chain/evidence.ts +3 -1
  556. package/src/plugins/builtin/supply-chain/flow-layout.ts +2 -1
  557. package/src/plugins/builtin/supply-chain/flow.tsx +23 -16
  558. package/src/plugins/builtin/supply-chain/graph-client.ts +8 -5
  559. package/src/plugins/builtin/supply-chain/graph-evidence.ts +1 -1
  560. package/src/plugins/builtin/supply-chain/graph-model.ts +10 -2
  561. package/src/plugins/builtin/supply-chain/graph-pane.tsx +9 -7
  562. package/src/plugins/builtin/supply-chain/graph.tsx +8 -6
  563. package/src/plugins/builtin/supply-chain/headless.ts +69 -27
  564. package/src/plugins/builtin/supply-chain/index.tsx +1 -1
  565. package/src/plugins/builtin/supply-chain/model.ts +76 -15
  566. package/src/plugins/builtin/supply-chain/pane.tsx +29 -15
  567. package/src/plugins/builtin/supply-chain/row-evidence.tsx +5 -4
  568. package/src/plugins/builtin/themes/model.ts +2 -5
  569. package/src/plugins/builtin/thirteenf/api.ts +54 -3
  570. package/src/plugins/builtin/thirteenf/data.ts +255 -12
  571. package/src/plugins/builtin/thirteenf/headless.ts +313 -28
  572. package/src/plugins/builtin/thirteenf/index.tsx +4 -1
  573. package/src/plugins/builtin/thirteenf/model.ts +244 -19
  574. package/src/plugins/builtin/thirteenf/overlap-pane.tsx +133 -33
  575. package/src/plugins/builtin/thirteenf/overlap.ts +1 -1
  576. package/src/plugins/builtin/thirteenf/pane.tsx +31 -7
  577. package/src/plugins/builtin/thirteenf/report-notes.ts +78 -0
  578. package/src/plugins/builtin/thirteenf/types.ts +49 -0
  579. package/src/plugins/builtin/ticker-detail/data-panes/historical-prices.tsx +22 -8
  580. package/src/plugins/builtin/ticker-detail/data-panes/history-bars.ts +17 -1
  581. package/src/plugins/builtin/ticker-detail/financials/model.ts +2 -42
  582. package/src/plugins/builtin/ticker-detail/financials/tab.tsx +1 -1
  583. package/src/plugins/builtin/ticker-detail/headless.ts +23 -10
  584. package/src/plugins/builtin/ticker-detail/overview/components.tsx +27 -3
  585. package/src/plugins/builtin/ticker-detail/overview/dividend.ts +60 -0
  586. package/src/plugins/builtin/ticker-detail/overview/model.ts +46 -9
  587. package/src/plugins/builtin/ticker-detail/overview/pane.tsx +3 -0
  588. package/src/plugins/builtin/ticker-detail/overview-tab.tsx +36 -3
  589. package/src/plugins/builtin/ticker-detail/quote-monitor/card.tsx +18 -19
  590. package/src/plugins/builtin/time-sales/client.ts +7 -4
  591. package/src/plugins/builtin/time-sales/headless.ts +71 -22
  592. package/src/plugins/builtin/time-sales/model.ts +12 -0
  593. package/src/plugins/builtin/time-sales/pane.tsx +31 -7
  594. package/src/plugins/builtin/time-sales/window.ts +128 -0
  595. package/src/plugins/builtin/trace-bonds/client.ts +351 -33
  596. package/src/plugins/builtin/trace-bonds/headless.ts +60 -22
  597. package/src/plugins/builtin/trace-bonds/index.tsx +4 -2
  598. package/src/plugins/builtin/trace-bonds/model.ts +27 -25
  599. package/src/plugins/builtin/trace-bonds/pane.tsx +63 -45
  600. package/src/plugins/builtin/treasury-auctions/cache.ts +61 -15
  601. package/src/plugins/builtin/treasury-auctions/client.ts +45 -10
  602. package/src/plugins/builtin/treasury-auctions/headless.ts +35 -13
  603. package/src/plugins/builtin/treasury-auctions/index.tsx +5 -2
  604. package/src/plugins/builtin/treasury-auctions/model.ts +20 -16
  605. package/src/plugins/builtin/treasury-auctions/pane.tsx +29 -12
  606. package/src/plugins/builtin/vol-surface/charts.tsx +2 -1
  607. package/src/plugins/builtin/vol-surface/headless.ts +3 -2
  608. package/src/plugins/builtin/vol-surface/pane.tsx +2 -1
  609. package/src/plugins/builtin/vol-surface/stored.ts +4 -7
  610. package/src/plugins/builtin/volatility/chart-model.ts +16 -15
  611. package/src/plugins/builtin/volatility/charts.tsx +5 -5
  612. package/src/plugins/builtin/volatility/client.ts +73 -2
  613. package/src/plugins/builtin/volatility/evidence.ts +13 -14
  614. package/src/plugins/builtin/volatility/headless.ts +13 -7
  615. package/src/plugins/builtin/volatility/index.tsx +1 -1
  616. package/src/plugins/builtin/volatility/model.ts +104 -38
  617. package/src/plugins/builtin/volatility/pane.tsx +42 -24
  618. package/src/plugins/builtin/volatility/series.ts +22 -13
  619. package/src/plugins/builtin/world-venue-map/geo-series.ts +9 -0
  620. package/src/plugins/builtin/world-venue-map/headless.ts +8 -5
  621. package/src/plugins/builtin/world-venue-map/index.ts +16 -2
  622. package/src/plugins/builtin/world-venue-map/map.tsx +13 -17
  623. package/src/plugins/builtin/yield-curve/curves.ts +29 -5
  624. package/src/plugins/builtin/yield-curve/headless.ts +41 -8
  625. package/src/plugins/builtin/yield-curve/history.ts +5 -5
  626. package/src/plugins/builtin/yield-curve/index.tsx +30 -13
  627. package/src/plugins/compat.ts +3 -1
  628. package/src/plugins/dependencies.ts +8 -2
  629. package/src/plugins/host-link.ts +12 -5
  630. package/src/plugins/installer.ts +16 -7
  631. package/src/plugins/loader.ts +9 -2
  632. package/src/plugins/marketplace/activation.ts +10 -4
  633. package/src/plugins/registry/host-actions.ts +3 -0
  634. package/src/plugins/registry/index.ts +3 -1
  635. package/src/{plugins/builtin/portfolio-list → portfolio}/allocation.ts +74 -12
  636. package/src/{plugins/builtin/portfolio-list → portfolio}/column-values.ts +140 -53
  637. package/src/portfolio/cost-fx.ts +84 -0
  638. package/src/portfolio/futures-positions.ts +213 -0
  639. package/src/portfolio/futures-terms.ts +75 -0
  640. package/src/portfolio/manual-lots.ts +78 -0
  641. package/src/portfolio/mutations.ts +70 -12
  642. package/src/portfolio/position-metrics.ts +89 -14
  643. package/src/portfolio/position-quantity.ts +43 -0
  644. package/src/portfolio/valuation-basis.ts +31 -4
  645. package/src/public/__snapshots__/public-api.test.ts.snap +4 -0
  646. package/src/public/time-series.ts +2 -1
  647. package/src/remote/confirm-change.tsx +2 -1
  648. package/src/remote/server.ts +1 -1
  649. package/src/remote/watchlist.ts +9 -1
  650. package/src/renderers/dom/data-table/row.tsx +1 -1
  651. package/src/renderers/dom/desktop/audio-player.tsx +312 -0
  652. package/src/renderers/dom/desktop/control-styles.ts +17 -82
  653. package/src/renderers/dom/desktop/controls.tsx +39 -63
  654. package/src/renderers/dom/desktop/dialog-actions.tsx +13 -53
  655. package/src/renderers/dom/desktop/icons.tsx +8 -0
  656. package/src/renderers/dom/desktop/list-view.tsx +6 -6
  657. package/src/renderers/dom/desktop/popover.tsx +0 -3
  658. package/src/renderers/dom/desktop/query-bar.tsx +6 -4
  659. package/src/renderers/dom/desktop/select-field.tsx +9 -8
  660. package/src/renderers/dom/desktop/stack-header.ts +3 -0
  661. package/src/renderers/dom/dom-ui-host.tsx +3 -2
  662. package/src/renderers/dom/host/chart-surface.tsx +3 -3
  663. package/src/renderers/dom/host/size-observer.ts +33 -4
  664. package/src/renderers/dom/host/surface-3d.tsx +3 -2
  665. package/src/renderers/dom/host/surface-fit.ts +4 -1
  666. package/src/renderers/dom/host/tabs.tsx +22 -132
  667. package/src/renderers/dom/styles.css +358 -160
  668. package/src/renderers/electrobun/bun/core-capabilities.ts +1 -1
  669. package/src/renderers/electrobun/bun/desktop/backend.ts +1 -1
  670. package/src/renderers/electrobun/bun/desktop/initialization.ts +1 -0
  671. package/src/renderers/electrobun/bun/desktop/state-broadcaster.ts +43 -1
  672. package/src/renderers/electrobun/bun/desktop/workspace/requests.ts +5 -1
  673. package/src/renderers/electrobun/shared/rpc-codec.ts +7 -0
  674. package/src/renderers/electrobun/view/cli-pane-shot-entry.tsx +21 -17
  675. package/src/renderers/electrobun/view/cli-pane-shot-frame.tsx +3 -3
  676. package/src/renderers/electrobun/view/desktop/window/bridge.ts +6 -8
  677. package/src/renderers/electrobun/view/desktop/window/snapshot.ts +18 -0
  678. package/src/series/capability.ts +1 -0
  679. package/src/series/files.ts +9 -3
  680. package/src/series/registry.ts +40 -14
  681. package/src/series/resolve.ts +121 -18
  682. package/src/series/standalone.ts +3 -2
  683. package/src/series/types.ts +55 -1
  684. package/src/series/validate.ts +39 -0
  685. package/src/shares/api.ts +26 -7
  686. package/src/shares/bug-report-dialog.tsx +2 -2
  687. package/src/shares/bug-report-flow.tsx +4 -7
  688. package/src/shares/capture-flow.ts +5 -4
  689. package/src/shares/capture-preview.tsx +2 -2
  690. package/src/shares/chat.ts +7 -27
  691. package/src/shares/flow.tsx +86 -40
  692. package/src/shares/location.ts +1 -3
  693. package/src/shares/pane-image.ts +11 -9
  694. package/src/shares/pane.ts +5 -2
  695. package/src/shares/payload.ts +1 -1
  696. package/src/shares/personal-pane.ts +3 -3
  697. package/src/shares/portable-layout.ts +9 -2
  698. package/src/shares/ready.ts +42 -0
  699. package/src/shares/test-harness.ts +62 -0
  700. package/src/sources/gloomberb-cloud/batched-lookups.ts +73 -0
  701. package/src/sources/gloomberb-cloud/fred-series.ts +27 -2
  702. package/src/sources/gloomberb-cloud/index.ts +64 -12
  703. package/src/sources/gloomberb-cloud/normalizers.ts +31 -2
  704. package/src/sources/gloomberb-cloud/perpetuals.ts +20 -1
  705. package/src/sources/history-omitted.ts +34 -0
  706. package/src/sources/history-result.ts +3 -0
  707. package/src/sources/history-retention.ts +1 -1
  708. package/src/sources/provider-errors.ts +43 -1
  709. package/src/sources/provider-router/batches.ts +3 -2
  710. package/src/sources/provider-router/cache.ts +2 -1
  711. package/src/sources/provider-router/cached-routes.ts +9 -3
  712. package/src/sources/provider-router/history.ts +9 -8
  713. package/src/sources/provider-router/index.ts +18 -3
  714. package/src/sources/provider-router/primary.ts +5 -4
  715. package/src/sources/provider-router/quote-route.ts +3 -1
  716. package/src/sources/provider-router/routing.ts +2 -1
  717. package/src/sources/provider-router/search.ts +47 -13
  718. package/src/sources/provider-router/streaming.ts +7 -4
  719. package/src/sources/sec-edgar.ts +1 -3
  720. package/src/state/app/context/index.tsx +9 -13
  721. package/src/state/app/tab-cursor.ts +149 -12
  722. package/src/state/hooks/quote-streaming.ts +3 -2
  723. package/src/state/hooks/session-snapshot.ts +3 -2
  724. package/src/state/persist-scheduler.ts +12 -4
  725. package/src/sync/controller.ts +22 -1
  726. package/src/sync/core-contributors.ts +59 -15
  727. package/src/team/collections-sync.ts +14 -4
  728. package/src/team/collections.ts +42 -11
  729. package/src/team/store.ts +5 -4
  730. package/src/telemetry/attention-counts.ts +8 -2
  731. package/src/telemetry/crash-reports-dom.ts +3 -0
  732. package/src/telemetry/crash-reports-node.ts +7 -4
  733. package/src/telemetry/crash-reports.ts +11 -11
  734. package/src/telemetry/usage-counts.ts +16 -12
  735. package/src/theme/colors.ts +2 -0
  736. package/src/theme/font-scale.ts +2 -0
  737. package/src/theme/ui-tokens.ts +71 -0
  738. package/src/tickers/batched-lookups.ts +186 -0
  739. package/src/tickers/company-name-listing.ts +97 -0
  740. package/src/tickers/company-name.ts +13 -0
  741. package/src/tickers/instrument-coverage.ts +112 -0
  742. package/src/tickers/listing-fate.ts +49 -9
  743. package/src/tickers/listing-venues.ts +24 -5
  744. package/src/tickers/metadata.ts +10 -0
  745. package/src/tickers/open-target.ts +13 -5
  746. package/src/tickers/search/index.ts +112 -35
  747. package/src/tickers/search/ranking.ts +49 -1
  748. package/src/tickers/terminal-codes.ts +79 -0
  749. package/src/tickers/ticker-changes.ts +74 -3
  750. package/src/tickers/us-listing.ts +2 -1
  751. package/src/time-series/chart-data.ts +79 -8
  752. package/src/time-series/fundamentals.ts +55 -7
  753. package/src/time-series/ice-credit.ts +17 -2
  754. package/src/time-series/live-bars.ts +21 -8
  755. package/src/time-series/live-quotes.ts +2 -3
  756. package/src/time-series/price-comparison.ts +6 -1
  757. package/src/time-series/resolve.ts +65 -10
  758. package/src/time-series/spec.ts +2 -1
  759. package/src/time-series/studies.ts +3 -3
  760. package/src/time-series/types.ts +22 -0
  761. package/src/time-series/use-chart-resolution.ts +2 -1
  762. package/src/types/config.ts +7 -0
  763. package/src/types/data-provider.ts +20 -0
  764. package/src/types/headless.ts +142 -1
  765. package/src/types/instrument.ts +6 -0
  766. package/src/types/plugin.ts +32 -9
  767. package/src/types/price-history.ts +5 -0
  768. package/src/types/ticker-changes.ts +19 -0
  769. package/src/types/ticker.ts +19 -2
  770. package/src/ui/context-menu.tsx +2 -0
  771. package/src/ui/host.tsx +40 -4
  772. package/src/ui/measured-cells.ts +13 -7
  773. package/src/ui/qr.ts +7 -5
  774. package/src/updater/index.ts +5 -5
  775. package/src/utils/calendar-date.ts +86 -27
  776. package/src/utils/currency-units.ts +26 -0
  777. package/src/utils/debug-log.ts +1 -1
  778. package/src/utils/dividend-cash.ts +48 -0
  779. package/src/utils/dom-screenshot-rasters.ts +3 -1
  780. package/src/utils/dom-screenshot.ts +14 -10
  781. package/src/utils/exchange-rate-snapshot.ts +9 -4
  782. package/src/utils/external-url.ts +1 -0
  783. package/src/utils/fiscal-period.ts +47 -0
  784. package/src/utils/format.ts +5 -2
  785. package/src/utils/forward-dividend.ts +160 -11
  786. package/src/utils/futures-generic.ts +34 -8
  787. package/src/utils/http-proxy-response.ts +2 -1
  788. package/src/utils/local-utc-offset.ts +2 -0
  789. package/src/utils/log-failure.ts +31 -0
  790. package/src/utils/option-expiry.ts +12 -12
  791. package/src/utils/price-history-integrity.ts +56 -0
  792. package/src/utils/price-history.ts +13 -1
  793. package/src/utils/sec-filings.ts +245 -0
  794. package/src/utils/selection-clipboard.ts +5 -2
  795. package/src/utils/throttled-fetch.ts +1 -0
  796. package/src/{plugins/builtin/dividend-yield/trailing-cash.ts → utils/trailing-dividend.ts} +55 -8
  797. package/src/utils/url.ts +1 -0
  798. package/src/utils/utc-time.ts +11 -0
  799. package/src/plugins/builtin/chat/share/targets.ts +0 -27
  800. package/src/renderers/dom/host/top-surface.ts +0 -119
  801. package/src/shares/dialog.tsx +0 -221
  802. package/src/shares/live.ts +0 -19
@@ -0,0 +1,213 @@
1
+ import type { FuturesContractSpec, FuturesContractTermsPayload } from "../api-client/futures-curve";
2
+ import type { ActiveQuoteDisplay } from "../market-data/market/status";
3
+ import type { PricePoint } from "../types/financials";
4
+ import type { TickerPosition, TickerRecord } from "../types/ticker";
5
+ import { classifyInstrumentType } from "../tickers/instrument-kind";
6
+ import { US_CENTS } from "../utils/currency-units";
7
+ import { parsePublicTickerKey } from "../utils/exchanges";
8
+
9
+ /**
10
+ * A futures position is held in contracts. One contract is worth its price
11
+ * times the contract's multiplier, which comes from the exchange's terms the
12
+ * way `quote` states them (Size, Point Value), and is stored on the lot as an
13
+ * option's is (`TickerPosition.multiplier`), so every reader values it alike.
14
+ * A lot whose contract size is unknown is not valued at all: a price per
15
+ * ounce times a count of contracts is no value.
16
+ */
17
+
18
+ /** What one contract counts: the price times `multiplier` is one contract's value, in the quote's currency. */
19
+ export interface FuturesContractSize {
20
+ multiplier: number;
21
+ /** One contract as the exchange words it, shortened for a row: "100 oz", "5,000 bushels", "$50 x index". */
22
+ size: string;
23
+ /**
24
+ * What the price, and so a lot's average cost, counts when it is not the
25
+ * quote's dollars: US cents (USX) for a grain or a soft, whose 5,000-bushel
26
+ * multiplier makes a value in cents. Absent where the price is in dollars.
27
+ */
28
+ currency?: typeof US_CENTS;
29
+ }
30
+
31
+ /** A future's latest confirmed exchange settlement, and the one before it where the daily history has it. */
32
+ export interface FuturesSettlement {
33
+ price: number;
34
+ /** The session it settles, YYYY-MM-DD. */
35
+ date: string;
36
+ previous: number | null;
37
+ }
38
+
39
+ /** What a portfolio reads from a future's terms: its contract size and its settlement. */
40
+ export interface PortfolioFuturesTerms {
41
+ size: FuturesContractSize | null;
42
+ settlement: FuturesSettlement | null;
43
+ }
44
+
45
+ /** A grain or a soft quotes in US cents, so a dollar point value is a hundred of its price units. */
46
+ const US_CENTS_UNIT = /^\s*US\s+cents?\b/i;
47
+
48
+ /** Whether a ticker is a futures contract (GC=F, GCZ26, CL1 typed as a future). */
49
+ export function isFuturesTicker(ticker: { metadata: Pick<TickerRecord["metadata"], "ticker" | "assetCategory"> }): boolean {
50
+ return classifyInstrumentType(ticker.metadata.assetCategory) === "future"
51
+ || /=F$/i.test(parsePublicTickerKey(ticker.metadata.ticker).symbol.trim());
52
+ }
53
+
54
+ /**
55
+ * One contract's multiplier and size from the exchange's terms: GC's $100
56
+ * point value is 100 oz a contract, ZC's $50 a cent is 5,000 bushels. Null
57
+ * without terms, so the size is never guessed.
58
+ */
59
+ export function futuresContractSize(spec: Pick<FuturesContractSpec, "unit" | "size" | "pointValue"> | null | undefined): FuturesContractSize | null {
60
+ if (!spec || !(typeof spec.pointValue === "number" && Number.isFinite(spec.pointValue) && spec.pointValue > 0)) return null;
61
+ const cents = US_CENTS_UNIT.test(spec.unit);
62
+ const multiplier = cents ? spec.pointValue * 100 : spec.pointValue;
63
+ return {
64
+ multiplier: Number(multiplier.toPrecision(12)),
65
+ size: spec.size.replace(/\btroy oz\b/, "oz").trim(),
66
+ ...(cents ? { currency: US_CENTS } : {}),
67
+ };
68
+ }
69
+
70
+ /** A count of contracts and what each one is: "1,000 × 100 oz", or the count alone when the size is unknown. */
71
+ export function futuresQuantityText(quantity: string, size: Pick<FuturesContractSize, "size"> | null | undefined): string {
72
+ return size?.size && quantity !== "—" ? `${quantity} × ${size.size}` : quantity;
73
+ }
74
+
75
+ function hasMultiplier(position: Pick<TickerPosition, "multiplier">): boolean {
76
+ return typeof position.multiplier === "number" && Number.isFinite(position.multiplier) && position.multiplier > 0;
77
+ }
78
+
79
+ /**
80
+ * The ticker with each lot that states no contract size given the one its
81
+ * terms do. Lots entered before positions were sized by contract, and lots a
82
+ * team collection sends, carry none. Such a lot of a contract that quotes in
83
+ * cents took its cost as the market quotes it, so a lot in dollars, or in no
84
+ * currency, is read in cents (a cost of 430 for corn is 430 cents). The same
85
+ * record when nothing changes.
86
+ */
87
+ export function withFuturesContractSize(ticker: TickerRecord, size: FuturesContractSize | null | undefined): TickerRecord {
88
+ if (!size || !isFuturesTicker(ticker) || ticker.metadata.positions.every(hasMultiplier)) return ticker;
89
+ return {
90
+ ...ticker,
91
+ metadata: {
92
+ ...ticker.metadata,
93
+ positions: ticker.metadata.positions.map((position) => {
94
+ if (hasMultiplier(position)) return position;
95
+ const currency = futuresLotCurrency(position, size.currency);
96
+ return { ...position, multiplier: size.multiplier, ...(currency !== position.currency ? { currency } : {}) };
97
+ }),
98
+ },
99
+ };
100
+ }
101
+
102
+ /**
103
+ * A future's lot's currency as the portfolio reads it: a lot saved before
104
+ * contract sizes, with no size and a dollar or no currency, of a future quoted
105
+ * in cents (`contractCurrency` USX) is in cents. Any other lot's own currency.
106
+ */
107
+ export function futuresLotCurrency(
108
+ position: Pick<TickerPosition, "currency" | "multiplier">,
109
+ contractCurrency: string | null | undefined,
110
+ ): string | undefined {
111
+ const stored = position.currency?.trim();
112
+ return contractCurrency && !hasMultiplier(position) && (!stored || stored.toUpperCase() === "USD") ? contractCurrency : position.currency;
113
+ }
114
+
115
+ const DAY_MS = 86_400_000;
116
+
117
+ /**
118
+ * The trading date a daily bar stands for. Bars are dated at midnight, UTC
119
+ * from Gloom Cloud but local where a runtime rebuilt the date: a bar at UTC
120
+ * midnight is that UTC day, one at this runtime's midnight its local day,
121
+ * however far east or west (UTC+13 dates the evening before in UTC), and any
122
+ * other the nearest UTC midnight's.
123
+ */
124
+ function dailyBarDay(time: number): string {
125
+ const date = new Date(time);
126
+ if (time % DAY_MS === 0) return date.toISOString().slice(0, 10);
127
+ if (date.getHours() === 0 && date.getMinutes() === 0 && date.getSeconds() === 0 && date.getMilliseconds() === 0) {
128
+ const pad = (value: number) => String(value).padStart(2, "0");
129
+ return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`;
130
+ }
131
+ return new Date(Math.round(time / DAY_MS) * DAY_MS).toISOString().slice(0, 10);
132
+ }
133
+
134
+ /** A session's close and the settlement it is checked against agree to well inside a tick. */
135
+ const SETTLEMENT_TOLERANCE = 1e-5;
136
+ /** Daily bars of a trading week: a longer gap before a settlement is not the session before it. */
137
+ const MAX_SESSION_GAP_DAYS = 5;
138
+
139
+ /**
140
+ * The confirmed settlement before the one of `date`, from a daily history
141
+ * whose bar for `date` closes at `settlement`: a close the exchange has not
142
+ * settled is skipped. Null when the history has no such bar, or more than one
143
+ * for the day, as weekly or intraday bars do, or when the bar before is
144
+ * further back than a session, so a move is never measured from another
145
+ * cadence's close.
146
+ */
147
+ export function previousFuturesSettlement(
148
+ history: readonly PricePoint[] | null | undefined,
149
+ date: string,
150
+ settlement?: number,
151
+ ): number | null {
152
+ const bars: { day: string; close: number }[] = [];
153
+ for (const point of history ?? []) {
154
+ const time = point.date instanceof Date ? point.date.getTime() : new Date(point.date).getTime();
155
+ if (!Number.isFinite(time) || point.unsettled || !Number.isFinite(point.close) || point.close <= 0) continue;
156
+ bars.push({ day: dailyBarDay(time), close: point.close });
157
+ }
158
+ bars.sort((left, right) => left.day.localeCompare(right.day));
159
+ const index = bars.findIndex((bar) => bar.day === date);
160
+ const own = bars[index];
161
+ const before = bars[index - 1];
162
+ if (!own || !before || bars[index + 1]?.day === date) return null;
163
+ if (settlement != null && Math.abs(own.close - settlement) > Math.abs(settlement) * SETTLEMENT_TOLERANCE) return null;
164
+ const gap = (Date.parse(`${date}T00:00:00Z`) - Date.parse(`${before.day}T00:00:00Z`)) / DAY_MS;
165
+ return gap <= MAX_SESSION_GAP_DAYS ? before.close : null;
166
+ }
167
+
168
+ /** What a portfolio reads from a future's terms, with the settlement before the latest when the history has it. */
169
+ export function portfolioFuturesTerms(
170
+ terms: Pick<FuturesContractTermsPayload, "spec" | "settlement"> | null | undefined,
171
+ history?: readonly PricePoint[] | null,
172
+ ): PortfolioFuturesTerms {
173
+ const settlement = terms?.settlement && Number.isFinite(terms.settlement.price) && terms.settlement.price > 0
174
+ ? {
175
+ price: terms.settlement.price,
176
+ date: terms.settlement.date,
177
+ previous: previousFuturesSettlement(history, terms.settlement.date, terms.settlement.price),
178
+ }
179
+ : null;
180
+ return { size: futuresContractSize(terms?.spec), settlement };
181
+ }
182
+
183
+ /**
184
+ * A future valued at its settlement, as `quote` gives it, with the move from
185
+ * the settlement before. The quote's own move is the Globex session's, from
186
+ * this settlement or an earlier one, so without the settlement before from the
187
+ * daily history the move is unknown rather than borrowed.
188
+ */
189
+ export function futuresSettlementDisplay(settlement: FuturesSettlement): ActiveQuoteDisplay {
190
+ const reference = settlement.previous;
191
+ if (reference == null || !(reference > 0)) return { price: settlement.price };
192
+ const change = settlement.price - reference;
193
+ return { price: settlement.price, change, changePercent: (change / reference) * 100 };
194
+ }
195
+
196
+ /**
197
+ * Every ticker with its futures lots sized by their terms (withFuturesContractSize),
198
+ * by symbol. The same array, and the same records, where nothing changes, so
199
+ * rows keyed by their records keep them.
200
+ */
201
+ export function withFuturesContractSizes(
202
+ tickers: readonly TickerRecord[],
203
+ terms: ReadonlyMap<string, Pick<PortfolioFuturesTerms, "size">> | null | undefined,
204
+ ): TickerRecord[] {
205
+ if (!terms || terms.size === 0) return tickers as TickerRecord[];
206
+ let changed = false;
207
+ const sized = tickers.map((ticker) => {
208
+ const next = withFuturesContractSize(ticker, terms.get(ticker.metadata.ticker)?.size);
209
+ changed ||= next !== ticker;
210
+ return next;
211
+ });
212
+ return changed ? sized : tickers as TickerRecord[];
213
+ }
@@ -0,0 +1,75 @@
1
+ import type { FuturesContractTermsPayload } from "../api-client/futures-curve";
2
+ import type { DataProvider } from "../types/data-provider";
3
+ import { loadFuturesContractTermsCached } from "../market-data/futures-contract";
4
+ import type { PricePoint } from "../types/financials";
5
+ import type { TickerRecord } from "../types/ticker";
6
+ import { logFailure } from "../utils/log-failure";
7
+ import {
8
+ futuresContractSize,
9
+ isFuturesTicker,
10
+ portfolioFuturesTerms,
11
+ type FuturesContractSize,
12
+ type PortfolioFuturesTerms,
13
+ } from "./futures-positions";
14
+
15
+ /** Where a portfolio reads its futures' terms and, for the move into a settlement, their daily bars. */
16
+ export interface PortfolioFuturesSources {
17
+ /** A symbol's contract terms and settlement; null when the server has none. Defaults to Gloom Cloud's, cached. */
18
+ terms?: (symbol: string) => Promise<FuturesContractTermsPayload | null>;
19
+ /** A month of daily bars, whose confirmed closes are settlements. */
20
+ history?: (symbol: string, exchange: string) => Promise<PricePoint[]>;
21
+ }
22
+
23
+ /**
24
+ * A month of a symbol's daily bars from `provider`: asked for by resolution,
25
+ * since a month's default history can be intraday bars, whose closes are no
26
+ * settlements. Bars a source says are of another cadence are none at all.
27
+ */
28
+ export function dailyFuturesHistory(
29
+ provider: Pick<DataProvider, "getPriceHistory" | "getPriceHistoryForResolutionWithMetadata">,
30
+ ): NonNullable<PortfolioFuturesSources["history"]> {
31
+ return async (symbol, exchange) => {
32
+ if (!provider.getPriceHistoryForResolutionWithMetadata) return provider.getPriceHistory(symbol, exchange, "1M");
33
+ const result = await provider.getPriceHistoryForResolutionWithMetadata(symbol, exchange, "1M", "1d");
34
+ return result.resolution == null || result.resolution === "1d" ? result.points : [];
35
+ };
36
+ }
37
+
38
+ /**
39
+ * Each futures holding's contract size and settlement, by symbol, as `quote`
40
+ * reads its terms. The settlement before the latest, which the day's move at
41
+ * the close measures from, is read from the daily bars only when `settlement`
42
+ * is asked for. A future whose terms cannot be read maps to no size and no
43
+ * settlement; any other ticker is left out.
44
+ */
45
+ export async function loadPortfolioFuturesTerms(
46
+ tickers: readonly TickerRecord[],
47
+ { settlement = false, sources = {} }: { settlement?: boolean; sources?: PortfolioFuturesSources } = {},
48
+ ): Promise<Map<string, PortfolioFuturesTerms>> {
49
+ const loadTerms = sources.terms ?? ((symbol: string) => loadFuturesContractTermsCached(symbol));
50
+ const futures = tickers.filter(isFuturesTicker);
51
+ const entries = await Promise.all(futures.map(async (ticker) => {
52
+ const symbol = ticker.metadata.ticker;
53
+ const terms = await loadTerms(symbol).catch(logFailure("portfolio-futures", "Read futures contract terms failed", null));
54
+ const history = settlement && terms?.settlement && sources.history
55
+ ? await sources.history(symbol, ticker.metadata.exchange).catch(logFailure("portfolio-futures", "Read futures settlement history failed", null))
56
+ : null;
57
+ return [symbol, portfolioFuturesTerms(terms, history)] as const;
58
+ }));
59
+ return new Map(entries);
60
+ }
61
+
62
+ /**
63
+ * The contract size a new futures lot is entered at, from its terms, so the
64
+ * lot is stored with its multiplier as an option's is. Null for any other
65
+ * holding, or a future whose terms cannot be read: the lot is then saved
66
+ * unsized and shown as such, never valued at one unit a contract.
67
+ */
68
+ export async function loadFuturesEntrySize(
69
+ ticker: TickerRecord,
70
+ load: (symbol: string) => Promise<FuturesContractTermsPayload | null> = loadFuturesContractTermsCached,
71
+ ): Promise<FuturesContractSize | null> {
72
+ if (!isFuturesTicker(ticker)) return null;
73
+ const terms = await load(ticker.metadata.ticker).catch(logFailure("portfolio-futures", "Read futures contract terms failed", null));
74
+ return futuresContractSize(terms?.spec);
75
+ }
@@ -0,0 +1,78 @@
1
+ import type { TickerPosition, TickerRecord } from "../types/ticker";
2
+ import { signedPositionDirection } from "./position-metrics";
3
+
4
+ /** The ticker's manual lots in one portfolio, in saved order. */
5
+ export function manualPortfolioLots(ticker: TickerRecord, portfolioId: string): TickerPosition[] {
6
+ return ticker.metadata.positions.filter((position) =>
7
+ position.portfolio === portfolioId && position.broker === "manual"
8
+ );
9
+ }
10
+
11
+ export interface ManualPortfolioPositionPrefill {
12
+ /** The manual lots the ticker holds in the portfolio. Setting a position replaces every one of them. */
13
+ lotCount: number;
14
+ /**
15
+ * The lot itself, or the total of several: signed shares added up, cost
16
+ * averaged by shares, in their common currency. Null with no lot, and with
17
+ * several that cannot be totalled.
18
+ */
19
+ position: TickerPosition | null;
20
+ /** The currencies of several lots that disagree. They are not totalled across currencies. */
21
+ currencies?: string[];
22
+ }
23
+
24
+ /** Drops the float noise of a sum (0.1 + 0.2) without losing a digit anyone entered. */
25
+ function tidyNumber(value: number): number {
26
+ return Number(value.toPrecision(15));
27
+ }
28
+
29
+ /**
30
+ * A ticker's manual holding in one portfolio as a single position, for what
31
+ * starts from it: the position form (so an unchanged save keeps the holding)
32
+ * and team collection sync (the quantity it sends and compares). One lot is
33
+ * itself; several are consolidated into the position a save would leave,
34
+ * instead of whichever lot came first.
35
+ */
36
+ export function getManualPortfolioPositionPrefill(ticker: TickerRecord, portfolioId: string): ManualPortfolioPositionPrefill {
37
+ const lots = manualPortfolioLots(ticker, portfolioId);
38
+ if (lots.length <= 1) {
39
+ const lot = lots[0];
40
+ // A lot marked short with a positive count is the same short as a negative count, which is how it is entered and sent.
41
+ if (!lot || lot.side !== "short" || !(lot.shares > 0)) return { lotCount: lots.length, position: lot ?? null };
42
+ const { side: _side, ...rest } = lot;
43
+ return { lotCount: 1, position: { ...rest, shares: -lot.shares } };
44
+ }
45
+
46
+ const lotCount = lots.length;
47
+ const currencies = [...new Set(lots.map((lot) => lot.currency?.trim() || ticker.metadata.currency?.trim() || ""))];
48
+ if (currencies.length > 1) return { lotCount, position: null, currencies };
49
+
50
+ // A long and a short lot offset each other, and lots of different contract
51
+ // sizes count different things: neither total is a position to save. A lot
52
+ // of no shares adds nothing to a total, so it decides neither.
53
+ const held = lots.filter((lot) => lot.shares !== 0);
54
+ const directions = new Set(held.map((lot) => signedPositionDirection(lot)));
55
+ const multipliers = new Set(held.map((lot) => lot.multiplier));
56
+ if (lots.some((lot) => !Number.isFinite(lot.shares)) || held.length === 0 || directions.size > 1 || multipliers.size > 1) {
57
+ return { lotCount, position: null };
58
+ }
59
+ const magnitude = held.reduce((sum, lot) => sum + Math.abs(lot.shares), 0);
60
+ const totalShares = [...directions][0]! * magnitude;
61
+ const costed = lots.every((lot) => Number.isFinite(lot.avgCost));
62
+ const avgCost = costed
63
+ ? tidyNumber(lots.reduce((sum, lot) => sum + Math.abs(lot.shares) * lot.avgCost!, 0) / magnitude)
64
+ : undefined;
65
+ const multiplier = held[0]!.multiplier;
66
+ return {
67
+ lotCount,
68
+ position: {
69
+ portfolio: portfolioId,
70
+ shares: tidyNumber(totalShares),
71
+ ...(avgCost !== undefined ? { avgCost } : {}),
72
+ // Lots that name no currency stay without one, as a single such lot does.
73
+ ...(currencies[0] && lots.some((lot) => lot.currency?.trim()) ? { currency: currencies[0] } : {}),
74
+ broker: "manual",
75
+ ...(multiplier !== undefined ? { multiplier } : {}),
76
+ },
77
+ };
78
+ }
@@ -1,9 +1,11 @@
1
1
  import type { AppConfig } from "../types/config";
2
2
  import type { Portfolio, PortfolioCash, TickerPosition, TickerRecord, Watchlist } from "../types/ticker";
3
- import { resolveCurrencyUnit } from "../utils/currency-units";
3
+ import { resolveCurrencyUnit, US_CENTS } from "../utils/currency-units";
4
4
  import { slugifyName } from "../utils/slugify";
5
5
  import { parseCollectionRef } from "../team/collections";
6
6
  import { findNamedCollection } from "./collection-name";
7
+ import { isFuturesTicker } from "./futures-positions";
8
+ import { manualPortfolioLots } from "./manual-lots";
7
9
 
8
10
  export interface DeleteWatchlistResult {
9
11
  config: AppConfig;
@@ -27,9 +29,46 @@ export interface RemoveTickerFromPortfolioResult {
27
29
  }
28
30
 
29
31
  export interface SetManualPortfolioPositionInput {
32
+ /** Signed: a negative number is a short. A future counts contracts. */
30
33
  shares: number;
31
34
  avgCost: number;
32
35
  currency: string;
36
+ /**
37
+ * A future's contract multiplier from its terms (futuresContractSize). Left
38
+ * out, the lot keeps the one it had, so an edit while the terms cannot be
39
+ * read does not unsize it.
40
+ */
41
+ multiplier?: number;
42
+ /** The purchase date, YYYY-MM-DD. Left out, a single manual lot keeps the one it had. */
43
+ dateAcquired?: string;
44
+ /**
45
+ * The rate the cost was bought at: one unit of `currency` in `costFx.currency`.
46
+ * Null clears it; left out, a single manual lot in the same currency keeps the one it had.
47
+ */
48
+ costFx?: { rate: number; currency: string } | null;
49
+ }
50
+
51
+ /** What a position's size counts, as its field and messages name it. */
52
+ export type PositionQuantityLabel = "Contracts" | "Shares";
53
+
54
+ /** A future is held in contracts, everything else in shares. */
55
+ export function positionQuantityLabel(
56
+ ticker: { metadata: Pick<TickerRecord["metadata"], "ticker" | "assetCategory"> } | null | undefined,
57
+ ): PositionQuantityLabel {
58
+ return ticker && isFuturesTicker(ticker) ? "Contracts" : "Shares";
59
+ }
60
+
61
+ /**
62
+ * A signed size as every manual entry takes it: a finite number, negative for
63
+ * a short, never zero, which is no position. The message names what it
64
+ * counts.
65
+ */
66
+ export function validatePositionShares(shares: number, label: PositionQuantityLabel = "Shares"): string | null {
67
+ if (!Number.isFinite(shares)) return label === "Contracts" ? "Contracts must be a number." : "Shares must be a number.";
68
+ if (shares !== 0) return null;
69
+ return label === "Contracts"
70
+ ? "Contracts cannot be 0. Enter a negative number for a short."
71
+ : "Shares cannot be 0. Enter a negative number for a short.";
33
72
  }
34
73
 
35
74
  export interface SetManualPortfolioPositionResult {
@@ -58,24 +97,28 @@ export function findPortfolio(config: AppConfig, rawName: string): Portfolio | n
58
97
  }
59
98
 
60
99
  export function getManualPortfolioPosition(ticker: TickerRecord, portfolioId: string): TickerPosition | null {
61
- return ticker.metadata.positions.find((position) =>
62
- position.portfolio === portfolioId && position.broker === "manual"
63
- ) ?? null;
100
+ return manualPortfolioLots(ticker, portfolioId)[0] ?? null;
64
101
  }
65
102
 
103
+ /**
104
+ * The currency a position is saved in: the one typed, else what a future's
105
+ * contract prices in (USX, US cents, for corn, so a cost typed as quoted
106
+ * counts cents), else the listing's, the portfolio's or the base currency.
107
+ */
66
108
  export function resolveManualPositionCurrency(
67
109
  rawCurrency: string | undefined,
68
110
  ticker: TickerRecord,
69
111
  portfolio: Portfolio,
70
112
  baseCurrency: string | undefined,
113
+ contractCurrency?: string | null,
71
114
  ): string {
72
- return (rawCurrency?.trim() || ticker.metadata.currency || portfolio.currency || baseCurrency || "USD").toUpperCase();
115
+ return (rawCurrency?.trim() || contractCurrency?.trim() || ticker.metadata.currency || portfolio.currency || baseCurrency || "USD").toUpperCase();
73
116
  }
74
117
 
75
- /** A plain ISO code in major units (AUD), else null: pence-type units and free text never total a portfolio. */
118
+ /** A plain ISO code in major units (AUD), else null: pence-type units, US cents and free text never total a portfolio. */
76
119
  function majorCurrencyCode(value: string | undefined): string | null {
77
120
  const raw = value?.trim() ?? "";
78
- return /^[A-Z]{3}$/.test(raw) && resolveCurrencyUnit(raw).divisor === 1 ? raw : null;
121
+ return /^[A-Z]{3}$/.test(raw) && raw !== US_CENTS && resolveCurrencyUnit(raw).divisor === 1 ? raw : null;
79
122
  }
80
123
 
81
124
  /** The currencies of a portfolio's open positions, as entered (or the listing's when a position has none). */
@@ -357,9 +400,8 @@ export function setManualPortfolioPosition(
357
400
  input: SetManualPortfolioPositionInput,
358
401
  ): SetManualPortfolioPositionResult {
359
402
  const nextCurrency = input.currency.trim().toUpperCase();
360
- if (!Number.isFinite(input.shares) || input.shares <= 0) {
361
- throw new Error("Shares must be greater than 0.");
362
- }
403
+ const sharesError = validatePositionShares(input.shares, positionQuantityLabel(ticker));
404
+ if (sharesError) throw new Error(sharesError);
363
405
  if (!Number.isFinite(input.avgCost)) {
364
406
  throw new Error("Average cost must be a valid number.");
365
407
  }
@@ -371,8 +413,18 @@ export function setManualPortfolioPosition(
371
413
  const replacedPositionCount = replacedPositions.length;
372
414
  // Editing a single snapshot (for example after a split) does not change its
373
415
  // acquisition date. A consolidated replacement of several lots has no one date.
374
- const dateAcquired = replacedPositions.length === 1 && replacedPositions[0]?.broker === "manual"
375
- ? replacedPositions[0].dateAcquired : undefined;
416
+ const single = replacedPositions.length === 1 && replacedPositions[0]?.broker === "manual" ? replacedPositions[0] : null;
417
+ const dateAcquired = input.dateAcquired ?? single?.dateAcquired;
418
+ // The rate the cost was bought at goes with its cost: a lot kept in its currency keeps it unless it is replaced or cleared.
419
+ const keptCostFx = single && single.currency?.trim().toUpperCase() === nextCurrency
420
+ && typeof single.costFxRate === "number" && single.costFxCurrency
421
+ ? { rate: single.costFxRate, currency: single.costFxCurrency } : null;
422
+ const costFx = input.costFx === undefined ? keptCostFx : input.costFx;
423
+ if (costFx && !(Number.isFinite(costFx.rate) && costFx.rate > 0)) throw new Error("The cost FX rate must be a positive number.");
424
+ // A contract's size does not change with the count held; one the lots agree on carries over.
425
+ const keptMultipliers = new Set(replacedPositions.map((position) => position.multiplier));
426
+ const keptMultiplier = keptMultipliers.size === 1 ? [...keptMultipliers][0] : undefined;
427
+ const multiplier = validMultiplier(input.multiplier) ?? validMultiplier(keptMultiplier);
376
428
  const nextPositions = ticker.metadata.positions.filter((position) => position.portfolio !== portfolioId);
377
429
  const addedMembership = !ticker.metadata.portfolios.includes(portfolioId);
378
430
 
@@ -383,6 +435,8 @@ export function setManualPortfolioPosition(
383
435
  currency: nextCurrency,
384
436
  broker: "manual",
385
437
  ...(dateAcquired ? { dateAcquired } : {}),
438
+ ...(costFx ? { costFxRate: costFx.rate, costFxCurrency: costFx.currency.trim().toUpperCase() } : {}),
439
+ ...(multiplier !== undefined ? { multiplier } : {}),
386
440
  });
387
441
 
388
442
  return {
@@ -396,6 +450,10 @@ export function setManualPortfolioPosition(
396
450
  };
397
451
  }
398
452
 
453
+ function validMultiplier(value: number | undefined): number | undefined {
454
+ return typeof value === "number" && Number.isFinite(value) && value > 0 ? value : undefined;
455
+ }
456
+
399
457
  export function deleteManualPortfolio(
400
458
  config: AppConfig,
401
459
  tickers: TickerRecord[],