usePositionStream
provides the current position details of the account, and includes some useful data calculations for showing positions, including:
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.
usePositionStream
returns an array, with the first item of the arry as follows:
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
.
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:
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