@gloom-sh/terminal 0.20.9 → 0.20.11
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/patches/@opentui%2Fcore@0.3.2.patch +16 -0
- package/src/api-client/auth.ts +6 -0
- package/src/api-client/data.ts +1 -0
- package/src/api-client/earnings.ts +15 -0
- package/src/api-client/index.ts +14 -3
- package/src/api-client/socket-connection.ts +355 -0
- package/src/api-client/socket-features.ts +75 -0
- package/src/api-client/socket-frames.ts +161 -0
- package/src/api-client/socket-listeners.ts +207 -0
- package/src/api-client/socket-quotes.ts +332 -0
- package/src/api-client/socket.ts +150 -983
- package/src/api-client/types/account.ts +10 -0
- package/src/api-client/types/billing.ts +10 -0
- package/src/api-client/types/econ.ts +19 -7
- package/src/api-client/types/market.ts +7 -0
- package/src/api-client/types/screener.ts +2 -0
- package/src/brokers/signed-in/adapter.ts +19 -5
- package/src/brokers/signed-in/client.ts +13 -1
- package/src/brokers/signed-in/sign-in-dialog.tsx +33 -9
- package/src/cli/commands/market.ts +18 -8
- package/src/cli/commands/overview.ts +26 -7
- package/src/cli/commands/ticker.ts +40 -15
- package/src/cli/desktop-pane-shot.ts +39 -0
- package/src/cli/errors.ts +20 -3
- package/src/cli/fx-pair.ts +11 -2
- package/src/cli/history-rows.ts +34 -3
- package/src/cli/index.ts +1 -1
- package/src/cli/listing-arg.ts +51 -13
- package/src/cli/pane-functions/headless.ts +4 -2
- package/src/cli/pane-functions/index.ts +1 -0
- package/src/cli/pane-functions/resolver.ts +2 -1
- package/src/cli/pane-functions/screenshot-assessment.ts +73 -5
- package/src/cli/pane-functions/screenshot-types.ts +4 -0
- package/src/components/chart/composite/chart-layout.ts +7 -4
- package/src/components/chart/composite/composite-chart.tsx +6 -16
- package/src/components/chart/composite/toolbar.tsx +258 -82
- package/src/components/chart/composite/use-composite-chart-keyboard.ts +5 -6
- package/src/components/chart/native/kitty/manager.ts +2 -0
- package/src/components/chart/native/surface/manager.ts +211 -11
- package/src/components/command-bar/list/model.ts +13 -0
- package/src/components/command-bar/panel/index.tsx +2 -13
- package/src/components/command-bar/panel/layout.ts +1 -7
- package/src/components/command-bar/panel/runtime.ts +0 -1
- package/src/components/command-bar/panel/types.ts +0 -2
- package/src/components/command-bar/routes/ticker-search/actions.ts +2 -0
- package/src/components/command-bar/routes/ticker-search/results.ts +15 -8
- package/src/components/command-bar/surface/index.tsx +10 -5
- package/src/components/command-bar/workflow/alert.ts +21 -7
- package/src/components/data-table/column-menu.tsx +89 -0
- package/src/components/data-table/sort-menu.tsx +9 -2
- package/src/components/data-table/table-pane.ts +3 -1
- package/src/components/data-table/view.tsx +33 -6
- package/src/components/form-modal/content.tsx +10 -0
- package/src/components/index.ts +1 -1
- package/src/components/layout/pane/footer/index.tsx +25 -11
- package/src/components/layout/pane/footer/model.ts +88 -21
- package/src/components/layout/pane/sidebar.tsx +125 -15
- package/src/components/layout/shell/active-drag.ts +18 -13
- package/src/components/layout/shell/drag/magnets.ts +34 -18
- package/src/components/metric-treemap/heat-surface.tsx +2 -1
- package/src/components/metric-treemap/index.tsx +3 -2
- package/src/components/ticker/list-table-view.tsx +5 -0
- package/src/components/ui/confirm-dialog.tsx +253 -7
- package/src/components/ui/data-table/column-order.ts +180 -0
- package/src/components/ui/data-table/index.tsx +13 -2
- package/src/components/ui/data-table/opentui/index.tsx +267 -23
- package/src/components/ui/data-table/opentui/model.ts +43 -4
- package/src/components/ui/data-table/types.ts +56 -0
- package/src/components/ui/data-table/use-column-order.ts +135 -0
- package/src/components/ui/index.ts +1 -1
- package/src/components/ui/list-view.tsx +4 -3
- package/src/components/ui/status.tsx +9 -6
- package/src/components/ui/table-layout.ts +120 -0
- package/src/docs/snapshot.json +39 -2
- package/src/i18n/es.ts +14 -0
- package/src/i18n/ja.ts +14 -0
- package/src/i18n/ko.ts +14 -0
- package/src/i18n/zh-cn.ts +14 -0
- package/src/i18n/zh-tw.ts +14 -0
- package/src/market-data/coordinator/index.ts +4 -3
- package/src/market-data/coordinator/quotes.ts +12 -4
- package/src/market-data/fx-closes.ts +14 -2
- package/src/market-data/market/change-basis.ts +35 -1
- package/src/market-data/market/status.ts +37 -0
- package/src/market-data/performance.ts +4 -1
- package/src/market-data/quotes/freshness.ts +12 -0
- package/src/market-data/quotes/live-valuation.ts +26 -3
- package/src/market-data/quotes/regular-session-valuation.ts +1 -1
- package/src/market-data/realized-volatility.ts +3 -0
- package/src/market-data/us-bond-market.ts +115 -0
- package/src/plugins/builtin/account-management/invite-row.tsx +54 -0
- package/src/plugins/builtin/account-management/keyboard.ts +3 -0
- package/src/plugins/builtin/account-management/model.ts +1 -0
- package/src/plugins/builtin/account-management/pane.tsx +51 -5
- package/src/plugins/builtin/account-management/trial-cancel.ts +32 -7
- package/src/plugins/builtin/broker-manager/detail.tsx +5 -3
- package/src/plugins/builtin/broker-manager/index.tsx +6 -6
- package/src/plugins/builtin/broker-manager/model.ts +15 -6
- package/src/plugins/builtin/broker-manager/pane-actions.tsx +11 -4
- package/src/plugins/builtin/broker-manager/sign-in-end.ts +50 -19
- package/src/plugins/builtin/broker-manager/table.ts +10 -4
- package/src/plugins/builtin/chat/sidebar.tsx +33 -16
- package/src/plugins/builtin/cloud/askg/pane-session.ts +94 -0
- package/src/plugins/builtin/cloud/askg/pane.tsx +40 -83
- package/src/plugins/builtin/cloud/askg/tool-timeline.tsx +2 -0
- package/src/plugins/builtin/congress-trades/pane.tsx +8 -2
- package/src/plugins/builtin/correlation/compute.ts +4 -3
- package/src/plugins/builtin/earnings/board-model.ts +33 -0
- package/src/plugins/builtin/earnings/board-table.ts +50 -11
- package/src/plugins/builtin/earnings/board.tsx +29 -13
- package/src/plugins/builtin/earnings/calendar.tsx +15 -3
- package/src/plugins/builtin/earnings/client.ts +4 -1
- package/src/plugins/builtin/earnings/headless.ts +27 -14
- package/src/plugins/builtin/econ/calendar-source.ts +3 -0
- package/src/plugins/builtin/equity-screener/live.ts +74 -18
- package/src/plugins/builtin/equity-screener/model.ts +19 -4
- package/src/plugins/builtin/equity-screener/pane.tsx +19 -14
- package/src/plugins/builtin/equity-screener/refresh-anchor.ts +45 -0
- package/src/plugins/builtin/equity-screener/results.ts +22 -2
- package/src/plugins/builtin/equity-screener/screen-check.ts +9 -3
- package/src/plugins/builtin/futures/index.tsx +15 -1
- package/src/plugins/builtin/futures/table.tsx +1 -1
- package/src/plugins/builtin/fx-matrix/index.tsx +2 -0
- package/src/plugins/builtin/help/index.tsx +1 -1
- package/src/plugins/builtin/holders/pane.tsx +30 -20
- package/src/plugins/builtin/ipo-calendar/model.ts +3 -3
- package/src/plugins/builtin/iv-history/events.ts +5 -0
- package/src/plugins/builtin/iv-history/headless.ts +19 -12
- package/src/plugins/builtin/kelly-sizer/sections.tsx +2 -0
- package/src/plugins/builtin/macro-day/headless.ts +27 -8
- package/src/plugins/builtin/macro-day/model.ts +17 -4
- package/src/plugins/builtin/macro-day/releases.ts +36 -15
- package/src/plugins/builtin/market-halts/model.ts +3 -2
- package/src/plugins/builtin/market-movers/headless.ts +2 -1
- package/src/plugins/builtin/market-movers/index.tsx +3 -2
- package/src/plugins/builtin/market-movers/model.ts +75 -22
- package/src/plugins/builtin/market-movers/screener.ts +2 -1
- package/src/plugins/builtin/market-movers/table.ts +7 -5
- package/src/plugins/builtin/options/view.tsx +2 -0
- package/src/plugins/builtin/options-scenario/pane.tsx +2 -1
- package/src/plugins/builtin/pe-band/model.ts +4 -0
- package/src/plugins/builtin/perps/cascade-tabs.tsx +2 -1
- package/src/plugins/builtin/portfolio-list/cell-version.ts +4 -4
- package/src/plugins/builtin/portfolio-list/cli/render.ts +9 -4
- package/src/plugins/builtin/portfolio-list/pane/index.tsx +15 -1
- package/src/plugins/builtin/portfolio-list/summary/index.tsx +24 -7
- package/src/plugins/builtin/portfolio-list/summary/totals.ts +40 -11
- package/src/plugins/builtin/portfolio-list/table.tsx +18 -1
- package/src/plugins/builtin/rate-path/pane.tsx +2 -0
- package/src/plugins/builtin/research/analyst-headless.ts +9 -1
- package/src/plugins/builtin/research/analyst-pane.tsx +10 -4
- package/src/plugins/builtin/research/client.ts +25 -1
- package/src/plugins/builtin/research/corporate-actions-pane.tsx +2 -1
- package/src/plugins/builtin/research/event-model.ts +3 -13
- package/src/plugins/builtin/research/event-sources.ts +3 -1
- package/src/plugins/builtin/revenue-breakdown/pane.tsx +2 -0
- package/src/plugins/builtin/reverse-dcf/pane.tsx +2 -1
- package/src/plugins/builtin/seasonality/pane.tsx +2 -1
- package/src/plugins/builtin/short-interest/headless.ts +2 -0
- package/src/plugins/builtin/short-interest/publications-headless.ts +2 -0
- package/src/plugins/builtin/short-interest/watch-headless.ts +1 -0
- package/src/plugins/builtin/thirteenf/pane.tsx +2 -0
- package/src/plugins/builtin/ticker-detail/financials/model.ts +28 -6
- package/src/plugins/builtin/ticker-detail/financials/ratio-table.tsx +26 -9
- package/src/plugins/builtin/ticker-detail/financials/tab.tsx +58 -35
- package/src/plugins/builtin/vol-surface/heat-grid.tsx +2 -1
- package/src/plugins/builtin/vol-surface/pane.tsx +2 -1
- package/src/plugins/builtin/world-indices/index.tsx +5 -1
- package/src/plugins/builtin/yield-curve/headless.ts +5 -1
- package/src/plugins/builtin/yield-curve/index.tsx +7 -1
- package/src/portfolio/column-values.ts +47 -14
- package/src/portfolio/return-metrics.ts +4 -2
- package/src/renderers/dom/data-table/column-drag.ts +147 -0
- package/src/renderers/dom/data-table/index.tsx +22 -0
- package/src/renderers/dom/data-table/row.tsx +27 -5
- package/src/renderers/dom/host/image-surface.tsx +19 -9
- package/src/renderers/dom/host/input.tsx +4 -0
- package/src/renderers/dom/styles.css +22 -0
- package/src/renderers/electrobun/view/cli-pane-shot-entry.tsx +23 -1
- package/src/renderers/opentui/chart-surface.tsx +1 -0
- package/src/renderers/opentui/frame-hits.ts +33 -0
- package/src/renderers/opentui/host.tsx +2 -0
- package/src/renderers/opentui/native-surface.ts +14 -21
- package/src/renderers/opentui/test-utils.tsx +3 -0
- package/src/sources/gloomberb-cloud/normalizers.ts +2 -0
- package/src/sources/provider-errors.ts +12 -0
- package/src/sources/provider-router/index.ts +12 -4
- package/src/state/app/context/index.tsx +22 -0
- package/src/state/pane-session.ts +145 -0
- package/src/test-support/app-store.ts +24 -1
- package/src/tickers/search/home-listing.ts +44 -1
- package/src/tickers/search/index.ts +5 -2
- package/src/tickers/search/ranking.ts +7 -7
- package/src/tickers/us-listing.ts +11 -5
- package/src/time-series/base-series.ts +7 -1
- package/src/time-series/fundamentals/current-valuation.ts +8 -0
- package/src/time-series/fundamentals/series.ts +6 -0
- package/src/time-series/live-quotes.ts +3 -9
- package/src/time-series/resolve.ts +1 -0
- package/src/types/financials.ts +20 -0
- package/src/types/headless.ts +9 -0
- package/src/ui/host.tsx +20 -0
- package/src/ui/pointer-drag.ts +11 -2
- package/src/utils/exchanges.ts +13 -8
- package/src/utils/fundamentals.ts +14 -3
- package/src/utils/price-earnings.ts +17 -10
- package/src/utils/price-history-integrity.ts +15 -0
- package/src/utils/reason-codes.ts +79 -0
- package/src/utils/share-multiples.cases.json +1667 -0
- package/src/utils/share-multiples.ts +384 -0
- package/src/utils/untrusted-text.ts +11 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Dispatch } from "react";
|
|
2
|
-
import type
|
|
2
|
+
import { appReducer, type AppAction, type AppContextStoreValue, type AppState } from "../state/app/context";
|
|
3
3
|
|
|
4
4
|
const ignoreAction: Dispatch<AppAction> = () => {};
|
|
5
5
|
const noUnsubscribe = () => {};
|
|
@@ -19,3 +19,26 @@ export function createStaticAppStore(
|
|
|
19
19
|
subscribe: () => noUnsubscribe,
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* An `AppContext` value that runs the app's reducer on every dispatch and
|
|
25
|
+
* notifies its subscribers, for a suite that checks what the app's own
|
|
26
|
+
* actions did to the state (a pane setting written, a layout saved).
|
|
27
|
+
*/
|
|
28
|
+
export function createReducerAppStore(state: AppState): AppContextStoreValue {
|
|
29
|
+
let current = state;
|
|
30
|
+
const listeners = new Set<() => void>();
|
|
31
|
+
return {
|
|
32
|
+
dispatch: (action) => {
|
|
33
|
+
current = appReducer(current, action);
|
|
34
|
+
for (const listener of listeners) listener();
|
|
35
|
+
},
|
|
36
|
+
getState: () => current,
|
|
37
|
+
subscribe: (listener) => {
|
|
38
|
+
listeners.add(listener);
|
|
39
|
+
return () => {
|
|
40
|
+
listeners.delete(listener);
|
|
41
|
+
};
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
}
|
|
@@ -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, isPlaceholderLine, isQualifiedTickerQuery, readsAsUsTicker } from "./ranking";
|
|
3
|
+
import { answersOnlyByKeyword, 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. */
|
|
@@ -187,6 +187,49 @@ export function withHomeListingLead<T extends TickerSearchCandidate>(items: T[],
|
|
|
187
187
|
return [...rest.slice(0, after), home, ...rest.slice(after)];
|
|
188
188
|
}
|
|
189
189
|
|
|
190
|
+
/**
|
|
191
|
+
* A US ticker typed that is also a large company's short name leads with the
|
|
192
|
+
* US line, as a bare ticker resolves, then the rows the service marks with
|
|
193
|
+
* the word as typed: the company the word names, ahead of the ticker's other
|
|
194
|
+
* rows. "aia" is the iShares Asia 50 ETF's AIA, then AIA Group's 1299; "byd"
|
|
195
|
+
* is Boyd Gaming's BYD, then BYD Company's 002594 and 1211. Under the
|
|
196
|
+
* ticker, each company's first row then comes before further venues of one
|
|
197
|
+
* already listed (Boyd Gaming's BYD on IEX, the ETF's AIA in Mexico), which
|
|
198
|
+
* would push the other companies out of a short list. A line on a US
|
|
199
|
+
* exchange, a home line and a saved row are no such copies, and a line
|
|
200
|
+
* with no name of its own is no other company. The lead's own
|
|
201
|
+
* home line, which `withHomeListingLead` put right after it, stays there. A
|
|
202
|
+
* name typed as a name (`Aia`) or with its venue (AIA:NASDAQ) asks for
|
|
203
|
+
* something else.
|
|
204
|
+
*/
|
|
205
|
+
export function withNamedCompanyAfterUsLead<T extends TickerSearchCandidate>(items: T[], query: string): T[] {
|
|
206
|
+
if (isQualifiedTickerQuery(query) || !readsAsUsTicker(query)) return items;
|
|
207
|
+
const typed = normalizeTickerSymbol(query);
|
|
208
|
+
const exact = (item: T) => normalizeTickerSymbol(item.symbol || item.label) === typed;
|
|
209
|
+
const [lead, next] = items;
|
|
210
|
+
if (!lead || lead.kind !== "search" || !exact(lead) || !isUsListingExchange(candidateExchange(lead))) return items;
|
|
211
|
+
const at = next && !exact(next) && next.result?.homeListing === true ? 2 : 1;
|
|
212
|
+
const named = items.slice(at).filter((item) => item.kind === "search" && !exact(item) && !!item.result && namedByService(query, item.result));
|
|
213
|
+
let rest = items.slice(at).filter((item) => !named.includes(item));
|
|
214
|
+
const companyOf = (item: T) => getIssuerGroupKey(item.detail) || item.id;
|
|
215
|
+
const listed = new Set(items.slice(0, at).filter(exact).map(companyOf));
|
|
216
|
+
const copies = rest.filter((item) => {
|
|
217
|
+
if (!exact(item)) return false;
|
|
218
|
+
const further = listed.has(companyOf(item));
|
|
219
|
+
listed.add(companyOf(item));
|
|
220
|
+
return further && item.kind === "search" && !item.saved && item.result?.homeListing !== true
|
|
221
|
+
&& !isUsListingExchange(candidateExchange(item));
|
|
222
|
+
});
|
|
223
|
+
const others = rest.filter((item) => !copies.includes(item));
|
|
224
|
+
// A line with no name of its own (a nameless Buenos Aires DK) is no other company the copies would crowd out.
|
|
225
|
+
const ownName = (item: T) => !!item.result?.name?.trim() && !isPlaceholderLine(item);
|
|
226
|
+
const last = others.findLastIndex((item) => exact(item) && ownName(item));
|
|
227
|
+
const crowding = copies.length > 0 && last >= 0 && rest.indexOf(copies[0]!) < rest.indexOf(others[last]!);
|
|
228
|
+
if (!named.length && !crowding) return items;
|
|
229
|
+
if (crowding) rest = [...others.slice(0, last + 1), ...copies, ...others.slice(last + 1)];
|
|
230
|
+
return [...items.slice(0, at), ...named, ...rest];
|
|
231
|
+
}
|
|
232
|
+
|
|
190
233
|
/** `items` with `home` moved just ahead of `lead`. */
|
|
191
234
|
function moveAhead<T>(items: readonly T[], home: T, lead: T): T[] {
|
|
192
235
|
const rest = items.filter((item) => item !== home);
|
|
@@ -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 } from "./home-listing";
|
|
44
|
+
import { 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";
|
|
@@ -356,7 +356,10 @@ export function buildTickerSearchCandidates({
|
|
|
356
356
|
query,
|
|
357
357
|
);
|
|
358
358
|
const providerItems = createProviderTickerSearchCandidates(filteredProviderResults, tickers, candidateOptions);
|
|
359
|
-
const ranked =
|
|
359
|
+
const ranked = withNamedCompanyAfterUsLead(
|
|
360
|
+
withHomeListingLead(withSuccessorFirst(rankTickerSearchItems([...localItems, ...providerItems], query), query), query),
|
|
361
|
+
query,
|
|
362
|
+
);
|
|
360
363
|
return limitTickerSearchCandidates(companyListingsFirst(assignTickerSearchCategories(ranked, query), query), totalLimit, localLimit);
|
|
361
364
|
}
|
|
362
365
|
|
|
@@ -371,17 +371,17 @@ export function rankTickerSearchItems<T extends Pick<TickerSearchRankableItem, "
|
|
|
371
371
|
const bIssuerRank = exactIssuerRank.get(exactIssuerKey(b)) ?? Number.POSITIVE_INFINITY;
|
|
372
372
|
if (aIssuerRank !== bIssuerRank) return aIssuerRank - bIssuerRank;
|
|
373
373
|
}
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
if (aSaved !== bSaved) return aSaved ? -1 : 1;
|
|
378
|
-
// Rows that answer to the same typed name (GOOGL and GOOG for "Google")
|
|
379
|
-
// keep the order the server gave them rather than the shorter symbol first.
|
|
380
|
-
if (a.symbolMatchRank === 2) {
|
|
374
|
+
// Rows the server sent for the name as typed (GOOGL and GOOG for "Google"; Microsoft, Micron and
|
|
375
|
+
// Microchip for "micro", largest first) keep its order, rather than the shorter name or symbol first.
|
|
376
|
+
if (a.symbolMatchRank === 2 && !isSavedSearchItem(a.item) && !isSavedSearchItem(b.item)) {
|
|
381
377
|
const aProviderRank = a.item.providerRank ?? Number.POSITIVE_INFINITY;
|
|
382
378
|
const bProviderRank = b.item.providerRank ?? Number.POSITIVE_INFINITY;
|
|
383
379
|
if (aProviderRank !== bProviderRank) return aProviderRank - bProviderRank;
|
|
384
380
|
}
|
|
381
|
+
if (b.score !== a.score) return b.score - a.score;
|
|
382
|
+
const aSaved = isSavedSearchItem(a.item);
|
|
383
|
+
const bSaved = isSavedSearchItem(b.item);
|
|
384
|
+
if (aSaved !== bSaved) return aSaved ? -1 : 1;
|
|
385
385
|
if (a.item.label.length !== b.item.label.length) return a.item.label.length - b.item.label.length;
|
|
386
386
|
return a.index - b.index;
|
|
387
387
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { logFailure } from "../utils/log-failure";
|
|
2
2
|
import type { DataProvider } from "../types/data-provider";
|
|
3
|
-
import { canonicalExchange, isUsListingExchange, parsePublicTickerKey } from "../utils/exchanges";
|
|
3
|
+
import { canonicalExchange, isUsListingExchange, isUsOtcVenue, parsePublicTickerKey } from "../utils/exchanges";
|
|
4
4
|
import { sameCompany } from "./company-name";
|
|
5
5
|
import { LISTING_SEARCH_LIMIT } from "./search";
|
|
6
6
|
import { classifyInstrumentKind } from "./search/ranking";
|
|
@@ -15,21 +15,27 @@ export interface UsListing {
|
|
|
15
15
|
/**
|
|
16
16
|
* A company's own listing on a US exchange, found by its name: Sanofi's SNY,
|
|
17
17
|
* Toyota's TM. Funds and contracts that carry its name are not its listing.
|
|
18
|
-
*
|
|
18
|
+
* With `otc`, a line over the counter counts when the company has none on an
|
|
19
|
+
* exchange. Null when search knows no such US line of the company.
|
|
19
20
|
*/
|
|
20
21
|
export async function findUsListingOfCompany(
|
|
21
22
|
dataProvider: Pick<DataProvider, "search">,
|
|
22
23
|
company: string | null | undefined,
|
|
24
|
+
{ otc = false }: { otc?: boolean } = {},
|
|
23
25
|
): Promise<UsListing | null> {
|
|
24
26
|
const name = company?.trim();
|
|
25
27
|
if (!name) return null;
|
|
26
28
|
const results = await dataProvider.search(name, { limit: LISTING_SEARCH_LIMIT }).catch(logFailure("tickers-us-listing", "Could not search US listing", []));
|
|
29
|
+
let overTheCounter: UsListing | null = null;
|
|
27
30
|
for (const result of results) {
|
|
28
31
|
const exchange = canonicalExchange(result.exchange === "SMART" ? result.primaryExchange : result.exchange || result.primaryExchange);
|
|
29
32
|
const kind = classifyInstrumentKind(result.brokerContract?.secType || result.type);
|
|
30
|
-
|
|
33
|
+
const listed = isUsListingExchange(exchange);
|
|
34
|
+
if (!(listed || (otc && isUsOtcVenue(exchange))) || kind === "fund" || kind === "derivative") continue;
|
|
31
35
|
if (!sameCompany(result.name, name) || parsePublicTickerKey(result.symbol).exchange) continue;
|
|
32
|
-
|
|
36
|
+
const line = { symbol: result.symbol.toUpperCase(), exchange, name: result.name };
|
|
37
|
+
if (listed) return line;
|
|
38
|
+
overTheCounter ??= line;
|
|
33
39
|
}
|
|
34
|
-
return
|
|
40
|
+
return overTheCounter;
|
|
35
41
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { resolveAssetDisplayKind } from "../market-data/market/format";
|
|
2
2
|
import { hasValidQuoteObservationTime } from "../market-data/quotes/freshness";
|
|
3
|
+
import { getActiveQuoteDisplay, getRegularSessionDisplay } from "../market-data/market/status";
|
|
3
4
|
import type { HistorySession } from "../types/price-history";
|
|
4
5
|
import { appendLiveQuotePoint, hasUnknownBondHistoryBasis } from "./chart-data";
|
|
5
6
|
import type { LiveBarAccumulator } from "./live-bars";
|
|
@@ -135,6 +136,8 @@ export function baseSecuritySeries(
|
|
|
135
136
|
quoteMetadata: QuoteMetadata | null | undefined = financials.quoteMetadata,
|
|
136
137
|
/** What a futures contract's price counts ("USD / gallon"), from its terms. */
|
|
137
138
|
contractUnit?: string | null,
|
|
139
|
+
/** The bars run into pre-market and after-hours trading. */
|
|
140
|
+
{ extendedHours = false }: { extendedHours?: boolean } = {},
|
|
138
141
|
): ResolvedSeries | null {
|
|
139
142
|
if (spec.source.kind !== "security") return null;
|
|
140
143
|
const field = getTimeSeriesField(spec.source.fieldId);
|
|
@@ -217,10 +220,13 @@ export function baseSecuritySeries(
|
|
|
217
220
|
const listingExchange = canonicalExchange(marketExchange) === "SMART" || usOption
|
|
218
221
|
? canonicalExchange(sessionExchange) || (routedUsListing ? "NYSE" : marketExchange)
|
|
219
222
|
: marketExchange;
|
|
223
|
+
// The move of the price the chart ends on: the regular session's, its close
|
|
224
|
+
// once it is over, as `quote` heads Last; the latest print's, an after-hours
|
|
225
|
+
// one included, where the bars run into extended hours.
|
|
220
226
|
const latestChangePercent = marketField && field.unit.startsWith("currency")
|
|
221
227
|
&& !unknownBondBasis
|
|
222
228
|
&& financials.quote && hasValidQuoteObservationTime(financials.quote)
|
|
223
|
-
? financials.quote.changePercent
|
|
229
|
+
? (extendedHours ? getActiveQuoteDisplay(financials.quote) : getRegularSessionDisplay(financials.quote))?.changePercent
|
|
224
230
|
: undefined;
|
|
225
231
|
const priceIssues = valuationPriceIssues(financials, spec.source);
|
|
226
232
|
// A source with closes only, such as a generic future, has flat bars (open,
|
|
@@ -129,6 +129,8 @@ function currentDerivedValuation(
|
|
|
129
129
|
))
|
|
130
130
|
.at(-1)?.candidate;
|
|
131
131
|
if (!statement) return null;
|
|
132
|
+
// A P/E `valuation` withdraws (utils/share-multiples) is withdrawn here too, never read again as the price over EPS.
|
|
133
|
+
if (metric === "trailingPE" && financials.fundamentals?.notMeaningful?.trailingPE) return { value: null, date: current.date, statement };
|
|
132
134
|
// The listing's EV needs no price in the statement's currency: an ADR's converts the statement instead.
|
|
133
135
|
const listing = listingEnterpriseMultiple(financials, statement, metric);
|
|
134
136
|
if (listing !== undefined) return { value: listing, date: current.date, statement };
|
|
@@ -202,6 +204,12 @@ function currentValuation(financials: TickerFinancials, period: SeriesPeriod | u
|
|
|
202
204
|
*/
|
|
203
205
|
export function valuationNotMeaningful(financials: TickerFinancials, source: SecuritySeriesSource): { reason: string; asOf: string } | undefined {
|
|
204
206
|
const [namespace, metric = ""] = canonicalTimeSeriesFieldId(source.fieldId).split(".");
|
|
207
|
+
if (namespace === "valuation" && (metric === "trailingPE" || metric === "forwardPE" || metric === "pegRatio")) {
|
|
208
|
+
const reason = financials.fundamentals?.notMeaningful?.[metric];
|
|
209
|
+
const asOf = financials.fundamentals?.trailingEpsPeriodEnd
|
|
210
|
+
?? [...financials.quarterlyStatements, ...financials.annualStatements].map((row) => row.date).sort().at(-1);
|
|
211
|
+
return reason && asOf ? { reason: reason[0]!.toUpperCase() + reason.slice(1), asOf: asOf.slice(0, 10) } : undefined;
|
|
212
|
+
}
|
|
205
213
|
if (namespace !== "valuation" || metric !== "evEbitda") return undefined;
|
|
206
214
|
// A daily series ends on the trailing twelve months, as its current point does.
|
|
207
215
|
const period = source.period === "daily" || source.period === "auto" || !source.period ? "ttm" : source.period;
|
|
@@ -8,6 +8,7 @@ import { createValuationCurrencyContext } from "../valuation-currency";
|
|
|
8
8
|
import { valuationPriceAtOrBefore, valuationQuoteIssue, type ValuationPriceIssue } from "../valuation-price";
|
|
9
9
|
import type { SecuritySeriesSource, TimeSeriesPoint } from "../types";
|
|
10
10
|
import { isBankOrInsurerIndustry } from "../../utils/ebitda";
|
|
11
|
+
import { notTheShare } from "../../utils/share-multiples";
|
|
11
12
|
import { currentDerivedValuationPoint, currentValuationStatements, providerCurrentValuationPoint } from "./current-valuation";
|
|
12
13
|
import { dailyStatementValuation, dailyValuationFallbackPeriod, historicalValuation } from "./historical-valuation";
|
|
13
14
|
import { FUNDAMENTAL_IDS, QUOTE_DERIVED_VALUATION_IDS, VALUATION_IDS, valuationSeriesUsesLiveQuote } from "./metric-ids";
|
|
@@ -16,6 +17,9 @@ import { sourceStatements } from "./source-statements";
|
|
|
16
17
|
import { fundamentalValue, metricAvailability } from "./statement-fields";
|
|
17
18
|
import { valuationAtPrice } from "./valuation-multiples";
|
|
18
19
|
|
|
20
|
+
/** The multiples of a share's price over its company's earnings (notTheShare withdraws them). */
|
|
21
|
+
const SHARE_PRICE_EARNINGS = new Set(["trailingPE", "forwardPE", "realizedNtmPE", "pegRatio"]);
|
|
22
|
+
|
|
19
23
|
/** Extracts the selected statement snapshot, retaining known availability dates without reconstructing prior vintages. */
|
|
20
24
|
export function extractFundamentalSeries(
|
|
21
25
|
financials: TickerFinancials | null,
|
|
@@ -49,6 +53,8 @@ export function extractFundamentalSeries(
|
|
|
49
53
|
}
|
|
50
54
|
|
|
51
55
|
if (namespace !== "valuation" || !VALUATION_IDS.has(metric)) return [];
|
|
56
|
+
// A warrant's, a right's, a unit's or an unratioed receipt's price over its company's EPS is no P/E at any date.
|
|
57
|
+
if (SHARE_PRICE_EARNINGS.has(metric) && notTheShare(financials)) return [];
|
|
52
58
|
// A bank's or an insurer's EBITDA measures nothing: its EV/EBITDA is N/M throughout (valuationNotMeaningful).
|
|
53
59
|
if (metric === "evEbitda" && isBankOrInsurerIndustry(financials.profile?.industry)) return [];
|
|
54
60
|
const fallback = dailyValuationFallbackPeriod(financials, source);
|
|
@@ -6,7 +6,7 @@ import type { ChartSeriesSpec, ChartSpec, SecuritySeriesSource } from "./types";
|
|
|
6
6
|
import { activeStudyInputSeriesIds } from "./studies/resolve";
|
|
7
7
|
import { withFormulaNextMonths } from "./formula-months";
|
|
8
8
|
import { valuationSeriesUsesLiveQuote } from "./fundamentals";
|
|
9
|
-
import { hasValidQuoteObservationTime } from "../market-data/quotes/freshness";
|
|
9
|
+
import { hasValidQuoteObservationTime, quoteStampBucket } from "../market-data/quotes/freshness";
|
|
10
10
|
import type { InstrumentRef } from "../market-data/request-types";
|
|
11
11
|
import type { QueryEntry } from "../market-data/result-types";
|
|
12
12
|
import { buildQuoteKey, instrumentFromQuoteTarget, resolveEntryData } from "../market-data/selectors";
|
|
@@ -105,19 +105,13 @@ function isNewerQuote(next: Quote, current: Quote | undefined): boolean {
|
|
|
105
105
|
&& (next.stale === true) !== (current.stale === true));
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
-
/** Every chart bar boundary, intraday or calendar, is a whole minute. */
|
|
109
|
-
const QUOTE_TIME_BUCKET_MS = 60_000;
|
|
110
|
-
|
|
111
|
-
function quoteTimeBucket(quote: Quote): number {
|
|
112
|
-
return Number.isFinite(quote.lastUpdated) ? Math.floor(quote.lastUpdated / QUOTE_TIME_BUCKET_MS) : Number.NaN;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
108
|
function hasResolutionRelevantChange(next: Quote, current: Quote | undefined): boolean {
|
|
116
109
|
if (!current) return true;
|
|
117
110
|
// Bid/ask updates restamp a quote many times a second without moving its
|
|
118
111
|
// price or volume. The stamp alone matters only when it crosses into
|
|
119
112
|
// another minute, where it can open a bar at the same price.
|
|
120
|
-
|
|
113
|
+
// Every chart bar boundary, intraday or calendar, is a whole minute (quoteStampBucket).
|
|
114
|
+
return !Object.is(quoteStampBucket(next), quoteStampBucket(current))
|
|
121
115
|
|| next.price !== current.price
|
|
122
116
|
|| next.volume !== current.volume
|
|
123
117
|
|| next.stale !== current.stale
|
|
@@ -1033,6 +1033,7 @@ async function resolveChartSpecPass(
|
|
|
1033
1033
|
history?.resolution,
|
|
1034
1034
|
quoteMetadata,
|
|
1035
1035
|
contractUnit,
|
|
1036
|
+
{ extendedHours: history?.extendedHours === true },
|
|
1036
1037
|
);
|
|
1037
1038
|
if (!base) throw new Error(`Unknown field ${source.fieldId}.`);
|
|
1038
1039
|
let result = builtBars ? withBuiltBarSize(base, builtBars) : base;
|
package/src/types/financials.ts
CHANGED
|
@@ -414,6 +414,12 @@ export interface Fundamentals extends DepositaryReceiptFacts {
|
|
|
414
414
|
epsCurrency?: string;
|
|
415
415
|
/** Set when `trailingPE` divides the price by the trailing EPS converted from another currency. */
|
|
416
416
|
trailingPEConversion?: TrailingPEConversion;
|
|
417
|
+
/**
|
|
418
|
+
* What the trailing EPS was worked out from where Gloom Cloud did not take
|
|
419
|
+
* its source's: `statements` (net income over shares), `home` (a receipt's
|
|
420
|
+
* home line, per receipt), `cpo` (a CPO line's company, per CPO).
|
|
421
|
+
*/
|
|
422
|
+
trailingEpsBasis?: "statements" | "home" | "cpo";
|
|
417
423
|
/** Provider-reported issuer market cap; marketCapCurrency identifies its units when known. */
|
|
418
424
|
marketCap?: number;
|
|
419
425
|
marketCapCurrency?: string;
|
|
@@ -475,6 +481,12 @@ export interface Fundamentals extends DepositaryReceiptFacts {
|
|
|
475
481
|
*/
|
|
476
482
|
trailingEpsSource?: "filed-quarters" | "served";
|
|
477
483
|
trailingEpsPeriodEnd?: string;
|
|
484
|
+
/**
|
|
485
|
+
* Why a multiple is withdrawn though its figures are numbers (utils/share-multiples): a warrant's price over its
|
|
486
|
+
* company's EPS, a receipt's with no ratio on record, an EPS that is not net income over the shares. The multiple
|
|
487
|
+
* itself is absent; every view reads it as N/M with this reason.
|
|
488
|
+
*/
|
|
489
|
+
notMeaningful?: Partial<Record<"trailingPE" | "forwardPE" | "pegRatio", string>>;
|
|
478
490
|
operatingMargin?: number;
|
|
479
491
|
profitMargin?: number;
|
|
480
492
|
revenueGrowth?: number;
|
|
@@ -1170,6 +1182,14 @@ export interface PricePoint {
|
|
|
1170
1182
|
rescaled?: number;
|
|
1171
1183
|
/** A continuous future's bar (NG=F): the contract it closes on (NGZ26). A change from the bar before is a roll. */
|
|
1172
1184
|
contract?: string;
|
|
1185
|
+
/** A currency pair's daily bar whose source repeated its open as its close: the close is the next session's open. */
|
|
1186
|
+
closeRebuilt?: boolean;
|
|
1187
|
+
/**
|
|
1188
|
+
* A currency pair's daily bar whose source repeated its open as its close, which no next open in its week rebuilds
|
|
1189
|
+
* (none, or one over 5% away): its close is no day's close, and returns leave the bar out
|
|
1190
|
+
* (pricePointCloseCopied).
|
|
1191
|
+
*/
|
|
1192
|
+
closeCopied?: boolean;
|
|
1173
1193
|
}
|
|
1174
1194
|
|
|
1175
1195
|
export interface StatementHistoryAttempt {
|
package/src/types/headless.ts
CHANGED
|
@@ -823,6 +823,15 @@ export interface HeadlessPaneDefinition<Shape extends HeadlessPaneShape = Headle
|
|
|
823
823
|
* in the US never shows that company's numbers.
|
|
824
824
|
*/
|
|
825
825
|
usListingsOnly?: string;
|
|
826
|
+
/**
|
|
827
|
+
* The data covers US over-the-counter lines too (FINRA's short interest
|
|
828
|
+
* and weekly off-exchange volume, the SEC's fails to deliver, daily
|
|
829
|
+
* closes), so a listing abroad is offered its company's OTC line when it
|
|
830
|
+
* has no US exchange listing (Tencent's TCEHY for 0700.HK). Without it
|
|
831
|
+
* only exchange listings are offered, as options, trades and FINRA's
|
|
832
|
+
* daily short volume cover no OTC line.
|
|
833
|
+
*/
|
|
834
|
+
usListingsOtc?: boolean;
|
|
826
835
|
/**
|
|
827
836
|
* A sentence that answer adds for a listing abroad, after its US listing:
|
|
828
837
|
* where to read the nearest data the function has for it (time and sales
|
package/src/ui/host.tsx
CHANGED
|
@@ -167,6 +167,8 @@ interface ScrollBarRenderable {
|
|
|
167
167
|
visible: boolean;
|
|
168
168
|
/** Terminal only: whether a click on the bar moves the keyboard focus to it. */
|
|
169
169
|
focusable?: boolean;
|
|
170
|
+
/** Terminal only: shows the bar again while the content overflows, after `visible` was set. */
|
|
171
|
+
resetVisibilityControl?(): void;
|
|
170
172
|
on?(event: "change", handler: () => void): void;
|
|
171
173
|
off?(event: "change", handler: () => void): void;
|
|
172
174
|
}
|
|
@@ -204,6 +206,8 @@ export interface InputRenderable {
|
|
|
204
206
|
setCursorOffset?(offset: number): void;
|
|
205
207
|
focus?(): void;
|
|
206
208
|
blur?(): void;
|
|
209
|
+
/** Whether the field has the keyboard now: the keys typed go to it. */
|
|
210
|
+
readonly focused?: boolean;
|
|
207
211
|
}
|
|
208
212
|
|
|
209
213
|
export interface TextareaRenderable extends InputRenderable {
|
|
@@ -265,6 +269,20 @@ export interface NativePaneImage {
|
|
|
265
269
|
cells?: { cols: number; rows: number; cells: NativeFrameCell[] };
|
|
266
270
|
}
|
|
267
271
|
|
|
272
|
+
/**
|
|
273
|
+
* What the frame on screen drew on top, cell by cell: kitty images are drawn
|
|
274
|
+
* out of band, so the terminal image layer reads this to keep each image under
|
|
275
|
+
* whatever covers it.
|
|
276
|
+
*/
|
|
277
|
+
export interface NativeFrameHits {
|
|
278
|
+
/** The renderable drawn last at a cell of the frame on screen, or null. */
|
|
279
|
+
at(x: number, y: number): unknown;
|
|
280
|
+
/** Whether a renderable fills its cells (a background), rather than only grouping or writing over others. */
|
|
281
|
+
paints(renderable: unknown): boolean;
|
|
282
|
+
/** Whether a renderable is still in the tree the terminal draws. */
|
|
283
|
+
attached(renderable: unknown): boolean;
|
|
284
|
+
}
|
|
285
|
+
|
|
268
286
|
/** The last frame the terminal renderer drew, as styled rows. */
|
|
269
287
|
export interface NativeFrameCapture {
|
|
270
288
|
cols: number;
|
|
@@ -302,6 +320,8 @@ export interface NativeRendererHost {
|
|
|
302
320
|
removePostProcessFn?(processFn: NativePostProcessFn): void;
|
|
303
321
|
/** Terminal renderers only. Kitty graphics are drawn out of band and come back as blank cells. */
|
|
304
322
|
captureFrame?(): NativeFrameCapture | null;
|
|
323
|
+
/** Terminal renderers only: what each cell of the frame on screen drew on top. */
|
|
324
|
+
frameHits?: NativeFrameHits;
|
|
305
325
|
/**
|
|
306
326
|
* Terminal renderers only: a PNG of a rectangle of the frame shown now, in
|
|
307
327
|
* cells, its characters drawn in a bundled font and its kitty images put back.
|
package/src/ui/pointer-drag.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
if (!renderable) return;
|
|
1
|
+
function setCapture(renderer: unknown, renderable: unknown): void {
|
|
3
2
|
const hostCapture = (renderer as { captureMouseRenderable?: (target: unknown) => void }).captureMouseRenderable;
|
|
4
3
|
if (typeof hostCapture === "function") {
|
|
5
4
|
hostCapture.call(renderer, renderable);
|
|
@@ -10,3 +9,13 @@ export function capturePointerDrag(renderer: unknown, renderable: unknown): void
|
|
|
10
9
|
capture.call(renderer, renderable);
|
|
11
10
|
}
|
|
12
11
|
}
|
|
12
|
+
|
|
13
|
+
export function capturePointerDrag(renderer: unknown, renderable: unknown): void {
|
|
14
|
+
if (!renderable) return;
|
|
15
|
+
setCapture(renderer, renderable);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Ends a capture whose release never came (the button let go outside the window), so the next press goes where it lands. */
|
|
19
|
+
export function releasePointerDrag(renderer: unknown): void {
|
|
20
|
+
setCapture(renderer, undefined);
|
|
21
|
+
}
|
package/src/utils/exchanges.ts
CHANGED
|
@@ -177,21 +177,26 @@ export function usShareClassSpellings(symbol: string, exchange?: string | null):
|
|
|
177
177
|
return [`${match[1]}.${match[2]}`, `${match[1]}-${match[2]}`, `${match[1]}/${match[2]}`];
|
|
178
178
|
}
|
|
179
179
|
|
|
180
|
+
/** Canonical US over-the-counter venues: OTC, and the OTC Markets tiers' listing codes. */
|
|
181
|
+
const US_OTC_EXCHANGES: ReadonlySet<string> = new Set(["OTC", "PINK", "PNK", "OQB", "OQX", "OEM", "OBB"]);
|
|
182
|
+
|
|
180
183
|
/** Canonical US equity venues: the listing exchanges plus other lit and OTC venues. */
|
|
181
184
|
const US_EQUITY_EXCHANGES: ReadonlySet<string> = new Set([
|
|
182
185
|
...US_LISTING_EXCHANGES,
|
|
183
186
|
"BYX",
|
|
184
187
|
"IEX",
|
|
185
|
-
|
|
186
|
-
"PINK",
|
|
187
|
-
// Listing codes for the OTC Markets tiers.
|
|
188
|
-
"PNK",
|
|
189
|
-
"OQB",
|
|
190
|
-
"OQX",
|
|
191
|
-
"OEM",
|
|
192
|
-
"OBB",
|
|
188
|
+
...US_OTC_EXCHANGES,
|
|
193
189
|
]);
|
|
194
190
|
|
|
191
|
+
/**
|
|
192
|
+
* A US over-the-counter venue, by its code (OTC, PNK, OQX) or as a quote
|
|
193
|
+
* names it ("OTC MARKETS OTCPK" for TCEHY, "Other OTC").
|
|
194
|
+
*/
|
|
195
|
+
export function isUsOtcVenue(value?: string): boolean {
|
|
196
|
+
const venue = canonicalExchange(value);
|
|
197
|
+
return US_OTC_EXCHANGES.has(venue) || /^(?:OTC MARKETS\b|OTCPK$|OTCQX$|OTCQB$|PINX$|OTHER OTC$)/.test(venue);
|
|
198
|
+
}
|
|
199
|
+
|
|
195
200
|
/** A US venue a stock or fund trades on, listed or over the counter. */
|
|
196
201
|
export function isUsEquityExchange(value?: string): boolean {
|
|
197
202
|
return US_EQUITY_EXCHANGES.has(canonicalExchange(value));
|
|
@@ -572,11 +572,22 @@ export function trailingEpsSourceNote(
|
|
|
572
572
|
|
|
573
573
|
type PriceEarningsBasis = Pick<Fundamentals, "financialCurrency" | "ttmConversion" | "epsCurrency" | "trailingPEConversion">;
|
|
574
574
|
|
|
575
|
-
/** The
|
|
576
|
-
|
|
575
|
+
/** The minor units a quote can be priced in, as Gloom Cloud reads them: pence, South African cents and agorot. */
|
|
576
|
+
const MINOR_QUOTE_UNITS = new Set(["GBp", "GBX", "ZAc", "ZAC", "ILA"]);
|
|
577
|
+
|
|
578
|
+
/**
|
|
579
|
+
* The trailing EPS in the price's currency and unit: converted at the rate the served P/E used when it says so, a
|
|
580
|
+
* rate into the major unit, so a price in pence, South African cents or agorot takes it a hundredfold (30,000 ILA
|
|
581
|
+
* over 2.50 USD at 3.7037 ILS is 32.4, not 3,240).
|
|
582
|
+
*/
|
|
583
|
+
export function priceEarningsEps(
|
|
584
|
+
fundamentals: Pick<Fundamentals, "eps" | "trailingPEConversion"> | undefined,
|
|
585
|
+
quoteCurrency?: string | null,
|
|
586
|
+
): number | undefined {
|
|
577
587
|
const eps = fundamentals?.eps;
|
|
578
588
|
const rate = fundamentals?.trailingPEConversion?.rate;
|
|
579
|
-
|
|
589
|
+
if (typeof eps !== "number" || typeof rate !== "number" || !Number.isFinite(rate) || !(rate > 0)) return eps;
|
|
590
|
+
return eps * rate * (MINOR_QUOTE_UNITS.has(quoteCurrency?.trim() ?? "") ? 100 : 1);
|
|
580
591
|
}
|
|
581
592
|
|
|
582
593
|
/**
|
|
@@ -61,20 +61,27 @@ type PriceEarningsField = "trailingPE" | "forwardPE" | "pegRatio";
|
|
|
61
61
|
|
|
62
62
|
/**
|
|
63
63
|
* Why each earnings multiple of a fundamentals block is not meaningful, if it
|
|
64
|
-
* is not:
|
|
65
|
-
*
|
|
66
|
-
*
|
|
64
|
+
* is not: one withdrawn as no multiple of the share (`notMeaningful`,
|
|
65
|
+
* utils/share-multiples: a warrant, a receipt with no ratio, an EPS that is
|
|
66
|
+
* not net income over the shares), a trailing or forward EPS at or below
|
|
67
|
+
* zero, or a multiple that is itself at or below zero. Forward P/E is judged
|
|
68
|
+
* on its own estimate only, so a trailing loss leaves a positive forward
|
|
69
|
+
* multiple alone.
|
|
67
70
|
*/
|
|
68
71
|
export function notMeaningfulMultiples(
|
|
69
|
-
fundamentals: Pick<Fundamentals, PriceEarningsField | "eps" | "forwardEps"> | undefined,
|
|
72
|
+
fundamentals: Pick<Fundamentals, PriceEarningsField | "eps" | "forwardEps" | "notMeaningful"> | undefined,
|
|
70
73
|
): Partial<Record<PriceEarningsField, string>> {
|
|
71
|
-
const reasons: Partial<Record<PriceEarningsField, string>> = {};
|
|
74
|
+
const reasons: Partial<Record<PriceEarningsField, string>> = { ...fundamentals?.notMeaningful };
|
|
72
75
|
if (!fundamentals) return reasons;
|
|
73
|
-
if (
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
if (
|
|
76
|
+
if (!reasons.trailingPE) {
|
|
77
|
+
if (nonPositive(fundamentals.eps)) reasons.trailingPE = "trailing EPS is not positive";
|
|
78
|
+
else if (nonPositive(fundamentals.trailingPE)) reasons.trailingPE = "trailing earnings are not positive";
|
|
79
|
+
}
|
|
80
|
+
if (!reasons.forwardPE) {
|
|
81
|
+
if (nonPositive(fundamentals.forwardEps)) reasons.forwardPE = "forward EPS is not positive";
|
|
82
|
+
else if (nonPositive(fundamentals.forwardPE)) reasons.forwardPE = "forward earnings are not positive";
|
|
83
|
+
}
|
|
84
|
+
if (!reasons.pegRatio && nonPositive(fundamentals.pegRatio)) reasons.pegRatio = "P/E or expected growth is not positive";
|
|
78
85
|
return reasons;
|
|
79
86
|
}
|
|
80
87
|
|
|
@@ -61,6 +61,21 @@ export function pricePointIntegrityFlags(point: PricePoint): string[] {
|
|
|
61
61
|
/** What a bar whose open alone contradicts its range is flagged with, in `history` and HP. */
|
|
62
62
|
export const OPEN_WITHHELD_FLAG = "open withheld";
|
|
63
63
|
|
|
64
|
+
/** A currency pair's bar whose close the server rebuilt from the next session's open: the source repeated its open as its close. */
|
|
65
|
+
export const CLOSE_REBUILT_FLAG = "close rebuilt";
|
|
66
|
+
/** A currency pair's bar whose source repeated its open as its close, which no next open in its week rebuilds. */
|
|
67
|
+
export const CLOSE_COPIED_FLAG = "close copied";
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Whether a bar's close is its source's copy of its open, which no next open
|
|
71
|
+
* in its week rebuilds (a Friday's, or one the next open is outside the range
|
|
72
|
+
* of): no day's close. A return into or out of it is no day's move, so
|
|
73
|
+
* return-based functions leave the bar out.
|
|
74
|
+
*/
|
|
75
|
+
export function pricePointCloseCopied(point: Pick<PricePoint, "closeCopied">): boolean {
|
|
76
|
+
return point.closeCopied === true;
|
|
77
|
+
}
|
|
78
|
+
|
|
64
79
|
/**
|
|
65
80
|
* Whether a bar's open alone contradicts its range: above its high or under
|
|
66
81
|
* its low, while the high, low and close agree. MTN on the JSE, 30 Oct 2026:
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reason codes are a data service's words for a machine: why it has nothing
|
|
3
|
+
* (NO_DATA, NOT_FOUND) or could not answer (UPSTREAM_ERROR, TIMEOUT). An
|
|
4
|
+
* error built from such an answer often carries one as its whole message, or
|
|
5
|
+
* after a symbol ("AAPL: UPSTREAM_ERROR"). Nothing shows one as it is: the
|
|
6
|
+
* shared states, table bodies, pane footers and the CLI read text through
|
|
7
|
+
* here, the one place a code becomes words.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
const BUSY = "the source is busy, try again shortly";
|
|
11
|
+
const NO_ANSWER = "the source did not answer";
|
|
12
|
+
|
|
13
|
+
/** What each code the data service sends means, as a clause. */
|
|
14
|
+
const CLAUSES: Readonly<Record<string, string>> = {
|
|
15
|
+
UPSTREAM_ERROR: NO_ANSWER,
|
|
16
|
+
SOURCE_REFUSED_STORED_COPY: NO_ANSWER,
|
|
17
|
+
TIMEOUT: "the source timed out",
|
|
18
|
+
RATE_LIMITED: BUSY,
|
|
19
|
+
UPSTREAM_RATE_LIMIT: BUSY,
|
|
20
|
+
NO_DATA: "no data",
|
|
21
|
+
NOT_FOUND: "nothing found",
|
|
22
|
+
BAD_MAPPING: "nothing found",
|
|
23
|
+
UNSUPPORTED_RANGE: "not available for this range",
|
|
24
|
+
PRO_REQUIRED: "needs Gloom Pro",
|
|
25
|
+
STALE_HISTORY: "the source's history is behind",
|
|
26
|
+
MALFORMED_HISTORY: "the source's history could not be read",
|
|
27
|
+
HISTORY_RETENTION: "older than the history kept",
|
|
28
|
+
AMBIGUOUS_TICKER: "the symbol is listed in several places, name the exchange",
|
|
29
|
+
AMBIGUOUS_EXCHANGE: "the symbol is listed in several places, name the exchange",
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
// Capitals joined by underscores, the shape of every code the service sends but TIMEOUT.
|
|
33
|
+
const CODE_SHAPE = /^[A-Z][A-Z0-9]*(?:_[A-Z0-9]+)+$/;
|
|
34
|
+
// A known code, or a source's failure (YAHOO_RATE_LIMIT, ..._ERROR), inside a longer text.
|
|
35
|
+
const EMBEDDED_CODE = /\b[A-Z][A-Z0-9]*(?:_[A-Z0-9]+)+\b/g;
|
|
36
|
+
|
|
37
|
+
/** Whether `text` is a reason code on its own (UPSTREAM_ERROR), not words. */
|
|
38
|
+
export function isReasonCode(text: string | null | undefined): boolean {
|
|
39
|
+
const trimmed = text?.trim() ?? "";
|
|
40
|
+
return Object.hasOwn(CLAUSES, trimmed) || CODE_SHAPE.test(trimmed);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* What a reason code says happened, as a clause to follow a colon or stand in
|
|
45
|
+
* a footer: "the source did not answer". An unknown code reads as a failure.
|
|
46
|
+
*/
|
|
47
|
+
function reasonCodeClause(code: string): string {
|
|
48
|
+
const trimmed = code.trim();
|
|
49
|
+
if (Object.hasOwn(CLAUSES, trimmed)) return CLAUSES[trimmed]!;
|
|
50
|
+
if (/RATE_?LIMIT/.test(trimmed)) return BUSY;
|
|
51
|
+
if (/TIMEOUT|TIMED_OUT/.test(trimmed)) return CLAUSES.TIMEOUT!;
|
|
52
|
+
if (/NOT_FOUND$/.test(trimmed)) return CLAUSES.NOT_FOUND!;
|
|
53
|
+
return NO_ANSWER;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function embeddedCode(token: string): boolean {
|
|
57
|
+
return Object.hasOwn(CLAUSES, token) || /(?:_ERROR|RATE_?LIMIT)$/.test(token);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function withEmbeddedCodes(text: string): string {
|
|
61
|
+
return text.replace(EMBEDDED_CODE, (token) => embeddedCode(token) ? reasonCodeClause(token) : token);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Text fit to show as a state's title or a CLI error: a bare reason code as
|
|
66
|
+
* a sentence ("The source did not answer."), a known code inside a longer
|
|
67
|
+
* text as its clause ("AAPL: the source did not answer"), anything else as
|
|
68
|
+
* it is.
|
|
69
|
+
*/
|
|
70
|
+
export function readableError(text: string): string {
|
|
71
|
+
if (!isReasonCode(text)) return withEmbeddedCodes(text);
|
|
72
|
+
const clause = reasonCodeClause(text);
|
|
73
|
+
return `${clause.charAt(0).toUpperCase()}${clause.slice(1)}.`;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** The same for a footer status, which reads as a clause: "the source did not answer". */
|
|
77
|
+
export function readableStatus(text: string): string {
|
|
78
|
+
return isReasonCode(text) ? reasonCodeClause(text) : withEmbeddedCodes(text);
|
|
79
|
+
}
|