Skip to content

Commit

Permalink
Added Pocketbits exchange.
Browse files Browse the repository at this point in the history
Added Polygon coin.
Removed Bitcoin Average.
  • Loading branch information
hwki committed May 28, 2021
1 parent 1a4f02a commit b2acbca
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 40 deletions.
8 changes: 4 additions & 4 deletions bitcoin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ android {
applicationId "com.brentpanther.bitcoinwidget"
minSdkVersion 21
targetSdkVersion 30
versionCode 261
versionName "7.4.2"
versionCode 262
versionName "7.4.3"
}

buildTypes {
Expand All @@ -36,9 +36,9 @@ android {
}

dependencies {
implementation "androidx.appcompat:appcompat:1.2.0"
implementation "androidx.appcompat:appcompat:1.3.0"
implementation "androidx.recyclerview:recyclerview:1.2.0"
implementation "androidx.core:core-ktx:1.3.2"
implementation "androidx.core:core-ktx:1.5.0"
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.preference:preference-ktx:1.1.1'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ enum class Coin(val coinName: String, @param:DrawableRes val icon: Int, internal
},
LTO("LTO Network", ic_lto, mapOf(L to ic_lto, LO to ic_lto_gray)),
MANA("Decentraland", ic_mana, mapOf(L to ic_mana, LO to ic_mana_gray)),
MATIC("Polygon", ic_matic, mapOf(L to ic_matic, LO to ic_matic_gray)),
MCO("MCO", ic_mco, mapOf(L to ic_mco, LO to ic_mco_gray, D to ic_mco_white)),
MKR("Maker", ic_mkr, mapOf(L to ic_mkr, LO to ic_mkr_gray)),
MLN("Melon", ic_mln, mapOf(L to ic_mln, LO to ic_mln_gray)),
Expand Down
29 changes: 13 additions & 16 deletions bitcoin/src/main/java/com/brentpanther/bitcoinwidget/Exchange.kt
Original file line number Diff line number Diff line change
Expand Up @@ -81,22 +81,6 @@ internal enum class Exchange(val exchangeName: String, shortName: String? = null
return obj.getAsJsonObject("${coin.lowercase(Locale.ROOT)}_${currency.lowercase(Locale.ROOT)}").get("last").asString
}
},
BITCOIN_AVERAGE("Bitcoin Average", "BTC avg") {

override fun getValue(coin: String, currency: String): String {
val url = "https://apiv2.bitcoinaverage.com/indices/local/ticker/short?crypto=$coin&fiats=$currency"
val obj = getJsonObject(url)
return obj.getAsJsonObject("$coin$currency").get("last").asString
}
},
BITCOIN_AVERAGE_GLOBAL("Bitcoin Average (global)", "BTC avg global") {

override fun getValue(coin: String, currency: String): String {
val url = "https://apiv2.bitcoinaverage.com/indices/global/ticker/short?crypto=$coin&fiats=$currency"
val obj = getJsonObject(url)
return obj.getAsJsonObject("$coin$currency").get("last").asString
}
},
BITCOINDE("Bitcoin.de") {

override fun getValue(coin: String, currency: String): String {
Expand Down Expand Up @@ -356,6 +340,7 @@ internal enum class Exchange(val exchangeName: String, shortName: String? = null
"LTC" to "litecoin",
"LTO" to "lto-network",
"MANA" to "decentraland",
"MATIC" to "matic-network",
"MCO" to "monaco",
"MKR" to "maker",
"MLN" to "melon",
Expand Down Expand Up @@ -681,6 +666,18 @@ internal enum class Exchange(val exchangeName: String, shortName: String? = null
return (value.toDouble() / 10.0.pow(8)).toString()
}
},
POCKETBITS("Pocketbits") {

override fun getValue(coin: String, currency: String): String? {
val url = "https://ticker.pocketbits.in/api/v1/ticker"
val obj = getJsonArray(url).firstOrNull {
it.asJsonObject.get("symbol").asString == "$coin$currency"
}?.asJsonObject ?: return null
val buy = obj.get("buy").asString.toDouble()
val sell = obj.get("sell").asString.toDouble()
return ((buy + sell) / 2).toString()
}
},
POLONIEX("Poloniex") {

override fun getValue(coin: String, currency: String): String {
Expand Down
Binary file added bitcoin/src/main/res/drawable-nodpi/ic_matic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion bitcoin/src/main/res/raw/cryptowidgetcoins.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.

2 changes: 1 addition & 1 deletion bitcoin/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
</string-array>
<string name="value_unknown" translatable="false">\u0020\u0020\u0020\?\u0020\u0020\u0020</string>
<string name="value_exchange_removed" translatable="false">\u0020!\u0020</string>
<string name="json_last_modified" translatable="false">Mon, 17 May 2021 00:00:00 GMT</string>
<string name="json_last_modified" translatable="false">Fri, 28 May 2021 16:00:00 GMT</string>
<string name="json_url" translatable="false">https://www.brentpanther.com/cryptowidgetcoins.json</string>

<string name="dialog_update_title">Updating</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ class ExchangeTest {
val data = ExchangeData(entry, loadJSON())
for (currency in data.currencies.sorted()) {
for (exchange in data.getExchanges(currency).toList().parallelStream()) {
// ignore exchanges that get grumpy for too many requests
if (exchange == "BITCOIN_AVERAGE") continue
if (exchange == "BITCOIN_AVERAGE_GLOBAL") continue
try {
var coinName = data.getExchangeCoinName(exchange)
var currencyName = data.getExchangeCurrencyName(exchange, currency)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ class GeneratePartiallySupportedCoins {
private val listUrl = "https://api.coingecko.com/api/v3/coins/list?include_platform=false"
private val dataUrl = "https://api.coingecko.com/api/v3/coins/"
private val dataUrl2 = "?localization=false&tickers=false&market_data=false&community_data=false&developer_data=false"
private val scoreLimit = 1
private val scoreLimit = 3

@Test
fun generate() {
val allCoins = Gson().fromJson(get(listUrl), JsonArray::class.java)
val existing = getExistingCoins()
existing.clear()
val initialCount = existing.count()
println("Filtering coins..")
val failed = mutableListOf<JsonObject>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class GenerateSupportedCoinsJson {

val exchanges =
listOf(this::abucoins, this::bibox, this::bigone, this::binance, this::binance_us, this::bit2c,
this::bitbank, this::bitbay, this::bitcambio, this::bitclude, this::bitcoinAverage, this::bitcoinAverageGlobal,
this::bitbank, this::bitbay, this::bitcambio, this::bitclude,
this::bitcoinde, this::bitfinex, this::bitflyer, this::bithumb, this::bithumbpro, this::bitmax, this::bitmex,
this::bitpay, this::bitso, this::bitstamp, this::bittrex, this::bitvavo, this::bleutrade,
this::braziliex, this::btcbox, this::btcmarkets, this::btcturk, this::bybit, this::cexio,
Expand All @@ -33,7 +33,8 @@ class GenerateSupportedCoinsJson {
this::cryptocom, this::deversifi, this::duedex, this::exmo, this::ftx, 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::lakebtc, this::lbank, this::liquid, this::luno, this::mercado,
this::nexchange, this::okcoin, this::okex, this::p2pb2b, this::paribu, this::paymium, this::phemex, this::poloniex,
this::nexchange, this::okcoin, this::okex, 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
).zip(Exchange.values())
Expand Down Expand Up @@ -232,14 +233,6 @@ class GenerateSupportedCoinsJson {
return parseKeys("https://api.bitclude.com/stats/ticker.json", "$")
}

private fun bitcoinAverage(): List<String> {
return parse("https://apiv2.bitcoinaverage.com/info/indices/ticker/local", "$.symbols[*]")
}

private fun bitcoinAverageGlobal(): List<String> {
return parse("https://apiv2.bitcoinaverage.com/info/indices/ticker/global", "$.symbols[*]")
}

private fun bitcoinde(): List<String> {
return listOf("BTC-EUR")
}
Expand Down Expand Up @@ -520,6 +513,10 @@ class GenerateSupportedCoinsJson {
return listOf("BTC_USDT", "XRP_USDT", "ETH_USDT", "LINK_USDT", "XTZ_USDT", "LTC_USDT")
}

private fun pocketbits(): List<String> {
return parse("https://ticker.pocketbits.in/api/v1/ticker", "$[*].symbol")
}

private fun poloniex(): List<String> {
return parseKeys("https://poloniex.com/public?command=returnTicker", "$").map {
it.split("_").reversed().joinToString("_")
Expand Down Expand Up @@ -576,8 +573,8 @@ class GenerateSupportedCoinsJson {
private fun wyre(): List<String> {
// is in currency - coin format
val list = parseKeys("https://api.sendwyre.com/v3/rates", "$")
val split1 = list.map { it.substring(it.length / 2, it.length) + "_" + it.substring(0, it.length / 2) }
val split2 = list.map { it.substring(ceil(7.0 / 2).toInt(), it.length) + "_" + it.substring(0, ceil(7.0 / 2).toInt()) }
val split1 = list.map { it.substring(3, it.length) + "_" + it.substring(0, 3) }
val split2 = list.map { it.substring(4, it.length) + "_" + it.substring(0, 4) }
return split1.plus(split2).distinct()
}

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.5.0'
ext.kotlin_version = '1.5.10'
repositories {
google()
mavenCentral()
Expand Down
3 changes: 3 additions & 0 deletions fastlane/metadata/android/en-US/changelogs/262.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Added Pocketbits exchange.
Added Polygon coin.
Removed Bitcoin Average, as their API is no longer public.

0 comments on commit b2acbca

Please sign in to comment.