gloomberb 0.19.4 → 0.19.6

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 (321) hide show
  1. package/package.json +3 -1
  2. package/patches/@opentui%2Fcore@0.3.2.patch +86 -25
  3. package/src/api-client/equity-screener.ts +23 -0
  4. package/src/app/pane-runtime/index.tsx +2 -0
  5. package/src/app/pane-runtime/plugin-bindings.ts +10 -1
  6. package/src/app.tsx +63 -16
  7. package/src/cli/commands/command-utils.ts +4 -0
  8. package/src/cli/commands/market.ts +264 -33
  9. package/src/cli/commands/search.ts +22 -4
  10. package/src/cli/commands/ticker.ts +84 -39
  11. package/src/cli/currency-name-hint.ts +60 -0
  12. package/src/cli/glossary.ts +3 -3
  13. package/src/cli/history-rows.ts +18 -1
  14. package/src/cli/known-gaps.ts +25 -2
  15. package/src/cli/listing-arg.ts +12 -0
  16. package/src/cli/not-a-ticker.ts +5 -3
  17. package/src/cli/pane-functions/capabilities.ts +2 -0
  18. package/src/cli/pane-functions/catalog.ts +31 -5
  19. package/src/cli/pane-functions/function-help.ts +8 -5
  20. package/src/cli/pane-functions/headless.ts +11 -6
  21. package/src/cli/pane-functions/market-session.ts +6 -7
  22. package/src/cli/pane-functions/resolver.ts +75 -2
  23. package/src/cli/quote-answer.ts +9 -0
  24. package/src/cli/series-search.ts +4 -5
  25. package/src/cli/symbol-list.ts +54 -2
  26. package/src/cli/symbol-rows.ts +14 -2
  27. package/src/cli/ticker-resolution.ts +89 -20
  28. package/src/components/chart/composite/axis-overlays.tsx +60 -27
  29. package/src/components/chart/composite/composite-chart.tsx +118 -63
  30. package/src/components/chart/composite/cursor-source.ts +111 -0
  31. package/src/components/chart/composite/format.ts +168 -6
  32. package/src/components/chart/composite/legend.tsx +8 -4
  33. package/src/components/chart/composite/panel-bitmap.ts +28 -2
  34. package/src/components/chart/composite/panel-labels.ts +20 -1
  35. package/src/components/chart/composite/panel-surface.tsx +201 -92
  36. package/src/components/chart/composite/price-axis-labels.tsx +92 -46
  37. package/src/components/chart/composite/price-series.ts +31 -8
  38. package/src/components/chart/composite/scene.ts +154 -59
  39. package/src/components/chart/composite/series-axis-tags.tsx +4 -2
  40. package/src/components/chart/composite/time-axis.ts +30 -7
  41. package/src/components/chart/composite/time-scale.ts +211 -56
  42. package/src/components/chart/composite/types.ts +11 -1
  43. package/src/components/chart/composite/use-composite-chart-keyboard.ts +32 -12
  44. package/src/components/chart/curve/curve-surface.tsx +5 -2
  45. package/src/components/chart/curve/model.ts +4 -1
  46. package/src/components/chart/native/use-bitmap-metrics.ts +81 -0
  47. package/src/components/chart/static/series.ts +3 -0
  48. package/src/components/command-bar/commands/collection-list.ts +81 -0
  49. package/src/components/command-bar/commands/direct/index.ts +6 -0
  50. package/src/components/command-bar/commands/registry.ts +8 -0
  51. package/src/components/command-bar/layout-items/current-layout.ts +22 -1
  52. package/src/components/command-bar/layout-items/focused-pane.ts +22 -1
  53. package/src/components/command-bar/pane-templates/items.ts +19 -3
  54. package/src/components/command-bar/pane-templates/workflow.ts +5 -0
  55. package/src/components/command-bar/routes/root/results.ts +23 -3
  56. package/src/components/command-bar/routes/root/selection.ts +4 -2
  57. package/src/components/command-bar/routes/root/shortcut-feedback.ts +1 -1
  58. package/src/components/command-bar/routes/root/shortcut-items.ts +3 -4
  59. package/src/components/command-bar/routes/root/shortcuts.ts +58 -14
  60. package/src/components/command-bar/routes/root/ticker-first.ts +32 -0
  61. package/src/components/command-bar/surface/environment.ts +2 -0
  62. package/src/components/command-bar/view-model.ts +7 -0
  63. package/src/components/command-bar/workflow/ops.ts +2 -1
  64. package/src/components/command-bar/workflow/tickers.ts +20 -0
  65. package/src/components/layout/shell/active-drag.ts +38 -7
  66. package/src/components/layout/shell/drag/magnets.ts +106 -0
  67. package/src/components/layout/shell/menu.ts +15 -1
  68. package/src/components/layout/shell/pane/actions.ts +4 -0
  69. package/src/components/layout/shell/ticker-link-menu.ts +12 -3
  70. package/src/components/layout/status-bar.tsx +20 -0
  71. package/src/components/layout/window-controls.tsx +96 -35
  72. package/src/components/layout/window-fullscreen.ts +20 -0
  73. package/src/components/onboarding/onboarding-keyboard.ts +5 -1
  74. package/src/components/onboarding/onboarding-wizard.tsx +15 -4
  75. package/src/components/onboarding/portfolio-step/positions-panel.tsx +8 -5
  76. package/src/components/onboarding/use-onboarding-progress.ts +20 -1
  77. package/src/components/price-sparkline/view.tsx +14 -6
  78. package/src/components/quote-flash.ts +36 -32
  79. package/src/components/ticker/badge/index.tsx +8 -4
  80. package/src/components/ticker/badge/list.tsx +23 -7
  81. package/src/components/ui/column-grid.tsx +8 -2
  82. package/src/components/ui/data-table/opentui/model.ts +4 -1
  83. package/src/components/ui/tabs.tsx +5 -2
  84. package/src/core/state/app/layout.ts +18 -3
  85. package/src/core/state/app/state.ts +2 -0
  86. package/src/core/state/app/types.ts +5 -0
  87. package/src/data/config/layout.ts +3 -0
  88. package/src/data/config/store/normalize.ts +39 -4
  89. package/src/i18n/es.ts +10 -0
  90. package/src/i18n/ja.ts +10 -0
  91. package/src/i18n/ko.ts +10 -0
  92. package/src/i18n/zh-cn.ts +10 -0
  93. package/src/i18n/zh-tw.ts +10 -0
  94. package/src/layout/pane-manager/floating-placement.ts +7 -4
  95. package/src/layout/pane-manager/floating.ts +5 -2
  96. package/src/market-data/bond-funds.ts +19 -0
  97. package/src/market-data/coordinator/events.ts +17 -1
  98. package/src/market-data/frame-scheduler.ts +47 -10
  99. package/src/market-data/frame-wake.ts +74 -0
  100. package/src/market-data/futures-board.ts +7 -6
  101. package/src/market-data/futures-contract.ts +14 -3
  102. package/src/market-data/hooks.tsx +12 -3
  103. package/src/market-data/market/freshness.ts +18 -0
  104. package/src/market-data/market/status.ts +15 -2
  105. package/src/market-data/performance.ts +78 -9
  106. package/src/market-data/request-types.ts +6 -3
  107. package/src/plugins/builtin/alerts/cli.ts +2 -1
  108. package/src/plugins/builtin/analytics/risk-evidence.ts +1 -0
  109. package/src/plugins/builtin/attention/evidence.ts +1 -1
  110. package/src/plugins/builtin/awards/client.ts +1 -1
  111. package/src/plugins/builtin/awards/evidence.ts +1 -1
  112. package/src/plugins/builtin/awards/pane.tsx +2 -1
  113. package/src/plugins/builtin/bond-calculator/headless.ts +2 -1
  114. package/src/plugins/builtin/bond-calculator/index.tsx +1 -1
  115. package/src/plugins/builtin/bond-calculator/math.ts +1 -1
  116. package/src/plugins/builtin/bond-calculator/model.ts +14 -5
  117. package/src/plugins/builtin/bond-calculator/pane.tsx +1 -1
  118. package/src/plugins/builtin/broker-manager/footer.ts +3 -2
  119. package/src/plugins/builtin/broker-manager/index.tsx +2 -1
  120. package/src/plugins/builtin/broker-manager/keyboard.ts +2 -1
  121. package/src/plugins/builtin/buildout/cells.tsx +25 -45
  122. package/src/plugins/builtin/buildout/detail/company.tsx +3 -3
  123. package/src/plugins/builtin/buildout/detail/index.tsx +1 -1
  124. package/src/plugins/builtin/buildout/detail/intel.tsx +4 -7
  125. package/src/plugins/builtin/buildout/detail/site.tsx +4 -4
  126. package/src/plugins/builtin/buildout/detail/ui.tsx +39 -38
  127. package/src/plugins/builtin/buildout/format.ts +23 -1
  128. package/src/plugins/builtin/buildout/model/types.ts +1 -0
  129. package/src/plugins/builtin/buildout/pane/index.tsx +2 -8
  130. package/src/plugins/builtin/buildout/table-model.ts +12 -4
  131. package/src/plugins/builtin/catalysts/evidence.ts +1 -1
  132. package/src/plugins/builtin/catalysts/pane.tsx +2 -1
  133. package/src/plugins/builtin/cds/headless.ts +1 -0
  134. package/src/plugins/builtin/cds/index.tsx +1 -1
  135. package/src/plugins/builtin/chart-composer/headless.ts +40 -1
  136. package/src/plugins/builtin/cloud/plugin.tsx +2 -0
  137. package/src/plugins/builtin/cloud/upgrade-status-widget.tsx +28 -3
  138. package/src/plugins/builtin/cloud-tweets/table.tsx +3 -2
  139. package/src/plugins/builtin/comment-letters/client.ts +2 -1
  140. package/src/plugins/builtin/company-kpis/client.ts +1 -1
  141. package/src/plugins/builtin/company-kpis/pane.tsx +2 -1
  142. package/src/plugins/builtin/company-kpis/screenshot-evidence.ts +3 -2
  143. package/src/plugins/builtin/correlation/headless.ts +3 -2
  144. package/src/plugins/builtin/cot/headless.ts +9 -3
  145. package/src/plugins/builtin/cot/model.ts +44 -3
  146. package/src/plugins/builtin/credit-documents/client.ts +1 -1
  147. package/src/plugins/builtin/credit-documents/evidence.ts +1 -1
  148. package/src/plugins/builtin/credit-documents/pane.tsx +2 -1
  149. package/src/plugins/builtin/crypto-board/pane.tsx +5 -4
  150. package/src/plugins/builtin/debt-maturities/headless.ts +11 -2
  151. package/src/plugins/builtin/debt-maturities/model.ts +66 -0
  152. package/src/plugins/builtin/debt-maturities/pane.tsx +23 -4
  153. package/src/plugins/builtin/earnings-calls/pane.tsx +1 -1
  154. package/src/plugins/builtin/earnings-ripple/index.tsx +6 -1
  155. package/src/plugins/builtin/earnings-ripple/pane.tsx +1 -1
  156. package/src/plugins/builtin/econ/calendar-model.ts +30 -6
  157. package/src/plugins/builtin/econ/fred-catalog.ts +5 -5
  158. package/src/plugins/builtin/econ/print-watch.ts +3 -1
  159. package/src/plugins/builtin/equity-screener/client.ts +1 -1
  160. package/src/plugins/builtin/equity-screener/criterion-editor.tsx +4 -16
  161. package/src/plugins/builtin/equity-screener/headless.ts +4 -2
  162. package/src/plugins/builtin/equity-screener/ideas.ts +67 -3
  163. package/src/plugins/builtin/equity-screener/model.ts +180 -12
  164. package/src/plugins/builtin/equity-screener/pane.tsx +52 -12
  165. package/src/plugins/builtin/equity-screener/screen-check.ts +7 -4
  166. package/src/plugins/builtin/equity-screener/watchlist.ts +33 -0
  167. package/src/plugins/builtin/futures/series.ts +16 -1
  168. package/src/plugins/builtin/futures-curve/client.ts +19 -0
  169. package/src/plugins/builtin/futures-curve/headless.ts +52 -13
  170. package/src/plugins/builtin/futures-curve/index.tsx +1 -1
  171. package/src/plugins/builtin/futures-curve/model.ts +77 -6
  172. package/src/plugins/builtin/futures-curve/pane.tsx +19 -3
  173. package/src/plugins/builtin/fx-matrix/headless.ts +4 -2
  174. package/src/plugins/builtin/fx-matrix/index.tsx +37 -3
  175. package/src/plugins/builtin/fx-matrix/pairs.ts +15 -0
  176. package/src/plugins/builtin/gpu/headless.ts +2 -1
  177. package/src/plugins/builtin/help/function-card.tsx +2 -1
  178. package/src/plugins/builtin/help/index.tsx +2 -1
  179. package/src/plugins/builtin/insider/display.ts +45 -6
  180. package/src/plugins/builtin/ipo-calendar/model.ts +2 -0
  181. package/src/plugins/builtin/iv-history/client.ts +2 -1
  182. package/src/plugins/builtin/iv-history/headless.ts +2 -1
  183. package/src/plugins/builtin/jobs/pages.ts +4 -4
  184. package/src/plugins/builtin/kelly-sizer/headless.ts +2 -1
  185. package/src/plugins/builtin/macro-day/client.ts +41 -0
  186. package/src/plugins/builtin/macro-day/headless.ts +19 -9
  187. package/src/plugins/builtin/macro-day/model.ts +3 -1
  188. package/src/plugins/builtin/market-heatmap/index.tsx +2 -1
  189. package/src/plugins/builtin/market-movers/index.tsx +4 -3
  190. package/src/plugins/builtin/members/client.ts +1 -1
  191. package/src/plugins/builtin/mna/distress/client.ts +1 -0
  192. package/src/plugins/builtin/mna/distress/headless.ts +1 -0
  193. package/src/plugins/builtin/mna/pane.tsx +4 -1
  194. package/src/plugins/builtin/options/market-reference.ts +1 -1
  195. package/src/plugins/builtin/options/open-interest-as-of.ts +3 -1
  196. package/src/plugins/builtin/options/view.tsx +2 -1
  197. package/src/plugins/builtin/options-calculator/evidence.ts +1 -1
  198. package/src/plugins/builtin/options-scenario/csp-screen-pane.tsx +1 -1
  199. package/src/plugins/builtin/options-scenario/csp-screen.ts +8 -4
  200. package/src/plugins/builtin/options-scenario/csp.ts +28 -9
  201. package/src/plugins/builtin/options-scenario/evidence.ts +5 -4
  202. package/src/plugins/builtin/options-scenario/pane.tsx +2 -1
  203. package/src/plugins/builtin/perps/client.ts +1 -1
  204. package/src/plugins/builtin/perps/pane.tsx +3 -1
  205. package/src/plugins/builtin/portfolio-list/cli/bulk-symbols.ts +17 -0
  206. package/src/plugins/builtin/portfolio-list/cli/portfolio-command.ts +2 -1
  207. package/src/plugins/builtin/portfolio-list/cli/watchlist-command.ts +4 -2
  208. package/src/plugins/builtin/portfolio-list/pane/index.tsx +7 -3
  209. package/src/plugins/builtin/portfolio-list/use-throttled-memo.ts +10 -19
  210. package/src/plugins/builtin/rate-path/headless.ts +24 -10
  211. package/src/plugins/builtin/research/analyst-model.ts +1 -0
  212. package/src/plugins/builtin/research/equity-diagnostic-pane.tsx +2 -1
  213. package/src/plugins/builtin/research/event-model.ts +10 -3
  214. package/src/plugins/builtin/research/events-headless.ts +20 -2
  215. package/src/plugins/builtin/research/index.tsx +1 -0
  216. package/src/plugins/builtin/research/relative-valuation-currency.ts +1 -1
  217. package/src/plugins/builtin/research/relative-valuation-peers.ts +2 -1
  218. package/src/plugins/builtin/research-search/command-bar-search.ts +3 -1
  219. package/src/plugins/builtin/research-search/snippet.ts +1 -0
  220. package/src/plugins/builtin/revenue-breakdown/client.ts +3 -2
  221. package/src/plugins/builtin/seasonality/headless.ts +2 -1
  222. package/src/plugins/builtin/sec/command-bar-search.ts +3 -2
  223. package/src/plugins/builtin/sec/fund-facts.ts +17 -1
  224. package/src/plugins/builtin/sec/index.tsx +8 -5
  225. package/src/plugins/builtin/sec/row-summaries.ts +28 -12
  226. package/src/plugins/builtin/shared/members-menu.tsx +103 -38
  227. package/src/plugins/builtin/short-interest/publications-model.ts +22 -1
  228. package/src/plugins/builtin/short-interest/publications-pane.tsx +13 -4
  229. package/src/plugins/builtin/short-interest/watch-client.ts +2 -1
  230. package/src/plugins/builtin/short-interest/watch-model.ts +1 -1
  231. package/src/plugins/builtin/social-mentions/client.ts +2 -1
  232. package/src/plugins/builtin/supply-chain/client.ts +1 -1
  233. package/src/plugins/builtin/supply-chain/evidence.ts +1 -1
  234. package/src/plugins/builtin/supply-chain/graph-pane.tsx +2 -1
  235. package/src/plugins/builtin/supply-chain/pane.tsx +2 -1
  236. package/src/plugins/builtin/ticker-detail/adr-pair/headless.ts +1 -1
  237. package/src/plugins/builtin/ticker-detail/adr-pair/model.ts +24 -4
  238. package/src/plugins/builtin/ticker-detail/adr-pair/tab.tsx +1 -1
  239. package/src/plugins/builtin/time-sales/client.ts +1 -0
  240. package/src/plugins/builtin/time-sales/pane.tsx +3 -2
  241. package/src/plugins/builtin/trace-bonds/client.ts +7 -4
  242. package/src/plugins/builtin/trace-bonds/index.tsx +1 -1
  243. package/src/plugins/builtin/vol-surface/client.ts +2 -1
  244. package/src/plugins/builtin/volatility/client.ts +6 -1
  245. package/src/plugins/builtin/volatility/headless.ts +0 -1
  246. package/src/plugins/builtin/yield-curve/curves.ts +15 -0
  247. package/src/plugins/builtin/yield-curve/headless.ts +9 -2
  248. package/src/plugins/builtin/yield-curve/index.tsx +5 -8
  249. package/src/plugins/host-modules.ts +22 -3
  250. package/src/plugins/host-smoke.ts +6 -3
  251. package/src/portfolio/collection-name.ts +19 -0
  252. package/src/portfolio/column-values.ts +76 -10
  253. package/src/renderers/browser/http-proxy-transport.ts +78 -8
  254. package/src/renderers/cloudflare/http-proxy.ts +13 -2
  255. package/src/renderers/cloudflare/proxy-session.ts +47 -24
  256. package/src/renderers/cloudflare/worker.ts +15 -2
  257. package/src/renderers/desktop/geometry.ts +279 -0
  258. package/src/renderers/desktop/screen-setup.ts +246 -0
  259. package/src/renderers/desktop/sequential-window-host.ts +179 -0
  260. package/src/renderers/desktop/test-utils.ts +71 -0
  261. package/src/renderers/desktop/window-controller.ts +433 -0
  262. package/src/renderers/desktop/window-host.ts +70 -0
  263. package/src/renderers/desktop/window-layouts.ts +630 -0
  264. package/src/renderers/dom/data-frames.ts +15 -4
  265. package/src/renderers/dom/host/box.tsx +204 -176
  266. package/src/renderers/dom/host/style.ts +49 -20
  267. package/src/renderers/dom/host/text.tsx +3 -2
  268. package/src/renderers/electrobun/bun/application-menu/click.ts +1 -0
  269. package/src/renderers/electrobun/bun/application-menu/index.ts +4 -1
  270. package/src/renderers/electrobun/bun/desktop/backend-requests.ts +19 -8
  271. package/src/renderers/electrobun/bun/desktop/backend.ts +322 -19
  272. package/src/renderers/electrobun/bun/desktop/detached-windows.ts +83 -61
  273. package/src/renderers/electrobun/bun/desktop/host-requests.ts +29 -15
  274. package/src/renderers/electrobun/bun/desktop/initialization.ts +30 -11
  275. package/src/renderers/electrobun/bun/desktop/relaunch.ts +9 -1
  276. package/src/renderers/electrobun/bun/desktop/screen-setup-file.ts +55 -0
  277. package/src/renderers/electrobun/bun/desktop/state-broadcaster.ts +44 -8
  278. package/src/renderers/electrobun/bun/desktop/windows-script.ts +9 -6
  279. package/src/renderers/electrobun/bun/desktop/workspace/index.ts +298 -97
  280. package/src/renderers/electrobun/bun/desktop/workspace/requests.ts +44 -6
  281. package/src/renderers/electrobun/bun/index.ts +4 -97
  282. package/src/renderers/electrobun/bun/window/electrobun-window-host.ts +306 -0
  283. package/src/renderers/electrobun/bun/window/focus.ts +0 -25
  284. package/src/renderers/electrobun/bun/window/remembered-frame.ts +4 -82
  285. package/src/renderers/electrobun/bun/window/windows-native.ts +26 -1
  286. package/src/renderers/electrobun/shared/protocol.ts +50 -2
  287. package/src/renderers/electrobun/view/backend-rpc.ts +15 -0
  288. package/src/renderers/electrobun/view/desktop/window/bridge.ts +63 -3
  289. package/src/renderers/electrobun/view/main.tsx +13 -7
  290. package/src/renderers/electrobun/view/ui-host.tsx +7 -0
  291. package/src/renderers/electrobun/view/window-fullscreen.ts +10 -3
  292. package/src/series/fred-argument.ts +17 -0
  293. package/src/sources/provider-router/financial-routes.ts +7 -1
  294. package/src/sources/provider-router/index.ts +7 -1
  295. package/src/state/app/context/index.tsx +16 -2
  296. package/src/state/desktop-windows.ts +63 -0
  297. package/src/sync/other-window-tabs.ts +62 -0
  298. package/src/tickers/company-name-listing.ts +23 -3
  299. package/src/tickers/listing-fate.ts +147 -1
  300. package/src/tickers/terminal-codes.ts +5 -0
  301. package/src/time-series/price-units.ts +11 -0
  302. package/src/time-series/types.ts +6 -0
  303. package/src/types/config.ts +10 -1
  304. package/src/types/desktop-window.ts +71 -2
  305. package/src/types/financials.ts +4 -0
  306. package/src/types/headless.ts +19 -0
  307. package/src/types/plugin.ts +6 -0
  308. package/src/ui/host.tsx +2 -0
  309. package/src/ui/index.tsx +14 -13
  310. package/src/ui/same-props.ts +58 -0
  311. package/src/utils/cli-output.ts +33 -4
  312. package/src/utils/currency-names.ts +20 -0
  313. package/src/utils/currency-pair.ts +6 -0
  314. package/src/utils/exchange-rate-snapshot.ts +20 -2
  315. package/src/utils/format.ts +7 -2
  316. package/src/utils/futures-generic.ts +12 -0
  317. package/src/utils/fx-market-hours.ts +43 -0
  318. package/src/utils/http-proxy-upstream.ts +6 -2
  319. package/src/utils/plugin-proxy-hosts.json +0 -4
  320. package/src/utils/plugin-proxy-hosts.ts +22 -0
  321. package/src/utils/sec-filings.ts +7 -1
@@ -2,10 +2,26 @@ import { readIntradayBar, readStaleReason } from "../market-data/quotes/intraday
2
2
  import type { QuoteIntradayBar } from "../types/financials";
3
3
  import type { ExchangeRateSnapshot } from "../types/exchange-rate";
4
4
  import { fixedUsdRate } from "./currency-units";
5
- import { fxFreshUntil } from "./fx-market-hours";
5
+ import { fxFreshUntil, fxPreCloseRefetchAt } from "./fx-market-hours";
6
6
 
7
7
  export const MAX_FX_OBSERVATION_AGE_MS = 7 * 24 * 60 * 60_000;
8
8
  const FX_FRESH_MS = 60 * 60_000;
9
+ /** The longest a source's FX runs behind the market, and what a rate that states no delay is taken to: Gloom Cloud's 15 minutes. */
10
+ const MAX_FX_DELAY_MINUTES = 15;
11
+
12
+ /** When a rate read at `fetchedAt` is read again for its week's close (fxPreCloseRefetchAt); a rate with no stated delay may be up to 15 minutes behind. */
13
+ function preCloseRefetchAt(fetchedAt: number | undefined, asOf: number | undefined, delayMinutes: number | undefined): number {
14
+ return fxPreCloseRefetchAt(fetchedAt, asOf, Math.min(delayMinutes ?? MAX_FX_DELAY_MINUTES, MAX_FX_DELAY_MINUTES) * 60_000);
15
+ }
16
+
17
+ /**
18
+ * Whether a cached rate is past the point it is read again for its FX week's
19
+ * close: shown while it is read again, it would stand in for a close it is
20
+ * not, so a caller that revalidates in the background waits for this one.
21
+ */
22
+ export function isPastPreCloseRefetch(result: { fetchedAt: number; asOf?: number; delayMinutes?: number }, now = Date.now()): boolean {
23
+ return preCloseRefetchAt(result.fetchedAt, result.asOf, result.delayMinutes) <= now;
24
+ }
9
25
 
10
26
  interface FxRateMetadata {
11
27
  fetchedAt?: number;
@@ -62,12 +78,14 @@ export function exchangeRateMetadata(value: unknown, currency: string, now = Dat
62
78
  if (expiresAt <= now) return fail();
63
79
  const delayMinutes = typeof data.delayMinutes === "number" && Number.isFinite(data.delayMinutes) && data.delayMinutes >= 0
64
80
  ? data.delayMinutes : undefined;
65
- const delay = Math.min(delayMinutes ?? 0, 15) * 60_000;
81
+ const delay = Math.min(delayMinutes ?? 0, MAX_FX_DELAY_MINUTES) * 60_000;
66
82
  const intradayBar = readIntradayBar(data.intradayBar);
67
83
  const staleReason = readStaleReason(data.staleReason);
68
84
  const staleAt = Math.min(declaredStaleAt ?? Infinity,
69
85
  fetchedAt === undefined ? Infinity : fxFreshUntil(fetchedAt, FX_FRESH_MS),
70
86
  asOf === undefined ? Infinity : fxFreshUntil(asOf, FX_FRESH_MS + delay),
87
+ // A rate this app read before the week closed is read again once the close is out: when it read it, not the source.
88
+ preCloseRefetchAt(fallbackFetchedAt ?? fetchedAt, asOf, delayMinutes),
71
89
  data.stale === true ? now : Infinity);
72
90
  return {
73
91
  ...(fetchedAt !== undefined ? { fetchedAt } : {}),
@@ -204,9 +204,14 @@ export function formatNumber(value: number | undefined, decimals = 2): string {
204
204
  export function formatSignificant(value: number | undefined, digits = 4): string {
205
205
  if (value == null || !Number.isFinite(value)) return formatNumber(undefined);
206
206
  if (value === 0) return getNumberFormatter(0).format(0);
207
+ return getNumberFormatter(significantDecimals(value, digits)).format(Number(value.toPrecision(digits)));
208
+ }
209
+
210
+ /** The decimals `formatSignificant` writes a value to: 0.8904 has 4, 1.123 has 3, 0 none. */
211
+ export function significantDecimals(value: number, digits = 4): number {
212
+ if (value === 0 || !Number.isFinite(value)) return 0;
207
213
  const rounded = Number(value.toPrecision(digits));
208
- const decimals = Math.min(12, Math.max(0, digits - 1 - Math.floor(Math.log10(Math.abs(rounded)))));
209
- return getNumberFormatter(decimals).format(rounded);
214
+ return Math.min(12, Math.max(0, digits - 1 - Math.floor(Math.log10(Math.abs(rounded)))));
210
215
  }
211
216
 
212
217
  /** A percentile rank with its window: "73 pctl 1Y", "-- pctl 1Y" when unranked, "73 pctl" without a window. */
@@ -68,6 +68,18 @@ const STANDARD_ROLL_DAYS: Readonly<Record<string, number>> = {
68
68
  VX: 0,
69
69
  };
70
70
 
71
+ /**
72
+ * Continuous symbols written as other roots' are (`CL=F`) for a root that has
73
+ * none, Cboe's VIX futures: `VX=F` is the front generic VX1, which follows
74
+ * the same front contract.
75
+ */
76
+ const GENERIC_FOR_ALIAS: Readonly<Record<string, string>> = { "VX=F": "VX1" };
77
+
78
+ /** The front generic a continuous symbol the root does not list stands for (VX=F: VX1), or null. */
79
+ export function continuousAliasGeneric(symbol: string): string | null {
80
+ return GENERIC_FOR_ALIAS[symbol.trim().toUpperCase()] ?? null;
81
+ }
82
+
71
83
  /** A root's standard roll: what a bare generic (NG1) and the continuous alias (NG=F) follow. */
72
84
  export function standardFuturesGenericRoll(root: string): FuturesGenericRoll {
73
85
  return { rule: "first-notice", days: STANDARD_ROLL_DAYS[root] ?? 1, standard: true };
@@ -85,6 +85,49 @@ export function latestFxWeekOpen(time: number): number | null {
85
85
  return latestNewYorkFivePm(time, 0);
86
86
  }
87
87
 
88
+ /**
89
+ * How close to the FX week's close a print is its close: Gloom Cloud dates the
90
+ * week's close by its last minute (20:59Z, or 21:59Z in winter).
91
+ */
92
+ const FX_CLOSE_PRINT_MS = 60_000;
93
+
94
+ /** Whether a print made at `time` is the close of the FX week that closed at `weekClose`. */
95
+ export function isFxWeekClosePrint(time: number, weekClose: number): boolean {
96
+ return time <= weekClose && time >= weekClose - FX_CLOSE_PRINT_MS;
97
+ }
98
+
99
+ /**
100
+ * When a rate fetched at `fetchedAt` must be read again because it may stand
101
+ * in for a close it is not: once the close of its FX week is out (the
102
+ * week's close, `delayMs` later for a delayed feed). A rate fetched at 20:39Z
103
+ * on a Friday is no close, yet the hours the market is shut do not age it
104
+ * (fxFreshUntil), so until Sunday's open it stood in for Friday's close. The
105
+ * week is the one `fetchedAt` falls in, not the one it is now, so the time is
106
+ * the same whether it is asked on Friday or on Sunday. Infinity for a rate
107
+ * that is that close (isFxWeekClosePrint).
108
+ */
109
+ export function fxPreCloseRefetchAt(fetchedAt: number | undefined, observedAt: number | undefined, delayMs: number): number {
110
+ if (fetchedAt == null || !Number.isFinite(fetchedAt)) return Infinity;
111
+ const close = fxWeekCloseOf(fetchedAt, delayMs);
112
+ if (close == null || (observedAt != null && isFxWeekClosePrint(observedAt, close))) return Infinity;
113
+ return close + delayMs;
114
+ }
115
+
116
+ /**
117
+ * The close of the FX week a rate fetched at `time` belongs to: the latest
118
+ * one while its print may still be on its way (`delayMs`), else the next one.
119
+ * The next close is a week on, give or take the hour a clock change moves it.
120
+ */
121
+ function fxWeekCloseOf(time: number, delayMs: number): number | null {
122
+ const latest = latestFxWeekClose(time);
123
+ if (latest != null && time < latest + delayMs) return latest;
124
+ for (const ahead of [7 * DAY_MS, 7 * DAY_MS + 2 * HOUR_MS]) {
125
+ const close = latestFxWeekClose(time + ahead);
126
+ if (close != null && close > time) return close;
127
+ }
128
+ return null;
129
+ }
130
+
88
131
  /**
89
132
  * When the closure the market is in began (Friday 17:00 New York time); null
90
133
  * while it trades. That is `latestFxWeekClose` for every moment the week is
@@ -53,6 +53,10 @@ export async function fetchCheckingRedirects(
53
53
  init: ProxiedRequestInit,
54
54
  options: { fetch: typeof fetch; check: ProxyTargetCheck; signal: AbortSignal },
55
55
  ): Promise<ProxyUpstreamResult> {
56
+ // Taken off `options` before calling: `options.fetch(...)` would call the
57
+ // runtime's fetch with `options` as `this`, which Cloudflare Workers reject
58
+ // with "Illegal invocation", failing every proxied request.
59
+ const { fetch: fetchUpstream, check, signal } = options;
56
60
  const headers = upstreamHeaders(init.headers);
57
61
  const mode = init.redirect ?? "follow";
58
62
  let url = first;
@@ -60,7 +64,7 @@ export async function fetchCheckingRedirects(
60
64
  let body = init.body;
61
65
 
62
66
  for (let followed = 0; ; followed += 1) {
63
- const response = await options.fetch(url, { method, headers, body, redirect: "manual", signal: options.signal });
67
+ const response = await fetchUpstream(url, { method, headers, body, redirect: "manual", signal });
64
68
  const location = REDIRECT_STATUSES.has(response.status) ? response.headers.get("location") : null;
65
69
  // "manual" hands the redirect back to the plugin. If it follows it, that
66
70
  // comes back through here as a new request and is checked like one.
@@ -77,7 +81,7 @@ export async function fetchCheckingRedirects(
77
81
  // Intentional ignore: a Location that does not parse is reported as an invalid redirect, never followed.
78
82
  return { error: "The upstream sent an invalid redirect.", status: 502 };
79
83
  }
80
- const target = await options.check(next);
84
+ const target = await check(next);
81
85
  if ("error" in target) return { error: `The upstream redirect was refused. ${target.error}`, status: 502 };
82
86
 
83
87
  if (target.url.origin !== url.origin) {
@@ -3,17 +3,13 @@
3
3
  "api.crypto.com",
4
4
  "api.elections.kalshi.com",
5
5
  "api.fda.gov",
6
- "api.fiscaldata.treasury.gov",
7
6
  "api.gemini.com",
8
7
  "api.limitless.exchange",
9
8
  "api.votehub.com",
10
9
  "clinicaltrials.gov",
11
- "clob.polymarket.com",
12
- "data-api.polymarket.com",
13
10
  "data.pascal.trade",
14
11
  "efts.sec.gov",
15
12
  "forms13f.com",
16
- "gamma-api.polymarket.com",
17
13
  "gateway.polymarket.us",
18
14
  "markets.newyorkfed.org",
19
15
  "nasdaqtrader.com",
@@ -18,6 +18,28 @@ import allowed from "./plugin-proxy-hosts.json";
18
18
  */
19
19
  export const PROXY_ALLOWED_HOSTS: readonly string[] = allowed.hosts;
20
20
 
21
+ /**
22
+ * Declared hosts the browser calls directly instead of through the proxy,
23
+ * because they answer the terminal's origin with CORS headers and need no
24
+ * header a browser cannot set. The worker lists them in `connect-src`, and
25
+ * the generator leaves them off the proxy list, so a request to one never
26
+ * costs a worker round trip or a slot in anyone's rate limit.
27
+ *
28
+ * Add a host here only after checking that it sends
29
+ * `access-control-allow-origin` for https://term.gloom.sh on the requests the
30
+ * plugin makes, and on their preflight when the plugin sends a header outside
31
+ * the CORS-safelisted ones (`Authorization`, say). The browser transport
32
+ * leaves `User-Agent` off these requests, so it never causes a preflight.
33
+ */
34
+ export const WEB_DIRECT_HOSTS: readonly string[] = [
35
+ "api.fiscaldata.treasury.gov",
36
+ "api.thebuildout.ai",
37
+ // Polymarket's read APIs. An events page can pass the proxy's 5 MB cap.
38
+ "clob.polymarket.com",
39
+ "data-api.polymarket.com",
40
+ "gamma-api.polymarket.com",
41
+ ];
42
+
21
43
  /** The worker route the browser posts proxied requests to. */
22
44
  export const HTTP_PROXY_PATH = "/http-proxy";
23
45
 
@@ -179,6 +179,8 @@ export interface HiddenFilings {
179
179
  pricingSupplements: number;
180
180
  /** The 13D/13G the company filed as a holder of other companies. */
181
181
  ownershipReportsAboutOthers: number;
182
+ /** A fund's trust filed these for its other funds (the sibling series' NPORT-P on the same day). */
183
+ otherFunds?: number;
182
184
  }
183
185
 
184
186
  /**
@@ -194,9 +196,12 @@ function keptFilings(
194
196
  const kept: SecFilingItem[] = [];
195
197
  const hidden: HiddenFilings = { pricingSupplements: 0, ownershipReportsAboutOthers: 0 };
196
198
  const isSupplement = pricingSupplementTest(filings);
199
+ // A fund's trust lists every fund it runs; where the service marks the fund's own series, the others' are left out.
200
+ const ownSeries = filings.some((filing) => filing.fundSeries === true);
197
201
  for (const filing of filings) {
198
202
  if (kept.length >= limit) break;
199
- if (isSupplement(filing)) hidden.pricingSupplements += 1;
203
+ if (ownSeries && filing.fundSeries === false) hidden.otherFunds = (hidden.otherFunds ?? 0) + 1;
204
+ else if (isSupplement(filing)) hidden.pricingSupplements += 1;
200
205
  else if (schedulesAboutOthers && isScheduleAboutAnotherCompany(filing)) hidden.ownershipReportsAboutOthers += 1;
201
206
  else kept.push(filing);
202
207
  }
@@ -213,6 +218,7 @@ export function hiddenFilingsNote(hidden: HiddenFilings): string | null {
213
218
  const parts = [
214
219
  count(hidden.pricingSupplements, "pricing supplement", "pricing supplements"),
215
220
  count(hidden.ownershipReportsAboutOthers, "ownership report about another company", "ownership reports about other companies"),
221
+ count(hidden.otherFunds ?? 0, "filing for the trust's other funds", "filings for the trust's other funds"),
216
222
  ].filter((part): part is string => part != null);
217
223
  return parts.length > 0 ? `${parts.join(" and ")} hidden, --all to show` : null;
218
224
  }