Skip to content

Commit

Permalink
Merge pull request #20 from aneonex/features/add-WazirX
Browse files Browse the repository at this point in the history
Added WazirX exchange
  • Loading branch information
aneonex authored Oct 18, 2020
2 parents 26cc4d4 + 8db8574 commit f729db2
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,5 +144,6 @@ object MarketsConfig {
addMarket(BitpandaPro())
addMarket(Indodax())
addMarket(Liquid())
addMarket(WazirX())
}
}
Original file line number Diff line number Diff line change
@@ -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<CurrencyPairInfo>) {
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")
}
}
}

0 comments on commit f729db2

Please sign in to comment.