use of org.knowm.xchange.hitbtc.v2.service.HitbtcMarketDataServiceRaw 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);
}
use of org.knowm.xchange.hitbtc.v2.service.HitbtcMarketDataServiceRaw in project XChange by knowm.
the class HitbtcExchange method remoteInit.
@Override
public void remoteInit() throws IOException {
HitbtcMarketDataServiceRaw dataService = ((HitbtcMarketDataServiceRaw) marketDataService);
List<HitbtcSymbol> hitbtcSymbols = dataService.getHitbtcSymbols();
Map<Currency, CurrencyMetaData> currencies = dataService.getHitbtcCurrencies().stream().collect(Collectors.toMap(hitbtcCurrency -> new Currency(hitbtcCurrency.getId()), hitbtcCurrency -> new CurrencyMetaData(null, hitbtcCurrency.getPayoutFee())));
Map<CurrencyPair, CurrencyPairMetaData> currencyPairs = hitbtcSymbols.stream().collect(Collectors.toMap(hitbtcSymbol -> new CurrencyPair(new Currency(hitbtcSymbol.getBaseCurrency()), new Currency(hitbtcSymbol.getQuoteCurrency())), hitbtcSymbol -> new CurrencyPairMetaData((BigDecimal) null, hitbtcSymbol.getQuantityIncrement(), (BigDecimal) null, hitbtcSymbol.getTickSize().scale(), (FeeTier[]) null)));
exchangeMetaData = HitbtcAdapters.adaptToExchangeMetaData(hitbtcSymbols, currencies, currencyPairs);
}
use of org.knowm.xchange.hitbtc.v2.service.HitbtcMarketDataServiceRaw in project XChange by knowm.
the class HitbtcAdapters method adaptSymbol.
public static CurrencyPair adaptSymbol(String symbol) {
if (symbols.isEmpty()) {
try {
HitbtcExchange exchange = ExchangeFactory.INSTANCE.createExchange(HitbtcExchange.class);
symbols = new HitbtcMarketDataServiceRaw(exchange).getHitbtcSymbols().stream().collect(Collectors.toMap(hitbtcSymbol -> hitbtcSymbol.getBaseCurrency() + hitbtcSymbol.getQuoteCurrency(), hitbtcSymbol -> new CurrencyPair(hitbtcSymbol.getBaseCurrency(), hitbtcSymbol.getQuoteCurrency())));
} catch (Exception ignored) {
}
}
return symbols.containsKey(symbol) ? symbols.get(symbol) : guessSymbol(symbol);
}
use of org.knowm.xchange.hitbtc.v2.service.HitbtcMarketDataServiceRaw in project XChange by knowm.
the class HitbtcMarketDataDemo method raw.
private static void raw(HitbtcMarketDataServiceRaw marketDataService) throws IOException {
HitbtcTicker ticker = marketDataService.getHitbtcTicker(CurrencyPair.BTC_USD);
System.out.println("BTC/USD Ticker: " + ticker.toString());
Map<String, HitbtcTicker> tickers = marketDataService.getHitbtcTickers();
System.out.println("All Tickers: " + tickers.toString());
// Get the latest order book data for BTC/USD
HitbtcOrderBook orderBook = marketDataService.getHitbtcOrderBook(CurrencyPair.BTC_USD);
System.out.println("Current Order Book size for BTC/USD: " + (orderBook.getAsks().length + orderBook.getBids().length));
System.out.println(orderBook);
}
use of org.knowm.xchange.hitbtc.v2.service.HitbtcMarketDataServiceRaw in project XChange by knowm.
the class HitbtcCandlesDemo method main.
public static void main(String[] args) throws Exception {
Exchange hitbtcExchange = HitbtcExampleUtils.createExchange();
hitbtcExchange.remoteInit();
System.out.println("Market metadata: " + hitbtcExchange.getExchangeMetaData().getCurrencyPairs().toString());
MarketDataService marketDataService = hitbtcExchange.getMarketDataService();
HitbtcMarketDataServiceRaw hitbtcMarketDataService = (HitbtcMarketDataServiceRaw) hitbtcExchange.getMarketDataService();
getCandles(hitbtcMarketDataService);
}
Aggregations