Skip to content

Commit

Permalink
⚡ support wbeth
Browse files Browse the repository at this point in the history
  • Loading branch information
oat9002 committed Feb 25, 2024
1 parent f5ccbbf commit dba7d1f
Showing 1 changed file with 40 additions and 23 deletions.
63 changes: 40 additions & 23 deletions src/main/scala/services/user/UserService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -121,32 +121,49 @@ class UserServiceImpl(using
satangPrices: List[SatangTicker],
binancePrices: List[BinanceTicker]
): CryptoBalance = {
val lastThbPrice = satangPrices
.filter(_.symbol != "luna_thb")
.find(_.symbol == s"${balance.symbol}_thb")
val btcToThb = satangPrices
.find(_.symbol == "btc_thb")
.map(_.lastPrice)
.getOrElse {
binancePrices
.find(_.symbol.toLowerCase() == s"${balance.symbol}busd")
.map(_.price) match {
case Some(busd) =>
satangPrices
.find(_.symbol == "busd_thb")
.getOrElse(BigDecimal(0))

val lastThbPrice = balance.symbol match {
case "wbeth" =>
val wbethToEth = binancePrices
.find(_.symbol.toLowerCase() == "wbetheth")
.map(_.price)
val ethToBtc = binancePrices
.find(_.symbol.toLowerCase() == "ethbtc")
.map(_.price)

(wbethToEth, ethToBtc) match {
case (Some(toEth), Some(toBtc)) =>
toEth * toBtc * btcToThb
case _ => BigDecimal(0)
}
case _ =>
satangPrices
.filter(_.symbol != "luna_thb")
.find(_.symbol == s"${balance.symbol}_thb")
.map(_.lastPrice)
.getOrElse {
val usdtToThb = satangPrices
.find(_.symbol == "usdt_thb")
.map(_.lastPrice)
.getOrElse(BigDecimal(0)) * busd
case None =>
.getOrElse(BigDecimal(0))

binancePrices
.find(_.symbol.toLowerCase() == s"${balance.symbol}btc")
.map(_.price) match {
case Some(btc) =>
satangPrices
.find(_.symbol == "btc_thb")
.map(_.lastPrice)
.getOrElse(BigDecimal(0)) * btc
case None => BigDecimal(0)
}
}
}
.find(_.symbol.toLowerCase() == s"${balance.symbol}usdt")
.map(_.price)
.map(_ * usdtToThb)
.getOrElse{
binancePrices
.find(_.symbol.toLowerCase() == s"${balance.symbol}btc")
.map(_.price)
.map(_ * btcToThb)
.getOrElse(BigDecimal(0))
}
}
}

CryptoBalance(
balance.symbol,
Expand Down

0 comments on commit dba7d1f

Please sign in to comment.