gloomberb 0.1.0 → 0.3.1
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 +25 -0
- package/README.md +68 -121
- package/bin/gloomberb +3 -0
- package/package.json +13 -4
- package/patches/@opentui%2Fcore@0.1.90.patch +356 -0
- package/src/app.tsx +1330 -0
- package/src/brokers/sync-broker-instance.test.ts +100 -0
- package/src/brokers/sync-broker-instance.ts +341 -0
- package/src/cli/commands/plugins.ts +173 -0
- package/src/cli/commands/portfolio.ts +210 -0
- package/src/cli/commands/search.ts +120 -0
- package/src/cli/commands/ticker.ts +375 -0
- package/src/cli/commands/watchlist.ts +210 -0
- package/src/cli/context.ts +62 -0
- package/src/cli/errors.ts +13 -0
- package/src/cli/helpers.ts +85 -0
- package/src/cli/index.ts +143 -0
- package/src/cli/ticker-resolution.ts +39 -0
- package/src/cli/types.ts +15 -0
- package/src/cli.test.ts +361 -0
- package/src/components/chart/chart-data.ts +239 -0
- package/src/components/chart/chart-renderer.ts +1199 -0
- package/src/components/chart/chart-types.ts +82 -0
- package/src/components/chart/chart-viewport.ts +21 -0
- package/src/components/chart/chart.test.ts +439 -0
- package/src/components/chart/comparison-chart-data.test.ts +109 -0
- package/src/components/chart/comparison-chart-data.ts +316 -0
- package/src/components/chart/comparison-chart-renderer.test.ts +84 -0
- package/src/components/chart/comparison-chart-renderer.ts +354 -0
- package/src/components/chart/comparison-stock-chart.tsx +1486 -0
- package/src/components/chart/cursor-motion.ts +48 -0
- package/src/components/chart/native/chart-rasterizer.ts +732 -0
- package/src/components/chart/native/kitty-adapter.ts +12 -0
- package/src/components/chart/native/kitty-manager.ts +142 -0
- package/src/components/chart/native/kitty-protocol.ts +110 -0
- package/src/components/chart/native/kitty-support.ts +71 -0
- package/src/components/chart/native/kitty.test.ts +620 -0
- package/src/components/chart/native/renderer-selection.ts +24 -0
- package/src/components/chart/native/surface-manager.ts +225 -0
- package/src/components/chart/native/surface-sync.ts +34 -0
- package/src/components/chart/stock-chart-renderer-switch.test.tsx +165 -0
- package/src/components/chart/stock-chart.test.ts +107 -0
- package/src/components/chart/stock-chart.tsx +1556 -0
- package/src/components/command-bar/__snapshots__/command-bar.test.tsx.snap +137 -0
- package/src/components/command-bar/command-bar.test.tsx +1524 -0
- package/src/components/command-bar/command-bar.tsx +4823 -0
- package/src/components/command-bar/command-registry.ts +261 -0
- package/src/components/command-bar/helpers.test.ts +224 -0
- package/src/components/command-bar/helpers.ts +371 -0
- package/src/components/command-bar/root-shortcuts.ts +158 -0
- package/src/components/command-bar/view-model.test.ts +152 -0
- package/src/components/command-bar/view-model.ts +185 -0
- package/src/components/command-bar/workflow-ops.test.ts +70 -0
- package/src/components/command-bar/workflow-ops.ts +433 -0
- package/src/components/command-bar/workflow-types.ts +127 -0
- package/src/components/detail-feed-view.test.tsx +105 -0
- package/src/components/detail-feed-view.tsx +295 -0
- package/src/components/index.ts +32 -0
- package/src/components/layout/floating-pane.tsx +49 -0
- package/src/components/layout/header.tsx +129 -0
- package/src/components/layout/pane-header.tsx +44 -0
- package/src/components/layout/pane.tsx +49 -0
- package/src/components/layout/pixel-mouse-mode.test.ts +122 -0
- package/src/components/layout/pixel-mouse.test.ts +40 -0
- package/src/components/layout/shell.test.tsx +625 -0
- package/src/components/layout/shell.tsx +1200 -0
- package/src/components/layout/status-bar.test.tsx +173 -0
- package/src/components/layout/status-bar.tsx +138 -0
- package/src/components/markdown-editor.tsx +134 -0
- package/src/components/onboarding/onboarding-wizard.test.tsx +184 -0
- package/src/components/onboarding/onboarding-wizard.tsx +1365 -0
- package/src/components/pane-settings-dialog.tsx +468 -0
- package/src/components/pane-template-wizard.test.tsx +52 -0
- package/src/components/pane-template-wizard.tsx +199 -0
- package/src/components/price-selector-dialog.tsx +195 -0
- package/src/components/spinner.tsx +2 -0
- package/src/components/tab-bar.tsx +17 -0
- package/src/components/ticker-badge-text.test.tsx +160 -0
- package/src/components/ticker-badge-text.tsx +58 -0
- package/src/components/ticker-badge.tsx +88 -0
- package/src/components/ticker-list-table.tsx +188 -0
- package/src/components/toggle-list.tsx +74 -0
- package/src/components/ui/button.tsx +77 -0
- package/src/components/ui/data-table.tsx +210 -0
- package/src/components/ui/external-link.tsx +22 -0
- package/src/components/ui/fields.tsx +187 -0
- package/src/components/ui/frame.tsx +73 -0
- package/src/components/ui/index.ts +53 -0
- package/src/components/ui/list-view.tsx +166 -0
- package/src/components/ui/loading.tsx +70 -0
- package/src/components/ui/status.tsx +83 -0
- package/src/components/ui/tabs.tsx +47 -0
- package/src/components/ui/toggle.tsx +164 -0
- package/src/components/ui/ui.test.tsx +134 -0
- package/src/data/app-persistence.ts +25 -0
- package/src/data/config-store.test.ts +310 -0
- package/src/data/config-store.ts +469 -0
- package/src/data/plugin-state-store.ts +102 -0
- package/src/data/resource-store.ts +323 -0
- package/src/data/session-store.ts +52 -0
- package/src/data/sqlite-cache.test.ts +103 -0
- package/src/data/sqlite-database.ts +62 -0
- package/src/data/sqlite-json.ts +19 -0
- package/src/data/ticker-repository.ts +45 -0
- package/src/data/ticker-store.ts +46 -0
- package/src/index.tsx +67 -0
- package/src/market-data/coordinator.test.ts +369 -0
- package/src/market-data/coordinator.ts +580 -0
- package/src/market-data/hooks.tsx +234 -0
- package/src/market-data/query-store.ts +28 -0
- package/src/market-data/request-types.test.ts +64 -0
- package/src/market-data/request-types.ts +70 -0
- package/src/market-data/result-types.ts +56 -0
- package/src/market-data/selectors.ts +166 -0
- package/src/market-data/trace.ts +7 -0
- package/src/pane-settings.test.ts +71 -0
- package/src/pane-settings.ts +73 -0
- package/src/plugins/builtin/ai/ask-ai-detail-tab.tsx +338 -0
- package/src/plugins/builtin/ai/gloomberb-cli.ts +70 -0
- package/src/plugins/builtin/ai/index.test.tsx +139 -0
- package/src/plugins/builtin/ai/index.tsx +86 -0
- package/src/plugins/builtin/ai/providers.ts +99 -0
- package/src/plugins/builtin/ai/runner.ts +82 -0
- package/src/plugins/builtin/ai/screener-contract.test.ts +117 -0
- package/src/plugins/builtin/ai/screener-contract.ts +174 -0
- package/src/plugins/builtin/ai/screener-pane.test.tsx +365 -0
- package/src/plugins/builtin/ai/screener-pane.tsx +1161 -0
- package/src/plugins/builtin/ai/settings.ts +79 -0
- package/src/plugins/builtin/ai/ticker-context.ts +64 -0
- package/src/plugins/builtin/ai/utils.ts +71 -0
- package/src/plugins/builtin/ask-ai.test.tsx +258 -0
- package/src/plugins/builtin/ask-ai.tsx +9 -0
- package/src/plugins/builtin/chat-controller.test.ts +217 -0
- package/src/plugins/builtin/chat-controller.ts +340 -0
- package/src/plugins/builtin/chat.test.tsx +451 -0
- package/src/plugins/builtin/chat.tsx +620 -0
- package/src/plugins/builtin/comparison-chart.test.tsx +277 -0
- package/src/plugins/builtin/comparison-chart.tsx +169 -0
- package/src/plugins/builtin/data-providers.ts +16 -0
- package/src/plugins/builtin/debug.tsx +351 -0
- package/src/plugins/builtin/help.test.tsx +110 -0
- package/src/plugins/builtin/help.tsx +281 -0
- package/src/plugins/builtin/layout-manager.tsx +264 -0
- package/src/plugins/builtin/manual-entry.tsx +25 -0
- package/src/plugins/builtin/news.tsx +143 -0
- package/src/plugins/builtin/notes-files.ts +58 -0
- package/src/plugins/builtin/notes.tsx +396 -0
- package/src/plugins/builtin/options-availability.test.tsx +179 -0
- package/src/plugins/builtin/options-availability.ts +158 -0
- package/src/plugins/builtin/options.tsx +364 -0
- package/src/plugins/builtin/portfolio-list/header.tsx +227 -0
- package/src/plugins/builtin/portfolio-list/index.tsx +99 -0
- package/src/plugins/builtin/portfolio-list/metrics.ts +436 -0
- package/src/plugins/builtin/portfolio-list/pane.tsx +533 -0
- package/src/plugins/builtin/portfolio-list/settings.ts +280 -0
- package/src/plugins/builtin/portfolio-list/summary.tsx +270 -0
- package/src/plugins/builtin/portfolio-list/table.tsx +64 -0
- package/src/plugins/builtin/portfolio-list.test.ts +74 -0
- package/src/plugins/builtin/portfolio-list.test.tsx +1164 -0
- package/src/plugins/builtin/portfolio-metrics.test.ts +153 -0
- package/src/plugins/builtin/quote-monitor.test.tsx +114 -0
- package/src/plugins/builtin/sec.tsx +250 -0
- package/src/plugins/builtin/ticker-detail/chart-tab.tsx +43 -0
- package/src/plugins/builtin/ticker-detail/financials-tab.tsx +390 -0
- package/src/plugins/builtin/ticker-detail/index.tsx +80 -0
- package/src/plugins/builtin/ticker-detail/overview-tab.tsx +242 -0
- package/src/plugins/builtin/ticker-detail/pane.tsx +183 -0
- package/src/plugins/builtin/ticker-detail/quote-monitor.tsx +83 -0
- package/src/plugins/builtin/ticker-detail/settings.ts +132 -0
- package/src/plugins/builtin/ticker-detail-chart-tab-switch.test.tsx +193 -0
- package/src/plugins/builtin/ticker-detail.test.tsx +578 -0
- package/src/plugins/builtin/yahoo.ts +18 -0
- package/src/plugins/event-bus.ts +37 -0
- package/src/plugins/ibkr/__snapshots__/trade-tab.test.tsx.snap +35 -0
- package/src/plugins/ibkr/account-cache.test.ts +101 -0
- package/src/plugins/ibkr/account-cache.ts +137 -0
- package/src/plugins/ibkr/broker-adapter.ts +168 -0
- package/src/plugins/ibkr/config.test.ts +68 -0
- package/src/plugins/ibkr/config.ts +262 -0
- package/src/plugins/ibkr/dialogs.tsx +83 -0
- package/src/plugins/ibkr/flex.test.ts +107 -0
- package/src/plugins/ibkr/flex.ts +267 -0
- package/src/plugins/ibkr/fundamental-parser.ts +149 -0
- package/src/plugins/ibkr/gateway-helpers.ts +28 -0
- package/src/plugins/ibkr/gateway-selection.ts +51 -0
- package/src/plugins/ibkr/gateway-service.test.ts +450 -0
- package/src/plugins/ibkr/gateway-service.ts +2228 -0
- package/src/plugins/ibkr/index.test.tsx +183 -0
- package/src/plugins/ibkr/index.tsx +153 -0
- package/src/plugins/ibkr/instance-selection.test.ts +121 -0
- package/src/plugins/ibkr/instance-selection.ts +36 -0
- package/src/plugins/ibkr/price-normalization.test.ts +38 -0
- package/src/plugins/ibkr/price-normalization.ts +59 -0
- package/src/plugins/ibkr/trade-badge.tsx +27 -0
- package/src/plugins/ibkr/trade-tab.test.tsx +225 -0
- package/src/plugins/ibkr/trade-tab.tsx +1050 -0
- package/src/plugins/ibkr/trade-utils.test.ts +175 -0
- package/src/plugins/ibkr/trade-utils.ts +149 -0
- package/src/plugins/ibkr/trading-pane.tsx +438 -0
- package/src/plugins/ibkr/trading-state.test.ts +109 -0
- package/src/plugins/ibkr/trading-state.ts +339 -0
- package/src/plugins/loader.ts +71 -0
- package/src/plugins/pane-manager.test.ts +103 -0
- package/src/plugins/pane-manager.ts +974 -0
- package/src/plugins/plugin-persistence.ts +85 -0
- package/src/plugins/plugin-runtime.test.tsx +185 -0
- package/src/plugins/plugin-runtime.tsx +175 -0
- package/src/plugins/prediction-markets/cache.ts +114 -0
- package/src/plugins/prediction-markets/categories.ts +223 -0
- package/src/plugins/prediction-markets/chart.tsx +512 -0
- package/src/plugins/prediction-markets/columns.ts +133 -0
- package/src/plugins/prediction-markets/controller-data.ts +614 -0
- package/src/plugins/prediction-markets/controller.ts +725 -0
- package/src/plugins/prediction-markets/detail/book.tsx +118 -0
- package/src/plugins/prediction-markets/detail/outcomes.tsx +102 -0
- package/src/plugins/prediction-markets/detail/overview.tsx +73 -0
- package/src/plugins/prediction-markets/detail/pane.tsx +308 -0
- package/src/plugins/prediction-markets/detail/rules.tsx +16 -0
- package/src/plugins/prediction-markets/detail/shared.tsx +29 -0
- package/src/plugins/prediction-markets/detail/trades.tsx +30 -0
- package/src/plugins/prediction-markets/detail.test.tsx +47 -0
- package/src/plugins/prediction-markets/index.tsx +102 -0
- package/src/plugins/prediction-markets/keyboard.ts +64 -0
- package/src/plugins/prediction-markets/launch.test.ts +126 -0
- package/src/plugins/prediction-markets/launch.ts +240 -0
- package/src/plugins/prediction-markets/metrics.ts +311 -0
- package/src/plugins/prediction-markets/navigation.ts +90 -0
- package/src/plugins/prediction-markets/outcome-order.ts +19 -0
- package/src/plugins/prediction-markets/pane.test.tsx +425 -0
- package/src/plugins/prediction-markets/pane.tsx +294 -0
- package/src/plugins/prediction-markets/plugin.test.tsx +570 -0
- package/src/plugins/prediction-markets/rows.ts +229 -0
- package/src/plugins/prediction-markets/services/fetch.ts +97 -0
- package/src/plugins/prediction-markets/services/kalshi-adapter.ts +555 -0
- package/src/plugins/prediction-markets/services/polymarket-adapter.ts +660 -0
- package/src/plugins/prediction-markets/services/polymarket-ws.ts +108 -0
- package/src/plugins/prediction-markets/settings.ts +164 -0
- package/src/plugins/prediction-markets/status.ts +24 -0
- package/src/plugins/prediction-markets/table.tsx +84 -0
- package/src/plugins/prediction-markets/test-helpers.tsx +636 -0
- package/src/plugins/prediction-markets/types.ts +186 -0
- package/src/plugins/registry.ts +633 -0
- package/src/sources/exchange-rates.ts +18 -0
- package/src/sources/gloomberb-cloud.test.ts +199 -0
- package/src/sources/gloomberb-cloud.ts +326 -0
- package/src/sources/provider-errors.ts +19 -0
- package/src/sources/provider-router.test.ts +1476 -0
- package/src/sources/provider-router.ts +1405 -0
- package/src/sources/sec-edgar.test.ts +286 -0
- package/src/sources/sec-edgar.ts +526 -0
- package/src/sources/yahoo-finance.test.ts +14 -0
- package/src/sources/yahoo-finance.ts +1017 -0
- package/src/state/app-activity.test.ts +41 -0
- package/src/state/app-activity.ts +106 -0
- package/src/state/app-bootstrap.test.ts +471 -0
- package/src/state/app-bootstrap.ts +308 -0
- package/src/state/app-context.test.ts +406 -0
- package/src/state/app-context.test.tsx +132 -0
- package/src/state/app-context.tsx +969 -0
- package/src/state/selectors.ts +67 -0
- package/src/state/session-persistence.test.ts +128 -0
- package/src/state/session-persistence.ts +161 -0
- package/src/state/ticker-refresh-queue.test.ts +46 -0
- package/src/state/ticker-refresh-queue.ts +40 -0
- package/src/state/use-inline-tickers.ts +174 -0
- package/src/state/use-quote-streaming.test.ts +37 -0
- package/src/state/use-quote-streaming.test.tsx +70 -0
- package/src/state/use-quote-streaming.ts +80 -0
- package/src/state/use-session-snapshot.ts +84 -0
- package/src/test-support/data-provider.ts +22 -0
- package/src/theme/color-utils.ts +67 -0
- package/src/theme/colors.ts +128 -0
- package/src/theme/themes.test.ts +45 -0
- package/src/theme/themes.ts +491 -0
- package/src/types/broker.ts +105 -0
- package/src/types/config.ts +434 -0
- package/src/types/data-provider.ts +81 -0
- package/src/types/financials.ts +142 -0
- package/src/types/instrument.ts +29 -0
- package/src/types/persistence.ts +21 -0
- package/src/types/plugin.ts +354 -0
- package/src/types/ticker.ts +58 -0
- package/src/types/trading.ts +85 -0
- package/src/updater.test.ts +162 -0
- package/src/updater.ts +247 -0
- package/src/utils/api-client.ts +666 -0
- package/src/utils/ascii-chart.ts +172 -0
- package/src/utils/broker-instances.ts +47 -0
- package/src/utils/cli-output.ts +83 -0
- package/src/utils/currency-units.test.ts +49 -0
- package/src/utils/currency-units.ts +82 -0
- package/src/utils/debug-log.ts +133 -0
- package/src/utils/exchange-rate-map.ts +8 -0
- package/src/utils/format.ts +158 -0
- package/src/utils/fuzzy-search.ts +34 -0
- package/src/utils/market-status.ts +95 -0
- package/src/utils/options.ts +86 -0
- package/src/utils/price-history.ts +39 -0
- package/src/utils/quote-time.test.ts +22 -0
- package/src/utils/quote-time.ts +50 -0
- package/src/utils/sec.test.ts +55 -0
- package/src/utils/sec.ts +45 -0
- package/src/utils/ticker-list.test.ts +22 -0
- package/src/utils/ticker-list.ts +35 -0
- package/src/utils/ticker-metadata.ts +51 -0
- package/src/utils/ticker-search.test.ts +227 -0
- package/src/utils/ticker-search.ts +764 -0
- package/src/utils/ticker-tokenizer.test.ts +48 -0
- package/src/utils/ticker-tokenizer.ts +72 -0
- package/src/version.ts +1 -0
- package/install.mjs +0 -69
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
import { TextAttributes } from "@opentui/core";
|
|
2
|
+
import { useTerminalDimensions } from "@opentui/react";
|
|
3
|
+
import { useFxRatesMap } from "../../../market-data/hooks";
|
|
4
|
+
import { useAppState, usePaneTicker } from "../../../state/app-context";
|
|
5
|
+
import { colors, priceColor } from "../../../theme/colors";
|
|
6
|
+
import {
|
|
7
|
+
convertCurrency,
|
|
8
|
+
formatCompact,
|
|
9
|
+
formatCompactCurrency,
|
|
10
|
+
formatCurrency,
|
|
11
|
+
formatNumber,
|
|
12
|
+
formatPercent,
|
|
13
|
+
formatPercentRaw,
|
|
14
|
+
} from "../../../utils/format";
|
|
15
|
+
import {
|
|
16
|
+
exchangeShortName,
|
|
17
|
+
marketStateColor,
|
|
18
|
+
marketStateLabel,
|
|
19
|
+
} from "../../../utils/market-status";
|
|
20
|
+
import { selectEffectiveExchangeRates } from "../../../utils/exchange-rate-map";
|
|
21
|
+
import { EmptyState, FieldRow } from "../../../components";
|
|
22
|
+
import { StockChart } from "../../../components/chart/stock-chart";
|
|
23
|
+
|
|
24
|
+
export function OverviewTab({ width }: { width?: number }) {
|
|
25
|
+
const { state } = useAppState();
|
|
26
|
+
const { ticker, financials } = usePaneTicker();
|
|
27
|
+
const { width: termWidth } = useTerminalDimensions();
|
|
28
|
+
|
|
29
|
+
if (!ticker) return <EmptyState title="No ticker selected." />;
|
|
30
|
+
|
|
31
|
+
const quote = financials?.quote;
|
|
32
|
+
const fundamentals = financials?.fundamentals;
|
|
33
|
+
const profile = financials?.profile;
|
|
34
|
+
const baseCurrency = state.config.baseCurrency;
|
|
35
|
+
const exchangeRates = useFxRatesMap([
|
|
36
|
+
baseCurrency,
|
|
37
|
+
ticker.metadata.currency,
|
|
38
|
+
quote?.currency,
|
|
39
|
+
...ticker.metadata.positions.map((position) => position.currency),
|
|
40
|
+
]);
|
|
41
|
+
const effectiveExchangeRates = selectEffectiveExchangeRates(exchangeRates, state.exchangeRates);
|
|
42
|
+
const quoteCurrency = quote?.currency ?? ticker.metadata.currency ?? baseCurrency;
|
|
43
|
+
const toBase = (value: number, fromCurrency: string) =>
|
|
44
|
+
convertCurrency(value, fromCurrency, baseCurrency, effectiveExchangeRates);
|
|
45
|
+
const sector = ticker.metadata.sector ?? profile?.sector;
|
|
46
|
+
const industry = ticker.metadata.industry ?? profile?.industry;
|
|
47
|
+
const description = profile?.description?.trim();
|
|
48
|
+
|
|
49
|
+
const chartWidth = Math.max((width || Math.floor(termWidth * 0.5)) - 4, 20);
|
|
50
|
+
const hasHistory = (financials?.priceHistory?.length ?? 0) > 2;
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<scrollbox flexGrow={1} scrollY>
|
|
54
|
+
<box flexDirection="column" paddingX={1} paddingBottom={1} gap={1}>
|
|
55
|
+
<box flexDirection="row">
|
|
56
|
+
<text attributes={TextAttributes.BOLD} fg={colors.textBright}>
|
|
57
|
+
{ticker.metadata.ticker}
|
|
58
|
+
</text>
|
|
59
|
+
{ticker.metadata.name && ticker.metadata.name !== ticker.metadata.ticker && (
|
|
60
|
+
<text fg={colors.textDim}>
|
|
61
|
+
{" "}- {ticker.metadata.name || quote?.name || ""}
|
|
62
|
+
</text>
|
|
63
|
+
)}
|
|
64
|
+
{quote?.exchangeName && (
|
|
65
|
+
<text fg={colors.textDim}>
|
|
66
|
+
{" "}({exchangeShortName(quote.exchangeName, quote.fullExchangeName)})
|
|
67
|
+
</text>
|
|
68
|
+
)}
|
|
69
|
+
{quote?.marketState && (
|
|
70
|
+
<text fg={marketStateColor(quote.marketState)}>
|
|
71
|
+
{" "}{marketStateLabel(quote.marketState)}
|
|
72
|
+
</text>
|
|
73
|
+
)}
|
|
74
|
+
</box>
|
|
75
|
+
|
|
76
|
+
{quote && (
|
|
77
|
+
<box flexDirection="column" gap={0}>
|
|
78
|
+
<box flexDirection="row" gap={2}>
|
|
79
|
+
<text attributes={TextAttributes.BOLD} fg={priceColor(quote.change)}>
|
|
80
|
+
{formatCurrency(quote.price, quote.currency)}
|
|
81
|
+
</text>
|
|
82
|
+
<text fg={priceColor(quote.change)}>
|
|
83
|
+
{quote.change >= 0 ? "+" : ""}
|
|
84
|
+
{quote.change.toFixed(2)} ({formatPercentRaw(quote.changePercent)})
|
|
85
|
+
</text>
|
|
86
|
+
</box>
|
|
87
|
+
{(quote.marketState === "PRE" || quote.marketState === "PREPRE") && quote.preMarketPrice != null && (
|
|
88
|
+
<box flexDirection="row" gap={2}>
|
|
89
|
+
<text fg={colors.textDim}>Pre-Market:</text>
|
|
90
|
+
<text fg={priceColor(quote.preMarketChange ?? 0)}>
|
|
91
|
+
{formatCurrency(quote.preMarketPrice, quote.currency)}
|
|
92
|
+
</text>
|
|
93
|
+
<text fg={priceColor(quote.preMarketChange ?? 0)}>
|
|
94
|
+
{(quote.preMarketChange ?? 0) >= 0 ? "+" : ""}
|
|
95
|
+
{(quote.preMarketChange ?? 0).toFixed(2)} ({formatPercentRaw(quote.preMarketChangePercent ?? 0)})
|
|
96
|
+
</text>
|
|
97
|
+
</box>
|
|
98
|
+
)}
|
|
99
|
+
{(quote.marketState === "POST" || quote.marketState === "POSTPOST") && quote.postMarketPrice != null && (
|
|
100
|
+
<box flexDirection="row" gap={2}>
|
|
101
|
+
<text fg={colors.textDim}>After-Hours:</text>
|
|
102
|
+
<text fg={priceColor(quote.postMarketChange ?? 0)}>
|
|
103
|
+
{formatCurrency(quote.postMarketPrice, quote.currency)}
|
|
104
|
+
</text>
|
|
105
|
+
<text fg={priceColor(quote.postMarketChange ?? 0)}>
|
|
106
|
+
{(quote.postMarketChange ?? 0) >= 0 ? "+" : ""}
|
|
107
|
+
{(quote.postMarketChange ?? 0).toFixed(2)} ({formatPercentRaw(quote.postMarketChangePercent ?? 0)})
|
|
108
|
+
</text>
|
|
109
|
+
</box>
|
|
110
|
+
)}
|
|
111
|
+
</box>
|
|
112
|
+
)}
|
|
113
|
+
|
|
114
|
+
{hasHistory && (
|
|
115
|
+
<StockChart width={chartWidth} height={8} focused={false} compact />
|
|
116
|
+
)}
|
|
117
|
+
|
|
118
|
+
<box flexDirection="column">
|
|
119
|
+
<FieldRow
|
|
120
|
+
label="Market Cap"
|
|
121
|
+
value={quote?.marketCap ? formatCompactCurrency(toBase(quote.marketCap, quoteCurrency), baseCurrency) : "—"}
|
|
122
|
+
/>
|
|
123
|
+
<FieldRow label="P/E (TTM)" value={fundamentals?.trailingPE ? formatNumber(fundamentals.trailingPE, 1) : "—"} />
|
|
124
|
+
<FieldRow label="Forward P/E" value={fundamentals?.forwardPE ? formatNumber(fundamentals.forwardPE, 1) : "—"} />
|
|
125
|
+
<FieldRow label="PEG Ratio" value={fundamentals?.pegRatio ? formatNumber(fundamentals.pegRatio, 2) : "—"} />
|
|
126
|
+
<FieldRow label="EPS" value={fundamentals?.eps ? formatCurrency(fundamentals.eps, quoteCurrency) : "—"} />
|
|
127
|
+
<FieldRow label="Div Yield" value={fundamentals?.dividendYield != null ? formatPercent(fundamentals.dividendYield) : "—"} />
|
|
128
|
+
<FieldRow label="Revenue" value={fundamentals?.revenue ? formatCompact(fundamentals.revenue) : "—"} />
|
|
129
|
+
<FieldRow label="Net Income" value={fundamentals?.netIncome ? formatCompact(fundamentals.netIncome) : "—"} />
|
|
130
|
+
<FieldRow label="FCF" value={fundamentals?.freeCashFlow ? formatCompact(fundamentals.freeCashFlow) : "—"} />
|
|
131
|
+
<FieldRow label="Op. Margin" value={fundamentals?.operatingMargin != null ? formatPercent(fundamentals.operatingMargin) : "—"} />
|
|
132
|
+
<FieldRow label="Profit Margin" value={fundamentals?.profitMargin != null ? formatPercent(fundamentals.profitMargin) : "—"} />
|
|
133
|
+
{(quote?.bid != null || quote?.ask != null) && (
|
|
134
|
+
<>
|
|
135
|
+
<FieldRow label="Bid" value={quote?.bid != null ? formatCurrency(quote.bid, quote.currency) : "—"} />
|
|
136
|
+
<FieldRow label="Ask" value={quote?.ask != null ? formatCurrency(quote.ask, quote.currency) : "—"} />
|
|
137
|
+
<FieldRow
|
|
138
|
+
label="Spread"
|
|
139
|
+
value={quote?.bid != null && quote?.ask != null ? formatCurrency(quote.ask - quote.bid, quote.currency) : "—"}
|
|
140
|
+
/>
|
|
141
|
+
</>
|
|
142
|
+
)}
|
|
143
|
+
<FieldRow
|
|
144
|
+
label="52W Range"
|
|
145
|
+
value={quote?.low52w && quote?.high52w ? `${formatCurrency(quote.low52w, quoteCurrency)} - ${formatCurrency(quote.high52w, quoteCurrency)}` : "—"}
|
|
146
|
+
/>
|
|
147
|
+
<FieldRow
|
|
148
|
+
label="1Y Return"
|
|
149
|
+
value={fundamentals?.return1Y != null ? formatPercent(fundamentals.return1Y) : "—"}
|
|
150
|
+
valueColor={fundamentals?.return1Y != null ? priceColor(fundamentals.return1Y) : undefined}
|
|
151
|
+
/>
|
|
152
|
+
<FieldRow
|
|
153
|
+
label="3Y Return"
|
|
154
|
+
value={fundamentals?.return3Y != null ? formatPercent(fundamentals.return3Y) : "—"}
|
|
155
|
+
valueColor={fundamentals?.return3Y != null ? priceColor(fundamentals.return3Y) : undefined}
|
|
156
|
+
/>
|
|
157
|
+
</box>
|
|
158
|
+
|
|
159
|
+
{description && (
|
|
160
|
+
<box flexDirection="column" paddingTop={1}>
|
|
161
|
+
<box height={1}>
|
|
162
|
+
<text attributes={TextAttributes.BOLD} fg={colors.textBright}>Description</text>
|
|
163
|
+
</box>
|
|
164
|
+
<text fg={colors.text}>{description}</text>
|
|
165
|
+
</box>
|
|
166
|
+
)}
|
|
167
|
+
|
|
168
|
+
{(sector || industry || ticker.metadata.assetCategory || ticker.metadata.isin) && (
|
|
169
|
+
<box flexDirection="column">
|
|
170
|
+
{ticker.metadata.assetCategory && (
|
|
171
|
+
<FieldRow label="Type" value={ticker.metadata.assetCategory} />
|
|
172
|
+
)}
|
|
173
|
+
{sector && (
|
|
174
|
+
<FieldRow label="Sector" value={sector} />
|
|
175
|
+
)}
|
|
176
|
+
{industry && (
|
|
177
|
+
<FieldRow label="Industry" value={industry} />
|
|
178
|
+
)}
|
|
179
|
+
{ticker.metadata.isin && (
|
|
180
|
+
<FieldRow label="ISIN" value={ticker.metadata.isin} />
|
|
181
|
+
)}
|
|
182
|
+
</box>
|
|
183
|
+
)}
|
|
184
|
+
|
|
185
|
+
{ticker.metadata.positions.length > 0 && (
|
|
186
|
+
<box flexDirection="column">
|
|
187
|
+
<box height={1}>
|
|
188
|
+
<text attributes={TextAttributes.BOLD} fg={colors.textBright}>Positions</text>
|
|
189
|
+
</box>
|
|
190
|
+
{ticker.metadata.positions.map((position, index) => {
|
|
191
|
+
const costBasis = position.shares * position.avgCost * (position.multiplier || 1);
|
|
192
|
+
const positionCurrency = position.currency || quoteCurrency;
|
|
193
|
+
const costBasisBase = toBase(costBasis, positionCurrency);
|
|
194
|
+
const marketValueBase = position.marketValue != null
|
|
195
|
+
? toBase(position.marketValue, positionCurrency)
|
|
196
|
+
: position.markPrice != null
|
|
197
|
+
? toBase(Math.abs(position.shares) * position.markPrice * (position.multiplier || 1), positionCurrency)
|
|
198
|
+
: quote
|
|
199
|
+
? toBase(Math.abs(position.shares) * quote.price * (position.multiplier || 1), quoteCurrency)
|
|
200
|
+
: null;
|
|
201
|
+
const pnlValue = position.unrealizedPnl != null
|
|
202
|
+
? toBase(position.unrealizedPnl, positionCurrency)
|
|
203
|
+
: marketValueBase != null
|
|
204
|
+
? marketValueBase - costBasisBase
|
|
205
|
+
: null;
|
|
206
|
+
const pnlText = pnlValue != null
|
|
207
|
+
? ` P&L: ${pnlValue >= 0 ? "+" : ""}${formatCurrency(pnlValue, baseCurrency)}`
|
|
208
|
+
: "";
|
|
209
|
+
|
|
210
|
+
return (
|
|
211
|
+
<box key={index} flexDirection="column">
|
|
212
|
+
<box flexDirection="row" height={1}>
|
|
213
|
+
<text fg={colors.textDim}>{position.portfolio}</text>
|
|
214
|
+
<text fg={colors.textMuted}>{" via "}{position.broker}</text>
|
|
215
|
+
{position.side === "short" && <text fg={colors.negative}>{" SHORT"}</text>}
|
|
216
|
+
</box>
|
|
217
|
+
<box flexDirection="row" height={1}>
|
|
218
|
+
<text fg={colors.text}>
|
|
219
|
+
{position.shares} {position.multiplier && position.multiplier > 1 ? "contracts" : "shares"} @ {formatCurrency(position.avgCost, positionCurrency)}
|
|
220
|
+
{" = "}{formatCurrency(costBasisBase, baseCurrency)}
|
|
221
|
+
</text>
|
|
222
|
+
{pnlText && (
|
|
223
|
+
<text fg={priceColor(pnlValue ?? 0)}>{pnlText}</text>
|
|
224
|
+
)}
|
|
225
|
+
</box>
|
|
226
|
+
{position.markPrice != null && (
|
|
227
|
+
<box flexDirection="row" height={1}>
|
|
228
|
+
<text fg={colors.textDim}>Mark: {formatCurrency(position.markPrice, positionCurrency)}</text>
|
|
229
|
+
{marketValueBase != null && (
|
|
230
|
+
<text fg={colors.textDim}>{" "}Mkt Value: {formatCurrency(marketValueBase, baseCurrency)}</text>
|
|
231
|
+
)}
|
|
232
|
+
</box>
|
|
233
|
+
)}
|
|
234
|
+
</box>
|
|
235
|
+
);
|
|
236
|
+
})}
|
|
237
|
+
</box>
|
|
238
|
+
)}
|
|
239
|
+
</box>
|
|
240
|
+
</scrollbox>
|
|
241
|
+
);
|
|
242
|
+
}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import { useKeyboard } from "@opentui/react";
|
|
2
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
3
|
+
import type { DetailTabDef, PaneProps } from "../../../types/plugin";
|
|
4
|
+
import { quoteSubscriptionTargetFromTicker } from "../../../market-data/request-types";
|
|
5
|
+
import {
|
|
6
|
+
useAppState,
|
|
7
|
+
usePaneCollection,
|
|
8
|
+
usePaneInstance,
|
|
9
|
+
usePaneStateValue,
|
|
10
|
+
usePaneTicker,
|
|
11
|
+
} from "../../../state/app-context";
|
|
12
|
+
import { useQuoteStreaming } from "../../../state/use-quote-streaming";
|
|
13
|
+
import { getCollectionName, getCollectionTickers } from "../../../state/selectors";
|
|
14
|
+
import { getSharedRegistry } from "../../registry";
|
|
15
|
+
import { EmptyState } from "../../../components";
|
|
16
|
+
import { TabBar } from "../../../components/tab-bar";
|
|
17
|
+
import { getConfiguredIbkrGatewayInstances } from "../../ibkr/instance-selection";
|
|
18
|
+
import { useOptionsAvailability } from "../options-availability";
|
|
19
|
+
import { ChartTab } from "./chart-tab";
|
|
20
|
+
import { FinancialsTab } from "./financials-tab";
|
|
21
|
+
import { OverviewTab } from "./overview-tab";
|
|
22
|
+
import {
|
|
23
|
+
buildVisibleDetailTabs,
|
|
24
|
+
getTickerDetailPaneSettings,
|
|
25
|
+
resolveLockedTabId,
|
|
26
|
+
} from "./settings";
|
|
27
|
+
|
|
28
|
+
export function TickerDetailPane({ focused, width, height }: PaneProps) {
|
|
29
|
+
const { state, dispatch } = useAppState();
|
|
30
|
+
const paneInstance = usePaneInstance();
|
|
31
|
+
const { ticker, financials } = usePaneTicker();
|
|
32
|
+
const streamingTarget = quoteSubscriptionTargetFromTicker(ticker, ticker?.metadata.ticker, "provider");
|
|
33
|
+
useQuoteStreaming(streamingTarget ? [streamingTarget] : []);
|
|
34
|
+
|
|
35
|
+
const { collectionId } = usePaneCollection();
|
|
36
|
+
const [activeTabId, setActiveTabId] = usePaneStateValue<string>("activeTabId", "overview");
|
|
37
|
+
const [chartInteractive, setChartInteractive] = useState(false);
|
|
38
|
+
const [pluginCaptured, setPluginCaptured] = useState(false);
|
|
39
|
+
const paneSettings = getTickerDetailPaneSettings(paneInstance?.settings);
|
|
40
|
+
const hasOptionsChain = useOptionsAvailability(ticker);
|
|
41
|
+
const collectionTickers = getCollectionTickers(state, collectionId);
|
|
42
|
+
const collectionName = getCollectionName(state, collectionId);
|
|
43
|
+
|
|
44
|
+
const disabledPlugins = state.config.disabledPlugins || [];
|
|
45
|
+
const registry = getSharedRegistry();
|
|
46
|
+
const pluginTabs: DetailTabDef[] = registry
|
|
47
|
+
? [...registry.detailTabs.values()].filter((tab) => !disabledPlugins.includes(tab.id))
|
|
48
|
+
: [];
|
|
49
|
+
const hasIbkrGatewayTrading = getConfiguredIbkrGatewayInstances(state.config).length > 0;
|
|
50
|
+
const allTabs = buildVisibleDetailTabs(pluginTabs, ticker, financials, {
|
|
51
|
+
hasIbkrGatewayTrading,
|
|
52
|
+
hasOptionsChain,
|
|
53
|
+
});
|
|
54
|
+
const resolvedTabId = paneSettings.hideTabs
|
|
55
|
+
? resolveLockedTabId(paneSettings, allTabs)
|
|
56
|
+
: (allTabs.some((tab) => tab.id === activeTabId) ? activeTabId : (allTabs[0]?.id ?? "overview"));
|
|
57
|
+
const activePluginTab = pluginTabs.find((tab) => tab.id === resolvedTabId && allTabs.some((visibleTab) => visibleTab.id === tab.id)) ?? null;
|
|
58
|
+
|
|
59
|
+
const allTabsRef = useRef(allTabs);
|
|
60
|
+
allTabsRef.current = allTabs;
|
|
61
|
+
|
|
62
|
+
const stateRef = useRef({
|
|
63
|
+
focused,
|
|
64
|
+
chartInteractive,
|
|
65
|
+
pluginCaptured,
|
|
66
|
+
activeTabId: resolvedTabId,
|
|
67
|
+
tabIdx: Math.max(0, allTabs.findIndex((tab) => tab.id === resolvedTabId)),
|
|
68
|
+
allTabCount: allTabs.length,
|
|
69
|
+
hideTabs: paneSettings.hideTabs,
|
|
70
|
+
});
|
|
71
|
+
stateRef.current = {
|
|
72
|
+
focused,
|
|
73
|
+
chartInteractive,
|
|
74
|
+
pluginCaptured,
|
|
75
|
+
activeTabId: resolvedTabId,
|
|
76
|
+
tabIdx: Math.max(0, allTabs.findIndex((tab) => tab.id === resolvedTabId)),
|
|
77
|
+
allTabCount: allTabs.length,
|
|
78
|
+
hideTabs: paneSettings.hideTabs,
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const setChartInteractiveEager = useCallback((value: boolean) => {
|
|
82
|
+
stateRef.current = { ...stateRef.current, chartInteractive: value };
|
|
83
|
+
setChartInteractive(value);
|
|
84
|
+
}, []);
|
|
85
|
+
|
|
86
|
+
const handlePluginCapture = useCallback((capturing: boolean) => {
|
|
87
|
+
stateRef.current = { ...stateRef.current, pluginCaptured: capturing };
|
|
88
|
+
setPluginCaptured(capturing);
|
|
89
|
+
dispatch({ type: "SET_INPUT_CAPTURED", captured: capturing });
|
|
90
|
+
}, [dispatch]);
|
|
91
|
+
|
|
92
|
+
useEffect(() => {
|
|
93
|
+
if (resolvedTabId !== "chart") {
|
|
94
|
+
setChartInteractive(false);
|
|
95
|
+
}
|
|
96
|
+
setPluginCaptured(false);
|
|
97
|
+
dispatch({ type: "SET_INPUT_CAPTURED", captured: false });
|
|
98
|
+
}, [resolvedTabId, dispatch]);
|
|
99
|
+
|
|
100
|
+
useEffect(() => {
|
|
101
|
+
if (resolvedTabId !== activeTabId) {
|
|
102
|
+
setActiveTabId(resolvedTabId);
|
|
103
|
+
}
|
|
104
|
+
}, [activeTabId, resolvedTabId, setActiveTabId]);
|
|
105
|
+
|
|
106
|
+
const handleKeyboard = useCallback((event: { name?: string }) => {
|
|
107
|
+
const currentState = stateRef.current;
|
|
108
|
+
if (!currentState.focused || currentState.pluginCaptured) return;
|
|
109
|
+
|
|
110
|
+
if (currentState.activeTabId === "chart") {
|
|
111
|
+
const isEnter = event.name === "enter" || event.name === "return";
|
|
112
|
+
if (event.name === "escape" && currentState.chartInteractive) {
|
|
113
|
+
setChartInteractiveEager(false);
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
if (isEnter && !currentState.chartInteractive) {
|
|
117
|
+
setChartInteractiveEager(true);
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
if (currentState.chartInteractive) return;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (currentState.hideTabs) return;
|
|
124
|
+
|
|
125
|
+
const tabs = allTabsRef.current;
|
|
126
|
+
if (event.name === "h" || event.name === "left") {
|
|
127
|
+
const nextIndex = Math.max(currentState.tabIdx - 1, 0);
|
|
128
|
+
setActiveTabId(tabs[nextIndex]!.id);
|
|
129
|
+
} else if (event.name === "l" || event.name === "right") {
|
|
130
|
+
const nextIndex = Math.min(currentState.tabIdx + 1, currentState.allTabCount - 1);
|
|
131
|
+
setActiveTabId(tabs[nextIndex]!.id);
|
|
132
|
+
}
|
|
133
|
+
}, [setActiveTabId, setChartInteractiveEager]);
|
|
134
|
+
|
|
135
|
+
useKeyboard(handleKeyboard);
|
|
136
|
+
|
|
137
|
+
if (!ticker) {
|
|
138
|
+
const isEmptyFollowCollection = paneInstance?.binding?.kind === "follow" && !!collectionId && collectionTickers.length === 0;
|
|
139
|
+
const message = isEmptyFollowCollection
|
|
140
|
+
? `No tickers in ${collectionName || "this collection"}.`
|
|
141
|
+
: "No ticker selected.";
|
|
142
|
+
|
|
143
|
+
return (
|
|
144
|
+
<box flexDirection="column" flexGrow={1} paddingX={1}>
|
|
145
|
+
<EmptyState title={message} />
|
|
146
|
+
</box>
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return (
|
|
151
|
+
<box flexDirection="column" flexGrow={1}>
|
|
152
|
+
{!paneSettings.hideTabs && (
|
|
153
|
+
<TabBar
|
|
154
|
+
tabs={allTabs.map((tab) => ({ label: tab.name, value: tab.id }))}
|
|
155
|
+
activeValue={resolvedTabId}
|
|
156
|
+
onSelect={setActiveTabId}
|
|
157
|
+
/>
|
|
158
|
+
)}
|
|
159
|
+
|
|
160
|
+
{resolvedTabId === "overview" && <OverviewTab width={width} />}
|
|
161
|
+
{resolvedTabId === "financials" && <FinancialsTab focused={focused} />}
|
|
162
|
+
{resolvedTabId === "chart" && (
|
|
163
|
+
<ChartTab
|
|
164
|
+
width={width}
|
|
165
|
+
height={height}
|
|
166
|
+
focused={focused}
|
|
167
|
+
interactive={chartInteractive}
|
|
168
|
+
axisMode={paneSettings.chartAxisMode}
|
|
169
|
+
onActivate={() => setChartInteractiveEager(true)}
|
|
170
|
+
/>
|
|
171
|
+
)}
|
|
172
|
+
|
|
173
|
+
{activePluginTab && (
|
|
174
|
+
<activePluginTab.component
|
|
175
|
+
width={width}
|
|
176
|
+
height={height}
|
|
177
|
+
focused={focused}
|
|
178
|
+
onCapture={handlePluginCapture}
|
|
179
|
+
/>
|
|
180
|
+
)}
|
|
181
|
+
</box>
|
|
182
|
+
);
|
|
183
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { TextAttributes } from "@opentui/core";
|
|
2
|
+
import type { PaneProps } from "../../../types/plugin";
|
|
3
|
+
import type { Quote } from "../../../types/financials";
|
|
4
|
+
import { quoteSubscriptionTargetFromTicker } from "../../../market-data/request-types";
|
|
5
|
+
import { usePaneTicker } from "../../../state/app-context";
|
|
6
|
+
import { useQuoteStreaming } from "../../../state/use-quote-streaming";
|
|
7
|
+
import { colors, priceColor } from "../../../theme/colors";
|
|
8
|
+
import { formatCurrency, formatPercentRaw } from "../../../utils/format";
|
|
9
|
+
import { getActiveQuoteDisplay } from "../../../utils/market-status";
|
|
10
|
+
import { EmptyState } from "../../../components";
|
|
11
|
+
|
|
12
|
+
function getQuoteMonitorDisplay(quote: Quote | null | undefined) {
|
|
13
|
+
return getActiveQuoteDisplay(quote);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function QuoteMonitorPane({ focused, width }: PaneProps) {
|
|
17
|
+
const { ticker, financials } = usePaneTicker();
|
|
18
|
+
const streamingTarget = quoteSubscriptionTargetFromTicker(ticker, ticker?.metadata.ticker, "provider");
|
|
19
|
+
useQuoteStreaming(streamingTarget ? [streamingTarget] : []);
|
|
20
|
+
|
|
21
|
+
if (!ticker) {
|
|
22
|
+
return (
|
|
23
|
+
<box flexDirection="column" flexGrow={1} paddingX={1}>
|
|
24
|
+
<EmptyState title="No ticker selected." />
|
|
25
|
+
</box>
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const display = getQuoteMonitorDisplay(financials?.quote);
|
|
30
|
+
const changeColor = priceColor(display?.change ?? 0);
|
|
31
|
+
const compact = width < 56;
|
|
32
|
+
const currency = financials?.quote?.currency ?? ticker.metadata.currency ?? "USD";
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<box flexDirection="column" flexGrow={1} backgroundColor={colors.panel} padding={1}>
|
|
36
|
+
<box
|
|
37
|
+
flexGrow={1}
|
|
38
|
+
border
|
|
39
|
+
borderColor={focused ? colors.borderFocused : colors.border}
|
|
40
|
+
backgroundColor={colors.bg}
|
|
41
|
+
paddingX={compact ? 2 : 4}
|
|
42
|
+
paddingY={1}
|
|
43
|
+
justifyContent="center"
|
|
44
|
+
>
|
|
45
|
+
{!display ? (
|
|
46
|
+
<box flexDirection="column" alignItems="center" justifyContent="center" gap={1} flexGrow={1}>
|
|
47
|
+
<text attributes={TextAttributes.BOLD} fg={colors.textBright}>
|
|
48
|
+
{ticker.metadata.ticker}
|
|
49
|
+
</text>
|
|
50
|
+
<text fg={colors.textDim}>Waiting for quote...</text>
|
|
51
|
+
</box>
|
|
52
|
+
) : (
|
|
53
|
+
<box
|
|
54
|
+
flexDirection={compact ? "column" : "row"}
|
|
55
|
+
alignItems={compact ? "flex-start" : "center"}
|
|
56
|
+
justifyContent="space-between"
|
|
57
|
+
gap={compact ? 1 : 2}
|
|
58
|
+
flexGrow={1}
|
|
59
|
+
>
|
|
60
|
+
<box flexGrow={1} justifyContent="center">
|
|
61
|
+
<text attributes={TextAttributes.BOLD} fg={colors.textBright}>
|
|
62
|
+
{ticker.metadata.ticker}
|
|
63
|
+
</text>
|
|
64
|
+
</box>
|
|
65
|
+
|
|
66
|
+
<box flexDirection="column" alignItems={compact ? "flex-start" : "flex-end"}>
|
|
67
|
+
<text attributes={TextAttributes.BOLD} fg={changeColor}>
|
|
68
|
+
{formatCurrency(display.price, currency)}
|
|
69
|
+
</text>
|
|
70
|
+
<box flexDirection="row" gap={1}>
|
|
71
|
+
<text fg={changeColor}>{formatPercentRaw(display.changePercent)}</text>
|
|
72
|
+
<text fg={changeColor}>
|
|
73
|
+
{display.change > 0 ? "+" : ""}
|
|
74
|
+
{display.change.toFixed(2)}
|
|
75
|
+
</text>
|
|
76
|
+
</box>
|
|
77
|
+
</box>
|
|
78
|
+
</box>
|
|
79
|
+
)}
|
|
80
|
+
</box>
|
|
81
|
+
</box>
|
|
82
|
+
);
|
|
83
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import type { PaneSettingsDef, DetailTabDef } from "../../../types/plugin";
|
|
2
|
+
import type { TickerFinancials } from "../../../types/financials";
|
|
3
|
+
import type { TickerRecord } from "../../../types/ticker";
|
|
4
|
+
import type { ChartAxisMode } from "../../../components/chart/chart-types";
|
|
5
|
+
import { getSharedRegistry } from "../../registry";
|
|
6
|
+
|
|
7
|
+
type DetailTabSummary = { id: string; name: string; order: number };
|
|
8
|
+
|
|
9
|
+
const CORE_OVERVIEW_TAB: DetailTabSummary = { id: "overview", name: "Overview", order: 10 };
|
|
10
|
+
const CORE_FINANCIALS_TAB: DetailTabSummary = { id: "financials", name: "Financials", order: 20 };
|
|
11
|
+
const CORE_CHART_TAB: DetailTabSummary = { id: "chart", name: "Chart", order: 30 };
|
|
12
|
+
|
|
13
|
+
export interface TickerDetailPaneSettings {
|
|
14
|
+
hideTabs: boolean;
|
|
15
|
+
lockedTabId: string;
|
|
16
|
+
chartAxisMode: ChartAxisMode;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function getTickerDetailPaneSettings(
|
|
20
|
+
settings: Record<string, unknown> | undefined,
|
|
21
|
+
): TickerDetailPaneSettings {
|
|
22
|
+
return {
|
|
23
|
+
hideTabs: settings?.hideTabs === true,
|
|
24
|
+
lockedTabId: typeof settings?.lockedTabId === "string" ? settings.lockedTabId : "overview",
|
|
25
|
+
chartAxisMode: settings?.chartAxisMode === "percent" ? "percent" : "price",
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function resolveLockedTabId(
|
|
30
|
+
settings: TickerDetailPaneSettings,
|
|
31
|
+
tabs: DetailTabSummary[],
|
|
32
|
+
): string {
|
|
33
|
+
if (tabs.some((tab) => tab.id === settings.lockedTabId)) {
|
|
34
|
+
return settings.lockedTabId;
|
|
35
|
+
}
|
|
36
|
+
return tabs[0]?.id ?? "overview";
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function getAvailableSettingsTabs(): DetailTabSummary[] {
|
|
40
|
+
const registry = getSharedRegistry();
|
|
41
|
+
const pluginTabs = registry
|
|
42
|
+
? [...registry.detailTabs.values()].map((tab) => ({ id: tab.id, name: tab.name, order: tab.order }))
|
|
43
|
+
: [];
|
|
44
|
+
|
|
45
|
+
return [CORE_OVERVIEW_TAB, CORE_FINANCIALS_TAB, CORE_CHART_TAB, ...pluginTabs]
|
|
46
|
+
.sort((left, right) => left.order - right.order)
|
|
47
|
+
.filter((tab, index, allTabs) => allTabs.findIndex((candidate) => candidate.id === tab.id) === index);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function buildTickerDetailSettingsDef(settings: TickerDetailPaneSettings): PaneSettingsDef {
|
|
51
|
+
const tabs = getAvailableSettingsTabs();
|
|
52
|
+
|
|
53
|
+
return {
|
|
54
|
+
title: "Detail Pane Settings",
|
|
55
|
+
fields: [
|
|
56
|
+
{
|
|
57
|
+
key: "hideTabs",
|
|
58
|
+
label: "Hide Tabs",
|
|
59
|
+
description: "Hide the detail tabs and lock this pane to one view.",
|
|
60
|
+
type: "toggle" as const,
|
|
61
|
+
},
|
|
62
|
+
...(settings.hideTabs
|
|
63
|
+
? [{
|
|
64
|
+
key: "lockedTabId",
|
|
65
|
+
label: "Locked Tab",
|
|
66
|
+
description: "Choose which tab this pane should stay pinned to when tabs are hidden.",
|
|
67
|
+
type: "select" as const,
|
|
68
|
+
options: tabs.map((tab) => ({ value: tab.id, label: tab.name })),
|
|
69
|
+
}]
|
|
70
|
+
: []),
|
|
71
|
+
{
|
|
72
|
+
key: "chartAxisMode",
|
|
73
|
+
label: "Chart Y-Axis",
|
|
74
|
+
description: "Show chart values as raw prices or percent change from the first visible point.",
|
|
75
|
+
type: "select" as const,
|
|
76
|
+
options: [
|
|
77
|
+
{ value: "price", label: "Price" },
|
|
78
|
+
{ value: "percent", label: "Percent" },
|
|
79
|
+
],
|
|
80
|
+
},
|
|
81
|
+
],
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function buildQuoteMonitorSettingsDef(): PaneSettingsDef {
|
|
86
|
+
return {
|
|
87
|
+
title: "Quote Monitor Settings",
|
|
88
|
+
fields: [
|
|
89
|
+
{
|
|
90
|
+
key: "symbol",
|
|
91
|
+
label: "Ticker",
|
|
92
|
+
description: "Set the fixed ticker symbol for this quote monitor.",
|
|
93
|
+
type: "text",
|
|
94
|
+
placeholder: "AAPL",
|
|
95
|
+
},
|
|
96
|
+
],
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function hasStatementFinancials(financials: TickerFinancials | null | undefined): boolean {
|
|
101
|
+
return (financials?.annualStatements.length ?? 0) > 0 || (financials?.quarterlyStatements.length ?? 0) > 0;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export function buildVisibleDetailTabs(
|
|
105
|
+
pluginTabs: DetailTabDef[],
|
|
106
|
+
ticker: TickerRecord | null,
|
|
107
|
+
financials: TickerFinancials | null | undefined,
|
|
108
|
+
options: {
|
|
109
|
+
hasIbkrGatewayTrading: boolean;
|
|
110
|
+
hasOptionsChain: boolean;
|
|
111
|
+
},
|
|
112
|
+
): DetailTabSummary[] {
|
|
113
|
+
const tabs: DetailTabSummary[] = [CORE_OVERVIEW_TAB];
|
|
114
|
+
if (hasStatementFinancials(financials)) {
|
|
115
|
+
tabs.push(CORE_FINANCIALS_TAB);
|
|
116
|
+
}
|
|
117
|
+
tabs.push(CORE_CHART_TAB);
|
|
118
|
+
|
|
119
|
+
for (const tab of pluginTabs) {
|
|
120
|
+
if (tab.isVisible && !tab.isVisible({
|
|
121
|
+
ticker,
|
|
122
|
+
financials,
|
|
123
|
+
hasIbkrGatewayTrading: options.hasIbkrGatewayTrading,
|
|
124
|
+
hasOptionsChain: options.hasOptionsChain,
|
|
125
|
+
})) continue;
|
|
126
|
+
if (tab.id === "ibkr-trade" && !options.hasIbkrGatewayTrading) continue;
|
|
127
|
+
if (tab.id === "options" && !options.hasOptionsChain) continue;
|
|
128
|
+
tabs.push({ id: tab.id, name: tab.name, order: tab.order });
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return tabs.sort((left, right) => left.order - right.order);
|
|
132
|
+
}
|