Search in sources :

Example 1 with IntervalPriceRequest

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

the class CryptoCompareRequestManager method fetch.

public List<IntervalPrice> fetch(List<IntervalPriceRequest> requests) throws InterruptedException, ExecutionException {
    List<IntervalPrice> results = new ArrayList<IntervalPrice>();
    List<Future<IntervalPrice>> futures = new ArrayList<Future<IntervalPrice>>();
    ExecutorService service = new ForkJoinPool(10);
    for (IntervalPriceRequest request : requests) {
        CryptoCompareRequestConsumer consumer = new CryptoCompareRequestConsumer(client, request);
        futures.add(service.submit(consumer));
    }
    for (Future<IntervalPrice> future : futures) {
        results.add(future.get());
    }
    return results;
}
Also used : IntervalPrice(io.altanalytics.domain.currency.IntervalPrice) ArrayList(java.util.ArrayList) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) IntervalPriceRequest(io.altanalytics.domain.currency.IntervalPriceRequest) ForkJoinPool(java.util.concurrent.ForkJoinPool)

Example 2 with IntervalPriceRequest

use of io.altanalytics.domain.currency.IntervalPriceRequest 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 3 with IntervalPriceRequest

use of io.altanalytics.domain.currency.IntervalPriceRequest 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)

Aggregations

IntervalPrice (io.altanalytics.domain.currency.IntervalPrice)3 IntervalPriceRequest (io.altanalytics.domain.currency.IntervalPriceRequest)3 CurrencyPair (io.altanalytics.domain.currency.CurrencyPair)2 Date (java.util.Date)2 ArrayList (java.util.ArrayList)1 ExecutorService (java.util.concurrent.ExecutorService)1 ForkJoinPool (java.util.concurrent.ForkJoinPool)1 Future (java.util.concurrent.Future)1 Scheduled (org.springframework.scheduling.annotation.Scheduled)1