This version (v0.7) has not been published to npm yet.
Skip to content

Portfolio ​

The portfolio namespace of @getenginex/sdk-predictions shows the player's positions and summary. All methods require login: without a session, they reject with UNAUTHENTICATED before any request. Monetary values are in minor units (cents).

Positions ​

ts
const positions = await predictions.portfolio.listPositions()
// [{ id, marketId, side: 'yes', quantity: 4, avgPrice: 60, unrealizedPnl: 8, status: 'open', ... }]

Returns an array (not a Page): the gateway ignores pagination and always returns the first page of 100. Each Position carries the side (side), quantity, avgPrice, totalCost, realizedPnl, unrealizedPnl, currentValue, currentPrice, status (open, closed or settled), the market and event data (marketStatus, eventId, eventStatus) and, when present, settledAt, marketResolution and trades (the executions that make up the position).

Position in a market ​

ts
const { yesQuantity, noQuantity, yesAvgPrice, noAvgPrice } = await predictions.portfolio.getPosition({
  marketId: 'mkt-1',
})

Sums the player's position per side. Having no position is not an error: the four numbers come back 0. The gateway sums only the first page of 10 positions in the market. A marketId that is empty, has leading or trailing whitespace, or contains /, . or .. rejects with CONFIGURATION_ERROR before the request.

Summary ​

ts
const { totalInvested, totalValue, totalUnrealizedPnl, pendingCollateral, openPositions, openOrders } =
  await predictions.portfolio.get()

Returns the totals (totalInvested, totalValue, totalRealizedPnl, totalUnrealizedPnl), the collateral locked in open orders (pendingCollateral), the counts (openPositionsCount, openOrdersCount, settledPositionsCount) and the openPositions and openOrders lists. For orders that just changed (for example, after orders.place), query again: it is a snapshot of the moment.

Testing ​

In the mock (withPredictionsRoutes()), the portfolio starts empty and follows the orders: an open limit order shows up in openOrders and in pendingCollateral; a market order becomes a position (listPositions, getPosition and get agree) and canceling an order releases the collateral. The routes answer 401 without a token.