gloomberb 0.20.6 → 0.20.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/api-client/fund-facts.ts +20 -4
- package/src/api-client/socket.ts +4 -4
- package/src/architecture/shortcut-labels-allowlist.json +1 -0
- package/src/cli/commands/market.ts +33 -17
- package/src/cli/commands/search.ts +19 -3
- package/src/cli/desktop-pane-shot.ts +61 -0
- package/src/cli/pane-functions/dom.ts +4 -4
- package/src/cli/pane-functions/freshness.ts +38 -5
- package/src/cli/pane-functions/screenshot-assessment.ts +16 -4
- package/src/cli/quote-answer.ts +57 -1
- package/src/cli/result.ts +17 -0
- package/src/docs/snapshot.json +55 -16
- package/src/i18n/es.ts +2 -0
- package/src/i18n/ja.ts +2 -0
- package/src/i18n/ko.ts +2 -0
- package/src/i18n/zh-cn.ts +2 -0
- package/src/i18n/zh-tw.ts +2 -0
- package/src/market-data/market/change-basis.ts +49 -8
- package/src/market-data/market/dated-previous-close.ts +133 -10
- package/src/market-data/market/freshness.ts +18 -6
- package/src/market-data/market/status.ts +9 -1
- package/src/market-data/published-nse-sessions.ts +16 -1
- package/src/market-data/quotes/freshness.ts +15 -0
- package/src/plugins/builtin/alerts/alert-engine.ts +15 -0
- package/src/plugins/builtin/alerts/cli.ts +22 -9
- package/src/plugins/builtin/alerts/headless.ts +1 -1
- package/src/plugins/builtin/alerts/index.tsx +5 -1
- package/src/plugins/builtin/alerts/metric-command.ts +1 -1
- package/src/plugins/builtin/holders/fund-holders.ts +22 -1
- package/src/plugins/builtin/holders/headless.ts +5 -4
- package/src/plugins/builtin/holders/pane.tsx +7 -3
- package/src/plugins/builtin/holders/report-header.ts +23 -0
- package/src/plugins/builtin/members/client.ts +1 -1
- package/src/plugins/builtin/members/headless.ts +2 -0
- package/src/plugins/builtin/members/model.ts +10 -8
- package/src/plugins/builtin/members/pane.tsx +4 -1
- package/src/plugins/builtin/portfolio-list/cli/portfolio-command.ts +5 -2
- package/src/plugins/builtin/portfolio-list/cli/render.ts +66 -23
- package/src/plugins/builtin/portfolio-list/headless.ts +2 -1
- package/src/plugins/builtin/portfolio-list/income.ts +46 -22
- package/src/plugins/builtin/portfolio-list/pane/data.ts +16 -6
- package/src/plugins/builtin/portfolio-list/pane/index.tsx +5 -4
- package/src/plugins/builtin/portfolio-list/use-throttled-ticker-order.ts +40 -3
- package/src/plugins/builtin/sec/fund-facts.ts +25 -5
- package/src/plugins/builtin/shared/report-freshness.ts +15 -6
- package/src/plugins/builtin/supply-chain/model.ts +18 -6
- package/src/portfolio/column-values.ts +3 -0
- package/src/portfolio/valuation-basis.ts +23 -1
- package/src/state/hooks/quote-streaming.ts +14 -6
- package/src/tickers/instrument-kind.ts +22 -1
- package/src/tickers/search/index.ts +5 -0
- package/src/tickers/terminal-codes.ts +17 -5
- package/src/time-series/fundamentals/current-valuation.ts +244 -0
- package/src/time-series/fundamentals/historical-valuation.ts +99 -0
- package/src/time-series/fundamentals/metric-ids.ts +61 -0
- package/src/time-series/fundamentals/period-points.ts +104 -0
- package/src/time-series/fundamentals/quarterly-ttm.ts +220 -0
- package/src/time-series/fundamentals/series.ts +164 -0
- package/src/time-series/fundamentals/source-statements.ts +177 -0
- package/src/time-series/fundamentals/statement-fields.ts +154 -0
- package/src/time-series/fundamentals/statement-merge.ts +124 -0
- package/src/time-series/fundamentals/statement.ts +114 -0
- package/src/time-series/fundamentals/valuation-multiples.ts +50 -0
- package/src/time-series/fundamentals.ts +18 -1407
- package/src/types/financials.ts +9 -0
- package/src/utils/debug-log.ts +29 -0
|
@@ -12,18 +12,44 @@ function hasSameMembership(left: readonly string[], right: readonly string[]): b
|
|
|
12
12
|
return right.every((symbol) => symbols.has(symbol));
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
+
function hasUnseenSymbol(symbols: ReadonlySet<string> | undefined, seen: ReadonlySet<string>): boolean {
|
|
16
|
+
if (!symbols) return false;
|
|
17
|
+
for (const symbol of symbols) {
|
|
18
|
+
if (!seen.has(symbol)) return true;
|
|
19
|
+
}
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The order a table shows while quotes move it. A user's sort change, a row
|
|
25
|
+
* joining or leaving, and a row getting its first figure in the sort column
|
|
26
|
+
* (the list's values arriving after its rows) all apply at once. Rows that
|
|
27
|
+
* already had a figure only reshuffle among themselves once per `throttleMs`,
|
|
28
|
+
* so live ticks do not make the list jump. `valuedSymbols` are the rows that
|
|
29
|
+
* have a figure now; leave it out for an order that has no such arrival.
|
|
30
|
+
*/
|
|
15
31
|
export function useThrottledTickerOrder(
|
|
16
32
|
candidateSymbols: string[],
|
|
17
33
|
resetKey: string,
|
|
18
|
-
throttleMs = PORTFOLIO_REORDER_THROTTLE_MS,
|
|
34
|
+
{ throttleMs = PORTFOLIO_REORDER_THROTTLE_MS, valuedSymbols }: {
|
|
35
|
+
throttleMs?: number;
|
|
36
|
+
valuedSymbols?: ReadonlySet<string>;
|
|
37
|
+
} = {},
|
|
19
38
|
): string[] {
|
|
20
39
|
const [committedSymbols, setCommittedSymbols] = useState(candidateSymbols);
|
|
21
40
|
const committedRef = useRef(candidateSymbols);
|
|
22
41
|
const latestCandidateRef = useRef(candidateSymbols);
|
|
23
42
|
const resetKeyRef = useRef(resetKey);
|
|
43
|
+
// Rows that have had a figure since the last sort or list change: a row that
|
|
44
|
+
// loses it and gets it back is a live flicker, not an arrival.
|
|
45
|
+
const valuedRef = useRef<Set<string> | null>(null);
|
|
46
|
+
if (valuedRef.current === null) valuedRef.current = new Set(valuedSymbols);
|
|
24
47
|
const lastCommitAtRef = useRef(0);
|
|
25
48
|
const timerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
26
49
|
const candidateKey = JSON.stringify(candidateSymbols);
|
|
50
|
+
// Whether a row has a figure it has not had before: a quote tick that only
|
|
51
|
+
// moves the rows' values does not wake the effect.
|
|
52
|
+
const hasNewValue = hasUnseenSymbol(valuedSymbols, valuedRef.current);
|
|
27
53
|
|
|
28
54
|
useEffect(() => {
|
|
29
55
|
latestCandidateRef.current = candidateSymbols;
|
|
@@ -32,13 +58,24 @@ export function useThrottledTickerOrder(
|
|
|
32
58
|
const membershipChanged = !hasSameMembership(current, candidateSymbols);
|
|
33
59
|
resetKeyRef.current = resetKey;
|
|
34
60
|
|
|
61
|
+
const valued = valuedRef.current!;
|
|
62
|
+
let firstValue = false;
|
|
63
|
+
if (resetChanged) valued.clear();
|
|
64
|
+
if (valuedSymbols) {
|
|
65
|
+
for (const symbol of valuedSymbols) {
|
|
66
|
+
if (valued.has(symbol)) continue;
|
|
67
|
+
valued.add(symbol);
|
|
68
|
+
firstValue = true;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
35
72
|
const commit = (nextSymbols: string[]) => {
|
|
36
73
|
committedRef.current = nextSymbols;
|
|
37
74
|
lastCommitAtRef.current = Date.now();
|
|
38
75
|
setCommittedSymbols(nextSymbols);
|
|
39
76
|
};
|
|
40
77
|
|
|
41
|
-
if (resetChanged || membershipChanged) {
|
|
78
|
+
if (resetChanged || membershipChanged || firstValue) {
|
|
42
79
|
if (timerRef.current) clearTimeout(timerRef.current);
|
|
43
80
|
timerRef.current = null;
|
|
44
81
|
if (!hasSameOrder(current, candidateSymbols)) commit(candidateSymbols);
|
|
@@ -60,7 +97,7 @@ export function useThrottledTickerOrder(
|
|
|
60
97
|
const latest = latestCandidateRef.current;
|
|
61
98
|
if (!hasSameOrder(committedRef.current, latest)) commit(latest);
|
|
62
99
|
}, remaining);
|
|
63
|
-
}, [candidateKey, resetKey, throttleMs]);
|
|
100
|
+
}, [candidateKey, resetKey, throttleMs, hasNewValue]);
|
|
64
101
|
|
|
65
102
|
useEffect(() => () => {
|
|
66
103
|
if (timerRef.current) clearTimeout(timerRef.current);
|
|
@@ -162,6 +162,12 @@ function leverageObjectiveText(leverage: Pick<FundLeverage, "value" | "reset">):
|
|
|
162
162
|
return `${leverageFactorLabel(leverage.value)} ${leverage.reset}, ${leverage.value < 0 ? "inverse" : "long"}`;
|
|
163
163
|
}
|
|
164
164
|
|
|
165
|
+
/** A premium's price when not the counter's own trade, after its date in a pane: ` · 3042:HKEX` (its traded counter's close), ` · nominal`. */
|
|
166
|
+
function premiumPriceNote(premium: NonNullable<FundFactsPayload["premiumDiscount"]>): string {
|
|
167
|
+
const price = premium.price;
|
|
168
|
+
return price?.kind === "counter" ? ` · ${price.ticker}` : price?.kind === "nominal" ? ` · ${t("nominal")}` : "";
|
|
169
|
+
}
|
|
170
|
+
|
|
165
171
|
/**
|
|
166
172
|
* How each dated figure reads beside the NAV, the date the sheet is about.
|
|
167
173
|
* Every figure says its own date. One that is older than it looks is marked:
|
|
@@ -199,7 +205,7 @@ function datedFigures(facts: FundFactsPayload): Record<"nav" | "premium" | "fee"
|
|
|
199
205
|
// A computed premium is dated by its close's session (a weekend month end's Friday), and says when it is an estimate's.
|
|
200
206
|
detail: premium?.asOf
|
|
201
207
|
? premium.basis === "computed"
|
|
202
|
-
? `${tf("{date} close", { date: closeSession(facts) ?? premium.asOf })}${premium.estimate ? ` · ${t("est.")}` : ""}`
|
|
208
|
+
? `${tf("{date} close", { date: closeSession(facts) ?? premium.asOf })}${premium.estimate ? ` · ${t("est.")}` : ""}${premiumPriceNote(premium)}`
|
|
203
209
|
: premium.asOf
|
|
204
210
|
: undefined,
|
|
205
211
|
marked: facts.stale || (!!premium?.asOf && !!nav && premium.asOf !== nav),
|
|
@@ -347,6 +353,20 @@ export function fundFactOverviewFields(facts: FundFactsPayload): FundFactOvervie
|
|
|
347
353
|
return fields;
|
|
348
354
|
}
|
|
349
355
|
|
|
356
|
+
/**
|
|
357
|
+
* What a computed premium is measured from, for text reports: the closing
|
|
358
|
+
* price, another counter's traded close at the NAVs' rate when this
|
|
359
|
+
* counter's was nominal (`3042:HKEX close HK$9.18 at the NAVs' rate vs
|
|
360
|
+
* NAV`), or the nominal close when no counter traded.
|
|
361
|
+
*/
|
|
362
|
+
function premiumBasis(premium: NonNullable<FundFactsPayload["premiumDiscount"]>): string | null {
|
|
363
|
+
if (premium.basis !== "computed") return null;
|
|
364
|
+
if (premium.estimate) return "closing price vs NAV estimate midpoint";
|
|
365
|
+
const price = premium.price;
|
|
366
|
+
if (price?.kind === "counter") return `${price.ticker} close ${formatCurrency(price.close, price.currency, 4)} at the NAVs' rate vs NAV`;
|
|
367
|
+
return price?.kind === "nominal" ? "nominal closing price vs NAV" : "closing price vs NAV";
|
|
368
|
+
}
|
|
369
|
+
|
|
350
370
|
/** Where a figure came from and when, for text reports: `2026-10-16 · iShares`. */
|
|
351
371
|
function provenance(...parts: (string | null | undefined)[]): string {
|
|
352
372
|
return parts.filter(Boolean).join(" · ");
|
|
@@ -375,12 +395,12 @@ export function fundFactEntries(facts: FundFactsPayload): HeadlessPaneEntry[] {
|
|
|
375
395
|
add("nav", "NAV", facts.nav.value, provenance(fundPrice(facts, facts.nav.value), date, estimate, facts.nav.source), facts.currency ?? "USD");
|
|
376
396
|
}
|
|
377
397
|
if (facts.closingPrice) add("closingPrice", "Closing price", facts.closingPrice.value,
|
|
378
|
-
provenance(fundPrice(facts, facts.closingPrice.value), facts.closingPrice.asOf, facts.closingPrice.
|
|
398
|
+
provenance(fundPrice(facts, facts.closingPrice.value), facts.closingPrice.asOf, facts.closingPrice.nominal ? "nominal, no trades" : null,
|
|
399
|
+
facts.closingPrice.source), facts.currency ?? "USD");
|
|
379
400
|
if (facts.premiumDiscount) {
|
|
380
|
-
const basis = facts.premiumDiscount.basis !== "computed" ? null
|
|
381
|
-
: facts.premiumDiscount.estimate ? "closing price vs NAV estimate midpoint" : "closing price vs NAV";
|
|
382
401
|
add("premiumDiscountPercent", "Premium/discount", facts.premiumDiscount.value,
|
|
383
|
-
provenance(formatPremiumPercent(facts.premiumDiscount.value), facts.premiumDiscount.asOf,
|
|
402
|
+
provenance(formatPremiumPercent(facts.premiumDiscount.value), facts.premiumDiscount.asOf, premiumBasis(facts.premiumDiscount),
|
|
403
|
+
facts.premiumDiscount.source), "%");
|
|
384
404
|
}
|
|
385
405
|
if (facts.netAssets) {
|
|
386
406
|
const scope = wholeFund(facts) ? "all share classes" : null;
|
|
@@ -82,6 +82,8 @@ const CLOUD_QUOTE_PROVIDER_ID = "gloomberb-cloud";
|
|
|
82
82
|
interface QuoteFreshnessFields {
|
|
83
83
|
dataSource?: "live" | "delayed";
|
|
84
84
|
stale?: boolean;
|
|
85
|
+
/** At its venue's nominal price, nothing having traded (Quote.nominalPrice): reports count it apart from stale rows. */
|
|
86
|
+
nominal?: true;
|
|
85
87
|
/** How far a delayed Gloom Cloud quote runs behind its venue's trades. */
|
|
86
88
|
delayMinutes?: number;
|
|
87
89
|
/** The venue whose sessions the quote follows, so the report can say whether its market is open. */
|
|
@@ -105,13 +107,15 @@ export function quoteFreshnessFields(
|
|
|
105
107
|
// A perpetual's venue is read about once a minute, not held back by a feed lag.
|
|
106
108
|
const delayed = quote.dataSource === "delayed" && quote.providerId === CLOUD_QUOTE_PROVIDER_ID && !isPerpetualExchange(exchange);
|
|
107
109
|
const sessionCalendar = readIndexSession(quote.indexSession);
|
|
108
|
-
// A print older than its venue's latest session says nothing of where that market stands now (no "markets open" beside it)
|
|
109
|
-
|
|
110
|
+
// A print older than its venue's latest session says nothing of where that market stands now (no "markets open" beside it);
|
|
111
|
+
// a nominal price is that session's, its last trade older.
|
|
112
|
+
const session = !!quote.nominalPrice || !isQuoteBeforeLatestSession(quote, now);
|
|
110
113
|
return {
|
|
111
114
|
// A quote served from its saved copy, its refresh having failed, marks the row drawn from it.
|
|
112
115
|
...savedCopyMark(quote),
|
|
113
116
|
...(quote.dataSource === "live" || quote.dataSource === "delayed" ? { dataSource: quote.dataSource } : {}),
|
|
114
117
|
stale: isQuoteStaleForCurrentSession(quote, now),
|
|
118
|
+
...(quote.nominalPrice ? { nominal: true as const } : {}),
|
|
115
119
|
...(delayed ? { delayMinutes: delayedFeedLagMs(exchange) / 60_000 } : {}),
|
|
116
120
|
...(exchange && session ? { sessionExchange: exchange } : {}),
|
|
117
121
|
// An index's final close reads as a close, not after hours.
|
|
@@ -124,11 +128,16 @@ export function quoteFreshnessFields(
|
|
|
124
128
|
* One quote as a report reads it among the observations behind a view: its
|
|
125
129
|
* freshness fields and when the price it headlines was observed
|
|
126
130
|
* (quoteHeadlineTime: in a pre-market nothing has traded in, the close it
|
|
127
|
-
* stands at). A
|
|
128
|
-
*
|
|
131
|
+
* stands at). A nominal price is dated by the session it is the venue's price
|
|
132
|
+
* for (`asOfDate`), not by the older last trade. A board publishes one per
|
|
133
|
+
* quote it shows, so `fn` and `shot` date it as `quote` dates the same quotes.
|
|
129
134
|
*/
|
|
130
|
-
export function quoteObservation(quote: Quote, now = Date.now()): QuoteFreshnessFields & { updatedAt: number } {
|
|
131
|
-
return {
|
|
135
|
+
export function quoteObservation(quote: Quote, now = Date.now()): QuoteFreshnessFields & { updatedAt: number; asOfDate?: string } {
|
|
136
|
+
return {
|
|
137
|
+
...quoteFreshnessFields(quote, now),
|
|
138
|
+
updatedAt: quoteHeadlineTime(quote),
|
|
139
|
+
...(quote.nominalPrice ? { asOfDate: quote.nominalPrice.session } : {}),
|
|
140
|
+
};
|
|
132
141
|
}
|
|
133
142
|
|
|
134
143
|
/**
|
|
@@ -211,26 +211,38 @@ export function lockedDisclosures(data: Pick<SupplyChainPayload, "says" | "names
|
|
|
211
211
|
|
|
212
212
|
/** Countries whose companies' own filings SPLC reads (docs/supply-chain.md, Coverage and limitations). */
|
|
213
213
|
const FILING_COUNTRIES = new Set(["US", "KR"]);
|
|
214
|
+
/**
|
|
215
|
+
* Where SPLC reads companies' own annual reports from the exchange: Hong
|
|
216
|
+
* Kong (HKEX), mainland China (cninfo) and Singapore (SGXNet), by the
|
|
217
|
+
* company's country or its listing's exchange. A few reports are read at a
|
|
218
|
+
* time, so a company there may not have had its report read yet.
|
|
219
|
+
*/
|
|
220
|
+
const REPORT_COUNTRIES = new Set(["HK", "CN", "SG"]);
|
|
221
|
+
const REPORT_EXCHANGES = new Set(["HKEX", "SSE", "SZSE", "SGX"]);
|
|
214
222
|
|
|
215
223
|
/**
|
|
216
224
|
* What a company with no disclosed relationship at all reads instead of an
|
|
217
225
|
* empty table. The server gives an entity's country as an ISO code (`US`,
|
|
218
226
|
* `KR`, `TW`) or none. A company in a country whose filings SPLC does not
|
|
219
227
|
* read names the markets it does; one whose country is not known is never
|
|
220
|
-
* said to be outside them.
|
|
221
|
-
* customer's filings name their suppliers.
|
|
222
|
-
* another company's supply chain ("fn SPLC
|
|
223
|
-
* there are relationships.
|
|
228
|
+
* said to be outside them. All but a US or Korean company point to the side
|
|
229
|
+
* that can still name it: a customer's filings name their suppliers.
|
|
230
|
+
* `command` is how the reader opens another company's supply chain ("fn SPLC
|
|
231
|
+
* AAPL" in the CLI). Null when there are relationships.
|
|
224
232
|
*/
|
|
225
233
|
export function supplyEmptyText(data: Pick<SupplyChainPayload, "symbol" | "entity" | "says" | "names" | "earlier">, command = (symbol: string) => `SPLC ${symbol}`): string | null {
|
|
226
234
|
if (data.says.length || data.names.length || data.earlier?.says.length || data.earlier?.names.length) return null;
|
|
227
235
|
const code = data.entity?.country?.trim().toUpperCase() ?? "";
|
|
228
236
|
const country = /^[A-Z]{2}$/.test(code) ? code : null;
|
|
237
|
+
const exchange = data.entity?.exchange?.trim().toUpperCase() ?? "";
|
|
229
238
|
const customerSide = `A customer's filings name its suppliers: try the customer's side, such as ${command("AAPL")}.`;
|
|
230
239
|
if (country && FILING_COUNTRIES.has(country)) return `No filing, announcement or call read so far names a relationship for ${data.symbol}.`;
|
|
240
|
+
if ((country && REPORT_COUNTRIES.has(country)) || REPORT_EXCHANGES.has(exchange)) {
|
|
241
|
+
return `No annual report, announcement or call read so far names a relationship for ${data.symbol}. ${customerSide}`;
|
|
242
|
+
}
|
|
231
243
|
if (!country) return `No filing, announcement or call read so far names a relationship for ${data.symbol}. ${customerSide}`;
|
|
232
|
-
return `No relationship for ${data.symbol}: SPLC reads US
|
|
233
|
-
+ `and none read so far names one. ${customerSide}`;
|
|
244
|
+
return `No relationship for ${data.symbol}: SPLC reads company filings from the US and Korea and annual reports from Hong Kong, mainland China `
|
|
245
|
+
+ `and Singapore, plus announcements and calls, and none read so far names one. ${customerSide}`;
|
|
234
246
|
}
|
|
235
247
|
|
|
236
248
|
/** The lock line of a free preview, in the same words in the pane and `fn SPLC`. */
|
|
@@ -68,6 +68,7 @@ import {
|
|
|
68
68
|
import {
|
|
69
69
|
getPortfolioValuationDisplay,
|
|
70
70
|
getPortfolioValuationTime,
|
|
71
|
+
valuesAtNominalPrice,
|
|
71
72
|
valuesAtSettlement,
|
|
72
73
|
type PortfolioValuationBasis,
|
|
73
74
|
} from "./valuation-basis";
|
|
@@ -773,6 +774,8 @@ export function getColumnValue(
|
|
|
773
774
|
// In UTC, as the header says; a close the venue's calendar gives no hour for is dated by its day.
|
|
774
775
|
// An export writes the date with it, as ISO: 16:49 alone says nothing of which day.
|
|
775
776
|
const iso = new Date(time.time).toISOString();
|
|
777
|
+
// A price nothing traded at says so; its export keeps the day of the session it is the venue's price for.
|
|
778
|
+
if (valuesAtNominalPrice(quote, positionMetrics, ctx.valuationBasis)) return { text: "nominal", color: colors.warning, value: iso.slice(0, 10) };
|
|
776
779
|
return {
|
|
777
780
|
// Every row names its day: a bare 00:47 beside Fri 21:00 reads as the same evening.
|
|
778
781
|
text: time.dateOnly ? formatShortDate(time.time, MONTH_DAY) : formatFeedTime(time.time, ctx.now, "—", { utc: true, dayToday: true }),
|
|
@@ -64,7 +64,9 @@ export function getPortfolioValuationDisplay(
|
|
|
64
64
|
* When the price a position is valued at on `basis` is from: the quote's time
|
|
65
65
|
* for a print, the session's close for a regular close
|
|
66
66
|
* (regularSessionValuationTime), and a future's settlement session at the
|
|
67
|
-
* close.
|
|
67
|
+
* close. A nominal price, nothing having traded, is dated by the session it is
|
|
68
|
+
* the venue's price for (Quote.nominalPrice), on either basis: its last trade
|
|
69
|
+
* is older and at another price. Null without a dated quote or settlement.
|
|
68
70
|
*/
|
|
69
71
|
export function getPortfolioValuationTime(
|
|
70
72
|
quote: Quote | null | undefined,
|
|
@@ -77,10 +79,30 @@ export function getPortfolioValuationTime(
|
|
|
77
79
|
return Number.isFinite(day) ? { time: day, dateOnly: true } : null;
|
|
78
80
|
}
|
|
79
81
|
if (!quote) return null;
|
|
82
|
+
const nominal = nominalPriceDay(quote);
|
|
83
|
+
if (nominal) return nominal;
|
|
80
84
|
if (valuesAtClose(metrics, basis)) return regularSessionValuationTime(quote);
|
|
81
85
|
return Number.isFinite(quote.lastUpdated) && quote.lastUpdated > 0 ? { time: quote.lastUpdated, dateOnly: false } : null;
|
|
82
86
|
}
|
|
83
87
|
|
|
88
|
+
/**
|
|
89
|
+
* Whether a position is valued at its venue's nominal price on `basis`: a
|
|
90
|
+
* quote nothing traded at (Quote.nominalPrice), never a future at its
|
|
91
|
+
* settlement.
|
|
92
|
+
*/
|
|
93
|
+
export function valuesAtNominalPrice(
|
|
94
|
+
quote: Quote | null | undefined,
|
|
95
|
+
metrics: Pick<PortfolioPositionMetrics, "isFuture"> | null | undefined,
|
|
96
|
+
basis: PortfolioValuationBasis = "latest-print",
|
|
97
|
+
): boolean {
|
|
98
|
+
return !!quote?.nominalPrice && !valuesAtSettlement(metrics ?? null, basis);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function nominalPriceDay(quote: Quote): ReportTime | null {
|
|
102
|
+
const day = quote.nominalPrice ? Date.parse(`${quote.nominalPrice.session}T00:00:00Z`) : Number.NaN;
|
|
103
|
+
return Number.isFinite(day) ? { time: day, dateOnly: true } : null;
|
|
104
|
+
}
|
|
105
|
+
|
|
84
106
|
/** A valuation time as exports write it: an ISO instant in UTC, or an ISO date. */
|
|
85
107
|
export function valuationTimeIso(time: ReportTime | null): string | null {
|
|
86
108
|
if (!time) return null;
|
|
@@ -3,7 +3,7 @@ import { useEffect, useMemo, useRef, useState } from "react";
|
|
|
3
3
|
import { useAppVisible, usePaneInView } from "../app/activity";
|
|
4
4
|
import type { QuoteSubscriptionTarget } from "../../types/data-provider";
|
|
5
5
|
import type { Quote } from "../../types/financials";
|
|
6
|
-
import { debugLog } from "../../utils/debug-log";
|
|
6
|
+
import { debugLog, previewList, type ListPreview } from "../../utils/debug-log";
|
|
7
7
|
import { normalizeSymbol } from "../../utils/exchanges";
|
|
8
8
|
import { getSharedMarketDataCoordinator, type MarketDataCoordinator } from "../../market-data/coordinator";
|
|
9
9
|
import { useQuoteEntries } from "../../market-data/hooks";
|
|
@@ -80,6 +80,8 @@ type UpdateableQuoteSubscription = (() => void) & {
|
|
|
80
80
|
interface ActiveQuoteSubscription {
|
|
81
81
|
identityKey: string;
|
|
82
82
|
subscriptionKey: string;
|
|
83
|
+
/** The subscription's targets as the log names them. */
|
|
84
|
+
preview: ListPreview<string>;
|
|
83
85
|
count: number;
|
|
84
86
|
dispose: UpdateableQuoteSubscription;
|
|
85
87
|
}
|
|
@@ -110,7 +112,7 @@ export function useQuoteStreaming(
|
|
|
110
112
|
// Keyed on the array, not its contents: callers memoize their targets, and a
|
|
111
113
|
// portfolio re-renders on every data frame, where re-keying and sorting a
|
|
112
114
|
// thousand targets cost a few milliseconds each time.
|
|
113
|
-
const { coordinatorTargets, identityKey, subscriptionKey } = useMemo(() => {
|
|
115
|
+
const { coordinatorTargets, identityKey, subscriptionKey, preview } = useMemo(() => {
|
|
114
116
|
const normalizedEntries = new Map<string, QuoteSubscriptionTarget>();
|
|
115
117
|
for (const target of targets) {
|
|
116
118
|
const resolved = normalizeQuoteStreamSubscriptionTarget(target);
|
|
@@ -127,16 +129,20 @@ export function useQuoteStreaming(
|
|
|
127
129
|
.sort()
|
|
128
130
|
.join("\u001f"),
|
|
129
131
|
subscriptionKey: sortedEntries.map(([key]) => key).join("|"),
|
|
132
|
+
// The log names the first few targets, not the hundreds a long list subscribes.
|
|
133
|
+
preview: previewList(sortedEntries, ([key]) => key),
|
|
130
134
|
};
|
|
131
135
|
}, [paneInView, targets]);
|
|
132
136
|
const latestSubscriptionRef = useRef({
|
|
133
137
|
identityKey,
|
|
134
138
|
subscriptionKey,
|
|
139
|
+
preview,
|
|
135
140
|
targets: coordinatorTargets,
|
|
136
141
|
});
|
|
137
142
|
latestSubscriptionRef.current = {
|
|
138
143
|
identityKey,
|
|
139
144
|
subscriptionKey,
|
|
145
|
+
preview,
|
|
140
146
|
targets: coordinatorTargets,
|
|
141
147
|
};
|
|
142
148
|
const activeSubscriptionRef = useRef<ActiveQuoteSubscription | null>(null);
|
|
@@ -147,7 +153,7 @@ export function useQuoteStreaming(
|
|
|
147
153
|
if (latest.targets.length > 0) {
|
|
148
154
|
quoteStreamLog.info("skipping subscription", {
|
|
149
155
|
reason: enabled ? "inactive" : "disabled",
|
|
150
|
-
targets: latest.
|
|
156
|
+
targets: latest.preview,
|
|
151
157
|
});
|
|
152
158
|
}
|
|
153
159
|
return;
|
|
@@ -156,11 +162,12 @@ export function useQuoteStreaming(
|
|
|
156
162
|
quoteStreamLog.info("subscribe", {
|
|
157
163
|
providerId: "market-data",
|
|
158
164
|
count: latest.targets.length,
|
|
159
|
-
targets: latest.
|
|
165
|
+
targets: latest.preview,
|
|
160
166
|
});
|
|
161
167
|
const active: ActiveQuoteSubscription = {
|
|
162
168
|
identityKey: latest.identityKey,
|
|
163
169
|
subscriptionKey: latest.subscriptionKey,
|
|
170
|
+
preview: latest.preview,
|
|
164
171
|
count: latest.targets.length,
|
|
165
172
|
dispose: coordinator.subscribeQuotes(latest.targets) as UpdateableQuoteSubscription,
|
|
166
173
|
};
|
|
@@ -172,7 +179,7 @@ export function useQuoteStreaming(
|
|
|
172
179
|
quoteStreamLog.info("unsubscribe", {
|
|
173
180
|
providerId: "market-data",
|
|
174
181
|
count: active.count,
|
|
175
|
-
targets: active.
|
|
182
|
+
targets: active.preview,
|
|
176
183
|
});
|
|
177
184
|
active.dispose();
|
|
178
185
|
};
|
|
@@ -193,7 +200,7 @@ export function useQuoteStreaming(
|
|
|
193
200
|
quoteStreamLog.info("update subscription", {
|
|
194
201
|
providerId: "market-data",
|
|
195
202
|
count: latest.targets.length,
|
|
196
|
-
targets: latest.
|
|
203
|
+
targets: latest.preview,
|
|
197
204
|
});
|
|
198
205
|
if (typeof active.dispose.update === "function") {
|
|
199
206
|
active.dispose.update(latest.targets);
|
|
@@ -203,6 +210,7 @@ export function useQuoteStreaming(
|
|
|
203
210
|
previousDispose();
|
|
204
211
|
}
|
|
205
212
|
active.subscriptionKey = latest.subscriptionKey;
|
|
213
|
+
active.preview = latest.preview;
|
|
206
214
|
active.count = latest.targets.length;
|
|
207
215
|
}, [appActive, coordinator, enabled, identityKey, subscriptionKey]);
|
|
208
216
|
}
|
|
@@ -148,6 +148,23 @@ export function isCryptoVenuePerpetual(type: string | null | undefined, name: st
|
|
|
148
148
|
return classifyInstrumentType(type) === "crypto" && /\(derivatives\)/i.test(name ?? "");
|
|
149
149
|
}
|
|
150
150
|
|
|
151
|
+
/** An exchange-traded fund's intraday indicative value as an index feed lists it, under the fund's own name: ^ARKK-IV. */
|
|
152
|
+
export function isIndicativeValueListing(symbol: string | null | undefined, type?: string | null): boolean {
|
|
153
|
+
return /^\^[A-Z0-9.]{1,10}-IV$/i.test(parsePublicTickerKey(symbol ?? "").symbol) || normalizeInstrumentType(type) === "INDICATIVEVALUE";
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* A crypto venue's copy of a fund's or a company's price: a token on its
|
|
158
|
+
* shares ("... Tokenized ETF (Ondo)", typed as a coin) or a perpetual on it
|
|
159
|
+
* ("... ETF (Derivatives)"). Neither is a listing of the fund or the company.
|
|
160
|
+
* A fund or share whose own name says tokenized is a listing.
|
|
161
|
+
*/
|
|
162
|
+
export function isCryptoVenueCopy(type: string | null | undefined, name: string | null | undefined): boolean {
|
|
163
|
+
return normalizeInstrumentType(type) === "TOKENIZEDPRODUCT"
|
|
164
|
+
|| (classifyInstrumentType(type) === "crypto" && /\btokeni[sz]ed\b/i.test(name ?? ""))
|
|
165
|
+
|| (isCryptoVenuePerpetual(type, name) && /\b(?:ETFS?|ETNS?|FUNDS?|TRUST|SHARES?|STOCK)\b/i.test(name ?? ""));
|
|
166
|
+
}
|
|
167
|
+
|
|
151
168
|
/**
|
|
152
169
|
* A quote type's code in the words the other types are written in ("Common
|
|
153
170
|
* Stock", "Depositary Receipt"), so one search lists one vocabulary. A generic
|
|
@@ -173,8 +190,12 @@ const TYPE_CODE_WORDS: Record<string, string> = {
|
|
|
173
190
|
export function instrumentTypeLabel(
|
|
174
191
|
type: string | null | undefined,
|
|
175
192
|
name: string | null | undefined,
|
|
176
|
-
options: { detail?: boolean } = {},
|
|
193
|
+
options: { detail?: boolean; symbol?: string } = {},
|
|
177
194
|
): string | undefined {
|
|
195
|
+
if (isIndicativeValueListing(options.symbol, type)) return options.detail ? "Indicative value (the fund's intraday estimate, not a listing)" : "Indicative value";
|
|
196
|
+
if (normalizeInstrumentType(type) !== "TOKENIZEDPRODUCT" && /\btokeni[sz]ed\b/i.test(name ?? "") && classifyInstrumentType(type) === "crypto") {
|
|
197
|
+
return options.detail ? "Tokenized product (a crypto token, not the listing)" : "Tokenized product";
|
|
198
|
+
}
|
|
178
199
|
if (isCryptoVenuePerpetual(type, name)) {
|
|
179
200
|
return options.detail ? "Perpetual futures price (24/7 on crypto venues; not the listed future, not spot)" : "Perpetual futures price";
|
|
180
201
|
}
|
|
@@ -35,6 +35,7 @@ import {
|
|
|
35
35
|
} from "./result";
|
|
36
36
|
|
|
37
37
|
import { typedPerpetualListing } from "../perpetual-listing";
|
|
38
|
+
import { isCryptoVenueCopy, isIndicativeValueListing } from "../instrument-kind";
|
|
38
39
|
import { renamedListingFor, renamedListingFormerLine, type RenamedListing } from "../renamed-listings";
|
|
39
40
|
import { endsInLegalForm, readNearMissListing, readVenueFirstListing, readTerminalListingCode } from "../terminal-codes";
|
|
40
41
|
import { isProviderBusy, ProviderBusyError, SEARCH_BUSY_MESSAGE } from "../../sources/provider-errors";
|
|
@@ -976,6 +977,10 @@ function assignTickerSearchCategories<T extends TickerSearchCandidate>(items: T[
|
|
|
976
977
|
if (item.instrumentClass === "fund" || item.instrumentClass === "derivative") {
|
|
977
978
|
return { ...item, category: "Funds & Derivatives" };
|
|
978
979
|
}
|
|
980
|
+
// A fund's indicative value (^ARKK-IV) or a crypto venue's token or perpetual on a fund names no listing of its own.
|
|
981
|
+
if (item.kind === "search" && (isIndicativeValueListing(item.symbol, item.result?.type) || isCryptoVenueCopy(item.result?.type, item.result?.name))) {
|
|
982
|
+
return { ...item, category: "Other Matches" };
|
|
983
|
+
}
|
|
979
984
|
if (!assignedPrimaryListing) {
|
|
980
985
|
assignedPrimaryListing = true;
|
|
981
986
|
return { ...item, category: "Primary Listing" };
|
|
@@ -438,8 +438,17 @@ export function readLondonDottedSymbol(raw: string): NearMissListing | null {
|
|
|
438
438
|
|
|
439
439
|
/** `BRK/B`: a US share class after a slash, as a broker writes it. One letter before the slash is a ratio or an abbreviation (P/E, N/A). */
|
|
440
440
|
const SLASH_CLASS = /^([A-Z]{2,5})\/([A-Z])$/;
|
|
441
|
-
/**
|
|
442
|
-
|
|
441
|
+
/**
|
|
442
|
+
* `700.HK`, `03042.HK`, `00700:HKEX`: a Hong Kong code without its leading
|
|
443
|
+
* zeros, or with the five digits HKEXnews and the Product Key Facts print.
|
|
444
|
+
*/
|
|
445
|
+
const HONG_KONG_CODE = /^(\d{1,5})(\.HK|:HKEX)$/;
|
|
446
|
+
|
|
447
|
+
/** A Hong Kong code as the app keys it: four digits at least (0700, 3042, 83042). */
|
|
448
|
+
function hongKongWorkingCode(digits: string): string | null {
|
|
449
|
+
const code = Number(digits);
|
|
450
|
+
return code > 0 ? String(code).padStart(4, "0") : null;
|
|
451
|
+
}
|
|
443
452
|
/** `6758.JP`, `MC.FP`: a symbol with a Bloomberg market code where a listing suffix goes. */
|
|
444
453
|
const MARKET_SUFFIX = /^([A-Z0-9]{1,10})\.([A-Z]{2})$/;
|
|
445
454
|
/**
|
|
@@ -454,7 +463,9 @@ const MARKET_SUFFIX_CODES: ReadonlySet<string> = new Set([
|
|
|
454
463
|
|
|
455
464
|
/**
|
|
456
465
|
* A symbol written nearly as a listing is (`700.HK`, `6758.JP`, `BRK/B`),
|
|
457
|
-
* read as the working form (`0700.HK`, `6758.T`, `BRK-B`)
|
|
466
|
+
* read as the working form (`0700.HK`, `6758.T`, `BRK-B`); a Hong Kong code
|
|
467
|
+
* with HKEX's five digits (`03042.HK`, `00700:HKEX`) drops its leading zeros
|
|
468
|
+
* (`3042.HK`, `0700:HKEX`). A Bloomberg market
|
|
458
469
|
* code after the dot is that market's listing suffix (`MC.FP` is `MC.PA`),
|
|
459
470
|
* `MARKET_SUFFIX_CODES` only, so `600519.SS` stays Shanghai. Null for
|
|
460
471
|
* anything else.
|
|
@@ -464,8 +475,9 @@ export function readNearMissListing(raw: string): NearMissListing | null {
|
|
|
464
475
|
const upper = typed.toUpperCase();
|
|
465
476
|
const slash = SLASH_CLASS.exec(upper);
|
|
466
477
|
if (slash) return { typed, symbol: `${slash[1]}-${slash[2]}` };
|
|
467
|
-
const hongKong =
|
|
468
|
-
|
|
478
|
+
const hongKong = HONG_KONG_CODE.exec(upper);
|
|
479
|
+
const code = hongKong ? hongKongWorkingCode(hongKong[1]!) : null;
|
|
480
|
+
if (hongKong) return code && code !== hongKong[1] ? { typed, symbol: `${code}${hongKong[2]}` } : null;
|
|
469
481
|
const suffixed = MARKET_SUFFIX.exec(upper);
|
|
470
482
|
if (!suffixed || !MARKET_SUFFIX_CODES.has(suffixed[2]!) || tickerHasListingSuffix(upper)) return null;
|
|
471
483
|
const venue = BLOOMBERG_MARKETS[suffixed[2]!]!.venues[0]!;
|