Skip to content

Commit

Permalink
Merge branch 'main' into mulan/ct-783-new-analytics-clickevent-for-sltp
Browse files Browse the repository at this point in the history
  • Loading branch information
moo-onthelawn committed Apr 30, 2024
2 parents d396798 + 0d50ae9 commit 8b8260e
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 318 deletions.
289 changes: 0 additions & 289 deletions detekt-baseline.xml

Large diffs are not rendered by default.

18 changes: 17 additions & 1 deletion detekt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,20 @@ naming:
# some of our package folders are structured /exchange.dydx.abacus instead of:
# /exchange -> /dydx -> /abacus
# didn't seem worth the potential thrash in PRs to fix (feel free to fix if you feel differently)
active: false
active: false

complexity:
CognitiveComplexMethod:
active: false
ComplexCondition:
active: false
CyclomaticComplexMethod:
active: false
LongParameterList:
active: false
LargeClass:
threshold: 1000 # up from 600
LongMethod:
threshold: 100 # up from 60
TooManyFunctions:
active: false
Original file line number Diff line number Diff line change
Expand Up @@ -2333,7 +2333,11 @@ open class StateManagerAdaptor(
val interval = Clock.System.now().toEpochMilliseconds()
.toDouble() - placeOrderRecord.timestampInMilliseconds
tracking(
if (placeOrderRecord.isTriggerOrder) AnalyticsEvent.TriggerPlaceOrderConfirmed.rawValue else AnalyticsEvent.TradePlaceOrderConfirmed.rawValue,
if (placeOrderRecord.isTriggerOrder) {
AnalyticsEvent.TriggerPlaceOrderConfirmed.rawValue
} else {
AnalyticsEvent.TradePlaceOrderConfirmed.rawValue
},
ParsingHelper.merge(
trackingParams(interval),
orderAnalyticsPayload,
Expand All @@ -2349,7 +2353,11 @@ open class StateManagerAdaptor(
val interval = Clock.System.now().toEpochMilliseconds()
.toDouble() - cancelOrderRecord.timestampInMilliseconds
tracking(
if (cancelOrderRecord.isTriggerOrder) AnalyticsEvent.TriggerCancelOrderConfirmed.rawValue else AnalyticsEvent.TradeCancelOrderConfirmed.rawValue,
if (cancelOrderRecord.isTriggerOrder) {
AnalyticsEvent.TriggerCancelOrderConfirmed.rawValue
} else {
AnalyticsEvent.TradeCancelOrderConfirmed.rawValue
},
ParsingHelper.merge(
trackingParams(interval),
orderAnalyticsPayload,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1149,9 +1149,17 @@ class V4StateManagerAdaptor(

tracking(
if (isCancel) {
if (isTriggerOrder) AnalyticsEvent.TriggerCancelOrder.rawValue else AnalyticsEvent.TradeCancelOrder.rawValue
if (isTriggerOrder) {
AnalyticsEvent.TriggerCancelOrder.rawValue
} else {
AnalyticsEvent.TradeCancelOrder.rawValue
}
} else {
if (isTriggerOrder) AnalyticsEvent.TriggerPlaceOrder.rawValue else AnalyticsEvent.TradePlaceOrder.rawValue
if (isTriggerOrder) {
AnalyticsEvent.TriggerPlaceOrder.rawValue
} else {
AnalyticsEvent.TradePlaceOrder.rawValue
}
},
ParsingHelper.merge(uiTrackingParams(uiDelayTimeMs), analyticsPayload)
?.toIMap(),
Expand All @@ -1169,18 +1177,34 @@ class V4StateManagerAdaptor(
if (error != null) {
tracking(
if (isCancel) {
if (isTriggerOrder) AnalyticsEvent.TriggerCancelOrderSubmissionFailed.rawValue else AnalyticsEvent.TradeCancelOrderSubmissionFailed.rawValue
if (isTriggerOrder) {
AnalyticsEvent.TriggerCancelOrderSubmissionFailed.rawValue
} else {
AnalyticsEvent.TradeCancelOrderSubmissionFailed.rawValue
}
} else {
if (isTriggerOrder) AnalyticsEvent.TriggerPlaceOrderSubmissionFailed.rawValue else AnalyticsEvent.TradePlaceOrderSubmissionFailed.rawValue
if (isTriggerOrder) {
AnalyticsEvent.TriggerPlaceOrderSubmissionFailed.rawValue
} else {
AnalyticsEvent.TradePlaceOrderSubmissionFailed.rawValue
}
},
ParsingHelper.merge(errorTrackingParams(error), analyticsPayload)?.toIMap(),
)
} else {
tracking(
if (isCancel) {
if (isTriggerOrder) AnalyticsEvent.TriggerCancelOrderSubmissionConfirmed.rawValue else AnalyticsEvent.TradeCancelOrderSubmissionConfirmed.rawValue
if (isTriggerOrder) {
AnalyticsEvent.TriggerCancelOrderSubmissionConfirmed.rawValue
} else {
AnalyticsEvent.TradeCancelOrderSubmissionConfirmed.rawValue
}
} else {
if (isTriggerOrder) AnalyticsEvent.TriggerPlaceOrderSubmissionConfirmed.rawValue else AnalyticsEvent.TradePlaceOrderSubmissionConfirmed.rawValue
if (isTriggerOrder) {
AnalyticsEvent.TriggerPlaceOrderSubmissionConfirmed.rawValue
} else {
AnalyticsEvent.TradePlaceOrderSubmissionConfirmed.rawValue
}
},
analyticsPayload,
)
Expand Down Expand Up @@ -1234,7 +1258,15 @@ class V4StateManagerAdaptor(
cancelPayload,
existingOrder,
)
submitCancelOrder(cancelPayload.orderId, marketId, callback, cancelPayload, cancelOrderAnalyticsPayload, uiClickTimeMs, true)
submitCancelOrder(
cancelPayload.orderId,
marketId,
callback,
cancelPayload,
cancelOrderAnalyticsPayload,
uiClickTimeMs,
true,
)
}

payload.placeOrderPayloads.forEach { placePayload ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,11 @@ internal class SubaccountSupervisor(
val interval = Clock.System.now().toEpochMilliseconds()
.toDouble() - placeOrderRecord.timestampInMilliseconds
tracking(
if (placeOrderRecord.isTriggerOrder) AnalyticsEvent.TriggerPlaceOrderConfirmed.rawValue else AnalyticsEvent.TradePlaceOrderConfirmed.rawValue,
if (placeOrderRecord.isTriggerOrder) {
AnalyticsEvent.TriggerPlaceOrderConfirmed.rawValue
} else {
AnalyticsEvent.TradePlaceOrderConfirmed.rawValue
},
ParsingHelper.merge(
trackingParams(interval),
orderAnalyticsPayload,
Expand All @@ -322,7 +326,11 @@ internal class SubaccountSupervisor(
val interval = Clock.System.now().toEpochMilliseconds()
.toDouble() - cancelOrderRecord.timestampInMilliseconds
tracking(
if (cancelOrderRecord.isTriggerOrder) AnalyticsEvent.TriggerCancelOrderConfirmed.rawValue else AnalyticsEvent.TradeCancelOrderConfirmed.rawValue,
if (cancelOrderRecord.isTriggerOrder) {
AnalyticsEvent.TriggerCancelOrderConfirmed.rawValue
} else {
AnalyticsEvent.TradeCancelOrderConfirmed.rawValue
},
ParsingHelper.merge(
trackingParams(interval),
orderAnalyticsPayload,
Expand Down Expand Up @@ -659,9 +667,17 @@ internal class SubaccountSupervisor(

tracking(
if (isCancel) {
if (isTriggerOrder) AnalyticsEvent.TriggerCancelOrder.rawValue else AnalyticsEvent.TradeCancelOrder.rawValue
if (isTriggerOrder) {
AnalyticsEvent.TriggerCancelOrder.rawValue
} else {
AnalyticsEvent.TradeCancelOrder.rawValue
}
} else {
if (isTriggerOrder) AnalyticsEvent.TriggerPlaceOrder.rawValue else AnalyticsEvent.TradePlaceOrder.rawValue
if (isTriggerOrder) {
AnalyticsEvent.TriggerPlaceOrder.rawValue
} else {
AnalyticsEvent.TradePlaceOrder.rawValue
}
},
ParsingHelper.merge(uiTrackingParams(uiDelayTimeMs), analyticsPayload)
?.toIMap(),
Expand All @@ -679,18 +695,34 @@ internal class SubaccountSupervisor(
if (error != null) {
tracking(
if (isCancel) {
if (isTriggerOrder) AnalyticsEvent.TriggerCancelOrderSubmissionFailed.rawValue else AnalyticsEvent.TradeCancelOrderSubmissionFailed.rawValue
if (isTriggerOrder) {
AnalyticsEvent.TriggerCancelOrderSubmissionFailed.rawValue
} else {
AnalyticsEvent.TradeCancelOrderSubmissionFailed.rawValue
}
} else {
if (isTriggerOrder) AnalyticsEvent.TriggerPlaceOrderSubmissionFailed.rawValue else AnalyticsEvent.TradePlaceOrderSubmissionFailed.rawValue
if (isTriggerOrder) {
AnalyticsEvent.TriggerPlaceOrderSubmissionFailed.rawValue
} else {
AnalyticsEvent.TradePlaceOrderSubmissionFailed.rawValue
}
},
ParsingHelper.merge(errorTrackingParams(error), analyticsPayload)?.toIMap(),
)
} else {
tracking(
if (isCancel) {
if (isTriggerOrder) AnalyticsEvent.TriggerCancelOrderSubmissionConfirmed.rawValue else AnalyticsEvent.TradeCancelOrderSubmissionConfirmed.rawValue
if (isTriggerOrder) {
AnalyticsEvent.TriggerCancelOrderSubmissionConfirmed.rawValue
} else {
AnalyticsEvent.TradeCancelOrderSubmissionConfirmed.rawValue
}
} else {
if (isTriggerOrder) AnalyticsEvent.TriggerPlaceOrderSubmissionConfirmed.rawValue else AnalyticsEvent.TradePlaceOrderSubmissionConfirmed.rawValue
if (isTriggerOrder) {
AnalyticsEvent.TriggerPlaceOrderSubmissionConfirmed.rawValue
} else {
AnalyticsEvent.TradePlaceOrderSubmissionConfirmed.rawValue
}
},
analyticsPayload,
)
Expand Down Expand Up @@ -821,7 +853,15 @@ internal class SubaccountSupervisor(
cancelPayload,
existingOrder,
)
submitCancelOrder(cancelPayload.orderId, marketId, callback, cancelPayload, cancelOrderAnalyticsPayload, uiClickTimeMs, true)
submitCancelOrder(
cancelPayload.orderId,
marketId,
callback,
cancelPayload,
cancelOrderAnalyticsPayload,
uiClickTimeMs,
true,
)
}

payload.placeOrderPayloads.forEach { placePayload ->
Expand Down
36 changes: 26 additions & 10 deletions src/commonMain/kotlin/exchange.dydx.abacus/utils/AnalyticsUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,18 @@ import exchange.dydx.abacus.state.manager.HumanReadablePlaceOrderPayload
import exchange.dydx.abacus.state.manager.HumanReadableTriggerOrdersPayload
import kollections.toIMap

enum class OrderAction(val rawValue: String) {
replace("REPLACE"),
cancel("CANCEL"),
create("CREATE"),
@JsExport
@Serializable
enum class TriggerOrderAction(val rawValue: String) {
REPLACE("REPLACE"),
CANCEL("CANCEL"),
CREATE("CREATE"),
;

companion object {
operator fun invoke(rawValue: String?) =
TriggerOrderAction.values().firstOrNull { it.rawValue == rawValue }
}
}

class AnalyticsUtils {
Expand All @@ -32,24 +40,32 @@ class AnalyticsUtils {
val stopLossOrderTypes = listOf(OrderType.stopMarket, OrderType.stopLimit)
val takeProfitOrderTypes = listOf(OrderType.takeProfitMarket, OrderType.takeProfitLimit)

var stopLossOrderAction: OrderAction? = null
var takeProfitOrderAction: OrderAction? = null
var stopLossOrderAction: TriggerOrderAction? = null
var takeProfitOrderAction: TriggerOrderAction? = null

placeOrderPayloads.forEach { placePayload ->
val orderType = OrderType.invoke(placePayload.type)
if (stopLossOrderTypes.contains(orderType)) {
stopLossOrderAction = OrderAction.create
stopLossOrderAction = TriggerOrderAction.CREATE
} else if (takeProfitOrderTypes.contains(orderType)) {
takeProfitOrderAction = OrderAction.create
takeProfitOrderAction = TriggerOrderAction.CREATE
}
}

cancelOrderPayloads.forEach { cancelPayload ->
val orderType = OrderType.invoke(cancelPayload.type)
if (stopLossOrderTypes.contains(orderType)) {
stopLossOrderAction = if (stopLossOrderAction == null) OrderAction.cancel else OrderAction.replace
stopLossOrderAction = if (stopLossOrderAction == null) {
TriggerOrderAction.CANCEL
} else {
TriggerOrderAction.REPLACE
}
} else if (takeProfitOrderTypes.contains(orderType)) {
takeProfitOrderAction = if (takeProfitOrderAction == null) OrderAction.cancel else OrderAction.replace
takeProfitOrderAction = if (takeProfitOrderAction == null) {
TriggerOrderAction.CANCEL
} else {
TriggerOrderAction.REPLACE
}
}
}

Expand Down

0 comments on commit 8b8260e

Please sign in to comment.