From 1b9dd2359b2e4555705198e34034a13c4eab7df6 Mon Sep 17 00:00:00 2001 From: Aneonex Software <69394046+aneonex@users.noreply.github.com> Date: Sun, 21 Nov 2021 12:32:17 +0300 Subject: [PATCH] Added MEXC Global exchange #160 --- .../datamodule/config/MarketsConfig.kt | 1 + .../datamodule/model/market/Mexc.kt | 63 +++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 dataModule/src/main/java/com/aneonex/bitcoinchecker/datamodule/model/market/Mexc.kt 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 a72478ba..d2169c88 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 @@ -196,6 +196,7 @@ object MarketsConfig { Bitrue(), FtxUs(), BinanceUs(), + Mexc(), ) val MARKETS: Map = registeredMarkets.map{it.key to it}.toMap() diff --git a/dataModule/src/main/java/com/aneonex/bitcoinchecker/datamodule/model/market/Mexc.kt b/dataModule/src/main/java/com/aneonex/bitcoinchecker/datamodule/model/market/Mexc.kt new file mode 100644 index 00000000..f3eab7ab --- /dev/null +++ b/dataModule/src/main/java/com/aneonex/bitcoinchecker/datamodule/model/market/Mexc.kt @@ -0,0 +1,63 @@ +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.Ticker +import com.aneonex.bitcoinchecker.datamodule.model.market.generic.SimpleMarket +import com.aneonex.bitcoinchecker.datamodule.util.forEachJSONObject +import org.json.JSONObject + +class Mexc : SimpleMarket( + "MEXC Global", + "https://www.mexc.com/open/api/v2/market/symbols", + "https://www.mexc.com/open/api/v2/market/ticker?symbol=%1\$s", + "Mexc" +) { + + override fun parseCurrencyPairsFromJsonObject( + requestId: Int, + jsonObject: JSONObject, + pairs: MutableList + ) { + jsonObject + .getJSONArray("data") + .forEachJSONObject { market -> + if (market.getString("state") == "ENABLED") { + val symbol = market.getString("symbol") + val assets = symbol.split('_') + if (assets.size == 2) { + pairs.add( + CurrencyPairInfo( + assets[0], // Base + assets[1], // Quote + symbol + ) + ) + } + } + } + } + + override fun parseTickerFromJsonObject( + requestId: Int, + jsonObject: JSONObject, + ticker: Ticker, + checkerInfo: CheckerInfo + ) { + jsonObject + .getJSONArray("data") + .getJSONObject(0) + .also { + ticker.last = it.getDouble("last") + ticker.vol = it.getDouble("volume") + + ticker.timestamp = it.getLong("time") + + ticker.high = it.getDouble("high") + ticker.low = it.getDouble("low") + + ticker.bid = it.getDouble("bid") + ticker.ask = it.getDouble("ask") + } + } +} \ No newline at end of file