Skip to content

Commit

Permalink
rename
Browse files Browse the repository at this point in the history
  • Loading branch information
aforaleka committed Aug 30, 2024
1 parent 5bb227f commit 1e6445e
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ enum class AnalyticsEvent {
// Trade
TradePlaceOrderClick,
TradeCancelOrderClick,
TradeCancelAllOrdersClick,
TradePlaceOrder,
TradeCancelOrder,
TradePlaceOrderSubmissionConfirmed,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ interface AsyncAbacusStateManagerProtocol {
fun closePositionPayload(): HumanReadablePlaceOrderPayload?
fun triggerOrdersPayload(): HumanReadableTriggerOrdersPayload?
fun cancelOrderPayload(orderId: String): HumanReadableCancelOrderPayload?
fun cancelOrdersPayload(marketId: String?): HumanReadableCancelMultipleOrdersPayload?
fun cancelAllOrdersPayload(marketId: String?): HumanReadableCancelAllOrdersPayload?
fun depositPayload(): HumanReadableDepositPayload?
fun withdrawPayload(): HumanReadableWithdrawPayload?
fun subaccountTransferPayload(): HumanReadableSubaccountTransferPayload?
Expand All @@ -81,7 +81,7 @@ interface AsyncAbacusStateManagerProtocol {
// Commit changes with params
fun faucet(amount: Double, callback: TransactionCallback)
fun cancelOrder(orderId: String, callback: TransactionCallback)
fun cancelOrders(marketId: String?, callback: TransactionCallback)
fun cancelAllOrders(marketId: String?, callback: TransactionCallback)

// Bridge functions.
// If client is not using cancelOrder function, it should call orderCanceled function with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ data class HumanReadableCancelOrderPayload(

@JsExport
@Serializable
data class HumanReadableCancelMultipleOrdersPayload(
data class HumanReadableCancelAllOrdersPayload(
val marketId: String?,
val payloads: IList<HumanReadableCancelOrderPayload>,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import exchange.dydx.abacus.state.manager.ConfigFile
import exchange.dydx.abacus.state.manager.GasToken
import exchange.dydx.abacus.state.manager.HistoricalPnlPeriod
import exchange.dydx.abacus.state.manager.HistoricalTradingRewardsPeriod
import exchange.dydx.abacus.state.manager.HumanReadableCancelMultipleOrdersPayload
import exchange.dydx.abacus.state.manager.HumanReadableCancelAllOrdersPayload
import exchange.dydx.abacus.state.manager.HumanReadableCancelOrderPayload
import exchange.dydx.abacus.state.manager.HumanReadableDepositPayload
import exchange.dydx.abacus.state.manager.HumanReadablePlaceOrderPayload
Expand Down Expand Up @@ -504,8 +504,8 @@ class AsyncAbacusStateManagerV2(
return adaptor?.cancelOrderPayload(orderId)
}

override fun cancelOrdersPayload(marketId: String?): HumanReadableCancelMultipleOrdersPayload? {
return adaptor?.cancelOrdersPayload(marketId)
override fun cancelAllOrdersPayload(marketId: String?): HumanReadableCancelAllOrdersPayload? {
return adaptor?.cancelAllOrdersPayload(marketId)
}

override fun triggerOrdersPayload(): HumanReadableTriggerOrdersPayload? {
Expand Down Expand Up @@ -608,9 +608,9 @@ class AsyncAbacusStateManagerV2(
}
}

override fun cancelOrders(marketId: String?, callback: TransactionCallback) {
override fun cancelAllOrders(marketId: String?, callback: TransactionCallback) {
try {
adaptor?.cancelOrders(marketId, callback)
adaptor?.cancelAllOrders(marketId, callback)
} catch (e: Exception) {
val error = V4TransactionErrors.error(null, e.toString())
callback(false, error, null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import exchange.dydx.abacus.state.manager.BlockAndTime
import exchange.dydx.abacus.state.manager.GasToken
import exchange.dydx.abacus.state.manager.HistoricalPnlPeriod
import exchange.dydx.abacus.state.manager.HistoricalTradingRewardsPeriod
import exchange.dydx.abacus.state.manager.HumanReadableCancelMultipleOrdersPayload
import exchange.dydx.abacus.state.manager.HumanReadableCancelAllOrdersPayload
import exchange.dydx.abacus.state.manager.HumanReadableCancelOrderPayload
import exchange.dydx.abacus.state.manager.HumanReadableDepositPayload
import exchange.dydx.abacus.state.manager.HumanReadablePlaceOrderPayload
Expand Down Expand Up @@ -57,10 +57,10 @@ import exchange.dydx.abacus.state.v2.supervisor.accountAddress
import exchange.dydx.abacus.state.v2.supervisor.addressRestriction
import exchange.dydx.abacus.state.v2.supervisor.adjustIsolatedMargin
import exchange.dydx.abacus.state.v2.supervisor.adjustIsolatedMarginPayload
import exchange.dydx.abacus.state.v2.supervisor.cancelAllOrders
import exchange.dydx.abacus.state.v2.supervisor.cancelAllOrdersPayload
import exchange.dydx.abacus.state.v2.supervisor.cancelOrder
import exchange.dydx.abacus.state.v2.supervisor.cancelOrderPayload
import exchange.dydx.abacus.state.v2.supervisor.cancelOrders
import exchange.dydx.abacus.state.v2.supervisor.cancelOrdersPayload
import exchange.dydx.abacus.state.v2.supervisor.closePosition
import exchange.dydx.abacus.state.v2.supervisor.closePositionPayload
import exchange.dydx.abacus.state.v2.supervisor.commitAdjustIsolatedMargin
Expand Down Expand Up @@ -541,8 +541,8 @@ internal class StateManagerAdaptorV2(
return accounts.cancelOrderPayload(orderId)
}

internal fun cancelOrdersPayload(marketId: String?): HumanReadableCancelMultipleOrdersPayload? {
return accounts.cancelOrdersPayload(marketId)
internal fun cancelAllOrdersPayload(marketId: String?): HumanReadableCancelAllOrdersPayload? {
return accounts.cancelAllOrdersPayload(marketId)
}

internal fun triggerOrdersPayload(): HumanReadableTriggerOrdersPayload? {
Expand Down Expand Up @@ -603,8 +603,8 @@ internal class StateManagerAdaptorV2(
accounts.cancelOrder(orderId, callback)
}

internal fun cancelOrders(marketId: String?, callback: TransactionCallback) {
accounts.cancelOrders(marketId, callback)
internal fun cancelAllOrders(marketId: String?, callback: TransactionCallback) {
accounts.cancelAllOrders(marketId, callback)
}

internal fun orderCanceled(orderId: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import exchange.dydx.abacus.state.changes.StateChanges
import exchange.dydx.abacus.state.manager.ApiData
import exchange.dydx.abacus.state.manager.BlockAndTime
import exchange.dydx.abacus.state.manager.HistoricalTradingRewardsPeriod
import exchange.dydx.abacus.state.manager.HumanReadableCancelMultipleOrdersPayload
import exchange.dydx.abacus.state.manager.HumanReadableCancelAllOrdersPayload
import exchange.dydx.abacus.state.manager.HumanReadableCancelOrderPayload
import exchange.dydx.abacus.state.manager.HumanReadableDepositPayload
import exchange.dydx.abacus.state.manager.HumanReadablePlaceOrderPayload
Expand Down Expand Up @@ -1181,8 +1181,8 @@ internal fun AccountSupervisor.cancelOrderPayload(
return subaccount?.cancelOrderPayload(orderId)
}

internal fun AccountSupervisor.cancelOrdersPayload(marketId: String?): HumanReadableCancelMultipleOrdersPayload? {
return subaccount?.cancelOrdersPayload(marketId)
internal fun AccountSupervisor.cancelAllOrdersPayload(marketId: String?): HumanReadableCancelAllOrdersPayload? {
return subaccount?.cancelAllOrdersPayload(marketId)
}

internal fun AccountSupervisor.depositPayload(): HumanReadableDepositPayload? {
Expand Down Expand Up @@ -1236,8 +1236,8 @@ internal fun AccountSupervisor.cancelOrder(orderId: String, callback: Transactio
subaccount?.cancelOrder(orderId = orderId, callback = callback)
}

internal fun AccountSupervisor.cancelOrders(marketId: String?, callback: TransactionCallback) {
subaccount?.cancelOrders(marketId, callback)
internal fun AccountSupervisor.cancelAllOrders(marketId: String?, callback: TransactionCallback) {
subaccount?.cancelAllOrders(marketId, callback)
}

internal fun AccountSupervisor.orderCanceled(orderId: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import exchange.dydx.abacus.state.manager.ApiData
import exchange.dydx.abacus.state.manager.BlockAndTime
import exchange.dydx.abacus.state.manager.HistoricalPnlPeriod
import exchange.dydx.abacus.state.manager.HistoricalTradingRewardsPeriod
import exchange.dydx.abacus.state.manager.HumanReadableCancelMultipleOrdersPayload
import exchange.dydx.abacus.state.manager.HumanReadableCancelAllOrdersPayload
import exchange.dydx.abacus.state.manager.HumanReadableCancelOrderPayload
import exchange.dydx.abacus.state.manager.HumanReadableDepositPayload
import exchange.dydx.abacus.state.manager.HumanReadablePlaceOrderPayload
Expand Down Expand Up @@ -276,8 +276,8 @@ internal fun AccountsSupervisor.cancelOrderPayload(orderId: String): HumanReadab
return account?.cancelOrderPayload(orderId)
}

internal fun AccountsSupervisor.cancelOrdersPayload(marketId: String?): HumanReadableCancelMultipleOrdersPayload? {
return account?.cancelOrdersPayload(marketId)
internal fun AccountsSupervisor.cancelAllOrdersPayload(marketId: String?): HumanReadableCancelAllOrdersPayload? {
return account?.cancelAllOrdersPayload(marketId)
}

internal fun AccountsSupervisor.depositPayload(): HumanReadableDepositPayload? {
Expand Down Expand Up @@ -342,8 +342,8 @@ internal fun AccountsSupervisor.cancelOrder(orderId: String, callback: Transacti
account?.cancelOrder(orderId, callback)
}

internal fun AccountsSupervisor.cancelOrders(marketId: String?, callback: TransactionCallback) {
account?.cancelOrders(marketId, callback)
internal fun AccountsSupervisor.cancelAllOrders(marketId: String?, callback: TransactionCallback) {
account?.cancelAllOrders(marketId, callback)
}

internal fun AccountsSupervisor.orderCanceled(orderId: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import exchange.dydx.abacus.state.changes.StateChanges
import exchange.dydx.abacus.state.manager.ApiData
import exchange.dydx.abacus.state.manager.BlockAndTime
import exchange.dydx.abacus.state.manager.FaucetRecord
import exchange.dydx.abacus.state.manager.HumanReadableCancelMultipleOrdersPayload
import exchange.dydx.abacus.state.manager.HumanReadableCancelAllOrdersPayload
import exchange.dydx.abacus.state.manager.HumanReadableCancelOrderPayload
import exchange.dydx.abacus.state.manager.HumanReadableDepositPayload
import exchange.dydx.abacus.state.manager.HumanReadableFaucetPayload
Expand Down Expand Up @@ -329,8 +329,8 @@ internal class SubaccountSupervisor(
return payloadProvider.cancelOrderPayload(orderId)
}

internal fun cancelOrdersPayload(marketId: String?): HumanReadableCancelMultipleOrdersPayload {
return payloadProvider.cancelOrdersPayload(marketId)
internal fun cancelAllOrdersPayload(marketId: String?): HumanReadableCancelAllOrdersPayload {
return payloadProvider.cancelAllOrdersPayload(marketId)
}

fun trade(
Expand Down Expand Up @@ -430,8 +430,8 @@ internal class SubaccountSupervisor(
return transactionSupervisor.cancelOrder(orderId, isOrphanedTriggerOrder, callback)
}

internal fun cancelOrders(marketId: String?, callback: TransactionCallback): HumanReadableCancelMultipleOrdersPayload {
return transactionSupervisor.cancelOrders(marketId, callback)
internal fun cancelAllOrders(marketId: String?, callback: TransactionCallback): HumanReadableCancelAllOrdersPayload {
return transactionSupervisor.cancelAllOrders(marketId, callback)
}

internal fun commitTriggerOrders(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import exchange.dydx.abacus.output.input.OrderStatus
import exchange.dydx.abacus.output.input.OrderType
import exchange.dydx.abacus.output.input.TradeInputGoodUntil
import exchange.dydx.abacus.output.input.TriggerOrder
import exchange.dydx.abacus.state.manager.HumanReadableCancelMultipleOrdersPayload
import exchange.dydx.abacus.state.manager.HumanReadableCancelAllOrdersPayload
import exchange.dydx.abacus.state.manager.HumanReadableCancelOrderPayload
import exchange.dydx.abacus.state.manager.HumanReadableDepositPayload
import exchange.dydx.abacus.state.manager.HumanReadablePlaceOrderPayload
Expand Down Expand Up @@ -39,7 +39,7 @@ internal interface SubaccountTransactionPayloadProviderProtocol {
fun cancelOrderPayload(orderId: String): HumanReadableCancelOrderPayload

@Throws(Exception::class)
fun cancelOrdersPayload(marketId: String?): HumanReadableCancelMultipleOrdersPayload
fun cancelAllOrdersPayload(marketId: String?): HumanReadableCancelAllOrdersPayload

fun triggerOrdersPayload(currentHeight: Int?): HumanReadableTriggerOrdersPayload

Expand Down Expand Up @@ -176,18 +176,18 @@ internal class SubaccountTransactionPayloadProvider(
}

@Throws(Exception::class)
override fun cancelOrdersPayload(
override fun cancelAllOrdersPayload(
marketId: String?,
): HumanReadableCancelMultipleOrdersPayload {
): HumanReadableCancelAllOrdersPayload {
val subaccount = stateMachine.state?.subaccount(subaccountNumber) ?: throw Exception("subaccount is null")
val openOrders = subaccount.orders?.let { orders ->
orders.filter { ( marketId == null || it.marketId == marketId ) && it.status.isOpen }
orders.filter { (marketId == null || it.marketId == marketId) && it.status.isOpen }
} ?: iEmptyList()
val cancelPayloads = openOrders.map { cancelOrderPayload(it.id) }.sortedBy { payload -> payload.orderFlags }.toIList()

return HumanReadableCancelMultipleOrdersPayload(
return HumanReadableCancelAllOrdersPayload(
marketId = marketId,
payloads = cancelPayloads
payloads = cancelPayloads,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import exchange.dydx.abacus.responses.ParsingErrorType
import exchange.dydx.abacus.responses.ParsingException
import exchange.dydx.abacus.state.manager.CancelOrderRecord
import exchange.dydx.abacus.state.manager.FaucetRecord
import exchange.dydx.abacus.state.manager.HumanReadableCancelMultipleOrdersPayload
import exchange.dydx.abacus.state.manager.HumanReadableCancelAllOrdersPayload
import exchange.dydx.abacus.state.manager.HumanReadableCancelOrderPayload
import exchange.dydx.abacus.state.manager.HumanReadablePlaceOrderPayload
import exchange.dydx.abacus.state.manager.HumanReadableSubaccountTransferPayload
Expand All @@ -32,7 +32,6 @@ import exchange.dydx.abacus.utils.IMap
import exchange.dydx.abacus.utils.IMutableList
import exchange.dydx.abacus.utils.Logger
import exchange.dydx.abacus.utils.NUM_PARENT_SUBACCOUNTS
import exchange.dydx.abacus.utils.Numeric
import exchange.dydx.abacus.utils.ParsingHelper
import exchange.dydx.abacus.utils.SHORT_TERM_ORDER_FLAGS
import exchange.dydx.abacus.utils.iMapOf
Expand Down Expand Up @@ -149,8 +148,8 @@ internal class SubaccountTransactionSupervisor(
return submitCancelOrder(orderId, marketId, callback, payload, analyticsPayload, uiClickTimeMs)
}

internal fun cancelOrders(marketId: String?, callback: TransactionCallback): HumanReadableCancelMultipleOrdersPayload {
val payload = payloadProvider.cancelOrdersPayload(marketId)
internal fun cancelAllOrders(marketId: String?, callback: TransactionCallback): HumanReadableCancelAllOrdersPayload {
val payload = payloadProvider.cancelAllOrdersPayload(marketId)

payload.payloads.forEach { cancelPayload ->
val subaccount = stateMachine.state?.subaccount(subaccountNumber)
Expand All @@ -159,18 +158,21 @@ internal class SubaccountTransactionSupervisor(
ParsingErrorType.MissingRequiredData,
"no existing order to be cancelled for $cancelPayload.orderId",
)
val marketId = existingOrder.marketId
val cancelOrderAnalyticsPayload = analyticsUtils.cancelOrderAnalyticsPayload(
val analyticsPayload = analyticsUtils.cancelOrderAnalyticsPayload(
cancelPayload,
existingOrder
existingOrder,
false,
false,
true,
)
val uiClickTimeMs = transactionTracker.trackOrderClick(analyticsPayload, AnalyticsEvent.TradeCancelAllOrdersClick)
submitCancelOrder(
orderId = cancelPayload.orderId,
marketId = marketId,
marketId = existingOrder.marketId,
callback = callback,
payload = cancelPayload,
analyticsPayload = cancelOrderAnalyticsPayload,
uiClickTimeMs = Numeric.double.ZERO, // TODO(@aforaleka) add back tracking
analyticsPayload = analyticsPayload,
uiClickTimeMs = uiClickTimeMs,
)
}
return payload
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,10 @@ class AnalyticsUtils {
existingOrder: SubaccountOrder?,
fromSlTpDialog: Boolean? = false,
isOrphanedTriggerOrder: Boolean = false,
isCancelAll: Boolean = false,
): IMap<String, Any>? {
return ParsingHelper.merge(
formatCancelOrderPayload(payload, fromSlTpDialog, isOrphanedTriggerOrder),
formatCancelOrderPayload(payload, fromSlTpDialog, isOrphanedTriggerOrder, isCancelAll),
if (existingOrder != null) formatOrder(existingOrder) else mapOf(),
)?.toIMap()
}
Expand All @@ -196,10 +197,12 @@ class AnalyticsUtils {
payload: HumanReadableCancelOrderPayload,
fromSlTpDialog: Boolean? = false,
isOrphanedTriggerOrder: Boolean = false,
isCancelAll: Boolean = false,
): IMap<String, Any>? {
return iMapOf(
"fromSlTpDialog" to fromSlTpDialog,
"isAutomaticallyCanceledByFrontend" to isOrphanedTriggerOrder,
"isCancelAll" to isCancelAll,
"subaccountNumber" to payload.subaccountNumber,
"clientId" to payload.clientId,
"orderId" to payload.orderId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ class V4TransactionTests : NetworkTests() {
val callback: TransactionCallback = { _, _, _ -> statefulCancelCalledCount++ }
val cancelPayloads = testChain!!.canceldOrderPayloads

subaccountSupervisor?.cancelOrders(null, callback)
subaccountSupervisor?.cancelAllOrders(null, callback)
// there are 2 short term orders and 4 stateful orders
// hence 2 stateful orders should be queued
assertEquals(3, cancelPayloads.size)
Expand All @@ -239,7 +239,7 @@ class V4TransactionTests : NetworkTests() {
val callback: TransactionCallback = { _, _, _ -> statefulCancelCalledCount++ }
val cancelPayloads = testChain!!.canceldOrderPayloads

subaccountSupervisor?.cancelOrders("ETH-USD", callback)
subaccountSupervisor?.cancelAllOrders("ETH-USD", callback)
// there are 1 short term order and 3 stateful orders in "ETH"
// hence 2 stateful orders should be queued
assertEquals(2, cancelPayloads.size)
Expand Down

0 comments on commit 1e6445e

Please sign in to comment.