@gloom-sh/terminal 0.20.16 → 0.20.18
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 +3 -1
- package/src/account/auth-dialog.tsx +19 -1
- package/src/account/billing.ts +2 -1
- package/src/account/heard-from-question.tsx +235 -0
- package/src/account/heard-from.ts +97 -0
- package/src/api-client/data.ts +16 -5
- package/src/api-client/heard-from.ts +72 -0
- package/src/api-client/index.ts +63 -6
- package/src/api-client/mna.ts +18 -0
- package/src/api-client/supply-chain.ts +9 -0
- package/src/api-client/types/billing.ts +35 -1
- package/src/api-client/types/econ.ts +3 -0
- package/src/app/global-shortcuts.ts +5 -3
- package/src/app/pro-welcome/keys.ts +27 -0
- package/src/app/pro-welcome/model.ts +158 -0
- package/src/app/pro-welcome/row.tsx +176 -0
- package/src/app/pro-welcome/use-pro-welcome.ts +156 -0
- package/src/app/runtime/external-profile-changes.ts +135 -0
- package/src/app.tsx +33 -2
- package/src/architecture/core-builtin-allowlist.json +1 -1
- package/src/architecture/floating-promise-allowlist.json +0 -1
- package/src/architecture/shortcut-labels-allowlist.json +1 -0
- package/src/cli/alert-listing.ts +98 -0
- package/src/cli/commands/fred-series.ts +3 -1
- package/src/cli/commands/market.ts +138 -22
- package/src/cli/commands/overview.ts +72 -14
- package/src/cli/commands/plugins.ts +3 -2
- package/src/cli/commands/search.ts +30 -6
- package/src/cli/context.ts +16 -5
- package/src/cli/csv-export.ts +74 -0
- package/src/cli/desktop-pane-shot.ts +75 -11
- package/src/cli/glossary.ts +64 -10
- package/src/cli/help.ts +4 -2
- package/src/cli/history-demergers.ts +117 -0
- package/src/cli/history-rows.ts +6 -2
- package/src/cli/index.ts +1 -0
- package/src/cli/known-gaps.ts +16 -0
- package/src/cli/known-us-stocks.ts +18 -0
- package/src/cli/listing-arg.ts +105 -15
- package/src/cli/pane-functions/catalog-snapshot-build.ts +83 -0
- package/src/cli/pane-functions/catalog-snapshot.json +866 -0
- package/src/cli/pane-functions/catalog-snapshot.ts +62 -0
- package/src/cli/pane-functions/catalog.ts +50 -16
- package/src/cli/pane-functions/data.ts +16 -4
- package/src/cli/pane-functions/dom.ts +24 -6
- package/src/cli/pane-functions/freshness.ts +17 -1
- package/src/cli/pane-functions/headless.ts +7 -2
- package/src/cli/pane-functions/index.ts +102 -44
- package/src/cli/pane-functions/resolver.ts +8 -5
- package/src/cli/pane-functions/screenshot-assessment.ts +30 -7
- package/src/cli/pane-functions/screenshot-bridge.ts +4 -2
- package/src/cli/pane-functions/screenshot-payload.ts +21 -0
- package/src/cli/pane-functions/screenshot-render.ts +3 -1
- package/src/cli/quote-answer.ts +32 -16
- package/src/cli/registry.ts +22 -2
- package/src/cli/report-tables.ts +17 -3
- package/src/cli/result.ts +8 -10
- package/src/cli/series-search.ts +45 -6
- package/src/cli/shot-temp-dir.ts +4 -9
- package/src/components/chart/composite/legend.tsx +80 -25
- package/src/components/chart/composite/panel-surface/panel-cursor.tsx +3 -3
- package/src/components/chart/composite/price-axis-labels.tsx +7 -5
- package/src/components/chart-table/header.tsx +9 -0
- package/src/components/chart-table/layout.ts +11 -11
- package/src/components/command-bar/pane-templates/items.ts +17 -1
- package/src/components/command-bar/routes/root/provider-search.ts +10 -1
- package/src/components/command-bar/routes/root/results.ts +34 -2
- package/src/components/command-bar/routes/root/runtime.ts +8 -1
- package/src/components/command-bar/routes/ticker-search/route.ts +5 -0
- package/src/components/command-bar/workflow/alert.ts +19 -8
- package/src/components/data-table/view.tsx +15 -2
- package/src/components/form-modal/content.tsx +9 -4
- package/src/components/index.ts +1 -1
- package/src/components/layout/header.tsx +9 -5
- package/src/components/layout/pane/capture-status.ts +6 -0
- package/src/components/layout/pane/footer/index.tsx +2 -0
- package/src/components/layout/pane/footer/model.ts +113 -15
- package/src/components/layout/pane/header.tsx +16 -2
- package/src/components/market-board/index.tsx +4 -2
- package/src/components/onboarding/onboarding-frame.tsx +6 -2
- package/src/components/onboarding/onboarding-keyboard.ts +7 -1
- package/src/components/onboarding/onboarding-wizard.tsx +3 -1
- package/src/components/onboarding/portfolio-step/positions-panel.tsx +24 -15
- package/src/components/onboarding/setup-cards.ts +36 -0
- package/src/components/onboarding/use-onboarding-progress.ts +22 -1
- package/src/components/onboarding/wizard-account.ts +6 -1
- package/src/components/onboarding/wizard-model.ts +32 -6
- package/src/components/onboarding/wizard-positions.ts +1 -1
- package/src/components/sign-in-gate.tsx +3 -1
- package/src/components/toggle-list.tsx +6 -8
- package/src/components/ui/confirm-dialog.tsx +47 -7
- package/src/components/ui/data-table/display-columns.ts +4 -1
- package/src/components/ui/data-table/hooks.ts +2 -3
- package/src/components/ui/data-table/index.tsx +4 -1
- package/src/components/ui/data-table/types.ts +19 -4
- package/src/components/ui/data-table/visible-range.ts +11 -1
- package/src/components/ui/display.tsx +17 -2
- package/src/components/ui/index.ts +1 -1
- package/src/components/ui/stat-grid.tsx +4 -0
- package/src/components/ui/status.tsx +13 -1
- package/src/components/ui/table-layout.ts +2 -1
- package/src/components/use-pane-notice-footer.tsx +16 -3
- package/src/data/config/store/index.ts +31 -0
- package/src/data/config/store/node.ts +61 -11
- package/src/data/config/store/normalize.ts +4 -6
- package/src/data/config/store/shared-file.ts +309 -0
- package/src/data/profile-merge.ts +299 -0
- package/src/data/sqlite/checkpointer.ts +11 -1
- package/src/data/sqlite/database.ts +1 -1
- package/src/data/ticker-repository.ts +134 -10
- package/src/data/ticker-store.ts +67 -0
- package/src/data/ticker-writes.ts +5 -0
- package/src/i18n/es.ts +27 -0
- package/src/i18n/ja.ts +27 -0
- package/src/i18n/ko.ts +27 -0
- package/src/i18n/zh-cn.ts +27 -0
- package/src/i18n/zh-tw.ts +27 -0
- package/src/layout-marketplace/gallery-desktop.tsx +2 -2
- package/src/market-data/ah-pair.ts +103 -0
- package/src/market-data/depositary-pair.ts +6 -2
- package/src/market-data/hooks.tsx +33 -2
- package/src/market-data/market/change-basis.ts +2 -1
- package/src/market-data/market/header-market.ts +11 -0
- package/src/market-data/split-terms.ts +28 -0
- package/src/plugins/builtin/account-management/footer.ts +1 -1
- package/src/plugins/builtin/account-management/keyboard.ts +4 -0
- package/src/plugins/builtin/account-management/model.ts +1 -0
- package/src/plugins/builtin/account-management/pane.tsx +75 -7
- package/src/plugins/builtin/account-management/payment-recovery-row.tsx +12 -5
- package/src/plugins/builtin/account-management/pro-cancel.tsx +197 -0
- package/src/plugins/builtin/account-management/trial-cancel.ts +1 -1
- package/src/plugins/builtin/alerts/cli-move.ts +2 -2
- package/src/plugins/builtin/alerts/cli.ts +36 -30
- package/src/plugins/builtin/alerts/constants.ts +10 -0
- package/src/plugins/builtin/alerts/earnings-listing.ts +20 -0
- package/src/plugins/builtin/alerts/format.ts +24 -8
- package/src/plugins/builtin/alerts/index.tsx +38 -9
- package/src/plugins/builtin/alerts/move-checks.ts +7 -0
- package/src/plugins/builtin/alerts/pane.tsx +1 -1
- package/src/plugins/builtin/alerts/quotes.ts +26 -2
- package/src/plugins/builtin/alerts/scheduled.ts +6 -1
- package/src/plugins/builtin/alerts/types.ts +7 -0
- package/src/plugins/builtin/analytics/manual-value.ts +61 -0
- package/src/plugins/builtin/analytics/risk-book.ts +7 -7
- package/src/plugins/builtin/analytics/risk-client.ts +26 -13
- package/src/plugins/builtin/analytics/risk-headless.ts +13 -8
- package/src/plugins/builtin/analytics/risk-model.ts +92 -4
- package/src/plugins/builtin/analytics/risk-pane.tsx +85 -38
- package/src/plugins/builtin/awards/pane.tsx +7 -3
- package/src/plugins/builtin/broker-trading/orders.tsx +2 -2
- package/src/plugins/builtin/central-bank-rates/model.ts +8 -2
- package/src/plugins/builtin/central-bank-rates/pane.tsx +5 -3
- package/src/plugins/builtin/chart-composer/cli-options.ts +4 -2
- package/src/plugins/builtin/chart-composer/data-catalog-pane.tsx +2 -6
- package/src/plugins/builtin/chart-composer/pane.tsx +9 -3
- package/src/plugins/builtin/cloud/auth-actions.tsx +11 -6
- package/src/plugins/builtin/cloud/company-picker.tsx +5 -3
- package/src/plugins/builtin/cloud/upgrade-command.ts +1 -1
- package/src/plugins/builtin/company-kpis/headless.ts +9 -4
- package/src/plugins/builtin/company-kpis/latest.ts +45 -0
- package/src/plugins/builtin/company-kpis/model.ts +38 -8
- package/src/plugins/builtin/company-kpis/pane.tsx +22 -8
- package/src/plugins/builtin/composite/alt-data.ts +20 -0
- package/src/plugins/builtin/composite/application.ts +14 -0
- package/src/plugins/builtin/composite/broker.ts +12 -0
- package/src/plugins/builtin/composite/credit.ts +33 -0
- package/src/plugins/builtin/composite/crypto.ts +10 -0
- package/src/plugins/builtin/composite/earnings.ts +12 -0
- package/src/plugins/builtin/composite/filings.ts +13 -0
- package/src/plugins/builtin/composite/futures-commodities.ts +23 -0
- package/src/plugins/builtin/composite/global-markets.ts +12 -0
- package/src/plugins/builtin/composite/options-volatility.ts +23 -0
- package/src/plugins/builtin/composite/ownership.ts +23 -0
- package/src/plugins/builtin/composite/portfolio.ts +10 -0
- package/src/plugins/builtin/composite/quant.ts +15 -0
- package/src/plugins/builtin/composite/rates-macro.ts +30 -0
- package/src/plugins/builtin/composite/screeners.ts +11 -0
- package/src/plugins/builtin/composite/shared.ts +11 -0
- package/src/plugins/builtin/composite/ticker-core.ts +36 -0
- package/src/plugins/builtin/congress-trades/headless.ts +31 -3
- package/src/plugins/builtin/correlation/index.tsx +13 -17
- package/src/plugins/builtin/correlation/matrix/model.ts +18 -0
- package/src/plugins/builtin/credit-conditions/series.ts +2 -2
- package/src/plugins/builtin/dividend-yield/client.ts +57 -16
- package/src/plugins/builtin/dividend-yield/headless.ts +17 -11
- package/src/plugins/builtin/dividend-yield/model.ts +4 -3
- package/src/plugins/builtin/dividend-yield/pane.tsx +22 -18
- package/src/plugins/builtin/dividend-yield/ranking.ts +1 -1
- package/src/plugins/builtin/dividend-yield/types.ts +4 -0
- package/src/plugins/builtin/dividend-yield/view.ts +23 -12
- package/src/plugins/builtin/earnings/board-model.ts +12 -0
- package/src/plugins/builtin/earnings/board-table.ts +7 -4
- package/src/plugins/builtin/earnings/board.tsx +2 -2
- package/src/plugins/builtin/earnings/fiscal-quarter.ts +39 -0
- package/src/plugins/builtin/earnings/headless.ts +7 -4
- package/src/plugins/builtin/earnings/highlight.ts +1 -1
- package/src/plugins/builtin/earnings/history-model.ts +6 -4
- package/src/plugins/builtin/earnings/history-table.ts +4 -3
- package/src/plugins/builtin/earnings-calls/pane.tsx +8 -2
- package/src/plugins/builtin/econ/calendar-model.ts +18 -0
- package/src/plugins/builtin/econ/fred-catalog.ts +1 -256
- package/src/plugins/builtin/econ/index.tsx +3 -0
- package/src/plugins/builtin/econ-statistics/cache.ts +1 -1
- package/src/plugins/builtin/econ-statistics/client.ts +11 -10
- package/src/plugins/builtin/econ-statistics/detail.tsx +1 -0
- package/src/plugins/builtin/econ-statistics/headless.ts +42 -6
- package/src/plugins/builtin/econ-statistics/index.tsx +1 -0
- package/src/plugins/builtin/econ-statistics/pane.tsx +7 -2
- package/src/plugins/builtin/econ-statistics/stats.ts +2 -1
- package/src/plugins/builtin/econ-statistics/view.ts +9 -3
- package/src/plugins/builtin/equity-screener/headless.ts +4 -1
- package/src/plugins/builtin/equity-screener/model.ts +7 -6
- package/src/plugins/builtin/estimate-revisions/headless.ts +1 -1
- package/src/plugins/builtin/exposure/model.ts +10 -0
- package/src/plugins/builtin/exposure/pane.tsx +10 -3
- package/src/plugins/builtin/fx-matrix/amount.ts +15 -1
- package/src/plugins/builtin/fx-matrix/headless.ts +12 -6
- package/src/plugins/builtin/fx-matrix/index.tsx +23 -5
- package/src/plugins/builtin/fx-matrix/settings.ts +9 -4
- package/src/plugins/builtin/kelly-sizer/pane.tsx +9 -4
- package/src/plugins/builtin/market-valuation/pane.tsx +22 -10
- package/src/plugins/builtin/mna/detail.tsx +67 -6
- package/src/plugins/builtin/mna/headless.ts +128 -13
- package/src/plugins/builtin/mna/model.ts +219 -16
- package/src/plugins/builtin/mna/pane.tsx +34 -6
- package/src/plugins/builtin/money-markets/model.ts +14 -5
- package/src/plugins/builtin/money-markets/pane.tsx +4 -3
- package/src/plugins/builtin/news/wire/news/footer.ts +3 -8
- package/src/plugins/builtin/options-scenario/csp-screen-pane.tsx +22 -6
- package/src/plugins/builtin/options-scenario/csp-screen.ts +39 -12
- package/src/plugins/builtin/options-scenario/strategy-screen.ts +7 -5
- package/src/plugins/builtin/pe-band/client.ts +13 -1
- package/src/plugins/builtin/pe-band/headless.ts +2 -2
- package/src/plugins/builtin/pe-band/model.ts +63 -10
- package/src/plugins/builtin/pe-band/pane.tsx +5 -5
- package/src/plugins/builtin/portfolio-list/allocation-rows.ts +26 -7
- package/src/plugins/builtin/portfolio-list/cli/portfolio-command.ts +66 -13
- package/src/plugins/builtin/portfolio-list/cli/render.ts +76 -33
- package/src/plugins/builtin/portfolio-list/headless.ts +69 -22
- package/src/plugins/builtin/portfolio-list/pane/data.ts +3 -3
- package/src/plugins/builtin/portfolio-list/pane/index.tsx +29 -14
- package/src/plugins/builtin/portfolio-list/summary/index.tsx +2 -2
- package/src/plugins/builtin/relative-rotation/pane.tsx +2 -3
- package/src/plugins/builtin/research/corporate-actions-pane.tsx +5 -1
- package/src/plugins/builtin/research/event-model.ts +31 -13
- package/src/plugins/builtin/research/headless.ts +8 -1
- package/src/plugins/builtin/research/relative-valuation-pane.tsx +19 -17
- package/src/plugins/builtin/sectors/index.tsx +6 -9
- package/src/plugins/builtin/shared/cloud-upgrade.ts +1 -1
- package/src/plugins/builtin/shared/earnings-report.ts +19 -4
- package/src/plugins/builtin/shared/fred-catalog.ts +256 -0
- package/src/plugins/builtin/shared/report-freshness.ts +2 -3
- package/src/plugins/builtin/shared/series-cache.ts +3 -0
- package/src/plugins/builtin/shared/series-detail-chart.tsx +3 -0
- package/src/plugins/builtin/short-interest/watch-pane.tsx +7 -7
- package/src/plugins/builtin/supply-chain/client.ts +34 -9
- package/src/plugins/builtin/supply-chain/evidence.ts +3 -2
- package/src/plugins/builtin/supply-chain/flow.tsx +4 -3
- package/src/plugins/builtin/supply-chain/graph-model.ts +14 -7
- package/src/plugins/builtin/supply-chain/graph-pane.tsx +3 -1
- package/src/plugins/builtin/supply-chain/graph.tsx +6 -3
- package/src/plugins/builtin/supply-chain/headless.ts +19 -4
- package/src/plugins/builtin/supply-chain/model.ts +50 -6
- package/src/plugins/builtin/supply-chain/pane.tsx +76 -16
- package/src/plugins/builtin/ticker-detail/adr-pair/ah.ts +62 -0
- package/src/plugins/builtin/ticker-detail/adr-pair/headless.ts +119 -20
- package/src/plugins/builtin/ticker-detail/adr-pair/model.ts +67 -1
- package/src/plugins/builtin/ticker-detail/adr-pair/tab.tsx +31 -16
- package/src/plugins/builtin/ticker-detail/overview/model.ts +17 -1
- package/src/plugins/builtin/ticker-detail/overview/pane.tsx +4 -0
- package/src/plugins/builtin/ticker-detail/overview-tab.tsx +9 -2
- package/src/plugins/builtin/ticker-detail/quote-monitor/card.tsx +9 -2
- package/src/plugins/builtin/ticker-detail/quote-monitor/index.tsx +5 -2
- package/src/plugins/builtin/time-sales/headless.ts +4 -1
- package/src/plugins/builtin/time-sales/pane.tsx +2 -0
- package/src/plugins/builtin/time-sales/window.ts +12 -0
- package/src/plugins/builtin/treasury-auctions/client.ts +4 -0
- package/src/plugins/builtin/treasury-auctions/treasury-direct.ts +2 -0
- package/src/plugins/builtin/treasury-daily/client.ts +23 -11
- package/src/plugins/builtin/volatility/model.ts +17 -0
- package/src/plugins/builtin/volatility/pane.tsx +13 -4
- package/src/plugins/builtin/world-indices/index.tsx +2 -0
- package/src/plugins/builtin/world-indices/table.tsx +15 -0
- package/src/plugins/builtin/world-venue-map/evidence.ts +3 -2
- package/src/plugins/builtin/world-venue-map/headless.ts +28 -16
- package/src/plugins/builtin/world-venue-map/index.ts +19 -6
- package/src/plugins/builtin/world-venue-map/layered-pane.tsx +9 -5
- package/src/plugins/builtin/world-venue-map/layers.ts +33 -11
- package/src/plugins/builtin/world-venue-map/map.tsx +12 -0
- package/src/plugins/builtin/world-venue-map/pane.tsx +35 -6
- package/src/plugins/builtin/world-venue-map/place.ts +119 -0
- package/src/plugins/catalog-data.ts +20 -0
- package/src/plugins/catalog-lazy.ts +51 -0
- package/src/plugins/catalog-ui.ts +16 -18
- package/src/plugins/host-smoke.ts +5 -2
- package/src/portfolio/allocation.ts +79 -19
- package/src/portfolio/cash-balances.ts +76 -0
- package/src/portfolio/mutations.ts +43 -8
- package/src/public/__snapshots__/public-api.test.ts.snap +1 -0
- package/src/renderers/desktop/window-layouts.ts +14 -0
- package/src/renderers/dom/data-table/row.tsx +2 -0
- package/src/renderers/dom/host/tabs.tsx +57 -8
- package/src/renderers/dom/styles.css +13 -5
- package/src/renderers/electrobun/bun/desktop/backend-requests.ts +4 -0
- package/src/renderers/electrobun/bun/desktop/backend.ts +22 -1
- package/src/renderers/electrobun/bun/window/native-min-size.ts +6 -1
- package/src/renderers/electrobun/shared/protocol.ts +4 -0
- package/src/renderers/electrobun/view/cli-pane-shot-entry.tsx +2 -0
- package/src/renderers/electrobun/view/cli-pane-shot-frame.tsx +50 -12
- package/src/renderers/electrobun/view/remote/ticker-repository.ts +10 -0
- package/src/series/standalone-catalog.ts +5 -4
- package/src/series/standalone.ts +13 -7
- package/src/sources/gloomberb-cloud/fred-publisher.ts +25 -0
- package/src/sources/gloomberb-cloud/fred-series.ts +1 -1
- package/src/sources/gloomberb-cloud/index.ts +14 -3
- package/src/sources/gloomberb-cloud/perpetuals.ts +60 -3
- package/src/sources/provider-router/financials.ts +20 -13
- package/src/sources/provider-router/index.ts +4 -0
- package/src/sources/provider-router/search.ts +1 -0
- package/src/sync/collections-contributor.ts +3 -1
- package/src/sync/config-merge.ts +10 -1
- package/src/sync/sanitize.ts +26 -2
- package/src/tickers/company-name-listing.ts +16 -2
- package/src/tickers/listing-fate.ts +12 -8
- package/src/tickers/renamed-listings.ts +43 -10
- package/src/tickers/search/home-listing.ts +28 -0
- package/src/tickers/search/index.ts +19 -7
- package/src/tickers/terminal-codes.ts +11 -1
- package/src/time-series/base-series.ts +3 -0
- package/src/time-series/ice-credit.ts +1 -0
- package/src/time-series/resolve.ts +3 -1
- package/src/time-series/spec.ts +2 -2
- package/src/time-series/types.ts +2 -1
- package/src/types/data-provider.ts +11 -0
- package/src/types/financials.ts +39 -3
- package/src/types/headless.ts +4 -2
- package/src/types/ticker.ts +10 -2
- package/src/utils/cli-output.ts +1 -1
- package/src/utils/declared-dividends.ts +13 -1
- package/src/utils/dividend-cash.ts +5 -1
- package/src/utils/forward-dividend.ts +4 -3
- package/src/utils/remove-folder.ts +37 -0
- package/src/utils/throttled-fetch.ts +15 -1
- package/src/utils/trailing-dividend.ts +1 -1
- package/src/plugins/builtin/composite-plugins.ts +0 -285
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import type { DemergerAction } from "../types/financials";
|
|
2
|
+
|
|
3
|
+
/** The flag a bar takes when a business was demerged out of the listing at it. */
|
|
4
|
+
export const DEMERGER_FLAG = "demerger";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A close this far below the one before can be a business leaving the line
|
|
8
|
+
* rather than the market: only then are the listing's corporate actions read
|
|
9
|
+
* beside its bars.
|
|
10
|
+
*/
|
|
11
|
+
const BREAK_FALL = 0.2;
|
|
12
|
+
|
|
13
|
+
interface DemergerRow {
|
|
14
|
+
date: string;
|
|
15
|
+
close?: number | null;
|
|
16
|
+
flag?: string | null;
|
|
17
|
+
interval?: string | null;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Whether any bar closes at least `BREAK_FALL` below the bar before it. */
|
|
21
|
+
export function hasPriceBreak(rows: readonly Pick<DemergerRow, "close">[]): boolean {
|
|
22
|
+
let previous: number | null = null;
|
|
23
|
+
for (const row of rows) {
|
|
24
|
+
if (row.close == null || !(row.close > 0)) continue;
|
|
25
|
+
if (previous != null && row.close <= previous * (1 - BREAK_FALL)) return true;
|
|
26
|
+
previous = row.close;
|
|
27
|
+
}
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** The demerger of `--json` and the note: "TMCV:NSE (Tata Motors Limited)". */
|
|
32
|
+
export function demergerSuccessor(action: Pick<DemergerAction, "successor">): string {
|
|
33
|
+
const { symbol, exchange, name } = action.successor;
|
|
34
|
+
const key = exchange ? `${symbol}:${exchange}` : symbol;
|
|
35
|
+
return name ? `${key} (${name})` : key;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* The bar a demerger's ex-date falls in: the daily bar of that session (the
|
|
40
|
+
* next one when the source has none of it), or the week's or month's bar
|
|
41
|
+
* that holds it. -1 when the bars do not reach it.
|
|
42
|
+
*/
|
|
43
|
+
function demergerBarIndex(rows: readonly DemergerRow[], exDate: string): number {
|
|
44
|
+
const day = (row: DemergerRow) => row.date.slice(0, 10);
|
|
45
|
+
const interval = rows[0]?.interval;
|
|
46
|
+
if (interval === "1wk" || interval === "1mo") {
|
|
47
|
+
const holding = rows.findLastIndex((row) => day(row) <= exDate);
|
|
48
|
+
if (holding <= 0) return -1;
|
|
49
|
+
// The last bar holds the ex-date only when its week or month runs over it.
|
|
50
|
+
const start = day(rows[holding]!);
|
|
51
|
+
const within = interval === "1mo" ? start.slice(0, 7) === exDate.slice(0, 7)
|
|
52
|
+
: Date.parse(`${exDate}T00:00:00Z`) - Date.parse(`${start}T00:00:00Z`) < 7 * 86_400_000;
|
|
53
|
+
return holding < rows.length - 1 || within ? holding : -1;
|
|
54
|
+
}
|
|
55
|
+
const first = rows.findIndex((row) => day(row) >= exDate);
|
|
56
|
+
// A bar before the ex-date is needed for the fall to be in the rows at all.
|
|
57
|
+
return first > 0 ? first : -1;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* The rows with the bar each demerger in them falls in flagged `demerger`,
|
|
62
|
+
* and the dates of those bars, oldest first: closes before them include a
|
|
63
|
+
* business the listing no longer has.
|
|
64
|
+
*/
|
|
65
|
+
export function withDemergerFlags<Row extends DemergerRow>(rows: readonly Row[], demergers: readonly DemergerAction[]): { rows: Row[]; breaks: Array<{ date: string; action: DemergerAction }> } {
|
|
66
|
+
const marked = [...rows];
|
|
67
|
+
const breaks: Array<{ date: string; action: DemergerAction }> = [];
|
|
68
|
+
for (const action of [...demergers].sort((left, right) => left.exDate.localeCompare(right.exDate))) {
|
|
69
|
+
const index = demergerBarIndex(marked, action.exDate);
|
|
70
|
+
if (index < 0) continue;
|
|
71
|
+
const row = marked[index]!;
|
|
72
|
+
const codes = (row.flag ?? "").split(",").filter(Boolean);
|
|
73
|
+
if (!codes.includes(DEMERGER_FLAG)) marked[index] = { ...row, flag: [...codes, DEMERGER_FLAG].join(",") };
|
|
74
|
+
breaks.push({ date: row.date, action });
|
|
75
|
+
}
|
|
76
|
+
return { rows: marked, breaks };
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* "On 2025-10-14 the commercial vehicles business was demerged into TMCV:NSE
|
|
81
|
+
* (Tata Motors Limited), 1 share per share, listed 2025-11-12: closes before
|
|
82
|
+
* it include that business, so the fall from 660.75 to 395.45 is no market
|
|
83
|
+
* loss (flag demerger)". Null without one in the bars.
|
|
84
|
+
*/
|
|
85
|
+
export function historyDemergerNote(
|
|
86
|
+
rows: readonly DemergerRow[],
|
|
87
|
+
breaks: ReadonlyArray<{ date: string; action: DemergerAction }>,
|
|
88
|
+
price: (value: number) => string,
|
|
89
|
+
): string | null {
|
|
90
|
+
if (breaks.length === 0) return null;
|
|
91
|
+
const parts = breaks.map(({ date, action }) => {
|
|
92
|
+
const index = rows.findIndex((row) => row.date === date);
|
|
93
|
+
const before = rows.slice(0, index).findLast((row) => row.close != null && row.close > 0)?.close;
|
|
94
|
+
const at = rows[index]?.close;
|
|
95
|
+
const what = action.business ? `the ${action.business} business was demerged` : "a business was demerged";
|
|
96
|
+
const ratio = action.ratio ? `, ${action.ratio} share per share` : "";
|
|
97
|
+
const listed = action.successor.listedOn ? `, listed ${action.successor.listedOn}` : ", not yet listed";
|
|
98
|
+
const fall = before != null && at != null ? `, so the fall from ${price(before)} to ${price(at)} is no market loss` : "";
|
|
99
|
+
return `On ${action.exDate} ${what} into ${demergerSuccessor(action)}${ratio}${listed}: closes before it include that business${fall}`;
|
|
100
|
+
});
|
|
101
|
+
return `${parts.join("; ")} (flag ${DEMERGER_FLAG})`;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* The rows split before each bar flagged `demerger`: a drawdown is measured
|
|
106
|
+
* within one run, never from a close that held the business to one that did
|
|
107
|
+
* not. Split by the bar's own flag, not its date: a weekly or monthly close
|
|
108
|
+
* is dated by its last session, not by the date its bar carries.
|
|
109
|
+
*/
|
|
110
|
+
export function demergerRuns<Row extends { flag?: string | null }>(rows: readonly Row[]): Row[][] {
|
|
111
|
+
const runs: Row[][] = [[]];
|
|
112
|
+
for (const row of rows) {
|
|
113
|
+
if ((row.flag ?? "").split(",").includes(DEMERGER_FLAG) && runs.at(-1)!.length > 0) runs.push([]);
|
|
114
|
+
runs.at(-1)!.push(row);
|
|
115
|
+
}
|
|
116
|
+
return runs;
|
|
117
|
+
}
|
package/src/cli/history-rows.ts
CHANGED
|
@@ -30,6 +30,7 @@ import { cleanFloat32Price, decimalPlaces } from "../utils/float32-price";
|
|
|
30
30
|
import { futuresBoardContract } from "../market-data/futures-board";
|
|
31
31
|
import { isFuturesInstrument } from "../market-data/futures-contract";
|
|
32
32
|
import { contractPriceUnit } from "../time-series/price-units";
|
|
33
|
+
import { DEMERGER_FLAG } from "./history-demergers";
|
|
33
34
|
|
|
34
35
|
/** A float32 price as the decimal it is, which a quote's dated close is cleaned with too (utils/float32-price). */
|
|
35
36
|
export { cleanFloat32Price };
|
|
@@ -44,8 +45,11 @@ const LATE_START_MIN_MS = 10 * DAY_MS;
|
|
|
44
45
|
const LATE_START_MIN_BARS = 3;
|
|
45
46
|
/** A close more than this many times the close before it, or less than its hundredth, follows a jump. */
|
|
46
47
|
const BREAK_JUMP_RATIO = 100;
|
|
47
|
-
/**
|
|
48
|
-
|
|
48
|
+
/**
|
|
49
|
+
* Flag codes for a break before a bar, whose prices stay as served; every other code blanks them. A demerger is one:
|
|
50
|
+
* the bar trades without a business the closes before it held.
|
|
51
|
+
*/
|
|
52
|
+
const BREAK_FLAGS: ReadonlySet<string> = new Set(["gap", "jump", DEMERGER_FLAG]);
|
|
49
53
|
const FIRST_MONDAY_MS = Date.UTC(1970, 0, 5);
|
|
50
54
|
|
|
51
55
|
export const BAR_INTERVAL_LABELS: Record<ManualChartResolution, string> = {
|
package/src/cli/index.ts
CHANGED
package/src/cli/known-gaps.ts
CHANGED
|
@@ -479,6 +479,22 @@ export function commandPointerLeads(query: string): boolean {
|
|
|
479
479
|
return findCommandPointer(query)?.leads === true;
|
|
480
480
|
}
|
|
481
481
|
|
|
482
|
+
/** The app's Send Feedback command (FB, FEEDBACK, BUG), which no function or CLI command does. */
|
|
483
|
+
const FEEDBACK_NAMES = new Set(["fb", "feedback", "bug", "bugs", "idea", "ideas"]);
|
|
484
|
+
const FEEDBACK_WORDS = new Set(["send", "report", "file", "submit", "give", "suggest", "a", "an"]);
|
|
485
|
+
|
|
486
|
+
/**
|
|
487
|
+
* The line `catalog` prints for a command of the app's command bar that is no
|
|
488
|
+
* function: `catalog FB`, `catalog feedback` and `catalog report bug` name
|
|
489
|
+
* Send Feedback, which the command bar opens as FB. Null for any other query.
|
|
490
|
+
* `search` leaves it out: FB there is a ticker.
|
|
491
|
+
*/
|
|
492
|
+
export function appCommandPointer(query: string): string | null {
|
|
493
|
+
const asked = words(query);
|
|
494
|
+
if (!asked.some((word) => FEEDBACK_NAMES.has(word)) || !asked.every((word) => FEEDBACK_NAMES.has(word) || FEEDBACK_WORDS.has(word))) return null;
|
|
495
|
+
return "Send Feedback: open the app (gloom) and run it from the command bar (Ctrl+P, FB), or open an issue at https://github.com/gloom-sh/gloomberb/issues";
|
|
496
|
+
}
|
|
497
|
+
|
|
482
498
|
/**
|
|
483
499
|
* The line for a command word typed as `gloom export LMT`: exporting is a flag every command takes, not a
|
|
484
500
|
* command, so the example runs on the symbol typed. Null for any other word.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { TOP_COIN_NAMES } from "../utils/crypto-pair";
|
|
2
|
+
import { isUsListingExchange } from "../utils/exchanges";
|
|
3
|
+
import { classifyInstrumentKind } from "../tickers/search/ranking";
|
|
4
|
+
|
|
5
|
+
let stocks: ReadonlySet<string> | undefined;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Whether the listings shipped with the app list the symbol as a stock on a US exchange, and no top coin is known by
|
|
9
|
+
* it (SOL is a coin before it is a company). Read from the shipped file the first time it is asked, a couple of
|
|
10
|
+
* milliseconds, so a command that never looks up a symbol does not load it.
|
|
11
|
+
*/
|
|
12
|
+
export function isKnownUsStock(symbol: string): boolean {
|
|
13
|
+
stocks ??= new Set((require("../tickers/search/major-listings.json") as { listings: ReadonlyArray<readonly unknown[]> }).listings
|
|
14
|
+
.filter(([, , exchange, type]) => isUsListingExchange(String(exchange)) && classifyInstrumentKind(String(type)) === "equity")
|
|
15
|
+
.map(([listed]) => String(listed).toUpperCase()));
|
|
16
|
+
const wanted = symbol.trim().toUpperCase();
|
|
17
|
+
return stocks.has(wanted) && !TOP_COIN_NAMES.has(wanted);
|
|
18
|
+
}
|
package/src/cli/listing-arg.ts
CHANGED
|
@@ -293,9 +293,38 @@ async function companyLineOn(symbol: string, exchange: string, venues: readonly
|
|
|
293
293
|
}
|
|
294
294
|
|
|
295
295
|
/** "PRU does not trade on HKEX. Prudential plc trades on HKEX as 2378:HKEX. PRU trades on: LSE, NYSE." */
|
|
296
|
-
async function notTradedText(
|
|
296
|
+
async function notTradedText(
|
|
297
|
+
listing: Pick<ListingArg, "symbol" | "exchange"> & { typed?: string },
|
|
298
|
+
venues: readonly ListingVenue[],
|
|
299
|
+
deps: ListingDeps,
|
|
300
|
+
): Promise<string> {
|
|
297
301
|
const companyLine = await companyLineOn(listing.symbol, listing.exchange, venues, deps);
|
|
298
|
-
return
|
|
302
|
+
return marketCodeNotTradedText(listing, venues, companyLine)
|
|
303
|
+
?? `${listing.symbol} does not trade on ${listing.exchange}.${companyLine}${tradesOn(listing.symbol, venues)}`;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* "IS is Bloomberg's code for NSE, where AKBNK does not trade. Did you mean
|
|
308
|
+
* AKBNK TI (AKBNK:BIST)?" for a listing typed as a Bloomberg code (`AKBNK IS`,
|
|
309
|
+
* read as AKBNK on NSE) whose symbol trades elsewhere: the code says which
|
|
310
|
+
* venue it named, and each venue the symbol is on is written the way it was
|
|
311
|
+
* typed, so the next try is one step. Null for a listing not typed so.
|
|
312
|
+
*/
|
|
313
|
+
function marketCodeNotTradedText(
|
|
314
|
+
listing: Pick<ListingArg, "symbol" | "exchange"> & { typed?: string },
|
|
315
|
+
venues: readonly ListingVenue[],
|
|
316
|
+
companyLine: string,
|
|
317
|
+
): string | null {
|
|
318
|
+
const code = listing.typed ? readTerminalListingCode(listing.typed) : null;
|
|
319
|
+
if (!code?.market || code.exchange !== listing.exchange || venues.length === 0) return null;
|
|
320
|
+
const symbol = code.symbol;
|
|
321
|
+
const choices = [...new Set(venues.map((venue) => {
|
|
322
|
+
const key = `${venue.symbol ?? symbol}:${venue.exchange}`;
|
|
323
|
+
const written = bloombergCodeOf(venue.symbol ?? symbol, venue.exchange);
|
|
324
|
+
return written ? `${written} (${key})` : key;
|
|
325
|
+
}))].slice(0, 3);
|
|
326
|
+
const meant = choices.length > 1 ? `${choices.slice(0, -1).join(", ")} or ${choices.at(-1)}` : choices[0]!;
|
|
327
|
+
return `${code.market} is Bloomberg's code for ${listing.exchange}, where ${symbol} does not trade.${companyLine} Did you mean ${meant}?`;
|
|
299
328
|
}
|
|
300
329
|
|
|
301
330
|
/** "Toronto Stock Exchange (TSX) or Tokyo Stock Exchange (JPX)". */
|
|
@@ -381,7 +410,7 @@ async function checkListingExchange(listing: ListingArg, deps: ListingDeps): Pro
|
|
|
381
410
|
* failure stands. It searches, so ask only after a request came back empty.
|
|
382
411
|
*/
|
|
383
412
|
export async function notTradedMessage(
|
|
384
|
-
listing: Pick<ListingArg, "symbol" | "exchange"
|
|
413
|
+
listing: Pick<ListingArg, "symbol" | "exchange"> & { typed?: string },
|
|
385
414
|
deps: ListingDeps,
|
|
386
415
|
): Promise<string | null> {
|
|
387
416
|
if (!listing.exchange) return null;
|
|
@@ -408,7 +437,7 @@ function withdrawnListingMessage(listing: Pick<ListingArg, "symbol" | "exchange"
|
|
|
408
437
|
|
|
409
438
|
/** Fails the command with `notTradedMessage`; returns when the symbol does trade there. */
|
|
410
439
|
export async function failIfNotTraded(
|
|
411
|
-
listing: Pick<ListingArg, "symbol" | "exchange"
|
|
440
|
+
listing: Pick<ListingArg, "symbol" | "exchange"> & { typed?: string },
|
|
412
441
|
deps: ListingDeps,
|
|
413
442
|
ctx: Pick<CliCommandContext, "fail">,
|
|
414
443
|
): Promise<void> {
|
|
@@ -436,6 +465,12 @@ export interface ListingDataRequest {
|
|
|
436
465
|
* whatever came back (`failMovedSymbol`).
|
|
437
466
|
*/
|
|
438
467
|
fate?: () => Promise<ListingFate>;
|
|
468
|
+
/**
|
|
469
|
+
* The listing's own quote, as the command reads it for itself: what says,
|
|
470
|
+
* without the fate, whether the line can have moved at all. A line whose
|
|
471
|
+
* quote trades is served as it comes back, with no lookup of its own.
|
|
472
|
+
*/
|
|
473
|
+
quote?: Promise<Quote | null>;
|
|
439
474
|
}
|
|
440
475
|
|
|
441
476
|
/**
|
|
@@ -1327,9 +1362,11 @@ export async function failUnchosenListing(
|
|
|
1327
1362
|
* calls what it returned empty, and a listing's exchange is one its symbol does
|
|
1328
1363
|
* not trade on, the command ends in that message instead of the request's own
|
|
1329
1364
|
* "unavailable". With `request`, a bare symbol no source serves ends naming
|
|
1330
|
-
* its other listings (`otherListingsMessage`), and
|
|
1331
|
-
*
|
|
1332
|
-
*
|
|
1365
|
+
* its other listings (`otherListingsMessage`), and a symbol whose company
|
|
1366
|
+
* moved ends naming its new symbol, served or not. A request that succeeds
|
|
1367
|
+
* costs no extra lookup beyond the fate the command reads anyway, or, given
|
|
1368
|
+
* the command's own quote (`request.quote`), beyond a quote that says the
|
|
1369
|
+
* line stopped.
|
|
1333
1370
|
*/
|
|
1334
1371
|
export async function loadForListing<T>(
|
|
1335
1372
|
listings: ListingForLoad | readonly ListingForLoad[],
|
|
@@ -1342,24 +1379,55 @@ export async function loadForListing<T>(
|
|
|
1342
1379
|
const all = "symbol" in listings ? [listings] : listings;
|
|
1343
1380
|
const named = all.filter((listing) => listing.exchange);
|
|
1344
1381
|
const checkVenues = () => Promise.all(named.map((listing) => failIfNotTraded(listing, deps, ctx)));
|
|
1382
|
+
// One listing a command asked for: a company that moved ends the command naming its new symbol, as `quote` names
|
|
1383
|
+
// it, whether the load came back empty or failed (FI's window before the listing that reused the symbol has no bars
|
|
1384
|
+
// at all) or served the old line (FI's 2024 statements). A command that reads the fate itself asks it either way.
|
|
1385
|
+
// Otherwise a load that served asks only when the command's own quote says the line stopped, so a symbol that
|
|
1386
|
+
// trades costs no lookup; a load that failed or came back empty asks with the quote it has, or reads one.
|
|
1387
|
+
const one = request && all.length === 1 ? all[0]! : null;
|
|
1388
|
+
const refuseMoved = async (served: boolean) => {
|
|
1389
|
+
if (!one || !request) return;
|
|
1390
|
+
const quote = request.fate || !request.quote ? undefined : await request.quote.catch(() => {
|
|
1391
|
+
// Intentional ignore: the quote is the command's own read, which reports its failure; with none, the line reads as unquoted.
|
|
1392
|
+
return null;
|
|
1393
|
+
});
|
|
1394
|
+
if (served && !request.fate && (quote === undefined || !lineMayHaveMoved(quote))) return;
|
|
1395
|
+
const moved = (await (request.fate ?? commandFate(one, deps, quote))()).moved;
|
|
1396
|
+
if (moved) failMovedSymbol(moved, request);
|
|
1397
|
+
};
|
|
1345
1398
|
let value: T;
|
|
1346
1399
|
try {
|
|
1347
1400
|
value = await load();
|
|
1348
1401
|
} catch (error) {
|
|
1349
1402
|
await checkVenues();
|
|
1403
|
+
await refuseMoved(false);
|
|
1350
1404
|
if (request && all.length === 1 && isNoProviderError(error)) await failUnservedListing(ctx, request, otherListingsMessage(all[0]!, deps, request));
|
|
1351
1405
|
throw error;
|
|
1352
1406
|
}
|
|
1353
|
-
|
|
1407
|
+
const missed = isMiss?.(value) === true;
|
|
1408
|
+
if (missed) await checkVenues();
|
|
1354
1409
|
// Data came back, but the symbol's company moved and nothing new lists there: the data is another security's.
|
|
1355
|
-
|
|
1356
|
-
const { moved } = await request.fate();
|
|
1357
|
-
if (moved) failMovedSymbol(moved, request);
|
|
1358
|
-
}
|
|
1410
|
+
await refuseMoved(!missed);
|
|
1359
1411
|
return value;
|
|
1360
1412
|
}
|
|
1361
1413
|
|
|
1362
|
-
|
|
1414
|
+
/**
|
|
1415
|
+
* The fate of a command's one listing when the command did not look it up
|
|
1416
|
+
* itself (`listingFateLoader`), read with the quote the command has (`quote`;
|
|
1417
|
+
* left out, the fate reads one). A symbol the change history is not about (a
|
|
1418
|
+
* listing abroad, a pair) asks nothing of it.
|
|
1419
|
+
*/
|
|
1420
|
+
function commandFate(listing: ListingForLoad, deps: Pick<ListingDeps, "dataProvider">, quote?: Quote | null): () => Promise<ListingFate> {
|
|
1421
|
+
let fate: Promise<ListingFate> | null = null;
|
|
1422
|
+
return () => fate ??= loadListingFate(listing, deps.dataProvider, quote === undefined ? {} : { quote });
|
|
1423
|
+
}
|
|
1424
|
+
|
|
1425
|
+
/** A command that ended naming the new symbol of a company that moved (`failMovedSymbol`). */
|
|
1426
|
+
export function isMovedSymbolFailure(error: unknown): boolean {
|
|
1427
|
+
return error instanceof Error && (error as { code?: unknown }).code === "ticker_moved";
|
|
1428
|
+
}
|
|
1429
|
+
|
|
1430
|
+
type ListingForLoad = Pick<ListingArg, "symbol" | "exchange"> & Partial<Pick<CliListing, "saved" | "request">>;
|
|
1363
1431
|
|
|
1364
1432
|
/** The saved ticker for a listing: under its own key, or a saved symbol whose venue it is. */
|
|
1365
1433
|
export async function loadSavedListing(store: ListingStore, listing: ListingArg): Promise<TickerRecord | null> {
|
|
@@ -1827,11 +1895,33 @@ async function refuseUnknownMarketCode(typed: string, deps: ListingDeps): Promis
|
|
|
1827
1895
|
async function checkTerminalCodeVenue(listing: ListingArg, market: string, deps: ListingDeps): Promise<void> {
|
|
1828
1896
|
const hint = bloombergMarketHint(market);
|
|
1829
1897
|
if (!hint && !isSearchOnlyVenue(listing.exchange)) return;
|
|
1830
|
-
|
|
1831
|
-
|
|
1898
|
+
// Only what search answers refuses the code: a busy or unreachable search leaves the listing's own request to speak.
|
|
1899
|
+
const venues = await listingVenues(listing.symbol, deps, { failTransient: true })
|
|
1900
|
+
.catch(logFailure("cli.listing-arg", "Read listing venues failed", null));
|
|
1901
|
+
if (!venues) return;
|
|
1902
|
+
const there = venues.filter((venue) => venue.exchange === listing.exchange);
|
|
1903
|
+
const own = (venue: ListingVenue) => !venue.symbol || venue.symbol.toUpperCase() === listing.symbol.toUpperCase();
|
|
1904
|
+
if (there.some(own) || (there.length > 0 && !hint)) return;
|
|
1905
|
+
// Where the codes differ, Bloomberg's ticker can name the company search lists there under the venue's code
|
|
1906
|
+
// (ARAMCO AB is Saudi Aramco, 2222 on Tadawul): say which one to type.
|
|
1907
|
+
const listed = there.find((venue) => !own(venue));
|
|
1908
|
+
const line = !hint ? null : listed ? { symbol: listed.symbol!, name: listed.name.trim() } : await venueLineNamed(listing, deps);
|
|
1909
|
+
if (line) {
|
|
1910
|
+
throw new ListingArgError(`${listing.symbol} is not a ${listing.exchange} code; did you mean ${line.symbol} ${market}${line.name ? ` (${line.name})` : ""}?`, hint!);
|
|
1911
|
+
}
|
|
1912
|
+
// Search lists the symbol nowhere: the request's own answer says what it finds, as it did before codes were checked.
|
|
1913
|
+
if (venues.length === 0) return;
|
|
1832
1914
|
throw new ListingArgError(await notTradedText(listing, venues, deps), hint ?? undefined);
|
|
1833
1915
|
}
|
|
1834
1916
|
|
|
1917
|
+
/** The one line search lists on the listing's venue for its symbol read as a name (ARAMCO: 2222 on TADAWUL); null for none or several. */
|
|
1918
|
+
async function venueLineNamed(listing: ListingArg, deps: ListingDeps): Promise<{ symbol: string; name: string } | null> {
|
|
1919
|
+
const found = await deps.dataProvider.search(listing.symbol).catch(logFailure("cli.listing-arg", "Search a code's company failed", []));
|
|
1920
|
+
const lines = found.filter((result) => canonicalExchange(result.exchange || result.primaryExchange) === listing.exchange);
|
|
1921
|
+
const symbols = [...new Set(lines.map((result) => parsePublicTickerKey(result.symbol).symbol))];
|
|
1922
|
+
return symbols.length === 1 && symbols[0] !== listing.symbol.toUpperCase() ? { symbol: symbols[0]!, name: lines[0]!.name.trim() } : null;
|
|
1923
|
+
}
|
|
1924
|
+
|
|
1835
1925
|
/**
|
|
1836
1926
|
* The index a broker's code names, as a listing: VIX.X and $VIX.X at once,
|
|
1837
1927
|
* $VIX when the sources answer that nothing trades as VIX. `$MOVE` stays
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { join } from "path";
|
|
2
|
+
import type { GloomPlugin } from "../../types/plugin";
|
|
3
|
+
import { createDefaultConfig } from "../../types/config";
|
|
4
|
+
import { catalogSeriesFacts } from "../series-search";
|
|
5
|
+
import type { MarketContext } from "../types";
|
|
6
|
+
import { getHeadlessPaneDefinition } from "./capabilities";
|
|
7
|
+
import { buildPaneCatalogEntries, buildPaneFunctionLookup } from "./catalog";
|
|
8
|
+
import type { CatalogSnapshot, CatalogSnapshotEntry } from "./catalog-snapshot";
|
|
9
|
+
import { createPaneCatalog } from "./discovery";
|
|
10
|
+
import { namesFunction } from "./resolver";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The built-in plugins `fn` may set up without the others: nothing outside one of them reads what its setup leaves
|
|
14
|
+
* behind (a persistence a client attaches, a notification watch), as the FRED series cache rates-macro attaches is
|
|
15
|
+
* read by the chart composer and the other plugins that chart a macro series. `plugin-coupling.test.ts` fails when
|
|
16
|
+
* code one of these plugins loads calls a setup effect that another plugin's module owns.
|
|
17
|
+
*/
|
|
18
|
+
export const SELF_CONTAINED_PLUGINS: readonly string[] = ["ownership", "news", "screeners"];
|
|
19
|
+
|
|
20
|
+
const SENTINEL_LIST = { id: "catalog-snapshot-list", name: "Catalog Snapshot List" };
|
|
21
|
+
|
|
22
|
+
/** A context whose first list holds a symbol (`withList`), or one with no list that holds any. */
|
|
23
|
+
function snapshotContext(withList: boolean): MarketContext {
|
|
24
|
+
const config = createDefaultConfig("/catalog-snapshot");
|
|
25
|
+
if (withList) config.watchlists = [{ id: SENTINEL_LIST.id, name: SENTINEL_LIST.name }];
|
|
26
|
+
const held = withList ? [{ metadata: { watchlists: [SENTINEL_LIST.id], portfolios: [], positions: [] } }] : [];
|
|
27
|
+
return { config, store: { loadAllTickers: async () => held } } as unknown as MarketContext;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** The catalog of `plugins` as a fresh profile reads it, with the series they declare. */
|
|
31
|
+
export async function buildCatalogSnapshot(plugins: GloomPlugin[]): Promise<CatalogSnapshot> {
|
|
32
|
+
const context = snapshotContext(false);
|
|
33
|
+
// One plugin at a time, each torn down before the next is set up: setups leave state that a dispose undoes.
|
|
34
|
+
const owners = new Map<string, string>();
|
|
35
|
+
for (const plugin of plugins) {
|
|
36
|
+
const own = await createPaneCatalog(context, [plugin]);
|
|
37
|
+
try {
|
|
38
|
+
for (const id of own.paneTemplates.keys()) owners.set(`template:${id}`, plugin.id);
|
|
39
|
+
for (const id of own.panes.keys()) owners.set(`pane:${id}`, plugin.id);
|
|
40
|
+
} finally {
|
|
41
|
+
own.destroy();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const registry = await createPaneCatalog(context, plugins);
|
|
45
|
+
try {
|
|
46
|
+
const bare = await buildPaneCatalogEntries(registry, context);
|
|
47
|
+
const listed = await buildPaneCatalogEntries(registry, snapshotContext(true));
|
|
48
|
+
const entries = bare.map((entry, index): CatalogSnapshotEntry => {
|
|
49
|
+
const { argExamples, ...rest } = entry;
|
|
50
|
+
const pluginId = (entry.templateId ? owners.get(`template:${entry.templateId}`) : undefined) ?? owners.get(`pane:${entry.paneId}`);
|
|
51
|
+
if (!pluginId) throw new Error(`No plugin holds the function ${entry.token}.`);
|
|
52
|
+
return {
|
|
53
|
+
...rest,
|
|
54
|
+
pluginId,
|
|
55
|
+
...argExamples ? { examples: [...argExamples] } : {},
|
|
56
|
+
...(listed[index]?.argExamples?.length ?? 0) > (argExamples?.length ?? 0) ? { listArgument: true as const } : {},
|
|
57
|
+
};
|
|
58
|
+
});
|
|
59
|
+
// A coded function that reports data, of plugins that stand alone, is found by the words that name it; `fn` then loads only them.
|
|
60
|
+
const order = new Map(plugins.map((plugin, index) => [plugin.id, index]));
|
|
61
|
+
const functions: Record<string, string[]> = {};
|
|
62
|
+
for (const [word, found] of buildPaneFunctionLookup(registry)) {
|
|
63
|
+
if (!("paneId" in found && "description" in found) || !found.shortcut?.prefix) continue;
|
|
64
|
+
const pane = registry.panes.get(found.paneId);
|
|
65
|
+
const holders = [...new Set([owners.get(`template:${found.id}`), owners.get(`pane:${found.paneId}`)])]
|
|
66
|
+
.filter((id): id is string => !!id).sort((a, b) => order.get(a)! - order.get(b)!);
|
|
67
|
+
if (pane && holders.length > 0 && holders.every((id) => SELF_CONTAINED_PLUGINS.includes(id))
|
|
68
|
+
&& getHeadlessPaneDefinition(found, pane) && namesFunction(found, pane, word)) functions[word] = holders;
|
|
69
|
+
}
|
|
70
|
+
return { entries, series: catalogSeriesFacts(plugins), functions: Object.fromEntries(Object.entries(functions).sort(([a], [b]) => a.localeCompare(b))) };
|
|
71
|
+
} finally {
|
|
72
|
+
registry.destroy();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export const CATALOG_SNAPSHOT_PATH = join(import.meta.dir, "catalog-snapshot.json");
|
|
77
|
+
|
|
78
|
+
/** One line to a function and to a series, so a change to one reads as a change to one line. */
|
|
79
|
+
export function renderCatalogSnapshot(snapshot: CatalogSnapshot): string {
|
|
80
|
+
const lines = (rows: readonly unknown[]) => rows.map((row) => ` ${JSON.stringify(row)}`).join(",\n");
|
|
81
|
+
const functions = Object.entries(snapshot.functions).map(([word, holders]) => ` ${JSON.stringify(word)}: ${JSON.stringify(holders)}`).join(",\n");
|
|
82
|
+
return `{\n "entries": [\n${lines(snapshot.entries)}\n ],\n "series": [\n${lines(snapshot.series)}\n ],\n "functions": {\n${functions}\n }\n}\n`;
|
|
83
|
+
}
|