-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4959 from bigscoop/gateio-stream-fixes
[gateio] Streaming fixes
- Loading branch information
Showing
9 changed files
with
120 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
http-client.private.env.json | ||
http-client.private.env.json | ||
integration-test.env.properties |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
## Using IntelliJ Idea HTTP client | ||
|
||
There are *.http files stored in `src/test/resources/rest` that can be used with IntelliJ Idea HTTP Client. | ||
|
||
Some requests need authorization, so the api credentials have to be stored in `http-client.private.env.json` in module's root. Sample content can be found in `example.http-client.private.env.json` | ||
|
||
> [!CAUTION] | ||
> Never commit your api credentials to the repository! | ||
|
||
[HTTP Client documentation](https://www.jetbrains.com/help/idea/http-client-in-product-code-editor.html) | ||
|
||
## Running integration tests that require API keys | ||
|
||
Integration tests that require API keys read them from environment variables. They can be defined in `integration-test.env.properties`. Sample content can be found in `example.integration-test.env.properties`. | ||
|
||
If no keys are provided the integration tests that need them are skipped. | ||
|
||
> [!CAUTION] | ||
> Never commit your api credentials to the repository! | ||
2 changes: 2 additions & 0 deletions
2
xchange-stream-gateio/example.integration-test.env.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
apiKey=change_me | ||
secretKey=change_me |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 38 additions & 23 deletions
61
...c/test/java/info/bitrich/xchangestream/gateio/GateioStreamingTradeServiceIntegration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |