BitfinexStreamingAdapters { @Nullable static BitfinexWebSocketAuthOrder adaptOrder(JsonNode order) { BitfinexWebSocketAuthOrder orderObject = createOrderObject(order); if (orderObject == null) { return null; } LOG.debug("Updated order: {}", orderObject); return orderObject; }    }
@Test public void testMarketOrder() { BitfinexWebSocketAuthOrder bitfinexWebSocketAuthOrder = new BitfinexWebSocketAuthOrder( 123123123L, 0L, 456456456L, "tBTCUSD", 1548674205259L, 1548674205259L, new BigDecimal("0.000"), new BigDecimal("0.004"), "MARKET", null, "EXECUTED @ 3495.1(0.004)", new BigDecimal("3495.2"), new BigDecimal("3495.2"), BigDecimal.ZERO, BigDecimal.ZERO, 0, 0 ); Order adaptedOrder = BitfinexStreamingAdapters.adaptOrder(bitfinexWebSocketAuthOrder); assertEquals("123123123", adaptedOrder.getId()); assertEquals(Order.OrderType.BID, adaptedOrder.getType()); assertEquals(new BigDecimal("3495.2"), adaptedOrder.getAveragePrice()); assertEquals(new BigDecimal("0.004"), adaptedOrder.getCumulativeAmount()); assertEquals(CurrencyPair.BTC_USD, adaptedOrder.getCurrencyPair()); assertEquals(new BigDecimal("0.004"), adaptedOrder.getOriginalAmount()); assertEquals(new BigDecimal("0.000"), adaptedOrder.getRemainingAmount()); assertEquals(OrderStatus.FILLED, adaptedOrder.getStatus()); assertEquals(new Date(1548674205259L).getTime(), adaptedOrder.getTimestamp().getTime()); }
@Test public void testStopOrder() { BitfinexWebSocketAuthOrder bitfinexWebSocketAuthOrder = new BitfinexWebSocketAuthOrder( 123123123L, 0L, 456456456L, "tBTCUSD", 1548674205259L, 1548674205259L, new BigDecimal("0.000"), new BigDecimal("0.004"), "STOP", null, "EXECUTED @ 3495.1(0.004)", new BigDecimal("3495.2"), new BigDecimal("3495.2"), BigDecimal.ZERO, BigDecimal.ZERO, 0, 0 ); Order adaptedOrder = BitfinexStreamingAdapters.adaptOrder(bitfinexWebSocketAuthOrder); assertEquals("123123123", adaptedOrder.getId()); assertEquals(Order.OrderType.BID, adaptedOrder.getType()); assertEquals(new BigDecimal("3495.2"), adaptedOrder.getAveragePrice()); assertEquals(new BigDecimal("0.004"), adaptedOrder.getCumulativeAmount()); assertEquals(CurrencyPair.BTC_USD, adaptedOrder.getCurrencyPair()); assertEquals(new BigDecimal("0.004"), adaptedOrder.getOriginalAmount()); assertEquals(new BigDecimal("0.000"), adaptedOrder.getRemainingAmount()); assertEquals(OrderStatus.FILLED, adaptedOrder.getStatus()); assertEquals(new Date(1548674205259L).getTime(), adaptedOrder.getTimestamp().getTime()); }
@Test public void testNewLimitOrder() { BitfinexWebSocketAuthOrder bitfinexWebSocketAuthOrder = new BitfinexWebSocketAuthOrder( 123123123L, 0L, 456456456L, "tBTCUSD", 1548674205259L, 1548674205267L, new BigDecimal("0.004"), new BigDecimal("0.004"), "EXCHANGE LIMIT", null, "ACTIVE", new BigDecimal("3495.2"), BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO, 0, 0 ); LimitOrder adaptedOrder = (LimitOrder) BitfinexStreamingAdapters.adaptOrder(bitfinexWebSocketAuthOrder); assertEquals("123123123", adaptedOrder.getId()); assertEquals(Order.OrderType.BID, adaptedOrder.getType()); assertEquals(BigDecimal.ZERO, adaptedOrder.getAveragePrice()); assertEquals(0, BigDecimal.ZERO.compareTo(adaptedOrder.getCumulativeAmount())); assertEquals(CurrencyPair.BTC_USD, adaptedOrder.getCurrencyPair()); assertEquals(new BigDecimal("3495.2"), adaptedOrder.getLimitPrice()); assertEquals(Collections.emptySet(), adaptedOrder.getOrderFlags()); assertEquals(new BigDecimal("0.004"), adaptedOrder.getOriginalAmount()); assertEquals(new BigDecimal("0.004"), adaptedOrder.getRemainingAmount()); assertEquals(OrderStatus.NEW, adaptedOrder.getStatus()); assertEquals(new Date(1548674205259L).getTime(), adaptedOrder.getTimestamp().getTime()); }
@Test public void testCancelledLimitOrder() { BitfinexWebSocketAuthOrder bitfinexWebSocketAuthOrder = new BitfinexWebSocketAuthOrder( 123123123L, 0L, 456456456L, "tBTCUSD", 1548674205259L, 1548674205267L, new BigDecimal("-0.004"), new BigDecimal("-0.004"), "LIMIT", null, "CANCELED", new BigDecimal("3495.2"), BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO, 0, 0 ); LimitOrder adaptedOrder = (LimitOrder) BitfinexStreamingAdapters.adaptOrder(bitfinexWebSocketAuthOrder); assertEquals("123123123", adaptedOrder.getId()); assertEquals(Order.OrderType.ASK, adaptedOrder.getType()); assertEquals(BigDecimal.ZERO, adaptedOrder.getAveragePrice()); assertEquals(0, BigDecimal.ZERO.compareTo(adaptedOrder.getCumulativeAmount())); assertEquals(CurrencyPair.BTC_USD, adaptedOrder.getCurrencyPair()); assertEquals(new BigDecimal("3495.2"), adaptedOrder.getLimitPrice()); assertEquals(new BigDecimal("0.004"), adaptedOrder.getOriginalAmount()); assertEquals(new BigDecimal("0.004"), adaptedOrder.getRemainingAmount()); assertEquals(OrderStatus.CANCELED, adaptedOrder.getStatus()); assertEquals(new Date(1548674205259L).getTime(), adaptedOrder.getTimestamp().getTime()); }
@Test public void testPartiallyFilledLimitOrder() { BitfinexWebSocketAuthOrder bitfinexWebSocketAuthOrder = new BitfinexWebSocketAuthOrder( 123123123L, 0L, 456456456L, "tBTCUSD", 1548674205259L, 1548674205267L, new BigDecimal("-0.001"), new BigDecimal("-0.004"), "LIMIT", null, "PARTIALLY FILLED @ 3495.1(0.003)", new BigDecimal("3495.2"), new BigDecimal("3495.1"), BigDecimal.ZERO, BigDecimal.ZERO, 0, 0 ); LimitOrder adaptedOrder = (LimitOrder) BitfinexStreamingAdapters.adaptOrder(bitfinexWebSocketAuthOrder); assertEquals("123123123", adaptedOrder.getId()); assertEquals(Order.OrderType.ASK, adaptedOrder.getType()); assertEquals(new BigDecimal("3495.1"), adaptedOrder.getAveragePrice()); assertEquals(new BigDecimal("0.003"), adaptedOrder.getCumulativeAmount()); assertEquals(CurrencyPair.BTC_USD, adaptedOrder.getCurrencyPair()); assertEquals(new BigDecimal("3495.2"), adaptedOrder.getLimitPrice()); assertEquals(new BigDecimal("0.004"), adaptedOrder.getOriginalAmount()); assertEquals(new BigDecimal("0.001"), adaptedOrder.getRemainingAmount()); assertEquals(OrderStatus.PARTIALLY_FILLED, adaptedOrder.getStatus()); assertEquals(new Date(1548674205259L).getTime(), adaptedOrder.getTimestamp().getTime()); }
@Test public void testExecutedLimitOrder() { BitfinexWebSocketAuthOrder bitfinexWebSocketAuthOrder = new BitfinexWebSocketAuthOrder( 123123123L, 0L, 456456456L, "tBTCUSD", 1548674205259L, 1548674205267L, BigDecimal.ZERO, new BigDecimal("0.004"), "EXCHANGE LIMIT", null, "EXECUTED @ 3495.1(0.004): was PARTIALLY FILLED @ 3495.1(0.003)", new BigDecimal("3495.2"), new BigDecimal("3495.1"), BigDecimal.ZERO, BigDecimal.ZERO, 0, 0 ); LimitOrder adaptedOrder = (LimitOrder) BitfinexStreamingAdapters.adaptOrder(bitfinexWebSocketAuthOrder); assertEquals("123123123", adaptedOrder.getId()); assertEquals(Order.OrderType.BID, adaptedOrder.getType()); assertEquals(new BigDecimal("3495.1"), adaptedOrder.getAveragePrice()); assertEquals(new BigDecimal("0.004"), adaptedOrder.getCumulativeAmount()); assertEquals(CurrencyPair.BTC_USD, adaptedOrder.getCurrencyPair()); assertEquals(new BigDecimal("3495.2"), adaptedOrder.getLimitPrice()); assertEquals(new BigDecimal("0.004"), adaptedOrder.getOriginalAmount()); assertEquals(new BigDecimal("0.000"), adaptedOrder.getRemainingAmount()); assertEquals(Collections.emptySet(), adaptedOrder.getOrderFlags()); assertEquals(OrderStatus.FILLED, adaptedOrder.getStatus()); assertEquals(new Date(1548674205259L).getTime(), adaptedOrder.getTimestamp().getTime()); }