Search in sources :

Example 6 with TradeStatistics2

use of bisq.core.trade.statistics.TradeStatistics2 in project bisq-core by bisq-network.

the class PublishTradeStatistics method run.

@Override
protected void run() {
    try {
        runInterceptHook();
        if (trade.getDepositTx() != null) {
            TradeStatistics2 tradeStatistics = new TradeStatistics2(trade.getOffer().getOfferPayload(), trade.getTradePrice(), trade.getTradeAmount(), trade.getDate(), trade.getDepositTx().getHashAsString());
            processModel.getP2PService().addPersistableNetworkPayload(tradeStatistics, true);
        }
        complete();
    } catch (Throwable t) {
        failed(t);
    }
}
Also used : TradeStatistics2(bisq.core.trade.statistics.TradeStatistics2)

Example 7 with TradeStatistics2

use of bisq.core.trade.statistics.TradeStatistics2 in project bisq-core by bisq-network.

the class PriceFeedService method applyLatestBisqMarketPrice.

public void applyLatestBisqMarketPrice(HashSet<TradeStatistics2> tradeStatisticsSet) {
    // takes about 10 ms for 5000 items
    Map<String, List<TradeStatistics2>> mapByCurrencyCode = new HashMap<>();
    tradeStatisticsSet.forEach(e -> {
        final List<TradeStatistics2> list;
        final String currencyCode = e.getCurrencyCode();
        if (mapByCurrencyCode.containsKey(currencyCode)) {
            list = mapByCurrencyCode.get(currencyCode);
        } else {
            list = new ArrayList<>();
            mapByCurrencyCode.put(currencyCode, list);
        }
        list.add(e);
    });
    mapByCurrencyCode.values().stream().filter(list -> !list.isEmpty()).forEach(list -> {
        list.sort((o1, o2) -> o1.getTradeDate().compareTo(o2.getTradeDate()));
        TradeStatistics2 tradeStatistics = list.get(list.size() - 1);
        setBisqMarketPrice(tradeStatistics.getCurrencyCode(), tradeStatistics.getTradePrice());
    });
}
Also used : TradeCurrency(bisq.core.locale.TradeCurrency) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) Date(java.util.Date) Inject(com.google.inject.Inject) Timer(bisq.common.Timer) HashMap(java.util.HashMap) Random(java.util.Random) SettableFuture(com.google.common.util.concurrent.SettableFuture) IntegerProperty(javafx.beans.property.IntegerProperty) ProvidersRepository(bisq.core.provider.ProvidersRepository) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Tuple2(bisq.common.util.Tuple2) SimpleIntegerProperty(javafx.beans.property.SimpleIntegerProperty) Map(java.util.Map) CurrencyUtil(bisq.core.locale.CurrencyUtil) Nullable(javax.annotation.Nullable) FaultHandler(bisq.common.handlers.FaultHandler) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) Log(bisq.common.app.Log) BisqEnvironment(bisq.core.app.BisqEnvironment) TradeStatistics2(bisq.core.trade.statistics.TradeStatistics2) MathUtils(bisq.common.util.MathUtils) Instant(java.time.Instant) HttpClient(bisq.network.http.HttpClient) FutureCallback(com.google.common.util.concurrent.FutureCallback) Consumer(java.util.function.Consumer) Futures(com.google.common.util.concurrent.Futures) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) Preferences(bisq.core.user.Preferences) UserThread(bisq.common.UserThread) Price(bisq.core.monetary.Price) ReadOnlyIntegerProperty(javafx.beans.property.ReadOnlyIntegerProperty) StringProperty(javafx.beans.property.StringProperty) NotNull(org.jetbrains.annotations.NotNull) HashMap(java.util.HashMap) TradeStatistics2(bisq.core.trade.statistics.TradeStatistics2) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

TradeStatistics2 (bisq.core.trade.statistics.TradeStatistics2)7 Date (java.util.Date)5 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)4 CandleData (bisq.desktop.main.market.trades.charts.CandleData)3 MathUtils (bisq.common.util.MathUtils)2 CurrencyUtil (bisq.core.locale.CurrencyUtil)2 FiatCurrency (bisq.core.locale.FiatCurrency)2 TradeCurrency (bisq.core.locale.TradeCurrency)2 Preferences (bisq.core.user.Preferences)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 Inject (com.google.inject.Inject)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 Timer (bisq.common.Timer)1 UserThread (bisq.common.UserThread)1 Log (bisq.common.app.Log)1 FaultHandler (bisq.common.handlers.FaultHandler)1 Tuple2 (bisq.common.util.Tuple2)1