-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added exchange WOO (Spot + Futures) #227
- Loading branch information
Showing
4 changed files
with
107 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
dataModule/src/main/java/com/aneonex/bitcoinchecker/datamodule/model/market/Woo.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters