gloomberb 0.10.0 → 0.10.2
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 +8 -1
- package/src/api-client/auth.ts +1 -0
- package/src/api-client/index.test.ts +359 -108
- package/src/api-client/index.ts +24 -13
- package/src/api-client/socket.ts +70 -35
- package/src/api-client/types.ts +1 -1
- package/src/app/language-observer.test.tsx +82 -0
- package/src/app/language-observer.tsx +13 -0
- package/src/app/pane-runtime/index.tsx +2 -2
- package/src/app/pane-runtime/pane-settings-runtime.tsx +2 -2
- package/src/app/pane-runtime/pane-template-runtime.ts +2 -2
- package/src/app/pane-runtime/plugin-bindings.ts +2 -2
- package/src/app/pane-runtime/ticker-open-runtime.ts +2 -2
- package/src/app/runtime/broker-import.ts +2 -2
- package/src/app/runtime/plugin-bindings.ts +2 -2
- package/src/app/runtime/startup.ts +2 -2
- package/src/app.tsx +16 -7
- package/src/brokers/account-cache.ts +6 -6
- package/src/brokers/broker-ticker-sync.ts +3 -3
- package/src/brokers/remote-broker-adapter.ts +2 -2
- package/src/brokers/sync-broker-instance.ts +5 -6
- package/src/cli/commands/api.ts +3 -6
- package/src/cli/commands/automation.ts +7 -15
- package/src/cli/commands/market.ts +26 -61
- package/src/cli/commands/overview.ts +34 -45
- package/src/cli/commands/search.ts +25 -27
- package/src/cli/commands/system.ts +27 -57
- package/src/cli/commands/ticker.ts +62 -63
- package/src/cli/context.test.ts +63 -0
- package/src/cli/context.ts +15 -1
- package/src/cli/index.ts +1 -1
- package/src/cli/pane-functions/data.ts +2 -19
- package/src/cli/pane-functions/index.ts +26 -25
- package/src/cli/pane-functions/report.ts +1 -1
- package/src/cli/pane-functions/screenshot.ts +3 -3
- package/src/cli/scoped-context.ts +41 -0
- package/src/components/chart/composite/composite-chart.test.tsx +615 -18
- package/src/components/chart/composite/composite-chart.tsx +179 -79
- package/src/components/chart/composite/format.test.ts +20 -7
- package/src/components/chart/composite/index.ts +0 -21
- package/src/components/chart/composite/interactions.test.ts +90 -3
- package/src/components/chart/composite/interactions.ts +189 -24
- package/src/components/chart/composite/price-series.ts +0 -2
- package/src/components/chart/composite/rasterizer.ts +10 -9
- package/src/components/chart/composite/renderers.test.ts +108 -2
- package/src/components/chart/composite/scene.test.ts +36 -0
- package/src/components/chart/composite/scene.ts +5 -2
- package/src/components/chart/composite/text-renderer.ts +37 -25
- package/src/components/chart/composite/time-axis.test.ts +243 -0
- package/src/components/chart/composite/time-axis.ts +608 -0
- package/src/components/chart/composite/types.ts +12 -1
- package/src/components/chart/core/data.ts +2 -159
- package/src/components/chart/core/date-window.ts +6 -225
- package/src/components/chart/core/palette.ts +1 -12
- package/src/components/chart/core/pointer.ts +0 -142
- package/src/components/chart/core/types.ts +1 -58
- package/src/components/chart/cursor-motion.ts +2 -4
- package/src/components/chart/indicators/types.ts +0 -9
- package/src/components/chart/market-session.ts +0 -11
- package/src/components/chart/native/kitty/protocol.ts +1 -1
- package/src/components/chart/native/raster/layout.ts +3 -10
- package/src/components/chart/static/chart/axis-overlays.test.tsx +64 -0
- package/src/components/chart/static/chart/axis-overlays.tsx +59 -14
- package/src/components/chart/static/chart/surface.tsx +1 -2
- package/src/components/command-bar/action-runtime.ts +2 -2
- package/src/components/command-bar/commands/direct/index.ts +1 -1
- package/src/components/command-bar/panel/body.tsx +2 -2
- package/src/components/command-bar/panel/index.tsx +11 -9
- package/src/components/command-bar/routes/ticker-search/actions.ts +2 -2
- package/src/components/command-bar/surface/index.tsx +2 -2
- package/src/components/command-bar/workflow/body.tsx +3 -3
- package/src/components/command-bar/workflow/collection-actions.ts +2 -2
- package/src/components/command-bar/workflow/coordinator.ts +2 -2
- package/src/components/command-bar/workflow/field-row.tsx +25 -11
- package/src/components/command-bar/workflow/tickers.ts +2 -2
- package/src/components/feed-data-table/stack-view.test.tsx +28 -36
- package/src/components/feed-data-table/stack-view.tsx +3 -1
- package/src/components/layout/detached-pane-shell.tsx +6 -6
- package/src/components/layout/header.tsx +13 -9
- package/src/components/layout/pane/content.test.tsx +42 -3
- package/src/components/layout/pane/content.tsx +3 -1
- package/src/components/layout/pane/footer/index.test.tsx +45 -2
- package/src/components/layout/pane/footer/registration.tsx +3 -1
- package/src/components/layout/shell/index.tsx +1 -2
- package/src/components/layout/shell/native/surfaces.ts +1 -1
- package/src/components/layout/shell/native/window-state.ts +1 -1
- package/src/components/layout/status-bar.tsx +12 -8
- package/src/components/layout/window-controls.tsx +8 -6
- package/src/components/onboarding/onboarding-wizard.tsx +3 -1
- package/src/components/pane-settings-dialog/desktop.tsx +0 -2
- package/src/components/pane-settings-dialog.tsx +0 -2
- package/src/components/pane-template-wizard.tsx +10 -9
- package/src/components/price-performance.tsx +2 -113
- package/src/components/price-sparkline/model.ts +15 -17
- package/src/components/price-sparkline/view.tsx +8 -7
- package/src/components/speedometer-gauge/desktop.tsx +2 -1
- package/src/components/speedometer-gauge/index.tsx +0 -2
- package/src/components/speedometer-gauge/terminal.tsx +24 -5
- package/src/components/ticker/badge/index.tsx +1 -18
- package/src/components/ui/data-table/opentui/index.tsx +3 -3
- package/src/components/ui/frame.tsx +1 -2
- package/src/components/ui/page-stack-view.test.tsx +126 -0
- package/src/components/ui/page-stack-view.tsx +24 -12
- package/src/components/ui/tabs.tsx +7 -3
- package/src/components/ui/ui.test.tsx +23 -2
- package/src/components/use-external-link-footer.ts +4 -2
- package/src/core/app-service-ports.ts +46 -0
- package/src/core/app-services.test.ts +66 -0
- package/src/core/app-services.ts +17 -15
- package/src/data/config/chart-settings.ts +3 -10
- package/src/data/config/store/index.test.ts +99 -2
- package/src/data/config/store/migrations.ts +278 -0
- package/src/data/config/store/normalize.ts +44 -186
- package/src/data/resource-store.ts +73 -12
- package/src/data/sqlite/cache.test.ts +104 -15
- package/src/i18n/index.test.ts +17 -0
- package/src/i18n/index.ts +23 -6
- package/src/i18n/ja.ts +13 -0
- package/src/i18n/ko.ts +13 -0
- package/src/i18n/react.ts +6 -0
- package/src/i18n/zh-cn.ts +13 -0
- package/src/i18n/zh-tw.ts +13 -0
- package/src/market-data/coordinator/auxiliary.ts +7 -3
- package/src/market-data/coordinator/chart.ts +1 -1
- package/src/market-data/coordinator/index.test.ts +26 -0
- package/src/market-data/coordinator/index.ts +11 -5
- package/src/market-data/coordinator/quotes.ts +4 -40
- package/src/market-data/coordinator/subscriptions.test.ts +89 -1
- package/src/market-data/hooks.tsx +47 -1
- package/src/market-data/market/status.ts +6 -6
- package/src/market-data/performance.ts +1 -1
- package/src/market-data/quote-subscription-target.test.ts +37 -0
- package/src/market-data/quote-subscription-target.ts +60 -0
- package/src/market-data/quotes/freshness.ts +1 -0
- package/src/market-data/quotes/resolution.ts +4 -0
- package/src/market-data/request-types.ts +3 -3
- package/src/news/aggregator.test.ts +97 -1
- package/src/news/aggregator.ts +100 -57
- package/src/news/hooks.test.tsx +64 -0
- package/src/news/hooks.ts +18 -25
- package/src/plugins/builtin/account-management/footer.ts +4 -2
- package/src/plugins/builtin/account-management/pane.tsx +9 -4
- package/src/plugins/builtin/ai/agent-history.ts +11 -7
- package/src/plugins/builtin/ai/ask-ai-detail-tab.tsx +0 -5
- package/src/plugins/builtin/ai/ask-ai.test.tsx +3 -4
- package/src/plugins/builtin/ai/index.test.ts +2 -2
- package/src/plugins/builtin/ai/index.tsx +10 -11
- package/src/plugins/builtin/ai/pane-settings.ts +1 -1
- package/src/plugins/builtin/ai/pi/runtime.ts +6 -5
- package/src/plugins/builtin/ai/providers.ts +1 -9
- package/src/plugins/builtin/ai/runner.ts +0 -6
- package/src/plugins/builtin/ai/screener/footer.ts +4 -1
- package/src/plugins/builtin/ai/screener/pane.test.tsx +9 -9
- package/src/plugins/builtin/ai/workspace/model.ts +2 -27
- package/src/plugins/builtin/ai/workspace/pane.tsx +2 -2
- package/src/plugins/builtin/analytics/metrics.ts +1 -7
- package/src/plugins/builtin/broker-manager/detail.tsx +3 -2
- package/src/plugins/builtin/broker-manager/index.tsx +4 -2
- package/src/plugins/builtin/chart-composer/editor/controller.ts +643 -0
- package/src/plugins/builtin/chart-composer/editor/desktop-view.tsx +134 -0
- package/src/plugins/builtin/chart-composer/editor/model.test.ts +85 -0
- package/src/plugins/builtin/chart-composer/editor/model.ts +292 -0
- package/src/plugins/builtin/chart-composer/editor/opentui-view.tsx +108 -0
- package/src/plugins/builtin/chart-composer/editor.tsx +65 -947
- package/src/plugins/builtin/chart-composer/index.tsx +0 -6
- package/src/plugins/builtin/chart-composer/pane.tsx +69 -36
- package/src/plugins/builtin/chart-composer/presets.ts +1 -19
- package/src/plugins/builtin/chart-composer/settings.ts +1 -1
- package/src/plugins/builtin/chat/content/composer-runtime.ts +1 -1
- package/src/plugins/builtin/chat/content/shortcuts.ts +0 -1
- package/src/plugins/builtin/chat/controller/fetch.ts +8 -2
- package/src/plugins/builtin/chat/controller/persistence.ts +2 -0
- package/src/plugins/builtin/chat/controller/session.test.ts +25 -0
- package/src/plugins/builtin/chat/controller/session.ts +2 -0
- package/src/plugins/builtin/chat/controller/state.ts +7 -0
- package/src/plugins/builtin/chat/controller.test.ts +73 -20
- package/src/plugins/builtin/chat/message/desktop.tsx +2 -0
- package/src/plugins/builtin/cloud-tweets/footer.ts +9 -28
- package/src/plugins/builtin/cloud-tweets/pane.tsx +0 -5
- package/src/plugins/builtin/cloud-tweets/table.tsx +12 -17
- package/src/plugins/builtin/correlation/compute.ts +4 -10
- package/src/plugins/builtin/econ/index.tsx +17 -19
- package/src/plugins/builtin/holders/types.ts +0 -1
- package/src/plugins/builtin/insider/index.tsx +6 -31
- package/src/plugins/builtin/news/index.tsx +5 -7
- package/src/plugins/builtin/news/wire/breaking/pane.test.tsx +6 -8
- package/src/plugins/builtin/news/wire/news/footer.ts +10 -11
- package/src/plugins/builtin/news/wire/read-state.test.ts +7 -0
- package/src/plugins/builtin/news/wire/read-state.ts +18 -28
- package/src/plugins/builtin/news/wire/rss/parser.ts +1 -11
- package/src/plugins/builtin/options/footer.test.ts +115 -0
- package/src/plugins/builtin/options/footer.ts +110 -0
- package/src/plugins/builtin/options/live-quotes.test.ts +238 -0
- package/src/plugins/builtin/options/live-quotes.ts +147 -0
- package/src/plugins/builtin/options/view.test.tsx +71 -1
- package/src/plugins/builtin/options/view.tsx +39 -24
- package/src/plugins/builtin/portfolio-list/cli/portfolio-command.ts +103 -117
- package/src/plugins/builtin/portfolio-list/cli/render.ts +11 -5
- package/src/plugins/builtin/portfolio-list/cli/watchlist-command.ts +120 -135
- package/src/plugins/builtin/portfolio-list/header.tsx +9 -4
- package/src/plugins/builtin/portfolio-list/quick-add/index.tsx +6 -1
- package/src/plugins/builtin/portfolio-list/quick-add/resolution.ts +4 -2
- package/src/plugins/builtin/research/corporate-actions-pane.tsx +24 -52
- package/src/plugins/builtin/sec/filing-content.test.ts +41 -0
- package/src/plugins/builtin/sec/filing-content.ts +94 -0
- package/src/plugins/builtin/sec/index.tsx +21 -104
- package/src/plugins/builtin/sectors/sector-model.ts +1 -7
- package/src/plugins/builtin/shared/cloud-upgrade.ts +1 -0
- package/src/plugins/builtin/shared/pane-footer.ts +82 -0
- package/src/plugins/builtin/shared/read-state.ts +64 -3
- package/src/plugins/builtin/substack/read-state.ts +16 -41
- package/src/plugins/builtin/thirteenf/pane.tsx +24 -73
- package/src/plugins/builtin/ticker-detail/quote-monitor/index.tsx +10 -10
- package/src/plugins/builtin/yield-curve/index.tsx +11 -9
- package/src/plugins/ibkr/dialogs.tsx +3 -3
- package/src/plugins/ibkr/gateway/fundamentals.ts +1 -1
- package/src/plugins/ibkr/gateway/history-requests.ts +2 -2
- package/src/plugins/ibkr/gateway/history.ts +2 -2
- package/src/plugins/ibkr/gateway/selection.ts +2 -2
- package/src/plugins/ibkr/gateway/service/index.ts +2 -2
- package/src/plugins/ibkr/gateway/service/native.ts +2 -2
- package/src/plugins/plugin-persistence.ts +3 -4
- package/src/plugins/prediction-markets/controller/keyboard.ts +1 -1
- package/src/plugins/prediction-markets/controller/live-updates.ts +6 -5
- package/src/plugins/prediction-markets/detail/book.tsx +2 -2
- package/src/plugins/prediction-markets/detail/outcomes.tsx +3 -1
- package/src/plugins/prediction-markets/detail/pane.tsx +3 -1
- package/src/plugins/prediction-markets/detail/trades.tsx +3 -3
- package/src/plugins/registry/context.ts +3 -4
- package/src/plugins/registry/index.ts +5 -6
- package/src/react/input.test.ts +126 -3
- package/src/react/input.ts +120 -1
- package/src/remote/app-host.tsx +2 -13
- package/src/renderers/electrobun/bun/desktop/backend-requests.ts +44 -60
- package/src/renderers/electrobun/bun/desktop/capability-bridge.ts +15 -13
- package/src/renderers/electrobun/bun/desktop/host-requests.ts +26 -22
- package/src/renderers/electrobun/bun/desktop/http-fetch.ts +5 -1
- package/src/renderers/electrobun/bun/desktop/initialization.ts +11 -6
- package/src/renderers/electrobun/bun/desktop/media.ts +5 -3
- package/src/renderers/electrobun/bun/desktop/plugin-state.ts +21 -22
- package/src/renderers/electrobun/bun/desktop/window-controls.ts +3 -1
- package/src/renderers/electrobun/bun/desktop/workspace/requests.ts +18 -18
- package/src/renderers/electrobun/bun/index.ts +123 -83
- package/src/renderers/electrobun/shared/protocol.ts +146 -7
- package/src/renderers/electrobun/view/app-services.ts +5 -8
- package/src/renderers/electrobun/view/backend-rpc.ts +18 -8
- package/src/renderers/electrobun/view/broker-remote-client.ts +2 -2
- package/src/renderers/electrobun/view/cli-pane-shot-entry.tsx +5 -22
- package/src/renderers/electrobun/view/config-host.ts +1 -1
- package/src/renderers/electrobun/view/context-menu.ts +1 -17
- package/src/renderers/electrobun/view/data-table/index.tsx +0 -1
- package/src/renderers/electrobun/view/data-table/row.tsx +0 -4
- package/src/renderers/electrobun/view/desktop/control-styles.ts +37 -34
- package/src/renderers/electrobun/view/desktop/controls.tsx +36 -33
- package/src/renderers/electrobun/view/desktop/list-view.tsx +15 -12
- package/src/renderers/electrobun/view/desktop/popover.tsx +2 -3
- package/src/renderers/electrobun/view/dialog-host.tsx +2 -3
- package/src/renderers/electrobun/view/fatal-screen.tsx +0 -1
- package/src/renderers/electrobun/view/host/box.tsx +0 -1
- package/src/renderers/electrobun/view/host/chart-surface.tsx +0 -1
- package/src/renderers/electrobun/view/host/input.tsx +0 -1
- package/src/renderers/electrobun/view/host/media-surface.tsx +0 -1
- package/src/renderers/electrobun/view/host/native.ts +0 -1
- package/src/renderers/electrobun/view/host/scroll-box.tsx +0 -1
- package/src/renderers/electrobun/view/host/tabs.tsx +0 -1
- package/src/renderers/electrobun/view/host/text.tsx +0 -1
- package/src/renderers/electrobun/view/http-fetch.ts +3 -11
- package/src/renderers/electrobun/view/input-host.tsx +10 -53
- package/src/renderers/electrobun/view/key-event.ts +0 -1
- package/src/renderers/electrobun/view/main.tsx +3 -3
- package/src/renderers/electrobun/view/native-renderer.ts +0 -1
- package/src/renderers/electrobun/view/native-stubs/backend-rpc.ts +13 -1
- package/src/renderers/electrobun/view/native-stubs/chart/surface-manager.ts +11 -0
- package/src/renderers/electrobun/view/native-stubs/native-stubs.test.ts +47 -0
- package/src/renderers/electrobun/view/remote/asset-data-client.ts +6 -44
- package/src/renderers/electrobun/view/remote/persistence.ts +6 -2
- package/src/renderers/electrobun/view/remote/quote-subscription-registry.test.ts +86 -0
- package/src/renderers/electrobun/view/remote/quote-subscription-registry.ts +72 -0
- package/src/renderers/electrobun/view/remote/ticker-repository.ts +2 -2
- package/src/renderers/electrobun/view/toast-host.tsx +0 -1
- package/src/renderers/electrobun/view/ui-host.tsx +1 -2
- package/src/renderers/electrobun/view/update-host.ts +1 -1
- package/src/renderers/opentui/chart-surface.tsx +2 -1
- package/src/renderers/opentui/dialog-host.tsx +20 -4
- package/src/renderers/opentui/image/loader.ts +12 -2
- package/src/renderers/opentui/input-host.tsx +7 -49
- package/src/renderers/opentui/start.tsx +2 -0
- package/src/sources/gloomberb-cloud/history-quality.ts +44 -0
- package/src/sources/gloomberb-cloud/index.test.ts +173 -0
- package/src/sources/gloomberb-cloud/index.ts +42 -20
- package/src/sources/gloomberb-cloud/normalizers.ts +9 -3
- package/src/sources/provider-router/cache.ts +1 -1
- package/src/sources/provider-router/document-routes.ts +10 -5
- package/src/sources/provider-router/financials.test.ts +14 -0
- package/src/sources/provider-router/financials.ts +6 -1
- package/src/sources/provider-router/history.test.ts +163 -1
- package/src/sources/provider-router/history.ts +278 -347
- package/src/sources/provider-router/index.ts +2 -2
- package/src/sources/provider-router/routing.test.ts +39 -0
- package/src/sources/provider-router/routing.ts +24 -11
- package/src/sources/provider-router/supplemental.ts +37 -17
- package/src/sources/sec-edgar/content.ts +2 -12
- package/src/sources/sec-edgar.ts +2 -13
- package/src/sources/yahoo-finance/history.ts +2 -2
- package/src/sources/yahoo-finance/options.ts +5 -0
- package/src/sources/yahoo-finance.ts +2 -2
- package/src/state/app/bootstrap.ts +2 -2
- package/src/state/app/context/index.tsx +2 -2
- package/src/state/hooks/quote-streaming.ts +66 -1
- package/src/state/hooks/session-snapshot.ts +2 -2
- package/src/state/selectors.ts +0 -9
- package/src/sync/controller.test.ts +98 -0
- package/src/sync/controller.ts +29 -5
- package/src/sync/react.ts +2 -2
- package/src/sync/types.ts +2 -2
- package/src/theme/colors.test.ts +10 -0
- package/src/theme/colors.ts +75 -78
- package/src/theme/theme-context.test.tsx +67 -0
- package/src/theme/theme-context.tsx +9 -5
- package/src/tickers/open-target.ts +2 -2
- package/src/tickers/search/upsert.ts +2 -2
- package/src/time-series/alignment.ts +0 -7
- package/src/time-series/chart-data.ts +145 -0
- package/src/time-series/date-window.ts +44 -0
- package/src/time-series/history-window.ts +21 -0
- package/src/time-series/hooks.test.ts +59 -0
- package/src/time-series/hooks.ts +33 -12
- package/src/time-series/market-resolution.ts +2 -2
- package/src/time-series/market.ts +1 -1
- package/src/time-series/range.ts +9 -0
- package/src/{components/chart/core → time-series}/resolution.ts +3 -102
- package/src/time-series/resolve.test.ts +203 -1
- package/src/time-series/resolve.ts +96 -18
- package/src/time-series/spec-studies.test.ts +15 -0
- package/src/time-series/spec.ts +2 -2
- package/src/time-series/studies.ts +5 -2
- package/src/time-series/types.ts +3 -1
- package/src/time-series/use-chart-resolution.test.tsx +358 -0
- package/src/time-series/use-chart-resolution.ts +46 -4
- package/src/types/broker.ts +2 -2
- package/src/types/data-provider.ts +3 -3
- package/src/types/financials.ts +12 -0
- package/src/types/plugin.ts +2 -2
- package/src/ui/context-menu.tsx +3 -2
- package/src/ui/dialog.tsx +2 -2
- package/src/utils/html-entities.ts +3 -5
- package/src/utils/main-thread-monitor.ts +1 -1
- package/src/utils/price-history.ts +5 -5
- package/src/version.ts +3 -1
- package/src/components/chart/core/viewport.test.ts +0 -8
- package/src/components/chart/core/viewport.ts +0 -24
- package/src/time-series/index.ts +0 -14
- /package/src/{components/chart/core → time-series}/resolution.test.ts +0 -0
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import type { OptionContract, Quote } from "../../../types/financials";
|
|
3
|
+
import type { QueryEntry } from "../../../market-data/result-types";
|
|
4
|
+
import type { OptionTableRow } from "./types";
|
|
5
|
+
import {
|
|
6
|
+
buildOptionQuoteKey,
|
|
7
|
+
buildOptionQuoteTargets,
|
|
8
|
+
hasLiveOptionQuote,
|
|
9
|
+
overlayOptionRowQuotes,
|
|
10
|
+
} from "./live-quotes";
|
|
11
|
+
|
|
12
|
+
function contract(strike: number, side: "C" | "P"): OptionContract {
|
|
13
|
+
return {
|
|
14
|
+
contractSymbol: `AAPL260731${side}${String(strike * 1000).padStart(8, "0")}`,
|
|
15
|
+
strike,
|
|
16
|
+
currency: "USD",
|
|
17
|
+
lastPrice: 1,
|
|
18
|
+
change: 0,
|
|
19
|
+
percentChange: 0,
|
|
20
|
+
volume: 10,
|
|
21
|
+
openInterest: 20,
|
|
22
|
+
bid: 0.9,
|
|
23
|
+
ask: 1.1,
|
|
24
|
+
impliedVolatility: 0.25,
|
|
25
|
+
inTheMoney: false,
|
|
26
|
+
expiration: 1_785_456_000,
|
|
27
|
+
lastTradeDate: 1_785_000_000,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function row(strike: number): OptionTableRow {
|
|
32
|
+
return {
|
|
33
|
+
strike,
|
|
34
|
+
call: contract(strike, "C"),
|
|
35
|
+
put: contract(strike, "P"),
|
|
36
|
+
isPositionStrike: false,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function readyQuote(quote: Quote): QueryEntry<Quote> {
|
|
41
|
+
return {
|
|
42
|
+
phase: "ready",
|
|
43
|
+
data: quote,
|
|
44
|
+
lastGoodData: quote,
|
|
45
|
+
source: quote.providerId ?? null,
|
|
46
|
+
fetchedAt: quote.lastUpdated,
|
|
47
|
+
staleAt: null,
|
|
48
|
+
error: null,
|
|
49
|
+
attempts: [],
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
describe("options live quotes", () => {
|
|
54
|
+
test("bounds selected-expiry subscriptions around the current strike", () => {
|
|
55
|
+
const rows = Array.from({ length: 100 }, (_, index) => row(50 + index));
|
|
56
|
+
const targets = buildOptionQuoteTargets(rows, 50, 14);
|
|
57
|
+
|
|
58
|
+
expect(targets).toHaveLength(16);
|
|
59
|
+
expect(
|
|
60
|
+
targets.every(
|
|
61
|
+
(target) => target.exchange === "OPTIONS" && target.surface === "options" && target.visible === true,
|
|
62
|
+
),
|
|
63
|
+
).toBe(true);
|
|
64
|
+
expect(targets.filter((target) => target.selected)).toHaveLength(2);
|
|
65
|
+
expect(targets.some((target) => target.symbol === rows[50]!.call!.contractSymbol)).toBe(true);
|
|
66
|
+
expect(targets.some((target) => target.symbol === rows[0]!.call!.contractSymbol)).toBe(false);
|
|
67
|
+
expect(targets.some((target) => target.symbol === rows.at(-1)!.put!.contractSymbol)).toBe(false);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test("overlays streamed quote fields while preserving chain-only Greeks and open interest", () => {
|
|
71
|
+
const original = row(100);
|
|
72
|
+
const symbol = original.call!.contractSymbol;
|
|
73
|
+
const quote: Quote = {
|
|
74
|
+
symbol,
|
|
75
|
+
providerId: "gloomberb-cloud",
|
|
76
|
+
price: 2.4,
|
|
77
|
+
mark: 2.5,
|
|
78
|
+
bid: 2.45,
|
|
79
|
+
ask: 2.55,
|
|
80
|
+
currency: "USD",
|
|
81
|
+
change: 0,
|
|
82
|
+
changePercent: 0,
|
|
83
|
+
lastUpdated: 1_800_000_000_000,
|
|
84
|
+
receivedAt: 1_800_000_010_000,
|
|
85
|
+
dataSource: "live",
|
|
86
|
+
delivery: "stream",
|
|
87
|
+
};
|
|
88
|
+
const entries = new Map([[buildOptionQuoteKey(symbol), readyQuote(quote)]]);
|
|
89
|
+
const freshness = {
|
|
90
|
+
chainAsOf: new Date(1_799_999_000_000).toISOString(),
|
|
91
|
+
chainDataSource: "live" as const,
|
|
92
|
+
now: 1_800_000_030_000,
|
|
93
|
+
subscriptionStartedAt: 1_799_999_500_000,
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const overlaid = overlayOptionRowQuotes([original], entries, freshness)[0]!.call!;
|
|
97
|
+
|
|
98
|
+
expect(overlaid).toMatchObject({
|
|
99
|
+
lastPrice: 2.5,
|
|
100
|
+
bid: 2.45,
|
|
101
|
+
ask: 2.55,
|
|
102
|
+
lastUpdated: 1_800_000_000_000,
|
|
103
|
+
impliedVolatility: 0.25,
|
|
104
|
+
openInterest: 20,
|
|
105
|
+
});
|
|
106
|
+
expect(hasLiveOptionQuote(entries, freshness)).toBe(true);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
test("rejects cached quotes from before this subscription or the current chain", () => {
|
|
110
|
+
const original = row(100);
|
|
111
|
+
const symbol = original.call!.contractSymbol;
|
|
112
|
+
const quote: Quote = {
|
|
113
|
+
symbol,
|
|
114
|
+
providerId: "gloomberb-cloud",
|
|
115
|
+
price: 9,
|
|
116
|
+
mark: 9,
|
|
117
|
+
bid: 8.9,
|
|
118
|
+
ask: 9.1,
|
|
119
|
+
currency: "USD",
|
|
120
|
+
change: 0,
|
|
121
|
+
changePercent: 0,
|
|
122
|
+
lastUpdated: 1_800_000_000_000,
|
|
123
|
+
receivedAt: 1_800_000_010_000,
|
|
124
|
+
dataSource: "live",
|
|
125
|
+
};
|
|
126
|
+
const entries = new Map([[buildOptionQuoteKey(symbol), readyQuote(quote)]]);
|
|
127
|
+
|
|
128
|
+
const beforeSubscription = {
|
|
129
|
+
chainAsOf: new Date(1_799_999_000_000).toISOString(),
|
|
130
|
+
now: 1_800_000_030_000,
|
|
131
|
+
subscriptionStartedAt: 1_800_000_020_000,
|
|
132
|
+
};
|
|
133
|
+
expect(overlayOptionRowQuotes([original], entries, beforeSubscription)[0]!.call!.lastPrice).toBe(1);
|
|
134
|
+
expect(hasLiveOptionQuote(entries, beforeSubscription)).toBe(false);
|
|
135
|
+
|
|
136
|
+
const olderThanChain = {
|
|
137
|
+
chainAsOf: new Date(1_800_000_005_000).toISOString(),
|
|
138
|
+
chainDataSource: "live" as const,
|
|
139
|
+
now: 1_800_000_030_000,
|
|
140
|
+
subscriptionStartedAt: 1_800_000_000_000,
|
|
141
|
+
};
|
|
142
|
+
expect(overlayOptionRowQuotes([original], entries, olderThanChain)[0]!.call!.lastPrice).toBe(1);
|
|
143
|
+
expect(hasLiveOptionQuote(entries, olderThanChain)).toBe(false);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
test("accepts a freshly delivered delayed quote older than the delayed chain fetch", () => {
|
|
147
|
+
const original = row(100);
|
|
148
|
+
const symbol = original.call!.contractSymbol;
|
|
149
|
+
const quote: Quote = {
|
|
150
|
+
symbol,
|
|
151
|
+
providerId: "gloomberb-cloud",
|
|
152
|
+
price: 2.2,
|
|
153
|
+
mark: 2.25,
|
|
154
|
+
bid: 2.2,
|
|
155
|
+
ask: 2.3,
|
|
156
|
+
currency: "USD",
|
|
157
|
+
change: 0,
|
|
158
|
+
changePercent: 0,
|
|
159
|
+
lastUpdated: 1_800_000_000_000,
|
|
160
|
+
receivedAt: 1_800_000_910_000,
|
|
161
|
+
dataSource: "delayed",
|
|
162
|
+
delivery: "poll",
|
|
163
|
+
stale: false,
|
|
164
|
+
};
|
|
165
|
+
const entries = new Map([[buildOptionQuoteKey(symbol), readyQuote(quote)]]);
|
|
166
|
+
const freshness = {
|
|
167
|
+
chainAsOf: new Date(1_800_000_900_000).toISOString(),
|
|
168
|
+
chainDataSource: "delayed" as const,
|
|
169
|
+
now: 1_800_000_930_000,
|
|
170
|
+
subscriptionStartedAt: 1_800_000_905_000,
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
expect(overlayOptionRowQuotes([original], entries, freshness)[0]!.call!.lastPrice).toBe(2.25);
|
|
174
|
+
expect(hasLiveOptionQuote(entries, freshness)).toBe(false);
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
test("overlays a valid polled quote without reporting a live stream", () => {
|
|
178
|
+
const original = row(100);
|
|
179
|
+
const symbol = original.call!.contractSymbol;
|
|
180
|
+
const quote: Quote = {
|
|
181
|
+
symbol,
|
|
182
|
+
providerId: "gloomberb-cloud",
|
|
183
|
+
price: 2.4,
|
|
184
|
+
mark: 2.5,
|
|
185
|
+
bid: 2.45,
|
|
186
|
+
ask: 2.55,
|
|
187
|
+
currency: "USD",
|
|
188
|
+
change: 0,
|
|
189
|
+
changePercent: 0,
|
|
190
|
+
lastUpdated: 1_800_000_000_000,
|
|
191
|
+
receivedAt: 1_800_000_010_000,
|
|
192
|
+
dataSource: "live",
|
|
193
|
+
delivery: "poll",
|
|
194
|
+
stale: false,
|
|
195
|
+
};
|
|
196
|
+
const entries = new Map([[buildOptionQuoteKey(symbol), readyQuote(quote)]]);
|
|
197
|
+
const freshness = {
|
|
198
|
+
chainAsOf: new Date(1_799_999_000_000).toISOString(),
|
|
199
|
+
chainDataSource: "live" as const,
|
|
200
|
+
now: 1_800_000_030_000,
|
|
201
|
+
subscriptionStartedAt: 1_799_999_500_000,
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
expect(overlayOptionRowQuotes([original], entries, freshness)[0]!.call!.lastPrice).toBe(2.5);
|
|
205
|
+
expect(hasLiveOptionQuote(entries, freshness)).toBe(false);
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
test("rejects a freshly received quote marked stale by the server", () => {
|
|
209
|
+
const original = row(100);
|
|
210
|
+
const symbol = original.call!.contractSymbol;
|
|
211
|
+
const quote: Quote = {
|
|
212
|
+
symbol,
|
|
213
|
+
providerId: "gloomberb-cloud",
|
|
214
|
+
price: 9,
|
|
215
|
+
mark: 9,
|
|
216
|
+
bid: 8.9,
|
|
217
|
+
ask: 9.1,
|
|
218
|
+
currency: "USD",
|
|
219
|
+
change: 0,
|
|
220
|
+
changePercent: 0,
|
|
221
|
+
lastUpdated: 1_800_000_900_000,
|
|
222
|
+
receivedAt: 1_800_000_910_000,
|
|
223
|
+
dataSource: "live",
|
|
224
|
+
delivery: "poll",
|
|
225
|
+
stale: true,
|
|
226
|
+
};
|
|
227
|
+
const entries = new Map([[buildOptionQuoteKey(symbol), readyQuote(quote)]]);
|
|
228
|
+
const freshness = {
|
|
229
|
+
chainAsOf: new Date(1_800_000_800_000).toISOString(),
|
|
230
|
+
chainDataSource: "live" as const,
|
|
231
|
+
now: 1_800_000_930_000,
|
|
232
|
+
subscriptionStartedAt: 1_800_000_905_000,
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
expect(overlayOptionRowQuotes([original], entries, freshness)[0]!.call!.lastPrice).toBe(1);
|
|
236
|
+
expect(hasLiveOptionQuote(entries, freshness)).toBe(false);
|
|
237
|
+
});
|
|
238
|
+
});
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import type { QuoteSubscriptionTarget } from "../../../types/data-provider";
|
|
2
|
+
import type { OptionContract, Quote } from "../../../types/financials";
|
|
3
|
+
import { buildQuoteKey, resolveEntryData } from "../../../market-data/selectors";
|
|
4
|
+
import type { QueryEntry } from "../../../market-data/result-types";
|
|
5
|
+
import type { OptionTableRow } from "./types";
|
|
6
|
+
|
|
7
|
+
export const OPTIONS_QUOTE_EXCHANGE = "OPTIONS";
|
|
8
|
+
export const OPTIONS_CHAIN_REFRESH_INTERVAL_MS = 10 * 60_000;
|
|
9
|
+
export const OPTIONS_STREAM_FRESHNESS_MS = 2 * 60_000;
|
|
10
|
+
|
|
11
|
+
const OPTIONS_STREAM_MAX_TARGETS = 16;
|
|
12
|
+
const OPTIONS_STREAM_MAX_ROWS = OPTIONS_STREAM_MAX_TARGETS / 2;
|
|
13
|
+
const OPTIONS_STREAM_OVERSCAN_ROWS = 4;
|
|
14
|
+
|
|
15
|
+
export interface OptionsQuoteFreshness {
|
|
16
|
+
chainAsOf?: string;
|
|
17
|
+
chainDataSource?: "live" | "delayed";
|
|
18
|
+
now: number;
|
|
19
|
+
subscriptionStartedAt: number;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function isFiniteNumber(value: number | undefined): value is number {
|
|
23
|
+
return typeof value === "number" && Number.isFinite(value);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function optionStreamRowCount(height: number): number {
|
|
27
|
+
const visibleRows = Math.max(1, Math.floor(height) - 3);
|
|
28
|
+
return Math.min(
|
|
29
|
+
OPTIONS_STREAM_MAX_ROWS,
|
|
30
|
+
visibleRows + OPTIONS_STREAM_OVERSCAN_ROWS,
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function optionStreamWindow(totalRows: number, selectedIndex: number, height: number): [number, number] {
|
|
35
|
+
const count = Math.min(totalRows, optionStreamRowCount(height));
|
|
36
|
+
const clampedIndex = Math.max(0, Math.min(selectedIndex, Math.max(0, totalRows - 1)));
|
|
37
|
+
const start = Math.max(0, Math.min(clampedIndex - Math.floor(count / 2), totalRows - count));
|
|
38
|
+
return [start, start + count];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function buildOptionQuoteTargets(
|
|
42
|
+
rows: readonly OptionTableRow[],
|
|
43
|
+
selectedIndex: number,
|
|
44
|
+
height: number,
|
|
45
|
+
): QuoteSubscriptionTarget[] {
|
|
46
|
+
if (rows.length === 0) return [];
|
|
47
|
+
const [start, end] = optionStreamWindow(rows.length, selectedIndex, height);
|
|
48
|
+
const targets = new Map<string, QuoteSubscriptionTarget>();
|
|
49
|
+
|
|
50
|
+
for (let index = start; index < end; index += 1) {
|
|
51
|
+
const row = rows[index];
|
|
52
|
+
if (!row) continue;
|
|
53
|
+
const selected = index === selectedIndex;
|
|
54
|
+
const distance = Math.abs(index - selectedIndex);
|
|
55
|
+
for (const contract of [row.call, row.put]) {
|
|
56
|
+
const symbol = contract?.contractSymbol.trim().toUpperCase();
|
|
57
|
+
if (!symbol) continue;
|
|
58
|
+
targets.set(symbol, {
|
|
59
|
+
symbol,
|
|
60
|
+
exchange: OPTIONS_QUOTE_EXCHANGE,
|
|
61
|
+
surface: "options",
|
|
62
|
+
visible: true,
|
|
63
|
+
selected,
|
|
64
|
+
weight: Math.max(50, 100 - distance),
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return [...targets.values()];
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function buildOptionQuoteKey(contractSymbol: string): string {
|
|
73
|
+
return buildQuoteKey({
|
|
74
|
+
symbol: contractSymbol,
|
|
75
|
+
exchange: OPTIONS_QUOTE_EXCHANGE,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function overlayOptionContractQuote(
|
|
80
|
+
contract: OptionContract | undefined,
|
|
81
|
+
quote: Quote | null | undefined,
|
|
82
|
+
): OptionContract | undefined {
|
|
83
|
+
if (!contract || !quote) return contract;
|
|
84
|
+
if (contract.lastUpdated != null && quote.lastUpdated < contract.lastUpdated) return contract;
|
|
85
|
+
|
|
86
|
+
const streamedPrice = isFiniteNumber(quote.mark) ? quote.mark : quote.price;
|
|
87
|
+
return {
|
|
88
|
+
...contract,
|
|
89
|
+
lastPrice: isFiniteNumber(streamedPrice) ? streamedPrice : contract.lastPrice,
|
|
90
|
+
bid: isFiniteNumber(quote.bid) ? quote.bid : contract.bid,
|
|
91
|
+
ask: isFiniteNumber(quote.ask) ? quote.ask : contract.ask,
|
|
92
|
+
lastUpdated: quote.lastUpdated,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function freshOptionQuote(entry: QueryEntry<Quote> | undefined, freshness: OptionsQuoteFreshness): Quote | null {
|
|
97
|
+
const quote = resolveEntryData(entry);
|
|
98
|
+
if (!quote || quote.stale === true) return null;
|
|
99
|
+
const receivedAt = quote.receivedAt ?? 0;
|
|
100
|
+
if (
|
|
101
|
+
!Number.isFinite(receivedAt) ||
|
|
102
|
+
receivedAt <= freshness.subscriptionStartedAt ||
|
|
103
|
+
freshness.now - receivedAt > OPTIONS_STREAM_FRESHNESS_MS
|
|
104
|
+
) {
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
const chainAsOf = freshness.chainAsOf ? Date.parse(freshness.chainAsOf) : Number.NaN;
|
|
108
|
+
if (
|
|
109
|
+
freshness.chainDataSource === "live" &&
|
|
110
|
+
quote.dataSource === "live" &&
|
|
111
|
+
Number.isFinite(chainAsOf) &&
|
|
112
|
+
Number.isFinite(quote.lastUpdated) &&
|
|
113
|
+
quote.lastUpdated < chainAsOf
|
|
114
|
+
) {
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
return quote;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export function overlayOptionRowQuotes(
|
|
121
|
+
rows: readonly OptionTableRow[],
|
|
122
|
+
quoteEntries: ReadonlyMap<string, QueryEntry<Quote>>,
|
|
123
|
+
freshness: OptionsQuoteFreshness,
|
|
124
|
+
): OptionTableRow[] {
|
|
125
|
+
return rows.map((row) => ({
|
|
126
|
+
...row,
|
|
127
|
+
call: overlayOptionContractQuote(
|
|
128
|
+
row.call,
|
|
129
|
+
row.call ? freshOptionQuote(quoteEntries.get(buildOptionQuoteKey(row.call.contractSymbol)), freshness) : null,
|
|
130
|
+
),
|
|
131
|
+
put: overlayOptionContractQuote(
|
|
132
|
+
row.put,
|
|
133
|
+
row.put ? freshOptionQuote(quoteEntries.get(buildOptionQuoteKey(row.put.contractSymbol)), freshness) : null,
|
|
134
|
+
),
|
|
135
|
+
}));
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export function hasLiveOptionQuote(
|
|
139
|
+
quoteEntries: ReadonlyMap<string, QueryEntry<Quote>>,
|
|
140
|
+
freshness: OptionsQuoteFreshness,
|
|
141
|
+
): boolean {
|
|
142
|
+
for (const entry of quoteEntries.values()) {
|
|
143
|
+
const quote = freshOptionQuote(entry, freshness);
|
|
144
|
+
if (quote?.dataSource === "live" && quote.delivery === "stream") return true;
|
|
145
|
+
}
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
@@ -6,7 +6,8 @@ import { MarketDataCoordinator, setSharedMarketDataCoordinator } from "../../../
|
|
|
6
6
|
import { AppContext, PaneInstanceProvider, createInitialState } from "../../../state/app/context";
|
|
7
7
|
import { createTestDataProvider } from "../../../test-support/data-provider";
|
|
8
8
|
import { cloneLayout, createDefaultConfig } from "../../../types/config";
|
|
9
|
-
import type {
|
|
9
|
+
import type { QuoteSubscriptionTarget } from "../../../types/data-provider";
|
|
10
|
+
import type { OptionContract, OptionsChain, Quote, TickerFinancials } from "../../../types/financials";
|
|
10
11
|
import type { TickerRecord } from "../../../types/ticker";
|
|
11
12
|
import { formatExpDate } from "../../../utils/options";
|
|
12
13
|
import { OptionsView } from "./view";
|
|
@@ -163,6 +164,75 @@ test("defaults the table around the nearest strike to the current quote", async
|
|
|
163
164
|
expect(frame).not.toContain(" 50 ");
|
|
164
165
|
});
|
|
165
166
|
|
|
167
|
+
test("streams a bounded options window and overlays live contract quotes", async () => {
|
|
168
|
+
const strikes = Array.from({ length: 100 }, (_, index) => 50 + index);
|
|
169
|
+
const subscriptions: QuoteSubscriptionTarget[][] = [];
|
|
170
|
+
let emitQuote:
|
|
171
|
+
| ((target: QuoteSubscriptionTarget, quote: Quote) => void)
|
|
172
|
+
| null = null;
|
|
173
|
+
const provider = createTestDataProvider({
|
|
174
|
+
getOptionsChain: async () => makeChain(strikes, 120),
|
|
175
|
+
subscribeQuotes: (targets, onQuote) => {
|
|
176
|
+
subscriptions.push(targets);
|
|
177
|
+
emitQuote = onQuote;
|
|
178
|
+
return () => {};
|
|
179
|
+
},
|
|
180
|
+
});
|
|
181
|
+
const coordinator = new MarketDataCoordinator(provider);
|
|
182
|
+
setSharedMarketDataCoordinator(coordinator);
|
|
183
|
+
|
|
184
|
+
await act(async () => {
|
|
185
|
+
testSetup = await testRender(
|
|
186
|
+
<OptionsHarness ticker={makeTicker("AAPL")} quotePrice={120.2} />,
|
|
187
|
+
{
|
|
188
|
+
width: 124,
|
|
189
|
+
height: 16,
|
|
190
|
+
},
|
|
191
|
+
);
|
|
192
|
+
});
|
|
193
|
+
await renderSettled();
|
|
194
|
+
|
|
195
|
+
const targets = subscriptions.at(-1) ?? [];
|
|
196
|
+
expect(targets.length).toBeGreaterThan(0);
|
|
197
|
+
expect(targets.length).toBeLessThanOrEqual(80);
|
|
198
|
+
expect(
|
|
199
|
+
targets.every(
|
|
200
|
+
(target) => target.exchange === "OPTIONS" && target.surface === "options",
|
|
201
|
+
),
|
|
202
|
+
).toBe(true);
|
|
203
|
+
const selectedCall = targets.find(
|
|
204
|
+
(target) => target.symbol === makeContract(120, "C").contractSymbol,
|
|
205
|
+
);
|
|
206
|
+
expect(selectedCall).toMatchObject({ selected: true });
|
|
207
|
+
|
|
208
|
+
await act(async () => {
|
|
209
|
+
emitQuote?.(selectedCall!, {
|
|
210
|
+
symbol: selectedCall!.symbol,
|
|
211
|
+
providerId: "gloomberb-cloud",
|
|
212
|
+
price: 99.9,
|
|
213
|
+
mark: 99.99,
|
|
214
|
+
bid: 99.98,
|
|
215
|
+
ask: 100,
|
|
216
|
+
currency: "USD",
|
|
217
|
+
change: 0,
|
|
218
|
+
changePercent: 0,
|
|
219
|
+
lastUpdated: Date.now(),
|
|
220
|
+
dataSource: "live",
|
|
221
|
+
});
|
|
222
|
+
await Promise.resolve();
|
|
223
|
+
await testSetup!.renderOnce();
|
|
224
|
+
});
|
|
225
|
+
await renderSettled();
|
|
226
|
+
|
|
227
|
+
expect(
|
|
228
|
+
coordinator.getQuoteEntry({
|
|
229
|
+
symbol: selectedCall!.symbol,
|
|
230
|
+
exchange: "OPTIONS",
|
|
231
|
+
}).data?.mark,
|
|
232
|
+
).toBe(99.99);
|
|
233
|
+
expect(testSetup!.captureCharFrame()).toContain("99.99");
|
|
234
|
+
});
|
|
235
|
+
|
|
166
236
|
test("lets the expiration tab row use the full available width", async () => {
|
|
167
237
|
const expirationDates = Array.from({ length: 9 }, (_, index) => (
|
|
168
238
|
Math.floor(Date.UTC(2026, index, 20) / 1000)
|
|
@@ -5,21 +5,27 @@ import { colors } from "../../../theme/colors";
|
|
|
5
5
|
import { isPlainKey } from "../../../utils/keyboard";
|
|
6
6
|
import { formatExpDate, resolveOptionsTarget } from "../../../utils/options";
|
|
7
7
|
import { useOptionsQuery, useResolvedEntryValue } from "../../../market-data/hooks";
|
|
8
|
-
import { DataTableView, Spinner, Tabs,
|
|
8
|
+
import { DataTableView, Spinner, Tabs, type DataTableKeyEvent } from "../../../components";
|
|
9
9
|
import { useShortcut } from "../../../react/input";
|
|
10
|
+
import { useLiveQuoteEntries } from "../../../state/hooks/quote-streaming";
|
|
10
11
|
import {
|
|
11
12
|
OPTION_COLUMNS,
|
|
12
13
|
buildStrikeList,
|
|
13
14
|
findNearestStrikeIndex,
|
|
14
|
-
formatIv,
|
|
15
|
-
formatStrikeLabel,
|
|
16
15
|
optionColumnColor,
|
|
17
16
|
renderOptionCell,
|
|
18
17
|
resolveDefaultStrikeTarget,
|
|
19
18
|
} from "./table";
|
|
20
19
|
import type { OptionColumn, OptionTableRow, OptionsViewProps } from "./types";
|
|
20
|
+
import {
|
|
21
|
+
buildOptionQuoteTargets,
|
|
22
|
+
hasLiveOptionQuote,
|
|
23
|
+
OPTIONS_CHAIN_REFRESH_INTERVAL_MS,
|
|
24
|
+
overlayOptionRowQuotes,
|
|
25
|
+
} from "./live-quotes";
|
|
26
|
+
import { useOptionsAccessFooter } from "./footer";
|
|
21
27
|
|
|
22
|
-
export function OptionsView({ width, focused, onCapture = () => {} }: OptionsViewProps) {
|
|
28
|
+
export function OptionsView({ width, height, focused, onCapture = () => {} }: OptionsViewProps) {
|
|
23
29
|
const { ticker, financials } = usePaneTicker();
|
|
24
30
|
const [expIdx, setExpIdx] = useState(0);
|
|
25
31
|
const [strikeIdx, setStrikeIdx] = useState(0);
|
|
@@ -52,6 +58,7 @@ export function OptionsView({ width, focused, onCapture = () => {} }: OptionsVie
|
|
|
52
58
|
baseRequest && selectedExpiration != null
|
|
53
59
|
? { ...baseRequest, expirationDate: selectedExpiration }
|
|
54
60
|
: null,
|
|
61
|
+
{ refreshIntervalMs: OPTIONS_CHAIN_REFRESH_INTERVAL_MS },
|
|
55
62
|
);
|
|
56
63
|
const expirationChain = useResolvedEntryValue(expirationChainEntry);
|
|
57
64
|
const chain = expirationChain ?? initialChain;
|
|
@@ -118,38 +125,46 @@ export function OptionsView({ width, focused, onCapture = () => {} }: OptionsVie
|
|
|
118
125
|
() => new Map(chain?.puts.map((p) => [p.strike, p]) ?? []),
|
|
119
126
|
[chain],
|
|
120
127
|
);
|
|
121
|
-
const
|
|
128
|
+
const snapshotRows = useMemo<OptionTableRow[]>(() => strikes.map((strike) => ({
|
|
122
129
|
strike,
|
|
123
130
|
call: callsByStrike.get(strike),
|
|
124
131
|
put: putsByStrike.get(strike),
|
|
125
132
|
isPositionStrike: !!parsed && Math.abs(strike - parsed.strike) < 0.01,
|
|
126
133
|
})), [callsByStrike, parsed, putsByStrike, strikes]);
|
|
127
|
-
const
|
|
128
|
-
|
|
129
|
-
|
|
134
|
+
const optionQuoteTargets = useMemo(
|
|
135
|
+
() => buildOptionQuoteTargets(snapshotRows, strikeIdx, height),
|
|
136
|
+
[height, snapshotRows, strikeIdx],
|
|
137
|
+
);
|
|
138
|
+
const {
|
|
139
|
+
entries: optionQuoteEntries,
|
|
140
|
+
freshnessNow,
|
|
141
|
+
subscriptionStartedAt,
|
|
142
|
+
} = useLiveQuoteEntries(optionQuoteTargets);
|
|
143
|
+
const optionQuoteFreshness = useMemo(
|
|
144
|
+
() => ({
|
|
145
|
+
chainAsOf: chain?.asOf,
|
|
146
|
+
chainDataSource: chain?.dataSource,
|
|
147
|
+
now: freshnessNow,
|
|
148
|
+
subscriptionStartedAt,
|
|
149
|
+
}),
|
|
150
|
+
[chain?.asOf, chain?.dataSource, freshnessNow, subscriptionStartedAt],
|
|
151
|
+
);
|
|
152
|
+
const rows = useMemo(
|
|
153
|
+
() => overlayOptionRowQuotes(snapshotRows, optionQuoteEntries, optionQuoteFreshness),
|
|
154
|
+
[optionQuoteEntries, optionQuoteFreshness, snapshotRows],
|
|
155
|
+
);
|
|
130
156
|
const optionColumns: OptionColumn[] = OPTION_COLUMNS.map((column) => ({
|
|
131
157
|
...column,
|
|
132
158
|
headerColor: optionColumnColor(column.id, colors.panel),
|
|
133
159
|
}));
|
|
134
160
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
...(selectedExpiration != null ? [{ id: "exp", parts: [{ text: formatExpDate(selectedExpiration), tone: "muted" as const }] }] : []),
|
|
138
|
-
...(selectedStrike != null ? [{ id: "strike", parts: [{ text: `Strike ${formatStrikeLabel(selectedStrike)}`, tone: "value" as const, bold: true }] }] : []),
|
|
139
|
-
...(selectedCall ? [{ id: "call-iv", parts: [{ text: "Call IV", tone: "label" as const }, { text: formatIv(selectedCall.impliedVolatility), tone: "value" as const }] }] : []),
|
|
140
|
-
...(selectedPut ? [{ id: "put-iv", parts: [{ text: "Put IV", tone: "label" as const }, { text: formatIv(selectedPut.impliedVolatility), tone: "value" as const }] }] : []),
|
|
141
|
-
...(loading ? [{ id: "loading", parts: [{ text: "loading", tone: "muted" as const }] }] : []),
|
|
142
|
-
...(error ? [{ id: "error", parts: [{ text: "error", tone: "warning" as const }] }] : []),
|
|
143
|
-
];
|
|
144
|
-
return info.length > 0 ? { info } : null;
|
|
145
|
-
}, [
|
|
161
|
+
useOptionsAccessFooter({
|
|
162
|
+
chain,
|
|
146
163
|
error,
|
|
164
|
+
focused,
|
|
165
|
+
hasLiveQuote: hasLiveOptionQuote(optionQuoteEntries, optionQuoteFreshness),
|
|
147
166
|
loading,
|
|
148
|
-
|
|
149
|
-
selectedExpiration,
|
|
150
|
-
selectedPut?.impliedVolatility,
|
|
151
|
-
selectedStrike,
|
|
152
|
-
]);
|
|
167
|
+
});
|
|
153
168
|
|
|
154
169
|
useEffect(() => {
|
|
155
170
|
setStrikeIdx((index) => {
|