use of org.knowm.xchange.dto.marketdata.OrderBook in project XChange by knowm.
the class LakeBTCAdapterTest method testAdaptOrderbook.
@Test
public void testAdaptOrderbook() throws IOException {
// Read in the JSON from the example resources
InputStream is = LakeBTCMarketDataJsonTest.class.getResourceAsStream("/org/knowm/xchange/lakebtc/dto/marketdata/example-orderbook-data.json");
// Use Jackson to parse it
ObjectMapper mapper = new ObjectMapper();
LakeBTCOrderBook orderBook = mapper.readValue(is, LakeBTCOrderBook.class);
OrderBook adaptedOrderBook = LakeBTCAdapters.adaptOrderBook(orderBook, CurrencyPair.BTC_USD);
List<LimitOrder> asks = adaptedOrderBook.getAsks();
assertThat(asks.size()).isEqualTo(3);
LimitOrder order = asks.get(0);
assertThat(order.getLimitPrice()).isEqualTo("564.87");
assertThat(order.getOriginalAmount()).isEqualTo("22.371");
assertThat(order.getCurrencyPair()).isEqualTo(CurrencyPair.BTC_USD);
}
use of org.knowm.xchange.dto.marketdata.OrderBook in project XChange by knowm.
the class BookSanityCheckerTest method testIncorrectBestAskAndBid.
@Test
public void testIncorrectBestAskAndBid() {
ArrayList<LimitOrder> asks = new ArrayList<>();
ArrayList<LimitOrder> bids = new ArrayList<>();
LimitOrder a1 = new LimitOrder(Order.OrderType.ASK, new BigDecimal(0.01), CurrencyPair.ADA_BNB, "1", new Date(), new BigDecimal(0.01));
asks.add(a1);
LimitOrder b1 = new LimitOrder(Order.OrderType.BID, new BigDecimal(0.02), CurrencyPair.ADA_BNB, "2", new Date(), new BigDecimal(0.02));
bids.add(b1);
OrderBook book = new OrderBook(new Date(), asks, bids);
Assert.assertEquals(format("Got incorrect best ask and bid %s, %s", a1, b1), BookSanityChecker.hasErrors(book));
}
use of org.knowm.xchange.dto.marketdata.OrderBook in project XChange by knowm.
the class BookSanityCheckerTest method testWithBidNoErrorOnNextOrder.
@Test
public void testWithBidNoErrorOnNextOrder() {
ArrayList<LimitOrder> asks = new ArrayList<>();
ArrayList<LimitOrder> bids = new ArrayList<>();
LimitOrder b1 = new LimitOrder(Order.OrderType.BID, new BigDecimal(-0.01), CurrencyPair.ADA_BNB, "1", new Date(), new BigDecimal(0.01));
LimitOrder b2 = new LimitOrder(Order.OrderType.BID, new BigDecimal(0.01), CurrencyPair.ADA_BNB, "2", new Date(), new BigDecimal(0.01));
bids.add(b1);
bids.add(b2);
OrderBook book = new OrderBook(new Date(), asks, bids);
Assert.assertEquals(format("LimitOrder amount is <= 0 for %s", b1), BookSanityChecker.hasErrors(book));
}
use of org.knowm.xchange.dto.marketdata.OrderBook in project XChange by knowm.
the class BookSanityCheckerTest method testWithAsksWithBidsNoErrors.
@Test
public void testWithAsksWithBidsNoErrors() {
ArrayList<LimitOrder> asks = new ArrayList<>();
ArrayList<LimitOrder> bids = new ArrayList<>();
asks.add(new LimitOrder(Order.OrderType.ASK, new BigDecimal(0.02), CurrencyPair.ADA_BNB, "1", new Date(), new BigDecimal(0.02)));
bids.add(new LimitOrder(Order.OrderType.BID, new BigDecimal(0.01), CurrencyPair.ADA_BNB, "2", new Date(), new BigDecimal(0.01)));
OrderBook book = new OrderBook(new Date(), asks, bids);
Assert.assertNull(BookSanityChecker.hasErrors(book));
}
use of org.knowm.xchange.dto.marketdata.OrderBook in project XChange by knowm.
the class FtxStreamingMarketDataService method getOrderBook.
@Override
public Observable<OrderBook> getOrderBook(CurrencyPair currencyPair, Object... args) {
OrderBook orderBook = new OrderBook(null, Lists.newArrayList(), Lists.newArrayList());
String channelName = "orderbook:" + FtxAdapters.adaptCurrencyPairToFtxMarket(currencyPair);
return service.subscribeChannel(channelName).map(res -> {
try {
return FtxStreamingAdapters.adaptOrderbookMessage(orderBook, currencyPair, res);
} catch (IllegalStateException e) {
LOG.warn("Resubscribing {} channel after adapter error {}", currencyPair, e.getMessage());
orderBook.getBids().clear();
orderBook.getAsks().clear();
// Resubscribe to the channel
this.service.sendMessage(service.getUnsubscribeMessage(channelName, args));
this.service.sendMessage(service.getSubscribeMessage(channelName, args));
return new OrderBook(null, Lists.newArrayList(), Lists.newArrayList(), false);
}
}).filter(ob -> ob.getBids().size() > 0 && ob.getAsks().size() > 0);
}
Aggregations