diff --git a/xchange-kraken/src/main/java/info/bitrich/xchangestream/kraken/KrakenOrderBookUtils.java b/xchange-kraken/src/main/java/info/bitrich/xchangestream/kraken/KrakenOrderBookUtils.java index 54b3907c4..daa02dacd 100644 --- a/xchange-kraken/src/main/java/info/bitrich/xchangestream/kraken/KrakenOrderBookUtils.java +++ b/xchange-kraken/src/main/java/info/bitrich/xchangestream/kraken/KrakenOrderBookUtils.java @@ -1,10 +1,7 @@ package info.bitrich.xchangestream.kraken; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.JsonNode; import info.bitrich.xchangestream.kraken.dto.KrakenOrderBook; import info.bitrich.xchangestream.kraken.dto.enums.KrakenOrderBookMessageType; -import info.bitrich.xchangestream.service.netty.StreamingObjectMapperHelper; import org.apache.commons.lang3.StringUtils; import org.knowm.xchange.kraken.dto.marketdata.KrakenPublicOrder; import org.slf4j.Logger; @@ -89,12 +86,12 @@ public static KrakenPublicOrder extractKrakenPublicOrder(List list) { return new KrakenPublicOrder( new BigDecimal(list.get(0)).stripTrailingZeros(), new BigDecimal(list.get(1)).stripTrailingZeros(), - timestampToMs(list.get(2)) - ); - } - private static long timestampToMs(String timestamp) { - return new BigDecimal(timestamp).multiply(new BigDecimal(1000)).longValue(); + //TODO: The XChange Kraken orderbook timestamp is a seconds format since epoch. + // But websocket order's timestamp is more accurate. It is required to improve the XChange Kraken for supporting higher precision. + // XChange method to fix: org.knowm.xchange.kraken.KrakenAdapters.adaptOrders + new BigDecimal(list.get(2)).longValue() + ); } } diff --git a/xchange-kraken/src/test/java/info/bitrich/xchangestream/kraken/KrakenOrderBookParseTest.java b/xchange-kraken/src/test/java/info/bitrich/xchangestream/kraken/KrakenOrderBookParseTest.java index d420f1e4b..076746836 100644 --- a/xchange-kraken/src/test/java/info/bitrich/xchangestream/kraken/KrakenOrderBookParseTest.java +++ b/xchange-kraken/src/test/java/info/bitrich/xchangestream/kraken/KrakenOrderBookParseTest.java @@ -6,8 +6,10 @@ import info.bitrich.xchangestream.service.netty.StreamingObjectMapperHelper; import org.junit.Assert; import org.junit.Test; +import org.knowm.xchange.kraken.dto.marketdata.KrakenPublicOrder; import java.io.IOException; +import java.math.BigDecimal; import java.util.List; public class KrakenOrderBookParseTest { @@ -25,6 +27,14 @@ public void testOrderBookSnapshot() throws IOException { Assert.assertEquals(25, krakenOrderBook.getAsk().length); Assert.assertNotNull(krakenOrderBook.getBid()); Assert.assertEquals(25, krakenOrderBook.getBid().length); + KrakenPublicOrder firstAsk = krakenOrderBook.getAsk()[0]; + Assert.assertEquals(0, new BigDecimal("8692").compareTo(firstAsk.getPrice())); + Assert.assertEquals(0, new BigDecimal("2.01122372").compareTo(firstAsk.getVolume())); + Assert.assertEquals(1561120269L, firstAsk.getTimestamp()); + KrakenPublicOrder firstBid = krakenOrderBook.getBid()[0]; + Assert.assertEquals(0, new BigDecimal("8691.9").compareTo(firstBid.getPrice())); + Assert.assertEquals(0, new BigDecimal("1.45612927").compareTo(firstBid.getVolume())); + Assert.assertEquals(1561120266L, firstBid.getTimestamp()); } @Test @@ -40,5 +50,9 @@ public void testOrderBookUpdate() throws IOException { Assert.assertEquals(2, krakenOrderBook.getAsk().length); Assert.assertNotNull(krakenOrderBook.getBid()); Assert.assertEquals(0, krakenOrderBook.getBid().length); + KrakenPublicOrder firstAsk = krakenOrderBook.getAsk()[0]; + Assert.assertEquals(0, new BigDecimal("9618.6").compareTo(firstAsk.getPrice())); + Assert.assertEquals(0, BigDecimal.ZERO.compareTo(firstAsk.getVolume())); + Assert.assertEquals(1561372908L, firstAsk.getTimestamp()); } }