Skip to content

Commit

Permalink
[gateio] Extend integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bigscoop committed Nov 6, 2024
1 parent 3fae38d commit caa19b9
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 42 deletions.
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
package info.bitrich.xchangestream.gateio;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
import static org.assertj.core.api.Assumptions.assumeThat;

import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.observers.TestObserver;
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.knowm.xchange.currency.Currency;
import org.knowm.xchange.dto.account.Balance;

@Disabled(
"Needs authenticated exchange and real balance change. Set env vars GATEIO_API_KEY/GATEIO_API_SECRET")
@Slf4j
class GateioStreamingAccountServiceIntegration extends GateioStreamingExchangeIT {

@BeforeEach
void authConfigured() {
assumeTrue(
StringUtils.isNotEmpty(exchange.getExchangeSpecification().getApiKey()), "Needs auth");
assumeTrue(
StringUtils.isNotEmpty(exchange.getExchangeSpecification().getSecretKey()), "Needs auth");
@BeforeAll
public static void credentialsPresent() {
// skip if there are no credentials
assumeThat(exchange.getExchangeSpecification().getApiKey()).isNotEmpty();
assumeThat(exchange.getExchangeSpecification().getSecretKey()).isNotEmpty();
}

@Test
Expand All @@ -31,10 +29,17 @@ void spot_balances() {

TestObserver<Balance> testObserver = observable.test();

Balance balance = testObserver.awaitCount(1).values().get(0);
List<Balance> balances = testObserver
// .awaitDone(10, TimeUnit.MINUTES)
.awaitCount(1)
.values();

testObserver.dispose();

assertThat(balance).hasNoNullFieldsOrProperties();
log.info("Received balances: {}", balances);

assumeThat(balances).overridingErrorMessage("Received nothing").isNotEmpty();

assertThat(balances).first().hasNoNullFieldsOrProperties();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public static void setup() {
StreamingExchangeFactory.INSTANCE
.createExchangeWithoutSpecification(GateioStreamingExchange.class)
.getDefaultExchangeSpecification();
spec.setApiKey(System.getenv("GATEIO_API_KEY"));
spec.setSecretKey(System.getenv("GATEIO_API_SECRET"));
spec.setApiKey(System.getProperty("apiKey"));
spec.setSecretKey(System.getProperty("secretKey"));

exchange = (GateioStreamingExchange) StreamingExchangeFactory.INSTANCE.createExchange(spec);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ void order_book() {

TestObserver<OrderBook> testObserver = observable.test();

OrderBook orderBook = testObserver.awaitCount(1).values().get(0);
OrderBook orderBook = testObserver
// .awaitDone(1, TimeUnit.MINUTES)
.awaitCount(1)
.values().get(0);

testObserver.dispose();

Expand All @@ -42,7 +45,10 @@ void trades() {

TestObserver<Trade> testObserver = observable.test();

Trade trade = testObserver.awaitCount(1).values().get(0);
Trade trade = testObserver
// .awaitDone(1, TimeUnit.MINUTES)
.awaitCount(1)
.values().get(0);

testObserver.dispose();

Expand All @@ -57,7 +63,10 @@ void ticker() {

TestObserver<Ticker> testObserver = observable.test();

Ticker ticker = testObserver.awaitCount(1).values().get(0);
Ticker ticker = testObserver
.awaitCount(1)
// .awaitDone(1, TimeUnit.MINUTES)
.values().get(0);

testObserver.dispose();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,54 +1,69 @@
package info.bitrich.xchangestream.gateio;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
import static org.assertj.core.api.Assumptions.assumeThat;
import static org.knowm.xchange.currency.CurrencyPair.BTC_USDT;

import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.observers.TestObserver;
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.knowm.xchange.currency.CurrencyPair;
import org.knowm.xchange.dto.trade.UserTrade;

@Disabled(
"Needs authenticated exchange and real user trade. Set env vars GATEIO_API_KEY/GATEIO_API_SECRET")
@Slf4j
class GateioStreamingTradeServiceIntegration extends GateioStreamingExchangeIT {

@BeforeEach
void authConfigured() {
assumeTrue(
StringUtils.isNotEmpty(exchange.getExchangeSpecification().getApiKey()), "Needs auth");
assumeTrue(
StringUtils.isNotEmpty(exchange.getExchangeSpecification().getSecretKey()), "Needs auth");
@BeforeAll
public static void credentialsPresent() {
// skip if there are no credentials
assumeThat(exchange.getExchangeSpecification().getApiKey()).isNotEmpty();
assumeThat(exchange.getExchangeSpecification().getSecretKey()).isNotEmpty();
}

@Test
void user_trades_btc() {
Observable<UserTrade> observable =
exchange.getStreamingTradeService().getUserTrades(CurrencyPair.BTC_USDT);
void user_trades_all() {
Observable<UserTrade> observable = exchange.getStreamingTradeService().getUserTrades();

TestObserver<UserTrade> testObserver = observable.test();

UserTrade userTrade = testObserver.awaitCount(1).values().get(0);
List<UserTrade> userTrades = testObserver
// .awaitDone(10, TimeUnit.MINUTES)
.awaitCount(1)
.values();

testObserver.dispose();

assertThat(userTrade).hasNoNullFieldsOrPropertiesExcept("makerOrderId", "takerOrderId");
assertThat(userTrade.getInstrument()).isEqualTo(CurrencyPair.BTC_USDT);
log.info("Received usertrades: {}", userTrades);

assumeThat(userTrades).overridingErrorMessage("No trades happened").isNotEmpty();

assertThat(userTrades.get(0).getInstrument()).isNotNull();
assertThat(userTrades.get(0).getId()).isNotNull();
assertThat(userTrades.get(0).getOrderId()).isNotNull();
}

@Test
void user_trades_all() {
Observable<UserTrade> observable = exchange.getStreamingTradeService().getUserTrades();
void user_trades_single_instrument() {
Observable<UserTrade> observable = exchange.getStreamingTradeService().getUserTrades(BTC_USDT);

TestObserver<UserTrade> testObserver = observable.test();

UserTrade userTrade = testObserver.awaitCount(1).values().get(0);
List<UserTrade> userTrades =
testObserver
// .awaitDone(1, TimeUnit.MINUTES)
.awaitCount(1)
.values();

testObserver.dispose();

assertThat(userTrade).hasNoNullFieldsOrPropertiesExcept("makerOrderId", "takerOrderId");
log.info("Received usertrades: {}", userTrades);

assumeThat(userTrades).overridingErrorMessage("No trades happened").isNotEmpty();

assertThat(userTrades.get(0).getInstrument()).isEqualTo(BTC_USDT);
assertThat(userTrades.get(0).getId()).isNotNull();
assertThat(userTrades.get(0).getOrderId()).isNotNull();
}
}

0 comments on commit caa19b9

Please sign in to comment.