Skip to content

Commit

Permalink
fix: add 250ms delay to order placement (#759)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredvu authored Nov 20, 2024
1 parent b13648b commit 72222b8
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 9 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ allprojects {
}

group = "exchange.dydx.abacus"
version = "1.13.33"
version = "1.13.34"

repositories {
google()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -97,6 +101,14 @@ internal class SubaccountTransactionSupervisor(
private val cancelingOrphanedTriggerOrders = mutableSetOf<String>()
private val reclaimingChildSubaccountNumbers = mutableSetOf<Int>()

private var isolatedMarginOrderTimer: LocalTimerProtocol? = null
set(value) {
if (field !== value) {
field?.cancel()
field = value
}
}

private fun fromSlTpDialogParams(fromSlTpDialog: Boolean): IMap<String, Any> {
return iMapOf(
"fromSlTpDialog" to fromSlTpDialog,
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion v4_abacus.podspec
Original file line number Diff line number Diff line change
@@ -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 = ''
Expand Down

0 comments on commit 72222b8

Please sign in to comment.