Skip to content

Commit

Permalink
Merge pull request #4937 from bigscoop/gateio-minor-improvements
Browse files Browse the repository at this point in the history
[gateio-v4] Minor improvements
  • Loading branch information
timmolter authored Aug 28, 2024
2 parents 8ef815e + 26a24a8 commit 43d5345
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@

import static org.assertj.core.api.Assertions.assertThat;

import java.io.IOException;
import java.util.List;
import org.apache.commons.lang3.ObjectUtils;
import org.junit.jupiter.api.Test;
import org.knowm.xchange.ExchangeFactory;
import org.knowm.xchange.currency.CurrencyPair;
import org.knowm.xchange.dto.Order.OrderType;
import org.knowm.xchange.dto.marketdata.OrderBook;
import org.knowm.xchange.dto.marketdata.Ticker;
import org.knowm.xchange.dto.meta.ExchangeHealth;
import org.knowm.xchange.gateio.GateioExchange;

Expand All @@ -17,4 +24,42 @@ void exchange_health() {
assertThat(actual).isEqualTo(ExchangeHealth.ONLINE);
}


@Test
void valid_tickers() throws IOException {
List<Ticker> tickers = exchange.getMarketDataService().getTickers(null);
assertThat(tickers).isNotEmpty();

assertThat(tickers).allSatisfy(ticker -> {
assertThat(ticker.getInstrument()).isNotNull();
assertThat(ticker.getLast()).isNotNull();
if (ObjectUtils.allNotNull(ticker.getBid(), ticker.getAsk()) && ticker.getBid().signum() > 0 && ticker.getAsk().signum() > 0) {
assertThat(ticker.getBid()).isLessThan(ticker.getAsk());
}
});
}


@Test
void valid_orderbook() throws IOException {
OrderBook orderBook = exchange.getMarketDataService().getOrderBook(CurrencyPair.BTC_USDT);

assertThat(orderBook.getBids()).isNotEmpty();
assertThat(orderBook.getAsks()).isNotEmpty();

assertThat(orderBook.getAsks().get(0).getLimitPrice()).isGreaterThan(orderBook.getBids().get(0).getLimitPrice());

assertThat(orderBook.getBids()).allSatisfy(limitOrder -> {
assertThat(limitOrder.getInstrument()).isEqualTo(CurrencyPair.BTC_USDT);
assertThat(limitOrder.getType()).isEqualTo(OrderType.BID);
});

assertThat(orderBook.getAsks()).allSatisfy(limitOrder -> {
assertThat(limitOrder.getInstrument()).isEqualTo(CurrencyPair.BTC_USDT);
assertThat(limitOrder.getType()).isEqualTo(OrderType.ASK);
});

}


}
13 changes: 13 additions & 0 deletions xchange-gateio-v4/src/test/resources/rest/spot.http
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@ Timestamp: {{timestamp}}
Content-Type: application/json


### List spot accounts
< {%
import {gen_sign} from 'sign.js'
gen_sign("GET", request);
%}

GET {{api_v4}}/spot/accounts
KEY: {{api_key}}
SIGN: {{sign}}
Timestamp: {{timestamp}}
Content-Type: application/json


### Query account book
< {%
import {gen_sign} from 'sign.js'
Expand Down

0 comments on commit 43d5345

Please sign in to comment.