diff --git a/xchange-blockchain/src/main/java/org/knowm/xchange/blockchain/Blockchain.java b/xchange-blockchain/src/main/java/org/knowm/xchange/blockchain/Blockchain.java index a7308a77b94..e563af0f850 100644 --- a/xchange-blockchain/src/main/java/org/knowm/xchange/blockchain/Blockchain.java +++ b/xchange-blockchain/src/main/java/org/knowm/xchange/blockchain/Blockchain.java @@ -1,9 +1,15 @@ package org.knowm.xchange.blockchain; +import org.knowm.xchange.blockchain.dto.BlockchainException; import org.knowm.xchange.blockchain.dto.account.BlockchainSymbol; +import org.knowm.xchange.blockchain.dto.marketdata.BlockchainOrderBook; -import javax.ws.rs.*; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; +import java.io.IOException; import java.util.Map; /** @@ -23,4 +29,15 @@ public interface Blockchain { @Path("/symbols") @GET Map getSymbols(); + + /** + * Level 3 Order Book data is available through the l3 channel. Each entry in bids and asks arrays is an order, + * along with its id (id), price (px) and quantity (qty) attributes. + * + * @param symbol + * @return All individual orders without aggregation of the L3 order book. + */ + @Path("/l3/{symbol}") + @GET + BlockchainOrderBook getOrderBookL3(@PathParam("symbol") String symbol) throws IOException, BlockchainException; } diff --git a/xchange-blockchain/src/main/java/org/knowm/xchange/blockchain/BlockchainAdapters.java b/xchange-blockchain/src/main/java/org/knowm/xchange/blockchain/BlockchainAdapters.java index e8609b7d73c..229300db8a4 100644 --- a/xchange-blockchain/src/main/java/org/knowm/xchange/blockchain/BlockchainAdapters.java +++ b/xchange-blockchain/src/main/java/org/knowm/xchange/blockchain/BlockchainAdapters.java @@ -5,12 +5,15 @@ import org.knowm.xchange.blockchain.dto.account.BlockchainDeposits; import org.knowm.xchange.blockchain.dto.account.BlockchainSymbol; import org.knowm.xchange.blockchain.dto.account.BlockchainWithdrawal; +import org.knowm.xchange.blockchain.dto.marketdata.BlockchainMarketDataOrder; +import org.knowm.xchange.blockchain.dto.marketdata.BlockchainOrderBook; import org.knowm.xchange.blockchain.dto.trade.BlockchainOrder; import org.knowm.xchange.currency.Currency; import org.knowm.xchange.currency.CurrencyPair; import org.knowm.xchange.dto.Order; import org.knowm.xchange.dto.account.AddressWithTag; import org.knowm.xchange.dto.account.FundingRecord; +import org.knowm.xchange.dto.marketdata.OrderBook; import org.knowm.xchange.dto.marketdata.Trades; import org.knowm.xchange.dto.meta.CurrencyMetaData; import org.knowm.xchange.dto.meta.CurrencyPairMetaData; @@ -249,6 +252,25 @@ public static ExchangeMetaData adaptMetaData(Map marke return new ExchangeMetaData(currencyPairs, currency, rateLimits, rateLimits, false); } + public static OrderBook toOrderBook(BlockchainOrderBook blockchainOrderBook) { + List asks = blockchainOrderBook.getAsks().stream() + .map(limitOrder -> toLimitOrder(limitOrder, Order.OrderType.ASK, blockchainOrderBook.getSymbol())) + .collect(Collectors.toList()); + List bids = blockchainOrderBook.getAsks().stream() + .map(limitOrder -> toLimitOrder(limitOrder, Order.OrderType.BID, blockchainOrderBook.getSymbol())) + .collect(Collectors.toList()); + + return new OrderBook(null, asks, bids); + } + + public static LimitOrder toLimitOrder(BlockchainMarketDataOrder blockchainMarketDataOrder, Order.OrderType orderType , CurrencyPair currencyPair) { + return new LimitOrder.Builder(orderType, currencyPair) + .instrument(currencyPair) + .limitPrice(blockchainMarketDataOrder.getPrice()) + .originalAmount(blockchainMarketDataOrder.getQuantity()) + .build(); + } + public static String getOrderType(Order.OrderType type){ return Order.OrderType.BID.equals(type)? BUY.toUpperCase() : SELL.toUpperCase(); } diff --git a/xchange-blockchain/src/main/java/org/knowm/xchange/blockchain/BlockchainAuthenticated.java b/xchange-blockchain/src/main/java/org/knowm/xchange/blockchain/BlockchainAuthenticated.java index 301f3d7bd24..5103ad30a97 100644 --- a/xchange-blockchain/src/main/java/org/knowm/xchange/blockchain/BlockchainAuthenticated.java +++ b/xchange-blockchain/src/main/java/org/knowm/xchange/blockchain/BlockchainAuthenticated.java @@ -167,6 +167,6 @@ List depositHistory(@QueryParam("from") Long startTime, List getTrades(@QueryParam("symbol") String symbol, @QueryParam("from") Long startTime, @QueryParam("to") Long endTime, - @QueryParam("limit") Integer limit); + @QueryParam("limit") Integer limit) throws IOException, BlockchainException; } diff --git a/xchange-blockchain/src/main/java/org/knowm/xchange/blockchain/BlockchainConstants.java b/xchange-blockchain/src/main/java/org/knowm/xchange/blockchain/BlockchainConstants.java index 2d8cea04546..fc890d806e7 100644 --- a/xchange-blockchain/src/main/java/org/knowm/xchange/blockchain/BlockchainConstants.java +++ b/xchange-blockchain/src/main/java/org/knowm/xchange/blockchain/BlockchainConstants.java @@ -18,6 +18,7 @@ public class BlockchainConstants { public static final String CANCEL_ALL_ORDERS = "cancelAllOrders"; public static final String GET_SYMBOLS = "getSymbols"; public static final String GET_TRADES = "getTrades"; + public static final String GET_ORDER_BOOK_L3 = "getOrderBookL3"; public static final String CURRENCY_PAIR_SYMBOL_FORMAT = "%s-%s"; public static final String X_API_TOKEN = "X-API-Token"; public static final String XCHANGE = "XChange"; diff --git a/xchange-blockchain/src/main/java/org/knowm/xchange/blockchain/BlockchainErrorAdapter.java b/xchange-blockchain/src/main/java/org/knowm/xchange/blockchain/BlockchainErrorAdapter.java index 789cab2ea4d..1f0b311a49b 100644 --- a/xchange-blockchain/src/main/java/org/knowm/xchange/blockchain/BlockchainErrorAdapter.java +++ b/xchange-blockchain/src/main/java/org/knowm/xchange/blockchain/BlockchainErrorAdapter.java @@ -21,6 +21,8 @@ public static ExchangeException adapt(BlockchainException e) { return new ExchangeSecurityException(message, e); case 404: return new RateLimitExceededException(message, e); + case 500: + return new InternalServerException(message, e); default: return new ExchangeException(message, e); } diff --git a/xchange-blockchain/src/main/java/org/knowm/xchange/blockchain/BlockchainExchange.java b/xchange-blockchain/src/main/java/org/knowm/xchange/blockchain/BlockchainExchange.java index 76198f88441..b00f1dcef6b 100644 --- a/xchange-blockchain/src/main/java/org/knowm/xchange/blockchain/BlockchainExchange.java +++ b/xchange-blockchain/src/main/java/org/knowm/xchange/blockchain/BlockchainExchange.java @@ -5,12 +5,12 @@ import org.knowm.xchange.blockchain.dto.account.BlockchainSymbol; import org.knowm.xchange.blockchain.service.BlockchainAccountService; import org.knowm.xchange.blockchain.service.BlockchainAccountServiceRaw; +import org.knowm.xchange.blockchain.service.BlockchainMarketDataService; import org.knowm.xchange.blockchain.service.BlockchainTradeService; import org.knowm.xchange.client.ExchangeRestProxyBuilder; import org.knowm.xchange.client.ResilienceRegistries; import org.knowm.xchange.exceptions.ExchangeException; import org.knowm.xchange.exceptions.NotYetImplementedForExchangeException; -import org.knowm.xchange.service.marketdata.MarketDataService; import si.mazi.rescu.SynchronizedValueFactory; import javax.ws.rs.HeaderParam; @@ -39,6 +39,7 @@ protected void initServices() { this.accountService = new BlockchainAccountService(this, this.blockchain, this.getResilienceRegistries()); this.tradeService = new BlockchainTradeService(this, this.blockchain, this.getResilienceRegistries()); + this.marketDataService = new BlockchainMarketDataService(this, this.blockchain, this.getResilienceRegistries()); } @Override @@ -72,9 +73,4 @@ public ResilienceRegistries getResilienceRegistries() { } return RESILIENCE_REGISTRIES; } - - @Override - public MarketDataService getMarketDataService() { - throw new NotYetImplementedForExchangeException(NOT_IMPLEMENTED_YET); - } } diff --git a/xchange-blockchain/src/main/java/org/knowm/xchange/blockchain/dto/marketdata/BlockchainMarketDataOrder.java b/xchange-blockchain/src/main/java/org/knowm/xchange/blockchain/dto/marketdata/BlockchainMarketDataOrder.java new file mode 100644 index 00000000000..42cc639c84f --- /dev/null +++ b/xchange-blockchain/src/main/java/org/knowm/xchange/blockchain/dto/marketdata/BlockchainMarketDataOrder.java @@ -0,0 +1,22 @@ +package org.knowm.xchange.blockchain.dto.marketdata; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Builder; +import lombok.Data; +import lombok.extern.jackson.Jacksonized; + +import java.math.BigDecimal; + +@Data +@Builder +@Jacksonized +@JsonIgnoreProperties(ignoreUnknown = true) +public class BlockchainMarketDataOrder { + + @JsonProperty("px") + private final BigDecimal price; + @JsonProperty("qty") + private final BigDecimal quantity; + private final Long num; +} diff --git a/xchange-blockchain/src/main/java/org/knowm/xchange/blockchain/dto/marketdata/BlockchainOrderBook.java b/xchange-blockchain/src/main/java/org/knowm/xchange/blockchain/dto/marketdata/BlockchainOrderBook.java new file mode 100644 index 00000000000..3bd08fd8c6c --- /dev/null +++ b/xchange-blockchain/src/main/java/org/knowm/xchange/blockchain/dto/marketdata/BlockchainOrderBook.java @@ -0,0 +1,23 @@ +package org.knowm.xchange.blockchain.dto.marketdata; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import lombok.Builder; +import lombok.Data; +import lombok.extern.jackson.Jacksonized; +import org.knowm.xchange.currency.CurrencyPair; +import org.knowm.xchange.utils.jackson.CurrencyPairDeserializer; + +import java.util.List; + +@Data +@Builder +@Jacksonized +@JsonIgnoreProperties(ignoreUnknown = true) +public class BlockchainOrderBook { + + @JsonDeserialize(using = CurrencyPairDeserializer.class) + private final CurrencyPair symbol; + private final List bids; + private final List asks; +} diff --git a/xchange-blockchain/src/main/java/org/knowm/xchange/blockchain/service/BlockchainMarketDataService.java b/xchange-blockchain/src/main/java/org/knowm/xchange/blockchain/service/BlockchainMarketDataService.java new file mode 100644 index 00000000000..998df17da1b --- /dev/null +++ b/xchange-blockchain/src/main/java/org/knowm/xchange/blockchain/service/BlockchainMarketDataService.java @@ -0,0 +1,72 @@ +package org.knowm.xchange.blockchain.service; + +import org.knowm.xchange.blockchain.BlockchainAdapters; +import org.knowm.xchange.blockchain.BlockchainAuthenticated; +import org.knowm.xchange.blockchain.BlockchainErrorAdapter; +import org.knowm.xchange.blockchain.BlockchainExchange; +import org.knowm.xchange.blockchain.dto.BlockchainException; +import org.knowm.xchange.client.ResilienceRegistries; +import org.knowm.xchange.currency.CurrencyPair; +import org.knowm.xchange.dto.marketdata.OrderBook; +import org.knowm.xchange.dto.marketdata.Ticker; +import org.knowm.xchange.dto.marketdata.Trades; +import org.knowm.xchange.exceptions.NotYetImplementedForExchangeException; +import org.knowm.xchange.instrument.Instrument; +import org.knowm.xchange.service.marketdata.MarketDataService; +import org.knowm.xchange.service.marketdata.params.Params; + +import java.io.IOException; +import java.util.List; + +import static org.knowm.xchange.blockchain.BlockchainConstants.NOT_IMPLEMENTED_YET; + +public class BlockchainMarketDataService extends BlockchainMarketDataServiceRaw implements MarketDataService { + + public BlockchainMarketDataService(BlockchainExchange exchange, BlockchainAuthenticated blockchainApi, ResilienceRegistries resilienceRegistries) { + super(exchange, blockchainApi, resilienceRegistries); + } + + @Override + public Ticker getTicker(CurrencyPair currencyPair, Object... args) throws IOException { + throw new NotYetImplementedForExchangeException(NOT_IMPLEMENTED_YET); + } + + @Override + public Ticker getTicker(Instrument instrument, Object... args) throws IOException { + throw new NotYetImplementedForExchangeException(NOT_IMPLEMENTED_YET); + } + + @Override + public List getTickers(Params params) { + throw new NotYetImplementedForExchangeException(NOT_IMPLEMENTED_YET); + } + + @Override + public OrderBook getOrderBook(CurrencyPair currencyPair, Object... args) throws IOException { + try { + return BlockchainAdapters.toOrderBook(this.getOrderBookL3(currencyPair)); + } catch (BlockchainException e) { + throw BlockchainErrorAdapter.adapt(e); + } + } + + @Override + public OrderBook getOrderBook(Instrument instrument, Object... args) throws IOException { + try { + return BlockchainAdapters.toOrderBook(this.getOrderBookL3(BlockchainAdapters.toCurrencyPair(instrument))); + } catch (BlockchainException e) { + throw BlockchainErrorAdapter.adapt(e); + } + } + + @Override + public Trades getTrades(CurrencyPair currencyPair, Object... args) throws IOException { + throw new NotYetImplementedForExchangeException(NOT_IMPLEMENTED_YET); + } + + @Override + public Trades getTrades(Instrument instrument, Object... args) throws IOException { + throw new NotYetImplementedForExchangeException(NOT_IMPLEMENTED_YET); + } + +} diff --git a/xchange-blockchain/src/main/java/org/knowm/xchange/blockchain/service/BlockchainMarketDataServiceRaw.java b/xchange-blockchain/src/main/java/org/knowm/xchange/blockchain/service/BlockchainMarketDataServiceRaw.java new file mode 100644 index 00000000000..b9717a015d6 --- /dev/null +++ b/xchange-blockchain/src/main/java/org/knowm/xchange/blockchain/service/BlockchainMarketDataServiceRaw.java @@ -0,0 +1,28 @@ +package org.knowm.xchange.blockchain.service; + +import org.knowm.xchange.blockchain.BlockchainAdapters; +import org.knowm.xchange.blockchain.BlockchainAuthenticated; +import org.knowm.xchange.blockchain.BlockchainExchange; +import org.knowm.xchange.blockchain.dto.BlockchainException; +import org.knowm.xchange.blockchain.dto.marketdata.BlockchainOrderBook; +import org.knowm.xchange.client.ResilienceRegistries; +import org.knowm.xchange.currency.CurrencyPair; + +import java.io.IOException; + +import static org.knowm.xchange.blockchain.BlockchainConstants.ENDPOINT_RATE_LIMIT; +import static org.knowm.xchange.blockchain.BlockchainConstants.GET_ORDER_BOOK_L3; + +public class BlockchainMarketDataServiceRaw extends BlockchainBaseService{ + + protected BlockchainMarketDataServiceRaw(BlockchainExchange exchange, BlockchainAuthenticated blockchainApi, ResilienceRegistries resilienceRegistries) { + super(exchange, blockchainApi, resilienceRegistries); + } + + protected BlockchainOrderBook getOrderBookL3(CurrencyPair currencyPair) throws IOException, BlockchainException { + return decorateApiCall(() -> this.blockchainApi.getOrderBookL3(BlockchainAdapters.toSymbol(currencyPair))) + .withRetry(retry(GET_ORDER_BOOK_L3)) + .withRateLimiter(rateLimiter(ENDPOINT_RATE_LIMIT)) + .call(); + } +} diff --git a/xchange-blockchain/src/test/java/org/knowm/xchange/blockchain/service/marketdata/MarketDataServiceTest.java b/xchange-blockchain/src/test/java/org/knowm/xchange/blockchain/service/marketdata/MarketDataServiceTest.java new file mode 100644 index 00000000000..a2836af8aee --- /dev/null +++ b/xchange-blockchain/src/test/java/org/knowm/xchange/blockchain/service/marketdata/MarketDataServiceTest.java @@ -0,0 +1,53 @@ +package org.knowm.xchange.blockchain.service.marketdata; + +import org.junit.Before; +import org.junit.Test; +import org.knowm.xchange.blockchain.BlockchainExchange; +import org.knowm.xchange.blockchain.service.BlockchainBaseTest; +import org.knowm.xchange.currency.CurrencyPair; +import org.knowm.xchange.dto.marketdata.OrderBook; +import org.knowm.xchange.exceptions.InternalServerException; +import org.knowm.xchange.instrument.Instrument; +import org.knowm.xchange.service.marketdata.MarketDataService; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.catchThrowable; +import static org.knowm.xchange.blockchain.service.utils.BlockchainConstants.*; + +public class MarketDataServiceTest extends BlockchainBaseTest { + private MarketDataService service; + + @Before + public void init() { + BlockchainExchange exchange = createExchange(); + service = exchange.getMarketDataService(); + } + + @Test(timeout = 2000) + public void getOrderBookSuccess() throws Exception { + stubGet(ORDERBOOK_JSON, 200, URL_ORDERBOOOK_L3); + OrderBook response = service.getOrderBook(CurrencyPair.BTC_USD); + assertThat(response).isNotNull(); + assertThat(response.getAsks().get(0).getLimitPrice()).isNotNull().isPositive(); + assertThat(response.getBids().get(0).getLimitPrice()).isNotNull().isPositive(); + } + + @Test(timeout = 2000) + public void getOrderBookFailure() { + stubGet(ORDERBOOK_FAILURE_JSON, 500, URL_ORDERBOOOK_L3); + Throwable exception = catchThrowable(() -> service.getOrderBook(CurrencyPair.BTC_USD)); + assertThat(exception) + .isInstanceOf(InternalServerException.class) + .hasMessage(STATUS_CODE_500); + } + + @Test(timeout = 2000) + public void getOrderBookByInstrumentSuccess() throws Exception { + stubGet(ORDERBOOK_JSON, 200, URL_ORDERBOOOK_L3); + Instrument instrument = CurrencyPair.BTC_USD; + OrderBook response = service.getOrderBook(instrument); + assertThat(response).isNotNull(); + assertThat(response.getAsks().get(0).getLimitPrice()).isNotNull().isPositive(); + assertThat(response.getBids().get(0).getLimitPrice()).isNotNull().isPositive(); + } +} diff --git a/xchange-blockchain/src/test/java/org/knowm/xchange/blockchain/service/utils/BlockchainConstants.java b/xchange-blockchain/src/test/java/org/knowm/xchange/blockchain/service/utils/BlockchainConstants.java index 690e56291e1..f7972dd7a82 100644 --- a/xchange-blockchain/src/test/java/org/knowm/xchange/blockchain/service/utils/BlockchainConstants.java +++ b/xchange-blockchain/src/test/java/org/knowm/xchange/blockchain/service/utils/BlockchainConstants.java @@ -15,15 +15,19 @@ public class BlockchainConstants { public static final String URL_ORDERS_BY_ID_2 = "/v3/exchange/orders/22222222"; public static final String URL_ORDERS_BY_ID = "/v3/exchange/orders/111111211"; public static final String URL_TRADES = "/v3/exchange/trades"; + public static final String URL_ORDERBOOOK_L3 = "/v3/exchange/l3/BTC-USD"; public static final String WITHDRAWAL_ID = "3QXYWgRGX2BPYBpUDBssGbeWEa5zq6snBZ"; public static final String STATUS_CODE_401 = "Unauthorized (HTTP status code: 401)"; public static final String STATUS_CODE_400 = "Bad Request (HTTP status code: 400)"; public static final String STATUS_CODE_404 = " (HTTP status code: 404)"; public static final String HTTP_CODE_400 = "HTTP status code was not OK: 400"; + public static final String STATUS_CODE_500 = " (HTTP status code: 500)"; public static final String ADDRESS = "1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa"; public static final String ADDRESS_DEPOSIT = "3CrbF4Z45fnJs62jFs1p3LkR8KiZSGKJFL"; public static final String ACCOUNT_INFORMATION_JSON = "accountInformation.json"; public static final String ORDERS_JSON = "orders.json"; + public static final String ORDERBOOK_JSON = "orderbook.json"; + public static final String ORDERBOOK_FAILURE_JSON = "orderbook_failure.json"; public static final String NEW_ORDER_MARKET_JSON = "new_order_market.json"; public static final String NEW_ORDER_LIMIT_JSON = "new_order_limit.json"; public static final String NEW_ORDER_STOP_JSON = "new_order_stop.json"; diff --git a/xchange-blockchain/src/test/resources/__files/orderbook.json b/xchange-blockchain/src/test/resources/__files/orderbook.json new file mode 100644 index 00000000000..b4a2fac5c69 --- /dev/null +++ b/xchange-blockchain/src/test/resources/__files/orderbook.json @@ -0,0 +1,172 @@ +{ + "symbol": "BTC-USD", + "bids": [ + { + "px": 21079.0, + "qty": 0.69, + "num": 528287406793 + }, + { + "px": 20865.0, + "qty": 0.28, + "num": 528287395754 + }, + { + "px": 20799.0, + "qty": 0.39, + "num": 528287364140 + }, + { + "px": 20495.0, + "qty": 0.41, + "num": 528287170168 + }, + { + "px": 20427.0, + "qty": 0.17, + "num": 528287169585 + }, + { + "px": 20422.0, + "qty": 0.59, + "num": 528287169465 + }, + { + "px": 20422.0, + "qty": 0.86, + "num": 528287169809 + }, + { + "px": 20380.0, + "qty": 0.74, + "num": 528287170250 + }, + { + "px": 20338.0, + "qty": 0.22, + "num": 528287165883 + }, + { + "px": 20222.0, + "qty": 0.57, + "num": 528287163593 + }, + { + "px": 20199.0, + "qty": 0.25, + "num": 528287162993 + }, + { + "px": 20167.0, + "qty": 0.1, + "num": 528287160165 + }, + { + "px": 20057.0, + "qty": 1.0, + "num": 528287159797 + }, + { + "px": 20008.0, + "qty": 0.17, + "num": 528287153135 + }, + { + "px": 10000.0, + "qty": 0.07142878, + "num": 528285237697 + }, + { + "px": 1000.0, + "qty": 0.002, + "num": 528285481282 + }, + { + "px": 2.0, + "qty": 1216.51205043, + "num": 528284038045 + } + ], + "asks": [ + { + "px": 20733.0, + "qty": 0.67, + "num": 528287170325 + }, + { + "px": 20903.0, + "qty": 0.78, + "num": 528287158515 + }, + { + "px": 20903.0, + "qty": 0.95, + "num": 528287158855 + }, + { + "px": 20903.0, + "qty": 0.34, + "num": 528287160040 + }, + { + "px": 20904.0, + "qty": 0.42, + "num": 528287157988 + }, + { + "px": 20904.0, + "qty": 0.17, + "num": 528287158533 + }, + { + "px": 20904.0, + "qty": 0.42, + "num": 528287161336 + }, + { + "px": 20904.0, + "qty": 0.46, + "num": 528287164572 + }, + { + "px": 20904.0, + "qty": 0.14, + "num": 528287168439 + }, + { + "px": 20905.0, + "qty": 0.96, + "num": 528287151762 + }, + { + "px": 20905.0, + "qty": 0.24, + "num": 528287156577 + }, + { + "px": 20905.0, + "qty": 0.78, + "num": 528287159814 + }, + { + "px": 20905.0, + "qty": 0.45, + "num": 528287163333 + }, + { + "px": 20905.0, + "qty": 0.25, + "num": 528287164699 + }, + { + "px": 20905.0, + "qty": 0.77, + "num": 528287167249 + }, + { + "px": 20906.0, + "qty": 0.48, + "num": 528287154938 + } + ] +} \ No newline at end of file diff --git a/xchange-blockchain/src/test/resources/__files/orderbook_failure.json b/xchange-blockchain/src/test/resources/__files/orderbook_failure.json new file mode 100644 index 00000000000..8497a1a4027 --- /dev/null +++ b/xchange-blockchain/src/test/resources/__files/orderbook_failure.json @@ -0,0 +1,7 @@ +{ + "timestamp": "2022-06-26T04:05:43.415+00:00", + "status": 500, + "error": "Internal Server Error", + "message": "", + "path": "/l3/BTC-USD" +} \ No newline at end of file diff --git a/xchange-examples/src/main/java/org/knowm/xchange/examples/blockchain/marketdata/BlockchainMarketDataDemo.java b/xchange-examples/src/main/java/org/knowm/xchange/examples/blockchain/marketdata/BlockchainMarketDataDemo.java new file mode 100644 index 00000000000..b6cdfbbc59c --- /dev/null +++ b/xchange-examples/src/main/java/org/knowm/xchange/examples/blockchain/marketdata/BlockchainMarketDataDemo.java @@ -0,0 +1,31 @@ +package org.knowm.xchange.examples.blockchain.marketdata; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; +import org.knowm.xchange.Exchange; +import org.knowm.xchange.currency.CurrencyPair; +import org.knowm.xchange.dto.marketdata.OrderBook; +import org.knowm.xchange.examples.blockchain.BlockchainDemoUtils; +import org.knowm.xchange.instrument.Instrument; +import org.knowm.xchange.service.marketdata.MarketDataService; + +import java.io.IOException; + +public class BlockchainMarketDataDemo { + private static final Exchange BLOCKCHAIN_EXCHANGE = BlockchainDemoUtils.createExchange(); + private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT); + + public static void main(String[] args) throws IOException, InterruptedException { + System.out.println("===== MARKETDATA SERVICE ====="); + marketDataServiceDemo(); + } + + private static void marketDataServiceDemo() throws IOException { + MarketDataService marketDataService = BLOCKCHAIN_EXCHANGE.getMarketDataService(); + + System.out.println("===== ORDERBOOK FOR BTC/USD ====="); + Instrument instrument = CurrencyPair.BTC_USD; + OrderBook orders = marketDataService.getOrderBook(instrument); + System.out.println(OBJECT_MAPPER.writeValueAsString(orders)); + } +}