diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/processor/input/TradeInputProcessor.kt b/src/commonMain/kotlin/exchange.dydx.abacus/processor/input/TradeInputProcessor.kt index 7e42408ac..add2f7140 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/processor/input/TradeInputProcessor.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/processor/input/TradeInputProcessor.kt @@ -258,6 +258,15 @@ internal class TradeInputProcessor( TradeInputField.marginMode -> { inputType.updateValueAction?.invoke(trade, inputData, parser) + + // when moving from cross to isolated, update targetLeverage so it isn't sitting at null + if (trade.marginMode === MarginMode.Isolated) { + val market = marketSummaryState.markets[trade.marketId] + val maxMarketLeverage = market?.perpetualMarket?.configs?.maxMarketLeverage + ?: Numeric.double.ONE + trade.targetLeverage = maxMarketLeverage + } + val changedSubaccountNumbers = MarginCalculator.getChangedSubaccountNumbers( parser = parser,