From 964ebceaa8bb3d04ad97d3b65b43470956254bb1 Mon Sep 17 00:00:00 2001 From: Rui Date: Mon, 29 Apr 2024 10:05:55 -0700 Subject: [PATCH] Add assetOfMarket() to PerpetualState --- .../kotlin/exchange.dydx.abacus/output/PerpetualState.kt | 5 +++++ .../state/manager/notification/NotificationsProvider.kt | 7 ------- .../notification/providers/FillsNotificationProvider.kt | 5 +++-- .../providers/OrderStatusChangesNotificationProvider.kt | 2 +- .../providers/PositionsNotificationProvider.kt | 2 +- 5 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/output/PerpetualState.kt b/src/commonMain/kotlin/exchange.dydx.abacus/output/PerpetualState.kt index 25d7936e3..af1872a7d 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/output/PerpetualState.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/output/PerpetualState.kt @@ -41,6 +41,11 @@ data class PerpetualState( return assets?.get(assetId) } + fun assetOfMarket(marketId: String): Asset? { + val assetId = market(marketId)?.assetId ?: return null + return assets?.get(assetId) + } + fun marketIds(): IList? { return marketsSummary?.marketIds() } diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/state/manager/notification/NotificationsProvider.kt b/src/commonMain/kotlin/exchange.dydx.abacus/state/manager/notification/NotificationsProvider.kt index 8521b5cbc..7e4886bed 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/state/manager/notification/NotificationsProvider.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/state/manager/notification/NotificationsProvider.kt @@ -1,6 +1,5 @@ package exchange.dydx.abacus.state.manager.notification -import exchange.dydx.abacus.output.Asset import exchange.dydx.abacus.output.Notification import exchange.dydx.abacus.protocols.ParserProtocol import exchange.dydx.abacus.state.manager.V4Environment @@ -17,12 +16,6 @@ interface NotificationsProviderProtocol { fun buildNotifications( subaccountNumber: Int ): IMap - - fun asset(stateMachine: TradingStateMachine, marketId: String): Asset? { - val market = stateMachine.state?.market(marketId) ?: return null - val assetId = market.assetId - return stateMachine.state?.asset(assetId) - } } class NotificationsProvider( diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/state/manager/notification/providers/FillsNotificationProvider.kt b/src/commonMain/kotlin/exchange.dydx.abacus/state/manager/notification/providers/FillsNotificationProvider.kt index 1b924a70f..02b719a69 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/state/manager/notification/providers/FillsNotificationProvider.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/state/manager/notification/providers/FillsNotificationProvider.kt @@ -14,6 +14,7 @@ import exchange.dydx.abacus.utils.IList import exchange.dydx.abacus.utils.IMap import exchange.dydx.abacus.utils.IMutableList import exchange.dydx.abacus.utils.JsonEncoder +import exchange.dydx.abacus.utils.ParsingHelper.Companion.asset import exchange.dydx.abacus.utils.Rounder import exchange.dydx.abacus.utils.UIImplementations import exchange.dydx.abacus.utils.iMapOf @@ -101,7 +102,7 @@ class FillsNotificationProvider( val marketId = fill.marketId val market = market(stateMachine, marketId) ?: return null val tickSize = market.configs?.tickSize ?: return null - val asset = asset(stateMachine, marketId) + val asset = stateMachine.state?.assetOfMarket(marketId) val assetText = asset?.name ?: marketId val marketImageUrl = asset?.resources?.imageUrl val side = fill.side.rawValue @@ -151,7 +152,7 @@ class FillsNotificationProvider( ): Notification? { val fillId = fill.id val marketId = fill.marketId - val asset = asset(stateMachine, marketId) ?: return null + val asset = stateMachine.state?.assetOfMarket(marketId) ?: return null val assetText = asset.name val marketImageUrl = asset.resources?.imageUrl val side = fill.side.rawValue diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/state/manager/notification/providers/OrderStatusChangesNotificationProvider.kt b/src/commonMain/kotlin/exchange.dydx.abacus/state/manager/notification/providers/OrderStatusChangesNotificationProvider.kt index 2088134c4..db1de4d35 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/state/manager/notification/providers/OrderStatusChangesNotificationProvider.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/state/manager/notification/providers/OrderStatusChangesNotificationProvider.kt @@ -96,7 +96,7 @@ class OrderStatusChangesNotificationProvider( } return if (statusNotificationStringKey != null && timestamp != null) { val marketId = order.marketId - val asset = asset(stateMachine, marketId) ?: return null + val asset = stateMachine.state?.assetOfMarket(marketId) ?: return null val marketImageUrl = asset.resources?.imageUrl val side = order.side.rawValue val sideText = uiImplementations.localizer?.localize("APP.GENERAL.$side") diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/state/manager/notification/providers/PositionsNotificationProvider.kt b/src/commonMain/kotlin/exchange.dydx.abacus/state/manager/notification/providers/PositionsNotificationProvider.kt index 28f00be72..54248d63f 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/state/manager/notification/providers/PositionsNotificationProvider.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/state/manager/notification/providers/PositionsNotificationProvider.kt @@ -43,7 +43,7 @@ class PositionsNotificationProvider( val positionStatus = parser.asString(position["status"]) if (positionStatus == "CLOSED") { val closedAt = parser.asDatetime(position["closedAt"]) ?: continue - val asset = asset(stateMachine, marketId) ?: continue + val asset = stateMachine.state?.assetOfMarket(marketId) ?: continue val assetText = asset.name val marketImageUrl = asset.resources?.imageUrl val params = (