gloomberb 0.20.2 → 0.20.4
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 +1 -1
- package/README.zh-CN.md +1 -1
- package/package.json +2 -1
- package/src/account/auth-dialog.tsx +17 -0
- package/src/account/auth-form.tsx +13 -8
- package/src/account/upgrade-dialog.tsx +1 -1
- package/src/api-client/central-bank-rates.ts +5 -0
- package/src/api-client/data.ts +23 -4
- package/src/api-client/debt-maturities.ts +45 -2
- package/src/api-client/earnings.ts +4 -2
- package/src/api-client/errors.ts +21 -11
- package/src/api-client/fx-interventions.ts +64 -0
- package/src/api-client/index.ts +2 -0
- package/src/api-client/paths.ts +9 -1
- package/src/api-client/release-summaries.ts +21 -0
- package/src/api-client/social-mentions.ts +47 -0
- package/src/api-client/types/econ.ts +4 -0
- package/src/app/keybindings/actions.ts +2 -2
- package/src/app/pane-runtime/ticker-open-runtime.ts +245 -66
- package/src/app.tsx +11 -1
- package/src/cli/command-options.ts +2 -1
- package/src/cli/commands/market.ts +188 -30
- package/src/cli/commands/news-search.ts +1 -3
- package/src/cli/commands/options-chain.ts +23 -6
- package/src/cli/commands/overview.ts +13 -5
- package/src/cli/commands/plugins.ts +76 -23
- package/src/cli/commands/search.ts +25 -6
- package/src/cli/commands/system.ts +19 -3
- package/src/cli/commands/ticker.ts +64 -21
- package/src/cli/fx-quote-rate.ts +49 -1
- package/src/cli/glossary.ts +95 -15
- package/src/cli/history-rows.ts +9 -25
- package/src/cli/index.ts +14 -46
- package/src/cli/known-gaps.ts +3 -3
- package/src/cli/listing-arg.ts +78 -18
- package/src/cli/name-entries.ts +3 -2
- package/src/cli/not-a-ticker.ts +6 -2
- package/src/cli/pane-functions/capabilities.ts +12 -1
- package/src/cli/pane-functions/function-help.ts +26 -14
- package/src/cli/pane-functions/headless.ts +3 -1
- package/src/cli/pane-functions/index.ts +32 -4
- package/src/cli/pane-functions/market-session.ts +8 -3
- package/src/cli/pane-functions/resolver.ts +18 -11
- package/src/cli/pane-functions/screenshot-payload.ts +36 -6
- package/src/cli/pane-functions/screenshot-render.ts +4 -0
- package/src/cli/quote-answer.ts +10 -0
- package/src/cli/report-tables.ts +40 -8
- package/src/cli/result.ts +21 -9
- package/src/cli/spreadsheet-hint.ts +43 -0
- package/src/cli/symbol-list.ts +58 -4
- package/src/cli/symbol-rows.ts +49 -2
- package/src/cli/ticker-resolution.ts +98 -5
- package/src/cli/types.ts +2 -0
- package/src/cli/unknown-command.ts +88 -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/assist/model.ts +6 -1
- package/src/components/command-bar/commands/direct/index.ts +9 -1
- package/src/components/command-bar/commands/registry.ts +18 -0
- package/src/components/command-bar/layout-items/focused-pane.ts +5 -5
- package/src/components/command-bar/pane-actions.ts +30 -13
- package/src/components/command-bar/panel/index.tsx +6 -3
- package/src/components/command-bar/panel/prompt-binding.ts +4 -0
- package/src/components/command-bar/panel/types.ts +3 -0
- package/src/components/command-bar/routes/header-market.ts +108 -0
- package/src/components/command-bar/routes/root/command-items.ts +5 -0
- package/src/components/command-bar/routes/root/provider-search.ts +192 -33
- package/src/components/command-bar/routes/root/results.ts +3 -0
- package/src/components/command-bar/routes/root/runtime.ts +28 -5
- package/src/components/command-bar/routes/ticker-search/results.ts +104 -6
- package/src/components/command-bar/routes/ticker-search/route.ts +3 -2
- package/src/components/command-bar/routing/list-state.ts +38 -0
- package/src/components/command-bar/selection-hint.ts +28 -0
- package/src/components/command-bar/surface/index.tsx +41 -3
- package/src/components/command-bar/view-model.ts +15 -0
- package/src/components/command-bar/workflow/tickers.ts +3 -2
- package/src/components/company-logo.tsx +20 -2
- package/src/components/data-table/export.ts +13 -8
- package/src/components/feedback-dialog.tsx +2 -1
- package/src/components/form-modal/field-row.tsx +2 -1
- package/src/components/input-search-bar.tsx +2 -2
- package/src/components/layout/detached-pane-shell.tsx +1 -1
- package/src/components/layout/double-escape-close.ts +8 -5
- package/src/components/layout/floating-pane.tsx +5 -1
- package/src/components/layout/header.tsx +75 -44
- package/src/components/layout/market-summary.ts +322 -116
- package/src/components/layout/pane/footer/index.tsx +44 -19
- package/src/components/layout/pane/footer/model.ts +52 -20
- package/src/components/layout/pane/header.tsx +3 -2
- 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/chrome.ts +15 -15
- 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/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 +8 -7
- package/src/components/layout/status-widget-space.ts +8 -0
- package/src/components/layout/window-edit/mode.ts +39 -7
- package/src/components/layout/window-edit/presentation.ts +1 -1
- package/src/components/markdown-editor.tsx +2 -2
- package/src/components/onboarding/account-step/form-panel.tsx +0 -3
- package/src/components/onboarding/onboarding-keyboard.ts +19 -6
- package/src/components/onboarding/onboarding-wizard.tsx +69 -14
- package/src/components/onboarding/portfolio-step/broker-fields-panel.tsx +0 -1
- package/src/components/onboarding/portfolio-step/positions-panel.tsx +0 -2
- package/src/components/price-sparkline/model.ts +26 -10
- package/src/components/ticker/list-table-view.tsx +29 -4
- package/src/components/ui/button.tsx +15 -2
- package/src/components/ui/choice-dialog.tsx +1 -0
- package/src/components/ui/column-grid.tsx +18 -9
- package/src/components/ui/data-table/index.tsx +5 -4
- package/src/components/ui/data-table/opentui/index.tsx +2 -1
- package/src/components/ui/data-table/types.ts +18 -0
- package/src/components/ui/delayed-mark.tsx +3 -2
- package/src/components/ui/field-grid.tsx +0 -2
- package/src/components/ui/fields.tsx +7 -4
- package/src/components/ui/inline-quick-add.tsx +2 -2
- package/src/components/ui/key-hint-words.ts +153 -0
- package/src/components/ui/key-hints.tsx +73 -0
- package/src/components/ui/list-view.tsx +7 -12
- package/src/components/ui/loading.tsx +10 -3
- package/src/components/ui/menu.tsx +9 -3
- package/src/components/ui/message-composer.tsx +2 -2
- package/src/components/ui/quote.ts +14 -1
- package/src/components/ui/shortcut-hint.tsx +28 -3
- package/src/components/ui/tabs.tsx +7 -0
- package/src/components/ui/text-prompt-dialog.tsx +2 -1
- package/src/core/state/app/command-bar-launch.ts +3 -0
- package/src/data/config/layout.ts +5 -2
- package/src/data/config/store/normalize.ts +6 -0
- package/src/docs/snapshot.json +149 -74
- package/src/i18n/es.ts +33 -9
- package/src/i18n/ja.ts +33 -9
- package/src/i18n/ko.ts +33 -9
- package/src/i18n/zh-cn.ts +33 -9
- package/src/i18n/zh-tw.ts +33 -9
- 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 +16 -1
- package/src/layout/pane-manager/index.ts +11 -0
- package/src/layout/pane-manager/layout-state.ts +10 -3
- package/src/market-data/bars-per-year.ts +27 -9
- package/src/market-data/coordinator/quotes.ts +22 -3
- package/src/market-data/futures-board.ts +126 -1
- package/src/market-data/futures-contract.ts +21 -6
- package/src/market-data/fx-interventions.ts +270 -0
- package/src/market-data/market/change-basis.ts +2 -2
- package/src/market-data/market/dated-previous-close.ts +163 -47
- package/src/market-data/market/format.ts +14 -3
- package/src/market-data/market/freshness.ts +24 -7
- package/src/market-data/market/header-market.ts +154 -0
- package/src/market-data/market/index-level.ts +29 -0
- package/src/market-data/market/index-session-venues.ts +44 -0
- package/src/market-data/market/status.ts +7 -2
- package/src/market-data/market/venue-session.ts +72 -0
- package/src/market-data/model-dividend-yield.ts +23 -8
- package/src/market-data/options-alternatives.ts +39 -4
- package/src/market-data/published-apac-sessions.ts +40 -2
- package/src/market-data/quotes/export-identity.ts +76 -0
- package/src/market-data/quotes/freshness.ts +22 -0
- package/src/market-data/quotes/time.ts +42 -1
- package/src/market-data/realized-volatility.ts +11 -7
- package/src/market-data/tax-equivalent.ts +145 -27
- package/src/news/news-model.ts +44 -2
- package/src/plugins/builtin/account-management/pane.tsx +2 -2
- package/src/plugins/builtin/alerts/alert-engine.ts +12 -6
- package/src/plugins/builtin/alerts/alert-log.ts +6 -2
- package/src/plugins/builtin/alerts/calendar-events.ts +74 -12
- package/src/plugins/builtin/alerts/cli-forms.ts +11 -1
- package/src/plugins/builtin/alerts/cli-move.ts +234 -0
- package/src/plugins/builtin/alerts/cli.ts +223 -32
- package/src/plugins/builtin/alerts/command.ts +33 -6
- package/src/plugins/builtin/alerts/event-rows.ts +18 -4
- package/src/plugins/builtin/alerts/events-pane.tsx +6 -2
- package/src/plugins/builtin/alerts/events.ts +9 -0
- package/src/plugins/builtin/alerts/format.ts +39 -15
- package/src/plugins/builtin/alerts/headless.ts +30 -18
- package/src/plugins/builtin/alerts/history.ts +1 -0
- package/src/plugins/builtin/alerts/index.tsx +86 -12
- package/src/plugins/builtin/alerts/live.ts +2 -1
- package/src/plugins/builtin/alerts/move-checks.ts +161 -0
- package/src/plugins/builtin/alerts/move.ts +181 -0
- package/src/plugins/builtin/alerts/pane.tsx +50 -22
- package/src/plugins/builtin/alerts/price-text.ts +62 -0
- package/src/plugins/builtin/alerts/price.ts +17 -0
- package/src/plugins/builtin/alerts/quotes.ts +84 -3
- package/src/plugins/builtin/alerts/scheduled-check.ts +7 -1
- package/src/plugins/builtin/alerts/storage.ts +22 -7
- package/src/plugins/builtin/alerts/types.ts +25 -0
- package/src/plugins/builtin/analytics/risk-client.ts +60 -39
- package/src/plugins/builtin/analytics/risk-episodes.ts +18 -0
- package/src/plugins/builtin/analytics/risk-headless.ts +20 -4
- package/src/plugins/builtin/analytics/risk-model.ts +68 -1
- package/src/plugins/builtin/analytics/risk-pane.tsx +15 -3
- package/src/plugins/builtin/backtest/engine.ts +4 -2
- package/src/plugins/builtin/backtest/window.ts +3 -1
- package/src/plugins/builtin/broker-manager/sign-in-end.ts +1 -1
- package/src/plugins/builtin/central-bank-rates/client.ts +4 -0
- package/src/plugins/builtin/central-bank-rates/headless.ts +1 -1
- package/src/plugins/builtin/central-bank-rates/model.ts +18 -8
- package/src/plugins/builtin/central-bank-rates/pane.tsx +6 -3
- package/src/plugins/builtin/changelog/index.tsx +292 -101
- package/src/plugins/builtin/changelog/versions.ts +293 -0
- package/src/plugins/builtin/chart-composer/cli-options.ts +5 -0
- package/src/plugins/builtin/chart-composer/headless-schema.ts +17 -1
- package/src/plugins/builtin/chart-composer/headless.ts +2 -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/message/render-state.ts +2 -5
- 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/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 +47 -6
- package/src/plugins/builtin/cloud/upgrade-status-widget.tsx +9 -2
- 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/cot/headless.ts +14 -2
- package/src/plugins/builtin/crypto-board/headless.ts +82 -17
- package/src/plugins/builtin/crypto-board/index.tsx +24 -2
- package/src/plugins/builtin/crypto-board/model.ts +5 -2
- package/src/plugins/builtin/crypto-board/pane.tsx +4 -1
- package/src/plugins/builtin/debt-maturities/client.ts +111 -6
- package/src/plugins/builtin/debt-maturities/headless.ts +84 -1
- package/src/plugins/builtin/debt-maturities/model.ts +97 -14
- package/src/plugins/builtin/debt-maturities/pane.tsx +165 -15
- package/src/plugins/builtin/debt-maturities/series.ts +3 -1
- package/src/plugins/builtin/dividend-yield/client.ts +22 -6
- package/src/plugins/builtin/dividend-yield/headless.ts +113 -46
- package/src/plugins/builtin/dividend-yield/model.ts +5 -2
- package/src/plugins/builtin/dividend-yield/pane.tsx +6 -3
- package/src/plugins/builtin/dividend-yield/ranking-reads.ts +11 -4
- package/src/plugins/builtin/dividend-yield/ranking.ts +113 -18
- package/src/plugins/builtin/dividend-yield/types.ts +2 -0
- package/src/plugins/builtin/dividend-yield/view.ts +3 -0
- package/src/plugins/builtin/earnings/index.tsx +2 -2
- package/src/plugins/builtin/econ/calendar-model.ts +21 -3
- package/src/plugins/builtin/econ/detail-view.tsx +5 -3
- package/src/plugins/builtin/econ/figures.ts +13 -0
- package/src/plugins/builtin/econ/fred-catalog.ts +6 -3
- package/src/plugins/builtin/econ/index.tsx +5 -3
- package/src/plugins/builtin/econ/types.ts +5 -0
- package/src/plugins/builtin/equity-screener/footer.ts +45 -0
- package/src/plugins/builtin/equity-screener/pane.tsx +4 -18
- package/src/plugins/builtin/equity-screener/ticker-check.tsx +2 -1
- package/src/plugins/builtin/fixed-income/model.ts +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 +17 -10
- package/src/plugins/builtin/futures/use-board-terms.ts +3 -3
- package/src/plugins/builtin/futures-curve/model.ts +3 -10
- package/src/plugins/builtin/help/function-card.tsx +2 -1
- package/src/plugins/builtin/help/function-index.ts +1 -0
- package/src/plugins/builtin/help/index.tsx +3 -3
- package/src/plugins/builtin/help/keybindings-editor.tsx +18 -4
- package/src/plugins/builtin/insider/client.ts +31 -14
- package/src/plugins/builtin/insider/signals-model.ts +2 -7
- package/src/plugins/builtin/iv-history/headless.ts +1 -2
- package/src/plugins/builtin/iv-history/model.ts +33 -23
- package/src/plugins/builtin/iv-history/screen-pane.tsx +0 -3
- package/src/plugins/builtin/kelly-sizer/headless.ts +64 -16
- package/src/plugins/builtin/kelly-sizer/history.ts +37 -28
- package/src/plugins/builtin/kelly-sizer/pane.tsx +43 -10
- package/src/plugins/builtin/kelly-sizer/sections.tsx +7 -2
- package/src/plugins/builtin/kelly-sizer/units.ts +29 -0
- package/src/plugins/builtin/layout-manager/index.tsx +8 -8
- package/src/plugins/builtin/news/headless.ts +2 -2
- package/src/plugins/builtin/news/index.tsx +10 -16
- package/src/plugins/builtin/news/overview-headlines.tsx +117 -0
- package/src/plugins/builtin/news/ticker-news.ts +35 -0
- package/src/plugins/builtin/news/wire/news/detail-view.tsx +8 -6
- package/src/plugins/builtin/news/wire/news/row.ts +49 -0
- package/src/plugins/builtin/news/wire/news/table.tsx +9 -20
- package/src/plugins/builtin/options/analytics.ts +7 -2
- package/src/plugins/builtin/options/live-quotes.ts +6 -1
- package/src/plugins/builtin/options/table.ts +3 -2
- package/src/plugins/builtin/options/view.tsx +11 -9
- package/src/plugins/builtin/options-scenario/client.ts +3 -0
- package/src/plugins/builtin/options-scenario/headless.ts +1 -1
- package/src/plugins/builtin/perps/client.ts +5 -4
- package/src/plugins/builtin/perps/headless.ts +134 -124
- package/src/plugins/builtin/perps/markets-section.tsx +7 -4
- package/src/plugins/builtin/perps/model.ts +8 -4
- package/src/plugins/builtin/perps/open-market.ts +4 -4
- package/src/plugins/builtin/perps/venue-markets.ts +3 -6
- package/src/plugins/builtin/plugin-marketplace/pane.tsx +11 -11
- package/src/plugins/builtin/portfolio-list/cell-version.ts +1 -0
- package/src/plugins/builtin/portfolio-list/cli/bulk-symbols.ts +34 -10
- package/src/plugins/builtin/portfolio-list/cli/period-report.ts +28 -2
- package/src/plugins/builtin/portfolio-list/cli/portfolio-command.ts +7 -3
- package/src/plugins/builtin/portfolio-list/cli/render.ts +66 -22
- package/src/plugins/builtin/portfolio-list/grid.tsx +5 -3
- package/src/plugins/builtin/portfolio-list/pane/data.ts +34 -1
- package/src/plugins/builtin/portfolio-list/pane/index.tsx +6 -0
- package/src/plugins/builtin/portfolio-list/pane/streaming.ts +15 -6
- package/src/plugins/builtin/portfolio-list/quick-add/resolution.ts +19 -7
- package/src/plugins/builtin/portfolio-list/summary/index.tsx +3 -1
- package/src/plugins/builtin/portfolio-list/table.tsx +30 -4
- package/src/plugins/builtin/realized-vol/evidence.ts +33 -6
- package/src/plugins/builtin/realized-vol/fx-proxy.ts +135 -0
- package/src/plugins/builtin/realized-vol/headless.ts +44 -8
- package/src/plugins/builtin/realized-vol/model.ts +9 -5
- package/src/plugins/builtin/realized-vol/pane.tsx +49 -15
- 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 +3 -3
- package/src/plugins/builtin/sec/headless.ts +48 -6
- package/src/plugins/builtin/sec/index.tsx +6 -4
- package/src/plugins/builtin/sec/model.ts +4 -1
- package/src/plugins/builtin/shared/cloud-upgrade.ts +27 -3
- package/src/plugins/builtin/shared/earnings-calendar.ts +2 -0
- package/src/plugins/builtin/shared/market-cap-bands.ts +12 -0
- package/src/plugins/builtin/shared/report-freshness.ts +3 -1
- package/src/plugins/builtin/shared/use-quote-board.ts +5 -3
- package/src/plugins/builtin/shared/volatility/options.ts +63 -2
- package/src/plugins/builtin/social-mentions/headless.ts +72 -3
- package/src/plugins/builtin/social-mentions/index.tsx +8 -4
- package/src/plugins/builtin/social-mentions/lock-note.ts +6 -2
- package/src/plugins/builtin/social-mentions/outliers-client.ts +101 -0
- package/src/plugins/builtin/social-mentions/outliers-model.ts +162 -0
- package/src/plugins/builtin/social-mentions/outliers-names.ts +51 -0
- package/src/plugins/builtin/social-mentions/outliers.tsx +276 -0
- package/src/plugins/builtin/social-mentions/pane.tsx +32 -3
- package/src/plugins/builtin/supply-chain/graph-pane.tsx +2 -2
- package/src/plugins/builtin/thirteenf/api.ts +36 -2
- package/src/plugins/builtin/thirteenf/data.ts +4 -1
- package/src/plugins/builtin/thirteenf/headless.ts +14 -6
- package/src/plugins/builtin/thirteenf/model.ts +56 -1
- package/src/plugins/builtin/thirteenf/pane.tsx +8 -8
- package/src/plugins/builtin/thirteenf/report-notes.ts +11 -0
- package/src/plugins/builtin/thirteenf/table.ts +2 -1
- package/src/plugins/builtin/thirteenf/types.ts +6 -0
- package/src/plugins/builtin/ticker-detail/data-panes/historical-prices.tsx +23 -3
- package/src/plugins/builtin/ticker-detail/financials/model.ts +5 -0
- package/src/plugins/builtin/ticker-detail/headless-schema.ts +2 -1
- package/src/plugins/builtin/ticker-detail/headless.ts +21 -66
- package/src/plugins/builtin/ticker-detail/index.tsx +5 -0
- package/src/plugins/builtin/ticker-detail/overview/components.tsx +67 -6
- package/src/plugins/builtin/ticker-detail/overview/model.ts +6 -4
- package/src/plugins/builtin/ticker-detail/overview/pane.tsx +15 -0
- package/src/plugins/builtin/ticker-detail/overview/tax-equivalent.ts +69 -0
- package/src/plugins/builtin/ticker-detail/overview-tab.tsx +69 -19
- package/src/plugins/builtin/ticker-detail/pane.tsx +7 -2
- package/src/plugins/builtin/ticker-detail/quote-monitor/card.tsx +47 -24
- package/src/plugins/builtin/ticker-detail/quote-monitor/export.ts +46 -0
- package/src/plugins/builtin/ticker-detail/quote-monitor/index.tsx +20 -1
- package/src/plugins/builtin/ticker-detail/quote-monitor/rows.ts +120 -0
- package/src/plugins/builtin/ticker-detail/research-tabs.ts +1 -5
- package/src/plugins/builtin/ticker-detail/settings.ts +6 -6
- package/src/plugins/builtin/treasury-auctions/cache.ts +85 -19
- package/src/plugins/builtin/treasury-auctions/index.tsx +22 -11
- package/src/plugins/builtin/treasury-auctions/model.ts +23 -0
- package/src/plugins/builtin/treasury-auctions/treasury-direct.ts +128 -0
- package/src/plugins/builtin/world-indices/client.ts +2 -0
- package/src/plugins/compat.ts +15 -0
- package/src/plugins/host-link.ts +6 -1
- package/src/plugins/installer.ts +53 -3
- package/src/portfolio/column-values.ts +14 -4
- package/src/portfolio/listed-symbol.ts +78 -0
- package/src/portfolio/real-return.ts +172 -0
- package/src/public/__snapshots__/public-api.test.ts.snap +1 -0
- package/src/remote/resources.ts +12 -1
- package/src/remote/schema.ts +1 -0
- package/src/remote/semantic-helpers.ts +29 -1
- package/src/remote/semantic-tree.tsx +32 -15
- package/src/renderers/browser/config-host.ts +56 -15
- package/src/renderers/browser/main.tsx +3 -1
- package/src/renderers/browser/ui-host.tsx +1 -0
- package/src/renderers/cloudflare/http-proxy.ts +1 -0
- package/src/renderers/cloudflare/worker.ts +16 -1
- package/src/renderers/dom/boot-frame.ts +2 -2
- package/src/renderers/dom/data-table/row.tsx +4 -1
- package/src/renderers/dom/desktop/controls.tsx +4 -4
- package/src/renderers/dom/desktop/dialog-actions.tsx +60 -41
- package/src/renderers/dom/dom-ui-host.tsx +3 -1
- package/src/renderers/dom/host/input.tsx +4 -1
- package/src/renderers/dom/host/tabs.tsx +10 -1
- package/src/renderers/dom/styles.css +73 -19
- package/src/renderers/electrobun/bun/desktop/app-name.ts +1 -1
- package/src/renderers/opentui/host.tsx +2 -1
- package/src/renderers/share/layout-view.tsx +1 -1
- package/src/sources/gloomberb-cloud/fred-series.ts +12 -0
- package/src/sources/gloomberb-cloud/index.ts +31 -2
- package/src/sources/gloomberb-cloud/news.ts +35 -12
- package/src/sources/gloomberb-cloud/normalizers.ts +29 -3
- package/src/sources/provider-router/cached-routes.ts +19 -7
- package/src/state/opening-ticker-panes.ts +47 -0
- package/src/state/pane-table-export-registry.ts +19 -6
- package/src/test-support/cli-context.ts +2 -0
- package/src/test-support/preload.ts +8 -1
- package/src/theme/colors.ts +9 -1
- package/src/theme/themes.ts +62 -15
- package/src/theme/tone-contrast.ts +40 -0
- package/src/theme/ui-tokens.ts +23 -3
- package/src/tickers/batched-lookups.ts +57 -8
- package/src/tickers/company-name-listing.ts +156 -14
- package/src/tickers/company-name.ts +30 -6
- package/src/tickers/instrument-kind.ts +23 -3
- package/src/tickers/list.ts +7 -0
- package/src/tickers/search/home-listing.ts +31 -9
- package/src/tickers/search/index.ts +13 -3
- package/src/tickers/search/listing-index.ts +558 -0
- package/src/tickers/search/major-listings.chunk.ts +10 -0
- package/src/tickers/search/major-listings.json +3346 -0
- package/src/tickers/search/ranking.ts +68 -1
- package/src/tickers/search/types.ts +4 -0
- package/src/tickers/terminal-codes.ts +26 -1
- package/src/time-series/calendar-month-returns.ts +47 -0
- package/src/time-series/currency-conversion.ts +130 -0
- package/src/time-series/hooks.ts +2 -0
- package/src/time-series/price-comparison.ts +34 -11
- package/src/time-series/resolve-context.ts +3 -0
- package/src/time-series/resolve.ts +14 -2
- package/src/time-series/spec.ts +1 -0
- package/src/time-series/studies/indicators.ts +4 -1
- package/src/time-series/types.ts +8 -0
- package/src/types/config.ts +13 -0
- package/src/types/context-menu.ts +2 -0
- package/src/types/data-provider.ts +28 -0
- package/src/types/financials.ts +20 -2
- package/src/types/headless.ts +12 -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 +114 -0
- package/src/types/plugin-pane-templates.ts +160 -0
- package/src/types/plugin-panes.ts +221 -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/host.tsx +8 -0
- package/src/ui/index.tsx +14 -3
- package/src/updater/github-releases.ts +23 -0
- package/src/utils/cli-output.ts +22 -9
- package/src/utils/datetime-format.ts +17 -3
- package/src/utils/display-number.ts +15 -0
- package/src/utils/double-escape-close.ts +61 -16
- package/src/utils/float32-price.ts +24 -0
- package/src/utils/forward-dividend.ts +81 -16
- package/src/utils/fx-market-hours.ts +11 -0
- package/src/utils/plugin-proxy-hosts.json +2 -1
- package/src/utils/price-history.ts +7 -6
- package/src/utils/report-timing.ts +62 -0
- package/src/utils/sec-filings.ts +32 -0
- package/src/utils/utc-time.ts +5 -0
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
// What this device read of each move rule, kept apart from the rules. The
|
|
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.
|
|
6
|
+
import type { QuoteChangeBasis } from "../../../market-data/market/change-basis";
|
|
7
|
+
import type { QuoteDataSource } from "../../../types/financials";
|
|
8
|
+
import type { AlertRule } from "./types";
|
|
9
|
+
|
|
10
|
+
/** The device's last reading of each move rule, by rule id, in plugin resume state: never synced. */
|
|
11
|
+
export const MOVE_CHECKS_KEY = "moveChecks";
|
|
12
|
+
|
|
13
|
+
/** One device's last reading of a move rule, and the session it last went off in. */
|
|
14
|
+
export interface MoveCheck {
|
|
15
|
+
/** The arming the reading is of (the rule's `armedAt`, else `createdAt`): an edit starts afresh. */
|
|
16
|
+
armedAt: number;
|
|
17
|
+
checkedAt: number;
|
|
18
|
+
/** The move read, in percent. */
|
|
19
|
+
percent?: number;
|
|
20
|
+
basis?: QuoteChangeBasis;
|
|
21
|
+
quoteAt?: number;
|
|
22
|
+
source?: QuoteDataSource;
|
|
23
|
+
currency?: string;
|
|
24
|
+
exchange?: string;
|
|
25
|
+
pence?: true;
|
|
26
|
+
/** Why the last check had no quote. */
|
|
27
|
+
error?: string;
|
|
28
|
+
/** It went off, and waits for a later session to arm it again. */
|
|
29
|
+
fired?: true;
|
|
30
|
+
firedAt?: number;
|
|
31
|
+
/** The session (a date) it last went off in. */
|
|
32
|
+
session?: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const isText = (value: unknown): value is string => typeof value === "string" && value.length > 0 && value.length <= 300;
|
|
36
|
+
const isNumber = (value: unknown): value is number => typeof value === "number" && Number.isFinite(value);
|
|
37
|
+
const BASIS_KINDS = new Set(["close", "settle", "previous close", "utc day", "24h"]);
|
|
38
|
+
const SOURCES = new Set<QuoteDataSource>(["live", "delayed", "snapshot"]);
|
|
39
|
+
|
|
40
|
+
function readBasis(value: unknown): QuoteChangeBasis | undefined {
|
|
41
|
+
if (!value || typeof value !== "object") return undefined;
|
|
42
|
+
const basis = value as Record<string, unknown>;
|
|
43
|
+
if (!BASIS_KINDS.has(String(basis.kind))) return undefined;
|
|
44
|
+
if ((basis.kind === "close" || basis.kind === "settle") && !isText(basis.date)) return undefined;
|
|
45
|
+
return value as QuoteChangeBasis;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** The saved readings that read; anything else is dropped, and the next check writes it again. */
|
|
49
|
+
export function readMoveChecks(value: unknown): Record<string, MoveCheck> {
|
|
50
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return {};
|
|
51
|
+
const checks: Record<string, MoveCheck> = {};
|
|
52
|
+
for (const [id, raw] of Object.entries(value as Record<string, unknown>)) {
|
|
53
|
+
if (!raw || typeof raw !== "object") continue;
|
|
54
|
+
const check = raw as Record<string, unknown>;
|
|
55
|
+
if (!isNumber(check.armedAt) || !isNumber(check.checkedAt)) continue;
|
|
56
|
+
const basis = readBasis(check.basis);
|
|
57
|
+
checks[id] = {
|
|
58
|
+
armedAt: check.armedAt,
|
|
59
|
+
checkedAt: check.checkedAt,
|
|
60
|
+
...isNumber(check.percent) ? { percent: check.percent } : {},
|
|
61
|
+
...basis ? { basis } : {},
|
|
62
|
+
...isNumber(check.quoteAt) ? { quoteAt: check.quoteAt } : {},
|
|
63
|
+
...SOURCES.has(check.source as QuoteDataSource) ? { source: check.source as QuoteDataSource } : {},
|
|
64
|
+
...isText(check.currency) ? { currency: check.currency } : {},
|
|
65
|
+
...isText(check.exchange) ? { exchange: check.exchange } : {},
|
|
66
|
+
...check.pence === true ? { pence: true as const } : {},
|
|
67
|
+
...isText(check.error) ? { error: check.error } : {},
|
|
68
|
+
...check.fired === true ? { fired: true as const } : {},
|
|
69
|
+
...isNumber(check.firedAt) ? { firedAt: check.firedAt } : {},
|
|
70
|
+
...isText(check.session) ? { session: check.session } : {},
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
return checks;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const armingOf = (alert: Pick<AlertRule, "armedAt" | "createdAt">) => alert.armedAt ?? alert.createdAt;
|
|
77
|
+
|
|
78
|
+
/** A judged move rule's reading, as this device keeps it; null before its first check. */
|
|
79
|
+
function moveCheckOf(alert: AlertRule): MoveCheck | null {
|
|
80
|
+
if (!alert.move || alert.lastCheckedAt == null) return null;
|
|
81
|
+
return {
|
|
82
|
+
armedAt: armingOf(alert),
|
|
83
|
+
checkedAt: alert.lastCheckedAt,
|
|
84
|
+
...alert.lastCheckedPrice != null && Number.isFinite(alert.lastCheckedPrice) ? { percent: alert.lastCheckedPrice } : {},
|
|
85
|
+
...alert.lastMoveBasis ? { basis: alert.lastMoveBasis } : {},
|
|
86
|
+
...alert.lastQuoteUpdatedAt != null && Number.isFinite(alert.lastQuoteUpdatedAt) ? { quoteAt: alert.lastQuoteUpdatedAt } : {},
|
|
87
|
+
...alert.lastQuoteSource ? { source: alert.lastQuoteSource } : {},
|
|
88
|
+
...alert.lastQuoteCurrency ? { currency: alert.lastQuoteCurrency } : {},
|
|
89
|
+
...alert.lastQuoteExchange ? { exchange: alert.lastQuoteExchange } : {},
|
|
90
|
+
...alert.lastQuotePence ? { pence: true as const } : {},
|
|
91
|
+
...alert.lastCheckError ? { error: alert.lastCheckError } : {},
|
|
92
|
+
...alert.status === "triggered" ? { fired: true as const, ...alert.triggeredAt ? { firedAt: alert.triggeredAt } : {} } : {},
|
|
93
|
+
...alert.moveSession ? { session: alert.moveSession } : {},
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* A move rule as this device reads it: the rule with its last reading, and
|
|
99
|
+
* triggered while it waits for the next session. A reading of an earlier
|
|
100
|
+
* arming (before an edit or a re-arm) is not its own. Any other rule, and a
|
|
101
|
+
* move rule never read here, is returned as the rule.
|
|
102
|
+
*/
|
|
103
|
+
function withMoveCheck(alert: AlertRule, check: MoveCheck | undefined): AlertRule {
|
|
104
|
+
if (!alert.move) return alert;
|
|
105
|
+
const rule = moveRuleOnly(alert);
|
|
106
|
+
if (!check || check.armedAt !== armingOf(alert)) return rule;
|
|
107
|
+
return {
|
|
108
|
+
...rule,
|
|
109
|
+
lastCheckedAt: check.checkedAt,
|
|
110
|
+
...check.percent != null ? { lastCheckedPrice: check.percent } : {},
|
|
111
|
+
...check.basis ? { lastMoveBasis: check.basis } : {},
|
|
112
|
+
...check.quoteAt != null ? { lastQuoteUpdatedAt: check.quoteAt } : {},
|
|
113
|
+
...check.source ? { lastQuoteSource: check.source } : {},
|
|
114
|
+
...check.currency ? { lastQuoteCurrency: check.currency } : {},
|
|
115
|
+
...check.exchange ? { lastQuoteExchange: check.exchange } : {},
|
|
116
|
+
...check.pence ? { lastQuotePence: true } : {},
|
|
117
|
+
...check.error ? { lastCheckError: check.error } : {},
|
|
118
|
+
...check.fired ? { status: "triggered" as const, ...check.firedAt ? { triggeredAt: check.firedAt } : {} } : {},
|
|
119
|
+
...check.session ? { moveSession: check.session } : {},
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** The rules with this device's readings of the move rules among them (`withMoveCheck`). */
|
|
124
|
+
export function withMoveChecks(alerts: AlertRule[], checks: Record<string, MoveCheck>): AlertRule[] {
|
|
125
|
+
return alerts.map((alert) => alert.move ? withMoveCheck(alert, checks[alert.id]) : alert);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** The readings to keep for the rules: each move rule's, as judged; a deleted rule's goes. */
|
|
129
|
+
export function moveChecksOf(alerts: readonly AlertRule[]): Record<string, MoveCheck> {
|
|
130
|
+
const checks: Record<string, MoveCheck> = {};
|
|
131
|
+
for (const alert of alerts) {
|
|
132
|
+
const check = moveCheckOf(alert);
|
|
133
|
+
if (check) checks[alert.id] = check;
|
|
134
|
+
}
|
|
135
|
+
return checks;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
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.
|
|
145
|
+
*/
|
|
146
|
+
export function moveRuleOnly(alert: AlertRule): AlertRule {
|
|
147
|
+
return {
|
|
148
|
+
id: alert.id,
|
|
149
|
+
symbol: alert.symbol,
|
|
150
|
+
...alert.exchange ? { exchange: alert.exchange } : {},
|
|
151
|
+
condition: alert.condition,
|
|
152
|
+
targetPrice: alert.targetPrice,
|
|
153
|
+
createdAt: alert.createdAt,
|
|
154
|
+
...alert.armedAt != null ? { armedAt: alert.armedAt } : {},
|
|
155
|
+
status: "active",
|
|
156
|
+
...alert.message ? { message: alert.message } : {},
|
|
157
|
+
...alert.moveDay ? { moveDay: alert.moveDay } : {},
|
|
158
|
+
move: true,
|
|
159
|
+
syncsMoveDay: true,
|
|
160
|
+
};
|
|
161
|
+
}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
// Alerts on a move from the previous close (`alerts add GBPUSD=X moves 0.5%`,
|
|
2
|
+
// `up 3%`, `down 3%`): the day's change the quote reports, measured from the
|
|
3
|
+
// close its change line names, for any listing or currency pair. One goes off
|
|
4
|
+
// once per session and arms itself again for the next one.
|
|
5
|
+
import { changeBasisLabel, quoteChangeBasis, type QuoteChangeBasis } from "../../../market-data/market/change-basis";
|
|
6
|
+
import { getActiveQuoteDisplay } from "../../../market-data/market/status";
|
|
7
|
+
import { quoteTradingDay } from "../../../market-data/quotes/day-range";
|
|
8
|
+
import type { Quote } from "../../../types/financials";
|
|
9
|
+
import type { AlertCondition, AlertRule } from "./types";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Move rules keep a synced list of their own: an app or a Gloom Cloud that
|
|
13
|
+
* reads `alerts` would judge `up 3` as a price above 3. The running app checks
|
|
14
|
+
* them, and for a signed-in account with Cloud sync, Gloom Cloud does too.
|
|
15
|
+
*/
|
|
16
|
+
export const MOVE_ALERTS_KEY = "moveAlerts";
|
|
17
|
+
|
|
18
|
+
/** The words a move is typed with, and the condition each keeps: either way, up, or down. */
|
|
19
|
+
const MOVE_WORDS: Readonly<Record<string, AlertCondition>> = {
|
|
20
|
+
moves: "crosses", move: "crosses", up: "above", rises: "above", down: "below", falls: "below",
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/** The condition a move word names (`moves`, `up`, `down`), or null for any other word. */
|
|
24
|
+
export function moveCondition(word: string | undefined): AlertCondition | null {
|
|
25
|
+
return word ? MOVE_WORDS[word.toLowerCase()] ?? null : null;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Who hears of a move, as docs/usage.md states it: the running app checks its
|
|
30
|
+
* move rules. Signed in with Cloud sync, Gloom Cloud checks them too and, with
|
|
31
|
+
* the app closed, pushes one that goes off to a registered phone and lists it
|
|
32
|
+
* in the day's market email, unless the app already alerted on that session
|
|
33
|
+
* (`moveDay`). Said where a move alert is made, as a price alert's add says it.
|
|
34
|
+
*/
|
|
35
|
+
export const MOVE_DELIVERY = "The app alerts while it is running; sign in with Cloud sync for a phone alert and a line in the day's market email when it is closed.";
|
|
36
|
+
|
|
37
|
+
/** The largest move a rule takes, in percent: a fall cannot pass 100%. */
|
|
38
|
+
const MAX_MOVE_PERCENT = 100;
|
|
39
|
+
|
|
40
|
+
/** `0.5%`, `3`, `+3%`: a move in percent, unsigned; null when it is no positive number up to 100. */
|
|
41
|
+
export function parseMovePercent(text: string | undefined): number | null {
|
|
42
|
+
const match = /^\+?(\d+(?:\.\d+)?|\.\d+)\s*%?$/.exec(text?.trim() ?? "");
|
|
43
|
+
const value = match ? Number(match[1]) : Number.NaN;
|
|
44
|
+
return Number.isFinite(value) && value > 0 && value <= MAX_MOVE_PERCENT ? value : null;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const percentText = (value: number) => `${Number(value.toFixed(2)).toFixed(2)}%`;
|
|
48
|
+
|
|
49
|
+
/** `±0.50%`, `+3.00%`, `-3.00%`: a move rule's target, signed by its direction. */
|
|
50
|
+
export function moveTargetText(alert: Pick<AlertRule, "condition" | "targetPrice">): string {
|
|
51
|
+
const sign = alert.condition === "crosses" ? "±" : alert.condition === "above" ? "+" : "-";
|
|
52
|
+
return `${sign}${percentText(alert.targetPrice)}`;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** `-0.38%`, `+1.20%`: a move as read, signed; `0.00%` unsigned. */
|
|
56
|
+
export function movePercentText(value: number): string {
|
|
57
|
+
const text = percentText(Math.abs(value));
|
|
58
|
+
return /[1-9]/.test(text) ? `${value > 0 ? "+" : "-"}${text}` : text;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** `moves 0.50%`, `up 3.00%`, `down 3.00%`: the rule in the words `alerts add` takes. */
|
|
62
|
+
export function moveRuleWords(alert: Pick<AlertRule, "condition" | "targetPrice">): string {
|
|
63
|
+
const word = alert.condition === "crosses" ? "moves" : alert.condition === "above" ? "up" : "down";
|
|
64
|
+
return `${word} ${percentText(alert.targetPrice)}`;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** The Trigger column's word: Moves, Up or Down. */
|
|
68
|
+
export function moveTriggerLabel(condition: AlertCondition): string {
|
|
69
|
+
return condition === "crosses" ? "Moves" : condition === "above" ? "Up" : "Down";
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** What a move is measured from, as the quote's change line names it: `vs Thu 5 Nov close`, `vs prev close`. */
|
|
73
|
+
export function moveBasisText(basis: QuoteChangeBasis | null | undefined, now = Date.now()): string {
|
|
74
|
+
return basis ? changeBasisLabel(basis, now) : "vs prev close";
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** A move as a quote reports it: the percent, what it is measured from, and the session it belongs to. */
|
|
78
|
+
export interface MoveReading {
|
|
79
|
+
percent: number;
|
|
80
|
+
basis: QuoteChangeBasis;
|
|
81
|
+
/**
|
|
82
|
+
* The session the move is of, as a date: the close it is measured from (the
|
|
83
|
+
* 2026-11-05 close) for a listing or a pair, the UTC day for a coin. Null
|
|
84
|
+
* when nothing dates it, as for a pair's print after the week's close: such
|
|
85
|
+
* a reading can set off an armed rule, never arm one again.
|
|
86
|
+
*/
|
|
87
|
+
session: string | null;
|
|
88
|
+
/**
|
|
89
|
+
* The move's own session, as the quote dates its change (changeSessionDate,
|
|
90
|
+
* the 2026-11-06 session), the way Gloom Cloud dates the moves it judges;
|
|
91
|
+
* null when nothing dates it.
|
|
92
|
+
*/
|
|
93
|
+
day: string | null;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const utcDay = (time: number) => new Date(time).toISOString().slice(0, 10);
|
|
97
|
+
const ISO_DAY = /^\d{4}-\d{2}-\d{2}$/;
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* The move a quote reports for a rule to judge: its change percent (the
|
|
101
|
+
* latest print's, extended hours included, as the alert's price is) and the
|
|
102
|
+
* close it is measured from. A coin's move from 00:00 UTC is that day's, one
|
|
103
|
+
* over 24 hours the UTC day's. Null for a quote with no move.
|
|
104
|
+
*/
|
|
105
|
+
export function readMove(quote: Quote, now = Date.now()): MoveReading | null {
|
|
106
|
+
const percent = getActiveQuoteDisplay(quote)?.changePercent ?? quote.changePercent;
|
|
107
|
+
if (!Number.isFinite(percent)) return null;
|
|
108
|
+
const basis = quoteChangeBasis(quote, { session: "active" });
|
|
109
|
+
if (!basis) return null;
|
|
110
|
+
const session = "date" in basis ? basis.date : basis.kind === "utc day" || basis.kind === "24h" ? utcDay(now) : null;
|
|
111
|
+
return { percent, basis, session, day: moveDayOf(quote, basis, now) };
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** The session a quote dates its move to: its changeSessionDate, a coin's UTC day, else its trading day. */
|
|
115
|
+
function moveDayOf(quote: Quote, basis: QuoteChangeBasis, now: number): string | null {
|
|
116
|
+
if (quote.changeSessionDate && ISO_DAY.test(quote.changeSessionDate)) return quote.changeSessionDate;
|
|
117
|
+
if (basis.kind === "utc day" || basis.kind === "24h") return utcDay(now);
|
|
118
|
+
const day = quoteTradingDay(quote);
|
|
119
|
+
return day && ISO_DAY.test(day) ? day : null;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** A reading this recent dates an undated one after it: the same session, read by a stream and a poll that disagree. */
|
|
123
|
+
const DATED_READING_MS = 12 * 60 * 60_000;
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* The session a rule that goes off on `reading` went off in: the reading's
|
|
127
|
+
* own, or for an undated one the session of the dated reading just before
|
|
128
|
+
* it, else the UTC day, so it is never armed again in the session it went
|
|
129
|
+
* off in (at worst it waits a session longer).
|
|
130
|
+
*/
|
|
131
|
+
function firedSession(alert: AlertRule, reading: MoveReading, now: number): string {
|
|
132
|
+
if (reading.session) return reading.session;
|
|
133
|
+
const before = alert.lastMoveBasis && "date" in alert.lastMoveBasis ? alert.lastMoveBasis.date : null;
|
|
134
|
+
const recent = alert.lastCheckedAt != null && now - alert.lastCheckedAt <= DATED_READING_MS;
|
|
135
|
+
return before && recent ? before : utcDay(now);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** The session a rule went off in, as a date: its own, or the UTC day it went off for one that names none. */
|
|
139
|
+
function lastFiredSession(alert: AlertRule): string | null {
|
|
140
|
+
if (alert.moveSession && ISO_DAY.test(alert.moveSession)) return alert.moveSession;
|
|
141
|
+
return alert.triggeredAt ? utcDay(alert.triggeredAt) : null;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** Whether a move reaches a rule: either way by its size, or up or down by it. */
|
|
145
|
+
export function moveReached(alert: Pick<AlertRule, "condition" | "targetPrice">, percent: number): boolean {
|
|
146
|
+
// To the hundredth of a percent the quote prints, so a 0.4999% move is not 0.50%.
|
|
147
|
+
const move = Math.round(percent * 100) / 100;
|
|
148
|
+
if (alert.condition === "above") return move >= alert.targetPrice;
|
|
149
|
+
if (alert.condition === "below") return move <= -alert.targetPrice;
|
|
150
|
+
return Math.abs(move) >= alert.targetPrice;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* A move rule judged on a quote. One that went off is armed again only by a
|
|
155
|
+
* dated session later than the one it went off in: a print after the close,
|
|
156
|
+
* a weekend quote, or a stream and a poll that date the move a day apart
|
|
157
|
+
* never arm it twice. Then it goes off when the move reaches it, once for the
|
|
158
|
+
* session, and the rule keeps the move's session (`moveDay`, the latest) for
|
|
159
|
+
* Gloom Cloud. Returns the rule with its reading, and whether it went off now.
|
|
160
|
+
*/
|
|
161
|
+
export function judgeMove(alert: AlertRule, quote: Quote, now = Date.now()): { alert: AlertRule; fired: boolean; reading: MoveReading | null } {
|
|
162
|
+
const reading = readMove(quote, now);
|
|
163
|
+
if (!reading) return { alert, fired: false, reading };
|
|
164
|
+
let next: AlertRule = { ...alert, lastCheckedPrice: reading.percent, lastMoveBasis: reading.basis };
|
|
165
|
+
const last = lastFiredSession(alert);
|
|
166
|
+
// Armed again for a new session: `triggeredAt` is cleared rather than left out, so it clears on a rule merged into.
|
|
167
|
+
if (next.status === "triggered" && reading.session && (!last || reading.session > last)) next = { ...next, status: "active", triggeredAt: undefined };
|
|
168
|
+
// A session it already went off in, as a dated reading says, never sets it off again.
|
|
169
|
+
const wentOff = !!reading.session && !!last && reading.session <= last && next.moveSession != null;
|
|
170
|
+
const fired = next.status === "active" && !wentOff && moveReached(next, reading.percent);
|
|
171
|
+
if (fired) {
|
|
172
|
+
const day = reading.day && (!alert.moveDay || reading.day > alert.moveDay) ? { moveDay: reading.day } : {};
|
|
173
|
+
next = { ...next, status: "triggered", triggeredAt: now, moveSession: firedSession(alert, reading, now), ...day };
|
|
174
|
+
}
|
|
175
|
+
return { alert: next, fired, reading };
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/** "GBPUSD=X moved -0.52% vs Thu 5 Nov close, at 1.33702": the notification of a move rule that went off. */
|
|
179
|
+
export function moveFiredText(listing: string, reading: MoveReading, price: string, now = Date.now()): string {
|
|
180
|
+
return `${listing} moved ${movePercentText(reading.percent)} ${moveBasisText(reading.basis, now)}, at ${price}`;
|
|
181
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { METRIC_ALERTS_KEY, RELATIVE_ALERTS_KEY, closeBasis,
|
|
1
|
+
import { METRIC_ALERTS_KEY, RELATIVE_ALERTS_KEY, closeBasis, metricReadingText } from "./metric-model";
|
|
2
2
|
import { metricAvailabilityError } from "./metric-data";
|
|
3
3
|
import { relativeAlertText } from "./metric-command";
|
|
4
4
|
import { levelAlertStoreKey, readLevelAlertStores } from "./storage";
|
|
@@ -32,6 +32,7 @@ import {
|
|
|
32
32
|
serializeAlerts,
|
|
33
33
|
} from "./alert-engine";
|
|
34
34
|
import { parseAlertEdit } from "./command";
|
|
35
|
+
import { MOVE_CHECKS_KEY, readMoveChecks, withMoveChecks } from "./move-checks";
|
|
35
36
|
import { ALERT_TABS, ALERTS_KEY } from "./constants";
|
|
36
37
|
import {
|
|
37
38
|
alertListing,
|
|
@@ -42,15 +43,18 @@ import {
|
|
|
42
43
|
formatQuoteChecked,
|
|
43
44
|
isoUtc,
|
|
44
45
|
listingWithCurrency,
|
|
46
|
+
measureLabel,
|
|
45
47
|
relativeTime,
|
|
48
|
+
triggerLabel,
|
|
46
49
|
} from "./format";
|
|
50
|
+
import { MOVE_ALERTS_KEY, moveBasisText, moveRuleWords } from "./move";
|
|
47
51
|
import { FIRED_LOG_KEY } from "./fired-log";
|
|
48
52
|
import { withAlertChange } from "./alert-log";
|
|
49
53
|
import type { AlertRule } from "./types";
|
|
50
54
|
import { useQuoteEntries } from "../../../market-data/hooks";
|
|
51
55
|
import { buildQuoteKey, resolveEntryData } from "../../../market-data/selectors";
|
|
52
56
|
import { alertInstrument, streamedAlertQuote, syncAlertQuoteStream } from "./live";
|
|
53
|
-
import { quoteAlertFields } from "./quotes";
|
|
57
|
+
import { moveQuoteFields, quoteAlertFields } from "./quotes";
|
|
54
58
|
import { clearPriceAlertFocus, getPriceAlertFocus, subscribePriceAlertFocus } from "./focus";
|
|
55
59
|
import { alertTarget, alertViewHints, priceRuleSubject, useOpenAlertTarget } from "./targets";
|
|
56
60
|
|
|
@@ -70,7 +74,8 @@ type AlertColumn = DataTableColumn & { id: AlertColumnId };
|
|
|
70
74
|
|
|
71
75
|
const ALERT_COLUMNS: AlertColumn[] = [
|
|
72
76
|
{ id: "status", label: "State", width: 9, align: "left" },
|
|
73
|
-
|
|
77
|
+
// Wide enough for a listing kept with its venue (7203:JPX).
|
|
78
|
+
{ id: "symbol", label: "Symbol", width: 9, align: "left" },
|
|
74
79
|
{ id: "metric", label: "Measure", width: 14, align: "left" },
|
|
75
80
|
{ id: "current", label: "Current", width: 8, align: "right" },
|
|
76
81
|
{ id: "target", label: "Target", width: 11, align: "right" },
|
|
@@ -85,10 +90,10 @@ const ALERT_COLUMNS: AlertColumn[] = [
|
|
|
85
90
|
|
|
86
91
|
const DETAIL_ROW = { labelWidth: 10, emphasis: false } as const;
|
|
87
92
|
|
|
88
|
-
/** "AAPL above 400.00": the rule, which titles its detail. */
|
|
93
|
+
/** "AAPL above 400.00", "GBPUSD=X moves 0.50% from the previous close": the rule, which titles its detail. */
|
|
89
94
|
function alertTitle(alert: AlertRule): string {
|
|
90
|
-
if (alert.metric) return formatAlertDescription(alert);
|
|
91
|
-
return `${alert.symbol} ${conditionLabel(alert.condition).toLowerCase()} ${formatAlertTargetPrice(alert)}`;
|
|
95
|
+
if (alert.metric || alert.move) return formatAlertDescription(alert);
|
|
96
|
+
return `${alertListing({ symbol: alert.symbol, exchange: alert.exchange })} ${conditionLabel(alert.condition).toLowerCase()} ${formatAlertTargetPrice(alert)}`;
|
|
92
97
|
}
|
|
93
98
|
|
|
94
99
|
/**
|
|
@@ -108,13 +113,15 @@ function AlertDetail({ alert, scrollRef }: { alert: AlertRule; scrollRef: RefObj
|
|
|
108
113
|
<KeyValueRow {...DETAIL_ROW} label="Listing" value={listingWithCurrency(alertListing(alert), alert.lastQuoteCurrency)} />
|
|
109
114
|
{/* With no quote the reason above says why; the price and its distance wait for one. */}
|
|
110
115
|
{basis ? <KeyValueRow {...DETAIL_ROW} label="Close date" value={alert.lastDailyClose ?? `Awaiting ${basis}`} /> : null}
|
|
111
|
-
{reason ? null : <KeyValueRow {...DETAIL_ROW} label="Current" value={formatCurrentPrice(alert, 24)} />}
|
|
116
|
+
{reason ? null : <KeyValueRow {...DETAIL_ROW} label={alert.move ? "Move" : "Current"} value={formatCurrentPrice(alert, 24)} />}
|
|
117
|
+
{/* What a move is measured from, as the quote's change line names it. */}
|
|
118
|
+
{!reason && alert.move ? <KeyValueRow {...DETAIL_ROW} label="From" value={moveBasisText(alert.lastMoveBasis).replace(/^vs /, "")} tone="muted" /> : null}
|
|
112
119
|
{/* The two readings that place the quadrant, as RRG states them. */}
|
|
113
120
|
{!reason && alert.metric?.kind === "rrg" && alert.lastCheckedPrice != null && alert.lastCheckedTarget != null ? <>
|
|
114
121
|
<KeyValueRow {...DETAIL_ROW} label="Strength" value={alert.lastCheckedPrice.toFixed(2)} />
|
|
115
122
|
<KeyValueRow {...DETAIL_ROW} label="Momentum" value={alert.lastCheckedTarget.toFixed(2)} />
|
|
116
123
|
</> : null}
|
|
117
|
-
{reason ? null : <KeyValueRow {...DETAIL_ROW} label="Away" value={formatAlertDistance(alert)} />}
|
|
124
|
+
{reason || alert.move ? null : <KeyValueRow {...DETAIL_ROW} label="Away" value={formatAlertDistance(alert)} />}
|
|
118
125
|
{reason
|
|
119
126
|
? alert.lastCheckedAt ? <KeyValueRow {...DETAIL_ROW} label="Checked" value={relativeTime(alert.lastCheckedAt)} tone="muted" /> : null
|
|
120
127
|
: <KeyValueRow {...DETAIL_ROW} label="Quote" value={formatQuoteChecked(alert)} tone="muted" />}
|
|
@@ -159,13 +166,19 @@ export function AlertsPane(props: PaneProps) {
|
|
|
159
166
|
);
|
|
160
167
|
}
|
|
161
168
|
|
|
169
|
+
/** No readings yet, one object for every render: a fresh `{}` each time would read as a change. */
|
|
170
|
+
const NO_MOVE_CHECKS = {};
|
|
171
|
+
|
|
162
172
|
function PriceAlertsPane({ focused, width, height }: PaneProps) {
|
|
163
173
|
const [alertsJson, setAlertsJson] = usePluginConfigState<unknown>(ALERTS_KEY, "[]");
|
|
164
174
|
const [metricsJson, setMetricsJson] = usePluginConfigState<unknown>(METRIC_ALERTS_KEY, "[]");
|
|
165
175
|
const [relativeJson, setRelativeJson] = usePluginConfigState<unknown>(RELATIVE_ALERTS_KEY, "[]");
|
|
176
|
+
const [movesJson, setMovesJson] = usePluginConfigState<unknown>(MOVE_ALERTS_KEY, "[]");
|
|
166
177
|
const { openPluginCommandWorkflow, notify } = usePluginAppActions();
|
|
167
178
|
// Deleting or re-arming a rule goes in this device's alert log, beside the alerts that fired.
|
|
168
179
|
const [, setAlertLog] = usePluginState<unknown>(FIRED_LOG_KEY, []);
|
|
180
|
+
// A move rule's readings, and whether it went off this session, are this device's, beside the synced rules.
|
|
181
|
+
const [savedMoveChecks, setMoveChecks] = usePluginState<unknown>(MOVE_CHECKS_KEY, NO_MOVE_CHECKS);
|
|
169
182
|
const dialog = useDialog();
|
|
170
183
|
const [selectedIdx, setSelectedIdx] = useState(0);
|
|
171
184
|
const [detailOpen, setDetailOpen] = useState(false);
|
|
@@ -176,12 +189,13 @@ function PriceAlertsPane({ focused, width, height }: PaneProps) {
|
|
|
176
189
|
const columns = width < 106 ? ALERT_COLUMNS.filter(column => column.id !== "away" && column.id !== "triggered" && column.id !== "created")
|
|
177
190
|
: width < 118 ? ALERT_COLUMNS.filter(column => column.id !== "created") : ALERT_COLUMNS;
|
|
178
191
|
const showHorizontalScrollbar = columns.reduce((sum, column) => sum + column.width + 1, 2) > width;
|
|
179
|
-
const stores = useMemo(() => readLevelAlertStores(key => key === ALERTS_KEY ? alertsJson : key === METRIC_ALERTS_KEY ? metricsJson
|
|
180
|
-
|
|
192
|
+
const stores = useMemo(() => readLevelAlertStores(key => key === ALERTS_KEY ? alertsJson : key === METRIC_ALERTS_KEY ? metricsJson
|
|
193
|
+
: key === MOVE_ALERTS_KEY ? movesJson : relativeJson),
|
|
194
|
+
[alertsJson, metricsJson, movesJson, relativeJson]);
|
|
181
195
|
const storeError = stores.error;
|
|
182
196
|
|
|
183
197
|
const { alerts, rows } = useMemo(() => {
|
|
184
|
-
const parsed = stores.alerts;
|
|
198
|
+
const parsed = withMoveChecks(stores.alerts, readMoveChecks(savedMoveChecks));
|
|
185
199
|
const activeAlerts = parsed.filter((a) => a.status === "active");
|
|
186
200
|
const triggeredAlerts = parsed
|
|
187
201
|
.filter((a) => a.status === "triggered")
|
|
@@ -191,7 +205,7 @@ function PriceAlertsPane({ focused, width, height }: PaneProps) {
|
|
|
191
205
|
alerts: parsed,
|
|
192
206
|
rows: [...activeAlerts, ...triggeredAlerts],
|
|
193
207
|
};
|
|
194
|
-
}, [stores]);
|
|
208
|
+
}, [savedMoveChecks, stores]);
|
|
195
209
|
|
|
196
210
|
const focusedAlertId = useSyncExternalStore(subscribePriceAlertFocus, getPriceAlertFocus, getPriceAlertFocus);
|
|
197
211
|
useEffect(() => {
|
|
@@ -224,7 +238,9 @@ function PriceAlertsPane({ focused, width, height }: PaneProps) {
|
|
|
224
238
|
}
|
|
225
239
|
if (alert.status !== "active") return alert;
|
|
226
240
|
const quote = streamedAlertQuote(resolveEntryData(liveEntries.get(buildQuoteKey(alertInstrument(alert)))));
|
|
227
|
-
|
|
241
|
+
if (!quote) return alert;
|
|
242
|
+
// A move rule reads the quote's move, measured from the close its change line names.
|
|
243
|
+
return alert.move ? { ...alert, ...moveQuoteFields(quote, quote.receivedAt) } : { ...alert, ...quoteAlertFields(quote, quote.receivedAt) };
|
|
228
244
|
}), [liveEntries, rows]);
|
|
229
245
|
|
|
230
246
|
const savePaneAlerts = useCallback((id: string, next: (current: AlertRule[]) => AlertRule[]): string | null => {
|
|
@@ -232,13 +248,14 @@ function PriceAlertsPane({ focused, width, height }: PaneProps) {
|
|
|
232
248
|
const key = found ? levelAlertStoreKey(found) : ALERTS_KEY;
|
|
233
249
|
if (stores.errors[key]) return stores.errors[key];
|
|
234
250
|
let error: string | null = null;
|
|
235
|
-
const setJson = key === METRIC_ALERTS_KEY ? setMetricsJson : key === RELATIVE_ALERTS_KEY ? setRelativeJson
|
|
251
|
+
const setJson = key === METRIC_ALERTS_KEY ? setMetricsJson : key === RELATIVE_ALERTS_KEY ? setRelativeJson
|
|
252
|
+
: key === MOVE_ALERTS_KEY ? setMovesJson : setAlertsJson;
|
|
236
253
|
setJson((currentJson: unknown) => {
|
|
237
254
|
error = readAlertsStoreError(currentJson);
|
|
238
255
|
return error ? currentJson : serializeAlerts(next(deserializeAlerts(currentJson)));
|
|
239
256
|
});
|
|
240
257
|
return error;
|
|
241
|
-
}, [alerts, setAlertsJson, setMetricsJson, setRelativeJson, stores]);
|
|
258
|
+
}, [alerts, setAlertsJson, setMetricsJson, setMovesJson, setRelativeJson, stores]);
|
|
242
259
|
|
|
243
260
|
const deleteAlert = useCallback(async (id: string) => {
|
|
244
261
|
const alert = alerts.find((a) => a.id === id);
|
|
@@ -259,6 +276,15 @@ function PriceAlertsPane({ focused, width, height }: PaneProps) {
|
|
|
259
276
|
}, [alerts, dialog, notify, rows.length, savePaneAlerts, setAlertLog]);
|
|
260
277
|
|
|
261
278
|
const rearmAlert = useCallback((id: string) => {
|
|
279
|
+
// A move rule that went off this session is armed again on this device alone, where it went off: its reading goes, the rule stays.
|
|
280
|
+
const move = alerts.find((alert) => alert.id === id && alert.move);
|
|
281
|
+
if (move) {
|
|
282
|
+
if (move.status !== "triggered") return;
|
|
283
|
+
setMoveChecks((saved: unknown) => Object.fromEntries(Object.entries(readMoveChecks(saved)).filter(([key]) => key !== id)));
|
|
284
|
+
setAlertLog((saved: unknown) => withAlertChange(saved, "rearmed", move));
|
|
285
|
+
syncAlertQuoteStream();
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
262
288
|
// Only an alert that went off is re-armed, as the store reads at the write: one still waiting is left, and not logged.
|
|
263
289
|
const rearmed: AlertRule[] = [];
|
|
264
290
|
const error = savePaneAlerts(id, (current) => current.map((a) => {
|
|
@@ -271,7 +297,7 @@ function PriceAlertsPane({ focused, width, height }: PaneProps) {
|
|
|
271
297
|
return;
|
|
272
298
|
}
|
|
273
299
|
for (const alert of rearmed) setAlertLog((saved: unknown) => withAlertChange(saved, "rearmed", alert));
|
|
274
|
-
}, [notify, savePaneAlerts, setAlertLog]);
|
|
300
|
+
}, [alerts, notify, savePaneAlerts, setAlertLog, setMoveChecks]);
|
|
275
301
|
|
|
276
302
|
const startAddAlert = useCallback(() => {
|
|
277
303
|
openPluginCommandWorkflow("set-alert");
|
|
@@ -306,10 +332,11 @@ function PriceAlertsPane({ focused, width, height }: PaneProps) {
|
|
|
306
332
|
type: "text",
|
|
307
333
|
key: "alert",
|
|
308
334
|
label: "Edit alert",
|
|
309
|
-
description: "SYMBOL above|below|crosses PRICE",
|
|
310
|
-
placeholder: "AAPL above 200",
|
|
335
|
+
description: selected.move ? "SYMBOL moves|up|down PERCENT" : "SYMBOL above|below|crosses PRICE",
|
|
336
|
+
placeholder: selected.move ? "GBPUSD=X moves 0.5%" : "AAPL above 200",
|
|
311
337
|
}}
|
|
312
|
-
currentValue={relativeAlertText(selected) ?? (selected.metric ? formatAlertDescription(selected).replace(" (TTM)", "").replace(" · on daily close", "")
|
|
338
|
+
currentValue={relativeAlertText(selected) ?? (selected.metric ? formatAlertDescription(selected).replace(" (TTM)", "").replace(" · on daily close", "")
|
|
339
|
+
: selected.move ? `${selected.symbol} ${moveRuleWords(selected)}` : `${selected.symbol} ${selected.condition} ${selected.targetPrice}`)}
|
|
313
340
|
onApply={async (value) => {
|
|
314
341
|
const parsed = parseAlertEdit(selected, value);
|
|
315
342
|
const error = savePaneAlerts(selected.id, (current) => current.map((alert) => (
|
|
@@ -404,12 +431,13 @@ function PriceAlertsPane({ focused, width, height }: PaneProps) {
|
|
|
404
431
|
};
|
|
405
432
|
case "symbol":
|
|
406
433
|
return {
|
|
407
|
-
|
|
434
|
+
// The listing as it was kept: 7203:JPX for Toyota in Tokyo, AAPL for a bare US symbol.
|
|
435
|
+
text: alertListing({ symbol: alert.symbol, exchange: alert.exchange }),
|
|
408
436
|
color: colors.textBright,
|
|
409
437
|
attributes: TextAttributes.BOLD,
|
|
410
438
|
};
|
|
411
439
|
case "metric":
|
|
412
|
-
return { text:
|
|
440
|
+
return { text: measureLabel(alert) };
|
|
413
441
|
case "current":
|
|
414
442
|
return {
|
|
415
443
|
text: formatCurrentPrice(alert, column.width),
|
|
@@ -426,7 +454,7 @@ function PriceAlertsPane({ focused, width, height }: PaneProps) {
|
|
|
426
454
|
color: colors.textDim,
|
|
427
455
|
};
|
|
428
456
|
case "condition":
|
|
429
|
-
return { text:
|
|
457
|
+
return { text: triggerLabel(alert) };
|
|
430
458
|
case "quote":
|
|
431
459
|
return {
|
|
432
460
|
text: formatQuoteChecked(alert),
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// An alert's prices as every surface writes them (ALRT, `fn ALRT`, `alerts
|
|
2
|
+
// list`, `alerts add` and the toast): at the instrument's precision, as
|
|
3
|
+
// `quote` prints it, and a London line in the pence it trades in.
|
|
4
|
+
import { currencyMinorDigits, formatMarketPrice, type MarketFormatOptions } from "../../../market-data/market/format";
|
|
5
|
+
import { canonicalExchange, parsePublicTickerKey } from "../../../utils/exchanges";
|
|
6
|
+
import { isCurrencyPairListing } from "../../../utils/fx-market-hours";
|
|
7
|
+
import { listingSuffixCandidate } from "../../../sources/listing-symbols";
|
|
8
|
+
import type { AlertRule } from "./types";
|
|
9
|
+
|
|
10
|
+
/** The fields of an alert its prices are written from. */
|
|
11
|
+
export type AlertPriceSubject = Pick<AlertRule, "symbol" | "exchange" | "lastQuoteExchange" | "lastQuoteCurrency" | "lastQuotePence">;
|
|
12
|
+
|
|
13
|
+
/** Whether an alert is on a currency pair (GBPUSD=X, EURUSD:CCY), whose rates print to the pair's precision. */
|
|
14
|
+
function isCurrencyPairAlert(alert: Pick<AlertRule, "symbol" | "exchange" | "lastQuoteExchange">): boolean {
|
|
15
|
+
return isCurrencyPairListing(alert.symbol, alert.exchange || alert.lastQuoteExchange);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Whether an alert's listing trades in pence (a London line priced in pounds, 117.35p), which its levels are written in. */
|
|
19
|
+
function isPenceAlert(alert: Pick<AlertRule, "lastQuotePence">): boolean {
|
|
20
|
+
return alert.lastQuotePence === true;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** A price's decimals, padded to its currency's minor unit (USD 2, JPY none) as `quote` pads them; a pair at its own precision. */
|
|
24
|
+
function priceOptions(alert: AlertPriceSubject, maxWidth?: number): MarketFormatOptions {
|
|
25
|
+
const currency = alert.lastQuoteCurrency;
|
|
26
|
+
if (isCurrencyPairAlert(alert)) return { assetCategory: "CURRENCY", ...currency ? { currency } : {}, ...maxWidth ? { maxWidth } : {} };
|
|
27
|
+
return {
|
|
28
|
+
...currency ? { currency } : {},
|
|
29
|
+
minimumFractionDigits: Math.min(2, currencyMinorDigits(currency)),
|
|
30
|
+
...maxWidth ? { maxWidth } : {},
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* An alert price as its instrument prints: `1.33750` on GBP/USD, `2,800` on
|
|
36
|
+
* Toyota in yen, `70.00p` on a London line in pence, `250.00` in dollars.
|
|
37
|
+
* Numbers only, with the pence sign where the unit is pence; `maxWidth` fits a
|
|
38
|
+
* table cell.
|
|
39
|
+
*/
|
|
40
|
+
export function alertPriceText(alert: AlertPriceSubject, value: number, maxWidth?: number): string {
|
|
41
|
+
if (!Number.isFinite(value)) return "-";
|
|
42
|
+
if (isPenceAlert(alert)) {
|
|
43
|
+
const pence = formatMarketPrice(value * 100, { minimumFractionDigits: 2, ...maxWidth ? { maxWidth: Math.max(1, maxWidth - 1) } : {} });
|
|
44
|
+
return `${pence}p`;
|
|
45
|
+
}
|
|
46
|
+
return formatMarketPrice(value, priceOptions(alert, maxWidth));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* The listing an alert is kept under, one key however it was typed: 7203.T,
|
|
51
|
+
* `7203 JP`, 7203:JPX and a rule saved by an older version as symbol
|
|
52
|
+
* `7203:JPX` on JPX are all `7203:JPX`; a bare symbol is its quote's venue
|
|
53
|
+
* once checked (AAPL:NASDAQ), else the symbol alone.
|
|
54
|
+
*/
|
|
55
|
+
export function alertListingKey(alert: Pick<AlertRule, "symbol" | "exchange" | "lastQuoteExchange">): string {
|
|
56
|
+
const typed = parsePublicTickerKey(alert.symbol);
|
|
57
|
+
const venue = canonicalExchange(typed.exchange || alert.exchange || alert.lastQuoteExchange || "");
|
|
58
|
+
const suffix = listingSuffixCandidate(typed.symbol);
|
|
59
|
+
const symbol = suffix && (!venue || canonicalExchange(suffix.exchange) === venue) ? suffix.symbol : typed.symbol;
|
|
60
|
+
const exchange = venue || (suffix ? canonicalExchange(suffix.exchange) : "");
|
|
61
|
+
return exchange ? `${symbol}:${exchange}` : symbol;
|
|
62
|
+
}
|
|
@@ -33,3 +33,20 @@ export function readAlertPrice(text: string): number {
|
|
|
33
33
|
if (price.kind === "invalid") throw new Error(`Alert price must be a number, got "${text.trim()}"; ${PRICE_FORMAT}.`);
|
|
34
34
|
return price.value;
|
|
35
35
|
}
|
|
36
|
+
|
|
37
|
+
/** A level in pence, as London lines trade: `70p`, `119.4p`. */
|
|
38
|
+
const PENCE_LEVEL = /^(\d[\d.,]*)\s*p$/i;
|
|
39
|
+
|
|
40
|
+
/** Whether a level is typed in pence (`70p`). */
|
|
41
|
+
export const isPenceLevel = (text: string): boolean => PENCE_LEVEL.test(text.trim());
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* An alert level as typed: a price (`readAlertPrice`), or one in pence
|
|
45
|
+
* (`70p`), kept in pounds as a London line's quote is (0.70) and marked so
|
|
46
|
+
* the line it is set on can be held to pence.
|
|
47
|
+
*/
|
|
48
|
+
export function readAlertLevel(text: string): { price: number; pence?: true } {
|
|
49
|
+
const pence = PENCE_LEVEL.exec(text.trim());
|
|
50
|
+
if (!pence) return { price: readAlertPrice(text) };
|
|
51
|
+
return { price: Number((readAlertPrice(pence[1]!) / 100).toPrecision(12)), pence: true };
|
|
52
|
+
}
|