BitfinexOrderbook { public synchronized BitfinexDepth toBitfinexDepth() { SortedMap<BigDecimal, BitfinexOrderbookLevel> bitfinexLevelAsks = new TreeMap<>(); SortedMap<BigDecimal, BitfinexOrderbookLevel> bitfinexLevelBids = new TreeMap<>(java.util.Collections.reverseOrder()); for (Map.Entry<BigDecimal, BitfinexOrderbookLevel> level : asks.entrySet()) { bitfinexLevelAsks.put(level.getValue().getPrice(), level.getValue()); } for (Map.Entry<BigDecimal, BitfinexOrderbookLevel> level : bids.entrySet()) { bitfinexLevelBids.put(level.getValue().getPrice(), level.getValue()); } List<BitfinexLevel> askLevels = new ArrayList<>(asks.size()); List<BitfinexLevel> bidLevels = new ArrayList<>(bids.size()); for (Map.Entry<BigDecimal, BitfinexOrderbookLevel> level : bitfinexLevelAsks.entrySet()) { askLevels.add(level.getValue().toBitfinexLevel()); } for (Map.Entry<BigDecimal, BitfinexOrderbookLevel> level : bitfinexLevelBids.entrySet()) { bidLevels.add(level.getValue().toBitfinexLevel()); } return new BitfinexDepth( askLevels.toArray(new BitfinexLevel[askLevels.size()]), bidLevels.toArray(new BitfinexLevel[bidLevels.size()])); } BitfinexOrderbook(BitfinexOrderbookLevel[] levels); synchronized BitfinexDepth toBitfinexDepth(); synchronized void updateLevel(BitfinexOrderbookLevel level);  }
@Test public void timestampShouldBeInSeconds() { BitfinexDepth depth = new BitfinexOrderbook( new BitfinexOrderbookLevel[] { new BitfinexOrderbookLevel(ONE, ONE, ONE), new BitfinexOrderbookLevel(ONE, ONE, ONE) }) .toBitfinexDepth(); OrderBook orderBook = BitfinexAdapters.adaptOrderBook(depth, BTC_USD); assertThat( "The timestamp should be a value less than now, but was: " + orderBook.getTimeStamp(), !orderBook.getTimeStamp().after(new Date())); }