use of org.knowm.xchange.dto.trade.LimitOrder in project XChange by knowm.
the class dydxStreamingAdaptersTest method dydxOrderBookChanges.
@Test
public void dydxOrderBookChanges() {
SortedMap<BigDecimal, BigDecimal> sideEntries = new TreeMap<>(Comparator.reverseOrder());
List<LimitOrder> limitOrders = dydxStreamingAdapters.dydxOrderBookChanges(Order.OrderType.BID, CurrencyPair.ETH_USD, new String[][] { { "1840", "10" }, { "1850", "1" } }, sideEntries, 10, false);
Assert.assertEquals(2, limitOrders.size());
Assert.assertEquals(new BigDecimal(1850), limitOrders.get(0).getLimitPrice());
Assert.assertEquals(new BigDecimal(1), limitOrders.get(0).getOriginalAmount());
Assert.assertEquals(2, sideEntries.size());
Assert.assertEquals(new BigDecimal(1850), sideEntries.firstKey());
Assert.assertEquals(new BigDecimal(1), sideEntries.get(sideEntries.firstKey()));
}
use of org.knowm.xchange.dto.trade.LimitOrder in project XChange by knowm.
the class BookSanityChecker method hasErrors.
public static String hasErrors(Iterator<LimitOrder> side) {
if (!side.hasNext())
return null;
LimitOrder prev = side.next();
String check = hasErrors(prev);
if (check != null)
return check;
while (side.hasNext()) {
LimitOrder curr = side.next();
check = hasErrors(curr);
if (check != null)
return check;
if (prev.getLimitPrice().compareTo(curr.getLimitPrice()) >= 0)
return format("Wrong price order for LimitOrders %s, %s", prev, curr);
prev = curr;
}
return null;
}
use of org.knowm.xchange.dto.trade.LimitOrder in project XChange by knowm.
the class BookSanityCheckerTest method testWithAsksLimitOrderError.
@Test
public void testWithAsksLimitOrderError() {
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);
OrderBook book = new OrderBook(new Date(), asks, bids);
Assert.assertEquals(format("LimitOrder amount is <= 0 for %s", a1), BookSanityChecker.hasErrors(book));
}
use of org.knowm.xchange.dto.trade.LimitOrder in project XChange by knowm.
the class BookSanityCheckerTest method testWithBidsWrongPriceOrder.
@Test
public void testWithBidsWrongPriceOrder() {
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.02), CurrencyPair.ADA_BNB, "2", new Date(), new BigDecimal(0.02));
bids.add(b1);
bids.add(b2);
OrderBook book = new OrderBook(new Date(), asks, bids);
Assert.assertEquals(format("Wrong price order for LimitOrders %s, %s", b2, b1), BookSanityChecker.hasErrors(book));
}
use of org.knowm.xchange.dto.trade.LimitOrder in project XChange by knowm.
the class BookSanityCheckerTest method testNoBidsNoErrors.
@Test
public void testNoBidsNoErrors() {
ArrayList<LimitOrder> asks = new ArrayList<>();
ArrayList<LimitOrder> bids = new ArrayList<>();
asks.add(new LimitOrder(Order.OrderType.ASK, new BigDecimal(0.01), CurrencyPair.ADA_BNB, "1", new Date(), new BigDecimal(0.01)));
asks.add(new LimitOrder(Order.OrderType.ASK, new BigDecimal(0.02), CurrencyPair.ADA_BNB, "2", new Date(), new BigDecimal(0.02)));
OrderBook book = new OrderBook(new Date(), asks, bids);
Assert.assertNull(BookSanityChecker.hasErrors(book));
}
Aggregations