Search in sources :

Example 26 with OrderBook

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

the class ZaifAdaptersTest method testFullBookAdapter.

@Test
public void testFullBookAdapter() throws IOException {
    // Read in the JSON from the example resources
    InputStream is = ZaifAdaptersTest.class.getResourceAsStream("/org/knowm/xchange/zaif/marketdata/example-fullbook-data.json");
    // Use Jackson to parse it
    ObjectMapper mapper = new ObjectMapper();
    ZaifFullBook zaifFullBook = mapper.readValue(is, ZaifFullBook.class);
    OrderBook orderBook = ZaifAdapters.adaptOrderBook(zaifFullBook, CurrencyPair.BTC_JPY);
    assertThat(orderBook.getBids().get(0).getCurrencyPair()).isEqualTo(CurrencyPair.BTC_JPY);
    assertThat(orderBook.getBids().get(0).getLimitPrice()).isEqualTo("934920");
    assertThat(orderBook.getBids().get(0).getOriginalAmount()).isEqualTo("0.03");
    assertThat(orderBook.getAsks().get(0).getLimitPrice()).isEqualTo("935355");
    assertThat(orderBook.getAsks().get(0).getOriginalAmount()).isEqualTo("0.02");
}
Also used : OrderBook(org.knowm.xchange.dto.marketdata.OrderBook) InputStream(java.io.InputStream) ZaifFullBook(org.knowm.xchange.zaif.dto.marketdata.ZaifFullBook) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 27 with OrderBook

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

the class MarketDataFetchIntegration method depthFetchTest.

@Test
public void depthFetchTest() throws Exception {
    Exchange exchange = ExchangeFactory.INSTANCE.createExchange(ZaifExchange.class);
    MarketDataService marketDataService = exchange.getMarketDataService();
    OrderBook orderBook = marketDataService.getOrderBook(CurrencyPair.BTC_JPY);
    System.out.println(orderBook.toString());
    assertThat(orderBook).isNotNull();
}
Also used : ZaifExchange(org.knowm.xchange.zaif.ZaifExchange) Exchange(org.knowm.xchange.Exchange) OrderBook(org.knowm.xchange.dto.marketdata.OrderBook) MarketDataService(org.knowm.xchange.service.marketdata.MarketDataService) Test(org.junit.Test)

Example 28 with OrderBook

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

the class YoBitMarketDataService method getOrderBooks.

public Iterable<OrderBook> getOrderBooks(OrderBooksRequestParam params) throws IOException {
    if (params instanceof MultiCurrencyOrderBooksRequestParams) {
        MultiCurrencyOrderBooksRequestParams booksRequestParam = (MultiCurrencyOrderBooksRequestParams) params;
        List<OrderBook> res = new ArrayList<>();
        YoBitOrderBooksReturn orderBooks = getOrderBooks(booksRequestParam.currencyPairs, booksRequestParam.desiredDepth);
        for (String ccyPair : orderBooks.orderBooks.keySet()) {
            CurrencyPair currencyPair = YoBitAdapters.adaptCurrencyPair(ccyPair);
            OrderBook orderBook = YoBitAdapters.adaptOrderBook(orderBooks.orderBooks.get(ccyPair), currencyPair);
            res.add(orderBook);
        }
        return res;
    }
    throw new IllegalStateException("Don't understand " + params);
}
Also used : OrderBook(org.knowm.xchange.dto.marketdata.OrderBook) YoBitOrderBooksReturn(org.knowm.xchange.yobit.dto.marketdata.YoBitOrderBooksReturn) MultiCurrencyOrderBooksRequestParams(org.knowm.xchange.yobit.dto.MultiCurrencyOrderBooksRequestParams) ArrayList(java.util.ArrayList) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 29 with OrderBook

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

the class MarketDataServiceIntegration method testGetAllOrderBooks.

@Test
public void testGetAllOrderBooks() throws Exception {
    BiboxMarketDataService marketDataService = (BiboxMarketDataService) BIBOX.getMarketDataService();
    List<OrderBook> orderBooks = marketDataService.getAllOrderBooks(200);
    assertThat(orderBooks.size()).isGreaterThan(20);
}
Also used : OrderBook(org.knowm.xchange.dto.marketdata.OrderBook) BiboxMarketDataService(org.knowm.xchange.bibox.service.BiboxMarketDataService) Test(org.junit.Test)

Example 30 with OrderBook

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

the class BTCMarketsMarketDataServiceTest method shouldGetOrderBook.

@Test
public void shouldGetOrderBook() throws IOException {
    // given
    final LimitOrder[] expectedAsks = expectedAsks();
    final LimitOrder[] expectedBids = expectedBids();
    BTCMarketsOrderBook orderBookMock = parse("org/knowm/xchange/btcmarkets/dto/" + "ShortOrderBook", BTCMarketsOrderBook.class);
    when(btcMarkets.getOrderBook("BTC", "AUD")).thenReturn(orderBookMock);
    // when
    OrderBook orderBook = btcMarketsMarketDataService.getOrderBook(CurrencyPair.BTC_AUD);
    // then
    assertThat(orderBook.getTimeStamp().getTime()).isEqualTo(1442997827000L);
    List<LimitOrder> asks = orderBook.getAsks();
    assertThat(asks).hasSize(3);
    for (int i = 0; i < asks.size(); i++) {
        BtcMarketsAssert.assertEquals(asks.get(i), expectedAsks[i]);
    }
    List<LimitOrder> bids = orderBook.getBids();
    assertThat(bids).hasSize(2);
    for (int i = 0; i < bids.size(); i++) {
        BtcMarketsAssert.assertEquals(bids.get(i), expectedBids[i]);
    }
}
Also used : BTCMarketsOrderBook(org.knowm.xchange.btcmarkets.dto.marketdata.BTCMarketsOrderBook) OrderBook(org.knowm.xchange.dto.marketdata.OrderBook) BTCMarketsOrderBook(org.knowm.xchange.btcmarkets.dto.marketdata.BTCMarketsOrderBook) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) 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