All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.knowm.xchange.cobinhood.service.CobinhoodMarketDataServiceRaw Maven / Gradle / Ivy

There is a newer version: 4.3.17.1
Show newest version
package org.knowm.xchange.cobinhood.service;

import java.io.IOException;
import org.knowm.xchange.Exchange;
import org.knowm.xchange.cobinhood.CobinhoodException;
import org.knowm.xchange.cobinhood.dto.CobinhoodAdapters;
import org.knowm.xchange.cobinhood.dto.CobinhoodResponse;
import org.knowm.xchange.cobinhood.dto.marketdata.*;
import org.knowm.xchange.currency.CurrencyPair;
import org.knowm.xchange.exceptions.ExchangeException;

public class CobinhoodMarketDataServiceRaw extends CobinhoodBaseService {

  protected CobinhoodMarketDataServiceRaw(Exchange exchange) {
    super(exchange);
  }

  public CobinhoodResponse getCobinhoodTicker(CurrencyPair currencyPair)
      throws IOException {
    try {
      return checkSuccess(cobinhood.tick(CobinhoodAdapters.adaptCurrencyPair(currencyPair)));
    } catch (CobinhoodException e) {
      throw new ExchangeException(e.getMessage(), e);
    }
  }

  public CobinhoodResponse getCobinhoodTickers() throws IOException {
    try {
      return checkSuccess(cobinhood.tick());
    } catch (CobinhoodException e) {
      throw new ExchangeException(e.getMessage(), e);
    }
  }

  public CobinhoodResponse getCobinhoodOrderBook(
      CurrencyPair currencyPair) throws IOException {
    return getCobinhoodOrderBook(currencyPair, null);
  }

  public CobinhoodResponse getCobinhoodOrderBook(
      CurrencyPair currencyPair, Integer limit) throws IOException {
    try {
      return checkSuccess(
          cobinhood.orders(CobinhoodAdapters.adaptCurrencyPair(currencyPair), limit));
    } catch (CobinhoodException e) {
      throw new ExchangeException(e.getMessage(), e);
    }
  }

  public CobinhoodResponse getCobinhoodTrades(
      CurrencyPair currencyPair, Integer limit) throws IOException {
    try {
      return checkSuccess(
          cobinhood.trades(CobinhoodAdapters.adaptCurrencyPair(currencyPair), limit));
    } catch (CobinhoodException e) {
      throw new ExchangeException(e.getMessage(), e);
    }
  }

  public CobinhoodResponse getCobinhoodCurrencies() throws IOException {
    try {
      return checkSuccess(cobinhood.currencies());
    } catch (CobinhoodException e) {
      throw new ExchangeException(e.getMessage(), e);
    }
  }

  public static  CobinhoodResponse checkSuccess(CobinhoodResponse response) {

    if (response.isSuccess()) {
      return response;
    } else {
      throw new ExchangeException(response.getError().getCode());
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy