Skip to content

Commit

Permalink
Merge pull request #4855 from bigscoop/gate-minor-fixes
Browse files Browse the repository at this point in the history
[gateio] [gateio-stream] Gateio minor fixes
  • Loading branch information
timmolter committed Apr 29, 2024
2 parents 6396c11 + a831d5a commit 4a4c2b6
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.io.IOException;
import java.util.List;
import org.apache.commons.lang3.Validate;
import java.util.Objects;
import org.knowm.xchange.currency.Currency;
import org.knowm.xchange.gateio.GateioErrorAdapter;
import org.knowm.xchange.gateio.GateioExchange;
Expand Down Expand Up @@ -86,7 +86,7 @@ public GateioWithdrawalRecord withdraw(GateioWithdrawalRequest gateioWithdrawalR


public List<GateioAddressRecord> getSavedAddresses(Currency currency) throws IOException {
Validate.notNull(currency);
Objects.requireNonNull(currency);
return gateioV4Authenticated.getSavedAddresses(apiKey, exchange.getNonceFactory(), gateioV4ParamsDigest, currency.getCurrencyCode());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Validate;
Expand Down Expand Up @@ -37,7 +38,7 @@ public Ticker getTicker(CurrencyPair currencyPair, Object... args) throws IOExce

@Override
public Ticker getTicker(Instrument instrument, Object... args) throws IOException {
Validate.notNull(instrument);
Objects.requireNonNull(instrument);
try {
List<GateioTicker> tickers = getGateioTickers(instrument);
Validate.validState(tickers.size() == 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.Validate;
Expand All @@ -30,10 +31,10 @@ public GateioTradeServiceRaw(GateioExchange exchange) {

public List<GateioOrder> listOrders(Instrument instrument, OrderStatus orderStatus) throws IOException {
// validate arguments
Validate.notNull(orderStatus);
Objects.requireNonNull(orderStatus);
Set<OrderStatus> allowedOrderStatuses = EnumSet.of(OrderStatus.OPEN, OrderStatus.CLOSED);
Validate.validState(allowedOrderStatuses.contains(orderStatus), "Allowed order statuses are: {}", allowedOrderStatuses);
Validate.notNull(instrument);
Objects.requireNonNull(instrument);

return gateioV4Authenticated.listOrders(apiKey, exchange.getNonceFactory(),
gateioV4ParamsDigest, GateioAdapters.toString(instrument), GateioAdapters.toString(orderStatus)
Expand Down
34 changes: 34 additions & 0 deletions xchange-gateio-v4/src/test/resources/rest/spot.http
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,37 @@ SIGN: {{sign}}
Timestamp: {{timestamp}}
Content-Type: application/json


### Create an order
< {%
import {gen_sign} from 'sign.js'
gen_sign("POST", request);
%}

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

{
"currency_pair": "BTC_USDT",
"type": "limit",
"side": "buy",
"amount": "0.001",
"price": "60000"
}


### Cancel a single order
< {%
import {gen_sign} from 'sign.js'
gen_sign("DELETE", request);
%}

DELETE {{api_v4}}/spot/orders/123456?currency_pair=BTC_USDT
KEY: {{api_key}}
SIGN: {{sign}}
Timestamp: {{timestamp}}
Content-Type: application/json

Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.time.Duration;
import java.time.Instant;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ArrayUtils;
Expand Down Expand Up @@ -108,7 +109,7 @@ private GateioWsRequest getWsRequest(String channelName, Event event, Object...
case Config.SPOT_TICKERS_CHANNEL:
case Config.SPOT_TRADES_CHANNEL: {
CurrencyPair currencyPair = (CurrencyPair) ArrayUtils.get(args, 0);
Validate.notNull(currencyPair);
Objects.requireNonNull(currencyPair);

payload = CurrencyPairPayload.builder()
.currencyPair(currencyPair)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package info.bitrich.xchangestream.gateio.config;

import org.apache.commons.lang3.RandomUtils;
import java.util.concurrent.ThreadLocalRandom;

public final class IdGenerator {

Expand All @@ -15,7 +15,7 @@ public static IdGenerator getInstance() {


public Long requestId() {
return RandomUtils.nextLong();
return ThreadLocalRandom.current().nextLong();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void spot_balances() {

Balance balance = testObserver
.assertSubscribed()
.awaitCount(1, TestWaitStrategy.SLEEP_10MS, 2000000)
.awaitCount(1, TestWaitStrategy.SPIN, 2000000)
.assertNoTimeout()
.values().get(0);

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

OrderBook orderBook = testObserver
.assertSubscribed()
.awaitCount(1, TestWaitStrategy.SLEEP_10MS, 20000)
.awaitCount(1, TestWaitStrategy.SPIN, 20000)
.assertNoTimeout()
.values().get(0);

Expand All @@ -49,7 +49,7 @@ void trades() {

Trade trade = testObserver
.assertSubscribed()
.awaitCount(1, TestWaitStrategy.SLEEP_10MS, 20000)
.awaitCount(1, TestWaitStrategy.SPIN, 20000)
.assertNoTimeout()
.values().get(0);

Expand All @@ -71,7 +71,7 @@ void ticker() {

Ticker ticker = testObserver
.assertSubscribed()
.awaitCount(1, TestWaitStrategy.SLEEP_10MS, 70000)
.awaitCount(1, TestWaitStrategy.SPIN, 70000)
.assertNoTimeout()
.values()
.get(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void user_trades_btc() {

UserTrade userTrade = testObserver
.assertSubscribed()
.awaitCount(1, TestWaitStrategy.SLEEP_10MS, 2000000)
.awaitCount(1, TestWaitStrategy.SPIN, 2000000)
.assertNoTimeout()
.values().get(0);

Expand All @@ -54,7 +54,7 @@ void user_trades_all() {

UserTrade userTrade = testObserver
.assertSubscribed()
.awaitCount(1, TestWaitStrategy.SLEEP_10MS, 2000000)
.awaitCount(1, TestWaitStrategy.SPIN, 2000000)
.assertNoTimeout()
.values().get(0);

Expand Down

0 comments on commit 4a4c2b6

Please sign in to comment.