Skip to content

Commit

Permalink
Update apis for all exchanges.
Browse files Browse the repository at this point in the history
Remove Abucoins and Urdubit.
Rename OKEx to OKX.
Rename Bithumb Pro to Biglobal exchanges.
Add BitMart, Digifinex, Hoo, Mexc, XT.com, and Yadio exchanges.
Refreshed coin list.
  • Loading branch information
hwki committed Feb 26, 2022
1 parent 82480c9 commit 978aeb4
Show file tree
Hide file tree
Showing 12 changed files with 165 additions and 132 deletions.
4 changes: 2 additions & 2 deletions bitcoin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ dependencies {
implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.work:work-runtime-ktx:2.7.1'
testImplementation 'junit:junit:4.13.2'
testImplementation 'com.jayway.jsonpath:json-path:2.6.0'
testImplementation 'com.jayway.jsonpath:json-path:2.7.0'

def room_version = "2.4.1"
def room_version = "2.4.2"

implementation "androidx.room:room-runtime:$room_version"
kapt "androidx.room:room-compiler:$room_version"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ import android.os.PowerManager
*/
object NetworkStatusHelper {

fun checkBattery(context: Context): Int {
private fun checkBattery(context: Context): Int {
val powerManager = context.getSystemService(Context.POWER_SERVICE) as PowerManager
if (powerManager.isPowerSaveMode && !powerManager.isIgnoringBatteryOptimizations(context.packageName)) {
return R.string.error_restricted_battery_saver
}
return 0
}

fun checkBackgroundData(context: Context): Int {
private fun checkBackgroundData(context: Context): Int {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
val connectivityManager = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
val restrictBackgroundStatus = connectivityManager.restrictBackgroundStatus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,19 @@ object DataMigration {

fun migrate(db: SupportSQLiteDatabase) {
migrateBitBayToZonda(db)
migrateOkexToOkx(db)
migrateBithumbProToBitGlobal(db)
fixRemovedExchanges(db)
}

private fun migrateBithumbProToBitGlobal(db: SupportSQLiteDatabase) {
db.execSQL("UPDATE Widget SET exchange = 'BITGLOBAL' WHERE exchange = 'BITHUMB_PRO'")
}

private fun migrateOkexToOkx(db: SupportSQLiteDatabase) {
db.execSQL("UPDATE Widget SET exchange = 'OKX' WHERE exchange = 'OKEX'")
}

private fun migrateBitBayToZonda(db: SupportSQLiteDatabase) {
db.execSQL("UPDATE Widget SET exchange = 'ZONDA' WHERE exchange = 'BITBAY'")
}
Expand Down

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion bitcoin/src/main/res/raw/cryptowidgetcoins_v2.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion bitcoin/src/main/res/raw/othercoins.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions bitcoin/src/main/res/values-pt-rBR/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
<string name="summary_refresh_interval">A cada %s</string>
<string name="summary_currency">Usar %s como moeda</string>
<string name="summary_exchange">Pegar data de %s</string>
<string name="summary_units">Mostrar %s em %s</string>
<string name="summary_inverse">Mostrar preço de %s em %s</string>
<string name="summary_units">Mostrar %1$s em %2$s</string>
<string name="summary_inverse">Mostrar preço de %1$s em %2$s</string>

<string-array name="themes" tools:ignore="InconsistentArrays">
<item>Tema Sólida</item>
Expand Down
4 changes: 2 additions & 2 deletions bitcoin/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
<string name="summary_refresh_interval">Every %s</string>
<string name="summary_currency">Use %s as currency</string>
<string name="summary_exchange">Get data from %s</string>
<string name="summary_units">Show %s as %s</string>
<string name="summary_inverse">Show price of %s in %s</string>
<string name="summary_units">Show %1$s as %2$s</string>
<string name="summary_inverse">Show price of %1$s in %2$s</string>

<string name="licenses" translatable="false"><![CDATA[
Licenses:<br/><br/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class ExchangeTest {
if (currencyName == null) currencyName = currency
valueOf(exchange).getValue(coinName, currencyName)!!.toDouble()
} catch (e: Exception) {
println("Failure: $coin $exchange $currency: ${e.message}")
System.err.println("Failure: $coin $exchange $currency: ${e.message}")
}
Thread.sleep(1500)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import java.io.InputStreamReader
import java.net.SocketTimeoutException
import java.util.concurrent.TimeUnit
import kotlin.math.roundToInt
import kotlin.streams.asSequence

class GeneratePartiallySupportedCoins {

Expand Down Expand Up @@ -44,7 +45,7 @@ class GeneratePartiallySupportedCoins {
val failed = mutableListOf<JsonObject>()
val total = allCoins.count()
var index = 0
for (obj in allCoins.map { it.asJsonObject }.stream()) {
for (obj in allCoins.map { it.asJsonObject }.stream().asSequence()) {
index++
if (index % 100 == 0) {
println("${(index * 100.0 / total).roundToInt()}%")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@ class GenerateSupportedCoinsJson {
allCurrencies = Currency.getAvailableCurrencies().asSequence().map { it.currencyCode }.plus(allCoins).plus(allCoinOverrides.keys).toSet()
System.err.println("all currencies: ${allCurrencies.sorted()}")
val exchanges =
listOf(this::abucoins, this::ascendex, this::bibox, this::bigone, this::binance, this::binance_us, this::bit2c,
listOf(this::ascendex, this::bibox, this::bigone, this::binance, this::binance_us, this::bit2c,
this::bitbank, this::bitcambio, this::bitclude,
this::bitcoinde, this::bitfinex, this::bitflyer, this::bithumb, this::bithumbpro, this::bitmex,
this::bitcoinde, this::bitfinex, this::bitflyer, this::bithumb, this::bitglobal, this::bitmart, this::bitmex,
this::bitpanda, this::bitpay, this::bitso, this::bitstamp, this::bittrex, this::bitrue, this::bitvavo, this::bleutrade,
this::btcbox, this::btcmarkets, this::btcturk, this::bybit, this::cexio,
this::chilebit, this::coinbase, this::coinbasepro, this::coindesk, this::coingecko,
this::coinjar, this::coinmate, this::coinone, this::coinsbit, this::coinsph, this::cointree,
this::cryptocom, this::deversifi, this::exmo, this::ftx, this::ftx_us, this::foxbit, this::gateio, this::gemini, this::hitbtc,
this::huobi, this::independent_reserve, this::indodax, this::itbit, this::korbit, this::kraken, this::kucoin,
this::kuna, this::lbank, this::liquid, this::luno, this::mercado, this::ndax,
this::nexchange, this::okcoin, this::okex, this::p2pb2b, this::paribu, this::paymium, this::phemex,
this::cryptocom, this::deversifi, this::digifinex, this::exmo, this::ftx, this::ftx_us, this::foxbit, this::gateio, this::gemini, this::hitbtc,
this::hoo, this::huobi, this::independent_reserve, this::indodax, this::itbit, this::korbit, this::kraken, this::kucoin,
this::kuna, this::lbank, this::liquid, this::luno, this::mercado, this::mexc, this::ndax,
this::nexchange, this::okcoin, this::okx, this::p2pb2b, this::paribu, this::paymium, this::phemex,
this::pocketbits, this::poloniex, this::probit, this::therock, this::tradeogre, this::uphold,
this::urdubit, this::vbtc, this::whitebit, this::wyre, this::yobit, this::zb, this::zbg, this::zonda
this::vbtc, this::whitebit, this::wyre, this::xt, this::yadio, this::yobit, this::zb, this::zbg, this::zonda
).zip(Exchange.values())

val jsonMap = mutableMapOf<String, List<*>>()
Expand Down Expand Up @@ -217,16 +217,12 @@ class GenerateSupportedCoinsJson {

// region exchange methods

private fun abucoins(): List<String> {
return parse("https://api.abucoins.com/products", "$[*].id")
}

private fun ascendex(): List<String> {
return parse("https://ascendex.com/api/pro/v1/products", "$.data[?(@.status=='Normal')].symbol")
}

private fun bibox(): List<String> {
return parse("https://api.bibox.com/v1/mdata?cmd=pairList", "$.result[*].pair")
return parse("https://api.bibox.com/v3/mdata/pairList", "$.result[*].pair")
}

private fun bigone(): List<String> {
Expand All @@ -248,18 +244,19 @@ class GenerateSupportedCoinsJson {
}

private fun bitbank(): List<String> {
return parse("https://api.bitbank.cc/v1/spot/pairs", "$.data.pairs[*].name")
return parse("https://public.bitbank.cc/tickers", "$.data[*].pair")
}

private fun bitcambio(): List<String> {
return listOf("BTC_BRL")
return parse("https://nova.bitcambio.com.br/api/v3/public/getmarkets", "$.result.[*].MarketName")
}

private fun bitclude(): List<String> {
return parseKeys("https://api.bitclude.com/stats/ticker.json", "$")
}

private fun bitcoinde(): List<String> {
// exchange supports more but only can get ticker data for btc-eur
return listOf("BTC-EUR")
}

Expand All @@ -271,20 +268,24 @@ class GenerateSupportedCoinsJson {

private fun bitflyer(): List<String> {
val pairs = mutableListOf<String>()
pairs.addAll(parse("https://api.bitflyer.jp/v1/markets", "$[*].product_code"))
pairs.addAll(parse("https://api.bitflyer.jp/v1/markets/usa", "$[*].product_code"))
pairs.addAll(parse("https://api.bitflyer.jp/v1/markets/eu", "$[*].product_code"))
pairs.addAll(parse("https://api.bitflyer.com/v1/markets", "$[*].product_code"))
pairs.addAll(parse("https://api.bitflyer.com/v1/markets/usa", "$[*].product_code"))
pairs.addAll(parse("https://api.bitflyer.com/v1/markets/eu", "$[*].product_code"))
return pairs
}

private fun bithumb(): List<String> {
return parseKeys("https://api.bithumb.com/public/ticker/ALL", "$.data").map { "${it}_KRW" }
}

private fun bithumbpro() : List<String> {
private fun bitglobal() : List<String> {
return parse("https://global-openapi.bithumb.pro/openapi/v1/spot/ticker?symbol=ALL", "$.data[*].s")
}

private fun bitmart(): List<String> {
return parse("https://api-cloud.bitmart.com/spot/v1/symbols", "$.data.symbols.[*]")
}

private fun bitmex(): List<String> {
return parse("https://www.bitmex.com/api/v1/instrument/active", "$.[*].symbol")
}
Expand All @@ -300,8 +301,8 @@ class GenerateSupportedCoinsJson {
}

private fun bitpay(): List<String> {
return parse("https://bitpay.com/currencies", "$.data[*].code").map {
"BTC_$it"
return parse("https://bitpay.com/currencies", "$.data[*].code").flatMap {
listOf("BTC_$it", "BCH_$it")
}
}

Expand Down Expand Up @@ -358,14 +359,13 @@ class GenerateSupportedCoinsJson {
return listOf("BTC_CLP")
}

@Suppress("UNCHECKED_CAST")
private fun coinbase(): List<String> {
val currencies = parse("https://api.coinbase.com/v2/currencies", "$.data[*].id")
return parseKeys("https://api.coinbase.com/v2/exchange-rates", "$.data.rates").filterNot {
it == "XRP"
}.map {
}.flatMap {
coin -> currencies.map { "${coin}_$it" }
}.flatten()
}
}

private fun coinbasepro(): List<String> {
Expand Down Expand Up @@ -422,6 +422,10 @@ class GenerateSupportedCoinsJson {
}
}

private fun digifinex(): List<String> {
return parse("https://openapi.digifinex.com/v3/ticker", "$.ticker.[*].symbol")
}

private fun exmo(): List<String> {
return parseKeys("https://api.exmo.com/v1.1/ticker", "$")
}
Expand Down Expand Up @@ -449,7 +453,11 @@ class GenerateSupportedCoinsJson {
}

private fun hitbtc(): List<String> {
return parse("https://api.hitbtc.com/api/2/public/symbol", "$[*].id")
return parseKeys("https://api.hitbtc.com/api/3/public/symbol", "$")
}

private fun hoo(): List<String> {
return parse("https://api.hoolgd.com/open/v1/tickers/market", "$.data[*].symbol")
}

private fun huobi(): List<String> {
Expand All @@ -470,9 +478,8 @@ class GenerateSupportedCoinsJson {
return parse("https://api.paxos.com/v2/markets", "$.markets[*].market")
}

@Suppress("UNCHECKED_CAST")
private fun korbit(): List<String> {
return parseKeys("https://api.korbit.co.kr/v1/constants", "$.exchange")
return parseKeys("https://api.korbit.co.kr/v1/ticker/detailed/all", "$")
}

private fun kraken(): List<String> {
Expand Down Expand Up @@ -500,7 +507,12 @@ class GenerateSupportedCoinsJson {
}

private fun mercado(): List<String> {
return listOf("BCH_BRL", "BTC_BRL", "ETH_BRL", "LTC_BRL", "XRP_BRL")
return parse("https://api.mercadobitcoin.net/api/v4/symbols", "$.symbol.[*]")
}

private fun mexc(): List<String> {
val pairs = parse("https://www.mexc.com/open/api/v2/market/symbols", "$.data.[*].symbol")
return pairs.filterNot { it.contains("USDC") }
}

private fun ndax(): List<String> {
Expand All @@ -515,8 +527,8 @@ class GenerateSupportedCoinsJson {
return parse("https://www.okcoin.com/api/spot/v3/instruments", "$[*].instrument_id")
}

private fun okex(): List<String> {
return parse("https://www.okex.com/api/spot/v3/instruments", "$[*].instrument_id")
private fun okx(): List<String> {
return parse("https://www.okx.com/api/v5/public/instruments?instType=SPOT", "$.data[*].instId")
}

private fun p2pb2b(): List<String> {
Expand All @@ -532,7 +544,9 @@ class GenerateSupportedCoinsJson {
}

private fun phemex(): List<String> {
return listOf("BTC_USDT", "XRP_USDT", "ETH_USDT", "LINK_USDT", "XTZ_USDT", "LTC_USDT")
val list = JsonPath.read(get("https://api.phemex.com/public/products"),
"$.data.products.[?(@.status == 'Listed' && @.type == 'Spot')]") as List<Map<String, *>>
return list.map { "${it["baseCurrency"]}-${it["quoteCurrency"]}" }
}

private fun pocketbits(): List<String> {
Expand All @@ -558,30 +572,10 @@ class GenerateSupportedCoinsJson {
return list.map { it.keys.first().split("-").reversed().joinToString("_") }
}

@Suppress("UNCHECKED_CAST")
private fun uphold(): List<String> {
val all = Gson().fromJson(get("https://api.uphold.com/v0/reserve/statistics"), List::class.java) as List<Map<String, Any>>
// uphold lists all its currencies in tiers. first crypto, then fiat, then stocks. we need to only pull the first tiers
// the only good way to do this is check alphabetical order
val pairs = mutableListOf<String>()
for (entry in all) {
var tier = 0
var lastCharacter = 'A'
for (value in entry["values"] as List<Map<String, String>>) {
val char = value["currency"]?.first() ?: 'A'
if (char < lastCharacter) {
tier++
}
if (tier == 2) break
lastCharacter = char
pairs.add("${entry["currency"].toString()}_${value["currency"]}")
}
}
return pairs
}

private fun urdubit(): List<String> {
return listOf("BTC_PKR")
val currencies = parse("https://api.uphold.com/v0/assets?q=type:fiat", "$.[?(@.status == 'open')].code")
val coins = parse("https://api.uphold.com/v0/assets", "$.[?(@.status == 'open' && @.type in ['cryptocurrency', 'utility_token', 'stablecoin'])].code")
return coins.flatMap { i -> currencies.plus(coins).map { j -> "$i-$j" } }
}

private fun vbtc(): List<String> {
Expand All @@ -600,12 +594,21 @@ class GenerateSupportedCoinsJson {
return split1.plus(split2).distinct()
}

private fun xt(): List<String> {
return parseKeys("https://api.xt.com/data/api/v1/getTickers", "$")
}

private fun yadio(): List<String> {
val currencies = parseKeys("https://api.yadio.io/currencies", "$")
return currencies.map { "BTC-$it" }
}

private fun yobit(): List<String> {
return parseKeys("https://yobit.net/api/3/info", "$.pairs")
}

private fun zb(): List<String> {
return parseKeys("http://api.zb.land/data/v1/markets", "$")
return parseKeys("http://api.zb.cafe/data/v1/markets", "$")
}

private fun zbg(): List<String> {
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.1.1'
classpath 'com.android.tools.build:gradle:7.1.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

// NOTE: Do not place your application dependencies here; they belong
Expand Down

0 comments on commit 978aeb4

Please sign in to comment.