ts client: Fix avg entry price and break even price
This commit is contained in:
parent
55e8fc390f
commit
7231ceea53
|
@ -6,7 +6,7 @@ import { MangoClient } from '../client';
|
|||
import { OPENBOOK_PROGRAM_ID } from '../constants';
|
||||
import { I80F48, I80F48Dto, ONE_I80F48, ZERO_I80F48 } from '../numbers/I80F48';
|
||||
import { toNativeI80F48, toUiDecimals, toUiDecimalsForQuote } from '../utils';
|
||||
import { Bank, TokenIndex } from './bank';
|
||||
import { Bank, QUOTE_DECIMALS, TokenIndex } from './bank';
|
||||
import { Group } from './group';
|
||||
import { HealthCache } from './healthCache';
|
||||
import { PerpMarket, PerpMarketIndex, PerpOrder, PerpOrderSide } from './perp';
|
||||
|
@ -1278,8 +1278,8 @@ export class PerpPosition {
|
|||
}
|
||||
|
||||
public getAverageEntryPriceUi(perpMarket: PerpMarket): number {
|
||||
return perpMarket.priceLotsToUi(
|
||||
new BN(this.avgEntryPricePerBaseLot / perpMarket.baseLotSize.toNumber()),
|
||||
return perpMarket.priceNativeToUi(
|
||||
this.avgEntryPricePerBaseLot / perpMarket.baseLotSize.toNumber(),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -1287,13 +1287,9 @@ export class PerpPosition {
|
|||
if (this.basePositionLots.eq(new BN(0))) {
|
||||
return 0;
|
||||
}
|
||||
return perpMarket.priceLotsToUi(
|
||||
new BN(
|
||||
this.quoteRunningNative
|
||||
.neg()
|
||||
.div(this.basePositionLots.mul(perpMarket.baseLotSize))
|
||||
.toNumber(),
|
||||
),
|
||||
return perpMarket.priceNativeToUi(
|
||||
-this.quoteRunningNative.toNumber() /
|
||||
this.basePositionLots.mul(perpMarket.baseLotSize).toNumber(),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ import Big from 'big.js';
|
|||
import { MangoClient } from '../client';
|
||||
import { I80F48, I80F48Dto, ZERO_I80F48 } from '../numbers/I80F48';
|
||||
import { Modify } from '../types';
|
||||
import { As, toNative, U64_MAX_BN } from '../utils';
|
||||
import { As, toNative, toUiDecimals, U64_MAX_BN } from '../utils';
|
||||
import {
|
||||
OracleConfig,
|
||||
OracleConfigDto,
|
||||
|
@ -370,6 +370,10 @@ export class PerpMarket {
|
|||
return parseFloat(price.toString()) * this.priceLotsToUiConverter;
|
||||
}
|
||||
|
||||
public priceNativeToUi(price: number): number {
|
||||
return toUiDecimals(price, QUOTE_DECIMALS - this.baseDecimals);
|
||||
}
|
||||
|
||||
public baseLotsToUi(quantity: BN): number {
|
||||
return parseFloat(quantity.toString()) * this.baseLotsToUiConverter;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue