gloomberb 0.20.13 → 0.20.14
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 +2 -1
- package/patches/@opentui%2Fcore@0.3.2.patch +22 -4
- package/src/account/auth-dialog.tsx +22 -4
- package/src/account/auth-form.tsx +6 -1
- package/src/account/checkout-handoff.tsx +7 -14
- package/src/account/device-signin-dialog.tsx +35 -24
- package/src/api-client/crypto-markets.ts +10 -0
- package/src/api-client/errors.ts +3 -1
- package/src/api-client/money-markets.ts +7 -0
- package/src/api-client/request.ts +12 -2
- package/src/architecture/floating-promise-allowlist.json +0 -1
- package/src/brokers/signed-in/sign-in-dialog.tsx +38 -38
- package/src/cli/commands/market.ts +95 -23
- package/src/cli/commands/overview.ts +18 -4
- package/src/cli/errors.ts +3 -1
- package/src/cli/freshness.ts +7 -2
- package/src/cli/glossary.ts +10 -5
- package/src/cli/helpers.ts +8 -16
- package/src/cli/history-export.ts +4 -0
- package/src/cli/known-gaps.ts +2 -2
- package/src/cli/listing-arg.ts +79 -11
- package/src/cli/not-a-ticker.ts +4 -0
- package/src/cli/pane-functions/catalog.ts +29 -8
- package/src/cli/pane-functions/headless.ts +5 -2
- package/src/cli/pane-functions/options.ts +7 -0
- package/src/cli/pane-functions/resolver.ts +61 -15
- package/src/cli/result.ts +22 -4
- package/src/cli/symbol-args.ts +5 -3
- package/src/cli/symbol-list.ts +23 -10
- package/src/cli/symbol-rows.ts +135 -3
- package/src/cli/treasury-yields.ts +15 -1
- package/src/components/chart/composite/format.ts +2 -1
- package/src/components/chart/composite/panel-surface/axis-markers.ts +133 -0
- package/src/components/chart/composite/panel-surface/level-labels.tsx +78 -0
- package/src/components/chart/composite/panel-surface/overlays.ts +108 -0
- package/src/components/chart/composite/panel-surface/pan-coast.ts +54 -0
- package/src/components/chart/composite/panel-surface/panel-cursor.tsx +138 -0
- package/src/components/chart/composite/panel-surface/panel-levels.ts +47 -0
- package/src/components/chart/composite/panel-surface/plot-gestures.ts +403 -0
- package/src/components/chart/composite/panel-surface/plot-pointer.ts +65 -0
- package/src/components/chart/composite/panel-surface/plot-wheel.ts +102 -0
- package/src/components/chart/composite/panel-surface/pointer.ts +12 -0
- package/src/components/chart/composite/panel-surface/props.ts +79 -0
- package/src/components/chart/composite/panel-surface/tool-readout.ts +151 -0
- package/src/components/chart/composite/panel-surface/value-axis-gestures.ts +152 -0
- package/src/components/chart/composite/panel-surface.tsx +81 -1177
- package/src/components/command-bar/commands/collection-list.ts +1 -0
- package/src/components/command-bar/routes/root/results.ts +3 -2
- package/src/components/command-bar/routes/root/runtime.ts +3 -2
- package/src/components/command-bar/routes/root/selection.ts +3 -2
- package/src/components/command-bar/routes/root/shortcuts.ts +15 -0
- package/src/components/layout/pane/title.ts +10 -4
- package/src/components/pane-settings-dialog/tui.tsx +6 -3
- package/src/components/pane-settings-dialog.tsx +2 -1
- package/src/components/pane-template-wizard.tsx +2 -0
- package/src/components/ui/choice-dialog.tsx +1 -1
- package/src/components/ui/confirm-dialog.tsx +3 -2
- package/src/components/ui/frame.tsx +7 -3
- package/src/components/ui/icon.tsx +4 -2
- package/src/components/ui/list-view.tsx +8 -0
- package/src/components/ui/number-prompt-dialog.tsx +2 -1
- package/src/components/use-pane-notice-footer.tsx +3 -1
- package/src/docs/snapshot.json +2 -2
- package/src/i18n/es.ts +1 -0
- package/src/i18n/ja.ts +1 -0
- package/src/i18n/ko.ts +1 -0
- package/src/i18n/zh-cn.ts +1 -0
- package/src/i18n/zh-tw.ts +1 -0
- package/src/market-data/market/format.ts +35 -1
- package/src/market-data/quotes/contributions.ts +13 -0
- package/src/market-data/quotes/export-identity.ts +36 -1
- package/src/market-data/quotes/resolution.ts +16 -0
- package/src/plugins/builtin/account-management/password-dialog.tsx +2 -2
- package/src/plugins/builtin/analytics/risk-client.ts +12 -2
- package/src/plugins/builtin/analytics/risk-headless.ts +66 -6
- package/src/plugins/builtin/analytics/risk-math.ts +23 -6
- package/src/plugins/builtin/analytics/risk-model.ts +20 -9
- package/src/plugins/builtin/analytics/risk-pane.tsx +2 -2
- package/src/plugins/builtin/chart-composer/catalog-inventory.ts +5 -2
- package/src/plugins/builtin/chart-composer/editor.tsx +1 -0
- package/src/plugins/builtin/chart-composer/pane.tsx +1 -1
- package/src/plugins/builtin/chart-composer/quick-add.tsx +4 -1
- package/src/plugins/builtin/chart-composer/series-catalog.ts +17 -1
- package/src/plugins/builtin/cloud/plugin.tsx +2 -0
- package/src/plugins/builtin/cloud/thesis/module.tsx +2 -0
- package/src/plugins/builtin/cloud/upgrade-status-widget.tsx +6 -2
- package/src/plugins/builtin/cpi/headless.ts +6 -1
- package/src/plugins/builtin/cpi/model.ts +17 -0
- package/src/plugins/builtin/cpi/pane.tsx +3 -1
- package/src/plugins/builtin/crypto-board/client.ts +6 -1
- package/src/plugins/builtin/crypto-board/headless.ts +10 -2
- package/src/plugins/builtin/crypto-board/model.ts +89 -11
- package/src/plugins/builtin/crypto-board/pane.tsx +20 -5
- package/src/plugins/builtin/dividend-yield/client.ts +24 -2
- package/src/plugins/builtin/dividend-yield/headless.ts +4 -2
- package/src/plugins/builtin/dividend-yield/ranking.ts +2 -1
- package/src/plugins/builtin/dividend-yield/view.ts +5 -1
- package/src/plugins/builtin/earnings/history-table.ts +8 -0
- package/src/plugins/builtin/earnings-ripple/index.tsx +2 -0
- package/src/plugins/builtin/econ/calendar-model.ts +17 -1
- package/src/plugins/builtin/econ/fred-catalog.ts +33 -4
- package/src/plugins/builtin/econ-statistics/headless.ts +21 -0
- package/src/plugins/builtin/macro-day/headless.ts +21 -10
- package/src/plugins/builtin/macro-day/model.ts +40 -3
- package/src/plugins/builtin/macro-day/pane.tsx +26 -8
- package/src/plugins/builtin/macro-day/releases.ts +24 -1
- package/src/plugins/builtin/money-markets/client.ts +4 -1
- package/src/plugins/builtin/money-markets/headless.ts +15 -4
- package/src/plugins/builtin/money-markets/index.tsx +1 -1
- package/src/plugins/builtin/money-markets/pane.tsx +7 -1
- package/src/plugins/builtin/portfolio-list/cli/bulk-symbols.ts +4 -2
- package/src/plugins/builtin/portfolio-list/cli/period-report.ts +61 -11
- package/src/plugins/builtin/portfolio-list/cli/portfolio-command.ts +11 -3
- package/src/plugins/builtin/portfolio-list/cli/watchlist-command.ts +2 -0
- package/src/plugins/builtin/portfolio-list/headless.ts +33 -6
- package/src/plugins/builtin/portfolio-list/pane/index.tsx +5 -3
- package/src/plugins/builtin/portfolio-list/pane/period-pnl.ts +24 -6
- package/src/plugins/builtin/portfolio-list/period-pnl.ts +16 -1
- package/src/plugins/builtin/portfolio-list/summary/index.tsx +4 -1
- package/src/plugins/builtin/portfolio-list/summary/totals.ts +6 -4
- package/src/plugins/builtin/portfolio-list/table.tsx +25 -15
- package/src/plugins/builtin/shared/cloud-upgrade.ts +4 -2
- package/src/plugins/builtin/shared/cpi-year-gap.ts +67 -0
- package/src/plugins/builtin/ticker-detail/adr-pair/headless.ts +45 -2
- package/src/plugins/builtin/ticker-detail/headless.ts +26 -1
- package/src/plugins/builtin/ticker-detail/overview/components.tsx +4 -5
- package/src/plugins/builtin/ticker-detail/overview/model.ts +4 -1
- package/src/plugins/builtin/ticker-detail/overview-tab.tsx +10 -2
- package/src/portfolio/collection-name.ts +2 -1
- package/src/portfolio/column-values.ts +14 -4
- package/src/portfolio/listed-symbol.ts +4 -2
- package/src/portfolio/period-pnl.ts +51 -1
- package/src/renderers/dom/dialog-host.tsx +5 -5
- package/src/renderers/electrobun/view/remote/capability-invoker.ts +1 -1
- package/src/renderers/opentui/dialog-host.tsx +3 -4
- package/src/sources/gloomberb-cloud/normalizers.ts +5 -0
- package/src/sources/provider-router/history.ts +5 -2
- package/src/test-support/plugin-persistence.ts +12 -0
- package/src/tickers/company-name-listing.ts +4 -3
- package/src/tickers/company-name.ts +19 -1
- package/src/tickers/instrument-coverage.ts +27 -0
- package/src/tickers/search/home-listing.ts +38 -1
- package/src/tickers/search/index.ts +3 -2
- package/src/tickers/search/ranking.ts +21 -2
- package/src/time-series/base-series.ts +4 -0
- package/src/time-series/types.ts +5 -2
- package/src/types/financials.ts +13 -0
- package/src/types/headless.ts +2 -0
- package/src/ui/dialog-stack.ts +17 -0
- package/src/ui/dialog.tsx +6 -2
- package/src/utils/crypto-pair.ts +9 -0
- package/src/utils/exchanges.ts +13 -0
- package/src/utils/financial-statements.ts +60 -3
- package/src/utils/futures-generic.ts +14 -0
- package/src/utils/trailing-dividend.ts +13 -3
|
@@ -9,6 +9,7 @@ import type {
|
|
|
9
9
|
import type { TickerRecord } from "../../../types/ticker";
|
|
10
10
|
import type { Quote } from "../../../types/financials";
|
|
11
11
|
import { formatNumber, formatPercentRaw } from "../../../utils/format";
|
|
12
|
+
import { displayTickerKey } from "../../../utils/exchanges";
|
|
12
13
|
import {
|
|
13
14
|
collectionQuoteHeadline,
|
|
14
15
|
dayMoveLine,
|
|
@@ -53,7 +54,7 @@ import { describeCollections } from "../../../portfolio/collection-name";
|
|
|
53
54
|
import { currentListingName } from "../../../tickers/listing-name";
|
|
54
55
|
import { REPORT_ROWS } from "../shared/headless-options";
|
|
55
56
|
import { readPriceWindow, type PriceWindow } from "../../../utils/price-window";
|
|
56
|
-
import { loadPeriodPnl, periodBasisText, periodBoughtText, periodUnpricedText } from "./period-pnl";
|
|
57
|
+
import { loadPeriodPnl, periodBasisText, periodBoughtText, periodCurrencyParts, periodFxLabel, periodUnpricedText } from "./period-pnl";
|
|
57
58
|
|
|
58
59
|
/** An extended print without a known regular close cannot supply a regular-session change. */
|
|
59
60
|
function regularChangeFields(quote: Quote | undefined, change: unknown) {
|
|
@@ -493,6 +494,16 @@ const PERIOD_COLUMNS: HeadlessPaneColumn[] = [
|
|
|
493
494
|
{ key: "contribution", header: "Contribution", align: "right", format: percent, description: "P&L over the book's value at the start, gross when it holds a short, in percent." },
|
|
494
495
|
];
|
|
495
496
|
|
|
497
|
+
/** `fn PF --from` on a book in more than one currency: each currency's price P&L, FX and total, and the book's. */
|
|
498
|
+
const PERIOD_CURRENCY_COLUMNS: HeadlessPaneColumn[] = [
|
|
499
|
+
{ key: "currency", header: "Currency" },
|
|
500
|
+
{ key: "local", header: "Local", align: "right", format: amount, description: "Its holdings' price P&L, in the portfolio's currency at the end's rate." },
|
|
501
|
+
{ key: "fx", header: "FX", align: "right", format: amount, description: "The currency's move on its holdings' start value." },
|
|
502
|
+
{ key: "total", header: "Total", align: "right", format: amount },
|
|
503
|
+
{ key: "contribution", header: "Contribution", align: "right", format: percent, description: "The total over the book's value at the start, in percent." },
|
|
504
|
+
{ key: "leftOut", header: "Left out", description: "Its holdings with no P&L over the window, which the figures leave out." },
|
|
505
|
+
];
|
|
506
|
+
|
|
496
507
|
/**
|
|
497
508
|
* PF over a period (`--from`, `--to`): P&L and contribution by position
|
|
498
509
|
* between two closes, as `portfolio show --from` reads them, on the
|
|
@@ -541,18 +552,30 @@ async function portfolioPeriodHoldings(
|
|
|
541
552
|
contribution: row.contribution,
|
|
542
553
|
};
|
|
543
554
|
});
|
|
544
|
-
|
|
545
|
-
|
|
555
|
+
// An FX line per currency, then the total; the book by currency under them, as portfolio show --from prints it.
|
|
556
|
+
const parts = periodCurrencyParts(result);
|
|
557
|
+
for (const part of parts) if (!part.own) rows.push({ symbol: periodFxLabel(part.currency), pnl: part.fx, contribution: part.fxContribution });
|
|
546
558
|
rows.push({ symbol: "TOTAL", pnl: result.total, contribution: result.totalContribution });
|
|
559
|
+
// A holding by the listing it is (ES3:SGX), not the key it is saved under (ES3:XSES).
|
|
560
|
+
const listing = (symbol: string) => { const ticker = bySymbolTicker.get(symbol); return ticker ? listingLabel(ticker) : displayTickerKey(symbol); };
|
|
561
|
+
const byCurrency = parts.length > 1 ? [
|
|
562
|
+
...parts.map((part) => ({ currency: part.currency, local: part.local, fx: part.own ? null : part.fx, total: part.total, contribution: part.contribution,
|
|
563
|
+
...(part.unpriced.length ? { leftOut: part.unpriced.map(listing).join(", ") } : {}) })),
|
|
564
|
+
{ currency: "TOTAL", local: result.total - result.fx, fx: result.fx, total: result.total, contribution: result.totalContribution,
|
|
565
|
+
...(result.unpriced.length ? { leftOut: result.unpriced.map(listing).join(", ") } : {}) },
|
|
566
|
+
] : [];
|
|
567
|
+
// The Left out column only when a holding is: each currency's figures name the ones they leave out.
|
|
568
|
+
const byCurrencyColumns = PERIOD_CURRENCY_COLUMNS.filter((column) => column.key !== "leftOut" || result.unpriced.length > 0)
|
|
569
|
+
.map((column) => column.align === "right" && column.key !== "contribution" ? { ...column, header: `${column.header} (${currency})` } : column);
|
|
547
570
|
const futuresHeldNow = result.rows.some((row) => { const ticker = bySymbolTicker.get(row.symbol); return !!ticker && isFuturesTicker(ticker); });
|
|
548
|
-
const bought = periodBoughtText(result);
|
|
571
|
+
const bought = periodBoughtText(result, listing);
|
|
549
572
|
const notices = [
|
|
550
573
|
`${periodBasisText(result, { futuresHeld: futuresHeldNow })}, in ${currency}.`,
|
|
551
574
|
...(result.contributionBase == null ? [] : [`Contribution is P&L over the book's ${result.contributionBasis === "gross" ? "gross exposure" : "value"} at the start, longs plus shorts at their absolute value when it holds a short; cash excluded.`]),
|
|
552
575
|
...(bought ? [bought] : []),
|
|
553
576
|
...(ordered.length > limit ? [`${ordered.length - limit} more position${ordered.length - limit === 1 ? "" : "s"} not shown; the FX line and the total include every position.`] : []),
|
|
554
577
|
];
|
|
555
|
-
const unpricedText = periodUnpricedText(result);
|
|
578
|
+
const unpricedText = periodUnpricedText(result, listing);
|
|
556
579
|
const errors = unpricedText ? [unpricedText] : [];
|
|
557
580
|
return {
|
|
558
581
|
freshness: {
|
|
@@ -563,8 +586,12 @@ async function portfolioPeriodHoldings(
|
|
|
563
586
|
},
|
|
564
587
|
columns: withListingLabels(withBookCurrency(PERIOD_COLUMNS, currency), tickers),
|
|
565
588
|
rows,
|
|
589
|
+
...(byCurrency.length ? {
|
|
590
|
+
textSections: [{ title: "By currency", columns: byCurrencyColumns, rows: byCurrency }],
|
|
591
|
+
exportTables: [{ title: "By currency", columns: byCurrencyColumns, rows: byCurrency, unit: currency }],
|
|
592
|
+
} : {}),
|
|
566
593
|
complete: errors.length === 0,
|
|
567
|
-
...(errors.length ? { errors } : {}),
|
|
594
|
+
...(errors.length ? { errors, incompleteDetail: `the total leaves out ${result.unpriced.map(listing).join(", ")}` } : {}),
|
|
568
595
|
metadata: {
|
|
569
596
|
collection: { kind: "portfolio", id: target.id, name: target.name },
|
|
570
597
|
currency,
|
|
@@ -115,7 +115,7 @@ import { withPurchaseDateCostFx } from "../../../../portfolio/cost-fx";
|
|
|
115
115
|
import { usePortfolioFuturesTerms } from "./futures-terms";
|
|
116
116
|
import { useFuturesFrontNotes } from "./futures-front";
|
|
117
117
|
import { usePurchaseDateCostFx } from "./purchase-date-fx";
|
|
118
|
-
import {
|
|
118
|
+
import { periodPnlLabel, periodPnlNotices, periodSummaryLines, usePanePeriodPnl } from "./period-pnl";
|
|
119
119
|
import type { LoadedPeriodPnl } from "../period-pnl";
|
|
120
120
|
import {
|
|
121
121
|
allocationFigures,
|
|
@@ -373,7 +373,7 @@ export function PortfolioListPane({ focused, width, height }: PaneProps) {
|
|
|
373
373
|
perpetualsVersion: perpetuals.version,
|
|
374
374
|
futuresTerms: futuresTerms.terms,
|
|
375
375
|
futuresTermsVersion: futuresTerms.version,
|
|
376
|
-
...(periodColumns ? { periodPnl: { rows: periodColumns.rows, pending: periodColumns.pending,
|
|
376
|
+
...(periodColumns ? { periodPnl: { rows: periodColumns.rows, pending: periodColumns.pending, lines: periodSummaryLines(periodColumns.result) }, periodPnlVersion: periodColumns.version } : {}),
|
|
377
377
|
}), [
|
|
378
378
|
activeCollectionId,
|
|
379
379
|
exchangeRates,
|
|
@@ -506,12 +506,14 @@ export function PortfolioListPane({ focused, width, height }: PaneProps) {
|
|
|
506
506
|
brokerPortfolio,
|
|
507
507
|
valuationBasis,
|
|
508
508
|
cashInTable: cashRowShown,
|
|
509
|
+
otherCurrencies,
|
|
509
510
|
period: periodColumns ? {
|
|
510
511
|
label: periodPnlLabel(periodColumns),
|
|
511
512
|
total: periodColumns.result?.total ?? null,
|
|
512
513
|
contribution: periodColumns.result?.totalContribution ?? null,
|
|
513
514
|
} : null,
|
|
514
|
-
}), [brokerPortfolio, cashRowShown, config.baseCurrency, convertAccountValue, isPortfolioTab, manualCash, periodColumns, portfolioSummaryTotals,
|
|
515
|
+
}), [brokerPortfolio, cashRowShown, config.baseCurrency, convertAccountValue, isPortfolioTab, manualCash, otherCurrencies, periodColumns, portfolioSummaryTotals,
|
|
516
|
+
summaryAccountState, totalsCurrency, valuationBasis]);
|
|
515
517
|
// The header row sits in the pane's one-cell side padding, like the table.
|
|
516
518
|
const summaryWidth = Math.max(0, width - 2);
|
|
517
519
|
const summaryLayout = useMemo(() => layoutPortfolioSummaryHeader(summarySegments, summaryWidth, {
|
|
@@ -6,9 +6,11 @@ import type { PeriodPnlRow } from "../../../../portfolio/period-pnl";
|
|
|
6
6
|
import type { Quote, TickerFinancials } from "../../../../types/financials";
|
|
7
7
|
import type { TickerRecord } from "../../../../types/ticker";
|
|
8
8
|
import { errorMessage } from "../../../../utils/errors";
|
|
9
|
+
import { displayTickerKey } from "../../../../utils/exchanges";
|
|
9
10
|
import { readPriceWindow, type PriceWindow } from "../../../../utils/price-window";
|
|
10
11
|
import { useAssetData } from "../../../runtime";
|
|
11
|
-
import { loadPeriodPnl, periodBoughtText, periodUnpricedText, type LoadedPeriodPnl } from "../period-pnl";
|
|
12
|
+
import { loadPeriodPnl, periodBoughtText, periodCurrencyParts, periodFxLabel, periodUnpricedText, type LoadedPeriodPnl } from "../period-pnl";
|
|
13
|
+
import type { PeriodSummaryLine } from "../../../../portfolio/column-values";
|
|
12
14
|
|
|
13
15
|
export interface PanePeriodPnl {
|
|
14
16
|
window: PriceWindow | null;
|
|
@@ -40,10 +42,25 @@ export function periodPnlLabel(period: PanePeriodPnl): string {
|
|
|
40
42
|
return `P&L ${dayMonth(start)}–${dayMonth(end)}`;
|
|
41
43
|
}
|
|
42
44
|
|
|
43
|
-
/**
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
/**
|
|
46
|
+
* The lines under the rows of a book in more than one currency, a block per
|
|
47
|
+
* currency, the book's own first: its holdings' price P&L (`HKD local`), its
|
|
48
|
+
* FX line (`FX HKD`) and the two together (`HKD total`). The book's own
|
|
49
|
+
* currency has no FX, so its one line is its total. The rows and the FX lines
|
|
50
|
+
* add up to the header's total. Empty when every holding is in the book's
|
|
51
|
+
* currency, whose total the header gives; only the FX line when every holding
|
|
52
|
+
* is in one other currency, whose total is the header's too.
|
|
53
|
+
*/
|
|
54
|
+
export function periodSummaryLines(result: LoadedPeriodPnl | null): PeriodSummaryLine[] {
|
|
55
|
+
const parts = periodCurrencyParts(result ?? { currencies: [] });
|
|
56
|
+
if (parts.length === 1) return parts.map((part) => ({ id: `period-fx-${part.currency}`, label: periodFxLabel(part.currency), pnl: part.fx, contribution: part.fxContribution }));
|
|
57
|
+
return parts.flatMap((part): PeriodSummaryLine[] => part.own
|
|
58
|
+
? [{ id: `period-total-${part.currency}`, label: `${part.currency} total`, pnl: part.total, contribution: part.contribution }]
|
|
59
|
+
: [
|
|
60
|
+
{ id: `period-local-${part.currency}`, label: `${part.currency} local`, pnl: part.local, contribution: part.localContribution },
|
|
61
|
+
{ id: `period-fx-${part.currency}`, label: periodFxLabel(part.currency), pnl: part.fx, contribution: part.fxContribution },
|
|
62
|
+
{ id: `period-total-${part.currency}`, label: `${part.currency} total`, pnl: part.total, contribution: part.contribution },
|
|
63
|
+
]);
|
|
47
64
|
}
|
|
48
65
|
|
|
49
66
|
/** What the period's P&L leaves out or could not read, and the holdings bought inside it, for the pane's notices. */
|
|
@@ -51,7 +68,8 @@ export function periodPnlNotices(period: PanePeriodPnl | null): string[] {
|
|
|
51
68
|
if (!period) return [];
|
|
52
69
|
if (period.error) return [`P&L period: ${period.error}`];
|
|
53
70
|
if (!period.result) return [];
|
|
54
|
-
|
|
71
|
+
// Each holding by the listing it is (ES3:SGX), not a venue's code it is saved under (ES3:XSES).
|
|
72
|
+
return [periodUnpricedText(period.result, displayTickerKey), periodBoughtText(period.result, displayTickerKey)].filter((notice): notice is string => !!notice);
|
|
55
73
|
}
|
|
56
74
|
|
|
57
75
|
/** The pane's P&L From and To as `portfolio show --from --to` reads them, or why they do not read. */
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Quote } from "../../../types/financials";
|
|
2
2
|
import { loadCostFxRate, type CostFxHistoryClient } from "../../../portfolio/cost-fx";
|
|
3
3
|
import { withFuturesContractSize, isFuturesTicker, type PortfolioFuturesTerms } from "../../../portfolio/futures-positions";
|
|
4
|
-
import { periodCurrency, periodPnl, type PeriodClose, type PeriodPnl, type PeriodPnlHolding, type PeriodPnlRow } from "../../../portfolio/period-pnl";
|
|
4
|
+
import { periodCurrency, periodPnl, type PeriodClose, type PeriodCurrencyPnl, type PeriodPnl, type PeriodPnlHolding, type PeriodPnlRow } from "../../../portfolio/period-pnl";
|
|
5
5
|
import { getPortfolioPositionMetrics } from "../../../portfolio/position-metrics";
|
|
6
6
|
import { barSessionDay, periodDayText } from "../../../market-data/market/period-return";
|
|
7
7
|
import { quoteHeadlineTime } from "../../../market-data/market/status";
|
|
@@ -203,6 +203,21 @@ export function periodBasisText(result: LoadedPeriodPnl, { futuresHeld, now = Da
|
|
|
203
203
|
return `P&L from ${start} to ${end}${futures}, on the holdings held now`;
|
|
204
204
|
}
|
|
205
205
|
|
|
206
|
+
/**
|
|
207
|
+
* The book by currency, as a report of the period lists it: each currency's
|
|
208
|
+
* price P&L, FX and total once the book holds a currency other than its own,
|
|
209
|
+
* the book's own first. Empty for a book in one currency, whose total says it.
|
|
210
|
+
*/
|
|
211
|
+
export function periodCurrencyParts(result: Pick<PeriodPnl, "currencies">): PeriodCurrencyPnl[] {
|
|
212
|
+
const parts = result.currencies ?? [];
|
|
213
|
+
return parts.some((part) => !part.own) ? parts : [];
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/** An FX line's label, as every report of a period writes it: `FX (HKD)`. */
|
|
217
|
+
export function periodFxLabel(currency: string): string {
|
|
218
|
+
return `FX (${currency})`;
|
|
219
|
+
}
|
|
220
|
+
|
|
206
221
|
/** `No P&L for GC=F (contract size unknown), 2382 (no close before 2020-03-18). The total leaves them out.` Null when every holding has one. */
|
|
207
222
|
export function periodUnpricedText(result: LoadedPeriodPnl, label: (symbol: string) => string = (symbol) => symbol): string | null {
|
|
208
223
|
if (!result.unpricedReasons.length) return null;
|
|
@@ -256,8 +256,11 @@ export function buildPortfolioSummarySegments({
|
|
|
256
256
|
valuationBasis,
|
|
257
257
|
period = null,
|
|
258
258
|
cashInTable = false,
|
|
259
|
+
otherCurrencies = false,
|
|
259
260
|
}: {
|
|
260
261
|
totals: PortfolioSummaryTotals;
|
|
262
|
+
/** The book holds a currency other than its own: its amounts name theirs ($1,179,156), a bare one beside HK$ prices being unclear. */
|
|
263
|
+
otherCurrencies?: boolean;
|
|
261
264
|
/** The table shows the cash as its own row (with its target and trade), so the header leaves it out. */
|
|
262
265
|
cashInTable?: boolean;
|
|
263
266
|
/**
|
|
@@ -281,7 +284,7 @@ export function buildPortfolioSummarySegments({
|
|
|
281
284
|
/** Cash entered by hand, in the totals currency, with the total it is weighed against. */
|
|
282
285
|
manualCash?: (PortfolioCashLine & { total: number | null }) | null;
|
|
283
286
|
}): PortfolioSummarySegment[] {
|
|
284
|
-
const money = (value: number | undefined, signed = false) => formatPortfolioAmount(value, currency, { signed, baseCurrency });
|
|
287
|
+
const money = (value: number | undefined, signed = false) => formatPortfolioAmount(value, currency, { signed, baseCurrency, named: otherCurrencies });
|
|
285
288
|
if (!isPortfolioTab) {
|
|
286
289
|
return totals.watchlistCount > 0
|
|
287
290
|
? [createSummarySegment("avg-day", [
|
|
@@ -104,16 +104,18 @@ function bookAmountText(value: number | undefined, currency: string, signed: boo
|
|
|
104
104
|
/**
|
|
105
105
|
* A total in the portfolio's currency (bookAmountText): never rounded to a
|
|
106
106
|
* hundred, as a compact 1.6k for $1,587.80 was. Bare when both it and the
|
|
107
|
-
* app's base currency are USD, as the pane has always shown it
|
|
108
|
-
*
|
|
107
|
+
* app's base currency are USD, as the pane has always shown it, unless the
|
|
108
|
+
* book holds another currency (`named`), beside whose prices a bare total
|
|
109
|
+
* would not say which it is in; otherwise it leads with the currency symbol,
|
|
110
|
+
* as prices do: A$108,612, +$600.12.
|
|
109
111
|
*/
|
|
110
112
|
export function formatPortfolioAmount(
|
|
111
113
|
value: number | undefined,
|
|
112
114
|
currency: string,
|
|
113
|
-
{ signed = false, baseCurrency = "USD" }: { signed?: boolean; baseCurrency?: string } = {},
|
|
115
|
+
{ signed = false, baseCurrency = "USD", named = false }: { signed?: boolean; baseCurrency?: string; named?: boolean } = {},
|
|
114
116
|
): string {
|
|
115
117
|
const text = bookAmountText(value, currency, signed);
|
|
116
|
-
const bare = currency === "USD" && (currencyCode(baseCurrency) ?? "USD") === "USD";
|
|
118
|
+
const bare = !named && currency === "USD" && (currencyCode(baseCurrency) ?? "USD") === "USD";
|
|
117
119
|
if (bare || value == null || !Number.isFinite(value)) return text;
|
|
118
120
|
const sign = text.startsWith("+") || text.startsWith("-") ? text.charAt(0) : "";
|
|
119
121
|
return `${sign}${getCurrencySymbol(currency)}${text.slice(sign.length)}`;
|
|
@@ -74,6 +74,12 @@ const COMPANY_COLUMN_IDS: ReadonlySet<string> = new Set([
|
|
|
74
74
|
* still gives.
|
|
75
75
|
*/
|
|
76
76
|
const NARROW_BOOK_DROP_ORDER = ["forward_pe", "pe", "dividend_yield", "market_cap", "cost_basis", PRICE_SPARKLINE_COLUMN_ID, "as_of"];
|
|
77
|
+
/**
|
|
78
|
+
* What a narrow book over a period gives up next, so the period's P&L and
|
|
79
|
+
* CONTRIB stay on screen: today's columns (the day's P&L, its change, the
|
|
80
|
+
* latest price) and the cost a period's P&L does not read.
|
|
81
|
+
*/
|
|
82
|
+
const NARROW_PERIOD_DROP_ORDER = [...NARROW_BOOK_DROP_ORDER, "day_pnl", "change_pct", "avg_cost", "price"];
|
|
77
83
|
/** Columns of a held position: a list that shows one is a book, whose value outranks its valuation. */
|
|
78
84
|
const POSITION_COLUMN_IDS: ReadonlySet<string> = new Set(["shares", "avg_cost", "cost_basis", "mkt_value", "weight", "day_pnl", "pnl", "pnl_pct"]);
|
|
79
85
|
|
|
@@ -109,13 +115,15 @@ export function fitPortfolioColumns(
|
|
|
109
115
|
rows: readonly { cell: (column: ColumnConfig) => string; settled: boolean }[],
|
|
110
116
|
width: number | undefined,
|
|
111
117
|
hidden: ReadonlySet<string> = new Set(),
|
|
118
|
+
/** The book shows P&L over a period: today's columns go before its P&L and CONTRIB. */
|
|
119
|
+
period = false,
|
|
112
120
|
): ColumnConfig[] {
|
|
113
121
|
const settled = rows.length > 0 && rows.every((row) => row.settled);
|
|
114
122
|
const figured = (column: ColumnConfig) => rows.some((row) => row.settled && !isEmptyCell(row.cell(column)));
|
|
115
123
|
const shown = columns.filter((column) => !COMPANY_COLUMN_IDS.has(column.id)
|
|
116
124
|
|| (settled ? figured(column) : !hidden.has(column.id) || figured(column)));
|
|
117
125
|
if (width == null || !shown.some((column) => POSITION_COLUMN_IDS.has(column.id))) return shown;
|
|
118
|
-
return dropColumnsToFit(shown, width - 1, NARROW_BOOK_DROP_ORDER);
|
|
126
|
+
return dropColumnsToFit(shown, width - 1, period ? NARROW_PERIOD_DROP_ORDER : NARROW_BOOK_DROP_ORDER);
|
|
119
127
|
}
|
|
120
128
|
|
|
121
129
|
/** A cell recomputes only when its row's records or a context input it reads change. */
|
|
@@ -304,11 +312,13 @@ export function PortfolioTickerTable({
|
|
|
304
312
|
tableFinancialsMap.get(ticker.metadata.ticker)?.quote?.yearRangeBasis === "daily-bars")
|
|
305
313
|
? rangeColumn.width + displayWidth(RANGE_FROM_BARS_NOTE) + 1
|
|
306
314
|
: 0, [rangeColumn, sortedTickers, tableFinancialsMap]);
|
|
307
|
-
// The Ticker column grows to its longest symbol, so ETH-USD and BA:LSE show whole beside their market-state dot
|
|
315
|
+
// The Ticker column grows to its longest symbol, so ETH-USD and BA:LSE show whole beside their market-state dot,
|
|
316
|
+
// and to a period's lines under the rows (HKD total).
|
|
317
|
+
const summaryLabels = columnContext.periodPnl?.lines?.map((line) => line.label).join("\n") ?? "";
|
|
308
318
|
const tickerWidth = useMemo(() => Math.min(MAX_TICKER_COLUMN_WIDTH, sortedTickers.reduce(
|
|
309
319
|
(widest, ticker) => Math.max(widest, TICKER_DOT_WIDTH + displayWidth(listedSymbol(ticker, tickerDisplayName(ticker), columnContext.homeMarket))),
|
|
310
|
-
0,
|
|
311
|
-
)), [columnContext.homeMarket, sortedTickers]);
|
|
320
|
+
summaryLabels ? Math.max(...summaryLabels.split("\n").map((label) => TICKER_DOT_WIDTH + displayWidth(label))) : 0,
|
|
321
|
+
)), [columnContext.homeMarket, sortedTickers, summaryLabels]);
|
|
312
322
|
// A book that holds a short weighs its positions against gross exposure, and the header says so.
|
|
313
323
|
const grossWeights = columnContext.portfolioWeightBasis === "gross";
|
|
314
324
|
// Market caps, values and P&L read in the book's currency, which their headers name (MKT VAL (CAD)), as the CLI's do.
|
|
@@ -338,34 +348,34 @@ export function PortfolioTickerTable({
|
|
|
338
348
|
cell: (column: ColumnConfig) => resolveCell(column, ticker, financials).text,
|
|
339
349
|
settled: companyDataSettled(financials, !!answeredSnapshots?.has(ticker.metadata.ticker)),
|
|
340
350
|
};
|
|
341
|
-
}), width, hiddenCompanyRef.current.ids).map((column) => column.id));
|
|
351
|
+
}), width, hiddenCompanyRef.current.ids, period).map((column) => column.id));
|
|
342
352
|
return sizedColumns.filter((column) => !shown.has(column.id)).map((column) => column.id).join(",");
|
|
343
|
-
}, [answeredSnapshots, resolveCell, sizedColumns, sortedTickers, tableFinancialsMap, width]);
|
|
353
|
+
}, [answeredSnapshots, period, resolveCell, sizedColumns, sortedTickers, tableFinancialsMap, width]);
|
|
344
354
|
hiddenCompanyRef.current.ids = new Set(hiddenColumnIds.split(",").filter((id) => COMPANY_COLUMN_IDS.has(id)));
|
|
345
355
|
const displayColumns = useMemo(() => {
|
|
346
356
|
const hidden = new Set(hiddenColumnIds.split(","));
|
|
347
357
|
return hiddenColumnIds ? sizedColumns.filter((column) => !hidden.has(column.id)) : sizedColumns;
|
|
348
358
|
}, [hiddenColumnIds, sizedColumns]);
|
|
349
|
-
// Over a period,
|
|
350
|
-
const
|
|
359
|
+
// Over a period, each currency's part under the rows, so P&L adds up to the header's total as portfolio show --from prints it.
|
|
360
|
+
const periodLines = columnContext.periodPnl?.lines ?? null;
|
|
351
361
|
const summaryRows = useMemo<TickerTableSummaryRow[] | undefined>(() => {
|
|
352
362
|
// A row's label goes in TICKER, or the first column when the pane shows none.
|
|
353
363
|
const labelColumn = displayColumns.some((column) => column.id === "ticker") ? "ticker" : displayColumns[0]?.id ?? "ticker";
|
|
354
364
|
const labelled = (row: TickerTableSummaryRow): TickerTableSummaryRow => labelColumn === "ticker" || !row.cells.ticker ? row
|
|
355
365
|
: { ...row, cells: { ...row.cells, [labelColumn]: row.cells.ticker } };
|
|
356
366
|
const rows = [
|
|
357
|
-
...(
|
|
358
|
-
id:
|
|
367
|
+
...(periodLines ?? []).map((line) => ({
|
|
368
|
+
id: line.id,
|
|
359
369
|
cells: {
|
|
360
|
-
ticker: { text:
|
|
361
|
-
pnl: periodPnlFigure(
|
|
362
|
-
pnl_pct: periodPnlFigure(
|
|
370
|
+
ticker: { text: line.label },
|
|
371
|
+
pnl: periodPnlFigure(line.pnl, "pnl"),
|
|
372
|
+
pnl_pct: periodPnlFigure(line.contribution, "contribution"),
|
|
363
373
|
},
|
|
364
|
-
}
|
|
374
|
+
})),
|
|
365
375
|
...(allocationRows ?? []),
|
|
366
376
|
].map(labelled);
|
|
367
377
|
return rows.length > 0 ? rows : undefined;
|
|
368
|
-
}, [allocationRows, displayColumns,
|
|
378
|
+
}, [allocationRows, displayColumns, periodLines]);
|
|
369
379
|
// The table offers "Sort by…" while it has a sort column. A watchlist starts
|
|
370
380
|
// unsorted and a third header click turns sorting off, so the unsorted state
|
|
371
381
|
// needs its own entry until TickerListTableView takes `sortable`.
|
|
@@ -53,6 +53,8 @@ interface CloudUpgradeOptions {
|
|
|
53
53
|
* never for a press ignored as a repeat.
|
|
54
54
|
*/
|
|
55
55
|
onOpening?: () => void;
|
|
56
|
+
/** What the press is about, said under the sign-up dialog's title when it opens first (`Stock quotes are 15 min delayed`). */
|
|
57
|
+
reason?: string;
|
|
56
58
|
}
|
|
57
59
|
|
|
58
60
|
function recordUpgradeIntent(placement: string | undefined): void {
|
|
@@ -178,7 +180,7 @@ export function openCloudUpgradeUrl(placement: string): boolean {
|
|
|
178
180
|
return true;
|
|
179
181
|
}
|
|
180
182
|
|
|
181
|
-
const CLOUD_UPGRADE_OPTION_KEYS: ReadonlyArray<keyof CloudUpgradeOptions> = ["placement", "interval", "recordIntent", "sheet", "onOpening"];
|
|
183
|
+
const CLOUD_UPGRADE_OPTION_KEYS: ReadonlyArray<keyof CloudUpgradeOptions> = ["placement", "interval", "recordIntent", "sheet", "onOpening", "reason"];
|
|
182
184
|
|
|
183
185
|
/** A press event carries none of these keys, so it never reads as options. */
|
|
184
186
|
function isCloudUpgradeOptions(value: unknown): value is CloudUpgradeOptions {
|
|
@@ -243,7 +245,7 @@ export function useCloudUpgradeAction(placement: string): (options?: unknown) =>
|
|
|
243
245
|
if (resolvePlanAccess(apiClient.getCurrentUser()).hasProAccess) return;
|
|
244
246
|
void openUpgradeRef.current({ ...checkout, recordIntent: false });
|
|
245
247
|
};
|
|
246
|
-
if (requestAuthDialog({ mode: "signup", onSignedIn: continueSignedIn })) {
|
|
248
|
+
if (requestAuthDialog({ mode: "signup", onSignedIn: continueSignedIn, ...(checkout.reason ? { reason: checkout.reason } : {}) })) {
|
|
247
249
|
if (checkout.recordIntent !== false) recordUpgradeIntent(checkout.placement);
|
|
248
250
|
return;
|
|
249
251
|
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The months BLS never published a CPI index for: October 2025, which the
|
|
3
|
+
* 2025 shutdown left uncollected. Every index of the release, all items and
|
|
4
|
+
* core among them, has no level that month, so a change against it has none.
|
|
5
|
+
*/
|
|
6
|
+
const UNPUBLISHED_CPI_MONTHS: ReadonlySet<string> = new Set(["2025-10"]);
|
|
7
|
+
|
|
8
|
+
const MONTH_NAMES = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November",
|
|
9
|
+
"December"];
|
|
10
|
+
|
|
11
|
+
/** "October 2025" from 2025-10 (a `YYYY-MM-DD` date names its month too). */
|
|
12
|
+
const monthName = (period: string) => `${MONTH_NAMES[Number(period.slice(5, 7)) - 1]} ${period.slice(0, 4)}`;
|
|
13
|
+
|
|
14
|
+
/** The month before or after one, `YYYY-MM`. */
|
|
15
|
+
function shiftMonth(period: string, months: number): string {
|
|
16
|
+
const at = new Date(Date.UTC(Number(period.slice(0, 4)), Number(period.slice(5, 7)) - 1 + months, 1));
|
|
17
|
+
return at.toISOString().slice(0, 7);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Why a CPI month has no change over twelve months, when the month a year
|
|
22
|
+
* before it has no index: "BLS published no October 2025 index, so no
|
|
23
|
+
* October 2026 y/y". Null for any other month (`YYYY-MM`).
|
|
24
|
+
*/
|
|
25
|
+
function cpiYearGapReason(period: string): string | null {
|
|
26
|
+
const yearAgo = shiftMonth(period, -12);
|
|
27
|
+
return UNPUBLISHED_CPI_MONTHS.has(yearAgo) ? `BLS published no ${monthName(yearAgo)} index, so no ${monthName(period)} y/y` : null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The line a CPI table with no year-over-year change for `period` closes on:
|
|
32
|
+
* why, and the latest change it has, "BLS published no October 2025 index, so
|
|
33
|
+
* no October 2026 y/y; All items 3.7% in September 2026." `latest` is the
|
|
34
|
+
* latest month that has one and its change in percent, to one decimal as BLS
|
|
35
|
+
* prints it. Null when the month has its change or none is missing for that reason.
|
|
36
|
+
*/
|
|
37
|
+
export function cpiYearGapNote(period: string, label: string, latest: { period: string; value: number } | null): string | null {
|
|
38
|
+
const reason = cpiYearGapReason(period);
|
|
39
|
+
if (!reason) return null;
|
|
40
|
+
return latest ? `${reason}; ${label} ${latest.value.toFixed(1)}% in ${monthName(latest.period)}.` : `${reason}.`;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* For a CPI series whose latest change over twelve months is for `latest`
|
|
45
|
+
* (`YYYY-MM`, or its first day), why the month after it has none, and the
|
|
46
|
+
* latest month's name: ECST's CPI y/y reads September 2026 after October's
|
|
47
|
+
* CPI is out, as October has no y/y. Null when the next month has its change.
|
|
48
|
+
*/
|
|
49
|
+
export function cpiNextYearGap(latest: string): { reason: string; latestMonth: string } | null {
|
|
50
|
+
const month = latest.slice(0, 7);
|
|
51
|
+
const reason = cpiYearGapReason(shiftMonth(month, 1));
|
|
52
|
+
return reason ? { reason, latestMonth: monthName(month) } : null;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** The US CPI changes over twelve months the economic calendar lists, all items and core, under the ids it gives them. */
|
|
56
|
+
const US_CPI_YOY_INDICATORS: ReadonlySet<string> = new Set(["us-inflation-rate-yoy", "us-core-inflation-rate-yoy"]);
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Why an economic calendar row of a US CPI change over twelve months has no
|
|
60
|
+
* actual, when the month a year before the one it covers has no index: the
|
|
61
|
+
* release of 10 November 2026 covers October 2026, and October 2025 was never
|
|
62
|
+
* published. A US CPI release covers the month before it. Null for any other row.
|
|
63
|
+
*/
|
|
64
|
+
export function cpiCalendarYearGapReason(row: { country: string; indicatorId?: string | null; actual: string | null; date: Date }): string | null {
|
|
65
|
+
if (row.country !== "US" || !row.indicatorId || !US_CPI_YOY_INDICATORS.has(row.indicatorId) || row.actual?.trim()) return null;
|
|
66
|
+
return cpiYearGapReason(shiftMonth(row.date.toISOString().slice(0, 7), -1));
|
|
67
|
+
}
|
|
@@ -4,6 +4,10 @@ import { dollarPairLabel, spotFromUsdValue, spotRateKind } from "../../../../mar
|
|
|
4
4
|
import { loadHeadlessFinancials, resolveHeadlessInstrument } from "../../shared/headless-market-data";
|
|
5
5
|
import { quoteObservation } from "../../shared/report-freshness";
|
|
6
6
|
import { heldCurrencyUnit } from "../../../../utils/currency-units";
|
|
7
|
+
import { canonicalExchange, displayTickerKey, isUsListingExchange, parsePublicTickerKey } from "../../../../utils/exchanges";
|
|
8
|
+
import { listingSuffixCandidate } from "../../../../sources/listing-symbols";
|
|
9
|
+
import { companyLinesName } from "../../../../tickers/company-name";
|
|
10
|
+
import { logFailure } from "../../../../utils/log-failure";
|
|
7
11
|
import { adrPairComparison, adrPairFigures, adrPairInputRows, adrPairLegs, ADR_PAIR_TEMPLATE_ID } from "./model";
|
|
8
12
|
|
|
9
13
|
/** Words that ask for this report's figures without being its code: `fn CCL` answers with ADR. */
|
|
@@ -32,6 +36,43 @@ async function readQuote(key: string, ctx: LoadContext, failed: (error: unknown)
|
|
|
32
36
|
return ctx.marketData.getQuote(instrument.symbol, instrument.exchange ?? "").catch(failed);
|
|
33
37
|
}
|
|
34
38
|
|
|
39
|
+
/** The company's other lines a note names before it counts the rest ("and 2 more"). */
|
|
40
|
+
const OTHER_LINES_NAMED = 3;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* The company's lines on venues other than the pair's, as their listings
|
|
44
|
+
* (Hong Kong's 0005:HKEX for HSBC beside its London home line), with the
|
|
45
|
+
* issuer's name. Null when the service cannot say.
|
|
46
|
+
*/
|
|
47
|
+
async function otherLines(receiptKey: string, homeKey: string, ctx: LoadContext): Promise<{ issuer: string; lines: string[] } | null> {
|
|
48
|
+
const { getIssuerListings } = ctx.marketData;
|
|
49
|
+
if (!getIssuerListings) return null;
|
|
50
|
+
const [receipt, home] = await Promise.all([resolveHeadlessInstrument(ctx, receiptKey), resolveHeadlessInstrument(ctx, homeKey)]);
|
|
51
|
+
const homeVenue = canonicalExchange(home.exchange || listingSuffixCandidate(home.symbol)?.exchange || parsePublicTickerKey(homeKey).exchange);
|
|
52
|
+
const issuer = await Promise.resolve().then(() => getIssuerListings.call(ctx.marketData, receipt.symbol, receipt.exchange || undefined))
|
|
53
|
+
.catch(logFailure("plugins.adr-pair", "Reading the company's listings failed", null));
|
|
54
|
+
if (!issuer) return null;
|
|
55
|
+
// The receipt is the company's US line; another US line or the home venue's is no line abroad to add.
|
|
56
|
+
const lines = issuer.listings.filter((line) => {
|
|
57
|
+
const venue = canonicalExchange(line.exchange);
|
|
58
|
+
return venue && venue !== homeVenue && !isUsListingExchange(venue);
|
|
59
|
+
}).map((line) => parsePublicTickerKey(line.symbol).exchange ? displayTickerKey(line.symbol) : `${line.symbol}:${canonicalExchange(line.exchange)}`);
|
|
60
|
+
return { issuer: issuer.name, lines: [...new Set(lines)] };
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* "HSBC Holdings plc also lists 0005:HKEX.", the company named as the
|
|
65
|
+
* not-traded message names it (`companyLinesName`, by its home line's name),
|
|
66
|
+
* the first few lines and how many more. Null when it has no other line.
|
|
67
|
+
*/
|
|
68
|
+
function otherLinesNote(other: { issuer: string; lines: string[] } | null, home: Quote | null): string | null {
|
|
69
|
+
if (!other || other.lines.length === 0) return null;
|
|
70
|
+
const named = other.lines.slice(0, OTHER_LINES_NAMED);
|
|
71
|
+
const more = other.lines.length - named.length;
|
|
72
|
+
const list = more > 0 ? `${named.join(", ")} and ${more} more` : named.join(", ");
|
|
73
|
+
return `${companyLinesName(home?.name, other.issuer)} also lists ${list}.`;
|
|
74
|
+
}
|
|
75
|
+
|
|
35
76
|
export const adrPairHeadless: HeadlessPaneDefinition<"bundle"> = {
|
|
36
77
|
shape: "bundle",
|
|
37
78
|
argument: { kind: "ticker", description: "A depositary receipt (GGAL, TSM) or its home listing (GGAL.BA, 2330.TW)" },
|
|
@@ -63,12 +104,14 @@ export const adrPairHeadless: HeadlessPaneDefinition<"bundle"> = {
|
|
|
63
104
|
errors.push(`${label}: ${error instanceof Error ? error.message : String(error)}`);
|
|
64
105
|
return null;
|
|
65
106
|
};
|
|
66
|
-
const [receipt, home] = await Promise.all([
|
|
107
|
+
const [receipt, home, other] = await Promise.all([
|
|
67
108
|
readQuote(legs.receiptKey, ctx, failed(legs.receiptKey)),
|
|
68
109
|
readQuote(legs.homeKey, ctx, failed(legs.homeKey)),
|
|
110
|
+
otherLines(legs.receiptKey, legs.homeKey, ctx),
|
|
69
111
|
]);
|
|
70
112
|
ctx.signal.throwIfAborted();
|
|
71
113
|
const quotes = { receipt, home };
|
|
114
|
+
const otherLinesText = otherLinesNote(other, home);
|
|
72
115
|
// A minor unit (GBp) is read as its currency, as the comparison reads the price.
|
|
73
116
|
const homeCurrency = quotes.home?.currency ? heldCurrencyUnit(quotes.home.currency).currency : "";
|
|
74
117
|
const spot = homeCurrency ? await readSpot(homeCurrency, ctx).catch(failed(dollarPairLabel(homeCurrency))) : null;
|
|
@@ -105,7 +148,7 @@ export const adrPairHeadless: HeadlessPaneDefinition<"bundle"> = {
|
|
|
105
148
|
rows: rows.map(({ opens: _opens, ...row }) => row),
|
|
106
149
|
},
|
|
107
150
|
],
|
|
108
|
-
...(comparison.timingNote ? { notes: [comparison.timingNote] } : {}),
|
|
151
|
+
...(comparison.timingNote || otherLinesText ? { notes: [comparison.timingNote, otherLinesText].filter((note): note is string => !!note) } : {}),
|
|
109
152
|
...(errors.length > 0 ? { errors } : {}),
|
|
110
153
|
freshness: {
|
|
111
154
|
observations: [quotes.receipt, quotes.home].filter((quote): quote is Quote => !!quote).map((quote) => ({ ...quoteObservation(quote) })),
|
|
@@ -46,7 +46,7 @@ import {
|
|
|
46
46
|
import { barHistoryFreshness, REPORTED_DATA } from "../shared/report-freshness";
|
|
47
47
|
import {
|
|
48
48
|
BAR_INTERVAL_LABELS, barPriceDecimals, cleanBarPrice, cleanFloat32Price, formatBarPrice, historyAllStart, historyAllStartNote, historyBarFlags,
|
|
49
|
-
historyBarValues, historyMissingPeriodsNote, historyPriceDecimals, priceTableIntegrityNotice, quotedPriceDivisor,
|
|
49
|
+
historyBarValues, historyExportUnit, historyMissingPeriodsNote, historyPriceDecimals, historyUnit, priceTableIntegrityNotice, quotedPriceDivisor,
|
|
50
50
|
} from "../../../cli/history-rows";
|
|
51
51
|
import { formatUtcTime } from "../../../utils/utc-time";
|
|
52
52
|
import { closeMoves } from "../../../utils/max-drawdown";
|
|
@@ -84,6 +84,22 @@ function reportWindowText(options: HeadlessPaneOptionValues): string | null {
|
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
+
/**
|
|
88
|
+
* What a listing's bars are priced in, as `history` exports it in `currency_or_unit` (`GBP`, `JPY per USD`, `index
|
|
89
|
+
* points`): by its quote, else by the listing facts research reads, as `history` falls back to them. Null when neither says.
|
|
90
|
+
*/
|
|
91
|
+
async function barPriceUnit(
|
|
92
|
+
ctx: Pick<HeadlessContext, "marketData">,
|
|
93
|
+
key: string,
|
|
94
|
+
listing: string,
|
|
95
|
+
exchange: string | undefined,
|
|
96
|
+
quote: { currency?: string; instrumentType?: string } | null,
|
|
97
|
+
): Promise<string | null> {
|
|
98
|
+
const listed = quote?.currency ? quote
|
|
99
|
+
: await ctx.marketData.getQuoteMetadata?.(listing, exchange ?? "").catch(logFailure("ticker-detail.headless", "Read listing facts for a bar unit failed", null));
|
|
100
|
+
return historyExportUnit(historyUnit(key, listed ?? quote));
|
|
101
|
+
}
|
|
102
|
+
|
|
87
103
|
/** Bars of a window that closed before today: the history asked for, which no later bar makes stale. */
|
|
88
104
|
function pastWindowFreshness(window: PriceWindow, size: HistoryBarSize, observedKey: string): HeadlessPaneFreshness {
|
|
89
105
|
return { status: "not-a-feed", basis: `${historyBarSizeWord(size)} bars, ${priceWindowText(window)}`, observedKey, oldest: null };
|
|
@@ -528,8 +544,13 @@ export const historicalPricesHeadless: HeadlessPaneDefinition<"rows"> = {
|
|
|
528
544
|
const openNotice = priceHistoryOpenNotice(points.filter(pricePointOpenWithheld).length);
|
|
529
545
|
const reportNotices = [...moveLines, notice, openNotice, wickNotice, priceHistoryRescaleNotice(points)].filter((line): line is string => line != null);
|
|
530
546
|
const flagged = rows.some((row) => row.flag);
|
|
547
|
+
// Every exported bar names what it is priced in and its size, as `history --csv` does.
|
|
548
|
+
const unit = await barPriceUnit(ctx, symbol, listing, exchange, quote);
|
|
549
|
+
const barInterval = size === "intraday" ? isIntradayResolution(requested) ? requested : null : size;
|
|
531
550
|
return {
|
|
532
551
|
rows: shown,
|
|
552
|
+
...(unit ? { unit } : {}),
|
|
553
|
+
...(barInterval ? { interval: barInterval } : {}),
|
|
533
554
|
columns: historyColumns(size, marked, false, false, decimals, undefined, flagged),
|
|
534
555
|
textColumns: historyColumns(size, marked, true, volumeMissing > 0, decimals,
|
|
535
556
|
(close) => penceFigure(Number(close.toFixed(Math.min(20, decimals))), quote, decimals), flagged),
|
|
@@ -627,6 +648,8 @@ export const returnsHeadless: HeadlessPaneDefinition<"rows"> = {
|
|
|
627
648
|
const textFigures = figures.map((column) => column.key === "intervalChange" ? { ...column, optional: true, dropPriority: 2 }
|
|
628
649
|
: column.key === "totalChange" ? { ...column, optional: true, dropPriority: 1 } : column);
|
|
629
650
|
const textColumns: HeadlessPaneColumn[] = [timeColumn(true), ...textFigures];
|
|
651
|
+
// Every exported row names what its prices are in and the bars' size, as `history --csv` does.
|
|
652
|
+
const unit = rows.length ? await barPriceUnit(ctx, key, symbol, exchange, null) : null;
|
|
630
653
|
// An interval the range is too long for is served in the nearest longer bar; say so rather than switch silently.
|
|
631
654
|
const notices = [
|
|
632
655
|
...moveLines,
|
|
@@ -641,6 +664,8 @@ export const returnsHeadless: HeadlessPaneDefinition<"rows"> = {
|
|
|
641
664
|
rows,
|
|
642
665
|
columns,
|
|
643
666
|
textColumns,
|
|
667
|
+
...(unit ? { unit } : {}),
|
|
668
|
+
interval: series.resolution,
|
|
644
669
|
unavailableSymbols: rows.length ? [] : [key],
|
|
645
670
|
...(rows.length ? {} : { errors: [`${key}: No bars in this window.`] }),
|
|
646
671
|
freshness: pastWindow ? pastWindowFreshness(window, series.resolution, "time") : {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ReactNode } from "react";
|
|
2
2
|
import { ActionRow, ColumnGrid, ColumnGridPair, RangeTrack, usePaneLinkMenuEntry, type ColumnGridCell, type ColumnGridColumn } from "../../../../components";
|
|
3
3
|
import { t, tf } from "../../../../i18n";
|
|
4
|
-
import { formatMarketPrice, formatMarketPriceWithCurrency, liveQuoteFormatOptions, type MarketFormatOptions } from "../../../../market-data/market/format";
|
|
4
|
+
import { formatMarketPrice, formatMarketPriceRange, formatMarketPriceWithCurrency, liveQuoteFormatOptions, type MarketFormatOptions } from "../../../../market-data/market/format";
|
|
5
5
|
import { colors, hoverBg, priceColor } from "../../../../theme/colors";
|
|
6
6
|
import type { Quote } from "../../../../types/financials";
|
|
7
7
|
import { Box, Text, useUiCapabilities } from "../../../../ui";
|
|
@@ -60,7 +60,7 @@ function compactRangeOptions(low: number, high: number, priceOptions: MarketForm
|
|
|
60
60
|
return priceOptions;
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
/** A range's two ends, in `style
|
|
63
|
+
/** A range's two ends, in `style`, both to one number of decimals. */
|
|
64
64
|
function formatRangeEndpoints(
|
|
65
65
|
low: number,
|
|
66
66
|
high: number,
|
|
@@ -68,9 +68,8 @@ function formatRangeEndpoints(
|
|
|
68
68
|
priceOptions: MarketFormatOptions,
|
|
69
69
|
style: RangeEndpointStyle = "price",
|
|
70
70
|
): [string, string] {
|
|
71
|
-
if (style === "price") return
|
|
72
|
-
|
|
73
|
-
return [formatMarketPrice(low, options), formatMarketPrice(high, options)];
|
|
71
|
+
if (style === "price") return formatMarketPriceRange(low, high, priceOptions, currency);
|
|
72
|
+
return formatMarketPriceRange(low, high, compactRangeOptions(low, high, priceOptions));
|
|
74
73
|
}
|
|
75
74
|
|
|
76
75
|
/** The longest endpoint among ranges drawn together, so stacked tracks start and end in one column. */
|