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

Make Cex Volume chart return points by day #42

Merged
merged 1 commit into from
Mar 30, 2023
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 @@ -2,6 +2,7 @@ package io.horizontalsystems.marketkit

import android.content.Context
import android.os.storage.StorageManager
import io.horizontalsystems.marketkit.chart.HsChartRequestHelper
import io.horizontalsystems.marketkit.managers.*
import io.horizontalsystems.marketkit.models.*
import io.horizontalsystems.marketkit.providers.*
Expand All @@ -12,6 +13,7 @@ import io.horizontalsystems.marketkit.syncers.HsDataSyncer
import io.reactivex.Observable
import io.reactivex.Single
import java.math.BigDecimal
import java.util.*

class MarketKit(
private val nftManager: NftManager,
Expand Down Expand Up @@ -203,7 +205,11 @@ class MarketKit(
// Pro Data

fun cexVolumesSingle(coinUid: String, currencyCode: String, timePeriod: HsTimePeriod): Single<List<ChartPoint>> {
return hsProvider.coinPriceChartSingle(coinUid, currencyCode, HsPeriodType.ByPeriod(timePeriod))
val periodType = HsPeriodType.ByPeriod(timePeriod)
val currentTime = Date().time / 1000
val fromTimestamp = HsChartRequestHelper.fromTimestamp(currentTime, periodType)
val interval = HsPointTimePeriod.Day1
return hsProvider.coinPriceChartSingle(coinUid, currencyCode, interval, fromTimestamp)
.map { response ->
response.mapNotNull { chartCoinPrice ->
chartCoinPrice.totalVolume?.let { volume ->
Expand Down Expand Up @@ -274,9 +280,21 @@ class MarketKit(
fun chartPointsSingle(
coinUid: String,
currencyCode: String,
hsPeriodType: HsPeriodType
periodType: HsPeriodType
): Single<List<ChartPoint>> {
return hsProvider.coinPriceChartSingle(coinUid, currencyCode, hsPeriodType)
val interval: HsPointTimePeriod
var fromTimestamp: Long? = null
when (periodType) {
is HsPeriodType.ByPeriod -> {
val currentTime = Date().time / 1000
fromTimestamp = HsChartRequestHelper.fromTimestamp(currentTime, periodType)
interval = HsChartRequestHelper.pointInterval(periodType)
}
is HsPeriodType.ByStartTime -> {
interval = HsChartRequestHelper.pointInterval(periodType)
}
}
return hsProvider.coinPriceChartSingle(coinUid, currencyCode, interval, fromTimestamp)
.map { response -> response.map { it.chartPoint } }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,10 @@ class HsProvider(baseUrl: String, apiKey: String) {
fun coinPriceChartSingle(
coinUid: String,
currencyCode: String,
periodType: HsPeriodType
periodType: HsPointTimePeriod,
fromTimestamp: Long?
): Single<List<ChartCoinPriceResponse>> {
val currentTime = Date().time / 1000
val fromTimestamp = HsChartRequestHelper.fromTimestamp(currentTime, periodType)
val pointInterval = HsChartRequestHelper.pointInterval(periodType)

return service.getCoinPriceChart(coinUid, currencyCode, fromTimestamp, pointInterval.value)
return service.getCoinPriceChart(coinUid, currencyCode, fromTimestamp, periodType.value)
}

fun coinPriceChartStartTime(coinUid: String): Single<Long> {
Expand Down