Skip to content

Commit

Permalink
BitBay: added currency pairs sync
Browse files Browse the repository at this point in the history
  • Loading branch information
aneonex committed Nov 29, 2020
1 parent 9b9a371 commit 9f3300c
Showing 1 changed file with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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.currency.Currency
Expand All @@ -13,6 +14,8 @@ class BitBay : Market(NAME, TTS_NAME, CURRENCY_PAIRS) {
private const val NAME = "BitBay.net"
private const val TTS_NAME = "Bit Bay"
private const val URL = "https://bitbay.net/API/Public/%1\$s%2\$s/ticker.json"
private const val URL_CURRENCY_PAIRS = "https://api.bitbay.net/rest/trading/ticker"

private val CURRENCY_PAIRS: CurrencyPairsMap = CurrencyPairsMap()

init {
Expand Down Expand Up @@ -55,6 +58,11 @@ class BitBay : Market(NAME, TTS_NAME, CURRENCY_PAIRS) {
Currency.EUR,
Currency.GBP
)
CURRENCY_PAIRS[VirtualCurrency.LINK] = arrayOf(
VirtualCurrency.BTC,
Currency.PLN,
Currency.USD,
)
CURRENCY_PAIRS[VirtualCurrency.LSK] = arrayOf(
VirtualCurrency.BTC,
Currency.PLN,
Expand Down Expand Up @@ -101,6 +109,24 @@ class BitBay : Market(NAME, TTS_NAME, CURRENCY_PAIRS) {
}
}

override fun getCurrencyPairsUrl(requestId: Int): String {
return URL_CURRENCY_PAIRS
}

override fun parseCurrencyPairsFromJsonObject(requestId: Int, jsonObject: JSONObject, pairs: MutableList<CurrencyPairInfo>) {
val itemsJson = jsonObject.getJSONObject("items")
itemsJson.keys().forEach {
val coins = it.split('-')
if(coins.size == 2){
pairs.add( CurrencyPairInfo(
coins[0], // base
coins[1], // quote
null
))
}
}
}

override fun getUrl(requestId: Int, checkerInfo: CheckerInfo): String {
return String.format(URL, checkerInfo.currencyBase, checkerInfo.currencyCounter)
}
Expand Down

0 comments on commit 9f3300c

Please sign in to comment.