diff --git a/build.gradle.kts b/build.gradle.kts index b29aac99d..0dce37b2f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -52,7 +52,7 @@ allprojects { } group = "exchange.dydx.abacus" -version = "1.13.33" +version = "1.13.34" repositories { google() diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/SubaccountTransactionSupervisor.kt b/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/SubaccountTransactionSupervisor.kt index 642f60f23..63b702ae7 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/SubaccountTransactionSupervisor.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/SubaccountTransactionSupervisor.kt @@ -6,9 +6,11 @@ import exchange.dydx.abacus.output.account.TransferRecordType import exchange.dydx.abacus.output.input.OrderSide import exchange.dydx.abacus.output.input.OrderStatus import exchange.dydx.abacus.protocols.AnalyticsEvent +import exchange.dydx.abacus.protocols.LocalTimerProtocol import exchange.dydx.abacus.protocols.ThreadingType import exchange.dydx.abacus.protocols.TransactionCallback import exchange.dydx.abacus.protocols.TransactionType +import exchange.dydx.abacus.protocols.run import exchange.dydx.abacus.responses.ParsingError import exchange.dydx.abacus.responses.ParsingErrorType import exchange.dydx.abacus.responses.ParsingException @@ -29,10 +31,12 @@ import exchange.dydx.abacus.state.model.findOrder import exchange.dydx.abacus.state.model.orderCanceled import exchange.dydx.abacus.utils.AnalyticsUtils import exchange.dydx.abacus.utils.CONDITIONAL_ORDER_FLAGS +import exchange.dydx.abacus.utils.CoroutineTimer import exchange.dydx.abacus.utils.IMap import exchange.dydx.abacus.utils.IMutableList import exchange.dydx.abacus.utils.Logger import exchange.dydx.abacus.utils.NUM_PARENT_SUBACCOUNTS +import exchange.dydx.abacus.utils.POST_TRANSFER_PLACE_ORDER_DELAY import exchange.dydx.abacus.utils.ParsingHelper import exchange.dydx.abacus.utils.SHORT_TERM_ORDER_FLAGS import exchange.dydx.abacus.utils.iMapOf @@ -97,6 +101,14 @@ internal class SubaccountTransactionSupervisor( private val cancelingOrphanedTriggerOrders = mutableSetOf() private val reclaimingChildSubaccountNumbers = mutableSetOf() + private var isolatedMarginOrderTimer: LocalTimerProtocol? = null + set(value) { + if (field !== value) { + field?.cancel() + field = value + } + } + private fun fromSlTpDialogParams(fromSlTpDialog: Boolean): IMap { return iMapOf( "fromSlTpDialog" to fromSlTpDialog, @@ -652,13 +664,18 @@ internal class SubaccountTransactionSupervisor( val isolatedMarginTransactionCallback = { response: String? -> val error = parseTransactionResponse(response) if (error == null) { - submitTransaction( - transactionType = TransactionType.PlaceOrder, - transactionPayloadString = string, - onSubmitTransaction = onSubmitOrderTransaction, - transactionCallback = orderTransactionCallback, - useTransactionQueue = useTransactionQueue, - ) + // Return submitTransaction after a delay to ensure the transfer is confirmed + val timer = helper.ioImplementations.timer ?: CoroutineTimer.instance + + isolatedMarginOrderTimer = timer.run(POST_TRANSFER_PLACE_ORDER_DELAY) { + submitTransaction( + transactionType = TransactionType.PlaceOrder, + transactionPayloadString = string, + onSubmitTransaction = onSubmitOrderTransaction, + transactionCallback = orderTransactionCallback, + useTransactionQueue = useTransactionQueue, + ) + } } else { // remove pending isolated order since it will not be placed val isolatedOrderRecord = this.pendingIsolatedOrderRecords.firstOrNull { diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/utils/Constants.kt b/src/commonMain/kotlin/exchange.dydx.abacus/utils/Constants.kt index 04cbcdb78..1af2fb9e6 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/utils/Constants.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/utils/Constants.kt @@ -18,6 +18,7 @@ internal const val MAX_FREE_COLLATERAL_BUFFER_PERCENT = 0.95 internal const val MAX_LEVERAGE_BUFFER_PERCENT = 0.98 internal const val MARGIN_COLLATERALIZATION_CHECK_BUFFER = 0.01; internal const val DEFAULT_TARGET_LEVERAGE = 2.0; +internal const val POST_TRANSFER_PLACE_ORDER_DELAY = 0.25; // Order flags internal const val SHORT_TERM_ORDER_FLAGS = 0 diff --git a/v4_abacus.podspec b/v4_abacus.podspec index 62bc0e5c0..991936106 100644 --- a/v4_abacus.podspec +++ b/v4_abacus.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |spec| spec.name = 'v4_abacus' - spec.version = '1.13.33' + spec.version = '1.13.34' spec.homepage = 'https://github.com/dydxprotocol/v4-abacus' spec.source = { :http=> ''} spec.authors = ''