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 2d5c692
Show file tree
Hide file tree
Showing 7 changed files with 205 additions and 343 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 @@ -76,7 +76,6 @@ import exchange.dydx.abacus.utils.IMap
import exchange.dydx.abacus.utils.IMutableList
import exchange.dydx.abacus.utils.IOImplementations
import exchange.dydx.abacus.utils.JsonEncoder
import exchange.dydx.abacus.utils.Logger
import exchange.dydx.abacus.utils.Parser
import exchange.dydx.abacus.utils.ParsingHelper
import exchange.dydx.abacus.utils.SHORT_TERM_ORDER_DURATION
Expand Down Expand Up @@ -1883,8 +1882,11 @@ open class StateManagerAdaptor(

val subaccountNumber = connectedSubaccountNumber ?: throw Exception("subaccountNumber is null")
val subaccount = stateMachine.state?.subaccount(subaccountNumber) ?: throw Exception("subaccount is null")
val position = subaccount.openPositions?.find { it.id == marketId }
val positionSize = position?.size?.current
val position = subaccount.openPositions?.find { it.id == marketId } ?: throw ParsingException(
ParsingErrorType.MissingRequiredData,
"no open position for $marketId",
)
val positionSize = position.size?.current

fun updateTriggerOrder(triggerOrder: TriggerOrder) {
// Cases
Expand Down Expand Up @@ -2164,8 +2166,8 @@ open class StateManagerAdaptor(

return HumanReadableCancelOrderPayload(
subaccountNumber,
orderId,
type,
orderId,
clientId,
orderFlags,
clobPairId,
Expand Down Expand Up @@ -2307,7 +2309,6 @@ open class StateManagerAdaptor(
ioImplementations.threading?.async(ThreadingType.main) {
ioImplementations.tracking?.log(eventName, paramsAsString)
}
Logger.e { "xcxc $eventName $paramsAsString" }
}

private fun didSetPlaceOrderRecords() {
Expand All @@ -2333,7 +2334,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 +2354,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 @@ -12,6 +12,8 @@ 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
import exchange.dydx.abacus.state.app.adaptors.V4TransactionErrors
import exchange.dydx.abacus.state.manager.configs.V4StateManagerConfigs
import exchange.dydx.abacus.state.model.TransferInputField
Expand Down Expand Up @@ -1007,7 +1009,11 @@ class V4StateManagerAdaptor(
val string = Json.encodeToString(payload)
val marketId = payload.marketId
val position = stateMachine.state?.subaccount(subaccountNumber)?.openPositions?.find { it.id == marketId }
val positionSize = position?.size?.current
?: throw ParsingException(
ParsingErrorType.MissingRequiredData,
"no open position for $marketId",
)
val positionSize = position.size?.current

stopWatchingLastOrder()

Expand Down Expand Up @@ -1062,7 +1068,7 @@ class V4StateManagerAdaptor(

private fun submitCancelOrder(
orderId: String,
marketId: String?,
marketId: String,
callback: TransactionCallback,
payload: HumanReadableCancelOrderPayload,
analyticsPayload: IMap<String, Any>?,
Expand All @@ -1073,7 +1079,11 @@ class V4StateManagerAdaptor(
val string = Json.encodeToString(payload)

val position = stateMachine.state?.subaccount(subaccountNumber)?.openPositions?.find { it.id == marketId }
val positionSize = position?.size?.current
?: throw ParsingException(
ParsingErrorType.MissingRequiredData,
"no open position for $marketId",
)
val positionSize = position.size?.current

val isShortTermOrder = payload.orderFlags == 0

Expand Down Expand Up @@ -1149,9 +1159,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 +1187,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 @@ -1208,8 +1242,11 @@ class V4StateManagerAdaptor(
override fun cancelOrder(orderId: String, callback: TransactionCallback) {
val payload = cancelOrderPayload(orderId)
val subaccount = stateMachine.state?.subaccount(subaccountNumber)
val existingOrder = subaccount?.orders?.firstOrNull { it.id == orderId }
val marketId = existingOrder?.marketId
val existingOrder = subaccount?.orders?.firstOrNull { it.id == orderId } ?: throw ParsingException(
ParsingErrorType.MissingRequiredData,
"no existing order to be cancelled for $orderId",
)
val marketId = existingOrder.marketId
val analyticsPayload = analyticsUtils.cancelOrderAnalyticsPayload(
payload,
existingOrder,
Expand All @@ -1229,12 +1266,24 @@ 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
?: throw ParsingException(
ParsingErrorType.MissingRequiredData,
"no existing order to be cancelled for $cancelPayload.orderId",
)
val marketId = existingOrder.marketId
val cancelOrderAnalyticsPayload = analyticsUtils.cancelOrderAnalyticsPayload(
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 @@ -63,8 +63,8 @@ data class HumanReadablePlaceOrderPayload(
@Serializable
data class HumanReadableCancelOrderPayload(
val subaccountNumber: Int,
val orderId: String,
val type: String,
val orderId: String,
val clientId: Int,
val orderFlags: Int,
val clobPairId: Int,
Expand All @@ -75,7 +75,7 @@ data class HumanReadableCancelOrderPayload(
@JsExport
@Serializable
data class HumanReadableTriggerOrdersPayload(
val marketId: String?,
val marketId: String,
val positionSize: Double?,
val placeOrderPayloads: List<HumanReadablePlaceOrderPayload>,
val cancelOrderPayloads: List<HumanReadableCancelOrderPayload>,
Expand Down
Loading

0 comments on commit 2d5c692

Please sign in to comment.