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

View File

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