getPositionInfoList
The getPositionInfoList function retrieves detailed information about positions based on a list of position cap information.
Function Signature
getPositionInfoList(
positionCapInfoList: IPositionCapInfo[],
owner: string
): Promise<IPositionInfo[]>Parameters
positionCapInfoList: An array ofIPositionCapInfoobjects, typically obtained fromgetPositionCapInfoList.owner: A string representing the owner's address.
Return Value
Returns a Promise that resolves to an array of IPositionInfo objects. Each IPositionInfo object contains detailed information about a position, including:
interface IPositionInfo {
id: string;
long: boolean;
owner: string;
version: number;
collateralToken: string;
indexToken: string;
collateralAmount: number;
positionAmount: number;
reservedAmount: number;
positionSize: number;
lastFundingRate: number;
lastReservingRate: number;
reservingFeeAmount: number;
fundingFeeValue: number;
closed: boolean;
openTimestamp: number;
protocol?: string;
}Description
This function takes a list of position cap information and fetches detailed data for each position. It calculates additional information such as reserving fee amount and funding fee value for open positions.
Usage Example
const owner = "0x1234..."; // Replace with actual owner address
const sudoAPI = new SudoAPI(provider);
try {
const positionCaps = await sudoAPI.getPositionCapInfoList(owner);
const positionInfoList = await sudoAPI.getPositionInfoList(positionCaps, owner);
console.log("Position Info List:", positionInfoList);
} catch (error) {
console.error("Error fetching position information:", error);
}Notes
The function sorts the returned positions by
openTimestampin ascending order.For open positions, the function calculates
reservingFeeAmountandfundingFeeValueusing separate API calls.If there's an error calculating
reservingFeeAmountorfundingFeeValue, these values are set to 0 and the error is logged.
Last updated