diff --git a/dataModule/src/main/java/com/aneonex/bitcoinchecker/datamodule/config/MarketsConfig.kt b/dataModule/src/main/java/com/aneonex/bitcoinchecker/datamodule/config/MarketsConfig.kt index 0b7e0fb0..f5e2adab 100644 --- a/dataModule/src/main/java/com/aneonex/bitcoinchecker/datamodule/config/MarketsConfig.kt +++ b/dataModule/src/main/java/com/aneonex/bitcoinchecker/datamodule/config/MarketsConfig.kt @@ -144,5 +144,6 @@ object MarketsConfig { addMarket(BitpandaPro()) addMarket(Indodax()) addMarket(Liquid()) + addMarket(WazirX()) } } \ No newline at end of file diff --git a/dataModule/src/main/java/com/aneonex/bitcoinchecker/datamodule/model/market/WazirX.kt b/dataModule/src/main/java/com/aneonex/bitcoinchecker/datamodule/model/market/WazirX.kt new file mode 100644 index 00000000..8ef49ed3 --- /dev/null +++ b/dataModule/src/main/java/com/aneonex/bitcoinchecker/datamodule/model/market/WazirX.kt @@ -0,0 +1,58 @@ +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 org.json.JSONObject +import java.util.* + +class WazirX : Market(NAME, TTS_NAME, null) { + companion object { + private const val NAME = "WazirX" + private const val TTS_NAME = "Wazir X" + private const val URL = "https://api.wazirx.com/api/v2/tickers/%1\$s" + private const val URL_CURRENCY_PAIRS = "https://api.wazirx.com/api/v2/market-status" + } + + override fun getCurrencyPairsUrl(requestId: Int): String? { + return URL_CURRENCY_PAIRS + } + + override fun parseCurrencyPairsFromJsonObject(requestId: Int, jsonObject: JSONObject, pairs: MutableList) { + val marketsJson = jsonObject.getJSONArray("markets") + for (i in 0 until marketsJson.length()) { + val market = marketsJson.getJSONObject(i) + + val baseCurrency = market.getString("baseMarket") + val qouteCurrency = market.getString("quoteMarket") + val pairId = "$baseCurrency$qouteCurrency" + + pairs.add( + CurrencyPairInfo( + baseCurrency.toUpperCase(Locale.ROOT), + qouteCurrency.toUpperCase(Locale.ROOT), + pairId + ) + ) + } + } + + override fun getUrl(requestId: Int, checkerInfo: CheckerInfo): String { + return String.format(URL, checkerInfo.currencyPairId) + } + + override fun parseTickerFromJsonObject(requestId: Int, jsonObject: JSONObject, ticker: Ticker, checkerInfo: CheckerInfo) { + jsonObject.apply { + getJSONObject("ticker").apply { + ticker.bid = getDouble("buy") + ticker.ask = getDouble("sell") + ticker.high = getDouble("high") + ticker.low = getDouble("low") + ticker.last = getDouble("last") + ticker.vol = getDouble("vol") + } + ticker.timestamp = getLong("at") + } + } +} \ No newline at end of file