show empty field if unrealized pnl cant be calculated

This commit is contained in:
tjs 2022-09-06 14:13:17 -04:00
parent 41450faf55
commit e13426f091
1 changed files with 8 additions and 7 deletions

View File

@ -36,8 +36,14 @@ export const collectPerpPosition = (
const perpMarketInfo = mangoGroup.perpMarkets[marketConfig.marketIndex]
const perpAccount = mangoAccount.perpAccounts[marketConfig.marketIndex]
const basePosition = perpMarket?.baseLotsToNumber(perpAccount.basePosition)
const indexPrice = mangoGroup
.getPrice(marketConfig.marketIndex, mangoCache)
.toNumber()
const notionalSize = Math.abs(basePosition * indexPrice)
let avgEntryPrice = 0,
let unrealizedPnl,
avgEntryPrice = 0,
breakEvenPrice = 0
const perpTradeHistory = tradeHistory.filter(
(t) => t.marketName === marketConfig.name
@ -54,16 +60,11 @@ export const collectPerpPosition = (
breakEvenPrice = perpAccount
.getBreakEvenPrice(mangoAccount, perpMarket, perpTradeHistory)
.toNumber()
unrealizedPnl = basePosition * (indexPrice - breakEvenPrice)
} catch (e) {
console.error(marketConfig.name, e)
}
const basePosition = perpMarket?.baseLotsToNumber(perpAccount.basePosition)
const indexPrice = mangoGroup
.getPrice(marketConfig.marketIndex, mangoCache)
.toNumber()
const notionalSize = Math.abs(basePosition * indexPrice)
const unrealizedPnl = basePosition * (indexPrice - breakEvenPrice)
const unsettledPnl = +nativeI80F48ToUi(
perpAccount.getPnl(
perpMarketInfo,