diff --git a/build.gradle.kts b/build.gradle.kts index d92b6f41b..21d5e2540 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -48,7 +48,7 @@ allprojects { } group = "exchange.dydx.abacus" -version = "1.6.37" +version = "1.6.38" repositories { google() diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/state/manager/V4StateManagerAdaptor.kt b/src/commonMain/kotlin/exchange.dydx.abacus/state/manager/V4StateManagerAdaptor.kt index e1baf727d..db2afa213 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/state/manager/V4StateManagerAdaptor.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/state/manager/V4StateManagerAdaptor.kt @@ -1174,7 +1174,13 @@ class V4StateManagerAdaptor( override fun cancelOrder(orderId: String, callback: TransactionCallback) { val payload = cancelOrderPayload(orderId) - val analyticsPayload = analyticsUtils.formatCancelOrderPayload(payload) + val subaccount = stateMachine.state?.subaccount(subaccountNumber) + val existingOrder = subaccount?.orders?.firstOrNull { it.id == orderId } + val analyticsPayload = ParsingHelper.merge( + analyticsUtils.formatCancelOrderPayload(payload), + if (existingOrder != null) analyticsUtils.formatOrder(existingOrder) else mapOf() + )?.toIMap() + submitCancelOrder(orderId, callback, payload, analyticsPayload) } diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/utils/AnalyticsUtils.kt b/src/commonMain/kotlin/exchange.dydx.abacus/utils/AnalyticsUtils.kt index 433f5c797..2360491db 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/utils/AnalyticsUtils.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/utils/AnalyticsUtils.kt @@ -31,11 +31,40 @@ class AnalyticsUtils { "size" to payload.size, "subaccountNumber" to payload.subaccountNumber, "timeInForce" to payload.timeInForce, + "inferredTimeInForce" to calculateOrderTimeInForce(payload), "triggerPrice" to payload.triggerPrice, "type" to payload.type, ) as IMap? } + /** + * Infer time in force from order params for analytics, mirroring v4-clients + * @param payload HumanReadablePlaceOrderPayload + */ + private fun calculateOrderTimeInForce( + payload: HumanReadablePlaceOrderPayload + ): String? { + return when (payload.type) { + "MARKET" -> payload.timeInForce ?: "FOK" + "LIMIT" -> { + when (payload.timeInForce) { + "GTT" -> if (payload.postOnly == true) "POST_ONLY" else "GTT" + else -> payload.timeInForce + } + } + + "STOP_LIMIT", "TAKE_PROFIT" -> { + when (payload.execution) { + "DEFAULT" -> "GTT" + else -> payload.execution + } + } + + "STOP_MARKET", "TAKE_PROFIT_MARKET" -> payload.execution + else -> payload.timeInForce ?: payload.execution + } + } + /** * Format Cancel Order Payload for `TradeCancelOrder` Analytic Event * @param payload HumanReadableCancelOrderPayload diff --git a/v4_abacus.podspec b/v4_abacus.podspec index d792e5a52..c5a38b6be 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.6.37' + spec.version = '1.6.38' spec.homepage = 'https://github.com/dydxprotocol/v4-abacus' spec.source = { :http=> ''} spec.authors = ''