Skip to content

Commit

Permalink
bitrich-info#448 revew fix - order timestamp more accurate now
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel Chertalev committed Dec 4, 2019
1 parent 1e4c04b commit 25566b2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class KrakenOrderBookUtils {
private static final String BID_UPDATE = "b";

private static final int EXPECTED_ORDER_BOOK_ARRAY_SIZE = 4;
private static final BigDecimal BIG_DECIMAL_1000 = new BigDecimal(1000);

@SuppressWarnings("unchecked")
public static KrakenOrderBook parse(List jsonParseResult) {
Expand Down Expand Up @@ -90,7 +91,7 @@ public static KrakenPublicOrder extractKrakenPublicOrder(List<String> list) {
//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()
new BigDecimal(list.get(2)).multiply(BIG_DECIMAL_1000).longValue()
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ public void testOrderBookSnapshot() throws IOException {
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());
Assert.assertEquals(1561120269939L, 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());
Assert.assertEquals(1561120266647L, firstBid.getTimestamp());
}

@Test
Expand All @@ -53,6 +53,6 @@ public void testOrderBookUpdate() throws IOException {
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());
Assert.assertEquals(1561372908562L, firstAsk.getTimestamp());
}
}

0 comments on commit 25566b2

Please sign in to comment.