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));
}
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));
}
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));
}
}
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);
}
}
}
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;
}
Aggregations