@gloom-sh/terminal 0.20.17 → 0.20.19

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 (453) hide show
  1. package/package.json +3 -1
  2. package/src/account/auth-dialog.tsx +19 -1
  3. package/src/account/billing.ts +2 -1
  4. package/src/account/heard-from-question.tsx +235 -0
  5. package/src/account/heard-from.ts +97 -0
  6. package/src/api-client/cot.ts +5 -6
  7. package/src/api-client/data.ts +14 -3
  8. package/src/api-client/heard-from.ts +72 -0
  9. package/src/api-client/index.ts +64 -6
  10. package/src/api-client/mna.ts +18 -0
  11. package/src/api-client/request.ts +162 -40
  12. package/src/api-client/supply-chain.ts +9 -0
  13. package/src/api-client/types/billing.ts +35 -1
  14. package/src/api-client/types/news.ts +45 -0
  15. package/src/api-client/types/world-venues.ts +9 -0
  16. package/src/app/global-shortcuts.ts +5 -3
  17. package/src/app/pro-welcome/keys.ts +27 -0
  18. package/src/app/pro-welcome/model.ts +158 -0
  19. package/src/app/pro-welcome/row.tsx +176 -0
  20. package/src/app/pro-welcome/use-pro-welcome.ts +156 -0
  21. package/src/app/runtime/external-profile-changes.ts +135 -0
  22. package/src/app.tsx +37 -4
  23. package/src/architecture/core-builtin-allowlist.json +1 -1
  24. package/src/architecture/floating-promise-allowlist.json +1 -2
  25. package/src/architecture/shortcut-labels-allowlist.json +1 -0
  26. package/src/cli/alert-listing.ts +98 -0
  27. package/src/cli/commands/market.ts +191 -39
  28. package/src/cli/commands/overview.ts +7 -1
  29. package/src/cli/commands/plugins.ts +3 -2
  30. package/src/cli/commands/search.ts +30 -6
  31. package/src/cli/commands/ticker.ts +13 -6
  32. package/src/cli/context.ts +24 -5
  33. package/src/cli/csv-export.ts +2 -1
  34. package/src/cli/desktop-pane-shot-browser.ts +3 -1
  35. package/src/cli/desktop-pane-shot-view.ts +0 -1
  36. package/src/cli/desktop-pane-shot.ts +276 -52
  37. package/src/cli/errors.ts +3 -9
  38. package/src/cli/exit-codes.ts +1 -1
  39. package/src/cli/glossary.ts +65 -11
  40. package/src/cli/help.ts +1 -1
  41. package/src/cli/history-demergers.ts +117 -0
  42. package/src/cli/history-rows.ts +8 -4
  43. package/src/cli/index.ts +2 -1
  44. package/src/cli/known-gaps.ts +16 -0
  45. package/src/cli/known-us-stocks.ts +18 -0
  46. package/src/cli/listing-arg.ts +192 -38
  47. package/src/cli/pane-functions/catalog-snapshot-build.ts +83 -0
  48. package/src/cli/pane-functions/catalog-snapshot.json +877 -0
  49. package/src/cli/pane-functions/catalog-snapshot.ts +62 -0
  50. package/src/cli/pane-functions/catalog.ts +50 -16
  51. package/src/cli/pane-functions/data.ts +16 -4
  52. package/src/cli/pane-functions/dom.ts +54 -8
  53. package/src/cli/pane-functions/freshness.ts +39 -4
  54. package/src/cli/pane-functions/function-help.ts +3 -3
  55. package/src/cli/pane-functions/headless.ts +9 -1
  56. package/src/cli/pane-functions/index.ts +175 -50
  57. package/src/cli/pane-functions/report-notices.ts +10 -0
  58. package/src/cli/pane-functions/resolver.ts +11 -7
  59. package/src/cli/pane-functions/screenshot-assessment.ts +38 -10
  60. package/src/cli/pane-functions/screenshot-data-evidence.ts +7 -15
  61. package/src/cli/pane-functions/screenshot-payload.ts +36 -1
  62. package/src/cli/pane-functions/screenshot-render.ts +24 -9
  63. package/src/cli/pane-functions/screenshot-types.ts +9 -0
  64. package/src/cli/quote-answer.ts +33 -17
  65. package/src/cli/registry.ts +22 -2
  66. package/src/cli/result.ts +22 -4
  67. package/src/cli/scroll-truncation.ts +7 -2
  68. package/src/cli/series-search.ts +45 -6
  69. package/src/cli/shot-temp-dir.ts +4 -9
  70. package/src/cli/ticker-resolution.ts +1 -1
  71. package/src/cli/unreachable.ts +21 -0
  72. package/src/components/chart/composite/drawing-store.ts +11 -7
  73. package/src/components/chart/composite/format.ts +1 -0
  74. package/src/components/chart/composite/legend.tsx +48 -20
  75. package/src/components/chart/composite/panel-surface/panel-cursor.tsx +3 -3
  76. package/src/components/chart/composite/panel-surface/plot-gestures.ts +9 -2
  77. package/src/components/chart/composite/panel-surface.tsx +1 -1
  78. package/src/components/chart/composite/price-axis-labels.tsx +7 -5
  79. package/src/components/chart/composite/tools.ts +164 -39
  80. package/src/components/chart-table/header.tsx +11 -2
  81. package/src/components/chart-table/layout.ts +16 -17
  82. package/src/components/command-bar/pane-templates/items.ts +17 -1
  83. package/src/components/command-bar/routes/root/provider-search.ts +10 -1
  84. package/src/components/command-bar/routes/root/results.ts +34 -2
  85. package/src/components/command-bar/routes/root/runtime.ts +19 -4
  86. package/src/components/command-bar/routes/ticker-search/results.ts +5 -0
  87. package/src/components/command-bar/routes/ticker-search/route.ts +5 -0
  88. package/src/components/command-bar/selection-runtime.ts +29 -5
  89. package/src/components/command-bar/surface/index.tsx +4 -1
  90. package/src/components/command-bar/workflow/alert.ts +32 -13
  91. package/src/components/data-table/view.tsx +15 -2
  92. package/src/components/form-modal/content.tsx +9 -4
  93. package/src/components/index.ts +1 -1
  94. package/src/components/layout/header.tsx +9 -5
  95. package/src/components/layout/pane/capture-status.ts +6 -0
  96. package/src/components/layout/pane/footer/index.tsx +2 -0
  97. package/src/components/layout/pane/footer/model.ts +123 -17
  98. package/src/components/layout/pane/header.tsx +16 -2
  99. package/src/components/layout/pane/status-footer.ts +24 -0
  100. package/src/components/market-board/index.tsx +4 -2
  101. package/src/components/onboarding/onboarding-frame.tsx +6 -2
  102. package/src/components/onboarding/onboarding-keyboard.ts +7 -1
  103. package/src/components/onboarding/onboarding-wizard.tsx +3 -1
  104. package/src/components/onboarding/portfolio-step/positions-panel.tsx +24 -15
  105. package/src/components/onboarding/setup-cards.ts +36 -0
  106. package/src/components/onboarding/use-onboarding-progress.ts +22 -1
  107. package/src/components/onboarding/wizard-account.ts +6 -1
  108. package/src/components/onboarding/wizard-model.ts +32 -6
  109. package/src/components/onboarding/wizard-positions.ts +1 -1
  110. package/src/components/price-performance.tsx +26 -8
  111. package/src/components/reader/article-reader.tsx +12 -5
  112. package/src/components/sign-in-gate.tsx +3 -1
  113. package/src/components/toggle-list.tsx +6 -8
  114. package/src/components/ui/confirm-dialog.tsx +47 -7
  115. package/src/components/ui/data-table/opentui/index.tsx +7 -0
  116. package/src/components/ui/data-table/types.ts +8 -0
  117. package/src/components/ui/display.tsx +17 -2
  118. package/src/components/ui/index.ts +1 -1
  119. package/src/components/ui/stat-grid.tsx +4 -0
  120. package/src/components/ui/status.tsx +13 -1
  121. package/src/components/ui/table-layout.ts +34 -2
  122. package/src/components/use-pane-notice-footer.tsx +16 -3
  123. package/src/data/config/store/index.ts +31 -0
  124. package/src/data/config/store/node.ts +61 -11
  125. package/src/data/config/store/normalize.ts +4 -6
  126. package/src/data/config/store/shared-file.ts +309 -0
  127. package/src/data/profile-merge.ts +299 -0
  128. package/src/data/sqlite/checkpointer.ts +11 -1
  129. package/src/data/sqlite/database.ts +1 -1
  130. package/src/data/ticker-repository.ts +134 -10
  131. package/src/data/ticker-store.ts +67 -0
  132. package/src/data/ticker-writes.ts +5 -0
  133. package/src/i18n/es.ts +27 -0
  134. package/src/i18n/ja.ts +27 -0
  135. package/src/i18n/ko.ts +27 -0
  136. package/src/i18n/zh-cn.ts +27 -0
  137. package/src/i18n/zh-tw.ts +27 -0
  138. package/src/layout-marketplace/gallery-desktop.tsx +2 -2
  139. package/src/market-data/ah-pair.ts +122 -0
  140. package/src/market-data/coordinator/entries.ts +6 -4
  141. package/src/market-data/coordinator/index.ts +14 -3
  142. package/src/market-data/depositary-pair.ts +6 -2
  143. package/src/market-data/futures-board.ts +36 -29
  144. package/src/market-data/futures-contract.ts +37 -1
  145. package/src/market-data/hooks.tsx +33 -2
  146. package/src/market-data/market/change-basis.ts +11 -1
  147. package/src/market-data/market/header-market.ts +11 -0
  148. package/src/market-data/market/status.ts +40 -4
  149. package/src/market-data/performance.ts +127 -32
  150. package/src/market-data/quotes/time.ts +5 -2
  151. package/src/market-data/split-terms.ts +28 -0
  152. package/src/news/types.ts +28 -0
  153. package/src/notifications/app-badge.ts +2 -3
  154. package/src/notifications/app-notifier.ts +5 -0
  155. package/src/plugins/builtin/account-management/footer.ts +1 -1
  156. package/src/plugins/builtin/account-management/keyboard.ts +4 -0
  157. package/src/plugins/builtin/account-management/model.ts +1 -0
  158. package/src/plugins/builtin/account-management/pane.tsx +75 -7
  159. package/src/plugins/builtin/account-management/payment-recovery-row.tsx +12 -5
  160. package/src/plugins/builtin/account-management/pro-cancel.tsx +197 -0
  161. package/src/plugins/builtin/account-management/trial-cancel.ts +1 -1
  162. package/src/plugins/builtin/alerts/cli-move.ts +2 -2
  163. package/src/plugins/builtin/alerts/cli.ts +101 -48
  164. package/src/plugins/builtin/alerts/command.ts +39 -9
  165. package/src/plugins/builtin/alerts/constants.ts +10 -0
  166. package/src/plugins/builtin/alerts/earnings-listing.ts +20 -0
  167. package/src/plugins/builtin/alerts/event-rows.ts +9 -3
  168. package/src/plugins/builtin/alerts/events-pane.tsx +16 -10
  169. package/src/plugins/builtin/alerts/format.ts +24 -8
  170. package/src/plugins/builtin/alerts/headless.ts +12 -6
  171. package/src/plugins/builtin/alerts/index.tsx +97 -16
  172. package/src/plugins/builtin/alerts/move-checks.ts +7 -0
  173. package/src/plugins/builtin/alerts/option-contract.ts +197 -0
  174. package/src/plugins/builtin/alerts/pane.tsx +1 -1
  175. package/src/plugins/builtin/alerts/price.ts +30 -5
  176. package/src/plugins/builtin/alerts/pro-rules.ts +62 -0
  177. package/src/plugins/builtin/alerts/quotes.ts +26 -2
  178. package/src/plugins/builtin/alerts/research-builder.ts +5 -10
  179. package/src/plugins/builtin/alerts/scheduled.ts +6 -1
  180. package/src/plugins/builtin/alerts/types.ts +7 -0
  181. package/src/plugins/builtin/analytics/account-returns.ts +1 -1
  182. package/src/plugins/builtin/analytics/manual-value.ts +61 -0
  183. package/src/plugins/builtin/analytics/pane-model.ts +2 -2
  184. package/src/plugins/builtin/analytics/risk-book.ts +7 -7
  185. package/src/plugins/builtin/analytics/risk-client.ts +27 -14
  186. package/src/plugins/builtin/analytics/risk-headless.ts +13 -8
  187. package/src/plugins/builtin/analytics/risk-model.ts +92 -4
  188. package/src/plugins/builtin/analytics/risk-pane.tsx +85 -38
  189. package/src/plugins/builtin/awards/pane.tsx +1 -1
  190. package/src/plugins/builtin/broker-trading/orders.tsx +2 -2
  191. package/src/plugins/builtin/buildout/company/pane.tsx +4 -14
  192. package/src/plugins/builtin/catalysts/model.ts +2 -1
  193. package/src/plugins/builtin/central-bank-rates/model.ts +8 -2
  194. package/src/plugins/builtin/central-bank-rates/pane.tsx +5 -3
  195. package/src/plugins/builtin/chart-composer/chart-spec.ts +5 -0
  196. package/src/plugins/builtin/chart-composer/cli-options.ts +9 -5
  197. package/src/plugins/builtin/chart-composer/data-catalog-pane.tsx +2 -6
  198. package/src/plugins/builtin/chart-composer/headless-schema.ts +14 -10
  199. package/src/plugins/builtin/chart-composer/headless.ts +2 -0
  200. package/src/plugins/builtin/chart-composer/index.tsx +17 -5
  201. package/src/plugins/builtin/chart-composer/pane.tsx +19 -6
  202. package/src/plugins/builtin/chart-composer/viewport-labels.ts +2 -17
  203. package/src/plugins/builtin/chat/controller/notifications.ts +1 -0
  204. package/src/plugins/builtin/chat/index.tsx +0 -1
  205. package/src/plugins/builtin/cloud/auth-actions.tsx +11 -6
  206. package/src/plugins/builtin/cloud/company-picker.tsx +5 -3
  207. package/src/plugins/builtin/cloud/upgrade-command.ts +1 -1
  208. package/src/plugins/builtin/commodities-energy/index.tsx +1 -1
  209. package/src/plugins/builtin/company-kpis/headless.ts +10 -5
  210. package/src/plugins/builtin/company-kpis/latest.ts +45 -0
  211. package/src/plugins/builtin/company-kpis/model.ts +57 -15
  212. package/src/plugins/builtin/company-kpis/pane.tsx +22 -8
  213. package/src/plugins/builtin/composite/alt-data.ts +20 -0
  214. package/src/plugins/builtin/composite/application.ts +14 -0
  215. package/src/plugins/builtin/composite/broker.ts +12 -0
  216. package/src/plugins/builtin/composite/credit.ts +33 -0
  217. package/src/plugins/builtin/composite/crypto.ts +10 -0
  218. package/src/plugins/builtin/composite/earnings.ts +12 -0
  219. package/src/plugins/builtin/composite/filings.ts +13 -0
  220. package/src/plugins/builtin/composite/futures-commodities.ts +23 -0
  221. package/src/plugins/builtin/composite/global-markets.ts +12 -0
  222. package/src/plugins/builtin/composite/options-volatility.ts +23 -0
  223. package/src/plugins/builtin/composite/ownership.ts +23 -0
  224. package/src/plugins/builtin/composite/portfolio.ts +10 -0
  225. package/src/plugins/builtin/composite/quant.ts +15 -0
  226. package/src/plugins/builtin/composite/rates-macro.ts +30 -0
  227. package/src/plugins/builtin/composite/screeners.ts +11 -0
  228. package/src/plugins/builtin/composite/shared.ts +11 -0
  229. package/src/plugins/builtin/composite/ticker-core.ts +36 -0
  230. package/src/plugins/builtin/congress-trades/headless.ts +31 -3
  231. package/src/plugins/builtin/congress-trades/model.ts +9 -5
  232. package/src/plugins/builtin/correlation/index.tsx +13 -17
  233. package/src/plugins/builtin/correlation/matrix/model.ts +18 -0
  234. package/src/plugins/builtin/cot/client.ts +2 -3
  235. package/src/plugins/builtin/cot/headless.ts +16 -16
  236. package/src/plugins/builtin/cot/index.tsx +6 -6
  237. package/src/plugins/builtin/cot/model.ts +25 -5
  238. package/src/plugins/builtin/cot/pane.tsx +11 -6
  239. package/src/plugins/builtin/cot/series.ts +11 -8
  240. package/src/plugins/builtin/cpi/model.ts +15 -4
  241. package/src/plugins/builtin/cpi/pane.tsx +29 -7
  242. package/src/plugins/builtin/dividend-yield/client.ts +57 -16
  243. package/src/plugins/builtin/dividend-yield/headless.ts +17 -11
  244. package/src/plugins/builtin/dividend-yield/model.ts +4 -3
  245. package/src/plugins/builtin/dividend-yield/pane.tsx +22 -18
  246. package/src/plugins/builtin/dividend-yield/ranking.ts +1 -1
  247. package/src/plugins/builtin/dividend-yield/types.ts +4 -0
  248. package/src/plugins/builtin/dividend-yield/view.ts +23 -12
  249. package/src/plugins/builtin/doe/model.ts +30 -0
  250. package/src/plugins/builtin/doe/pane.tsx +8 -2
  251. package/src/plugins/builtin/earnings/board-table.ts +9 -4
  252. package/src/plugins/builtin/earnings/fiscal-quarter.ts +39 -0
  253. package/src/plugins/builtin/earnings/headless.ts +16 -6
  254. package/src/plugins/builtin/earnings/history-model.ts +6 -4
  255. package/src/plugins/builtin/earnings/history-table.ts +7 -4
  256. package/src/plugins/builtin/earnings-calls/calendar.tsx +4 -3
  257. package/src/plugins/builtin/earnings-calls/pane.tsx +8 -2
  258. package/src/plugins/builtin/earnings-ripple/pane.tsx +2 -2
  259. package/src/plugins/builtin/econ/calendar-model.ts +16 -0
  260. package/src/plugins/builtin/econ/index.tsx +7 -2
  261. package/src/plugins/builtin/equity-screener/headless.ts +4 -1
  262. package/src/plugins/builtin/equity-screener/model.ts +7 -6
  263. package/src/plugins/builtin/estimate-revisions/headless.ts +1 -1
  264. package/src/plugins/builtin/exposure/model.ts +10 -0
  265. package/src/plugins/builtin/exposure/pane.tsx +10 -3
  266. package/src/plugins/builtin/futures/model.ts +14 -1
  267. package/src/plugins/builtin/futures/series.ts +1 -8
  268. package/src/plugins/builtin/fx-matrix/amount.ts +15 -1
  269. package/src/plugins/builtin/fx-matrix/headless.ts +12 -6
  270. package/src/plugins/builtin/fx-matrix/index.tsx +25 -7
  271. package/src/plugins/builtin/fx-matrix/settings.ts +9 -4
  272. package/src/plugins/builtin/insider/detail.tsx +36 -7
  273. package/src/plugins/builtin/insider/filing-stories.ts +110 -0
  274. package/src/plugins/builtin/insider/headless.ts +37 -2
  275. package/src/plugins/builtin/insider/index.tsx +79 -10
  276. package/src/plugins/builtin/insider/model.ts +43 -5
  277. package/src/plugins/builtin/ipo-calendar/client.ts +11 -1
  278. package/src/plugins/builtin/ipo-calendar/model.ts +3 -7
  279. package/src/plugins/builtin/jobs/headless.ts +2 -1
  280. package/src/plugins/builtin/jobs/model.ts +6 -0
  281. package/src/plugins/builtin/jobs/pane.tsx +8 -3
  282. package/src/plugins/builtin/kelly-sizer/pane.tsx +9 -4
  283. package/src/plugins/builtin/market-valuation/pane.tsx +22 -10
  284. package/src/plugins/builtin/mna/detail.tsx +67 -6
  285. package/src/plugins/builtin/mna/headless.ts +128 -13
  286. package/src/plugins/builtin/mna/model.ts +219 -16
  287. package/src/plugins/builtin/mna/pane.tsx +34 -6
  288. package/src/plugins/builtin/money-markets/model.ts +14 -5
  289. package/src/plugins/builtin/money-markets/pane.tsx +4 -3
  290. package/src/plugins/builtin/news/wire/news/detail-view.tsx +118 -10
  291. package/src/plugins/builtin/news/wire/news/footer.ts +3 -8
  292. package/src/plugins/builtin/news/wire/news/story-evidence.ts +178 -0
  293. package/src/plugins/builtin/options/analytics.ts +1 -1
  294. package/src/plugins/builtin/options/view.tsx +18 -11
  295. package/src/plugins/builtin/options-positioning/model.ts +11 -0
  296. package/src/plugins/builtin/options-positioning/pane.tsx +22 -1
  297. package/src/plugins/builtin/options-scenario/client.ts +49 -8
  298. package/src/plugins/builtin/options-scenario/csp-screen-pane.tsx +22 -6
  299. package/src/plugins/builtin/options-scenario/csp-screen.ts +39 -12
  300. package/src/plugins/builtin/options-scenario/headless.ts +7 -3
  301. package/src/plugins/builtin/options-scenario/model.ts +33 -2
  302. package/src/plugins/builtin/options-scenario/pane.tsx +3 -4
  303. package/src/plugins/builtin/options-scenario/strategy-screen.ts +7 -5
  304. package/src/plugins/builtin/pe-band/client.ts +13 -1
  305. package/src/plugins/builtin/pe-band/headless.ts +2 -2
  306. package/src/plugins/builtin/pe-band/model.ts +63 -10
  307. package/src/plugins/builtin/pe-band/pane.tsx +5 -5
  308. package/src/plugins/builtin/perps/cascade.ts +4 -3
  309. package/src/plugins/builtin/perps/markets-section.tsx +5 -2
  310. package/src/plugins/builtin/perps/model.ts +4 -3
  311. package/src/plugins/builtin/portfolio-list/allocation-rows.ts +26 -7
  312. package/src/plugins/builtin/portfolio-list/cli/portfolio-command.ts +66 -13
  313. package/src/plugins/builtin/portfolio-list/cli/render.ts +76 -33
  314. package/src/plugins/builtin/portfolio-list/headless.ts +69 -22
  315. package/src/plugins/builtin/portfolio-list/pane/data.ts +3 -3
  316. package/src/plugins/builtin/portfolio-list/pane/index.tsx +29 -14
  317. package/src/plugins/builtin/portfolio-list/summary/index.tsx +2 -2
  318. package/src/plugins/builtin/portfolio-list/table.tsx +3 -2
  319. package/src/plugins/builtin/relative-rotation/pane.tsx +2 -3
  320. package/src/plugins/builtin/research/corporate-actions-pane.tsx +33 -14
  321. package/src/plugins/builtin/research/event-model.ts +43 -19
  322. package/src/plugins/builtin/research/headless.ts +8 -1
  323. package/src/plugins/builtin/research/relative-valuation-pane.tsx +19 -17
  324. package/src/plugins/builtin/research-search/index.tsx +3 -1
  325. package/src/plugins/builtin/scanner/denied.tsx +16 -4
  326. package/src/plugins/builtin/scanner/flow-pane.tsx +1 -1
  327. package/src/plugins/builtin/scanner/hilo-pane.tsx +1 -1
  328. package/src/plugins/builtin/sec/filing-display.tsx +14 -2
  329. package/src/plugins/builtin/sec/headless.ts +42 -4
  330. package/src/plugins/builtin/sec/index.tsx +21 -1
  331. package/src/plugins/builtin/sectors/index.tsx +6 -9
  332. package/src/plugins/builtin/sectors/sector-model.ts +1 -1
  333. package/src/plugins/builtin/shared/cloud-upgrade.ts +1 -1
  334. package/src/plugins/builtin/shared/earnings-report.ts +49 -5
  335. package/src/plugins/builtin/shared/options-pro-copy.ts +34 -0
  336. package/src/plugins/builtin/shared/report-freshness.ts +2 -3
  337. package/src/plugins/builtin/shared/statement-currency.ts +23 -0
  338. package/src/plugins/builtin/shared/ticker-surface.ts +1 -1
  339. package/src/plugins/builtin/supply-chain/client.ts +34 -9
  340. package/src/plugins/builtin/supply-chain/evidence.ts +3 -2
  341. package/src/plugins/builtin/supply-chain/flow.tsx +4 -3
  342. package/src/plugins/builtin/supply-chain/graph-model.ts +14 -7
  343. package/src/plugins/builtin/supply-chain/graph-pane.tsx +3 -1
  344. package/src/plugins/builtin/supply-chain/graph.tsx +6 -3
  345. package/src/plugins/builtin/supply-chain/headless.ts +19 -4
  346. package/src/plugins/builtin/supply-chain/model.ts +50 -6
  347. package/src/plugins/builtin/supply-chain/pane.tsx +79 -18
  348. package/src/plugins/builtin/themes/headless.ts +4 -4
  349. package/src/plugins/builtin/themes/model.ts +11 -8
  350. package/src/plugins/builtin/themes/pane.tsx +2 -2
  351. package/src/plugins/builtin/ticker-detail/adr-pair/ah.ts +62 -0
  352. package/src/plugins/builtin/ticker-detail/adr-pair/headless.ts +119 -20
  353. package/src/plugins/builtin/ticker-detail/adr-pair/model.ts +51 -1
  354. package/src/plugins/builtin/ticker-detail/adr-pair/tab.tsx +25 -14
  355. package/src/plugins/builtin/ticker-detail/financials/model.ts +22 -32
  356. package/src/plugins/builtin/ticker-detail/financials/tab.tsx +7 -9
  357. package/src/plugins/builtin/ticker-detail/headless-schema.ts +2 -0
  358. package/src/plugins/builtin/ticker-detail/headless.ts +28 -12
  359. package/src/plugins/builtin/ticker-detail/overview/board-lot.ts +21 -0
  360. package/src/plugins/builtin/ticker-detail/overview/model.ts +28 -2
  361. package/src/plugins/builtin/ticker-detail/overview/pane.tsx +8 -0
  362. package/src/plugins/builtin/ticker-detail/overview-tab.tsx +68 -13
  363. package/src/plugins/builtin/ticker-detail/quote-monitor/card.tsx +9 -2
  364. package/src/plugins/builtin/ticker-detail/quote-monitor/index.tsx +5 -2
  365. package/src/plugins/builtin/volatility/model.ts +17 -0
  366. package/src/plugins/builtin/volatility/pane.tsx +16 -7
  367. package/src/plugins/builtin/world-indices/index.tsx +2 -0
  368. package/src/plugins/builtin/world-indices/table.tsx +15 -0
  369. package/src/plugins/builtin/world-venue-map/evidence.ts +3 -2
  370. package/src/plugins/builtin/world-venue-map/headless.ts +32 -18
  371. package/src/plugins/builtin/world-venue-map/index.ts +19 -6
  372. package/src/plugins/builtin/world-venue-map/layered-pane.tsx +9 -5
  373. package/src/plugins/builtin/world-venue-map/layers.ts +33 -11
  374. package/src/plugins/builtin/world-venue-map/map.tsx +12 -0
  375. package/src/plugins/builtin/world-venue-map/model.ts +6 -1
  376. package/src/plugins/builtin/world-venue-map/pane.tsx +35 -6
  377. package/src/plugins/builtin/world-venue-map/place.ts +119 -0
  378. package/src/plugins/builtin/world-venue-map/venue-header.tsx +5 -3
  379. package/src/plugins/catalog-browser.ts +10 -1
  380. package/src/plugins/catalog-data.ts +20 -0
  381. package/src/plugins/catalog-lazy.ts +51 -0
  382. package/src/plugins/catalog-ui.ts +16 -18
  383. package/src/plugins/host-smoke.ts +5 -2
  384. package/src/portfolio/allocation.ts +79 -19
  385. package/src/portfolio/cash-balances.ts +76 -0
  386. package/src/portfolio/mutations.ts +43 -8
  387. package/src/public/__snapshots__/public-api.test.ts.snap +1 -0
  388. package/src/renderers/browser/activity.ts +16 -0
  389. package/src/renderers/browser/app-badge-host.ts +14 -0
  390. package/src/renderers/browser/main.tsx +5 -0
  391. package/src/renderers/browser/notifications.ts +103 -0
  392. package/src/renderers/browser/ui-host.tsx +4 -0
  393. package/src/renderers/desktop/window-layouts.ts +14 -0
  394. package/src/renderers/dom/data-table/index.tsx +27 -4
  395. package/src/renderers/dom/data-table/row.tsx +2 -0
  396. package/src/renderers/dom/host/tabs.tsx +57 -8
  397. package/src/renderers/dom/styles.css +13 -5
  398. package/src/renderers/electrobun/bun/desktop/backend-requests.ts +4 -0
  399. package/src/renderers/electrobun/bun/desktop/backend.ts +22 -1
  400. package/src/renderers/electrobun/bun/window/native-min-size.ts +6 -1
  401. package/src/renderers/electrobun/shared/protocol.ts +4 -0
  402. package/src/renderers/electrobun/view/cli-pane-shot-frame.tsx +50 -12
  403. package/src/renderers/electrobun/view/http-fetch.ts +3 -2
  404. package/src/renderers/electrobun/view/remote/ticker-repository.ts +10 -0
  405. package/src/series/standalone-catalog.ts +5 -4
  406. package/src/series/standalone.ts +13 -7
  407. package/src/sources/gloomberb-cloud/index.ts +22 -9
  408. package/src/sources/gloomberb-cloud/news.ts +35 -0
  409. package/src/sources/gloomberb-cloud/perpetuals.ts +60 -3
  410. package/src/sources/provider-errors.ts +34 -7
  411. package/src/sources/provider-router/financials.ts +20 -13
  412. package/src/sources/provider-router/history.ts +32 -6
  413. package/src/sources/provider-router/index.ts +4 -0
  414. package/src/sources/provider-router/search.ts +1 -0
  415. package/src/sync/collections-contributor.ts +3 -1
  416. package/src/sync/config-merge.ts +10 -1
  417. package/src/sync/sanitize.ts +26 -2
  418. package/src/tickers/company-name-listing.ts +16 -2
  419. package/src/tickers/listing-fate.ts +12 -8
  420. package/src/tickers/renamed-listings.ts +43 -10
  421. package/src/tickers/search/home-listing.ts +28 -0
  422. package/src/tickers/search/index.ts +19 -7
  423. package/src/tickers/terminal-codes.ts +11 -1
  424. package/src/time-series/base-series.ts +39 -6
  425. package/src/time-series/chart-seed.ts +2 -2
  426. package/src/time-series/history-quality.ts +4 -1
  427. package/src/time-series/hooks.ts +2 -0
  428. package/src/time-series/price-comparison.ts +17 -23
  429. package/src/time-series/reporting.ts +1 -1
  430. package/src/time-series/resolution.ts +13 -0
  431. package/src/time-series/resolve-context.ts +6 -0
  432. package/src/time-series/resolve.ts +42 -3
  433. package/src/time-series/spec.ts +2 -2
  434. package/src/time-series/types.ts +3 -2
  435. package/src/types/data-provider.ts +11 -0
  436. package/src/types/financials.ts +48 -4
  437. package/src/types/headless.ts +1 -0
  438. package/src/types/issuer-listings.ts +2 -0
  439. package/src/types/plugin-notifications.ts +3 -0
  440. package/src/types/price-history.ts +6 -4
  441. package/src/types/ticker.ts +10 -2
  442. package/src/ui/host.tsx +2 -0
  443. package/src/utils/cli-output.ts +1 -1
  444. package/src/utils/declared-dividends.ts +13 -1
  445. package/src/utils/dividend-cash.ts +5 -1
  446. package/src/utils/exchange-announcements.ts +7 -2
  447. package/src/utils/forward-dividend.ts +4 -3
  448. package/src/utils/fundamentals.ts +40 -0
  449. package/src/utils/network-failure.ts +2 -0
  450. package/src/utils/price-history-integrity.ts +9 -1
  451. package/src/utils/remove-folder.ts +37 -0
  452. package/src/utils/trailing-dividend.ts +1 -1
  453. package/src/plugins/builtin/composite-plugins.ts +0 -285
@@ -4,6 +4,7 @@
4
4
  // off; every check and every re-arm for the next session stay in plugin resume
5
5
  // state, as IV levels' readings do.
6
6
  import type { QuoteChangeBasis } from "../../../market-data/market/change-basis";
7
+ import type { ExtendedSession } from "../../../market-data/market/status";
7
8
  import type { QuoteDataSource } from "../../../types/financials";
8
9
  import type { AlertRule } from "./types";
9
10
 
@@ -23,6 +24,8 @@ export interface MoveCheck {
23
24
  currency?: string;
24
25
  exchange?: string;
25
26
  pence?: true;
27
+ /** The extended session the move's price is a print of (`AlertRule.lastQuoteSession`). */
28
+ print?: ExtendedSession;
26
29
  /** Why the last check had no quote. */
27
30
  error?: string;
28
31
  /** It went off, and waits for a later session to arm it again. */
@@ -36,6 +39,7 @@ const isText = (value: unknown): value is string => typeof value === "string" &&
36
39
  const isNumber = (value: unknown): value is number => typeof value === "number" && Number.isFinite(value);
37
40
  const BASIS_KINDS = new Set(["close", "settle", "previous close", "utc day", "24h"]);
38
41
  const SOURCES = new Set<QuoteDataSource>(["live", "delayed", "snapshot"]);
42
+ const PRINTS = new Set<ExtendedSession>(["PRE", "POST", "OVERNIGHT"]);
39
43
 
40
44
  function readBasis(value: unknown): QuoteChangeBasis | undefined {
41
45
  if (!value || typeof value !== "object") return undefined;
@@ -64,6 +68,7 @@ export function readMoveChecks(value: unknown): Record<string, MoveCheck> {
64
68
  ...isText(check.currency) ? { currency: check.currency } : {},
65
69
  ...isText(check.exchange) ? { exchange: check.exchange } : {},
66
70
  ...check.pence === true ? { pence: true as const } : {},
71
+ ...PRINTS.has(check.print as ExtendedSession) ? { print: check.print as ExtendedSession } : {},
67
72
  ...isText(check.error) ? { error: check.error } : {},
68
73
  ...check.fired === true ? { fired: true as const } : {},
69
74
  ...isNumber(check.firedAt) ? { firedAt: check.firedAt } : {},
@@ -88,6 +93,7 @@ function moveCheckOf(alert: AlertRule): MoveCheck | null {
88
93
  ...alert.lastQuoteCurrency ? { currency: alert.lastQuoteCurrency } : {},
89
94
  ...alert.lastQuoteExchange ? { exchange: alert.lastQuoteExchange } : {},
90
95
  ...alert.lastQuotePence ? { pence: true as const } : {},
96
+ ...alert.lastQuoteSession ? { print: alert.lastQuoteSession } : {},
91
97
  ...alert.lastCheckError ? { error: alert.lastCheckError } : {},
92
98
  ...alert.status === "triggered" ? { fired: true as const, ...alert.triggeredAt ? { firedAt: alert.triggeredAt } : {} } : {},
93
99
  ...alert.moveSession ? { session: alert.moveSession } : {},
@@ -114,6 +120,7 @@ function withMoveCheck(alert: AlertRule, check: MoveCheck | undefined): AlertRul
114
120
  ...check.currency ? { lastQuoteCurrency: check.currency } : {},
115
121
  ...check.exchange ? { lastQuoteExchange: check.exchange } : {},
116
122
  ...check.pence ? { lastQuotePence: true } : {},
123
+ ...check.print ? { lastQuoteSession: check.print } : {},
117
124
  ...check.error ? { lastCheckError: check.error } : {},
118
125
  ...check.fired ? { status: "triggered" as const, ...check.firedAt ? { triggeredAt: check.firedAt } : {} } : {},
119
126
  ...check.session ? { moveSession: check.session } : {},
@@ -0,0 +1,197 @@
1
+ // An option contract as people type it for an IV spike alert (`SPY 680C 11/19`,
2
+ // `SPY241119C680`, `SPY Nov 19 680 call`), read against the listed chain into
3
+ // the one OCC contract it names. Anything that names none, or more than one,
4
+ // is refused with the OCC form and a contract that is listed.
5
+ import type { OptionContract, OptionsChain } from "../../../types/financials";
6
+ import { expiryIsoDate, isLiveOptionExpiry } from "../../../utils/option-expiry";
7
+ import { optionContractName } from "../../../utils/options";
8
+
9
+ /** One contract as typed: its root, expiry (the year left out when it was), side and strike. */
10
+ export interface LooseOptionContract {
11
+ root: string;
12
+ /** Null when the year was not typed (`11/19`): the next listed expiry on that day. */
13
+ year: number | null;
14
+ month: number;
15
+ day: number;
16
+ side: "C" | "P";
17
+ strike: number;
18
+ }
19
+
20
+ /** An OCC contract as a rule keeps it: root, YYMMDD, C or P, the strike times 1,000 in 8 digits. */
21
+ export const OCC_CONTRACT = /^(?:O:)?[A-Z.]{1,6}\d{6}[CP]\d{8}$/i;
22
+
23
+ const MONTHS = ["JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"];
24
+ const NUMBER = String.raw`\$?(\d+(?:\.\d+)?)`;
25
+ const SIDE_WORDS: Readonly<Record<string, "C" | "P">> = { C: "C", CALL: "C", CALLS: "C", P: "P", PUT: "P", PUTS: "P" };
26
+
27
+ const two = (value: number) => String(value).padStart(2, "0");
28
+
29
+ /** The OCC symbol of a contract: `SPY261119C00680000`. */
30
+ function occContractSymbol(root: string, year: number, month: number, day: number, side: "C" | "P", strike: number): string {
31
+ return `${root}${two(year % 100)}${two(month)}${two(day)}${side}${String(Math.round(strike * 1000)).padStart(8, "0")}`;
32
+ }
33
+
34
+ function validDay(year: number, month: number, day: number): boolean {
35
+ const date = new Date(Date.UTC(year, month - 1, day));
36
+ return date.getUTCFullYear() === year && date.getUTCMonth() === month - 1 && date.getUTCDate() === day;
37
+ }
38
+
39
+ function monthOf(token: string): number | null {
40
+ const index = MONTHS.findIndex((month) => token.startsWith(month) && /^[A-Z]+$/.test(token) && token.length <= 9);
41
+ return index < 0 ? null : index + 1;
42
+ }
43
+
44
+ const fullYear = (text: string) => text.length === 4 ? Number(text) : 2000 + Number(text.replace(/^'/, ""));
45
+
46
+ /**
47
+ * A contract typed loosely: an OCC symbol whose strike is not padded
48
+ * (`SPY241119C680`), or the root, an expiry (`11/19`, `11/19/26`,
49
+ * `2026-11-19`, `261119`, `Nov 19 '26`, `19 Nov`) and the strike with its side
50
+ * (`680C`, `C680`, `680 call`) in any order. Null for anything else.
51
+ */
52
+ export function parseLooseOptionContract(text: string): LooseOptionContract | null {
53
+ const typed = text.trim().toUpperCase().replace(/^O:/, "").replace(/,/g, "");
54
+ const compact = new RegExp(String.raw`^([A-Z][A-Z.]{0,5})\s*(\d{2})(\d{2})(\d{2})\s*([CP])\s*${NUMBER}$`).exec(typed);
55
+ if (compact) {
56
+ const [, root, yy, mm, dd, side, strike] = compact;
57
+ const year = 2000 + Number(yy);
58
+ // Eight digits with no point are OCC's own strike, in thousandths.
59
+ const value = /^\d{8}$/.test(strike!) ? Number(strike) / 1000 : Number(strike);
60
+ return validDay(year, Number(mm), Number(dd)) && value > 0
61
+ ? { root: root!, year, month: Number(mm), day: Number(dd), side: side as "C" | "P", strike: value } : null;
62
+ }
63
+ const [root = "", ...tokens] = typed.split(/\s+/);
64
+ if (!/^[A-Z][A-Z.]{0,5}$/.test(root) || tokens.length === 0) return null;
65
+ let date: { year: number | null; month: number; day: number } | null = null;
66
+ let side: "C" | "P" | null = null;
67
+ let strike: number | null = null;
68
+ const rest: string[] = [];
69
+ for (const token of tokens) {
70
+ const withSide = new RegExp(`^${NUMBER}([CP])$`).exec(token) ?? new RegExp(`^([CP])${NUMBER}$`).exec(token);
71
+ const slash = /^(\d{1,2})\/(\d{1,2})(?:\/(\d{2}|\d{4}))?$/.exec(token);
72
+ const iso = /^(\d{4})-(\d{2})-(\d{2})$/.exec(token);
73
+ const yymmdd = /^(\d{2})(\d{2})(\d{2})$/.exec(token);
74
+ if (withSide && strike == null) {
75
+ const [first, second] = [withSide[1]!, withSide[2]!];
76
+ side = (/^[CP]$/.test(first) ? first : second) as "C" | "P";
77
+ strike = Number(/^[CP]$/.test(first) ? second : first);
78
+ } else if (slash && !date) date = { month: Number(slash[1]), day: Number(slash[2]), year: slash[3] ? fullYear(slash[3]) : null };
79
+ else if (iso && !date) date = { year: Number(iso[1]), month: Number(iso[2]), day: Number(iso[3]) };
80
+ else if (yymmdd && !date) date = { year: 2000 + Number(yymmdd[1]), month: Number(yymmdd[2]), day: Number(yymmdd[3]) };
81
+ else rest.push(token);
82
+ }
83
+ // A month by name takes the day beside it (`Nov 19`, `19 Nov`), and a year after them (`'26`, `2026`).
84
+ const named = rest.findIndex((token) => monthOf(token) != null);
85
+ if (named >= 0 && !date) {
86
+ const month = monthOf(rest[named]!)!;
87
+ const dayAt = /^\d{1,2}$/.test(rest[named + 1] ?? "") ? named + 1 : /^\d{1,2}$/.test(rest[named - 1] ?? "") ? named - 1 : -1;
88
+ if (dayAt < 0) return null;
89
+ const after = rest[Math.max(named, dayAt) + 1] ?? "";
90
+ // `'26` and `2026` are years; a bare `26` only while a strike is typed beside it, else it is the strike.
91
+ const strikeLater = rest.slice(Math.max(named, dayAt) + 2).some((token) => new RegExp(`^${NUMBER}$`).test(token));
92
+ const yearToken = /^'\d{2}$|^20\d{2}$/.test(after) || (/^\d{2}$/.test(after) && (strike != null || strikeLater)) ? after : null;
93
+ date = { month, day: Number(rest[dayAt]), year: yearToken ? fullYear(yearToken) : null };
94
+ rest.splice(Math.min(named, dayAt), yearToken ? 3 : 2);
95
+ }
96
+ for (const token of rest) {
97
+ if (SIDE_WORDS[token] && !side) side = SIDE_WORDS[token]!;
98
+ else if (new RegExp(`^${NUMBER}$`).test(token) && strike == null) strike = Number(token.replace(/^\$/, ""));
99
+ else return null;
100
+ }
101
+ if (!date || !side || strike == null || !(strike > 0)) return null;
102
+ if (date.month < 1 || date.month > 12 || !validDay(date.year ?? 2028, date.month, date.day)) return null;
103
+ return { root, ...date, side, strike };
104
+ }
105
+
106
+ /** How a contract was typed, in words: `SPY Nov 19 $680 Call`. */
107
+ function describe(contract: LooseOptionContract): string {
108
+ return `${contract.root} ${MONTHS[contract.month - 1]![0]}${MONTHS[contract.month - 1]!.slice(1).toLowerCase()} ${contract.day}`
109
+ + `${contract.year != null ? ` '${two(contract.year % 100)}` : ""} $${contract.strike} ${contract.side === "C" ? "Call" : "Put"}`;
110
+ }
111
+
112
+ /** The next `month`/`day` from `now` (this year's, or next year's once it has passed), as a chain stamps an expiry. */
113
+ function nextDay(month: number, day: number, now: number): number {
114
+ const year = new Date(now).getUTCFullYear();
115
+ const thisYear = Date.UTC(year, month - 1, day);
116
+ return (thisYear >= Date.UTC(year, new Date(now).getUTCMonth(), new Date(now).getUTCDate()) ? thisYear : Date.UTC(year + 1, month - 1, day)) / 1000;
117
+ }
118
+
119
+ /** What the chain's listing is read through: the expiries with no argument, one expiry's contracts with its stamp. */
120
+ export type ChainReader = (expiration?: number) => Promise<Pick<OptionsChain, "expirationDates" | "calls" | "puts">>;
121
+
122
+ /** The OCC form, said where a contract does not read or names none listed. */
123
+ export function occFormText(example: string): string {
124
+ return `An IV spike follows one OCC contract: the root, the expiry as YYMMDD, C or P, and the strike times 1,000 in 8 digits, such as ${example}`;
125
+ }
126
+
127
+ /** A contract's OCC symbol as listed (SPXW for an SPX weekly), else as built from what it is. */
128
+ function listedSymbol(contract: OptionContract, built: string): string {
129
+ const symbol = contract.contractSymbol?.trim().toUpperCase().replace(/^O:/, "") ?? "";
130
+ return OCC_CONTRACT.test(symbol) ? symbol : built;
131
+ }
132
+
133
+ /**
134
+ * The one listed contract a loosely typed one names, with the note saying what
135
+ * it was read as. A year left out is the next listed expiry on that day. A
136
+ * contract past its expiry is returned as typed, for the rule to refuse it as
137
+ * expired; one that names no listed contract throws, with the OCC form and a
138
+ * listed contract to copy, and one that names several (SPX and SPXW on one
139
+ * expiry) throws naming each, never picking one.
140
+ */
141
+ export async function resolveLooseOptionContract(
142
+ typed: string,
143
+ contract: LooseOptionContract,
144
+ readChain: ChainReader,
145
+ now: number,
146
+ ): Promise<{ contract: string; readAs: string | null }> {
147
+ const { root, month, day, side, strike } = contract;
148
+ if (contract.year != null) {
149
+ const stamp = Date.UTC(contract.year, month - 1, day) / 1000;
150
+ // Expired: the rule refuses it, naming the expiry and the underlying's live ones.
151
+ if (!isLiveOptionExpiry(stamp, now)) return { contract: occContractSymbol(root, contract.year, month, day, side, strike), readAs: null };
152
+ }
153
+ const listing = await readChain();
154
+ const live = [...new Set(listing.expirationDates)].filter((stamp) => isLiveOptionExpiry(stamp, now)).sort((a, b) => a - b);
155
+ const sameDay = (stamp: number) => {
156
+ const date = new Date(stamp * 1000);
157
+ return date.getUTCMonth() + 1 === month && date.getUTCDate() === day && (contract.year == null || date.getUTCFullYear() === contract.year);
158
+ };
159
+ const expiry = live.find(sameDay);
160
+ const contracts = expiry == null ? [] : (await readChain(expiry))[side === "C" ? "calls" : "puts"];
161
+ // Every contract the day lists at that strike and side, once each: two roots can list one (SPX and SPXW).
162
+ const expiryDate = expiry == null ? null : new Date(expiry * 1000);
163
+ const matches = expiryDate == null ? [] : [...new Set(contracts.filter((entry) => Math.abs(entry.strike - strike) < 1e-6)
164
+ .map((entry) => listedSymbol(entry, occContractSymbol(root, expiryDate.getUTCFullYear(), month, day, side, strike))))];
165
+ if (matches.length > 1) {
166
+ throw new Error(`"${typed.trim()}" (${describe(contract)}) matches ${matches.length} listed contracts: ${matches.join(", ")}. `
167
+ + "An IV spike follows one: name it by its OCC symbol.");
168
+ }
169
+ const [symbol] = matches;
170
+ if (symbol) return { contract: symbol, readAs: `Read "${typed.trim()}" as ${symbol} (${optionContractName(symbol) ?? symbol}).` };
171
+ // A listed contract to copy: the typed strike's nearest on the typed day's expiry, else on the live expiry nearest that day.
172
+ const typedDay = contract.year != null ? Date.UTC(contract.year, month - 1, day) / 1000 : nextDay(month, day, now);
173
+ const exampleExpiry = expiry ?? live.reduce<number | undefined>((best, stamp) =>
174
+ best == null || Math.abs(stamp - typedDay) < Math.abs(best - typedDay) ? stamp : best, undefined);
175
+ const exampleChain = exampleExpiry == null ? [] : expiry != null ? contracts
176
+ : (await readChain(exampleExpiry))[side === "C" ? "calls" : "puts"];
177
+ const nearest = exampleChain.reduce<OptionContract | null>((best, entry) => !best || Math.abs(entry.strike - strike) < Math.abs(best.strike - strike) ? entry : best, null);
178
+ const exampleDate = exampleExpiry == null ? null : new Date(exampleExpiry * 1000);
179
+ const example = nearest && exampleDate
180
+ ? listedSymbol(nearest, occContractSymbol(root, exampleDate.getUTCFullYear(), exampleDate.getUTCMonth() + 1, exampleDate.getUTCDate(), side, nearest.strike))
181
+ : occContractExample(now);
182
+ const why = expiry == null
183
+ ? `${root} lists no live expiry on ${MONTHS[month - 1]![0]}${MONTHS[month - 1]!.slice(1).toLowerCase()} ${day}${contract.year != null ? ` ${contract.year}` : ""}`
184
+ : `${root}'s ${expiryIsoDate(expiry)} expiry lists no $${strike} ${side === "C" ? "call" : "put"}`;
185
+ throw new Error(`"${typed.trim()}" (${describe(contract)}) names no listed contract: ${why}. ${occFormText(example)}; gloom options ${root} lists them.`);
186
+ }
187
+
188
+ /**
189
+ * An OCC contract that has not expired, for an example where no chain gives
190
+ * one: an AAPL call on the monthly expiry (the third Friday) two months from `now`.
191
+ */
192
+ export function occContractExample(now: number | Date = Date.now()): string {
193
+ const at = new Date(now);
194
+ const month = new Date(Date.UTC(at.getUTCFullYear(), at.getUTCMonth() + 2, 1));
195
+ const thirdFriday = 1 + ((5 - month.getUTCDay() + 7) % 7) + 14;
196
+ return occContractSymbol("AAPL", month.getUTCFullYear(), month.getUTCMonth() + 1, thirdFriday, "C", 300);
197
+ }
@@ -116,7 +116,7 @@ function AlertDetail({ alert, scrollRef }: { alert: AlertRule; scrollRef: RefObj
116
116
  <KeyValueRow {...DETAIL_ROW} label="Listing" value={listingWithCurrency(alertListing(alert), alert.lastQuoteCurrency)} />
117
117
  {/* With no quote the reason above says why; the price and its distance wait for one. */}
118
118
  {basis ? <KeyValueRow {...DETAIL_ROW} label="Close date" value={alert.lastDailyClose ?? `Awaiting ${basis}`} /> : null}
119
- {reason ? null : <KeyValueRow {...DETAIL_ROW} label={alert.move ? "Move" : "Current"} value={formatCurrentPrice(alert, 24)} />}
119
+ {reason ? null : <KeyValueRow {...DETAIL_ROW} label={alert.move ? "Move" : "Current"} value={formatCurrentPrice(alert, 24, { words: true })} />}
120
120
  {/* What a move is measured from, as the quote's change line names it. */}
121
121
  {!reason && alert.move ? <KeyValueRow {...DETAIL_ROW} label="From" value={moveBasisText(alert.lastMoveBasis).replace(/^vs /, "")} tone="muted" /> : null}
122
122
  {/* The two readings that place the quadrant, as RRG states them. */}
@@ -9,12 +9,37 @@ const PRICE_FORMAT = "type 81000 or 81k";
9
9
 
10
10
  const scaled = (value: number, scale: number) => Number((value * scale).toPrecision(15));
11
11
 
12
- /** A price as `parsePastedNumber` reads it, and `81k` is 81000: the scale applies to either reading of a comma and three digits. */
12
+ /** A dollar price's marks: `$757.75`, `US$ 1,000`, `757.75 USD`. */
13
+ const DOLLAR_LEAD = /^(?:US)?\$\s*/i;
14
+ const DOLLAR_TAIL = /\s*USD$/i;
15
+
16
+ /**
17
+ * A price without the dollar marks it was typed with (`$757.75`, `US$ 1,000`,
18
+ * `757.75 USD`), and whether it had one: a dollar price is written the US way,
19
+ * so a comma in it groups thousands.
20
+ */
21
+ function withoutDollarMark(text: string): { text: string; dollars: boolean } {
22
+ const trimmed = text.trim();
23
+ const bare = trimmed.replace(DOLLAR_LEAD, "").replace(DOLLAR_TAIL, "");
24
+ return { text: bare, dollars: bare !== trimmed };
25
+ }
26
+
27
+ /** Whether a word is a dollar mark alone (`$`, `US$`, `USD`), as a shell splits `$ 757.75` or `757.75 USD`. */
28
+ export const isDollarMark = (word: string): boolean => /^(?:US\$|\$|USD)$/i.test(word.trim());
29
+
30
+ /**
31
+ * A price as `parsePastedNumber` reads it, and `81k` is 81000: the scale
32
+ * applies to either reading of a comma and three digits. A dollar price
33
+ * (`$1,000`, `1,000 USD`) is written the US way, so its comma groups thousands
34
+ * and it reads two ways no more.
35
+ */
13
36
  export function parseAlertPrice(text: string): PastedNumber {
14
- const match = SCALED_PRICE.exec(text.trim());
15
- if (!match) return parsePastedNumber(text);
16
- const scale = PRICE_SCALES[match[2]!.toLowerCase() as keyof typeof PRICE_SCALES];
17
- const base = parsePastedNumber(match[1]);
37
+ const { text: bare, dollars } = withoutDollarMark(text);
38
+ const match = SCALED_PRICE.exec(bare);
39
+ const scale = match ? PRICE_SCALES[match[2]!.toLowerCase() as keyof typeof PRICE_SCALES] : 1;
40
+ const base = parsePastedNumber(match ? match[1] : bare);
41
+ if (base.kind === "ambiguous" && dollars) return { kind: "number", value: scaled(base.thousands, scale) };
42
+ if (!match) return base;
18
43
  if (base.kind === "number") return { kind: "number", value: scaled(base.value, scale) };
19
44
  if (base.kind === "ambiguous") return { kind: "ambiguous", thousands: scaled(base.thousands, scale), decimal: scaled(base.decimal, scale) };
20
45
  return base;
@@ -0,0 +1,62 @@
1
+ // The event rules Gloom Cloud checks only for an account with Pro, and what
2
+ // every surface says about them: ALRT's Events tab, Add Event Alert, `fn ALRT`
3
+ // and `alerts add` and `alerts list`. A leaf module, so the form's fields
4
+ // (research-builder) and the rows (event-rows) read the same words, which
5
+ // live in shared/options-pro-copy beside the FLOW wall's.
6
+ import { resolvePlanAccess, type PlanAccessUser } from "../../../api-client/plan-rules";
7
+ import { proAlertFormNote, proAlertFree, proAlertSavedNote, proAlertsFree } from "../shared/options-pro-copy";
8
+
9
+ /**
10
+ * The rules Gloom Cloud checks only for an account with Pro, as docs/usage.md marks them: options flow and an
11
+ * IV spike. A free account saves them, and nothing checks them; signing in alone does not change that.
12
+ */
13
+ const PRO_RULE_NAMES: Readonly<Record<string, string>> = { options_flow: "options flow", iv_spike: "IV spike" };
14
+
15
+ /** Whether a rule is checked only for an account with Gloom Cloud Pro (options flow, an IV spike). */
16
+ export function checkedOnlyWithPro(rule: { kind: string }): boolean {
17
+ return Object.hasOwn(PRO_RULE_NAMES, rule.kind);
18
+ }
19
+
20
+ /**
21
+ * Whether the account in hand gets its Pro rules checked: signed in with Pro. Signed in before the account has
22
+ * loaded (`user` unknown), it is taken to, so a Pro start does not flash Needs Pro.
23
+ */
24
+ export function checksProRules(signedIn: boolean, user: PlanAccessUser | null | undefined): boolean {
25
+ return signedIn && (user ? resolvePlanAccess(user).hasProAccess : true);
26
+ }
27
+
28
+ /** The state of a waiting Pro rule nothing checks without Pro, as `alerts list` and its CSV write it. */
29
+ export const NEEDS_PRO = "needs Pro";
30
+
31
+ /** The Events tab's status for a selected rule that reads Needs Pro: what is free instead, the row saying it needs Pro. */
32
+ export function proRuleStatus(rule: { kind: string }): string {
33
+ return proAlertFree(rule.kind);
34
+ }
35
+
36
+ /** What Add Event Alert says under a Pro kind's first field, before the rule is saved; null for any other kind. */
37
+ export function proRuleFormNote(kind: string): string | null {
38
+ return checkedOnlyWithPro({ kind }) ? proAlertFormNote(kind) : null;
39
+ }
40
+
41
+ /** "options flow", "options flow and IV spike": the Pro kinds among `rules`, for a note that names them. */
42
+ function proRuleNames(rules: readonly { kind: string }[]): string {
43
+ const names = [...new Set(rules.flatMap((rule) => checkedOnlyWithPro(rule) ? [PRO_RULE_NAMES[rule.kind]!] : []))];
44
+ return names.length > 1 ? `${names.slice(0, -1).join(", ")} and ${names.at(-1)}` : names[0] ?? "";
45
+ }
46
+
47
+ /**
48
+ * What a list says once about its Pro rules (options flow, an IV spike): Gloom Cloud checks them only with Pro.
49
+ * `waiting` are those nothing checks now (signed out, or on a free plan), which read Needs Pro.
50
+ */
51
+ export function needsProNote(rules: readonly { kind: string }[], waiting: number): string {
52
+ const names = proRuleNames(rules);
53
+ const lead = waiting > 0
54
+ ? `${waiting === 1 ? "1 event alert needs" : `${waiting} event alerts need`} Pro (${names}).`
55
+ : `${names.charAt(0).toUpperCase()}${names.slice(1)} alerts are checked only with Pro.`;
56
+ return `${lead} ${proAlertsFree(rules.map((rule) => rule.kind))}`;
57
+ }
58
+
59
+ /** What `alerts add` and the saved toast add after a Pro rule saved without Pro: checked only with Pro, and what is free. */
60
+ export function savedWithoutProNote(rule: { kind: string }): string {
61
+ return ` ${proAlertSavedNote(rule.kind)}`;
62
+ }
@@ -1,10 +1,12 @@
1
1
  import type { DataProvider } from "../../../types/data-provider";
2
2
  import { chunked } from "../../../utils/concurrency";
3
3
  import type { Quote } from "../../../types/financials";
4
- import { getActiveQuoteDisplay } from "../../../market-data/market/status";
4
+ import { extendedPrintSession, getActiveQuoteDisplay } from "../../../market-data/market/status";
5
5
  import { isPenceQuotedLine } from "../../../market-data/market/format";
6
6
  import { isQuoteStaleForCurrentSession } from "../../../market-data/quotes/freshness";
7
7
  import { canonicalExchange } from "../../../utils/exchanges";
8
+ import { futuresContractByWord } from "../../../market-data/futures-board";
9
+ import { isFuturesInstrument } from "../../../market-data/futures-contract";
8
10
  import { readMove } from "./move";
9
11
  import type { AlertRule } from "./types";
10
12
 
@@ -63,7 +65,7 @@ export async function resolveAlertQuotes(
63
65
  }
64
66
 
65
67
  /** A quote an alert may be judged on, at the price its active session shows; throws for a stale one or one with no price. */
66
- function alertQuote(quote: Quote, symbol: string): Quote {
68
+ export function alertQuote(quote: Quote, symbol: string): Quote {
67
69
  // A last known price is not the price now: it must neither trigger an alert nor set its baseline.
68
70
  if (isQuoteStaleForCurrentSession(quote)) throw new Error(`The quote for "${symbol}" is stale.`);
69
71
  const display = getActiveQuoteDisplay(quote);
@@ -91,6 +93,7 @@ export function quoteAlertFields(
91
93
  | "lastQuoteCurrency"
92
94
  | "lastQuoteExchange"
93
95
  | "lastQuotePence"
96
+ | "lastQuoteSession"
94
97
  > & { lastCheckError?: undefined } {
95
98
  const exchange = quote.listingExchangeName || quote.exchangeName;
96
99
  return {
@@ -103,6 +106,8 @@ export function quoteAlertFields(
103
106
  ...(exchange ? { lastQuoteExchange: canonicalExchange(exchange) } : {}),
104
107
  // A London line in pence writes its levels in pence; a quote that is not clears it.
105
108
  lastQuotePence: isPenceQuotedLine(quote) || undefined,
109
+ // An after-hours print says so wherever the reading is shown, as `quote` names it beside Last.
110
+ lastQuoteSession: extendedPrintSession(quote, quote.price) ?? undefined,
106
111
  lastCheckError: undefined,
107
112
  };
108
113
  }
@@ -134,6 +139,25 @@ const priceText = (value: number) => value.toLocaleString("en-US", Math.abs(valu
134
139
  ? { maximumFractionDigits: 2 }
135
140
  : { maximumSignificantDigits: 4 });
136
141
 
142
+ /**
143
+ * "GOLD is Gold.com, Inc.; for Gold, the future is GC=F (gloom alerts add
144
+ * GC=F below 3700).": a commodity's word typed bare that a security trades as
145
+ * (GOLD is Gold.com, WTI is W&T Offshore), with the future it may have meant,
146
+ * as `quote` says it. Null for any other symbol, a venue named, or a future.
147
+ */
148
+ export function commodityFutureNote(
149
+ typed: string,
150
+ quote: Pick<Quote, "name" | "instrumentType">,
151
+ retry: ((symbol: string) => string | null) | null = null,
152
+ ): string | null {
153
+ const symbol = typed.trim().toUpperCase();
154
+ if (symbol.includes(":")) return null;
155
+ const contract = futuresContractByWord(symbol);
156
+ if (!contract || isFuturesInstrument(symbol, quote.instrumentType)) return null;
157
+ const command = retry?.(contract.symbol);
158
+ return `${symbol} is ${quote.name?.trim() || "a security"}; for ${contract.name}, the future is ${contract.symbol}${command ? ` (${command})` : ""}.`;
159
+ }
160
+
137
161
  /**
138
162
  * Why a price target is refused: more than ten times the last price, or under
139
163
  * a tenth of it, which is a slip or another instrument's price (bitcoin's,
@@ -2,6 +2,8 @@ import type { GloomPlugin } from "../../../types/plugin";
2
2
  import { DEFAULT_LEAD_DAYS, isResearchAlertKind, MACRO_ALERT_EVENTS, normalizeResearchRule, readResearchRule, RESEARCH_ALERT_FORMS, type IvLevelMetric, type MacroAlertEvent, type ResearchAlertKind } from "./research-rules";
3
3
  import type { EventAlertRule } from "./events";
4
4
  import { isLiveOptionExpiry, parseOptionExpiration } from "../../../utils/option-expiry";
5
+ import { proRuleFormNote } from "./pro-rules";
6
+ import { occContractExample } from "./option-contract";
5
7
 
6
8
  /** What a macro event is called in a rule, a list and a notification. */
7
9
  export const MACRO_EVENT_NAMES: Record<MacroAlertEvent, string> = { cpi: "CPI release", fomc: "FOMC decision" };
@@ -16,16 +18,6 @@ export function formatIvLevel(metric: IvLevelMetric, value: number): string {
16
18
  const rounded = Number(value.toFixed(2));
17
19
  return metric === "atm" ? `${rounded}%` : `${rounded > 0 ? "+" : ""}${rounded} pts`;
18
20
  }
19
- /**
20
- * An OCC contract that has not expired, for the IV spike form's example: an
21
- * AAPL call on the monthly expiry (the third Friday) two months from `now`.
22
- */
23
- function occContractExample(now = new Date()): string {
24
- const month = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth() + 2, 1));
25
- const thirdFriday = 1 + ((5 - month.getUTCDay() + 7) % 7) + 14;
26
- const two = (value: number) => String(value).padStart(2, "0");
27
- return `AAPL${two(month.getUTCFullYear() % 100)}${two(month.getUTCMonth() + 1)}${two(thirdFriday)}C00300000`;
28
- }
29
21
  type Command = Parameters<Parameters<NonNullable<GloomPlugin["setup"]>>[0]["registerCommand"]>[0];
30
22
  type Field = NonNullable<Command["wizard"]>[number];
31
23
  /** An earnings alert goes off days before the report, or once its results are out. */
@@ -68,6 +60,9 @@ export const researchWizardFields: Field[] = RESEARCH_FORM_KINDS.flatMap(kind =>
68
60
  }
69
61
  if (kind === "iv_level") fields.push({key:"threshold",label:"Level (IV %, RR vol pts)",type:"number",placeholder:"35",required:true});
70
62
  if (kind === "unusual_volume" || kind === "short_interest_change" || kind === "iv_spike") fields.push({key:"threshold",label:kind === "unusual_volume" ? "Volume / prior 20-session average" : kind === "iv_spike" ? "IV rise (percentage points)" : "Settlement change (%)",type:"number",defaultValue:kind === "unusual_volume" ? "2" : kind === "iv_spike" ? "5" : "10"});
63
+ // A Pro kind says so under its first field, before anything is saved: a free account saves it, and nothing checks it.
64
+ const proNote = proRuleFormNote(kind);
65
+ if (proNote && fields[0]) fields[0] = { ...fields[0], body: [proNote] };
71
66
  return fields.map(field => ({...field, key:`${kind}:${field.key}`, dependsOn: kind === "earnings_date" && field.key === "leadDays"
72
67
  // The lead time is for an alert before the date, not one waiting for results.
73
68
  ? [{key:"event",value:kind}, {key:"earnings_date:when",value:"before"}]
@@ -164,6 +164,11 @@ export function scheduledTriggerText(rule: Pick<ScheduledRule, "leadDays" | "tri
164
164
  return `${rule.leadDays} day${rule.leadDays === 1 ? "" : "s"} before${rule.prints ? " and when it prints" : ""}`;
165
165
  }
166
166
 
167
+ /** Why an earnings alert is refused for a listing outside the US: 0700:HKEX, and D05, which is D05:SGX. */
168
+ export function earningsUsOnlyMessage(listing: string): string {
169
+ return `Earnings alerts follow US listings, such as CRWV or AAPL:NASDAQ. ${listing} is not one.`;
170
+ }
171
+
167
172
  /**
168
173
  * A new rule for `target`, alerting `lead` days before it or, for earnings,
169
174
  * once the results are out, with the event date the caller looked up. Throws
@@ -185,7 +190,7 @@ export function createScheduledAlert(
185
190
  : { version: 1, event: target.event, ...timing });
186
191
  if (!value) {
187
192
  throw new Error(target.kind === "earnings"
188
- ? `Earnings alerts follow US listings, such as CRWV or AAPL:NASDAQ. ${target.exchange ? `${target.symbol}:${target.exchange}` : target.symbol} is not one.`
193
+ ? earningsUsOnlyMessage(target.exchange ? `${target.symbol}:${target.exchange}` : target.symbol)
189
194
  : target.kind === "release"
190
195
  ? `A calendar event alert takes the event's name, a two-letter country and 1 to ${MAX_LEAD_DAYS} days before.`
191
196
  : `Days before must be a whole number from 1 to ${MAX_LEAD_DAYS}.`);
@@ -1,5 +1,6 @@
1
1
  import type { QuoteDataSource } from "../../../types/financials";
2
2
  import type { QuoteChangeBasis } from "../../../market-data/market/change-basis";
3
+ import type { ExtendedSession } from "../../../market-data/market/status";
3
4
 
4
5
  export type AlertCondition = "above" | "below" | "crosses";
5
6
  export type AlertStatus = "active" | "triggered" | "expired";
@@ -52,5 +53,11 @@ export interface AlertRule {
52
53
  lastQuoteExchange?: string;
53
54
  /** That quote was of a London line in pence (117.35p), whose levels are written in pence. */
54
55
  lastQuotePence?: boolean;
56
+ /**
57
+ * The pre-market, after-hours or overnight session the last reading's price
58
+ * is a print of, which lists say beside it; absent for the regular session's
59
+ * price or close.
60
+ */
61
+ lastQuoteSession?: ExtendedSession;
55
62
  message?: string;
56
63
  }
@@ -99,7 +99,7 @@ export function buildAccountRiskRows({
99
99
  label: "Beta (SPY)",
100
100
  value: beta == null ? MISSING_VALUE : formatNumber(beta, 2),
101
101
  detail: benchmarkIntegrity
102
- ? "SPY benchmark: inconsistent OHLC history"
102
+ ? "SPY benchmark: contradictory prices in its history"
103
103
  : beta == null ? "Insufficient overlap with SPY" : `Account · ${sampleWindow(betaSample)}`,
104
104
  },
105
105
  { id: "volatility", label: "Volatility", value: volatility == null ? MISSING_VALUE : formatReturn(volatility).replace("+", ""), detail },
@@ -0,0 +1,61 @@
1
+ import type { Portfolio, TickerRecord } from "../../../types/ticker";
2
+ import { riskInstrumentId, riskInstrumentOf, type RiskMarketSnapshot } from "./risk-client";
3
+ import { evidenceDay } from "./risk-evidence";
4
+ import { bridgedFxClose } from "./risk-fx";
5
+
6
+ export function manualPortfolioValue(
7
+ portfolio: Portfolio,
8
+ tickers: readonly TickerRecord[],
9
+ market: RiskMarketSnapshot,
10
+ cash: number | null,
11
+ ) {
12
+ if (portfolio.brokerId || portfolio.brokerInstanceId || portfolio.brokerAccountId) return null;
13
+ if (tickers.some((ticker) => ticker.metadata.positions.some((position) =>
14
+ position.portfolio === portfolio.id && position.shares !== 0 && position.broker !== "manual"))) return null;
15
+ const histories = new Map(market.histories.map((history) => [riskInstrumentId(history.instrument), history]));
16
+ const lots = tickers.flatMap((ticker) => ticker.metadata.positions
17
+ .filter((position) => position.portfolio === portfolio.id && position.shares !== 0)
18
+ .map((position) => ({
19
+ symbol: ticker.metadata.ticker,
20
+ start: position.dateAcquired,
21
+ quantity: (position.side === "short" ? -Math.abs(position.shares) : position.shares) * (position.multiplier ?? 1),
22
+ history: histories.get(riskInstrumentId(riskInstrumentOf(ticker))),
23
+ })));
24
+ if (!lots.length && !cash) return null;
25
+ const dates = [...new Set(market.histories.flatMap((history) => history.closes?.map((point) => point.date) ?? []))].sort();
26
+ const starts = lots.map((lot) => lot.start ?? dates[0]).filter((date): date is string => !!date);
27
+ const start = starts.sort()[0] ?? dates[0];
28
+ const warnings = new Set<string>();
29
+ if (cash == null) warnings.add("Estimated value: cash FX unavailable.");
30
+ for (const lot of lots) {
31
+ if (lot.start && !evidenceDay(lot.start)) warnings.add(`Estimated value: invalid acquired date for ${lot.symbol}.`);
32
+ if (!lot.history?.closes?.length) warnings.add(`Estimated value: daily closes unavailable for ${lot.symbol}.`);
33
+ }
34
+ const closes = lots.map((lot) => new Map(lot.history?.closes?.map((point) => [point.date, point.close])));
35
+ const points = dates.filter((date) => start && date >= start).map((date) => {
36
+ let value = cash;
37
+ const fx = portfolio.currency === "USD" ? 1 : market.accountFx && !market.accountFx.error
38
+ && market.accountFx.first && market.accountFx.asOf && date >= market.accountFx.first && date <= market.accountFx.asOf
39
+ ? bridgedFxClose((day) => market.accountFx!.closes[day], date)?.rate : null;
40
+ for (const [index, lot] of lots.entries()) {
41
+ if (lot.start && evidenceDay(lot.start) && date < lot.start) continue;
42
+ const close = closes[index]!.get(date);
43
+ if (value == null || close == null || !fx || !Number.isFinite(lot.quantity) || (lot.start && !evidenceDay(lot.start))) {
44
+ value = null;
45
+ break;
46
+ }
47
+ value += lot.quantity * close / fx;
48
+ }
49
+ return { date, value: value != null && Number.isFinite(value) ? value : null };
50
+ });
51
+ if (points.some((point) => point.value == null)) warnings.add("Estimated value has gaps where daily closes or FX are missing.");
52
+ if (points.filter((point) => point.value != null).length < 2) warnings.add("Estimated value needs at least two available daily closes.");
53
+ return {
54
+ kind: "estimate" as const,
55
+ label: "Estimated value",
56
+ currency: portfolio.currency,
57
+ points,
58
+ warnings: [...warnings],
59
+ complete: points.length > 1 && points.every((point) => point.value != null),
60
+ };
61
+ }
@@ -416,7 +416,7 @@ export function buildAnalyticsRiskRows({
416
416
  }): AnalyticsMetricRow[] {
417
417
  const unavailable = unvaluedCount > 0
418
418
  ? `${unvaluedCount} holding${unvaluedCount === 1 ? "" : "s"} unvalued; check prices and FX`
419
- : historyIntegrity.length > 0 ? `Inconsistent OHLC history: ${historyIntegrity.map((entry) => entry.symbol).join(", ")}`
419
+ : historyIntegrity.length > 0 ? `Contradictory prices in the history: ${historyIntegrity.map((entry) => entry.symbol).join(", ")}`
420
420
  : unsupportedReason ?? (missingCount > 0 ? "Incomplete holding history" : null);
421
421
  const partial = formatRiskCoverage(coverage, missingCount);
422
422
  return [
@@ -425,7 +425,7 @@ export function buildAnalyticsRiskRows({
425
425
  ].map((row) => {
426
426
  const rowTimestamps = row.id === "beta" ? betaHoldingTimestamps ?? returnTimestamps : returnTimestamps;
427
427
  const reason = unavailable ?? (rowTimestamps && !rowTimestamps.supported ? rowTimestamps.reason : null)
428
- ?? (row.id === "beta" && benchmarkIntegrity ? "SPY benchmark: inconsistent OHLC history"
428
+ ?? (row.id === "beta" && benchmarkIntegrity ? "SPY benchmark: contradictory prices in its history"
429
429
  : row.id === "beta" && benchmarkTimestamps && !benchmarkTimestamps.supported ? "SPY timestamps unverified"
430
430
  : row.id === "sharpe" && sharpeCadence && !sharpeCadence.supported ? sharpeCadence.reason : null);
431
431
  const sample = row.id === "beta" && returns && benchmarkReturns ? alignedAssetReturns(returns, benchmarkReturns) : returns;
@@ -22,10 +22,11 @@ const ISO_CURRENCY = /^[A-Z]{3}$/;
22
22
  /**
23
23
  * The portfolio's cash by currency: the broker account's own balances when it
24
24
  * reports them per currency, else its total cash (in the portfolio's currency
25
- * when the account names none), else the amount entered with `portfolio cash set`.
25
+ * when the account names none), else each currency's balance entered with
26
+ * `portfolio cash set`.
26
27
  */
27
28
  export function riskCashLines(
28
- portfolio: Pick<Portfolio, "cash" | "currency">,
29
+ portfolio: Pick<Portfolio, "cash" | "otherCash" | "currency">,
29
30
  account: Pick<BrokerAccount, "cashBalances" | "totalCashValue" | "currency"> | null | undefined,
30
31
  ): RiskCashLine[] {
31
32
  const byCurrency = new Map<string, number>();
@@ -36,11 +37,10 @@ export function riskCashLines(
36
37
  byCurrency.set(currency, (byCurrency.get(currency) ?? 0) + balance.quantity);
37
38
  }
38
39
  if (byCurrency.size) return [...byCurrency].map(([currency, amount]) => ({ currency, amount }));
39
- const line = resolvePortfolioCash(portfolio, account);
40
- const currency = (line?.currency.trim() || portfolio.currency || "").toUpperCase();
41
- return line && ISO_CURRENCY.test(currency) && Number.isFinite(line.amount) && line.amount !== 0
42
- ? [{ currency, amount: line.amount }]
43
- : [];
40
+ return (resolvePortfolioCash(portfolio, account)?.balances ?? []).flatMap((line) => {
41
+ const currency = (line.currency.trim() || portfolio.currency || "").toUpperCase();
42
+ return ISO_CURRENCY.test(currency) && Number.isFinite(line.amount) && line.amount !== 0 ? [{ currency, amount: line.amount }] : [];
43
+ });
44
44
  }
45
45
 
46
46
  /** A currency's move against USD, in percent of its USD value: TRY -20 is the lira 20% weaker. */