mirror of
https://github.com/haveno-dex/haveno.git
synced 2024-10-01 01:35:48 -04:00
parent
55f62f92dd
commit
3157891bbb
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
package bisq.core.provider.price;
|
package bisq.core.provider.price;
|
||||||
|
|
||||||
|
import bisq.core.locale.CurrencyUtil;
|
||||||
import bisq.core.provider.HttpClientProvider;
|
import bisq.core.provider.HttpClientProvider;
|
||||||
|
|
||||||
import bisq.network.http.HttpClient;
|
import bisq.network.http.HttpClient;
|
||||||
@ -68,7 +69,20 @@ public class PriceProvider extends HttpClientProvider {
|
|||||||
tsMap.put("poloniexTs", ((Double) map.get("poloniexTs")).longValue());
|
tsMap.put("poloniexTs", ((Double) map.get("poloniexTs")).longValue());
|
||||||
tsMap.put("coinmarketcapTs", ((Double) map.get("coinmarketcapTs")).longValue());
|
tsMap.put("coinmarketcapTs", ((Double) map.get("coinmarketcapTs")).longValue());
|
||||||
|
|
||||||
|
// get btc per xmr price to convert all prices to xmr
|
||||||
|
// TODO (woodser): currently using bisq price feed, switch?
|
||||||
|
Double btcPerXmr = null;
|
||||||
List<?> list = (ArrayList<?>) map.get("data");
|
List<?> list = (ArrayList<?>) map.get("data");
|
||||||
|
for (Object obj : list) {
|
||||||
|
LinkedTreeMap<?, ?> treeMap = (LinkedTreeMap<?, ?>) obj;
|
||||||
|
String currencyCode = (String) treeMap.get("currencyCode");
|
||||||
|
if ("XMR".equalsIgnoreCase(currencyCode)) {
|
||||||
|
btcPerXmr = (Double) treeMap.get("price");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final double btcPerXmrFinal = btcPerXmr;
|
||||||
list.forEach(obj -> {
|
list.forEach(obj -> {
|
||||||
try {
|
try {
|
||||||
LinkedTreeMap<?, ?> treeMap = (LinkedTreeMap<?, ?>) obj;
|
LinkedTreeMap<?, ?> treeMap = (LinkedTreeMap<?, ?>) obj;
|
||||||
@ -76,6 +90,14 @@ public class PriceProvider extends HttpClientProvider {
|
|||||||
double price = (Double) treeMap.get("price");
|
double price = (Double) treeMap.get("price");
|
||||||
// json uses double for our timestampSec long value...
|
// json uses double for our timestampSec long value...
|
||||||
long timestampSec = MathUtils.doubleToLong((Double) treeMap.get("timestampSec"));
|
long timestampSec = MathUtils.doubleToLong((Double) treeMap.get("timestampSec"));
|
||||||
|
|
||||||
|
// convert price from btc to xmr
|
||||||
|
boolean isFiat = CurrencyUtil.isFiatCurrency(currencyCode);
|
||||||
|
if (isFiat) price = price * btcPerXmrFinal;
|
||||||
|
else price = price / btcPerXmrFinal;
|
||||||
|
|
||||||
|
// TODO (woodser): remove xmr from list since base currency and add btc, test by doing btc/xmr trade
|
||||||
|
|
||||||
marketPriceMap.put(currencyCode, new MarketPrice(currencyCode, price, timestampSec, true));
|
marketPriceMap.put(currencyCode, new MarketPrice(currencyCode, price, timestampSec, true));
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
log.error(t.toString());
|
log.error(t.toString());
|
||||||
|
Loading…
Reference in New Issue
Block a user