@gloom-sh/terminal 0.20.3 → 0.20.5
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/README.md +2 -0
- package/bin/gloom +9 -0
- package/bin/without-bun.cjs +98 -0
- package/package.json +3 -1
- package/src/account/auth-dialog.tsx +17 -0
- package/src/api-client/data.ts +144 -35
- package/src/api-client/fx-interventions.ts +64 -0
- package/src/api-client/index.ts +1 -0
- package/src/api-client/release-summaries.ts +21 -0
- package/src/api-client/types/econ.ts +12 -0
- package/src/api-client/yield-curves.ts +1 -1
- package/src/app/global-shortcuts.ts +4 -1
- package/src/app/keybindings/actions.ts +8 -2
- package/src/app/keybindings/config.ts +2 -1
- package/src/app/keybindings/index.ts +1 -0
- package/src/app/keybindings/labels.ts +6 -1
- package/src/app/keybindings/resolve.ts +23 -4
- package/src/app/keybindings/terminal-keys.ts +35 -0
- package/src/app/pane-runtime/index.tsx +2 -2
- package/src/app/pane-runtime/ticker-open-runtime.ts +274 -67
- package/src/architecture/ui-literals-allowlist.json +1 -1
- package/src/capabilities/chart-series.ts +27 -1
- package/src/cli/commands/keybindings.ts +5 -5
- package/src/cli/commands/market.ts +154 -21
- package/src/cli/commands/news-search.ts +60 -10
- package/src/cli/commands/overview.ts +16 -1
- package/src/cli/commands/plugins.ts +27 -5
- package/src/cli/commands/remote.ts +16 -17
- package/src/cli/commands/system.ts +20 -4
- package/src/cli/commands/ticker.ts +60 -19
- package/src/cli/fx-forward.ts +25 -7
- package/src/cli/glossary.ts +19 -5
- package/src/cli/history-rows.ts +5 -3
- package/src/cli/index.ts +8 -8
- package/src/cli/known-gaps.ts +27 -1
- package/src/cli/listing-arg.ts +11 -1
- package/src/cli/name-entries.ts +5 -1
- package/src/cli/not-a-ticker.ts +4 -0
- package/src/cli/pane-functions/function-help.ts +5 -5
- package/src/cli/report-tables.ts +18 -6
- package/src/cli/result.ts +15 -7
- package/src/cli/types.ts +2 -0
- package/src/components/chart/composite/axis-overlays.tsx +22 -0
- package/src/components/chart/composite/composite-chart.tsx +54 -13
- package/src/components/chart/composite/event-captions.ts +109 -0
- package/src/components/chart/composite/event-guides.ts +74 -0
- package/src/components/chart/composite/rasterizer.ts +2 -0
- package/src/components/chart/composite/text-renderer.ts +2 -0
- package/src/components/chart/composite/types.ts +31 -0
- package/src/components/command-bar/layout-items/focused-pane.ts +5 -5
- package/src/components/command-bar/pane-settings.ts +2 -2
- package/src/components/command-bar/routes/root/provider-search.ts +5 -4
- package/src/components/command-bar/routes/root/results.ts +6 -2
- package/src/components/command-bar/routes/ticker-search/results.ts +51 -0
- package/src/components/command-bar/routes/ticker-search/route.ts +3 -2
- package/src/components/input-search-bar.tsx +9 -2
- package/src/components/layout/detached-pane-shell.tsx +1 -1
- package/src/components/layout/floating-pane.tsx +5 -1
- package/src/components/layout/pane/footer/index.tsx +21 -14
- package/src/components/layout/pane/footer/model.ts +6 -0
- package/src/components/layout/pane/header.tsx +2 -0
- package/src/components/layout/shell/action-menu-overlay.tsx +10 -5
- package/src/components/layout/shell/active-drag.ts +149 -105
- package/src/components/layout/shell/drag/drop-zones.ts +162 -0
- package/src/components/layout/shell/drag/index.ts +47 -218
- package/src/components/layout/shell/drag/live.ts +10 -3
- package/src/components/layout/shell/drag/overlays.tsx +182 -5
- package/src/components/layout/shell/drag/runtime.ts +29 -6
- package/src/components/layout/shell/drag/shared-edges.ts +156 -0
- package/src/components/layout/shell/index.tsx +11 -6
- package/src/components/layout/shell/menu.ts +11 -2
- package/src/components/layout/shell/native/pointer-runtime.ts +25 -0
- package/src/components/layout/shell/native/window-state.ts +2 -2
- package/src/components/layout/shell/pane/capture.ts +4 -1
- package/src/components/layout/shell/pane/layers.tsx +71 -7
- package/src/components/layout/shell/terminal-pointer-runtime.ts +18 -9
- package/src/components/layout/shell/window-mode/index.ts +8 -10
- package/src/components/layout/status-bar.tsx +6 -1
- package/src/components/layout/window-edit/mode.ts +39 -7
- package/src/components/layout/window-edit/presentation.ts +1 -1
- package/src/components/onboarding/first-run-workspace.ts +44 -2
- package/src/components/onboarding/onboarding-frame.tsx +11 -2
- package/src/components/onboarding/onboarding-keyboard.ts +20 -0
- package/src/components/onboarding/onboarding-wizard.tsx +16 -11
- package/src/components/onboarding/portfolio-step/positions-panel.tsx +62 -1
- package/src/components/onboarding/use-onboarding-progress.ts +12 -4
- package/src/components/pane-settings-dialog/desktop.tsx +2 -2
- package/src/components/pane-settings-dialog/tui.tsx +2 -2
- package/src/components/pane-settings-dialog/value.ts +6 -0
- package/src/components/pane-settings-dialog.tsx +3 -3
- package/src/components/reader/detail-reader.tsx +4 -0
- package/src/components/ui/button.tsx +2 -0
- package/src/components/ui/choice-dialog.tsx +1 -0
- package/src/components/ui/data-table/index.tsx +4 -3
- package/src/components/ui/index.ts +1 -1
- package/src/components/ui/list-view.tsx +7 -12
- package/src/components/ui/loading.tsx +10 -3
- package/src/components/ui/menu.tsx +6 -2
- package/src/components/ui/page-stack-view.tsx +3 -0
- package/src/components/ui/pane-link-chip.tsx +269 -54
- package/src/components/ui/query-bar.tsx +2 -1
- package/src/components/ui/quote.ts +14 -1
- package/src/components/ui/tabs.tsx +97 -19
- package/src/core/state/app/layout-reducer.ts +7 -0
- package/src/core/state/app/layout.ts +44 -7
- package/src/core/state/app/state.ts +1 -1
- package/src/core/state/app/types.ts +22 -2
- package/src/data/config/layout.ts +5 -2
- package/src/docs/snapshot.json +54 -13
- package/src/i18n/es.ts +9 -8
- package/src/i18n/ja.ts +9 -8
- package/src/i18n/ko.ts +9 -8
- package/src/i18n/zh-cn.ts +9 -8
- package/src/i18n/zh-tw.ts +9 -8
- package/src/layout/pane-manager/floating-actions.ts +17 -0
- package/src/layout/pane-manager/floating-stack.ts +187 -0
- package/src/layout/pane-manager/floating.ts +4 -2
- package/src/layout/pane-manager/gridlock.ts +5 -1
- package/src/layout/pane-manager/index.ts +11 -0
- package/src/layout/pane-manager/layout-state.ts +10 -3
- package/src/market-data/depositary-pair.ts +5 -3
- package/src/market-data/futures-board.ts +46 -1
- package/src/market-data/futures-contract.ts +12 -3
- package/src/market-data/fx-interventions.ts +270 -0
- package/src/market-data/market/dated-previous-close.ts +94 -15
- package/src/market-data/market/status.ts +17 -1
- package/src/news/news-model.ts +44 -2
- package/src/plugins/builtin/alerts/cli.ts +4 -4
- package/src/plugins/builtin/alerts/format.ts +1 -2
- package/src/plugins/builtin/alerts/headless.ts +1 -2
- package/src/plugins/builtin/alerts/move-checks.ts +12 -6
- package/src/plugins/builtin/alerts/move.ts +30 -9
- package/src/plugins/builtin/alerts/pane.tsx +0 -2
- package/src/plugins/builtin/alerts/storage.ts +4 -2
- package/src/plugins/builtin/alerts/types.ts +12 -0
- package/src/plugins/builtin/analytics/risk-client.ts +10 -4
- package/src/plugins/builtin/analytics/risk-episodes.ts +5 -4
- package/src/plugins/builtin/analytics/risk-headless.ts +4 -2
- package/src/plugins/builtin/analytics/risk-sectors.ts +91 -0
- package/src/plugins/builtin/awards/index.tsx +1 -1
- package/src/plugins/builtin/buildout/index.tsx +1 -0
- package/src/plugins/builtin/catalysts/index.tsx +2 -2
- package/src/plugins/builtin/cds/headless.ts +4 -0
- package/src/plugins/builtin/changelog/index.tsx +292 -101
- package/src/plugins/builtin/changelog/versions.ts +293 -0
- package/src/plugins/builtin/chart-composer/headless.ts +2 -1
- package/src/plugins/builtin/chart-composer/index.tsx +1 -0
- package/src/plugins/builtin/chart-composer/intervention-events.ts +105 -0
- package/src/plugins/builtin/chart-composer/pane.tsx +21 -7
- package/src/plugins/builtin/chat/content/composer.tsx +5 -4
- package/src/plugins/builtin/chat/content/index.tsx +12 -2
- package/src/plugins/builtin/chat/content/layout-metrics.ts +3 -3
- package/src/plugins/builtin/chat/content/open-targets.ts +3 -3
- package/src/plugins/builtin/chat/layout.ts +5 -2
- package/src/plugins/builtin/chat/message/pane-chip.tsx +61 -40
- package/src/plugins/builtin/chat/message/render-state.ts +2 -5
- package/src/plugins/builtin/chat/message/terminal.tsx +13 -15
- package/src/plugins/builtin/chat/pane-links/previews.ts +51 -5
- package/src/plugins/builtin/chat/pane-links/share-card.ts +36 -0
- package/src/plugins/builtin/cloud/askg/attached-pane.tsx +10 -5
- package/src/plugins/builtin/cloud/askg/controller.ts +141 -5
- package/src/plugins/builtin/cloud/askg/executor.ts +113 -4
- package/src/plugins/builtin/cloud/askg/manifest.ts +28 -13
- package/src/plugins/builtin/cloud/askg/model.ts +14 -4
- package/src/plugins/builtin/cloud/askg/pane.tsx +70 -46
- package/src/plugins/builtin/cloud/askg/tool-display.ts +1 -0
- package/src/plugins/builtin/cloud/askg/turn-parts.tsx +70 -0
- package/src/plugins/builtin/cloud/terminal-relay/engine.ts +50 -130
- package/src/plugins/builtin/cloud/terminal-relay/policy.ts +327 -7
- package/src/plugins/builtin/cloud/terminal-relay/prompts.tsx +2 -1
- package/src/plugins/builtin/cloud/terminal-relay/redact.ts +52 -9
- package/src/plugins/builtin/commodities-energy/index.tsx +1 -3
- package/src/plugins/builtin/commodities-energy/view-state.ts +3 -0
- package/src/plugins/builtin/commodity-balances/index.tsx +1 -0
- package/src/plugins/builtin/company-attention/index.tsx +1 -1
- package/src/plugins/builtin/company-kpis/headless.ts +3 -1
- package/src/plugins/builtin/company-kpis/index.tsx +2 -2
- package/src/plugins/builtin/cot/headless.ts +14 -2
- package/src/plugins/builtin/cot/index.tsx +1 -1
- package/src/plugins/builtin/cpi/index.tsx +1 -1
- package/src/plugins/builtin/crypto-board/index.tsx +1 -0
- package/src/plugins/builtin/dividend-yield/index.tsx +1 -0
- package/src/plugins/builtin/doe/index.tsx +1 -1
- package/src/plugins/builtin/earnings/index.tsx +2 -2
- package/src/plugins/builtin/earnings-calls/headless.ts +5 -1
- package/src/plugins/builtin/earnings-calls/index.tsx +1 -0
- package/src/plugins/builtin/econ/calendar-model.ts +74 -1
- package/src/plugins/builtin/econ/fred-catalog.ts +3 -1
- package/src/plugins/builtin/econ/index.tsx +1 -0
- package/src/plugins/builtin/econ-statistics/index.tsx +1 -0
- package/src/plugins/builtin/econ-statistics/pane.tsx +6 -0
- package/src/plugins/builtin/estimate-revisions/index.tsx +1 -0
- package/src/plugins/builtin/executives/index.tsx +1 -0
- package/src/plugins/builtin/filing-events/index.tsx +1 -0
- package/src/plugins/builtin/fixed-income/index.tsx +1 -0
- package/src/plugins/builtin/futures/index.tsx +25 -4
- package/src/plugins/builtin/futures/model.ts +28 -32
- package/src/plugins/builtin/futures/series.ts +4 -3
- package/src/plugins/builtin/futures/table.tsx +16 -9
- package/src/plugins/builtin/futures/use-board-terms.ts +3 -3
- package/src/plugins/builtin/futures-curve/headless.ts +3 -3
- package/src/plugins/builtin/futures-curve/index.tsx +1 -1
- package/src/plugins/builtin/futures-curve/model.ts +18 -0
- package/src/plugins/builtin/gpu/index.tsx +1 -1
- package/src/plugins/builtin/help/functions-table.tsx +1 -1
- package/src/plugins/builtin/help/index.tsx +14 -4
- package/src/plugins/builtin/help/keybindings-editor.tsx +19 -5
- package/src/plugins/builtin/holders/index.tsx +1 -0
- package/src/plugins/builtin/holders/report-header.ts +2 -2
- package/src/plugins/builtin/insider/index.tsx +1 -0
- package/src/plugins/builtin/iv-history/index.tsx +1 -1
- package/src/plugins/builtin/jobs/index.tsx +1 -0
- package/src/plugins/builtin/layout-manager/index.tsx +8 -8
- package/src/plugins/builtin/macro-day/headless.ts +27 -8
- package/src/plugins/builtin/macro-day/index.tsx +1 -1
- package/src/plugins/builtin/macro-day/model.ts +19 -3
- package/src/plugins/builtin/macro-day/pane.tsx +14 -9
- package/src/plugins/builtin/macro-day/releases.ts +25 -7
- package/src/plugins/builtin/market-valuation/index.tsx +1 -0
- package/src/plugins/builtin/market-valuation/pane.tsx +8 -0
- package/src/plugins/builtin/members/index.tsx +1 -1
- package/src/plugins/builtin/mna/index.tsx +1 -0
- package/src/plugins/builtin/news/headless.ts +2 -2
- package/src/plugins/builtin/news/index.tsx +4 -3
- package/src/plugins/builtin/news/wire/index.tsx +5 -1
- package/src/plugins/builtin/news/wire/news/detail-view.tsx +4 -0
- package/src/plugins/builtin/news/wire/news/list-search.ts +5 -2
- package/src/plugins/builtin/options/index.tsx +1 -0
- package/src/plugins/builtin/options-positioning/index.tsx +1 -0
- package/src/plugins/builtin/pe-band/index.tsx +1 -1
- package/src/plugins/builtin/perps/markets-section.tsx +5 -2
- package/src/plugins/builtin/plugin-marketplace/pane.tsx +11 -11
- package/src/plugins/builtin/portfolio-list/cli/portfolio-command.ts +25 -0
- package/src/plugins/builtin/portfolio-list/headless.ts +15 -6
- package/src/plugins/builtin/portfolio-list/summary/index.tsx +3 -1
- package/src/plugins/builtin/power/index.tsx +1 -1
- package/src/plugins/builtin/realized-vol/index.tsx +1 -1
- package/src/plugins/builtin/research/event-model.ts +9 -1
- package/src/plugins/builtin/research/event-sources.ts +22 -0
- package/src/plugins/builtin/research/headless.ts +11 -5
- package/src/plugins/builtin/research/index.tsx +4 -0
- package/src/plugins/builtin/research-search/index.tsx +1 -0
- package/src/plugins/builtin/research-search/pane.tsx +8 -0
- package/src/plugins/builtin/revenue-breakdown/index.tsx +1 -0
- package/src/plugins/builtin/reverse-dcf/index.tsx +1 -1
- package/src/plugins/builtin/risk-factors/index.tsx +1 -0
- package/src/plugins/builtin/scanner/headless.ts +52 -13
- package/src/plugins/builtin/seasonality/index.tsx +1 -1
- package/src/plugins/builtin/sec/index.tsx +1 -0
- package/src/plugins/builtin/series-inventory.ts +1 -1
- package/src/plugins/builtin/shared/cloud-upgrade.ts +27 -3
- package/src/plugins/builtin/shared/scanner-capture.ts +11 -3
- package/src/plugins/builtin/shared/series-list-detail.tsx +5 -0
- package/src/plugins/builtin/short-interest/index.tsx +1 -0
- package/src/plugins/builtin/social-mentions/index.tsx +1 -1
- package/src/plugins/builtin/supply-chain/index.tsx +1 -0
- package/src/plugins/builtin/thirteenf/data.ts +43 -10
- package/src/plugins/builtin/thirteenf/headless.ts +55 -11
- package/src/plugins/builtin/thirteenf/model.ts +25 -9
- package/src/plugins/builtin/thirteenf/report-notes.ts +27 -6
- package/src/plugins/builtin/thirteenf/types.ts +2 -0
- package/src/plugins/builtin/ticker-detail/adr-pair/model.ts +1 -1
- package/src/plugins/builtin/ticker-detail/financials/model.ts +12 -0
- package/src/plugins/builtin/ticker-detail/financials/ratio-table.tsx +3 -3
- package/src/plugins/builtin/ticker-detail/financials/tab.tsx +5 -5
- package/src/plugins/builtin/ticker-detail/headless.ts +18 -13
- package/src/plugins/builtin/ticker-detail/index.tsx +4 -0
- package/src/plugins/builtin/ticker-detail/overview/components.tsx +54 -5
- package/src/plugins/builtin/ticker-detail/overview/model.ts +6 -4
- package/src/plugins/builtin/ticker-detail/overview-tab.tsx +34 -17
- package/src/plugins/builtin/ticker-detail/pane.tsx +7 -2
- package/src/plugins/builtin/time-sales/client.ts +9 -11
- package/src/plugins/builtin/time-sales/index.tsx +1 -1
- package/src/plugins/builtin/treasury-auctions/after.ts +267 -0
- package/src/plugins/builtin/treasury-auctions/cache.ts +18 -3
- package/src/plugins/builtin/treasury-auctions/client.ts +33 -2
- package/src/plugins/builtin/treasury-auctions/headless.ts +109 -19
- package/src/plugins/builtin/treasury-auctions/index.tsx +14 -4
- package/src/plugins/builtin/treasury-auctions/model.ts +256 -28
- package/src/plugins/builtin/treasury-auctions/pane.tsx +139 -28
- package/src/plugins/builtin/treasury-auctions/treasury-direct.ts +5 -2
- package/src/plugins/builtin/treasury-auctions/types.ts +7 -1
- package/src/plugins/builtin/vol-surface/index.tsx +1 -1
- package/src/plugins/builtin/world-venue-map/index.ts +1 -0
- package/src/plugins/builtin/yield-curve/curves.ts +10 -4
- package/src/plugins/builtin/yield-curve/headless.ts +6 -2
- package/src/plugins/builtin/yield-curve/index.tsx +3 -3
- package/src/plugins/builtin/yield-curve/series.ts +10 -0
- package/src/plugins/builtin/yield-curve/world.ts +3 -1
- package/src/plugins/installer.ts +45 -0
- package/src/portfolio/column-values.ts +2 -1
- package/src/public/__snapshots__/public-api.test.ts.snap +4 -0
- package/src/public/remote.ts +7 -1
- package/src/remote/client.ts +191 -11
- package/src/remote/controller-utils.ts +13 -1
- package/src/remote/controller.ts +88 -26
- package/src/remote/endpoint.ts +24 -0
- package/src/remote/form.ts +59 -4
- package/src/remote/resources.ts +56 -19
- package/src/remote/schema.ts +22 -9
- package/src/remote/secrets.ts +12 -0
- package/src/remote/semantic-helpers.ts +29 -1
- package/src/remote/semantic-tree.tsx +44 -15
- package/src/remote/server.ts +2 -1
- package/src/remote/surface.tsx +192 -0
- package/src/remote/types.ts +5 -0
- package/src/renderers/cloudflare/worker.ts +16 -1
- package/src/renderers/dom/styles.css +40 -6
- package/src/renderers/opentui/host.tsx +6 -0
- package/src/renderers/share/layout-view.tsx +1 -1
- package/src/series/standalone.ts +2 -2
- package/src/shares/api.ts +21 -4
- package/src/shares/item.ts +73 -0
- package/src/shares/pane-item.ts +205 -0
- package/src/shares/pane.ts +4 -0
- package/src/shares/payload.ts +9 -5
- package/src/sources/gloomberb-cloud/news.ts +37 -12
- package/src/state/opening-ticker-panes.ts +47 -0
- package/src/test-support/cli-context.ts +2 -0
- package/src/test-support/preload.ts +4 -1
- package/src/tickers/instrument-kind.ts +23 -3
- package/src/tickers/renamed-listings.ts +105 -0
- package/src/tickers/search/index.ts +103 -16
- package/src/time-series/resolve.ts +2 -2
- package/src/types/config.ts +5 -0
- package/src/types/context-menu.ts +2 -0
- package/src/types/financials.ts +1 -0
- package/src/types/plugin-commands.ts +140 -0
- package/src/types/plugin-context.ts +125 -0
- package/src/types/plugin-contributions.ts +55 -0
- package/src/types/plugin-definition.ts +234 -0
- package/src/types/plugin-notifications.ts +38 -0
- package/src/types/plugin-pane-settings.ts +116 -0
- package/src/types/plugin-pane-templates.ts +160 -0
- package/src/types/plugin-panes.ts +243 -0
- package/src/types/plugin-reports.ts +35 -0
- package/src/types/plugin-shared.ts +14 -0
- package/src/types/plugin-state.ts +71 -0
- package/src/types/plugin.ts +14 -1169
- package/src/ui/index.tsx +14 -3
- package/src/updater/github-releases.ts +23 -0
- package/src/utils/central-banks.ts +86 -1
- package/src/utils/cli-output.ts +22 -9
- package/src/utils/datetime-format.ts +12 -3
- package/src/utils/depositary-receipt.ts +28 -3
- package/src/utils/fundamentals.ts +14 -0
- package/src/utils/max-drawdown.ts +97 -16
- package/src/utils/untrusted-text.ts +29 -0
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
import { apiClient } from "../api-client";
|
|
2
|
+
import type { FxInterventionDay, FxInterventionMonth, FxInterventionRun, FxInterventionsPayload } from "../api-client/fx-interventions";
|
|
3
|
+
import { currencyPairSpelling } from "../utils/currency-pair";
|
|
4
|
+
import { logFailure } from "../utils/log-failure";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Japan's foreign exchange interventions as its Ministry of Finance publishes
|
|
8
|
+
* them: each intervention, from the quarterly releases, and each monthly
|
|
9
|
+
* total, which names no day and no pair until its quarter is released. Shown
|
|
10
|
+
* in `fx` and `history` notes for a yen pair, and on a yen pair's chart.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/** The two currencies of a yen pair, as the listing writes them: USD and JPY for USDJPY=X. */
|
|
14
|
+
export interface FxInterventionPair {
|
|
15
|
+
base: string;
|
|
16
|
+
quote: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** The side Japan took: it bought yen to hold it up, or sold yen to hold it down. */
|
|
20
|
+
type FxInterventionSide = "yen bought" | "yen sold";
|
|
21
|
+
|
|
22
|
+
/** A total the ministry has reported whose days are not published yet. */
|
|
23
|
+
interface UndatedTotal {
|
|
24
|
+
from: string;
|
|
25
|
+
to: string;
|
|
26
|
+
amountJpy: number;
|
|
27
|
+
releasedOn: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const DAY_MS = 86_400_000;
|
|
31
|
+
const MONTHS = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
|
|
32
|
+
const CURRENCY_WORDS: Record<string, string> = { USD: "dollars", JPY: "yen", EUR: "euros", DEM: "marks", IDR: "rupiah" };
|
|
33
|
+
const DAYS_KNOWN: ReadonlySet<unknown> = new Set(["all", "partial", "none"]);
|
|
34
|
+
|
|
35
|
+
const isDay = (value: unknown): value is string => typeof value === "string" && /^\d{4}-\d{2}-\d{2}$/.test(value)
|
|
36
|
+
&& Number.isFinite(Date.parse(`${value}T00:00:00Z`)) && new Date(`${value}T00:00:00Z`).toISOString().slice(0, 10) === value;
|
|
37
|
+
const isCode = (value: unknown) => value === null || typeof value === "string" && /^[A-Z]{3}$/.test(value);
|
|
38
|
+
const isAmount = (value: unknown): value is number => typeof value === "number" && Number.isFinite(value) && value >= 0;
|
|
39
|
+
const nextDay = (date: string) => new Date(Date.parse(`${date}T00:00:00Z`) + DAY_MS).toISOString().slice(0, 10);
|
|
40
|
+
|
|
41
|
+
function readsAsDay(day: FxInterventionDay | undefined): boolean {
|
|
42
|
+
return !!day && isDay(day.date) && isAmount(day.amountJpy) && isCode(day.sold) && isCode(day.bought) && typeof day.pair === "string";
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function readsAsRun(run: FxInterventionRun | undefined): boolean {
|
|
46
|
+
return !!run && isDay(run.from) && isDay(run.to) && run.to >= run.from && Number.isInteger(run.days) && run.days >= 1
|
|
47
|
+
&& isAmount(run.amountJpy) && isCode(run.sold) && isCode(run.bought) && typeof run.pair === "string";
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function readsAsMonth(month: FxInterventionMonth | undefined): boolean {
|
|
51
|
+
return !!month && isDay(month.from) && isDay(month.to) && month.to >= month.from && isAmount(month.amountJpy) && isDay(month.releasedOn)
|
|
52
|
+
&& DAYS_KNOWN.has(month.daysKnown) && isAmount(month.undatedAmountJpy) && month.undatedAmountJpy <= month.amountJpy;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* The reply as this app reads it, or null: a reply with a day out of order, a
|
|
57
|
+
* negative or missing amount or a period that ends before it starts is no
|
|
58
|
+
* record, never a guessed one. A server without the route answers 404, which
|
|
59
|
+
* the loader also reads as none.
|
|
60
|
+
*/
|
|
61
|
+
export function readFxInterventions(payload: unknown): FxInterventionsPayload | null {
|
|
62
|
+
if (!payload || typeof payload !== "object") return null;
|
|
63
|
+
const record = payload as FxInterventionsPayload;
|
|
64
|
+
if (record.status !== "available" || !Array.isArray(record.days) || !Array.isArray(record.interventions) || !Array.isArray(record.months)
|
|
65
|
+
|| !(record.dailyThrough === null || isDay(record.dailyThrough))) return null;
|
|
66
|
+
const inOrder = <T>(entries: readonly T[], date: (entry: T) => string) => entries.every((entry, index) => index === 0 || date(entries[index - 1]!) <= date(entry));
|
|
67
|
+
if (!record.days.every(readsAsDay) || !inOrder(record.days, (day) => day.date)) return null;
|
|
68
|
+
if (!record.interventions.every(readsAsRun) || !inOrder(record.interventions, (run) => run.from)) return null;
|
|
69
|
+
return record.months.every(readsAsMonth) ? record : null;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
type FxInterventionsClient = Pick<typeof apiClient, "getCloudFxInterventions">;
|
|
73
|
+
const FRESH_MS = 10 * 60_000;
|
|
74
|
+
const RETRY_MS = 60_000;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* A loader of the record from Gloom Cloud: null when it has none (not read
|
|
78
|
+
* yet, an older server) or could not be reached, so a note or a chart marker
|
|
79
|
+
* is left out, never the rate or the chart it goes with. One request serves
|
|
80
|
+
* every caller for ten minutes, a failed one for a minute.
|
|
81
|
+
*/
|
|
82
|
+
export function createFxInterventionsLoader(
|
|
83
|
+
client: FxInterventionsClient,
|
|
84
|
+
now: () => number = Date.now,
|
|
85
|
+
): () => Promise<FxInterventionsPayload | null> {
|
|
86
|
+
let held: { at: number; ttl: number; promise: Promise<FxInterventionsPayload | null> } | null = null;
|
|
87
|
+
return () => {
|
|
88
|
+
const at = now();
|
|
89
|
+
if (held && at - held.at < held.ttl) return held.promise;
|
|
90
|
+
const promise = client.getCloudFxInterventions()
|
|
91
|
+
.then(readFxInterventions, logFailure("market-data.fx-interventions", "Japan's intervention record could not be read", null));
|
|
92
|
+
const entry = { at, ttl: FRESH_MS, promise };
|
|
93
|
+
held = entry;
|
|
94
|
+
void promise.then((payload) => { if (!payload) entry.ttl = RETRY_MS; });
|
|
95
|
+
return promise;
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** The record from Gloom Cloud, shared by every caller in the app. */
|
|
100
|
+
export const loadFxInterventions = createFxInterventionsLoader(apiClient);
|
|
101
|
+
|
|
102
|
+
/** The pair a listing is, when one side is the yen: USD and JPY for USDJPY=X or JPY=X. */
|
|
103
|
+
export function fxInterventionPair(symbol: string, exchange?: string): FxInterventionPair | null {
|
|
104
|
+
const spelling = currencyPairSpelling(symbol, exchange);
|
|
105
|
+
if (!spelling || spelling.ambiguous) return null;
|
|
106
|
+
const base = spelling.symbol.slice(0, 3), quote = spelling.symbol.slice(3, 6);
|
|
107
|
+
return base === "JPY" || quote === "JPY" ? { base, quote } : null;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const inPair = (run: Pick<FxInterventionRun, "sold" | "bought">, pair: FxInterventionPair) => (
|
|
111
|
+
run.sold === pair.base && run.bought === pair.quote || run.sold === pair.quote && run.bought === pair.base
|
|
112
|
+
);
|
|
113
|
+
/** USD/JPY either way round: the only pair a monthly total, which names none, is shown for. */
|
|
114
|
+
const isDollarYen = (pair: FxInterventionPair) => inPair({ sold: "USD", bought: "JPY" }, pair);
|
|
115
|
+
|
|
116
|
+
/** The pair's interventions, oldest first. */
|
|
117
|
+
function fxInterventionsIn(payload: FxInterventionsPayload, pair: FxInterventionPair): FxInterventionRun[] {
|
|
118
|
+
return payload.interventions.filter((run) => inPair(run, pair));
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** Which way the ministry went. */
|
|
122
|
+
function fxInterventionSide(run: Pick<FxInterventionRun, "sold" | "bought">): FxInterventionSide | null {
|
|
123
|
+
return run.bought === "JPY" ? "yen bought" : run.sold === "JPY" ? "yen sold" : null;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Monthly totals, or the part of one, no published day accounts for yet: for
|
|
128
|
+
* USD/JPY only, since a total names no pair and nearly every intervention
|
|
129
|
+
* since 2004 has been in it. A month that runs past the daily record counts
|
|
130
|
+
* from the day after it.
|
|
131
|
+
*/
|
|
132
|
+
function undatedTotals(payload: FxInterventionsPayload, pair: FxInterventionPair): UndatedTotal[] {
|
|
133
|
+
if (!isDollarYen(pair)) return [];
|
|
134
|
+
return payload.months.filter((month) => month.undatedAmountJpy > 0).map((month) => {
|
|
135
|
+
const after = month.daysKnown === "partial" && payload.dailyThrough ? nextDay(payload.dailyThrough) : month.from;
|
|
136
|
+
return { from: after > month.from && after <= month.to ? after : month.from, to: month.to, amountJpy: month.undatedAmountJpy, releasedOn: month.releasedOn };
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function dayText(date: string, withYear = true): string {
|
|
141
|
+
const [year, month, day] = date.split("-").map(Number);
|
|
142
|
+
return `${day} ${MONTHS[month! - 1]}${withYear ? ` ${year}` : ""}`;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** 22 Sep 2022, 21–24 Oct 2022, 29 Apr–1 May 2024, 29 Dec 2003–16 Jan 2004. */
|
|
146
|
+
function spanText(from: string, to: string, withYear = true): string {
|
|
147
|
+
if (from === to) return dayText(from, withYear);
|
|
148
|
+
if (from.slice(0, 7) === to.slice(0, 7)) return `${Number(from.slice(8))}–${dayText(to, withYear)}`;
|
|
149
|
+
return `${dayText(from, withYear && from.slice(0, 4) !== to.slice(0, 4))}–${dayText(to, withYear)}`;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** ¥11,734.9 billion: the ministry's own unit and precision. */
|
|
153
|
+
function yenText(amountJpy: number): string {
|
|
154
|
+
return `¥${(amountJpy / 1e9).toLocaleString("en-US", { minimumFractionDigits: 1, maximumFractionDigits: 1 })} billion`;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** ¥11.7tn, ¥780bn: short enough for a list or a chart caption. */
|
|
158
|
+
function yenShort(amountJpy: number): string {
|
|
159
|
+
return amountJpy >= 1e12 ? `¥${(amountJpy / 1e12).toFixed(1)}tn` : `¥${Math.round(amountJpy / 1e9).toLocaleString("en-US")}bn`;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** Dollars sold for yen; the ministry's words when a side has no code. */
|
|
163
|
+
function directionText(run: Pick<FxInterventionRun, "sold" | "bought" | "pair">): string {
|
|
164
|
+
const sold = run.sold && CURRENCY_WORDS[run.sold], bought = run.bought && CURRENCY_WORDS[run.bought];
|
|
165
|
+
return sold && bought ? `${sold} sold for ${bought}` : run.pair;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const pairText = (pair: FxInterventionPair) => `${pair.base}/${pair.quote}`;
|
|
169
|
+
const runText = (run: FxInterventionRun) => (
|
|
170
|
+
`${spanText(run.from, run.to)}, ${yenText(run.amountJpy)} of ${directionText(run)}${run.days > 1 ? ` on ${run.days} days` : ""}`
|
|
171
|
+
);
|
|
172
|
+
const periodText = (total: UndatedTotal) => `from ${dayText(total.from, total.from.slice(0, 4) !== total.to.slice(0, 4))} to ${dayText(total.to)}`;
|
|
173
|
+
const releasedText = (total: UndatedTotal) => `a monthly total released ${dayText(total.releasedOn)}: its days and pair come with the quarterly release`;
|
|
174
|
+
/** The last day any release covers, a monthly one included. */
|
|
175
|
+
function recordsThrough(payload: FxInterventionsPayload): string | null {
|
|
176
|
+
return [payload.dailyThrough, ...payload.months.map((month) => month.to)].filter((date): date is string => !!date).sort().at(-1) ?? null;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* `fx`'s note for a yen pair: the ministry's latest intervention in it, and
|
|
181
|
+
* for USD/JPY any monthly total its days have not been published for yet.
|
|
182
|
+
* Nothing for a pair it never intervened in and no undated total.
|
|
183
|
+
*/
|
|
184
|
+
export function fxInterventionLatestNote(payload: FxInterventionsPayload, pair: FxInterventionPair): string | null {
|
|
185
|
+
const last = fxInterventionsIn(payload, pair).at(-1);
|
|
186
|
+
const undated = undatedTotals(payload, pair).at(-1);
|
|
187
|
+
if (!last && !undated) return null;
|
|
188
|
+
const through = recordsThrough(payload);
|
|
189
|
+
const sentences = [
|
|
190
|
+
...undated ? [`Japan's Ministry of Finance reported ${yenText(undated.amountJpy)} of intervention ${periodText(undated)}, ${releasedText(undated)}.`] : [],
|
|
191
|
+
...last ? [`${undated ? "Its last dated intervention" : "Japan's Ministry of Finance last intervened"} in ${pairText(pair)}: ${runText(last)}.`] : [],
|
|
192
|
+
];
|
|
193
|
+
return `${sentences.join(" ")}${through ? ` Records through ${dayText(through)}.` : ""}`;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/** At most this many interventions are named in a window; older ones are counted. */
|
|
197
|
+
const NAMED_INTERVENTIONS = 6;
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* `history`'s note: the ministry's interventions in the pair between the
|
|
201
|
+
* first bar shown and the end of the last one's period, newest last, in short
|
|
202
|
+
* amounts, and for USD/JPY a monthly total in it whose days are not published
|
|
203
|
+
* yet. Nothing when the bars span none.
|
|
204
|
+
*/
|
|
205
|
+
export function fxInterventionWindowNote(payload: FxInterventionsPayload, pair: FxInterventionPair, from: string, to: string): string | null {
|
|
206
|
+
const runs = fxInterventionsIn(payload, pair).filter((run) => run.to >= from && run.from <= to);
|
|
207
|
+
const undated = undatedTotals(payload, pair).filter((total) => total.to >= from && total.from <= to);
|
|
208
|
+
if (runs.length === 0 && undated.length === 0) return null;
|
|
209
|
+
const named = runs.slice(-NAMED_INTERVENTIONS);
|
|
210
|
+
const earlier = runs.length - named.length;
|
|
211
|
+
const sides = new Set(runs.map(fxInterventionSide));
|
|
212
|
+
const side = sides.size === 1 ? [...sides][0] : null;
|
|
213
|
+
const lead = side === "yen bought" ? "bought yen" : side === "yen sold" ? "sold yen" : "intervened";
|
|
214
|
+
const entry = (run: FxInterventionRun) => {
|
|
215
|
+
const own = side ? null : fxInterventionSide(run);
|
|
216
|
+
return `${spanText(run.from, run.to)} ${yenShort(run.amountJpy)}${own ? ` ${own}` : ""}`;
|
|
217
|
+
};
|
|
218
|
+
const sentences = [
|
|
219
|
+
...named.length > 0 ? [`Japan's Ministry of Finance ${lead} in ${pairText(pair)} in these bars: ${named.map(entry).join("; ")}${
|
|
220
|
+
earlier > 0 ? `; and ${earlier} earlier from ${dayText(runs[0]!.from)}` : ""}.`] : [],
|
|
221
|
+
...undated.map((total) => `${named.length > 0 ? "It also" : "Japan's Ministry of Finance"} reported ${yenShort(total.amountJpy)} ${periodText(total)}, ${releasedText(total)}.`),
|
|
222
|
+
];
|
|
223
|
+
return sentences.join(" ");
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/** A chart marker for one intervention, or for a total its days are not published for yet. */
|
|
227
|
+
export interface FxInterventionMarker {
|
|
228
|
+
id: string;
|
|
229
|
+
date: string;
|
|
230
|
+
/** A total's last day: it is drawn from its first day to here. */
|
|
231
|
+
endDate?: string;
|
|
232
|
+
/** Its caption, longest first: the `MoF` prefix goes first when room is short, never the dates. */
|
|
233
|
+
captions: string[];
|
|
234
|
+
/** A total with no day yet: drawn dotted across its period. */
|
|
235
|
+
undated: boolean;
|
|
236
|
+
amountJpy: number;
|
|
237
|
+
side: FxInterventionSide | null;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
const PAIR_NOT_PUBLISHED = "pair not yet published";
|
|
241
|
+
|
|
242
|
+
/** The pair's interventions, then for USD/JPY any total without days, as chart markers. */
|
|
243
|
+
export function fxInterventionMarkers(payload: FxInterventionsPayload, pair: FxInterventionPair): FxInterventionMarker[] {
|
|
244
|
+
return [
|
|
245
|
+
...fxInterventionsIn(payload, pair).map((run): FxInterventionMarker => {
|
|
246
|
+
const amount = yenShort(run.amountJpy), side = fxInterventionSide(run);
|
|
247
|
+
const told = side ? `${amount} ${side}` : amount;
|
|
248
|
+
return {
|
|
249
|
+
id: `mof:${run.from}:${run.sold}:${run.bought}`, date: run.from, captions: [...new Set([`MoF ${told}`, told, amount])],
|
|
250
|
+
undated: false, amountJpy: run.amountJpy, side,
|
|
251
|
+
};
|
|
252
|
+
}),
|
|
253
|
+
...undatedTotals(payload, pair).map((total): FxInterventionMarker => {
|
|
254
|
+
const dated = `${yenShort(total.amountJpy)} ${spanText(total.from, total.to, false)}`;
|
|
255
|
+
return {
|
|
256
|
+
id: `mof:${total.from}:${total.to}`, date: total.from, endDate: total.to,
|
|
257
|
+
captions: [`MoF ${dated}, ${PAIR_NOT_PUBLISHED}`, `${dated}, ${PAIR_NOT_PUBLISHED}`, dated],
|
|
258
|
+
undated: true, amountJpy: total.amountJpy, side: null,
|
|
259
|
+
};
|
|
260
|
+
}),
|
|
261
|
+
];
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/** One caption for markers too close to caption apart: their sum and count, and the side when they share one. */
|
|
265
|
+
export function fxInterventionSharedCaptions(markers: readonly FxInterventionMarker[]): string[] {
|
|
266
|
+
const total = `${yenShort(markers.reduce((sum, marker) => sum + marker.amountJpy, 0))} ×${markers.length}`;
|
|
267
|
+
const sides = new Set(markers.map((marker) => marker.side));
|
|
268
|
+
const side = sides.size === 1 ? [...sides][0] : null;
|
|
269
|
+
return side ? [`MoF ${total} ${side}`, `${total} ${side}`, total] : [`MoF ${total}`, total];
|
|
270
|
+
}
|
|
@@ -17,9 +17,10 @@ const SAME_CLOSE_RELATIVE = 1e-5;
|
|
|
17
17
|
*/
|
|
18
18
|
const SAME_INDEX_CLOSE_RELATIVE = 1e-4;
|
|
19
19
|
/**
|
|
20
|
-
* How long a reading that named no day,
|
|
21
|
-
*
|
|
22
|
-
*
|
|
20
|
+
* How long a reading that named no day, corrected an index's close, or found
|
|
21
|
+
* no official close yet for a closed B3 session stands before the closes are
|
|
22
|
+
* read again: a history a session behind catches up, a failed read is
|
|
23
|
+
* retried, a correction is checked again.
|
|
23
24
|
*/
|
|
24
25
|
const UNDATED_RETRY_MS = 10 * 60_000;
|
|
25
26
|
/** Readings kept at once; the oldest goes first. */
|
|
@@ -61,6 +62,8 @@ export interface PreviousCloseDatesOptions {
|
|
|
61
62
|
indexWaitMs?: number;
|
|
62
63
|
}
|
|
63
64
|
|
|
65
|
+
type ReadingFields = Pick<Reading, "date" | "close" | "sessionClose" | "awaitsSessionClose">;
|
|
66
|
+
|
|
64
67
|
interface Reading {
|
|
65
68
|
date: string | null;
|
|
66
69
|
/**
|
|
@@ -68,9 +71,32 @@ interface Reading {
|
|
|
68
71
|
* disagrees with it: an index's, whose move is then measured from it.
|
|
69
72
|
*/
|
|
70
73
|
close?: number;
|
|
74
|
+
/** The official close of the quote's own session, from its daily bar, where the quote ends on a later print (B3). */
|
|
75
|
+
sessionClose?: number;
|
|
76
|
+
/** A closed quote on such a venue whose session's bar was not in the history yet: read again until it lands. */
|
|
77
|
+
awaitsSessionClose?: boolean;
|
|
71
78
|
at: number;
|
|
72
79
|
}
|
|
73
80
|
|
|
81
|
+
/**
|
|
82
|
+
* Venues whose quoted previous close is the exchange's official close, not
|
|
83
|
+
* the last trade its daily bar closes on, with how far apart the two can be:
|
|
84
|
+
* the BMV's closing auction gave WALMEX 53.57 on Thu 5 Nov 2026 beside a
|
|
85
|
+
* 53.68 last trade. The bar of the trading weekday right before the move's
|
|
86
|
+
* session still dates it, when the two are that close.
|
|
87
|
+
*/
|
|
88
|
+
const OFFICIAL_PREVIOUS_CLOSE_VENUES: ReadonlyMap<string, number> = new Map([["BMV", 0.01]]);
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Venues whose closed quote can end on a print after the closing call while
|
|
92
|
+
* the daily bar is the official close, as history and the portfolio read it:
|
|
93
|
+
* B3's PETR4 quoted R$45.36 on Fri 6 Nov 2026 beside a R$45.30 close.
|
|
94
|
+
*/
|
|
95
|
+
const DAILY_BAR_CLOSE_VENUES: ReadonlySet<string> = new Set(["B3"]);
|
|
96
|
+
|
|
97
|
+
/** A close this far from the quote's price is another unit's or another listing's, never the session's. */
|
|
98
|
+
const MAX_SESSION_CLOSE_MOVE = 0.25;
|
|
99
|
+
|
|
74
100
|
/** One listing whatever spelling of its exchange a request used. */
|
|
75
101
|
export function datedCloseListingKey(listing: DatedCloseListing): string {
|
|
76
102
|
return `${listing.symbol.trim().toUpperCase()}|${canonicalExchange(listing.exchange)}`;
|
|
@@ -103,7 +129,9 @@ function datedReadingKey(quote: Quote, listing: DatedCloseListing): string | nul
|
|
|
103
129
|
const previousClose = quote.previousClose;
|
|
104
130
|
const sessionDate = changeBasisSessionDate(quote);
|
|
105
131
|
if (previousClose == null || !Number.isFinite(previousClose) || !sessionDate) return null;
|
|
106
|
-
|
|
132
|
+
// A session read while it traded has no close yet: once closed it is read again for its official close.
|
|
133
|
+
const closed = DAILY_BAR_CLOSE_VENUES.has(calendarVenue(quote)) && quote.marketState === "CLOSED" ? "|closed" : "";
|
|
134
|
+
return `${datedCloseListingKey(listing)}|${sessionDate}|${previousClose}${closed}`;
|
|
107
135
|
}
|
|
108
136
|
|
|
109
137
|
/**
|
|
@@ -133,7 +161,37 @@ function latestCloseBefore(points: readonly DailyClose[], quote: Quote): string
|
|
|
133
161
|
.filter((point) => point.date < sessionDate)
|
|
134
162
|
.sort((left, right) => left.date.localeCompare(right.date))
|
|
135
163
|
.at(-1);
|
|
136
|
-
|
|
164
|
+
if (!before) return null;
|
|
165
|
+
if (sameClose(before.close, quote.previousClose!)) return before.date;
|
|
166
|
+
const apart = OFFICIAL_PREVIOUS_CLOSE_VENUES.get(calendarVenue(quote));
|
|
167
|
+
return apart != null && before.date === weekdayBefore(sessionDate)
|
|
168
|
+
&& Math.abs(before.close - quote.previousClose!) <= before.close * apart ? before.date : null;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/** The weekday before a local `YYYY-MM-DD`: Friday for a Monday. */
|
|
172
|
+
function weekdayBefore(date: string): string {
|
|
173
|
+
const day = new Date(`${date}T00:00:00Z`);
|
|
174
|
+
do day.setUTCDate(day.getUTCDate() - 1);
|
|
175
|
+
while (day.getUTCDay() === 0 || day.getUTCDay() === 6);
|
|
176
|
+
return day.toISOString().slice(0, 10);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* The official close of a closed quote's own session on a venue whose quote
|
|
181
|
+
* can end on a later print (DAILY_BAR_CLOSE_VENUES): the session's finished
|
|
182
|
+
* daily bar, when it differs from the quote's price; undefined when it does
|
|
183
|
+
* not. `awaits` when the history has no finished bar of that session yet.
|
|
184
|
+
*/
|
|
185
|
+
function sessionCloseOf(points: readonly DailyClose[], quote: Quote): { close?: number; awaits?: true } {
|
|
186
|
+
if (quote.marketState !== "CLOSED" || !DAILY_BAR_CLOSE_VENUES.has(calendarVenue(quote))) return {};
|
|
187
|
+
if (typeof quote.regularClose === "number" && quote.regularClose > 0) return {};
|
|
188
|
+
const sessionDate = changeBasisSessionDate(quote);
|
|
189
|
+
if (!sessionDate) return {};
|
|
190
|
+
const bar = closedBars(points, quote).findLast((point) => point.date === sessionDate && point.close > 0);
|
|
191
|
+
if (!bar) return { awaits: true };
|
|
192
|
+
if (!(quote.price > 0) || sameClose(bar.close, quote.price)) return {};
|
|
193
|
+
const close = cleanFloat32Price(bar.close);
|
|
194
|
+
return Math.abs(close / quote.price - 1) <= MAX_SESSION_CLOSE_MOVE ? { close } : {};
|
|
137
195
|
}
|
|
138
196
|
|
|
139
197
|
/**
|
|
@@ -164,9 +222,15 @@ function indexCloseOn(points: readonly DailyClose[], quote: Quote, date: string)
|
|
|
164
222
|
return Math.abs(previousClose - close) <= close * SAME_INDEX_CLOSE_RELATIVE ? { date } : { date, close };
|
|
165
223
|
}
|
|
166
224
|
|
|
167
|
-
function readingOf(points: readonly DailyClose[], quote: Quote):
|
|
225
|
+
function readingOf(points: readonly DailyClose[], quote: Quote): ReadingFields {
|
|
168
226
|
const indexDate = datedIndexClose(quote);
|
|
169
|
-
|
|
227
|
+
if (indexDate) return indexCloseOn(points, quote, indexDate);
|
|
228
|
+
const session = sessionCloseOf(points, quote);
|
|
229
|
+
return {
|
|
230
|
+
date: latestCloseBefore(points, quote),
|
|
231
|
+
...session.close != null ? { sessionClose: session.close } : {},
|
|
232
|
+
...session.awaits ? { awaitsSessionClose: true } : {},
|
|
233
|
+
};
|
|
170
234
|
}
|
|
171
235
|
|
|
172
236
|
function withDate<T extends Quote | null | undefined>(quote: T, date: string | null | undefined): T {
|
|
@@ -174,7 +238,20 @@ function withDate<T extends Quote | null | undefined>(quote: T, date: string | n
|
|
|
174
238
|
}
|
|
175
239
|
|
|
176
240
|
/** The quote as a reading has it: dated, and for an index measured from that day's close when its own disagrees. */
|
|
177
|
-
function withReading<T extends Quote | null | undefined>(quote: T, reading: Pick<Reading, "date" | "close"> | undefined): T {
|
|
241
|
+
function withReading<T extends Quote | null | undefined>(quote: T, reading: Pick<Reading, "date" | "close" | "sessionClose"> | undefined): T {
|
|
242
|
+
if (!quote || !reading) return quote;
|
|
243
|
+
const closed = withSessionClose(quote, reading.sessionClose);
|
|
244
|
+
return closed === quote ? withDatedReading(quote, reading) : withDatedReading(closed as T, reading);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/** A closed quote that ended on a later print headlines its session's official close, as history and the portfolio read it. */
|
|
248
|
+
function withSessionClose<T extends Quote>(quote: T, close: number | undefined): T {
|
|
249
|
+
const sessionDate = close != null && quote.marketState === "CLOSED" && !(typeof quote.regularClose === "number" && quote.regularClose > 0)
|
|
250
|
+
? changeBasisSessionDate(quote) : null;
|
|
251
|
+
return sessionDate ? { ...quote, regularClose: close, regularCloseSessionDate: sessionDate } : quote;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
function withDatedReading<T extends Quote | null | undefined>(quote: T, reading: Pick<Reading, "date" | "close"> | undefined): T {
|
|
178
255
|
if (!quote || !reading?.date) return quote;
|
|
179
256
|
if (reading.close == null) return withDate(quote, reading.date);
|
|
180
257
|
const close = reading.close;
|
|
@@ -204,7 +281,7 @@ function withReading<T extends Quote | null | undefined>(quote: T, reading: Pick
|
|
|
204
281
|
*/
|
|
205
282
|
export class PreviousCloseDates {
|
|
206
283
|
private readonly readings = new Map<string, Reading>();
|
|
207
|
-
private readonly pending = new Map<string, Promise<
|
|
284
|
+
private readonly pending = new Map<string, Promise<ReadingFields>>();
|
|
208
285
|
/** The latest copy of each quote a read is pending for, which the read dates when it lands. */
|
|
209
286
|
private readonly latestCopies = new Map<string, { quote: Quote; listing: DatedCloseListing }>();
|
|
210
287
|
/** Dating reads and index checks queue apart, so neither waits behind the other. */
|
|
@@ -268,21 +345,23 @@ export class PreviousCloseDates {
|
|
|
268
345
|
* Whether a reading answers without another read: a day it named that
|
|
269
346
|
* agreed with the quote's close, or any other reading taken lately. A
|
|
270
347
|
* correction (an index's close the quote disagreed with) is read again as
|
|
271
|
-
* an undated one is, so a wrong close cannot stand for the session
|
|
348
|
+
* an undated one is, so a wrong close cannot stand for the session, and so
|
|
349
|
+
* is a closed B3 quote's whose session's official close had not landed.
|
|
272
350
|
*/
|
|
273
351
|
private stands(reading: Reading | undefined): boolean {
|
|
274
|
-
return !!reading && ((!!reading.date && reading.close == null
|
|
352
|
+
return !!reading && ((!!reading.date && reading.close == null && !reading.awaitsSessionClose)
|
|
353
|
+
|| this.now() - reading.at < UNDATED_RETRY_MS);
|
|
275
354
|
}
|
|
276
355
|
|
|
277
|
-
private start(key: string, quote: Quote, listing: DatedCloseListing): Promise<
|
|
356
|
+
private start(key: string, quote: Quote, listing: DatedCloseListing): Promise<ReadingFields> {
|
|
278
357
|
this.latestCopies.set(key, { quote, listing });
|
|
279
358
|
return this.pending.get(key) ?? this.read(key, quote, listing);
|
|
280
359
|
}
|
|
281
360
|
|
|
282
|
-
private read(key: string, quote: Quote, listing: DatedCloseListing): Promise<
|
|
361
|
+
private read(key: string, quote: Quote, listing: DatedCloseListing): Promise<ReadingFields> {
|
|
283
362
|
const read = this.inSlot(datedIndexClose(quote) ? "index" : "dating", () => withDeadline(Promise.resolve().then(() => this.readCloses(listing)), this.readDeadlineMs, "Reading daily closes timed out"))
|
|
284
363
|
.then((points) => readingOf(points, quote))
|
|
285
|
-
.catch(logFailure("market-data.dated-previous-close", "Read daily closes failed", { date: null }))
|
|
364
|
+
.catch(logFailure("market-data.dated-previous-close", "Read daily closes failed", { date: null } as ReadingFields))
|
|
286
365
|
.then((reading) => {
|
|
287
366
|
this.pending.delete(key);
|
|
288
367
|
this.readings.delete(key);
|
|
@@ -290,7 +369,7 @@ export class PreviousCloseDates {
|
|
|
290
369
|
this.readings.set(key, { ...reading, at: this.now() });
|
|
291
370
|
const latest = this.latestCopies.get(key);
|
|
292
371
|
this.latestCopies.delete(key);
|
|
293
|
-
if (reading.date && latest && this.options.onDated) {
|
|
372
|
+
if ((reading.date || reading.sessionClose != null) && latest && this.options.onDated) {
|
|
294
373
|
try {
|
|
295
374
|
this.options.onDated(latest.listing, withReading(latest.quote, reading));
|
|
296
375
|
} catch (error) {
|
|
@@ -89,9 +89,25 @@ export function quoteBookSessionLabel(quote: Quote): string | null {
|
|
|
89
89
|
if (extended) return extended;
|
|
90
90
|
const day = quoteTradingDay(quote);
|
|
91
91
|
const date = day ? new Date(`${day}T00:00:00Z`) : null;
|
|
92
|
-
|
|
92
|
+
const label = date && Number.isFinite(date.getTime())
|
|
93
93
|
? `last quote, ${WEEKDAYS[date.getUTCDay()]} ${date.getUTCDate()} ${MONTHS[date.getUTCMonth()]}`
|
|
94
94
|
: "last quote";
|
|
95
|
+
return offMarketBook(quote) ? `${label}, off-market` : label;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Past this share of the last price, a closed market's bid or ask is no market for it. */
|
|
99
|
+
const OFF_MARKET_SHARE = 0.05;
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Whether a closed market's last bid or ask is more than 5% off the last
|
|
103
|
+
* price: FMX's $118.00 / $135.00 around a $129.85 close on 6 Nov 2026 is a
|
|
104
|
+
* book left after the close, not where it trades.
|
|
105
|
+
*/
|
|
106
|
+
function offMarketBook(quote: Pick<Quote, "price" | "bid" | "ask">): boolean {
|
|
107
|
+
const last = quote.price;
|
|
108
|
+
if (typeof last !== "number" || !Number.isFinite(last) || last <= 0) return false;
|
|
109
|
+
return [quote.bid, quote.ask].some((side) =>
|
|
110
|
+
typeof side === "number" && Number.isFinite(side) && side > 0 && Math.abs(side - last) / last > OFF_MARKET_SHARE);
|
|
95
111
|
}
|
|
96
112
|
|
|
97
113
|
/** `Thu close`: the weekday of the session whose close a quote still stands at. */
|
package/src/news/news-model.ts
CHANGED
|
@@ -246,13 +246,55 @@ export function filterNewsArticlesForQuery(items: NewsArticle[], query: NewsQuer
|
|
|
246
246
|
return filtered.slice(0, MAX_ARTICLES);
|
|
247
247
|
}
|
|
248
248
|
|
|
249
|
+
/** Words that carry no news of their own: a summary made of them and the headline's words says nothing new. */
|
|
250
|
+
const FILLER_WORDS = new Set([
|
|
251
|
+
"a", "an", "the", "and", "or", "but", "of", "to", "in", "on", "at", "for", "from", "by", "with", "as", "into", "onto",
|
|
252
|
+
"over", "through", "about", "after", "amid", "than", "that", "this", "these", "those", "it", "its", "their", "his",
|
|
253
|
+
"her", "they", "is", "are", "was", "were", "be", "been", "being", "has", "have", "had", "will", "would", "could",
|
|
254
|
+
"may", "might", "can", "also", "which", "who", "while", "more", "some",
|
|
255
|
+
]);
|
|
256
|
+
|
|
257
|
+
/** A word cut to its stem, near enough to match its other forms: seeking and seeks, restricts and restrictions. */
|
|
258
|
+
function wordStem(word: string): string {
|
|
259
|
+
const bare = word.replace(/['\u2019]s$/, "");
|
|
260
|
+
let stem = bare.length > 5 ? bare.replace(/(?:ing|ed)$/, "") : bare;
|
|
261
|
+
stem = stem.length > 3 ? stem.replace(/e?s$/, "") : stem;
|
|
262
|
+
return stem.length >= 3 ? stem : bare;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function newsWordStems(text: string): string[] {
|
|
266
|
+
return (text.toLowerCase().match(/[\p{L}\p{N}]+(?:['\u2019][\p{L}]+)?/gu) ?? [])
|
|
267
|
+
.filter((word) => !FILLER_WORDS.has(word))
|
|
268
|
+
.map(wordStem);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/** How much of a summary may be words its headline lacks and the summary still only restate it. */
|
|
272
|
+
const RESTATED_NEW_WORDS = 1 / 3;
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Whether a story's summary only says its headline again, in other words or
|
|
276
|
+
* not: at most a third of its words (fillers aside) are words the headline
|
|
277
|
+
* lacks, in any of their forms. "Apple is seeking to raise about $7 billion
|
|
278
|
+
* through a bond sale, Bloomberg News reports." restates "Apple seeks about $7
|
|
279
|
+
* billion from bond sale, Bloomberg News reports"; a summary that adds the
|
|
280
|
+
* why or the numbers does not.
|
|
281
|
+
*/
|
|
282
|
+
export function summaryRestatesHeadline(title: string, summary: string): boolean {
|
|
283
|
+
const headline = newsWordStems(title);
|
|
284
|
+
const words = newsWordStems(summary);
|
|
285
|
+
if (words.length === 0) return true;
|
|
286
|
+
const known = (word: string) => headline.some((stem) => stem === word
|
|
287
|
+
|| (Math.min(stem.length, word.length) >= 4 && (stem.startsWith(word) || word.startsWith(stem))));
|
|
288
|
+
return words.filter((word) => !known(word)).length <= words.length * RESTATED_NEW_WORDS;
|
|
289
|
+
}
|
|
290
|
+
|
|
249
291
|
/**
|
|
250
292
|
* A story's summary as one line under its row in a text list (`news`,
|
|
251
293
|
* `fn CN`): its whitespace and line breaks run together, null when it has
|
|
252
|
-
* none or only
|
|
294
|
+
* none or only restates the headline (summaryRestatesHeadline).
|
|
253
295
|
*/
|
|
254
296
|
export function newsSummaryLine(article: Pick<NewsArticle, "title" | "summary">): string | null {
|
|
255
297
|
const summary = article.summary?.replace(/\s+/g, " ").trim();
|
|
256
|
-
if (!summary ||
|
|
298
|
+
if (!summary || summaryRestatesHeadline(article.title, summary)) return null;
|
|
257
299
|
return summary;
|
|
258
300
|
}
|
|
@@ -84,7 +84,7 @@ import {
|
|
|
84
84
|
bulkMoveLogRule, MOVE_REARM, moveNowText, parseMoveAddArgs, planMoveAlerts, quoteSavedListings, quoteTypedSymbols, uniqueInputs, venueCounts,
|
|
85
85
|
watchlistListings, MAX_BULK_ALERTS, type MoveAddRequest, type MoveListing, type MovePlan,
|
|
86
86
|
} from "./cli-move";
|
|
87
|
-
import {
|
|
87
|
+
import { MOVE_DELIVERY, moveRuleWords } from "./move";
|
|
88
88
|
import { MOVE_CHECKS_KEY, moveChecksOf, readMoveChecks, withMoveChecks, type MoveCheck } from "./move-checks";
|
|
89
89
|
import { listAddLookups } from "../portfolio-list/cli/bulk-symbols";
|
|
90
90
|
import type { AlertCondition, AlertRule } from "./types";
|
|
@@ -1094,7 +1094,7 @@ export const alertsCliCommand: CliCommandDef = {
|
|
|
1094
1094
|
];
|
|
1095
1095
|
const waiting = rows.filter((row) => row.status === NEEDS_SIGN_IN).length;
|
|
1096
1096
|
const allWarnings = [...(alertsError ? [alertsError] : []), ...(events.error ? [events.error] : []), ...warnings, ...cloud.warning ? [cloud.warning] : [],
|
|
1097
|
-
...waiting ? [needsSignInNote(waiting)] : []
|
|
1097
|
+
...waiting ? [needsSignInNote(waiting)] : []];
|
|
1098
1098
|
ctx.printResult({ data: rows, ...(allWarnings.length ? { warnings: allWarnings } : {}) }, {
|
|
1099
1099
|
rows: (data) => data.map(textRow),
|
|
1100
1100
|
textColumns: [
|
|
@@ -1193,7 +1193,7 @@ export const alertsCliCommand: CliCommandDef = {
|
|
|
1193
1193
|
const alert = plan.added[0]!;
|
|
1194
1194
|
const nowText = moveNowText(alert, now);
|
|
1195
1195
|
ctx.printResult({ data: { changed: !ctx.cliOptions.dryRun, dryRun: ctx.cliOptions.dryRun, alert }, ...(notes.length ? { warnings: notes } : {}) }, {
|
|
1196
|
-
text: (data) => `Added alert ${data.alert.id}: ${formatAlertDescription(data.alert)} (${MOVE_REARM}).${nowText ? ` ${capitalize(nowText)}.` : ""}${dryRunNote(data.dryRun)}\n${
|
|
1196
|
+
text: (data) => `Added alert ${data.alert.id}: ${formatAlertDescription(data.alert)} (${MOVE_REARM}).${nowText ? ` ${capitalize(nowText)}.` : ""}${dryRunNote(data.dryRun)}\n${MOVE_DELIVERY}`,
|
|
1197
1197
|
});
|
|
1198
1198
|
return;
|
|
1199
1199
|
}
|
|
@@ -1206,7 +1206,7 @@ export const alertsCliCommand: CliCommandDef = {
|
|
|
1206
1206
|
}, {
|
|
1207
1207
|
text: (data) => [
|
|
1208
1208
|
`Added ${data.added.length} move ${data.added.length === 1 ? "alert" : "alerts"}${source ? ` ${source}` : ""}: ${rule} from the previous close (${MOVE_REARM}).${dryRunNote(data.dryRun)}`,
|
|
1209
|
-
...data.added.length ? [` ${
|
|
1209
|
+
...data.added.length ? [` ${MOVE_DELIVERY}`] : [],
|
|
1210
1210
|
...data.added.length ? [` By venue: ${venueCounts(data.added)}.`] : [],
|
|
1211
1211
|
...moveSummaryLines(plan, moves),
|
|
1212
1212
|
].join("\n"),
|
|
@@ -155,8 +155,7 @@ export function triggerLabel(alert: Pick<AlertRule, "condition" | "move" | "metr
|
|
|
155
155
|
|
|
156
156
|
/** The Measure cell: Price, Move, or the measure's name. */
|
|
157
157
|
export function measureLabel(alert: Pick<AlertRule, "move" | "metric">): string {
|
|
158
|
-
|
|
159
|
-
return alert.metric ? metricName(alert.metric) : alert.move ? "Move, app only" : "Price";
|
|
158
|
+
return alert.metric ? metricName(alert.metric) : alert.move ? "Move" : "Price";
|
|
160
159
|
}
|
|
161
160
|
|
|
162
161
|
export function conditionLabel(condition: AlertCondition): string {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { closeBasis, metricReadingText } from "./metric-model";
|
|
2
|
-
import {
|
|
2
|
+
import { moveBasisText, movePercentText } from "./move";
|
|
3
3
|
/**
|
|
4
4
|
* `gloom fn ALRT`: the Alerts pane's three tabs as reports. Prices lists
|
|
5
5
|
* the price alerts as the pane's table does, Events the event alerts (earnings,
|
|
@@ -135,7 +135,6 @@ function pricesResult(alerts: readonly AlertRule[], error: string | null, events
|
|
|
135
135
|
const active = alerts.filter((alert) => alert.status === "active");
|
|
136
136
|
const triggered = alerts.filter((alert) => alert.status === "triggered").sort((a, b) => (b.triggeredAt ?? 0) - (a.triggeredAt ?? 0));
|
|
137
137
|
const notes = [
|
|
138
|
-
...alerts.some((alert) => alert.move) ? [MOVE_APP_ONLY] : [],
|
|
139
138
|
...events > 0 ? [`${plural(events, "event alert")} not listed here: gloom fn ALRT --tab events`] : [],
|
|
140
139
|
];
|
|
141
140
|
return {
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// What this device read of each move rule, kept apart from the rules. The
|
|
2
|
-
// synced `moveAlerts` list holds the rules
|
|
3
|
-
//
|
|
4
|
-
// for the next session stay in plugin resume
|
|
2
|
+
// synced `moveAlerts` list holds the rules and the latest session each went off
|
|
3
|
+
// in (`moveDay`, for Gloom Cloud), so it changes only when a rule does or goes
|
|
4
|
+
// off; every check and every re-arm for the next session stay in plugin resume
|
|
5
|
+
// state, as IV levels' readings do.
|
|
5
6
|
import type { QuoteChangeBasis } from "../../../market-data/market/change-basis";
|
|
6
7
|
import type { QuoteDataSource } from "../../../types/financials";
|
|
7
8
|
import type { AlertRule } from "./types";
|
|
@@ -135,9 +136,12 @@ export function moveChecksOf(alerts: readonly AlertRule[]): Record<string, MoveC
|
|
|
135
136
|
}
|
|
136
137
|
|
|
137
138
|
/**
|
|
138
|
-
* A move rule as the synced list keeps it: the rule
|
|
139
|
-
*
|
|
140
|
-
*
|
|
139
|
+
* A move rule as the synced list keeps it: the rule, never a reading, so no
|
|
140
|
+
* check writes the list another device pulls. Always active there: whether
|
|
141
|
+
* it went off this session is this device's to say. The latest session it
|
|
142
|
+
* went off in (`moveDay`) goes with it, so Gloom Cloud never alerts on that
|
|
143
|
+
* session again; it changes at most once a session. `syncsMoveDay` says this
|
|
144
|
+
* app keeps `moveDay`, so Gloom Cloud may judge the rule.
|
|
141
145
|
*/
|
|
142
146
|
export function moveRuleOnly(alert: AlertRule): AlertRule {
|
|
143
147
|
return {
|
|
@@ -150,6 +154,8 @@ export function moveRuleOnly(alert: AlertRule): AlertRule {
|
|
|
150
154
|
...alert.armedAt != null ? { armedAt: alert.armedAt } : {},
|
|
151
155
|
status: "active",
|
|
152
156
|
...alert.message ? { message: alert.message } : {},
|
|
157
|
+
...alert.moveDay ? { moveDay: alert.moveDay } : {},
|
|
153
158
|
move: true,
|
|
159
|
+
syncsMoveDay: true,
|
|
154
160
|
};
|
|
155
161
|
}
|