Search in sources :

Example 6 with IntervalPrice

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

the class CryptoCompareLiveClient method parseResponse.

private IntervalPrice parseResponse(CurrencyPair currencyPair, String response) throws IOException, ParseException {
    JSONParser jsonParser = new JSONParser();
    JSONObject jsonObject = (JSONObject) jsonParser.parse(response);
    JSONObject data = (JSONObject) jsonObject.get(JSON_FIELD_DATA);
    JSONObject nestedtradeCurrencyRecord = (JSONObject) data.get(currencyPair.tradeCurrency);
    JSONObject nestedBaseCurrencyRecord = (JSONObject) nestedtradeCurrencyRecord.get(currencyPair.baseCurrency);
    Double volume = parseNumber(nestedBaseCurrencyRecord.get(JSON_FIELD_DATA_DAY_VOLUME));
    Double price = parseNumber(nestedBaseCurrencyRecord.get(JSON_FIELD_DATA_PRICE));
    Date date = Calendar.getInstance().getTime();
    return new IntervalPrice(currencyPair, date, date, new BigDecimal(price), new BigDecimal(price), new BigDecimal(price), new BigDecimal(price), new BigDecimal(volume), new BigDecimal(volume));
}
Also used : IntervalPrice(io.altanalytics.domain.currency.IntervalPrice) JSONObject(org.json.simple.JSONObject) JSONParser(org.json.simple.parser.JSONParser) Date(java.util.Date) BigDecimal(java.math.BigDecimal)

Example 7 with IntervalPrice

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

the class ElasticReader method parseIntervalPrice.

private IntervalPrice parseIntervalPrice(SearchHit searchHit, CurrencyPair currencyPair) throws ParseException {
    DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
    df.setTimeZone(TimeZone.getTimeZone("UTC"));
    Date openDate = df.parse((String) searchHit.getSourceAsMap().get("openDate"));
    Date closeDate = df.parse((String) searchHit.getSourceAsMap().get("closeDate"));
    Double openPrice = (Double) searchHit.getSourceAsMap().get("openPrice");
    Double lowPrice = (Double) searchHit.getSourceAsMap().get("lowPrice");
    Double highPrice = (Double) searchHit.getSourceAsMap().get("highPrice");
    Double closePrice = (Double) searchHit.getSourceAsMap().get("closePrice");
    Double intervalVolume = (Double) searchHit.getSourceAsMap().get("intervalVolume");
    Double dayVolume = (Double) searchHit.getSourceAsMap().get("dayVolume");
    return new IntervalPrice(currencyPair, openDate, closeDate, BigDecimal.valueOf(openPrice), BigDecimal.valueOf(lowPrice), BigDecimal.valueOf(highPrice), BigDecimal.valueOf(closePrice), BigDecimal.valueOf(intervalVolume), BigDecimal.valueOf(dayVolume));
}
Also used : IntervalPrice(io.altanalytics.domain.currency.IntervalPrice) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 8 with IntervalPrice

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

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

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

the class CryptoCompareLiveRecorder method delta.

private List<IntervalPrice> delta(List<IntervalPrice> latestIntervalPrices, Date requestDate) {
    List<IntervalPrice> deltas = new ArrayList<IntervalPrice>();
    for (IntervalPrice latestIntervalPrice : latestIntervalPrices) {
        if (currentMarketData.containsKey(latestIntervalPrice.getCurrencyPair())) {
            IntervalPrice delta = delta(latestIntervalPrice, currentMarketData.get(latestIntervalPrice.getCurrencyPair()));
            deltas.add(delta);
        }
        currentMarketData.put(latestIntervalPrice.getCurrencyPair(), latestIntervalPrice);
    }
    return deltas;
}
Also used : IntervalPrice(io.altanalytics.domain.currency.IntervalPrice) ArrayList(java.util.ArrayList)

Aggregations

IntervalPrice (io.altanalytics.domain.currency.IntervalPrice)11 Date (java.util.Date)7 ArrayList (java.util.ArrayList)5 BigDecimal (java.math.BigDecimal)4 CurrencyPair (io.altanalytics.domain.currency.CurrencyPair)3 IntervalPriceRequest (io.altanalytics.domain.currency.IntervalPriceRequest)3 JSONObject (org.json.simple.JSONObject)2 JSONParser (org.json.simple.parser.JSONParser)2 Scheduled (org.springframework.scheduling.annotation.Scheduled)2 Analytic (io.altanalytics.domain.currency.Analytic)1 IOException (java.io.IOException)1 DateFormat (java.text.DateFormat)1 ParseException (java.text.ParseException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ExecutorService (java.util.concurrent.ExecutorService)1 ForkJoinPool (java.util.concurrent.ForkJoinPool)1 Future (java.util.concurrent.Future)1 BulkRequestBuilder (org.elasticsearch.action.bulk.BulkRequestBuilder)1 BulkResponse (org.elasticsearch.action.bulk.BulkResponse)1 SearchResponse (org.elasticsearch.action.search.SearchResponse)1