Search in sources :

Example 21 with LimitOrder

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()));
}
Also used : TreeMap(java.util.TreeMap) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 22 with LimitOrder

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;
}
Also used : LimitOrder(org.knowm.xchange.dto.trade.LimitOrder)

Example 23 with LimitOrder

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));
}
Also used : OrderBook(org.knowm.xchange.dto.marketdata.OrderBook) ArrayList(java.util.ArrayList) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) BigDecimal(java.math.BigDecimal) Date(java.util.Date) Test(org.junit.Test)

Example 24 with LimitOrder

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));
}
Also used : OrderBook(org.knowm.xchange.dto.marketdata.OrderBook) ArrayList(java.util.ArrayList) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) BigDecimal(java.math.BigDecimal) Date(java.util.Date) Test(org.junit.Test)

Example 25 with LimitOrder

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));
}
Also used : OrderBook(org.knowm.xchange.dto.marketdata.OrderBook) ArrayList(java.util.ArrayList) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) BigDecimal(java.math.BigDecimal) Date(java.util.Date) Test(org.junit.Test)

Aggregations

LimitOrder (org.knowm.xchange.dto.trade.LimitOrder)337 BigDecimal (java.math.BigDecimal)188 Test (org.junit.Test)122 Date (java.util.Date)110 ArrayList (java.util.ArrayList)95 CurrencyPair (org.knowm.xchange.currency.CurrencyPair)90 OrderBook (org.knowm.xchange.dto.marketdata.OrderBook)89 OpenOrders (org.knowm.xchange.dto.trade.OpenOrders)77 Order (org.knowm.xchange.dto.Order)50 OrderType (org.knowm.xchange.dto.Order.OrderType)39 Exchange (org.knowm.xchange.Exchange)31 MarketOrder (org.knowm.xchange.dto.trade.MarketOrder)29 List (java.util.List)28 TradeService (org.knowm.xchange.service.trade.TradeService)28 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)23 IOException (java.io.IOException)20 Collectors (java.util.stream.Collectors)20 MarketDataService (org.knowm.xchange.service.marketdata.MarketDataService)17 InputStream (java.io.InputStream)15 DefaultOpenOrdersParamCurrencyPair (org.knowm.xchange.service.trade.params.orders.DefaultOpenOrdersParamCurrencyPair)15