-
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.
Migrate test app to Jetpack Compose (#222)
* Test app fully refactored and migrated to Jetpack Compose * Turn off dataBinding (not used) * Fixed log view * Fixed button state for market update pairs * Fixed currency in ticker view * Updated CapeCrypto exchange
- Loading branch information
Showing
93 changed files
with
2,927 additions
and
1,284 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
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
90 changes: 60 additions & 30 deletions
90
dataModule/src/main/java/com/aneonex/bitcoinchecker/datamodule/model/market/CapeCrypto.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 |
---|---|---|
@@ -1,66 +1,96 @@ | ||
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 com.aneonex.bitcoinchecker.datamodule.model.currency.Currency | ||
import com.aneonex.bitcoinchecker.datamodule.model.currency.CurrencyPairsMap | ||
import com.aneonex.bitcoinchecker.datamodule.model.currency.VirtualCurrency | ||
import com.aneonex.bitcoinchecker.datamodule.util.forEachJSONObject | ||
import org.json.JSONArray | ||
import org.json.JSONObject | ||
|
||
|
||
class CapeCrypto : Market(NAME, TTS_NAME, CURRENCY_PAIRS) { | ||
class CapeCrypto : Market(NAME, TTS_NAME) { | ||
companion object { | ||
private const val NAME = "Cape Crypto" | ||
private const val TTS_NAME = NAME | ||
// private const val URL_TICKER = "https://trade.capecrypto.com/api/v2/peatio/public/markets/btczar/tickers" | ||
private const val URL_TICKER = "https://trade.capecrypto.com/api/v2/peatio/public/markets/%1\$s%2\$s/tickers" | ||
private const val URL_ORDERS = "https://trade.capecrypto.com/api/v2/peatio/public/markets/%1\$s%2\$s/order-book?asks_limit=1&bids_limit=1" | ||
private val CURRENCY_PAIRS: CurrencyPairsMap = CurrencyPairsMap() | ||
private const val URL_PAIRS = "https://trade.capecrypto.com/api/v2/peatio/public/markets" | ||
private const val URL_TICKER = "https://trade.capecrypto.com/api/v2/peatio/public/markets/%1\$s/tickers" | ||
private const val URL_ORDERS = "https://trade.capecrypto.com/api/v2/peatio/public/markets/%1\$s/order-book?asks_limit=1&bids_limit=1" | ||
} | ||
|
||
init { | ||
CURRENCY_PAIRS[VirtualCurrency.BTC] = arrayOf( | ||
Currency.ZAR | ||
) | ||
} | ||
override fun getCurrencyPairsUrl(requestId: Int): String { | ||
return URL_PAIRS | ||
} | ||
|
||
override fun parseCurrencyPairs( | ||
requestId: Int, | ||
responseString: String, | ||
pairs: MutableList<CurrencyPairInfo> | ||
) { | ||
JSONArray(responseString) | ||
.forEachJSONObject { market -> | ||
pairs.add( | ||
CurrencyPairInfo( | ||
market.getString("base_unit").uppercase(), | ||
market.getString("quote_unit").uppercase(), | ||
market.getString("id") | ||
) | ||
) | ||
} | ||
} | ||
|
||
override fun getNumOfRequests(checkerInfo: CheckerInfo?): Int { | ||
return 2 | ||
} | ||
|
||
override fun getUrl(requestId: Int, checkerInfo: CheckerInfo): String { | ||
val pairId = checkerInfo.currencyPairId ?: with(checkerInfo){"$currencyBaseLowerCase$currencyCounterLowerCase"} | ||
return if (requestId == 0) { | ||
String.format(URL_TICKER, checkerInfo.currencyBaseLowerCase, checkerInfo.currencyCounterLowerCase) | ||
String.format(URL_TICKER, pairId) | ||
} else { | ||
String.format(URL_ORDERS, checkerInfo.currencyBaseLowerCase, checkerInfo.currencyCounterLowerCase) | ||
String.format(URL_ORDERS, pairId) | ||
} | ||
} | ||
|
||
@Throws(Exception::class) | ||
override fun parseTickerFromJsonObject(requestId: Int, jsonObject: JSONObject, ticker: Ticker, | ||
checkerInfo: CheckerInfo) { | ||
override fun parseTickerFromJsonObject( | ||
requestId: Int, | ||
jsonObject: JSONObject, | ||
ticker: Ticker, | ||
checkerInfo: CheckerInfo | ||
) { | ||
|
||
if (requestId == 0) { | ||
ticker.vol = jsonObject.getJSONObject("ticker").getDouble("vol") | ||
ticker.high = jsonObject.getJSONObject("ticker").getDouble("high") | ||
ticker.low = jsonObject.getJSONObject("ticker").getDouble("low") | ||
ticker.last = jsonObject.getJSONObject("ticker").getDouble("last") | ||
ticker.timestamp = jsonObject.getLong("at") | ||
|
||
jsonObject.getJSONObject("ticker").also { | ||
ticker.last = it.getDouble("last") | ||
|
||
ticker.vol = it.getDouble("amount") | ||
ticker.volQuote = it.getDouble("vol") | ||
|
||
ticker.high = it.getDouble("high") | ||
ticker.low = it.getDouble("low") | ||
} | ||
} else { | ||
val jArrayBids: JSONArray = jsonObject.getJSONArray("bids") | ||
val jArrayAsks: JSONArray = jsonObject.getJSONArray("asks") | ||
val jResultBids = jArrayBids.getJSONObject(0) | ||
val jResultAsks = jArrayAsks.getJSONObject(0) | ||
ticker.bid = jResultBids.getDouble("price") | ||
ticker.ask = jResultAsks.getDouble("price") | ||
jsonObject | ||
.getJSONArray("bids") | ||
.getJSONObject(0) | ||
.also { ticker.bid = it.getDouble("price") } | ||
|
||
jsonObject | ||
.getJSONArray("asks") | ||
.getJSONObject(0) | ||
.also { ticker.ask = it.getDouble("price") } | ||
} | ||
} | ||
|
||
@Throws(Exception::class) | ||
override fun parseErrorFromJsonObject(requestId: Int, jsonObject: JSONObject, | ||
checkerInfo: CheckerInfo?): String? { | ||
return jsonObject.getString("message") | ||
override fun parseErrorFromJsonObject( | ||
requestId: Int, | ||
jsonObject: JSONObject, | ||
checkerInfo: CheckerInfo? | ||
): String? { | ||
return jsonObject.getJSONArray("errors").getString(0) | ||
} | ||
} |
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
115 changes: 115 additions & 0 deletions
115
dataModuleTester/schemas/com.aneonex.bitcoinchecker.tester.data.local.MarketDatabase/1.json
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,115 @@ | ||
{ | ||
"formatVersion": 1, | ||
"database": { | ||
"version": 1, | ||
"identityHash": "3114016120a0732454bcf8c5b9ed35d2", | ||
"entities": [ | ||
{ | ||
"tableName": "markets", | ||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `marketKey` TEXT NOT NULL COLLATE NOCASE, `updateDate` INTEGER NOT NULL)", | ||
"fields": [ | ||
{ | ||
"fieldPath": "id", | ||
"columnName": "id", | ||
"affinity": "INTEGER", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "marketKey", | ||
"columnName": "marketKey", | ||
"affinity": "TEXT", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "updateDate", | ||
"columnName": "updateDate", | ||
"affinity": "INTEGER", | ||
"notNull": true | ||
} | ||
], | ||
"primaryKey": { | ||
"columnNames": [ | ||
"id" | ||
], | ||
"autoGenerate": true | ||
}, | ||
"indices": [ | ||
{ | ||
"name": "index_markets_marketKey", | ||
"unique": false, | ||
"columnNames": [ | ||
"marketKey" | ||
], | ||
"orders": [], | ||
"createSql": "CREATE INDEX IF NOT EXISTS `index_markets_marketKey` ON `${TABLE_NAME}` (`marketKey`)" | ||
} | ||
], | ||
"foreignKeys": [] | ||
}, | ||
{ | ||
"tableName": "market_pairs", | ||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`marketId` INTEGER NOT NULL, `baseAsset` TEXT NOT NULL, `quoteAsset` TEXT NOT NULL, `contractType` TEXT NOT NULL, `marketPairId` TEXT, PRIMARY KEY(`marketId`, `baseAsset`, `quoteAsset`, `contractType`), FOREIGN KEY(`marketId`) REFERENCES `markets`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )", | ||
"fields": [ | ||
{ | ||
"fieldPath": "marketId", | ||
"columnName": "marketId", | ||
"affinity": "INTEGER", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "baseAsset", | ||
"columnName": "baseAsset", | ||
"affinity": "TEXT", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "quoteAsset", | ||
"columnName": "quoteAsset", | ||
"affinity": "TEXT", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "contractType", | ||
"columnName": "contractType", | ||
"affinity": "TEXT", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "marketPairId", | ||
"columnName": "marketPairId", | ||
"affinity": "TEXT", | ||
"notNull": false | ||
} | ||
], | ||
"primaryKey": { | ||
"columnNames": [ | ||
"marketId", | ||
"baseAsset", | ||
"quoteAsset", | ||
"contractType" | ||
], | ||
"autoGenerate": false | ||
}, | ||
"indices": [], | ||
"foreignKeys": [ | ||
{ | ||
"table": "markets", | ||
"onDelete": "CASCADE", | ||
"onUpdate": "NO ACTION", | ||
"columns": [ | ||
"marketId" | ||
], | ||
"referencedColumns": [ | ||
"id" | ||
] | ||
} | ||
] | ||
} | ||
], | ||
"views": [], | ||
"setupQueries": [ | ||
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)", | ||
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '3114016120a0732454bcf8c5b9ed35d2')" | ||
] | ||
} | ||
} |
Oops, something went wrong.