Skip to content

Commit

Permalink
Test camel-xchange with kraken until binance issues are resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesnetherton committed Aug 20, 2021
1 parent d9dd921 commit aa7bbd1
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ void registerForReflection(BuildProducer<ReflectiveClassBuildItem> reflectiveCla
String[] dtoClasses = index.getKnownClasses()
.stream()
.map(classInfo -> classInfo.name().toString())
.filter(className -> className.startsWith("org.knowm.xchange.dto"))
.filter(className -> className.matches("^org\\.knowm\\.xchange.*dto.*"))
.toArray(String[]::new);
reflectiveClass.produce(new ReflectiveClassBuildItem(false, true, dtoClasses));
reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, dtoClasses));

// rescu REST framework needs reflective access to the value method on some JAX-RS annotations
String[] jaxrsAnnotations = index.getKnownClasses()
Expand All @@ -110,7 +110,6 @@ void registerForReflection(BuildProducer<ReflectiveClassBuildItem> reflectiveCla
.filter(className -> className.startsWith("javax.ws.rs"))
.toArray(String[]::new);
reflectiveClass.produce(new ReflectiveClassBuildItem(true, false, jaxrsAnnotations));

}

@BuildStep
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/xchange/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
<!-- Test adding additional crypto exchanges -->
<dependency>
<groupId>org.knowm.xchange</groupId>
<artifactId>xchange-coinbase</artifactId>
<artifactId>xchange-kraken</artifactId>
</dependency>

<!-- test dependencies -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
@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";

@Inject
ProducerTemplate producerTemplate;

Expand All @@ -53,9 +57,9 @@ public JsonObject currencyTicker(@PathParam("exchange") String cryptoExchange,
"xchange:" + cryptoExchange + "?service=marketdata&method=ticker&currencyPair=" + currencyPair, null,
Ticker.class);
return Json.createObjectBuilder()
.add("open", ticker.getOpen().longValue())
.add("high", ticker.getHigh().longValue())
.add("low", ticker.getLow().longValue())
.add("last", ticker.getLast().longValue())
.add("bid", ticker.getBid().longValue())
.add("ask", ticker.getAsk().longValue())
.build();
}

Expand All @@ -64,7 +68,8 @@ public JsonObject currencyTicker(@PathParam("exchange") String cryptoExchange,
@Produces(MediaType.APPLICATION_JSON)
@SuppressWarnings("unchecked")
public JsonObject currencies() {
List<Currency> currencies = producerTemplate.requestBody("xchange:binance?service=metadata&method=currencies", null,
List<Currency> currencies = producerTemplate.requestBody(
"xchange:" + DEFAULT_CRYPTO_EXCHANGE + "?service=metadata&method=currencies", null,
List.class);
JsonArrayBuilder builder = Json.createArrayBuilder();
currencies.forEach(c -> builder.add(c.getSymbol()));
Expand All @@ -75,17 +80,19 @@ public JsonObject currencies() {
@GET
@Produces(MediaType.TEXT_PLAIN)
public String currencyMetadata(@PathParam("symbol") String symbol) {
CurrencyMetaData metaData = producerTemplate.requestBody("xchange:binance?service=metadata&method=currencyMetaData",
CurrencyMetaData metaData = producerTemplate.requestBody(
"xchange:" + DEFAULT_CRYPTO_EXCHANGE + "?service=metadata&method=currencyMetaData",
Currency.getInstance(symbol), CurrencyMetaData.class);
return metaData.getWithdrawalFee().toPlainString();
return metaData.getScale().toString();
}

@Path("/currency/pairs")
@GET
@Produces(MediaType.APPLICATION_JSON)
@SuppressWarnings("unchecked")
public JsonObject currencyPairs() {
List<CurrencyPair> currencyPairs = producerTemplate.requestBody("xchange:binance?service=metadata&method=currencyPairs",
List<CurrencyPair> currencyPairs = producerTemplate.requestBody(
"xchange:" + DEFAULT_CRYPTO_EXCHANGE + "?service=metadata&method=currencyPairs",
null, List.class);
JsonArrayBuilder builder = Json.createArrayBuilder();
currencyPairs.forEach(cp -> builder.add(cp.toString()));
Expand All @@ -97,7 +104,8 @@ public JsonObject currencyPairs() {
@Produces(MediaType.TEXT_PLAIN)
public String currencyPairsMetadata(@QueryParam("base") String base, @QueryParam("counter") String counter) {
CurrencyPairMetaData metaData = producerTemplate.requestBody(
"xchange:binance?service=metadata&method=currencyPairMetaData", new CurrencyPair(base, counter),
"xchange:" + DEFAULT_CRYPTO_EXCHANGE + "?service=metadata&method=currencyPairMetaData",
new CurrencyPair(base, counter),
CurrencyPairMetaData.class);
return metaData.getTradingFee().toPlainString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@
*/
package org.apache.camel.quarkus.component.xchange.it;

import io.quarkus.test.junit.DisabledOnNativeImage;
import io.quarkus.test.junit.NativeImageTest;

@DisabledOnNativeImage("https://github.com/apache/camel-quarkus/issues/3016")
@NativeImageTest
class XchangeIT extends XchangeTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import io.quarkus.test.junit.QuarkusTest;
import io.restassured.RestAssured;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
Expand All @@ -28,22 +27,24 @@
import static org.hamcrest.Matchers.hasItems;
import static org.hamcrest.Matchers.not;

@Disabled("https://github.com/apache/camel-quarkus/issues/3016")
@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 = { "binance", "coinbase" })
@ValueSource(strings = { "kraken" })
public void currencyTicker(String cryptoExchange) {
RestAssured.given()
.queryParam("currencyPair", "BTC/USDT")
.get("/xchange/ticker/" + cryptoExchange)
.then()
.statusCode(200)
.body(
"open", greaterThan(0),
"high", greaterThan(0),
"low", greaterThan(0));
"last", greaterThan(0),
"bid", greaterThan(0),
"ask", greaterThan(0));
}

@Test
Expand Down
2 changes: 1 addition & 1 deletion poms/bom-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@
</dependency>
<dependency>
<groupId>org.knowm.xchange</groupId>
<artifactId>xchange-coinbase</artifactId>
<artifactId>xchange-kraken</artifactId>
<version>${xchange.version}</version>
</dependency>
<dependency>
Expand Down

0 comments on commit aa7bbd1

Please sign in to comment.