gloomberb 0.19.4 → 0.19.5
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 +3 -1
- package/src/cli/commands/command-utils.ts +4 -0
- package/src/cli/commands/market.ts +119 -27
- package/src/cli/commands/search.ts +1 -1
- package/src/cli/commands/ticker.ts +10 -6
- package/src/cli/currency-name-hint.ts +60 -0
- package/src/cli/history-rows.ts +18 -1
- package/src/cli/known-gaps.ts +17 -2
- package/src/cli/not-a-ticker.ts +5 -3
- package/src/cli/pane-functions/catalog.ts +9 -1
- package/src/cli/pane-functions/headless.ts +7 -3
- package/src/cli/pane-functions/market-session.ts +6 -7
- package/src/cli/series-search.ts +4 -5
- package/src/components/chart/composite/panel-bitmap.ts +28 -2
- package/src/components/chart/composite/time-axis.ts +17 -2
- package/src/components/layout/shell/active-drag.ts +38 -7
- package/src/components/layout/shell/drag/magnets.ts +106 -0
- package/src/components/layout/window-controls.tsx +96 -35
- package/src/components/layout/window-fullscreen.ts +20 -0
- package/src/components/quote-flash.ts +36 -32
- package/src/market-data/coordinator/events.ts +17 -1
- package/src/market-data/frame-scheduler.ts +47 -10
- package/src/market-data/frame-wake.ts +74 -0
- package/src/market-data/futures-board.ts +7 -6
- package/src/market-data/hooks.tsx +12 -3
- package/src/market-data/performance.ts +78 -9
- package/src/market-data/request-types.ts +6 -3
- package/src/plugins/builtin/alerts/cli.ts +2 -1
- package/src/plugins/builtin/analytics/risk-evidence.ts +1 -0
- package/src/plugins/builtin/attention/evidence.ts +1 -1
- package/src/plugins/builtin/awards/client.ts +1 -1
- package/src/plugins/builtin/awards/evidence.ts +1 -1
- package/src/plugins/builtin/awards/pane.tsx +2 -1
- package/src/plugins/builtin/bond-calculator/math.ts +1 -1
- package/src/plugins/builtin/broker-manager/footer.ts +3 -2
- package/src/plugins/builtin/broker-manager/index.tsx +2 -1
- package/src/plugins/builtin/broker-manager/keyboard.ts +2 -1
- package/src/plugins/builtin/catalysts/evidence.ts +1 -1
- package/src/plugins/builtin/catalysts/pane.tsx +2 -1
- package/src/plugins/builtin/chart-composer/headless.ts +40 -1
- package/src/plugins/builtin/cloud-tweets/table.tsx +3 -2
- package/src/plugins/builtin/comment-letters/client.ts +2 -1
- package/src/plugins/builtin/company-kpis/client.ts +1 -1
- package/src/plugins/builtin/company-kpis/pane.tsx +2 -1
- package/src/plugins/builtin/company-kpis/screenshot-evidence.ts +3 -2
- package/src/plugins/builtin/cot/headless.ts +9 -3
- package/src/plugins/builtin/cot/model.ts +44 -3
- package/src/plugins/builtin/credit-documents/client.ts +1 -1
- package/src/plugins/builtin/credit-documents/evidence.ts +1 -1
- package/src/plugins/builtin/credit-documents/pane.tsx +2 -1
- package/src/plugins/builtin/earnings-calls/pane.tsx +1 -1
- package/src/plugins/builtin/earnings-ripple/index.tsx +6 -1
- package/src/plugins/builtin/econ/calendar-model.ts +2 -0
- package/src/plugins/builtin/econ/fred-catalog.ts +5 -5
- package/src/plugins/builtin/econ/print-watch.ts +3 -1
- package/src/plugins/builtin/futures/series.ts +16 -1
- package/src/plugins/builtin/fx-matrix/headless.ts +4 -2
- package/src/plugins/builtin/fx-matrix/index.tsx +37 -3
- package/src/plugins/builtin/fx-matrix/pairs.ts +15 -0
- package/src/plugins/builtin/gpu/headless.ts +2 -1
- package/src/plugins/builtin/help/function-card.tsx +2 -1
- package/src/plugins/builtin/help/index.tsx +2 -1
- package/src/plugins/builtin/insider/display.ts +45 -6
- package/src/plugins/builtin/ipo-calendar/model.ts +2 -0
- package/src/plugins/builtin/iv-history/client.ts +2 -1
- package/src/plugins/builtin/iv-history/headless.ts +2 -1
- package/src/plugins/builtin/jobs/pages.ts +4 -4
- package/src/plugins/builtin/kelly-sizer/headless.ts +2 -1
- package/src/plugins/builtin/market-heatmap/index.tsx +2 -1
- package/src/plugins/builtin/members/client.ts +1 -1
- package/src/plugins/builtin/mna/distress/client.ts +1 -0
- package/src/plugins/builtin/mna/pane.tsx +4 -1
- package/src/plugins/builtin/options/market-reference.ts +1 -1
- package/src/plugins/builtin/options/open-interest-as-of.ts +3 -1
- package/src/plugins/builtin/options/view.tsx +2 -1
- package/src/plugins/builtin/options-calculator/evidence.ts +1 -1
- package/src/plugins/builtin/options-scenario/csp-screen-pane.tsx +1 -1
- package/src/plugins/builtin/options-scenario/csp-screen.ts +8 -4
- package/src/plugins/builtin/options-scenario/csp.ts +28 -9
- package/src/plugins/builtin/options-scenario/evidence.ts +5 -4
- package/src/plugins/builtin/options-scenario/pane.tsx +2 -1
- package/src/plugins/builtin/perps/client.ts +1 -1
- package/src/plugins/builtin/portfolio-list/cli/watchlist-command.ts +2 -1
- package/src/plugins/builtin/portfolio-list/pane/index.tsx +7 -3
- package/src/plugins/builtin/portfolio-list/use-throttled-memo.ts +10 -19
- package/src/plugins/builtin/research/analyst-model.ts +1 -0
- package/src/plugins/builtin/research/equity-diagnostic-pane.tsx +2 -1
- package/src/plugins/builtin/research/index.tsx +1 -0
- package/src/plugins/builtin/research/relative-valuation-currency.ts +1 -1
- package/src/plugins/builtin/research/relative-valuation-peers.ts +2 -1
- package/src/plugins/builtin/research-search/command-bar-search.ts +3 -1
- package/src/plugins/builtin/research-search/snippet.ts +1 -0
- package/src/plugins/builtin/revenue-breakdown/client.ts +3 -2
- package/src/plugins/builtin/seasonality/headless.ts +2 -1
- package/src/plugins/builtin/sec/command-bar-search.ts +3 -2
- package/src/plugins/builtin/sec/index.tsx +7 -4
- package/src/plugins/builtin/sec/row-summaries.ts +28 -12
- package/src/plugins/builtin/short-interest/watch-client.ts +2 -1
- package/src/plugins/builtin/social-mentions/client.ts +2 -1
- package/src/plugins/builtin/supply-chain/client.ts +1 -1
- package/src/plugins/builtin/supply-chain/evidence.ts +1 -1
- package/src/plugins/builtin/supply-chain/graph-pane.tsx +2 -1
- package/src/plugins/builtin/supply-chain/pane.tsx +2 -1
- package/src/plugins/builtin/ticker-detail/adr-pair/headless.ts +1 -1
- package/src/plugins/builtin/ticker-detail/adr-pair/model.ts +24 -4
- package/src/plugins/builtin/ticker-detail/adr-pair/tab.tsx +1 -1
- package/src/plugins/builtin/time-sales/client.ts +1 -0
- package/src/plugins/builtin/vol-surface/client.ts +2 -1
- package/src/plugins/builtin/yield-curve/headless.ts +3 -1
- package/src/portfolio/column-values.ts +76 -10
- package/src/renderers/dom/host/box.tsx +204 -176
- package/src/renderers/dom/host/style.ts +49 -20
- package/src/renderers/dom/host/text.tsx +3 -2
- package/src/renderers/electrobun/bun/desktop/backend.ts +2 -0
- package/src/renderers/electrobun/bun/desktop/host-requests.ts +25 -1
- package/src/renderers/electrobun/bun/desktop/relaunch.ts +9 -1
- package/src/renderers/electrobun/bun/desktop/windows-script.ts +9 -6
- package/src/renderers/electrobun/bun/window/windows-native.ts +26 -1
- package/src/renderers/electrobun/shared/protocol.ts +6 -0
- package/src/renderers/electrobun/view/ui-host.tsx +7 -0
- package/src/renderers/electrobun/view/window-fullscreen.ts +10 -3
- package/src/sources/provider-router/index.ts +7 -1
- package/src/time-series/price-units.ts +11 -0
- package/src/ui/host.tsx +2 -0
- package/src/utils/currency-names.ts +20 -0
- package/src/utils/currency-pair.ts +6 -0
- package/src/utils/exchange-rate-snapshot.ts +20 -2
- package/src/utils/fx-market-hours.ts +43 -0
|
@@ -22,6 +22,7 @@ import { ProWall, SignInWall } from "../cloud/auth-actions";
|
|
|
22
22
|
import { useCloudPlanAction, useCloudUpgradeAction } from "../shared/cloud-upgrade";
|
|
23
23
|
import { usePlanAccess } from "../../../api-client/plan-access";
|
|
24
24
|
import { useBoundTicker } from "../shared/ticker-request";
|
|
25
|
+
import { logFailure } from "../../../utils/log-failure";
|
|
25
26
|
|
|
26
27
|
const FOOTER_ID = "equity-diagnostic";
|
|
27
28
|
/** Width of the "Observed"/"Reading" label column before the layout stacks. */
|
|
@@ -519,7 +520,7 @@ export function EquityDiagnosticView({ focused, width, height }: {
|
|
|
519
520
|
}).then((sourceId) => {
|
|
520
521
|
const source = sources.find((entry) => entry.id === sourceId);
|
|
521
522
|
if (source) void rendererHost.openExternal(source.url);
|
|
522
|
-
}).catch((
|
|
523
|
+
}).catch(logFailure("research.equity-diagnostic-pane", "Open diagnostic source choices failed"));
|
|
523
524
|
}, [dialog, rendererHost, sources]);
|
|
524
525
|
|
|
525
526
|
// The preview's pitch sits in the body, not an empty state, so its buttons
|
|
@@ -170,6 +170,7 @@ export const researchModule: PluginModule = {
|
|
|
170
170
|
? options.symbols
|
|
171
171
|
: parseTickerListInput(options?.arg ?? context.activeTicker ?? "", MAX_RELATIVE_VALUATION_TICKERS);
|
|
172
172
|
} catch {
|
|
173
|
+
// Intentional ignore: a ticker list the parser rejects creates no pane.
|
|
173
174
|
return null;
|
|
174
175
|
}
|
|
175
176
|
return {
|
|
@@ -162,7 +162,7 @@ export function normalizeCapCurrency(value: string): string {
|
|
|
162
162
|
try {
|
|
163
163
|
known = Intl.supportedValuesOf("currency");
|
|
164
164
|
} catch {
|
|
165
|
-
//
|
|
165
|
+
// Intentional ignore: an older runtime lists no currencies, so the shape check stands alone.
|
|
166
166
|
}
|
|
167
167
|
if (!CURRENCY_CODE.test(code) || (known.length > 0 && !known.includes(code))) {
|
|
168
168
|
throw new Error(`Invalid --currency value "${value}". Use a three-letter currency code such as USD or EUR.`);
|
|
@@ -10,6 +10,7 @@ import { notATickerSymbol } from "../../../sources/provider-errors";
|
|
|
10
10
|
import { fetchScreen } from "../equity-screener/client";
|
|
11
11
|
import { loadHeadlessFinancials } from "../shared/headless-market-data";
|
|
12
12
|
import { loadFxLegs } from "./relative-valuation-currency";
|
|
13
|
+
import { logFailure } from "../../../utils/log-failure";
|
|
13
14
|
|
|
14
15
|
/** The pane setting holding the peers chosen for its subject (`PeerSelection`), which the report reads back too. */
|
|
15
16
|
export const PEER_SELECTION_SETTING = "peerSelection";
|
|
@@ -438,7 +439,7 @@ export async function pickPeers(symbol: string, financials: TickerFinancials | n
|
|
|
438
439
|
let failure: string | null = null;
|
|
439
440
|
try {
|
|
440
441
|
const [capUsd, industryRows, coreRows] = await Promise.all([
|
|
441
|
-
subjectCapUsd(financials, ctx).catch((
|
|
442
|
+
subjectCapUsd(financials, ctx).catch(logFailure("research.relative-valuation-peers", "Read subject market cap for peers failed", null)),
|
|
442
443
|
screenRows([{ field: "industry", op: "in", value: [group.industry] }], ctx),
|
|
443
444
|
group.related ? screenRows([{ field: "symbol", op: "in", value: [...group.related.core] }], ctx) : Promise.resolve([]),
|
|
444
445
|
]);
|
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
RESEARCH_SEARCH_TEMPLATE_ID,
|
|
17
17
|
} from "./model";
|
|
18
18
|
import { parseMarkedSnippet } from "./snippet";
|
|
19
|
+
import { logFailure } from "../../../utils/log-failure";
|
|
19
20
|
|
|
20
21
|
/**
|
|
21
22
|
* Each hit costs two rows (title, then source and snippet), and the sheet now
|
|
@@ -123,7 +124,8 @@ function createCorpusSearchProvider(
|
|
|
123
124
|
signal,
|
|
124
125
|
);
|
|
125
126
|
hits = response.hits ?? [];
|
|
126
|
-
} catch {
|
|
127
|
+
} catch (error) {
|
|
128
|
+
if (!signal.aborted) logFailure("research-search.command-bar-search", "Search documents for command bar failed")(error);
|
|
127
129
|
return [];
|
|
128
130
|
}
|
|
129
131
|
|
|
@@ -7,6 +7,7 @@ import type {
|
|
|
7
7
|
import type { IssuerListingParams } from "../../../api-client/paths";
|
|
8
8
|
import { createPluginCache } from "../../../data/plugin-cache";
|
|
9
9
|
import { secListingKey } from "../../../utils/sec";
|
|
10
|
+
import { logFailure } from "../../../utils/log-failure";
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
13
|
* Revenue by product, segment or region comes from Gloom Cloud, which reads
|
|
@@ -94,8 +95,8 @@ export function cachedRevenueBreakdown(
|
|
|
94
95
|
if (!cached) return null;
|
|
95
96
|
try {
|
|
96
97
|
return { payload: validateRevenueBreakdown(cached.data), stale: false, refreshError: null };
|
|
97
|
-
} catch {
|
|
98
|
-
return null;
|
|
98
|
+
} catch (error) {
|
|
99
|
+
return logFailure("revenue-breakdown.client", "Validate cached revenue breakdown failed", null)(error);
|
|
99
100
|
}
|
|
100
101
|
}
|
|
101
102
|
|
|
@@ -3,6 +3,7 @@ import { resolveHeadlessInstrument } from "../shared/headless-market-data";
|
|
|
3
3
|
import { loadSeasonalityHistory } from "./client";
|
|
4
4
|
import { closedHistoryBarDay, formingHistoryBar } from "../ticker-detail/data-panes/history-bars";
|
|
5
5
|
import { MONTH_LABELS, projectSeasonality, projectWeekdays, TURN_OF_MONTH_LABELS } from "./model";
|
|
6
|
+
import { logFailure } from "../../../utils/log-failure";
|
|
6
7
|
|
|
7
8
|
const percent = (digits: number) => (value: unknown) => typeof value === "number" ? `${(value * 100).toFixed(digits)}%` : "--";
|
|
8
9
|
const statColumns = (digits: number, countHeader: string) => [{ key: "mean", header: "Avg", format: percent(digits) },
|
|
@@ -50,7 +51,7 @@ export const seasonalityHeadless: HeadlessPaneDefinition<"bundle"> = {
|
|
|
50
51
|
// Monthly bars are dated by their month's first day, which is no close while the month runs.
|
|
51
52
|
const bar = model.asOf?.toISOString().slice(0, 10);
|
|
52
53
|
// The venue whose sessions say whether the month still runs: the key's, or for a bare symbol its quote's.
|
|
53
|
-
const quote = bar && !instrument.exchange ? await ctx.marketData.getQuote(instrument.symbol, "").catch((
|
|
54
|
+
const quote = bar && !instrument.exchange ? await ctx.marketData.getQuote(instrument.symbol, "").catch(logFailure("seasonality.headless", "Load seasonality quote failed", null)) : null;
|
|
54
55
|
const venue = instrument.exchange || quote?.listingExchangeName || quote?.exchangeName || undefined;
|
|
55
56
|
const forming = formingHistoryBar("1mo", bar, venue, Date.now());
|
|
56
57
|
const closed = forming ? null : closedHistoryBarDay("1mo", bar, venue, Date.now());
|
|
@@ -9,6 +9,7 @@ import type {
|
|
|
9
9
|
import { formatShortDate } from "../../../utils/datetime-format";
|
|
10
10
|
import { secFilingItemCodes } from "../../../utils/sec";
|
|
11
11
|
import { getFilingColumnText } from "./model";
|
|
12
|
+
import { logFailure } from "../../../utils/log-failure";
|
|
12
13
|
|
|
13
14
|
const SEC_TEMPLATE_ID = "sec-pane";
|
|
14
15
|
const FILING_ROW_LIMIT = 4;
|
|
@@ -216,8 +217,8 @@ export function createSecFilingSearchProvider(
|
|
|
216
217
|
count: RECENT_FILING_COUNT,
|
|
217
218
|
});
|
|
218
219
|
filings = entry.data ?? entry.lastGoodData ?? [];
|
|
219
|
-
} catch {
|
|
220
|
-
return [];
|
|
220
|
+
} catch (error) {
|
|
221
|
+
return logFailure("sec.command-bar-search", "Load SEC filings for command bar search failed", [])(error);
|
|
221
222
|
}
|
|
222
223
|
if (signal.aborted) return [];
|
|
223
224
|
const now = deps.now();
|
|
@@ -23,6 +23,7 @@ import { mayBeUsEquityOrFundTicker, mayBeUsEquityTicker, secFilingItemCodes, US_
|
|
|
23
23
|
import { fundAbroadProfile, venueAbroad, type FundAbroadProfile } from "./fund-abroad";
|
|
24
24
|
import { listingAnnouncementsPage } from "../../../utils/exchange-announcements";
|
|
25
25
|
import { pricingSupplementTest } from "../../../utils/sec-filings";
|
|
26
|
+
import { formatInsiderName } from "../insider/display";
|
|
26
27
|
import { parseForm4Xml } from "../insider/insider-data";
|
|
27
28
|
import { createTickerSurfacePaneTemplate } from "../shared/ticker-surface";
|
|
28
29
|
import {
|
|
@@ -63,7 +64,7 @@ import {
|
|
|
63
64
|
secIssuerLabel,
|
|
64
65
|
secReportedAcceptance,
|
|
65
66
|
} from "./model";
|
|
66
|
-
import { rowSummary, rowSummaryTarget } from "./row-summaries";
|
|
67
|
+
import { ownerNames, rowSummary, rowSummaryTarget } from "./row-summaries";
|
|
67
68
|
import { usePaneTickerIdentity } from "../../../state/hooks/pane-ticker";
|
|
68
69
|
import { createSecFilingSearchProvider, resetSecFilingFocusRequests, useSecFilingFocusRequest } from "./command-bar-search";
|
|
69
70
|
|
|
@@ -150,7 +151,7 @@ function buildForm4Detail(content: string | null, filing: SecFilingItem): string
|
|
|
150
151
|
if (!tx) return buildDetailBody(filing);
|
|
151
152
|
|
|
152
153
|
const lines: string[] = [];
|
|
153
|
-
lines.push(`Insider: ${tx.reportedName}`);
|
|
154
|
+
lines.push(`Insider: ${formatInsiderName(tx.reportedName)}`);
|
|
154
155
|
if (tx.title) lines.push(`Title: ${tx.title}`);
|
|
155
156
|
for (const [index, transaction] of transactions.entries()) {
|
|
156
157
|
if (transactions.length > 1) lines.push("", `Transaction ${index + 1}`);
|
|
@@ -172,6 +173,8 @@ function toFeedItems(
|
|
|
172
173
|
documentsError: string | null,
|
|
173
174
|
contentErrors: Map<string, string>,
|
|
174
175
|
): FeedDataTableItem[] {
|
|
176
|
+
// A Form 144 names its seller freely; the insider forms read beside it say which way round.
|
|
177
|
+
const knownOwners = filings.flatMap((filing) => ownerNames(filing.form, contentCache.get(filing.accessionNumber)));
|
|
175
178
|
return filings.map((filing) => {
|
|
176
179
|
const displayTitle = getFilingDisplayTitle(filing);
|
|
177
180
|
const acceptedAt = secReportedAcceptance(filing);
|
|
@@ -186,7 +189,7 @@ function toFeedItems(
|
|
|
186
189
|
// An insider form read once says who traded and how, a fund's 24F-2NT its
|
|
187
190
|
// year's flows; the row says it too.
|
|
188
191
|
const summaryTarget = rowSummaryTarget(filing);
|
|
189
|
-
const readSummary = summaryTarget ? rowSummary(filing.form, contentCache.get(summaryTarget.accessionNumber)) : null;
|
|
192
|
+
const readSummary = summaryTarget ? rowSummary(filing.form, contentCache.get(summaryTarget.accessionNumber), knownOwners) : null;
|
|
190
193
|
const form4Detail = isOwnership && hasFetchedContent
|
|
191
194
|
? buildForm4Detail(fetchedContent ?? null, filing)
|
|
192
195
|
: null;
|
|
@@ -413,7 +416,7 @@ function SecView({ width, height, focused, paneType }: { width: number; height:
|
|
|
413
416
|
const filing = visibleFilings.find((candidate) => candidate.accessionNumber === item.id);
|
|
414
417
|
if (!coordinator || !filing) return;
|
|
415
418
|
if (coordinator.getSecDocumentsEntry(filing.accessionNumber).phase !== "idle") return;
|
|
416
|
-
void coordinator.loadSecFilingDocuments(filing).catch(() => {});
|
|
419
|
+
void coordinator.loadSecFilingDocuments(filing).catch(() => { /* Intentional ignore: the coordinator keeps a failed warm-up's error, which the filing shows when opened. */ });
|
|
417
420
|
}, [visibleFilings]);
|
|
418
421
|
|
|
419
422
|
const refresh = useCallback(() => {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { SecFilingItem } from "../../../types/data-provider";
|
|
2
2
|
import { decodeHtmlEntities } from "../../../utils/html-entities";
|
|
3
3
|
import { formatCompact } from "../../../utils/format";
|
|
4
|
+
import { formatFreeformPersonName, formatInsiderName } from "../insider/display";
|
|
4
5
|
import { parseForm4Xml, transactionTypeLabel } from "../insider/insider-data";
|
|
5
6
|
import { buildInsiderTransactionTitle } from "./filing-display";
|
|
6
7
|
|
|
@@ -36,9 +37,20 @@ export function rowSummaryTarget(filing: SecFilingItem): SecFilingItem | null {
|
|
|
36
37
|
return { ...filing, accessionNumber: `${filing.accessionNumber}:${document}`, primaryDocument: document, primaryDocumentUrl: url, filingUrl: url };
|
|
37
38
|
}
|
|
38
39
|
|
|
39
|
-
function
|
|
40
|
-
const
|
|
41
|
-
return decodeHtmlEntities((match
|
|
40
|
+
function tagTexts(xml: string, tag: string): string[] {
|
|
41
|
+
const pattern = new RegExp(`<(?:[\\w.-]+:)?${tag}(?:\\s[^>]*)?>([\\s\\S]*?)<\\/(?:[\\w.-]+:)?${tag}\\s*>`, "gi");
|
|
42
|
+
return [...xml.matchAll(pattern)].map((match) => decodeHtmlEntities((match[1] ?? "").replace(/<[^>]*>/g, "").trim()));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const tagText = (xml: string, tag: string): string => tagTexts(xml, tag)[0] ?? "";
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* The reporting owners a Form 3, 4 or 5 names, spelled as filed ("COOK TIMOTHY D"):
|
|
49
|
+
* what a Form 144's free-text seller is recognised by, so one person reads alike on every row.
|
|
50
|
+
*/
|
|
51
|
+
export function ownerNames(form: string, content: string | null | undefined): string[] {
|
|
52
|
+
if (!content || !/^[345](?:\/A)?$/i.test(form.trim())) return [];
|
|
53
|
+
return tagTexts(content, "rptOwnerName").filter(Boolean);
|
|
42
54
|
}
|
|
43
55
|
|
|
44
56
|
const money = (value: number) => `$${formatCompact(value)}`;
|
|
@@ -47,9 +59,10 @@ const money = (value: number) => `$${formatCompact(value)}`;
|
|
|
47
59
|
* A Form 144 is a notice that someone means to sell: who, how many shares
|
|
48
60
|
* and what they were worth when it was filed.
|
|
49
61
|
*/
|
|
50
|
-
function form144Summary(xml: string): RowSummary | null {
|
|
51
|
-
const
|
|
52
|
-
if (!
|
|
62
|
+
function form144Summary(xml: string, knownOwners: readonly string[]): RowSummary | null {
|
|
63
|
+
const filedName = tagText(xml, "nameOfPersonForWhoseAccountTheSecuritiesAreToBeSold");
|
|
64
|
+
if (!filedName) return null;
|
|
65
|
+
const name = formatFreeformPersonName(filedName, knownOwners);
|
|
53
66
|
const shares = Number(tagText(xml, "noOfUnitsSold"));
|
|
54
67
|
const value = Number(tagText(xml, "aggregateMarketValue"));
|
|
55
68
|
const amount = [
|
|
@@ -62,7 +75,7 @@ function form144Summary(xml: string): RowSummary | null {
|
|
|
62
75
|
/** The reporting owner of a Form 3, which lists holdings and no transactions. */
|
|
63
76
|
function initialOwnershipSummary(xml: string): RowSummary | null {
|
|
64
77
|
const name = tagText(xml, "rptOwnerName");
|
|
65
|
-
return name ? { title: `${name}: initial holdings`, direction: null } : null;
|
|
78
|
+
return name ? { title: `${formatInsiderName(name)}: initial holdings`, direction: null } : null;
|
|
66
79
|
}
|
|
67
80
|
|
|
68
81
|
const signedMoney = (value: number) => `${value < 0 ? "-" : "+"}${money(Math.abs(value))}`;
|
|
@@ -86,20 +99,23 @@ function fundFlowSummary(xml: string): RowSummary | null {
|
|
|
86
99
|
/**
|
|
87
100
|
* The row text of a filing whose content has been read, or null when it was
|
|
88
101
|
* not read or says nothing a row can use. An insider form with one
|
|
89
|
-
* transaction says it in full; one with several lists their kinds.
|
|
102
|
+
* transaction says it in full; one with several lists their kinds. Names read
|
|
103
|
+
* as the Insider table writes them; `knownOwners` (`ownerNames` of the
|
|
104
|
+
* insider forms read beside this one) tells a Form 144's seller which way round
|
|
105
|
+
* their name is filed.
|
|
90
106
|
*/
|
|
91
|
-
export function rowSummary(form: string, content: string | null | undefined): RowSummary | null {
|
|
107
|
+
export function rowSummary(form: string, content: string | null | undefined, knownOwners: readonly string[] = []): RowSummary | null {
|
|
92
108
|
if (!content) return null;
|
|
93
109
|
if (FUND_FLOW_FORM.test(form.trim())) return fundFlowSummary(content);
|
|
94
110
|
if (!isOwnershipForm(form)) return null;
|
|
95
111
|
const base = form.trim().replace(/\/A$/i, "");
|
|
96
|
-
if (base === "144") return form144Summary(content);
|
|
112
|
+
if (base === "144") return form144Summary(content, knownOwners);
|
|
97
113
|
const transactions = parseForm4Xml(content);
|
|
98
114
|
const first = transactions[0];
|
|
99
115
|
if (!first) return base === "3" ? initialOwnershipSummary(content) : null;
|
|
100
116
|
const codes = new Set(transactions.map((transaction) => transaction.transactionType));
|
|
101
117
|
const direction = codes.has("P") && !codes.has("S") ? "buy" : codes.has("S") && !codes.has("P") ? "sell" : null;
|
|
102
|
-
if (transactions.length === 1) return { title: `${first.reportedName}: ${buildInsiderTransactionTitle(first)}`, direction };
|
|
118
|
+
if (transactions.length === 1) return { title: `${formatInsiderName(first.reportedName)}: ${buildInsiderTransactionTitle(first)}`, direction };
|
|
103
119
|
const kinds = [...new Set(transactions.map((transaction) => transactionTypeLabel(transaction.transactionType)))];
|
|
104
|
-
return { title: `${first.reportedName}: ${transactions.length} transactions, ${kinds.join(", ")}`, direction };
|
|
120
|
+
return { title: `${formatInsiderName(first.reportedName)}: ${transactions.length} transactions, ${kinds.join(", ")}`, direction };
|
|
105
121
|
}
|
|
@@ -9,6 +9,7 @@ import { loadShortInterest, type ShortInterestResult } from "./client";
|
|
|
9
9
|
import { type CurrentFloat, type SettlementFloatStatistics, withPercentFloat } from "./model";
|
|
10
10
|
import { buildShortWatchRow, type ShortWatchRow } from "./watch-model";
|
|
11
11
|
import type { ShortInterestRecord } from "./types";
|
|
12
|
+
import { logFailure } from "../../../utils/log-failure";
|
|
12
13
|
|
|
13
14
|
const CONCURRENCY = 6;
|
|
14
15
|
|
|
@@ -47,7 +48,7 @@ async function loadFloats(
|
|
|
47
48
|
): Promise<FloatSnapshot[]> {
|
|
48
49
|
const entries = await Promise.resolve()
|
|
49
50
|
.then(() => loadSnapshots(symbols.map((symbol) => ({ symbol, exchange: "" })), options))
|
|
50
|
-
.catch((
|
|
51
|
+
.catch(logFailure("short-interest.watch-client", "Load float snapshots failed", []));
|
|
51
52
|
return symbols.map((_symbol, index) => {
|
|
52
53
|
const entry = entries[index];
|
|
53
54
|
const fundamentals = (entry ? resolveEntryValue(entry) : null)?.fundamentals;
|
|
@@ -5,6 +5,7 @@ import type { SocialMentionDayPosts, SocialMentionPost, SocialMentionsPayload, S
|
|
|
5
5
|
import { createPluginCache, savedCopyForTransientFailure } from "../../../data/plugin-cache";
|
|
6
6
|
import { CLOUD_SESSION_REQUIRED } from "../shared/research-cloud-session";
|
|
7
7
|
import { unavailableOnServer } from "../shared/cloud-resource";
|
|
8
|
+
import { logFailure } from "../../../utils/log-failure";
|
|
8
9
|
|
|
9
10
|
export const socialMentionsCache = createPluginCache<SocialMentionsPayload>({
|
|
10
11
|
kind: "social-mentions", source: "gloom-cloud", schemaVersion: 1,
|
|
@@ -71,7 +72,7 @@ export function cachedSocialMentions(symbol: string, range: SocialMentionsRange)
|
|
|
71
72
|
const cached = socialMentionsCache.get(cacheKey(symbol, range), { allowExpired: true });
|
|
72
73
|
if (!cached) return null;
|
|
73
74
|
try { return { payload: validateSocialMentions(cached.data, symbol, range), stale: false, refreshError: null }; }
|
|
74
|
-
catch { return null; }
|
|
75
|
+
catch (error) { return logFailure("social-mentions.client", "Validate cached social mentions failed", null)(error); }
|
|
75
76
|
}
|
|
76
77
|
export async function loadSocialMentions(symbol: string, range: SocialMentionsRange, force = false): Promise<SocialMentionsResource> {
|
|
77
78
|
// A refusal (a signed-out session, any other 4xx but 408 and 429) or a reply that fails validation shows as itself.
|
|
@@ -22,7 +22,7 @@ const date = (value: unknown) => text(value) && /^\d{4}-\d{2}-\d{2}$/.test(value
|
|
|
22
22
|
const timestamp = (value: unknown) => text(value) && Number.isFinite(Date.parse(value));
|
|
23
23
|
const tier = (value: unknown) => Number.isInteger(value) && Number(value) >= 1 && Number(value) <= 6;
|
|
24
24
|
const claim = (value: unknown) => ["disclosed", "company_confirmed", "reported", "rumored"].includes(String(value));
|
|
25
|
-
const url = (value: unknown) => { try { return text(value) && ["http:", "https:"].includes(new URL(value).protocol); } catch { return false; } };
|
|
25
|
+
const url = (value: unknown) => { try { return text(value) && ["http:", "https:"].includes(new URL(value).protocol); } catch { /* Intentional ignore: malformed URLs fail this web link field validator. */ return false; } };
|
|
26
26
|
function evidence(value: SupplyEvidenceItem): boolean {
|
|
27
27
|
return !!value && text(value.id) && tier(value.tier) && claim(value.claimType) && url(value.url)
|
|
28
28
|
&& text(value.title) && text(value.publisher) && timestamp(value.publishedAt) && timestamp(value.fetchedAt)
|
|
@@ -70,7 +70,7 @@ export const supplyScreenshotEvidence: PaneScreenshotEvidenceHook<SupplyEvidence
|
|
|
70
70
|
// Return the validated payload: restricted quotes and glosses have been removed.
|
|
71
71
|
return { ...value, payload } as unknown as SupplyEvidence;
|
|
72
72
|
}
|
|
73
|
-
} catch { return null; }
|
|
73
|
+
} catch { /* Intentional ignore: invalid captured observations are rejected as evidence by returning null. */ return null; }
|
|
74
74
|
},
|
|
75
75
|
mismatches(evidence, { resolved, payload }) {
|
|
76
76
|
const settings = payload.config.layout.instances.find(entry => entry.instanceId === payload.paneId)?.settings;
|
|
@@ -26,6 +26,7 @@ import { isPlainKey } from "../../../utils/keyboard";
|
|
|
26
26
|
import { DATE_FIELD_EXAMPLES } from "../../../utils/calendar-date";
|
|
27
27
|
import { displayWidth } from "../../../utils/format";
|
|
28
28
|
import { useRemoteUiNode } from "../../../remote/semantic-tree";
|
|
29
|
+
import { logFailure } from "../../../utils/log-failure";
|
|
29
30
|
|
|
30
31
|
const PATH_COLUMNS: DataTableColumn[] = [{ id: "route", label: "Route", width: 40, align: "left" }, { id: "relationships", label: "Relationships", width: 22, align: "left" }, { id: "hops", label: "Hops", width: 6, align: "right" }, { id: "score", label: "Score", width: 9, align: "right" }, { id: "confidence", label: "Confidence", width: 12, align: "right" }, { id: "exposure", label: "Estimated exposure", width: 35, align: "left" }];
|
|
31
32
|
const SOURCE_LABELS = { xbrl: "Structured filing", filing_text: "Filing text", press_release: "Company release", call: "Earnings call", news: "News", web: "Website", import: "Imported record" };
|
|
@@ -126,7 +127,7 @@ export function SupplyGraphPane({ symbol, tab, width, height, focused }: { symbo
|
|
|
126
127
|
const [visibleLinks, setVisibleLinks] = useState<string[]>([]);
|
|
127
128
|
const [inputsOpen, setInputsOpen] = useState(false);
|
|
128
129
|
const [snapshotSetting] = usePaneSettingValue<GraphPayload | null>("graphSnapshot", null);
|
|
129
|
-
const snapshot = useMemo(() => { try { return snapshotSetting ? validateGraph(snapshotSetting) : null; } catch { return null; } }, [snapshotSetting]);
|
|
130
|
+
const snapshot = useMemo(() => { try { return snapshotSetting ? validateGraph(snapshotSetting) : null; } catch (error) { return logFailure("supply-chain.graph-pane", "Validate supply chain graph snapshot failed", null)(error); } }, [snapshotSetting]);
|
|
130
131
|
const loader = useCallback((force: boolean) => snapshot ? Promise.resolve({ payload: snapshot, stale: false, refreshError: null }) : loadGraph(focus, target, options, accessKey, force), [focus, target, options, accessKey, snapshot]);
|
|
131
132
|
const resource = useAsyncResource(tab === "path" && !target ? null : loader, { initialData: () => cachedGraph(focus, target, options, accessKey), clearOnError: isAccessDenied });
|
|
132
133
|
const data = resource.data?.payload ?? null;
|
|
@@ -36,6 +36,7 @@ import {
|
|
|
36
36
|
} from "./model";
|
|
37
37
|
import { RowEvidence } from "./row-evidence";
|
|
38
38
|
import { evidenceDate, evidenceLabel, isUnconfirmed, matchesSupplyOptions, supplyOptions, TIER_OPTIONS } from "./trust";
|
|
39
|
+
import { logFailure } from "../../../utils/log-failure";
|
|
39
40
|
|
|
40
41
|
type Item = { kind: "edge"; row: SupplyRow } | { kind: "locked"; id: string };
|
|
41
42
|
const itemId = (item: Item) => item.kind === "edge" ? item.row.id : item.id;
|
|
@@ -183,7 +184,7 @@ function SupplyView({ symbol, width, height, focused }: Pick<PaneProps, "width"
|
|
|
183
184
|
const accessKey = `${session.requestKey}:${access.hasProAccess ? "full" : "preview"}`;
|
|
184
185
|
const openUpgrade = useCloudUpgradeAction("splc");
|
|
185
186
|
const [snapshotSetting] = usePaneSettingValue<SupplyChainPayload | null>("supplySnapshot", null);
|
|
186
|
-
const snapshot = useMemo(() => { try { return snapshotSetting ? validateSupplyChain(snapshotSetting) : null; } catch { return null; } }, [snapshotSetting]);
|
|
187
|
+
const snapshot = useMemo(() => { try { return snapshotSetting ? validateSupplyChain(snapshotSetting) : null; } catch (error) { return logFailure("supply-chain.pane", "Validate supply chain snapshot failed", null)(error); } }, [snapshotSetting]);
|
|
187
188
|
const [openingTab] = usePaneSettingValue("tab", "table");
|
|
188
189
|
const [savedTab, setTab] = usePluginPaneState<string>("supply:tab", openingTab);
|
|
189
190
|
const graphTab = savedTab === "graph" || savedTab === "path";
|
|
@@ -78,7 +78,7 @@ export const adrPairHeadless: HeadlessPaneDefinition<"bundle"> = {
|
|
|
78
78
|
return { sections: [], empty: `No price for ${missing}, so the pair cannot be compared.`, unavailableSymbols: [missing], errors };
|
|
79
79
|
}
|
|
80
80
|
const figures = adrPairFigures(comparison);
|
|
81
|
-
const rows = adrPairInputRows(comparison);
|
|
81
|
+
const rows = adrPairInputRows(comparison, quotes);
|
|
82
82
|
const kind = spotRateKind(homeCurrency);
|
|
83
83
|
return {
|
|
84
84
|
sections: [
|
|
@@ -2,7 +2,8 @@ import type { DepositaryPair, Quote, TickerFinancials } from "../../../../types/
|
|
|
2
2
|
import type { TickerRecord } from "../../../../types/ticker";
|
|
3
3
|
import { canonicalExchange, parsePublicTickerKey, publicTickerKey } from "../../../../utils/exchanges";
|
|
4
4
|
import { listingSuffixCandidate, listingSuffixVenue } from "../../../../sources/listing-symbols";
|
|
5
|
-
import { formatMarketPriceWithCurrency } from "../../../../market-data/market/format";
|
|
5
|
+
import { formatMarketPriceWithCurrency, liveQuoteFormatOptions, type MarketFormatOptions } from "../../../../market-data/market/format";
|
|
6
|
+
import { heldCurrencyUnit } from "../../../../utils/currency-units";
|
|
6
7
|
import { adrRatioText } from "../../../../utils/depositary-receipt";
|
|
7
8
|
import {
|
|
8
9
|
compareDepositaryPair, dollarPairLabel, formatPairRate, isReceiptSide, listingDepositaryPair, pairPriceInput, pairTimeText,
|
|
@@ -108,20 +109,39 @@ function sessionText(input: PairPriceInput): string {
|
|
|
108
109
|
return input.open ? "Open" : "Closed";
|
|
109
110
|
}
|
|
110
111
|
|
|
112
|
+
/**
|
|
113
|
+
* A leg's price written as the quote monitor writes the listing's: its
|
|
114
|
+
* instrument's own decimals (cents on a dollar price, $419.50 and never
|
|
115
|
+
* $419.5). The comparison reads a minor unit (GBp) in its currency, so the
|
|
116
|
+
* session prices the decimals come from are read in it too.
|
|
117
|
+
*/
|
|
118
|
+
function legPriceOptions(input: PairPriceInput, quote: Quote | null | undefined): MarketFormatOptions {
|
|
119
|
+
const divisor = quote?.currency ? heldCurrencyUnit(quote.currency).divisor : 1;
|
|
120
|
+
const inCurrency = (value: number | undefined) => value == null ? value : value / divisor;
|
|
121
|
+
return liveQuoteFormatOptions(
|
|
122
|
+
quote ? { ...quote, previousClose: inCurrency(quote.previousClose), regularClose: inCurrency(quote.regularClose), open: inCurrency(quote.open) } : null,
|
|
123
|
+
input.currency,
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
|
|
111
127
|
/** The inputs the figures come from, each with when it was set. */
|
|
112
|
-
export function adrPairInputRows(
|
|
128
|
+
export function adrPairInputRows(
|
|
129
|
+
comparison: DepositaryPairComparison,
|
|
130
|
+
quotes: { receipt: Quote | null | undefined; home: Quote | null | undefined },
|
|
131
|
+
now = Date.now(),
|
|
132
|
+
): AdrPairInputRow[] {
|
|
113
133
|
const { home, receipt, spot, ratio } = comparison;
|
|
114
134
|
const time = (value: number | null) => value == null ? "—" : pairTimeText(value, now).replace(/ UTC$/, "");
|
|
115
135
|
const kind = spotRateKind(home.currency);
|
|
116
136
|
return [
|
|
117
137
|
{
|
|
118
138
|
id: "home", listing: home.symbol, role: `Home, ${ratioCount(ratio)} per ADR`,
|
|
119
|
-
price: formatMarketPriceWithCurrency(home.price, home.currency, { currencyCode: true }),
|
|
139
|
+
price: formatMarketPriceWithCurrency(home.price, home.currency, { ...legPriceOptions(home, quotes.home), currencyCode: true }),
|
|
120
140
|
asOf: time(home.observedAt), session: sessionText(home), opens: home.symbol,
|
|
121
141
|
},
|
|
122
142
|
{
|
|
123
143
|
id: "receipt", listing: receipt.symbol, role: "ADR",
|
|
124
|
-
price: formatMarketPriceWithCurrency(receipt.price, receipt.currency), asOf: time(receipt.observedAt),
|
|
144
|
+
price: formatMarketPriceWithCurrency(receipt.price, receipt.currency, legPriceOptions(receipt, quotes.receipt)), asOf: time(receipt.observedAt),
|
|
125
145
|
session: sessionText(receipt), opens: receipt.symbol,
|
|
126
146
|
},
|
|
127
147
|
...spot ? [{
|
|
@@ -49,7 +49,7 @@ export function AdrPairResearchTab({ width, height, focused }: TickerResearchTab
|
|
|
49
49
|
const [selectedIndex, setSelectedIndex] = useState(0);
|
|
50
50
|
|
|
51
51
|
const stats: StatItem[] = comparison ? adrPairFigures(comparison) : [];
|
|
52
|
-
const rows = comparison ? adrPairInputRows(comparison) : [];
|
|
52
|
+
const rows = comparison ? adrPairInputRows(comparison, { receipt: receiptQuote, home: homeQuote }) : [];
|
|
53
53
|
|
|
54
54
|
if (!legs) return <EmptyState title="No ADR pair for this listing." />;
|
|
55
55
|
const pending = (entry: typeof receiptEntry) => !entry || entry.phase === "loading" || entry.phase === "idle";
|
|
@@ -79,6 +79,7 @@ export function tapeRejection(body: string): string | null {
|
|
|
79
79
|
const value = JSON.parse(body) as { gaps?: unknown };
|
|
80
80
|
return Array.isArray(value?.gaps) && typeof value.gaps[0] === "string" ? value.gaps[0] : null;
|
|
81
81
|
} catch {
|
|
82
|
+
// Intentional ignore: an error body that is not JSON names no gap, so the request's own error stands.
|
|
82
83
|
return null;
|
|
83
84
|
}
|
|
84
85
|
}
|
|
@@ -15,6 +15,7 @@ import { abortable, abortError } from "../../../utils/async-deadline";
|
|
|
15
15
|
import { errorMessage } from "../../../utils/errors";
|
|
16
16
|
import { expiredExpiryText, findListedExpiry, isLiveOptionExpiry, liveOptionExpiries, optionExpiryVenue, unlistedExpiryText } from "../../../utils/option-expiry";
|
|
17
17
|
import { optionModelSpot } from "../options/model-spot";
|
|
18
|
+
import { logFailure } from "../../../utils/log-failure";
|
|
18
19
|
|
|
19
20
|
const DEFAULT_SURFACE_EXPIRY_LIMIT = 18;
|
|
20
21
|
/** Expiries read at a time from a source that takes them one by one. */
|
|
@@ -190,7 +191,7 @@ export async function loadVolatilitySurface(
|
|
|
190
191
|
checkAbort();
|
|
191
192
|
publish();
|
|
192
193
|
// Asked while the catalogue loads, so it costs the expiries no wait.
|
|
193
|
-
const batched = Promise.resolve().then(() => dependencies.batchesExpiries?.()).then((answer) => answer === true, (
|
|
194
|
+
const batched = Promise.resolve().then(() => dependencies.batchesExpiries?.()).then((answer) => answer === true, logFailure("vol-surface.client", "Read expiry batching support failed", false));
|
|
194
195
|
const treasury = Promise.resolve().then(() => dependencies.loadYieldCurve()).then((value) => {
|
|
195
196
|
if (request.signal?.aborted) return;
|
|
196
197
|
curve = value;
|
|
@@ -16,6 +16,7 @@ import { SWAP_TENORS, type SwapCurvePayload, type SwapTenor } from "../../../api
|
|
|
16
16
|
import { fetchSwapCurve, loadSavedCurve, loadSavedWorldRows } from "./client";
|
|
17
17
|
import { savedCopyMark } from "../../../data/saved-copies";
|
|
18
18
|
import { formatSwapBp, selectedSwapTenor } from "./swaps-model";
|
|
19
|
+
import { logFailure } from "../../../utils/log-failure";
|
|
19
20
|
|
|
20
21
|
const percent = (value: unknown) => value == null ? "-" : `${Number(value).toFixed(2)}%`;
|
|
21
22
|
/** A move already in basis points: `+3bp`, `-1bp`, `0bp`. */
|
|
@@ -164,6 +165,7 @@ export function createYieldCurveHeadless(
|
|
|
164
165
|
const curve = curveIdOf(args.options.curve) ?? parseCurveArgument(args.argument).curve ?? "us";
|
|
165
166
|
return `Yield Curves | ${curveOption(curve).label}`;
|
|
166
167
|
} catch {
|
|
168
|
+
// Intentional ignore: the load reports a curve it cannot read, so the title stays generic.
|
|
167
169
|
return "Yield Curves";
|
|
168
170
|
}
|
|
169
171
|
},
|
|
@@ -206,7 +208,7 @@ export function createYieldCurveHeadless(
|
|
|
206
208
|
const compareAsOf = comparePoints ? curveAsOf(comparePoints) : null;
|
|
207
209
|
const compareAt = (maturity: string) => comparePoints?.find((point) => point.maturity === maturity)?.yield ?? null;
|
|
208
210
|
// The stored curve brings its look-backs; the FRED fallback's load after it, and a failure leaves the move blank.
|
|
209
|
-
const lookbacks: YieldLookbackCurves = data.lookbacks ?? (session ? await loadLookbacks(session, context).catch((
|
|
211
|
+
const lookbacks: YieldLookbackCurves = data.lookbacks ?? (session ? await loadLookbacks(session, context).catch(logFailure("yield-curve.headless", "Load yield curve lookbacks failed", {})) : {});
|
|
210
212
|
const tenorRows = new Map(yieldTenorRows(points, lookbacks).map((row) => [row.id, row]));
|
|
211
213
|
const rows = [...points].sort((a, b) => a.maturityYears - b.maturityYears);
|
|
212
214
|
const missing = points.filter((point) => point.yield == null);
|
|
@@ -397,6 +397,80 @@ function futuresContractSizeLabel(
|
|
|
397
397
|
return !metrics.unknownContractSize && multiplier > 1 ? { size: formatMarketQuantity(multiplier) } : null;
|
|
398
398
|
}
|
|
399
399
|
|
|
400
|
+
interface RowPositionMetrics {
|
|
401
|
+
quoteCurrency: string;
|
|
402
|
+
quote: Quote | undefined;
|
|
403
|
+
/** What the figures were worked out for: a context that disagrees works them out again. */
|
|
404
|
+
activeTab: string | undefined;
|
|
405
|
+
baseCurrency: string;
|
|
406
|
+
exchangeRates: Map<string, number>;
|
|
407
|
+
/** In the position's own currency. */
|
|
408
|
+
position: PortfolioPositionMetrics;
|
|
409
|
+
/** Converted into the pane's currency (`ctx.baseCurrency`). */
|
|
410
|
+
base: PortfolioPositionMetrics;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
/** Each shared context's row figures, by record. */
|
|
414
|
+
const sharedRowMetrics = new WeakMap<ColumnContext, WeakMap<TickerRecord, RowPositionMetrics>>();
|
|
415
|
+
const rowMetricsByOwner = new WeakMap<object, WeakMap<TickerRecord, RowPositionMetrics>>();
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* Lets the cells and sort keys read with `ctx` work out each row's position
|
|
419
|
+
* figures once per quote, rather than twice a cell: a pane's rows recompute
|
|
420
|
+
* every visible cell when a quote ticks. Contexts given the same `owner` share
|
|
421
|
+
* the figures while they agree on the tab, currency and rates (a context that
|
|
422
|
+
* disagrees works them out again). Only for records that are replaced when
|
|
423
|
+
* they change, never edited in place.
|
|
424
|
+
*/
|
|
425
|
+
export function sharePositionMetrics<T extends ColumnContext>(ctx: T, owner: object = ctx): T {
|
|
426
|
+
let rows = rowMetricsByOwner.get(owner);
|
|
427
|
+
if (!rows) {
|
|
428
|
+
rows = new WeakMap();
|
|
429
|
+
rowMetricsByOwner.set(owner, rows);
|
|
430
|
+
}
|
|
431
|
+
sharedRowMetrics.set(ctx, rows);
|
|
432
|
+
return ctx;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
function computeRowPositionMetrics(ticker: TickerRecord, ctx: ColumnContext, quoteCurrency: string, quote: Quote | undefined): RowPositionMetrics {
|
|
436
|
+
const { activeTab, baseCurrency, exchangeRates } = ctx;
|
|
437
|
+
return {
|
|
438
|
+
quoteCurrency,
|
|
439
|
+
quote,
|
|
440
|
+
activeTab,
|
|
441
|
+
baseCurrency,
|
|
442
|
+
exchangeRates,
|
|
443
|
+
position: getPortfolioPositionMetrics(ticker, ctx.activeTab, quoteCurrency, undefined, quote),
|
|
444
|
+
base: getPortfolioPositionMetrics(ticker, ctx.activeTab, quoteCurrency, {
|
|
445
|
+
currency: baseCurrency,
|
|
446
|
+
convert: (value, currency) => convertCurrency(value, currency, baseCurrency, exchangeRates),
|
|
447
|
+
}, quote),
|
|
448
|
+
};
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
/** A row's position figures, in its own currency and in the pane's (sharePositionMetrics). */
|
|
452
|
+
function rowPositionMetrics(
|
|
453
|
+
ticker: TickerRecord,
|
|
454
|
+
ctx: ColumnContext,
|
|
455
|
+
quoteCurrency: string,
|
|
456
|
+
quote: Quote | undefined,
|
|
457
|
+
): RowPositionMetrics {
|
|
458
|
+
const rows = sharedRowMetrics.get(ctx);
|
|
459
|
+
if (!rows) return computeRowPositionMetrics(ticker, ctx, quoteCurrency, quote);
|
|
460
|
+
const cached = rows.get(ticker);
|
|
461
|
+
if (
|
|
462
|
+
cached
|
|
463
|
+
&& cached.quote === quote
|
|
464
|
+
&& cached.quoteCurrency === quoteCurrency
|
|
465
|
+
&& cached.activeTab === ctx.activeTab
|
|
466
|
+
&& cached.baseCurrency === ctx.baseCurrency
|
|
467
|
+
&& cached.exchangeRates === ctx.exchangeRates
|
|
468
|
+
) return cached;
|
|
469
|
+
const entry = computeRowPositionMetrics(ticker, ctx, quoteCurrency, quote);
|
|
470
|
+
rows.set(ticker, entry);
|
|
471
|
+
return entry;
|
|
472
|
+
}
|
|
473
|
+
|
|
400
474
|
export function getColumnValue(
|
|
401
475
|
col: ColumnConfig,
|
|
402
476
|
ticker: TickerRecord,
|
|
@@ -408,7 +482,7 @@ export function getColumnValue(
|
|
|
408
482
|
const fundamentals = financials?.fundamentals;
|
|
409
483
|
const quoteCurrency = quote?.currency || ticker.metadata.currency || "USD";
|
|
410
484
|
|
|
411
|
-
const positionMetrics =
|
|
485
|
+
const { position: positionMetrics, base: baseMetrics } = rowPositionMetrics(ticker, ctx, quoteCurrency, quote);
|
|
412
486
|
const futures = positionMetrics.isFuture ? ctx.futuresTerms?.get(ticker.metadata.ticker) : undefined;
|
|
413
487
|
// The latest print, which the quote columns read, and the price the position is valued at.
|
|
414
488
|
const liveQuote = getPortfolioQuoteDisplay(positionMetrics, quote);
|
|
@@ -416,10 +490,6 @@ export function getColumnValue(
|
|
|
416
490
|
const displayQuote = tradedQuoteDisplay(positionMetrics, liveQuote, quote);
|
|
417
491
|
const headlineQuote = settledHeadline(positionMetrics, ctx, futures) ?? headlineQuoteDisplay(displayQuote, quote);
|
|
418
492
|
const { positionCurrency, totalShares, totalCost, totalCostUnits, totalPriceUnits, multiplierHint, brokerMarkPrice } = positionMetrics;
|
|
419
|
-
const baseMetrics = getPortfolioPositionMetrics(ticker, ctx.activeTab, quoteCurrency, {
|
|
420
|
-
currency: ctx.baseCurrency,
|
|
421
|
-
convert: (value, currency) => convertCurrency(value, currency, ctx.baseCurrency, ctx.exchangeRates),
|
|
422
|
-
}, quote);
|
|
423
493
|
|
|
424
494
|
const toBaseQuote = (value: number) =>
|
|
425
495
|
convertCurrency(value, quoteCurrency, ctx.baseCurrency, ctx.exchangeRates);
|
|
@@ -685,17 +755,13 @@ export function getSortValue(
|
|
|
685
755
|
const fundamentals = financials?.fundamentals;
|
|
686
756
|
const quoteCurrency = quote?.currency || ticker.metadata.currency || "USD";
|
|
687
757
|
|
|
688
|
-
const positionMetrics =
|
|
758
|
+
const { position: positionMetrics, base: baseMetrics } = rowPositionMetrics(ticker, ctx, quoteCurrency, quote);
|
|
689
759
|
const futures = positionMetrics.isFuture ? ctx.futuresTerms?.get(ticker.metadata.ticker) : undefined;
|
|
690
760
|
const liveQuote = getPortfolioQuoteDisplay(positionMetrics, quote);
|
|
691
761
|
const activeQuote = getPortfolioValuationDisplay(positionMetrics, quote, ctx.valuationBasis, futures?.settlement);
|
|
692
762
|
const displayQuote = tradedQuoteDisplay(positionMetrics, liveQuote, quote);
|
|
693
763
|
const headlineQuote = settledHeadline(positionMetrics, ctx, futures) ?? headlineQuoteDisplay(displayQuote, quote);
|
|
694
764
|
const { positionCurrency, totalShares, totalCost, totalCostUnits, totalPriceUnits, brokerMarkPrice } = positionMetrics;
|
|
695
|
-
const baseMetrics = getPortfolioPositionMetrics(ticker, ctx.activeTab, quoteCurrency, {
|
|
696
|
-
currency: ctx.baseCurrency,
|
|
697
|
-
convert: (value, currency) => convertCurrency(value, currency, ctx.baseCurrency, ctx.exchangeRates),
|
|
698
|
-
}, quote);
|
|
699
765
|
|
|
700
766
|
const toBaseQuote = (value: number) =>
|
|
701
767
|
convertCurrency(value, quoteCurrency, ctx.baseCurrency, ctx.exchangeRates);
|