mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-07-24 15:35:34 -04:00
Use combo box for Make market price, update all prices on interval
This commit is contained in:
parent
0ebf3f6b36
commit
3f5e1296b1
11 changed files with 251 additions and 89 deletions
|
@ -8,13 +8,10 @@ import io.bitsquare.app.Log;
|
|||
import io.bitsquare.btc.pricefeed.providers.BitcoinAveragePriceProvider;
|
||||
import io.bitsquare.btc.pricefeed.providers.PoloniexPriceProvider;
|
||||
import io.bitsquare.btc.pricefeed.providers.PriceProvider;
|
||||
import io.bitsquare.common.Timer;
|
||||
import io.bitsquare.common.UserThread;
|
||||
import io.bitsquare.common.handlers.FaultHandler;
|
||||
import javafx.beans.property.ObjectProperty;
|
||||
import javafx.beans.property.SimpleObjectProperty;
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import javafx.beans.property.StringProperty;
|
||||
import io.bitsquare.locale.CurrencyUtil;
|
||||
import javafx.beans.property.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -43,8 +40,10 @@ public class PriceFeed {
|
|||
}
|
||||
}
|
||||
|
||||
private static final long PERIOD_FIAT_SEC = Timer.STRESS_TEST ? 30 : 60; // We load only the selected currency on interval. Only the first request we load all
|
||||
private static final long PERIOD_CRYPTO_SEC = Timer.STRESS_TEST ? 30 : 10 * 60; // We load the full list with 33kb so we don't want to load too often
|
||||
private static final long PERIOD_FIAT_SEC = 60;
|
||||
private static final long PERIOD_ALL_FIAT_SEC = 60 * 5;
|
||||
private static final long PERIOD_CRYPTO_SEC = 60;
|
||||
private static final long PERIOD_ALL_CRYPTO_SEC = 60 * 5;
|
||||
|
||||
private final Map<String, MarketPrice> cache = new HashMap<>();
|
||||
private final PriceProvider fiatPriceProvider = new BitcoinAveragePriceProvider();
|
||||
|
@ -53,8 +52,9 @@ public class PriceFeed {
|
|||
private FaultHandler faultHandler;
|
||||
private Type type;
|
||||
private String currencyCode;
|
||||
transient private final StringProperty currencyCodeProperty = new SimpleStringProperty();
|
||||
transient private final ObjectProperty<Type> typeProperty = new SimpleObjectProperty<>();
|
||||
private final StringProperty currencyCodeProperty = new SimpleStringProperty();
|
||||
private final ObjectProperty<Type> typeProperty = new SimpleObjectProperty<>();
|
||||
private final IntegerProperty currenciesUpdateFlag = new SimpleIntegerProperty(0);
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -84,6 +84,10 @@ public class PriceFeed {
|
|||
UserThread.runPeriodically(() -> requestAllPrices(cryptoCurrenciesPriceProvider, this::applyPrice),
|
||||
PERIOD_CRYPTO_SEC);
|
||||
});
|
||||
|
||||
UserThread.runPeriodically(() -> requestAllPrices(fiatPriceProvider, this::applyPrice), PERIOD_ALL_FIAT_SEC);
|
||||
UserThread.runPeriodically(() -> requestAllPrices(cryptoCurrenciesPriceProvider, this::applyPrice), PERIOD_ALL_CRYPTO_SEC);
|
||||
|
||||
requestAllPrices(cryptoCurrenciesPriceProvider, this::applyPrice);
|
||||
}
|
||||
|
||||
|
@ -109,6 +113,11 @@ public class PriceFeed {
|
|||
this.currencyCode = currencyCode;
|
||||
currencyCodeProperty.set(currencyCode);
|
||||
applyPrice();
|
||||
|
||||
if (CurrencyUtil.isFiatCurrency(currencyCode))
|
||||
requestPrice(fiatPriceProvider);
|
||||
else
|
||||
requestPrice(cryptoCurrenciesPriceProvider);
|
||||
}
|
||||
|
||||
|
||||
|
@ -132,6 +141,10 @@ public class PriceFeed {
|
|||
return typeProperty;
|
||||
}
|
||||
|
||||
public IntegerProperty currenciesUpdateFlagProperty() {
|
||||
return currenciesUpdateFlag;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Private
|
||||
|
@ -142,13 +155,15 @@ public class PriceFeed {
|
|||
if (cache.containsKey(currencyCode)) {
|
||||
MarketPrice marketPrice = cache.get(currencyCode);
|
||||
//log.debug("applyPrice type=" + type);
|
||||
priceConsumer.accept(marketPrice.getPrice(type));
|
||||
if (marketPrice != null)
|
||||
priceConsumer.accept(marketPrice.getPrice(type));
|
||||
} else {
|
||||
String errorMessage = "We don't have a price for currencyCode " + currencyCode;
|
||||
log.debug(errorMessage);
|
||||
faultHandler.handleFault(errorMessage, new PriceRequestException(errorMessage));
|
||||
}
|
||||
}
|
||||
currenciesUpdateFlag.setValue(currenciesUpdateFlag.get() + 1);
|
||||
}
|
||||
|
||||
private void requestPrice(PriceProvider provider) {
|
||||
|
|
|
@ -83,7 +83,7 @@ public final class Preferences implements Persistable {
|
|||
return defaultTradeCurrency;
|
||||
}
|
||||
|
||||
private static boolean _useAnimations = true;
|
||||
private static boolean staticUseAnimations = true;
|
||||
|
||||
transient private final Storage<Preferences> storage;
|
||||
transient private final BitsquareEnvironment bitsquareEnvironment;
|
||||
|
@ -107,10 +107,12 @@ public final class Preferences implements Persistable {
|
|||
private TradeCurrency preferredTradeCurrency;
|
||||
private long nonTradeTxFeePerKB = FeePolicy.getNonTradeFeePerKb().value;
|
||||
private double maxPriceDistanceInPercent;
|
||||
private boolean useInvertedMarketPrice;
|
||||
|
||||
// Observable wrappers
|
||||
transient private final StringProperty btcDenominationProperty = new SimpleStringProperty(btcDenomination);
|
||||
transient private final BooleanProperty useAnimationsProperty = new SimpleBooleanProperty(useAnimations);
|
||||
transient private final BooleanProperty useInvertedMarketPriceProperty = new SimpleBooleanProperty(useInvertedMarketPrice);
|
||||
transient private final ObservableList<FiatCurrency> fiatCurrenciesAsObservable = FXCollections.observableArrayList();
|
||||
transient private final ObservableList<CryptoCurrency> cryptoCurrenciesAsObservable = FXCollections.observableArrayList();
|
||||
transient private final ObservableList<TradeCurrency> tradeCurrenciesAsObservable = FXCollections.observableArrayList();
|
||||
|
@ -130,6 +132,7 @@ public final class Preferences implements Persistable {
|
|||
if (persisted != null) {
|
||||
setBtcDenomination(persisted.btcDenomination);
|
||||
setUseAnimations(persisted.useAnimations);
|
||||
setUseInvertedMarketPrice(persisted.useInvertedMarketPrice);
|
||||
|
||||
setFiatCurrencies(persisted.fiatCurrencies);
|
||||
fiatCurrencies = new ArrayList<>(fiatCurrenciesAsObservable);
|
||||
|
@ -194,7 +197,11 @@ public final class Preferences implements Persistable {
|
|||
});
|
||||
useAnimationsProperty.addListener((ov) -> {
|
||||
useAnimations = useAnimationsProperty.get();
|
||||
_useAnimations = useAnimations;
|
||||
staticUseAnimations = useAnimations;
|
||||
storage.queueUpForSave(2000);
|
||||
});
|
||||
useInvertedMarketPriceProperty.addListener((ov) -> {
|
||||
useInvertedMarketPrice = useInvertedMarketPriceProperty.get();
|
||||
storage.queueUpForSave(2000);
|
||||
});
|
||||
fiatCurrenciesAsObservable.addListener((Observable ov) -> {
|
||||
|
@ -229,12 +236,16 @@ public final class Preferences implements Persistable {
|
|||
// Setter
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public void setBtcDenomination(String btcDenominationProperty) {
|
||||
this.btcDenominationProperty.set(btcDenominationProperty);
|
||||
public void setBtcDenomination(String btcDenomination) {
|
||||
this.btcDenominationProperty.set(btcDenomination);
|
||||
}
|
||||
|
||||
public void setUseAnimations(boolean useAnimationsProperty) {
|
||||
this.useAnimationsProperty.set(useAnimationsProperty);
|
||||
public void setUseAnimations(boolean useAnimations) {
|
||||
this.useAnimationsProperty.set(useAnimations);
|
||||
}
|
||||
|
||||
public void setUseInvertedMarketPrice(boolean useInvertedMarketPrice) {
|
||||
this.useInvertedMarketPriceProperty.set(useInvertedMarketPrice);
|
||||
}
|
||||
|
||||
public void setBitcoinNetwork(BitcoinNetwork bitcoinNetwork) {
|
||||
|
@ -343,6 +354,11 @@ public final class Preferences implements Persistable {
|
|||
storage.queueUpForSave();
|
||||
}
|
||||
|
||||
public boolean flipUseInvertedMarketPrice() {
|
||||
setUseInvertedMarketPrice(!getUseInvertedMarketPrice());
|
||||
return getUseInvertedMarketPrice();
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Getter
|
||||
|
@ -352,22 +368,31 @@ public final class Preferences implements Persistable {
|
|||
return btcDenominationProperty.get();
|
||||
}
|
||||
|
||||
public boolean getUseAnimations() {
|
||||
return useAnimationsProperty.get();
|
||||
}
|
||||
|
||||
public static boolean useAnimations() {
|
||||
return _useAnimations;
|
||||
}
|
||||
|
||||
public StringProperty btcDenominationProperty() {
|
||||
return btcDenominationProperty;
|
||||
}
|
||||
|
||||
public boolean getUseAnimations() {
|
||||
return useAnimationsProperty.get();
|
||||
}
|
||||
|
||||
public BooleanProperty useAnimationsProperty() {
|
||||
return useAnimationsProperty;
|
||||
}
|
||||
|
||||
|
||||
public static boolean useAnimations() {
|
||||
return staticUseAnimations;
|
||||
}
|
||||
|
||||
public boolean getUseInvertedMarketPrice() {
|
||||
return useInvertedMarketPriceProperty.get();
|
||||
}
|
||||
|
||||
public BooleanProperty useInvertedMarketPriceProperty() {
|
||||
return useInvertedMarketPriceProperty;
|
||||
}
|
||||
|
||||
public BitcoinNetwork getBitcoinNetwork() {
|
||||
return bitcoinNetwork;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue