perp position pnl using breakeven price

This commit is contained in:
Tyler Shipe 2021-08-30 02:33:41 -04:00
parent bc447a5296
commit 9c3c0677bd
2 changed files with 39 additions and 30 deletions

View File

@ -88,37 +88,37 @@ const BalancesTable = () => {
<Tr className="text-th-fgd-3 text-xs">
<Th
scope="col"
className={`px-6 py-3 text-left font-normal`}
className={`px-6 py-2 text-left font-normal`}
>
Asset
</Th>
<Th
scope="col"
className={`px-6 py-3 text-left font-normal`}
className={`px-6 py-2 text-left font-normal`}
>
Deposits
</Th>
<Th
scope="col"
className={`px-6 py-3 text-left font-normal`}
className={`px-6 py-2 text-left font-normal`}
>
Borrows
</Th>
<Th
scope="col"
className={`px-6 py-3 text-left font-normal`}
className={`px-6 py-2 text-left font-normal`}
>
In Orders
</Th>
<Th
scope="col"
className={`px-6 py-3 text-left font-normal`}
className={`px-6 py-2 text-left font-normal`}
>
Unsettled
</Th>
<Th
scope="col"
className={`px-6 py-3 text-left font-normal`}
className={`px-6 py-2 text-left font-normal`}
>
Net
</Th>
@ -134,7 +134,7 @@ const BalancesTable = () => {
`}
>
<Td
className={`flex items-center px-6 py-3 whitespace-nowrap text-sm text-th-fgd-1`}
className={`flex items-center px-6 py-3.5 whitespace-nowrap text-sm text-th-fgd-1`}
>
<img
alt=""
@ -147,27 +147,27 @@ const BalancesTable = () => {
{balance.symbol}
</Td>
<Td
className={`px-6 py-3 whitespace-nowrap text-sm text-th-fgd-1`}
className={`px-6 py-3.5 whitespace-nowrap text-sm text-th-fgd-1`}
>
{balance.deposits.toFixed()}
</Td>
<Td
className={`px-6 py-3 whitespace-nowrap text-sm text-th-fgd-1`}
className={`px-6 py-3.5 whitespace-nowrap text-sm text-th-fgd-1`}
>
{balance.borrows.toFixed()}
</Td>
<Td
className={`px-6 py-3 whitespace-nowrap text-sm text-th-fgd-1`}
className={`px-6 py-3.5 whitespace-nowrap text-sm text-th-fgd-1`}
>
{balance.orders}
</Td>
<Td
className={`px-6 py-3 whitespace-nowrap text-sm text-th-fgd-1`}
className={`px-6 py-3.5 whitespace-nowrap text-sm text-th-fgd-1`}
>
{balance.unsettled}
</Td>
<Td
className={`px-6 py-3 whitespace-nowrap text-sm text-th-fgd-1`}
className={`px-6 py-3.5 whitespace-nowrap text-sm text-th-fgd-1`}
>
{balance.net.toFixed()}
</Td>

View File

@ -124,23 +124,27 @@ const PositionsTable = () => {
const perpTradeHistory = tradeHistory.filter(
(t) => t.marketName === marketConfig.name
)
const breakEvenPrice = getBreakEvenPrice(
let breakEvenPrice
try {
breakEvenPrice = perpAccount.getBreakEvenPrice(
mangoAccount,
perpAccount,
perpMarket,
perpTradeHistory
)
} catch (e) {
breakEvenPrice = null
}
const pnl =
perpMarket.baseLotsToNumber(perpAccount.basePosition) *
(mangoGroup.getPrice(marketIndex, mangoCache).toNumber() -
parseFloat(
perpAccount.getBreakEvenPrice(
mangoAccount,
perpMarket,
perpTradeHistory
)
))
breakEvenPrice !== null
? perpMarket.baseLotsToNumber(
perpAccount.basePosition
) *
(mangoGroup
.getPrice(marketIndex, mangoCache)
.toNumber() -
parseFloat(breakEvenPrice))
: null
return (
<Tr
@ -227,14 +231,19 @@ const PositionsTable = () => {
)}
</Td>
<Td className="px-2 py-2 whitespace-nowrap text-sm text-th-fgd-1">
{breakEvenPrice}
{getBreakEvenPrice(
mangoAccount,
perpAccount,
perpMarket,
perpTradeHistory
)}
</Td>
<Td
className={`px-2 py-2 whitespace-nowrap text-sm text-th-fgd-1 ${
pnl > 0 ? 'text-th-green' : 'text-th-red'
pnl >= 0 ? 'text-th-green' : 'text-th-red'
}`}
>
{usdFormatter(pnl)}
{pnl !== null ? usdFormatter(pnl) : '--'}
</Td>
{showMarketCloseModal ? (
<MarketCloseModal