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

Add Coin Analytics endpoints #31

Merged
merged 3 commits into from
Mar 9, 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 @@ -453,6 +453,51 @@ class MainViewModel(private val marketKit: MarketKit) : ViewModel() {
}
}

fun runAnalyticsPreview() {
val chain = "ethereum"
marketKit.analyticsPreviewSingle(chain)
.subscribeOn(Schedulers.io())
.subscribe({ data ->
Log.e("AAA", "cexVolume rank30d: ${data.cexVolume?.rank30d} points: ${data.cexVolume?.points} dexVolume rank30d: ${data.dexVolume?.rank30d} points: ${data.dexVolume?.points} ")
Log.e("AAA", "fundsInvested: ${data.fundsInvested} holders: ${data.holders} ")
}, {
Log.e("AAA", "runAnalyticsPreview error", it)
}).let {
disposables.add(it)
}
}

fun runAnalytics() {
val chain = "ethereum"
val currencyCode = "usd"
marketKit.analyticsSingle(chain, currencyCode)
.subscribeOn(Schedulers.io())
.subscribe({ data ->
Log.e("AAA", "cexVolume rank30d: ${data.cexVolume?.rank30d} points.size: ${data.cexVolume?.points?.size} transactions volume30d: ${data.transactions?.volume30d} points.size: ${data.transactions?.points?.size} ")
Log.e("AAA", "fundsInvested: ${data.fundsInvested} holders.size: ${data.holders?.size} ")
}, {
Log.e("AAA", "runAnalyticsPreview error", it)
}).let {
disposables.add(it)
}
}

fun runTokenHolders() {
val blockchainUid = "uniswap"
marketKit.tokenHoldersSingle(blockchainUid)
.subscribeOn(Schedulers.io())
.subscribe({ data ->
Log.e("AAA", "runTokenHolders count: ${data.count} holders.size: ${data.topHolders.size} ")
data.topHolders.forEach { holder ->
Log.e("AAA", "Holder: address: ${holder.address} percentage: ${holder.percentage} ")
}
}, {
Log.e("AAA", "runAnalyticsPreview error", it)
}).let {
disposables.add(it)
}
}

override fun onCleared() {
disposables.clear()
}
Expand Down
2 changes: 1 addition & 1 deletion marketkit/src/main/assets/initial_coins_list
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CREATE TABLE IF NOT EXISTS `BlockchainEntity` (`uid` TEXT NOT NULL, `name` TEXT NOT NULL, `explorerUrl` TEXT, PRIMARY KEY(`uid`));
CREATE TABLE IF NOT EXISTS `BlockchainEntity` (`uid` TEXT NOT NULL, `name` TEXT NOT NULL, `eip3091url` TEXT, PRIMARY KEY(`uid`));
CREATE TABLE IF NOT EXISTS `Coin` (`uid` TEXT NOT NULL, `name` TEXT NOT NULL, `code` TEXT NOT NULL, `marketCapRank` INTEGER, `coinGeckoId` TEXT, PRIMARY KEY(`uid`));
CREATE TABLE IF NOT EXISTS `TokenEntity` (`coinUid` TEXT NOT NULL, `blockchainUid` TEXT NOT NULL, `type` TEXT NOT NULL, `decimals` INTEGER, `reference` TEXT, PRIMARY KEY(`coinUid`, `blockchainUid`, `type`), FOREIGN KEY(`coinUid`) REFERENCES `Coin`(`uid`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`blockchainUid`) REFERENCES `BlockchainEntity`(`uid`) ON UPDATE NO ACTION ON DELETE CASCADE );
INSERT INTO BlockchainEntity VALUES('swagbucks','SwagBucks',NULL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ class MarketKit(

// Details

fun topHoldersSingle(coinUid: String): Single<List<TokenHolder>> {
return coinManager.topHoldersSingle(coinUid)
fun tokenHoldersSingle(blockchainUid: String): Single<TokenHolders> {
return hsProvider.tokenHoldersSingle(blockchainUid)
}

fun treasuriesSingle(coinUid: String, currencyCode: String): Single<List<CoinTreasury>> {
Expand Down Expand Up @@ -219,6 +219,14 @@ class MarketKit(
return coinManager.activeAddressesSingle(coinUid, currencyCode, timePeriod, sessionKey)
}

fun analyticsPreviewSingle(coinUid: String): Single<AnalyticsPreview> {
return hsProvider.analyticsPreviewSingle(coinUid)
}

fun analyticsSingle(coinUid: String, currencyCode: String): Single<Analytics> {
return hsProvider.analyticsSingle(coinUid, currencyCode)
}

// Overview
fun marketOverviewSingle(currencyCode: String): Single<MarketOverview> =
marketOverviewManager.marketOverviewSingle(currencyCode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,6 @@ class CoinManager(
return hsProvider.marketInfoGlobalTvlSingle(chain, currencyCode, timePeriod)
}

fun topHoldersSingle(coinUid: String): Single<List<TokenHolder>> {
return hsProvider.topHoldersSingle(coinUid)
}

fun treasuriesSingle(coinUid: String, currencyCode: String): Single<List<CoinTreasury>> {
return hsProvider.coinTreasuriesSingle(coinUid, currencyCode)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import java.util.*
data class Blockchain(
val type: BlockchainType,
val name: String,
val explorerUrl: String?
val eip3091url: String?
) : Parcelable {

val uid: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ data class BlockchainEntity(
@PrimaryKey
val uid: String,
val name: String,
val explorerUrl: String?
val eip3091url: String?
) {

val blockchain: Blockchain
get() = Blockchain(BlockchainType.fromUid(uid), name, explorerUrl)
get() = Blockchain(BlockchainType.fromUid(uid), name, eip3091url)

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

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

data class ProChartPointDataRaw(
Expand Down Expand Up @@ -78,3 +79,129 @@ data class ActiveAddressesDataResponse(
get() = ProChartPointDataRaw.countPoints(addresses)

}

data class Analytics(
@SerializedName("cex_volume")
val cexVolume: ExVolume?,
@SerializedName("dex_volume")
val dexVolume: ExVolume?,
@SerializedName("dex_liquidity")
val dexLiquidity: DexLiquidity?,
val addresses: Addresses?,
val transactions: Transactions?,
val revenue: Revenue?,
val tvl: Tvl?,
val reports: Int?,
@SerializedName("funds_invested")
val fundsInvested: BigDecimal?,
val treasuries: BigDecimal?,
val holders: List<HolderBlockchain>?,
) {

data class ExVolume(
@SerializedName("rank_30d")
val rank30d: Int,
val points: List<VolumePoint>,
)

data class DexLiquidity(
val rank: Int,
val points: List<VolumePoint>,
)

data class Addresses(
@SerializedName("rank_30d")
val rank30d: Int,
@SerializedName("count_30d")
val count30d: Int,
val points: List<CountPoint>,
)

data class Transactions(
@SerializedName("rank_30d")
val rank30d: Int,
@SerializedName("volume_30d")
val volume30d: BigDecimal,
val points: List<CountPoint>,
)

data class Tvl(
val rank: Int,
val ratio: BigDecimal,
val points: List<CountPoint>,
)

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

data class VolumePoint(
val volume: BigDecimal,
val timestamp: Long,
)

data class HolderBlockchain(
@SerializedName("blockchain_uid")
val blockchainUid: String,
val count: BigDecimal,
)

data class Revenue(
@SerializedName("rank_30d")
val rank30d: Int,
@SerializedName("value_30d")
val value30d: BigDecimal,
)
}

data class AnalyticsPreview(
@SerializedName("cex_volume")
val cexVolume: VolumePreview?,
@SerializedName("dex_volume")
val dexVolume: VolumePreview?,
@SerializedName("dex_liquidity")
val dexLiquidity: LiquidityPreview?,
val addresses: VolumePreview?,
val transactions: TransactionPreview?,
val revenue: RevenuePreview?,
val tvl: TvlPreview?,
val reports: Boolean = false,
@SerializedName("funds_invested")
val fundsInvested: Boolean = false,
val treasuries: Boolean = false,
val holders: Boolean = false,
) {

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

data class LiquidityPreview(
val rank: Boolean = false,
val points: Boolean = false,
)

data class TransactionPreview(
@SerializedName("rank_30d")
val rank30d: Boolean = false,
@SerializedName("volume_30d")
val volume30d: Boolean = false,
val points: Boolean = false,
)

data class RevenuePreview(
@SerializedName("rank_30d")
val rank30d: Boolean = false,
@SerializedName("value_30d")
val value30d: Boolean = false,
)

data class TvlPreview(
val rank: Boolean = false,
val ratio: Boolean = false,
val points: Boolean = false,
)
}

This file was deleted.

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 TokenHolders(
val count: BigDecimal,
@SerializedName("top_holders")
val topHolders: List<Holder>
)

data class Holder(
val address: String,
val percentage: BigDecimal,
val balance: BigDecimal
)
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ class HsProvider(baseUrl: String, apiKey: String) {
}
}

fun topHoldersSingle(coinUid: String): Single<List<TokenHolder>> {
return service.getTopHolders(coinUid)
fun tokenHoldersSingle(blockchainUid: String): Single<TokenHolders> {
return service.getTokenHolders(blockchainUid)
}

fun coinTreasuriesSingle(coinUid: String, currencyCode: String): Single<List<CoinTreasury>> {
Expand Down Expand Up @@ -225,6 +225,14 @@ class HsProvider(baseUrl: String, apiKey: String) {
return service.getAllTokens()
}

fun analyticsPreviewSingle(coinUid: String): Single<AnalyticsPreview> {
return service.getAnalyticsPreview(coinUid)
}

fun analyticsSingle(coinUid: String, currencyCode: String): Single<Analytics> {
return service.getAnalyticsData(coinUid, currencyCode)
}

private interface MarketService {

@GET("coins")
Expand Down Expand Up @@ -357,10 +365,10 @@ class HsProvider(baseUrl: String, apiKey: String) {
@Query("blockchain") blockchain: String?
): Single<List<MarketInfoTvlResponse>>

@GET("addresses/holders")
fun getTopHolders(
@Query("coin_uid") coinUid: String
): Single<List<TokenHolder>>
@GET("analytics/{blockchainUid}/holders")
fun getTokenHolders(
@Path("blockchainUid") coinUid: String
): Single<TokenHolders>

@GET("funds/treasuries")
fun getCoinTreasuries(
Expand Down Expand Up @@ -425,6 +433,17 @@ class HsProvider(baseUrl: String, apiKey: String) {
@GET("tokens/list")
fun getAllTokens(): Single<List<TokenResponse>>

@GET("analytics/{coinUid}/preview")
fun getAnalyticsPreview(
@Path("coinUid") coinUid: String,
): Single<AnalyticsPreview>

@GET("analytics/{coinUid}")
fun getAnalyticsData(
@Path("coinUid") coinUid: String,
@Query("currency") currencyCode: String,
): Single<Analytics>

companion object {
private const val marketInfoFields =
"name,code,price,price_change_24h,market_cap_rank,coingecko_id,market_cap,market_cap_rank,total_volume"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import java.util.logging.Logger
Exchange::class,
SyncerState::class,
],
version = 6,
version = 7,
exportSchema = false
)
@TypeConverters(DatabaseTypeConverters::class)
Expand Down