Skip to content
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

moo-onthelawn
Copy link
Contributor

@moo-onthelawn moo-onthelawn commented Aug 30, 2024

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

Copy link

linear bot commented Aug 30, 2024

@@ -78,7 +78,6 @@ internal class TradeInputCalculator(
val subaccount = if (marginMode == MarginMode.Cross) {
crossMarginSubaccount
} else {
// TODO: incorrect for isolated trades; fix CT-1092
Copy link
Contributor Author

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
Copy link
Contributor

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
            }
        }
}

ruixhuang
ruixhuang previously approved these changes Aug 31, 2024
Comment on lines +23 to +29
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
}
Copy link
Contributor

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?

Copy link
Contributor

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

@moo-onthelawn
Copy link
Contributor Author

closed due to unsigned commit from mobile bot #631

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants