Skip to content
This repository has been archived by the owner on Jun 8, 2020. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'upstream/develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
amarkowski committed Feb 2, 2018
2 parents aabf962 + 760b03f commit cfe81fc
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,28 @@ public class BitstampStreamingMarketDataService implements StreamingMarketDataSe
this.service = service;
}

public Observable<OrderBook> getDifferentialOrderBook(CurrencyPair currencyPair, Object... args) {
return getOrderBook("diff_order_book", currencyPair, args);
}

@Override
public Observable<OrderBook> getOrderBook(CurrencyPair currencyPair, Object... args) {
String channelName = "order_book" + getChannelPostfix(currencyPair);
return getOrderBook("order_book", currencyPair, args);
}

private Observable<OrderBook> getOrderBook(String channelPrefix, CurrencyPair currencyPair, Object... args) {
String channelName = channelPrefix + getChannelPostfix(currencyPair);

return service.subscribeChannel(channelName, "data")
.map(s -> {
ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
BitstampOrderBook orderBook = mapper.readValue(s, BitstampOrderBook.class);
org.knowm.xchange.bitstamp.dto.marketdata.BitstampOrderBook bitstampOrderBook = new org.knowm.xchange.bitstamp.dto.marketdata.BitstampOrderBook(new Date().getTime() / 1000L, orderBook.getBids(), orderBook.getAsks());
org.knowm.xchange.bitstamp.dto.marketdata.BitstampOrderBook bitstampOrderBook =
new org.knowm.xchange.bitstamp.dto.marketdata.BitstampOrderBook(
new Date().getTime() / 1000L,
orderBook.getBids(),
orderBook.getAsks());

return BitstampAdapters.adaptOrderBook(bitstampOrderBook, currencyPair);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.function.Supplier;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.eq;
Expand All @@ -36,12 +37,11 @@ public void setUp() throws Exception {
marketDataService = new BitstampStreamingMarketDataService(streamingService);
}

@Test
public void testGetOrderBook() throws Exception {
public void testOrderbookCommon(String channelName, Supplier<TestObserver<OrderBook>> updater) throws Exception {
// Given order book in JSON
String orderBook = new String(Files.readAllBytes(Paths.get(ClassLoader.getSystemResource("order-book.json").toURI())));

when(streamingService.subscribeChannel(eq("order_book_btceur"), eq("data"))).thenReturn(Observable.just(orderBook));
when(streamingService.subscribeChannel(eq(channelName), eq("data"))).thenReturn(Observable.just(orderBook));

List<LimitOrder> bids = new ArrayList<>();
bids.add(new LimitOrder(Order.OrderType.BID, new BigDecimal("0.922"), CurrencyPair.BTC_EUR, "", null, new BigDecimal("819.9")));
Expand All @@ -53,7 +53,7 @@ public void testGetOrderBook() throws Exception {
asks.add(new LimitOrder(Order.OrderType.ASK, new BigDecimal("0.035"), CurrencyPair.BTC_EUR, "", null, new BigDecimal("821.6")));

// Call get order book observable
TestObserver<OrderBook> test = marketDataService.getOrderBook(CurrencyPair.BTC_EUR).test();
TestObserver<OrderBook> test = updater.get();

// We get order book object in correct order
test.assertValue(orderBook1 -> {
Expand All @@ -63,6 +63,16 @@ public void testGetOrderBook() throws Exception {
});
}

@Test
public void testGetDifferentialOrderBook() throws Exception {
testOrderbookCommon("diff_order_book_btceur", () -> marketDataService.getDifferentialOrderBook(CurrencyPair.BTC_EUR).test());
}

@Test
public void testGetOrderBook() throws Exception {
testOrderbookCommon("order_book_btceur", () -> marketDataService.getOrderBook(CurrencyPair.BTC_EUR).test());
}

@Test
public void testGetTrades() throws Exception {
// Given order book in JSON
Expand Down

0 comments on commit cfe81fc

Please sign in to comment.