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/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"], 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; diff --git a/sdks/typescript/tests/hosted-mappers.test.ts b/sdks/typescript/tests/hosted-mappers.test.ts new file mode 100644 index 00000000..735f23f7 --- /dev/null +++ b/sdks/typescript/tests/hosted-mappers.test.ts @@ -0,0 +1,54 @@ +/** + * 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); + }); + + 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(); + }); + + 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); + }); +});