Skip to content

Commit

Permalink
Merge pull request #599 from alephium/mobula-production
Browse files Browse the repository at this point in the history
Update to latest mobula
  • Loading branch information
tdroxler authored Jan 14, 2025
2 parents 1400ec7 + d45caed commit fac8aac
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
2 changes: 1 addition & 1 deletion app/src/main/resources/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ explorer {
]
liquidity-minimum = 100 # in USD
liquidity-minimum = ${?EXPLORER_MARKET_LIQUIDITY_MINIMUM}
mobula-uri = "https://api.mobula.io/api/1"
mobula-uri = "https://production-api.mobula.io/api/1"
mobula-uri = ${?EXPLORER_MARKET_MOBULA_URI}
coingecko-uri = "https://api.coingecko.com/api/v3"
coingecko-uri = ${?EXPLORER_MARKET_COINGECKO_URI}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,19 @@ object MarketService extends StrictLogging {
}
}

private def validateData(
asset: TokenList.Entry,
price: Double,
liquidity: Double
): Option[Price] = {
// If the liquidity is below the minimum, the price is unavailable
if (liquidity < marketConfig.liquidityMinimum) {
None
} else {
Some(Price(asset.symbol, price, liquidity))
}
}

@SuppressWarnings(Array("org.wartremover.warts.IterableOps"))
def convertJsonToMobulaPrices(
assets: ArraySeq[TokenList.Entry]
Expand All @@ -386,18 +399,14 @@ object MarketService extends StrictLogging {
Try {
ArraySeq.from(assets.flatMap { asset =>
val address = tokenListToAddresses(ArraySeq(asset)).head
data.value.get(address.toBase58) match {
case Some(value) =>
val price = value("price").num
val liquidity = value("liquidity").num
// If the liquidity is below the minimum, the price is unavailable
if (liquidity < marketConfig.liquidityMinimum) {
None
} else {
Some(Price(asset.symbol, price, liquidity))
}
case None =>
None
data.value.get(address.toBase58).flatMap { value =>
for {
price <- value("price").numOpt
liquidity <- value("liquidity").numOpt
result <- validateData(asset, price, liquidity)
} yield {
result
}
}
})
}.toEither.left.map { error =>
Expand Down

0 comments on commit fac8aac

Please sign in to comment.