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,51 @@
|
|
|
1
|
+
import type { TickerMetadata, TickerPosition } from "../types/ticker";
|
|
2
|
+
|
|
3
|
+
const DEFAULT_TICKER_METADATA: Omit<TickerMetadata, "ticker" | "exchange" | "currency" | "name"> = {
|
|
4
|
+
portfolios: [],
|
|
5
|
+
watchlists: [],
|
|
6
|
+
positions: [],
|
|
7
|
+
broker_contracts: [],
|
|
8
|
+
custom: {},
|
|
9
|
+
tags: [],
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
function hydratePosition(raw: Record<string, unknown>): TickerPosition {
|
|
13
|
+
return {
|
|
14
|
+
portfolio: (raw.portfolio as string) ?? "",
|
|
15
|
+
shares: (raw.shares as number) ?? 0,
|
|
16
|
+
avgCost: (raw.avgCost ?? raw.avg_cost) as number ?? 0,
|
|
17
|
+
currency: (raw.currency as string) ?? undefined,
|
|
18
|
+
dateAcquired: (raw.dateAcquired ?? raw.date_acquired) as string | undefined,
|
|
19
|
+
broker: (raw.broker as string) ?? "manual",
|
|
20
|
+
side: (raw.side as "long" | "short") ?? undefined,
|
|
21
|
+
marketValue: (raw.marketValue ?? raw.market_value) as number | undefined,
|
|
22
|
+
unrealizedPnl: (raw.unrealizedPnl ?? raw.unrealized_pnl) as number | undefined,
|
|
23
|
+
multiplier: (raw.multiplier as number) ?? undefined,
|
|
24
|
+
markPrice: (raw.markPrice ?? raw.mark_price) as number | undefined,
|
|
25
|
+
brokerInstanceId: (raw.brokerInstanceId ?? raw.broker_instance_id) as string | undefined,
|
|
26
|
+
brokerAccountId: (raw.brokerAccountId ?? raw.broker_account_id) as string | undefined,
|
|
27
|
+
brokerContractId: (raw.brokerContractId ?? raw.broker_contract_id) as number | undefined,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function hydrateTickerMetadata(data: Record<string, unknown>): TickerMetadata {
|
|
32
|
+
const rawPositions = Array.isArray(data.positions) ? data.positions : [];
|
|
33
|
+
return {
|
|
34
|
+
...DEFAULT_TICKER_METADATA,
|
|
35
|
+
ticker: (data.ticker as string) ?? "",
|
|
36
|
+
exchange: (data.exchange as string) ?? "",
|
|
37
|
+
currency: (data.currency as string) ?? "USD",
|
|
38
|
+
name: (data.name as string) ?? "",
|
|
39
|
+
sector: data.sector as string | undefined,
|
|
40
|
+
industry: data.industry as string | undefined,
|
|
41
|
+
assetCategory: (data.assetCategory ?? data.asset_category) as string | undefined,
|
|
42
|
+
isin: data.isin as string | undefined,
|
|
43
|
+
cusip: data.cusip as string | undefined,
|
|
44
|
+
portfolios: Array.isArray(data.portfolios) ? [...data.portfolios] : [],
|
|
45
|
+
watchlists: Array.isArray(data.watchlists) ? [...data.watchlists] : [],
|
|
46
|
+
positions: rawPositions.map((position) => hydratePosition(position as Record<string, unknown>)),
|
|
47
|
+
broker_contracts: Array.isArray(data.broker_contracts) ? [...data.broker_contracts] : [],
|
|
48
|
+
custom: data.custom && typeof data.custom === "object" ? { ...(data.custom as Record<string, unknown>) } : {},
|
|
49
|
+
tags: Array.isArray(data.tags) ? [...data.tags] : [],
|
|
50
|
+
};
|
|
51
|
+
}
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import type { DataProvider } from "../types/data-provider";
|
|
3
|
+
import type { InstrumentSearchResult } from "../types/instrument";
|
|
4
|
+
import type { TickerRecord } from "../types/ticker";
|
|
5
|
+
import { createTestDataProvider } from "../test-support/data-provider";
|
|
6
|
+
import {
|
|
7
|
+
buildTickerSearchCandidates,
|
|
8
|
+
createLocalTickerSearchCandidates,
|
|
9
|
+
findExactTickerSearchMatch,
|
|
10
|
+
normalizeTickerInput,
|
|
11
|
+
resolveTickerSearch,
|
|
12
|
+
searchTickerCandidates,
|
|
13
|
+
upsertTickerFromSearchResult,
|
|
14
|
+
} from "./ticker-search";
|
|
15
|
+
|
|
16
|
+
function makeTicker(symbol: string, name = symbol): TickerRecord {
|
|
17
|
+
return {
|
|
18
|
+
metadata: {
|
|
19
|
+
ticker: symbol,
|
|
20
|
+
exchange: "NASDAQ",
|
|
21
|
+
currency: "USD",
|
|
22
|
+
name,
|
|
23
|
+
portfolios: [],
|
|
24
|
+
watchlists: [],
|
|
25
|
+
positions: [],
|
|
26
|
+
custom: {},
|
|
27
|
+
tags: [],
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function makeSearchResult(symbol: string, name = symbol): InstrumentSearchResult {
|
|
33
|
+
return {
|
|
34
|
+
providerId: "test",
|
|
35
|
+
symbol,
|
|
36
|
+
name,
|
|
37
|
+
exchange: "NASDAQ",
|
|
38
|
+
type: "EQUITY",
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function makeDataProvider(results: InstrumentSearchResult[]): DataProvider {
|
|
43
|
+
return createTestDataProvider({
|
|
44
|
+
id: "test",
|
|
45
|
+
search: async () => results,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
describe("ticker-search utilities", () => {
|
|
50
|
+
test("normalizes explicit and focused ticker inputs", () => {
|
|
51
|
+
expect(normalizeTickerInput("AAPL", undefined)).toBe("AAPL");
|
|
52
|
+
expect(normalizeTickerInput("AAPL", " msft ")).toBe("MSFT");
|
|
53
|
+
expect(normalizeTickerInput(null, undefined)).toBeNull();
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test("finds exact provider matches for direct ticker resolution", async () => {
|
|
57
|
+
const tickers = new Map<string, TickerRecord>([["AAPL", makeTicker("AAPL", "Apple")]]);
|
|
58
|
+
const resolved = await resolveTickerSearch({
|
|
59
|
+
query: "MSFT",
|
|
60
|
+
activeTicker: null,
|
|
61
|
+
tickers,
|
|
62
|
+
dataProvider: makeDataProvider([
|
|
63
|
+
makeSearchResult("MSFT", "Microsoft"),
|
|
64
|
+
makeSearchResult("MSFTW", "Microsoft Warrants"),
|
|
65
|
+
]),
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
expect(resolved).toMatchObject({
|
|
69
|
+
kind: "provider",
|
|
70
|
+
symbol: "MSFT",
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test("combines local and provider candidates without duplicate saved symbols", async () => {
|
|
75
|
+
const tickers = new Map<string, TickerRecord>([["AAPL", makeTicker("AAPL", "Apple")]]);
|
|
76
|
+
const results = await searchTickerCandidates({
|
|
77
|
+
query: "appl",
|
|
78
|
+
tickers,
|
|
79
|
+
dataProvider: makeDataProvider([
|
|
80
|
+
makeSearchResult("AAPL", "Apple Inc"),
|
|
81
|
+
makeSearchResult("APP", "AppLovin"),
|
|
82
|
+
]),
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
expect(results.map((item) => item.id)).toEqual(["goto:AAPL", "search:APP"]);
|
|
86
|
+
expect(findExactTickerSearchMatch(results, "AAPL")?.id).toBe("goto:AAPL");
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
test("uses provider metadata to keep stale saved tickers intuitive in search results", async () => {
|
|
90
|
+
const tickers = new Map<string, TickerRecord>([["AAPL", makeTicker("AAPL", "AAPL")]]);
|
|
91
|
+
const results = await searchTickerCandidates({
|
|
92
|
+
query: "apple",
|
|
93
|
+
tickers,
|
|
94
|
+
dataProvider: makeDataProvider([
|
|
95
|
+
makeSearchResult("AAPL", "Apple Inc"),
|
|
96
|
+
makeSearchResult("APLE", "Apple Hospitality REIT, Inc."),
|
|
97
|
+
]),
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
expect(results.map((item) => item.id)).toEqual(["goto:AAPL", "search:APLE"]);
|
|
101
|
+
expect(results[0]).toMatchObject({
|
|
102
|
+
id: "goto:AAPL",
|
|
103
|
+
detail: "Apple Inc",
|
|
104
|
+
category: "Saved",
|
|
105
|
+
});
|
|
106
|
+
expect(findExactTickerSearchMatch(results, "AAPL")?.id).toBe("goto:AAPL");
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
test("preserves exchange-qualified symbols and groups provider listings intuitively", () => {
|
|
110
|
+
const results = buildTickerSearchCandidates({
|
|
111
|
+
query: "apple",
|
|
112
|
+
tickers: new Map<string, TickerRecord>(),
|
|
113
|
+
providerResults: [
|
|
114
|
+
makeSearchResult("AAPL", "Apple Inc"),
|
|
115
|
+
{ ...makeSearchResult("AAPL.BA", "Apple Inc"), exchange: "Buenos Aires" },
|
|
116
|
+
{ ...makeSearchResult("APLY.NE", "Apple Yield Shares Purpose ETF"), exchange: "NEO", type: "ETF" },
|
|
117
|
+
],
|
|
118
|
+
localLimit: 6,
|
|
119
|
+
totalLimit: 8,
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
expect(results.map((item) => [item.label, item.category])).toEqual([
|
|
123
|
+
["AAPL", "Primary Listing"],
|
|
124
|
+
["AAPL.BA", "Other Listings"],
|
|
125
|
+
["APLY.NE", "Funds & Derivatives"],
|
|
126
|
+
]);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
test("finds exact symbol aliases for dotted share classes", () => {
|
|
130
|
+
const match = findExactTickerSearchMatch([
|
|
131
|
+
{
|
|
132
|
+
id: "search:BRK.B",
|
|
133
|
+
label: "BRK.B",
|
|
134
|
+
detail: "Berkshire Hathaway Inc. Class B",
|
|
135
|
+
kind: "search",
|
|
136
|
+
category: "Primary Listing",
|
|
137
|
+
searchAliases: ["BRK.B", "BRK B", "BRKB"],
|
|
138
|
+
},
|
|
139
|
+
], "brkb");
|
|
140
|
+
|
|
141
|
+
expect(match?.id).toBe("search:BRK.B");
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
test("expands compact share-class queries when searching providers", async () => {
|
|
145
|
+
const queries: string[] = [];
|
|
146
|
+
const expandedResults = await searchTickerCandidates({
|
|
147
|
+
query: "brkb",
|
|
148
|
+
tickers: new Map<string, TickerRecord>(),
|
|
149
|
+
dataProvider: createTestDataProvider({
|
|
150
|
+
id: "test",
|
|
151
|
+
search: async (query) => {
|
|
152
|
+
queries.push(query);
|
|
153
|
+
return query.toLowerCase() === "brk-b"
|
|
154
|
+
? [{ providerId: "test", symbol: "BRK-B", name: "Berkshire Hathaway Inc. Class B", exchange: "NYSE", type: "EQUITY" }]
|
|
155
|
+
: [];
|
|
156
|
+
},
|
|
157
|
+
}),
|
|
158
|
+
totalLimit: 5,
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
expect(queries).toContain("BRK-B");
|
|
162
|
+
expect(expandedResults[0]).toMatchObject({
|
|
163
|
+
label: "BRK-B",
|
|
164
|
+
category: "Primary Listing",
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
test("upserts ticker records from provider search results", async () => {
|
|
169
|
+
const saved: TickerRecord[] = [];
|
|
170
|
+
const repository = {
|
|
171
|
+
loadTicker: async () => null,
|
|
172
|
+
createTicker: async (metadata: TickerRecord["metadata"]) => ({ metadata }),
|
|
173
|
+
saveTicker: async (ticker: TickerRecord) => {
|
|
174
|
+
saved.push(ticker);
|
|
175
|
+
},
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
const { ticker, created } = await upsertTickerFromSearchResult(repository as any, {
|
|
179
|
+
providerId: "test",
|
|
180
|
+
symbol: "NVDA",
|
|
181
|
+
name: "NVIDIA",
|
|
182
|
+
exchange: "NASDAQ",
|
|
183
|
+
type: "EQUITY",
|
|
184
|
+
currency: "USD",
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
expect(created).toBe(true);
|
|
188
|
+
expect(ticker.metadata.ticker).toBe("NVDA");
|
|
189
|
+
expect(saved).toHaveLength(0);
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
test("refreshes low-quality saved metadata when opening a provider-backed result", async () => {
|
|
193
|
+
const existing = makeTicker("AAPL", "AAPL");
|
|
194
|
+
const saved: TickerRecord[] = [];
|
|
195
|
+
const repository = {
|
|
196
|
+
loadTicker: async () => existing,
|
|
197
|
+
createTicker: async (metadata: TickerRecord["metadata"]) => ({ metadata }),
|
|
198
|
+
saveTicker: async (ticker: TickerRecord) => {
|
|
199
|
+
saved.push(ticker);
|
|
200
|
+
},
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
const { ticker, created } = await upsertTickerFromSearchResult(repository as any, {
|
|
204
|
+
providerId: "test",
|
|
205
|
+
symbol: "AAPL",
|
|
206
|
+
name: "Apple Inc.",
|
|
207
|
+
exchange: "NASDAQ",
|
|
208
|
+
type: "EQUITY",
|
|
209
|
+
currency: "USD",
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
expect(created).toBe(false);
|
|
213
|
+
expect(ticker.metadata.name).toBe("Apple Inc.");
|
|
214
|
+
expect(saved).toHaveLength(1);
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
test("exposes local ticker candidates in saved category", () => {
|
|
218
|
+
expect(createLocalTickerSearchCandidates([makeTicker("TSLA", "Tesla")])).toEqual([
|
|
219
|
+
expect.objectContaining({
|
|
220
|
+
id: "goto:TSLA",
|
|
221
|
+
label: "TSLA",
|
|
222
|
+
category: "Saved",
|
|
223
|
+
kind: "ticker",
|
|
224
|
+
}),
|
|
225
|
+
]);
|
|
226
|
+
});
|
|
227
|
+
});
|