> ## 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

> Subscribe to live price-driven changes for an existing open positions payload.

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

## Example

```ts theme={null}
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:

```ts theme={null}
const priceStream = client.streamPrices([0, 1]);
const positions = await client.getOpenPositions({ user: '0xTraderAddress' });
const stream = client.streamPositionUpdates(positions, priceStream);
```

## Response schema

```ts theme={null}
interface OstiumPositionUpdatesStream {
  onUpdate(handler: (positions: OpenPositionsResponse) => void): () => void;
  onOpen(handler: () => void): this;
  onError(handler: (event: Error) => void): this;
  onClose(handler: (code: number, reason: string) => void): this;
  getCurrent(): OpenPositionsResponse;
  ingestTick(tick: PriceTick): void;
  ingestSnapshot(ticks: PriceTick[]): void;
  close(): void;
}
```
