gloomberb 0.20.2 → 0.20.3
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-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 +17 -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/index.ts +1 -0
- package/src/api-client/paths.ts +9 -1
- package/src/api-client/social-mentions.ts +47 -0
- package/src/api-client/types/econ.ts +4 -0
- package/src/app.tsx +11 -1
- package/src/cli/command-options.ts +2 -1
- package/src/cli/commands/market.ts +111 -29
- package/src/cli/commands/options-chain.ts +23 -6
- package/src/cli/commands/overview.ts +13 -5
- package/src/cli/commands/plugins.ts +49 -18
- package/src/cli/commands/search.ts +25 -6
- package/src/cli/commands/ticker.ts +4 -2
- 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 +6 -38
- 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 +23 -11
- 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 +22 -2
- package/src/cli/result.ts +7 -3
- 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/unknown-command.ts +88 -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/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 +190 -32
- 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 +53 -6
- 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/double-escape-close.ts +8 -5
- 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 +26 -8
- package/src/components/layout/pane/footer/model.ts +46 -20
- package/src/components/layout/pane/header.tsx +3 -2
- package/src/components/layout/shell/chrome.ts +15 -15
- package/src/components/layout/status-bar.tsx +8 -7
- package/src/components/layout/status-widget-space.ts +8 -0
- 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 +15 -6
- package/src/components/onboarding/onboarding-wizard.tsx +61 -11
- 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 +13 -2
- package/src/components/ui/column-grid.tsx +18 -9
- package/src/components/ui/data-table/index.tsx +1 -1
- 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/menu.tsx +3 -1
- package/src/components/ui/message-composer.tsx +2 -2
- 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/store/normalize.ts +6 -0
- package/src/docs/snapshot.json +120 -69
- package/src/i18n/es.ts +24 -1
- package/src/i18n/ja.ts +24 -1
- package/src/i18n/ko.ts +24 -1
- package/src/i18n/zh-cn.ts +24 -1
- package/src/i18n/zh-tw.ts +24 -1
- package/src/layout/pane-manager/gridlock.ts +11 -0
- 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 +80 -0
- package/src/market-data/futures-contract.ts +9 -3
- 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/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 +224 -33
- 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 +40 -15
- package/src/plugins/builtin/alerts/headless.ts +31 -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 +155 -0
- package/src/plugins/builtin/alerts/move.ts +160 -0
- package/src/plugins/builtin/alerts/pane.tsx +52 -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 +20 -7
- package/src/plugins/builtin/alerts/types.ts +13 -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/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/cloud/upgrade-status-widget.tsx +9 -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/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/table.tsx +1 -1
- 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/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/news/index.tsx +7 -13
- 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 +2 -2
- 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/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/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/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/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 +13 -1
- 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 +41 -6
- 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 +8 -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/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/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 +33 -13
- package/src/renderers/electrobun/bun/desktop/app-name.ts +1 -1
- package/src/renderers/opentui/host.tsx +2 -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/normalizers.ts +29 -3
- package/src/sources/provider-router/cached-routes.ts +19 -7
- package/src/state/pane-table-export-registry.ts +19 -6
- package/src/test-support/preload.ts +5 -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/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 +8 -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/ui/host.tsx +8 -0
- 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,155 @@
|
|
|
1
|
+
// What this device read of each move rule, kept apart from the rules. The
|
|
2
|
+
// synced `moveAlerts` list holds the rules alone, so it changes only when a
|
|
3
|
+
// rule does; every check, every session a rule went off in and every re-arm
|
|
4
|
+
// for the next session stay in plugin resume state, as IV levels' readings do.
|
|
5
|
+
import type { QuoteChangeBasis } from "../../../market-data/market/change-basis";
|
|
6
|
+
import type { QuoteDataSource } from "../../../types/financials";
|
|
7
|
+
import type { AlertRule } from "./types";
|
|
8
|
+
|
|
9
|
+
/** The device's last reading of each move rule, by rule id, in plugin resume state: never synced. */
|
|
10
|
+
export const MOVE_CHECKS_KEY = "moveChecks";
|
|
11
|
+
|
|
12
|
+
/** One device's last reading of a move rule, and the session it last went off in. */
|
|
13
|
+
export interface MoveCheck {
|
|
14
|
+
/** The arming the reading is of (the rule's `armedAt`, else `createdAt`): an edit starts afresh. */
|
|
15
|
+
armedAt: number;
|
|
16
|
+
checkedAt: number;
|
|
17
|
+
/** The move read, in percent. */
|
|
18
|
+
percent?: number;
|
|
19
|
+
basis?: QuoteChangeBasis;
|
|
20
|
+
quoteAt?: number;
|
|
21
|
+
source?: QuoteDataSource;
|
|
22
|
+
currency?: string;
|
|
23
|
+
exchange?: string;
|
|
24
|
+
pence?: true;
|
|
25
|
+
/** Why the last check had no quote. */
|
|
26
|
+
error?: string;
|
|
27
|
+
/** It went off, and waits for a later session to arm it again. */
|
|
28
|
+
fired?: true;
|
|
29
|
+
firedAt?: number;
|
|
30
|
+
/** The session (a date) it last went off in. */
|
|
31
|
+
session?: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const isText = (value: unknown): value is string => typeof value === "string" && value.length > 0 && value.length <= 300;
|
|
35
|
+
const isNumber = (value: unknown): value is number => typeof value === "number" && Number.isFinite(value);
|
|
36
|
+
const BASIS_KINDS = new Set(["close", "settle", "previous close", "utc day", "24h"]);
|
|
37
|
+
const SOURCES = new Set<QuoteDataSource>(["live", "delayed", "snapshot"]);
|
|
38
|
+
|
|
39
|
+
function readBasis(value: unknown): QuoteChangeBasis | undefined {
|
|
40
|
+
if (!value || typeof value !== "object") return undefined;
|
|
41
|
+
const basis = value as Record<string, unknown>;
|
|
42
|
+
if (!BASIS_KINDS.has(String(basis.kind))) return undefined;
|
|
43
|
+
if ((basis.kind === "close" || basis.kind === "settle") && !isText(basis.date)) return undefined;
|
|
44
|
+
return value as QuoteChangeBasis;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** The saved readings that read; anything else is dropped, and the next check writes it again. */
|
|
48
|
+
export function readMoveChecks(value: unknown): Record<string, MoveCheck> {
|
|
49
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return {};
|
|
50
|
+
const checks: Record<string, MoveCheck> = {};
|
|
51
|
+
for (const [id, raw] of Object.entries(value as Record<string, unknown>)) {
|
|
52
|
+
if (!raw || typeof raw !== "object") continue;
|
|
53
|
+
const check = raw as Record<string, unknown>;
|
|
54
|
+
if (!isNumber(check.armedAt) || !isNumber(check.checkedAt)) continue;
|
|
55
|
+
const basis = readBasis(check.basis);
|
|
56
|
+
checks[id] = {
|
|
57
|
+
armedAt: check.armedAt,
|
|
58
|
+
checkedAt: check.checkedAt,
|
|
59
|
+
...isNumber(check.percent) ? { percent: check.percent } : {},
|
|
60
|
+
...basis ? { basis } : {},
|
|
61
|
+
...isNumber(check.quoteAt) ? { quoteAt: check.quoteAt } : {},
|
|
62
|
+
...SOURCES.has(check.source as QuoteDataSource) ? { source: check.source as QuoteDataSource } : {},
|
|
63
|
+
...isText(check.currency) ? { currency: check.currency } : {},
|
|
64
|
+
...isText(check.exchange) ? { exchange: check.exchange } : {},
|
|
65
|
+
...check.pence === true ? { pence: true as const } : {},
|
|
66
|
+
...isText(check.error) ? { error: check.error } : {},
|
|
67
|
+
...check.fired === true ? { fired: true as const } : {},
|
|
68
|
+
...isNumber(check.firedAt) ? { firedAt: check.firedAt } : {},
|
|
69
|
+
...isText(check.session) ? { session: check.session } : {},
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
return checks;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const armingOf = (alert: Pick<AlertRule, "armedAt" | "createdAt">) => alert.armedAt ?? alert.createdAt;
|
|
76
|
+
|
|
77
|
+
/** A judged move rule's reading, as this device keeps it; null before its first check. */
|
|
78
|
+
function moveCheckOf(alert: AlertRule): MoveCheck | null {
|
|
79
|
+
if (!alert.move || alert.lastCheckedAt == null) return null;
|
|
80
|
+
return {
|
|
81
|
+
armedAt: armingOf(alert),
|
|
82
|
+
checkedAt: alert.lastCheckedAt,
|
|
83
|
+
...alert.lastCheckedPrice != null && Number.isFinite(alert.lastCheckedPrice) ? { percent: alert.lastCheckedPrice } : {},
|
|
84
|
+
...alert.lastMoveBasis ? { basis: alert.lastMoveBasis } : {},
|
|
85
|
+
...alert.lastQuoteUpdatedAt != null && Number.isFinite(alert.lastQuoteUpdatedAt) ? { quoteAt: alert.lastQuoteUpdatedAt } : {},
|
|
86
|
+
...alert.lastQuoteSource ? { source: alert.lastQuoteSource } : {},
|
|
87
|
+
...alert.lastQuoteCurrency ? { currency: alert.lastQuoteCurrency } : {},
|
|
88
|
+
...alert.lastQuoteExchange ? { exchange: alert.lastQuoteExchange } : {},
|
|
89
|
+
...alert.lastQuotePence ? { pence: true as const } : {},
|
|
90
|
+
...alert.lastCheckError ? { error: alert.lastCheckError } : {},
|
|
91
|
+
...alert.status === "triggered" ? { fired: true as const, ...alert.triggeredAt ? { firedAt: alert.triggeredAt } : {} } : {},
|
|
92
|
+
...alert.moveSession ? { session: alert.moveSession } : {},
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* A move rule as this device reads it: the rule with its last reading, and
|
|
98
|
+
* triggered while it waits for the next session. A reading of an earlier
|
|
99
|
+
* arming (before an edit or a re-arm) is not its own. Any other rule, and a
|
|
100
|
+
* move rule never read here, is returned as the rule.
|
|
101
|
+
*/
|
|
102
|
+
function withMoveCheck(alert: AlertRule, check: MoveCheck | undefined): AlertRule {
|
|
103
|
+
if (!alert.move) return alert;
|
|
104
|
+
const rule = moveRuleOnly(alert);
|
|
105
|
+
if (!check || check.armedAt !== armingOf(alert)) return rule;
|
|
106
|
+
return {
|
|
107
|
+
...rule,
|
|
108
|
+
lastCheckedAt: check.checkedAt,
|
|
109
|
+
...check.percent != null ? { lastCheckedPrice: check.percent } : {},
|
|
110
|
+
...check.basis ? { lastMoveBasis: check.basis } : {},
|
|
111
|
+
...check.quoteAt != null ? { lastQuoteUpdatedAt: check.quoteAt } : {},
|
|
112
|
+
...check.source ? { lastQuoteSource: check.source } : {},
|
|
113
|
+
...check.currency ? { lastQuoteCurrency: check.currency } : {},
|
|
114
|
+
...check.exchange ? { lastQuoteExchange: check.exchange } : {},
|
|
115
|
+
...check.pence ? { lastQuotePence: true } : {},
|
|
116
|
+
...check.error ? { lastCheckError: check.error } : {},
|
|
117
|
+
...check.fired ? { status: "triggered" as const, ...check.firedAt ? { triggeredAt: check.firedAt } : {} } : {},
|
|
118
|
+
...check.session ? { moveSession: check.session } : {},
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** The rules with this device's readings of the move rules among them (`withMoveCheck`). */
|
|
123
|
+
export function withMoveChecks(alerts: AlertRule[], checks: Record<string, MoveCheck>): AlertRule[] {
|
|
124
|
+
return alerts.map((alert) => alert.move ? withMoveCheck(alert, checks[alert.id]) : alert);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** The readings to keep for the rules: each move rule's, as judged; a deleted rule's goes. */
|
|
128
|
+
export function moveChecksOf(alerts: readonly AlertRule[]): Record<string, MoveCheck> {
|
|
129
|
+
const checks: Record<string, MoveCheck> = {};
|
|
130
|
+
for (const alert of alerts) {
|
|
131
|
+
const check = moveCheckOf(alert);
|
|
132
|
+
if (check) checks[alert.id] = check;
|
|
133
|
+
}
|
|
134
|
+
return checks;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* A move rule as the synced list keeps it: the rule alone, never a reading,
|
|
139
|
+
* so no check writes the list another device pulls. Always active there:
|
|
140
|
+
* whether it went off this session is this device's to say.
|
|
141
|
+
*/
|
|
142
|
+
export function moveRuleOnly(alert: AlertRule): AlertRule {
|
|
143
|
+
return {
|
|
144
|
+
id: alert.id,
|
|
145
|
+
symbol: alert.symbol,
|
|
146
|
+
...alert.exchange ? { exchange: alert.exchange } : {},
|
|
147
|
+
condition: alert.condition,
|
|
148
|
+
targetPrice: alert.targetPrice,
|
|
149
|
+
createdAt: alert.createdAt,
|
|
150
|
+
...alert.armedAt != null ? { armedAt: alert.armedAt } : {},
|
|
151
|
+
status: "active",
|
|
152
|
+
...alert.message ? { message: alert.message } : {},
|
|
153
|
+
move: true,
|
|
154
|
+
};
|
|
155
|
+
}
|
|
@@ -0,0 +1,160 @@
|
|
|
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 type { Quote } from "../../../types/financials";
|
|
8
|
+
import type { AlertCondition, AlertRule } from "./types";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Move rules keep a synced list of their own: an app or a Gloom Cloud that
|
|
12
|
+
* reads `alerts` would judge `up 3` as a price above 3. Only the running app
|
|
13
|
+
* checks them.
|
|
14
|
+
*/
|
|
15
|
+
export const MOVE_ALERTS_KEY = "moveAlerts";
|
|
16
|
+
|
|
17
|
+
/** The words a move is typed with, and the condition each keeps: either way, up, or down. */
|
|
18
|
+
const MOVE_WORDS: Readonly<Record<string, AlertCondition>> = {
|
|
19
|
+
moves: "crosses", move: "crosses", up: "above", rises: "above", down: "below", falls: "below",
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/** The condition a move word names (`moves`, `up`, `down`), or null for any other word. */
|
|
23
|
+
export function moveCondition(word: string | undefined): AlertCondition | null {
|
|
24
|
+
return word ? MOVE_WORDS[word.toLowerCase()] ?? null : null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Who hears of a move: only the running app checks moves, so no email or
|
|
29
|
+
* phone alert comes of one, signed in or not. Said where a move alert is
|
|
30
|
+
* made and listed, so nobody waits for an email.
|
|
31
|
+
*/
|
|
32
|
+
export const MOVE_APP_ONLY = "Move alerts notify only while the app is running, even when signed in with Cloud sync: no email or phone alert.";
|
|
33
|
+
|
|
34
|
+
/** The largest move a rule takes, in percent: a fall cannot pass 100%. */
|
|
35
|
+
const MAX_MOVE_PERCENT = 100;
|
|
36
|
+
|
|
37
|
+
/** `0.5%`, `3`, `+3%`: a move in percent, unsigned; null when it is no positive number up to 100. */
|
|
38
|
+
export function parseMovePercent(text: string | undefined): number | null {
|
|
39
|
+
const match = /^\+?(\d+(?:\.\d+)?|\.\d+)\s*%?$/.exec(text?.trim() ?? "");
|
|
40
|
+
const value = match ? Number(match[1]) : Number.NaN;
|
|
41
|
+
return Number.isFinite(value) && value > 0 && value <= MAX_MOVE_PERCENT ? value : null;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const percentText = (value: number) => `${Number(value.toFixed(2)).toFixed(2)}%`;
|
|
45
|
+
|
|
46
|
+
/** `±0.50%`, `+3.00%`, `-3.00%`: a move rule's target, signed by its direction. */
|
|
47
|
+
export function moveTargetText(alert: Pick<AlertRule, "condition" | "targetPrice">): string {
|
|
48
|
+
const sign = alert.condition === "crosses" ? "±" : alert.condition === "above" ? "+" : "-";
|
|
49
|
+
return `${sign}${percentText(alert.targetPrice)}`;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** `-0.38%`, `+1.20%`: a move as read, signed; `0.00%` unsigned. */
|
|
53
|
+
export function movePercentText(value: number): string {
|
|
54
|
+
const text = percentText(Math.abs(value));
|
|
55
|
+
return /[1-9]/.test(text) ? `${value > 0 ? "+" : "-"}${text}` : text;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** `moves 0.50%`, `up 3.00%`, `down 3.00%`: the rule in the words `alerts add` takes. */
|
|
59
|
+
export function moveRuleWords(alert: Pick<AlertRule, "condition" | "targetPrice">): string {
|
|
60
|
+
const word = alert.condition === "crosses" ? "moves" : alert.condition === "above" ? "up" : "down";
|
|
61
|
+
return `${word} ${percentText(alert.targetPrice)}`;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** The Trigger column's word: Moves, Up or Down. */
|
|
65
|
+
export function moveTriggerLabel(condition: AlertCondition): string {
|
|
66
|
+
return condition === "crosses" ? "Moves" : condition === "above" ? "Up" : "Down";
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** What a move is measured from, as the quote's change line names it: `vs Thu 5 Nov close`, `vs prev close`. */
|
|
70
|
+
export function moveBasisText(basis: QuoteChangeBasis | null | undefined, now = Date.now()): string {
|
|
71
|
+
return basis ? changeBasisLabel(basis, now) : "vs prev close";
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** A move as a quote reports it: the percent, what it is measured from, and the session it belongs to. */
|
|
75
|
+
export interface MoveReading {
|
|
76
|
+
percent: number;
|
|
77
|
+
basis: QuoteChangeBasis;
|
|
78
|
+
/**
|
|
79
|
+
* The session the move is of, as a date: the close it is measured from (the
|
|
80
|
+
* 2026-11-05 close) for a listing or a pair, the UTC day for a coin. Null
|
|
81
|
+
* when nothing dates it, as for a pair's print after the week's close: such
|
|
82
|
+
* a reading can set off an armed rule, never arm one again.
|
|
83
|
+
*/
|
|
84
|
+
session: string | null;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const utcDay = (time: number) => new Date(time).toISOString().slice(0, 10);
|
|
88
|
+
const ISO_DAY = /^\d{4}-\d{2}-\d{2}$/;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* The move a quote reports for a rule to judge: its change percent (the
|
|
92
|
+
* latest print's, extended hours included, as the alert's price is) and the
|
|
93
|
+
* close it is measured from. A coin's move from 00:00 UTC is that day's, one
|
|
94
|
+
* over 24 hours the UTC day's. Null for a quote with no move.
|
|
95
|
+
*/
|
|
96
|
+
export function readMove(quote: Quote, now = Date.now()): MoveReading | null {
|
|
97
|
+
const percent = getActiveQuoteDisplay(quote)?.changePercent ?? quote.changePercent;
|
|
98
|
+
if (!Number.isFinite(percent)) return null;
|
|
99
|
+
const basis = quoteChangeBasis(quote, { session: "active" });
|
|
100
|
+
if (!basis) return null;
|
|
101
|
+
const session = "date" in basis ? basis.date : basis.kind === "utc day" || basis.kind === "24h" ? utcDay(now) : null;
|
|
102
|
+
return { percent, basis, session };
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** A reading this recent dates an undated one after it: the same session, read by a stream and a poll that disagree. */
|
|
106
|
+
const DATED_READING_MS = 12 * 60 * 60_000;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* The session a rule that goes off on `reading` went off in: the reading's
|
|
110
|
+
* own, or for an undated one the session of the dated reading just before
|
|
111
|
+
* it, else the UTC day, so it is never armed again in the session it went
|
|
112
|
+
* off in (at worst it waits a session longer).
|
|
113
|
+
*/
|
|
114
|
+
function firedSession(alert: AlertRule, reading: MoveReading, now: number): string {
|
|
115
|
+
if (reading.session) return reading.session;
|
|
116
|
+
const before = alert.lastMoveBasis && "date" in alert.lastMoveBasis ? alert.lastMoveBasis.date : null;
|
|
117
|
+
const recent = alert.lastCheckedAt != null && now - alert.lastCheckedAt <= DATED_READING_MS;
|
|
118
|
+
return before && recent ? before : utcDay(now);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** The session a rule went off in, as a date: its own, or the UTC day it went off for one that names none. */
|
|
122
|
+
function lastFiredSession(alert: AlertRule): string | null {
|
|
123
|
+
if (alert.moveSession && ISO_DAY.test(alert.moveSession)) return alert.moveSession;
|
|
124
|
+
return alert.triggeredAt ? utcDay(alert.triggeredAt) : null;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** Whether a move reaches a rule: either way by its size, or up or down by it. */
|
|
128
|
+
export function moveReached(alert: Pick<AlertRule, "condition" | "targetPrice">, percent: number): boolean {
|
|
129
|
+
// To the hundredth of a percent the quote prints, so a 0.4999% move is not 0.50%.
|
|
130
|
+
const move = Math.round(percent * 100) / 100;
|
|
131
|
+
if (alert.condition === "above") return move >= alert.targetPrice;
|
|
132
|
+
if (alert.condition === "below") return move <= -alert.targetPrice;
|
|
133
|
+
return Math.abs(move) >= alert.targetPrice;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* A move rule judged on a quote. One that went off is armed again only by a
|
|
138
|
+
* dated session later than the one it went off in: a print after the close,
|
|
139
|
+
* a weekend quote, or a stream and a poll that date the move a day apart
|
|
140
|
+
* never arm it twice. Then it goes off when the move reaches it, once for the
|
|
141
|
+
* session. Returns the rule with its reading, and whether it went off now.
|
|
142
|
+
*/
|
|
143
|
+
export function judgeMove(alert: AlertRule, quote: Quote, now = Date.now()): { alert: AlertRule; fired: boolean; reading: MoveReading | null } {
|
|
144
|
+
const reading = readMove(quote, now);
|
|
145
|
+
if (!reading) return { alert, fired: false, reading };
|
|
146
|
+
let next: AlertRule = { ...alert, lastCheckedPrice: reading.percent, lastMoveBasis: reading.basis };
|
|
147
|
+
const last = lastFiredSession(alert);
|
|
148
|
+
// Armed again for a new session: `triggeredAt` is cleared rather than left out, so it clears on a rule merged into.
|
|
149
|
+
if (next.status === "triggered" && reading.session && (!last || reading.session > last)) next = { ...next, status: "active", triggeredAt: undefined };
|
|
150
|
+
// A session it already went off in, as a dated reading says, never sets it off again.
|
|
151
|
+
const wentOff = !!reading.session && !!last && reading.session <= last && next.moveSession != null;
|
|
152
|
+
const fired = next.status === "active" && !wentOff && moveReached(next, reading.percent);
|
|
153
|
+
if (fired) next = { ...next, status: "triggered", triggeredAt: now, moveSession: firedSession(alert, reading, now) };
|
|
154
|
+
return { alert: next, fired, reading };
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** "GBPUSD=X moved -0.52% vs Thu 5 Nov close, at 1.33702": the notification of a move rule that went off. */
|
|
158
|
+
export function moveFiredText(listing: string, reading: MoveReading, price: string, now = Date.now()): string {
|
|
159
|
+
return `${listing} moved ${movePercentText(reading.percent)} ${moveBasisText(reading.basis, now)}, at ${price}`;
|
|
160
|
+
}
|
|
@@ -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,17 @@ 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}
|
|
119
|
+
{/* Only the running app checks a move: no email or phone alert comes of it, signed in or not. */}
|
|
120
|
+
{alert.move ? <KeyValueRow {...DETAIL_ROW} label="Notifies" value="Only while the app is running; no email or phone alert, even with Cloud sync" /> : null}
|
|
112
121
|
{/* The two readings that place the quadrant, as RRG states them. */}
|
|
113
122
|
{!reason && alert.metric?.kind === "rrg" && alert.lastCheckedPrice != null && alert.lastCheckedTarget != null ? <>
|
|
114
123
|
<KeyValueRow {...DETAIL_ROW} label="Strength" value={alert.lastCheckedPrice.toFixed(2)} />
|
|
115
124
|
<KeyValueRow {...DETAIL_ROW} label="Momentum" value={alert.lastCheckedTarget.toFixed(2)} />
|
|
116
125
|
</> : null}
|
|
117
|
-
{reason ? null : <KeyValueRow {...DETAIL_ROW} label="Away" value={formatAlertDistance(alert)} />}
|
|
126
|
+
{reason || alert.move ? null : <KeyValueRow {...DETAIL_ROW} label="Away" value={formatAlertDistance(alert)} />}
|
|
118
127
|
{reason
|
|
119
128
|
? alert.lastCheckedAt ? <KeyValueRow {...DETAIL_ROW} label="Checked" value={relativeTime(alert.lastCheckedAt)} tone="muted" /> : null
|
|
120
129
|
: <KeyValueRow {...DETAIL_ROW} label="Quote" value={formatQuoteChecked(alert)} tone="muted" />}
|
|
@@ -159,13 +168,19 @@ export function AlertsPane(props: PaneProps) {
|
|
|
159
168
|
);
|
|
160
169
|
}
|
|
161
170
|
|
|
171
|
+
/** No readings yet, one object for every render: a fresh `{}` each time would read as a change. */
|
|
172
|
+
const NO_MOVE_CHECKS = {};
|
|
173
|
+
|
|
162
174
|
function PriceAlertsPane({ focused, width, height }: PaneProps) {
|
|
163
175
|
const [alertsJson, setAlertsJson] = usePluginConfigState<unknown>(ALERTS_KEY, "[]");
|
|
164
176
|
const [metricsJson, setMetricsJson] = usePluginConfigState<unknown>(METRIC_ALERTS_KEY, "[]");
|
|
165
177
|
const [relativeJson, setRelativeJson] = usePluginConfigState<unknown>(RELATIVE_ALERTS_KEY, "[]");
|
|
178
|
+
const [movesJson, setMovesJson] = usePluginConfigState<unknown>(MOVE_ALERTS_KEY, "[]");
|
|
166
179
|
const { openPluginCommandWorkflow, notify } = usePluginAppActions();
|
|
167
180
|
// Deleting or re-arming a rule goes in this device's alert log, beside the alerts that fired.
|
|
168
181
|
const [, setAlertLog] = usePluginState<unknown>(FIRED_LOG_KEY, []);
|
|
182
|
+
// A move rule's readings, and whether it went off this session, are this device's, beside the synced rules.
|
|
183
|
+
const [savedMoveChecks, setMoveChecks] = usePluginState<unknown>(MOVE_CHECKS_KEY, NO_MOVE_CHECKS);
|
|
169
184
|
const dialog = useDialog();
|
|
170
185
|
const [selectedIdx, setSelectedIdx] = useState(0);
|
|
171
186
|
const [detailOpen, setDetailOpen] = useState(false);
|
|
@@ -176,12 +191,13 @@ function PriceAlertsPane({ focused, width, height }: PaneProps) {
|
|
|
176
191
|
const columns = width < 106 ? ALERT_COLUMNS.filter(column => column.id !== "away" && column.id !== "triggered" && column.id !== "created")
|
|
177
192
|
: width < 118 ? ALERT_COLUMNS.filter(column => column.id !== "created") : ALERT_COLUMNS;
|
|
178
193
|
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
|
-
|
|
194
|
+
const stores = useMemo(() => readLevelAlertStores(key => key === ALERTS_KEY ? alertsJson : key === METRIC_ALERTS_KEY ? metricsJson
|
|
195
|
+
: key === MOVE_ALERTS_KEY ? movesJson : relativeJson),
|
|
196
|
+
[alertsJson, metricsJson, movesJson, relativeJson]);
|
|
181
197
|
const storeError = stores.error;
|
|
182
198
|
|
|
183
199
|
const { alerts, rows } = useMemo(() => {
|
|
184
|
-
const parsed = stores.alerts;
|
|
200
|
+
const parsed = withMoveChecks(stores.alerts, readMoveChecks(savedMoveChecks));
|
|
185
201
|
const activeAlerts = parsed.filter((a) => a.status === "active");
|
|
186
202
|
const triggeredAlerts = parsed
|
|
187
203
|
.filter((a) => a.status === "triggered")
|
|
@@ -191,7 +207,7 @@ function PriceAlertsPane({ focused, width, height }: PaneProps) {
|
|
|
191
207
|
alerts: parsed,
|
|
192
208
|
rows: [...activeAlerts, ...triggeredAlerts],
|
|
193
209
|
};
|
|
194
|
-
}, [stores]);
|
|
210
|
+
}, [savedMoveChecks, stores]);
|
|
195
211
|
|
|
196
212
|
const focusedAlertId = useSyncExternalStore(subscribePriceAlertFocus, getPriceAlertFocus, getPriceAlertFocus);
|
|
197
213
|
useEffect(() => {
|
|
@@ -224,7 +240,9 @@ function PriceAlertsPane({ focused, width, height }: PaneProps) {
|
|
|
224
240
|
}
|
|
225
241
|
if (alert.status !== "active") return alert;
|
|
226
242
|
const quote = streamedAlertQuote(resolveEntryData(liveEntries.get(buildQuoteKey(alertInstrument(alert)))));
|
|
227
|
-
|
|
243
|
+
if (!quote) return alert;
|
|
244
|
+
// A move rule reads the quote's move, measured from the close its change line names.
|
|
245
|
+
return alert.move ? { ...alert, ...moveQuoteFields(quote, quote.receivedAt) } : { ...alert, ...quoteAlertFields(quote, quote.receivedAt) };
|
|
228
246
|
}), [liveEntries, rows]);
|
|
229
247
|
|
|
230
248
|
const savePaneAlerts = useCallback((id: string, next: (current: AlertRule[]) => AlertRule[]): string | null => {
|
|
@@ -232,13 +250,14 @@ function PriceAlertsPane({ focused, width, height }: PaneProps) {
|
|
|
232
250
|
const key = found ? levelAlertStoreKey(found) : ALERTS_KEY;
|
|
233
251
|
if (stores.errors[key]) return stores.errors[key];
|
|
234
252
|
let error: string | null = null;
|
|
235
|
-
const setJson = key === METRIC_ALERTS_KEY ? setMetricsJson : key === RELATIVE_ALERTS_KEY ? setRelativeJson
|
|
253
|
+
const setJson = key === METRIC_ALERTS_KEY ? setMetricsJson : key === RELATIVE_ALERTS_KEY ? setRelativeJson
|
|
254
|
+
: key === MOVE_ALERTS_KEY ? setMovesJson : setAlertsJson;
|
|
236
255
|
setJson((currentJson: unknown) => {
|
|
237
256
|
error = readAlertsStoreError(currentJson);
|
|
238
257
|
return error ? currentJson : serializeAlerts(next(deserializeAlerts(currentJson)));
|
|
239
258
|
});
|
|
240
259
|
return error;
|
|
241
|
-
}, [alerts, setAlertsJson, setMetricsJson, setRelativeJson, stores]);
|
|
260
|
+
}, [alerts, setAlertsJson, setMetricsJson, setMovesJson, setRelativeJson, stores]);
|
|
242
261
|
|
|
243
262
|
const deleteAlert = useCallback(async (id: string) => {
|
|
244
263
|
const alert = alerts.find((a) => a.id === id);
|
|
@@ -259,6 +278,15 @@ function PriceAlertsPane({ focused, width, height }: PaneProps) {
|
|
|
259
278
|
}, [alerts, dialog, notify, rows.length, savePaneAlerts, setAlertLog]);
|
|
260
279
|
|
|
261
280
|
const rearmAlert = useCallback((id: string) => {
|
|
281
|
+
// 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.
|
|
282
|
+
const move = alerts.find((alert) => alert.id === id && alert.move);
|
|
283
|
+
if (move) {
|
|
284
|
+
if (move.status !== "triggered") return;
|
|
285
|
+
setMoveChecks((saved: unknown) => Object.fromEntries(Object.entries(readMoveChecks(saved)).filter(([key]) => key !== id)));
|
|
286
|
+
setAlertLog((saved: unknown) => withAlertChange(saved, "rearmed", move));
|
|
287
|
+
syncAlertQuoteStream();
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
262
290
|
// 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
291
|
const rearmed: AlertRule[] = [];
|
|
264
292
|
const error = savePaneAlerts(id, (current) => current.map((a) => {
|
|
@@ -271,7 +299,7 @@ function PriceAlertsPane({ focused, width, height }: PaneProps) {
|
|
|
271
299
|
return;
|
|
272
300
|
}
|
|
273
301
|
for (const alert of rearmed) setAlertLog((saved: unknown) => withAlertChange(saved, "rearmed", alert));
|
|
274
|
-
}, [notify, savePaneAlerts, setAlertLog]);
|
|
302
|
+
}, [alerts, notify, savePaneAlerts, setAlertLog, setMoveChecks]);
|
|
275
303
|
|
|
276
304
|
const startAddAlert = useCallback(() => {
|
|
277
305
|
openPluginCommandWorkflow("set-alert");
|
|
@@ -306,10 +334,11 @@ function PriceAlertsPane({ focused, width, height }: PaneProps) {
|
|
|
306
334
|
type: "text",
|
|
307
335
|
key: "alert",
|
|
308
336
|
label: "Edit alert",
|
|
309
|
-
description: "SYMBOL above|below|crosses PRICE",
|
|
310
|
-
placeholder: "AAPL above 200",
|
|
337
|
+
description: selected.move ? "SYMBOL moves|up|down PERCENT" : "SYMBOL above|below|crosses PRICE",
|
|
338
|
+
placeholder: selected.move ? "GBPUSD=X moves 0.5%" : "AAPL above 200",
|
|
311
339
|
}}
|
|
312
|
-
currentValue={relativeAlertText(selected) ?? (selected.metric ? formatAlertDescription(selected).replace(" (TTM)", "").replace(" · on daily close", "")
|
|
340
|
+
currentValue={relativeAlertText(selected) ?? (selected.metric ? formatAlertDescription(selected).replace(" (TTM)", "").replace(" · on daily close", "")
|
|
341
|
+
: selected.move ? `${selected.symbol} ${moveRuleWords(selected)}` : `${selected.symbol} ${selected.condition} ${selected.targetPrice}`)}
|
|
313
342
|
onApply={async (value) => {
|
|
314
343
|
const parsed = parseAlertEdit(selected, value);
|
|
315
344
|
const error = savePaneAlerts(selected.id, (current) => current.map((alert) => (
|
|
@@ -404,12 +433,13 @@ function PriceAlertsPane({ focused, width, height }: PaneProps) {
|
|
|
404
433
|
};
|
|
405
434
|
case "symbol":
|
|
406
435
|
return {
|
|
407
|
-
|
|
436
|
+
// The listing as it was kept: 7203:JPX for Toyota in Tokyo, AAPL for a bare US symbol.
|
|
437
|
+
text: alertListing({ symbol: alert.symbol, exchange: alert.exchange }),
|
|
408
438
|
color: colors.textBright,
|
|
409
439
|
attributes: TextAttributes.BOLD,
|
|
410
440
|
};
|
|
411
441
|
case "metric":
|
|
412
|
-
return { text:
|
|
442
|
+
return { text: measureLabel(alert) };
|
|
413
443
|
case "current":
|
|
414
444
|
return {
|
|
415
445
|
text: formatCurrentPrice(alert, column.width),
|
|
@@ -426,7 +456,7 @@ function PriceAlertsPane({ focused, width, height }: PaneProps) {
|
|
|
426
456
|
color: colors.textDim,
|
|
427
457
|
};
|
|
428
458
|
case "condition":
|
|
429
|
-
return { text:
|
|
459
|
+
return { text: triggerLabel(alert) };
|
|
430
460
|
case "quote":
|
|
431
461
|
return {
|
|
432
462
|
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
|
+
}
|