@gloom-sh/terminal 0.20.18 → 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 (204) hide show
  1. package/package.json +1 -1
  2. package/src/api-client/cot.ts +5 -6
  3. package/src/api-client/data.ts +11 -1
  4. package/src/api-client/index.ts +1 -0
  5. package/src/api-client/request.ts +162 -40
  6. package/src/api-client/types/news.ts +45 -0
  7. package/src/api-client/types/world-venues.ts +9 -0
  8. package/src/app.tsx +4 -2
  9. package/src/architecture/floating-promise-allowlist.json +1 -1
  10. package/src/cli/commands/market.ts +53 -17
  11. package/src/cli/commands/ticker.ts +13 -6
  12. package/src/cli/context.ts +8 -0
  13. package/src/cli/desktop-pane-shot-browser.ts +3 -1
  14. package/src/cli/desktop-pane-shot-view.ts +0 -1
  15. package/src/cli/desktop-pane-shot.ts +204 -43
  16. package/src/cli/errors.ts +3 -9
  17. package/src/cli/exit-codes.ts +1 -1
  18. package/src/cli/glossary.ts +1 -1
  19. package/src/cli/help.ts +1 -1
  20. package/src/cli/history-rows.ts +2 -2
  21. package/src/cli/index.ts +1 -1
  22. package/src/cli/listing-arg.ts +87 -23
  23. package/src/cli/pane-functions/catalog-snapshot.json +17 -6
  24. package/src/cli/pane-functions/dom.ts +30 -2
  25. package/src/cli/pane-functions/freshness.ts +23 -4
  26. package/src/cli/pane-functions/function-help.ts +3 -3
  27. package/src/cli/pane-functions/headless.ts +9 -1
  28. package/src/cli/pane-functions/index.ts +77 -10
  29. package/src/cli/pane-functions/report-notices.ts +10 -0
  30. package/src/cli/pane-functions/resolver.ts +3 -2
  31. package/src/cli/pane-functions/screenshot-assessment.ts +10 -5
  32. package/src/cli/pane-functions/screenshot-data-evidence.ts +7 -15
  33. package/src/cli/pane-functions/screenshot-payload.ts +24 -10
  34. package/src/cli/pane-functions/screenshot-render.ts +21 -8
  35. package/src/cli/pane-functions/screenshot-types.ts +9 -0
  36. package/src/cli/quote-answer.ts +1 -1
  37. package/src/cli/result.ts +17 -0
  38. package/src/cli/scroll-truncation.ts +7 -2
  39. package/src/cli/ticker-resolution.ts +1 -1
  40. package/src/cli/unreachable.ts +21 -0
  41. package/src/components/chart/composite/drawing-store.ts +11 -7
  42. package/src/components/chart/composite/format.ts +1 -0
  43. package/src/components/chart/composite/legend.tsx +5 -2
  44. package/src/components/chart/composite/panel-surface/plot-gestures.ts +9 -2
  45. package/src/components/chart/composite/panel-surface.tsx +1 -1
  46. package/src/components/chart/composite/tools.ts +164 -39
  47. package/src/components/chart-table/header.tsx +2 -2
  48. package/src/components/chart-table/layout.ts +5 -6
  49. package/src/components/command-bar/routes/root/runtime.ts +11 -3
  50. package/src/components/command-bar/routes/ticker-search/results.ts +5 -0
  51. package/src/components/command-bar/selection-runtime.ts +29 -5
  52. package/src/components/command-bar/surface/index.tsx +4 -1
  53. package/src/components/command-bar/workflow/alert.ts +13 -5
  54. package/src/components/layout/pane/footer/model.ts +10 -2
  55. package/src/components/layout/pane/status-footer.ts +24 -0
  56. package/src/components/price-performance.tsx +26 -8
  57. package/src/components/reader/article-reader.tsx +12 -5
  58. package/src/components/ui/data-table/opentui/index.tsx +7 -0
  59. package/src/components/ui/table-layout.ts +32 -1
  60. package/src/market-data/ah-pair.ts +19 -0
  61. package/src/market-data/coordinator/entries.ts +6 -4
  62. package/src/market-data/coordinator/index.ts +14 -3
  63. package/src/market-data/futures-board.ts +36 -29
  64. package/src/market-data/futures-contract.ts +37 -1
  65. package/src/market-data/market/change-basis.ts +9 -0
  66. package/src/market-data/market/status.ts +40 -4
  67. package/src/market-data/performance.ts +127 -32
  68. package/src/market-data/quotes/time.ts +5 -2
  69. package/src/news/types.ts +28 -0
  70. package/src/notifications/app-badge.ts +2 -3
  71. package/src/notifications/app-notifier.ts +5 -0
  72. package/src/plugins/builtin/alerts/cli.ts +65 -18
  73. package/src/plugins/builtin/alerts/command.ts +39 -9
  74. package/src/plugins/builtin/alerts/event-rows.ts +9 -3
  75. package/src/plugins/builtin/alerts/events-pane.tsx +16 -10
  76. package/src/plugins/builtin/alerts/headless.ts +12 -6
  77. package/src/plugins/builtin/alerts/index.tsx +60 -8
  78. package/src/plugins/builtin/alerts/option-contract.ts +197 -0
  79. package/src/plugins/builtin/alerts/price.ts +30 -5
  80. package/src/plugins/builtin/alerts/pro-rules.ts +62 -0
  81. package/src/plugins/builtin/alerts/research-builder.ts +5 -10
  82. package/src/plugins/builtin/analytics/account-returns.ts +1 -1
  83. package/src/plugins/builtin/analytics/pane-model.ts +2 -2
  84. package/src/plugins/builtin/analytics/risk-client.ts +1 -1
  85. package/src/plugins/builtin/buildout/company/pane.tsx +4 -14
  86. package/src/plugins/builtin/catalysts/model.ts +2 -1
  87. package/src/plugins/builtin/chart-composer/chart-spec.ts +5 -0
  88. package/src/plugins/builtin/chart-composer/cli-options.ts +5 -3
  89. package/src/plugins/builtin/chart-composer/headless-schema.ts +14 -10
  90. package/src/plugins/builtin/chart-composer/headless.ts +2 -0
  91. package/src/plugins/builtin/chart-composer/index.tsx +17 -5
  92. package/src/plugins/builtin/chart-composer/pane.tsx +14 -4
  93. package/src/plugins/builtin/chart-composer/viewport-labels.ts +2 -17
  94. package/src/plugins/builtin/chat/controller/notifications.ts +1 -0
  95. package/src/plugins/builtin/chat/index.tsx +0 -1
  96. package/src/plugins/builtin/commodities-energy/index.tsx +1 -1
  97. package/src/plugins/builtin/company-kpis/headless.ts +1 -1
  98. package/src/plugins/builtin/company-kpis/model.ts +21 -9
  99. package/src/plugins/builtin/congress-trades/model.ts +9 -5
  100. package/src/plugins/builtin/cot/client.ts +2 -3
  101. package/src/plugins/builtin/cot/headless.ts +16 -16
  102. package/src/plugins/builtin/cot/index.tsx +6 -6
  103. package/src/plugins/builtin/cot/model.ts +25 -5
  104. package/src/plugins/builtin/cot/pane.tsx +11 -6
  105. package/src/plugins/builtin/cot/series.ts +11 -8
  106. package/src/plugins/builtin/cpi/model.ts +15 -4
  107. package/src/plugins/builtin/cpi/pane.tsx +29 -7
  108. package/src/plugins/builtin/doe/model.ts +30 -0
  109. package/src/plugins/builtin/doe/pane.tsx +8 -2
  110. package/src/plugins/builtin/earnings/board-table.ts +9 -4
  111. package/src/plugins/builtin/earnings/headless.ts +10 -3
  112. package/src/plugins/builtin/earnings/history-table.ts +4 -2
  113. package/src/plugins/builtin/earnings-calls/calendar.tsx +4 -3
  114. package/src/plugins/builtin/earnings-ripple/pane.tsx +2 -2
  115. package/src/plugins/builtin/econ/index.tsx +4 -2
  116. package/src/plugins/builtin/futures/model.ts +14 -1
  117. package/src/plugins/builtin/futures/series.ts +1 -8
  118. package/src/plugins/builtin/fx-matrix/index.tsx +2 -2
  119. package/src/plugins/builtin/insider/detail.tsx +36 -7
  120. package/src/plugins/builtin/insider/filing-stories.ts +110 -0
  121. package/src/plugins/builtin/insider/headless.ts +37 -2
  122. package/src/plugins/builtin/insider/index.tsx +79 -10
  123. package/src/plugins/builtin/insider/model.ts +43 -5
  124. package/src/plugins/builtin/ipo-calendar/client.ts +11 -1
  125. package/src/plugins/builtin/ipo-calendar/model.ts +3 -7
  126. package/src/plugins/builtin/jobs/headless.ts +2 -1
  127. package/src/plugins/builtin/jobs/model.ts +6 -0
  128. package/src/plugins/builtin/jobs/pane.tsx +8 -3
  129. package/src/plugins/builtin/news/wire/news/detail-view.tsx +118 -10
  130. package/src/plugins/builtin/news/wire/news/story-evidence.ts +178 -0
  131. package/src/plugins/builtin/options/analytics.ts +1 -1
  132. package/src/plugins/builtin/options/view.tsx +18 -11
  133. package/src/plugins/builtin/options-positioning/model.ts +11 -0
  134. package/src/plugins/builtin/options-positioning/pane.tsx +22 -1
  135. package/src/plugins/builtin/options-scenario/client.ts +49 -8
  136. package/src/plugins/builtin/options-scenario/headless.ts +7 -3
  137. package/src/plugins/builtin/options-scenario/model.ts +33 -2
  138. package/src/plugins/builtin/options-scenario/pane.tsx +3 -4
  139. package/src/plugins/builtin/perps/cascade.ts +4 -3
  140. package/src/plugins/builtin/perps/markets-section.tsx +5 -2
  141. package/src/plugins/builtin/perps/model.ts +4 -3
  142. package/src/plugins/builtin/portfolio-list/table.tsx +3 -2
  143. package/src/plugins/builtin/research/corporate-actions-pane.tsx +29 -14
  144. package/src/plugins/builtin/research/event-model.ts +12 -6
  145. package/src/plugins/builtin/research-search/index.tsx +3 -1
  146. package/src/plugins/builtin/scanner/denied.tsx +16 -4
  147. package/src/plugins/builtin/scanner/flow-pane.tsx +1 -1
  148. package/src/plugins/builtin/scanner/hilo-pane.tsx +1 -1
  149. package/src/plugins/builtin/sec/filing-display.tsx +14 -2
  150. package/src/plugins/builtin/sec/headless.ts +42 -4
  151. package/src/plugins/builtin/sec/index.tsx +21 -1
  152. package/src/plugins/builtin/sectors/sector-model.ts +1 -1
  153. package/src/plugins/builtin/shared/earnings-report.ts +32 -3
  154. package/src/plugins/builtin/shared/options-pro-copy.ts +34 -0
  155. package/src/plugins/builtin/shared/statement-currency.ts +23 -0
  156. package/src/plugins/builtin/shared/ticker-surface.ts +1 -1
  157. package/src/plugins/builtin/supply-chain/pane.tsx +4 -3
  158. package/src/plugins/builtin/themes/headless.ts +4 -4
  159. package/src/plugins/builtin/themes/model.ts +11 -8
  160. package/src/plugins/builtin/themes/pane.tsx +2 -2
  161. package/src/plugins/builtin/ticker-detail/financials/model.ts +22 -32
  162. package/src/plugins/builtin/ticker-detail/financials/tab.tsx +7 -9
  163. package/src/plugins/builtin/ticker-detail/headless-schema.ts +2 -0
  164. package/src/plugins/builtin/ticker-detail/headless.ts +28 -12
  165. package/src/plugins/builtin/ticker-detail/overview/board-lot.ts +21 -0
  166. package/src/plugins/builtin/ticker-detail/overview/model.ts +11 -1
  167. package/src/plugins/builtin/ticker-detail/overview/pane.tsx +4 -0
  168. package/src/plugins/builtin/ticker-detail/overview-tab.tsx +61 -13
  169. package/src/plugins/builtin/volatility/pane.tsx +3 -3
  170. package/src/plugins/builtin/world-venue-map/headless.ts +4 -2
  171. package/src/plugins/builtin/world-venue-map/model.ts +6 -1
  172. package/src/plugins/builtin/world-venue-map/venue-header.tsx +5 -3
  173. package/src/plugins/catalog-browser.ts +10 -1
  174. package/src/renderers/browser/activity.ts +16 -0
  175. package/src/renderers/browser/app-badge-host.ts +14 -0
  176. package/src/renderers/browser/main.tsx +5 -0
  177. package/src/renderers/browser/notifications.ts +103 -0
  178. package/src/renderers/browser/ui-host.tsx +4 -0
  179. package/src/renderers/dom/data-table/index.tsx +27 -4
  180. package/src/renderers/electrobun/view/http-fetch.ts +3 -2
  181. package/src/sources/gloomberb-cloud/index.ts +8 -6
  182. package/src/sources/gloomberb-cloud/news.ts +35 -0
  183. package/src/sources/provider-errors.ts +34 -7
  184. package/src/sources/provider-router/history.ts +32 -6
  185. package/src/time-series/base-series.ts +39 -6
  186. package/src/time-series/chart-seed.ts +2 -2
  187. package/src/time-series/history-quality.ts +4 -1
  188. package/src/time-series/hooks.ts +2 -0
  189. package/src/time-series/price-comparison.ts +17 -23
  190. package/src/time-series/reporting.ts +1 -1
  191. package/src/time-series/resolution.ts +13 -0
  192. package/src/time-series/resolve-context.ts +6 -0
  193. package/src/time-series/resolve.ts +39 -2
  194. package/src/time-series/types.ts +2 -1
  195. package/src/types/financials.ts +9 -1
  196. package/src/types/headless.ts +1 -0
  197. package/src/types/issuer-listings.ts +2 -0
  198. package/src/types/plugin-notifications.ts +3 -0
  199. package/src/types/price-history.ts +6 -4
  200. package/src/ui/host.tsx +2 -0
  201. package/src/utils/exchange-announcements.ts +7 -2
  202. package/src/utils/fundamentals.ts +40 -0
  203. package/src/utils/network-failure.ts +2 -0
  204. package/src/utils/price-history-integrity.ts +9 -1
@@ -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
+ }
@@ -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
+ }
@@ -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"}]
@@ -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 },
@@ -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;
@@ -280,7 +280,7 @@ export function validateRiskHistory(
280
280
  }));
281
281
  const local = resolveDatedReturns(prices);
282
282
  if (local.integrity)
283
- throw new Error("Daily history has inconsistent OHLC observations");
283
+ throw new Error("Daily history has contradictory prices");
284
284
  // A converted series is on the NYSE calendar the basket and SPY share.
285
285
  const usd = conversion
286
286
  ? convertClosesToUsd(
@@ -16,6 +16,7 @@ import {
16
16
  type StatItem,
17
17
  } from "../../../../components";
18
18
  import { statGridWithin } from "../../../../components/ui/stat-grid";
19
+ import { dropColumnsToFit } from "../../../../components/ui/table-layout";
19
20
  import { useAsyncResource, usePaneSettingValue, usePluginAppActions } from "../../../../public/react";
20
21
  import { usePaneStateValue } from "../../../../state/app/context";
21
22
  import { usePaneTickerIdentity } from "../../../../state/hooks/pane-ticker";
@@ -81,17 +82,6 @@ const SIGNAL_COLUMNS: BuildoutColumn[] = [
81
82
  { id: "companies", label: "Also", width: 16, align: "left" },
82
83
  ];
83
84
 
84
- /** Columns that fit `width`, the flexible ones first to give way after the fixed tail. */
85
- function fitColumns<C extends DataTableColumn>(columns: readonly C[], width: number, dropOrder: readonly string[]): C[] {
86
- let kept = [...columns];
87
- for (const id of dropOrder) {
88
- const total = kept.reduce((sum, column) => sum + column.width + 1, 0);
89
- if (total <= width) break;
90
- kept = kept.filter((column) => column.id !== id);
91
- }
92
- return kept;
93
- }
94
-
95
85
  function headerItems(profile: BuildoutCompanyProfile): StatItem[] {
96
86
  const count = (role: BuildoutRelation["role"]) => profile.relations.filter((relation) => relation.role === role).length;
97
87
  const power = count("power");
@@ -233,7 +223,7 @@ export function BuildoutCompanyPane({ focused, width, height }: PaneProps) {
233
223
  </ScrollBox>
234
224
  );
235
225
  } else if (tab === "sites") {
236
- const columns = fitColumns(SITE_COLUMNS, width - 1, ["place", "type", "mw"]);
226
+ const columns = dropColumnsToFit(SITE_COLUMNS, width - 1, ["place", "type", "mw"]);
237
227
  body = (
238
228
  <DataTableStackView<BuildoutCompanySite, SiteColumn>
239
229
  focused={focused}
@@ -253,7 +243,7 @@ export function BuildoutCompanyPane({ focused, width, height }: PaneProps) {
253
243
  />
254
244
  );
255
245
  } else if (tab === "hiring") {
256
- const columns = fitColumns(HIRING_COLUMNS, width - 1, ["site", "family", "change"]);
246
+ const columns = dropColumnsToFit(HIRING_COLUMNS, width - 1, ["site", "family", "change"]);
257
247
  body = company.hiring.segments.length ? (
258
248
  <DataTableStackView<BuildoutHiringSegment, HiringColumn>
259
249
  focused={focused}
@@ -298,7 +288,7 @@ export function BuildoutCompanyPane({ focused, width, height }: PaneProps) {
298
288
  )}
299
289
  rootWidth={width}
300
290
  rootHeight={bodyHeight}
301
- columns={fitColumns(SIGNAL_COLUMNS, width - 1, ["companies"])}
291
+ columns={dropColumnsToFit(SIGNAL_COLUMNS, width - 1, ["companies"])}
302
292
  sortColumnId={null}
303
293
  sortDirection="asc"
304
294
  items={signalRows}
@@ -1,6 +1,7 @@
1
1
  import { MISSING_VALUE } from "../../../utils/format";
2
2
  import type { CatalystEvent, CatalystFilters, CatalystResponse, CatalystType } from "../../../api-client/catalysts";
3
3
  import type { DataTableColumn, TableSection } from "../../../components";
4
+ import { markHiddenTableColumns } from "../../../components/ui/table-layout";
4
5
  import { publicTickerKey } from "../../../utils/exchanges";
5
6
  import { humanLabel, type StateTone } from "../shared/research-cells";
6
7
 
@@ -90,7 +91,7 @@ function fitColumns(columns: FitColumn[], width: number): DataTableColumn[] {
90
91
  if (over > 0) kept = kept.map((column) => column.id === "basis" ? { ...column, width: Math.max(column.min ?? column.width, column.width - over) } : column);
91
92
  if (tableNeed(kept) > width) kept = kept.map((column) => ({ ...column, width: column.min ?? column.width }));
92
93
  for (const id of ["basis", "parties"]) drop(id);
93
- return kept.map(({ min: _min, ...column }) => column);
94
+ return markHiddenTableColumns(columns, kept.map(({ min: _min, ...column }) => column));
94
95
  }
95
96
 
96
97
  /** The date basis column as wide as its longest label on screen ("Primary completion (actual)"), never narrower than its heading. */
@@ -7,6 +7,7 @@ import {
7
7
  validateChartSpec,
8
8
  } from "../../../time-series/spec";
9
9
  import { isRecord } from "../../../utils/guards";
10
+ import type { ChartResolution, TimeRange } from "../../../time-series/range";
10
11
 
11
12
  export const CHART_SPEC_SETTING_KEY = "chartSpec";
12
13
  export const CHART_INTERACTION_VIEWPORT_SETTING_KEY = "chartInteractionViewport";
@@ -33,6 +34,10 @@ export function parseSharedPinnedMoment(value: unknown, now = Date.now()): numbe
33
34
  }
34
35
  export const MAX_CHART_COMPOSER_SERIES = MAX_CHART_SERIES;
35
36
 
37
+ export function comparisonPresetResolution(range: TimeRange): ChartResolution {
38
+ return range === "1D" ? "auto" : "1d";
39
+ }
40
+
36
41
  export interface ChartInteractionViewport {
37
42
  authoredViewportKey: string;
38
43
  start: string;
@@ -12,6 +12,7 @@ import {
12
12
  import type { ChartSeriesSpec, ChartSpec, SeriesPeriod } from "../../../time-series/types";
13
13
  import { yearToDateBaseDay } from "../../../market-data/market/year-to-date";
14
14
  import { readPriceWindow } from "../../../utils/price-window";
15
+ import { comparisonPresetResolution } from "./chart-spec";
15
16
 
16
17
  const PRICE_CAPABILITIES = new Set(["price-chart", "intraday-price-chart", "price-comparison"]);
17
18
 
@@ -73,7 +74,8 @@ export function applyChartComposerCapabilityOptions(
73
74
  const range = capabilityId === "intraday-price-chart" && typeof options.session === "string"
74
75
  ? "1D"
75
76
  : selectedRange;
76
- const resolution = chartResolution(options);
77
+ const resolution = chartResolution(options)
78
+ ?? (capabilityId === "price-comparison" ? comparisonPresetResolution(range ?? next.viewport.range) : null);
77
79
  if (range || resolution) {
78
80
  next = {
79
81
  ...next,
@@ -95,7 +97,7 @@ export function applyChartComposerCapabilityOptions(
95
97
  } } };
96
98
  }
97
99
 
98
- if (capabilityId === "price-chart" && options.extendedHours === true) {
100
+ if ((capabilityId === "price-chart" || capabilityId === "price-comparison") && options.extendedHours === true) {
99
101
  next = { ...next, viewport: { ...next.viewport, extendedHours: true } };
100
102
  }
101
103
 
@@ -104,7 +106,7 @@ export function applyChartComposerCapabilityOptions(
104
106
  }
105
107
 
106
108
  // --currency USD: every leg converted into it at each day's FX close.
107
- if (capabilityId === "price-comparison" && typeof options.currency === "string" && /^[A-Z]{3}$/.test(options.currency)) {
109
+ if ((capabilityId === "price-comparison" || capabilityId === "fundamental-series") && typeof options.currency === "string" && /^[A-Z]{3}$/.test(options.currency)) {
108
110
  next = { ...next, viewport: { ...next.viewport, currency: options.currency } };
109
111
  }
110
112
 
@@ -5,6 +5,7 @@ import { FINANCIAL_PERIOD_OPTION, FINANCIAL_PERIOD_COUNT_OPTION, HISTORY_RANGE_V
5
5
  import { DATE_OPTION_EXAMPLES } from "../../../utils/calendar-date";
6
6
  import { PRICE_WINDOW_FROM_HELP, PRICE_WINDOW_TO_HELP } from "../../../utils/price-window";
7
7
  import { isCurrencyCode } from "../../../utils/currency-pair";
8
+ import { STATEMENT_CURRENCY_OPTION } from "../shared/statement-currency";
8
9
 
9
10
  type PaneSchema = Pick<HeadlessPaneDefinition, "argument" | "options" | "discovery">;
10
11
 
@@ -17,6 +18,13 @@ const FUNDAMENTAL_PERIOD_OPTION: HeadlessPaneOptionDef = { ...FINANCIAL_PERIOD_O
17
18
 
18
19
  const BAR_SIZES = CHART_BAR_SIZE_PRESETS.map((value) => ({ value }));
19
20
 
21
+ const EXTENDED_HOURS_OPTION = {
22
+ key: "extendedHours",
23
+ description: "Include pre-market and after-hours bars on an intraday chart of a US listing.",
24
+ type: "boolean" as const,
25
+ defaultValue: false,
26
+ };
27
+
20
28
  const BAR_SIZE_DESCRIPTION = "Bar size: any count of minutes, hours, days, weeks or months; one the source does not serve is built from its shorter bars";
21
29
 
22
30
  /**
@@ -85,12 +93,7 @@ export const paneSchemas = {
85
93
  values: HISTORY_RANGE_VALUES,
86
94
  defaultValue: "5Y",
87
95
  },
88
- {
89
- key: "extendedHours",
90
- description: "Include pre-market and after-hours bars on an intraday chart of a US listing.",
91
- type: "boolean",
92
- defaultValue: false,
93
- },
96
+ EXTENDED_HOURS_OPTION,
94
97
  ],
95
98
  discovery: {
96
99
  id: "price-chart",
@@ -136,7 +139,7 @@ export const paneSchemas = {
136
139
  options: [
137
140
  {
138
141
  key: "rangePreset",
139
- description: "Price-history window. YTD runs from the prior year's last close.",
142
+ description: "Price-history window. 1D compares intraday bars in the latest session; YTD runs from the prior year's last close.",
140
143
  type: "enum",
141
144
  aliases: ["range"],
142
145
  values: RETURN_RANGE_VALUES,
@@ -172,19 +175,19 @@ export const paneSchemas = {
172
175
  },
173
176
  {
174
177
  key: "chartResolution",
175
- description: BAR_SIZE_DESCRIPTION,
178
+ description: `${BAR_SIZE_DESCRIPTION}. Defaults to intraday for 1D and daily otherwise`,
176
179
  type: "enum",
177
180
  aliases: ["resolution"],
178
181
  values: BAR_SIZES,
179
- defaultValue: "1d",
180
182
  normalize: (value) => normalizeBarSize(value, false),
181
183
  },
184
+ EXTENDED_HOURS_OPTION,
182
185
  ],
183
186
  discovery: {
184
187
  id: "price-comparison",
185
188
  aliases: ["stock comparison", "price performance comparison", "returns comparison", "compare stock prices", "hedged vs unhedged",
186
189
  "currency hedged"],
187
- limitations: ["Compares closing-price changes over shared observation dates, in each listing's currency unless currency is set, which converts each close at that day's FX close. Cash distributions are excluded unless totalReturn is set, which reinvests each distribution at its ex-date close."],
190
+ limitations: ["Compares price changes over shared bar times for 1D and shared observation dates for daily bars. Uses each listing's currency unless currency is set, which converts each bar at that day's FX close. Cash distributions are excluded unless totalReturn is set, which reinvests each distribution at its ex-date close."],
188
191
  screenshotReadiness: "ready",
189
192
  },
190
193
  },
@@ -217,6 +220,7 @@ export const paneSchemas = {
217
220
  },
218
221
  FUNDAMENTAL_PERIOD_OPTION,
219
222
  FINANCIAL_PERIOD_COUNT_OPTION,
223
+ STATEMENT_CURRENCY_OPTION,
220
224
  ],
221
225
  discovery: {
222
226
  id: "fundamental-series",
@@ -34,6 +34,7 @@ import { uncoveredCapabilityMessage } from "../../../capabilities/chart-series";
34
34
  import { loadFuturesContractTerms, loadFuturesPriceUnit } from "../../../market-data/futures-contract";
35
35
  import { formulaContractNote, formulaRollNote } from "../../../time-series/studies/formula";
36
36
  import { loadDailyFxCloses } from "../../../time-series/currency-conversion";
37
+ import { loadStatementCurrency } from "../shared/statement-currency";
37
38
  import { canonicalExchange, isKnownExchangeCode, isUsListingExchange, parsePublicTickerKey, publicTickerKey } from "../../../utils/exchanges";
38
39
  import { zonedDateKey, zonedDateTimeParts } from "../../../utils/zoned-date-time";
39
40
  import { futuresSessionOpenMinute } from "../../../market-data/market/trading-sessions";
@@ -162,6 +163,7 @@ export async function loadChartPaneModel(
162
163
  loadFuturesPriceUnit: (symbol) => loadFuturesPriceUnit(symbol, (key) => loadFuturesContractTerms(key, context.apiClient)),
163
164
  loadEarningsHistory: (symbol) => context.apiClient.getCloudEarningsHistory(symbol, 100),
164
165
  loadFxCloses: (currency, startDate) => loadDailyFxCloses(currency, startDate, context.apiClient),
166
+ loadStatementCurrency: (target, currencies) => loadStatementCurrency(target, currencies, context),
165
167
  loadFredSeries: async (request) => ({
166
168
  data: await context.apiClient.getCloudFredSeries(request.seriesId, {
167
169
  startDate: request.startDate,