@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.
- package/package.json +1 -1
- package/src/api-client/cot.ts +5 -6
- package/src/api-client/data.ts +11 -1
- package/src/api-client/index.ts +1 -0
- package/src/api-client/request.ts +162 -40
- package/src/api-client/types/news.ts +45 -0
- package/src/api-client/types/world-venues.ts +9 -0
- package/src/app.tsx +4 -2
- package/src/architecture/floating-promise-allowlist.json +1 -1
- package/src/cli/commands/market.ts +53 -17
- package/src/cli/commands/ticker.ts +13 -6
- package/src/cli/context.ts +8 -0
- package/src/cli/desktop-pane-shot-browser.ts +3 -1
- package/src/cli/desktop-pane-shot-view.ts +0 -1
- package/src/cli/desktop-pane-shot.ts +204 -43
- package/src/cli/errors.ts +3 -9
- package/src/cli/exit-codes.ts +1 -1
- package/src/cli/glossary.ts +1 -1
- package/src/cli/help.ts +1 -1
- package/src/cli/history-rows.ts +2 -2
- package/src/cli/index.ts +1 -1
- package/src/cli/listing-arg.ts +87 -23
- package/src/cli/pane-functions/catalog-snapshot.json +17 -6
- package/src/cli/pane-functions/dom.ts +30 -2
- package/src/cli/pane-functions/freshness.ts +23 -4
- package/src/cli/pane-functions/function-help.ts +3 -3
- package/src/cli/pane-functions/headless.ts +9 -1
- package/src/cli/pane-functions/index.ts +77 -10
- package/src/cli/pane-functions/report-notices.ts +10 -0
- package/src/cli/pane-functions/resolver.ts +3 -2
- package/src/cli/pane-functions/screenshot-assessment.ts +10 -5
- package/src/cli/pane-functions/screenshot-data-evidence.ts +7 -15
- package/src/cli/pane-functions/screenshot-payload.ts +24 -10
- package/src/cli/pane-functions/screenshot-render.ts +21 -8
- package/src/cli/pane-functions/screenshot-types.ts +9 -0
- package/src/cli/quote-answer.ts +1 -1
- package/src/cli/result.ts +17 -0
- package/src/cli/scroll-truncation.ts +7 -2
- package/src/cli/ticker-resolution.ts +1 -1
- package/src/cli/unreachable.ts +21 -0
- package/src/components/chart/composite/drawing-store.ts +11 -7
- package/src/components/chart/composite/format.ts +1 -0
- package/src/components/chart/composite/legend.tsx +5 -2
- package/src/components/chart/composite/panel-surface/plot-gestures.ts +9 -2
- package/src/components/chart/composite/panel-surface.tsx +1 -1
- package/src/components/chart/composite/tools.ts +164 -39
- package/src/components/chart-table/header.tsx +2 -2
- package/src/components/chart-table/layout.ts +5 -6
- package/src/components/command-bar/routes/root/runtime.ts +11 -3
- package/src/components/command-bar/routes/ticker-search/results.ts +5 -0
- package/src/components/command-bar/selection-runtime.ts +29 -5
- package/src/components/command-bar/surface/index.tsx +4 -1
- package/src/components/command-bar/workflow/alert.ts +13 -5
- package/src/components/layout/pane/footer/model.ts +10 -2
- package/src/components/layout/pane/status-footer.ts +24 -0
- package/src/components/price-performance.tsx +26 -8
- package/src/components/reader/article-reader.tsx +12 -5
- package/src/components/ui/data-table/opentui/index.tsx +7 -0
- package/src/components/ui/table-layout.ts +32 -1
- package/src/market-data/ah-pair.ts +19 -0
- package/src/market-data/coordinator/entries.ts +6 -4
- package/src/market-data/coordinator/index.ts +14 -3
- package/src/market-data/futures-board.ts +36 -29
- package/src/market-data/futures-contract.ts +37 -1
- package/src/market-data/market/change-basis.ts +9 -0
- package/src/market-data/market/status.ts +40 -4
- package/src/market-data/performance.ts +127 -32
- package/src/market-data/quotes/time.ts +5 -2
- package/src/news/types.ts +28 -0
- package/src/notifications/app-badge.ts +2 -3
- package/src/notifications/app-notifier.ts +5 -0
- package/src/plugins/builtin/alerts/cli.ts +65 -18
- package/src/plugins/builtin/alerts/command.ts +39 -9
- package/src/plugins/builtin/alerts/event-rows.ts +9 -3
- package/src/plugins/builtin/alerts/events-pane.tsx +16 -10
- package/src/plugins/builtin/alerts/headless.ts +12 -6
- package/src/plugins/builtin/alerts/index.tsx +60 -8
- package/src/plugins/builtin/alerts/option-contract.ts +197 -0
- package/src/plugins/builtin/alerts/price.ts +30 -5
- package/src/plugins/builtin/alerts/pro-rules.ts +62 -0
- package/src/plugins/builtin/alerts/research-builder.ts +5 -10
- package/src/plugins/builtin/analytics/account-returns.ts +1 -1
- package/src/plugins/builtin/analytics/pane-model.ts +2 -2
- package/src/plugins/builtin/analytics/risk-client.ts +1 -1
- package/src/plugins/builtin/buildout/company/pane.tsx +4 -14
- package/src/plugins/builtin/catalysts/model.ts +2 -1
- package/src/plugins/builtin/chart-composer/chart-spec.ts +5 -0
- package/src/plugins/builtin/chart-composer/cli-options.ts +5 -3
- package/src/plugins/builtin/chart-composer/headless-schema.ts +14 -10
- package/src/plugins/builtin/chart-composer/headless.ts +2 -0
- package/src/plugins/builtin/chart-composer/index.tsx +17 -5
- package/src/plugins/builtin/chart-composer/pane.tsx +14 -4
- package/src/plugins/builtin/chart-composer/viewport-labels.ts +2 -17
- package/src/plugins/builtin/chat/controller/notifications.ts +1 -0
- package/src/plugins/builtin/chat/index.tsx +0 -1
- package/src/plugins/builtin/commodities-energy/index.tsx +1 -1
- package/src/plugins/builtin/company-kpis/headless.ts +1 -1
- package/src/plugins/builtin/company-kpis/model.ts +21 -9
- package/src/plugins/builtin/congress-trades/model.ts +9 -5
- package/src/plugins/builtin/cot/client.ts +2 -3
- package/src/plugins/builtin/cot/headless.ts +16 -16
- package/src/plugins/builtin/cot/index.tsx +6 -6
- package/src/plugins/builtin/cot/model.ts +25 -5
- package/src/plugins/builtin/cot/pane.tsx +11 -6
- package/src/plugins/builtin/cot/series.ts +11 -8
- package/src/plugins/builtin/cpi/model.ts +15 -4
- package/src/plugins/builtin/cpi/pane.tsx +29 -7
- package/src/plugins/builtin/doe/model.ts +30 -0
- package/src/plugins/builtin/doe/pane.tsx +8 -2
- package/src/plugins/builtin/earnings/board-table.ts +9 -4
- package/src/plugins/builtin/earnings/headless.ts +10 -3
- package/src/plugins/builtin/earnings/history-table.ts +4 -2
- package/src/plugins/builtin/earnings-calls/calendar.tsx +4 -3
- package/src/plugins/builtin/earnings-ripple/pane.tsx +2 -2
- package/src/plugins/builtin/econ/index.tsx +4 -2
- package/src/plugins/builtin/futures/model.ts +14 -1
- package/src/plugins/builtin/futures/series.ts +1 -8
- package/src/plugins/builtin/fx-matrix/index.tsx +2 -2
- package/src/plugins/builtin/insider/detail.tsx +36 -7
- package/src/plugins/builtin/insider/filing-stories.ts +110 -0
- package/src/plugins/builtin/insider/headless.ts +37 -2
- package/src/plugins/builtin/insider/index.tsx +79 -10
- package/src/plugins/builtin/insider/model.ts +43 -5
- package/src/plugins/builtin/ipo-calendar/client.ts +11 -1
- package/src/plugins/builtin/ipo-calendar/model.ts +3 -7
- package/src/plugins/builtin/jobs/headless.ts +2 -1
- package/src/plugins/builtin/jobs/model.ts +6 -0
- package/src/plugins/builtin/jobs/pane.tsx +8 -3
- package/src/plugins/builtin/news/wire/news/detail-view.tsx +118 -10
- package/src/plugins/builtin/news/wire/news/story-evidence.ts +178 -0
- package/src/plugins/builtin/options/analytics.ts +1 -1
- package/src/plugins/builtin/options/view.tsx +18 -11
- package/src/plugins/builtin/options-positioning/model.ts +11 -0
- package/src/plugins/builtin/options-positioning/pane.tsx +22 -1
- package/src/plugins/builtin/options-scenario/client.ts +49 -8
- package/src/plugins/builtin/options-scenario/headless.ts +7 -3
- package/src/plugins/builtin/options-scenario/model.ts +33 -2
- package/src/plugins/builtin/options-scenario/pane.tsx +3 -4
- package/src/plugins/builtin/perps/cascade.ts +4 -3
- package/src/plugins/builtin/perps/markets-section.tsx +5 -2
- package/src/plugins/builtin/perps/model.ts +4 -3
- package/src/plugins/builtin/portfolio-list/table.tsx +3 -2
- package/src/plugins/builtin/research/corporate-actions-pane.tsx +29 -14
- package/src/plugins/builtin/research/event-model.ts +12 -6
- package/src/plugins/builtin/research-search/index.tsx +3 -1
- package/src/plugins/builtin/scanner/denied.tsx +16 -4
- package/src/plugins/builtin/scanner/flow-pane.tsx +1 -1
- package/src/plugins/builtin/scanner/hilo-pane.tsx +1 -1
- package/src/plugins/builtin/sec/filing-display.tsx +14 -2
- package/src/plugins/builtin/sec/headless.ts +42 -4
- package/src/plugins/builtin/sec/index.tsx +21 -1
- package/src/plugins/builtin/sectors/sector-model.ts +1 -1
- package/src/plugins/builtin/shared/earnings-report.ts +32 -3
- package/src/plugins/builtin/shared/options-pro-copy.ts +34 -0
- package/src/plugins/builtin/shared/statement-currency.ts +23 -0
- package/src/plugins/builtin/shared/ticker-surface.ts +1 -1
- package/src/plugins/builtin/supply-chain/pane.tsx +4 -3
- package/src/plugins/builtin/themes/headless.ts +4 -4
- package/src/plugins/builtin/themes/model.ts +11 -8
- package/src/plugins/builtin/themes/pane.tsx +2 -2
- package/src/plugins/builtin/ticker-detail/financials/model.ts +22 -32
- package/src/plugins/builtin/ticker-detail/financials/tab.tsx +7 -9
- package/src/plugins/builtin/ticker-detail/headless-schema.ts +2 -0
- package/src/plugins/builtin/ticker-detail/headless.ts +28 -12
- package/src/plugins/builtin/ticker-detail/overview/board-lot.ts +21 -0
- package/src/plugins/builtin/ticker-detail/overview/model.ts +11 -1
- package/src/plugins/builtin/ticker-detail/overview/pane.tsx +4 -0
- package/src/plugins/builtin/ticker-detail/overview-tab.tsx +61 -13
- package/src/plugins/builtin/volatility/pane.tsx +3 -3
- package/src/plugins/builtin/world-venue-map/headless.ts +4 -2
- package/src/plugins/builtin/world-venue-map/model.ts +6 -1
- package/src/plugins/builtin/world-venue-map/venue-header.tsx +5 -3
- package/src/plugins/catalog-browser.ts +10 -1
- package/src/renderers/browser/activity.ts +16 -0
- package/src/renderers/browser/app-badge-host.ts +14 -0
- package/src/renderers/browser/main.tsx +5 -0
- package/src/renderers/browser/notifications.ts +103 -0
- package/src/renderers/browser/ui-host.tsx +4 -0
- package/src/renderers/dom/data-table/index.tsx +27 -4
- package/src/renderers/electrobun/view/http-fetch.ts +3 -2
- package/src/sources/gloomberb-cloud/index.ts +8 -6
- package/src/sources/gloomberb-cloud/news.ts +35 -0
- package/src/sources/provider-errors.ts +34 -7
- package/src/sources/provider-router/history.ts +32 -6
- package/src/time-series/base-series.ts +39 -6
- package/src/time-series/chart-seed.ts +2 -2
- package/src/time-series/history-quality.ts +4 -1
- package/src/time-series/hooks.ts +2 -0
- package/src/time-series/price-comparison.ts +17 -23
- package/src/time-series/reporting.ts +1 -1
- package/src/time-series/resolution.ts +13 -0
- package/src/time-series/resolve-context.ts +6 -0
- package/src/time-series/resolve.ts +39 -2
- package/src/time-series/types.ts +2 -1
- package/src/types/financials.ts +9 -1
- package/src/types/headless.ts +1 -0
- package/src/types/issuer-listings.ts +2 -0
- package/src/types/plugin-notifications.ts +3 -0
- package/src/types/price-history.ts +6 -4
- package/src/ui/host.tsx +2 -0
- package/src/utils/exchange-announcements.ts +7 -2
- package/src/utils/fundamentals.ts +40 -0
- package/src/utils/network-failure.ts +2 -0
- package/src/utils/price-history-integrity.ts +9 -1
|
@@ -27,6 +27,7 @@ import {
|
|
|
27
27
|
buildTableGridTemplateColumns,
|
|
28
28
|
getTableWidth,
|
|
29
29
|
hasMeaningfulTableHorizontalOverflow,
|
|
30
|
+
hiddenTableColumnText,
|
|
30
31
|
tableFreezesFirstColumn,
|
|
31
32
|
} from "../../../components/ui/table-layout";
|
|
32
33
|
import { WEB_CELL_HEIGHT, WEB_CELL_WIDTH } from "../../../theme/font-scale";
|
|
@@ -61,12 +62,12 @@ const OVERFLOW_FADE_PX = 28;
|
|
|
61
62
|
* rather than as a mask on it so the vertical scrollbar stays crisp. The
|
|
62
63
|
* header band fades into the header colour and the rows into the table's.
|
|
63
64
|
*/
|
|
64
|
-
function overflowFadeStyle(side: "left" | "right", offsetPx: number, bottomPx: number): CSSProperties {
|
|
65
|
+
function overflowFadeStyle(side: "left" | "right", offsetPx: number, bottomPx: number, topPx: number): CSSProperties {
|
|
65
66
|
const direction = side === "left" ? "to left" : "to right";
|
|
66
67
|
const headerPx = tableHeaderPx();
|
|
67
68
|
return {
|
|
68
69
|
position: "absolute",
|
|
69
|
-
top:
|
|
70
|
+
top: topPx,
|
|
70
71
|
bottom: bottomPx,
|
|
71
72
|
[side]: offsetPx,
|
|
72
73
|
width: OVERFLOW_FADE_PX,
|
|
@@ -345,6 +346,8 @@ export function WebDataTable<T, C extends DataTableColumn = DataTableColumn>({
|
|
|
345
346
|
}, [bodyHorizontal.bar, headerHorizontal.bar, horizontalScrollEnabled]);
|
|
346
347
|
|
|
347
348
|
const overflowEdges = useHorizontalScrollEdges(bodyElementRef, [horizontalScrollEnabled]);
|
|
349
|
+
const hiddenColumns = items.length ? hiddenTableColumnText(columns) : null;
|
|
350
|
+
const disclosureHeight = hiddenColumns ? headerPx : 0;
|
|
348
351
|
// A frozen first column already covers what scrolls under it, so the left
|
|
349
352
|
// fade starts past it and its gap.
|
|
350
353
|
const [frozenEdgePx, setFrozenEdgePx] = useState(0);
|
|
@@ -398,6 +401,11 @@ export function WebDataTable<T, C extends DataTableColumn = DataTableColumn>({
|
|
|
398
401
|
|
|
399
402
|
return (
|
|
400
403
|
<div data-gloom-role="data-table" style={rootStyle}>
|
|
404
|
+
{hiddenColumns ? <div style={{ flex: `0 0 ${disclosureHeight}px`, lineHeight: `${disclosureHeight}px`,
|
|
405
|
+
paddingInline: "var(--gloom-space-sm)", color: CSS_TEXT_DIM,
|
|
406
|
+
backgroundColor: CSS_PANEL, whiteSpace: "nowrap", overflow: "hidden", textOverflow: "ellipsis" }} title={hiddenColumns}>
|
|
407
|
+
{hiddenColumns}
|
|
408
|
+
</div> : null}
|
|
401
409
|
<div
|
|
402
410
|
ref={bodyElementRef}
|
|
403
411
|
data-gloom-role="data-table-body-scroll"
|
|
@@ -546,16 +554,31 @@ export function WebDataTable<T, C extends DataTableColumn = DataTableColumn>({
|
|
|
546
554
|
<div
|
|
547
555
|
data-gloom-role="data-table-overflow-fade"
|
|
548
556
|
data-gloom-edge="left"
|
|
549
|
-
style={overflowFadeStyle("left", frozenEdgePx, overflowEdges.scrollbarBottom)}
|
|
557
|
+
style={overflowFadeStyle("left", frozenEdgePx, overflowEdges.scrollbarBottom, disclosureHeight)}
|
|
550
558
|
/>
|
|
551
559
|
) : null}
|
|
552
560
|
{horizontalScrollEnabled && overflowEdges.end ? (
|
|
553
561
|
<div
|
|
554
562
|
data-gloom-role="data-table-overflow-fade"
|
|
555
563
|
data-gloom-edge="right"
|
|
556
|
-
style={overflowFadeStyle("right", overflowEdges.scrollbarRight, overflowEdges.scrollbarBottom)}
|
|
564
|
+
style={overflowFadeStyle("right", overflowEdges.scrollbarRight, overflowEdges.scrollbarBottom, disclosureHeight)}
|
|
557
565
|
/>
|
|
558
566
|
) : null}
|
|
567
|
+
{horizontalScrollEnabled && overflowEdges.end && items.length ? (
|
|
568
|
+
<button type="button" aria-label="Show more columns" onClick={() => {
|
|
569
|
+
const body = bodyElementRef.current;
|
|
570
|
+
if (!body) return;
|
|
571
|
+
focusPane();
|
|
572
|
+
const bounds = body.getBoundingClientRect();
|
|
573
|
+
const visibleRight = bounds.left + body.clientWidth;
|
|
574
|
+
const next = [...body.querySelectorAll<HTMLElement>('[data-gloom-role="data-table-header-cell"]')]
|
|
575
|
+
.map((cell) => cell.getBoundingClientRect()).find((cell) => cell.right > visibleRight + 1 && cell.left > bounds.left + frozenEdgePx + 1);
|
|
576
|
+
body.scrollLeft += next ? next.left - bounds.left - frozenEdgePx : body.clientWidth - frozenEdgePx;
|
|
577
|
+
}} style={{ position: "absolute", insetInlineEnd: overflowEdges.scrollbarRight, top: disclosureHeight, zIndex: 4,
|
|
578
|
+
cursor: "pointer", border: 0, height: headerPx, background: CSS_PANEL, color: CSS_TEXT_DIM, font: "inherit" }}>
|
|
579
|
+
More
|
|
580
|
+
</button>
|
|
581
|
+
) : null}
|
|
559
582
|
</div>
|
|
560
583
|
);
|
|
561
584
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { setCloudApiFetchTransport } from "../../../api-client";
|
|
2
|
+
import { marketReadLimitMs } from "../../../api-client/request";
|
|
2
3
|
import {
|
|
3
4
|
createProxyResponse,
|
|
4
5
|
createProxyResponseHeaders,
|
|
@@ -11,7 +12,7 @@ import { setHttpFetchTransport } from "../../../utils/http-transport";
|
|
|
11
12
|
import { backendRequest, onBackendMessage } from "./backend-rpc";
|
|
12
13
|
import { logFailure } from "../../../utils/log-failure";
|
|
13
14
|
|
|
14
|
-
const
|
|
15
|
+
const MARKET_FETCH_GRACE_MS = 1_000;
|
|
15
16
|
/**
|
|
16
17
|
* The view gives up on a feedback upload after 45 s (api-client/feedback.ts),
|
|
17
18
|
* but aborting in the view does not stop the Bun process's fetch. Stop it a
|
|
@@ -59,7 +60,7 @@ async function electrobunCloudApiFetch(url: string, init?: RequestInit): Promise
|
|
|
59
60
|
}
|
|
60
61
|
const path = new URL(url).pathname;
|
|
61
62
|
const timeoutMs = path.startsWith("/market/")
|
|
62
|
-
?
|
|
63
|
+
? marketReadLimitMs(path) + MARKET_FETCH_GRACE_MS
|
|
63
64
|
: path === "/telemetry/attention"
|
|
64
65
|
? 5_000
|
|
65
66
|
: path.endsWith("/feedback") && init?.method === "POST"
|
|
@@ -260,8 +260,9 @@ function mapCloudPriceHistory(
|
|
|
260
260
|
&& requestedStart.getTime() < Date.parse(coverageStart)) throw new HistoryCoverageError(coverageStart);
|
|
261
261
|
// The server marks a cached copy it could not refresh in time. Bars that
|
|
262
262
|
// reach the venue's latest settled session still answer, and the router's
|
|
263
|
-
// own current-window check applies to them as to any other copy. Older bars
|
|
264
|
-
//
|
|
263
|
+
// own current-window check applies to them as to any other copy. Older bars
|
|
264
|
+
// are a miss that carries them, shown as behind when no source has the
|
|
265
|
+
// present; a stale answer without bars is a miss.
|
|
265
266
|
const stale = isStaleCloudResponse(response);
|
|
266
267
|
if (stale && response.status !== "success" && response.status !== "partial") {
|
|
267
268
|
throw new StaleHistoryError(`Cloud chart data is stale for ${ticker}`);
|
|
@@ -288,9 +289,6 @@ function mapCloudPriceHistory(
|
|
|
288
289
|
`Cloud chart data is unavailable for ${ticker}`,
|
|
289
290
|
).map((point) => mapPricePoint(point, divisor, exchange, coin)),
|
|
290
291
|
);
|
|
291
|
-
if (stale && !reachesLatestSettledSession(points, Date.now(), { symbol: ticker, exchange, intervalMs: priceHistoryIntervalMs(interval) })) {
|
|
292
|
-
throw new StaleHistoryError(`Cloud chart data is stale for ${ticker}`);
|
|
293
|
-
}
|
|
294
292
|
const intraday = /^\d+(min|h)$/i.test(interval);
|
|
295
293
|
// Daily bars answering an intraday range: the listing has no intraday bars.
|
|
296
294
|
const dailyBars = intraday && response.servedResolution === "1day";
|
|
@@ -315,7 +313,7 @@ function mapCloudPriceHistory(
|
|
|
315
313
|
// Sessions of daily bars the answer left out for a close at or below zero.
|
|
316
314
|
const nonPositiveCloseDates = resolution === "1d" ? cloudNonPositiveCloseDates(response.omittedSessions) : undefined;
|
|
317
315
|
const delisting = parseListingDelisting(response.delisting);
|
|
318
|
-
|
|
316
|
+
const result: PriceHistoryResult = {
|
|
319
317
|
points,
|
|
320
318
|
resolution,
|
|
321
319
|
...(delisting ? { delisting } : {}),
|
|
@@ -325,6 +323,10 @@ function mapCloudPriceHistory(
|
|
|
325
323
|
...(coverageNote ? { coverageNote } : {}),
|
|
326
324
|
...(extendedHours ? { extendedHours: true } : {}),
|
|
327
325
|
};
|
|
326
|
+
if (stale && !reachesLatestSettledSession(points, Date.now(), { symbol: ticker, exchange, intervalMs: priceHistoryIntervalMs(interval) })) {
|
|
327
|
+
throw new StaleHistoryError(`Cloud chart data is stale for ${ticker}`, result);
|
|
328
|
+
}
|
|
329
|
+
return result;
|
|
328
330
|
}
|
|
329
331
|
|
|
330
332
|
/**
|
|
@@ -2,6 +2,7 @@ import { normalizeNewsFeed } from "../../news/news-model";
|
|
|
2
2
|
import { readableNewsSource } from "../../news/source-label";
|
|
3
3
|
import { collectNewsDisplayTickers } from "../../news/ticker-symbols";
|
|
4
4
|
import type { NewsAccess, NewsArticle, NewsQuery, NewsStoryItem } from "../../types/news-source";
|
|
5
|
+
import type { NewsInsiderFiling } from "../../news/types";
|
|
5
6
|
import { CLOUD_NEWS_DELAY_HOURS } from "../../api-client/plan-rules";
|
|
6
7
|
import type {
|
|
7
8
|
apiClient,
|
|
@@ -82,6 +83,39 @@ function mapCloudNewsStoryItem(
|
|
|
82
83
|
};
|
|
83
84
|
}
|
|
84
85
|
|
|
86
|
+
const ISO_DAY = /^\d{4}-\d{2}-\d{2}$/;
|
|
87
|
+
const ACCESSION = /^\d{10}-\d{2}-\d{6}$/;
|
|
88
|
+
const positive = (value: unknown): value is number => typeof value === "number" && Number.isFinite(value) && value > 0;
|
|
89
|
+
|
|
90
|
+
/** The Form 4s a story reports, each one whole: a filing a field of which does not read is left out. */
|
|
91
|
+
function insiderFilings(payload: CloudNewsPayload["insiderFilings"]): NewsInsiderFiling[] {
|
|
92
|
+
if (!Array.isArray(payload)) return [];
|
|
93
|
+
return payload.flatMap((filing): NewsInsiderFiling[] => {
|
|
94
|
+
if (!filing || !ACCESSION.test(filing.accession) || !filing.insider?.trim()) return [];
|
|
95
|
+
if (!ISO_DAY.test(filing.firstTradeDate) || !ISO_DAY.test(filing.lastTradeDate) || !ISO_DAY.test(filing.filedOn)) return [];
|
|
96
|
+
if (!positive(filing.shares) || !positive(filing.value) || !positive(filing.weightedPrice) || !Number.isInteger(filing.lines)) return [];
|
|
97
|
+
if (filing.side !== "sale" && filing.side !== "purchase") return [];
|
|
98
|
+
return [{
|
|
99
|
+
accession: filing.accession,
|
|
100
|
+
form: filing.form || "4",
|
|
101
|
+
filedOn: filing.filedOn,
|
|
102
|
+
issuerName: filing.issuerName?.trim() || null,
|
|
103
|
+
ticker: filing.ticker?.trim().toUpperCase() || null,
|
|
104
|
+
insider: filing.insider.trim(),
|
|
105
|
+
title: filing.title?.trim() || null,
|
|
106
|
+
side: filing.side,
|
|
107
|
+
firstTradeDate: filing.firstTradeDate,
|
|
108
|
+
lastTradeDate: filing.lastTradeDate,
|
|
109
|
+
lines: filing.lines,
|
|
110
|
+
shares: filing.shares,
|
|
111
|
+
value: filing.value,
|
|
112
|
+
weightedPrice: filing.weightedPrice,
|
|
113
|
+
rule10b51: typeof filing.rule10b51 === "boolean" ? filing.rule10b51 : null,
|
|
114
|
+
url: /^https:\/\/www\.sec\.gov\//.test(filing.url) ? filing.url : "",
|
|
115
|
+
}];
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
|
|
85
119
|
/** A folded row's notices, when the service says how many (two or more) and since when. */
|
|
86
120
|
function routineNotices(payload: CloudNewsPayload["routine"]): NewsArticle["routine"] | null {
|
|
87
121
|
if (!payload || !Number.isInteger(payload.notices) || payload.notices < 2) return null;
|
|
@@ -133,6 +167,7 @@ export function mapCloudNewsArticle(
|
|
|
133
167
|
sourceCount: item.sourceCount,
|
|
134
168
|
items: item.items?.map(mapCloudNewsStoryItem) ?? [],
|
|
135
169
|
...(routineNotices(item.routine) ? { routine: routineNotices(item.routine)! } : {}),
|
|
170
|
+
...(item.insiderFilings ? { insiderFilings: insiderFilings(item.insiderFilings) } : {}),
|
|
136
171
|
};
|
|
137
172
|
}
|
|
138
173
|
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { DataServiceUnreachableError, isNetworkFailure } from "../utils/network-failure";
|
|
2
|
-
import {
|
|
2
|
+
import { OperationTimeoutError } from "../utils/async-deadline";
|
|
3
|
+
import { ApiRequestError, isTransientFailure, wasAskedTwice } from "../api-client/errors";
|
|
4
|
+
import type { PriceHistoryResult } from "../types/price-history";
|
|
3
5
|
|
|
4
6
|
// Registered, so a miss raised by another copy of this module (a plugin that
|
|
5
7
|
// resolved `gloomberb/market-data` from the source tree) is still recognized.
|
|
@@ -47,11 +49,18 @@ export function createProviderMiss(message?: string, reason?: unknown, options?:
|
|
|
47
49
|
return new ProviderMissError(message, reason, options);
|
|
48
50
|
}
|
|
49
51
|
|
|
50
|
-
/**
|
|
52
|
+
/**
|
|
53
|
+
* A source has the listing's bars but not up to the present: it answered, just
|
|
54
|
+
* behind. `behind` is what it answered, which the router shows, said to be
|
|
55
|
+
* behind, when no source has the present.
|
|
56
|
+
*/
|
|
51
57
|
export class StaleHistoryError extends ProviderMissError {
|
|
52
|
-
|
|
58
|
+
readonly behind?: PriceHistoryResult;
|
|
59
|
+
|
|
60
|
+
constructor(message: string, behind?: PriceHistoryResult) {
|
|
53
61
|
super(message);
|
|
54
62
|
this.name = "StaleHistoryError";
|
|
63
|
+
if (behind) this.behind = behind;
|
|
55
64
|
}
|
|
56
65
|
}
|
|
57
66
|
|
|
@@ -136,8 +145,15 @@ export function isNoProviderMessage(message: string): boolean {
|
|
|
136
145
|
* data, since asked again in a moment it may. "for SYMBOL" closes the first
|
|
137
146
|
* sentence, so a table's note can name several symbols in front of it.
|
|
138
147
|
*/
|
|
139
|
-
export function serviceDidNotAnswerMessage(symbol?: string): string {
|
|
140
|
-
|
|
148
|
+
export function serviceDidNotAnswerMessage(symbol?: string, failure?: unknown): string {
|
|
149
|
+
// A source the service reads that took too long (TIMEOUT) is said as a timeout, never as no source for the symbol.
|
|
150
|
+
const then = serviceSourceTimedOut(failure) ? "Its source timed out; try again in a moment." : "Try again in a moment.";
|
|
151
|
+
return `Gloom's data service did not answer${symbol ? ` for ${symbol}` : ""}. ${then}`;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** Whether the data service answered that the source it reads timed out (reason TIMEOUT), asked twice. */
|
|
155
|
+
function serviceSourceTimedOut(failure: unknown): boolean {
|
|
156
|
+
return failure instanceof Error && failure.message.trim() === "TIMEOUT";
|
|
141
157
|
}
|
|
142
158
|
|
|
143
159
|
/** The router's generic answer that no provider served a request, holding the failure behind it when a provider failed rather than missed. */
|
|
@@ -154,7 +170,8 @@ class NoProviderError extends Error {
|
|
|
154
170
|
* the data service, and a listing read the data service failed to answer twice
|
|
155
171
|
* (`wasAskedTwice`, `serviceDidNotAnswerMessage`), each of which says that
|
|
156
172
|
* rather than that no source has the symbol; any other failure, a 5xx on a read
|
|
157
|
-
* that is not asked again among them, keeps the generic message.
|
|
173
|
+
* that is not asked again among them, keeps the generic message. A timeout
|
|
174
|
+
* on a working connection is kept in its own words as well.
|
|
158
175
|
*/
|
|
159
176
|
export function noProviderError(message: string, note: ProviderMissNote | undefined, symbol?: string): Error {
|
|
160
177
|
if (note?.reason) return createProviderMiss(note.reason, note.reason);
|
|
@@ -162,7 +179,8 @@ export function noProviderError(message: string, note: ProviderMissNote | undefi
|
|
|
162
179
|
if (isNetworkFailure(note?.failure)) {
|
|
163
180
|
return note!.failure instanceof DataServiceUnreachableError ? note!.failure : new DataServiceUnreachableError(note!.failure);
|
|
164
181
|
}
|
|
165
|
-
if (
|
|
182
|
+
if (note?.failure instanceof OperationTimeoutError) return new NoProviderError(note.failure.message, note.failure);
|
|
183
|
+
if (wasAskedTwice(note?.failure)) return new NoProviderError(serviceDidNotAnswerMessage(symbol, note!.failure), note!.failure);
|
|
166
184
|
if (note?.failure instanceof ApiRequestError && note.failure.status === 429) {
|
|
167
185
|
return new NoProviderError(rateLimitedMessage(symbol, note.failure.retryAfterMs), note.failure);
|
|
168
186
|
}
|
|
@@ -188,6 +206,15 @@ export function isSourceFailure(error: unknown): boolean {
|
|
|
188
206
|
return error instanceof NoProviderError && error.failure !== undefined;
|
|
189
207
|
}
|
|
190
208
|
|
|
209
|
+
/**
|
|
210
|
+
* A source failure (`isSourceFailure`) that asking again shortly may get
|
|
211
|
+
* past: the source timed out, was rate limited or overloaded
|
|
212
|
+
* (`isTransientFailure`). A source that refused the read is not one.
|
|
213
|
+
*/
|
|
214
|
+
export function isTransientSourceFailure(error: unknown): boolean {
|
|
215
|
+
return error instanceof NoProviderError && error.failure !== undefined && isTransientFailure(error.failure);
|
|
216
|
+
}
|
|
217
|
+
|
|
191
218
|
/**
|
|
192
219
|
* The router's bare "No history provider available": no source failed, none
|
|
193
220
|
* gave a reason or said the symbol is unknown, and none served bars it could
|
|
@@ -87,6 +87,18 @@ interface HistoryAttempts {
|
|
|
87
87
|
misses: ProviderMissNote;
|
|
88
88
|
coverageError?: HistoryCoverageError;
|
|
89
89
|
retention?: HistoryRetention;
|
|
90
|
+
/** The furthest-reaching bars a source answered and marked as stopping short of the present (StaleHistoryError). */
|
|
91
|
+
behind?: PriceHistoryResult;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function noteBehindAnswer(attempts: HistoryAttempts | undefined, value: PriceHistoryResult): void {
|
|
95
|
+
if (!attempts || !hasUsablePriceHistory(value.points)) return;
|
|
96
|
+
if (!attempts.behind || lastBarTime(value) > lastBarTime(attempts.behind)) attempts.behind = value;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function lastBarTime(value: PriceHistoryResult): number {
|
|
100
|
+
const last = value.points.at(-1);
|
|
101
|
+
return last ? getPricePointTimestamp(last) : Number.NEGATIVE_INFINITY;
|
|
90
102
|
}
|
|
91
103
|
|
|
92
104
|
function recordHistoryOutcome(attempts: HistoryAttempts | undefined, sourceKey: string, outcome: HistorySourceOutcome["outcome"], status?: number): void {
|
|
@@ -128,6 +140,7 @@ function recordHistoryError(attempts: HistoryAttempts | undefined, request: Hist
|
|
|
128
140
|
if (error instanceof StaleHistoryError) {
|
|
129
141
|
// It has the bars, only not up to the present: behind, as a stale copy it served would be.
|
|
130
142
|
recordHistoryOutcome(attempts, sourceKey, "stale");
|
|
143
|
+
if (error.behind) noteBehindAnswer(attempts, normalizeRequestResult({ ...error.behind, sourceKey }, request));
|
|
131
144
|
} else if (error instanceof InvalidHistoryResultError) {
|
|
132
145
|
recordHistoryOutcome(attempts, sourceKey, "malformed");
|
|
133
146
|
} else if (isHistoryRetentionError(error)) {
|
|
@@ -750,11 +763,21 @@ export class ProviderRouterHistoryRoutes {
|
|
|
750
763
|
// empty chart. Intraday copies expire two days after they are saved. A
|
|
751
764
|
// coin never closes, so its old copy is not shown: the miss says why.
|
|
752
765
|
const coin = isRoundTheClockCoin(target.symbol, target.exchange || request.target.exchange);
|
|
753
|
-
const
|
|
754
|
-
|
|
755
|
-
.filter((record) => !supersededCacheSources.has(record.sourceKey));
|
|
766
|
+
const fallbackEntries = ranked.filter((entry) => !supersededCacheSources.has(entry.record.sourceKey));
|
|
767
|
+
const fallbackRecords = fallbackEntries.map((entry) => entry.record);
|
|
756
768
|
const fallbackRecord = fallbackRecords.find((record) => !request.isCachedValueStale(record.value, record.fetchedAt))
|
|
757
769
|
?? (coin ? undefined : fallbackRecords[0]);
|
|
770
|
+
// A source's own answer that stops short of the present (the service's
|
|
771
|
+
// stored series while its source refuses) is shown, said to be behind, as
|
|
772
|
+
// a saved copy short of the latest session is: unless a copy is current or
|
|
773
|
+
// reaches further. A coin's is not, in the current window, for the reason
|
|
774
|
+
// its old copy is not.
|
|
775
|
+
const behindAnswer = coin && currentWindow ? undefined : attempts.behind;
|
|
776
|
+
const fallbackCurrent = !!fallbackRecord && !request.isCachedValueStale(fallbackRecord.value, fallbackRecord.fetchedAt)
|
|
777
|
+
&& fallbackEntries.find((entry) => entry.record === fallbackRecord)?.tier === 0;
|
|
778
|
+
if (behindAnswer && !fallbackCurrent && (!fallbackRecord || lastBarTime(behindAnswer) >= lastBarTime(fallbackRecord.value))) {
|
|
779
|
+
return withReportedGaps({ ...behindAnswer, savedCopyBehind: true });
|
|
780
|
+
}
|
|
758
781
|
if (fallbackRecord) {
|
|
759
782
|
// A copy short of the latest session says so, so the chart can tell it
|
|
760
783
|
// from a current one: a thin listing's complete copy is not behind.
|
|
@@ -773,10 +796,13 @@ export class ProviderRouterHistoryRoutes {
|
|
|
773
796
|
const candidates = [...attempts.candidates.values()].sort((a, b) => sourceOrder.indexOf(a.sourceKey) - sourceOrder.indexOf(b.sourceKey));
|
|
774
797
|
throw new HistoryRetentionError(candidates[0]?.retention ?? attempts.retention, { candidates, outcomes: [...attempts.outcomes.values()] });
|
|
775
798
|
}
|
|
799
|
+
// A source answered but its history stops short of the present, and was not shown (a coin's, one without
|
|
800
|
+
// bars, or one this router's own check finds behind): say so, not that nothing answered.
|
|
801
|
+
if (!providerResult && !reportedGaps.some((value) => value.points.length > 0)
|
|
802
|
+
&& [...attempts.outcomes.values()].some((outcome) => outcome.outcome === "stale")) {
|
|
803
|
+
throw new Error(`Latest history for ${target.symbol} is behind`);
|
|
804
|
+
}
|
|
776
805
|
if (!providerResult && request.missingProviderError && !reportedGaps.some((value) => value.points.length > 0)) {
|
|
777
|
-
// A source answered a coin's history but it stops short of the present: say so, not that nothing answered.
|
|
778
|
-
const behind = coin && [...attempts.outcomes.values()].some((outcome) => outcome.outcome === "stale");
|
|
779
|
-
if (behind) throw new Error(`Latest history for ${target.symbol} is behind`);
|
|
780
806
|
// A reason the service gave ("ADX listings have daily bars only.") says why; one that has no
|
|
781
807
|
// listing for the symbol says it is not a ticker; otherwise no source answered. A coin trades
|
|
782
808
|
// around the clock and its sources are there: they could not answer just now. So could a
|
|
@@ -35,6 +35,7 @@ import type {
|
|
|
35
35
|
ChartSeriesSpec,
|
|
36
36
|
ChartSpec,
|
|
37
37
|
ResolvedSeries,
|
|
38
|
+
TimeSeriesPoint,
|
|
38
39
|
} from "./types";
|
|
39
40
|
import { instrumentLabel } from "./resolve-context";
|
|
40
41
|
import { finiteDate } from "./chart-bounds";
|
|
@@ -130,6 +131,34 @@ function quotedInstrumentLabel(
|
|
|
130
131
|
return index && quoted && !source.instrument.instrument ? source.instrument.symbol.trim() : instrumentLabel(source);
|
|
131
132
|
}
|
|
132
133
|
|
|
134
|
+
/** A bar's move from `reference`, in percent; undefined when either is not a price. */
|
|
135
|
+
function barMovePercent(bar: TimeSeriesPoint | undefined, reference: number): number | undefined {
|
|
136
|
+
const close = bar?.close ?? bar?.value;
|
|
137
|
+
return reference > 0 && typeof close === "number" && Number.isFinite(close) ? (close / reference - 1) * 100 : undefined;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* A bar's move from the close a quote's change is measured from (its price less
|
|
142
|
+
* its change), in percent; the quote's own percent when the quote states no
|
|
143
|
+
* change or the bar no close.
|
|
144
|
+
*/
|
|
145
|
+
function barChangePercent(bar: TimeSeriesPoint | undefined, display: { price: number; change?: number; changePercent?: number }): number | undefined {
|
|
146
|
+
const reference = typeof display.change === "number" && Number.isFinite(display.change) ? display.price - display.change : Number.NaN;
|
|
147
|
+
return barMovePercent(bar, reference) ?? display.changePercent;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* A one-day chart's price series with the prior close it draws as its
|
|
152
|
+
* reference line. The legend's move is then the last bar's from that line,
|
|
153
|
+
* the price and the move read off the chart itself, as a reader checks them
|
|
154
|
+
* (`$654.41 -0.39%` beside a 656.95 line); a series with no move to show (no
|
|
155
|
+
* quote stated one) keeps none.
|
|
156
|
+
*/
|
|
157
|
+
export function withPriorClose(series: ResolvedSeries, priorClose: number): ResolvedSeries {
|
|
158
|
+
const move = series.latestChangePercent === undefined ? undefined : barMovePercent(series.points.at(-1), priorClose);
|
|
159
|
+
return { ...series, priorClose, ...move !== undefined ? { latestChangePercent: move } : {} };
|
|
160
|
+
}
|
|
161
|
+
|
|
133
162
|
export function baseSecuritySeries(
|
|
134
163
|
spec: ChartSeriesSpec,
|
|
135
164
|
financials: TickerFinancials,
|
|
@@ -226,14 +255,18 @@ export function baseSecuritySeries(
|
|
|
226
255
|
const listingExchange = canonicalExchange(marketExchange) === "SMART" || usOption
|
|
227
256
|
? canonicalExchange(sessionExchange) || (routedUsListing ? "NYSE" : marketExchange)
|
|
228
257
|
: marketExchange;
|
|
229
|
-
// The move of the price the chart ends on
|
|
230
|
-
// once it is over, as `quote`
|
|
231
|
-
//
|
|
232
|
-
|
|
258
|
+
// The move of the price the chart ends on, from the close the quote measures
|
|
259
|
+
// it from: the regular session's (its close once it is over, as `quote`
|
|
260
|
+
// heads Last), or the latest print's, an after-hours one included, where the
|
|
261
|
+
// bars run into extended hours. The legend prints it beside the last bar, so
|
|
262
|
+
// it is that bar's close against the quote's reference, one observation: a
|
|
263
|
+
// quote read a moment apart from the bars would print another price's move.
|
|
264
|
+
const display = marketField && field.unit.startsWith("currency")
|
|
233
265
|
&& !unknownBondBasis
|
|
234
266
|
&& financials.quote && hasValidQuoteObservationTime(financials.quote)
|
|
235
|
-
? (extendedHours ? getActiveQuoteDisplay(financials.quote) : getRegularSessionDisplay(financials.quote))
|
|
236
|
-
:
|
|
267
|
+
? (extendedHours ? getActiveQuoteDisplay(financials.quote) : getRegularSessionDisplay(financials.quote))
|
|
268
|
+
: null;
|
|
269
|
+
const latestChangePercent = display ? barChangePercent(points.at(-1), display) : undefined;
|
|
237
270
|
const priceIssues = valuationPriceIssues(financials, spec.source);
|
|
238
271
|
// A source with closes only, such as a generic future, has flat bars (open,
|
|
239
272
|
// high and low filled from the close): nothing to draw as candles.
|
|
@@ -31,7 +31,7 @@ import {
|
|
|
31
31
|
followLatestMarketObservation,
|
|
32
32
|
latestSessionView,
|
|
33
33
|
} from "./chart-bounds";
|
|
34
|
-
import { emptyFinancials, chartCalculationSeriesIds, baseSecuritySeries } from "./base-series";
|
|
34
|
+
import { emptyFinancials, chartCalculationSeriesIds, baseSecuritySeries, withPriorClose } from "./base-series";
|
|
35
35
|
import {
|
|
36
36
|
resolvePriceHistoryIntegrity,
|
|
37
37
|
assignAxes,
|
|
@@ -106,7 +106,7 @@ export function seedChartResolutionResult(
|
|
|
106
106
|
const primary = series[0]!;
|
|
107
107
|
if (sessionView?.priorClose != null && primary.transform === "raw"
|
|
108
108
|
&& primary.unitGroup.startsWith("price") && primary.unitGroup !== "price:unknown") {
|
|
109
|
-
series[0] =
|
|
109
|
+
series[0] = withPriorClose(primary, sessionView.priorClose);
|
|
110
110
|
}
|
|
111
111
|
const resolutionSupport = support.length === series.length ? intersectChartResolutionSupport(support) : [];
|
|
112
112
|
const priceComparison = resolvePriceComparison(spec, series, bounds, resolution, spec.viewport.dateWindow,
|
|
@@ -27,7 +27,10 @@ function isIsolatedOhlcOutlier(
|
|
|
27
27
|
return false;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
const tradedWick = (point.volume ?? 0) > 0
|
|
31
|
+
&& point.open != null && point.high != null && point.low != null
|
|
32
|
+
&& point.high >= Math.max(point.open, point.close) && point.low <= Math.min(point.open, point.close);
|
|
33
|
+
return (tradedWick ? [point.open] : [point.open, point.high, point.low]).some((value) => (
|
|
31
34
|
typeof value === "number"
|
|
32
35
|
&& Number.isFinite(value)
|
|
33
36
|
&& relativeDifference(value, point.close) > ISOLATED_OHLC_OUTLIER_RATIO
|
package/src/time-series/hooks.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { getSharedRegistry } from "../plugins/registry";
|
|
|
7
7
|
import { createChartSeriesResolver } from "../capabilities";
|
|
8
8
|
import { loadFuturesPriceUnit } from "../market-data/futures-contract";
|
|
9
9
|
import { loadDailyFxCloses } from "./currency-conversion";
|
|
10
|
+
import { loadStatementCurrency } from "../plugins/builtin/shared/statement-currency";
|
|
10
11
|
import { useAppSelector } from "../state/app/context";
|
|
11
12
|
import type { FredSeriesRequest } from "../sources/gloomberb-cloud/fred-series";
|
|
12
13
|
import type { TickerRecord } from "../types/ticker";
|
|
@@ -85,6 +86,7 @@ export function useResolvedChartSpec(
|
|
|
85
86
|
capabilityRefreshMs: registeredSeriesRefreshMs,
|
|
86
87
|
loadFuturesPriceUnit: (symbol: string) => loadFuturesPriceUnit(symbol),
|
|
87
88
|
loadFxCloses: (currency: string, startDate: string) => loadDailyFxCloses(currency, startDate, apiClient),
|
|
89
|
+
...(dataProvider ? { loadStatementCurrency: (target: string, currencies: readonly string[]) => loadStatementCurrency(target, currencies, { marketData: dataProvider }) } : {}),
|
|
88
90
|
}), [capabilityInvoker, dataProvider]);
|
|
89
91
|
return useChartResolution(hydratedSpec, sources, { ...options, snapshot });
|
|
90
92
|
}
|
|
@@ -66,10 +66,9 @@ export interface PriceComparison {
|
|
|
66
66
|
export interface PriceComparisonOptions {
|
|
67
67
|
/**
|
|
68
68
|
* The chart's untouched preset range; null for authored dates or a view
|
|
69
|
-
* panned or zoomed off it. A
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
* same date a range before (periodBaseDay), as RETURN is.
|
|
69
|
+
* panned or zoomed off it. A calendar range (1W to 5Y) is measured from
|
|
70
|
+
* the close on or before the same date a range before the shared end
|
|
71
|
+
* (periodBaseDay), as RETURN is.
|
|
73
72
|
*/
|
|
74
73
|
preset?: TimeRange | null;
|
|
75
74
|
now?: number;
|
|
@@ -328,11 +327,10 @@ interface ComparedLeg {
|
|
|
328
327
|
*
|
|
329
328
|
* Calendar bars compare by session date. An untouched preset range measures
|
|
330
329
|
* each leg from its own close on or before the same date a range before the
|
|
331
|
-
*
|
|
332
|
-
*
|
|
333
|
-
*
|
|
334
|
-
*
|
|
335
|
-
* is left out with its reason and the others still compare.
|
|
330
|
+
* last shared observation (periodBaseDay), the convention RETURN and every
|
|
331
|
+
* period return share. Authored dates and a panned view use a shared base.
|
|
332
|
+
* A daily bar that is still forming is comparable only if it is forming on
|
|
333
|
+
* every leg. A leg without a usable span is left out with its reason.
|
|
336
334
|
*/
|
|
337
335
|
export function resolvePriceComparison(
|
|
338
336
|
spec: ChartSpec,
|
|
@@ -390,12 +388,16 @@ export function resolvePriceComparison(
|
|
|
390
388
|
const dayOf = (leg: ComparedLeg, key: string) => calendarBars ? key : observationDate(Number(key), leg.entry);
|
|
391
389
|
const preset = options.preset ?? null;
|
|
392
390
|
const period = !dateWindow && isReturnPeriod(preset) ? preset : null;
|
|
393
|
-
const ownEnds = preset !== null && !dateWindow;
|
|
394
391
|
const shared = (keys: (leg: ComparedLeg) => readonly string[]) => {
|
|
395
392
|
const sets = legs.map((leg) => new Set(keys(leg)));
|
|
396
393
|
return legs.length ? keys(legs[0]!).filter((key) => sets.every((set) => set.has(key))) : [];
|
|
397
394
|
};
|
|
398
395
|
const sharedWindow = shared((leg) => leg.window);
|
|
396
|
+
const isForming = (leg: ComparedLeg, key: string): boolean => calendarBars && !options.closedEnds?.has(leg.id)
|
|
397
|
+
&& (leg.points.get(key)?.partial === true || isIntradayDailyBar(sessionDay(key), legVenue(leg.entry), now));
|
|
398
|
+
const sharedEnd = resolution === "1d"
|
|
399
|
+
? sharedWindow.findLast((key) => legs.every((leg) => isForming(leg, key) === isForming(legs[0]!, key)))
|
|
400
|
+
: sharedWindow.at(-1);
|
|
399
401
|
// Authored dates (`--from 2026-10-19`) measure from the close before the first date, as RETURN does: the last
|
|
400
402
|
// date the legs share before it. Weekly and monthly bars keep the bar the window starts in.
|
|
401
403
|
const authoredFrom = !preset && dateWindow && /^\d{4}-\d{2}-\d{2}$/.test(dateWindow.start) && (resolution === "1d" || !calendarBars)
|
|
@@ -406,10 +408,7 @@ export function resolvePriceComparison(
|
|
|
406
408
|
&& legs.every((leg) => nonzero(leg, key))).at(-1)
|
|
407
409
|
: undefined;
|
|
408
410
|
const sharedStart = authoredBase ?? sharedWindow.find((key) => legs.every((leg) => nonzero(leg, key)));
|
|
409
|
-
|
|
410
|
-
const anchor = period && legs.length
|
|
411
|
-
? legs.map((leg) => calendarBars ? sessionDay(leg.window.at(-1)!) : dayOf(leg, leg.window.at(-1)!)).sort().at(-1)!
|
|
412
|
-
: null;
|
|
411
|
+
const anchor = period && sharedEnd !== undefined ? (calendarBars ? sessionDay(sharedEnd) : dayOf(legs[0]!, sharedEnd)) : null;
|
|
413
412
|
const baseDay = anchor && period ? periodBaseDay(anchor, period) : null;
|
|
414
413
|
const closeDay = (leg: ComparedLeg, key: string) => calendarBars && resolution !== "1d" ? barCloseDay(key, resolution, legVenue(leg.entry)) : key;
|
|
415
414
|
// Intraday bars share their times, so their base is the last bar the legs share on or before the base day.
|
|
@@ -426,18 +425,14 @@ export function resolvePriceComparison(
|
|
|
426
425
|
// Without a close on or before the base day (a listing younger than the range), its first close in range.
|
|
427
426
|
return base !== undefined && nonzero(leg, base) ? base : leg.window.find((key) => nonzero(leg, key));
|
|
428
427
|
};
|
|
429
|
-
const
|
|
430
|
-
// Legs that share their dates compare over two of them or not at all; a leg that runs on its own is left out alone.
|
|
431
|
-
const sharedSpan = sharedStart !== undefined && sharedEnd !== undefined && order(sharedStart, sharedEnd) < 0;
|
|
432
|
-
const compared = baseDay || ownEnds || sharedSpan ? legs.flatMap((leg) => {
|
|
428
|
+
const compared = sharedEnd === undefined ? [] : legs.flatMap((leg) => {
|
|
433
429
|
const start = startOf(leg);
|
|
434
|
-
|
|
435
|
-
if (start !== undefined && end !== undefined && order(start, end) < 0) return [{ leg, start, end }];
|
|
430
|
+
if (start !== undefined && order(start, sharedEnd) < 0) return [{ leg, start, end: sharedEnd }];
|
|
436
431
|
if (baseDay || sharedStart !== undefined) {
|
|
437
432
|
dropped.push({ seriesId: leg.id, label: leg.label, reason: start === undefined ? "no nonzero price to measure from in this range" : "only one price in this range" });
|
|
438
433
|
}
|
|
439
434
|
return [];
|
|
440
|
-
})
|
|
435
|
+
});
|
|
441
436
|
// "Left out: VIX; EWJ (only one price in this range)."
|
|
442
437
|
const droppedText = dropped.length
|
|
443
438
|
? ` Left out: ${dropped.map((entry) => reported.has(entry.seriesId) ? entry.label : `${entry.label} (${entry.reason})`).join("; ")}.`
|
|
@@ -457,9 +452,8 @@ export function resolvePriceComparison(
|
|
|
457
452
|
const currentYear = new Date(now).getUTCFullYear();
|
|
458
453
|
const legDays = Object.fromEntries(compared.map(({ leg, start, end }) => {
|
|
459
454
|
const endDay = calendarBars ? sessionDay(end) : dayOf(leg, end);
|
|
460
|
-
// A daily bar of the session still trading, or a week or month running through it.
|
|
461
455
|
return [leg.id, { baseDay: calendarBars ? sessionDay(start) : dayOf(leg, start), endDay,
|
|
462
|
-
intraday:
|
|
456
|
+
intraday: isForming(leg, end) }];
|
|
463
457
|
}));
|
|
464
458
|
const span = calendarBars
|
|
465
459
|
? (() => {
|
|
@@ -112,7 +112,7 @@ export function summarizeResolvedSeries(series: ResolvedSeries) {
|
|
|
112
112
|
startValue: null, endValue: null, return: null,
|
|
113
113
|
unit: series.rawUnit ?? series.unit,
|
|
114
114
|
pointCount: series.points.length,
|
|
115
|
-
unavailableReason: inconsistentOhlc ? "
|
|
115
|
+
unavailableReason: inconsistentOhlc ? "Contradictory prices in the selected bars."
|
|
116
116
|
: "Invalid valuation price in the selected observations.",
|
|
117
117
|
};
|
|
118
118
|
}
|
|
@@ -181,6 +181,19 @@ export function chartBarSizeParts(size: unknown): { count: number; unit: ChartBa
|
|
|
181
181
|
return canonicalBarSize(count, unit) === size ? { count, unit } : null;
|
|
182
182
|
}
|
|
183
183
|
|
|
184
|
+
const BAR_SIZE_NAMES: Readonly<Record<ManualChartResolution, string>> = {
|
|
185
|
+
"1m": "1-minute", "5m": "5-minute", "15m": "15-minute", "30m": "30-minute", "45m": "45-minute",
|
|
186
|
+
"1h": "hourly", "1d": "daily", "1wk": "weekly", "1mo": "monthly",
|
|
187
|
+
};
|
|
188
|
+
const BAR_UNIT_NAMES: Readonly<Record<ChartBarSizeUnit, string>> = { m: "minute", h: "hour", d: "day", wk: "week", mo: "month" };
|
|
189
|
+
|
|
190
|
+
/** A bar size in words, as a sentence names it: `5-minute`, `daily`, a built one `4-hour`. */
|
|
191
|
+
export function chartBarSizeName(size: ChartBarSize): string {
|
|
192
|
+
if (isManualChartResolution(size)) return BAR_SIZE_NAMES[size];
|
|
193
|
+
const parts = chartBarSizeParts(size);
|
|
194
|
+
return parts ? `${parts.count}-${BAR_UNIT_NAMES[parts.unit]}` : size;
|
|
195
|
+
}
|
|
196
|
+
|
|
184
197
|
/** A stored bar size (`4h`, `2d`, `1wk`); `auto` is not one. */
|
|
185
198
|
function isChartBarSize(value: unknown): value is ChartBarSize {
|
|
186
199
|
return chartBarSizeParts(value) !== null;
|
|
@@ -43,6 +43,12 @@ export interface ChartResolveSources {
|
|
|
43
43
|
loadFuturesPriceUnit?: (symbol: string) => Promise<string | null>;
|
|
44
44
|
/** A currency's daily USD closes, for a chart converted into one currency (`viewport.currency`). */
|
|
45
45
|
loadFxCloses?: LoadFxCloses;
|
|
46
|
+
loadStatementCurrency?: (target: string, currencies: readonly string[]) => Promise<{
|
|
47
|
+
rates: ReadonlyMap<string, number>;
|
|
48
|
+
note: string | null;
|
|
49
|
+
rateNotes?: readonly string[];
|
|
50
|
+
failures: readonly string[];
|
|
51
|
+
}>;
|
|
46
52
|
/** Provider-neutral boundary for plugin-owned chart series. */
|
|
47
53
|
resolveCapabilitySeries?: (
|
|
48
54
|
source: Extract<ChartSeriesSpec["source"], { kind: "capability" }>,
|