From f36d2850ae4512e78e1e6837199aec11352c5326 Mon Sep 17 00:00:00 2001 From: mike-dydx Date: Thu, 23 May 2024 15:35:49 -0400 Subject: [PATCH] change back to `marginMode` --- .../exchange.dydx.abacus/output/Account.kt | 17 +++++---- .../wallet/account/OrderProcessor.kt | 4 +- .../account/PerpetualPositionProcessor.kt | 4 +- .../payload/v4/V4ParentSubaccountTests.kt | 37 +++++++++++++++---- 4 files changed, 43 insertions(+), 19 deletions(-) diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/output/Account.kt b/src/commonMain/kotlin/exchange.dydx.abacus/output/Account.kt index 836b0506c..e42be23c9 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/output/Account.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/output/Account.kt @@ -1,5 +1,6 @@ package exchange.dydx.abacus.output +import exchange.dydx.abacus.output.input.MarginMode import exchange.dydx.abacus.output.input.OrderSide import exchange.dydx.abacus.output.input.OrderStatus import exchange.dydx.abacus.output.input.OrderTimeInForce @@ -255,7 +256,7 @@ data class SubaccountPosition( val marginUsage: TradeStatesWithDoubleValues, val quoteBalance: TradeStatesWithDoubleValues, // available for isolated market position val equity: TradeStatesWithDoubleValues, // available for isolated market position - val marketType: PerpetualMarketType? + val marginMode: MarginMode? ) { companion object { internal fun create( @@ -384,7 +385,7 @@ data class SubaccountPosition( parser, parser.asMap(data["equity"]), ) - val marketType = parser.asString(data["marketType"])?.let { PerpetualMarketType.invoke(it) } + val marginMode = parser.asString(data["marginMode"])?.let { MarginMode.invoke(it) } return if (existing?.id != id || existing.assetId != assetId || @@ -413,7 +414,7 @@ data class SubaccountPosition( existing.marginUsage !== marginUsage || existing.quoteBalance !== quoteBalance || existing.equity !== equity || - existing.marketType != marketType + existing.marginMode != marginMode ) { val side = positionSide(size) SubaccountPosition( @@ -445,7 +446,7 @@ data class SubaccountPosition( marginUsage, quoteBalance, equity, - marketType, + marginMode, ) } else { existing @@ -666,7 +667,7 @@ data class SubaccountOrder( val cancelReason: String?, val resources: SubaccountOrderResources, val subaccountNumber: Int?, - val marketType: PerpetualMarketType? + val marginMode: MarginMode? ) { companion object { internal fun create( @@ -700,7 +701,7 @@ data class SubaccountOrder( } // TODO: Remove default to 0 for subaccountNumber once new indexer response is consumed. Prevents breaking change val subaccountNumber = parser.asInt(data["subaccountNumber"]) ?: 0 - val marketType = parser.asString(data["marketType"])?.let { PerpetualMarketType.invoke(it) } + 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 ) { @@ -751,7 +752,7 @@ data class SubaccountOrder( existing.cancelReason != cancelReason || existing.resources !== resources || existing.subaccountNumber != subaccountNumber || - existing.marketType != marketType + existing.marginMode != marginMode ) { SubaccountOrder( id, @@ -781,7 +782,7 @@ data class SubaccountOrder( cancelReason, resources, subaccountNumber, - marketType, + marginMode, ) } else { existing diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/processor/wallet/account/OrderProcessor.kt b/src/commonMain/kotlin/exchange.dydx.abacus/processor/wallet/account/OrderProcessor.kt index a06189ac3..e264bc26b 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/processor/wallet/account/OrderProcessor.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/processor/wallet/account/OrderProcessor.kt @@ -1,6 +1,6 @@ package exchange.dydx.abacus.processor.wallet.account -import exchange.dydx.abacus.output.PerpetualMarketType +import exchange.dydx.abacus.output.input.MarginMode import exchange.dydx.abacus.processor.base.BaseProcessor import exchange.dydx.abacus.processor.utils.OrderTypeProcessor import exchange.dydx.abacus.protocols.ParserProtocol @@ -207,7 +207,7 @@ internal class OrderProcessor(parser: ParserProtocol) : BaseProcessor(parser) { parser.asInt(modified["subaccountNumber"])?.run { modified.safeSet("subaccountNumber", this) // the v4_parent_subaccount message has subaccountNumber available but v4_orders does not - modified.safeSet("marketType", if (this >= NUM_PARENT_SUBACCOUNTS) PerpetualMarketType.ISOLATED else PerpetualMarketType.CROSS) + modified.safeSet("marginMode", if (this >= NUM_PARENT_SUBACCOUNTS) MarginMode.isolated else MarginMode.cross) } val size = parser.asDouble(payload["size"]) if (size != null) { diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/processor/wallet/account/PerpetualPositionProcessor.kt b/src/commonMain/kotlin/exchange.dydx.abacus/processor/wallet/account/PerpetualPositionProcessor.kt index eaead0235..bf6d79abc 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/processor/wallet/account/PerpetualPositionProcessor.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/processor/wallet/account/PerpetualPositionProcessor.kt @@ -1,7 +1,7 @@ package exchange.dydx.abacus.processor.wallet.account import abs -import exchange.dydx.abacus.output.PerpetualMarketType +import exchange.dydx.abacus.output.input.MarginMode import exchange.dydx.abacus.processor.base.BaseProcessor import exchange.dydx.abacus.protocols.ParserProtocol import exchange.dydx.abacus.utils.NUM_PARENT_SUBACCOUNTS @@ -121,7 +121,7 @@ internal class PerpetualPositionProcessor(parser: ParserProtocol) : BaseProcesso modified.safeSet("subaccountNumber", this) // the v4_parent_subaccount message has subaccountNumber available but v4_orders does not - modified.safeSet("marketType", if (this >= NUM_PARENT_SUBACCOUNTS) PerpetualMarketType.ISOLATED else PerpetualMarketType.CROSS) + modified.safeSet("marginMode", if (this >= NUM_PARENT_SUBACCOUNTS) MarginMode.isolated else MarginMode.cross) } ParsingHelper.asset(parser.asString(modified["id"]))?.let { 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 bf38c593f..34cf1e247 100644 --- a/src/commonTest/kotlin/exchange.dydx.abacus/payload/v4/V4ParentSubaccountTests.kt +++ b/src/commonTest/kotlin/exchange.dydx.abacus/payload/v4/V4ParentSubaccountTests.kt @@ -84,7 +84,7 @@ class V4ParentSubaccountTests : V4BaseTests(true) { "current": -0.12 }, "subaccountNumber": 0, - "marginMode": "CROSS" + "marginMode": "cross" } } }, @@ -132,7 +132,7 @@ class V4ParentSubaccountTests : V4BaseTests(true) { "current": 7962.44 }, "subaccountNumber": 128, - "marginMode": "ISOLATED" + "marginMode": "isolated" } }, "orders": { @@ -150,7 +150,7 @@ class V4ParentSubaccountTests : V4BaseTests(true) { "reduceOnly": false, "goodTilBlock": "5837", "subaccountNumber": 128, - "marginMode": "ISOLATED" + "marginMode": "isolated" } } } @@ -194,7 +194,7 @@ class V4ParentSubaccountTests : V4BaseTests(true) { "current": -0.12 }, "subaccountNumber": 0, - "marginMode": "CROSS" + "marginMode": "cross" }, "RUNE-USD": { "id": "RUNE-USD", @@ -239,7 +239,7 @@ class V4ParentSubaccountTests : V4BaseTests(true) { "current": 0.0397 }, "subaccountNumber": 128, - "marginMode": "ISOLATED" + "marginMode": "isolated" } }, "pendingPositions": [ @@ -257,8 +257,7 @@ class V4ParentSubaccountTests : V4BaseTests(true) { }, "equity": { "current": 500.0 - "subaccountNumber": 128, - "marginMode": "ISOLATED" + } } ] } @@ -282,6 +281,10 @@ class V4ParentSubaccountTests : V4BaseTests(true) { "trade": { "marginMode": "ISOLATED", "targetLeverage": 1.0 + "targetLeverage": 1.0, + "options": { + "needsMarginMode": true + } } } } @@ -298,6 +301,10 @@ class V4ParentSubaccountTests : V4BaseTests(true) { "current": "trade", "trade": { "marginMode": "CROSS" + "marginMode": "CROSS", + "options": { + "needsMarginMode": true + } } } } @@ -314,6 +321,10 @@ class V4ParentSubaccountTests : V4BaseTests(true) { "current": "trade", "trade": { "marginMode": "ISOLATED" + "marginMode": "ISOLATED", + "options": { + "needsMarginMode": true + } } } } @@ -330,6 +341,10 @@ class V4ParentSubaccountTests : V4BaseTests(true) { "current": "trade", "trade": { "marginMode": "CROSS" + "marginMode": "CROSS", + "options": { + "needsMarginMode": true + } } } } @@ -346,6 +361,10 @@ class V4ParentSubaccountTests : V4BaseTests(true) { "current": "trade", "trade": { "marginMode": "ISOLATED" + "marginMode": "ISOLATED", + "options": { + "needsMarginMode": true + } } } } @@ -362,6 +381,10 @@ class V4ParentSubaccountTests : V4BaseTests(true) { "current": "trade", "trade": { "marginMode": "CROSS" + "marginMode": "CROSS", + "options": { + "needsMarginMode": true + } } } }