Search in sources :

Example 1 with HitbtcCandle

use of org.knowm.xchange.hitbtc.v2.dto.HitbtcCandle in project XChange by knowm.

the class HitbtcCandlesDemo method getCandles.

private static void getCandles(HitbtcMarketDataServiceRaw hitbtcMarketDataService) throws IOException, ParseException {
    CurrencyPair currencyPair = new CurrencyPair("BTC/USD");
    int limit = 10;
    String sort = "ASC";
    String period = "M15";
    int offset = 10;
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
    LocalDateTime end = LocalDateTime.parse("2019-01-24 00:00", formatter);
    LocalDateTime start = LocalDateTime.parse("2019-01-23 00:00", formatter);
    Date from = Date.from(start.atZone(ZoneId.systemDefault()).toInstant());
    Date till = Date.from(end.atZone(ZoneId.systemDefault()).toInstant());
    // default is latest candles sorted ASC
    System.out.println("Default");
    List<HitbtcCandle> candles = hitbtcMarketDataService.getHitbtcCandles(currencyPair, limit, period);
    printCandles(candles);
    // sorted
    sort = "ASC";
    System.out.println("Sorted " + sort);
    candles = hitbtcMarketDataService.getHitbtcCandles(currencyPair, limit, period, sort);
    printCandles(candles);
    sort = "DESC";
    System.out.println("Sorted " + sort);
    candles = hitbtcMarketDataService.getHitbtcCandles(currencyPair, limit, period, sort);
    printCandles(candles);
    // sorted with date range
    System.out.println("Filtered from " + from + " to " + till + " and sort " + sort);
    candles = hitbtcMarketDataService.getHitbtcCandles(currencyPair, limit, period, from, till, "ASC");
    printCandles(candles);
    // using offset
    System.out.println("Using offset " + offset + " and sort " + sort);
    candles = hitbtcMarketDataService.getHitbtcCandles(currencyPair, limit, period, offset, sort);
    printCandles(candles);
}
Also used : LocalDateTime(java.time.LocalDateTime) HitbtcCandle(org.knowm.xchange.hitbtc.v2.dto.HitbtcCandle) DateTimeFormatter(java.time.format.DateTimeFormatter) Date(java.util.Date) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 2 with HitbtcCandle

use of org.knowm.xchange.hitbtc.v2.dto.HitbtcCandle in project XChange by knowm.

the class HitbtcCandlesDemo method printCandles.

private static void printCandles(List<HitbtcCandle> candles) {
    System.out.println("----------------------------------------------------------------------------------------");
    System.out.printf("%-30s %-15s %-15s %-15s %-15s \n", "Timestamp", "Open", "Max", "Min", "Close");
    System.out.println("----------------------------------------------------------------------------------------");
    for (HitbtcCandle candle : candles) {
        System.out.printf("%-30s %-15s %-15s %-15s %-15s \n", candle.getTimestamp(), candle.getOpen(), candle.getMax(), candle.getMin(), candle.getClose());
    }
    System.out.println("----------------------------------------------------------------------------------------");
    System.out.println();
    System.out.println();
}
Also used : HitbtcCandle(org.knowm.xchange.hitbtc.v2.dto.HitbtcCandle)

Aggregations

HitbtcCandle (org.knowm.xchange.hitbtc.v2.dto.HitbtcCandle)2 LocalDateTime (java.time.LocalDateTime)1 DateTimeFormatter (java.time.format.DateTimeFormatter)1 Date (java.util.Date)1 CurrencyPair (org.knowm.xchange.currency.CurrencyPair)1