> ## Documentation Index
> Fetch the complete documentation index at: https://staging-docs.orderly.network/llms.txt
> Use this file to discover all available pages before exploring further.

# usePositionStream

> Hook to stream position data with calculated values for margin, liquidation price, and unrealized PnL.

* [Tech docs](/sdks/tech-doc/modules/orderly_network_hooks#usepositionstream)

`usePositionStream` provides the current position details of the account, and includes some useful data calculations for showing positions, including:

* Position value
* Position liquidation price
* Position margin
* Unrealized PnL
* Unsettled PnL
* Aggregated position data

<Note>
  If you do not want to use the data provided by `usePositionStream`, you may use the
  `@orderly.network/perp package`. This package implements all position related calculations. See
  [reference](/sdks/perp/overview).
</Note>

## Position list

`usePositionStream` returns an array, with the first item of the arry as follows:

```typescript theme={null}
interface Position {
  rows: positionsRows;
  aggregated: Record<string, any>;
  totalCollateral: number;
  totalValue: number;
  totalUnrealizedROI: number;
}
```

### Position

### Aggregated position data

Usually, the UI will display some aggregated position data, for instance the total position value, total collateral, and the total unrealized ROI. These data are all provided by `usePositionStream`.

```typescript theme={null}
interface Aggregated {
  unrealPnL: number;
  notional: number;
  unsettledPnL: number;
}
```

### Position info

The data returned by [Orderly positions API](/build-on-omnichain/restful-api/private/get-all-positions-info) also includes the following Position info. One can retrieve these data through the second element of the `usePositionStream` array response:

```typescript theme={null}
interface PositionInfo {
  margin_ratio: number;
  initial_margin_ratio: number;
  maintenance_margin_ratio: number;
  open_margin_ratio: number;
  current_margin_ratio_with_orders: number;
  initial_margin_ratio_with_orders: number;
  maintenance_margin_ratio_with_orders: number;
  total_collateral_value: number;
  free_collateral: number;
  rows: Position[];
  total_pnl_24_h: number;
}
```

## Position management

### Close position

To close a position, just place a reduce-only order with the opposite position of the open position. For example, if the open position is a long, close the position by placing a SELL order of the same size.

Positions can be closed by using `useOrderEntry`. For more details, please see [orders](/sdks/hooks/orders)
/orders)
