Search in sources :

Example 1 with KrakenDepth

use of org.knowm.xchange.kraken.dto.marketdata.KrakenDepth in project XChange by knowm.

the class KrakenDepthDemo method raw.

private static void raw(Exchange krakenExchange) throws IOException {
    // Interested in the public market data feed (no authentication)
    KrakenMarketDataServiceRaw krakenMarketDataService = (KrakenMarketDataServiceRaw) krakenExchange.getMarketDataService();
    // Get the latest full order book data
    KrakenDepth depth = krakenMarketDataService.getKrakenDepth(CurrencyPair.BTC_EUR, Long.MAX_VALUE);
    System.out.println(depth.toString());
    System.out.println("size: " + (depth.getAsks().size() + depth.getBids().size()));
    // Get the latest partial size order book data
    depth = krakenMarketDataService.getKrakenDepth(CurrencyPair.BTC_EUR, 3L);
    System.out.println(depth.toString());
    System.out.println("size: " + (depth.getAsks().size() + depth.getBids().size()));
}
Also used : KrakenDepth(org.knowm.xchange.kraken.dto.marketdata.KrakenDepth) KrakenMarketDataServiceRaw(org.knowm.xchange.kraken.service.KrakenMarketDataServiceRaw)

Example 2 with KrakenDepth

use of org.knowm.xchange.kraken.dto.marketdata.KrakenDepth in project XChange by knowm.

the class KrakenAdaptersTest method testAdaptOrderBook.

@Test
public void testAdaptOrderBook() throws JsonParseException, JsonMappingException, IOException {
    // Read in the JSON from the example resources
    InputStream is = KrakenAdaptersTest.class.getResourceAsStream("/org/knowm/xchange/kraken/dto/marketdata/example-depth-data.json");
    // Use Jackson to parse it
    ObjectMapper mapper = new ObjectMapper();
    KrakenDepthResult krakenDepthResult = mapper.readValue(is, KrakenDepthResult.class);
    Map<String, KrakenDepth> krakenDepths = krakenDepthResult.getResult();
    String krakenAssetPair = "XXBTZEUR";
    KrakenDepth krakenDepth = krakenDepths.get(krakenAssetPair);
    OrderBook orderBook = KrakenAdapters.adaptOrderBook(krakenDepth, CurrencyPair.BTC_EUR);
    List<LimitOrder> asks = orderBook.getAsks();
    assertThat(asks.size()).isEqualTo(3);
    LimitOrder order = asks.get(0);
    assertThat(order.getLimitPrice()).isEqualTo(new BigDecimal("530.75513"));
    assertThat(order.getOriginalAmount()).isEqualTo("0.248");
    assertThat(order.getTimestamp()).isEqualTo(new Date(1391825343000L));
}
Also used : KrakenDepth(org.knowm.xchange.kraken.dto.marketdata.KrakenDepth) KrakenDepthResult(org.knowm.xchange.kraken.dto.marketdata.results.KrakenDepthResult) OrderBook(org.knowm.xchange.dto.marketdata.OrderBook) InputStream(java.io.InputStream) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) BigDecimal(java.math.BigDecimal) Date(java.util.Date) Test(org.junit.Test)

Example 3 with KrakenDepth

use of org.knowm.xchange.kraken.dto.marketdata.KrakenDepth in project XChange by knowm.

the class KrakenMarketDataService method getOrderBook.

@Override
public OrderBook getOrderBook(CurrencyPair currencyPair, Object... args) throws IOException {
    long count = Long.MAX_VALUE;
    if (args != null && args.length > 0) {
        Object arg0 = args[0];
        if (arg0 instanceof Long) {
            count = (Long) arg0;
        } else if (arg0 instanceof Integer) {
            count = (Integer) arg0;
        } else {
            throw new ExchangeException("args[0] must be of type Long or Integer");
        }
    }
    KrakenDepth krakenDepth = getKrakenDepth(currencyPair, count);
    return KrakenAdapters.adaptOrderBook(krakenDepth, currencyPair);
}
Also used : KrakenDepth(org.knowm.xchange.kraken.dto.marketdata.KrakenDepth) ExchangeException(org.knowm.xchange.exceptions.ExchangeException)

Aggregations

KrakenDepth (org.knowm.xchange.kraken.dto.marketdata.KrakenDepth)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 InputStream (java.io.InputStream)1 BigDecimal (java.math.BigDecimal)1 Date (java.util.Date)1 Test (org.junit.Test)1 OrderBook (org.knowm.xchange.dto.marketdata.OrderBook)1 LimitOrder (org.knowm.xchange.dto.trade.LimitOrder)1 ExchangeException (org.knowm.xchange.exceptions.ExchangeException)1 KrakenDepthResult (org.knowm.xchange.kraken.dto.marketdata.results.KrakenDepthResult)1 KrakenMarketDataServiceRaw (org.knowm.xchange.kraken.service.KrakenMarketDataServiceRaw)1