From 3509fc786d56a35d3451fc80d541ffbec598f832 Mon Sep 17 00:00:00 2001 From: ibrahim Date: Sat, 31 Oct 2026 14:57:40 +0000 Subject: [PATCH 1/5] test(ts-sdk): hosted position maps current_value to currentValue --- sdks/typescript/.sandbox.sb | 38 ++++++++++++++++++++ sdks/typescript/tests/hosted-mappers.test.ts | 32 +++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 sdks/typescript/.sandbox.sb create mode 100644 sdks/typescript/tests/hosted-mappers.test.ts diff --git a/sdks/typescript/.sandbox.sb b/sdks/typescript/.sandbox.sb new file mode 100644 index 00000000..eb59712a --- /dev/null +++ b/sdks/typescript/.sandbox.sb @@ -0,0 +1,38 @@ +(version 1) +(deny default) +(allow process-exec process-fork) +(allow signal (target same-sandbox)) +(allow sysctl-read) +(allow file-read* (literal "/")) +(allow file-read-metadata (literal "/Users")) +(allow file-read-metadata (literal "/Users/ibrahimyildiz")) +(allow file-read-metadata (literal "/Users/ibrahimyildiz/Library")) +(allow file-read-metadata (literal "/Users/ibrahimyildiz/Library/Application Support")) +(allow file-read-metadata (literal "/Users/ibrahimyildiz/Library/Application Support/Contributor")) +(allow file-read-metadata (literal "/Users/ibrahimyildiz/Library/Application Support/Contributor/runs")) +(allow file-read-metadata (literal "/Users/ibrahimyildiz/Library/Application Support/Contributor/runs/2026-10-29")) +(allow file-read-metadata (literal "/Users/ibrahimyildiz/Library/Application Support/Contributor/runs/2026-10-29/pmxt-dev-pmxt-2423")) +(allow file-read-metadata (literal "/Users/ibrahimyildiz/Library/Application Support/Contributor/runs/2026-10-29/pmxt-dev-pmxt-2423/repo")) +(allow file-read-metadata (literal "/Users/ibrahimyildiz/Library/Application Support/Contributor/runs/2026-10-29/pmxt-dev-pmxt-2423/repo/sdks")) +(allow file-read-metadata (literal "/opt")) +(allow file-read-metadata (literal "/private/var")) +(allow file-read-metadata (literal "/private/var/select")) +(allow file-read-metadata (literal "/var")) +(allow file-read* (subpath "/usr")) +(allow file-read* (subpath "/bin")) +(allow file-read* (subpath "/sbin")) +(allow file-read* (subpath "/System")) +(allow file-read* (subpath "/Library")) +(allow file-read* (subpath "/opt/homebrew")) +(allow file-read* (subpath "/private/etc")) +(allow file-read* (subpath "/dev")) +(allow file-read* (subpath "/Users/ibrahimyildiz/Library/Application Support/Contributor/runs/2026-10-29/pmxt-dev-pmxt-2423/repo/sdks/typescript")) +(allow file-read* (literal "/var/select/developer_dir")) +(allow file-read* (literal "/private/var/select/developer_dir")) +(allow file-read* (literal "/etc/protocols")) +(allow file-read* (literal "/etc/services")) +(allow file-read* (literal "/etc/resolv.conf")) +(allow file-write* (subpath "/Users/ibrahimyildiz/Library/Application Support/Contributor/runs/2026-10-29/pmxt-dev-pmxt-2423/repo/sdks/typescript")) +(allow file-read* file-write* (literal "/dev/null")) +(allow file-read* file-write* (literal "/dev/urandom")) +(allow network*) diff --git a/sdks/typescript/tests/hosted-mappers.test.ts b/sdks/typescript/tests/hosted-mappers.test.ts new file mode 100644 index 00000000..174cc7e5 --- /dev/null +++ b/sdks/typescript/tests/hosted-mappers.test.ts @@ -0,0 +1,32 @@ +/** + * Tests for `positionFromV0` — hosted `PositionV0` JSON → SDK `Position`. + * + * Verifies the mapper carries every field the hosted payload supplies, + * including mark-to-market data, and never fabricates missing values. + */ + +import { positionFromV0 } from "../pmxt/hosted-mappers"; + +describe("positionFromV0", () => { + it("maps current_value from the hosted payload to currentValue", () => { + const position = positionFromV0({ + market_id: "mkt-1", + outcome_id: "out-yes", + shares: 25, + entry_price: 0.4, + current_price: 0.55, + current_value: 13.75, + unrealized_pnl: 3.75, + realized_pnl: 0, + }); + + expect(position.marketId).toBe("mkt-1"); + expect(position.outcomeId).toBe("out-yes"); + expect(position.size).toBe(25); + expect(position.entryPrice).toBe(0.4); + expect(position.currentPrice).toBe(0.55); + expect(position.currentValue).toBe(13.75); + expect(position.unrealizedPnL).toBe(3.75); + expect(position.realizedPnL).toBe(0); + }); +}); From 0d15adac506d7ff52d81ecdbf1bab02d061a1c75 Mon Sep 17 00:00:00 2001 From: ibrahim Date: Sat, 31 Oct 2026 14:57:40 +0000 Subject: [PATCH 2/5] test(ts-sdk): currentValue stays undefined when the payload omits it --- sdks/typescript/tests/hosted-mappers.test.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/sdks/typescript/tests/hosted-mappers.test.ts b/sdks/typescript/tests/hosted-mappers.test.ts index 174cc7e5..732dfdbc 100644 --- a/sdks/typescript/tests/hosted-mappers.test.ts +++ b/sdks/typescript/tests/hosted-mappers.test.ts @@ -29,4 +29,14 @@ describe("positionFromV0", () => { expect(position.unrealizedPnL).toBe(3.75); expect(position.realizedPnL).toBe(0); }); + it("leaves currentValue undefined when the hosted payload omits it", () => { + const position = positionFromV0({ + market_id: "mkt-2", + outcome_id: "out-no", + shares: 10, + current_price: 0.3, + }); + + expect(position.currentValue).toBeUndefined(); + }); }); From 216ee490ebe3e0b4f084bf017714b1535e639cda Mon Sep 17 00:00:00 2001 From: ibrahim Date: Sat, 31 Oct 2026 14:58:00 +0000 Subject: [PATCH 3/5] test(ts-sdk): camelCase currentValue payloads map as well --- sdks/typescript/tests/hosted-mappers.test.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/sdks/typescript/tests/hosted-mappers.test.ts b/sdks/typescript/tests/hosted-mappers.test.ts index 732dfdbc..735f23f7 100644 --- a/sdks/typescript/tests/hosted-mappers.test.ts +++ b/sdks/typescript/tests/hosted-mappers.test.ts @@ -29,6 +29,7 @@ describe("positionFromV0", () => { expect(position.unrealizedPnL).toBe(3.75); expect(position.realizedPnL).toBe(0); }); + it("leaves currentValue undefined when the hosted payload omits it", () => { const position = positionFromV0({ market_id: "mkt-2", @@ -39,4 +40,15 @@ describe("positionFromV0", () => { expect(position.currentValue).toBeUndefined(); }); + + it("maps camelCase currentValue payloads as well", () => { + const position = positionFromV0({ + marketId: "mkt-3", + outcomeId: "out-yes", + size: 4, + currentValue: 2, + }); + + expect(position.currentValue).toBe(2); + }); }); From a00bb7eaf19c7feb4ebe84c007df97cf9bcf9f51 Mon Sep 17 00:00:00 2001 From: ibrahim Date: Sat, 31 Oct 2026 14:58:18 +0000 Subject: [PATCH 4/5] feat(ts-sdk): add currentValue to the Position model --- sdks/typescript/pmxt/models.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sdks/typescript/pmxt/models.ts b/sdks/typescript/pmxt/models.ts index 5db743cb..348f4cf4 100644 --- a/sdks/typescript/pmxt/models.ts +++ b/sdks/typescript/pmxt/models.ts @@ -372,6 +372,9 @@ export interface Position { /** Current market price (populated in venue-direct mode; may be undefined in hosted mode when the server hasn't enriched). */ currentPrice?: number | null; + /** Current market value of the position (size * currentPrice). Populated in hosted mode when the server supplies mark-to-market data; may be undefined in hosted mode when the server hasn't enriched. */ + currentValue?: number | null; + /** Unrealized profit/loss (populated in venue-direct mode; may be undefined in hosted mode when the server hasn't enriched). */ unrealizedPnL?: number | null; From 56b4ed279821e89d8fb077484177099007994db3 Mon Sep 17 00:00:00 2001 From: ibrahim Date: Sat, 31 Oct 2026 14:58:18 +0000 Subject: [PATCH 5/5] fix(ts-sdk): positionFromV0 maps current_value/currentValue --- sdks/typescript/pmxt/hosted-mappers.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sdks/typescript/pmxt/hosted-mappers.ts b/sdks/typescript/pmxt/hosted-mappers.ts index ac6719c9..96d810a0 100644 --- a/sdks/typescript/pmxt/hosted-mappers.ts +++ b/sdks/typescript/pmxt/hosted-mappers.ts @@ -153,7 +153,7 @@ export function userTradeToV0(trade: UserTrade): Record { * Map a `PositionV0` JSON object to {@link Position}. * * Optional fields (`outcomeLabel`, `entryPrice`, `currentPrice`, - * `unrealizedPnL`, `realizedPnL`) surface as `undefined` when missing — + * `currentValue`, `unrealizedPnL`, `realizedPnL`) surface as `undefined` when missing — * **never** a fake `0` or `""`. This keeps the SDK honest about which data * the server actually provided. */ @@ -191,6 +191,9 @@ export function positionFromV0(payload: Record): Position { size, entryPrice: entryPrice as number | undefined, currentPrice: currentPrice as number | undefined, + currentValue: floatOrUndefined( + payload["current_value"] ?? payload["currentValue"], + ), unrealizedPnL: unrealizedPnL as number | undefined, realizedPnL: floatOrUndefined( payload["realized_pnl"] ?? payload["realizedPnl"] ?? payload["realizedPnL"],