Skip to content

Commit

Permalink
Added MEXC Global exchange #160
Browse files Browse the repository at this point in the history
  • Loading branch information
aneonex committed Nov 21, 2021
1 parent 7c6ef37 commit 1b9dd23
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ object MarketsConfig {
Bitrue(),
FtxUs(),
BinanceUs(),
Mexc(),
)

val MARKETS: Map<String, Market> = registeredMarkets.map{it.key to it}.toMap()
Expand Down
Original file line number Diff line number Diff line change
@@ -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<CurrencyPairInfo>
) {
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")
}
}
}

0 comments on commit 1b9dd23

Please sign in to comment.