Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reinstate binance in xchange tests #3106

Merged
merged 1 commit into from
Sep 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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