Skip to content

Commit

Permalink
Implement new analytics API
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelekol committed Mar 28, 2023
1 parent 4f96350 commit 551f46a
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 165 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class MainViewModel(private val marketKit: MarketKit) : ViewModel() {
val interval = HsPeriodType.ByStartTime(time)

//fetch chartInfo from API
marketKit.chartInfoSingle(coinUid, currencyCode, interval)
marketKit.chartPointsSingle(coinUid, currencyCode, interval)
.subscribeOn(Schedulers.io())
.subscribe({
Log.w("AAA", "fetchChartInfo: ${it}")
Expand Down
56 changes: 28 additions & 28 deletions marketkit/src/main/java/io/horizontalsystems/marketkit/MarketKit.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package io.horizontalsystems.marketkit

import android.content.Context
import android.os.storage.StorageManager
import io.horizontalsystems.marketkit.chart.ChartManager
import io.horizontalsystems.marketkit.managers.*
import io.horizontalsystems.marketkit.models.*
import io.horizontalsystems.marketkit.providers.*
Expand All @@ -23,7 +22,6 @@ class MarketKit(
private val coinHistoricalPriceManager: CoinHistoricalPriceManager,
private val coinPriceSyncManager: CoinPriceSyncManager,
private val postManager: PostManager,
private val chartManager: ChartManager,
private val exchangeSyncer: ExchangeSyncer,
private val globalMarketInfoManager: GlobalMarketInfoManager,
private val hsProvider: HsProvider,
Expand Down Expand Up @@ -87,23 +85,25 @@ class MarketKit(
}

fun marketInfoDetailsSingle(coinUid: String, currencyCode: String): Single<MarketInfoDetails> {
return coinManager.marketInfoDetailsSingle(coinUid, currencyCode)
return hsProvider.getMarketInfoDetails(coinUid, currencyCode).map {
MarketInfoDetails(it)
}
}

fun marketInfoTvlSingle(
coinUid: String,
currencyCode: String,
timePeriod: HsTimePeriod
): Single<List<ChartPoint>> {
return coinManager.marketInfoTvlSingle(coinUid, currencyCode, timePeriod)
return hsProvider.marketInfoTvlSingle(coinUid, currencyCode, timePeriod)
}

fun marketInfoGlobalTvlSingle(
chain: String,
currencyCode: String,
timePeriod: HsTimePeriod
): Single<List<ChartPoint>> {
return coinManager.marketInfoGlobalTvlSingle(chain, currencyCode, timePeriod)
return hsProvider.marketInfoGlobalTvlSingle(chain, currencyCode, timePeriod)
}

fun defiMarketInfosSingle(currencyCode: String): Single<List<DefiMarketInfo>> {
Expand Down Expand Up @@ -185,15 +185,15 @@ class MarketKit(
}

fun treasuriesSingle(coinUid: String, currencyCode: String): Single<List<CoinTreasury>> {
return coinManager.treasuriesSingle(coinUid, currencyCode)
return hsProvider.coinTreasuriesSingle(coinUid, currencyCode)
}

fun investmentsSingle(coinUid: String): Single<List<CoinInvestment>> {
return coinManager.investmentsSingle(coinUid)
return hsProvider.investmentsSingle(coinUid)
}

fun coinReportsSingle(coinUid: String): Single<List<CoinReport>> {
return coinManager.coinReportsSingle(coinUid)
return hsProvider.coinReportsSingle(coinUid)
}

fun auditReportsSingle(addresses: List<String>): Single<List<Auditor>> {
Expand All @@ -207,30 +207,26 @@ class MarketKit(
.map { response ->
response.mapNotNull { chartCoinPrice ->
chartCoinPrice.totalVolume?.let { volume ->
ChartPoint(
volume,
chartCoinPrice.timestamp,
null
)
ChartPoint(volume, chartCoinPrice.timestamp, null)
}
}
}
}

fun dexLiquiditySingle(coinUid: String, currencyCode: String, timePeriod: HsTimePeriod, sessionKey: String?): Single<DexLiquiditiesResponse> {
return coinManager.dexLiquiditySingle(coinUid, currencyCode, timePeriod, sessionKey)
fun dexLiquiditySingle(coinUid: String, currencyCode: String, timePeriod: HsTimePeriod, sessionKey: String?): Single<List<Analytics.VolumePoint>> {
return hsProvider.dexLiquiditySingle(coinUid, currencyCode, timePeriod, sessionKey)
}

fun dexVolumesSingle(coinUid: String, currencyCode: String, timePeriod: HsTimePeriod, sessionKey: String?): Single<DexVolumesResponse> {
return coinManager.dexVolumesSingle(coinUid, currencyCode, timePeriod, sessionKey)
fun dexVolumesSingle(coinUid: String, currencyCode: String, timePeriod: HsTimePeriod, sessionKey: String?): Single<List<Analytics.VolumePoint>> {
return hsProvider.dexVolumesSingle(coinUid, currencyCode, timePeriod, sessionKey)
}

fun transactionDataSingle(coinUid: String, currencyCode: String, timePeriod: HsTimePeriod, platform: String?, sessionKey: String?): Single<TransactionsDataResponse> {
return coinManager.transactionDataSingle(coinUid, currencyCode, timePeriod, platform, sessionKey)
fun transactionDataSingle(coinUid: String, timePeriod: HsTimePeriod, platform: String?, sessionKey: String?): Single<List<Analytics.CountVolumePoint>> {
return hsProvider.transactionDataSingle(coinUid, timePeriod, platform, sessionKey)
}

fun activeAddressesSingle(coinUid: String, currencyCode: String, timePeriod: HsTimePeriod, sessionKey: String?): Single<ActiveAddressesDataResponse> {
return coinManager.activeAddressesSingle(coinUid, currencyCode, timePeriod, sessionKey)
fun activeAddressesSingle(coinUid: String, timePeriod: HsTimePeriod, sessionKey: String?): Single<List<Analytics.CountPoint>> {
return hsProvider.activeAddressesSingle(coinUid, timePeriod, sessionKey)
}

fun analyticsPreviewSingle(coinUid: String): Single<AnalyticsPreview> {
Expand Down Expand Up @@ -275,12 +271,17 @@ class MarketKit(

// Chart Info

fun chartInfoSingle(coinUid: String, currencyCode: String, periodType: HsPeriodType): Single<List<ChartPoint>> {
return chartManager.chartInfoSingle(coinUid, currencyCode, periodType)
fun chartPointsSingle(
coinUid: String,
currencyCode: String,
hsPeriodType: HsPeriodType
): Single<List<ChartPoint>> {
return hsProvider.coinPriceChartSingle(coinUid, currencyCode, hsPeriodType)
.map { response -> response.map { it.chartPoint } }
}

fun chartStartTimeSingle(coinUid: String): Single<Long> {
return chartManager.chartStartTimeSingle(coinUid)
return hsProvider.coinPriceChartStartTime(coinUid)
}

// Global Market Info
Expand All @@ -290,11 +291,12 @@ class MarketKit(
}

fun topPlatformsSingle(currencyCode: String): Single<List<TopPlatform>> {
return coinManager.topPlatformsSingle(currencyCode)
return hsProvider.topPlatformsSingle(currencyCode)
.map { responseList -> responseList.map { it.topPlatform } }
}

fun topPlatformMarketCapPointsSingle(chain: String, timePeriod: HsTimePeriod, currencyCode: String): Single<List<TopPlatformMarketCapPoint>> {
return coinManager.topPlatformMarketCapPointsSingle(chain, timePeriod, currencyCode)
return hsProvider.topPlatformMarketCapPointsSingle(chain, timePeriod, currencyCode)
}

fun topPlatformCoinListSingle(chain: String, currencyCode: String): Single<List<MarketInfo>> {
Expand Down Expand Up @@ -350,7 +352,6 @@ class MarketKit(
coinPriceManager.listener = coinPriceSyncManager
val cryptoCompareProvider = CryptoCompareProvider(cryptoCompareApiKey)
val postManager = PostManager(cryptoCompareProvider)
val chartManager = ChartManager(hsProvider)
val globalMarketInfoStorage = GlobalMarketInfoStorage(marketDatabase)
val globalMarketInfoManager = GlobalMarketInfoManager(hsProvider, globalMarketInfoStorage)
val hsDataSyncer = HsDataSyncer(coinSyncer, hsProvider)
Expand All @@ -364,7 +365,6 @@ class MarketKit(
coinHistoricalPriceManager,
coinPriceSyncManager,
postManager,
chartManager,
exchangeSyncer,
globalMarketInfoManager,
hsProvider,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -99,53 +99,10 @@ class CoinManager(
}
}

fun marketInfoDetailsSingle(coinUid: String, currency: String): Single<MarketInfoDetails> {
return hsProvider.getMarketInfoDetails(coinUid, currency).map {
MarketInfoDetails(it)
}
}

fun marketInfoTvlSingle(
coinUid: String,
currencyCode: String,
timePeriod: HsTimePeriod
): Single<List<ChartPoint>> {
return hsProvider.marketInfoTvlSingle(coinUid, currencyCode, timePeriod)
}

fun marketInfoGlobalTvlSingle(
chain: String,
currencyCode: String,
timePeriod: HsTimePeriod
): Single<List<ChartPoint>> {
return hsProvider.marketInfoGlobalTvlSingle(chain, currencyCode, timePeriod)
}

fun treasuriesSingle(coinUid: String, currencyCode: String): Single<List<CoinTreasury>> {
return hsProvider.coinTreasuriesSingle(coinUid, currencyCode)
}

fun investmentsSingle(coinUid: String): Single<List<CoinInvestment>> {
return hsProvider.investmentsSingle(coinUid)
}

fun coinReportsSingle(coinUid: String): Single<List<CoinReport>> {
return hsProvider.coinReportsSingle(coinUid)
}

fun auditReportsSingle(addresses: List<String>): Single<List<Auditor>> {
return defiYieldProvider.auditReportsSingle(addresses)
}

fun topPlatformsSingle(currencyCode: String): Single<List<TopPlatform>> {
return hsProvider.topPlatformsSingle(currencyCode)
.map { responseList -> responseList.map { it.topPlatform } }
}

fun topPlatformMarketCapPointsSingle(chain: String, timePeriod: HsTimePeriod, currencyCode: String): Single<List<TopPlatformMarketCapPoint>> {
return hsProvider.topPlatformMarketCapPointsSingle(chain, timePeriod, currencyCode)
}

fun topPlatformCoinListSingle(chain: String, currencyCode: String): Single<List<MarketInfo>> {
return hsProvider.topPlatformCoinListSingle(chain, currencyCode)
.map { getMarketInfos(it) }
Expand Down Expand Up @@ -179,49 +136,6 @@ class CoinManager(
}
}

fun dexLiquiditySingle(
coinUid: String,
currencyCode: String,
timePeriod: HsTimePeriod,
sessionKey: String?
): Single<DexLiquiditiesResponse> {
return hsProvider.dexLiquiditySingle(coinUid, currencyCode, timePeriod, sessionKey)
}

fun dexVolumesSingle(
coinUid: String,
currencyCode: String,
timePeriod: HsTimePeriod,
sessionKey: String?
): Single<DexVolumesResponse> {
return hsProvider.dexVolumesSingle(coinUid, currencyCode, timePeriod, sessionKey)
}

fun transactionDataSingle(
coinUid: String,
currencyCode: String,
timePeriod: HsTimePeriod,
platform: String?,
sessionKey: String?
): Single<TransactionsDataResponse> {
return hsProvider.transactionDataSingle(
coinUid,
currencyCode,
timePeriod,
platform,
sessionKey
)
}

fun activeAddressesSingle(
coinUid: String,
currencyCode: String,
timePeriod: HsTimePeriod,
sessionKey: String?
): Single<ActiveAddressesDataResponse> {
return hsProvider.activeAddressesSingle(coinUid, currencyCode, timePeriod, sessionKey)
}

fun topMoversSingle(currencyCode: String): Single<TopMovers> =
hsProvider.topMoversRawSingle(currencyCode)
.map { raw ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ data class Analytics(
fun chartPoints(): List<ChartPoint> {
return points.map {
ChartPoint(
it.count,
it.count.toBigDecimal(),
it.timestamp,
null
)
Expand All @@ -157,7 +157,7 @@ data class Analytics(
fun chartPoints(): List<ChartPoint> {
return points.map {
ChartPoint(
it.count,
it.count.toBigDecimal(),
it.timestamp,
null
)
Expand All @@ -182,7 +182,13 @@ data class Analytics(
}

data class CountPoint(
val count: BigDecimal,
val count: String,
val timestamp: Long,
)

data class CountVolumePoint(
val count: String,
val volume: BigDecimal,
val timestamp: Long,
)

Expand Down Expand Up @@ -218,7 +224,7 @@ data class AnalyticsPreview(
val dexVolume: VolumePreview?,
@SerializedName("dex_liquidity")
val dexLiquidity: LiquidityPreview?,
val addresses: VolumePreview?,
val addresses: AddressesPreview?,
val transactions: TransactionPreview?,
val revenue: RevenuePreview?,
val tvl: TvlPreview?,
Expand All @@ -240,6 +246,14 @@ data class AnalyticsPreview(
val points: Boolean = false,
)

data class AddressesPreview(
@SerializedName("rank_30d")
val rank30d: Boolean = false,
@SerializedName("count_30d")
val count30d: Boolean = false,
val points: Boolean = false,
)

data class TransactionPreview(
@SerializedName("rank_30d")
val rank30d: Boolean = false,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package io.horizontalsystems.marketkit.models

import io.horizontalsystems.marketkit.chart.HsChartRequestHelper

enum class HsTimePeriod(val value: String) {
Day1("1d"),
Week1("1w"),
Expand Down
Loading

0 comments on commit 551f46a

Please sign in to comment.