Skip to content

Commit

Permalink
Added exchange WOO (Spot + Futures) #227
Browse files Browse the repository at this point in the history
  • Loading branch information
aneonex committed Jan 28, 2023
1 parent 5faee02 commit 7b21300
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ object MarketsConfig {
BybitDerivatives(),
Exbitron(),
Txbit(),

Woo(),
)

val MARKETS: Map<String, Market> = registeredMarkets.associateBy { it.key }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
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.FuturesContractType
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 Woo : SimpleMarket(
"WOO",
"https://api.woo.org/v1/public/info",
"https://api.woo.org/v1/public/market_trades?symbol=%1\$s&limit=1"
) {

override fun getUrl(requestId: Int, checkerInfo: CheckerInfo): String {
if(checkerInfo.contractType != FuturesContractType.NONE)
return String.format("https://api.woo.org/v1/public/futures/%1\$s", getPairId(checkerInfo))

return super.getUrl(requestId, checkerInfo)
}

override fun parseCurrencyPairsFromJsonObject(
requestId: Int,
jsonObject: JSONObject,
pairs: MutableList<CurrencyPairInfo>
) {
jsonObject
.getJSONArray("rows")
.forEachJSONObject { market ->
val pair = parseCurrencyPair(market)
if(pair != null) {
pairs.add(pair)
}
}
}

private fun parseCurrencyPair(market: JSONObject): CurrencyPairInfo? {
val symbol = market.getString("symbol")
val symbolParts = symbol.split('_')
if(symbolParts.size != 3)
return null

val contractType = when(symbolParts[0]) {
"SPOT" -> FuturesContractType.NONE
"PERP" -> FuturesContractType.PERPETUAL
else -> return null
}

return CurrencyPairInfo(
symbolParts[1],
symbolParts[2],
symbol,
contractType
)
}

override fun parseTickerFromJsonObject(
requestId: Int,
jsonObject: JSONObject,
ticker: Ticker,
checkerInfo: CheckerInfo
) {
if(checkerInfo.contractType == FuturesContractType.NONE) {
jsonObject
.getJSONArray("rows")
.getJSONObject(0)
.also {
ticker.last = it.getDouble("executed_price")
ticker.timestamp = it.getString("executed_timestamp")
.replace(".", "")
.toLong()
}
} else {
jsonObject
.also {
ticker.timestamp = it.getLong("timestamp")
}
.getJSONObject("info")
.also {
ticker.last = it.getDouble("24h_close")

ticker.high = it.getDouble("24h_high")
ticker.low = it.getDouble("24h_low")

ticker.vol = it.getDouble("24h_volumn")
ticker.volQuote = it.getDouble("24h_amount")
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ data class MyMarketPairsInfo(

return pairs
.filter {
it.contractType != FuturesContractType.NONE
&& it.currencyBase == baseCurrency
&& it.currencyCounter == quoteCurrency }
it.currencyBase == baseCurrency
&& it.currencyCounter == quoteCurrency }
.map { it.contractType }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,14 @@ private fun MarketScreenMain(
}
}

if(contactTypes.isNotEmpty()) {
val hasContractTypes = contactTypes.isNotEmpty() && !(contactTypes.size == 1 && contactTypes[0] == FuturesContractType.NONE)

if(hasContractTypes) {
Row(
modifier = Modifier.padding(bottom = basePadding),
) {
ComboBox(
itemList = contactTypes.map { it.toString() },
itemList = contactTypes.map { getContractTypeName(it) },
selectedIndex = contactTypes.indexOf(currentContractType),
label = stringResource(id = R.string.market_screen_contract_type),
onValueChange = { index ->
Expand Down Expand Up @@ -288,6 +290,13 @@ private fun MarketScreenMain(
}
}

private fun getContractTypeName(contractType: FuturesContractType): String {
if(contractType == FuturesContractType.NONE)
return "Spot"

return contractType.toString()
}

/*
@Preview(showBackground = true)
@Composable
Expand Down

0 comments on commit 7b21300

Please sign in to comment.