Skip to content

Commit

Permalink
update v2
Browse files Browse the repository at this point in the history
  • Loading branch information
aforaleka committed Aug 19, 2024
1 parent 2aa0087 commit 8b1c56c
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import exchange.dydx.abacus.state.internalstate.InternalSubaccountCalculated
import exchange.dydx.abacus.state.internalstate.InternalSubaccountState
import exchange.dydx.abacus.utils.Numeric
import indexer.codegen.IndexerPerpetualPositionStatus
import kotlin.math.max

internal class SubaccountCalculatorV2(
val parser: ParserProtocol
Expand Down Expand Up @@ -395,13 +396,15 @@ internal class SubaccountCalculatorV2(
calculated.maxLeverage = maxLeverage

if (entryPrice != null) {
val leverage = position.calculated[period]?.leverage
val scaledLeverage = max(leverage?.abs() ?: 1.0, 1.0)
val entryValue = size * entryPrice
val currentValue = size * oraclePrice
val unrealizedPnl = currentValue - entryValue
val unrealizedPnlPercent =
if (entryValue != Numeric.double.ZERO) unrealizedPnl / entryValue.abs() else null
val scaledUnrealizedPnlPercent =
if (entryValue != Numeric.double.ZERO) unrealizedPnl / entryValue.abs() * scaledLeverage else null
calculated.unrealizedPnl = unrealizedPnl
calculated.unrealizedPnlPercent = unrealizedPnlPercent
calculated.unrealizedPnlPercent = scaledUnrealizedPnlPercent
}

val marginMode = position.marginMode
Expand Down

0 comments on commit 8b1c56c

Please sign in to comment.