From 02f64690ca340c6cc13f9cb9dfa938b59a475817 Mon Sep 17 00:00:00 2001 From: mike-dydx Date: Tue, 21 May 2024 23:58:55 -0400 Subject: [PATCH 1/4] add margin type to position --- .../calculator/AccountCalculator.kt | 19 ++++++++++++++ .../AdjustIsolatedMarginInputCalculator.kt | 2 +- .../exchange.dydx.abacus/output/Account.kt | 25 ++++++++++++++++--- .../wallet/account/AccountProcessor.kt | 10 ++++++++ .../payload/v4/V4ParentSubaccountTests.kt | 3 +++ 5 files changed, 55 insertions(+), 4 deletions(-) diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/calculator/AccountCalculator.kt b/src/commonMain/kotlin/exchange.dydx.abacus/calculator/AccountCalculator.kt index d9c128523..4455105fd 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/calculator/AccountCalculator.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/calculator/AccountCalculator.kt @@ -5,6 +5,7 @@ import exchange.dydx.abacus.utils.NUM_PARENT_SUBACCOUNTS import exchange.dydx.abacus.utils.ParsingHelper import exchange.dydx.abacus.utils.mutable import exchange.dydx.abacus.utils.safeSet +import exchange.dydx.abacus.output.MarginType class AccountCalculator(val parser: ParserProtocol, private val useParentSubaccount: Boolean) { private val subaccountCalculator = SubaccountCalculator(parser) @@ -55,6 +56,8 @@ class AccountCalculator(val parser: ParserProtocol, private val useParentSubacco if (subaccountNumbers != null) { val groupedSubaccounts = mutableMapOf() for (subaccountNumber in subaccountNumbers) { + // 128 is the number of parent subaccounts, anything above that is reserved for isolated margin subaccounts + val marginType = if(subaccountNumber >= 128) MarginType.ISOLATED else MarginType.CROSS val subaccount = parser.asNativeMap(parser.value(subaccounts, "$subaccountNumber")) ?: break if (subaccountNumber < NUM_PARENT_SUBACCOUNTS) { @@ -76,6 +79,7 @@ class AccountCalculator(val parser: ParserProtocol, private val useParentSubacco mergeChildOpenPositions( parentSubaccount, subaccountNumber, + marginType, subaccount, childOpenPositions, ) @@ -85,6 +89,7 @@ class AccountCalculator(val parser: ParserProtocol, private val useParentSubacco mergeChildPendingPositions( parentSubaccount, subaccountNumber, + marginType, subaccount, orders, markets, @@ -108,6 +113,7 @@ class AccountCalculator(val parser: ParserProtocol, private val useParentSubacco private fun mergeChildOpenPositions( parentSubaccount: Map, childSubaccountNumber: Int, + marginType: MarginType, childSubaccount: Map, childOpenPositions: Map, ): Map { @@ -121,6 +127,10 @@ class AccountCalculator(val parser: ParserProtocol, private val useParentSubacco "childSubaccountNumber", childSubaccountNumber, ) + modifiedChildOpenPosition?.safeSet( + "marginType", + marginType, + ) modifiedChildOpenPosition?.safeSet( "quoteBalance", childSubaccount["quoteBalance"], @@ -145,6 +155,7 @@ class AccountCalculator(val parser: ParserProtocol, private val useParentSubacco private fun mergeChildPendingPositions( parentSubaccount: Map, childSubaccountNumber: Int, + marginType: MarginType, childSubaccount: Map, childOrders: Map, markets: Map?, @@ -189,6 +200,14 @@ class AccountCalculator(val parser: ParserProtocol, private val useParentSubacco "orderCount", parser.value(pending, "orderCount"), ) + modifiedPendingPosition?.safeSet( + "childSubaccountNumber", + childSubaccountNumber, + ) + modifiedPendingPosition?.safeSet( + "marginType", + marginType, + ) modifiedPendingPosition.safeSet( "quoteBalance", childSubaccount["quoteBalance"], diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/calculator/AdjustIsolatedMarginInputCalculator.kt b/src/commonMain/kotlin/exchange.dydx.abacus/calculator/AdjustIsolatedMarginInputCalculator.kt index ac4ddd73a..1becc07ca 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/calculator/AdjustIsolatedMarginInputCalculator.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/calculator/AdjustIsolatedMarginInputCalculator.kt @@ -16,7 +16,7 @@ internal class AdjustIsolatedMarginInputCalculator(val parser: ParserProtocol) { ): Map { val wallet = parser.asNativeMap(state["wallet"]) val isolatedMarginAdjustment = parser.asNativeMap(state["adjustIsolatedMargin"]) - val childSubaccountNumber = parser.asInt(isolatedMarginAdjustment?.get("ChildSubaccountNumber")) + val childSubaccountNumber = parser.asInt(isolatedMarginAdjustment?.get("childSubaccountNumber")) val type = parser.asString(isolatedMarginAdjustment?.get("Type"))?.let { IsolatedMarginAdjustmentType.valueOf(it) } ?: IsolatedMarginAdjustmentType.Add diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/output/Account.kt b/src/commonMain/kotlin/exchange.dydx.abacus/output/Account.kt index 7432a2a0e..6836b71c8 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/output/Account.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/output/Account.kt @@ -177,6 +177,18 @@ enum class PositionSide(val rawValue: String) { } } +@JsExport +@Serializable +enum class MarginType(val rawValue: String) { + ISOLATED("ISOLATED"), + CROSS("CROSS"); + + companion object { + operator fun invoke(rawValue: String) = + MarginType.values().firstOrNull { it.rawValue == rawValue } + } +} + @JsExport @Serializable data class TradeStatesWithPositionSides( @@ -249,10 +261,14 @@ data class SubaccountPosition( val liquidationPrice: TradeStatesWithDoubleValues, val resources: SubaccountPositionResources, val childSubaccountNumber: Int?, + val marginType: MarginType?, val freeCollateral: TradeStatesWithDoubleValues, val marginUsage: TradeStatesWithDoubleValues, - val quoteBalance: TradeStatesWithDoubleValues, // available for isolated market position - val equity: TradeStatesWithDoubleValues, // available for isolated market position + /** available for isolated market position */ + val quoteBalance: TradeStatesWithDoubleValues, + /** available for isolated market position */ + val equity: TradeStatesWithDoubleValues, + /** Margin type of the position */ ) { companion object { internal fun create( @@ -361,6 +377,7 @@ data class SubaccountPosition( parser.asMap(data["liquidationPrice"]), ) val childSubaccountNumber = parser.asInt(data["childSubaccountNumber"]) + val marginType = parser.asString("marginType")?.let{ MarginType.invoke(it) } val freeCollateral = TradeStatesWithDoubleValues.create( null, parser, @@ -408,7 +425,8 @@ data class SubaccountPosition( existing.freeCollateral !== freeCollateral || existing.marginUsage !== marginUsage || existing.quoteBalance !== quoteBalance || - existing.equity !== equity + existing.equity !== equity || + existing.marginType !== marginType ) { val side = positionSide(size) SubaccountPosition( @@ -436,6 +454,7 @@ data class SubaccountPosition( liquidationPrice, resources, childSubaccountNumber, + marginType, freeCollateral, marginUsage, quoteBalance, diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/processor/wallet/account/AccountProcessor.kt b/src/commonMain/kotlin/exchange.dydx.abacus/processor/wallet/account/AccountProcessor.kt index 8bd017a8e..2575131ca 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/processor/wallet/account/AccountProcessor.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/processor/wallet/account/AccountProcessor.kt @@ -1,6 +1,7 @@ package exchange.dydx.abacus.processor.wallet.account import com.ionspin.kotlin.bignum.decimal.toBigDecimal +import exchange.dydx.abacus.output.MarginType import exchange.dydx.abacus.processor.base.BaseProcessor import exchange.dydx.abacus.protocols.ParserProtocol import exchange.dydx.abacus.responses.SocketInfo @@ -351,6 +352,14 @@ internal open class SubaccountProcessor(parser: ParserProtocol) : BaseProcessor( return quoteBalance } + internal fun calculateMarginType( + subaccount: Map, + payload: Map, + ): MarginType { + print("reached") + return MarginType.CROSS + } + private fun deriveQuoteBalance(assetPositions: Map?): Double? { val usdc = parser.asNativeMap(assetPositions?.get("USDC")) return if (usdc != null) { @@ -713,6 +722,7 @@ internal class V4SubaccountsProcessor(parser: ParserProtocol) : SubaccountProces ) } modified["quoteBalance"] = calculateQuoteBalance(modified, content) + modified["marginType"] = calculateMarginType(modified, content) return modified } 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 b23fb799a..e453cdcbf 100644 --- a/src/commonTest/kotlin/exchange.dydx.abacus/payload/v4/V4ParentSubaccountTests.kt +++ b/src/commonTest/kotlin/exchange.dydx.abacus/payload/v4/V4ParentSubaccountTests.kt @@ -218,6 +218,7 @@ class V4ParentSubaccountTests : V4BaseTests(true) { "current": 7962.44 }, "childSubaccountNumber": 128, + "marginType": "ISOLATED", "equity": { "current": 829.16 }, @@ -533,6 +534,7 @@ class V4ParentSubaccountTests : V4BaseTests(true) { "current": 1410.69 }, "childSubaccountNumber": 128, + "marginType": "ISOLATED", "quoteBalance": { "current": 267.89 }, @@ -603,6 +605,7 @@ class V4ParentSubaccountTests : V4BaseTests(true) { "current": 1949.55 }, "childSubaccountNumber": 128, + "marginType": "ISOLATED", "quoteBalance": { "current": 367.89 }, From 8e89702d33fffcea4cfd5e8bd344359c4832a1c1 Mon Sep 17 00:00:00 2001 From: mike-dydx Date: Wed, 22 May 2024 10:23:52 -0400 Subject: [PATCH 2/4] replace marginType w marginMode and add marginMode to SubaccountOrder --- .../calculator/AccountCalculator.kt | 35 ++++++++++------ .../exchange.dydx.abacus/output/Account.kt | 40 +++++++++++-------- .../wallet/account/AccountProcessor.kt | 6 +-- .../payload/v4/V4ParentSubaccountTests.kt | 6 +-- 4 files changed, 52 insertions(+), 35 deletions(-) diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/calculator/AccountCalculator.kt b/src/commonMain/kotlin/exchange.dydx.abacus/calculator/AccountCalculator.kt index 4455105fd..7c3b2cd0d 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/calculator/AccountCalculator.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/calculator/AccountCalculator.kt @@ -5,7 +5,7 @@ import exchange.dydx.abacus.utils.NUM_PARENT_SUBACCOUNTS import exchange.dydx.abacus.utils.ParsingHelper import exchange.dydx.abacus.utils.mutable import exchange.dydx.abacus.utils.safeSet -import exchange.dydx.abacus.output.MarginType +import exchange.dydx.abacus.output.MarginMode class AccountCalculator(val parser: ParserProtocol, private val useParentSubaccount: Boolean) { private val subaccountCalculator = SubaccountCalculator(parser) @@ -56,8 +56,7 @@ class AccountCalculator(val parser: ParserProtocol, private val useParentSubacco if (subaccountNumbers != null) { val groupedSubaccounts = mutableMapOf() for (subaccountNumber in subaccountNumbers) { - // 128 is the number of parent subaccounts, anything above that is reserved for isolated margin subaccounts - val marginType = if(subaccountNumber >= 128) MarginType.ISOLATED else MarginType.CROSS + val marginMode = if(subaccountNumber >= NUM_PARENT_SUBACCOUNTS) MarginMode.ISOLATED else MarginMode.CROSS val subaccount = parser.asNativeMap(parser.value(subaccounts, "$subaccountNumber")) ?: break if (subaccountNumber < NUM_PARENT_SUBACCOUNTS) { @@ -79,7 +78,7 @@ class AccountCalculator(val parser: ParserProtocol, private val useParentSubacco mergeChildOpenPositions( parentSubaccount, subaccountNumber, - marginType, + marginMode, subaccount, childOpenPositions, ) @@ -89,7 +88,7 @@ class AccountCalculator(val parser: ParserProtocol, private val useParentSubacco mergeChildPendingPositions( parentSubaccount, subaccountNumber, - marginType, + marginMode, subaccount, orders, markets, @@ -98,7 +97,7 @@ class AccountCalculator(val parser: ParserProtocol, private val useParentSubacco parentSubaccount } } - parentSubaccount = mergeOrders(parentSubaccount, subaccount) + parentSubaccount = mergeOrders(parentSubaccount, subaccount, marginMode) parentSubaccount = sumEquity(parentSubaccount, subaccount) groupedSubaccounts["$parentSubaccountNumber"] = parentSubaccount } @@ -113,7 +112,7 @@ class AccountCalculator(val parser: ParserProtocol, private val useParentSubacco private fun mergeChildOpenPositions( parentSubaccount: Map, childSubaccountNumber: Int, - marginType: MarginType, + marginMode: MarginMode, childSubaccount: Map, childOpenPositions: Map, ): Map { @@ -128,8 +127,8 @@ class AccountCalculator(val parser: ParserProtocol, private val useParentSubacco childSubaccountNumber, ) modifiedChildOpenPosition?.safeSet( - "marginType", - marginType, + "marginMode", + marginMode, ) modifiedChildOpenPosition?.safeSet( "quoteBalance", @@ -155,7 +154,7 @@ class AccountCalculator(val parser: ParserProtocol, private val useParentSubacco private fun mergeChildPendingPositions( parentSubaccount: Map, childSubaccountNumber: Int, - marginType: MarginType, + marginMode: MarginMode, childSubaccount: Map, childOrders: Map, markets: Map?, @@ -205,8 +204,8 @@ class AccountCalculator(val parser: ParserProtocol, private val useParentSubacco childSubaccountNumber, ) modifiedPendingPosition?.safeSet( - "marginType", - marginType, + "marginMode", + marginMode, ) modifiedPendingPosition.safeSet( "quoteBalance", @@ -238,12 +237,13 @@ class AccountCalculator(val parser: ParserProtocol, private val useParentSubacco private fun mergeOrders( parentSubaccount: Map, childSubaccount: Map, + marginMode: MarginMode, ): Map { // Each empty subaccount should have order for one market only // Just in case it has more than one market, we will create // two separate pending positions. - val mergedOrders = ParsingHelper.merge( + var mergedOrders = ParsingHelper.merge( parser.asNativeMap( parser.value(parentSubaccount, "orders"), ), @@ -252,6 +252,15 @@ class AccountCalculator(val parser: ParserProtocol, private val useParentSubacco ), ) + mergedOrders = mergedOrders?.mapValues { (_, value) -> + var modifiedOrder = parser.asMap(value)?.toMutableMap() ?: mutableMapOf() + modifiedOrder?.safeSet( + "marginMode", + marginMode, + ) + modifiedOrder + } + val modifiedParentSubaccount = parentSubaccount.toMutableMap() modifiedParentSubaccount.safeSet( "orders", diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/output/Account.kt b/src/commonMain/kotlin/exchange.dydx.abacus/output/Account.kt index 6836b71c8..5d0ac12aa 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/output/Account.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/output/Account.kt @@ -179,13 +179,13 @@ enum class PositionSide(val rawValue: String) { @JsExport @Serializable -enum class MarginType(val rawValue: String) { +enum class MarginMode(val rawValue: String) { ISOLATED("ISOLATED"), CROSS("CROSS"); companion object { operator fun invoke(rawValue: String) = - MarginType.values().firstOrNull { it.rawValue == rawValue } + MarginMode.values().firstOrNull { it.rawValue == rawValue } } } @@ -261,7 +261,7 @@ data class SubaccountPosition( val liquidationPrice: TradeStatesWithDoubleValues, val resources: SubaccountPositionResources, val childSubaccountNumber: Int?, - val marginType: MarginType?, + val marginMode: MarginMode?, val freeCollateral: TradeStatesWithDoubleValues, val marginUsage: TradeStatesWithDoubleValues, /** available for isolated market position */ @@ -377,7 +377,7 @@ data class SubaccountPosition( parser.asMap(data["liquidationPrice"]), ) val childSubaccountNumber = parser.asInt(data["childSubaccountNumber"]) - val marginType = parser.asString("marginType")?.let{ MarginType.invoke(it) } + val marginMode = parser.asString("marginType")?.let{ MarginMode.invoke(it) } val freeCollateral = TradeStatesWithDoubleValues.create( null, parser, @@ -426,7 +426,7 @@ data class SubaccountPosition( existing.marginUsage !== marginUsage || existing.quoteBalance !== quoteBalance || existing.equity !== equity || - existing.marginType !== marginType + existing.marginMode !== marginMode ) { val side = positionSide(size) SubaccountPosition( @@ -454,7 +454,7 @@ data class SubaccountPosition( liquidationPrice, resources, childSubaccountNumber, - marginType, + marginMode, freeCollateral, marginUsage, quoteBalance, @@ -652,7 +652,6 @@ data class SubaccountOrderResources( @JsExport @Serializable data class SubaccountOrder( - val subaccountNumber: Int?, val id: String, val clientId: Int?, val type: OrderType, @@ -679,7 +678,9 @@ data class SubaccountOrder( val reduceOnly: Boolean, val cancelReason: String?, val resources: SubaccountOrderResources, -) { + val subaccountNumber: Int?, + val marginMode: MarginMode?, + ) { companion object { internal fun create( existing: SubaccountOrder?, @@ -689,8 +690,6 @@ data class SubaccountOrder( ): SubaccountOrder? { Logger.d { "creating Account Order\n" } data?.let { - // TODO: Remove default to 0 for subaccountNumber once new indexer response is consumed. Prevents breaking change - val subaccountNumber = parser.asInt(data["subaccountNumber"]) ?: 0 val id = parser.asString(data["id"]) val clientId = parser.asInt(data["clientId"]) val marketId = parser.asString(data["marketId"]) @@ -712,6 +711,9 @@ data class SubaccountOrder( val resources = parser.asMap(data["resources"])?.let { SubaccountOrderResources.create(existing?.resources, parser, it, localizer) } + // TODO: Remove default to 0 for subaccountNumber once new indexer response is consumed. Prevents breaking change + val subaccountNumber = parser.asInt(data["subaccountNumber"]) ?: 0 + val marginMode = parser.asString(data["marginMode"])?.let { MarginMode.invoke(it) } if (id != null && marketId != null && type != null && side != null && status != null && price != null && size != null && resources != null ) { @@ -736,8 +738,7 @@ data class SubaccountOrder( val cancelReason = parser.asString(data["cancelReason"]) return if ( - existing?.subaccountNumber != subaccountNumber || - existing.id != id || + existing?.id != id || existing.clientId != clientId || existing.type !== type || existing.side !== side || @@ -761,10 +762,11 @@ data class SubaccountOrder( existing.postOnly != postOnly || existing.reduceOnly != reduceOnly || existing.cancelReason != cancelReason || - existing.resources !== resources + existing.resources !== resources || + existing.subaccountNumber != subaccountNumber || + existing.marginMode !== marginMode ) { SubaccountOrder( - subaccountNumber, id, clientId, type, @@ -791,7 +793,9 @@ data class SubaccountOrder( reduceOnly, cancelReason, resources, - ) + subaccountNumber, + marginMode, + ) } else { existing } @@ -1357,7 +1361,11 @@ data class Subaccount( parser.asList(data["pendingPositions"]), ) val orders = - orders(parser, existing?.orders, parser.asMap(data["orders"]), localizer) + orders(parser, + existing?.orders, + parser.asMap(data["orders"]), + localizer + ) /* val transfers = AccountTransfers.fromArray( diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/processor/wallet/account/AccountProcessor.kt b/src/commonMain/kotlin/exchange.dydx.abacus/processor/wallet/account/AccountProcessor.kt index 2575131ca..672db1d60 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/processor/wallet/account/AccountProcessor.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/processor/wallet/account/AccountProcessor.kt @@ -1,7 +1,7 @@ package exchange.dydx.abacus.processor.wallet.account import com.ionspin.kotlin.bignum.decimal.toBigDecimal -import exchange.dydx.abacus.output.MarginType +import exchange.dydx.abacus.output.MarginMode import exchange.dydx.abacus.processor.base.BaseProcessor import exchange.dydx.abacus.protocols.ParserProtocol import exchange.dydx.abacus.responses.SocketInfo @@ -355,9 +355,9 @@ internal open class SubaccountProcessor(parser: ParserProtocol) : BaseProcessor( internal fun calculateMarginType( subaccount: Map, payload: Map, - ): MarginType { + ): MarginMode { print("reached") - return MarginType.CROSS + return MarginMode.CROSS } private fun deriveQuoteBalance(assetPositions: Map?): Double? { 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 e453cdcbf..2b7143b63 100644 --- a/src/commonTest/kotlin/exchange.dydx.abacus/payload/v4/V4ParentSubaccountTests.kt +++ b/src/commonTest/kotlin/exchange.dydx.abacus/payload/v4/V4ParentSubaccountTests.kt @@ -218,7 +218,7 @@ class V4ParentSubaccountTests : V4BaseTests(true) { "current": 7962.44 }, "childSubaccountNumber": 128, - "marginType": "ISOLATED", + "marginMode": "ISOLATED", "equity": { "current": 829.16 }, @@ -534,7 +534,7 @@ class V4ParentSubaccountTests : V4BaseTests(true) { "current": 1410.69 }, "childSubaccountNumber": 128, - "marginType": "ISOLATED", + "marginMode": "ISOLATED", "quoteBalance": { "current": 267.89 }, @@ -605,7 +605,7 @@ class V4ParentSubaccountTests : V4BaseTests(true) { "current": 1949.55 }, "childSubaccountNumber": 128, - "marginType": "ISOLATED", + "marginMode": "ISOLATED", "quoteBalance": { "current": 367.89 }, From 2e9a23976b2acc47a4b0f5708c36d03499d2ef71 Mon Sep 17 00:00:00 2001 From: mike-dydx Date: Wed, 22 May 2024 11:57:32 -0400 Subject: [PATCH 3/4] undo --- .../calculator/AdjustIsolatedMarginInputCalculator.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/calculator/AdjustIsolatedMarginInputCalculator.kt b/src/commonMain/kotlin/exchange.dydx.abacus/calculator/AdjustIsolatedMarginInputCalculator.kt index 1becc07ca..ac4ddd73a 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/calculator/AdjustIsolatedMarginInputCalculator.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/calculator/AdjustIsolatedMarginInputCalculator.kt @@ -16,7 +16,7 @@ internal class AdjustIsolatedMarginInputCalculator(val parser: ParserProtocol) { ): Map { val wallet = parser.asNativeMap(state["wallet"]) val isolatedMarginAdjustment = parser.asNativeMap(state["adjustIsolatedMargin"]) - val childSubaccountNumber = parser.asInt(isolatedMarginAdjustment?.get("childSubaccountNumber")) + val childSubaccountNumber = parser.asInt(isolatedMarginAdjustment?.get("ChildSubaccountNumber")) val type = parser.asString(isolatedMarginAdjustment?.get("Type"))?.let { IsolatedMarginAdjustmentType.valueOf(it) } ?: IsolatedMarginAdjustmentType.Add From 1f5994e9e4f9192476190be344d50ba59a9e96bd Mon Sep 17 00:00:00 2001 From: mike-dydx Date: Wed, 22 May 2024 12:00:25 -0400 Subject: [PATCH 4/4] undo --- .../processor/wallet/account/AccountProcessor.kt | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/processor/wallet/account/AccountProcessor.kt b/src/commonMain/kotlin/exchange.dydx.abacus/processor/wallet/account/AccountProcessor.kt index 672db1d60..8bd017a8e 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/processor/wallet/account/AccountProcessor.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/processor/wallet/account/AccountProcessor.kt @@ -1,7 +1,6 @@ package exchange.dydx.abacus.processor.wallet.account import com.ionspin.kotlin.bignum.decimal.toBigDecimal -import exchange.dydx.abacus.output.MarginMode import exchange.dydx.abacus.processor.base.BaseProcessor import exchange.dydx.abacus.protocols.ParserProtocol import exchange.dydx.abacus.responses.SocketInfo @@ -352,14 +351,6 @@ internal open class SubaccountProcessor(parser: ParserProtocol) : BaseProcessor( return quoteBalance } - internal fun calculateMarginType( - subaccount: Map, - payload: Map, - ): MarginMode { - print("reached") - return MarginMode.CROSS - } - private fun deriveQuoteBalance(assetPositions: Map?): Double? { val usdc = parser.asNativeMap(assetPositions?.get("USDC")) return if (usdc != null) { @@ -722,7 +713,6 @@ internal class V4SubaccountsProcessor(parser: ParserProtocol) : SubaccountProces ) } modified["quoteBalance"] = calculateQuoteBalance(modified, content) - modified["marginType"] = calculateMarginType(modified, content) return modified }