use of io.altanalytics.domain.currency.IntervalPrice in project bibot by alfintech.
the class AnalyticsRecorder method tick.
@Scheduled(cron = "${recorder.analytics.schedule}")
public void tick() throws Exception {
if (active) {
List<CurrencyPair> currencyPairs = CurrencyPairUtil.constructCurrencyPairs(tradeCurrencies, baseCurrencies);
Date analyticsEndDate = DateUtil.now();
Date analyticsStartDate = DateUtil.shiftToPast(analyticsEndDate, interval);
List<Analytic> analytics = new ArrayList<Analytic>();
for (CurrencyPair currencyPair : currencyPairs) {
// Volume calcs
List<IntervalPrice> intervalPrices = reader.getIntervalPrices(analyticsStartDate, analyticsEndDate, currencyPair);
BigDecimal intervalVolume = VolumeCalculator.cumulative(intervalPrices);
BigDecimal dayVolume = intervalPrices.get(0).getDayVolume();
BigDecimal dayAverageVolume = VolumeCalculator.average(dayVolume, interval);
BigDecimal percentageVolume = BigDecimalUtil.multiply(BigDecimalUtil.divide(intervalVolume, dayAverageVolume), new BigDecimal(100));
// ATH % calcs
BigDecimal allTimeHigh = reader.getAllTimeHigh(currencyPair).getClose();
BigDecimal currentPrice = intervalPrices.get(intervalPrices.size() - 1).getClose();
BigDecimal percentageATH = BigDecimalUtil.divide(currentPrice, allTimeHigh);
Analytic analytic = new Analytic(currencyPair, intervalVolume, dayAverageVolume, percentageVolume, percentageATH, analyticsEndDate);
analytics.add(analytic);
}
publisher.publishAnalytics(analytics);
}
}
Aggregations