-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
849875d
commit b900925
Showing
43 changed files
with
905 additions
and
311 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
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
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
21 changes: 16 additions & 5 deletions
21
...d/domain/src/commonMain/kotlin/network/bisq/mobile/client/market/MarketPriceApiGateway.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,16 +1,27 @@ | ||
package network.bisq.mobile.client.market | ||
|
||
import kotlinx.serialization.Serializable | ||
import network.bisq.mobile.client.service.ApiRequestService | ||
import network.bisq.mobile.client.websocket.WebSocketClient | ||
import network.bisq.mobile.client.websocket.rest_api_proxy.WebSocketRestApiClient | ||
import network.bisq.mobile.client.websocket.subscription.WebSocketEventObserver | ||
import network.bisq.mobile.client.websocket.subscription.Topic | ||
import network.bisq.mobile.utils.Logging | ||
|
||
class MarketPriceApiGateway(private val apiRequestService: ApiRequestService) : Logging { | ||
class MarketPriceApiGateway( | ||
private val webSocketRestApiClient: WebSocketRestApiClient, | ||
private val webSocketClient: WebSocketClient, | ||
) : Logging { | ||
private val basePath = "market-price" | ||
|
||
suspend fun getQuotes(): MarketPriceResponse { | ||
return apiRequestService.get("$basePath/quotes") | ||
return webSocketRestApiClient.get("$basePath/quotes") | ||
} | ||
|
||
suspend fun subscribeMarketPrice(): WebSocketEventObserver? { | ||
return webSocketClient.subscribe(Topic.MARKET_PRICE) | ||
} | ||
|
||
@Serializable | ||
data class MarketPriceResponse(val quotes: Map<String, Long>) | ||
} | ||
|
||
@Serializable | ||
class MarketPriceResponse(val quotes: Map<String, Long>) |
17 changes: 17 additions & 0 deletions
17
shared/domain/src/commonMain/kotlin/network/bisq/mobile/client/market/PriceFormatter.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,17 @@ | ||
package network.bisq.mobile.client.market | ||
|
||
import network.bisq.mobile.client.replicated_model.common.currency.Market | ||
import kotlin.math.pow | ||
import kotlin.math.round | ||
|
||
fun formatMarketPrice(market: Market, quote: Long): String { | ||
val doubleValue: Double = quote.toDouble() / 10000 | ||
val stringValue: String = doubleValue.roundTo(2).toString() | ||
return stringValue + " " + market.marketCodes | ||
} | ||
|
||
fun Double.roundTo(places: Int): Double { | ||
require(places >= 0) { "Decimal places must be non-negative" } | ||
val factor = 10.0.pow(places) | ||
return round(this * factor) / factor | ||
} |
Oops, something went wrong.