Skip to content

Commit

Permalink
Merge pull request #13 from horizontalsystems/add_pro_charts
Browse files Browse the repository at this point in the history
Add PRO charts methods
  • Loading branch information
esen authored May 19, 2022
2 parents 8ee4187 + 33a3540 commit 2c55ffd
Show file tree
Hide file tree
Showing 4 changed files with 160 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,24 @@ class MarketKit(
return coinManager.auditReportsSingle(addresses)
}

// Pro Details

fun dexLiquiditySingle(coinUid: String, currencyCode: String, timePeriod: HsTimePeriod, sessionKey: String?): Single<DexLiquiditiesResponse> {
return coinManager.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 transactionDataSingle(coinUid: String, currencyCode: String, timePeriod: HsTimePeriod, platform: String?, sessionKey: String?): Single<TransactionsDataResponse> {
return coinManager.transactionDataSingle(coinUid, currencyCode, timePeriod, platform, sessionKey)
}

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

// Chart Info

fun chartInfo(coinUid: String, currencyCode: String, interval: HsTimePeriod): ChartInfo? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,4 +236,20 @@ 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)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package io.horizontalsystems.marketkit.models

import java.math.BigDecimal

data class ProChartPointDataRaw(
val timestamp: Long,
val count: Int?,
val volume: BigDecimal?
) {

companion object {

fun volumePoints(rawChartPoints: List<ProChartPointDataRaw>): List<ChartPoint> =
rawChartPoints.mapNotNull { raw ->
raw.volume?.let {
ChartPoint(
it,
raw.timestamp,
mapOf()
)
}
}

fun countPoints(rawChartPoints: List<ProChartPointDataRaw>): List<ChartPoint> =
rawChartPoints.mapNotNull { raw ->
raw.count?.let {
ChartPoint(
it.toBigDecimal(),
raw.timestamp,
mapOf()
)
}
}

}

}

data class DexLiquiditiesResponse(
val platforms: List<String>,
val liquidity: List<ProChartPointDataRaw>
) {

val volumePoints: List<ChartPoint>
get() = ProChartPointDataRaw.volumePoints(liquidity)

}

data class DexVolumesResponse(
val platforms: List<String>,
val volumes: List<ProChartPointDataRaw>
) {

val volumePoints: List<ChartPoint>
get() = ProChartPointDataRaw.volumePoints(volumes)

}

data class TransactionsDataResponse(
val platforms: List<String>,
val transactions: List<ProChartPointDataRaw>
) {

val volumePoints: List<ChartPoint>
get() = ProChartPointDataRaw.volumePoints(transactions)

val countPoints: List<ChartPoint>
get() = ProChartPointDataRaw.countPoints(transactions)

}

data class ActiveAddressesDataResponse(
val platforms: List<String>,
val addresses: List<ProChartPointDataRaw>
) {

val countPoints: List<ChartPoint>
get() = ProChartPointDataRaw.countPoints(addresses)

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import com.google.gson.annotations.SerializedName
import io.horizontalsystems.marketkit.chart.HsChartRequestHelper
import io.horizontalsystems.marketkit.models.*
import io.reactivex.Single
import retrofit2.http.GET
import retrofit2.http.Path
import retrofit2.http.Query
import retrofit2.http.*
import java.math.BigDecimal
import java.util.*

Expand Down Expand Up @@ -187,6 +185,22 @@ class HsProvider(baseUrl: String, apiKey: String) {
return service.getTopPlatformMarketCapPoints(chain)
}

fun dexLiquiditySingle(coinUid: String, currencyCode: String, timePeriod: HsTimePeriod, sessionKey: String?): Single<DexLiquiditiesResponse> {
return service.getDexLiquidities(sessionKey?.let { "Bearer ${it}" }, coinUid, timePeriod.value)
}

fun dexVolumesSingle(coinUid: String, currencyCode: String, timePeriod: HsTimePeriod, sessionKey: String?): Single<DexVolumesResponse> {
return service.getDexVolumes(sessionKey?.let { "Bearer ${it}" }, coinUid, timePeriod.value)
}

fun transactionDataSingle(coinUid: String, currencyCode: String, timePeriod: HsTimePeriod, platform: String?, sessionKey: String?): Single<TransactionsDataResponse> {
return service.getTransactions(sessionKey?.let { "Bearer ${it}" }, coinUid, timePeriod.value, platform)
}

fun activeAddressesSingle(coinUid: String, currencyCode: String, timePeriod: HsTimePeriod, sessionKey: String?): Single<ActiveAddressesDataResponse> {
return service.getActiveAddresses(sessionKey?.let { "Bearer ${it}" }, coinUid, timePeriod.value)
}

private interface MarketService {
@GET("coins")
fun getFullCoins(
Expand Down Expand Up @@ -279,6 +293,35 @@ class HsProvider(baseUrl: String, apiKey: String) {
@Query("currency") currencyCode: String
): Single<MarketInfoDetailsResponse>

@GET("transactions/dex-liquidity")
fun getDexLiquidities(
@Header("authorization") auth: String?,
@Query("coin_uid") coinUid: String,
@Query("interval") interval: String
): Single<DexLiquiditiesResponse>

@GET("transactions/dex-volumes")
fun getDexVolumes(
@Header("authorization") auth: String?,
@Query("coin_uid") coinUid: String,
@Query("interval") interval: String
): Single<DexVolumesResponse>

@GET("transactions")
fun getTransactions(
@Header("authorization") auth: String?,
@Query("coin_uid") coinUid: String,
@Query("interval") interval: String,
@Query("platform") platform: String?
): Single<TransactionsDataResponse>

@GET("addresses")
fun getActiveAddresses(
@Header("authorization") auth: String?,
@Query("coin_uid") coinUid: String,
@Query("interval") interval: String
): Single<ActiveAddressesDataResponse>

@GET("defi-protocols/{coinUid}/tvls")
fun getMarketInfoTvl(
@Path("coinUid") coinUid: String,
Expand Down

0 comments on commit 2c55ffd

Please sign in to comment.