add getCumulativeFundingUi

This commit is contained in:
Lou-Kamades 2023-11-05 15:13:23 +01:00
parent 2b4101d978
commit b39412d3a2
No known key found for this signature in database
GPG Key ID: 87A166E4D7C01F30
1 changed files with 18 additions and 0 deletions

View File

@ -1475,6 +1475,24 @@ export class PerpPosition {
};
}
/**
* @returns perp position cumulative funding.
* If the user paid $1 in funding for a short position, this would be -1e6.
* Caveat: This will only return cumulative interest since the perp position was last opened.
*/
public getCumulativeFundingUi(perpMarket: PerpMarket): number {
if (perpMarket.perpMarketIndex !== this.marketIndex) {
throw new Error("PerpPosition doesn't belong to the given market!");
}
const cumulativeFunding = this.getCumulativeFunding(perpMarket);
// can't be long and short at the same time
if (cumulativeFunding.cumulativeLongFunding !== 0) {
return -1 * toUiDecimalsForQuote(cumulativeFunding.cumulativeLongFunding);
} else {
return toUiDecimalsForQuote(cumulativeFunding.cumulativeShortFunding);
}
}
public getEquity(perpMarket: PerpMarket): I80F48 {
if (perpMarket.perpMarketIndex !== this.marketIndex) {
throw new Error("PerpPosition doesn't belong to the given market!");