use of org.knowm.xchange.dto.trade.LimitOrder 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.trade.LimitOrder 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.trade.LimitOrder 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.trade.LimitOrder 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.trade.LimitOrder in project XChange by knowm.
the class dydxStreamingAdapters method dydxOrderBookChanges.
public static List<LimitOrder> dydxOrderBookChanges(org.knowm.xchange.dto.Order.OrderType orderType, CurrencyPair currencyPair, String[][] changes, SortedMap<BigDecimal, BigDecimal> sideEntries, int maxDepth, boolean isV1) {
if (sideEntries == null) {
return Collections.emptyList();
}
if (changes != null) {
for (String[] level : changes) {
BigDecimal price;
BigDecimal volume;
if (isV1) {
price = new BigDecimal(level[level.length - 2]).movePointRight(amounts.get(currencyPair.base) - amounts.get(currencyPair.counter));
volume = new BigDecimal(level[level.length - 1]).movePointLeft(amounts.get(currencyPair.base));
} else {
price = new BigDecimal(level[level.length - 2]);
volume = new BigDecimal(level[level.length - 1]);
}
sideEntries.put(price, volume);
}
}
Stream<Map.Entry<BigDecimal, BigDecimal>> stream = sideEntries.entrySet().stream().filter(level -> level.getValue().compareTo(BigDecimal.ZERO) != 0);
if (maxDepth != 0) {
stream = stream.limit(maxDepth);
}
return stream.map(level -> new LimitOrder(orderType, level.getValue(), currencyPair, "0", null, level.getKey())).collect(Collectors.toList());
}
Aggregations