Search in sources :

Example 1 with KrakenDepthResult

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

the class KrakenDepthJSONTest method testUnmarshal.

@Test
public void testUnmarshal() throws IOException {
    // Read in the JSON from the example resources
    InputStream is = KrakenDepthJSONTest.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();
    // Verify that the example data was unmarshalled correctly
    assertThat(krakenDepths.get("XXBTXLTC")).isEqualTo(null);
    List<KrakenPublicOrder> krakenAsks = krakenDepths.get("XXBTZEUR").getAsks();
    KrakenPublicOrder krakenPublicOrder = krakenAsks.get(0);
    assertThat(krakenPublicOrder.getPrice()).isEqualTo(new BigDecimal("530.75513"));
    assertThat(krakenPublicOrder.getVolume()).isEqualTo(new BigDecimal("0.248"));
    assertThat(krakenPublicOrder.getTimestamp()).isEqualTo(1391825343L);
}
Also used : KrakenDepthResult(org.knowm.xchange.kraken.dto.marketdata.results.KrakenDepthResult) InputStream(java.io.InputStream) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 2 with KrakenDepthResult

use of org.knowm.xchange.kraken.dto.marketdata.results.KrakenDepthResult 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 KrakenDepthResult

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

the class KrakenMarketDataServiceRaw method getKrakenDepth.

public KrakenDepth getKrakenDepth(CurrencyPair currencyPair, long count) throws IOException {
    String krakenCurrencyPair = KrakenUtils.createKrakenCurrencyPair(currencyPair);
    KrakenDepthResult result = kraken.getDepth(krakenCurrencyPair, count);
    return checkResult(result).get(krakenCurrencyPair);
}
Also used : KrakenDepthResult(org.knowm.xchange.kraken.dto.marketdata.results.KrakenDepthResult)

Aggregations

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