Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.ostium.com/llms.txt

Use this file to discover all available pages before exploring further.

streamPositionUpdates(initial, priceStream?) takes a previously fetched getOpenPositions() response and emits an updated payload whenever relevant prices change.

Example

const positions = await client.getOpenPositions({ user: '0xTraderAddress' });
const stream = client.streamPositionUpdates(positions);

stream.onUpdate(next => {
  console.log(next.marginSummary.totalRawPnlUsd);
  console.log(next.pairPositions[0]?.position.unrealizedPnl);
});

stream.onError(err => console.error(err));

How it works

  • the SDK extracts the unique pairId values from initial.pairPositions
  • it subscribes only to those pairs
  • on each price tick, it recalculates price-sensitive fields and emits the full updated OpenPositionsResponse

Reusing an existing price stream

If your app already owns a price WebSocket, pass it as the second argument to avoid opening another connection:
const priceStream = client.streamPrices([0, 1]);
const positions = await client.getOpenPositions({ user: '0xTraderAddress' });
const stream = client.streamPositionUpdates(positions, priceStream);