Search in sources :

Example 16 with OrderBook

use of org.knowm.xchange.dto.marketdata.OrderBook 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 17 with OrderBook

use of org.knowm.xchange.dto.marketdata.OrderBook 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 18 with OrderBook

use of org.knowm.xchange.dto.marketdata.OrderBook 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)

Example 19 with OrderBook

use of org.knowm.xchange.dto.marketdata.OrderBook in project XChange by knowm.

the class CryptopiaAdapters method adaptOrderBook.

/**
 * Adapts a CryptopiaOrderBook to an OrderBook Object
 *
 * @param cryptopiaOrderBook The exchange specific order book
 * @param currencyPair (e.g. BTC/USD)
 * @return The XChange OrderBook
 */
public static OrderBook adaptOrderBook(CryptopiaOrderBook cryptopiaOrderBook, CurrencyPair currencyPair) {
    List<LimitOrder> asks = createOrders(currencyPair, Order.OrderType.ASK, cryptopiaOrderBook.getAsks());
    List<LimitOrder> bids = createOrders(currencyPair, Order.OrderType.BID, cryptopiaOrderBook.getBids());
    return new OrderBook(new Date(), asks, bids);
}
Also used : OrderBook(org.knowm.xchange.dto.marketdata.OrderBook) CryptopiaOrderBook(org.knowm.xchange.cryptopia.dto.marketdata.CryptopiaOrderBook) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) Date(java.util.Date)

Example 20 with OrderBook

use of org.knowm.xchange.dto.marketdata.OrderBook in project XChange by knowm.

the class OrderBookTest method testSerializeDeserialize.

@Test
public void testSerializeDeserialize() throws IOException {
    OrderBook jsonCopy = ObjectMapperHelper.viaJSON(orderBook);
    assertThat(jsonCopy.getTimeStamp()).isEqualTo(orderBook.getTimeStamp());
}
Also used : OrderBook(org.knowm.xchange.dto.marketdata.OrderBook) Test(org.junit.Test)

Aggregations

OrderBook (org.knowm.xchange.dto.marketdata.OrderBook)193 Test (org.junit.Test)88 LimitOrder (org.knowm.xchange.dto.trade.LimitOrder)87 BigDecimal (java.math.BigDecimal)53 MarketDataService (org.knowm.xchange.service.marketdata.MarketDataService)44 Date (java.util.Date)43 CurrencyPair (org.knowm.xchange.currency.CurrencyPair)42 ArrayList (java.util.ArrayList)36 Exchange (org.knowm.xchange.Exchange)34 Ticker (org.knowm.xchange.dto.marketdata.Ticker)32 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)25 InputStream (java.io.InputStream)19 Trades (org.knowm.xchange.dto.marketdata.Trades)18 Trade (org.knowm.xchange.dto.marketdata.Trade)15 List (java.util.List)13 JsonNode (com.fasterxml.jackson.databind.JsonNode)11 Collectors (java.util.stream.Collectors)10 ExchangeSpecification (org.knowm.xchange.ExchangeSpecification)10 IOException (java.io.IOException)9 Order (org.knowm.xchange.dto.Order)9