use of io.altanalytics.domain.currency.IntervalPrice in project bibot by alfintech.
the class ElasticPublisher method publishMarketData.
@Override
public void publishMarketData(List<IntervalPrice> marketDataList) throws IOException {
BulkRequestBuilder bulkRequest = client.prepareBulk();
for (IntervalPrice marketData : marketDataList) {
System.out.println(marketData);
XContentBuilder builder = XContentFactory.jsonBuilder().startObject().field("currencyPair", marketData.getCurrencyPair().toString()).field("openDate", marketData.getOpenTime()).field("closeDate", marketData.getCloseTime()).field("openPrice", BigDecimalUtil.toDouble(marketData.getOpen())).field("closePrice", BigDecimalUtil.toDouble(marketData.getClose())).field("highPrice", BigDecimalUtil.toDouble(marketData.getHigh())).field("lowPrice", BigDecimalUtil.toDouble(marketData.getLow())).field("intervalVolume", BigDecimalUtil.toDouble(marketData.getIntervalVolume())).field("dayVolume", BigDecimalUtil.toDouble(marketData.getDayVolume())).endObject();
bulkRequest.add(client.prepareIndex("marketdata", "minutely", marketData.getCurrencyPair().toString() + marketData.getOpenTime().getTime()).setSource(builder));
}
BulkResponse response = bulkRequest.get();
LOG.debug(response.toString());
}
use of io.altanalytics.domain.currency.IntervalPrice in project bibot by alfintech.
the class ElasticReader method getIntervalPrices.
@Override
public List<IntervalPrice> getIntervalPrices(Date fromDate, Date toDate, CurrencyPair currencyPair) throws Exception {
List<IntervalPrice> intervalPrices = new ArrayList<IntervalPrice>();
SearchResponse response = client.prepareSearch("marketdata").setTypes("minutely").setSearchType(SearchType.DFS_QUERY_THEN_FETCH).setQuery(QueryBuilders.matchQuery("currencyPair", currencyPair.toString())).setPostFilter(QueryBuilders.rangeQuery("openDate").from(fromDate.getTime()).to(toDate.getTime())).addSort("openDate", SortOrder.ASC).setSize(1000).get();
response.getHits().forEach(new Consumer<SearchHit>() {
@Override
public void accept(SearchHit searchHit) {
try {
intervalPrices.add(parseIntervalPrice(searchHit, currencyPair));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
});
return intervalPrices;
}
use of io.altanalytics.domain.currency.IntervalPrice 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;
}
use of io.altanalytics.domain.currency.IntervalPrice in project bibot by alfintech.
the class CryptoCompareHistoricRecorder method interpolateHour.
private List<IntervalPrice> interpolateHour(IntervalPrice marketData) {
List<IntervalPrice> interpolated = new ArrayList<IntervalPrice>();
Date slidingWindow = new Date(marketData.getOpenTime().getTime());
while (slidingWindow.before(marketData.getCloseTime())) {
Date openTime = new Date(slidingWindow.getTime());
slidingWindow = DateUtil.shiftToFuture(openTime, MS_IN_TEN_SECS);
Date closeTime = new Date(slidingWindow.getTime());
interpolated.add(new IntervalPrice(marketData.getCurrencyPair(), openTime, closeTime, marketData.getOpen(), marketData.getClose(), marketData.getLow(), marketData.getHigh(), BigDecimalUtil.divide(marketData.getIntervalVolume(), new BigDecimal(SECONDS_IN_HOUR)), BigDecimal.ZERO));
}
return interpolated;
}
use of io.altanalytics.domain.currency.IntervalPrice in project bibot by alfintech.
the class CryptoCompareHistoricClient method parseResponse.
private IntervalPrice parseResponse(CurrencyPair currencyPair, String response) throws IOException, ParseException {
JSONParser jsonParser = new JSONParser();
JSONObject jsonObject = (JSONObject) jsonParser.parse(response);
JSONArray data = (JSONArray) jsonObject.get(JSON_FIELD_DATA);
Long closeEpochTime = ((Long) jsonObject.get(JSON_FIELD_DATA_CLOSE_TIME)) * MS_IN_SEC;
Long openEpochTime = ((Long) jsonObject.get(JSON_FIELD_DATA_OPEN_TIME)) * MS_IN_SEC;
JSONObject dataRecord = (JSONObject) data.get(data.size() == 0 ? 0 : 1);
Double high = parseNumber(dataRecord.get(JSON_FIELD_DATA_HIGH));
Double low = parseNumber(dataRecord.get(JSON_FIELD_DATA_LOW));
Double volume = parseNumber(dataRecord.get(JSON_FIELD_DATA_VOLUME));
Double close = parseNumber(dataRecord.get(JSON_FIELD_DATA_CLOSE));
Double open = parseNumber(dataRecord.get(JSON_FIELD_DATA_OPEN));
return new IntervalPrice(currencyPair, new Date(openEpochTime), new Date(closeEpochTime), new BigDecimal(open), new BigDecimal(low), new BigDecimal(high), new BigDecimal(close), new BigDecimal(volume), new BigDecimal(volume));
}
Aggregations