Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[gateio] [gateio-stream] Gateio minor fixes #4855

Merged
merged 3 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading