Skip to content

Commit

Permalink
Add assetOfMarket() to PerpetualState
Browse files Browse the repository at this point in the history
  • Loading branch information
ruixhuang committed Apr 29, 2024
1 parent 519678e commit 964ebce
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>? {
return marketsSummary?.marketIds()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -17,12 +16,6 @@ interface NotificationsProviderProtocol {
fun buildNotifications(
subaccountNumber: Int
): IMap<String, Notification>

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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down

0 comments on commit 964ebce

Please sign in to comment.