-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: update default target leverage on isolated market orders to be max market leverage #613
Conversation
@@ -78,7 +78,6 @@ internal class TradeInputCalculator( | |||
val subaccount = if (marginMode == MarginMode.Cross) { | |||
crossMarginSubaccount | |||
} else { | |||
// TODO: incorrect for isolated trades; fix CT-1092 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not actually incorrect, sorry poorly placed TODO which was just to remind me to properly calculate maxLeverage for isolated which we no longer need
@@ -19,6 +20,16 @@ internal class TradeInputMarginModeCalculator { | |||
marketId = tradeInput.marketId, | |||
subaccountNumber = subaccountNumber, | |||
) | |||
val market = markets?.get(tradeInput.marketId) | |||
val imf = market?.perpetualMarket?.configs?.initialMarginFraction ?: Numeric.double.ZERO |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Since this logic is used elsewhere, we can make it a computed property of MarketConfigs
... Something like this:
data class MarketConfigs(...) {
....
internal val maxMarketLeverage: Double
get() {
val imf = initialMarginFraction ?: Numeric.double.ZERO
val effectiveImf = effectiveInitialMarginFraction ?: Numeric.double.ZERO
return if (effectiveImf > Numeric.double.ZERO) {
Numeric.double.ONE / effectiveImf
} else if (imf > Numeric.double.ZERO) {
Numeric.double.ONE / imf
} else {
Numeric.double.ONE
}
}
}
val maxMarketLeverage = if (effectiveImf > Numeric.double.ZERO) { | ||
Numeric.double.ONE / effectiveImf | ||
} else if (imf > Numeric.double.ZERO) { | ||
Numeric.double.ONE / imf | ||
} else { | ||
Numeric.double.ONE | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the calculation for maxMarketLeverage
is duplicated in quite a few places. Would it be easier to have a pure function in marketCalculator
or something similar and just use in each of these cases?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to what Rui said, if it can be included in the actual configs struct it would be easy to de-dupe this calculation
…-to-max-market-lev-instead-of
…-to-max-market-lev-instead-of
…-to-max-market-lev-instead-of
closed due to unsigned commit from mobile bot #631 |
instead of defaulting to 1 as target leverage, default to max market lev
still respects existing position leverage, if it exists
Screen.Recording.2024-08-31.at.2.50.57.AM.mov