Search in sources :

Example 1 with CurrencyPair

use of io.altanalytics.domain.currency.CurrencyPair in project bibot by alfintech.

the class CryptoCompareHistoricRecorder method process.

public void process() throws Exception {
    List<CurrencyPair> currencyPairs = CurrencyPairUtil.constructCurrencyPairs(tradeCurrencies, baseCurrencies);
    Date datetimeToRetrieve = startOfThisHour();
    for (int i = 0; i < HOURS_IN_YEAR; i++) {
        datetimeToRetrieve = DateUtil.shiftToPast(datetimeToRetrieve, MILLISECONDS_IN_HOUR);
        List<IntervalPriceRequest> requests = requestsForCurrencyPairs(currencyPairs, datetimeToRetrieve);
        List<IntervalPrice> intervalPrices = fetch(marketDataClient, requests);
        publish(interpolate(intervalPrices));
    }
}
Also used : IntervalPrice(io.altanalytics.domain.currency.IntervalPrice) IntervalPriceRequest(io.altanalytics.domain.currency.IntervalPriceRequest) Date(java.util.Date) CurrencyPair(io.altanalytics.domain.currency.CurrencyPair)

Example 2 with CurrencyPair

use of io.altanalytics.domain.currency.CurrencyPair in project bibot by alfintech.

the class CryptoCompareLiveRecorder method tick.

@Scheduled(cron = "${recorder.live.schedule}")
public void tick() throws Exception {
    if (active) {
        Date requestDate = DateUtil.intervalStart(interval);
        List<CurrencyPair> currencyPairs = CurrencyPairUtil.constructCurrencyPairs(tradeCurrencies, baseCurrencies);
        List<IntervalPriceRequest> requests = requestsForCurrencyPairs(currencyPairs, requestDate);
        List<IntervalPrice> latestIntervalPrices = fetch(marketDataClient, requests);
        List<IntervalPrice> deltas = delta(latestIntervalPrices, requestDate);
        if (!deltas.isEmpty()) {
            publish(deltas);
        }
    }
}
Also used : IntervalPrice(io.altanalytics.domain.currency.IntervalPrice) IntervalPriceRequest(io.altanalytics.domain.currency.IntervalPriceRequest) Date(java.util.Date) CurrencyPair(io.altanalytics.domain.currency.CurrencyPair) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Example 3 with CurrencyPair

use of io.altanalytics.domain.currency.CurrencyPair 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);
    }
}
Also used : IntervalPrice(io.altanalytics.domain.currency.IntervalPrice) Analytic(io.altanalytics.domain.currency.Analytic) ArrayList(java.util.ArrayList) Date(java.util.Date) BigDecimal(java.math.BigDecimal) CurrencyPair(io.altanalytics.domain.currency.CurrencyPair) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Aggregations

CurrencyPair (io.altanalytics.domain.currency.CurrencyPair)3 IntervalPrice (io.altanalytics.domain.currency.IntervalPrice)3 Date (java.util.Date)3 IntervalPriceRequest (io.altanalytics.domain.currency.IntervalPriceRequest)2 Scheduled (org.springframework.scheduling.annotation.Scheduled)2 Analytic (io.altanalytics.domain.currency.Analytic)1 BigDecimal (java.math.BigDecimal)1 ArrayList (java.util.ArrayList)1