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

Implement Top Platforms #12

Merged
merged 2 commits into from
May 5, 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 @@ -313,6 +313,36 @@ class MainViewModel(private val marketKit: MarketKit) : ViewModel() {
}
}

fun runTopPlatforms() {
val currencyCode = "eur"
marketKit.topPlatformsSingle(currencyCode)
.subscribeOn(Schedulers.io())
.subscribe({ platforms ->
platforms.forEach {
Log.e("AAA", "topPlatformsSingle ${it.name} marketCap: ${it.marketCap} rank: ${it.rank}")
}
}, {
Log.e("AAA", "topPlatformsSingle error", it)
}).let {
disposables.add(it)
}
}

fun runTopPlatformsMarketCapPoints() {
val chain = "ethereum"
marketKit.topPlatformsMarketCapPointsSingle(chain)
.subscribeOn(Schedulers.io())
.subscribe({ points ->
points.forEach {
Log.e("AAA", "date: ${it.date} marketCap: ${it.marketCap} ")
}
}, {
Log.e("AAA", "topPlatformsMarketCapPointsSingle error", it)
}).let {
disposables.add(it)
}
}

override fun onCleared() {
disposables.clear()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,14 @@ class MarketKit(
return globalMarketInfoManager.globalMarketInfoSingle(currencyCode, timePeriod)
}

fun topPlatformsSingle(currencyCode: String): Single<List<TopPlatform>> {
return coinManager.topPlatformsSingle(currencyCode)
}

fun topPlatformsMarketCapPointsSingle(chain: String): Single<List<TopPlatformMarketCapPoint>> {
return coinManager.topPlatformsMarketCapPointsSingle(chain)
}

companion object {
fun getInstance(
context: Context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,31 @@ class CoinManager(
return defiYieldProvider.auditReportsSingle(addresses)
}

fun topPlatformsSingle(currencyCode: String): Single<List<TopPlatform>> {
return hsProvider.topPlatformsSingle(currencyCode)
.map { responseList ->
responseList.map {
TopPlatform(
it.uid,
it.name,
it.rank,
it.protocols,
it.marketCap,
it.stats["rank_1d"]?.toInt(),
it.stats["rank_1w"]?.toInt(),
it.stats["rank_1m"]?.toInt(),
it.stats["change_1d"],
it.stats["change_1w"],
it.stats["change_1m"],
)
}
}
}

fun topPlatformsMarketCapPointsSingle(chain: String): Single<List<TopPlatformMarketCapPoint>> {
return hsProvider.topPlatformMarketCapPointsSingle(chain)
}

private fun getMarketInfos(rawMarketInfos: List<MarketInfoRaw>): List<MarketInfo> {
return try {
val fullCoins = storage.fullCoins(rawMarketInfos.map { it.uid })
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package io.horizontalsystems.marketkit.models

import java.math.BigDecimal

data class TopPlatform(
val uid: String,
val name: String,
val rank: Int,
val protocols: Int,
val marketCap: BigDecimal,
val rank1D: Int?,
val rank1W: Int?,
val rank1M: Int?,
val change1D: BigDecimal?,
val change1W: BigDecimal?,
val change1M: BigDecimal?,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package io.horizontalsystems.marketkit.models

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

data class TopPlatformMarketCapPoint(
val date: Long,
@SerializedName("market_cap")
val marketCap: BigDecimal,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package io.horizontalsystems.marketkit.models

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

data class TopPlatformResponse(
val uid: String,
val name: String,
val rank: Int,
val protocols: Int,
@SerializedName("market_cap")
val marketCap: BigDecimal,
val stats: Map<String, BigDecimal?>,
)
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,14 @@ class HsProvider(baseUrl: String, apiKey: String) {
return service.getCoinReports(coinUid)
}

fun topPlatformsSingle(currencyCode: String): Single<List<TopPlatformResponse>> {
return service.getTopPlatforms(currencyCode)
}

fun topPlatformMarketCapPointsSingle(chain: String): Single<List<TopPlatformMarketCapPoint>> {
return service.getTopPlatformMarketCapPoints(chain)
}

private interface MarketService {
@GET("coins")
fun getFullCoins(
Expand Down Expand Up @@ -312,6 +320,16 @@ class HsProvider(baseUrl: String, apiKey: String) {
@Query("currency") currencyCode: String,
): Single<List<GlobalMarketPoint>>

@GET("top-platforms")
fun getTopPlatforms(
@Query("currency") currencyCode: String
): Single<List<TopPlatformResponse>>

@GET("top-platforms/{chain}/chart")
fun getTopPlatformMarketCapPoints(
@Path("chain") chain: String
): Single<List<TopPlatformMarketCapPoint>>

companion object {
private const val marketInfoFields =
"name,code,price,price_change_24h,market_cap_rank,coingecko_id,market_cap,total_volume"
Expand Down