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
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.
Position list
usePositionStream
returns an array, with the first item of the arry as follows:
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
.
Position info
The data returned by Orderly positions API also includes the following Position info. One can retrieve these data through the second element of the usePositionStream
array response:
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