Skip to content

Commit

Permalink
Fetch crypto with coingecko
Browse files Browse the repository at this point in the history
  • Loading branch information
mdrlzy authored and kirillt committed Dec 2, 2022
1 parent 36abe87 commit a844787
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,11 @@ class CryptoCurrencyRepo @Inject constructor(
override val type = CurrencyType.CRYPTO

override suspend fun fetchRemote(): List<CurrencyRate> =
cryptoAPI.getCryptoRates().findUSDTPairs()
cryptoAPI.getCryptoRates()
.map { CurrencyRate(it.symbol.uppercase(), it.current_price) }

override suspend fun getCurrencyName(): List<CurrencyName> =
getCurrencyRate().map {
CurrencyName(it.code, name = "")
}

// api returns pairs like ETHBTC, ETHBNB, ETHTRX, ETHUSDT
// we only take USDT pairs
private fun List<CryptoRateResponse>.findUSDTPairs() =
mapNotNull { (code, price) ->
if (code.takeLast(4) == "USDT") {
CurrencyRate(code.dropLast(4), price)
} else
null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ package space.taran.arkrate.data.crypto

data class CryptoRateResponse(
val symbol: String,
val price: Double
val current_price: Double
)

0 comments on commit a844787

Please sign in to comment.