Minor refactoring

This commit is contained in:
ghubstan 2022-06-18 11:24:39 -03:00
parent a12dd52b81
commit 2c043b4b21
No known key found for this signature in database
GPG Key ID: E35592D6800A861E
2 changed files with 16 additions and 12 deletions

View File

@ -2,7 +2,7 @@ getavgbsqprice
NAME
----
getavgbsqprice - get average BSQ price in btc and usd
getavgbsqprice - get average bsq price in btc and usd
SYNOPSIS
--------

View File

@ -88,17 +88,7 @@ class GrpcPriceService extends PriceImplBase {
try {
var days = req.getDays();
Tuple2<Price, Price> prices = coreApi.getAverageBsqTradePrice(days);
var usdPrice = new BigDecimal(prices.first.toString())
.setScale(Fiat.SMALLEST_UNIT_EXPONENT, RoundingMode.HALF_UP);
var btcPrice = new BigDecimal(prices.second.toString())
.setScale(Altcoin.SMALLEST_UNIT_EXPONENT, RoundingMode.HALF_UP);
var proto = AverageBsqTradePrice.newBuilder()
.setUsdPrice(usdPrice.toString())
.setBtcPrice(btcPrice.toString())
.build();
var reply = GetAverageBsqTradePriceReply.newBuilder()
.setPrice(proto)
.build();
var reply = buildGetAverageBsqTradePriceReply(prices);
responseObserver.onNext(reply);
responseObserver.onCompleted();
} catch (Throwable cause) {
@ -121,4 +111,18 @@ class GrpcPriceService extends PriceImplBase {
}}
)));
}
private GetAverageBsqTradePriceReply buildGetAverageBsqTradePriceReply(Tuple2<Price, Price> prices) {
var usdPrice = new BigDecimal(prices.first.toString())
.setScale(Fiat.SMALLEST_UNIT_EXPONENT, RoundingMode.HALF_UP);
var btcPrice = new BigDecimal(prices.second.toString())
.setScale(Altcoin.SMALLEST_UNIT_EXPONENT, RoundingMode.HALF_UP);
var proto = AverageBsqTradePrice.newBuilder()
.setUsdPrice(usdPrice.toString())
.setBtcPrice(btcPrice.toString())
.build();
return GetAverageBsqTradePriceReply.newBuilder()
.setPrice(proto)
.build();
}
}