-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
v1.6.53: add analytics for SL/TP #325
v1.6.53: add analytics for SL/TP #325
Conversation
4fa7d8e
to
72873a3
Compare
c843288
to
a47d64e
Compare
a47d64e
to
2d5c692
Compare
cf8e211
to
6e5458c
Compare
@@ -1880,10 +1878,15 @@ open class StateManagerAdaptor( | |||
val cancelOrderPayloads = mutableListOf<HumanReadableCancelOrderPayload>() | |||
val triggerOrders = stateMachine.state?.input?.triggerOrders | |||
|
|||
val marketId = triggerOrders?.marketId ?: throw Exception("marketId is null") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
kotlin tip: we can instead enforce triggerOrders
is non-null by doing:
val triggerOrders = requireNotNull(stateMachine.state?.input?.triggerOrders) { "triggerOrders input was null" }
then we don't need to do null checks on it later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
part of me wants to write a codemod to go through the whole repo to replace all of the throwException
s
src/commonMain/kotlin/exchange.dydx.abacus/utils/AnalyticsUtils.kt
Outdated
Show resolved
Hide resolved
var takeProfitOrderAction: TriggerOrderAction? = null | ||
|
||
placeOrderPayloads.forEach { placePayload -> | ||
val orderType = OrderType.invoke(placePayload.type) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.invoke()
can be called like a constructor: OrderType(placePayload.type)
"positionSize" to payload.positionSize, | ||
"stopLossOrderAction" to stopLossOrderAction?.rawValue, | ||
"takeProfitOrderAction" to takeProfitOrderAction?.rawValue, | ||
) as IMap<String, Any>? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this cast necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah good point - should be fine if I just update the return type to be IMap<String, Any?>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh actually I see why we have all these casts in the file - it's because ParsingHelper.merge
expects and returns Map<String, Any>?
instead of Map<String, Any?>
. Given how widely this is used, it seems like a pretty beefy change to fix, so I might just keep it like this for now 😢
val submitTimeMs = Clock.System.now().toEpochMilliseconds().toDouble() | ||
val uiDelayTimeMs = submitTimeMs - uiClickTimeMs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I missed this before, why are we converting these timestamps to Double? Shouldn't we be using Long?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm unsure - this is just the existing pattern; cc @aforaleka who may have more context (I think you added these values for analytics?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i only looked at the screenshots and the output looks good from analytics perspective
Summary of Logging Added
TriggerOrderClick
event withmarketId
positionSize: Double
[takeProfit/stopLoss]OrderAction: 'CREATE' | 'CANCEL' | 'REPLACE' | null (if no action)
[takeProfit/stopLoss]Order[Cancel/Place]ClientId: Int
Trade[Cancel/Place]Order
logged with existing params andfromSlTpDialog: true
Trade[Cancel/Place]OrderConfirmed
logged with existing params andfromSlTpDialog: true
Trade[Cancel/Place]OrderSubmissionConfirmed
logged with existing params andfromSlTpDialog: true
Trade[Cancel/Place]OrderFailed
logged with existing params andfromSlTpDialog: true
Testing
Built locally on web and logged output.
Code
New behavior: single
TriggerOrderClick
firedOld behavior:
TradePlaceOrder
andTradeCancelOrder
firedNew behavior:
TradePlaceOrder
/TradeCancelOrder
withfromSlTp: true
New behavior:
TradePlaceOrderSubmissionConfirmed
/TradeCancelOrderSubmissionConfirmed
withfromSlTp: true
New behavior:
TradePlaceOrderSubmissionFailed
/TradeCancelOrderSubmissionFailed
withfromSlTp: true
New behavior:
TradeCancelOrderConfirmed
/TradePlaceOrderConfirmed
withfromSlTp: true
triggerOrdersAnalyticsPayload
TriggerOrderClick
event; other events continue to useplaceOrderAnalyticsPayload
/cancelOrderAnalyticsPayload
marketId
,(total)PositionSize
,stopLossOrderAction
/takeProfitOrderAction
(REPLACE / CANCEL / CREATE),stopLossOrder[Cancel/Place]ClientId
,takeProfitOrder[Cancel/Place]ClientId
PlaceOrderRecord
/CancelOrderRecord
: addedfromSlTp
to pass toTrade[Cancel/Place]OrderConfirmed
HumanReadableTriggerOrdersPayload
: addmarketId
,positionSize
fortriggerOrdersAnalyticsPayload
HumanReadableCancelOrderPayload
: addtype