gloomberb 0.2.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/README.md +20 -19
- package/bin/gloomberb +3 -0
- package/package.json +5 -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 -68
|
@@ -0,0 +1,390 @@
|
|
|
1
|
+
import { TextAttributes, type ScrollBoxRenderable } from "@opentui/core";
|
|
2
|
+
import { useKeyboard } from "@opentui/react";
|
|
3
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
4
|
+
import { usePaneTicker } from "../../../state/app-context";
|
|
5
|
+
import { colors, priceColor } from "../../../theme/colors";
|
|
6
|
+
import type { FinancialStatement } from "../../../types/financials";
|
|
7
|
+
import {
|
|
8
|
+
formatGrowthShort,
|
|
9
|
+
formatNumber,
|
|
10
|
+
formatWithDivisor,
|
|
11
|
+
padTo,
|
|
12
|
+
pickUnit,
|
|
13
|
+
} from "../../../utils/format";
|
|
14
|
+
|
|
15
|
+
type MetricDef = {
|
|
16
|
+
label: string;
|
|
17
|
+
key: keyof FinancialStatement;
|
|
18
|
+
format: "compact" | "eps";
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
type FinancialSubTab = {
|
|
22
|
+
name: string;
|
|
23
|
+
key: string;
|
|
24
|
+
metrics: MetricDef[];
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
type FinancialPeriod = "annual" | "quarterly";
|
|
28
|
+
|
|
29
|
+
const FINANCIAL_SUB_TABS: FinancialSubTab[] = [
|
|
30
|
+
{
|
|
31
|
+
name: "Income",
|
|
32
|
+
key: "income",
|
|
33
|
+
metrics: [
|
|
34
|
+
{ label: "Revenue", key: "totalRevenue", format: "compact" },
|
|
35
|
+
{ label: "Cost of Revenue", key: "costOfRevenue", format: "compact" },
|
|
36
|
+
{ label: "Gross Profit", key: "grossProfit", format: "compact" },
|
|
37
|
+
{ label: "R&D", key: "researchAndDevelopment", format: "compact" },
|
|
38
|
+
{ label: "SG&A", key: "sellingGeneralAndAdministration", format: "compact" },
|
|
39
|
+
{ label: "Operating Exp", key: "operatingExpense", format: "compact" },
|
|
40
|
+
{ label: "Operating Inc", key: "operatingIncome", format: "compact" },
|
|
41
|
+
{ label: "Interest Exp", key: "interestExpense", format: "compact" },
|
|
42
|
+
{ label: "Tax Provision", key: "taxProvision", format: "compact" },
|
|
43
|
+
{ label: "Net Income", key: "netIncome", format: "compact" },
|
|
44
|
+
{ label: "EBITDA", key: "ebitda", format: "compact" },
|
|
45
|
+
{ label: "Basic EPS", key: "basicEps", format: "eps" },
|
|
46
|
+
{ label: "Diluted EPS", key: "eps", format: "eps" },
|
|
47
|
+
{ label: "Shares Out", key: "dilutedShares", format: "compact" },
|
|
48
|
+
],
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
name: "Cash Flow",
|
|
52
|
+
key: "cashflow",
|
|
53
|
+
metrics: [
|
|
54
|
+
{ label: "Operating CF", key: "operatingCashFlow", format: "compact" },
|
|
55
|
+
{ label: "CapEx", key: "capitalExpenditure", format: "compact" },
|
|
56
|
+
{ label: "Free Cash Flow", key: "freeCashFlow", format: "compact" },
|
|
57
|
+
{ label: "Investing CF", key: "investingCashFlow", format: "compact" },
|
|
58
|
+
{ label: "Financing CF", key: "financingCashFlow", format: "compact" },
|
|
59
|
+
{ label: "Debt Issuance", key: "issuanceOfDebt", format: "compact" },
|
|
60
|
+
{ label: "Buybacks", key: "repurchaseOfCapitalStock", format: "compact" },
|
|
61
|
+
{ label: "Dividends Paid", key: "cashDividendsPaid", format: "compact" },
|
|
62
|
+
],
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
name: "Balance Sheet",
|
|
66
|
+
key: "balance",
|
|
67
|
+
metrics: [
|
|
68
|
+
{ label: "Total Assets", key: "totalAssets", format: "compact" },
|
|
69
|
+
{ label: "Current Assets", key: "currentAssets", format: "compact" },
|
|
70
|
+
{ label: "Cash & Equiv", key: "cashAndCashEquivalents", format: "compact" },
|
|
71
|
+
{ label: "Total Liab", key: "totalLiabilities", format: "compact" },
|
|
72
|
+
{ label: "Current Liab", key: "currentLiabilities", format: "compact" },
|
|
73
|
+
{ label: "Long-Term Debt", key: "longTermDebt", format: "compact" },
|
|
74
|
+
{ label: "Total Debt", key: "totalDebt", format: "compact" },
|
|
75
|
+
{ label: "Equity", key: "totalEquity", format: "compact" },
|
|
76
|
+
{ label: "Retained Earn", key: "retainedEarnings", format: "compact" },
|
|
77
|
+
],
|
|
78
|
+
},
|
|
79
|
+
];
|
|
80
|
+
|
|
81
|
+
const FLOW_KEYS = new Set<string>([
|
|
82
|
+
"totalRevenue",
|
|
83
|
+
"costOfRevenue",
|
|
84
|
+
"grossProfit",
|
|
85
|
+
"sellingGeneralAndAdministration",
|
|
86
|
+
"researchAndDevelopment",
|
|
87
|
+
"operatingExpense",
|
|
88
|
+
"operatingIncome",
|
|
89
|
+
"interestExpense",
|
|
90
|
+
"taxProvision",
|
|
91
|
+
"netIncome",
|
|
92
|
+
"ebitda",
|
|
93
|
+
"basicEps",
|
|
94
|
+
"eps",
|
|
95
|
+
"operatingCashFlow",
|
|
96
|
+
"capitalExpenditure",
|
|
97
|
+
"freeCashFlow",
|
|
98
|
+
"investingCashFlow",
|
|
99
|
+
"financingCashFlow",
|
|
100
|
+
"issuanceOfDebt",
|
|
101
|
+
"repurchaseOfCapitalStock",
|
|
102
|
+
"cashDividendsPaid",
|
|
103
|
+
]);
|
|
104
|
+
|
|
105
|
+
const BALANCE_KEYS = new Set<string>([
|
|
106
|
+
"totalAssets",
|
|
107
|
+
"currentAssets",
|
|
108
|
+
"cashAndCashEquivalents",
|
|
109
|
+
"totalLiabilities",
|
|
110
|
+
"currentLiabilities",
|
|
111
|
+
"longTermDebt",
|
|
112
|
+
"totalDebt",
|
|
113
|
+
"totalEquity",
|
|
114
|
+
"retainedEarnings",
|
|
115
|
+
"dilutedShares",
|
|
116
|
+
]);
|
|
117
|
+
|
|
118
|
+
const FINANCIAL_COL_W = 18;
|
|
119
|
+
const FINANCIAL_LABEL_W = 20;
|
|
120
|
+
const FINANCIAL_GROWTH_W = 7;
|
|
121
|
+
const FINANCIAL_VALUE_W = FINANCIAL_COL_W - FINANCIAL_GROWTH_W;
|
|
122
|
+
|
|
123
|
+
function aggregateQuarterlyStatements(
|
|
124
|
+
statements: FinancialStatement[],
|
|
125
|
+
date: string,
|
|
126
|
+
): FinancialStatement | null {
|
|
127
|
+
if (statements.length < 4) return null;
|
|
128
|
+
|
|
129
|
+
const aggregate: FinancialStatement = { date };
|
|
130
|
+
for (const key of FLOW_KEYS) {
|
|
131
|
+
const values = statements
|
|
132
|
+
.map((statement) => (statement as Record<string, unknown>)[key])
|
|
133
|
+
.filter((value): value is number => typeof value === "number");
|
|
134
|
+
if (values.length === 4) {
|
|
135
|
+
(aggregate as Record<string, unknown>)[key] = values.reduce((left, right) => left + right, 0);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const latest = statements[statements.length - 1]!;
|
|
140
|
+
for (const key of BALANCE_KEYS) {
|
|
141
|
+
const value = (latest as Record<string, unknown>)[key];
|
|
142
|
+
if (typeof value === "number") {
|
|
143
|
+
(aggregate as Record<string, unknown>)[key] = value;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return aggregate;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function computeTTM(quarterlyStatements: FinancialStatement[]) {
|
|
151
|
+
return aggregateQuarterlyStatements(quarterlyStatements.slice(-4), "TTM");
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function computePreviousTtm(quarterlyStatements: FinancialStatement[]) {
|
|
155
|
+
return aggregateQuarterlyStatements(quarterlyStatements.slice(-8, -4), "prevTTM");
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function computeGrowth(current: number | undefined, previous: number | undefined): number | undefined {
|
|
159
|
+
if (current == null || previous == null || previous === 0) return undefined;
|
|
160
|
+
return (current - previous) / Math.abs(previous);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function formatFinancialCell(value: string, growth: number | undefined) {
|
|
164
|
+
const growthText = growth != null ? formatGrowthShort(growth) : "";
|
|
165
|
+
return {
|
|
166
|
+
valueText: padTo(value, FINANCIAL_VALUE_W, "right"),
|
|
167
|
+
growthText: padTo(growthText ? ` ${growthText}` : "", FINANCIAL_GROWTH_W, "right"),
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function formatFinancialHeader(date: string): string {
|
|
172
|
+
const label = date === "TTM" ? "TTM" : date.slice(0, 7);
|
|
173
|
+
return padTo(label, FINANCIAL_COL_W, "center");
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function resolveFinancialPeriod(
|
|
177
|
+
requestedPeriod: FinancialPeriod,
|
|
178
|
+
hasAnnualStatements: boolean,
|
|
179
|
+
hasQuarterlyStatements: boolean,
|
|
180
|
+
): FinancialPeriod {
|
|
181
|
+
if (requestedPeriod === "annual") {
|
|
182
|
+
return hasAnnualStatements || !hasQuarterlyStatements ? "annual" : "quarterly";
|
|
183
|
+
}
|
|
184
|
+
return hasQuarterlyStatements || !hasAnnualStatements ? "quarterly" : "annual";
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function buildPreviousStatementMap(
|
|
188
|
+
period: FinancialPeriod,
|
|
189
|
+
annualStatements: FinancialStatement[],
|
|
190
|
+
quarterlyStatements: FinancialStatement[],
|
|
191
|
+
ttm: FinancialStatement | null,
|
|
192
|
+
) {
|
|
193
|
+
const sourceStatements = period === "annual" ? annualStatements : quarterlyStatements;
|
|
194
|
+
const previousMap = new Map<string, FinancialStatement>();
|
|
195
|
+
|
|
196
|
+
for (let index = 1; index < sourceStatements.length; index += 1) {
|
|
197
|
+
previousMap.set(sourceStatements[index]!.date, sourceStatements[index - 1]!);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
if (ttm) {
|
|
201
|
+
const previousTtm = computePreviousTtm(quarterlyStatements);
|
|
202
|
+
if (previousTtm) {
|
|
203
|
+
previousMap.set("TTM", previousTtm);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
return previousMap;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export function FinancialsTab({
|
|
211
|
+
focused,
|
|
212
|
+
headerScrollId,
|
|
213
|
+
bodyScrollId,
|
|
214
|
+
}: {
|
|
215
|
+
focused: boolean;
|
|
216
|
+
headerScrollId?: string;
|
|
217
|
+
bodyScrollId?: string;
|
|
218
|
+
}) {
|
|
219
|
+
const { financials } = usePaneTicker();
|
|
220
|
+
const annualStatements = financials?.annualStatements ?? [];
|
|
221
|
+
const quarterlyStatements = financials?.quarterlyStatements ?? [];
|
|
222
|
+
const hasAnnualStatements = annualStatements.length > 0;
|
|
223
|
+
const hasQuarterlyStatements = quarterlyStatements.length > 0;
|
|
224
|
+
const [period, setPeriod] = useState<FinancialPeriod>(hasAnnualStatements ? "annual" : "quarterly");
|
|
225
|
+
const [subTabIdx, setSubTabIdx] = useState(0);
|
|
226
|
+
const bodyScrollRef = useRef<ScrollBoxRenderable>(null);
|
|
227
|
+
const headerScrollRef = useRef<ScrollBoxRenderable>(null);
|
|
228
|
+
|
|
229
|
+
const syncHeaderScroll = useCallback(() => {
|
|
230
|
+
const body = bodyScrollRef.current;
|
|
231
|
+
const header = headerScrollRef.current;
|
|
232
|
+
if (body && header && header.scrollLeft !== body.scrollLeft) {
|
|
233
|
+
header.scrollLeft = body.scrollLeft;
|
|
234
|
+
}
|
|
235
|
+
}, []);
|
|
236
|
+
|
|
237
|
+
useKeyboard((event) => {
|
|
238
|
+
if (!focused) return;
|
|
239
|
+
if (event.name === "a" && hasAnnualStatements) setPeriod("annual");
|
|
240
|
+
else if (event.name === "q" && hasQuarterlyStatements) setPeriod("quarterly");
|
|
241
|
+
else if (event.name === "1") setSubTabIdx(0);
|
|
242
|
+
else if (event.name === "2") setSubTabIdx(1);
|
|
243
|
+
else if (event.name === "3") setSubTabIdx(2);
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
useEffect(() => {
|
|
247
|
+
if (period === "annual" && !hasAnnualStatements && hasQuarterlyStatements) {
|
|
248
|
+
setPeriod("quarterly");
|
|
249
|
+
} else if (period === "quarterly" && !hasQuarterlyStatements && hasAnnualStatements) {
|
|
250
|
+
setPeriod("annual");
|
|
251
|
+
}
|
|
252
|
+
}, [hasAnnualStatements, hasQuarterlyStatements, period]);
|
|
253
|
+
|
|
254
|
+
if (!financials || (!hasAnnualStatements && !hasQuarterlyStatements)) {
|
|
255
|
+
return <text fg={colors.textDim}>No financial data available.</text>;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
const subTab = FINANCIAL_SUB_TABS[subTabIdx]!;
|
|
259
|
+
const resolvedPeriod = resolveFinancialPeriod(period, hasAnnualStatements, hasQuarterlyStatements);
|
|
260
|
+
const isAnnual = resolvedPeriod === "annual";
|
|
261
|
+
const rawStatements = isAnnual
|
|
262
|
+
? annualStatements.slice(-5).reverse()
|
|
263
|
+
: quarterlyStatements.slice(-6).reverse();
|
|
264
|
+
const ttm = isAnnual ? computeTTM(quarterlyStatements) : null;
|
|
265
|
+
const displayStatements = ttm ? [ttm, ...rawStatements] : rawStatements;
|
|
266
|
+
const previousStatementMap = buildPreviousStatementMap(
|
|
267
|
+
resolvedPeriod,
|
|
268
|
+
annualStatements,
|
|
269
|
+
quarterlyStatements,
|
|
270
|
+
ttm,
|
|
271
|
+
);
|
|
272
|
+
const tableWidth = FINANCIAL_LABEL_W + (displayStatements.length * FINANCIAL_COL_W);
|
|
273
|
+
|
|
274
|
+
useEffect(() => {
|
|
275
|
+
if (headerScrollRef.current) {
|
|
276
|
+
headerScrollRef.current.horizontalScrollBar.visible = false;
|
|
277
|
+
}
|
|
278
|
+
syncHeaderScroll();
|
|
279
|
+
}, [displayStatements.length, isAnnual, subTabIdx, syncHeaderScroll]);
|
|
280
|
+
|
|
281
|
+
useEffect(() => {
|
|
282
|
+
const body = bodyScrollRef.current;
|
|
283
|
+
if (!body) return;
|
|
284
|
+
const hasVerticalOverflow = body.scrollHeight > body.viewport.height;
|
|
285
|
+
body.verticalScrollBar.visible = hasVerticalOverflow;
|
|
286
|
+
if (!hasVerticalOverflow && body.scrollTop !== 0) {
|
|
287
|
+
body.scrollTo({ x: body.scrollLeft, y: 0 });
|
|
288
|
+
}
|
|
289
|
+
}, [displayStatements.length, isAnnual, subTabIdx, subTab.metrics.length]);
|
|
290
|
+
|
|
291
|
+
return (
|
|
292
|
+
<box flexDirection="column" flexGrow={1} paddingX={2} paddingBottom={1}>
|
|
293
|
+
<box flexDirection="row" height={1}>
|
|
294
|
+
{FINANCIAL_SUB_TABS.map((tab, index) => (
|
|
295
|
+
<box key={tab.key} flexDirection="row" onMouseDown={() => setSubTabIdx(index)}>
|
|
296
|
+
<text
|
|
297
|
+
fg={index === subTabIdx ? colors.textBright : colors.textDim}
|
|
298
|
+
attributes={index === subTabIdx ? TextAttributes.BOLD : 0}
|
|
299
|
+
>
|
|
300
|
+
{`${index + 1}:${tab.name}`}
|
|
301
|
+
</text>
|
|
302
|
+
{index < FINANCIAL_SUB_TABS.length - 1 && <text fg={colors.textMuted}>{" │ "}</text>}
|
|
303
|
+
</box>
|
|
304
|
+
))}
|
|
305
|
+
<box flexGrow={1} />
|
|
306
|
+
<box onMouseDown={() => setPeriod("annual")}>
|
|
307
|
+
<text fg={isAnnual ? colors.textBright : colors.textDim} attributes={isAnnual ? TextAttributes.BOLD : 0}>a</text>
|
|
308
|
+
</box>
|
|
309
|
+
<text fg={colors.textMuted}>/</text>
|
|
310
|
+
<box onMouseDown={() => setPeriod("quarterly")}>
|
|
311
|
+
<text fg={!isAnnual ? colors.textBright : colors.textDim} attributes={!isAnnual ? TextAttributes.BOLD : 0}>q</text>
|
|
312
|
+
</box>
|
|
313
|
+
</box>
|
|
314
|
+
<box height={1} />
|
|
315
|
+
|
|
316
|
+
<scrollbox id={headerScrollId} ref={headerScrollRef} height={1} scrollX focusable={false}>
|
|
317
|
+
<box flexDirection="row" width={tableWidth} height={1}>
|
|
318
|
+
<box width={FINANCIAL_LABEL_W}>
|
|
319
|
+
<text attributes={TextAttributes.BOLD} fg={colors.textDim}>
|
|
320
|
+
{isAnnual ? "Annual" : "Quarterly"}
|
|
321
|
+
</text>
|
|
322
|
+
</box>
|
|
323
|
+
{displayStatements.map((statement) => (
|
|
324
|
+
<box key={statement.date} width={FINANCIAL_COL_W}>
|
|
325
|
+
<text
|
|
326
|
+
attributes={TextAttributes.BOLD}
|
|
327
|
+
fg={statement.date === "TTM" ? colors.textBright : colors.textDim}
|
|
328
|
+
>
|
|
329
|
+
{formatFinancialHeader(statement.date)}
|
|
330
|
+
</text>
|
|
331
|
+
</box>
|
|
332
|
+
))}
|
|
333
|
+
</box>
|
|
334
|
+
</scrollbox>
|
|
335
|
+
<box height={1} />
|
|
336
|
+
|
|
337
|
+
<scrollbox
|
|
338
|
+
id={bodyScrollId}
|
|
339
|
+
ref={bodyScrollRef}
|
|
340
|
+
flexGrow={1}
|
|
341
|
+
scrollX
|
|
342
|
+
scrollY
|
|
343
|
+
focusable={false}
|
|
344
|
+
onMouseDown={() => queueMicrotask(syncHeaderScroll)}
|
|
345
|
+
onMouseUp={() => queueMicrotask(syncHeaderScroll)}
|
|
346
|
+
onMouseDrag={() => queueMicrotask(syncHeaderScroll)}
|
|
347
|
+
onMouseScroll={() => queueMicrotask(syncHeaderScroll)}
|
|
348
|
+
>
|
|
349
|
+
<box flexDirection="column" width={tableWidth} paddingBottom={1}>
|
|
350
|
+
{subTab.metrics.map(({ label, key, format }, index) => {
|
|
351
|
+
const isEps = format === "eps";
|
|
352
|
+
const allValues = displayStatements.map((statement) => statement[key] as number | undefined);
|
|
353
|
+
const { suffix, divisor } = isEps ? { suffix: "", divisor: 1 } : pickUnit(allValues);
|
|
354
|
+
const unitLabel = suffix ? `${label} (${suffix})` : label;
|
|
355
|
+
|
|
356
|
+
return (
|
|
357
|
+
<box key={key} flexDirection="column" width={tableWidth}>
|
|
358
|
+
{index > 0 && index % 4 === 0 && <box height={1} width={tableWidth} />}
|
|
359
|
+
<box flexDirection="row" width={tableWidth} height={1}>
|
|
360
|
+
<box width={FINANCIAL_LABEL_W}>
|
|
361
|
+
<text fg={colors.textDim}>{unitLabel}</text>
|
|
362
|
+
</box>
|
|
363
|
+
{displayStatements.map((statement) => {
|
|
364
|
+
const value = statement[key] as number | undefined;
|
|
365
|
+
const previous = previousStatementMap.get(statement.date);
|
|
366
|
+
const previousValue = previous ? (previous[key] as number | undefined) : undefined;
|
|
367
|
+
const growth = computeGrowth(value, previousValue);
|
|
368
|
+
const formattedValue = value != null
|
|
369
|
+
? isEps
|
|
370
|
+
? formatNumber(value, 2)
|
|
371
|
+
: formatWithDivisor(value, divisor)
|
|
372
|
+
: "—";
|
|
373
|
+
const cell = formatFinancialCell(formattedValue, growth);
|
|
374
|
+
|
|
375
|
+
return (
|
|
376
|
+
<box key={statement.date} width={FINANCIAL_COL_W} flexDirection="row">
|
|
377
|
+
<text fg={colors.text}>{cell.valueText}</text>
|
|
378
|
+
<text fg={growth != null ? priceColor(growth) : colors.text}>{cell.growthText}</text>
|
|
379
|
+
</box>
|
|
380
|
+
);
|
|
381
|
+
})}
|
|
382
|
+
</box>
|
|
383
|
+
</box>
|
|
384
|
+
);
|
|
385
|
+
})}
|
|
386
|
+
</box>
|
|
387
|
+
</scrollbox>
|
|
388
|
+
</box>
|
|
389
|
+
);
|
|
390
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { GloomPlugin } from "../../../types/plugin";
|
|
2
|
+
import { normalizeTickerInput } from "../../../utils/ticker-search";
|
|
3
|
+
import { TickerDetailPane } from "./pane";
|
|
4
|
+
import { FinancialsTab } from "./financials-tab";
|
|
5
|
+
import { QuoteMonitorPane } from "./quote-monitor";
|
|
6
|
+
import {
|
|
7
|
+
buildQuoteMonitorSettingsDef,
|
|
8
|
+
buildTickerDetailSettingsDef,
|
|
9
|
+
getTickerDetailPaneSettings,
|
|
10
|
+
} from "./settings";
|
|
11
|
+
|
|
12
|
+
export { FinancialsTab } from "./financials-tab";
|
|
13
|
+
export { QuoteMonitorPane } from "./quote-monitor";
|
|
14
|
+
export { buildVisibleDetailTabs } from "./settings";
|
|
15
|
+
|
|
16
|
+
export const tickerDetailPlugin: GloomPlugin = {
|
|
17
|
+
id: "ticker-detail",
|
|
18
|
+
name: "Ticker Detail",
|
|
19
|
+
version: "1.0.0",
|
|
20
|
+
|
|
21
|
+
panes: [
|
|
22
|
+
{
|
|
23
|
+
id: "ticker-detail",
|
|
24
|
+
name: "Detail",
|
|
25
|
+
icon: "D",
|
|
26
|
+
component: TickerDetailPane,
|
|
27
|
+
defaultPosition: "right",
|
|
28
|
+
defaultMode: "floating",
|
|
29
|
+
settings: (context) => buildTickerDetailSettingsDef(getTickerDetailPaneSettings(context.settings)),
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
id: "quote-monitor",
|
|
33
|
+
name: "Quote Monitor",
|
|
34
|
+
icon: "Q",
|
|
35
|
+
component: QuoteMonitorPane,
|
|
36
|
+
defaultPosition: "right",
|
|
37
|
+
defaultMode: "floating",
|
|
38
|
+
defaultFloatingSize: { width: 64, height: 8 },
|
|
39
|
+
settings: buildQuoteMonitorSettingsDef(),
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
paneTemplates: [
|
|
43
|
+
{
|
|
44
|
+
id: "new-ticker-detail-pane",
|
|
45
|
+
paneId: "ticker-detail",
|
|
46
|
+
label: "New Ticker Detail Pane",
|
|
47
|
+
description: "Open another detail pane for the selected ticker or current collection",
|
|
48
|
+
keywords: ["new", "ticker", "detail", "pane", "inspector"],
|
|
49
|
+
canCreate: (context) => context.activeTicker !== null || context.activeCollectionId !== null,
|
|
50
|
+
createInstance: (context) => (
|
|
51
|
+
context.activeTicker
|
|
52
|
+
? {
|
|
53
|
+
title: context.activeTicker,
|
|
54
|
+
binding: { kind: "fixed", symbol: context.activeTicker },
|
|
55
|
+
}
|
|
56
|
+
: {}
|
|
57
|
+
),
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
id: "quote-monitor-pane",
|
|
61
|
+
paneId: "quote-monitor",
|
|
62
|
+
label: "Quote Monitor",
|
|
63
|
+
description: "Open a compact quote monitor for the selected ticker",
|
|
64
|
+
keywords: ["quote", "monitor", "price", "ticker", "pane"],
|
|
65
|
+
shortcut: { prefix: "QQ", argPlaceholder: "ticker", argKind: "ticker" },
|
|
66
|
+
canCreate: (context, options) => (options?.symbol ?? normalizeTickerInput(context.activeTicker, options?.arg)) !== null,
|
|
67
|
+
createInstance: (context, options) => {
|
|
68
|
+
const ticker = options?.symbol ?? normalizeTickerInput(context.activeTicker, options?.arg);
|
|
69
|
+
return ticker
|
|
70
|
+
? {
|
|
71
|
+
title: ticker,
|
|
72
|
+
binding: { kind: "fixed", symbol: ticker },
|
|
73
|
+
settings: { symbol: ticker },
|
|
74
|
+
placement: "floating",
|
|
75
|
+
}
|
|
76
|
+
: null;
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
],
|
|
80
|
+
};
|