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 826eca65f..c015f10ba 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/state/manager/V4StateManagerAdaptor.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/state/manager/V4StateManagerAdaptor.kt @@ -1040,6 +1040,7 @@ class V4StateManagerAdaptor( callback, if (isTriggerOrder) { HumanReadableTriggerOrdersPayload( + payload.marketId, listOf(payload), emptyList(), ) @@ -1056,6 +1057,7 @@ class V4StateManagerAdaptor( private fun submitCancelOrder( orderId: String, + marketId: String?, callback: TransactionCallback, payload: HumanReadableCancelOrderPayload, analyticsPayload: IMap?, @@ -1101,6 +1103,7 @@ class V4StateManagerAdaptor( callback, if (isTriggerOrder) { HumanReadableTriggerOrdersPayload( + marketId, emptyList(), listOf(payload), ) @@ -1191,13 +1194,14 @@ class V4StateManagerAdaptor( val payload = cancelOrderPayload(orderId) val subaccount = stateMachine.state?.subaccount(subaccountNumber) val existingOrder = subaccount?.orders?.firstOrNull { it.id == orderId } + val marketId = existingOrder?.marketId val analyticsPayload = analyticsUtils.cancelOrderAnalyticsPayload( payload, existingOrder, ) val uiClickTimeMs = trackOrderClick(analyticsPayload, AnalyticsEvent.TradeCancelOrderClick) - submitCancelOrder(orderId, callback, payload, analyticsPayload, uiClickTimeMs) + submitCancelOrder(orderId, marketId, callback, payload, analyticsPayload, uiClickTimeMs) } override fun commitTriggerOrders(callback: TransactionCallback): HumanReadableTriggerOrdersPayload { @@ -1210,11 +1214,12 @@ class V4StateManagerAdaptor( payload.cancelOrderPayloads.forEach { cancelPayload -> val subaccount = stateMachine.state?.subaccount(subaccountNumber) val existingOrder = subaccount?.orders?.firstOrNull { it.id == cancelPayload.orderId } + val marketId = existingOrder?.marketId val cancelOrderAnalyticsPayload = analyticsUtils.cancelTriggerOrderAnalyticsPayload( cancelPayload, existingOrder, ) - submitCancelOrder(cancelPayload.orderId, callback, cancelPayload, cancelOrderAnalyticsPayload, uiClickTimeMs, true) + submitCancelOrder(cancelPayload.orderId, marketId, callback, cancelPayload, cancelOrderAnalyticsPayload, uiClickTimeMs, true) } payload.placeOrderPayloads.forEach { placePayload -> diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/state/manager/utils/Payloads.kt b/src/commonMain/kotlin/exchange.dydx.abacus/state/manager/utils/Payloads.kt index 657bbf329..bcf2fc3cd 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/state/manager/utils/Payloads.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/state/manager/utils/Payloads.kt @@ -73,7 +73,7 @@ data class HumanReadableCancelOrderPayload( @JsExport @Serializable data class HumanReadableTriggerOrdersPayload( - val marketId: String, + val marketId: String?, val placeOrderPayloads: List, val cancelOrderPayloads: List, ) diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/SubaccountSupervisor.kt b/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/SubaccountSupervisor.kt index 3a445c31e..244ce60f1 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/SubaccountSupervisor.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/SubaccountSupervisor.kt @@ -582,6 +582,7 @@ internal class SubaccountSupervisor( callback, if (isTriggerOrder) { HumanReadableTriggerOrdersPayload( + payload.marketId, listOf(payload), emptyList(), ) @@ -685,17 +686,16 @@ internal class SubaccountSupervisor( private fun submitCancelOrder( orderId: String, + marketId: String?, callback: TransactionCallback, payload: HumanReadableCancelOrderPayload, analyticsPayload: IMap?, + uiClickTimeMs: Double, isTriggerOrder: Boolean = false, ): HumanReadableCancelOrderPayload { val clientId = payload.clientId val string = Json.encodeToString(payload) - val uiClickTimeMs = Clock.System.now().toEpochMilliseconds().toDouble() - tracking(AnalyticsEvent.TradeCancelOrderClick.rawValue, analyticsPayload) - stopWatchingLastOrder() val isShortTermOrder = payload.orderFlags == 0 @@ -731,6 +731,7 @@ internal class SubaccountSupervisor( callback, if (isTriggerOrder) { HumanReadableTriggerOrdersPayload( + marketId, emptyList(), listOf(payload), ) @@ -777,9 +778,11 @@ internal class SubaccountSupervisor( val payload = cancelOrderPayload(orderId) val subaccount = stateMachine.state?.subaccount(subaccountNumber) val existingOrder = subaccount?.orders?.firstOrNull { it.id == orderId } + val marketId = existingOrder?.marketId val analyticsPayload = analyticsUtils.cancelOrderAnalyticsPayload(payload, existingOrder) + val uiClickTimeMs = trackOrderClick(analyticsPayload, AnalyticsEvent.TradeCancelOrderClick) - return submitCancelOrder(orderId, callback, payload, analyticsPayload) + return submitCancelOrder(orderId, marketId, callback, payload, analyticsPayload, uiClickTimeMs) } internal fun commitTriggerOrders( @@ -795,11 +798,12 @@ internal class SubaccountSupervisor( payload.cancelOrderPayloads.forEach { cancelPayload -> val subaccount = stateMachine.state?.subaccount(subaccountNumber) val existingOrder = subaccount?.orders?.firstOrNull { it.id == cancelPayload.orderId } + val marketId = existingOrder?.marketId val cancelOrderAnalyticsPayload = analyticsUtils.cancelTriggerOrderAnalyticsPayload( cancelPayload, existingOrder, ) - submitCancelOrder(cancelPayload.orderId, callback, cancelPayload, cancelOrderAnalyticsPayload, true) + submitCancelOrder(cancelPayload.orderId, marketId, callback, cancelPayload, cancelOrderAnalyticsPayload, uiClickTimeMs, true) } payload.placeOrderPayloads.forEach { placePayload -> diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/utils/AnalyticsUtils.kt b/src/commonMain/kotlin/exchange.dydx.abacus/utils/AnalyticsUtils.kt index c7afaafcd..b1827c285 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/utils/AnalyticsUtils.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/utils/AnalyticsUtils.kt @@ -68,7 +68,7 @@ class AnalyticsUtils { payload: HumanReadableCancelOrderPayload, existingOrder: SubaccountOrder?, ): IMap? { - return cancelOrderAnalyticsPayload(payload, existingOrder, true) + return cancelOrderAnalyticsPayload(payload, existingOrder) } /** @@ -79,7 +79,7 @@ class AnalyticsUtils { payload: HumanReadablePlaceOrderPayload, midMarketPrice: Double?, ): IMap? { - return placeOrderAnalyticsPayload(payload, midMarketPrice, false, true) + return placeOrderAnalyticsPayload(payload, midMarketPrice, false) } /** @@ -87,16 +87,14 @@ class AnalyticsUtils { * @param payload HumanReadablePlaceOrderPayload * @param midMarketPrice Double? * @param isClosePosition Boolean? - * @param fromSlTpDialog Boolean? */ fun placeOrderAnalyticsPayload( payload: HumanReadablePlaceOrderPayload, midMarketPrice: Double?, isClosePosition: Boolean? = false, - fromSlTpDialog: Boolean? = false, // xcxc remove ): IMap? { return ParsingHelper.merge( - formatPlaceOrderPayload(payload, isClosePosition, fromSlTpDialog), + formatPlaceOrderPayload(payload, isClosePosition), iMapOf( "inferredTimeInForce" to calculateOrderTimeInForce(payload), "midMarketPrice" to midMarketPrice, @@ -112,7 +110,6 @@ class AnalyticsUtils { private fun formatPlaceOrderPayload( payload: HumanReadablePlaceOrderPayload, isClosePosition: Boolean? = false, - fromSlTpDialog: Boolean? = false, ): IMap? { return iMapOf( "clientId" to payload.clientId, @@ -121,7 +118,6 @@ class AnalyticsUtils { "goodTilTimeInSeconds" to payload.goodTilTimeInSeconds, "goodTilBlock" to payload.goodTilBlock, "isClosePosition" to isClosePosition, - "fromSlTpDialog" to fromSlTpDialog, "marketId" to payload.marketId, "postOnly" to payload.postOnly, "price" to payload.price, @@ -167,25 +163,21 @@ class AnalyticsUtils { * Format Cancel Order Payload and add order details for `TradeCancelOrder` Analytic Events * @param payload HumanReadableCancelOrderPayload * @param existingOrder SubaccountOrder? - * @param fromSlTpDialog Boolean */ fun cancelOrderAnalyticsPayload( payload: HumanReadableCancelOrderPayload, existingOrder: SubaccountOrder?, - fromSlTpDialog: Boolean? = false, ): IMap? { return ParsingHelper.merge( - formatCancelOrderPayload(payload, fromSlTpDialog), + formatCancelOrderPayload(payload), if (existingOrder != null) formatOrder(existingOrder) else mapOf(), )?.toIMap() } private fun formatCancelOrderPayload( payload: HumanReadableCancelOrderPayload, - fromSlTpDialog: Boolean? = false, ): IMap? { return iMapOf( - "fromSlTpDialog" to fromSlTpDialog, // xcxc remove "subaccountNumber" to payload.subaccountNumber, "clientId" to payload.clientId, "orderId" to payload.orderId,