Skip to content

Commit

Permalink
change back to marginMode
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-dydx committed May 23, 2024
1 parent fe576d0 commit f36d285
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 19 deletions.
17 changes: 9 additions & 8 deletions src/commonMain/kotlin/exchange.dydx.abacus/output/Account.kt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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 ||
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -445,7 +446,7 @@ data class SubaccountPosition(
marginUsage,
quoteBalance,
equity,
marketType,
marginMode,
)
} else {
existing
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
) {
Expand Down Expand Up @@ -751,7 +752,7 @@ data class SubaccountOrder(
existing.cancelReason != cancelReason ||
existing.resources !== resources ||
existing.subaccountNumber != subaccountNumber ||
existing.marketType != marketType
existing.marginMode != marginMode
) {
SubaccountOrder(
id,
Expand Down Expand Up @@ -781,7 +782,7 @@ data class SubaccountOrder(
cancelReason,
resources,
subaccountNumber,
marketType,
marginMode,
)
} else {
existing
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class V4ParentSubaccountTests : V4BaseTests(true) {
"current": -0.12
},
"subaccountNumber": 0,
"marginMode": "CROSS"
"marginMode": "cross"
}
}
},
Expand Down Expand Up @@ -132,7 +132,7 @@ class V4ParentSubaccountTests : V4BaseTests(true) {
"current": 7962.44
},
"subaccountNumber": 128,
"marginMode": "ISOLATED"
"marginMode": "isolated"
}
},
"orders": {
Expand All @@ -150,7 +150,7 @@ class V4ParentSubaccountTests : V4BaseTests(true) {
"reduceOnly": false,
"goodTilBlock": "5837",
"subaccountNumber": 128,
"marginMode": "ISOLATED"
"marginMode": "isolated"
}
}
}
Expand Down Expand Up @@ -194,7 +194,7 @@ class V4ParentSubaccountTests : V4BaseTests(true) {
"current": -0.12
},
"subaccountNumber": 0,
"marginMode": "CROSS"
"marginMode": "cross"
},
"RUNE-USD": {
"id": "RUNE-USD",
Expand Down Expand Up @@ -239,7 +239,7 @@ class V4ParentSubaccountTests : V4BaseTests(true) {
"current": 0.0397
},
"subaccountNumber": 128,
"marginMode": "ISOLATED"
"marginMode": "isolated"
}
},
"pendingPositions": [
Expand All @@ -257,8 +257,7 @@ class V4ParentSubaccountTests : V4BaseTests(true) {
},
"equity": {
"current": 500.0
"subaccountNumber": 128,
"marginMode": "ISOLATED"
}
}
]
}
Expand All @@ -282,6 +281,10 @@ class V4ParentSubaccountTests : V4BaseTests(true) {
"trade": {
"marginMode": "ISOLATED",
"targetLeverage": 1.0
"targetLeverage": 1.0,
"options": {
"needsMarginMode": true
}
}
}
}
Expand All @@ -298,6 +301,10 @@ class V4ParentSubaccountTests : V4BaseTests(true) {
"current": "trade",
"trade": {
"marginMode": "CROSS"
"marginMode": "CROSS",
"options": {
"needsMarginMode": true
}
}
}
}
Expand All @@ -314,6 +321,10 @@ class V4ParentSubaccountTests : V4BaseTests(true) {
"current": "trade",
"trade": {
"marginMode": "ISOLATED"
"marginMode": "ISOLATED",
"options": {
"needsMarginMode": true
}
}
}
}
Expand All @@ -330,6 +341,10 @@ class V4ParentSubaccountTests : V4BaseTests(true) {
"current": "trade",
"trade": {
"marginMode": "CROSS"
"marginMode": "CROSS",
"options": {
"needsMarginMode": true
}
}
}
}
Expand All @@ -346,6 +361,10 @@ class V4ParentSubaccountTests : V4BaseTests(true) {
"current": "trade",
"trade": {
"marginMode": "ISOLATED"
"marginMode": "ISOLATED",
"options": {
"needsMarginMode": true
}
}
}
}
Expand All @@ -362,6 +381,10 @@ class V4ParentSubaccountTests : V4BaseTests(true) {
"current": "trade",
"trade": {
"marginMode": "CROSS"
"marginMode": "CROSS",
"options": {
"needsMarginMode": true
}
}
}
}
Expand Down

0 comments on commit f36d285

Please sign in to comment.