gloomberb 0.10.4 → 0.11.0
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/LICENSE +1 -1
- package/README.md +30 -3
- package/README.zh-CN.md +1 -1
- package/package.json +5 -5
- package/src/api-client/auth.ts +34 -0
- package/src/api-client/data.ts +25 -0
- package/src/api-client/index.test.ts +81 -0
- package/src/api-client/index.ts +37 -0
- package/src/api-client/request.test.ts +30 -0
- package/src/api-client/request.ts +44 -20
- package/src/api-client/socket-health.test.ts +79 -0
- package/src/api-client/socket.ts +108 -5
- package/src/api-client/types.ts +139 -0
- package/src/app/global-shortcuts.test.tsx +144 -9
- package/src/app/global-shortcuts.ts +33 -11
- package/src/app/runtime/broker-import.ts +39 -5
- package/src/app/runtime/startup.ts +7 -1
- package/src/app/runtime/update.ts +26 -1
- package/src/app.tsx +36 -19
- package/src/brokers/broker-ticker-sync.ts +3 -8
- package/src/brokers/sync-broker-instance.test.ts +59 -0
- package/src/brokers/sync-broker-instance.ts +37 -13
- package/src/capabilities/chart-series.ts +318 -0
- package/src/capabilities/factories.ts +46 -0
- package/src/capabilities/index.ts +1 -0
- package/src/capabilities/registry.test.ts +135 -0
- package/src/capabilities/registry.ts +31 -4
- package/src/capabilities/types.ts +52 -0
- package/src/cli/commands/overview.ts +2 -2
- package/src/cli/desktop-pane-shot.ts +2 -0
- package/src/cli/entry.ts +11 -1
- package/src/cli/native-smoke.ts +5 -0
- package/src/cli/pane-functions/catalog.ts +4 -0
- package/src/cli/pane-functions/data.ts +6 -1
- package/src/cli/pane-functions/discovery.ts +76 -10
- package/src/cli/pane-functions/report.test.ts +76 -0
- package/src/cli/pane-functions/report.ts +7 -1
- package/src/cli/pane-functions/resolver.ts +4 -1
- package/src/cli/pane-functions/screenshot.test.ts +56 -3
- package/src/cli/pane-functions/screenshot.ts +68 -5
- package/src/components/chart/composite/composite-chart.test.tsx +54 -0
- package/src/components/chart/composite/composite-chart.tsx +92 -15
- package/src/components/chart/composite/downsample.test.ts +136 -0
- package/src/components/chart/composite/downsample.ts +208 -0
- package/src/components/chart/composite/panel-series.test.ts +66 -0
- package/src/components/chart/composite/panel-series.ts +101 -0
- package/src/components/chart/multi-line/renderer.ts +1 -0
- package/src/components/chart/native/kitty/index.test.ts +25 -3
- package/src/components/chart/native/kitty/support.ts +37 -3
- package/src/components/chart/native/use-chart-text-fallback.ts +19 -0
- package/src/components/chart/static/chart/surface.tsx +43 -12
- package/src/components/chart/static/multi-line-chart-surface.tsx +41 -5
- package/src/components/command-bar/commands/direct/index.ts +18 -0
- package/src/components/command-bar/commands/registry.ts +14 -0
- package/src/components/command-bar/routes/root/article-results.test.ts +83 -0
- package/src/components/command-bar/routes/root/article-results.ts +55 -0
- package/src/components/command-bar/routes/root/command-items.ts +3 -0
- package/src/components/command-bar/routes/root/provider-search.ts +7 -3
- package/src/components/command-bar/routes/root/results.ts +38 -11
- package/src/components/command-bar/routes/root/runtime.ts +6 -2
- package/src/components/command-bar/routes/ticker-search/actions.ts +1 -1
- package/src/components/command-bar/routes/ticker-search/results.test.ts +34 -0
- package/src/components/command-bar/routes/ticker-search/results.ts +4 -6
- package/src/components/command-bar/routes/ticker-search/route.ts +2 -2
- package/src/components/command-bar/routing/list-state.ts +2 -1
- package/src/components/command-bar/surface/assist.test.tsx +13 -6
- package/src/components/command-bar/surface/index.test.tsx +65 -0
- package/src/components/command-bar/surface/index.tsx +35 -0
- package/src/components/command-bar/view-model.test.ts +43 -0
- package/src/components/command-bar/view-model.ts +41 -4
- package/src/components/command-bar/workflow/collection-actions.test.ts +94 -0
- package/src/components/command-bar/workflow/collection-actions.ts +14 -3
- package/src/components/command-bar/workflow/ops.test.ts +136 -0
- package/src/components/command-bar/workflow/ops.ts +71 -1
- package/src/components/index.ts +1 -1
- package/src/components/layout/header.test.tsx +35 -0
- package/src/components/layout/header.tsx +101 -9
- package/src/components/layout/pane/cycle-order.test.ts +0 -1
- package/src/components/layout/pane/footer/index.test.tsx +19 -19
- package/src/components/layout/pane/header.tsx +2 -13
- package/src/components/layout/shell/index.tsx +3 -0
- package/src/components/layout/status-bar.test.tsx +36 -1
- package/src/components/layout/status-bar.tsx +48 -2
- package/src/components/onboarding/account-step/chooser-panel.tsx +27 -50
- package/src/components/onboarding/account-step/form-panel.tsx +85 -29
- package/src/components/onboarding/account-step/index.tsx +10 -1
- package/src/components/onboarding/account-step/model.ts +3 -3
- package/src/components/onboarding/account-step/qr-panel.tsx +68 -0
- package/src/components/onboarding/account-step/signed-in-panel.tsx +4 -7
- package/src/components/onboarding/onboarding-frame.tsx +517 -0
- package/src/components/onboarding/onboarding-steps.tsx +0 -264
- package/src/components/onboarding/onboarding-wizard.test.tsx +626 -200
- package/src/components/onboarding/onboarding-wizard.tsx +848 -266
- package/src/components/onboarding/portfolio-step/broker-fields-panel.tsx +81 -51
- package/src/components/onboarding/portfolio-step/broker-setup-panel.tsx +14 -20
- package/src/components/onboarding/portfolio-step/broker-sync-panel.tsx +8 -11
- package/src/components/onboarding/portfolio-step/choose-panel.tsx +18 -22
- package/src/components/onboarding/portfolio-step/index.tsx +3 -0
- package/src/components/onboarding/portfolio-step/types.ts +3 -0
- package/src/components/onboarding/wizard-account.ts +38 -3
- package/src/components/onboarding/wizard-broker-sync.ts +45 -67
- package/src/components/onboarding/wizard-model.ts +18 -2
- package/src/components/ui/data-table/opentui/index.tsx +29 -9
- package/src/components/ui/data-table/types.ts +2 -0
- package/src/components/ui/external-link.tsx +4 -2
- package/src/components/ui/loading.tsx +1 -1
- package/src/components/ui/status.tsx +76 -4
- package/src/components/ui/table-layout.test.ts +24 -0
- package/src/components/ui/table-layout.ts +90 -23
- package/src/components/ui/tabs.tsx +86 -4
- package/src/core/app-services.ts +14 -3
- package/src/core/connection-health.test.ts +143 -0
- package/src/core/connection-health.ts +295 -0
- package/src/core/state/app/layout-reducer.ts +34 -0
- package/src/core/state/app/layout.ts +21 -0
- package/src/core/state/app/state.ts +10 -0
- package/src/core/state/app/types.ts +7 -1
- package/src/data/config/chart-settings.ts +11 -2
- package/src/data/config/store/index.test.ts +83 -9
- package/src/data/config/store/migrations.ts +16 -0
- package/src/data/config/store/normalize.ts +59 -1
- package/src/data/fred-series.ts +8 -2
- package/src/i18n/es.ts +126 -0
- package/src/i18n/ja.ts +126 -0
- package/src/i18n/ko.ts +126 -0
- package/src/i18n/zh-cn.ts +126 -0
- package/src/i18n/zh-tw.ts +126 -0
- package/src/market-data/coordinator/chart.ts +3 -2
- package/src/market-data/hooks.tsx +3 -2
- package/src/market-data/market/status.test.ts +12 -0
- package/src/market-data/market/status.ts +34 -17
- package/src/news/aggregator.test.ts +39 -0
- package/src/news/aggregator.ts +78 -22
- package/src/news/hooks.ts +4 -0
- package/src/notifications/app-notifier.test.ts +28 -6
- package/src/notifications/app-notifier.ts +24 -5
- package/src/plugins/broker-sync/broker-sync.test.ts +130 -0
- package/src/plugins/broker-sync/native-loader.ts +10 -0
- package/src/plugins/broker-sync/normalize.ts +271 -0
- package/src/plugins/broker-sync/public.ts +122 -0
- package/src/plugins/broker-sync/robinhood-native.ts +367 -0
- package/src/plugins/broker-sync/robinhood.ts +114 -0
- package/src/plugins/broker-sync/simplefin-native.ts +201 -0
- package/src/plugins/broker-sync/simplefin.ts +70 -0
- package/src/plugins/builtin/account-management/footer.ts +8 -19
- package/src/plugins/builtin/account-management/pane.tsx +13 -8
- package/src/plugins/builtin/ai/pi/host.ts +6 -5
- package/src/plugins/builtin/ai/providers.ts +1 -1
- package/src/plugins/builtin/ai/screener/footer.ts +0 -7
- package/src/plugins/builtin/ai/screener/pane.test.tsx +2 -1
- package/src/plugins/builtin/ai/screener/pane.tsx +3 -1
- package/src/plugins/builtin/ai/screener/results-view.tsx +8 -0
- package/src/plugins/builtin/ai/screener/runner.ts +7 -3
- package/src/plugins/builtin/ai/workspace/pane.tsx +13 -2
- package/src/plugins/builtin/alerts/alert-engine.ts +13 -0
- package/src/plugins/builtin/alerts/constants.ts +2 -1
- package/src/plugins/builtin/alerts/index.tsx +67 -36
- package/src/plugins/builtin/alerts/pane.tsx +17 -65
- package/src/plugins/builtin/analytics/index.tsx +24 -11
- package/src/plugins/builtin/analytics/pane-model.ts +48 -14
- package/src/plugins/builtin/analytics/portfolio-selection.ts +19 -0
- package/src/plugins/builtin/analytics/view.tsx +5 -3
- package/src/plugins/builtin/broker-manager/detail.tsx +7 -2
- package/src/plugins/builtin/broker-manager/footer.ts +4 -9
- package/src/plugins/builtin/broker-manager/index.tsx +1 -6
- package/src/plugins/builtin/buildout/detail/ui.tsx +15 -4
- package/src/plugins/builtin/buildout/pane/header.tsx +1 -0
- package/src/plugins/builtin/changelog/index.tsx +60 -45
- package/src/plugins/builtin/chart-composer/catalog-inventory.test.ts +97 -0
- package/src/plugins/builtin/chart-composer/catalog-inventory.ts +366 -0
- package/src/plugins/builtin/chart-composer/chart-spec.ts +21 -1
- package/src/plugins/builtin/chart-composer/data-catalog-pane.tsx +307 -0
- package/src/plugins/builtin/chart-composer/editor/controller.ts +1 -1
- package/src/plugins/builtin/chart-composer/index.tsx +45 -5
- package/src/plugins/builtin/chart-composer/pane.tsx +7 -88
- package/src/plugins/builtin/chart-composer/presets.test.ts +48 -0
- package/src/plugins/builtin/chart-composer/presets.ts +69 -3
- package/src/plugins/builtin/chart-composer/quick-add.tsx +8 -5
- package/src/plugins/builtin/chart-composer/semantic.ts +18 -14
- package/src/plugins/builtin/chart-composer/series-catalog.test.ts +39 -0
- package/src/plugins/builtin/chart-composer/series-catalog.ts +104 -3
- package/src/plugins/builtin/chart-composer/shortcuts.test.ts +10 -10
- package/src/plugins/builtin/chart-composer/shortcuts.ts +4 -12
- package/src/plugins/builtin/chart-composer/use-series-catalog.ts +230 -23
- package/src/plugins/builtin/chat/chat.test.tsx +22 -0
- package/src/plugins/builtin/chat/content/composer.tsx +6 -4
- package/src/plugins/builtin/chat/content/index.tsx +7 -0
- package/src/plugins/builtin/chat/content/snapshot.ts +9 -2
- package/src/plugins/builtin/chat/content/transcript.tsx +10 -0
- package/src/plugins/builtin/chat/controller/channel-actions.ts +11 -1
- package/src/plugins/builtin/chat/controller/channels.ts +13 -3
- package/src/plugins/builtin/chat/controller/index.ts +61 -7
- package/src/plugins/builtin/chat/controller/lifecycle.ts +3 -0
- package/src/plugins/builtin/chat/controller/message-loading.ts +5 -1
- package/src/plugins/builtin/chat/controller/messages.ts +3 -1
- package/src/plugins/builtin/chat/controller/notifications.ts +32 -11
- package/src/plugins/builtin/chat/controller/state.ts +7 -0
- package/src/plugins/builtin/chat/controller/view.ts +1 -0
- package/src/plugins/builtin/chat/controller.test.ts +117 -28
- package/src/plugins/builtin/cloud/auth-commands.ts +18 -0
- package/src/plugins/builtin/cloud/device-signin-dialog.tsx +243 -0
- package/src/plugins/builtin/cloud/device-signin.test.ts +217 -0
- package/src/plugins/builtin/cloud/device-signin.ts +240 -0
- package/src/plugins/builtin/cloud/plugin.tsx +7 -1
- package/src/plugins/builtin/cloud-tweets/table.tsx +57 -10
- package/src/plugins/builtin/composite-plugins.ts +39 -5
- package/src/plugins/builtin/congress-trades/detail.tsx +2 -4
- package/src/plugins/builtin/congress-trades/footer.ts +7 -16
- package/src/plugins/builtin/congress-trades/pane.tsx +12 -20
- package/src/plugins/builtin/connections/index.ts +53 -0
- package/src/plugins/builtin/connections/pane.test.tsx +79 -0
- package/src/plugins/builtin/connections/pane.tsx +258 -0
- package/src/plugins/builtin/correlation/index.test.tsx +2 -1
- package/src/plugins/builtin/correlation/index.tsx +58 -19
- package/src/plugins/builtin/correlation/matrix/model.ts +18 -7
- package/src/plugins/builtin/correlation/relationship/pane.tsx +43 -19
- package/src/plugins/builtin/correlation/settings.ts +1 -1
- package/src/plugins/builtin/credit-conditions/client.test.ts +80 -0
- package/src/plugins/builtin/credit-conditions/client.ts +105 -0
- package/src/plugins/builtin/credit-conditions/index.test.tsx +111 -0
- package/src/plugins/builtin/credit-conditions/index.tsx +227 -0
- package/src/plugins/builtin/credit-conditions/model.test.ts +43 -0
- package/src/plugins/builtin/credit-conditions/model.ts +64 -0
- package/src/plugins/builtin/debug/index.tsx +11 -6
- package/src/plugins/builtin/dividend-yield/client.test.ts +58 -0
- package/src/plugins/builtin/dividend-yield/client.ts +252 -0
- package/src/plugins/builtin/dividend-yield/index.tsx +61 -0
- package/src/plugins/builtin/dividend-yield/model.ts +83 -0
- package/src/plugins/builtin/dividend-yield/pane.tsx +305 -0
- package/src/plugins/builtin/dividend-yield/types.ts +22 -0
- package/src/plugins/builtin/earnings/data/cache.test.ts +10 -7
- package/src/plugins/builtin/earnings/data/cache.ts +23 -9
- package/src/plugins/builtin/earnings/index.tsx +57 -6
- package/src/plugins/builtin/econ/calendar-model.test.ts +37 -3
- package/src/plugins/builtin/econ/calendar-model.ts +32 -26
- package/src/plugins/builtin/econ/fred-cache.test.ts +8 -1
- package/src/plugins/builtin/econ/fred-series-map.ts +18 -0
- package/src/plugins/builtin/econ/index.test.tsx +105 -0
- package/src/plugins/builtin/econ/index.tsx +95 -52
- package/src/plugins/builtin/fear-greed/cache.test.ts +18 -3
- package/src/plugins/builtin/fear-greed/cache.ts +18 -6
- package/src/plugins/builtin/fear-greed/charts.tsx +9 -2
- package/src/plugins/builtin/fear-greed/format.ts +0 -9
- package/src/plugins/builtin/fear-greed/pane.tsx +21 -21
- package/src/plugins/builtin/futures/contracts.ts +100 -0
- package/src/plugins/builtin/futures/index.tsx +298 -0
- package/src/plugins/builtin/futures/model.test.ts +129 -0
- package/src/plugins/builtin/futures/model.ts +136 -0
- package/src/plugins/builtin/futures/pane.test.tsx +239 -0
- package/src/plugins/builtin/futures/table.test.ts +155 -0
- package/src/plugins/builtin/futures/table.tsx +241 -0
- package/src/plugins/builtin/fx-matrix/index.tsx +160 -134
- package/src/plugins/builtin/fx-matrix/pairs.ts +12 -1
- package/src/plugins/builtin/fx-matrix/pane.test.tsx +109 -0
- package/src/plugins/builtin/help/components.tsx +1 -30
- package/src/plugins/builtin/help/index.tsx +5 -25
- package/src/plugins/builtin/holders/pane.tsx +17 -12
- package/src/plugins/builtin/holders/treemap.tsx +4 -2
- package/src/plugins/builtin/insider/index.tsx +20 -10
- package/src/plugins/builtin/ipo-calendar/cache.ts +101 -0
- package/src/plugins/builtin/ipo-calendar/client.test.ts +31 -0
- package/src/plugins/builtin/ipo-calendar/client.ts +296 -0
- package/src/plugins/builtin/ipo-calendar/index.tsx +65 -0
- package/src/plugins/builtin/ipo-calendar/model.ts +145 -0
- package/src/plugins/builtin/ipo-calendar/pane.tsx +328 -0
- package/src/plugins/builtin/ipo-calendar/types.ts +19 -0
- package/src/plugins/builtin/kelly-sizer/index.test.tsx +3 -3
- package/src/plugins/builtin/kelly-sizer/model.ts +8 -1
- package/src/plugins/builtin/kelly-sizer/pane.tsx +33 -15
- package/src/plugins/builtin/kelly-sizer/view.tsx +12 -5
- package/src/plugins/builtin/market-halts/client.ts +114 -0
- package/src/plugins/builtin/market-halts/index.tsx +29 -0
- package/src/plugins/builtin/market-halts/model.test.ts +187 -0
- package/src/plugins/builtin/market-halts/model.ts +291 -0
- package/src/plugins/builtin/market-halts/pane.tsx +256 -0
- package/src/plugins/builtin/market-heatmap/data.test.ts +1 -0
- package/src/plugins/builtin/market-heatmap/data.ts +12 -3
- package/src/plugins/builtin/market-heatmap/index.tsx +131 -46
- package/src/plugins/builtin/market-movers/index.tsx +145 -63
- package/src/plugins/builtin/market-movers/model.ts +19 -3
- package/src/plugins/builtin/market-movers/screener.test.ts +108 -0
- package/src/plugins/builtin/market-movers/screener.ts +168 -10
- package/src/plugins/builtin/news/index.tsx +78 -99
- package/src/plugins/builtin/news/wire/article-search.test.ts +72 -0
- package/src/plugins/builtin/news/wire/article-search.ts +140 -0
- package/src/plugins/builtin/news/wire/breaking/pane.tsx +18 -8
- package/src/plugins/builtin/news/wire/categories.ts +35 -0
- package/src/plugins/builtin/news/wire/default-feeds.ts +47 -1
- package/src/plugins/builtin/news/wire/feed-config.test.ts +10 -5
- package/src/plugins/builtin/news/wire/index.tsx +41 -4
- package/src/plugins/builtin/news/wire/industry-pane.tsx +38 -19
- package/src/plugins/builtin/news/wire/news/detail-view.tsx +10 -5
- package/src/plugins/builtin/news/wire/news/footer.ts +1 -0
- package/src/plugins/builtin/news/wire/news/preset-pane.tsx +15 -6
- package/src/plugins/builtin/news/wire/news/query-presets.ts +16 -2
- package/src/plugins/builtin/news/wire/news/table.test.tsx +54 -0
- package/src/plugins/builtin/news/wire/news/table.tsx +111 -17
- package/src/plugins/builtin/notes/files.test.ts +18 -0
- package/src/plugins/builtin/notes/files.ts +10 -4
- package/src/plugins/builtin/notes/index.tsx +4 -1
- package/src/plugins/builtin/notes/quick-notes-pane.test.tsx +182 -0
- package/src/plugins/builtin/notes/quick-notes-pane.tsx +74 -31
- package/src/plugins/builtin/notes/ticker-notes-tab.test.tsx +380 -0
- package/src/plugins/builtin/notes/ticker-notes-tab.tsx +97 -40
- package/src/plugins/builtin/options/calc-seed.test.ts +118 -0
- package/src/plugins/builtin/options/calc-seed.ts +52 -0
- package/src/plugins/builtin/options/footer.ts +4 -1
- package/src/plugins/builtin/options/index.tsx +22 -1
- package/src/plugins/builtin/options/live-quotes.ts +8 -0
- package/src/plugins/builtin/options/table.ts +3 -1
- package/src/plugins/builtin/options/view.test.tsx +5 -1
- package/src/plugins/builtin/options/view.tsx +112 -17
- package/src/plugins/builtin/options-calculator/index.tsx +35 -0
- package/src/plugins/builtin/options-calculator/model.test.ts +172 -0
- package/src/plugins/builtin/options-calculator/model.ts +273 -0
- package/src/plugins/builtin/options-calculator/pane.test.tsx +138 -0
- package/src/plugins/builtin/options-calculator/pane.tsx +218 -0
- package/src/plugins/builtin/plugin-module.test.ts +16 -2
- package/src/plugins/builtin/plugin-module.ts +5 -1
- package/src/plugins/builtin/polls/client.ts +57 -0
- package/src/plugins/builtin/polls/hooks.ts +20 -0
- package/src/plugins/builtin/polls/index.tsx +35 -0
- package/src/plugins/builtin/polls/normalize.test.ts +230 -0
- package/src/plugins/builtin/polls/normalize.ts +319 -0
- package/src/plugins/builtin/polls/pane.tsx +722 -0
- package/src/plugins/builtin/polls/types.ts +77 -0
- package/src/plugins/builtin/portfolio-list/header.tsx +15 -4
- package/src/plugins/builtin/portfolio-list/pane/index.tsx +7 -3
- package/src/plugins/builtin/portfolio-list/pane/supplemental.ts +1 -1
- package/src/plugins/builtin/portfolio-list/quick-add/index.tsx +2 -0
- package/src/plugins/builtin/portfolio-list/summary/index.tsx +2 -1
- package/src/plugins/builtin/research/analyst-pane.tsx +40 -67
- package/src/plugins/builtin/research/corporate-actions-pane.tsx +25 -19
- package/src/plugins/builtin/research/index.test.ts +6 -25
- package/src/plugins/builtin/research/index.tsx +11 -5
- package/src/plugins/builtin/research/relative-valuation-pane.tsx +86 -26
- package/src/plugins/builtin/scanner/denied.tsx +31 -0
- package/src/plugins/builtin/scanner/feed.ts +94 -0
- package/src/plugins/builtin/scanner/flow-model.test.ts +85 -0
- package/src/plugins/builtin/scanner/flow-model.ts +133 -0
- package/src/plugins/builtin/scanner/flow-pane.tsx +197 -0
- package/src/plugins/builtin/scanner/hilo-bars.tsx +121 -0
- package/src/plugins/builtin/scanner/hilo-model.test.ts +44 -0
- package/src/plugins/builtin/scanner/hilo-model.ts +75 -0
- package/src/plugins/builtin/scanner/hilo-pane.tsx +165 -0
- package/src/plugins/builtin/scanner/index.ts +109 -0
- package/src/plugins/builtin/scanner/waiting.tsx +11 -0
- package/src/plugins/builtin/sec/index.tsx +11 -7
- package/src/plugins/builtin/sectors/index.tsx +105 -81
- package/src/plugins/builtin/sectors/move-bar.tsx +43 -0
- package/src/plugins/builtin/sectors/sector-data.ts +18 -0
- package/src/plugins/builtin/sectors/sector-model.ts +13 -15
- package/src/plugins/builtin/shared/auto-refresh.ts +51 -0
- package/src/plugins/builtin/shared/cloud-upgrade.ts +29 -5
- package/src/plugins/builtin/shared/pane-footer.ts +16 -3
- package/src/plugins/builtin/shared/screener-live-quotes.test.ts +91 -0
- package/src/plugins/builtin/shared/screener-live-quotes.ts +134 -0
- package/src/plugins/builtin/shared/table-pane.ts +1 -5
- package/src/plugins/builtin/shared/use-quote-board.test.tsx +211 -0
- package/src/plugins/builtin/shared/use-quote-board.ts +195 -0
- package/src/plugins/builtin/short-interest/client.ts +124 -0
- package/src/plugins/builtin/short-interest/index.tsx +62 -0
- package/src/plugins/builtin/short-interest/model.ts +113 -0
- package/src/plugins/builtin/short-interest/pane.tsx +252 -0
- package/src/plugins/builtin/short-interest/types.ts +9 -0
- package/src/plugins/builtin/substack/article-detail.tsx +15 -1
- package/src/plugins/builtin/substack/pane-footer.ts +3 -22
- package/src/plugins/builtin/substack/pane.tsx +1 -2
- package/src/plugins/builtin/thirteenf/api.ts +4 -1
- package/src/plugins/builtin/thirteenf/model.ts +2 -0
- package/src/plugins/builtin/thirteenf/pane.tsx +6 -2
- package/src/plugins/builtin/ticker-detail/data-panes/historical-prices.tsx +10 -4
- package/src/plugins/builtin/ticker-detail/data-panes/provider-search.tsx +67 -11
- package/src/plugins/builtin/ticker-detail/financials/tab.tsx +15 -8
- package/src/plugins/builtin/ticker-detail/index.tsx +5 -21
- package/src/plugins/builtin/ticker-detail/overview/components.tsx +72 -32
- package/src/plugins/builtin/ticker-detail/overview-tab.tsx +0 -10
- package/src/plugins/builtin/ticker-detail/pane.tsx +4 -1
- package/src/plugins/builtin/ticker-detail/quote-monitor/card.test.tsx +70 -0
- package/src/plugins/builtin/ticker-detail/quote-monitor/card.tsx +34 -26
- package/src/plugins/builtin/ticker-detail/quote-monitor/index.tsx +96 -49
- package/src/plugins/builtin/ticker-detail/research-tabs.ts +32 -0
- package/src/plugins/builtin/ticker-research-backend-plugin.ts +2 -9
- package/src/plugins/builtin/ticker-research-plugin.ts +6 -0
- package/src/plugins/builtin/treasury-auctions/cache.test.ts +173 -0
- package/src/plugins/builtin/treasury-auctions/cache.ts +104 -0
- package/src/plugins/builtin/treasury-auctions/client.test.ts +181 -0
- package/src/plugins/builtin/treasury-auctions/client.ts +151 -0
- package/src/plugins/builtin/treasury-auctions/index.tsx +90 -0
- package/src/plugins/builtin/treasury-auctions/model.test.ts +147 -0
- package/src/plugins/builtin/treasury-auctions/model.ts +188 -0
- package/src/plugins/builtin/treasury-auctions/pane.test.tsx +170 -0
- package/src/plugins/builtin/treasury-auctions/pane.tsx +417 -0
- package/src/plugins/builtin/treasury-auctions/types.ts +59 -0
- package/src/plugins/builtin/tv/pane.tsx +67 -7
- package/src/plugins/builtin/tv/youtube-embed.test.ts +84 -0
- package/src/plugins/builtin/tv/youtube-embed.ts +173 -0
- package/src/plugins/builtin/tv/youtube-stream.ts +27 -2
- package/src/plugins/builtin/volatility/client.ts +87 -0
- package/src/plugins/builtin/volatility/index.test.tsx +107 -0
- package/src/plugins/builtin/volatility/index.tsx +193 -0
- package/src/plugins/builtin/volatility/model.test.ts +66 -0
- package/src/plugins/builtin/volatility/model.ts +113 -0
- package/src/plugins/builtin/world-indices/footer.ts +43 -23
- package/src/plugins/builtin/world-indices/index.tsx +44 -93
- package/src/plugins/builtin/world-indices/indices.ts +11 -2
- package/src/plugins/builtin/world-indices/model.ts +17 -24
- package/src/plugins/builtin/world-indices/pane.test.tsx +116 -0
- package/src/plugins/builtin/world-indices/table.tsx +82 -37
- package/src/plugins/builtin/yield-curve/index.tsx +16 -7
- package/src/plugins/builtin/yield-curve/treasury-data.test.ts +25 -0
- package/src/plugins/builtin/yield-curve/treasury-data.ts +16 -0
- package/src/plugins/catalog-backend.ts +8 -0
- package/src/plugins/catalog-ui.ts +8 -0
- package/src/plugins/event-bus.ts +1 -0
- package/src/plugins/ibkr/gateway/account-loaders.ts +1 -1
- package/src/plugins/ibkr/trade/tab/footer.ts +9 -23
- package/src/plugins/ibkr/trade/tab/index.tsx +1 -5
- package/src/plugins/ibkr/trading/pane-view.tsx +149 -87
- package/src/plugins/ibkr/trading/pane.tsx +2 -2
- package/src/plugins/ownership.ts +3 -0
- package/src/plugins/pane-manager/floating.ts +8 -2
- package/src/plugins/pane-manager.test.ts +13 -0
- package/src/plugins/prediction-markets/backend-plugin.ts +2 -0
- package/src/plugins/prediction-markets/capability.test.ts +281 -0
- package/src/plugins/prediction-markets/capability.ts +171 -0
- package/src/plugins/prediction-markets/chart.tsx +18 -26
- package/src/plugins/prediction-markets/columns.ts +3 -2
- package/src/plugins/prediction-markets/controller/catalog.ts +15 -12
- package/src/plugins/prediction-markets/controller/detail.ts +4 -0
- package/src/plugins/prediction-markets/controller/index.ts +0 -15
- package/src/plugins/prediction-markets/detail/book.tsx +3 -23
- package/src/plugins/prediction-markets/detail/overview.tsx +0 -18
- package/src/plugins/prediction-markets/detail/pane.tsx +36 -12
- package/src/plugins/prediction-markets/detail.test.tsx +1 -1
- package/src/plugins/prediction-markets/index.tsx +2 -0
- package/src/plugins/prediction-markets/metrics.ts +28 -18
- package/src/plugins/prediction-markets/navigation.ts +1 -0
- package/src/plugins/prediction-markets/pane.test.tsx +1 -1
- package/src/plugins/prediction-markets/pane.tsx +0 -1
- package/src/plugins/prediction-markets/services/fetch.ts +3 -2
- package/src/plugins/prediction-markets/services/kalshi/adapter.ts +82 -23
- package/src/plugins/prediction-markets/services/kalshi/normalize.ts +3 -1
- package/src/plugins/prediction-markets/services/kalshi/types.ts +14 -0
- package/src/plugins/prediction-markets/services/polymarket/adapter.ts +26 -14
- package/src/plugins/prediction-markets/services/polymarket/detail.ts +67 -18
- package/src/plugins/prediction-markets/test-helpers.tsx +0 -1
- package/src/plugins/prediction-markets/types.ts +3 -9
- package/src/plugins/registry/context.ts +6 -1
- package/src/plugins/registry/index.test.ts +2 -0
- package/src/plugins/registry/index.ts +53 -3
- package/src/plugins/runtime/context.tsx +4 -2
- package/src/plugins/runtime/index.tsx +9 -0
- package/src/remote/controller.test.ts +17 -4
- package/src/renderers/electrobun/bun/application-menu/index.ts +1 -1
- package/src/renderers/electrobun/bun/core-capabilities.ts +2 -2
- package/src/renderers/electrobun/bun/desktop/capability-bridge.test.ts +64 -0
- package/src/renderers/electrobun/bun/desktop/capability-bridge.ts +41 -7
- package/src/renderers/electrobun/bun/desktop/host-requests.ts +5 -2
- package/src/renderers/electrobun/bun/desktop/http-fetch.test.ts +33 -0
- package/src/renderers/electrobun/bun/desktop/http-fetch.ts +53 -6
- package/src/renderers/electrobun/bun/desktop/initialization.test.ts +27 -0
- package/src/renderers/electrobun/bun/desktop/initialization.ts +6 -1
- package/src/renderers/electrobun/bun/index.ts +1 -0
- package/src/renderers/electrobun/shared/protocol.ts +2 -0
- package/src/renderers/electrobun/view/app-services.ts +25 -2
- package/src/renderers/electrobun/view/build-assets.ts +5 -0
- package/src/renderers/electrobun/view/cli-pane-shot-entry.tsx +186 -65
- package/src/renderers/electrobun/view/cli-pane-shot-health.test.ts +25 -0
- package/src/renderers/electrobun/view/cli-pane-shot-health.ts +31 -0
- package/src/renderers/electrobun/view/data-table/index.tsx +10 -11
- package/src/renderers/electrobun/view/data-table/row.tsx +2 -0
- package/src/renderers/electrobun/view/desktop/controls.test.tsx +68 -0
- package/src/renderers/electrobun/view/desktop/controls.tsx +25 -1
- package/src/renderers/electrobun/view/host/box.test.tsx +80 -0
- package/src/renderers/electrobun/view/host/media-surface.tsx +70 -3
- package/src/renderers/electrobun/view/host/tabs.tsx +97 -5
- package/src/renderers/electrobun/view/host/text.tsx +5 -2
- package/src/renderers/electrobun/view/input-host.test.tsx +140 -0
- package/src/renderers/electrobun/view/input-host.tsx +4 -2
- package/src/renderers/electrobun/view/native-stubs/backend-rpc.ts +19 -1
- package/src/renderers/electrobun/view/native-stubs/broker-sync-native-loader.ts +7 -0
- package/src/renderers/electrobun/view/native-stubs/chart/kitty-support.ts +10 -0
- package/src/renderers/electrobun/view/remote/capability-invoker.test.ts +46 -0
- package/src/renderers/electrobun/view/remote/capability-invoker.ts +34 -13
- package/src/renderers/electrobun/view/remote/connection-health-backend.ts +19 -0
- package/src/renderers/electrobun/view/remote/connection-health.test.ts +44 -0
- package/src/renderers/electrobun/view/remote/connection-health.ts +49 -0
- package/src/renderers/electrobun/view/styles.css +5 -0
- package/src/renderers/opentui/dialog-host.tsx +279 -80
- package/src/renderers/opentui/host.tsx +15 -1
- package/src/renderers/opentui/terminal-media.test.ts +102 -0
- package/src/renderers/opentui/terminal-media.ts +142 -0
- package/src/renderers/opentui/test-utils.tsx +9 -6
- package/src/renderers/opentui/toast-host.tsx +136 -7
- package/src/renderers/opentui/ui-host.tsx +19 -3
- package/src/sources/provider-router/connection-health.test.ts +28 -0
- package/src/sources/provider-router/connection-health.ts +47 -0
- package/src/sources/provider-router/history.test.ts +53 -4
- package/src/sources/provider-router/history.ts +119 -14
- package/src/sources/provider-router/index.ts +12 -1
- package/src/sources/yahoo-finance/history.ts +2 -9
- package/src/sources/yahoo-finance/http.ts +1 -1
- package/src/sources/yahoo-finance/symbols.ts +1 -1
- package/src/sources/yahoo-finance/types.ts +19 -0
- package/src/state/app/context/index.test.tsx +101 -0
- package/src/state/app/context/index.tsx +10 -0
- package/src/state/config-save-scheduler.ts +1 -6
- package/src/state/persist-scheduler.test.ts +31 -0
- package/src/state/persist-scheduler.ts +21 -8
- package/src/sync/auth-transition.test.ts +36 -0
- package/src/sync/auth-transition.ts +22 -0
- package/src/sync/core-contributors.test.ts +58 -1
- package/src/sync/core-contributors.ts +39 -2
- package/src/sync/react.ts +9 -0
- package/src/test-support/plugin-runtime.ts +3 -0
- package/src/theme/font-scale.test.ts +14 -0
- package/src/theme/font-scale.ts +69 -0
- package/src/tickers/search/index.test.ts +284 -2
- package/src/tickers/search/index.ts +55 -18
- package/src/tickers/search/ranking.ts +143 -18
- package/src/tickers/search/types.ts +1 -0
- package/src/time-series/alignment.ts +15 -11
- package/src/time-series/field-catalog.ts +10 -0
- package/src/time-series/fundamentals.ts +19 -11
- package/src/time-series/hooks.ts +8 -2
- package/src/time-series/parsed-history-cache.ts +35 -0
- package/src/time-series/resolution.ts +10 -0
- package/src/time-series/resolve.test.ts +332 -3
- package/src/time-series/resolve.ts +225 -25
- package/src/time-series/spec-studies.test.ts +23 -0
- package/src/time-series/spec.ts +21 -2
- package/src/time-series/transforms.test.ts +76 -1
- package/src/time-series/transforms.ts +39 -8
- package/src/time-series/types.ts +9 -2
- package/src/time-series/use-chart-resolution.test.tsx +105 -1
- package/src/time-series/use-chart-resolution.ts +67 -13
- package/src/types/config.ts +30 -27
- package/src/types/media.ts +2 -0
- package/src/types/plugin.ts +8 -1
- package/src/ui/host.tsx +4 -0
- package/src/ui/pointer-drag.ts +12 -0
- package/src/ui/qr.test.ts +79 -0
- package/src/ui/qr.ts +82 -0
- package/src/updater/github-releases.test.ts +3 -3
- package/src/updater/github-releases.ts +1 -1
- package/src/updater.test.ts +117 -16
- package/src/updater.ts +32 -5
- package/src/utils/exchanges.ts +1 -0
- package/src/utils/external-url.test.ts +32 -0
- package/src/utils/external-url.ts +23 -0
- package/src/utils/sort-values.ts +31 -0
- package/src/utils/zoned-date-time.ts +67 -0
- package/src/components/onboarding/wizard-keyboard.ts +0 -306
- package/src/plugins/builtin/chart-composer/date-window-dialog.tsx +0 -120
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
import { afterEach, describe, expect, test } from "bun:test";
|
|
2
|
+
import { act, useReducer, useState } from "react";
|
|
3
|
+
import { PaneFooterProvider } from "../../../components/layout/pane/footer";
|
|
4
|
+
import { TestDialogProvider, testRender } from "../../../renderers/opentui/test-utils";
|
|
5
|
+
import { createTestPluginRuntime } from "../../../test-support/plugin-runtime";
|
|
6
|
+
import {
|
|
7
|
+
AppContext,
|
|
8
|
+
PaneInstanceProvider,
|
|
9
|
+
appReducer,
|
|
10
|
+
createInitialState,
|
|
11
|
+
} from "../../../state/app/context";
|
|
12
|
+
import { cloneLayout, createDefaultConfig } from "../../../types/config";
|
|
13
|
+
import type { TickerRecord } from "../../../types/ticker";
|
|
14
|
+
import { Box, Text } from "../../../ui";
|
|
15
|
+
import { PluginRenderProvider, type PluginRuntimeAccess } from "../../runtime";
|
|
16
|
+
import { createNotesTab } from "./ticker-notes-tab";
|
|
17
|
+
import type { NotesFiles } from "./files";
|
|
18
|
+
|
|
19
|
+
const TEST_PANE_ID = "ticker-detail:notes-test";
|
|
20
|
+
|
|
21
|
+
let testSetup: Awaited<ReturnType<typeof testRender>> | undefined;
|
|
22
|
+
|
|
23
|
+
function makeTicker(symbol: string): TickerRecord {
|
|
24
|
+
return {
|
|
25
|
+
metadata: {
|
|
26
|
+
ticker: symbol,
|
|
27
|
+
exchange: "NASDAQ",
|
|
28
|
+
currency: "USD",
|
|
29
|
+
name: symbol,
|
|
30
|
+
portfolios: [],
|
|
31
|
+
watchlists: [],
|
|
32
|
+
positions: [],
|
|
33
|
+
custom: {},
|
|
34
|
+
tags: [],
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function createMockNotesFiles(options?: {
|
|
40
|
+
loadDelayMs?: number;
|
|
41
|
+
notes?: Record<string, string>;
|
|
42
|
+
saveError?: Error;
|
|
43
|
+
}) {
|
|
44
|
+
const saves: Array<{ symbol: string; text: string }> = [];
|
|
45
|
+
const notes = new Map(Object.entries(options?.notes ?? {}));
|
|
46
|
+
const loadDelayMs = options?.loadDelayMs ?? 0;
|
|
47
|
+
return {
|
|
48
|
+
saves,
|
|
49
|
+
async load(symbol: string) {
|
|
50
|
+
if (loadDelayMs > 0) {
|
|
51
|
+
await new Promise((resolve) => setTimeout(resolve, loadDelayMs));
|
|
52
|
+
}
|
|
53
|
+
return notes.get(symbol) ?? "";
|
|
54
|
+
},
|
|
55
|
+
async save(symbol: string, text: string) {
|
|
56
|
+
saves.push({ symbol, text });
|
|
57
|
+
if (options?.saveError) throw options.saveError;
|
|
58
|
+
},
|
|
59
|
+
async delete() {},
|
|
60
|
+
quickNoteKey(id: string) {
|
|
61
|
+
return `__quick__/${id}`;
|
|
62
|
+
},
|
|
63
|
+
async loadQuickNotesIndex() {
|
|
64
|
+
return [];
|
|
65
|
+
},
|
|
66
|
+
async saveQuickNotesIndex() {},
|
|
67
|
+
} as unknown as NotesFiles & { saves: Array<{ symbol: string; text: string }> };
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function createNotesHarnessConfig(symbol: string) {
|
|
71
|
+
const config = createDefaultConfig("/tmp/gloomberb-notes-tab");
|
|
72
|
+
const layout = {
|
|
73
|
+
dockRoot: { kind: "pane" as const, instanceId: TEST_PANE_ID },
|
|
74
|
+
instances: [{
|
|
75
|
+
instanceId: TEST_PANE_ID,
|
|
76
|
+
paneId: "ticker-detail",
|
|
77
|
+
binding: { kind: "fixed" as const, symbol },
|
|
78
|
+
}],
|
|
79
|
+
floating: [],
|
|
80
|
+
detached: [],
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
return {
|
|
84
|
+
...config,
|
|
85
|
+
layout,
|
|
86
|
+
layouts: [{ name: "Default", layout: cloneLayout(layout) }],
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function NotesTabHarness({
|
|
91
|
+
NotesTab,
|
|
92
|
+
initialSymbol,
|
|
93
|
+
runtime = createTestPluginRuntime(),
|
|
94
|
+
}: {
|
|
95
|
+
NotesTab: ReturnType<typeof createNotesTab>;
|
|
96
|
+
initialSymbol: string;
|
|
97
|
+
runtime?: PluginRuntimeAccess;
|
|
98
|
+
}) {
|
|
99
|
+
const [focused, setFocused] = useState(true);
|
|
100
|
+
const [state, dispatch] = useReducer(appReducer, undefined, () => {
|
|
101
|
+
const initial = createInitialState(createNotesHarnessConfig(initialSymbol));
|
|
102
|
+
initial.focusedPaneId = TEST_PANE_ID;
|
|
103
|
+
initial.tickers = new Map([
|
|
104
|
+
["AAPL", makeTicker("AAPL")],
|
|
105
|
+
["MSFT", makeTicker("MSFT")],
|
|
106
|
+
]);
|
|
107
|
+
return initial;
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
const switchSymbol = (nextSymbol: string) => {
|
|
111
|
+
dispatch({
|
|
112
|
+
type: "UPDATE_LAYOUT",
|
|
113
|
+
layout: {
|
|
114
|
+
...state.config.layout,
|
|
115
|
+
instances: state.config.layout.instances.map((instance) => (
|
|
116
|
+
instance.instanceId === TEST_PANE_ID
|
|
117
|
+
? { ...instance, binding: { kind: "fixed" as const, symbol: nextSymbol } }
|
|
118
|
+
: instance
|
|
119
|
+
)),
|
|
120
|
+
},
|
|
121
|
+
});
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
return (
|
|
125
|
+
<TestDialogProvider>
|
|
126
|
+
<Box flexDirection="column" width={80} height={24}>
|
|
127
|
+
<AppContext value={{ state, dispatch }}>
|
|
128
|
+
<PaneInstanceProvider paneId={TEST_PANE_ID}>
|
|
129
|
+
<PluginRenderProvider pluginId="notes" runtime={runtime}>
|
|
130
|
+
<PaneFooterProvider>
|
|
131
|
+
{() => (
|
|
132
|
+
<>
|
|
133
|
+
<NotesTab
|
|
134
|
+
width={78}
|
|
135
|
+
height={20}
|
|
136
|
+
focused={focused}
|
|
137
|
+
onCapture={() => {}}
|
|
138
|
+
/>
|
|
139
|
+
<Text onMouseDown={() => setFocused(false)}>blur-tab</Text>
|
|
140
|
+
<Text onMouseDown={() => switchSymbol("MSFT")}>switch-msft</Text>
|
|
141
|
+
</>
|
|
142
|
+
)}
|
|
143
|
+
</PaneFooterProvider>
|
|
144
|
+
</PluginRenderProvider>
|
|
145
|
+
</PaneInstanceProvider>
|
|
146
|
+
</AppContext>
|
|
147
|
+
</Box>
|
|
148
|
+
</TestDialogProvider>
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
afterEach(async () => {
|
|
153
|
+
if (testSetup) {
|
|
154
|
+
await act(async () => {
|
|
155
|
+
testSetup!.renderer.destroy();
|
|
156
|
+
});
|
|
157
|
+
testSetup = undefined;
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
describe("createNotesTab", () => {
|
|
162
|
+
test("surfaces a save failure when the tab loses focus", async () => {
|
|
163
|
+
const notifications: string[] = [];
|
|
164
|
+
const notesFiles = createMockNotesFiles({ saveError: new Error("disk full") });
|
|
165
|
+
const NotesTab = createNotesTab(notesFiles);
|
|
166
|
+
const runtime = createTestPluginRuntime({
|
|
167
|
+
notify: ({ body }) => { notifications.push(body); },
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
testSetup = await testRender(
|
|
171
|
+
<NotesTabHarness NotesTab={NotesTab} initialSymbol="AAPL" runtime={runtime} />,
|
|
172
|
+
{ width: 80, height: 24 },
|
|
173
|
+
);
|
|
174
|
+
await testSetup.renderOnce();
|
|
175
|
+
|
|
176
|
+
let frame = testSetup.captureCharFrame();
|
|
177
|
+
const placeholderRow = frame.split("\n").findIndex((line) => line.includes("Write notes"));
|
|
178
|
+
const placeholderCol = frame.split("\n")[placeholderRow]?.indexOf("Write notes") ?? -1;
|
|
179
|
+
expect(placeholderRow).toBeGreaterThanOrEqual(0);
|
|
180
|
+
expect(placeholderCol).toBeGreaterThanOrEqual(0);
|
|
181
|
+
|
|
182
|
+
await act(async () => {
|
|
183
|
+
await testSetup!.mockMouse.click(placeholderCol + 1, placeholderRow);
|
|
184
|
+
await testSetup!.renderOnce();
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
await act(async () => {
|
|
188
|
+
await testSetup!.mockInput.typeText("ab");
|
|
189
|
+
await testSetup!.renderOnce();
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
frame = testSetup.captureCharFrame();
|
|
193
|
+
expect(frame).toContain("ab");
|
|
194
|
+
|
|
195
|
+
const blurRow = frame.split("\n").findIndex((line) => line.includes("blur-tab"));
|
|
196
|
+
const blurCol = frame.split("\n")[blurRow]?.indexOf("blur-tab") ?? -1;
|
|
197
|
+
expect(blurRow).toBeGreaterThanOrEqual(0);
|
|
198
|
+
|
|
199
|
+
const originalError = console.error;
|
|
200
|
+
console.error = () => {};
|
|
201
|
+
try {
|
|
202
|
+
await act(async () => {
|
|
203
|
+
await testSetup!.mockMouse.click(blurCol + 1, blurRow);
|
|
204
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
205
|
+
await testSetup!.renderOnce();
|
|
206
|
+
});
|
|
207
|
+
} finally {
|
|
208
|
+
console.error = originalError;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
expect(notesFiles.saves).toEqual([{ symbol: "AAPL", text: "ab" }]);
|
|
212
|
+
expect(notifications).toEqual(["Failed to save note. Check disk space and permissions."]);
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
test("does not save stale buffer text to a new ticker before its notes load", async () => {
|
|
216
|
+
const notesFiles = createMockNotesFiles({
|
|
217
|
+
loadDelayMs: 50,
|
|
218
|
+
notes: { MSFT: "msft-note" },
|
|
219
|
+
});
|
|
220
|
+
const NotesTab = createNotesTab(notesFiles);
|
|
221
|
+
|
|
222
|
+
testSetup = await testRender(
|
|
223
|
+
<NotesTabHarness NotesTab={NotesTab} initialSymbol="AAPL" />,
|
|
224
|
+
{ width: 80, height: 24 },
|
|
225
|
+
);
|
|
226
|
+
await testSetup.renderOnce();
|
|
227
|
+
|
|
228
|
+
let frame = testSetup.captureCharFrame();
|
|
229
|
+
const placeholderRow = frame.split("\n").findIndex((line) => line.includes("Write notes"));
|
|
230
|
+
const placeholderCol = frame.split("\n")[placeholderRow]?.indexOf("Write notes") ?? -1;
|
|
231
|
+
|
|
232
|
+
await act(async () => {
|
|
233
|
+
await testSetup!.mockMouse.click(placeholderCol + 1, placeholderRow);
|
|
234
|
+
await testSetup!.renderOnce();
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
await act(async () => {
|
|
238
|
+
await testSetup!.mockInput.typeText("aapl-note");
|
|
239
|
+
await testSetup!.renderOnce();
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
frame = testSetup.captureCharFrame();
|
|
243
|
+
expect(frame).toContain("aapl-note");
|
|
244
|
+
|
|
245
|
+
const switchRow = frame.split("\n").findIndex((line) => line.includes("switch-msft"));
|
|
246
|
+
const switchCol = frame.split("\n")[switchRow]?.indexOf("switch-msft") ?? -1;
|
|
247
|
+
|
|
248
|
+
await act(async () => {
|
|
249
|
+
await testSetup!.mockMouse.click(switchCol + 1, switchRow);
|
|
250
|
+
await testSetup!.renderOnce();
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
frame = testSetup.captureCharFrame();
|
|
254
|
+
const blurRow = frame.split("\n").findIndex((line) => line.includes("blur-tab"));
|
|
255
|
+
const blurCol = frame.split("\n")[blurRow]?.indexOf("blur-tab") ?? -1;
|
|
256
|
+
|
|
257
|
+
await act(async () => {
|
|
258
|
+
await testSetup!.mockMouse.click(blurCol + 1, blurRow);
|
|
259
|
+
await testSetup!.renderOnce();
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
expect(notesFiles.saves).toEqual([{ symbol: "AAPL", text: "aapl-note" }]);
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
test("does not overwrite notes when switching away before initial load completes", async () => {
|
|
266
|
+
const notesFiles = createMockNotesFiles({
|
|
267
|
+
loadDelayMs: 100,
|
|
268
|
+
notes: { AAPL: "existing-aapl-note", MSFT: "" },
|
|
269
|
+
});
|
|
270
|
+
const NotesTab = createNotesTab(notesFiles);
|
|
271
|
+
|
|
272
|
+
testSetup = await testRender(
|
|
273
|
+
<NotesTabHarness NotesTab={NotesTab} initialSymbol="AAPL" />,
|
|
274
|
+
{ width: 80, height: 24 },
|
|
275
|
+
);
|
|
276
|
+
await testSetup.renderOnce();
|
|
277
|
+
|
|
278
|
+
let frame = testSetup.captureCharFrame();
|
|
279
|
+
const switchRow = frame.split("\n").findIndex((line) => line.includes("switch-msft"));
|
|
280
|
+
const switchCol = frame.split("\n")[switchRow]?.indexOf("switch-msft") ?? -1;
|
|
281
|
+
|
|
282
|
+
await act(async () => {
|
|
283
|
+
await testSetup!.mockMouse.click(switchCol + 1, switchRow);
|
|
284
|
+
await testSetup!.renderOnce();
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
await act(async () => {
|
|
288
|
+
await new Promise((resolve) => setTimeout(resolve, 150));
|
|
289
|
+
await testSetup!.renderOnce();
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
expect(notesFiles.saves).toEqual([]);
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
test("loads new ticker notes after switching away from edit mode", async () => {
|
|
296
|
+
const notesFiles = createMockNotesFiles({
|
|
297
|
+
loadDelayMs: 100,
|
|
298
|
+
notes: { MSFT: "msft-note" },
|
|
299
|
+
});
|
|
300
|
+
const NotesTab = createNotesTab(notesFiles);
|
|
301
|
+
|
|
302
|
+
testSetup = await testRender(
|
|
303
|
+
<NotesTabHarness NotesTab={NotesTab} initialSymbol="AAPL" />,
|
|
304
|
+
{ width: 80, height: 24 },
|
|
305
|
+
);
|
|
306
|
+
await testSetup.renderOnce();
|
|
307
|
+
|
|
308
|
+
let frame = testSetup.captureCharFrame();
|
|
309
|
+
const placeholderRow = frame.split("\n").findIndex((line) => line.includes("Write notes"));
|
|
310
|
+
const placeholderCol = frame.split("\n")[placeholderRow]?.indexOf("Write notes") ?? -1;
|
|
311
|
+
|
|
312
|
+
await act(async () => {
|
|
313
|
+
await testSetup!.mockMouse.click(placeholderCol + 1, placeholderRow);
|
|
314
|
+
await testSetup!.renderOnce();
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
await act(async () => {
|
|
318
|
+
await testSetup!.mockInput.typeText("aapl-note");
|
|
319
|
+
await testSetup!.renderOnce();
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
frame = testSetup.captureCharFrame();
|
|
323
|
+
const switchRow = frame.split("\n").findIndex((line) => line.includes("switch-msft"));
|
|
324
|
+
const switchCol = frame.split("\n")[switchRow]?.indexOf("switch-msft") ?? -1;
|
|
325
|
+
|
|
326
|
+
await act(async () => {
|
|
327
|
+
await testSetup!.mockMouse.click(switchCol + 1, switchRow);
|
|
328
|
+
await testSetup!.renderOnce();
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
await act(async () => {
|
|
332
|
+
await new Promise((resolve) => setTimeout(resolve, 150));
|
|
333
|
+
await testSetup!.renderOnce();
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
frame = testSetup.captureCharFrame();
|
|
337
|
+
const previewRow = frame.split("\n").findIndex((line) => line.includes("Write notes") || line.includes("msft-note"));
|
|
338
|
+
const previewCol = frame.split("\n")[previewRow]?.search(/Write notes|msft-note/) ?? -1;
|
|
339
|
+
|
|
340
|
+
await act(async () => {
|
|
341
|
+
await testSetup!.mockMouse.click(previewCol + 1, previewRow);
|
|
342
|
+
await testSetup!.renderOnce();
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
frame = testSetup.captureCharFrame();
|
|
346
|
+
expect(frame).toContain("msft-note");
|
|
347
|
+
expect(notesFiles.saves).toEqual([{ symbol: "AAPL", text: "aapl-note" }]);
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
test("applies loaded notes if edit mode starts before load finishes", async () => {
|
|
351
|
+
const notesFiles = createMockNotesFiles({
|
|
352
|
+
loadDelayMs: 100,
|
|
353
|
+
notes: { AAPL: "existing-note" },
|
|
354
|
+
});
|
|
355
|
+
const NotesTab = createNotesTab(notesFiles);
|
|
356
|
+
|
|
357
|
+
testSetup = await testRender(
|
|
358
|
+
<NotesTabHarness NotesTab={NotesTab} initialSymbol="AAPL" />,
|
|
359
|
+
{ width: 80, height: 24 },
|
|
360
|
+
);
|
|
361
|
+
await testSetup.renderOnce();
|
|
362
|
+
|
|
363
|
+
let frame = testSetup.captureCharFrame();
|
|
364
|
+
const placeholderRow = frame.split("\n").findIndex((line) => line.includes("Write notes"));
|
|
365
|
+
const placeholderCol = frame.split("\n")[placeholderRow]?.indexOf("Write notes") ?? -1;
|
|
366
|
+
|
|
367
|
+
await act(async () => {
|
|
368
|
+
await testSetup!.mockMouse.click(placeholderCol + 1, placeholderRow);
|
|
369
|
+
await testSetup!.renderOnce();
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
await act(async () => {
|
|
373
|
+
await new Promise((resolve) => setTimeout(resolve, 150));
|
|
374
|
+
await testSetup!.renderOnce();
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
frame = testSetup.captureCharFrame();
|
|
378
|
+
expect(frame).toContain("existing-note");
|
|
379
|
+
});
|
|
380
|
+
});
|
|
@@ -5,7 +5,8 @@ import type { TickerResearchTabProps } from "../../../types/plugin";
|
|
|
5
5
|
import { usePaneTicker } from "../../../state/app/context";
|
|
6
6
|
import { colors } from "../../../theme/colors";
|
|
7
7
|
import { MarkdownEditor } from "../../../components/markdown-editor";
|
|
8
|
-
import { usePaneFooter } from "../../../components";
|
|
8
|
+
import { EmptyState, usePaneFooter } from "../../../components";
|
|
9
|
+
import { usePluginAppActions } from "../../runtime";
|
|
9
10
|
import type { NotesFiles } from "./files";
|
|
10
11
|
import { MarkdownNotePreview } from "./markdown-note-preview";
|
|
11
12
|
import { useSyncedText } from "./text-state";
|
|
@@ -13,59 +14,109 @@ import { useSyncedText } from "./text-state";
|
|
|
13
14
|
export function createNotesTab(notesFiles: NotesFiles) {
|
|
14
15
|
return function NotesTab({ focused, width, onCapture }: TickerResearchTabProps) {
|
|
15
16
|
const { ticker } = usePaneTicker();
|
|
17
|
+
const { notify } = usePluginAppActions();
|
|
16
18
|
const textareaRef = useRef<TextareaRenderable | null>(null);
|
|
17
19
|
const [notesFocused, setNotesFocused] = useState(false);
|
|
20
|
+
const [loadError, setLoadError] = useState<string | null>(null);
|
|
18
21
|
const { text: noteText, textRef: noteTextRef, setText: setNoteText } = useSyncedText("");
|
|
19
22
|
const wasNotesFocusedRef = useRef(false);
|
|
23
|
+
const notesFocusedRef = useRef(notesFocused);
|
|
24
|
+
notesFocusedRef.current = notesFocused;
|
|
25
|
+
const loadedSymbolRef = useRef<string | null>(null);
|
|
26
|
+
const lastSavedTextRef = useRef<Map<string, string>>(new Map());
|
|
20
27
|
|
|
21
28
|
const setNotesFocusedAndCapture = useCallback((value: boolean) => {
|
|
22
29
|
setNotesFocused(value);
|
|
23
30
|
onCapture(value);
|
|
24
31
|
}, [onCapture]);
|
|
32
|
+
const setNotesFocusedAndCaptureRef = useRef(setNotesFocusedAndCapture);
|
|
33
|
+
setNotesFocusedAndCaptureRef.current = setNotesFocusedAndCapture;
|
|
25
34
|
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
35
|
+
const applyNoteText = useCallback((text: string) => {
|
|
36
|
+
setNoteText(text);
|
|
37
|
+
textareaRef.current?.setText(text);
|
|
38
|
+
}, [setNoteText]);
|
|
39
|
+
|
|
40
|
+
const getCurrentNoteText = useCallback(() => {
|
|
41
|
+
try {
|
|
42
|
+
return textareaRef.current?.editBuffer.getText() ?? noteTextRef.current;
|
|
43
|
+
} catch {
|
|
44
|
+
return noteTextRef.current;
|
|
45
|
+
}
|
|
46
|
+
}, [noteTextRef]);
|
|
47
|
+
|
|
48
|
+
const tickerSymbol = ticker?.metadata.ticker ?? null;
|
|
49
|
+
|
|
50
|
+
const handleNoteChange = useCallback((value: string) => {
|
|
51
|
+
if (tickerSymbol && value !== noteTextRef.current) {
|
|
52
|
+
loadedSymbolRef.current = tickerSymbol;
|
|
53
|
+
}
|
|
54
|
+
setNoteText(value);
|
|
55
|
+
}, [noteTextRef, setNoteText, tickerSymbol]);
|
|
29
56
|
|
|
30
57
|
const saveNotesFor = useCallback((symbol: string | null, text: string) => {
|
|
31
58
|
if (!symbol) return;
|
|
32
|
-
|
|
33
|
-
|
|
59
|
+
// Blur and symbol switches both save; without this every ticker switch
|
|
60
|
+
// rewrites an unchanged file and can clobber another pane on the same symbol.
|
|
61
|
+
if (lastSavedTextRef.current.get(symbol) === text) return;
|
|
62
|
+
lastSavedTextRef.current.set(symbol, text);
|
|
63
|
+
notesFiles.save(symbol, text).catch((error) => {
|
|
64
|
+
console.error("[notes] Failed to save ticker note:", error);
|
|
65
|
+
notify({ body: "Failed to save note. Check disk space and permissions.", type: "error" });
|
|
66
|
+
});
|
|
67
|
+
}, [notesFiles, notify]);
|
|
34
68
|
|
|
35
69
|
useEffect(() => {
|
|
36
|
-
if (
|
|
37
|
-
|
|
70
|
+
if (
|
|
71
|
+
wasNotesFocusedRef.current
|
|
72
|
+
&& !notesFocused
|
|
73
|
+
&& tickerSymbol
|
|
74
|
+
&& loadedSymbolRef.current === tickerSymbol
|
|
75
|
+
) {
|
|
76
|
+
saveNotesFor(tickerSymbol, getCurrentNoteText());
|
|
38
77
|
}
|
|
39
78
|
wasNotesFocusedRef.current = notesFocused;
|
|
40
|
-
}, [getCurrentNoteText, notesFocused,
|
|
79
|
+
}, [getCurrentNoteText, notesFocused, tickerSymbol, saveNotesFor]);
|
|
41
80
|
|
|
42
|
-
const tickerSymbol = ticker?.metadata.ticker ?? null;
|
|
43
|
-
const prevSymbolRef = useRef<string | null>(null);
|
|
44
81
|
useEffect(() => {
|
|
45
|
-
if (
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
prevSymbolRef.current = tickerSymbol;
|
|
82
|
+
if (!focused && notesFocused) {
|
|
83
|
+
setNotesFocusedAndCapture(false);
|
|
84
|
+
}
|
|
85
|
+
}, [focused, notesFocused, setNotesFocusedAndCapture]);
|
|
50
86
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
87
|
+
useEffect(() => {
|
|
88
|
+
loadedSymbolRef.current = null;
|
|
89
|
+
applyNoteText("");
|
|
90
|
+
setLoadError(null);
|
|
56
91
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
textareaRef.current?.setText(nextNotes);
|
|
60
|
-
}).catch(() => {
|
|
61
|
-
setNoteText("");
|
|
62
|
-
textareaRef.current?.setText("");
|
|
63
|
-
});
|
|
92
|
+
if (notesFocusedRef.current) {
|
|
93
|
+
setNotesFocusedAndCaptureRef.current(false);
|
|
64
94
|
}
|
|
65
|
-
|
|
95
|
+
|
|
96
|
+
if (!tickerSymbol) return;
|
|
97
|
+
|
|
98
|
+
let cancelled = false;
|
|
99
|
+
const applyLoaded = (text: string) => {
|
|
100
|
+
if (cancelled || loadedSymbolRef.current === tickerSymbol) return;
|
|
101
|
+
loadedSymbolRef.current = tickerSymbol;
|
|
102
|
+
lastSavedTextRef.current.set(tickerSymbol, text);
|
|
103
|
+
applyNoteText(text);
|
|
104
|
+
};
|
|
105
|
+
notesFiles.load(tickerSymbol).then(applyLoaded, (error: unknown) => {
|
|
106
|
+
// Leave the symbol unloaded so the unmount save below cannot overwrite it.
|
|
107
|
+
if (!cancelled) setLoadError(error instanceof Error ? error.message : String(error));
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
return () => {
|
|
111
|
+
cancelled = true;
|
|
112
|
+
if (loadedSymbolRef.current === tickerSymbol) {
|
|
113
|
+
saveNotesFor(tickerSymbol, getCurrentNoteText());
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
}, [tickerSymbol, applyNoteText, getCurrentNoteText, saveNotesFor, notesFiles]);
|
|
66
117
|
|
|
67
118
|
useShortcut((event) => {
|
|
68
|
-
if (!focused) return;
|
|
119
|
+
if (!focused || loadError) return;
|
|
69
120
|
const isEnter = event.name === "enter" || event.name === "return";
|
|
70
121
|
if (isEnter && !notesFocused) {
|
|
71
122
|
setNotesFocusedAndCapture(true);
|
|
@@ -78,31 +129,37 @@ export function createNotesTab(notesFiles: NotesFiles) {
|
|
|
78
129
|
}, { allowEditable: true });
|
|
79
130
|
|
|
80
131
|
usePaneFooter("ticker-notes", () => ({
|
|
81
|
-
info:
|
|
82
|
-
{ id: "
|
|
83
|
-
|
|
84
|
-
}), [notesFocused]);
|
|
132
|
+
info: loadError
|
|
133
|
+
? [{ id: "load-error", parts: [{ text: loadError, tone: "warning" as const }] }]
|
|
134
|
+
: [{ id: "mode", parts: [{ text: notesFocused ? "editing" : "viewing", tone: "muted" as const }] }],
|
|
135
|
+
}), [loadError, notesFocused]);
|
|
85
136
|
|
|
86
137
|
if (!ticker) return <Text fg={colors.textDim}>Select a ticker to view notes.</Text>;
|
|
87
138
|
|
|
88
139
|
return (
|
|
89
140
|
<Box flexDirection="column" flexGrow={1}>
|
|
90
|
-
<Box flexGrow={1} minHeight={0} paddingX={1} onMouseDown={() => { if (!notesFocused) setNotesFocusedAndCapture(true); }}>
|
|
91
|
-
{
|
|
141
|
+
<Box flexGrow={1} minHeight={0} paddingX={1} onMouseDown={() => { if (!notesFocused && !loadError) setNotesFocusedAndCapture(true); }}>
|
|
142
|
+
{loadError ? (
|
|
143
|
+
<EmptyState
|
|
144
|
+
title="These notes could not be read."
|
|
145
|
+
message={loadError}
|
|
146
|
+
hint="Editing is disabled so the saved note is not overwritten."
|
|
147
|
+
/>
|
|
148
|
+
) : notesFocused ? (
|
|
92
149
|
<MarkdownEditor
|
|
93
|
-
textareaKey=
|
|
94
|
-
focused={
|
|
150
|
+
textareaKey="editing"
|
|
151
|
+
focused={focused}
|
|
95
152
|
initialValue={noteText}
|
|
96
153
|
placeholder="Write notes about this ticker..."
|
|
97
154
|
onRef={(ref) => { textareaRef.current = ref; }}
|
|
98
|
-
onChange={
|
|
155
|
+
onChange={handleNoteChange}
|
|
99
156
|
/>
|
|
100
157
|
) : (
|
|
101
158
|
<MarkdownNotePreview
|
|
102
159
|
text={noteText}
|
|
103
160
|
width={width}
|
|
104
161
|
placeholder="Write notes about this ticker..."
|
|
105
|
-
onActivate={() => setNotesFocusedAndCapture(true)}
|
|
162
|
+
onActivate={() => { if (!loadError) setNotesFocusedAndCapture(true); }}
|
|
106
163
|
/>
|
|
107
164
|
)}
|
|
108
165
|
</Box>
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import type { OptionContract } from "../../../types/financials";
|
|
3
|
+
import { draftFromParams } from "../options-calculator/model";
|
|
4
|
+
import { buildChainCalcParams, resolveCalcSide } from "./calc-seed";
|
|
5
|
+
import type { OptionTableRow } from "./types";
|
|
6
|
+
|
|
7
|
+
const NOW = Date.UTC(2026, 7, 20, 18, 0, 0);
|
|
8
|
+
const EXPIRATION = Date.UTC(2026, 8, 19) / 1000;
|
|
9
|
+
|
|
10
|
+
function contract(overrides: Partial<OptionContract> = {}): OptionContract {
|
|
11
|
+
return {
|
|
12
|
+
contractSymbol: "AAPL260919C00230000",
|
|
13
|
+
strike: 230,
|
|
14
|
+
currency: "USD",
|
|
15
|
+
lastPrice: 7.35,
|
|
16
|
+
change: 0,
|
|
17
|
+
percentChange: 0,
|
|
18
|
+
volume: 10,
|
|
19
|
+
openInterest: 100,
|
|
20
|
+
bid: 7.2,
|
|
21
|
+
ask: 7.5,
|
|
22
|
+
impliedVolatility: 0.284,
|
|
23
|
+
inTheMoney: true,
|
|
24
|
+
expiration: EXPIRATION,
|
|
25
|
+
lastTradeDate: 0,
|
|
26
|
+
...overrides,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function row(overrides: Partial<OptionTableRow> = {}): OptionTableRow {
|
|
31
|
+
return { strike: 230, call: contract(), put: contract(), isPositionStrike: false, ...overrides };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
describe("resolveCalcSide", () => {
|
|
35
|
+
test("uses the explicit side a call or put cell click chose", () => {
|
|
36
|
+
expect(resolveCalcSide("put", "C", row())).toBe("put");
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test("prefers the side of an option position when nothing was clicked", () => {
|
|
40
|
+
expect(resolveCalcSide(null, "P", row())).toBe("put");
|
|
41
|
+
expect(resolveCalcSide(null, "C", row())).toBe("call");
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test("defaults to the call without a position", () => {
|
|
45
|
+
expect(resolveCalcSide(null, null, row())).toBe("call");
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test("falls back to whichever contract the strike actually has", () => {
|
|
49
|
+
expect(resolveCalcSide("call", null, row({ call: undefined }))).toBe("put");
|
|
50
|
+
expect(resolveCalcSide(null, "P", row({ put: undefined }))).toBe("call");
|
|
51
|
+
expect(resolveCalcSide("call", null, row({ call: undefined, put: undefined }))).toBeNull();
|
|
52
|
+
expect(resolveCalcSide("call", null, null)).toBeNull();
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
describe("buildChainCalcParams", () => {
|
|
57
|
+
test("seeds the calculator from the selected contract", () => {
|
|
58
|
+
const params = buildChainCalcParams({
|
|
59
|
+
symbol: "AAPL",
|
|
60
|
+
row: row(),
|
|
61
|
+
side: "put",
|
|
62
|
+
spot: 231.5,
|
|
63
|
+
dividendYield: 0.0044,
|
|
64
|
+
now: NOW,
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
expect(draftFromParams(params!)).toMatchObject({
|
|
68
|
+
symbol: "AAPL",
|
|
69
|
+
side: "put",
|
|
70
|
+
spot: 231.5,
|
|
71
|
+
strike: 230,
|
|
72
|
+
volatility: 0.284,
|
|
73
|
+
marketPrice: 7.35,
|
|
74
|
+
dividendYield: 0.0044,
|
|
75
|
+
});
|
|
76
|
+
expect(draftFromParams(params!).daysToExpiry).toBeCloseTo(30 + 2 / 24, 8);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
test("uses the mid when the contract has not traded", () => {
|
|
80
|
+
const params = buildChainCalcParams({
|
|
81
|
+
symbol: "AAPL",
|
|
82
|
+
row: row({ call: contract({ lastPrice: 0, bid: 7, ask: 8 }) }),
|
|
83
|
+
side: "call",
|
|
84
|
+
spot: 231.5,
|
|
85
|
+
dividendYield: null,
|
|
86
|
+
now: NOW,
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
expect(draftFromParams(params!).marketPrice).toBe(7.5);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
test("returns nothing without a contract or a trustworthy underlying spot", () => {
|
|
93
|
+
expect(buildChainCalcParams({
|
|
94
|
+
symbol: "AAPL",
|
|
95
|
+
row: row({ put: undefined }),
|
|
96
|
+
side: "put",
|
|
97
|
+
spot: 231.5,
|
|
98
|
+
dividendYield: null,
|
|
99
|
+
now: NOW,
|
|
100
|
+
})).toBeNull();
|
|
101
|
+
expect(buildChainCalcParams({
|
|
102
|
+
symbol: "AAPL",
|
|
103
|
+
row: null,
|
|
104
|
+
side: null,
|
|
105
|
+
spot: 231.5,
|
|
106
|
+
dividendYield: null,
|
|
107
|
+
now: NOW,
|
|
108
|
+
})).toBeNull();
|
|
109
|
+
expect(buildChainCalcParams({
|
|
110
|
+
symbol: "AAPL",
|
|
111
|
+
row: row(),
|
|
112
|
+
side: "call",
|
|
113
|
+
spot: null,
|
|
114
|
+
dividendYield: null,
|
|
115
|
+
now: NOW,
|
|
116
|
+
})).toBeNull();
|
|
117
|
+
});
|
|
118
|
+
});
|