Skip to content

Commit

Permalink
add missing fields in place/cancel order events
Browse files Browse the repository at this point in the history
  • Loading branch information
aforaleka committed Apr 11, 2024
1 parent 7cc9fad commit ee563e2
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 3 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ allprojects {
}

group = "exchange.dydx.abacus"
version = "1.6.37"
version = "1.6.38"

repositories {
google()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
29 changes: 29 additions & 0 deletions src/commonMain/kotlin/exchange.dydx.abacus/utils/AnalyticsUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Any>?
}

/**
* 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
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.6.37'
spec.version = '1.6.38'
spec.homepage = 'https://github.com/dydxprotocol/v4-abacus'
spec.source = { :http=> ''}
spec.authors = ''
Expand Down

0 comments on commit ee563e2

Please sign in to comment.