gloomberb 0.9.3 → 0.9.4
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 +1 -0
- package/package.json +1 -1
- package/src/app/runtime/desktop-menu.ts +5 -1
- package/src/app/runtime/ticker-refresh.ts +4 -1
- package/src/app.tsx +10 -1
- package/src/brokers/account-cache.ts +1 -1
- package/src/brokers/sync-broker-instance.test.ts +107 -0
- package/src/brokers/sync-broker-instance.ts +22 -10
- package/src/cli/desktop-pane-shot.ts +2 -1
- package/src/cli/pane-functions/screenshot.ts +13 -1
- package/src/components/chart/bar-chart-renderer.test.ts +108 -3
- package/src/components/chart/bar-chart-renderer.ts +226 -27
- package/src/components/chart/core/pointer.ts +32 -6
- package/src/components/chart/price-axis-labels.tsx +3 -1
- package/src/components/chart/static/bar-chart-surface.test.tsx +97 -0
- package/src/components/chart/static/bar-chart-surface.tsx +151 -28
- package/src/components/chart/static/chart/axis-overlays.tsx +243 -0
- package/src/components/chart/static/chart/surface.test.tsx +92 -0
- package/src/components/chart/static/chart/surface.tsx +167 -24
- package/src/components/chart/stock-chart/index.test.ts +25 -0
- package/src/components/command-bar/layout-items/current-layout.ts +5 -1
- package/src/components/layout/detached-pane-shell.tsx +6 -3
- package/src/components/layout/floating-pane.tsx +3 -2
- package/src/components/layout/pane/content.tsx +20 -8
- package/src/components/layout/pane/footer/registration.tsx +6 -2
- package/src/components/layout/pane/frame.tsx +4 -4
- package/src/components/layout/pane/header.tsx +40 -4
- package/src/components/layout/pane/index.tsx +3 -1
- package/src/components/layout/pane/sizing.test.ts +43 -0
- package/src/components/layout/pane/sizing.ts +13 -4
- package/src/components/layout/shell/cursor-occlusion.ts +196 -0
- package/src/components/layout/shell/drag/runtime.ts +9 -2
- package/src/components/layout/shell/index.test.tsx +92 -2
- package/src/components/layout/shell/index.tsx +37 -2
- package/src/components/layout/shell/layout-state.test.ts +33 -0
- package/src/components/layout/shell/layout-state.ts +4 -9
- package/src/components/layout/shell/pane/layers.tsx +8 -2
- package/src/components/layout/shell/visible-layout.ts +17 -0
- package/src/components/layout/status-bar.test.tsx +6 -1
- package/src/components/layout/status-bar.tsx +5 -1
- package/src/components/onboarding/onboarding-steps.tsx +8 -28
- package/src/components/onboarding/onboarding-wizard.test.tsx +13 -12
- package/src/components/onboarding/onboarding-wizard.tsx +2 -4
- package/src/components/onboarding/portfolio-step/index.tsx +0 -12
- package/src/components/onboarding/portfolio-step/types.ts +1 -3
- package/src/components/onboarding/wizard-keyboard.ts +2 -5
- package/src/components/table-view-shared.tsx +12 -4
- package/src/components/ui/data-table/opentui/index.tsx +25 -12
- package/src/components/ui/data-table/types.ts +4 -0
- package/src/components/ui/fields.tsx +10 -3
- package/src/components/ui/page-stack-view.tsx +6 -2
- package/src/components/ui/table-layout.test.ts +25 -0
- package/src/components/ui/table-layout.ts +22 -6
- package/src/components/ui/tabs.tsx +26 -10
- package/src/components/ui/ui.test.tsx +87 -0
- package/src/core/state/app/layout-reducer.ts +2 -2
- package/src/plugins/builtin/analytics/index.test.tsx +6 -2
- package/src/plugins/builtin/analytics/pane-model.ts +43 -8
- package/src/plugins/builtin/kelly-sizer/constants.ts +3 -0
- package/src/plugins/builtin/kelly-sizer/fields.ts +214 -0
- package/src/plugins/builtin/kelly-sizer/index.test.tsx +197 -0
- package/src/plugins/builtin/kelly-sizer/index.tsx +47 -0
- package/src/plugins/builtin/kelly-sizer/model.test.ts +152 -0
- package/src/plugins/builtin/kelly-sizer/model.ts +580 -0
- package/src/plugins/builtin/kelly-sizer/pane.tsx +558 -0
- package/src/plugins/builtin/kelly-sizer/portfolio.ts +71 -0
- package/src/plugins/builtin/kelly-sizer/sections.tsx +142 -0
- package/src/plugins/builtin/kelly-sizer/state.ts +67 -0
- package/src/plugins/builtin/kelly-sizer/test-support.tsx +174 -0
- package/src/plugins/builtin/kelly-sizer/types.ts +156 -0
- package/src/plugins/builtin/kelly-sizer/view.test.tsx +77 -0
- package/src/plugins/builtin/kelly-sizer/view.tsx +375 -0
- package/src/plugins/builtin/layout-manager/index.tsx +5 -1
- package/src/plugins/builtin/options/view.test.tsx +141 -4
- package/src/plugins/builtin/options/view.tsx +76 -15
- package/src/plugins/builtin/portfolio-list/account-metrics.test.ts +26 -1
- package/src/plugins/builtin/portfolio-list/account-metrics.ts +14 -0
- package/src/plugins/builtin/portfolio-list/index.test.ts +23 -0
- package/src/plugins/builtin/portfolio-list/pane/index.tsx +2 -0
- package/src/plugins/builtin/portfolio-list/summary/index.test.ts +59 -1
- package/src/plugins/builtin/portfolio-list/summary/index.tsx +36 -5
- package/src/plugins/builtin/ticker-detail/data-panes/fundamental-graph/content.tsx +149 -48
- package/src/plugins/builtin/ticker-detail/data-panes/fundamental-graph/model.ts +25 -2
- package/src/plugins/builtin/ticker-detail/data-panes/fundamental-graph.tsx +5 -4
- package/src/plugins/builtin/ticker-detail/data-panes.test.ts +16 -0
- package/src/plugins/builtin/ticker-detail/index.test.tsx +143 -0
- package/src/plugins/catalog-ui.ts +2 -0
- package/src/plugins/ibkr/broker-adapter.ts +19 -0
- package/src/plugins/ibkr/config.test.ts +31 -2
- package/src/plugins/ibkr/config.ts +9 -2
- package/src/plugins/ibkr/flex/index.test.ts +18 -9
- package/src/plugins/ibkr/flex/index.ts +30 -0
- package/src/plugins/ibkr/flex/statement-client.ts +68 -14
- package/src/plugins/ibkr/gateway/account-loaders.ts +1 -1
- package/src/plugins/ibkr/gateway/account-summary.ts +1 -0
- package/src/plugins/ibkr/gateway/service/index.test.ts +8 -0
- package/src/plugins/pane-manager/gridlock.ts +13 -5
- package/src/plugins/pane-manager/layout-state.ts +25 -0
- package/src/plugins/pane-manager.test.ts +33 -0
- package/src/plugins/pane-manager.ts +6 -1
- package/src/plugins/prediction-markets/chart.tsx +10 -4
- package/src/plugins/prediction-markets/detail/book.tsx +141 -96
- package/src/plugins/prediction-markets/detail/overview.tsx +3 -0
- package/src/plugins/prediction-markets/detail/pane.tsx +71 -64
- package/src/plugins/prediction-markets/detail/shared.tsx +19 -0
- package/src/plugins/prediction-markets/detail/trades.tsx +64 -19
- package/src/plugins/prediction-markets/detail.test.tsx +50 -0
- package/src/plugins/prediction-markets/pane.test.tsx +43 -0
- package/src/plugins/prediction-markets/pane.tsx +50 -22
- package/src/plugins/prediction-markets/test-helpers.tsx +41 -23
- package/src/renderers/electrobun/view/cli-pane-shot-entry.tsx +13 -2
- package/src/renderers/electrobun/view/data-table/index.tsx +19 -4
- package/src/renderers/electrobun/view/data-table/row.tsx +30 -6
- package/src/renderers/electrobun/view/desktop/controls.tsx +11 -5
- package/src/renderers/electrobun/view/host/input.tsx +115 -18
- package/src/renderers/electrobun/view/host/tabs.tsx +7 -2
- package/src/renderers/electrobun/view/styles.css +11 -0
- package/src/renderers/opentui/host.tsx +17 -1
- package/src/renderers/opentui/ui-host.tsx +57 -25
- package/src/sources/provider-router/batches.ts +16 -2
- package/src/sources/provider-router/financial-routes.ts +5 -0
- package/src/sources/provider-router/financials.ts +11 -23
- package/src/sources/provider-router/index.test.ts +189 -0
- package/src/sources/provider-router/primary.ts +3 -2
- package/src/sources/sec-edgar.test.ts +83 -0
- package/src/sources/sec-edgar.ts +231 -0
- package/src/sources/yahoo-finance.test.ts +51 -0
- package/src/sources/yahoo-finance.ts +49 -1
- package/src/state/app/context/index.test.tsx +5 -8
- package/src/types/broker.ts +1 -0
- package/src/types/config.ts +10 -0
- package/src/types/trading.ts +2 -0
- package/src/ui/host.tsx +16 -0
- package/src/ui/index.tsx +2 -0
- package/src/utils/financial-statements.ts +23 -0
- package/src/version.ts +1 -1
- package/src/components/onboarding/portfolio-step/manual-name-panel.tsx +0 -62
|
@@ -59,6 +59,10 @@ describe("parseFlexAccounts", () => {
|
|
|
59
59
|
<FxPosition accountId="DU12345" assetCategory="CASH" functionalCurrency="USD" fxCurrency="USD" quantity="-303029.144938754" value="-303029.144938754" />
|
|
60
60
|
<FxPosition accountId="DU12345" assetCategory="CASH" functionalCurrency="USD" fxCurrency="EUR" quantity="-351957.025" value="-405102.535775" />
|
|
61
61
|
</FxPositions>
|
|
62
|
+
<OpenPositions>
|
|
63
|
+
<OpenPosition accountId="DU12345" symbol="AAPL" assetCategory="STK" position="100" currency="USD" positionValue="100000" fxRateToBase="1" />
|
|
64
|
+
<OpenPosition accountId="DU12345" symbol="ASML" assetCategory="STK" position="10" currency="EUR" positionValue="50000" fxRateToBase="1.2" />
|
|
65
|
+
</OpenPositions>
|
|
62
66
|
</FlexStatement>
|
|
63
67
|
</FlexStatements>
|
|
64
68
|
</FlexQueryResponse>
|
|
@@ -71,7 +75,9 @@ describe("parseFlexAccounts", () => {
|
|
|
71
75
|
name: "Main",
|
|
72
76
|
currency: "USD",
|
|
73
77
|
source: "flex",
|
|
78
|
+
asOfDate: "2026-03-27",
|
|
74
79
|
netLiquidation: 764713.626876249,
|
|
80
|
+
grossPositionValue: 160000,
|
|
75
81
|
totalCashValue: -1050953.720462251,
|
|
76
82
|
settledCash: -917604.448220862,
|
|
77
83
|
cashBalances: [
|
|
@@ -110,7 +116,9 @@ describe("parseFlexAccounts", () => {
|
|
|
110
116
|
currency: "USD",
|
|
111
117
|
source: "flex",
|
|
112
118
|
updatedAt: new Date(2026, 2, 27).getTime(),
|
|
119
|
+
asOfDate: "2026-03-27",
|
|
113
120
|
netLiquidation: 12345.67,
|
|
121
|
+
grossPositionValue: undefined,
|
|
114
122
|
totalCashValue: undefined,
|
|
115
123
|
settledCash: undefined,
|
|
116
124
|
cashBalances: undefined,
|
|
@@ -190,9 +198,9 @@ describe("parseFlexPortfolioPerformance", () => {
|
|
|
190
198
|
|
|
191
199
|
describe("requestFlexStatement", () => {
|
|
192
200
|
test("uses the configured HTTP transport for statement requests", async () => {
|
|
193
|
-
const requests: string
|
|
194
|
-
setHttpFetchTransport(async (url) => {
|
|
195
|
-
requests.push(url);
|
|
201
|
+
const requests: Array<{ url: string; init: RequestInit | undefined }> = [];
|
|
202
|
+
setHttpFetchTransport(async (url, init) => {
|
|
203
|
+
requests.push({ url, init });
|
|
196
204
|
return new Response(
|
|
197
205
|
"<FlexStatementResponse><ReferenceCode>987654</ReferenceCode></FlexStatementResponse>",
|
|
198
206
|
{ status: 200 },
|
|
@@ -202,16 +210,17 @@ describe("requestFlexStatement", () => {
|
|
|
202
210
|
await expect(requestFlexStatement({
|
|
203
211
|
token: "secret-flex-token",
|
|
204
212
|
queryId: "12345",
|
|
205
|
-
endpoint: "https://
|
|
213
|
+
endpoint: "https://ndcdyn.interactivebrokers.com/AccountManagement/FlexWebService/SendRequest",
|
|
206
214
|
})).resolves.toBe("987654");
|
|
207
215
|
|
|
208
216
|
expect(requests).toHaveLength(1);
|
|
209
|
-
expect(requests[0]).toContain("q=12345");
|
|
217
|
+
expect(requests[0]?.url).toContain("q=12345");
|
|
218
|
+
expect((requests[0]?.init?.headers as Record<string, string> | undefined)?.["User-Agent"]).toBeTruthy();
|
|
210
219
|
});
|
|
211
220
|
|
|
212
221
|
test("adds request context to vague IBKR Flex errors without exposing the token", async () => {
|
|
213
222
|
globalThis.fetch = (async () => new Response(
|
|
214
|
-
"<FlexStatementResponse><ErrorMessage>Load failed</ErrorMessage></FlexStatementResponse>",
|
|
223
|
+
"<FlexStatementResponse><ErrorCode>1001</ErrorCode><ErrorMessage>Load failed</ErrorMessage></FlexStatementResponse>",
|
|
215
224
|
{ status: 200 },
|
|
216
225
|
)) as unknown as typeof fetch;
|
|
217
226
|
|
|
@@ -220,14 +229,14 @@ describe("requestFlexStatement", () => {
|
|
|
220
229
|
await requestFlexStatement({
|
|
221
230
|
token: "secret-flex-token",
|
|
222
231
|
queryId: "12345",
|
|
223
|
-
endpoint: "https://
|
|
232
|
+
endpoint: "https://ndcdyn.interactivebrokers.com/AccountManagement/FlexWebService/SendRequest",
|
|
224
233
|
});
|
|
225
234
|
} catch (error) {
|
|
226
235
|
message = error instanceof Error ? error.message : String(error);
|
|
227
236
|
}
|
|
228
237
|
|
|
229
|
-
expect(message).toContain("IBKR Flex request failed while requesting the statement: Load failed.");
|
|
230
|
-
expect(message).toContain("Endpoint
|
|
238
|
+
expect(message).toContain("IBKR Flex request failed while requesting the statement: IBKR error 1001: Load failed.");
|
|
239
|
+
expect(message).toContain("Endpoint SendRequest");
|
|
231
240
|
expect(message).toContain("query ID 12345");
|
|
232
241
|
expect(message).toContain("token configured");
|
|
233
242
|
expect(message).toContain("Flex Web Service is enabled");
|
|
@@ -63,6 +63,34 @@ function parseFlexDate(raw: string | undefined): string | null {
|
|
|
63
63
|
return new Date(parsed).toISOString().slice(0, 10);
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
+
function parseFlexGrossPositionValue(
|
|
67
|
+
body: string,
|
|
68
|
+
statementAccountId: string,
|
|
69
|
+
baseCurrency: string | undefined,
|
|
70
|
+
): number | undefined {
|
|
71
|
+
let total = 0;
|
|
72
|
+
let hasValue = false;
|
|
73
|
+
|
|
74
|
+
for (const entry of body.matchAll(/<OpenPosition\b([^>]*)\/?>/g)) {
|
|
75
|
+
const attributes = parseAttributes(entry[1] ?? "");
|
|
76
|
+
const accountId = attributes.accountId || statementAccountId;
|
|
77
|
+
if (!accountId || (statementAccountId && accountId !== statementAccountId)) continue;
|
|
78
|
+
|
|
79
|
+
const marketValue = parseNumber(attributes.positionValue);
|
|
80
|
+
if (marketValue == null) continue;
|
|
81
|
+
|
|
82
|
+
const positionCurrency = attributes.currency || baseCurrency;
|
|
83
|
+
const fxRateToBase = parseNumber(attributes.fxRateToBase)
|
|
84
|
+
?? (baseCurrency && positionCurrency === baseCurrency ? 1 : undefined);
|
|
85
|
+
if (fxRateToBase == null) continue;
|
|
86
|
+
|
|
87
|
+
total += Math.abs(marketValue * fxRateToBase);
|
|
88
|
+
hasValue = true;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return hasValue ? total : undefined;
|
|
92
|
+
}
|
|
93
|
+
|
|
66
94
|
function buildContractRef(attributes: Record<string, string>, symbol: string, assetCategory: string): BrokerContractRef | undefined {
|
|
67
95
|
const conIdRaw = attributes.conid || attributes.conId;
|
|
68
96
|
const strikeRaw = attributes.strike;
|
|
@@ -211,7 +239,9 @@ export function parseFlexAccounts(xml: string): BrokerAccount[] {
|
|
|
211
239
|
currency: accountCurrency,
|
|
212
240
|
source: "flex",
|
|
213
241
|
updatedAt: parseFlexTimestamp(statementAttrs.whenGenerated, statementAttrs.toDate || statementAttrs.fromDate),
|
|
242
|
+
asOfDate: parseFlexDate(statementAttrs.toDate || statementAttrs.fromDate) ?? undefined,
|
|
214
243
|
netLiquidation: parseNumber(changeInNavAttrs?.endingValue),
|
|
244
|
+
grossPositionValue: parseFlexGrossPositionValue(body, accountId, accountCurrency),
|
|
215
245
|
totalCashValue: parseNumber(baseCashAttrs?.endingCash),
|
|
216
246
|
settledCash: parseNumber(baseCashAttrs?.endingSettledCash),
|
|
217
247
|
cashBalances: cashBalances.length > 0 ? cashBalances : undefined,
|
|
@@ -2,7 +2,8 @@ import { httpFetch } from "../../../utils/http-transport";
|
|
|
2
2
|
import type { FlexQueryConfig } from "../config";
|
|
3
3
|
import { IBKR_STATEMENT_URL } from "../config";
|
|
4
4
|
|
|
5
|
-
const IBKR_STATEMENT_GET_URL = "https://
|
|
5
|
+
const IBKR_STATEMENT_GET_URL = "https://ndcdyn.interactivebrokers.com/AccountManagement/FlexWebService/GetStatement";
|
|
6
|
+
const FLEX_USER_AGENT = "Gloomberb/1.0 Flex";
|
|
6
7
|
const FLEX_STATEMENT_CACHE_MS = 15 * 60_000;
|
|
7
8
|
const FLEX_STATEMENT_INITIAL_WAIT_MS = 3_000;
|
|
8
9
|
const FLEX_STATEMENT_POLL_DELAY_MS = 5_000;
|
|
@@ -29,10 +30,54 @@ function decodeXmlText(value: string): string {
|
|
|
29
30
|
.replace(/'/g, "'");
|
|
30
31
|
}
|
|
31
32
|
|
|
33
|
+
function extractXmlTag(text: string, tagName: string): string | null {
|
|
34
|
+
const match = text.match(new RegExp(`<${tagName}>\\s*([^<]*?)\\s*<\\/${tagName}>`, "i"));
|
|
35
|
+
return match?.[1] ? decodeXmlText(match[1].trim()) : null;
|
|
36
|
+
}
|
|
37
|
+
|
|
32
38
|
function extractFlexErrorMessage(text: string): string | null {
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
return
|
|
39
|
+
const message = extractXmlTag(text, "ErrorMessage");
|
|
40
|
+
const code = extractXmlTag(text, "ErrorCode");
|
|
41
|
+
if (message && code) return `IBKR error ${code}: ${message}`;
|
|
42
|
+
return message;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function buildFlexUrl(endpoint: string, params: Record<string, string>): string {
|
|
46
|
+
const url = new URL(endpoint);
|
|
47
|
+
for (const [key, value] of Object.entries(params)) {
|
|
48
|
+
url.searchParams.set(key, value);
|
|
49
|
+
}
|
|
50
|
+
return url.toString();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function resolveFlexGetEndpoint(sendEndpoint: string | undefined): string {
|
|
54
|
+
if (!sendEndpoint || sendEndpoint === IBKR_STATEMENT_URL) return IBKR_STATEMENT_GET_URL;
|
|
55
|
+
|
|
56
|
+
try {
|
|
57
|
+
const url = new URL(sendEndpoint);
|
|
58
|
+
url.search = "";
|
|
59
|
+
if (url.pathname.endsWith("/SendRequest")) {
|
|
60
|
+
url.pathname = url.pathname.replace(/\/SendRequest$/, "/GetStatement");
|
|
61
|
+
return url.toString();
|
|
62
|
+
}
|
|
63
|
+
if (url.pathname.endsWith("FlexStatementService.SendRequest")) {
|
|
64
|
+
url.pathname = url.pathname.replace(/FlexStatementService\.SendRequest$/, "FlexStatementService.GetStatement");
|
|
65
|
+
return url.toString();
|
|
66
|
+
}
|
|
67
|
+
} catch {
|
|
68
|
+
return IBKR_STATEMENT_GET_URL;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return IBKR_STATEMENT_GET_URL;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function flexRequestInit(): RequestInit {
|
|
75
|
+
return {
|
|
76
|
+
headers: {
|
|
77
|
+
"User-Agent": FLEX_USER_AGENT,
|
|
78
|
+
},
|
|
79
|
+
signal: AbortSignal.timeout(30_000),
|
|
80
|
+
};
|
|
36
81
|
}
|
|
37
82
|
|
|
38
83
|
function endpointName(endpoint: string | undefined): string {
|
|
@@ -69,11 +114,15 @@ function flexError(providerMessage: string, context: FlexErrorContext): Error {
|
|
|
69
114
|
|
|
70
115
|
export async function requestFlexStatement(config: FlexQueryConfig): Promise<string> {
|
|
71
116
|
const endpoint = config.endpoint || IBKR_STATEMENT_URL;
|
|
72
|
-
const url =
|
|
117
|
+
const url = buildFlexUrl(endpoint, {
|
|
118
|
+
t: config.token,
|
|
119
|
+
q: config.queryId,
|
|
120
|
+
v: "3",
|
|
121
|
+
});
|
|
73
122
|
let resp: Response;
|
|
74
123
|
let text: string;
|
|
75
124
|
try {
|
|
76
|
-
resp = await httpFetch(url,
|
|
125
|
+
resp = await httpFetch(url, flexRequestInit());
|
|
77
126
|
text = await resp.text();
|
|
78
127
|
} catch (error) {
|
|
79
128
|
throw flexError(error instanceof Error ? error.message : "Network request failed", {
|
|
@@ -84,8 +133,8 @@ export async function requestFlexStatement(config: FlexQueryConfig): Promise<str
|
|
|
84
133
|
});
|
|
85
134
|
}
|
|
86
135
|
|
|
87
|
-
const
|
|
88
|
-
if (!
|
|
136
|
+
const referenceCode = extractXmlTag(text, "ReferenceCode");
|
|
137
|
+
if (!referenceCode) {
|
|
89
138
|
throw flexError(extractFlexErrorMessage(text) || "No reference code returned", {
|
|
90
139
|
phase: "request",
|
|
91
140
|
endpoint,
|
|
@@ -95,7 +144,7 @@ export async function requestFlexStatement(config: FlexQueryConfig): Promise<str
|
|
|
95
144
|
});
|
|
96
145
|
}
|
|
97
146
|
|
|
98
|
-
return
|
|
147
|
+
return referenceCode;
|
|
99
148
|
}
|
|
100
149
|
|
|
101
150
|
async function getFlexStatement(
|
|
@@ -105,17 +154,22 @@ async function getFlexStatement(
|
|
|
105
154
|
): Promise<string> {
|
|
106
155
|
await new Promise((resolve) => setTimeout(resolve, FLEX_STATEMENT_INITIAL_WAIT_MS));
|
|
107
156
|
|
|
108
|
-
const
|
|
157
|
+
const endpoint = resolveFlexGetEndpoint(context.endpoint);
|
|
158
|
+
const url = buildFlexUrl(endpoint, {
|
|
159
|
+
t: token,
|
|
160
|
+
q: referenceCode,
|
|
161
|
+
v: "3",
|
|
162
|
+
});
|
|
109
163
|
for (let attempt = 0; attempt < FLEX_STATEMENT_MAX_DOWNLOAD_ATTEMPTS; attempt += 1) {
|
|
110
164
|
let resp: Response;
|
|
111
165
|
let text: string;
|
|
112
166
|
try {
|
|
113
|
-
resp = await httpFetch(url,
|
|
167
|
+
resp = await httpFetch(url, flexRequestInit());
|
|
114
168
|
text = await resp.text();
|
|
115
169
|
} catch (error) {
|
|
116
170
|
throw flexError(error instanceof Error ? error.message : "Network request failed", {
|
|
117
171
|
phase: "download",
|
|
118
|
-
endpoint
|
|
172
|
+
endpoint,
|
|
119
173
|
queryId: context.queryId,
|
|
120
174
|
token,
|
|
121
175
|
referenceCode,
|
|
@@ -135,7 +189,7 @@ async function getFlexStatement(
|
|
|
135
189
|
if (providerMessage) {
|
|
136
190
|
throw flexError(providerMessage, {
|
|
137
191
|
phase: "download",
|
|
138
|
-
endpoint
|
|
192
|
+
endpoint,
|
|
139
193
|
queryId: context.queryId,
|
|
140
194
|
token,
|
|
141
195
|
referenceCode,
|
|
@@ -146,7 +200,7 @@ async function getFlexStatement(
|
|
|
146
200
|
|
|
147
201
|
throw flexError("statement generation timed out", {
|
|
148
202
|
phase: "download",
|
|
149
|
-
endpoint
|
|
203
|
+
endpoint,
|
|
150
204
|
queryId: context.queryId,
|
|
151
205
|
token,
|
|
152
206
|
referenceCode,
|
|
@@ -96,7 +96,7 @@ export async function loadIbkrAccounts({
|
|
|
96
96
|
const result = await firstValueFrom(
|
|
97
97
|
api.getAccountSummary(
|
|
98
98
|
"All",
|
|
99
|
-
"NetLiquidation,TotalCashValue,SettledCash,AvailableFunds,BuyingPower,ExcessLiquidity,InitMarginReq,MaintMarginReq,$LEDGER:ALL",
|
|
99
|
+
"NetLiquidation,GrossPositionValue,TotalCashValue,SettledCash,AvailableFunds,BuyingPower,ExcessLiquidity,InitMarginReq,MaintMarginReq,$LEDGER:ALL",
|
|
100
100
|
)
|
|
101
101
|
.pipe(take(1), timeout(10_000)),
|
|
102
102
|
);
|
|
@@ -148,6 +148,7 @@ export function summarizeBrokerAccount(
|
|
|
148
148
|
source: "gateway",
|
|
149
149
|
updatedAt,
|
|
150
150
|
netLiquidation: getAccountSummaryNumberWithAggregateFallback(tags, aggregateTags, "NetLiquidation", currency, allowAggregateCashBalances),
|
|
151
|
+
grossPositionValue: getAccountSummaryNumberWithAggregateFallback(tags, aggregateTags, "GrossPositionValue", currency, allowAggregateCashBalances),
|
|
151
152
|
totalCashValue: getAccountSummaryNumberWithAggregateFallback(tags, aggregateTags, "TotalCashValue", currency, allowAggregateCashBalances),
|
|
152
153
|
settledCash: getAccountSummaryNumberWithAggregateFallback(tags, aggregateTags, "SettledCash", currency, allowAggregateCashBalances),
|
|
153
154
|
availableFunds: getAccountSummaryNumberWithAggregateFallback(tags, aggregateTags, "AvailableFunds", currency, allowAggregateCashBalances),
|
|
@@ -35,6 +35,7 @@ describe("summarizeBrokerAccount", () => {
|
|
|
35
35
|
test("maps gateway account summary fields and ledger balances", () => {
|
|
36
36
|
const tags = makeTags({
|
|
37
37
|
NetLiquidation: { USD: "764713.62" },
|
|
38
|
+
GrossPositionValue: { USD: "1815667.34" },
|
|
38
39
|
TotalCashValue: { USD: "-1050953.72" },
|
|
39
40
|
SettledCash: { USD: "-917604.44" },
|
|
40
41
|
AvailableFunds: { USD: "112345.67" },
|
|
@@ -52,6 +53,7 @@ describe("summarizeBrokerAccount", () => {
|
|
|
52
53
|
source: "gateway",
|
|
53
54
|
updatedAt: 1_717_000_000_000,
|
|
54
55
|
netLiquidation: 764713.62,
|
|
56
|
+
grossPositionValue: 1815667.34,
|
|
55
57
|
totalCashValue: -1050953.72,
|
|
56
58
|
settledCash: -917604.44,
|
|
57
59
|
availableFunds: 112345.67,
|
|
@@ -72,6 +74,7 @@ describe("summarizeBrokerAccount", () => {
|
|
|
72
74
|
test("falls back to the aggregate cash summary for single-account gateways", () => {
|
|
73
75
|
const accountTags = makeTags({
|
|
74
76
|
NetLiquidation: { USD: "129360.15" },
|
|
77
|
+
GrossPositionValue: { USD: "1066.36" },
|
|
75
78
|
TotalCashValue: { USD: "128293.79" },
|
|
76
79
|
AvailableFunds: { USD: "129031.52" },
|
|
77
80
|
BuyingPower: { USD: "860210.13" },
|
|
@@ -99,6 +102,7 @@ describe("summarizeBrokerAccount", () => {
|
|
|
99
102
|
source: "gateway",
|
|
100
103
|
updatedAt: 1_717_000_000_000,
|
|
101
104
|
netLiquidation: 129360.15,
|
|
105
|
+
grossPositionValue: 1066.36,
|
|
102
106
|
totalCashValue: 128293.79,
|
|
103
107
|
settledCash: undefined,
|
|
104
108
|
availableFunds: 129031.52,
|
|
@@ -119,6 +123,7 @@ describe("summarizeBrokerAccount", () => {
|
|
|
119
123
|
test("falls back to aggregate summary metrics when a single-account gateway only returns the All row", () => {
|
|
120
124
|
const aggregateTags = makeTags({
|
|
121
125
|
NetLiquidation: { USD: "129360.15" },
|
|
126
|
+
GrossPositionValue: { USD: "1066.36" },
|
|
122
127
|
TotalCashValue: { USD: "128293.79" },
|
|
123
128
|
AvailableFunds: { USD: "129031.52" },
|
|
124
129
|
BuyingPower: { USD: "860210.13" },
|
|
@@ -144,6 +149,7 @@ describe("summarizeBrokerAccount", () => {
|
|
|
144
149
|
source: "gateway",
|
|
145
150
|
updatedAt: 1_717_000_000_000,
|
|
146
151
|
netLiquidation: 129360.15,
|
|
152
|
+
grossPositionValue: 1066.36,
|
|
147
153
|
totalCashValue: 128293.79,
|
|
148
154
|
settledCash: undefined,
|
|
149
155
|
availableFunds: 129031.52,
|
|
@@ -164,6 +170,7 @@ describe("summarizeBrokerAccount", () => {
|
|
|
164
170
|
test("maps account-level P&L into gateway account snapshots", () => {
|
|
165
171
|
const tags = makeTags({
|
|
166
172
|
NetLiquidation: { USD: "100000" },
|
|
173
|
+
GrossPositionValue: { USD: "75000" },
|
|
167
174
|
});
|
|
168
175
|
|
|
169
176
|
expect(summarizeBrokerAccount("DU12345", tags, 1_717_000_000_000, undefined, false, {
|
|
@@ -186,6 +193,7 @@ describe("summarizeBrokerAccount", () => {
|
|
|
186
193
|
source: "gateway",
|
|
187
194
|
updatedAt: 123,
|
|
188
195
|
netLiquidation: undefined,
|
|
196
|
+
grossPositionValue: undefined,
|
|
189
197
|
totalCashValue: undefined,
|
|
190
198
|
settledCash: undefined,
|
|
191
199
|
availableFunds: undefined,
|
|
@@ -8,15 +8,23 @@ import {
|
|
|
8
8
|
getDockLeafLayouts,
|
|
9
9
|
type LayoutBounds,
|
|
10
10
|
} from "./dock-tree";
|
|
11
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
finalizeLayout,
|
|
13
|
+
removeUnavailablePaneTypes,
|
|
14
|
+
type PaneTypeAvailability,
|
|
15
|
+
} from "./layout-state";
|
|
12
16
|
|
|
13
17
|
export function gridlockAllPanes(
|
|
14
18
|
layout: LayoutConfig,
|
|
15
19
|
bounds: LayoutBounds = { x: 0, y: 0, width: 120, height: 40 },
|
|
20
|
+
paneTypes?: PaneTypeAvailability,
|
|
16
21
|
): LayoutConfig {
|
|
17
|
-
const
|
|
22
|
+
const visibleLayout = paneTypes
|
|
23
|
+
? removeUnavailablePaneTypes(layout, paneTypes)
|
|
24
|
+
: layout;
|
|
25
|
+
const dockedRects: GridlockRect[] = getDockLeafLayouts(visibleLayout, bounds)
|
|
18
26
|
.map((leaf) => ({ instanceId: leaf.instanceId, ...leaf.rect }));
|
|
19
|
-
const floatingRects: GridlockRect[] =
|
|
27
|
+
const floatingRects: GridlockRect[] = visibleLayout.floating.map((entry) => ({
|
|
20
28
|
instanceId: entry.instanceId,
|
|
21
29
|
x: entry.x,
|
|
22
30
|
y: entry.y,
|
|
@@ -24,10 +32,10 @@ export function gridlockAllPanes(
|
|
|
24
32
|
height: entry.height,
|
|
25
33
|
}));
|
|
26
34
|
const allRects = [...dockedRects, ...floatingRects];
|
|
27
|
-
if (allRects.length === 0) return
|
|
35
|
+
if (allRects.length === 0) return visibleLayout;
|
|
28
36
|
|
|
29
37
|
return finalizeLayout({
|
|
30
|
-
...
|
|
38
|
+
...visibleLayout,
|
|
31
39
|
dockRoot: inferDockTreeFromRects(allRects, boundsForRects(allRects)),
|
|
32
40
|
floating: [],
|
|
33
41
|
});
|
|
@@ -169,3 +169,28 @@ export function removeFloatingPanes(layout: LayoutConfig): LayoutConfig {
|
|
|
169
169
|
layout.floating.map((entry) => entry.instanceId),
|
|
170
170
|
));
|
|
171
171
|
}
|
|
172
|
+
|
|
173
|
+
export type PaneTypeAvailability = { has(paneId: string): boolean } | ((paneId: string) => unknown);
|
|
174
|
+
|
|
175
|
+
function paneTypeIsAvailable(availability: PaneTypeAvailability, paneId: string): boolean {
|
|
176
|
+
return typeof availability === "function"
|
|
177
|
+
? !!availability(paneId)
|
|
178
|
+
: availability.has(paneId);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export function removeUnavailablePaneTypes(
|
|
182
|
+
layout: LayoutConfig,
|
|
183
|
+
availability: PaneTypeAvailability,
|
|
184
|
+
options: { disabledPaneIds?: ReadonlySet<string> } = {},
|
|
185
|
+
): LayoutConfig {
|
|
186
|
+
const unavailableInstanceIds = layout.instances
|
|
187
|
+
.filter((instance) => (
|
|
188
|
+
options.disabledPaneIds?.has(instance.paneId)
|
|
189
|
+
|| !paneTypeIsAvailable(availability, instance.paneId)
|
|
190
|
+
))
|
|
191
|
+
.map((instance) => instance.instanceId);
|
|
192
|
+
|
|
193
|
+
return unavailableInstanceIds.length > 0
|
|
194
|
+
? removePaneInstances(layout, unavailableInstanceIds)
|
|
195
|
+
: layout;
|
|
196
|
+
}
|
|
@@ -109,6 +109,39 @@ describe("pane-manager split-tree drops", () => {
|
|
|
109
109
|
expect(getDockedPaneIds(next)).toHaveLength(layout.instances.length);
|
|
110
110
|
});
|
|
111
111
|
|
|
112
|
+
test("gridlock drops pane types that cannot render before tiling", () => {
|
|
113
|
+
const layout: LayoutConfig = {
|
|
114
|
+
dockRoot: {
|
|
115
|
+
kind: "split" as const,
|
|
116
|
+
axis: "horizontal" as const,
|
|
117
|
+
ratio: 0.5,
|
|
118
|
+
first: {
|
|
119
|
+
kind: "split" as const,
|
|
120
|
+
axis: "vertical" as const,
|
|
121
|
+
ratio: 0.5,
|
|
122
|
+
first: { kind: "pane" as const, instanceId: "missing:main" },
|
|
123
|
+
second: { kind: "pane" as const, instanceId: "chat:main" },
|
|
124
|
+
},
|
|
125
|
+
second: { kind: "pane" as const, instanceId: "sectors:main" },
|
|
126
|
+
},
|
|
127
|
+
instances: [
|
|
128
|
+
createPaneInstance("missing-plugin", { instanceId: "missing:main" }),
|
|
129
|
+
createPaneInstance("chat", { instanceId: "chat:main" }),
|
|
130
|
+
createPaneInstance("sectors", { instanceId: "sectors:main" }),
|
|
131
|
+
],
|
|
132
|
+
floating: [],
|
|
133
|
+
detached: [],
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
const next = gridlockAllPanes(layout, BOUNDS, new Set(["chat", "sectors"]));
|
|
137
|
+
|
|
138
|
+
expect(next.instances.map((instance) => instance.instanceId)).toEqual(["chat:main", "sectors:main"]);
|
|
139
|
+
expect(getDockedPaneIds(next)).toEqual(["chat:main", "sectors:main"]);
|
|
140
|
+
expect(getLeafRect(next, "missing:main", BOUNDS)).toBeNull();
|
|
141
|
+
expect(getLeafRect(next, "chat:main", BOUNDS)).toEqual({ x: 0, y: 0, width: 60, height: 40 });
|
|
142
|
+
expect(getLeafRect(next, "sectors:main", BOUNDS)).toEqual({ x: 60, y: 0, width: 60, height: 40 });
|
|
143
|
+
});
|
|
144
|
+
|
|
112
145
|
test("gridlock infers a matching tiled layout from arranged windows", () => {
|
|
113
146
|
const config = createDefaultConfig("/tmp/gloomberb-test");
|
|
114
147
|
let layout: LayoutConfig = {
|
|
@@ -49,7 +49,12 @@ export {
|
|
|
49
49
|
swapPanes,
|
|
50
50
|
} from "./pane-manager/docking";
|
|
51
51
|
|
|
52
|
-
export {
|
|
52
|
+
export {
|
|
53
|
+
removeFloatingPanes,
|
|
54
|
+
removePane,
|
|
55
|
+
removeUnavailablePaneTypes,
|
|
56
|
+
type PaneTypeAvailability,
|
|
57
|
+
} from "./pane-manager/layout-state";
|
|
53
58
|
export { gridlockAllPanes } from "./pane-manager/gridlock";
|
|
54
59
|
export type {
|
|
55
60
|
DropTarget,
|
|
@@ -72,12 +72,14 @@ export function PredictionMarketChart({
|
|
|
72
72
|
history,
|
|
73
73
|
width,
|
|
74
74
|
height,
|
|
75
|
+
loading = false,
|
|
75
76
|
range,
|
|
76
77
|
onRangeSelect,
|
|
77
78
|
}: {
|
|
78
79
|
history: PredictionHistoryPoint[];
|
|
79
80
|
width: number;
|
|
80
81
|
height: number;
|
|
82
|
+
loading?: boolean;
|
|
81
83
|
range: PredictionHistoryRange;
|
|
82
84
|
onRangeSelect: (range: PredictionHistoryRange) => void;
|
|
83
85
|
}) {
|
|
@@ -93,10 +95,14 @@ export function PredictionMarketChart({
|
|
|
93
95
|
/>
|
|
94
96
|
</Box>
|
|
95
97
|
<Box flexGrow={1} justifyContent="center">
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
98
|
+
{loading ? (
|
|
99
|
+
<Text fg={colors.textDim}>Loading chart...</Text>
|
|
100
|
+
) : (
|
|
101
|
+
<EmptyState
|
|
102
|
+
title="No chart history."
|
|
103
|
+
hint="This venue did not return price history for the selected market."
|
|
104
|
+
/>
|
|
105
|
+
)}
|
|
100
106
|
</Box>
|
|
101
107
|
</Box>
|
|
102
108
|
);
|