From b2dc01634b834e5765028e026a52ce6ec12ccb99 Mon Sep 17 00:00:00 2001 From: John Huang Date: Fri, 31 May 2024 11:40:11 -0700 Subject: [PATCH] TRA-329 Added position leverage and position margin to receipt lines (#403) Co-authored-by: mobile-build-bot-git Co-authored-by: Rui <102453770+ruixhuang@users.noreply.github.com> Co-authored-by: Jared Vu --- .../state/model/TradingStateMachine.kt | 48 ++++++++++++++----- .../payload/v4/V4ParentSubaccountTests.kt | 17 ++++++- 2 files changed, 50 insertions(+), 15 deletions(-) diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/state/model/TradingStateMachine.kt b/src/commonMain/kotlin/exchange.dydx.abacus/state/model/TradingStateMachine.kt index 25c710599..c08d384fa 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/state/model/TradingStateMachine.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/state/model/TradingStateMachine.kt @@ -912,24 +912,46 @@ open class TradingStateMachine( "trade" -> { val trade = parser.asNativeMap(input["trade"]) ?: return null val type = parser.asString(trade["type"]) ?: return null + val isolatedMargin = parser.asString(trade["marginMode"]) == "ISOLATED" return when (type) { "MARKET", "STOP_MARKET", "TAKE_PROFIT_MARKET", "TRAILING_STOP" -> { - listOf( - ReceiptLine.BuyingPower.rawValue, - ReceiptLine.MarginUsage.rawValue, - ReceiptLine.ExpectedPrice.rawValue, - ReceiptLine.Fee.rawValue, - ReceiptLine.Reward.rawValue, - ) + if (isolatedMargin) { + listOf( + ReceiptLine.ExpectedPrice.rawValue, + ReceiptLine.LiquidationPrice.rawValue, + ReceiptLine.PositionMargin.rawValue, + ReceiptLine.PositionLeverage.rawValue, + ReceiptLine.Fee.rawValue, + ReceiptLine.Reward.rawValue, + ) + } else { + listOf( + ReceiptLine.BuyingPower.rawValue, + ReceiptLine.MarginUsage.rawValue, + ReceiptLine.ExpectedPrice.rawValue, + ReceiptLine.Fee.rawValue, + ReceiptLine.Reward.rawValue, + ) + } } else -> { - listOf( - ReceiptLine.BuyingPower.rawValue, - ReceiptLine.MarginUsage.rawValue, - ReceiptLine.Fee.rawValue, - ReceiptLine.Reward.rawValue, - ) + if (isolatedMargin) { + listOf( + ReceiptLine.LiquidationPrice.rawValue, + ReceiptLine.PositionMargin.rawValue, + ReceiptLine.PositionLeverage.rawValue, + ReceiptLine.Fee.rawValue, + ReceiptLine.Reward.rawValue, + ) + } else { + listOf( + ReceiptLine.BuyingPower.rawValue, + ReceiptLine.MarginUsage.rawValue, + ReceiptLine.Fee.rawValue, + ReceiptLine.Reward.rawValue, + ) + } } } } diff --git a/src/commonTest/kotlin/exchange.dydx.abacus/payload/v4/V4ParentSubaccountTests.kt b/src/commonTest/kotlin/exchange.dydx.abacus/payload/v4/V4ParentSubaccountTests.kt index 05ae61fe7..0f29a6531 100644 --- a/src/commonTest/kotlin/exchange.dydx.abacus/payload/v4/V4ParentSubaccountTests.kt +++ b/src/commonTest/kotlin/exchange.dydx.abacus/payload/v4/V4ParentSubaccountTests.kt @@ -284,7 +284,14 @@ class V4ParentSubaccountTests : V4BaseTests(true) { "options": { "needsMarginMode": false } - } + }, + "receiptLines": [ + "LIQUIDATION_PRICE", + "POSITION_MARGIN", + "POSITION_LEVERAGE", + "FEE", + "REWARD" + ] } } """.trimIndent(), @@ -303,7 +310,13 @@ class V4ParentSubaccountTests : V4BaseTests(true) { "options": { "needsMarginMode": false } - } + }, + "receiptLines": [ + "BUYING_POWER", + "MARGIN_USAGE", + "FEE", + "REWARD" + ] } } """.trimIndent(),