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 of IPositionCapInfo objects, typically obtained from getPositionCapInfoList.

  • 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 openTimestamp in ascending order.

  • For open positions, the function calculates reservingFeeAmount and fundingFeeValue using separate API calls.

  • If there's an error calculating reservingFeeAmount or fundingFeeValue, these values are set to 0 and the error is logged.

Last updated