Skip to content

Commit

Permalink
return default as often as possible
Browse files Browse the repository at this point in the history
  • Loading branch information
moo-onthelawn committed Aug 21, 2024
1 parent 4d94186 commit 42ae94d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1688,8 +1688,6 @@ internal class TradeInputCalculator(
"openPositions.$marketId",
),
)
val equity = parser.asDouble(parser.value(subaccount, "equity.current")) ?: return null
val freeCollateral = parser.asDouble(parser.value(subaccount, "freeCollateral.current")) ?: return null

val initialMarginFraction =
parser.asDouble(parser.value(market, "configs.effectiveInitialMarginFraction"))
Expand All @@ -1699,9 +1697,12 @@ internal class TradeInputCalculator(
} else {
Numeric.double.ONE / initialMarginFraction
}

val equity = parser.asDouble(parser.value(subaccount, "equity.current"))
val freeCollateral = parser.asDouble(parser.value(subaccount, "freeCollateral.current")) ?: Numeric.double.ZERO
val positionNotionalTotal = parser.asDouble(parser.value(position, "notionalTotal.current")) ?: Numeric.double.ZERO

return if (equity > Numeric.double.ZERO) {
return if (equity != null && equity > Numeric.double.ZERO) {
(freeCollateral + positionNotionalTotal / maxMarketLeverage) * maxMarketLeverage / equity
} else {
maxMarketLeverage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,6 @@ internal class TradeInputOptionsCalculator(
return null
}

val equity = subaccount.calculated[CalculationPeriod.current]?.equity ?: return null
val freeCollateral = subaccount.calculated[CalculationPeriod.current]?.freeCollateral ?: return null
val initialMarginFraction =
market.perpetualMarket?.configs?.effectiveInitialMarginFraction ?: return null

Expand All @@ -362,9 +360,12 @@ internal class TradeInputOptionsCalculator(
} else {
Numeric.double.ONE / initialMarginFraction
}

val equity = subaccount.calculated[CalculationPeriod.current]?.equity
val freeCollateral = subaccount.calculated[CalculationPeriod.current]?.freeCollateral ?: Numeric.double.ZERO
val positionNotionalTotal = position?.calculated?.get(CalculationPeriod.current)?.notionalTotal ?: Numeric.double.ZERO

return if (equity > Numeric.double.ZERO) {
return if (equity != null && equity > Numeric.double.ZERO) {
(freeCollateral + positionNotionalTotal / maxMarketLeverage) * maxMarketLeverage / equity
} else {
maxMarketLeverage
Expand Down

0 comments on commit 42ae94d

Please sign in to comment.