-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
Added new exchanges and removed legacy
There are no files selected for viewing
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
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 | ||
|
||
class Ftx : Market(NAME, TTS_NAME, null) { | ||
companion object { | ||
private const val NAME = "FTX" | ||
private const val TTS_NAME = "FTX" | ||
private const val URL = "https://ftx.com/api/markets/%1\$s" | ||
private const val URL_CURRENCY_PAIRS = "https://ftx.com/api/markets" | ||
} | ||
|
||
override fun getCurrencyPairsUrl(requestId: Int): String? { | ||
return URL_CURRENCY_PAIRS | ||
} | ||
|
||
override fun parseCurrencyPairsFromJsonObject(requestId: Int, jsonObject: JSONObject, pairs: MutableList<CurrencyPairInfo>) { | ||
val markets = jsonObject.getJSONArray("result") | ||
for(i in 0 until markets.length()){ | ||
val market = markets.getJSONObject(i) | ||
|
||
if(market.getString("type") != "spot") continue | ||
|
||
pairs.add( CurrencyPairInfo( | ||
market.getString("baseCurrency"), | ||
market.getString("quoteCurrency"), | ||
market.getString("name"), | ||
)) | ||
} | ||
|
||
} | ||
|
||
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) { | ||
val market = jsonObject.getJSONObject("result") | ||
|
||
ticker.bid = market.getDouble("bid") | ||
ticker.ask = market.getDouble("ask") | ||
ticker.last = market.getDouble("last") | ||
|
||
if(ticker.last > 0) | ||
ticker.vol = market.getDouble("quoteVolume24h") / ticker.last | ||
} | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
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.JSONArray | ||
import org.json.JSONObject | ||
|
||
class GateIo : Market(NAME, TTS_NAME, null) { | ||
|
||
companion object { | ||
private const val NAME = "Gate.io" | ||
private const val TTS_NAME = "Gate io" | ||
private const val URL = "https://api.gateio.ws/api/v4/spot/tickers?currency_pair=%1\$s" | ||
private const val URL_CURRENCY_PAIRS = "https://api.gateio.ws/api/v4/spot/currency_pairs" | ||
} | ||
|
||
override fun getUrl(requestId: Int, checkerInfo: CheckerInfo): String { | ||
return String.format(URL, checkerInfo.currencyPairId) | ||
} | ||
|
||
override fun parseTicker(requestId: Int, responseString: String, ticker: Ticker, checkerInfo: CheckerInfo) { | ||
val jsonArray = JSONArray(responseString) | ||
if(jsonArray.length() < 1) throw ArrayIndexOutOfBoundsException("No data") | ||
|
||
val jsonObject = jsonArray.getJSONObject(0) | ||
|
||
ticker.bid = jsonObject.getDouble("highest_bid") | ||
ticker.ask = jsonObject.getDouble("lowest_ask") | ||
ticker.vol = jsonObject.getDouble("base_volume") | ||
ticker.high = jsonObject.getDouble("high_24h") | ||
ticker.low = jsonObject.getDouble("low_24h") | ||
ticker.last = jsonObject.getDouble("last") | ||
} | ||
|
||
// ==================== | ||
// Get currency pairs | ||
// ==================== | ||
override fun getCurrencyPairsUrl(requestId: Int): String? { | ||
return URL_CURRENCY_PAIRS | ||
} | ||
|
||
@Throws(Exception::class) | ||
override fun parseCurrencyPairs(requestId: Int, responseString: String, pairs: MutableList<CurrencyPairInfo>) { | ||
val jsonArray = JSONArray(responseString) | ||
|
||
for (i in 0 until jsonArray.length()) { | ||
val pairJson = jsonArray.getJSONObject(i) | ||
|
||
if(pairJson.getString("trade_status") != "tradable") continue | ||
|
||
pairs.add(CurrencyPairInfo( | ||
pairJson.getString("base"), | ||
pairJson.getString("quote"), | ||
pairJson.getString("id") | ||
)) | ||
} | ||
} | ||
} |
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
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.JSONArray | ||
import org.json.JSONObject | ||
|
||
class Okex : Market(NAME, TTS_NAME, null) { | ||
companion object { | ||
private const val NAME = "OKEx" | ||
private const val TTS_NAME = "OKEX" | ||
private const val URL = "https://www.okex.com/api/spot/v3/instruments/%1\$s/ticker" | ||
private const val URL_CURRENCY_PAIRS = "https://www.okex.com/api/spot/v3/instruments" | ||
} | ||
|
||
override fun getCurrencyPairsUrl(requestId: Int): String? { | ||
return URL_CURRENCY_PAIRS | ||
} | ||
|
||
@Throws(Exception::class) | ||
override fun parseCurrencyPairs(requestId: Int, responseString: String, pairs: MutableList<CurrencyPairInfo>) { | ||
val pairsArray = JSONArray(responseString) | ||
for (i in 0 until pairsArray.length()) { | ||
val pairJson = pairsArray.getJSONObject(i) | ||
pairs.add(CurrencyPairInfo( | ||
pairJson.getString("base_currency"), | ||
pairJson.getString("quote_currency"), | ||
pairJson.getString("instrument_id"))) | ||
} | ||
} | ||
|
||
override fun getUrl(requestId: Int, checkerInfo: CheckerInfo): String { | ||
var pairId = checkerInfo.currencyPairId | ||
if(pairId == null){ | ||
pairId = "${checkerInfo.currencyBase}-${checkerInfo.currencyCounter}" | ||
} | ||
return String.format(URL, pairId) | ||
} | ||
|
||
@Throws(Exception::class) | ||
override fun parseTickerFromJsonObject(requestId: Int, jsonObject: JSONObject, ticker: Ticker, checkerInfo: CheckerInfo) { | ||
// val tickerJsonObject = jsonObject.getJSONObject("ticker") | ||
ticker.bid = jsonObject.getDouble("bid") | ||
ticker.ask = jsonObject.getDouble("ask") | ||
ticker.vol = jsonObject.getDouble("base_volume_24h") | ||
ticker.high = jsonObject.getDouble("high_24h") | ||
ticker.low = jsonObject.getDouble("low_24h") | ||
ticker.last = jsonObject.getDouble("last") | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package com.aneonex.bitcoinchecker.datamodule.model.market | ||
|
||
import com.aneonex.bitcoinchecker.datamodule.model.CheckerInfo | ||
import com.aneonex.bitcoinchecker.datamodule.model.Futures | ||
import com.aneonex.bitcoinchecker.datamodule.model.FuturesMarket | ||
import com.aneonex.bitcoinchecker.datamodule.model.Ticker | ||
import com.aneonex.bitcoinchecker.datamodule.model.currency.Currency | ||
import com.aneonex.bitcoinchecker.datamodule.model.currency.CurrencyPairsMap | ||
import com.aneonex.bitcoinchecker.datamodule.model.currency.VirtualCurrency | ||
import org.json.JSONObject | ||
import java.time.ZonedDateTime | ||
|
||
class OkexFutures : FuturesMarket(NAME, TTS_NAME, CURRENCY_PAIRS, CONTRACT_TYPES) { | ||
companion object { | ||
private const val NAME = "OKEx Futures" | ||
private const val TTS_NAME = "Okex Futures" | ||
private const val URL = "https://www.okex.com/api/futures/v3/instruments/%1\$s/ticker" | ||
private val CURRENCY_PAIRS: CurrencyPairsMap = CurrencyPairsMap() | ||
private val CONTRACT_TYPES = intArrayOf( | ||
Futures.CONTRACT_TYPE_WEEKLY, | ||
Futures.CONTRACT_TYPE_BIWEEKLY, | ||
Futures.CONTRACT_TYPE_QUARTERLY, | ||
Futures.CONTRACT_TYPE_BIQUARTERLY | ||
) | ||
|
||
init { | ||
CURRENCY_PAIRS[VirtualCurrency.BTC] = arrayOf( | ||
Currency.USD, | ||
VirtualCurrency.USDT | ||
) | ||
CURRENCY_PAIRS[VirtualCurrency.ETH] = arrayOf( | ||
Currency.USD, | ||
VirtualCurrency.USDT | ||
) | ||
CURRENCY_PAIRS[VirtualCurrency.LTC] = arrayOf( | ||
Currency.USD, | ||
VirtualCurrency.USDT | ||
) | ||
CURRENCY_PAIRS[VirtualCurrency.EOS] = arrayOf( | ||
Currency.USD, | ||
VirtualCurrency.USDT | ||
) | ||
CURRENCY_PAIRS[VirtualCurrency.XRP] = arrayOf( | ||
Currency.USD, | ||
VirtualCurrency.USDT | ||
) | ||
CURRENCY_PAIRS[VirtualCurrency.BCH] = arrayOf( | ||
Currency.USD, | ||
VirtualCurrency.USDT | ||
) | ||
CURRENCY_PAIRS[VirtualCurrency.TRX] = arrayOf( | ||
Currency.USD, | ||
VirtualCurrency.USDT | ||
) | ||
CURRENCY_PAIRS[VirtualCurrency.LINK] = arrayOf( | ||
Currency.USD, | ||
VirtualCurrency.USDT | ||
) | ||
} | ||
} | ||
|
||
public override fun getUrl(requestId: Int, checkerInfo: CheckerInfo, contractType: Int): String { | ||
return String.format(URL, getInstrumentId(checkerInfo.currencyBase, checkerInfo.currencyCounter, contractType)) | ||
} | ||
|
||
private fun getInstrumentId(currencyBase: String, currencyCounter: String, contractType: Int): String { | ||
val suffix = when (contractType) { | ||
Futures.CONTRACT_TYPE_WEEKLY -> "201009" | ||
Futures.CONTRACT_TYPE_BIWEEKLY -> "201016" | ||
Futures.CONTRACT_TYPE_QUARTERLY -> "201225" | ||
Futures.CONTRACT_TYPE_BIQUARTERLY -> "210326" | ||
else -> throw ArrayIndexOutOfBoundsException("Unknown contract type: $contractType") | ||
} | ||
|
||
return "$currencyBase-$currencyCounter-$suffix" | ||
} | ||
|
||
override fun parseTickerFromJsonObject(requestId: Int, jsonObject: JSONObject, ticker: Ticker, checkerInfo: CheckerInfo) { | ||
ticker.bid = jsonObject.getDouble("best_bid") | ||
ticker.ask = jsonObject.getDouble("best_ask") | ||
ticker.vol = jsonObject.getDouble("volume_token_24h") | ||
ticker.high = jsonObject.getDouble("high_24h") | ||
ticker.low = jsonObject.getDouble("low_24h") | ||
ticker.last = jsonObject.getDouble("last") | ||
ticker.timestamp = ZonedDateTime.parse(jsonObject.getString("timestamp")).toEpochSecond() | ||
} | ||
} |
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
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.JSONArray | ||
|
||
class Upbit : Market(NAME, TTS_NAME, null) { | ||
companion object { | ||
private const val NAME = "Upbit" | ||
private const val TTS_NAME = "Up bit" | ||
private const val URL = "https://api.upbit.com/v1/ticker?markets=%1\$s" | ||
private const val URL_CURRENCY_PAIRS = "https://api.upbit.com/v1/market/all?isDetails=false" | ||
} | ||
|
||
override fun getCurrencyPairsUrl(requestId: Int): String? { | ||
return URL_CURRENCY_PAIRS | ||
} | ||
|
||
override fun parseCurrencyPairs(requestId: Int, responseString: String, pairs: MutableList<CurrencyPairInfo>) { | ||
val markets = JSONArray(responseString) | ||
|
||
for(i in 0 until markets.length()){ | ||
val market = markets.getJSONObject(i) | ||
|
||
val marketId = market.getString("market") | ||
val assets = marketId.split("-") | ||
if(assets.size != 2) continue | ||
|
||
pairs.add( CurrencyPairInfo( | ||
assets[1], | ||
assets[0], | ||
marketId, | ||
)) | ||
} | ||
} | ||
|
||
override fun getUrl(requestId: Int, checkerInfo: CheckerInfo): String { | ||
return String.format(URL, checkerInfo.currencyPairId) | ||
} | ||
|
||
override fun parseTicker(requestId: Int, responseString: String, ticker: Ticker, checkerInfo: CheckerInfo) { | ||
val jsonArray = JSONArray(responseString) | ||
|
||
jsonArray.getJSONObject(0).apply { | ||
ticker.high = getDouble("high_price") | ||
ticker.low = getDouble("low_price") | ||
ticker.last = getDouble("trade_price") | ||
ticker.vol = getDouble("acc_trade_volume") | ||
ticker.timestamp = getLong("timestamp") | ||
} | ||
} | ||
} |
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
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 | ||
|
||
class ZgCom : Market(NAME, TTS_NAME, null) { | ||
companion object { | ||
private const val NAME = "ZG.com" | ||
private const val TTS_NAME = "ZG dot com" | ||
private const val URL = "https://api.zg.com/openapi/quote/v1/ticker/24hr?symbol=%1\$s" | ||
private const val URL_CURRENCY_PAIRS = "https://api.zg.com/openapi/v1/brokerInfo" | ||
} | ||
|
||
override fun getCurrencyPairsUrl(requestId: Int): String? { | ||
return URL_CURRENCY_PAIRS | ||
} | ||
|
||
override fun parseCurrencyPairsFromJsonObject(requestId: Int, jsonObject: JSONObject, pairs: MutableList<CurrencyPairInfo>) { | ||
val markets = jsonObject.getJSONArray("symbols") | ||
for(i in 0 until markets.length()){ | ||
val market = markets.getJSONObject(i) | ||
|
||
if(market.getString("status") != "TRADING") continue | ||
|
||
pairs.add( CurrencyPairInfo( | ||
market.getString("baseAsset"), | ||
market.getString("quoteAsset"), | ||
market.getString("symbol"), | ||
)) | ||
} | ||
} | ||
|
||
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 { | ||
ticker.bid = getDouble("bestBidPrice") | ||
ticker.ask = getDouble("bestAskPrice") | ||
ticker.high = getDouble("highPrice") | ||
ticker.low = getDouble("lowPrice") | ||
ticker.last = getDouble("lastPrice") | ||
ticker.vol = getDouble("volume") | ||
ticker.timestamp = getLong("time") | ||
} | ||
} | ||
} |