Search in sources :

Example 1 with HitbtcMarketDataServiceRaw

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

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);
}
Also used : HttpURLConnection(java.net.HttpURLConnection) Logger(org.slf4j.Logger) HitbtcMetaData(org.knowm.xchange.hitbtc.v2.dto.HitbtcMetaData) LoggerFactory(org.slf4j.LoggerFactory) IOException(java.io.IOException) Field(java.lang.reflect.Field) Collectors(java.util.stream.Collectors) FeeTier(org.knowm.xchange.dto.meta.FeeTier) HitbtcMarketDataService(org.knowm.xchange.hitbtc.v2.service.HitbtcMarketDataService) BigDecimal(java.math.BigDecimal) HitbtcAccountService(org.knowm.xchange.hitbtc.v2.service.HitbtcAccountService) List(java.util.List) Currency(org.knowm.xchange.currency.Currency) CurrencyPairMetaData(org.knowm.xchange.dto.meta.CurrencyPairMetaData) BaseExchange(org.knowm.xchange.BaseExchange) ExchangeSpecification(org.knowm.xchange.ExchangeSpecification) CurrencyMetaData(org.knowm.xchange.dto.meta.CurrencyMetaData) Modifier(java.lang.reflect.Modifier) Map(java.util.Map) HitbtcSymbol(org.knowm.xchange.hitbtc.v2.dto.HitbtcSymbol) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) HitbtcMarketDataServiceRaw(org.knowm.xchange.hitbtc.v2.service.HitbtcMarketDataServiceRaw) HitbtcTradeService(org.knowm.xchange.hitbtc.v2.service.HitbtcTradeService) InputStream(java.io.InputStream) CurrencyPairMetaData(org.knowm.xchange.dto.meta.CurrencyPairMetaData) HitbtcMarketDataServiceRaw(org.knowm.xchange.hitbtc.v2.service.HitbtcMarketDataServiceRaw) CurrencyMetaData(org.knowm.xchange.dto.meta.CurrencyMetaData) Currency(org.knowm.xchange.currency.Currency) HitbtcSymbol(org.knowm.xchange.hitbtc.v2.dto.HitbtcSymbol) FeeTier(org.knowm.xchange.dto.meta.FeeTier) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 3 with HitbtcMarketDataServiceRaw

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);
}
Also used : HitbtcMarketDataServiceRaw(org.knowm.xchange.hitbtc.v2.service.HitbtcMarketDataServiceRaw) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 4 with HitbtcMarketDataServiceRaw

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);
}
Also used : HitbtcOrderBook(org.knowm.xchange.hitbtc.v2.dto.HitbtcOrderBook) HitbtcTicker(org.knowm.xchange.hitbtc.v2.dto.HitbtcTicker)

Example 5 with HitbtcMarketDataServiceRaw

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);
}
Also used : Exchange(org.knowm.xchange.Exchange) HitbtcMarketDataServiceRaw(org.knowm.xchange.hitbtc.v2.service.HitbtcMarketDataServiceRaw) MarketDataService(org.knowm.xchange.service.marketdata.MarketDataService)

Aggregations

CurrencyPair (org.knowm.xchange.currency.CurrencyPair)3 HitbtcMarketDataServiceRaw (org.knowm.xchange.hitbtc.v2.service.HitbtcMarketDataServiceRaw)3 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Field (java.lang.reflect.Field)1 Modifier (java.lang.reflect.Modifier)1 BigDecimal (java.math.BigDecimal)1 HttpURLConnection (java.net.HttpURLConnection)1 LocalDateTime (java.time.LocalDateTime)1 DateTimeFormatter (java.time.format.DateTimeFormatter)1 Date (java.util.Date)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 BaseExchange (org.knowm.xchange.BaseExchange)1 Exchange (org.knowm.xchange.Exchange)1 ExchangeSpecification (org.knowm.xchange.ExchangeSpecification)1 Currency (org.knowm.xchange.currency.Currency)1 CurrencyMetaData (org.knowm.xchange.dto.meta.CurrencyMetaData)1 CurrencyPairMetaData (org.knowm.xchange.dto.meta.CurrencyPairMetaData)1