Skip to content

Commit

Permalink
Reinstate binance in xchange tests
Browse files Browse the repository at this point in the history
Fixes #3016
  • Loading branch information
jamesnetherton committed Sep 16, 2021
1 parent dbb286a commit 2556689
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.inject.Named;
import javax.json.Json;
import javax.json.JsonArrayBuilder;
import javax.json.JsonObject;
Expand All @@ -31,6 +32,7 @@
import javax.ws.rs.core.MediaType;

import org.apache.camel.ProducerTemplate;
import org.apache.camel.component.xchange.XChangeComponent;
import org.knowm.xchange.currency.Currency;
import org.knowm.xchange.currency.CurrencyPair;
import org.knowm.xchange.dto.marketdata.Ticker;
Expand All @@ -41,20 +43,22 @@
@ApplicationScoped
public class XchangeResource {

// TODO: Reinstate binance as the default crypto exchange and kraken as the secondary
// https://github.com/apache/camel-quarkus/issues/3016
public static final String DEFAULT_CRYPTO_EXCHANGE = "kraken";
public static final String DEFAULT_CRYPTO_EXCHANGE = "binance";

@Inject
ProducerTemplate producerTemplate;

@Path("/ticker/{exchange}")
@GET
@Produces(MediaType.APPLICATION_JSON)
public JsonObject currencyTicker(@PathParam("exchange") String cryptoExchange,
public JsonObject currencyTicker(
@PathParam("exchange") String cryptoExchange,
@QueryParam("currencyPair") String currencyPair) {

String component = cryptoExchange.equals(DEFAULT_CRYPTO_EXCHANGE) ? "xchange" : "xchange-" + cryptoExchange;

Ticker ticker = producerTemplate.requestBody(
"xchange:" + cryptoExchange + "?service=marketdata&method=ticker&currencyPair=" + currencyPair, null,
component + ":" + cryptoExchange + "?service=marketdata&method=ticker&currencyPair=" + currencyPair, null,
Ticker.class);
return Json.createObjectBuilder()
.add("last", ticker.getLast().longValue())
Expand Down Expand Up @@ -109,4 +113,11 @@ public String currencyPairsMetadata(@QueryParam("base") String base, @QueryParam
CurrencyPairMetaData.class);
return metaData.getTradingFee().toPlainString();
}

@Named("xchange-kraken")
public XChangeComponent xChangeComponent() {
// We are forced to create a dedicated component instance to work with multiple crypto exchanges
// https://issues.apache.org/jira/browse/CAMEL-16978
return new XChangeComponent();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

import static org.apache.camel.quarkus.component.xchange.it.XchangeResource.DEFAULT_CRYPTO_EXCHANGE;
import static org.hamcrest.Matchers.emptyOrNullString;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.hasItems;
Expand All @@ -30,11 +31,8 @@
@QuarkusTest
class XchangeTest {

// TODO: Reinstate binance as the default crypto exchange and kraken as the secondary
// https://github.com/apache/camel-quarkus/issues/3016
// @ValueSource(strings = { DEFAULT_CRYPTO_EXCHANGE, "kraken" })
@ParameterizedTest
@ValueSource(strings = { "kraken" })
@ValueSource(strings = { DEFAULT_CRYPTO_EXCHANGE, "kraken" })
public void currencyTicker(String cryptoExchange) {
RestAssured.given()
.queryParam("currencyPair", "BTC/USDT")
Expand Down

0 comments on commit 2556689

Please sign in to comment.