Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide coin category market data #11

Merged
merged 1 commit into from
Apr 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,22 @@ class MainViewModel(private val marketKit: MarketKit) : ViewModel() {
}
}

fun runCategoriesMarketData() {
val currencyCode = "USD"
marketKit.categoriesMarketDataSingle(currencyCode)
.subscribeOn(Schedulers.io())
.subscribe({
it.forEach {
Log.w("AAA", "Category: ${it.uid} marketCap: ${it.marketCap} diff24H: ${it.diff24H}")
}
}, {
Log.e("AAA", "runCategoriesMarketData Error", it)
})
.let {
disposables.add(it)
}
}

fun runFetchPosts() {
marketKit.postsSingle()
.subscribeOn(Schedulers.io())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ class MarketKit(
return coinCategoryManager.coinCategory(uid)
}

fun categoriesMarketDataSingle(currencyCode: String): Single<List<CoinCategoryMarketData>> {
return coinCategoryManager.categoryMarketDataSingle(currencyCode)
}

fun sync() {
coinSyncer.sync()
coinCategorySyncer.sync()
Expand Down Expand Up @@ -253,7 +257,7 @@ class MarketKit(

val marketDatabase = MarketDatabase.getInstance(context)
val hsProvider = HsProvider(hsApiBaseUrl, hsApiKey)
val coinCategoryManager = CoinCategoryManager(CoinCategoryStorage(marketDatabase))
val coinCategoryManager = CoinCategoryManager(CoinCategoryStorage(marketDatabase), hsProvider)
val coinGeckoProvider = CoinGeckoProvider("https://api.coingecko.com/api/v3/")
val defiYieldProvider = DefiYieldProvider(defiYieldApiKey)
val exchangeManager = ExchangeManager(ExchangeStorage(marketDatabase))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package io.horizontalsystems.marketkit.managers

import io.horizontalsystems.marketkit.models.CoinCategory
import io.horizontalsystems.marketkit.models.CoinCategoryMarketData
import io.horizontalsystems.marketkit.providers.HsProvider
import io.horizontalsystems.marketkit.storage.CoinCategoryStorage
import io.reactivex.Single
import io.reactivex.subjects.PublishSubject

class CoinCategoryManager(
private val storage: CoinCategoryStorage
private val storage: CoinCategoryStorage,
private val hsProvider: HsProvider
) {
val coinCategoriesObservable = PublishSubject.create<List<CoinCategory>>()

Expand All @@ -25,4 +29,8 @@ class CoinCategoryManager(
storage.save(coinCategories)
coinCategoriesObservable.onNext(coinCategories)
}

fun categoryMarketDataSingle(currencyCode: String): Single<List<CoinCategoryMarketData>> {
return hsProvider.coinCategoriesMarketDataSingle(currencyCode)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.horizontalsystems.marketkit.models

import com.google.gson.annotations.SerializedName
import java.math.BigDecimal

data class CoinCategoryMarketData(
val uid: String,
@SerializedName("market_cap")
val marketCap: BigDecimal?,
@SerializedName("change_24h")
val diff24H: BigDecimal?,
@SerializedName("change_1w")
val diff1W: BigDecimal?,
@SerializedName("change_1m")
val diff1M: BigDecimal?,
)
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ class HsProvider(baseUrl: String, apiKey: String) {
return service.getCategories()
}

fun coinCategoriesMarketDataSingle(currencyCode: String): Single<List<CoinCategoryMarketData>> {
return service.getCategoriesMarketData(currencyCode)
}

fun getCoinPrices(coinUids: List<String>, currencyCode: String): Single<List<CoinPrice>> {
return service.getCoinPrices(coinUids.joinToString(separator = ","), currencyCode)
.map { coinPrices ->
Expand Down Expand Up @@ -209,6 +213,11 @@ class HsProvider(baseUrl: String, apiKey: String) {
@GET("categories")
fun getCategories(): Single<List<CoinCategory>>

@GET("categories")
fun getCategoriesMarketData(
@Query("currency") currencyCode: String
): Single<List<CoinCategoryMarketData>>

@GET("coins")
fun getCoinPrices(
@Query("uids") uids: String,
Expand Down