Skip to content

Commit

Permalink
Added CoinJar Exchange
Browse files Browse the repository at this point in the history
  • Loading branch information
aneonex committed Aug 6, 2021
1 parent 7cb70ee commit 8e6da11
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ object MarketsConfig {
Foxbit(),

Bitkub(),

CoinJarExchange(),
)

@kotlin.jvm.JvmField
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ class CoinJar : Market(NAME, TTS_NAME, null) {
}

companion object {
private const val NAME = "CoinJar"
private const val TTS_NAME = "Coin Jar"
private const val NAME = "CoinJar Prices"
private const val TTS_NAME = "Coin Jar prices"
private const val URL = "https://api.coinjar.com/v3/exchange_rates"
private const val URL_CURRENCY_PAIRS = URL
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.aneonex.bitcoinchecker.datamodule.model.market

import com.aneonex.bitcoinchecker.datamodule.model.CheckerInfo
import com.aneonex.bitcoinchecker.datamodule.model.CurrencyPairInfo
import com.aneonex.bitcoinchecker.datamodule.model.Market
import com.aneonex.bitcoinchecker.datamodule.model.Ticker
import com.aneonex.bitcoinchecker.datamodule.model.market.generic.SimpleMarket
import com.aneonex.bitcoinchecker.datamodule.util.TimeUtils
import com.aneonex.bitcoinchecker.datamodule.util.forEachJSONObject
import org.json.JSONArray
import org.json.JSONObject

class CoinJarExchange : SimpleMarket(
"CoinJar Exchange",
"https://api.exchange.coinjar.com/products",
"https://data.exchange.coinjar.com/products/%1\$s/ticker",
"Coin Jar exchange") {

override fun parseTickerFromJsonObject(requestId: Int, jsonObject: JSONObject, ticker: Ticker, checkerInfo: CheckerInfo) {
ticker.apply {
bid = jsonObject.getDouble("bid")
ask = jsonObject.getDouble("ask")
last = jsonObject.getDouble("last")
vol = jsonObject.getDouble("volume_24h")
timestamp = TimeUtils.convertISODateToTimestamp(jsonObject.getString("current_time"))
}
}

override fun parseCurrencyPairs(
requestId: Int,
responseString: String,
pairs: MutableList<CurrencyPairInfo>
) {
JSONArray(responseString).forEachJSONObject {
val assets = it.getString("name").split('/')
if(assets.size == 2) {
pairs.add(
CurrencyPairInfo(
assets[0],
assets[1],
it.getString("id")
)
)
}
}
}
}

0 comments on commit 8e6da11

Please sign in to comment.