Skip to content

Commit

Permalink
Support WBETH (#37)
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
oat9002 and github-actions[bot] authored Feb 25, 2024
1 parent f5ccbbf commit 857fb98
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/main/scala/models/binance/Saving.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ object Saving {
case class PositionAmount(
asset: String,
totalAmount: BigDecimal,
collateralAmount: BigDecimal,
collateralAmount: BigDecimal
)
object PositionAmount {
given Encoder[PositionAmount] = deriveEncoder[PositionAmount]
Expand Down
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 857fb98

Please sign in to comment.