From c68efa0ff1273b6bd41b77ba4f9099c08ccb63dc Mon Sep 17 00:00:00 2001 From: aforaleka Date: Wed, 18 Sep 2024 18:59:51 -0400 Subject: [PATCH] close all positions return payload --- .../state/manager/AsyncAbacusStateManagerProtocol.kt | 2 +- .../state/v2/manager/AsyncAbacusStateManagerV2.kt | 5 +++-- .../state/v2/manager/StateManagerAdaptorV2.kt | 4 ++-- .../state/v2/supervisor/AccountSupervisor.kt | 4 ++-- .../state/v2/supervisor/AccountsSupervisor.kt | 4 ++-- 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/state/manager/AsyncAbacusStateManagerProtocol.kt b/src/commonMain/kotlin/exchange.dydx.abacus/state/manager/AsyncAbacusStateManagerProtocol.kt index 76ae9413f..b3cc627ff 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/state/manager/AsyncAbacusStateManagerProtocol.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/state/manager/AsyncAbacusStateManagerProtocol.kt @@ -88,7 +88,7 @@ interface AsyncAbacusStateManagerProtocol { fun faucet(amount: Double, callback: TransactionCallback) fun cancelOrder(orderId: String, callback: TransactionCallback) fun cancelAllOrders(marketId: String?, callback: TransactionCallback) - fun closeAllPositions(callback: TransactionCallback) + fun closeAllPositions(callback: TransactionCallback): HumanReadableCloseAllPositionsPayload? // Bridge functions. // If client is not using cancelOrder function, it should call orderCanceled function with diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/manager/AsyncAbacusStateManagerV2.kt b/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/manager/AsyncAbacusStateManagerV2.kt index fbc414c2a..a8b5123be 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/manager/AsyncAbacusStateManagerV2.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/manager/AsyncAbacusStateManagerV2.kt @@ -630,12 +630,13 @@ class AsyncAbacusStateManagerV2( } } - override fun closeAllPositions(callback: TransactionCallback) { - try { + override fun closeAllPositions(callback: TransactionCallback): HumanReadableCloseAllPositionsPayload? { + return try { adaptor?.closeAllPositions(callback) } catch (e: Exception) { val error = V4TransactionErrors.error(null, e.toString()) callback(false, error, null) + null } } diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/manager/StateManagerAdaptorV2.kt b/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/manager/StateManagerAdaptorV2.kt index 0c78bcd25..d8782dc35 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/manager/StateManagerAdaptorV2.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/manager/StateManagerAdaptorV2.kt @@ -615,8 +615,8 @@ internal class StateManagerAdaptorV2( accounts.cancelAllOrders(marketId, callback) } - internal fun closeAllPositions(callback: TransactionCallback) { - accounts.closeAllPositions(currentHeight, callback) + internal fun closeAllPositions(callback: TransactionCallback): HumanReadableCloseAllPositionsPayload? { + return accounts.closeAllPositions(currentHeight, callback) } internal fun orderCanceled(orderId: String) { diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/AccountSupervisor.kt b/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/AccountSupervisor.kt index 9118726ab..1a3dcec02 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/AccountSupervisor.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/AccountSupervisor.kt @@ -1214,8 +1214,8 @@ internal fun AccountSupervisor.cancelAllOrders(marketId: String?, callback: Tran subaccount?.cancelAllOrders(marketId, callback) } -internal fun AccountSupervisor.closeAllPositions(currentHeight: Int?, callback: TransactionCallback) { - subaccount?.closeAllPositions(currentHeight, callback) +internal fun AccountSupervisor.closeAllPositions(currentHeight: Int?, callback: TransactionCallback): HumanReadableCloseAllPositionsPayload? { + return subaccount?.closeAllPositions(currentHeight, callback) } internal fun AccountSupervisor.orderCanceled(orderId: String) { diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/AccountsSupervisor.kt b/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/AccountsSupervisor.kt index 9b33a07e9..0fb8da7b0 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/AccountsSupervisor.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/AccountsSupervisor.kt @@ -366,8 +366,8 @@ internal fun AccountsSupervisor.cancelAllOrders(marketId: String?, callback: Tra account?.cancelAllOrders(marketId, callback) } -internal fun AccountsSupervisor.closeAllPositions(currentHeight: Int?, callback: TransactionCallback) { - account?.closeAllPositions(currentHeight, callback) +internal fun AccountsSupervisor.closeAllPositions(currentHeight: Int?, callback: TransactionCallback): HumanReadableCloseAllPositionsPayload? { + return account?.closeAllPositions(currentHeight, callback) } internal fun AccountsSupervisor.orderCanceled(orderId: String) {