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,570 @@
|
|
|
1
|
+
import { afterEach, describe, expect, test } from "bun:test";
|
|
2
|
+
import { cleanupPredictionTest, createConfig, installPredictionMarketMocks } from "./test-helpers";
|
|
3
|
+
import { colors } from "../../theme/colors";
|
|
4
|
+
import { predictionMarketsPlugin } from "./index";
|
|
5
|
+
import { resolvePredictionKeyboardCommand } from "./keyboard";
|
|
6
|
+
import { buildPredictionListRows } from "./rows";
|
|
7
|
+
import { getPredictionColumnValue } from "./metrics";
|
|
8
|
+
import {
|
|
9
|
+
loadKalshiCatalog,
|
|
10
|
+
loadKalshiHistory,
|
|
11
|
+
normalizeKalshiMarket,
|
|
12
|
+
} from "./services/kalshi-adapter";
|
|
13
|
+
import {
|
|
14
|
+
loadPolymarketCatalog,
|
|
15
|
+
loadPolymarketDetail,
|
|
16
|
+
normalizePolymarketMarket,
|
|
17
|
+
} from "./services/polymarket-adapter";
|
|
18
|
+
|
|
19
|
+
afterEach(async () => {
|
|
20
|
+
await cleanupPredictionTest();
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
describe("prediction markets plugin registration and services", () => {
|
|
24
|
+
test("exposes the pane template and search command", () => {
|
|
25
|
+
const commands: string[] = [];
|
|
26
|
+
const ctx = {
|
|
27
|
+
persistence: {
|
|
28
|
+
getState: () => null,
|
|
29
|
+
setState: () => {},
|
|
30
|
+
deleteState: () => {},
|
|
31
|
+
getResource: () => null,
|
|
32
|
+
setResource: (_kind: string, _key: string, value: unknown) => ({
|
|
33
|
+
value,
|
|
34
|
+
fetchedAt: Date.now(),
|
|
35
|
+
staleAt: Date.now(),
|
|
36
|
+
expiresAt: Date.now(),
|
|
37
|
+
sourceKey: "test",
|
|
38
|
+
schemaVersion: 1,
|
|
39
|
+
provenance: null,
|
|
40
|
+
stale: false,
|
|
41
|
+
expired: false,
|
|
42
|
+
}),
|
|
43
|
+
deleteResource: () => {},
|
|
44
|
+
},
|
|
45
|
+
registerCommand: (command: { id: string }) => {
|
|
46
|
+
commands.push(command.id);
|
|
47
|
+
},
|
|
48
|
+
resume: {
|
|
49
|
+
getState: () => null,
|
|
50
|
+
setState: () => {},
|
|
51
|
+
deleteState: () => {},
|
|
52
|
+
getPaneState: () => null,
|
|
53
|
+
setPaneState: () => {},
|
|
54
|
+
deletePaneState: () => {},
|
|
55
|
+
},
|
|
56
|
+
focusPane: () => {},
|
|
57
|
+
getConfig: () => createConfig(),
|
|
58
|
+
} as any;
|
|
59
|
+
|
|
60
|
+
predictionMarketsPlugin.setup?.(ctx);
|
|
61
|
+
|
|
62
|
+
expect(predictionMarketsPlugin.toggleable).toBe(true);
|
|
63
|
+
expect(predictionMarketsPlugin.panes?.[0]?.defaultMode).toBe("floating");
|
|
64
|
+
expect(predictionMarketsPlugin.paneTemplates?.[0]?.shortcut?.prefix).toBe(
|
|
65
|
+
"PM",
|
|
66
|
+
);
|
|
67
|
+
expect(commands).toContain("prediction-markets-open");
|
|
68
|
+
expect(commands).toContain("prediction-markets-search");
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test("normalizes venue payloads", () => {
|
|
72
|
+
expect(
|
|
73
|
+
normalizePolymarketMarket({
|
|
74
|
+
id: "pm-1",
|
|
75
|
+
question: "Will inflation fall?",
|
|
76
|
+
conditionId: "cond-1",
|
|
77
|
+
outcomes: '["Yes","No"]',
|
|
78
|
+
outcomePrices: '["0.62","0.38"]',
|
|
79
|
+
clobTokenIds: '["yes-1","no-1"]',
|
|
80
|
+
events: [
|
|
81
|
+
{
|
|
82
|
+
id: "event-1",
|
|
83
|
+
title: "US inflation",
|
|
84
|
+
openInterest: 12,
|
|
85
|
+
tags: [{ label: "Macro" }],
|
|
86
|
+
} as any,
|
|
87
|
+
],
|
|
88
|
+
} as any)?.yesPrice,
|
|
89
|
+
).toBe(0.62);
|
|
90
|
+
|
|
91
|
+
expect(
|
|
92
|
+
normalizeKalshiMarket({
|
|
93
|
+
ticker: "KAL-1",
|
|
94
|
+
title: "Will the Fed cut rates?",
|
|
95
|
+
yes_sub_title: "Yes",
|
|
96
|
+
status: "open",
|
|
97
|
+
market_type: "binary",
|
|
98
|
+
yes_bid_dollars: "0.47",
|
|
99
|
+
yes_ask_dollars: "0.49",
|
|
100
|
+
no_bid_dollars: "0.51",
|
|
101
|
+
no_ask_dollars: "0.53",
|
|
102
|
+
last_price_dollars: "0.48",
|
|
103
|
+
volume_24h_fp: "15000",
|
|
104
|
+
volume_fp: "90000",
|
|
105
|
+
open_interest_fp: "45000",
|
|
106
|
+
liquidity_dollars: "250000",
|
|
107
|
+
} as any)?.volume24h,
|
|
108
|
+
).toBe(15000);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
test("uses Kalshi target subtitles to disambiguate strike ladders", () => {
|
|
112
|
+
const summary = normalizeKalshiMarket(
|
|
113
|
+
{
|
|
114
|
+
ticker: "KXFED-27APR-T0.25",
|
|
115
|
+
title:
|
|
116
|
+
"Will the upper bound of the federal funds target rate be above 0.25%?",
|
|
117
|
+
yes_sub_title: "Above 0.25%",
|
|
118
|
+
event_ticker: "KXFED-27APR",
|
|
119
|
+
status: "open",
|
|
120
|
+
market_type: "binary",
|
|
121
|
+
last_price_dollars: "0.48",
|
|
122
|
+
strike_type: "greater",
|
|
123
|
+
floor_strike: "0.25",
|
|
124
|
+
} as any,
|
|
125
|
+
{
|
|
126
|
+
title: "Federal funds target rate after April 2026 FOMC",
|
|
127
|
+
sub_title: "Upper bound",
|
|
128
|
+
category: "Economics",
|
|
129
|
+
series_ticker: "KXFED",
|
|
130
|
+
},
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
expect(summary?.marketLabel).toBe("Above 0.25%");
|
|
134
|
+
expect(summary?.eventLabel).toBe(
|
|
135
|
+
"Federal funds target rate after April 2026 FOMC · Upper bound",
|
|
136
|
+
);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
test("collapses multi-market venue events into grouped list rows", () => {
|
|
140
|
+
const rows = buildPredictionListRows([
|
|
141
|
+
normalizeKalshiMarket(
|
|
142
|
+
{
|
|
143
|
+
ticker: "KXFED-27APR-T4.25",
|
|
144
|
+
title:
|
|
145
|
+
"Will the upper bound of the federal funds target rate be above 4.25%?",
|
|
146
|
+
yes_sub_title: "Above 4.25%",
|
|
147
|
+
event_ticker: "KXFED-27APR",
|
|
148
|
+
status: "open",
|
|
149
|
+
market_type: "binary",
|
|
150
|
+
last_price_dollars: "0.48",
|
|
151
|
+
volume_24h_fp: "15000",
|
|
152
|
+
strike_type: "greater",
|
|
153
|
+
floor_strike: "4.25",
|
|
154
|
+
} as any,
|
|
155
|
+
{
|
|
156
|
+
title: "Federal funds target rate after April 2026 FOMC",
|
|
157
|
+
sub_title: "Upper bound",
|
|
158
|
+
category: "Economics",
|
|
159
|
+
series_ticker: "KXFED",
|
|
160
|
+
},
|
|
161
|
+
)!,
|
|
162
|
+
normalizeKalshiMarket(
|
|
163
|
+
{
|
|
164
|
+
ticker: "KXFED-27APR-T4.50",
|
|
165
|
+
title:
|
|
166
|
+
"Will the upper bound of the federal funds target rate be above 4.50%?",
|
|
167
|
+
yes_sub_title: "Above 4.50%",
|
|
168
|
+
event_ticker: "KXFED-27APR",
|
|
169
|
+
status: "open",
|
|
170
|
+
market_type: "binary",
|
|
171
|
+
last_price_dollars: "0.31",
|
|
172
|
+
volume_24h_fp: "12000",
|
|
173
|
+
strike_type: "greater",
|
|
174
|
+
floor_strike: "4.50",
|
|
175
|
+
} as any,
|
|
176
|
+
{
|
|
177
|
+
title: "Federal funds target rate after April 2026 FOMC",
|
|
178
|
+
sub_title: "Upper bound",
|
|
179
|
+
category: "Economics",
|
|
180
|
+
series_ticker: "KXFED",
|
|
181
|
+
},
|
|
182
|
+
)!,
|
|
183
|
+
]);
|
|
184
|
+
|
|
185
|
+
expect(rows).toHaveLength(1);
|
|
186
|
+
expect(rows[0]?.kind).toBe("group");
|
|
187
|
+
expect(rows[0]?.focusMarketKey).toBe("kalshi:KXFED-27APR-T4.25");
|
|
188
|
+
expect(rows[0]?.focusYesPrice).toBe(0.48);
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
test("styles YES consistently and uses the lead contract quote on grouped rows", () => {
|
|
192
|
+
const [row] = buildPredictionListRows([
|
|
193
|
+
normalizeKalshiMarket(
|
|
194
|
+
{
|
|
195
|
+
ticker: "KXFED-27APR-T4.25",
|
|
196
|
+
title:
|
|
197
|
+
"Will the upper bound of the federal funds target rate be above 4.25%?",
|
|
198
|
+
yes_sub_title: "Above 4.25%",
|
|
199
|
+
event_ticker: "KXFED-27APR",
|
|
200
|
+
status: "open",
|
|
201
|
+
market_type: "binary",
|
|
202
|
+
last_price_dollars: "0.48",
|
|
203
|
+
volume_24h_fp: "15000",
|
|
204
|
+
strike_type: "greater",
|
|
205
|
+
floor_strike: "4.25",
|
|
206
|
+
} as any,
|
|
207
|
+
{
|
|
208
|
+
title: "Federal funds target rate after April 2026 FOMC",
|
|
209
|
+
sub_title: "Upper bound",
|
|
210
|
+
category: "Economics",
|
|
211
|
+
series_ticker: "KXFED",
|
|
212
|
+
},
|
|
213
|
+
)!,
|
|
214
|
+
normalizeKalshiMarket(
|
|
215
|
+
{
|
|
216
|
+
ticker: "KXFED-27APR-T4.50",
|
|
217
|
+
title:
|
|
218
|
+
"Will the upper bound of the federal funds target rate be above 4.50%?",
|
|
219
|
+
yes_sub_title: "Above 4.50%",
|
|
220
|
+
event_ticker: "KXFED-27APR",
|
|
221
|
+
status: "open",
|
|
222
|
+
market_type: "binary",
|
|
223
|
+
last_price_dollars: "0.31",
|
|
224
|
+
volume_24h_fp: "12000",
|
|
225
|
+
strike_type: "greater",
|
|
226
|
+
floor_strike: "4.50",
|
|
227
|
+
} as any,
|
|
228
|
+
{
|
|
229
|
+
title: "Federal funds target rate after April 2026 FOMC",
|
|
230
|
+
sub_title: "Upper bound",
|
|
231
|
+
category: "Economics",
|
|
232
|
+
series_ticker: "KXFED",
|
|
233
|
+
},
|
|
234
|
+
)!,
|
|
235
|
+
]);
|
|
236
|
+
|
|
237
|
+
expect(
|
|
238
|
+
getPredictionColumnValue(
|
|
239
|
+
{
|
|
240
|
+
id: "yes",
|
|
241
|
+
label: "TOP ODDS",
|
|
242
|
+
width: 20,
|
|
243
|
+
align: "left",
|
|
244
|
+
description: "",
|
|
245
|
+
},
|
|
246
|
+
row!,
|
|
247
|
+
false,
|
|
248
|
+
),
|
|
249
|
+
).toMatchObject({
|
|
250
|
+
text: "48% Above 4.25%",
|
|
251
|
+
color: colors.negative,
|
|
252
|
+
});
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
test("uses an allowed Kalshi candlestick interval for 1W history", async () => {
|
|
256
|
+
let candlestickUrl: string | null = null;
|
|
257
|
+
|
|
258
|
+
globalThis.fetch = (async (input: Request | string | URL) => {
|
|
259
|
+
const url = String(input);
|
|
260
|
+
if (url.includes("/trade-api/v2/events/FED-1")) {
|
|
261
|
+
return new Response(
|
|
262
|
+
JSON.stringify({
|
|
263
|
+
event: {
|
|
264
|
+
title: "Fed series",
|
|
265
|
+
category: "Macro",
|
|
266
|
+
event_ticker: "FED-1",
|
|
267
|
+
series_ticker: "FED",
|
|
268
|
+
},
|
|
269
|
+
markets: [],
|
|
270
|
+
}),
|
|
271
|
+
{ status: 200 },
|
|
272
|
+
);
|
|
273
|
+
}
|
|
274
|
+
if (url.includes("/trade-api/v2/series/FED/markets/KAL-1/candlesticks")) {
|
|
275
|
+
candlestickUrl = url;
|
|
276
|
+
return new Response(JSON.stringify({ candlesticks: [] }), {
|
|
277
|
+
status: 200,
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
return new Response(JSON.stringify({}), { status: 200 });
|
|
281
|
+
}) as unknown as typeof fetch;
|
|
282
|
+
|
|
283
|
+
const summary = normalizeKalshiMarket({
|
|
284
|
+
ticker: "KAL-1",
|
|
285
|
+
title: "Will the Fed cut rates?",
|
|
286
|
+
yes_sub_title: "Yes",
|
|
287
|
+
event_ticker: "FED-1",
|
|
288
|
+
status: "open",
|
|
289
|
+
market_type: "binary",
|
|
290
|
+
last_price_dollars: "0.48",
|
|
291
|
+
} as any);
|
|
292
|
+
|
|
293
|
+
const history = await loadKalshiHistory(summary!, "1W");
|
|
294
|
+
expect(history).toEqual([]);
|
|
295
|
+
expect(candlestickUrl).toContain("period_interval=60");
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
test("normalizes keyboard commands from terminal key sequences", () => {
|
|
299
|
+
expect(resolvePredictionKeyboardCommand({ name: "esc" })).toBe("escape");
|
|
300
|
+
expect(resolvePredictionKeyboardCommand({ sequence: "j" })).toBe(
|
|
301
|
+
"move-down",
|
|
302
|
+
);
|
|
303
|
+
expect(resolvePredictionKeyboardCommand({ sequence: "\u001bOC" })).toBe(
|
|
304
|
+
"next-category",
|
|
305
|
+
);
|
|
306
|
+
expect(
|
|
307
|
+
resolvePredictionKeyboardCommand({
|
|
308
|
+
name: "right",
|
|
309
|
+
sequence: "\u001b[1;2C",
|
|
310
|
+
shift: true,
|
|
311
|
+
}),
|
|
312
|
+
).toBe("next-venue-tab");
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
test("filters closed Polymarket child markets from the catalog", async () => {
|
|
316
|
+
globalThis.fetch = (async (input: Request | string | URL) => {
|
|
317
|
+
const url = String(input);
|
|
318
|
+
if (url.includes("gamma-api.polymarket.com/events?")) {
|
|
319
|
+
return new Response(
|
|
320
|
+
JSON.stringify([
|
|
321
|
+
{
|
|
322
|
+
id: "event-iran",
|
|
323
|
+
title: "US forces enter Iran by..?",
|
|
324
|
+
tags: [{ label: "Geopolitics", slug: "geopolitics" }],
|
|
325
|
+
markets: [
|
|
326
|
+
{
|
|
327
|
+
id: "open-market",
|
|
328
|
+
question: "US forces enter Iran by April 30?",
|
|
329
|
+
groupItemTitle: "April 30",
|
|
330
|
+
conditionId: "cond-open",
|
|
331
|
+
outcomes: '["Yes","No"]',
|
|
332
|
+
outcomePrices: '["0.55","0.45"]',
|
|
333
|
+
clobTokenIds: '["yes-open","no-open"]',
|
|
334
|
+
volume24hr: 2500000,
|
|
335
|
+
spread: 0.01,
|
|
336
|
+
active: true,
|
|
337
|
+
closed: false,
|
|
338
|
+
},
|
|
339
|
+
{
|
|
340
|
+
id: "closed-market",
|
|
341
|
+
question: "US forces enter Iran by March 15?",
|
|
342
|
+
groupItemTitle: "March 15",
|
|
343
|
+
conditionId: "cond-closed",
|
|
344
|
+
outcomes: '["Yes","No"]',
|
|
345
|
+
outcomePrices: '["0.01","0.99"]',
|
|
346
|
+
clobTokenIds: '["yes-closed","no-closed"]',
|
|
347
|
+
volume24hr: 9999999,
|
|
348
|
+
spread: 0.01,
|
|
349
|
+
active: false,
|
|
350
|
+
closed: true,
|
|
351
|
+
},
|
|
352
|
+
],
|
|
353
|
+
},
|
|
354
|
+
]),
|
|
355
|
+
{ status: 200 },
|
|
356
|
+
);
|
|
357
|
+
}
|
|
358
|
+
return new Response(JSON.stringify({}), { status: 200 });
|
|
359
|
+
}) as unknown as typeof fetch;
|
|
360
|
+
|
|
361
|
+
const markets = await loadPolymarketCatalog("", "all");
|
|
362
|
+
expect(markets).toHaveLength(1);
|
|
363
|
+
expect(markets[0]?.marketLabel).toBe("April 30");
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
test("uses remote catalog endpoints for search and category changes", async () => {
|
|
367
|
+
const { fetchUrls } = installPredictionMarketMocks();
|
|
368
|
+
|
|
369
|
+
await loadPolymarketCatalog("inflation", "macro");
|
|
370
|
+
await loadKalshiCatalog("", "macro");
|
|
371
|
+
|
|
372
|
+
expect(
|
|
373
|
+
fetchUrls.some((url) =>
|
|
374
|
+
url.includes("gamma-api.polymarket.com/public-search?q=inflation"),
|
|
375
|
+
),
|
|
376
|
+
).toBe(true);
|
|
377
|
+
expect(
|
|
378
|
+
fetchUrls.some(
|
|
379
|
+
(url) =>
|
|
380
|
+
url.includes("/trade-api/v2/events?") &&
|
|
381
|
+
url.includes("category=Economics"),
|
|
382
|
+
),
|
|
383
|
+
).toBe(true);
|
|
384
|
+
});
|
|
385
|
+
|
|
386
|
+
test("falls back to thin Polymarket search results when event hydration fails", async () => {
|
|
387
|
+
let eventFetchCount = 0;
|
|
388
|
+
|
|
389
|
+
globalThis.fetch = (async (input: Request | string | URL) => {
|
|
390
|
+
const url = String(input);
|
|
391
|
+
if (url.includes("gamma-api.polymarket.com/public-search")) {
|
|
392
|
+
return new Response(
|
|
393
|
+
JSON.stringify({
|
|
394
|
+
events: [
|
|
395
|
+
{
|
|
396
|
+
id: "event-1",
|
|
397
|
+
title: "Fed decision in April?",
|
|
398
|
+
endDate: "2026-04-29T00:00:00Z",
|
|
399
|
+
markets: [
|
|
400
|
+
{
|
|
401
|
+
question:
|
|
402
|
+
"Will the Fed decrease interest rates by 25 bps after the April 2026 meeting?",
|
|
403
|
+
groupItemTitle: "25 bps decrease",
|
|
404
|
+
slug: "will-the-fed-decrease-interest-rates-by-25-bps-after-the-april-2026-meeting",
|
|
405
|
+
outcomes: ["Yes", "No"],
|
|
406
|
+
outcomePrices: ["0.22", "0.78"],
|
|
407
|
+
bestBid: 0.21,
|
|
408
|
+
bestAsk: 0.23,
|
|
409
|
+
lastTradePrice: 0.22,
|
|
410
|
+
spread: 0.02,
|
|
411
|
+
active: true,
|
|
412
|
+
closed: false,
|
|
413
|
+
},
|
|
414
|
+
],
|
|
415
|
+
},
|
|
416
|
+
],
|
|
417
|
+
}),
|
|
418
|
+
{ status: 200 },
|
|
419
|
+
);
|
|
420
|
+
}
|
|
421
|
+
if (url.includes("gamma-api.polymarket.com/events/event-1")) {
|
|
422
|
+
eventFetchCount += 1;
|
|
423
|
+
if (eventFetchCount === 1) {
|
|
424
|
+
return new Response("{}", { status: 500 });
|
|
425
|
+
}
|
|
426
|
+
return new Response(
|
|
427
|
+
JSON.stringify({
|
|
428
|
+
id: "event-1",
|
|
429
|
+
title: "Fed decision in April?",
|
|
430
|
+
description: "Canonical event",
|
|
431
|
+
resolutionSource: "FOMC",
|
|
432
|
+
openInterest: 500000,
|
|
433
|
+
tags: [{ label: "Macro", slug: "economy" }],
|
|
434
|
+
markets: [
|
|
435
|
+
{
|
|
436
|
+
id: "pm-1",
|
|
437
|
+
question:
|
|
438
|
+
"Will the Fed decrease interest rates by 25 bps after the April 2026 meeting?",
|
|
439
|
+
groupItemTitle: "25 bps decrease",
|
|
440
|
+
conditionId: "cond-1",
|
|
441
|
+
slug: "will-the-fed-decrease-interest-rates-by-25-bps-after-the-april-2026-meeting",
|
|
442
|
+
outcomes: '["Yes","No"]',
|
|
443
|
+
outcomePrices: '["0.22","0.78"]',
|
|
444
|
+
clobTokenIds: '["yes-1","no-1"]',
|
|
445
|
+
bestBid: 0.21,
|
|
446
|
+
bestAsk: 0.23,
|
|
447
|
+
lastTradePrice: 0.22,
|
|
448
|
+
spread: 0.02,
|
|
449
|
+
volume24hr: 120000,
|
|
450
|
+
volumeNum: 900000,
|
|
451
|
+
liquidityNum: 150000,
|
|
452
|
+
active: true,
|
|
453
|
+
closed: false,
|
|
454
|
+
},
|
|
455
|
+
],
|
|
456
|
+
}),
|
|
457
|
+
{ status: 200 },
|
|
458
|
+
);
|
|
459
|
+
}
|
|
460
|
+
if (url.includes("clob.polymarket.com/prices-history")) {
|
|
461
|
+
return new Response(
|
|
462
|
+
JSON.stringify({ history: [{ t: 1711929600, p: 0.22 }] }),
|
|
463
|
+
{ status: 200 },
|
|
464
|
+
);
|
|
465
|
+
}
|
|
466
|
+
if (url.includes("clob.polymarket.com/book?token_id=yes-1")) {
|
|
467
|
+
return new Response(
|
|
468
|
+
JSON.stringify({
|
|
469
|
+
bids: [{ price: "0.21", size: "100" }],
|
|
470
|
+
asks: [{ price: "0.23", size: "120" }],
|
|
471
|
+
last_trade_price: "0.22",
|
|
472
|
+
}),
|
|
473
|
+
{ status: 200 },
|
|
474
|
+
);
|
|
475
|
+
}
|
|
476
|
+
if (url.includes("clob.polymarket.com/book?token_id=no-1")) {
|
|
477
|
+
return new Response(
|
|
478
|
+
JSON.stringify({
|
|
479
|
+
bids: [{ price: "0.77", size: "80" }],
|
|
480
|
+
asks: [{ price: "0.79", size: "90" }],
|
|
481
|
+
last_trade_price: "0.78",
|
|
482
|
+
}),
|
|
483
|
+
{ status: 200 },
|
|
484
|
+
);
|
|
485
|
+
}
|
|
486
|
+
if (url.includes("data-api.polymarket.com/trades?market=cond-1")) {
|
|
487
|
+
return new Response(
|
|
488
|
+
JSON.stringify([
|
|
489
|
+
{
|
|
490
|
+
transactionHash: "0xabc",
|
|
491
|
+
side: "BUY",
|
|
492
|
+
size: 25,
|
|
493
|
+
price: 0.22,
|
|
494
|
+
timestamp: 1712102400,
|
|
495
|
+
outcome: "Yes",
|
|
496
|
+
},
|
|
497
|
+
]),
|
|
498
|
+
{ status: 200 },
|
|
499
|
+
);
|
|
500
|
+
}
|
|
501
|
+
return new Response(JSON.stringify({}), { status: 200 });
|
|
502
|
+
}) as unknown as typeof fetch;
|
|
503
|
+
|
|
504
|
+
const searchResults = await loadPolymarketCatalog("fed", "all");
|
|
505
|
+
const detail = await loadPolymarketDetail(searchResults[0]!, "1M");
|
|
506
|
+
|
|
507
|
+
expect(searchResults[0]?.conditionId).toBeUndefined();
|
|
508
|
+
expect(detail.summary.conditionId).toBe("cond-1");
|
|
509
|
+
});
|
|
510
|
+
|
|
511
|
+
test("filters Kalshi markets locally when venue category responses bleed across buckets", async () => {
|
|
512
|
+
globalThis.fetch = (async (input: Request | string | URL) => {
|
|
513
|
+
const url = String(input);
|
|
514
|
+
if (url.includes("/trade-api/v2/events?")) {
|
|
515
|
+
return new Response(
|
|
516
|
+
JSON.stringify({
|
|
517
|
+
events: [
|
|
518
|
+
{
|
|
519
|
+
title: "Fed series",
|
|
520
|
+
sub_title: "Upper bound",
|
|
521
|
+
category: "Economics",
|
|
522
|
+
event_ticker: "FED-1",
|
|
523
|
+
series_ticker: "FED",
|
|
524
|
+
markets: [
|
|
525
|
+
{
|
|
526
|
+
ticker: "KAL-MACRO",
|
|
527
|
+
title:
|
|
528
|
+
"Will the upper bound of the federal funds target rate be above 4.25%?",
|
|
529
|
+
yes_sub_title: "Above 4.25%",
|
|
530
|
+
event_ticker: "FED-1",
|
|
531
|
+
status: "open",
|
|
532
|
+
market_type: "binary",
|
|
533
|
+
last_price_dollars: "0.48",
|
|
534
|
+
volume_24h_fp: "15000",
|
|
535
|
+
strike_type: "greater",
|
|
536
|
+
floor_strike: "4.25",
|
|
537
|
+
},
|
|
538
|
+
],
|
|
539
|
+
},
|
|
540
|
+
{
|
|
541
|
+
title: "NBA Finals winner",
|
|
542
|
+
category: "Sports",
|
|
543
|
+
event_ticker: "NBA-1",
|
|
544
|
+
series_ticker: "NBA",
|
|
545
|
+
markets: [
|
|
546
|
+
{
|
|
547
|
+
ticker: "KAL-SPORTS",
|
|
548
|
+
title: "Will the Knicks win the title?",
|
|
549
|
+
event_ticker: "NBA-1",
|
|
550
|
+
status: "open",
|
|
551
|
+
market_type: "binary",
|
|
552
|
+
last_price_dollars: "0.35",
|
|
553
|
+
volume_24h_fp: "12000",
|
|
554
|
+
},
|
|
555
|
+
],
|
|
556
|
+
},
|
|
557
|
+
],
|
|
558
|
+
}),
|
|
559
|
+
{ status: 200 },
|
|
560
|
+
);
|
|
561
|
+
}
|
|
562
|
+
return new Response(JSON.stringify({}), { status: 200 });
|
|
563
|
+
}) as unknown as typeof fetch;
|
|
564
|
+
|
|
565
|
+
const macroMarkets = await loadKalshiCatalog("", "macro");
|
|
566
|
+
expect(macroMarkets.map((market) => market.marketId)).toEqual([
|
|
567
|
+
"KAL-MACRO",
|
|
568
|
+
]);
|
|
569
|
+
});
|
|
570
|
+
});
|