Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions sdks/typescript/.sandbox.sb
Original file line number Diff line number Diff line change
@@ -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*)
5 changes: 4 additions & 1 deletion sdks/typescript/pmxt/hosted-mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export function userTradeToV0(trade: UserTrade): Record<string, unknown> {
* 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.
*/
Expand Down Expand Up @@ -191,6 +191,9 @@ export function positionFromV0(payload: Record<string, unknown>): 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"],
Expand Down
3 changes: 3 additions & 0 deletions sdks/typescript/pmxt/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
54 changes: 54 additions & 0 deletions sdks/typescript/tests/hosted-mappers.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});