gloomberb 0.20.13 → 0.20.16
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/index.ts +54 -0
- package/src/api-client/install-experiments.ts +8 -7
- package/src/api-client/money-markets.ts +7 -0
- package/src/api-client/paths.ts +2 -1
- package/src/api-client/product-waitlist.ts +63 -0
- package/src/api-client/request.ts +16 -4
- package/src/api-client/types/billing.ts +45 -0
- package/src/api-client/yearly-plan.ts +132 -0
- package/src/app/global-shortcuts.ts +5 -3
- package/src/app/pane-runtime/index.tsx +2 -2
- package/src/app/pane-runtime/plugin-bindings.ts +3 -1
- package/src/app/pane-runtime/ticker-open-runtime.ts +6 -1
- package/src/app/since-last-visit/keys.ts +26 -0
- package/src/app/since-last-visit/model.ts +266 -0
- package/src/app/since-last-visit/strip.tsx +193 -0
- package/src/app/since-last-visit/use-since-last-visit.ts +289 -0
- package/src/app/since-last-visit/visit-tracker.ts +191 -0
- package/src/app.tsx +15 -0
- 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 +103 -27
- package/src/cli/commands/overview.ts +18 -4
- package/src/cli/commands/system.ts +29 -1
- package/src/cli/commands/ticker.ts +12 -5
- package/src/cli/desktop-pane-shot-api-policy.ts +4 -1
- package/src/cli/desktop-pane-shot-browser.ts +2 -1
- package/src/cli/desktop-pane-shot-view.ts +3 -7
- package/src/cli/desktop-pane-shot.ts +26 -28
- package/src/cli/errors.ts +3 -1
- package/src/cli/freshness.ts +7 -2
- package/src/cli/glossary.ts +10 -5
- package/src/cli/help.ts +1 -0
- package/src/cli/helpers.ts +8 -16
- package/src/cli/history-export.ts +4 -0
- package/src/cli/history-rows.ts +24 -0
- package/src/cli/index.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/options.ts +29 -1
- package/src/cli/pane-functions/catalog.ts +70 -12
- package/src/cli/pane-functions/function-help.ts +1 -1
- package/src/cli/pane-functions/headless.ts +68 -3
- package/src/cli/pane-functions/index.ts +2 -2
- package/src/cli/pane-functions/options.ts +7 -0
- package/src/cli/pane-functions/resolver.ts +104 -15
- package/src/cli/pane-functions/screenshot-payload.ts +3 -0
- package/src/cli/report-tables.ts +20 -5
- package/src/cli/result.ts +22 -4
- package/src/cli/shot-temp-dir.ts +30 -0
- package/src/cli/suffixed-listing-rows.ts +11 -0
- 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/composite-chart.tsx +3 -3
- 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/commands/direct/index.ts +31 -8
- package/src/components/command-bar/commands/registry.ts +7 -0
- package/src/components/command-bar/routes/root/command-items.ts +8 -0
- package/src/components/command-bar/routes/root/results.ts +19 -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/company-logo.tsx +10 -3
- package/src/components/data-table/sections.ts +6 -1
- package/src/components/layout/pane/title.ts +16 -6
- package/src/components/layout/shell/index.tsx +5 -1
- package/src/components/layout/shell/ticker-link-menu.ts +12 -9
- 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/ticker/badge/format.ts +12 -3
- package/src/components/ticker/badge/index.tsx +9 -3
- package/src/components/ticker/list-table-view.tsx +119 -17
- package/src/components/ui/choice-dialog.tsx +1 -1
- package/src/components/ui/confirm-dialog.tsx +3 -2
- package/src/components/ui/data-table/display-columns.ts +16 -0
- package/src/components/ui/data-table/index.tsx +40 -9
- package/src/components/ui/data-table/types.ts +14 -0
- 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/core/state/app/layout-reducer.ts +3 -1
- package/src/core/state/app/layout.ts +2 -2
- package/src/data/config/layout.ts +14 -0
- package/src/data/config/store/normalize.ts +11 -1
- package/src/docs/snapshot.json +2 -2
- package/src/i18n/es.ts +39 -0
- package/src/i18n/ja.ts +39 -0
- package/src/i18n/ko.ts +39 -0
- package/src/i18n/zh-cn.ts +39 -0
- package/src/i18n/zh-tw.ts +39 -0
- package/src/layout/pane-follow.ts +141 -4
- package/src/layout/pane-layout-move.ts +10 -7
- package/src/layout/ticker-navigation.ts +13 -19
- package/src/layout/ticker-retarget.ts +3 -2
- package/src/market-data/market/format.ts +35 -1
- package/src/market-data/market/index-level.ts +19 -0
- 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/keyboard.ts +14 -0
- package/src/plugins/builtin/account-management/model.ts +2 -0
- package/src/plugins/builtin/account-management/pane.tsx +79 -7
- package/src/plugins/builtin/account-management/password-dialog.tsx +2 -2
- package/src/plugins/builtin/account-management/payment-recovery-row.tsx +97 -0
- package/src/plugins/builtin/account-management/yearly-plan-row.tsx +359 -0
- 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/awards/pane.tsx +6 -8
- package/src/plugins/builtin/changelog/index.tsx +6 -44
- package/src/plugins/builtin/changelog/versions.ts +17 -68
- 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/askg/executor.ts +2 -1
- package/src/plugins/builtin/cloud/askg/sources.ts +2 -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 +4 -2
- 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/debt-maturities/model.ts +1 -1
- 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/board-table.ts +1 -1
- package/src/plugins/builtin/earnings/board.tsx +36 -16
- package/src/plugins/builtin/earnings/highlight.ts +47 -0
- package/src/plugins/builtin/earnings/history-table.ts +9 -1
- package/src/plugins/builtin/earnings/index.tsx +1 -1
- package/src/plugins/builtin/earnings-calls/pane.tsx +2 -2
- 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/estimate-revisions/model.ts +1 -1
- package/src/plugins/builtin/exposure/index.tsx +1 -1
- package/src/plugins/builtin/macro-day/headless.ts +21 -10
- package/src/plugins/builtin/macro-day/model.ts +42 -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/market-valuation/detail.tsx +3 -3
- package/src/plugins/builtin/market-valuation/headless.ts +11 -4
- package/src/plugins/builtin/market-valuation/pane.tsx +3 -1
- package/src/plugins/builtin/market-valuation/view.ts +14 -0
- 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/news/wire/news/detail-view.tsx +20 -8
- package/src/plugins/builtin/pe-band/pane.tsx +1 -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/render.ts +8 -1
- package/src/plugins/builtin/portfolio-list/cli/watchlist-command.ts +178 -17
- package/src/plugins/builtin/portfolio-list/headless.ts +33 -6
- package/src/plugins/builtin/portfolio-list/pane/groups.tsx +220 -0
- package/src/plugins/builtin/portfolio-list/pane/index.tsx +95 -18
- 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 +38 -16
- package/src/plugins/builtin/research/corporate-actions-pane.tsx +4 -2
- package/src/plugins/builtin/research/relative-valuation-headless.ts +15 -5
- package/src/plugins/builtin/research/relative-valuation-model.ts +7 -1
- package/src/plugins/builtin/research/relative-valuation-pane.tsx +7 -4
- 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/shared/headless-options.ts +1 -1
- package/src/plugins/builtin/social-mentions/model.ts +2 -2
- package/src/plugins/builtin/thirteenf/pane.tsx +1 -1
- package/src/plugins/builtin/ticker-detail/adr-pair/headless.ts +45 -2
- package/src/plugins/builtin/ticker-detail/financials/model.ts +51 -16
- package/src/plugins/builtin/ticker-detail/financials/nopat.ts +16 -0
- package/src/plugins/builtin/ticker-detail/financials/ratios.ts +44 -13
- package/src/plugins/builtin/ticker-detail/financials/schema.ts +33 -2
- package/src/plugins/builtin/ticker-detail/financials/tab.tsx +4 -2
- package/src/plugins/builtin/ticker-detail/headless-schema.ts +30 -4
- package/src/plugins/builtin/ticker-detail/headless.ts +280 -35
- package/src/plugins/builtin/ticker-detail/overview/components.tsx +4 -5
- package/src/plugins/builtin/ticker-detail/overview/model.ts +9 -2
- package/src/plugins/builtin/ticker-detail/overview-tab.tsx +10 -2
- package/src/plugins/builtin/ticker-detail/pharma-signals/eligibility.ts +32 -0
- package/src/plugins/builtin/ticker-detail/pharma-signals/tab.tsx +162 -0
- package/src/plugins/builtin/ticker-detail/pharma-signals/waitlist.ts +126 -0
- package/src/plugins/builtin/ticker-detail/research-groups.ts +6 -4
- package/src/plugins/builtin/ticker-detail/research-tabs.ts +11 -0
- package/src/portfolio/collection-name.ts +2 -1
- package/src/portfolio/column-values.ts +34 -12
- package/src/portfolio/listed-symbol.ts +4 -2
- package/src/portfolio/period-pnl.ts +51 -1
- package/src/portfolio/suffixed-listings.ts +3 -1
- package/src/portfolio/watchlist-groups.ts +212 -0
- package/src/react/ticker-source.ts +3 -1
- package/src/renderers/dom/dialog-host.tsx +5 -5
- package/src/renderers/dom/styles.css +7 -0
- 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/state/app/bootstrap.ts +11 -0
- package/src/state/app/context/index.tsx +6 -0
- package/src/sync/collections-contributor.ts +5 -2
- package/src/sync/config-merge.ts +10 -2
- package/src/sync/sanitize.ts +28 -0
- package/src/telemetry/usage-counts.ts +17 -0
- 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/chart-seed.ts +1 -1
- package/src/time-series/financial-period-coverage.ts +4 -12
- package/src/time-series/parsed-history-cache.ts +1 -1
- package/src/time-series/resolve.ts +1 -1
- package/src/time-series/types.ts +5 -2
- package/src/time-series/use-chart-resolution.ts +6 -1
- package/src/types/config.ts +32 -0
- package/src/types/financials.ts +13 -0
- package/src/types/headless.ts +7 -0
- package/src/types/plugin-context.ts +5 -0
- package/src/types/ticker.ts +14 -0
- package/src/ui/ascii-font.ts +1 -4
- package/src/ui/dialog-stack.ts +17 -0
- package/src/ui/dialog.tsx +6 -2
- package/src/utils/async-deadline.ts +2 -2
- package/src/utils/crypto-pair.ts +9 -0
- package/src/utils/csv.ts +44 -5
- package/src/utils/exchanges.ts +13 -0
- package/src/utils/financial-statements.ts +60 -3
- package/src/utils/futures-generic.ts +17 -0
- package/src/utils/trailing-dividend.ts +13 -3
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { CompanyProfile } from "../../../../types/financials";
|
|
2
|
+
import type { TickerInstrumentKind } from "../../../../types/instrument";
|
|
3
|
+
|
|
4
|
+
/** The Signals tab's id: what `?tab=`, `--tab` and a saved layout name it by. */
|
|
5
|
+
export const PHARMA_SIGNALS_TAB_ID = "pharma-signals";
|
|
6
|
+
|
|
7
|
+
/** The profile's industries of drug developers: Biotechnology, Drug Manufacturers - General, - Specialty & Generic. */
|
|
8
|
+
const DRUG_INDUSTRY = /^(?:biotechnology|drug manufacturers\b.*)$/i;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* SEC codes of drug makers, for a US filer whose profile names no industry:
|
|
12
|
+
* medicinal chemicals (2833), pharmaceutical preparations (2834) and
|
|
13
|
+
* biological products (2836). Diagnostic substances (2835) are not drugs.
|
|
14
|
+
*/
|
|
15
|
+
const DRUG_SIC = new Set(["2833", "2834", "2836"]);
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Whether a listing gets the Signals tab: a company share whose profile says
|
|
19
|
+
* it develops or makes drugs. Other healthcare (devices, services, insurers,
|
|
20
|
+
* tools), funds such as a biotech ETF, and a listing whose profile has not
|
|
21
|
+
* loaded do not: the tab shows once the profile says so, never on a guess
|
|
22
|
+
* from the name.
|
|
23
|
+
*/
|
|
24
|
+
export function isPharmaSignalsListing(
|
|
25
|
+
instrumentKind: TickerInstrumentKind,
|
|
26
|
+
profile: Pick<CompanyProfile, "industry" | "sic"> | null | undefined,
|
|
27
|
+
): boolean {
|
|
28
|
+
if (instrumentKind !== "equity" || !profile) return false;
|
|
29
|
+
const industry = profile.industry?.trim();
|
|
30
|
+
if (industry) return DRUG_INDUSTRY.test(industry);
|
|
31
|
+
return DRUG_SIC.has(profile.sic?.trim() ?? "");
|
|
32
|
+
}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { createContext, useCallback, useContext, useRef, useSyncExternalStore } from "react";
|
|
2
|
+
import { requestAuthDialog } from "../../../../account/auth-dialog";
|
|
3
|
+
import { apiClient } from "../../../../api-client";
|
|
4
|
+
import { usePlanAccess } from "../../../../api-client/plan-access";
|
|
5
|
+
import { isEmailVerificationRequired } from "../../../../api-client/product-waitlist";
|
|
6
|
+
import { Button, confirmDialog, PaneStatusBody, usePaneStatusFooter } from "../../../../components";
|
|
7
|
+
import { usePaneRefreshKey } from "../../../../components/data-table/table-pane";
|
|
8
|
+
import { t } from "../../../../i18n";
|
|
9
|
+
import { usePluginAppActions } from "../../../../public/react";
|
|
10
|
+
import { colors } from "../../../../theme/colors";
|
|
11
|
+
import type { TickerResearchTabProps } from "../../../../types/plugin";
|
|
12
|
+
import { Box, Text, TextAttributes } from "../../../../ui";
|
|
13
|
+
import { useOptionalDialog } from "../../../../ui/dialog";
|
|
14
|
+
import { logFailure } from "../../../../utils/log-failure";
|
|
15
|
+
import { useProductWaitlist, type WaitlistClient } from "./waitlist";
|
|
16
|
+
|
|
17
|
+
export const PharmaWaitlistClientContext = createContext<WaitlistClient | null>(null);
|
|
18
|
+
|
|
19
|
+
const PRODUCT = "pharma-signals";
|
|
20
|
+
const PLANNED = "Planned: alerts the day a trial's endpoint, enrollment, dates or status change, and cash runway against the next catalyst.";
|
|
21
|
+
const RESEND_VERIFICATION = "Resend Verification Email";
|
|
22
|
+
|
|
23
|
+
function subscribeAccount(onChange: () => void): () => void {
|
|
24
|
+
return apiClient.subscribeCurrentUser(onChange);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function currentAccount(): string | null {
|
|
28
|
+
return apiClient.getCurrentUser()?.id ?? null;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** The consent itself: what joining costs (nothing now) and the one email it allows. */
|
|
32
|
+
function JoinDialogBody() {
|
|
33
|
+
return (
|
|
34
|
+
<Box flexDirection="column">
|
|
35
|
+
<Text fg={colors.text} wrapText>{t("Planned price: $50/month on top of Pro, once it launches.")}</Text>
|
|
36
|
+
<Box height={1} />
|
|
37
|
+
<Text fg={colors.positive} attributes={TextAttributes.BOLD} wrapText>{t("Nothing is charged now. No card needed.")}</Text>
|
|
38
|
+
<Box height={1} />
|
|
39
|
+
<Text fg={colors.textDim} wrapText>{t("We email you once, only if it launches. Nothing else.")}</Text>
|
|
40
|
+
</Box>
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The Signals tab of a drug developer's research pane: an add-on that is not
|
|
46
|
+
* built, said plainly, with a no-charge waitlist. Nothing in it is data, so
|
|
47
|
+
* it shows no rows, real or made up. Joining asks first, every time, and
|
|
48
|
+
* never happens at sign-in: signed out, the button only opens the sign-in.
|
|
49
|
+
* The launch email goes to the account's address, so an unverified one is
|
|
50
|
+
* asked to verify it first: the app sends nothing for an address it knows is
|
|
51
|
+
* unverified, and says the same when the service refuses one it thought was.
|
|
52
|
+
*/
|
|
53
|
+
export function PharmaSignalsResearchTab({ width, height, focused }: TickerResearchTabProps) {
|
|
54
|
+
const client = useContext(PharmaWaitlistClientContext) ?? apiClient;
|
|
55
|
+
const account = useSyncExternalStore(subscribeAccount, currentAccount, currentAccount);
|
|
56
|
+
const access = usePlanAccess();
|
|
57
|
+
const waitlist = useProductWaitlist(client, PRODUCT, account && access.emailVerified ? account : null);
|
|
58
|
+
const needsVerification = !!account && (!access.emailVerified || waitlist.unverified);
|
|
59
|
+
const { change, retry } = waitlist;
|
|
60
|
+
const dialog = useOptionalDialog();
|
|
61
|
+
const { openCommandBar, notify } = usePluginAppActions();
|
|
62
|
+
// The join dialog is open: the key or press that answered it does not open another.
|
|
63
|
+
const asking = useRef(false);
|
|
64
|
+
|
|
65
|
+
usePaneRefreshKey(retry, { focused });
|
|
66
|
+
usePaneStatusFooter({ registrationId: "pharma-signals", loading: waitlist.loading, error: waitlist.error });
|
|
67
|
+
|
|
68
|
+
const failed = useCallback((message: string, unverifiedMessage: string, error: unknown) => {
|
|
69
|
+
if (isEmailVerificationRequired(error)) {
|
|
70
|
+
notify({ body: t(unverifiedMessage), type: "error", desktop: "never" });
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
logFailure("pharma-signals", message)(error);
|
|
74
|
+
notify({ body: t(message), type: "error", desktop: "never" });
|
|
75
|
+
}, [notify]);
|
|
76
|
+
|
|
77
|
+
const join = useCallback(() => {
|
|
78
|
+
if (!account) {
|
|
79
|
+
if (!requestAuthDialog({ mode: "login" })) openCommandBar("Log In");
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
if (!dialog || asking.current) return;
|
|
83
|
+
asking.current = true;
|
|
84
|
+
// The account the person decides as: a sign-in elsewhere while the dialog is open sends nothing.
|
|
85
|
+
const decidedAs = account;
|
|
86
|
+
confirmDialog(dialog, {
|
|
87
|
+
title: t("Join the pharma signals waitlist"),
|
|
88
|
+
body: <JoinDialogBody />,
|
|
89
|
+
confirmLabel: t("Join waitlist"),
|
|
90
|
+
cancelLabel: t("Not now"),
|
|
91
|
+
confirmVariant: "primary",
|
|
92
|
+
// An opt-in: a stray Enter answers Not now; only `y` or the button joins.
|
|
93
|
+
defaultAction: "cancel",
|
|
94
|
+
})
|
|
95
|
+
.then((confirmed) => {
|
|
96
|
+
// Released a turn after the answer, once the key that gave it has gone everywhere it goes.
|
|
97
|
+
setTimeout(() => { asking.current = false; }, 0);
|
|
98
|
+
return confirmed ? change(true, decidedAs) : null;
|
|
99
|
+
})
|
|
100
|
+
.catch((error: unknown) => failed("Couldn't join the waitlist. Try again.", "Verify your email to join the waitlist.", error));
|
|
101
|
+
}, [account, change, dialog, failed, openCommandBar]);
|
|
102
|
+
|
|
103
|
+
const leave = useCallback(() => {
|
|
104
|
+
if (!account) return;
|
|
105
|
+
change(false, account)
|
|
106
|
+
.catch((error: unknown) => failed("Couldn't leave the waitlist. Try again.", "Verify your email to leave the waitlist.", error));
|
|
107
|
+
}, [account, change, failed]);
|
|
108
|
+
|
|
109
|
+
if (needsVerification) {
|
|
110
|
+
return (
|
|
111
|
+
<PaneStatusBody
|
|
112
|
+
empty
|
|
113
|
+
width={width}
|
|
114
|
+
height={height}
|
|
115
|
+
emptyTitle={t("Verify your email to join the pharma signals waitlist.")}
|
|
116
|
+
emptyMessage={t(PLANNED)}
|
|
117
|
+
actions={<Button label={t(RESEND_VERIFICATION)} onPress={() => openCommandBar(RESEND_VERIFICATION)} />}
|
|
118
|
+
/>
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (waitlist.joined) {
|
|
123
|
+
return (
|
|
124
|
+
<PaneStatusBody
|
|
125
|
+
empty
|
|
126
|
+
width={width}
|
|
127
|
+
height={height}
|
|
128
|
+
emptyTitle={t("You're on the pharma signals waitlist.")}
|
|
129
|
+
emptyMessage={t("We email you once, only if it launches. Nothing is charged.")}
|
|
130
|
+
actions={(
|
|
131
|
+
<Button
|
|
132
|
+
label={t("Leave waitlist")}
|
|
133
|
+
variant="secondary"
|
|
134
|
+
pending={waitlist.pending === "leave"}
|
|
135
|
+
pendingLabel={t("Leaving…")}
|
|
136
|
+
onPress={leave}
|
|
137
|
+
/>
|
|
138
|
+
)}
|
|
139
|
+
/>
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const known = !account || waitlist.joined === false;
|
|
144
|
+
return (
|
|
145
|
+
<PaneStatusBody
|
|
146
|
+
empty
|
|
147
|
+
width={width}
|
|
148
|
+
height={height}
|
|
149
|
+
emptyTitle={t("Pharma signals are not available yet.")}
|
|
150
|
+
emptyMessage={t(PLANNED)}
|
|
151
|
+
retry={waitlist.error ? { onRetry: retry } : undefined}
|
|
152
|
+
actions={known ? (
|
|
153
|
+
<Button
|
|
154
|
+
label={account ? t("Join waitlist") : t("Log in to join")}
|
|
155
|
+
pending={waitlist.pending === "join"}
|
|
156
|
+
pendingLabel={t("Joining…")}
|
|
157
|
+
onPress={join}
|
|
158
|
+
/>
|
|
159
|
+
) : undefined}
|
|
160
|
+
/>
|
|
161
|
+
);
|
|
162
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
2
|
+
import type { apiClient } from "../../../../api-client";
|
|
3
|
+
import { isEmailVerificationRequired, type WaitlistProduct, type WaitlistState } from "../../../../api-client/product-waitlist";
|
|
4
|
+
import { errorMessage } from "../../../../utils/errors";
|
|
5
|
+
|
|
6
|
+
/** The waitlist calls the tab makes; tests hand it their own. */
|
|
7
|
+
export type WaitlistClient = Pick<typeof apiClient, "getWaitlist" | "joinWaitlist" | "leaveWaitlist">;
|
|
8
|
+
|
|
9
|
+
export interface ProductWaitlist {
|
|
10
|
+
/** Whether the signed-in account is on the list; undefined until its read answers, or signed out. */
|
|
11
|
+
joined: boolean | undefined;
|
|
12
|
+
/** The account's place is being read. */
|
|
13
|
+
loading: boolean;
|
|
14
|
+
/** Why the read failed; null otherwise. */
|
|
15
|
+
error: string | null;
|
|
16
|
+
/**
|
|
17
|
+
* The service refused the account because its address is not verified: its
|
|
18
|
+
* place cannot be read or changed until it is. Not an error to retry.
|
|
19
|
+
*/
|
|
20
|
+
unverified: boolean;
|
|
21
|
+
/** A join or a leave on its way. */
|
|
22
|
+
pending: "join" | "leave" | null;
|
|
23
|
+
/** Reads the account's place again. */
|
|
24
|
+
retry(): void;
|
|
25
|
+
/**
|
|
26
|
+
* Joins or leaves for `account`, the one the person decided as. Nothing is
|
|
27
|
+
* sent when another account holds the session by now, and an answer that
|
|
28
|
+
* lands after the account changed is not shown: null in both cases.
|
|
29
|
+
*/
|
|
30
|
+
change(joined: boolean, account: string): Promise<WaitlistState | null>;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
interface Snapshot {
|
|
34
|
+
account: string | null;
|
|
35
|
+
joined: boolean | undefined;
|
|
36
|
+
error: string | null;
|
|
37
|
+
unverified: boolean;
|
|
38
|
+
pending: "join" | "leave" | null;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function fresh(account: string | null): Snapshot {
|
|
42
|
+
return { account, joined: undefined, error: null, unverified: false, pending: null };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* The signed-in account's place on a product's waitlist. Everything is the
|
|
47
|
+
* account's: a sign-in, a sign-out or another account starts from nothing at
|
|
48
|
+
* once, and no answer for the account that left is shown for the next one.
|
|
49
|
+
* A read that was already out when a join or a leave began is dropped, so it
|
|
50
|
+
* cannot put back the state from before the change. `account` is null for an
|
|
51
|
+
* account the app already knows is unverified: nothing is sent for it.
|
|
52
|
+
*/
|
|
53
|
+
export function useProductWaitlist(client: WaitlistClient, product: WaitlistProduct, account: string | null): ProductWaitlist {
|
|
54
|
+
const [stored, setStored] = useState<Snapshot>(() => fresh(account));
|
|
55
|
+
const [reads, setReads] = useState(0);
|
|
56
|
+
const accountRef = useRef(account);
|
|
57
|
+
accountRef.current = account;
|
|
58
|
+
// Bumped by every change: a read that began before it answers too late.
|
|
59
|
+
const changes = useRef(0);
|
|
60
|
+
// The account a change is on its way for; a second press waits for it.
|
|
61
|
+
const changing = useRef<string | null>(null);
|
|
62
|
+
|
|
63
|
+
const snapshot = stored.account === account ? stored : fresh(account);
|
|
64
|
+
if (snapshot !== stored) setStored(snapshot);
|
|
65
|
+
|
|
66
|
+
const update = useCallback((forAccount: string, patch: Partial<Snapshot>) => {
|
|
67
|
+
setStored((current) => (current.account === forAccount ? { ...current, ...patch } : current));
|
|
68
|
+
}, []);
|
|
69
|
+
|
|
70
|
+
useEffect(() => {
|
|
71
|
+
if (!account) return;
|
|
72
|
+
let live = true;
|
|
73
|
+
const since = changes.current;
|
|
74
|
+
const current = () => live && accountRef.current === account && changes.current === since;
|
|
75
|
+
client.getWaitlist(product).then((state) => {
|
|
76
|
+
if (current()) update(account, { joined: state.joined, error: null, unverified: false });
|
|
77
|
+
}, (error: unknown) => {
|
|
78
|
+
if (!current()) return;
|
|
79
|
+
// Refused for an unverified address, the place is unknown again, not the last one read.
|
|
80
|
+
update(account, isEmailVerificationRequired(error) ? { joined: undefined, unverified: true } : { error: errorMessage(error) });
|
|
81
|
+
});
|
|
82
|
+
return () => { live = false; };
|
|
83
|
+
}, [account, client, product, reads, update]);
|
|
84
|
+
|
|
85
|
+
const retry = useCallback(() => {
|
|
86
|
+
if (accountRef.current) update(accountRef.current, { error: null, unverified: false });
|
|
87
|
+
setReads((count) => count + 1);
|
|
88
|
+
}, [update]);
|
|
89
|
+
|
|
90
|
+
const change = useCallback(async (joined: boolean, forAccount: string): Promise<WaitlistState | null> => {
|
|
91
|
+
if (accountRef.current !== forAccount || changing.current === forAccount) return null;
|
|
92
|
+
changing.current = forAccount;
|
|
93
|
+
changes.current += 1;
|
|
94
|
+
update(forAccount, { pending: joined ? "join" : "leave" });
|
|
95
|
+
try {
|
|
96
|
+
const state = joined ? await client.joinWaitlist(product) : await client.leaveWaitlist(product);
|
|
97
|
+
if (accountRef.current !== forAccount) return null;
|
|
98
|
+
update(forAccount, { joined: state.joined, error: null, unverified: false, pending: null });
|
|
99
|
+
return state;
|
|
100
|
+
} catch (error) {
|
|
101
|
+
if (accountRef.current === forAccount) {
|
|
102
|
+
if (isEmailVerificationRequired(error)) {
|
|
103
|
+
// The service holds no answer for this account until it verifies: nothing to read again.
|
|
104
|
+
update(forAccount, { joined: undefined, unverified: true, pending: null });
|
|
105
|
+
} else {
|
|
106
|
+
update(forAccount, { pending: null });
|
|
107
|
+
// The read this change dropped is asked again, so the state is known.
|
|
108
|
+
setReads((count) => count + 1);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
throw error;
|
|
112
|
+
} finally {
|
|
113
|
+
if (changing.current === forAccount) changing.current = null;
|
|
114
|
+
}
|
|
115
|
+
}, [client, product, update]);
|
|
116
|
+
|
|
117
|
+
return {
|
|
118
|
+
joined: snapshot.joined,
|
|
119
|
+
loading: !!account && snapshot.joined === undefined && snapshot.error === null && !snapshot.unverified,
|
|
120
|
+
error: snapshot.error,
|
|
121
|
+
unverified: snapshot.unverified,
|
|
122
|
+
pending: snapshot.pending,
|
|
123
|
+
retry,
|
|
124
|
+
change,
|
|
125
|
+
};
|
|
126
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ADR_PAIR_TAB_ID } from "./adr-pair/model";
|
|
2
|
+
import { PHARMA_SIGNALS_TAB_ID } from "./pharma-signals/eligibility";
|
|
2
3
|
|
|
3
4
|
/** What the grouping reads of a research tab. */
|
|
4
5
|
export interface TickerResearchTabSummary {
|
|
@@ -23,9 +24,10 @@ interface TickerResearchGroupDef {
|
|
|
23
24
|
* Trade is Chart with the ticket beside it, and closing the ticket goes back
|
|
24
25
|
* to Chart (`ResearchTradeWorkspace`), so it is Chart's second view. ADR vs
|
|
25
26
|
* Home, the receipt's price against its home line, is the last of
|
|
26
|
-
* Financials.
|
|
27
|
-
*
|
|
28
|
-
*
|
|
27
|
+
* Financials. Signals, a drug developer's add-on waitlist, is the last of
|
|
28
|
+
* Events, beside its catalysts. Each shows only for some tickers, so each
|
|
29
|
+
* comes after the views every ticker has. A plugin's own tab is in no group:
|
|
30
|
+
* it gets its own top tab after these (`groupTickerResearchTabs`).
|
|
29
31
|
*/
|
|
30
32
|
const TICKER_RESEARCH_GROUPS: readonly TickerResearchGroupDef[] = [
|
|
31
33
|
{ id: "overview", name: "Overview", views: ["overview"] },
|
|
@@ -33,7 +35,7 @@ const TICKER_RESEARCH_GROUPS: readonly TickerResearchGroupDef[] = [
|
|
|
33
35
|
{ id: "financials", name: "Financials", views: ["financials", "revenue", "equity-diagnostic", "dividend-yield", ADR_PAIR_TAB_ID] },
|
|
34
36
|
{ id: "analysts", name: "Analysts", views: ["analyst-research", "earnings-calls"] },
|
|
35
37
|
{ id: "options", name: "Options", views: ["options"] },
|
|
36
|
-
{ id: "events", name: "Events", views: ["corporate-actions", "catalysts", "mna"] },
|
|
38
|
+
{ id: "events", name: "Events", views: ["corporate-actions", "catalysts", "mna", PHARMA_SIGNALS_TAB_ID] },
|
|
37
39
|
{ id: "filings", name: "Filings", views: ["sec", "filing-events", "risk-factors"] },
|
|
38
40
|
{ id: "ownership", name: "Ownership", views: ["holders", "insider", "thirteenf", "congress", "short-interest"] },
|
|
39
41
|
{ id: "people", name: "People", views: ["executives", "jobs", "hiring-momentum"] },
|
|
@@ -5,6 +5,8 @@ import { AdrPairResearchTab } from "./adr-pair/tab";
|
|
|
5
5
|
import { ADR_PAIR_TAB_ID } from "./adr-pair/model";
|
|
6
6
|
import { listingDepositaryPair } from "../../../market-data/depositary-pair";
|
|
7
7
|
import { hasStatementFinancials } from "./financials/model";
|
|
8
|
+
import { isPharmaSignalsListing, PHARMA_SIGNALS_TAB_ID } from "./pharma-signals/eligibility";
|
|
9
|
+
import { PharmaSignalsResearchTab } from "./pharma-signals/tab";
|
|
8
10
|
|
|
9
11
|
/**
|
|
10
12
|
* Tabs this module owns. They are registered through `setup()` like any other
|
|
@@ -36,4 +38,13 @@ export const TICKER_RESEARCH_BUILTIN_TABS: TickerResearchTabDef[] = [
|
|
|
36
38
|
component: AdrPairResearchTab,
|
|
37
39
|
isVisible: ({ financials }) => !!listingDepositaryPair(financials),
|
|
38
40
|
},
|
|
41
|
+
{
|
|
42
|
+
// A drug developer's add-on that is not built yet: a no-charge waitlist, on no other listing.
|
|
43
|
+
id: PHARMA_SIGNALS_TAB_ID,
|
|
44
|
+
name: "Signals",
|
|
45
|
+
order: 36,
|
|
46
|
+
component: PharmaSignalsResearchTab,
|
|
47
|
+
instruments: ["equity"],
|
|
48
|
+
isVisible: ({ financials, instrumentKind }) => isPharmaSignalsListing(instrumentKind, financials?.profile),
|
|
49
|
+
},
|
|
39
50
|
];
|
|
@@ -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
|
}
|
|
@@ -40,7 +40,7 @@ import {
|
|
|
40
40
|
import { formatOptionTicker } from "../utils/options";
|
|
41
41
|
import { distributionHistory, forwardYieldMayHaveLapsed, lapsedDividend } from "../utils/forward-dividend";
|
|
42
42
|
import { classifyInstrumentType } from "../tickers/instrument-kind";
|
|
43
|
-
import { isIndexLevel, reportedQuoteVolume } from "../market-data/market/index-level";
|
|
43
|
+
import { isIndexLevel, quoteVolumeCurrency, reportedQuoteVolume } from "../market-data/market/index-level";
|
|
44
44
|
import { futuresQuoteFromSettle } from "../market-data/market/change-basis";
|
|
45
45
|
import { perpetualDisplaySymbol, perpetualListing } from "../tickers/perpetual-listing";
|
|
46
46
|
import { premiumToUnderlying, type PerpetualPremiumRow } from "../market-data/perpetual-premium";
|
|
@@ -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);
|
|
@@ -682,9 +692,8 @@ export function getColumnValue(
|
|
|
682
692
|
return { text: volume != null ? formatCompact(volume, { fixedDecimals: true }) : MISSING_VALUE };
|
|
683
693
|
}
|
|
684
694
|
case "dollar_volume": {
|
|
685
|
-
const
|
|
686
|
-
|
|
687
|
-
return { text: formatCompact(toBaseQuote(displayQuote.price * volume), { fixedDecimals: true }) };
|
|
695
|
+
const traded = tradedValue(quote, displayQuote, toBaseQuote);
|
|
696
|
+
return { text: traded == null ? MISSING_VALUE : formatCompact(traded, { fixedDecimals: true }) };
|
|
688
697
|
}
|
|
689
698
|
case "range_52w": {
|
|
690
699
|
const position = fiftyTwoWeekPosition(displayQuote, quote);
|
|
@@ -859,6 +868,21 @@ export function getColumnValue(
|
|
|
859
868
|
}
|
|
860
869
|
}
|
|
861
870
|
|
|
871
|
+
/**
|
|
872
|
+
* The value a row's volume traded, in the base currency: shares or contracts at the price, or a coin's volume
|
|
873
|
+
* itself, which is already a value in its quote currency (quoteVolumeCurrency), never priced again.
|
|
874
|
+
*/
|
|
875
|
+
function tradedValue(
|
|
876
|
+
quote: Quote | null | undefined,
|
|
877
|
+
displayQuote: { price: number } | null | undefined,
|
|
878
|
+
toBaseQuote: (value: number) => number,
|
|
879
|
+
): number | null {
|
|
880
|
+
const volume = reportedQuoteVolume(quote);
|
|
881
|
+
if (volume == null) return null;
|
|
882
|
+
if (quoteVolumeCurrency(quote)) return toBaseQuote(volume);
|
|
883
|
+
return displayQuote ? toBaseQuote(displayQuote.price * volume) : null;
|
|
884
|
+
}
|
|
885
|
+
|
|
862
886
|
export function getSortValue(
|
|
863
887
|
col: ColumnConfig,
|
|
864
888
|
ticker: TickerRecord,
|
|
@@ -932,10 +956,8 @@ export function getSortValue(
|
|
|
932
956
|
return quote?.delisting ? null : headlineChangePercent(headlineQuote, quote) ?? null;
|
|
933
957
|
case "volume":
|
|
934
958
|
return reportedQuoteVolume(quote);
|
|
935
|
-
case "dollar_volume":
|
|
936
|
-
|
|
937
|
-
return displayQuote && volume != null ? toBaseQuote(displayQuote.price * volume) : null;
|
|
938
|
-
}
|
|
959
|
+
case "dollar_volume":
|
|
960
|
+
return tradedValue(quote, displayQuote, toBaseQuote);
|
|
939
961
|
case "range_52w":
|
|
940
962
|
return fiftyTwoWeekPosition(displayQuote, quote);
|
|
941
963
|
case "market_cap": {
|
|
@@ -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,6 +1,7 @@
|
|
|
1
1
|
import type { AppConfig } from "../types/config";
|
|
2
2
|
import type { TickerMetadata, TickerPosition, TickerRecord } from "../types/ticker";
|
|
3
3
|
import { listingSuffixVenue, tickerHasListingSuffix } from "../sources/listing-symbols";
|
|
4
|
+
import { moveWatchlistGroupSymbols } from "./watchlist-groups";
|
|
4
5
|
import { canonicalExchange, parsePublicTickerKey, publicTickerKey } from "../utils/exchanges";
|
|
5
6
|
|
|
6
7
|
/**
|
|
@@ -197,7 +198,8 @@ export async function mergeSavedSuffixedListings(
|
|
|
197
198
|
): Promise<{ tickers: TickerRecord[]; config: AppConfig; keptCustom: SuffixedListingMerge["keptCustom"] } | null> {
|
|
198
199
|
const merge = mergeSuffixedListings(tickers);
|
|
199
200
|
if (!merge) return null;
|
|
200
|
-
|
|
201
|
+
// Target weights and watchlist groups follow their rows to the listing's key.
|
|
202
|
+
const nextConfig = moveWatchlistGroupSymbols(moveTargetWeights(config, merge.moved), merge.moved);
|
|
201
203
|
if (merge.saves.length === 0 && nextConfig === config) return null;
|
|
202
204
|
if (nextConfig !== config) await save.config(nextConfig);
|
|
203
205
|
if (merge.saves.length > 0) await save.tickers(merge.saves);
|