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
|
@@ -40,6 +40,7 @@ import { formatShortDate } from "../../../../utils/datetime-format";
|
|
|
40
40
|
import { safeExternalUrl } from "../../../../utils/external-url";
|
|
41
41
|
import type { FundBondFacts } from "../../../../api-client/fund-facts";
|
|
42
42
|
import { bondFigures } from "../../../../market-data/bond-funds";
|
|
43
|
+
import { quoteStatsBasisText } from "../../../../market-data/quotes/export-identity";
|
|
43
44
|
import { formatRunwayMonths, type CashRunway, type RunwayEstimate } from "../../../../utils/cash-runway";
|
|
44
45
|
|
|
45
46
|
type CurrencyConverter = (value: number, fromCurrency: string) => number;
|
|
@@ -210,7 +211,9 @@ export function buildOverviewStats({
|
|
|
210
211
|
const volume = reportedQuoteVolume(quote);
|
|
211
212
|
if (volume != null) {
|
|
212
213
|
// Live figures keep their decimals (12.30M, not 12.3M) so the digits hold still.
|
|
213
|
-
|
|
214
|
+
// A coin's volume is the composite's or one exchange's own day, said beside it as its range's is.
|
|
215
|
+
const basis = quoteStatsBasisText(quote, false);
|
|
216
|
+
stats.push({ label: "Volume", value: formatCompact(volume, { fixedDecimals: true }), ...(basis ? { detail: basis } : {}) });
|
|
214
217
|
}
|
|
215
218
|
// Price-derived statistics follow the quote; see live-valuation for when a stored figure is kept.
|
|
216
219
|
// Market cap and EV read in the currency they are reported in, as the revenue and income beside them do, with
|
|
@@ -76,6 +76,7 @@ import { taxEquivalentFields, useOverviewTaxEquivalent } from "./overview/tax-eq
|
|
|
76
76
|
import { distributionBasis, type TaxRates } from "../../../market-data/tax-equivalent";
|
|
77
77
|
import { currentListingName } from "../../../tickers/listing-name";
|
|
78
78
|
import { isYieldIndexSymbol } from "../../../tickers/index-roots";
|
|
79
|
+
import { coinPriceVenueText, quoteStatsBasisText } from "../../../market-data/quotes/export-identity";
|
|
79
80
|
import { hiddenOnLogScale, logScaleHiddenWarning } from "../../../time-series/log-scale";
|
|
80
81
|
import {
|
|
81
82
|
autoOverviewChartScale, resolveOverviewChartScale, toggledOverviewChartScale, type OverviewChartScaleChoice,
|
|
@@ -328,12 +329,17 @@ function ResolvedOverviewTab({
|
|
|
328
329
|
// The pane title already names the ticker, so the line leads with the company and drops a name that only repeats it.
|
|
329
330
|
// The listing's own quote names it first: BA on LSE is BAE Systems, whatever name a search gave the row it was saved from.
|
|
330
331
|
const companyName = currentListingName(ticker, quote) ?? "";
|
|
331
|
-
|
|
332
|
+
// A coin's price says where it is from and when, where a listing names its venue: the crypto venue's own code
|
|
333
|
+
// would tell a reader nothing about whose price it is.
|
|
334
|
+
const coinVenue = instrumentKind === "crypto" ? coinPriceVenueText(quote) : "";
|
|
335
|
+
const shownVenue = coinVenue || listingVenue;
|
|
336
|
+
const venueText = shownVenue ? (companyName ? ` (${shownVenue})` : shownVenue) : "";
|
|
332
337
|
const sessionLabel = quoteSessionLabel(quote);
|
|
333
338
|
const marketStateText = sessionLabel ? t(sessionLabel) : "";
|
|
334
339
|
// Signed out or free, the headline price is the delayed one. The status bar says so for the
|
|
335
340
|
// app; where it is hidden, or in a capture of the pane alone, the mark says so after the session.
|
|
336
|
-
|
|
341
|
+
// A coin's venue already says when its price is held back.
|
|
342
|
+
const delayMinutes = sessionQuote && !coinVenue ? quoteDelayMinutes : null;
|
|
337
343
|
const delayCells = delayMinutes != null ? delayedMarkWidth(delayMinutes, nativePaneChrome === true) + 1 : 0;
|
|
338
344
|
const hasIdentityLine = Boolean(companyName || venueText || marketStateText || delayMinutes != null);
|
|
339
345
|
// The desktop logo is a square from the top of the company name's capitals down to the
|
|
@@ -596,6 +602,8 @@ function ResolvedOverviewTab({
|
|
|
596
602
|
low={quote.low!}
|
|
597
603
|
high={quote.high!}
|
|
598
604
|
label={dayRangeLabel}
|
|
605
|
+
// A coin's range is the composite's or one exchange's own day: said, so a switch between them shows.
|
|
606
|
+
note={quoteStatsBasisText(quote) || undefined}
|
|
599
607
|
shortLabel={delisted ? t("Last") : t("Day")}
|
|
600
608
|
labelWidth={rangeLabelWidth}
|
|
601
609
|
endpointWidth={rangeEndpointCells}
|
|
@@ -82,8 +82,9 @@ export function readWatchlistArgument(
|
|
|
82
82
|
watchlist: { name: string },
|
|
83
83
|
members: readonly string[],
|
|
84
84
|
maximum: number | undefined,
|
|
85
|
+
kind: "watchlist" | "portfolio" = "watchlist",
|
|
85
86
|
): { symbols: string[]; note: string } {
|
|
86
|
-
const read = `Read ${typed.trim()} as
|
|
87
|
+
const read = `Read ${typed.trim()} as ${kind} ${watchlist.name} (${members.length} ${kind === "portfolio" ? "holding" : "symbol"}${members.length === 1 ? "" : "s"})`;
|
|
87
88
|
if (maximum == null || members.length <= maximum) return { symbols: [...members], note: `${read}.` };
|
|
88
89
|
return { symbols: members.slice(0, maximum), note: `${read}; the first ${maximum} are read.` };
|
|
89
90
|
}
|
|
@@ -157,15 +157,25 @@ export interface ColumnContext {
|
|
|
157
157
|
/**
|
|
158
158
|
* P&L over a period instead of since cost (the pane's P&L From): P&L shows
|
|
159
159
|
* each row's P&L between the two closes and P&L% its contribution to the
|
|
160
|
-
* book. Rows are missing while the closes load (`pending`). `
|
|
161
|
-
*
|
|
162
|
-
*
|
|
160
|
+
* book. Rows are missing while the closes load (`pending`). `lines` are
|
|
161
|
+
* the lines under the rows: a book in more than one currency's part in each
|
|
162
|
+
* (its price P&L, its FX line, its total), so the rows and FX lines add up
|
|
163
|
+
* to the header's total.
|
|
163
164
|
*/
|
|
164
|
-
periodPnl?: { rows: ReadonlyMap<string, PeriodPnlRow>; pending: boolean;
|
|
165
|
+
periodPnl?: { rows: ReadonlyMap<string, PeriodPnlRow>; pending: boolean; lines?: readonly PeriodSummaryLine[] | null };
|
|
165
166
|
/** Moves whenever `periodPnl` does. */
|
|
166
167
|
periodPnlVersion?: number;
|
|
167
168
|
}
|
|
168
169
|
|
|
170
|
+
/** A line under a period's rows (`FX HKD`, `HKD total`): its label, P&L and contribution. */
|
|
171
|
+
export interface PeriodSummaryLine {
|
|
172
|
+
id: string;
|
|
173
|
+
label: string;
|
|
174
|
+
/** Null when every holding it covers is left out. */
|
|
175
|
+
pnl: number | null;
|
|
176
|
+
contribution: number | null;
|
|
177
|
+
}
|
|
178
|
+
|
|
169
179
|
/** A row's P&L or contribution over the pane's period: `…` while the closes load, `—` without both. */
|
|
170
180
|
function periodPnlCell(period: NonNullable<ColumnContext["periodPnl"]>, symbol: string, field: "pnl" | "contribution"): { text: string; color?: string } {
|
|
171
181
|
const row = period.rows.get(symbol);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { TickerRecord } from "../types/ticker";
|
|
2
|
-
import { canonicalExchange, canonicalTickerKey, isUsEquityExchange, parsePublicTickerKey } from "../utils/exchanges";
|
|
2
|
+
import { canonicalExchange, canonicalTickerKey, displayTickerKey, isUsEquityExchange, parsePublicTickerKey } from "../utils/exchanges";
|
|
3
3
|
import { classifyInstrumentType, kindFromListingSyntax } from "../tickers/instrument-kind";
|
|
4
4
|
import { listingSuffixVenue } from "../sources/listing-symbols";
|
|
5
5
|
|
|
@@ -56,8 +56,10 @@ export function listHomeMarket(tickers: Iterable<TickerRecord>): string {
|
|
|
56
56
|
* reads as Boeing in a US list; else as `display` writes it.
|
|
57
57
|
*/
|
|
58
58
|
export function listedSymbol(ticker: TickerRecord, display: string, homeMarket: string | undefined): string {
|
|
59
|
+
// A key saved under its venue's code reads by the venue's name, as every other row: ES3:XSES is ES3:SGX.
|
|
60
|
+
if (display.includes(":")) return displayTickerKey(display);
|
|
59
61
|
const market = listingMarket(ticker);
|
|
60
|
-
if (!market || !homeMarket || market === homeMarket
|
|
62
|
+
if (!market || !homeMarket || market === homeMarket) return display;
|
|
61
63
|
const listing = venueListing(ticker.metadata.ticker, ticker.metadata.exchange);
|
|
62
64
|
return canonicalTickerKey(listing.symbol, listing.exchange);
|
|
63
65
|
}
|
|
@@ -58,6 +58,34 @@ export interface PeriodPnlRow {
|
|
|
58
58
|
contribution: number | null;
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
+
/**
|
|
62
|
+
* One currency's part of the book over the period: its holdings' price P&L
|
|
63
|
+
* (local), its move on their start value (FX), the two together, and the
|
|
64
|
+
* total's share of the book. Over the holdings that have both closes, as the
|
|
65
|
+
* book's total is; `unpriced` names the ones it leaves out.
|
|
66
|
+
*/
|
|
67
|
+
export interface PeriodCurrencyPnl {
|
|
68
|
+
/** The major currency its holdings are priced in: GBP for a price in pence. */
|
|
69
|
+
currency: string;
|
|
70
|
+
/** The book's own currency, which has no FX line. */
|
|
71
|
+
own: boolean;
|
|
72
|
+
/**
|
|
73
|
+
* The holdings' price P&L, in the book's currency at the end's rate. Each
|
|
74
|
+
* figure is null when every holding in the currency is left out: there is
|
|
75
|
+
* nothing to add up, which is not a P&L of 0.
|
|
76
|
+
*/
|
|
77
|
+
local: number | null;
|
|
78
|
+
/** The currency's move on the holdings' start value; 0 in the book's currency. */
|
|
79
|
+
fx: number | null;
|
|
80
|
+
total: number | null;
|
|
81
|
+
/** Each over the book's contribution base, in percent. */
|
|
82
|
+
localContribution: number | null;
|
|
83
|
+
fxContribution: number | null;
|
|
84
|
+
contribution: number | null;
|
|
85
|
+
/** Its holdings without a close at one end of the window or a rate: left out of the figures. */
|
|
86
|
+
unpriced: string[];
|
|
87
|
+
}
|
|
88
|
+
|
|
61
89
|
export interface PeriodPnl {
|
|
62
90
|
rows: PeriodPnlRow[];
|
|
63
91
|
/** The FX line: every holding's currency move, together. */
|
|
@@ -75,6 +103,8 @@ export interface PeriodPnl {
|
|
|
75
103
|
contributionBasis: "net" | "gross";
|
|
76
104
|
/** Holdings without a close at one end of the window, or without a rate for their currency. */
|
|
77
105
|
unpriced: string[];
|
|
106
|
+
/** The book by the currency its holdings are priced in: the book's own first, then the others by code. */
|
|
107
|
+
currencies: PeriodCurrencyPnl[];
|
|
78
108
|
}
|
|
79
109
|
|
|
80
110
|
const finite = (value: number | null | undefined): value is number => value != null && Number.isFinite(value);
|
|
@@ -117,5 +147,25 @@ export function periodPnl(holdings: readonly PeriodPnlHolding[], bookCurrency: s
|
|
|
117
147
|
const fx = rows.reduce((sum, row) => sum + (finite(row.fx) ? row.fx : 0), 0);
|
|
118
148
|
const total = rows.reduce((sum, row) => sum + (finite(row.pnl) && finite(row.fx) ? row.pnl + row.fx : 0), 0);
|
|
119
149
|
const share = (value: number) => contributionBase ? (value / contributionBase) * 100 : null;
|
|
120
|
-
|
|
150
|
+
// Each holding counts under the major currency it converts through, priced or not, so a part that leaves one out says so.
|
|
151
|
+
const groups = new Map<string, { currency: string; own: boolean; counted: number; local: number; fx: number; unpriced: string[] }>();
|
|
152
|
+
for (const row of rows) {
|
|
153
|
+
const { currency, own } = periodCurrency(row.currency, bookCurrency);
|
|
154
|
+
const key = own ? heldCurrencyUnit(bookCurrency).currency || bookCurrency : currency;
|
|
155
|
+
const group = groups.get(key) ?? { currency: key, own, counted: 0, local: 0, fx: 0, unpriced: [] };
|
|
156
|
+
groups.set(key, group);
|
|
157
|
+
if (finite(row.pnl) && finite(row.fx)) {
|
|
158
|
+
group.counted += 1;
|
|
159
|
+
group.local += row.pnl;
|
|
160
|
+
group.fx += row.fx;
|
|
161
|
+
} else {
|
|
162
|
+
group.unpriced.push(row.symbol);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
const currencies = [...groups.values()]
|
|
166
|
+
.map(({ currency, own, counted, local, fx, unpriced }): PeriodCurrencyPnl => counted === 0
|
|
167
|
+
? { currency, own, local: null, fx: null, total: null, localContribution: null, fxContribution: null, contribution: null, unpriced }
|
|
168
|
+
: { currency, own, local, fx, total: local + fx, localContribution: share(local), fxContribution: share(fx), contribution: share(local + fx), unpriced })
|
|
169
|
+
.sort((a, b) => Number(b.own) - Number(a.own) || a.currency.localeCompare(b.currency));
|
|
170
|
+
return { rows, fx, fxContribution: share(fx), total, totalContribution: share(total), contributionBase, contributionBasis: shorts ? "gross" : "net", unpriced, currencies };
|
|
121
171
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/** @jsxImportSource react */
|
|
2
2
|
import { useEffect, useRef, type ReactNode } from "react";
|
|
3
|
-
import { DialogHostProvider } from "../../ui/dialog";
|
|
3
|
+
import { DialogHostProvider, type DialogOptions } from "../../ui/dialog";
|
|
4
4
|
import {
|
|
5
5
|
bridgeDialogContent,
|
|
6
6
|
DialogBridgeRegistrationProvider,
|
|
7
7
|
useDialogBridgeSlot,
|
|
8
8
|
} from "../../ui/dialog-bridge";
|
|
9
|
-
import { useDialogStack } from "../../ui/dialog-stack";
|
|
9
|
+
import { closesOnClickOutside, useDialogStack } from "../../ui/dialog-stack";
|
|
10
10
|
import { blendHex } from "../../theme/colors";
|
|
11
11
|
import { useThemeColors } from "../../theme/theme-context";
|
|
12
12
|
import { isEditableTarget, isInsideDialogSurface } from "./host/focus-scope";
|
|
@@ -14,7 +14,7 @@ import { isEditableTarget, isInsideDialogSurface } from "./host/focus-scope";
|
|
|
14
14
|
interface DialogState {
|
|
15
15
|
id: string;
|
|
16
16
|
content: ReactNode | ((context: { dialogId: string; dismiss(): void; resolve(value: unknown): void }) => ReactNode);
|
|
17
|
-
closeOnClickOutside:
|
|
17
|
+
closeOnClickOutside: DialogOptions["closeOnClickOutside"];
|
|
18
18
|
returnFocus: HTMLElement | null;
|
|
19
19
|
}
|
|
20
20
|
|
|
@@ -42,7 +42,7 @@ export function WebDialogHostProvider({ children }: { children: ReactNode }) {
|
|
|
42
42
|
return {
|
|
43
43
|
id,
|
|
44
44
|
content: options.content as DialogState["content"],
|
|
45
|
-
closeOnClickOutside: options.closeOnClickOutside
|
|
45
|
+
closeOnClickOutside: options.closeOnClickOutside,
|
|
46
46
|
returnFocus,
|
|
47
47
|
};
|
|
48
48
|
},
|
|
@@ -99,7 +99,7 @@ export function WebDialogHostProvider({ children }: { children: ReactNode }) {
|
|
|
99
99
|
data-topmost={isTopmost ? "true" : "false"}
|
|
100
100
|
onMouseDown={(event) => {
|
|
101
101
|
if (event.target !== event.currentTarget) return;
|
|
102
|
-
if (isTopmost && dialogState.closeOnClickOutside) {
|
|
102
|
+
if (isTopmost && closesOnClickOutside(dialogState.closeOnClickOutside)) {
|
|
103
103
|
close(dialogState.id, undefined);
|
|
104
104
|
return;
|
|
105
105
|
}
|
|
@@ -42,7 +42,7 @@ export function createCapabilityInvoker(options: {
|
|
|
42
42
|
? withDeadline(
|
|
43
43
|
request,
|
|
44
44
|
options.timeoutMs,
|
|
45
|
-
`Asset data request timed out after ${options.timeoutMs}ms
|
|
45
|
+
`Asset data request timed out after ${options.timeoutMs}ms`,
|
|
46
46
|
)
|
|
47
47
|
: request;
|
|
48
48
|
if (!invokeOptions.signal) {
|
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
useDialogBridgeSlot,
|
|
18
18
|
type DialogContentBridge,
|
|
19
19
|
} from "../../ui/dialog-bridge";
|
|
20
|
-
import { useDialogStack, type DialogKind } from "../../ui/dialog-stack";
|
|
20
|
+
import { closesOnClickOutside, useDialogStack, type DialogKind } from "../../ui/dialog-stack";
|
|
21
21
|
|
|
22
22
|
interface DialogRecord {
|
|
23
23
|
id: string;
|
|
@@ -26,7 +26,7 @@ interface DialogRecord {
|
|
|
26
26
|
size?: DialogOptions["size"];
|
|
27
27
|
style?: DialogStyle;
|
|
28
28
|
closeOnEscape?: boolean;
|
|
29
|
-
closeOnClickOutside?:
|
|
29
|
+
closeOnClickOutside?: DialogOptions["closeOnClickOutside"];
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
function renderDialogContent(content: unknown, context: AlertContext | PromptContext<unknown>): ReactNode {
|
|
@@ -82,7 +82,6 @@ function DialogLayer({
|
|
|
82
82
|
? Math.max(1, Math.min(style.maxHeight, viewportHeight))
|
|
83
83
|
: viewportHeight;
|
|
84
84
|
const closeOnEscape = dialog.closeOnEscape ?? true;
|
|
85
|
-
const closeOnClickOutside = dialog.closeOnClickOutside ?? false;
|
|
86
85
|
const zIndex = 9_998 + index * 2;
|
|
87
86
|
|
|
88
87
|
useKeyboard((event) => {
|
|
@@ -124,7 +123,7 @@ function DialogLayer({
|
|
|
124
123
|
alignItems="center"
|
|
125
124
|
justifyContent="center"
|
|
126
125
|
onMouseDown={() => {
|
|
127
|
-
if (isTopmost && closeOnClickOutside) close(dialog.id);
|
|
126
|
+
if (isTopmost && closesOnClickOutside(dialog.closeOnClickOutside)) close(dialog.id);
|
|
128
127
|
}}
|
|
129
128
|
>
|
|
130
129
|
<box
|
|
@@ -124,6 +124,8 @@ export function mapQuote(
|
|
|
124
124
|
delisting: parseListingDelisting(quote.delisting),
|
|
125
125
|
intradayBar: readIntradayBar(quote.intradayBar),
|
|
126
126
|
staleReason: readStaleReason(quote.staleReason),
|
|
127
|
+
// An exchange's name, shown as the quote's source: nothing longer or stranger is.
|
|
128
|
+
priceVenue: typeof quote.priceVenue === "string" && /^[A-Za-z][A-Za-z0-9 .-]{0,23}$/.test(quote.priceVenue) ? quote.priceVenue : undefined,
|
|
127
129
|
priceBasis,
|
|
128
130
|
priceObservation,
|
|
129
131
|
currency: currency || quote.currency,
|
|
@@ -143,6 +145,9 @@ export function mapQuote(
|
|
|
143
145
|
low52w: normalizePriceValueByDivisor(quote.low52w, divisor),
|
|
144
146
|
// The service read the 52-week range from its stored daily bars, its source's being unusable.
|
|
145
147
|
yearRangeBasis: quote.yearRangeBasis === "daily-bars" ? "daily-bars" : undefined,
|
|
148
|
+
// What a coin's day range and volume measure: the composite's, or one exchange's own day.
|
|
149
|
+
statsBasis: quote.statsBasis === "composite" || quote.statsBasis === "exchange" ? quote.statsBasis : undefined,
|
|
150
|
+
rangeWidened: quote.rangeWidened === true ? true : undefined,
|
|
146
151
|
// No live quote: the close of the latest daily bar of this session.
|
|
147
152
|
dailyClose: readDailyClose(quote.dailyClose),
|
|
148
153
|
bid: normalizePriceValueByDivisor(quote.bid, divisor),
|
|
@@ -779,8 +779,11 @@ export class ProviderRouterHistoryRoutes {
|
|
|
779
779
|
if (behind) throw new Error(`Latest history for ${target.symbol} is behind`);
|
|
780
780
|
// A reason the service gave ("ADX listings have daily bars only.") says why; one that has no
|
|
781
781
|
// listing for the symbol says it is not a ticker; otherwise no source answered. A coin trades
|
|
782
|
-
// around the clock and its sources are there: they could not answer just now.
|
|
783
|
-
|
|
782
|
+
// around the clock and its sources are there: they could not answer just now. So could a
|
|
783
|
+
// source that failed (a timeout, a 5xx) rather than had nothing: that is no listing without
|
|
784
|
+
// history, and never reads as one ("No history provider available").
|
|
785
|
+
const failed = coin || attempts.misses.failure !== undefined;
|
|
786
|
+
throw noProviderError(failed ? `No source could load history for ${request.target.symbol} just now` : request.missingProviderError,
|
|
784
787
|
attempts.misses, request.target.symbol);
|
|
785
788
|
}
|
|
786
789
|
// A window of dates no source could answer, because one failed rather than had nothing, is that failure:
|
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
import type { PersistedResourceValue } from "../types/persistence";
|
|
2
2
|
import type { PluginPersistence } from "../types/plugin";
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* A mid-morning UTC moment for a test to hold the clock at (`setSystemTime`),
|
|
6
|
+
* when it reads the time of day off a copy `seedResource` saved: that copy is
|
|
7
|
+
* dated a minute before the clock, so in the first minute of a day it is from
|
|
8
|
+
* the day before and reads with its date ("saved copy from 13 Nov 23:59")
|
|
9
|
+
* instead of "saved copy from 23:59". Its minutes and seconds are ones no time
|
|
10
|
+
* zone's midnight falls on, so the minute before it is never another day's
|
|
11
|
+
* wherever the test runs.
|
|
12
|
+
*/
|
|
13
|
+
export const SAVED_COPY_TEST_NOW = Date.parse("2026-11-13T10:17:42Z");
|
|
14
|
+
|
|
4
15
|
export class MemoryPluginPersistence implements PluginPersistence {
|
|
5
16
|
private readonly state = new Map<string, { schemaVersion: number; value: unknown }>();
|
|
6
17
|
private readonly resources = new Map<string, PersistedResourceValue<unknown>>();
|
|
@@ -83,6 +94,7 @@ export class MemoryPluginPersistence implements PluginPersistence {
|
|
|
83
94
|
provenance?: unknown;
|
|
84
95
|
} = {},
|
|
85
96
|
): void {
|
|
97
|
+
// A minute back: see SAVED_COPY_TEST_NOW for what a test that reads this copy's time of day holds the clock for.
|
|
86
98
|
const now = Date.now();
|
|
87
99
|
this.resources.set(this.resourceKey(kind, key, options.sourceKey), {
|
|
88
100
|
value,
|
|
@@ -5,7 +5,7 @@ import type { InstrumentSearchResult } from "../types/instrument";
|
|
|
5
5
|
import { canonicalExchange, isUsEquityExchange, isUsListingExchange, parsePublicTickerKey } from "../utils/exchanges";
|
|
6
6
|
import { companyLines, companyNameExtraWords, companyNameMatch, foldNameLetters, namedByService, runTogether, sameCompany, shortCompanyName } from "./company-name";
|
|
7
7
|
import { LISTING_SEARCH_LIMIT } from "./search";
|
|
8
|
-
import { lineDistance, primaryCompanyLine } from "./search/home-listing";
|
|
8
|
+
import { isFundReceipt, lineDistance, primaryCompanyLine } from "./search/home-listing";
|
|
9
9
|
import { classifyInstrumentKind, isCryptoInstrumentType } from "./search/ranking";
|
|
10
10
|
import { isProviderBusy, type ProviderBusyError } from "../sources/provider-errors";
|
|
11
11
|
import { readTerminalListingCode, type TerminalListing, type TerminalListingCode } from "./terminal-codes";
|
|
@@ -178,8 +178,9 @@ function rankCompanyLines(name: string, results: readonly InstrumentSearchResult
|
|
|
178
178
|
|| parsePublicTickerKey(result.symbol).exchange) return [];
|
|
179
179
|
// A word alone names a company by these lines only; the company's other lines are still its lines.
|
|
180
180
|
const namesCompany = !(options.oneWord && (match.abbreviated > 0 || isCryptoInstrumentType(type) || !(order === 0 || named || match.extra === 0)));
|
|
181
|
-
// A receipt is a company's shares too, however search types it ("Depositary Receipt" or "American Depositary Receipt")
|
|
182
|
-
|
|
181
|
+
// A receipt is a company's shares too, however search types it ("Depositary Receipt" or "American Depositary Receipt"),
|
|
182
|
+
// unless it is one on a fund search lists under its name: the Tracker Fund's Thai receipt is the fund's line.
|
|
183
|
+
const stock = RECEIPT.test(type) ? (isFundReceipt(result, results) ? 1 : 0) : classifyInstrumentKind(type) === "equity" ? 0 : 1;
|
|
183
184
|
const home = result.homeListing === true;
|
|
184
185
|
const line = home ? 0 : 1 + lineDistance(type, exchange, result.symbol);
|
|
185
186
|
return [{
|
|
@@ -31,7 +31,10 @@ const NAME_NOISE = new Set([
|
|
|
31
31
|
"anonim", "sirketi", "ortakligi",
|
|
32
32
|
]);
|
|
33
33
|
// Turkish legal forms short enough to open another company's name (AO Smith, AO World): a legal form only as its last word.
|
|
34
|
-
|
|
34
|
+
// So is a partnership limited by shares (Hermès International SCA), whatever a venue spells out.
|
|
35
|
+
const LAST_WORD_NOISE = new Set(["ao", "tas", "sca"]);
|
|
36
|
+
// A legal form a venue spells out in words that are no legal form alone: Hermès International Société en commandite par actions.
|
|
37
|
+
const SPELLED_SCA = /\bsociete en commandite par actions\b/g;
|
|
35
38
|
// Words a venue adds to the share it lists ("Microsoft Corporation Common Stock"), never part of whose it is.
|
|
36
39
|
const SHARE_NOISE = new Set(["common", "ordinary", "stock", "shares", "share"]);
|
|
37
40
|
// A venue's short form of a share class word, read as the word: "Volkswagen AG Pref. Share" in Zurich is its "Preferred Stock".
|
|
@@ -43,6 +46,7 @@ function companyKey(name: string): string {
|
|
|
43
46
|
.replace(/\([^)]*\)/g, " ")
|
|
44
47
|
.replace(/\b(?:(?:american|global) )?depositary (?:shares?|receipts?)\b/g, " ")
|
|
45
48
|
.replace(/\./g, "")
|
|
49
|
+
.replace(SPELLED_SCA, "sca")
|
|
46
50
|
.split(/[^\p{L}\p{N}]+/u)
|
|
47
51
|
.map((word) => SHARE_WORD_FORMS[word] ?? word)
|
|
48
52
|
.filter((word) => word && !NAME_NOISE.has(word));
|
|
@@ -333,6 +337,20 @@ function nameWord(word: string, opening: boolean, domain: boolean): string {
|
|
|
333
337
|
return `${word.charAt(0)}${word.slice(1).toLowerCase()}`;
|
|
334
338
|
}
|
|
335
339
|
|
|
340
|
+
/**
|
|
341
|
+
* The name a company is introduced by beside its lines on other venues
|
|
342
|
+
* ("Prudential plc trades on HKEX as 2378:HKEX", "HSBC Holdings plc also
|
|
343
|
+
* lists 0005:HKEX"): the name its home line is listed under, which tells
|
|
344
|
+
* Prudential plc from Prudential Financial, else its issuer's, cased. Without
|
|
345
|
+
* the comma or the full stop a listing's name can carry beside its legal form:
|
|
346
|
+
* "HSBC Holdings, plc." is HSBC Holdings plc.
|
|
347
|
+
*/
|
|
348
|
+
export function companyLinesName(listedName: string | null | undefined, issuerName: string): string {
|
|
349
|
+
return (listedName?.trim() || companyNameCase(issuerName))
|
|
350
|
+
.replace(/,\s*(?=(?:plc|inc|ltd|limited|corp|sa|ag|nv|se)\b)/i, " ")
|
|
351
|
+
.replace(/\.$/, "");
|
|
352
|
+
}
|
|
353
|
+
|
|
336
354
|
/**
|
|
337
355
|
* A company name a source writes in capitals (an ETF's holdings file: "APPLE INC", "MERCK & CO INC") as it is
|
|
338
356
|
* normally written: "Apple Inc", "Merck & Co Inc". Legal forms and short words take their usual case, initials
|
|
@@ -95,6 +95,33 @@ export function uncoveredInstrumentMessage(
|
|
|
95
95
|
return `${name} covers ${coveredNoun(covered)} only, and ${instrument.symbol} is ${instrumentKindNoun(instrument)}.`;
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
+
/** "futures contracts", "ETFs", "indices": what several instruments of one kind are. */
|
|
99
|
+
function pluralNoun(noun: string): string {
|
|
100
|
+
const bare = noun.replace(/^an? /, "");
|
|
101
|
+
if (bare === "index") return "indices";
|
|
102
|
+
return bare.endsWith("y") ? `${bare.slice(0, -1)}ies` : `${bare}s`;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* What a list function says once of every entry outside what it covers, in
|
|
107
|
+
* place of a line each: "RIPL covers companies only, and leaves out ES=F, NQ1
|
|
108
|
+
* (futures contracts) and ES3:SGX (an ETF)."
|
|
109
|
+
*/
|
|
110
|
+
export function uncoveredInstrumentsMessage(
|
|
111
|
+
name: string,
|
|
112
|
+
covered: readonly TickerInstrumentKind[],
|
|
113
|
+
instruments: readonly InstrumentOfKind[],
|
|
114
|
+
): string {
|
|
115
|
+
const groups = new Map<string, string[]>();
|
|
116
|
+
for (const instrument of instruments) {
|
|
117
|
+
const noun = instrumentKindNoun(instrument);
|
|
118
|
+
groups.set(noun, [...groups.get(noun) ?? [], instrument.symbol]);
|
|
119
|
+
}
|
|
120
|
+
const parts = [...groups].map(([noun, symbols]) => `${symbols.join(", ")} (${symbols.length > 1 ? pluralNoun(noun) : noun})`);
|
|
121
|
+
const list = parts.length > 1 ? `${parts.slice(0, -1).join(", ")} and ${parts.at(-1)}` : parts[0] ?? "";
|
|
122
|
+
return `${name} covers ${coveredNoun(covered)} only, and leaves out ${list}.`;
|
|
123
|
+
}
|
|
124
|
+
|
|
98
125
|
/**
|
|
99
126
|
* What a ticker is without asking for its quote: an index, pair, future or
|
|
100
127
|
* coin by its symbol (^VIX, EURUSD=X), a fund by the type it was saved with
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { canonicalExchange, isUsListingExchange } from "../../utils/exchanges";
|
|
2
2
|
import { companyLines, companyNameExtraWords, companyNameMatch, namedByService, type CompanyLineFacts } from "../company-name";
|
|
3
|
-
import { answersOnlyByKeyword, getIssuerGroupKey, isPlaceholderLine, isQualifiedTickerQuery, normalizeTickerSymbol, readsAsUsTicker } from "./ranking";
|
|
3
|
+
import { answersOnlyByKeyword, classifyInstrumentKind, getIssuerGroupKey, isPlaceholderLine, isQualifiedTickerQuery, normalizeTickerSymbol, readsAsUsTicker } from "./ranking";
|
|
4
4
|
import type { TickerSearchCandidate } from "./types";
|
|
5
5
|
|
|
6
6
|
/** Venues that only quote shares listed elsewhere: the OTC tiers, Frankfurt's open market and Germany's regional exchanges. */
|
|
@@ -23,16 +23,53 @@ export function listingDistance(candidate: TickerSearchCandidate): 0 | 1 | 2 {
|
|
|
23
23
|
return lineDistance(candidate.instrumentType ?? "", candidateExchange(candidate), candidate.symbol);
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
/** B3's own codes: four letters and the class's number (PETR3, PETR4, BOVA11). */
|
|
27
|
+
const B3_CODE = /^[A-Z]{4}\d{1,2}$/i;
|
|
28
|
+
/** B3's odd-lot (fractional) line of a code: the code and F (PETR3F), which quotes the same shares in lots under 100. */
|
|
29
|
+
const B3_ODD_LOT = /^[A-Z]{4}\d{1,2}F$/i;
|
|
30
|
+
|
|
26
31
|
/** `listingDistance` of a line by its type, its canonical venue and its symbol. */
|
|
27
32
|
export function lineDistance(type: string, exchange: string, symbol: string): 0 | 1 | 2 {
|
|
28
33
|
if (RECEIPT_TYPE.test(type)) return 2;
|
|
29
34
|
// An index's code is its own (XU100 for the BIST 100), never a secondary line of shares.
|
|
30
35
|
if (/^\s*index\s*$/i.test(type)) return 0;
|
|
36
|
+
// B3's own codes mix letters and digits (PETR3); its odd-lot line quotes the same shares (PETR3F).
|
|
37
|
+
if (exchange === "B3" && (B3_CODE.test(symbol) || B3_ODD_LOT.test(symbol))) return B3_ODD_LOT.test(symbol) ? 1 : 0;
|
|
31
38
|
// A code mixing digits and letters is a secondary line (Milan's 4MSFT, London's 0R1I), except on SGX, whose
|
|
32
39
|
// own codes mix them (D05, 5E2).
|
|
33
40
|
return SECONDARY_VENUES.has(exchange) || exchange !== "SGX" && /\d/.test(symbol) && /[A-Za-z]/.test(symbol) ? 1 : 0;
|
|
34
41
|
}
|
|
35
42
|
|
|
43
|
+
/** A receipt's name without the words that say it is one: "Tracker Fund of Hong Kong DR" is the fund's name. */
|
|
44
|
+
const receiptFreeName = (name: string | null | undefined) => (name ?? "").toLowerCase()
|
|
45
|
+
.replace(/\b(?:adrs?|adss?|gdrs?|cdrs?|drs?|cedears?|(?:american |global )?depositary (?:receipts?|shares?))\b/g, " ")
|
|
46
|
+
.replace(/[^\p{L}\p{N}]+/gu, " ").trim();
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Whether a depositary receipt is one on a fund: search lists a fund under the
|
|
50
|
+
* receipt's name. The Thai receipt on the Tracker Fund of Hong Kong (HK01 on
|
|
51
|
+
* SET) is the fund's line, not a company's shares, so it ranks and is listed
|
|
52
|
+
* as the fund is, never as a company's primary listing over the fund itself
|
|
53
|
+
* (2800 on HKEX).
|
|
54
|
+
*/
|
|
55
|
+
export function isFundReceipt(
|
|
56
|
+
line: { type?: string | null; name?: string | null },
|
|
57
|
+
lines: readonly { type?: string | null; name?: string | null }[],
|
|
58
|
+
): boolean {
|
|
59
|
+
if (!RECEIPT_TYPE.test(line.type ?? "")) return false;
|
|
60
|
+
const name = receiptFreeName(line.name);
|
|
61
|
+
return !!name && lines.some((other) => other !== line && !RECEIPT_TYPE.test(other.type ?? "")
|
|
62
|
+
&& classifyInstrumentKind(other.type ?? "") === "fund" && receiptFreeName(other.name) === name);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Search's rows with each receipt on a fund (`isFundReceipt`) classed as the fund is. */
|
|
66
|
+
export function withFundReceiptsAsFunds<T extends TickerSearchCandidate>(items: T[]): T[] {
|
|
67
|
+
const lines = items.map((item) => item.result ?? {});
|
|
68
|
+
return items.map((item, index) => item.kind === "search" && item.instrumentClass !== "fund" && isFundReceipt(lines[index]!, lines)
|
|
69
|
+
? { ...item, instrumentClass: "fund" as const }
|
|
70
|
+
: item);
|
|
71
|
+
}
|
|
72
|
+
|
|
36
73
|
/** How the primary-listing choice weighs one of a company's lines. */
|
|
37
74
|
export interface WeighedCompanyLine {
|
|
38
75
|
/** `listingDistance`: 0 its own line, 1 a line quoting shares listed elsewhere, 2 a receipt. */
|
|
@@ -41,7 +41,7 @@ import { endsInLegalForm, readNearMissListing, readVenueFirstListing, readTermin
|
|
|
41
41
|
import { isProviderBusy, ProviderBusyError, SEARCH_BUSY_MESSAGE } from "../../sources/provider-errors";
|
|
42
42
|
import { settleWithin } from "../../utils/async-deadline";
|
|
43
43
|
import { companyNameExtraWords } from "../company-name";
|
|
44
|
-
import { withHomeListingLead, withNamedCompanyAfterUsLead } from "./home-listing";
|
|
44
|
+
import { withFundReceiptsAsFunds, withHomeListingLead, withNamedCompanyAfterUsLead } from "./home-listing";
|
|
45
45
|
import { answeredInFull, rememberSearchAnswer, withKnownListings } from "./listing-index";
|
|
46
46
|
import { savedAbroadForBareSymbol, savedUsListingOf } from "./bare-symbol";
|
|
47
47
|
import { delistingLabel, parseListingWithdrawal, withdrawalLabel } from "../../market-data/quotes/delisting";
|
|
@@ -361,7 +361,8 @@ export function buildTickerSearchCandidates({
|
|
|
361
361
|
createLocalTickerSearchCandidates(tickers.values(), providerHints.results, candidateOptions),
|
|
362
362
|
query,
|
|
363
363
|
);
|
|
364
|
-
|
|
364
|
+
// A receipt on a fund is the fund's line, never a company's primary listing over it (HK01 on SET for the Tracker Fund).
|
|
365
|
+
const providerItems = withFundReceiptsAsFunds(createProviderTickerSearchCandidates(filteredProviderResults, tickers, candidateOptions));
|
|
365
366
|
const ranked = withNamedCompanyAfterUsLead(
|
|
366
367
|
withHomeListingLead(withSuccessorFirst(rankTickerSearchItems([...localItems, ...providerItems], query), query), query),
|
|
367
368
|
query,
|
|
@@ -8,6 +8,7 @@ import { typedCoinPairListing } from "../../utils/crypto-pair";
|
|
|
8
8
|
import { canonicalExchange, exchangeCodeVenues, isUsListingExchange, parsePublicTickerKey, typedExchangeCode } from "../../utils/exchanges";
|
|
9
9
|
import { assetClassKeeps, assetClassMarketSymbol, instrumentClassCode, parseAssetClassQuery } from "./asset-classes";
|
|
10
10
|
import { futuresContractByCode } from "../../market-data/futures-board";
|
|
11
|
+
import { sameCompany } from "../company-name";
|
|
11
12
|
|
|
12
13
|
const FUND_TYPES = new Set(["ETF", "ETN", "ETP", "FUND", "MUTUALFUND", "CEF", "CLOSEDEND"]);
|
|
13
14
|
const DERIVATIVE_TYPES = new Set(["OPT", "OPTION", "OPTIONS", "FUT", "FUTURE", "FUTURES", "PERP", "PERPETUAL", "WARRANT", "WARRANTS", "RIGHT", "RIGHTS"]);
|
|
@@ -700,13 +701,31 @@ export function answersOnlyByKeyword(
|
|
|
700
701
|
* wants (an exchange or "ETF" beside the word).
|
|
701
702
|
*/
|
|
702
703
|
export function themeQueryWord(
|
|
703
|
-
items: ReadonlyArray<
|
|
704
|
+
items: ReadonlyArray<ThemeAnswerRow>,
|
|
704
705
|
query: string,
|
|
705
706
|
): string | null {
|
|
706
707
|
const intent = analyzeSearchQuery(query);
|
|
707
708
|
const word = intent.normalizedQuery;
|
|
708
709
|
if (!word || word.includes(" ") || intent.exchangeHints.length > 0 || intent.assetPreference != null) return null;
|
|
709
|
-
|
|
710
|
+
const tagged = (item: ThemeAnswerRow) => item.searchKeywords?.some((keyword) => normalizeSearchText(keyword) === word) ?? false;
|
|
711
|
+
if (!items.some(tagged)) return null;
|
|
712
|
+
return namesOneCompany(items.filter((item) => !tagged(item))) ? null : word;
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
/** A row of an answer as `themeQueryWord` reads it: a search row (`name`) or a ranked row (`detail`, its name first). */
|
|
716
|
+
type ThemeAnswerRow = Pick<TickerSearchRankableItem, "searchKeywords" | "homeListing"> & { name?: string; detail?: string };
|
|
717
|
+
|
|
718
|
+
/**
|
|
719
|
+
* Whether most of the rows the service sent for a word by name are one
|
|
720
|
+
* company's lines, its home line among them: the word is that company's
|
|
721
|
+
* name, whatever rows it also tags ("Hermes" is Hermès International,
|
|
722
|
+
* though the service sends Federated Hermes's funds and holdings with the
|
|
723
|
+
* word). A sector word's rows are many companies' ("steel", "gaming").
|
|
724
|
+
*/
|
|
725
|
+
function namesOneCompany(rows: readonly ThemeAnswerRow[]): boolean {
|
|
726
|
+
const name = (row: ThemeAnswerRow) => row.name ?? row.detail?.split(" | ")[0] ?? "";
|
|
727
|
+
return rows.some((home) => home.homeListing === true
|
|
728
|
+
&& rows.filter((row) => sameCompany(name(row), name(home))).length * 2 > rows.length);
|
|
710
729
|
}
|
|
711
730
|
|
|
712
731
|
/** How many sector funds lead a sector word's list: the rest of the list is the companies named for it. */
|
|
@@ -164,6 +164,10 @@ export function baseSecuritySeries(
|
|
|
164
164
|
const volumeUnit = unknownBondBasis ? undefined
|
|
165
165
|
: assetKind === "equity" || instrumentKind === "equity" || instrumentKind === "fund" ? "shares" as const
|
|
166
166
|
: assetKind === "contract" || instrumentKind === "future" || instrumentKind === "option" ? "contracts" as const
|
|
167
|
+
// A coin's volume from Gloom Cloud, whose bars say what it counts (`aggregate`, `1 spot venue`), is the value
|
|
168
|
+
// traded in its quote currency, never a count of coins; another source's states no unit.
|
|
169
|
+
: (assetKind === "crypto" || instrumentKind === "crypto") && currency
|
|
170
|
+
&& (financials.priceHistory ?? []).some((point) => point.volumeBasis != null) ? currency
|
|
167
171
|
: undefined;
|
|
168
172
|
// An index has no volume of its own: sources sum its members' volume.
|
|
169
173
|
const volumeBasis = !volumeUnit && !unknownBondBasis && instrumentKind === "index" ? "index-members" as const : undefined;
|
package/src/time-series/types.ts
CHANGED
|
@@ -249,8 +249,11 @@ export interface ResolvedSeries {
|
|
|
249
249
|
* never on decimal steps that read 104-25.60. Unset for decimal prices.
|
|
250
250
|
*/
|
|
251
251
|
tickGrid?: number;
|
|
252
|
-
/**
|
|
253
|
-
|
|
252
|
+
/**
|
|
253
|
+
* Volume basis established by the source instrument; omitted when unspecified. A coin's is the traded value in the
|
|
254
|
+
* currency its price is in (`USD`), as Gloom Cloud serves a coin's volume.
|
|
255
|
+
*/
|
|
256
|
+
volumeUnit?: "shares" | "contracts" | (string & {});
|
|
254
257
|
/**
|
|
255
258
|
* Set where the volume is the combined volume of an index's members. It has
|
|
256
259
|
* no unit of its own to state and nothing unknown to warn about; the volume
|
package/src/types/financials.ts
CHANGED
|
@@ -211,6 +211,14 @@ export interface Quote extends DepositaryReceiptFacts {
|
|
|
211
211
|
* repeated the day's range, or reached zero): said beside it.
|
|
212
212
|
*/
|
|
213
213
|
yearRangeBasis?: "daily-bars";
|
|
214
|
+
/**
|
|
215
|
+
* What a coin's day range and volume measure, as the service says: the
|
|
216
|
+
* composite's across exchanges, or one exchange's own day (a real-time
|
|
217
|
+
* crypto feed's). Said beside each, so a source switch is never silent.
|
|
218
|
+
*/
|
|
219
|
+
statsBasis?: "composite" | "exchange";
|
|
220
|
+
/** The composite's day range was widened to take in `priceVenue`'s price, which fell outside it. */
|
|
221
|
+
rangeWidened?: boolean;
|
|
214
222
|
/**
|
|
215
223
|
* No live quote: the price is the close of the latest stored daily bar of
|
|
216
224
|
* `session` (an exchange-local date), said beside the price.
|
|
@@ -300,6 +308,11 @@ export interface Quote extends DepositaryReceiptFacts {
|
|
|
300
308
|
provenance?: QuoteProvenance;
|
|
301
309
|
/** Freshness class for the quote data. Provider identity lives in providerId/provenance. */
|
|
302
310
|
dataSource?: QuoteDataSource;
|
|
311
|
+
/**
|
|
312
|
+
* The spot exchange whose own last trade the price is (Coinbase, Kraken), on a coin's quote; absent on the
|
|
313
|
+
* composite price, which blends several exchanges. Sources name the quote by it (`quoteSourceName`).
|
|
314
|
+
*/
|
|
315
|
+
priceVenue?: string;
|
|
303
316
|
/**
|
|
304
317
|
* A perpetual contract's whole market row as of this quote (funding, open
|
|
305
318
|
* interest, premium), so every view of the contract reads the figures that
|