Skip to content

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
moo-onthelawn committed Apr 30, 2024
1 parent 2d6300d commit 77b4743
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1876,10 +1876,9 @@ open class StateManagerAdaptor(
fun triggerOrdersPayload(): HumanReadableTriggerOrdersPayload {
val placeOrderPayloads = mutableListOf<HumanReadablePlaceOrderPayload>()
val cancelOrderPayloads = mutableListOf<HumanReadableCancelOrderPayload>()
val triggerOrders = stateMachine.state?.input?.triggerOrders

val marketId = triggerOrders?.marketId ?: throw Exception("marketId is null")
val triggerOrders = requireNotNull(stateMachine.state?.input?.triggerOrders) { "triggerOrders input was null" }

val marketId = requireNotNull(triggerOrders.marketId) { "triggerOrders.marektId was null" }
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 }
Expand Down Expand Up @@ -2307,7 +2306,7 @@ open class StateManagerAdaptor(
)
}

internal fun tracking(eventName: String, params: IMap<String, Any>?) {
internal fun tracking(eventName: String, params: IMap<String, Any?>?) {
val paramsAsString = jsonEncoder.encode(params)
ioImplementations.threading?.async(ThreadingType.main) {
ioImplementations.tracking?.log(eventName, paramsAsString)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1130,7 +1130,7 @@ class V4StateManagerAdaptor(
}

private fun trackOrderClick(
analyticsPayload: IMap<String, Any>?,
analyticsPayload: IMap<String, Any?>?,
analyticsEvent: AnalyticsEvent,
): Double {
val uiClickTimeMs = Clock.System.now().toEpochMilliseconds().toDouble()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ internal open class NetworkSupervisor(
}
}

internal fun tracking(eventName: String, params: IMap<String, Any>?) {
internal fun tracking(eventName: String, params: IMap<String, Any?>?) {
val paramsAsString = helper.jsonEncoder.encode(params)
helper.ioImplementations.threading?.async(ThreadingType.main) {
helper.ioImplementations.tracking?.log(eventName, paramsAsString)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ internal class SubaccountSupervisor(
}

private fun trackOrderClick(
analyticsPayload: IMap<String, Any>?,
analyticsPayload: IMap<String, Any?>?,
analyticsEvent: AnalyticsEvent,
): Double {
val uiClickTimeMs = Clock.System.now().toEpochMilliseconds().toDouble()
Expand Down Expand Up @@ -1019,10 +1019,9 @@ internal class SubaccountSupervisor(
fun triggerOrdersPayload(currentHeight: Int?): HumanReadableTriggerOrdersPayload {
val placeOrderPayloads = mutableListOf<HumanReadablePlaceOrderPayload>()
val cancelOrderPayloads = mutableListOf<HumanReadableCancelOrderPayload>()
val triggerOrders = stateMachine.state?.input?.triggerOrders

val marketId = triggerOrders?.marketId ?: throw Exception("marketId is null")
val triggerOrders = requireNotNull(stateMachine.state?.input?.triggerOrders) { "triggerOrders input was null" }

val marketId = requireNotNull(triggerOrders.marketId) { "triggerOrders.marketId was null" }
val subaccount = stateMachine.state?.subaccount(subaccountNumber)
val position = subaccount?.openPositions?.find { it.id == marketId }
val positionSize = position?.size?.current
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ enum class TriggerOrderAction(val rawValue: String) {
CANCEL("CANCEL"),
CREATE("CREATE"),
;

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

class AnalyticsUtils {
Expand All @@ -35,7 +30,7 @@ class AnalyticsUtils {
*/
fun triggerOrdersAnalyticsPayload(
payload: HumanReadableTriggerOrdersPayload,
): IMap<String, Any>? {
): IMap<String, Any?>? {
val placeOrderPayloads = payload.placeOrderPayloads
val cancelOrderPayloads = payload.cancelOrderPayloads

Expand All @@ -51,7 +46,7 @@ class AnalyticsUtils {
var takeProfitOrderAction: TriggerOrderAction? = null

placeOrderPayloads.forEach { placePayload ->
val orderType = OrderType.invoke(placePayload.type)
val orderType = OrderType(placePayload.type)
if (stopLossOrderTypes.contains(orderType)) {
stopLossOrderPlaceClientId = placePayload.clientId
stopLossOrderAction = TriggerOrderAction.CREATE
Expand All @@ -62,7 +57,7 @@ class AnalyticsUtils {
}

cancelOrderPayloads.forEach { cancelPayload ->
val orderType = OrderType.invoke(cancelPayload.type)
val orderType = OrderType(cancelPayload.type)
if (stopLossOrderTypes.contains(orderType)) {
stopLossOrderCancelClientId = cancelPayload.clientId
stopLossOrderAction = if (stopLossOrderAction == null) {
Expand All @@ -89,7 +84,7 @@ class AnalyticsUtils {
"takeProfitOrderAction" to takeProfitOrderAction?.rawValue,
"takeProfitOrderCancelClientId" to takeProfitOrderCancelClientId,
"takeProfitOrderPlaceClientId" to takeProfitOrderPlaceClientId,
) as IMap<String, Any>?
)
}

/**
Expand Down

0 comments on commit 77b4743

Please sign in to comment.