@gloom-sh/terminal 0.20.20 → 0.20.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -1
- package/src/api-client/data.ts +1 -1
- package/src/api-client/equity-screener.ts +17 -0
- package/src/api-client/futures-curve.ts +5 -0
- package/src/api-client/market-discovery.ts +8 -0
- package/src/api-client/members.ts +2 -0
- package/src/api-client/paths.ts +3 -0
- package/src/api-client/perps.ts +20 -0
- package/src/api-client/request.ts +53 -7
- package/src/api-client/types/filings-and-calls.ts +2 -0
- package/src/app/pane-runtime/plugin-bindings.ts +6 -4
- package/src/app/pro-welcome/model.ts +15 -11
- package/src/app/pro-welcome/row.tsx +3 -3
- package/src/app/pro-welcome/use-pro-welcome.ts +2 -2
- package/src/app/runtime/startup.ts +3 -2
- package/src/app.tsx +3 -2
- package/src/capabilities/asset-data-inputs.ts +5 -0
- package/src/capabilities/factories.ts +8 -3
- package/src/capabilities/registry.ts +1 -0
- package/src/capabilities/types.ts +1 -0
- package/src/cli/commands/market.ts +68 -35
- package/src/cli/commands/options-chain.ts +2 -2
- package/src/cli/commands/overview.ts +10 -9
- package/src/cli/commands/ticker.ts +19 -4
- package/src/cli/desktop-pane-shot.ts +11 -3
- package/src/cli/export-source.ts +35 -2
- package/src/cli/glossary.ts +3 -2
- package/src/cli/helpers.ts +2 -1
- package/src/cli/history-demergers.ts +41 -10
- package/src/cli/history-rows.ts +3 -1
- package/src/cli/known-gaps.ts +21 -7
- package/src/cli/listing-arg.ts +22 -11
- package/src/cli/pane-functions/capabilities.ts +4 -9
- package/src/cli/pane-functions/catalog-snapshot.json +29 -29
- package/src/cli/pane-functions/catalog.ts +1 -18
- package/src/cli/pane-functions/data.ts +8 -4
- package/src/cli/pane-functions/financial-ratio-shot.ts +20 -5
- package/src/cli/pane-functions/freshness.ts +57 -12
- package/src/cli/pane-functions/function-help.ts +2 -2
- package/src/cli/pane-functions/headless.ts +6 -0
- package/src/cli/pane-functions/index.ts +11 -4
- package/src/cli/pane-functions/market-session.ts +25 -0
- package/src/cli/pane-functions/report-notices.ts +10 -0
- package/src/cli/pane-functions/resolver.ts +75 -3
- package/src/cli/pane-functions/screenshot-bridge.ts +1 -0
- package/src/cli/pane-functions/screenshot-data-evidence.ts +1 -0
- package/src/cli/pane-functions/screenshot-payload.ts +38 -5
- package/src/cli/pane-functions/screenshot-render.ts +20 -7
- package/src/cli/perpetual-contract.ts +14 -1
- package/src/cli/report-tables.ts +11 -2
- package/src/cli/result.ts +6 -1
- package/src/components/chart-table/layout.ts +8 -4
- package/src/components/command-bar/list/model.ts +2 -0
- package/src/components/command-bar/pane-templates/items.ts +5 -25
- package/src/components/command-bar/panel/index.tsx +7 -4
- package/src/components/command-bar/routes/root/provider-search.ts +4 -4
- package/src/components/command-bar/routes/root/results.ts +6 -2
- package/src/components/command-bar/routes/ticker-search/results.ts +19 -0
- package/src/components/command-bar/routes/ticker-search/route.ts +3 -3
- package/src/components/command-bar/routes/ticker-search/title.ts +23 -0
- package/src/components/command-bar/routing/list-state.ts +17 -5
- package/src/components/command-bar/selection-runtime.ts +3 -2
- package/src/components/command-bar/surface/index.tsx +2 -0
- package/src/components/command-bar/workflow/alert.ts +6 -4
- package/src/components/command-bar/workflow/collection-actions.ts +2 -1
- package/src/components/layout/pane/footer/index.tsx +1 -0
- package/src/components/layout/pane/footer/model.ts +20 -7
- package/src/components/layout/pane/title.ts +11 -2
- package/src/components/price-selector-dialog.tsx +8 -4
- package/src/components/ticker/badge/list.tsx +4 -3
- package/src/components/ticker/list-table-view.tsx +12 -1
- package/src/components/ui/query-bar.tsx +20 -14
- package/src/data/cached-query.ts +20 -4
- package/src/data/news-pane-snapshots.ts +2 -1
- package/src/data/plugin-cache.ts +5 -1
- package/src/data/saved-copies.ts +68 -2
- package/src/docs/snapshot.json +65 -14
- package/src/docs/topics.ts +11 -9
- package/src/i18n/es.ts +1 -0
- package/src/i18n/ja.ts +1 -0
- package/src/i18n/ko.ts +1 -0
- package/src/i18n/zh-cn.ts +1 -0
- package/src/i18n/zh-tw.ts +1 -0
- package/src/market-data/coordinator/index.ts +25 -5
- package/src/market-data/depositary-pair.ts +27 -10
- package/src/market-data/futures-roll-returns.ts +54 -7
- package/src/market-data/fx-closes.ts +14 -0
- package/src/market-data/market/futures-product-hours.ts +113 -0
- package/src/market-data/market/futures-week.ts +2 -0
- package/src/market-data/market/globex-day.ts +9 -2
- package/src/market-data/market/status.ts +32 -25
- package/src/market-data/market/venue-session.ts +18 -0
- package/src/market-data/options-alternatives.ts +49 -7
- package/src/market-data/perpetual-open-interest.ts +41 -0
- package/src/market-data/quotes/contributions.ts +4 -2
- package/src/market-data/quotes/export-identity.ts +11 -3
- package/src/market-data/quotes/freshness.ts +3 -2
- package/src/market-data/quotes/resolution.ts +9 -2
- package/src/market-data/quotes/tick-range.ts +22 -1
- package/src/market-data/quotes/time.ts +34 -4
- package/src/market-data/split-terms.ts +3 -2
- package/src/news/aggregator.ts +1 -0
- package/src/news/news-model.ts +12 -2
- package/src/news/types.ts +15 -0
- package/src/plugins/builtin/alerts/alert-engine.ts +2 -0
- package/src/plugins/builtin/alerts/cli-forms.ts +3 -2
- package/src/plugins/builtin/alerts/cli-move.ts +5 -2
- package/src/plugins/builtin/alerts/cli.ts +50 -25
- package/src/plugins/builtin/alerts/command.ts +51 -3
- package/src/plugins/builtin/alerts/event-rows.ts +1 -1
- package/src/plugins/builtin/alerts/events-pane.tsx +1 -1
- package/src/plugins/builtin/alerts/format.ts +67 -8
- package/src/plugins/builtin/alerts/headless.ts +22 -6
- package/src/plugins/builtin/alerts/index.tsx +26 -25
- package/src/plugins/builtin/alerts/move-checks.ts +1 -0
- package/src/plugins/builtin/alerts/pane.tsx +15 -6
- package/src/plugins/builtin/alerts/pro-rules.ts +9 -4
- package/src/plugins/builtin/alerts/quotes.ts +10 -5
- package/src/plugins/builtin/alerts/session.ts +28 -0
- package/src/plugins/builtin/alerts/types.ts +1 -0
- package/src/plugins/builtin/analytics/pane-model.ts +2 -1
- package/src/plugins/builtin/analytics/risk-model.ts +2 -2
- package/src/plugins/builtin/attention/headless.ts +2 -2
- package/src/plugins/builtin/attention/model.ts +7 -2
- package/src/plugins/builtin/attention/pane.tsx +2 -1
- package/src/plugins/builtin/awards/headless.ts +1 -1
- package/src/plugins/builtin/broker-trading/ticket.tsx +13 -5
- package/src/plugins/builtin/buildout/detail/company.tsx +0 -1
- package/src/plugins/builtin/buildout/detail/ui.tsx +7 -5
- package/src/plugins/builtin/buildout/model/normalizers.ts +0 -1
- package/src/plugins/builtin/buildout/model/types.ts +0 -1
- package/src/plugins/builtin/buildout/pane/index.tsx +9 -0
- package/src/plugins/builtin/buildout/pane/status.tsx +11 -0
- package/src/plugins/builtin/catalysts/headless.ts +1 -1
- package/src/plugins/builtin/chart-composer/headless.ts +14 -6
- package/src/plugins/builtin/chart-composer/pane.tsx +2 -1
- package/src/plugins/builtin/chart-composer/session-history.ts +14 -2
- package/src/plugins/builtin/chat/controller/index.ts +5 -3
- package/src/plugins/builtin/chat/controller/session-runtime.ts +18 -8
- package/src/plugins/builtin/chat/index.tsx +1 -1
- package/src/plugins/builtin/cloud/auth-actions.tsx +4 -2
- package/src/plugins/builtin/cloud/mcp-connect/dialog.tsx +4 -1
- package/src/plugins/builtin/cloud/thesis/ticker-tab.tsx +2 -1
- package/src/plugins/builtin/company-attention/headless.ts +2 -1
- package/src/plugins/builtin/company-kpis/headless.ts +1 -1
- package/src/plugins/builtin/correlation/headless.ts +3 -3
- package/src/plugins/builtin/correlation/history.ts +1 -0
- package/src/plugins/builtin/correlation/index.tsx +7 -5
- package/src/plugins/builtin/correlation/matrix/selection.ts +21 -3
- package/src/plugins/builtin/correlation/relationship/model.ts +5 -0
- package/src/plugins/builtin/correlation/relationship/pane.tsx +3 -2
- package/src/plugins/builtin/correlation/relationship/view-model.ts +3 -2
- package/src/plugins/builtin/credit-documents/headless.ts +1 -1
- package/src/plugins/builtin/dividend-yield/client.ts +81 -10
- package/src/plugins/builtin/dividend-yield/headless.ts +21 -10
- package/src/plugins/builtin/dividend-yield/model.ts +1 -1
- package/src/plugins/builtin/dividend-yield/pane.tsx +9 -5
- package/src/plugins/builtin/dividend-yield/ranking.ts +15 -5
- package/src/plugins/builtin/dividend-yield/reference-price.ts +3 -0
- package/src/plugins/builtin/dividend-yield/types.ts +12 -0
- package/src/plugins/builtin/dividend-yield/view.ts +30 -7
- package/src/plugins/builtin/doe/headless.ts +1 -1
- package/src/plugins/builtin/doe/pane.tsx +16 -7
- package/src/plugins/builtin/earnings-calls/data.ts +8 -5
- package/src/plugins/builtin/earnings-ripple/headless.ts +1 -1
- package/src/plugins/builtin/econ/calendar-model.ts +1 -1
- package/src/plugins/builtin/econ/index.tsx +26 -18
- package/src/plugins/builtin/equity-screener/client.ts +1 -1
- package/src/plugins/builtin/equity-screener/headless.ts +149 -31
- package/src/plugins/builtin/equity-screener/live.ts +23 -5
- package/src/plugins/builtin/equity-screener/model.ts +27 -12
- package/src/plugins/builtin/equity-screener/pane.tsx +5 -5
- package/src/plugins/builtin/exposure/headless.ts +1 -1
- package/src/plugins/builtin/exposure/holdings.ts +2 -2
- package/src/plugins/builtin/futures/index.tsx +29 -1
- package/src/plugins/builtin/futures/model.ts +93 -10
- package/src/plugins/builtin/futures/returns.ts +54 -1
- package/src/plugins/builtin/futures/table.tsx +14 -2
- package/src/plugins/builtin/futures/use-front-returns.ts +20 -3
- package/src/plugins/builtin/futures-curve/client.ts +1 -1
- package/src/plugins/builtin/futures-curve/headless.ts +9 -3
- package/src/plugins/builtin/futures-curve/model.ts +19 -5
- package/src/plugins/builtin/futures-curve/pane.tsx +12 -6
- package/src/plugins/builtin/gpu/headless.ts +1 -1
- package/src/plugins/builtin/gpu/model.ts +1 -1
- package/src/plugins/builtin/help/function-index.ts +16 -8
- package/src/plugins/builtin/help/functions-table.tsx +6 -4
- package/src/plugins/builtin/help/shortcut-model.ts +7 -2
- package/src/plugins/builtin/holders/headless.ts +16 -5
- package/src/plugins/builtin/holders/pane.tsx +43 -5
- package/src/plugins/builtin/insider/client.ts +118 -11
- package/src/plugins/builtin/insider/filing-stories.ts +36 -20
- package/src/plugins/builtin/insider/issuer.ts +5 -2
- package/src/plugins/builtin/iv-history/headless.ts +2 -0
- package/src/plugins/builtin/macro-day/client.ts +2 -3
- package/src/plugins/builtin/macro-day/comparison.ts +58 -0
- package/src/plugins/builtin/macro-day/headless.ts +47 -3
- package/src/plugins/builtin/macro-day/index.tsx +32 -9
- package/src/plugins/builtin/macro-day/model.ts +1 -1
- package/src/plugins/builtin/macro-day/pane.tsx +99 -12
- package/src/plugins/builtin/market-heatmap/index.tsx +2 -2
- package/src/plugins/builtin/market-movers/footer.ts +29 -3
- package/src/plugins/builtin/market-movers/headless.ts +12 -5
- package/src/plugins/builtin/market-movers/index.tsx +3 -3
- package/src/plugins/builtin/market-movers/session-body.tsx +6 -3
- package/src/plugins/builtin/market-valuation/detail.tsx +3 -3
- package/src/plugins/builtin/market-valuation/headless.ts +6 -6
- package/src/plugins/builtin/market-valuation/pane.tsx +2 -3
- package/src/plugins/builtin/market-valuation/view.ts +6 -8
- package/src/plugins/builtin/members/client.ts +9 -2
- package/src/plugins/builtin/members/headless.ts +8 -10
- package/src/plugins/builtin/members/model.ts +29 -17
- package/src/plugins/builtin/members/pane.tsx +10 -12
- package/src/plugins/builtin/money-markets/headless.ts +1 -1
- package/src/plugins/builtin/news/headless.ts +4 -0
- package/src/plugins/builtin/news/index.tsx +3 -1
- package/src/plugins/builtin/news/wire/industry-pane.tsx +2 -1
- package/src/plugins/builtin/news/wire/news/preset-pane.tsx +1 -1
- package/src/plugins/builtin/news/wire/persisted-articles.ts +8 -4
- package/src/plugins/builtin/notes/headless.ts +7 -0
- package/src/plugins/builtin/notes/index.tsx +1 -1
- package/src/plugins/builtin/notes/quick-notes-pane.tsx +18 -2
- package/src/plugins/builtin/options/view.tsx +7 -6
- package/src/plugins/builtin/options-positioning/headless.ts +4 -4
- package/src/plugins/builtin/options-positioning/pane.tsx +7 -3
- package/src/plugins/builtin/options-scenario/client.ts +20 -4
- package/src/plugins/builtin/options-scenario/headless.ts +1 -1
- package/src/plugins/builtin/pe-band/client.ts +5 -9
- package/src/plugins/builtin/pe-band/headless.ts +11 -13
- package/src/plugins/builtin/pe-band/model.ts +39 -60
- package/src/plugins/builtin/pe-band/pane.tsx +14 -15
- package/src/plugins/builtin/perps/equity-row.tsx +3 -1
- package/src/plugins/builtin/perps/freshness.ts +16 -9
- package/src/plugins/builtin/perps/headless.ts +4 -1
- package/src/plugins/builtin/perps/markets-section.tsx +16 -10
- package/src/plugins/builtin/perps/model.ts +33 -2
- package/src/plugins/builtin/perps/pane.tsx +3 -2
- package/src/plugins/builtin/perps/status-line.ts +12 -3
- package/src/plugins/builtin/perps/venue-markets.ts +38 -0
- package/src/plugins/builtin/plugin-marketplace/pane.tsx +4 -3
- package/src/plugins/builtin/portfolio-list/cell-version.ts +1 -1
- package/src/plugins/builtin/portfolio-list/cli/render.ts +46 -7
- package/src/plugins/builtin/portfolio-list/headless.ts +31 -8
- package/src/plugins/builtin/portfolio-list/settings.ts +3 -0
- package/src/plugins/builtin/portfolio-list/table.tsx +7 -1
- package/src/plugins/builtin/power/headless.ts +1 -1
- package/src/plugins/builtin/realized-vol/headless.ts +1 -1
- package/src/plugins/builtin/research/corporate-actions-pane.tsx +27 -13
- package/src/plugins/builtin/scanner/feed.ts +7 -4
- package/src/plugins/builtin/scanner/flow-pane.tsx +8 -4
- package/src/plugins/builtin/scanner/headless.ts +57 -26
- package/src/plugins/builtin/scanner/hilo-pane.tsx +6 -3
- package/src/plugins/builtin/scanner/lock-note.ts +3 -2
- package/src/plugins/builtin/scanner/us-session.ts +9 -0
- package/src/plugins/builtin/seasonality/client.ts +46 -10
- package/src/plugins/builtin/seasonality/headless.ts +29 -11
- package/src/plugins/builtin/seasonality/model.ts +101 -24
- package/src/plugins/builtin/seasonality/pane.tsx +10 -6
- package/src/plugins/builtin/sec/filing-content.ts +13 -0
- package/src/plugins/builtin/sec/index.tsx +16 -11
- package/src/plugins/builtin/sectors/client.ts +27 -5
- package/src/plugins/builtin/sectors/headless.ts +2 -1
- package/src/plugins/builtin/sectors/index.tsx +22 -10
- package/src/plugins/builtin/shared/cloud-resource.ts +3 -3
- package/src/plugins/builtin/shared/extended-print.ts +38 -0
- package/src/plugins/builtin/shared/pro-feature-wall.tsx +1 -1
- package/src/plugins/builtin/shared/report-freshness.ts +7 -3
- package/src/plugins/builtin/shared/scanner-capture.ts +16 -3
- package/src/plugins/builtin/shared/ticker-company.ts +17 -8
- package/src/plugins/builtin/shared/use-quote-board.ts +11 -4
- package/src/plugins/builtin/social-mentions/client.ts +7 -3
- package/src/plugins/builtin/social-mentions/outliers.tsx +9 -2
- package/src/plugins/builtin/thirteenf/api.ts +24 -3
- package/src/plugins/builtin/thirteenf/data.ts +21 -8
- package/src/plugins/builtin/thirteenf/headless.ts +7 -3
- package/src/plugins/builtin/thirteenf/signals-pane.tsx +10 -3
- package/src/plugins/builtin/thirteenf/signals.ts +22 -1
- package/src/plugins/builtin/ticker-detail/adr-pair/model.ts +4 -2
- package/src/plugins/builtin/ticker-detail/financials/model.ts +7 -0
- package/src/plugins/builtin/ticker-detail/financials/ratio-table.tsx +15 -6
- package/src/plugins/builtin/ticker-detail/financials/ratios.ts +5 -4
- package/src/plugins/builtin/ticker-detail/financials/tab.tsx +14 -5
- package/src/plugins/builtin/ticker-detail/headless.ts +32 -26
- package/src/plugins/builtin/ticker-detail/index.tsx +1 -1
- package/src/plugins/builtin/ticker-detail/overview/components.tsx +8 -3
- package/src/plugins/builtin/ticker-detail/overview/model.ts +28 -5
- package/src/plugins/builtin/ticker-detail/overview/pane.tsx +14 -1
- package/src/plugins/builtin/ticker-detail/overview-tab.tsx +9 -8
- package/src/plugins/builtin/ticker-detail/pane.tsx +16 -9
- package/src/plugins/builtin/ticker-detail/quote-monitor/card.tsx +41 -23
- package/src/plugins/builtin/ticker-detail/quote-monitor/rows.ts +30 -13
- package/src/plugins/builtin/ticker-detail/settings.ts +9 -2
- package/src/plugins/builtin/time-sales/headless.ts +49 -13
- package/src/plugins/builtin/time-sales/model.ts +2 -2
- package/src/plugins/builtin/time-sales/window.ts +84 -10
- package/src/plugins/builtin/vol-surface/charts.tsx +4 -2
- package/src/plugins/builtin/vol-surface/events.ts +12 -5
- package/src/plugins/builtin/vol-surface/headless.ts +1 -1
- package/src/plugins/builtin/vol-surface/pane.tsx +15 -7
- package/src/plugins/builtin/world-indices/footer.ts +1 -1
- package/src/plugins/builtin/world-venue-map/chokepoint-report.ts +3 -1
- package/src/plugins/builtin/world-venue-map/headless.ts +27 -13
- package/src/plugins/builtin/yield-curve/client.ts +3 -1
- package/src/plugins/duplicates.ts +60 -0
- package/src/plugins/loader.ts +12 -3
- package/src/plugins/marketplace/model.ts +10 -1
- package/src/portfolio/column-values.ts +52 -5
- package/src/react/async-resource.ts +8 -7
- package/src/renderers/browser/bundled-plugins.ts +2 -1
- package/src/renderers/dom/build-assets.ts +20 -0
- package/src/renderers/dom/data-table/index.tsx +36 -2
- package/src/renderers/dom/es2023-array-methods.ts +57 -0
- package/src/renderers/dom/host/surface-fit.ts +64 -13
- package/src/renderers/dom/styles.css +6 -1
- package/src/renderers/electrobun/bun/external-plugins.ts +16 -6
- package/src/renderers/electrobun/shared/protocol.ts +2 -0
- package/src/renderers/electrobun/view/cli-pane-shot-entry.tsx +31 -7
- package/src/renderers/electrobun/view/cli-pane-shot-frame.tsx +15 -8
- package/src/renderers/electrobun/view/external-plugins.ts +1 -0
- package/src/renderers/electrobun/view/remote/asset-data-client.ts +1 -0
- package/src/series/types.ts +1 -0
- package/src/sources/gloomberb-cloud/fred-attribution.ts +6 -5
- package/src/sources/gloomberb-cloud/index.ts +42 -5
- package/src/sources/gloomberb-cloud/news.ts +15 -2
- package/src/sources/gloomberb-cloud/normalizers.ts +9 -0
- package/src/sources/history-result.ts +2 -1
- package/src/sources/history-retention.ts +14 -2
- package/src/sources/listing-symbols.ts +1 -1
- package/src/sources/provider-router/cache.ts +32 -3
- package/src/sources/provider-router/cached-routes.ts +25 -0
- package/src/sources/provider-router/connection-health.ts +1 -0
- package/src/sources/provider-router/history.ts +2 -2
- package/src/sources/provider-router/index.ts +14 -0
- package/src/sources/provider-router/sec-filings-page.ts +25 -0
- package/src/sources/sec-edgar/content.ts +67 -36
- package/src/tickers/listing-fate.ts +28 -0
- package/src/tickers/search/home-listing.ts +3 -0
- package/src/tickers/search/index-root-lead.ts +40 -0
- package/src/tickers/terminal-codes.ts +7 -4
- package/src/time-series/base-series.ts +17 -8
- package/src/time-series/fundamentals/historical-valuation.ts +2 -2
- package/src/time-series/fundamentals/series.ts +15 -12
- package/src/time-series/history-acquisition.ts +2 -0
- package/src/time-series/market.ts +3 -1
- package/src/time-series/price-comparison.ts +3 -1
- package/src/time-series/resolve-context.ts +8 -0
- package/src/time-series/resolve.ts +50 -10
- package/src/time-series/types.ts +1 -0
- package/src/time-series/use-chart-resolution.ts +2 -2
- package/src/time-series/valuation-currency.ts +40 -12
- package/src/types/data-provider.ts +30 -1
- package/src/types/financials.ts +23 -0
- package/src/types/headless.ts +23 -0
- package/src/types/instrument.ts +1 -0
- package/src/utils/crypto-pair.ts +16 -0
- package/src/utils/exchange-announcements.ts +2 -1
- package/src/utils/exchange-notation.generated.ts +58 -1
- package/src/utils/exchanges.ts +43 -1
- package/src/utils/format.ts +37 -2
- package/src/utils/function-search.ts +38 -0
- package/src/utils/fuzzy-search.ts +10 -6
- package/src/utils/option-choice.ts +15 -0
- package/src/utils/price-history.ts +15 -1
- package/src/utils/reason-codes.ts +6 -3
- package/src/utils/trailing-dividend.ts +241 -28
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { fxLegForCurrency } from "../../../market-data/coordinator/fx-legs";
|
|
2
1
|
import { regularSessionValuationPrice } from "../../../market-data/quotes/regular-session-valuation";
|
|
3
|
-
import {
|
|
2
|
+
import { crossFxCloseOnOrBefore, dailyFxLeg, type FxCloses } from "../../../market-data/fx-closes";
|
|
4
3
|
import { knownWhenFiled } from "../../../time-series/fundamentals";
|
|
5
4
|
import { STALE_TRAILING_EPS_MS, trailingEpsSteps as sharedTrailingEpsSteps, type EpsStep } from "../../../time-series/filed-trailing-eps";
|
|
6
5
|
import { createValuationCurrencyContext } from "../../../time-series/valuation-currency";
|
|
@@ -39,17 +38,17 @@ export interface PeBandRow extends EpsStep {
|
|
|
39
38
|
fx: FxClose | null;
|
|
40
39
|
}
|
|
41
40
|
|
|
42
|
-
/**
|
|
41
|
+
/** Price currency per unit of the reporting currency. */
|
|
43
42
|
interface FxClose {
|
|
44
43
|
date: string;
|
|
45
44
|
rate: number;
|
|
46
45
|
}
|
|
47
46
|
|
|
48
|
-
/** EPS
|
|
47
|
+
/** EPS converted from the reporting currency at the period's daily FX close. */
|
|
49
48
|
interface EpsConversion {
|
|
50
49
|
/** The statement currency of today's EPS. */
|
|
51
50
|
currency: string;
|
|
52
|
-
/** The
|
|
51
|
+
/** The rate that converts the trailing EPS currently in force. */
|
|
53
52
|
latest: FxClose;
|
|
54
53
|
}
|
|
55
54
|
|
|
@@ -86,7 +85,7 @@ export interface PeBandModel {
|
|
|
86
85
|
undated: number;
|
|
87
86
|
/** Trailing sums in the window that are unavailable (a quarter's EPS is withheld or not reported). */
|
|
88
87
|
unavailable: number;
|
|
89
|
-
/** Set when
|
|
88
|
+
/** Set when current EPS was converted to the listing currency. */
|
|
90
89
|
conversion: EpsConversion | null;
|
|
91
90
|
/** Blocks the pane: nothing can be priced. */
|
|
92
91
|
error: string | null;
|
|
@@ -116,35 +115,22 @@ export function perShareDigits(value: number): number {
|
|
|
116
115
|
|
|
117
116
|
export const formatPerShare = (value: number) => value.toFixed(perShareDigits(value));
|
|
118
117
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
* dollar) or "EUR/USD 1.17" (dollars per euro), from USD per unit.
|
|
122
|
-
*/
|
|
123
|
-
export function fxPairQuote(currency: string, usdPerUnit: number): { pair: string; value: number } {
|
|
124
|
-
const perDollar = fxLegForCurrency(currency)?.invert ?? true;
|
|
125
|
-
return perDollar ? { pair: `USD/${currency}`, value: 1 / usdPerUnit } : { pair: `${currency}/USD`, value: usdPerUnit };
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/** The statement unit of an EPS currency when it is a whole currency other than USD with a daily pair, else null. */
|
|
129
|
-
function fxCurrency(code: string | null | undefined): string | null {
|
|
130
|
-
const unit = resolveCurrencyUnit(code);
|
|
131
|
-
return unit.divisor === 1 && unit.currency !== "USD" && fxLegForCurrency(unit.currency) ? unit.currency : null;
|
|
118
|
+
export function formatEpsFx(from: string, to: string, rate: number): string {
|
|
119
|
+
return `${resolveCurrencyUnit(from).currency}/${resolveCurrencyUnit(to).currency} ${rate.toPrecision(5)}`;
|
|
132
120
|
}
|
|
133
121
|
|
|
134
|
-
|
|
135
|
-
const
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
const rows = [...financials.annualStatements, ...financials.quarterlyStatements].filter((row) => typeof row.eps === "number");
|
|
147
|
-
return [...new Set(rows.flatMap((row) => fxCurrency(row.currency?.trim()) ?? []))];
|
|
122
|
+
export function epsFxCurrencies(financials: TickerFinancials, reports: readonly ReportDate[]): Map<string, string> {
|
|
123
|
+
const target = resolveCurrencyUnit(financials.quote?.currency).currency;
|
|
124
|
+
const starts = new Map<string, string>();
|
|
125
|
+
if (target !== "USD" && !dailyFxLeg(target)) return starts;
|
|
126
|
+
for (const step of trailingEpsSteps(financials, reports)) {
|
|
127
|
+
const source = resolveCurrencyUnit(step.currency).currency;
|
|
128
|
+
if (step.eps == null || source === target || (source !== "USD" && !dailyFxLeg(source))) continue;
|
|
129
|
+
for (const currency of [source, target]) {
|
|
130
|
+
if (currency !== "USD" && (!starts.has(currency) || step.periodEnd < starts.get(currency)!)) starts.set(currency, step.periodEnd);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return starts;
|
|
148
134
|
}
|
|
149
135
|
|
|
150
136
|
function quantile(sorted: readonly number[], q: number): number {
|
|
@@ -241,7 +227,7 @@ export function projectPeBand(
|
|
|
241
227
|
history: readonly PricePoint[],
|
|
242
228
|
options: {
|
|
243
229
|
symbol: string; lookbackYears: number; now?: number; reports?: readonly ReportDate[];
|
|
244
|
-
/** Daily FX closes by
|
|
230
|
+
/** Daily FX closes by currency, quoted in USD per unit. */
|
|
245
231
|
fx?: ReadonlyMap<string, FxCloses>;
|
|
246
232
|
/** Why a needed FX history is missing, said when it leaves today's EPS unconverted. */
|
|
247
233
|
fxError?: string | null;
|
|
@@ -265,26 +251,20 @@ export function projectPeBand(
|
|
|
265
251
|
const factor = units.priceInStatementUnits({ date: step.periodEnd, currency: step.currency ?? undefined }, 1);
|
|
266
252
|
return factor ? 1 / factor : null;
|
|
267
253
|
};
|
|
268
|
-
|
|
269
|
-
const
|
|
270
|
-
const code = isDollarPrice(currency) ? fxCurrency(step.currency) : null;
|
|
271
|
-
return code ? options.fx?.get(code) ?? null : null;
|
|
272
|
-
};
|
|
273
|
-
if (unitScale(latest) == null && !fxFor(latest)) {
|
|
274
|
-
const fxCode = isDollarPrice(currency) ? fxCurrency(latest.currency) : null;
|
|
275
|
-
return { ...empty, error: !currency || !latest.currency ? "The price or EPS currency is unknown."
|
|
276
|
-
: `EPS is reported in ${latest.currency} and the price is in ${currency}${fxCode && options.fxError ? `; ${options.fxError}` : ""}.` };
|
|
277
|
-
}
|
|
278
|
-
/** The EPS in price units on `date` (YYYY-MM-DD), with the FX close used when it was converted. */
|
|
279
|
-
const priced = (step: EpsStep | null, date: string): { eps: number; fx: FxClose | null } | null => {
|
|
254
|
+
const quoteUnit = resolveCurrencyUnit(currency);
|
|
255
|
+
const priced = (step: EpsStep | null): { eps: number; fx: FxClose | null } | null => {
|
|
280
256
|
if (step?.eps == null) return null;
|
|
281
257
|
const factor = unitScale(step);
|
|
282
258
|
if (factor != null) return { eps: step.eps * factor, fx: null };
|
|
283
|
-
const
|
|
284
|
-
const close =
|
|
285
|
-
return close ? { eps: step.eps * close.rate, fx: close } : null;
|
|
259
|
+
const source = resolveCurrencyUnit(step.currency);
|
|
260
|
+
const close = options.fx && crossFxCloseOnOrBefore(options.fx, source.currency, quoteUnit.currency, step.periodEnd);
|
|
261
|
+
return close ? { eps: step.eps / source.divisor * close.rate * quoteUnit.divisor, fx: close } : null;
|
|
286
262
|
};
|
|
287
|
-
const
|
|
263
|
+
const pricedSteps = new Map(allSteps.map((step) => [step, priced(step)]));
|
|
264
|
+
if (!pricedSteps.get(latest) && !allSteps.some((step) => pricedSteps.get(step))) {
|
|
265
|
+
return { ...empty, error: !currency || !latest.currency ? "The price or EPS currency is unknown."
|
|
266
|
+
: `EPS is reported in ${latest.currency} and the price is in ${currency}; ${options.fxError ?? `no FX close for ${latest.periodEnd}`}.` };
|
|
267
|
+
}
|
|
288
268
|
|
|
289
269
|
const now = options.now ?? Date.now();
|
|
290
270
|
const firstKnown = allSteps.find((step) => step.eps != null)!.knownAt.getTime();
|
|
@@ -294,9 +274,8 @@ export function projectPeBand(
|
|
|
294
274
|
const dailyStart = daily[0]?.date.getTime() ?? Number.POSITIVE_INFINITY;
|
|
295
275
|
/** A close as the chart reads it: with the EPS in force on its day, and the P/E they make. */
|
|
296
276
|
const reading = (point: { date: Date; close: number }): PeBandWeek => {
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
const eps = priced(stepAt(allSteps, point.date.getTime()), day(point.date))?.eps ?? null;
|
|
277
|
+
const step = stepAt(allSteps, point.date.getTime());
|
|
278
|
+
const eps = step ? pricedSteps.get(step)?.eps ?? null : null;
|
|
300
279
|
const positive = eps != null && eps > 0 ? eps : null;
|
|
301
280
|
return { date: point.date, close: point.close, eps: positive, pe: positive ? point.close / positive : null };
|
|
302
281
|
};
|
|
@@ -308,8 +287,7 @@ export function projectPeBand(
|
|
|
308
287
|
const rows = steps.filter((step) => step.eps != null).map((step): PeBandRow => {
|
|
309
288
|
const time = step.knownAt.getTime();
|
|
310
289
|
const price = (dayClose(time) ?? sorted.findLast((point) => point.date.getTime() <= time))?.close ?? null;
|
|
311
|
-
|
|
312
|
-
const converted = priced(step, day(step.knownAt));
|
|
290
|
+
const converted = pricedSteps.get(step);
|
|
313
291
|
const eps = converted?.eps ?? null;
|
|
314
292
|
const prior = allSteps.find((other) => other.eps != null && other.currency === step.currency
|
|
315
293
|
&& Math.abs(Date.parse(step.periodEnd) - Date.parse(other.periodEnd) - 365 * DAY_MS) <= 20 * DAY_MS);
|
|
@@ -325,9 +303,9 @@ export function projectPeBand(
|
|
|
325
303
|
// Today's figure reads like every week's: one whose newest quarter has no EPS keeps the last figure, dated in the
|
|
326
304
|
// table, where the headline EPS (TTM) needs that quarter's own (filed-trailing-eps) and shows Gloom Cloud's, labelled.
|
|
327
305
|
const currentStep = stepAt(allSteps, now);
|
|
328
|
-
|
|
329
|
-
const currentEps =
|
|
330
|
-
const latestFx =
|
|
306
|
+
const currentConversion = currentStep ? pricedSteps.get(currentStep) : null;
|
|
307
|
+
const currentEps = currentConversion?.eps ?? null;
|
|
308
|
+
const latestFx = currentConversion?.fx;
|
|
331
309
|
const currentPe = price != null && currentEps != null && currentEps > 0 ? price / currentEps : null;
|
|
332
310
|
const multiples = chooseMultiples(pes, currentPe);
|
|
333
311
|
const above = currentPe == null ? undefined : multiples.find((multiple) => multiple >= currentPe);
|
|
@@ -341,7 +319,7 @@ export function projectPeBand(
|
|
|
341
319
|
const points = [...byTime.values()].sort((a, b) => a.date.getTime() - b.date.getTime());
|
|
342
320
|
return {
|
|
343
321
|
...empty, weeks, points, rows, multiples,
|
|
344
|
-
conversion: latestFx ? { currency:
|
|
322
|
+
conversion: latestFx && currentStep?.currency ? { currency: currentStep.currency, latest: latestFx } : null,
|
|
345
323
|
sample: ranked.length ? { start: ranked[0]!.date, weeks: ranked.length } : null,
|
|
346
324
|
bandCeiling: highestClose > 0 ? Math.max(highestClose * 1.5, above != null && currentEps != null ? above * currentEps : 0) : null,
|
|
347
325
|
current: price == null ? null : { price, eps: currentEps, pe: currentPe, step: currentStep,
|
|
@@ -349,6 +327,7 @@ export function projectPeBand(
|
|
|
349
327
|
range: ordered.length ? { min: ordered[0]!, median: quantile(ordered, 0.5), max: ordered.at(-1)! } : null,
|
|
350
328
|
undated: steps.filter((step) => !step.dated && step.eps != null).length,
|
|
351
329
|
unavailable: steps.filter((step) => step.eps == null).length,
|
|
352
|
-
notice:
|
|
330
|
+
notice: currentStep && !currentConversion ? options.fxError ?? `No FX close for ${currentStep.periodEnd}.`
|
|
331
|
+
: pes.length ? null : "Trailing EPS was not positive in this window, so there is no P/E band.",
|
|
353
332
|
};
|
|
354
333
|
}
|
|
@@ -15,7 +15,7 @@ import { Box } from "../../../ui";
|
|
|
15
15
|
import { MISSING_VALUE, formatCurrency, formatPercentileRank } from "../../../utils/format";
|
|
16
16
|
import { useAssetData } from "../../runtime";
|
|
17
17
|
import { loadPeBandInputs } from "./client";
|
|
18
|
-
import {
|
|
18
|
+
import { formatEpsFx, formatPerShare, perShareDigits, projectPeBand, type PeBandModel, type PeBandRow } from "./model";
|
|
19
19
|
|
|
20
20
|
export const LOOKBACK_OPTIONS = [{ value: "5", label: "5Y" }, { value: "10", label: "10Y" }, { value: "0", label: "Max" }];
|
|
21
21
|
|
|
@@ -30,12 +30,12 @@ const periodLabel = (row: Pick<PeBandRow, "basis" | "periodEnd">) =>
|
|
|
30
30
|
`${row.basis === "annual" ? "FY" : "TTM"} ${MONTHS[Number(row.periodEnd.slice(5, 7)) - 1]} ${row.periodEnd.slice(0, 4)}`;
|
|
31
31
|
|
|
32
32
|
/** With EPS converted from another currency, the table keeps the reported figure and adds the FX close it was converted at. */
|
|
33
|
-
function tableColumns(
|
|
33
|
+
function tableColumns(showFx: boolean): DataTableColumn[] {
|
|
34
34
|
return [
|
|
35
35
|
{ id: "period", label: "Period", width: 13, align: "left" },
|
|
36
36
|
{ id: "known", label: "Known", width: 11, align: "left" },
|
|
37
|
-
{ id: "eps", label:
|
|
38
|
-
...(
|
|
37
|
+
{ id: "eps", label: "EPS", width: showFx ? 14 : 9, align: "right" },
|
|
38
|
+
...(showFx ? [{ id: "fx", label: "Period-end FX", width: 17, align: "right" as const }] : []),
|
|
39
39
|
{ id: "yoy", label: "YoY", width: 8, align: "right", omitWhenEmpty: true },
|
|
40
40
|
{ id: "price", label: "Price", width: 10, align: "right" },
|
|
41
41
|
{ id: "pe", label: "P/E", width: 7, align: "right" },
|
|
@@ -44,19 +44,18 @@ function tableColumns(conversion: PeBandModel["conversion"]): DataTableColumn[]
|
|
|
44
44
|
|
|
45
45
|
const rowKey = (row: PeBandRow) => `${row.basis}:${row.periodEnd}`;
|
|
46
46
|
|
|
47
|
-
function renderCell(row: PeBandRow, column: DataTableColumn, colors: ReturnType<typeof useThemeColors
|
|
47
|
+
function renderCell(row: PeBandRow, column: DataTableColumn, colors: ReturnType<typeof useThemeColors>, fxTarget?: string): DataTableCell {
|
|
48
48
|
switch (column.id) {
|
|
49
49
|
case "period": return { text: periodLabel(row) };
|
|
50
50
|
// A figure with no publication date on record steps at its period end.
|
|
51
51
|
case "known": return row.dated ? { text: row.knownAt.toISOString().slice(0, 10), value: row.knownAt.toISOString().slice(0, 10) }
|
|
52
52
|
: { text: "period end", color: colors.textMuted };
|
|
53
|
-
case "eps": return { text: row.eps == null ? MISSING_VALUE : formatPerShare(row.eps)
|
|
53
|
+
case "eps": return { text: row.eps == null ? MISSING_VALUE : `${formatPerShare(row.eps)}${fxTarget && row.currency ? ` ${row.currency}` : ""}`, value: row.eps,
|
|
54
54
|
color: row.eps != null && row.eps <= 0 ? colors.negative : undefined };
|
|
55
55
|
case "yoy": return { text: pct(row.yoy), value: row.yoy == null ? null : row.yoy * 100,
|
|
56
56
|
color: row.yoy == null || Math.abs(row.yoy) < 0.0005 ? undefined : row.yoy > 0 ? colors.positive : colors.negative };
|
|
57
57
|
case "fx": {
|
|
58
|
-
|
|
59
|
-
return { text: quote == null ? MISSING_VALUE : quote.toPrecision(5), value: quote };
|
|
58
|
+
return { text: row.fx && row.currency && fxTarget ? formatEpsFx(row.currency, fxTarget, row.fx.rate) : MISSING_VALUE, value: row.fx?.rate };
|
|
60
59
|
}
|
|
61
60
|
case "price": return { text: row.price == null ? MISSING_VALUE : formatPerShare(row.price), value: row.price };
|
|
62
61
|
default: return { text: multiple(row.pe), value: row.pe };
|
|
@@ -111,7 +110,8 @@ export function PeBandPane({ width, height, focused }: PaneProps) {
|
|
|
111
110
|
: null, [inputs.data, lookbackYears, symbol]);
|
|
112
111
|
const rows = model?.rows ?? [];
|
|
113
112
|
const conversion = model?.conversion ?? null;
|
|
114
|
-
const
|
|
113
|
+
const showFx = !!conversion || rows.some((row) => row.fx);
|
|
114
|
+
const columns = useMemo(() => tableColumns(showFx), [showFx]);
|
|
115
115
|
const series = useMemo(() => model && !model.error ? chartSeries(model, colors) : [], [model, colors]);
|
|
116
116
|
const currency = model?.currency ?? undefined;
|
|
117
117
|
const firstWeek = model?.weeks[0]?.date;
|
|
@@ -144,9 +144,8 @@ export function PeBandPane({ width, height, focused }: PaneProps) {
|
|
|
144
144
|
const { current, range } = model;
|
|
145
145
|
const step = current.step;
|
|
146
146
|
// Converted EPS says what it was converted from, and at which close.
|
|
147
|
-
const
|
|
148
|
-
|
|
149
|
-
? `, from ${conversion.currency} ${formatPerShare(step.eps)} at ${pair.pair} ${pair.value.toPrecision(5)}` : "";
|
|
147
|
+
const converted = step?.eps != null && conversion && currency && step.currency === conversion.currency
|
|
148
|
+
? ` · from ${conversion.currency} ${formatPerShare(step.eps)} at ${formatEpsFx(conversion.currency, currency, conversion.latest.rate)}` : "";
|
|
150
149
|
return [
|
|
151
150
|
{ id: "pe", label: "P/E", value: multiple(current.pe),
|
|
152
151
|
detail: current.pe != null ? formatPercentileRank(current.percentile, windowLabel) : current.eps != null ? "EPS not positive" : "EPS unavailable" },
|
|
@@ -169,10 +168,10 @@ export function PeBandPane({ width, height, focused }: PaneProps) {
|
|
|
169
168
|
selection={{ kind: "id", selectedId: selected, getId: rowKey, onChange: (id) => setSelectedId(id) }}
|
|
170
169
|
selectedTextOverridesCellColor
|
|
171
170
|
getExportMetadata={() => [["symbol", model.symbol], ["currency", model.currency ?? ""],
|
|
172
|
-
["units",
|
|
173
|
-
? `EPS as reported
|
|
171
|
+
["units", showFx
|
|
172
|
+
? `EPS as reported; period-end FX to ${model.currency ?? ""}; P/E at the close of the day the EPS became known`
|
|
174
173
|
: "EPS and price in the listing currency; P/E at the close of the day the EPS became known"]]}
|
|
175
|
-
renderCell={(row, column) => renderCell(row, column, colors)}
|
|
174
|
+
renderCell={(row, column) => renderCell(row, column, colors, showFx ? currency : undefined)}
|
|
176
175
|
rootBefore={<ChartTableHeader width={width} height={height} tableRows={rows.length} tableColumns={columns} query={query} figures={figures}
|
|
177
176
|
chart={model.weeks.length >= 2 ? { series, formatValue: formatPrice, formatAxisValue: formatAxis, remoteKind: "pe-band", ...link } : null} />} />
|
|
178
177
|
: null}
|
|
@@ -9,6 +9,7 @@ import { useResearchCloudSession } from "../shared/research-cloud-session";
|
|
|
9
9
|
import { perpEquityIdentity } from "./equity-identity";
|
|
10
10
|
import { perpetualListing } from "../../../tickers/perpetual-listing";
|
|
11
11
|
import { loadPerpSelection, loadPerpsEquity } from "./client";
|
|
12
|
+
import { rowReadAt } from "../../../market-data/perpetual-open-interest";
|
|
12
13
|
import { compact, percent, perpDescription, price, readingTime } from "./model";
|
|
13
14
|
import { useLivePerpRows } from "./live-rows";
|
|
14
15
|
import { openPerpLabel, useOpenPerpMarket } from "./open-market";
|
|
@@ -62,7 +63,8 @@ function PerpRow({ row, stale, width, own = false }: { row: PerpBoardRow; stale:
|
|
|
62
63
|
const openMarket = useOpenPerpMarket();
|
|
63
64
|
const open = () => openMarket(row.marketId);
|
|
64
65
|
usePaneLinkMenuEntry(`function:perps-pane:${row.marketId}`, openPerpLabel(row), open);
|
|
65
|
-
|
|
66
|
+
// Dated by its oldest figure: a streamed mark can sit beside the open interest the last poll read.
|
|
67
|
+
const read = readingTime(rowReadAt(row));
|
|
66
68
|
const staleText = row.stale || stale ? " · stale" : "";
|
|
67
69
|
const figures = own
|
|
68
70
|
? row.underlyingPremium != null ? [`${percent(row.underlyingPremium, 2)} vs ${row.underlyingSymbol ?? "underlying"} last${staleText}`] : staleText ? ["stale"] : []
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { PerpBoardRow } from "../../../api-client/perps";
|
|
2
2
|
import type { HeadlessPaneFreshness } from "../../../types/headless";
|
|
3
|
+
import { readAsOne, rowReadAt, type PerpOpenInterest } from "../../../market-data/perpetual-open-interest";
|
|
3
4
|
import { venueName, venuesOf } from "./model";
|
|
4
5
|
|
|
5
|
-
type Dated = Pick<PerpBoardRow, "venue" | "observedAt" | "stale"
|
|
6
|
+
type Dated = Pick<PerpBoardRow, "venue" | "observedAt" | "stale"> & PerpOpenInterest;
|
|
6
7
|
type Funded = Pick<PerpBoardRow, "venue" | "fundingRate" | "fundingRate8h" | "fundingKind" | "nextFundingAt">;
|
|
7
8
|
|
|
8
9
|
const WEEKDAYS = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"] as const;
|
|
@@ -47,25 +48,31 @@ export function fundingNote(rows: readonly Funded[], now = Date.now()): string |
|
|
|
47
48
|
}).join("; ")}`;
|
|
48
49
|
}
|
|
49
50
|
|
|
50
|
-
/**
|
|
51
|
-
|
|
51
|
+
/**
|
|
52
|
+
* What a capture reads of a row: when its figures were read, its open interest's own read when that is older (a
|
|
53
|
+
* streamed mark beside polled open interest), and whether the venue has stopped answering for it.
|
|
54
|
+
*/
|
|
55
|
+
const perpObservation = (row: Dated) => ({ observedAt: rowReadAt(row), stale: row.stale });
|
|
52
56
|
|
|
53
57
|
/**
|
|
54
58
|
* How current a view of perpetual markets is: each venue's own newest observation, how old the oldest price shown is,
|
|
55
59
|
* and what the funding figures it shows (`funding`) are. `live` only while every row followed streams from its venue's
|
|
56
|
-
* socket
|
|
57
|
-
*
|
|
58
|
-
*
|
|
60
|
+
* socket and every figure on it came with the stream: a streamed mark beside the open interest the last poll read
|
|
61
|
+
* (Binance's socket carries none) is not live. Otherwise no feed word, since a row off the stream is the venue's own
|
|
62
|
+
* reading from the last pass (about once a minute), neither streamed nor held back. Stale after an hour without a
|
|
63
|
+
* read, or for a row whose venue stopped answering. The report, the capture and the pane footer all read this, rows
|
|
64
|
+
* and all, so they end with the same line.
|
|
59
65
|
*/
|
|
60
66
|
export function perpFreshness(rows: readonly Dated[], { funding = [], venue = "all", now = Date.now(), live = false }: {
|
|
61
67
|
funding?: readonly Funded[]; venue?: string; now?: number;
|
|
62
|
-
/** Every row followed moves with its venue's socket
|
|
68
|
+
/** Every row followed moves with its venue's socket. */
|
|
63
69
|
live?: boolean;
|
|
64
70
|
} = {}): HeadlessPaneFreshness {
|
|
65
71
|
const sources = venuesOf(rows).map((id) => ({ source: venueName(id), asOf: new Date(Math.max(...rows.filter((row) => row.venue === id)
|
|
66
|
-
.map((row) => Date.parse(row
|
|
72
|
+
.map((row) => Date.parse(rowReadAt(row))))).toISOString() }));
|
|
67
73
|
const source = sources.length ? sources.map((entry) => entry.source).join(", ") : venue !== "all" ? venueName(venue) : null;
|
|
68
74
|
const note = fundingNote(funding, now);
|
|
69
|
-
|
|
75
|
+
const streamed = live && rows.every(readAsOne);
|
|
76
|
+
return { ...(source ? { source } : {}), sources, ...(streamed ? { status: "live" as const } : {}), ageOnly: true, maxAgeMinutes: 60,
|
|
70
77
|
observations: rows.map(perpObservation), ...(note ? { note } : {}) };
|
|
71
78
|
}
|
|
@@ -6,7 +6,7 @@ import { DEPTH_COLUMN_IDS, depthBandTotals, depthCellText, depthColumnLabel, dep
|
|
|
6
6
|
PRINT_COLUMN_IDS, printCellText, printColumnLabel, type DepthColumnId, type LiquidationColumnId, type PrintColumnId } from "./cascade";
|
|
7
7
|
import { boardSearchText, fetchPerpSelection, fetchPerpsBoard, fetchPerpsCompare, fetchPerpsDepth, fetchPerpsHistory, fetchPerpsLiquidations, fetchPerpsRankings, marketQuery, nearestPerpMarkets } from "./client";
|
|
8
8
|
import { perpFreshness } from "./freshness";
|
|
9
|
-
import { aprFootnote, ASSET_FILTERS, BOARD_COLUMNS, BOARD_SORTS, collectedVenueCount, COMPARE_COLUMNS, compact, fundingSpread, HISTORY_METRICS, label, marketLabel, observed, openingTab, PERP_TABS, perpCellText,
|
|
9
|
+
import { aprFootnote, ASSET_FILTERS, BOARD_COLUMNS, BOARD_SORTS, collectedVenueCount, COMPARE_COLUMNS, compact, fundingSpread, HISTORY_METRICS, label, marketLabel, observed, openInterestFields, openingTab, PERP_TABS, perpCellText,
|
|
10
10
|
perpColumnLabel, percent, perpHistoryProText, positioningFields, price, RANKING_COLUMNS, rankingRows, RANKINGS, ratioText, share, time, uncoveredVenueNote, VENUES, venueAprSummary, venueName, venuesOf, IDENTITY_VENUES,
|
|
11
11
|
type PerpColumnId } from "./model";
|
|
12
12
|
import { freePreviewNote } from "../shared/free-preview";
|
|
@@ -342,6 +342,9 @@ async function loadPerpTab(args: HeadlessPaneLoadArgs, ctx: HeadlessPaneContext)
|
|
|
342
342
|
// Where the figures were read, as the pane's Evidence names it: the venue's own endpoint and its time.
|
|
343
343
|
{ title: "Source", entries: [{ key: "sourceUrl", label: "URL", value: selected.sourceUrl },
|
|
344
344
|
{ key: "sourceAsOf", label: "Venue as of", value: selected.sourceAsOf, formatted: time(selected.sourceAsOf) }] },
|
|
345
|
+
// The open interest's own read, which the market's source and time above do not date, and how its USD was made.
|
|
346
|
+
{ title: "Open interest", entries: openInterestFields(selected).map((field) => ({ key: field.key, label: field.label, value: field.value,
|
|
347
|
+
formatted: field.detail ? `${field.text} · ${field.detail}` : field.text })) },
|
|
345
348
|
...(positioning ? [{ title: "Positioning", entries: positioning.map((field) => ({ key: field.key, label: field.label, value: field.value,
|
|
346
349
|
formatted: field.detail ? `${field.text} · ${field.detail}` : field.text })) }] : []),
|
|
347
350
|
{ title: "Observation revisions", columns: REVISION_COLUMNS, rows: market.evidence.map((row) => ({ ...row })), ...lockedTable(market.access !== "pro") }],
|
|
@@ -6,6 +6,7 @@ import { ActionRow, ColumnGrid, SectionHeading, type ColumnGridCell, type Column
|
|
|
6
6
|
import { hiddenTableColumnText, markHiddenTableColumns } from "../../../components/ui/table-layout";
|
|
7
7
|
import { t, tf } from "../../../i18n";
|
|
8
8
|
import { useAsyncResource, useAutoRefresh } from "../../../public/react";
|
|
9
|
+
import { useAgeClock } from "../../../react/auto-refresh";
|
|
9
10
|
import { useThemeColors } from "../../../theme/theme-context";
|
|
10
11
|
import { perpetualListing } from "../../../tickers/perpetual-listing";
|
|
11
12
|
import { premiumToUnderlying } from "../../../market-data/perpetual-premium";
|
|
@@ -18,9 +19,10 @@ import { useResearchCloudSession } from "../shared/research-cloud-session";
|
|
|
18
19
|
import { loadPerpsCompare, loadPerpsEquity } from "./client";
|
|
19
20
|
import { perpEquityIdentity } from "./equity-identity";
|
|
20
21
|
import { useLivePerpRows } from "./live-rows";
|
|
21
|
-
import { compact, perpCell, percent, price,
|
|
22
|
+
import { compact, perpCell, percent, price, venueName } from "./model";
|
|
22
23
|
import { openPerpLabel, useOpenPerpMarket } from "./open-market";
|
|
23
|
-
import {
|
|
24
|
+
import { freshnessLine } from "./status-line";
|
|
25
|
+
import { contractText, foldSmallMarkets, mergeVenueMarkets, venueMarketsFreshness, withPrimaryReading, type PerpVenueMarket } from "./venue-markets";
|
|
24
26
|
|
|
25
27
|
const STOCK_TYPES = new Set(["STK", "EQUITY", "STOCK", "COMMON STOCK"]);
|
|
26
28
|
const COIN_PAIR = /^([A-Z0-9]{1,15})[-/](?:USD|USDT|USDC)$/;
|
|
@@ -74,8 +76,8 @@ function fitColumns(width: number, venueWidth: number): Column[] {
|
|
|
74
76
|
/**
|
|
75
77
|
* DES's perpetual markets on a stock or a coin: one row per venue (its contracts merged, `venue-markets.ts`), the
|
|
76
78
|
* deepest first, markets with a small share of the open interest folded behind a row that shows them. A row opens
|
|
77
|
-
* PERP on its venue's deepest contract. The figures move with the quote stream while the venue streams
|
|
78
|
-
*
|
|
79
|
+
* PERP on its venue's deepest contract. The figures move with the quote stream while the venue streams, and the
|
|
80
|
+
* section ends with PERP's status line: each venue's time, never newer than a figure on its row.
|
|
79
81
|
*/
|
|
80
82
|
export function PerpMarketsSection({ symbol, exchange, instrumentType, quote, width }: {
|
|
81
83
|
symbol: string;
|
|
@@ -105,8 +107,13 @@ export function PerpMarketsSection({ symbol, exchange, instrumentType, quote, wi
|
|
|
105
107
|
// The deepest contract of each row on screen follows the quote stream.
|
|
106
108
|
const primaries = useMemo(() => visible.map((market) => market.primary), [visible]);
|
|
107
109
|
const live = useLivePerpRows(primaries, { surface: "detail" });
|
|
110
|
+
const now = useAgeClock(resource.updatedAt);
|
|
108
111
|
if (!assetKey || !markets.length) return null;
|
|
109
|
-
|
|
112
|
+
// A streamed reading moves the venue's whole row: its mark, and the open interest and volume counted with it.
|
|
113
|
+
const rows = visible.map((market, index) => {
|
|
114
|
+
const row = live.rows[index] ?? market.primary;
|
|
115
|
+
return { market: withPrimaryReading(market, row), row };
|
|
116
|
+
});
|
|
110
117
|
const premiumLabel = asset?.kind === "stock" ? "vs last" : "Premium";
|
|
111
118
|
// The venue column fits the longest venue name shown.
|
|
112
119
|
const venueWidth = Math.min(VENUE_MAX_WIDTH, Math.max(VENUE_MIN_WIDTH, ...visible.map((market) => displayWidth(venueName(market.venue)))));
|
|
@@ -140,10 +147,9 @@ export function PerpMarketsSection({ symbol, exchange, instrumentType, quote, wi
|
|
|
140
147
|
return { text: compact(column.id === "oi" ? market.openInterestUsd : market.volume24hUsd), color: colors.text };
|
|
141
148
|
};
|
|
142
149
|
const body = rows.map(({ market, row }) => columns.map((column) => cell(column, market, row)));
|
|
143
|
-
//
|
|
144
|
-
const
|
|
145
|
-
const
|
|
146
|
-
const stale = read.length > 0 && (!!resource.data?.stale || read.some(({ row }) => row.stale));
|
|
150
|
+
// Each venue's own time, as PERP's footer gives it: the first form that fits.
|
|
151
|
+
const status = freshnessLine(venueMarketsFreshness(rows.map(({ market }) => market), { now, streaming: live.liveMarkets, refreshFailed: !!resource.data?.stale }), now);
|
|
152
|
+
const statusText = status.variants.find((variant) => displayWidth(variant) <= width) ?? status.variants.at(-1);
|
|
147
153
|
return (
|
|
148
154
|
<Box flexDirection="column" data-gloom-role="perp-markets">
|
|
149
155
|
<SectionHeading title={t("Perpetuals")} />
|
|
@@ -154,7 +160,7 @@ export function PerpMarketsSection({ symbol, exchange, instrumentType, quote, wi
|
|
|
154
160
|
label={expanded ? t("Fewer markets") : folded.length === 1 ? t("1 smaller market") : tf("{count} smaller markets", { count: String(folded.length) })}
|
|
155
161
|
onPress={() => setExpanded((value) => !value)} />
|
|
156
162
|
)}
|
|
157
|
-
{
|
|
163
|
+
{statusText && <Text fg={status.stale ? colors.warning : colors.textDim}>{statusText}</Text>}
|
|
158
164
|
</Box>
|
|
159
165
|
);
|
|
160
166
|
}
|
|
@@ -2,6 +2,7 @@ import type { PerpBoardRow, PerpHistoryPayload, PerpLongShortRatio, PerpRankings
|
|
|
2
2
|
import type { DataTableCell, DataTableColumn } from "../../../components";
|
|
3
3
|
import { scalarPoint, staticSeries } from "../../../components/chart/static/series";
|
|
4
4
|
import { getTableWidth, markHiddenTableColumns } from "../../../components/ui/table-layout";
|
|
5
|
+
import { openInterestSourceOf, rowReadAt, type PerpOpenInterest } from "../../../market-data/perpetual-open-interest";
|
|
5
6
|
import { MISSING_VALUE, formatCompact } from "../../../utils/format";
|
|
6
7
|
import { isUsListingExchange, publicTickerKey } from "../../../utils/exchanges";
|
|
7
8
|
import { isRecord } from "../../../utils/guards";
|
|
@@ -206,6 +207,35 @@ export function positioningFields(row: Pick<PerpBoardRow, "longShortRatio" | "lo
|
|
|
206
207
|
];
|
|
207
208
|
}
|
|
208
209
|
|
|
210
|
+
const USD_BASES: Record<"mark" | "oracle" | "face-value", string> = { mark: "mark × contracts", oracle: "oracle × contracts", "face-value": "contracts × face value" };
|
|
211
|
+
/**
|
|
212
|
+
* How a market's OI USD was made: `mark × contracts, USDT valued at 1 USD`, or the venue's own figure
|
|
213
|
+
* (`Bybit's own USDT value, USDT valued at 1 USD`). Null without a USD figure or when the server does not say.
|
|
214
|
+
*/
|
|
215
|
+
function openInterestUsdBasis(row: PerpOpenInterest & Pick<PerpBoardRow, "venue">): string | null {
|
|
216
|
+
const source = openInterestSourceOf(row);
|
|
217
|
+
if (row.openInterestUsd == null || !source?.usdBasis) return null;
|
|
218
|
+
const made = source.usdBasis === "venue" ? `${venueName(row.venue)}'s own ${source.usdParity ?? "USD"} value` : USD_BASES[source.usdBasis];
|
|
219
|
+
return made ? `${made}${source.usdParity ? `, ${source.usdParity} valued at 1 USD` : ""}` : null;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* The open interest as Evidence lists it, shared by the pane and the text report: the figure with how its USD was
|
|
223
|
+
* made, then its own read, the venue's time for it and the endpoint, never the market's. A server that does not say
|
|
224
|
+
* where it read the open interest leaves its time "Not stated".
|
|
225
|
+
*/
|
|
226
|
+
export function openInterestFields(row: Pick<PerpBoardRow, "venue" | "baseAsset" | "openInterestBase" | "openInterestUsd" | "openInterestSource">): PositioningField[] {
|
|
227
|
+
const basis = openInterestUsdBasis(row);
|
|
228
|
+
const amount: PositioningField = { key: "openInterest", label: "Open interest", value: row.openInterestUsd,
|
|
229
|
+
text: `${compact(row.openInterestBase)} ${row.baseAsset} · ${compact(row.openInterestUsd)} USD`, ...(basis ? { detail: `USD = ${basis}` } : {}) };
|
|
230
|
+
if (row.openInterestBase == null && row.openInterestUsd == null) return [amount];
|
|
231
|
+
const source = openInterestSourceOf(row);
|
|
232
|
+
if (!source) return [amount, { key: "openInterestObservedAt", label: "OI observed", value: null, text: "Not stated" }];
|
|
233
|
+
return [amount,
|
|
234
|
+
{ key: "openInterestObservedAt", label: "OI observed", value: source.observedAt, text: time(source.observedAt) },
|
|
235
|
+
{ key: "openInterestAsOf", label: "OI source as of", value: source.asOf, text: time(source.asOf) },
|
|
236
|
+
{ key: "openInterestSourceUrl", label: "OI source", value: source.url, text: source.url }];
|
|
237
|
+
}
|
|
238
|
+
|
|
209
239
|
// One text per figure, shared by the pane cells and the text report so the two always agree.
|
|
210
240
|
const markText = (row: Pick<PerpBoardRow, "markPrice" | "quoteCurrency">) => row.markPrice == null ? MISSING_VALUE : `${price(row.markPrice)} ${row.quoteCurrency}`;
|
|
211
241
|
const fundingPerInterval = (row: Pick<PerpBoardRow, "fundingRate" | "fundingIntervalHours" | "fundingKind">) => row.fundingRate == null ? MISSING_VALUE : `${percent(row.fundingRate, 5)} /${fundingInterval(row)}`;
|
|
@@ -313,7 +343,8 @@ export function perpCellText(row: PerpBoardRow, id: PerpColumnId): string {
|
|
|
313
343
|
if (id === "markPrice") return markText(row);
|
|
314
344
|
if (id === "fundingRate") return fundingPerInterval(row);
|
|
315
345
|
if (id === "openInterestUsd") return compact(row.openInterestUsd);
|
|
316
|
-
|
|
346
|
+
// A row is dated by its oldest figure: a streamed mark can sit beside the open interest the last poll read.
|
|
347
|
+
if (id === "observedAt") return observed(rowReadAt(row));
|
|
317
348
|
if (id === "longShare") return share(row.longShortRatio?.longShare);
|
|
318
349
|
const digits = SIGNED[id];
|
|
319
350
|
return digits === undefined ? MISSING_VALUE : percent(row[id as keyof PerpBoardRow] as number | null, digits);
|
|
@@ -322,7 +353,7 @@ export function perpCell(row: PerpBoardRow, id: PerpColumnId, colors: Pick<Theme
|
|
|
322
353
|
const text = perpCellText(row, id);
|
|
323
354
|
if (id === "market") return { text, color: row.stale ? colors.textDim : colors.textBright };
|
|
324
355
|
if (id === "venue" || id === "symbol") return { text, color: colors.textMuted };
|
|
325
|
-
if (id === "observedAt") return { text, value: row
|
|
356
|
+
if (id === "observedAt") return { text, value: rowReadAt(row), color: row.stale ? colors.textMuted : colors.textDim };
|
|
326
357
|
if (id === "markPrice") return { text, value: row.markPrice };
|
|
327
358
|
if (id === "openInterestUsd") return { text, value: row.openInterestUsd };
|
|
328
359
|
// A share, not a signed move: no tone, dimmed like a stale market when its bucket is old.
|
|
@@ -28,7 +28,7 @@ import { useFreshnessStatusLine } from "./status-line";
|
|
|
28
28
|
import { useLivePerpRows, useLivePerpTableRows } from "./live-rows";
|
|
29
29
|
import { perpBoardRowSource, readPerpBoardRow } from "./board-row-source";
|
|
30
30
|
import { aprFormula, ASSET_FILTERS, BOARD_SORTS, boardColumns, collectedVenueCount, compact, compareColumns, dayChange, fundingInterval, fundingSpread, historyCaption, historyCell, historyChange, historyColumns,
|
|
31
|
-
HISTORY_METRICS, historyRows, historySeries, historyValue, inPoints, isAssetTab, isMarketTab, label, longShortReason, marketLabel, metricLabel, openingTab, perpCell, perpHistoryProText, PERP_TABS, percent,
|
|
31
|
+
HISTORY_METRICS, historyRows, historySeries, historyValue, inPoints, isAssetTab, isMarketTab, label, longShortReason, marketLabel, metricLabel, openInterestFields, openingTab, perpCell, perpHistoryProText, PERP_TABS, percent,
|
|
32
32
|
positioningFields, price, rankingColumns, rankingRows, RANKINGS, ratioText, share, sortLabel, time, underlyingTicker, venueAprSummary, venueLabel, venueName, venuesOf, type HistoryMetric,
|
|
33
33
|
type PerpColumnId, type PerpTab, type RankingKey } from "./model";
|
|
34
34
|
|
|
@@ -81,7 +81,8 @@ function MarketEvidence({ row, data, width, height }: { row: PerpBoardRow; data:
|
|
|
81
81
|
...(row.predictedFundingRate != null ? [["Predicted funding", `${percent(row.predictedFundingRate)} / ${row.predictedFundingIntervalHours ?? MISSING_VALUE}h`] as [string, string]] : []),
|
|
82
82
|
...(row.nextFundingAt ? [["Next funding", time(row.nextFundingAt)] as [string, string]] : []),
|
|
83
83
|
...(acrossVenues ? [["APR across venues", acrossVenues.text] as [string, string]] : [])]],
|
|
84
|
-
|
|
84
|
+
// The open interest is dated and sourced by its own read, not the market's above.
|
|
85
|
+
["Open Interest", [...openInterestFields(row).map((field): EvidenceField => [field.label, field.text, field.detail]),
|
|
85
86
|
["OI change 1h / 24h", row.oiChange1h == null && row.oiChange24h == null ? "Collecting" : `${percent(row.oiChange1h, 2)} / ${percent(row.oiChange24h, 2)}`, "own snapshots"]]],
|
|
86
87
|
...(positioning ? [["Positioning", positioning.map((field) => [field.label, field.text, field.detail])] as [string, EvidenceField[]]] : []),
|
|
87
88
|
...(row.underlying ? [["Underlying", [...listed, ["Underlying last", `${price(row.underlying.price)} ${row.underlying.currency}`, time(row.underlying.asOf)], ["Underlying session", row.underlying.marketState ?? "Unknown"],
|
|
@@ -5,6 +5,15 @@ import { useAgeClock } from "../../../react/auto-refresh";
|
|
|
5
5
|
import { useRemoteUiNode } from "../../../remote/semantic-tree";
|
|
6
6
|
import type { HeadlessPaneFreshness } from "../../../types/headless";
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* A declared freshness as a pane writes it, PERP's status line: its forms from longest to shortest, for the first that
|
|
10
|
+
* fits, and whether it is stale.
|
|
11
|
+
*/
|
|
12
|
+
export function freshnessLine(declared: HeadlessPaneFreshness, now: number): { variants: string[]; stale: boolean } {
|
|
13
|
+
const freshness = deriveHeadlessFreshness({ shape: "rows" }, { rows: [], freshness: declared }, now);
|
|
14
|
+
return { variants: paneStatusLineVariants(freshness), stale: freshness.status === "stale" };
|
|
15
|
+
}
|
|
16
|
+
|
|
8
17
|
/**
|
|
9
18
|
* The footer line a tab ends with, from the same freshness its text report declares (`declare`, null while there is
|
|
10
19
|
* nothing to date): the source, its time and how old it is, the line `fn PERP` and `shot PERP` end with. It keeps ageing
|
|
@@ -16,10 +25,10 @@ export function useFreshnessStatusLine(declare: ((now: number) => HeadlessPaneFr
|
|
|
16
25
|
useRemoteUiNode(declared ? { role: "report-freshness", label: "Venue freshness", getMetadata: () => ({ ...declared }) } : null);
|
|
17
26
|
return useMemo(() => {
|
|
18
27
|
if (!declared) return [];
|
|
19
|
-
const
|
|
20
|
-
const tone =
|
|
28
|
+
const { variants, stale } = freshnessLine(declared, now);
|
|
29
|
+
const tone = stale ? "warning" as const : "muted" as const;
|
|
21
30
|
// A footer too narrow beside its keys gives up the note before any venue's time.
|
|
22
|
-
const [line, ...shorter] =
|
|
31
|
+
const [line, ...shorter] = variants.map((text) => [{ text, tone }]);
|
|
23
32
|
return [{ id: "perp-freshness", asOf: true, parts: line!, variants: shorter }];
|
|
24
33
|
}, [declared, now]);
|
|
25
34
|
}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import type { PerpBoardRow } from "../../../api-client/perps";
|
|
2
|
+
import type { HeadlessPaneFreshness } from "../../../types/headless";
|
|
3
|
+
import { readAsOne, rowReadAt } from "../../../market-data/perpetual-open-interest";
|
|
4
|
+
import { perpFreshness } from "./freshness";
|
|
2
5
|
import { venueName } from "./model";
|
|
3
6
|
|
|
4
7
|
/**
|
|
@@ -60,6 +63,41 @@ export function mergeVenueMarkets(rows: readonly PerpBoardRow[]): PerpVenueMarke
|
|
|
60
63
|
}).sort((a, b) => deeper(a, b) || venueName(a.venue).localeCompare(venueName(b.venue)) || a.key.localeCompare(b.key));
|
|
61
64
|
}
|
|
62
65
|
|
|
66
|
+
/**
|
|
67
|
+
* A venue's row with its deepest contract's newer reading (the quote stream's) laid over it: the open interest and
|
|
68
|
+
* volume count that reading, so they move with the mark beside them. The row itself for the reading it was made from.
|
|
69
|
+
*/
|
|
70
|
+
export function withPrimaryReading(market: PerpVenueMarket, row: PerpBoardRow): PerpVenueMarket {
|
|
71
|
+
if (row === market.primary) return market;
|
|
72
|
+
const contracts = [row, ...market.contracts.slice(1)];
|
|
73
|
+
return { ...market, primary: row, contracts, openInterestUsd: sumOrNull(contracts.map((contract) => contract.openInterestUsd)),
|
|
74
|
+
volume24hUsd: sumOrNull(contracts.map((contract) => contract.volume24hUsd)) };
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* When a venue's row was read: the oldest reading among the contracts its figures are made of, each one's open
|
|
79
|
+
* interest by its own read, so the row is never dated newer than a figure it shows.
|
|
80
|
+
*/
|
|
81
|
+
export function venueMarketReadAt(market: Pick<PerpVenueMarket, "contracts">): string {
|
|
82
|
+
return market.contracts.map(rowReadAt).reduce((oldest, at) => Date.parse(at) < Date.parse(oldest) ? at : oldest);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* How current a list of venue rows is, in PERP's status line: each venue dated by its row's oldest figure, how old the
|
|
87
|
+
* oldest row is, and `live` only while every figure shown streams. A market streams when its deepest contract follows
|
|
88
|
+
* its venue's socket (`streaming`) and its open interest came with it, not from the last poll (Binance's socket carries
|
|
89
|
+
* none); a venue's other contracts are the last read. `refreshFailed` marks the rows off the stream stale: the last
|
|
90
|
+
* read failed and its saved copy is shown.
|
|
91
|
+
*/
|
|
92
|
+
export function venueMarketsFreshness(markets: readonly PerpVenueMarket[], { now = Date.now(), streaming, refreshFailed = false }: {
|
|
93
|
+
now?: number; streaming: ReadonlySet<string>; refreshFailed?: boolean;
|
|
94
|
+
}): HeadlessPaneFreshness {
|
|
95
|
+
const streams = (market: PerpVenueMarket) => streaming.has(market.primary.marketId) && readAsOne(market.primary);
|
|
96
|
+
const rows = markets.map((market) => ({ venue: market.primary.venue, observedAt: venueMarketReadAt(market),
|
|
97
|
+
stale: market.contracts.some((contract) => contract.stale) || refreshFailed && !streams(market) }));
|
|
98
|
+
return perpFreshness(rows, { now, live: markets.length > 0 && markets.every((market) => streams(market) && market.contracts.length === 1) });
|
|
99
|
+
}
|
|
100
|
+
|
|
63
101
|
/** A market under this share of the asset's open interest is folded behind "more". */
|
|
64
102
|
const SMALL_MARKET_SHARE = 0.02;
|
|
65
103
|
|