From 96ba05ee6b0c93ec9c02fc63cbc74fbee4e4fc54 Mon Sep 17 00:00:00 2001 From: jaredvu Date: Mon, 17 Jun 2024 21:07:37 -0700 Subject: [PATCH 1/4] Update order status enum strings --- .../calculator/AccountCalculator.kt | 1 + .../v2/supervisor/SubaccountSupervisor.kt | 29 +++++++++++++++---- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/calculator/AccountCalculator.kt b/src/commonMain/kotlin/exchange.dydx.abacus/calculator/AccountCalculator.kt index 47bf2bd59..b3e349ca2 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/calculator/AccountCalculator.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/calculator/AccountCalculator.kt @@ -177,6 +177,7 @@ class AccountCalculator(val parser: ParserProtocol, private val useParentSubacco } val orderStatus = parser.asString(parser.value(order, "status")) + if (!listOf("OPEN", "PENDING", "UNTRIGGERED", "PARTIALLY_FILLED").contains(orderStatus)) { continue } diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/SubaccountSupervisor.kt b/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/SubaccountSupervisor.kt index 2bf562908..3ed60a6f5 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/SubaccountSupervisor.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/SubaccountSupervisor.kt @@ -64,6 +64,7 @@ import exchange.dydx.abacus.utils.GoodTil import exchange.dydx.abacus.utils.IList import exchange.dydx.abacus.utils.IMap import exchange.dydx.abacus.utils.IMutableList +import exchange.dydx.abacus.utils.Logger import exchange.dydx.abacus.utils.MAX_SUBACCOUNT_NUMBER import exchange.dydx.abacus.utils.NUM_PARENT_SUBACCOUNTS import exchange.dydx.abacus.utils.ParsingHelper @@ -71,6 +72,7 @@ import exchange.dydx.abacus.utils.SHORT_TERM_ORDER_DURATION import exchange.dydx.abacus.utils.SHORT_TERM_ORDER_FLAGS import exchange.dydx.abacus.utils.iMapOf import exchange.dydx.abacus.utils.mutable +import exchange.dydx.abacus.utils.toJsonElement import exchange.dydx.abacus.utils.values import kollections.iListOf import kollections.iMutableListOf @@ -556,7 +558,13 @@ internal class SubaccountSupervisor( val openPositions = subaccount.openPositions val openOrders = subaccount.orders?.filter { order -> val status = helper.parser.asString(order.status) - status == "open" || status == "pending" || status == "untriggered" || status == "partiallyFilled" + + iListOf( + OrderStatus.Open.name, + OrderStatus.Pending.name, + OrderStatus.Untriggered.name, + OrderStatus.PartiallyFilled.name, + ).contains(status) } val positionMarketIds = openPositions?.map { position -> @@ -1476,12 +1484,18 @@ internal class SubaccountSupervisor( return@mapValues 0.0 } + val quoteBalance = subaccount.value.quoteBalance?.current ?: 0.0 val openPositions = subaccount.value.openPositions + val openOrders = subaccount.value.orders?.filter { order -> val status = helper.parser.asString(order.status) - iListOf("open", "pending", "untriggered", "partiallyFilled").contains(status) + iListOf( + OrderStatus.Open.name, + OrderStatus.Pending.name, + OrderStatus.Untriggered.name, + OrderStatus.PartiallyFilled.name + ).contains(status) } - val quoteBalance = subaccount.value.quoteBalance?.current ?: 0.0 // Only return a quoteBalance if the subaccount has no open positions or orders if (openPositions.isNullOrEmpty() && openOrders.isNullOrEmpty() && quoteBalance > 0.0) { @@ -1496,8 +1510,13 @@ internal class SubaccountSupervisor( val transferPayloadStrings = iMutableListOf() subaccountQuoteBalanceMap.forEach { - val childSubaccountNumber = it.key.toInt() - val amountToTransfer = it.value.toString() + val childSubaccountNumber = helper.parser.asInt(it.key) + val amountToTransfer = helper.parser.asString(it.value) + + if (childSubaccountNumber == null || amountToTransfer == null) { + Logger.e {"Child Subaccount Number or Amount to Transfer is null"} + return@forEach + } val transferPayload = HumanReadableSubaccountTransferPayload( childSubaccountNumber, From 14ef04d16a3d31399a239c0807e0801eb00c6830 Mon Sep 17 00:00:00 2001 From: jaredvu Date: Mon, 17 Jun 2024 21:09:13 -0700 Subject: [PATCH 2/4] remove unused import --- .../state/v2/supervisor/SubaccountSupervisor.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/SubaccountSupervisor.kt b/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/SubaccountSupervisor.kt index 3ed60a6f5..54aee7e5d 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/SubaccountSupervisor.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/SubaccountSupervisor.kt @@ -72,7 +72,6 @@ import exchange.dydx.abacus.utils.SHORT_TERM_ORDER_DURATION import exchange.dydx.abacus.utils.SHORT_TERM_ORDER_FLAGS import exchange.dydx.abacus.utils.iMapOf import exchange.dydx.abacus.utils.mutable -import exchange.dydx.abacus.utils.toJsonElement import exchange.dydx.abacus.utils.values import kollections.iListOf import kollections.iMutableListOf From 46535de27a2760b14af674592072de37c76a63ba Mon Sep 17 00:00:00 2001 From: mobile-build-bot-git Date: Tue, 18 Jun 2024 04:10:42 +0000 Subject: [PATCH 3/4] Bump version --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index c8d548cc0..a543bd113 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -51,7 +51,7 @@ allprojects { } group = "exchange.dydx.abacus" -version = "1.7.82" +version = "1.7.83" repositories { google() From eabfc7c4920d35f1ddfec5b8cd8ebbcea4dc9e7c Mon Sep 17 00:00:00 2001 From: jaredvu Date: Mon, 17 Jun 2024 21:16:50 -0700 Subject: [PATCH 4/4] spotlessApply --- .../state/v2/supervisor/SubaccountSupervisor.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/SubaccountSupervisor.kt b/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/SubaccountSupervisor.kt index 54aee7e5d..87e55c70d 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/SubaccountSupervisor.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/SubaccountSupervisor.kt @@ -1492,7 +1492,7 @@ internal class SubaccountSupervisor( OrderStatus.Open.name, OrderStatus.Pending.name, OrderStatus.Untriggered.name, - OrderStatus.PartiallyFilled.name + OrderStatus.PartiallyFilled.name, ).contains(status) } @@ -1513,7 +1513,7 @@ internal class SubaccountSupervisor( val amountToTransfer = helper.parser.asString(it.value) if (childSubaccountNumber == null || amountToTransfer == null) { - Logger.e {"Child Subaccount Number or Amount to Transfer is null"} + Logger.e { "Child Subaccount Number or Amount to Transfer is null" } return@forEach }