From ae126bd35bc1e6b3a649daaee4dcbffb5e9e1970 Mon Sep 17 00:00:00 2001 From: aforaleka Date: Mon, 17 Jun 2024 15:19:26 -0400 Subject: [PATCH] address comments --- .../kotlin/exchange.dydx.abacus/output/input/TradeInput.kt | 6 +++--- .../processor/wallet/account/OrderProcessor.kt | 7 ++++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/output/input/TradeInput.kt b/src/commonMain/kotlin/exchange.dydx.abacus/output/input/TradeInput.kt index c04234447..72da5889e 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/output/input/TradeInput.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/output/input/TradeInput.kt @@ -707,10 +707,10 @@ enum class OrderStatus(val rawValue: String) { canceling("BEST_EFFORT_CANCELED"), filled("FILLED"), `open`("OPEN"), - pending("PENDING"), + pending("PENDING"), // indexer returns order as BEST_EFFORT_OPENED, or BEST_EFFORT_CANCELED when order is IOC untriggered("UNTRIGGERED"), - partiallyFilled("PARTIALLY_FILLED"), - partiallyCanceled("PARTIALLY_CANCELED"); + partiallyFilled("PARTIALLY_FILLED"), // indexer returns order as OPEN but order is partially filled + partiallyCanceled("PARTIALLY_CANCELED"); // indexer returns order as CANCELED but order is partially filled companion object { operator fun invoke(rawValue: String): OrderStatus? { 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 8807e8eb6..328ed7768 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 @@ -228,10 +228,11 @@ internal class OrderProcessor(parser: ParserProtocol) : BaseProcessor(parser) { parser.asDouble(payload["orderFlags"])?.let { orderFlags -> // if order is short-term order and indexer returns best effort canceled and has no partial fill // treat as a pending order until it's partially filled or finalized + val isShortTermOrder = orderFlags.equals(Numeric.double.ZERO) val isBestEffortCanceled = modified["status"] == "BEST_EFFORT_CANCELED" val cancelReason = parser.asString(modified["cancelReason"]) val isUserCanceled = cancelReason == "USER_CANCELED" || cancelReason == "ORDER_REMOVAL_REASON_USER_CANCELED" - if (orderFlags.equals(Numeric.double.ZERO) && isBestEffortCanceled && !isUserCanceled) { + if (isShortTermOrder && isBestEffortCanceled && !isUserCanceled) { modified.safeSet("status", "PENDING") } } @@ -319,7 +320,7 @@ internal class OrderProcessor(parser: ParserProtocol) : BaseProcessor(parser) { return Pair(existing, false) } - private fun isStatusFinalized(status: Any?): Boolean { + private fun isStatusFinalized(status: String?): Boolean { // once an order is filled, canceled, or canceled with partial fill // there is no need to update status again return when (status) { @@ -333,7 +334,7 @@ internal class OrderProcessor(parser: ParserProtocol) : BaseProcessor(parser) { ): Map { val modified = existing.mutable() // show order status as canceling if frontend initiated cancel - if (!isStatusFinalized(modified["status"])) { + if (!isStatusFinalized(parser.asString(modified["status"]))) { modified["status"] = "BEST_EFFORT_CANCELED" }