diff --git a/xchange-binance/src/main/java/org/knowm/xchange/binance/dto/meta/BinanceSystemStatus.java b/xchange-binance/src/main/java/org/knowm/xchange/binance/dto/meta/BinanceSystemStatus.java index c9935d2058a..54f7c981877 100644 --- a/xchange-binance/src/main/java/org/knowm/xchange/binance/dto/meta/BinanceSystemStatus.java +++ b/xchange-binance/src/main/java/org/knowm/xchange/binance/dto/meta/BinanceSystemStatus.java @@ -1,19 +1,21 @@ package org.knowm.xchange.binance.dto.meta; import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Builder; +import lombok.Value; +import lombok.extern.jackson.Jacksonized; +@Value +@Builder +@Jacksonized public class BinanceSystemStatus { // 0: normal,1:system maintenance - @JsonProperty private String status; - // normal or system maintenance - @JsonProperty private String msg; + @JsonProperty + String status; - public String getStatus() { - return status; - } + // normal or system maintenance + @JsonProperty + String msg; - public String getMsg() { - return msg; - } } diff --git a/xchange-binance/src/main/java/org/knowm/xchange/binance/service/BinanceMarketDataService.java b/xchange-binance/src/main/java/org/knowm/xchange/binance/service/BinanceMarketDataService.java index aa86840d183..91d01008baa 100644 --- a/xchange-binance/src/main/java/org/knowm/xchange/binance/service/BinanceMarketDataService.java +++ b/xchange-binance/src/main/java/org/knowm/xchange/binance/service/BinanceMarketDataService.java @@ -21,6 +21,7 @@ import org.knowm.xchange.dto.marketdata.OrderBook; import org.knowm.xchange.dto.marketdata.Ticker; import org.knowm.xchange.dto.marketdata.Trades; +import org.knowm.xchange.dto.meta.ExchangeHealth; import org.knowm.xchange.dto.trade.LimitOrder; import org.knowm.xchange.exceptions.ExchangeException; import org.knowm.xchange.instrument.Instrument; @@ -35,6 +36,20 @@ public BinanceMarketDataService( super(exchange, resilienceRegistries); } + + @Override + public ExchangeHealth getExchangeHealth() { + try { + if (getSystemStatus().getStatus().equals("0")) { + return ExchangeHealth.ONLINE; + } + } catch (IOException e) { + return ExchangeHealth.OFFLINE; + } + return ExchangeHealth.OFFLINE; + } + + /** * optional parameters provided in the args array: * diff --git a/xchange-binance/src/main/java/org/knowm/xchange/binance/service/BinanceUsAccountService.java b/xchange-binance/src/main/java/org/knowm/xchange/binance/service/BinanceUsAccountService.java index 08027faa0c1..0f0ca3e4ebe 100644 --- a/xchange-binance/src/main/java/org/knowm/xchange/binance/service/BinanceUsAccountService.java +++ b/xchange-binance/src/main/java/org/knowm/xchange/binance/service/BinanceUsAccountService.java @@ -88,6 +88,6 @@ public List getFundingHistory(TradeHistoryParams params) { @Override public BinanceSystemStatus getSystemStatus() { LOG.warn("getSystemStatus: {}", NOT_SUPPORTED); - return new BinanceSystemStatus(); + return BinanceSystemStatus.builder().build(); } } diff --git a/xchange-binance/src/test/java/org/knowm/xchange/binance/service/marketdata/MarketDataServiceIntegration.java b/xchange-binance/src/test/java/org/knowm/xchange/binance/service/marketdata/MarketDataServiceIntegration.java index b437e151e14..5abc058178c 100644 --- a/xchange-binance/src/test/java/org/knowm/xchange/binance/service/marketdata/MarketDataServiceIntegration.java +++ b/xchange-binance/src/test/java/org/knowm/xchange/binance/service/marketdata/MarketDataServiceIntegration.java @@ -9,10 +9,17 @@ import org.knowm.xchange.currency.CurrencyPair; 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.instrument.Instrument; public class MarketDataServiceIntegration extends BinanceExchangeIntegration { + @Test + public void exchange_health() { + assertThat(exchange.getMarketDataService().getExchangeHealth()).isEqualTo(ExchangeHealth.ONLINE); + } + + @Test public void valid_timestamp() { diff --git a/xchange-bitstamp/src/main/java/org/knowm/xchange/bitstamp/BitstampAuthenticatedV2.java b/xchange-bitstamp/src/main/java/org/knowm/xchange/bitstamp/BitstampAuthenticatedV2.java index f94a2d393cc..2a065718308 100644 --- a/xchange-bitstamp/src/main/java/org/knowm/xchange/bitstamp/BitstampAuthenticatedV2.java +++ b/xchange-bitstamp/src/main/java/org/knowm/xchange/bitstamp/BitstampAuthenticatedV2.java @@ -10,6 +10,7 @@ import jakarta.ws.rs.core.MediaType; import java.io.IOException; import java.math.BigDecimal; +import java.util.List; import org.knowm.xchange.bitstamp.dto.BitstampException; import org.knowm.xchange.bitstamp.dto.BitstampTransferBalanceResponse; import org.knowm.xchange.bitstamp.dto.account.BitstampBalance; @@ -17,6 +18,7 @@ import org.knowm.xchange.bitstamp.dto.account.BitstampRippleDepositAddress; import org.knowm.xchange.bitstamp.dto.account.BitstampWithdrawal; import org.knowm.xchange.bitstamp.dto.account.DepositTransaction; +import org.knowm.xchange.bitstamp.dto.account.WithdrawalFee; import org.knowm.xchange.bitstamp.dto.account.WithdrawalRequest; import org.knowm.xchange.bitstamp.dto.trade.BitstampCancelAllOrdersResponse; import org.knowm.xchange.bitstamp.dto.trade.BitstampOrder; @@ -646,7 +648,7 @@ BitstampTransferBalanceResponse transferSubAccountBalanceToMain( @POST @Path("withdrawal-requests/") @Consumes(MediaType.APPLICATION_FORM_URLENCODED) - WithdrawalRequest[] getWithdrawalRequests( + List getWithdrawalRequests( @HeaderParam("X-Auth") String apiKey, @HeaderParam("X-Auth-Signature") ParamsDigest signer, @HeaderParam("X-Auth-Nonce") SynchronizedValueFactory nonce, @@ -655,6 +657,16 @@ WithdrawalRequest[] getWithdrawalRequests( @FormParam("timedelta") Long timeDelta) throws BitstampException, IOException; + @POST + @Path("fees/withdrawal/") + List getWithdrawalFees( + @HeaderParam("X-Auth") String apiKey, + @HeaderParam("X-Auth-Signature") ParamsDigest signer, + @HeaderParam("X-Auth-Nonce") SynchronizedValueFactory nonce, + @HeaderParam("X-Auth-Timestamp") SynchronizedValueFactory timeStamp, + @HeaderParam("X-Auth-Version") String version) + throws BitstampException, IOException; + @POST @Path("withdrawal/open/") @Consumes(MediaType.APPLICATION_FORM_URLENCODED) diff --git a/xchange-bitstamp/src/main/java/org/knowm/xchange/bitstamp/BitstampExchange.java b/xchange-bitstamp/src/main/java/org/knowm/xchange/bitstamp/BitstampExchange.java index 4ab00df0136..81a666b66ef 100644 --- a/xchange-bitstamp/src/main/java/org/knowm/xchange/bitstamp/BitstampExchange.java +++ b/xchange-bitstamp/src/main/java/org/knowm/xchange/bitstamp/BitstampExchange.java @@ -1,7 +1,7 @@ package org.knowm.xchange.bitstamp; import java.io.IOException; -import java.util.Arrays; +import java.util.List; import java.util.UUID; import java.util.concurrent.TimeUnit; import org.knowm.xchange.BaseExchange; @@ -68,8 +68,8 @@ public SynchronizedValueFactory getTimestampFactory() { public void remoteInit() throws IOException, ExchangeException { BitstampMarketDataServiceRaw dataService = (BitstampMarketDataServiceRaw) this.marketDataService; - BitstampPairInfo[] bitstampPairInfos = dataService.getTradingPairsInfo(); + List bitstampPairInfos = dataService.getTradingPairsInfo(); exchangeMetaData = - BitstampAdapters.adaptMetaData(Arrays.asList(bitstampPairInfos), exchangeMetaData); + BitstampAdapters.adaptMetaData(bitstampPairInfos, exchangeMetaData); } } diff --git a/xchange-bitstamp/src/main/java/org/knowm/xchange/bitstamp/BitstampV2.java b/xchange-bitstamp/src/main/java/org/knowm/xchange/bitstamp/BitstampV2.java index 6ecaa9843be..388d9f69600 100644 --- a/xchange-bitstamp/src/main/java/org/knowm/xchange/bitstamp/BitstampV2.java +++ b/xchange-bitstamp/src/main/java/org/knowm/xchange/bitstamp/BitstampV2.java @@ -54,7 +54,7 @@ BitstampTransaction[] getTransactions( @GET @Path("trading-pairs-info/") - BitstampPairInfo[] getTradingPairsInfo() throws IOException, BitstampException; + List getTradingPairsInfo() throws IOException, BitstampException; class Pair { public final CurrencyPair pair; diff --git a/xchange-bitstamp/src/main/java/org/knowm/xchange/bitstamp/dto/account/WithdrawalFee.java b/xchange-bitstamp/src/main/java/org/knowm/xchange/bitstamp/dto/account/WithdrawalFee.java new file mode 100644 index 00000000000..7a62ca1e27a --- /dev/null +++ b/xchange-bitstamp/src/main/java/org/knowm/xchange/bitstamp/dto/account/WithdrawalFee.java @@ -0,0 +1,19 @@ +package org.knowm.xchange.bitstamp.dto.account; + +import java.math.BigDecimal; +import lombok.Builder; +import lombok.Value; +import lombok.extern.jackson.Jacksonized; +import org.knowm.xchange.currency.Currency; + +@Jacksonized +@Value +@Builder +public class WithdrawalFee { + + String network; + + BigDecimal fee; + + Currency currency; +} diff --git a/xchange-bitstamp/src/main/java/org/knowm/xchange/bitstamp/service/BitstampAccountServiceRaw.java b/xchange-bitstamp/src/main/java/org/knowm/xchange/bitstamp/service/BitstampAccountServiceRaw.java index 2b2bd571574..1d70f13f078 100644 --- a/xchange-bitstamp/src/main/java/org/knowm/xchange/bitstamp/service/BitstampAccountServiceRaw.java +++ b/xchange-bitstamp/src/main/java/org/knowm/xchange/bitstamp/service/BitstampAccountServiceRaw.java @@ -19,6 +19,7 @@ import org.knowm.xchange.bitstamp.dto.account.BitstampRippleDepositAddress; import org.knowm.xchange.bitstamp.dto.account.BitstampWithdrawal; import org.knowm.xchange.bitstamp.dto.account.DepositTransaction; +import org.knowm.xchange.bitstamp.dto.account.WithdrawalFee; import org.knowm.xchange.bitstamp.dto.account.WithdrawalRequest; import org.knowm.xchange.bitstamp.dto.trade.BitstampUserTransaction; import org.knowm.xchange.client.ExchangeRestProxyBuilder; @@ -349,16 +350,27 @@ public List getUnconfirmedDeposits() throws IOException { public List getWithdrawalRequests(Long timeDelta) throws IOException { try { - final List response = - Arrays.asList( - bitstampAuthenticatedV2.getWithdrawalRequests( + return bitstampAuthenticatedV2.getWithdrawalRequests( apiKeyForV2Requests, signatureCreatorV2, uuidNonceFactory, timestampFactory, API_VERSION, - timeDelta)); - return response; + timeDelta); + } catch (BitstampException e) { + throw handleError(e); + } + } + + public List getWithdrawalFees() throws IOException { + + try { + return bitstampAuthenticatedV2.getWithdrawalFees( + apiKeyForV2Requests, + signatureCreatorV2, + uuidNonceFactory, + timestampFactory, + API_VERSION); } catch (BitstampException e) { throw handleError(e); } diff --git a/xchange-bitstamp/src/main/java/org/knowm/xchange/bitstamp/service/BitstampMarketDataServiceRaw.java b/xchange-bitstamp/src/main/java/org/knowm/xchange/bitstamp/service/BitstampMarketDataServiceRaw.java index 70b28dcc556..76a0d98b084 100644 --- a/xchange-bitstamp/src/main/java/org/knowm/xchange/bitstamp/service/BitstampMarketDataServiceRaw.java +++ b/xchange-bitstamp/src/main/java/org/knowm/xchange/bitstamp/service/BitstampMarketDataServiceRaw.java @@ -71,7 +71,7 @@ public BitstampTransaction[] getTransactions(CurrencyPair pair, @Nullable Bitsta } } - public BitstampPairInfo[] getTradingPairsInfo() throws IOException { + public List getTradingPairsInfo() throws IOException { try { return bitstampV2.getTradingPairsInfo(); } catch (BitstampException e) { diff --git a/xchange-bitstamp/src/test/java/org/knowm/xchange/bitstamp/dto/account/WithdrawalFeesJSONTest.java b/xchange-bitstamp/src/test/java/org/knowm/xchange/bitstamp/dto/account/WithdrawalFeesJSONTest.java new file mode 100644 index 00000000000..34fd836a659 --- /dev/null +++ b/xchange-bitstamp/src/test/java/org/knowm/xchange/bitstamp/dto/account/WithdrawalFeesJSONTest.java @@ -0,0 +1,35 @@ +package org.knowm.xchange.bitstamp.dto.account; + +import static org.assertj.core.api.Assertions.assertThat; + +import com.fasterxml.jackson.databind.ObjectMapper; +import java.io.IOException; +import java.io.InputStream; +import java.math.BigDecimal; +import java.util.List; +import org.junit.Test; + +public class WithdrawalFeesJSONTest { + + @Test + public void testUnmarshal() throws IOException { + + // Read in the JSON from the example resources + InputStream is = + WithdrawalFeesJSONTest.class.getResourceAsStream( + "/org/knowm/xchange/bitstamp/dto/account/withdrawal-fees.json"); + + // Use Jackson to parse it + ObjectMapper mapper = new ObjectMapper(); + + List withdrawalFees = + mapper.readValue( + is, + mapper.getTypeFactory().constructCollectionType(List.class, WithdrawalFee.class)); + + assertThat(withdrawalFees.size()).isEqualTo(1); + assertThat(withdrawalFees.get(0).getNetwork()).isEqualTo("bitcoin"); + assertThat(withdrawalFees.get(0).getCurrency().getCurrencyCode()).isEqualToIgnoringCase("btc"); + assertThat(withdrawalFees.get(0).getFee()).isEqualTo(new BigDecimal("0.00015000")); + } +} diff --git a/xchange-bitstamp/src/test/resources/org/knowm/xchange/bitstamp/dto/account/withdrawal-fees.json b/xchange-bitstamp/src/test/resources/org/knowm/xchange/bitstamp/dto/account/withdrawal-fees.json new file mode 100644 index 00000000000..cdce1e9b58f --- /dev/null +++ b/xchange-bitstamp/src/test/resources/org/knowm/xchange/bitstamp/dto/account/withdrawal-fees.json @@ -0,0 +1,7 @@ +[ + { + "currency": "btc", + "fee": "0.00015000", + "network": "bitcoin" + } +] \ No newline at end of file diff --git a/xchange-bybit/src/main/java/org/knowm/xchange/bybit/BybitAdapters.java b/xchange-bybit/src/main/java/org/knowm/xchange/bybit/BybitAdapters.java index d196840076a..d09624c8c29 100644 --- a/xchange-bybit/src/main/java/org/knowm/xchange/bybit/BybitAdapters.java +++ b/xchange-bybit/src/main/java/org/knowm/xchange/bybit/BybitAdapters.java @@ -48,7 +48,8 @@ public class BybitAdapters { - private static final SimpleDateFormat OPTION_DATE_FORMAT = new SimpleDateFormat("ddMMMyy", Locale.US); + private static final ThreadLocal OPTION_DATE_FORMAT = ThreadLocal.withInitial( + () -> new SimpleDateFormat("ddMMMyy")); public static final List QUOTE_CURRENCIES = Arrays.asList("USDT", "USDC", "EUR", "BTC", "ETH", "DAI", "BRZ"); public static Wallet adaptBybitBalances(List coinWalletBalances) { @@ -133,7 +134,7 @@ public static String convertToBybitSymbol(Instrument instrument) { return String.format( "%s-%s-%s-%s", optionsContract.getBase(), - OPTION_DATE_FORMAT.format(optionsContract.getExpireDate()), + OPTION_DATE_FORMAT.get().format(optionsContract.getExpireDate()), optionsContract.getStrike(), optionsContract.getType().equals(OptionsContract.OptionType.PUT) ? "P" : "C") .toUpperCase(); @@ -191,7 +192,7 @@ public static Instrument adaptInstrumentInfo(BybitInstrumentInfo instrumentInfo) return new OptionsContract.Builder() .currencyPair( new CurrencyPair(instrumentInfo.getBaseCoin(), instrumentInfo.getQuoteCoin())) - .expireDate(OPTION_DATE_FORMAT.parse(expireDateString)) + .expireDate(OPTION_DATE_FORMAT.get().parse(expireDateString)) .strike(strike) .type( optionInstrumentInfo.getOptionsType().equals(OptionType.CALL) diff --git a/xchange-bybit/src/main/java/org/knowm/xchange/bybit/service/BybitMarketDataService.java b/xchange-bybit/src/main/java/org/knowm/xchange/bybit/service/BybitMarketDataService.java index 2ed9c055278..b76da919996 100644 --- a/xchange-bybit/src/main/java/org/knowm/xchange/bybit/service/BybitMarketDataService.java +++ b/xchange-bybit/src/main/java/org/knowm/xchange/bybit/service/BybitMarketDataService.java @@ -3,7 +3,6 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; -import java.util.stream.Collectors; import org.knowm.xchange.bybit.BybitAdapters; import org.knowm.xchange.bybit.BybitExchange; import org.knowm.xchange.bybit.dto.BybitCategory; @@ -65,11 +64,19 @@ public Ticker getTicker(CurrencyPair currencyPair, Object... args) throws IOExce @Override public List getTickers(Params params) throws IOException { - if (!(params instanceof BybitCategory)) { + // get category + BybitCategory category; + if (params == null) { + category = BybitCategory.SPOT; + } + else if (!(params instanceof BybitCategory)) { throw new IllegalArgumentException("Params must be instance of BybitCategory"); } - BybitCategory category = (BybitCategory) params; - if (category.equals(BybitCategory.OPTION)) { + else { + category = (BybitCategory) params; + } + + if (category == BybitCategory.OPTION) { throw new NotYetImplementedForExchangeException("category OPTION not yet implemented"); } BybitResult> response = getTickers(category); diff --git a/xchange-bybit/src/test/resources/logback.xml b/xchange-bybit/src/test/resources/logback.xml index da2d1b62c3c..2a586567a6e 100644 --- a/xchange-bybit/src/test/resources/logback.xml +++ b/xchange-bybit/src/test/resources/logback.xml @@ -17,7 +17,7 @@ - - + + \ No newline at end of file diff --git a/xchange-core/src/main/java/org/knowm/xchange/dto/meta/ExchangeHealth.java b/xchange-core/src/main/java/org/knowm/xchange/dto/meta/ExchangeHealth.java new file mode 100644 index 00000000000..9b1cc0e86d1 --- /dev/null +++ b/xchange-core/src/main/java/org/knowm/xchange/dto/meta/ExchangeHealth.java @@ -0,0 +1,11 @@ +package org.knowm.xchange.dto.meta; + +public enum ExchangeHealth { + ONLINE, + OFFLINE, + + /** + * Can only cancel the order but not place order + */ + CANCEL_ONLY; +} diff --git a/xchange-core/src/main/java/org/knowm/xchange/service/marketdata/MarketDataService.java b/xchange-core/src/main/java/org/knowm/xchange/service/marketdata/MarketDataService.java index 6583e59726a..66a68dd4b42 100644 --- a/xchange-core/src/main/java/org/knowm/xchange/service/marketdata/MarketDataService.java +++ b/xchange-core/src/main/java/org/knowm/xchange/service/marketdata/MarketDataService.java @@ -4,7 +4,13 @@ import java.util.List; import org.knowm.xchange.Exchange; import org.knowm.xchange.currency.CurrencyPair; -import org.knowm.xchange.dto.marketdata.*; +import org.knowm.xchange.dto.marketdata.CandleStickData; +import org.knowm.xchange.dto.marketdata.FundingRate; +import org.knowm.xchange.dto.marketdata.FundingRates; +import org.knowm.xchange.dto.marketdata.OrderBook; +import org.knowm.xchange.dto.marketdata.Ticker; +import org.knowm.xchange.dto.marketdata.Trades; +import org.knowm.xchange.dto.meta.ExchangeHealth; import org.knowm.xchange.exceptions.ExchangeException; import org.knowm.xchange.exceptions.NotAvailableFromExchangeException; import org.knowm.xchange.exceptions.NotYetImplementedForExchangeException; @@ -25,6 +31,15 @@ */ public interface MarketDataService extends BaseService { + /** + * Get exchange health + * + * @return The exchange health + */ + default ExchangeHealth getExchangeHealth() { + return ExchangeHealth.ONLINE; + } + /** * Get a ticker representing the current exchange rate * diff --git a/xchange-examples/src/main/java/org/knowm/xchange/examples/bitstamp/account/BitstampAccountDemo.java b/xchange-examples/src/main/java/org/knowm/xchange/examples/bitstamp/account/BitstampAccountDemo.java index 1c67bc1dc29..327f74b2555 100644 --- a/xchange-examples/src/main/java/org/knowm/xchange/examples/bitstamp/account/BitstampAccountDemo.java +++ b/xchange-examples/src/main/java/org/knowm/xchange/examples/bitstamp/account/BitstampAccountDemo.java @@ -8,6 +8,7 @@ import org.knowm.xchange.bitstamp.dto.account.BitstampDepositAddress; import org.knowm.xchange.bitstamp.dto.account.BitstampWithdrawal; import org.knowm.xchange.bitstamp.dto.account.DepositTransaction; +import org.knowm.xchange.bitstamp.dto.account.WithdrawalFee; import org.knowm.xchange.bitstamp.dto.account.WithdrawalRequest; import org.knowm.xchange.bitstamp.service.BitstampAccountServiceRaw; import org.knowm.xchange.currency.Currency; @@ -67,6 +68,12 @@ private static void raw(BitstampAccountServiceRaw accountService) throws IOExcep System.out.println(unconfirmedDeposit); } + final List withdrawalFees = accountService.getWithdrawalFees(); + System.out.println("Withdrawal requests:"); + for (WithdrawalFee withdrawalFee : withdrawalFees) { + System.out.println(withdrawalFee); + } + final List withdrawalRequests = accountService.getWithdrawalRequests(50000000l); System.out.println("Withdrawal requests:"); diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/Gateio.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/Gateio.java index fc805d69428..df71bd93c89 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/Gateio.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/Gateio.java @@ -6,16 +6,25 @@ import jakarta.ws.rs.Produces; import jakarta.ws.rs.QueryParam; import jakarta.ws.rs.core.MediaType; -import org.knowm.xchange.gateio.dto.GateioException; -import org.knowm.xchange.gateio.dto.marketdata.*; - import java.io.IOException; import java.util.List; +import org.knowm.xchange.gateio.dto.GateioException; +import org.knowm.xchange.gateio.dto.marketdata.GateioCurrencyChain; +import org.knowm.xchange.gateio.dto.marketdata.GateioCurrencyInfo; +import org.knowm.xchange.gateio.dto.marketdata.GateioCurrencyPairDetails; +import org.knowm.xchange.gateio.dto.marketdata.GateioOrderBook; +import org.knowm.xchange.gateio.dto.marketdata.GateioServerTime; +import org.knowm.xchange.gateio.dto.marketdata.GateioTicker; @Path("api/v4") @Produces(MediaType.APPLICATION_JSON) public interface Gateio { + @GET + @Path("spot/time") + GateioServerTime getServerTime() throws IOException, GateioException; + + @GET @Path("spot/currencies") List getCurrencies() throws IOException, GateioException; diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioErrorAdapter.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioErrorAdapter.java index 11324b523f1..9778ce96da1 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioErrorAdapter.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioErrorAdapter.java @@ -1,7 +1,14 @@ package org.knowm.xchange.gateio; import lombok.experimental.UtilityClass; -import org.knowm.xchange.exceptions.*; +import org.knowm.xchange.exceptions.ExchangeException; +import org.knowm.xchange.exceptions.ExchangeSecurityException; +import org.knowm.xchange.exceptions.FundsExceededException; +import org.knowm.xchange.exceptions.InstrumentNotValidException; +import org.knowm.xchange.exceptions.InternalServerException; +import org.knowm.xchange.exceptions.OrderAmountUnderMinimumException; +import org.knowm.xchange.exceptions.OrderNotValidException; +import org.knowm.xchange.exceptions.RateLimitExceededException; import org.knowm.xchange.gateio.dto.GateioException; @UtilityClass @@ -42,7 +49,7 @@ public ExchangeException adapt(GateioException e) { return new InternalServerException(e.getMessage(), e); case INVALID_PARAM_VALUE: - if (e.getMessage().contains("below minimum")) { + if (e.getMessage().contains("below minimum") || e.getMessage().contains("too small")) { return new OrderAmountUnderMinimumException(e.getMessage(), e); } else { diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/Config.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/Config.java index e99b200e06b..fb9de0bfe5e 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/Config.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/Config.java @@ -1,16 +1,23 @@ package org.knowm.xchange.gateio.config; +import java.time.Clock; import lombok.Data; import si.mazi.rescu.IRestProxyFactory; import si.mazi.rescu.RestProxyFactoryImpl; @Data -public class Config { +public final class Config { private Class restProxyFactoryClass = RestProxyFactoryImpl.class; + private Clock clock; + private static Config instance = new Config(); + private Config() { + clock = Clock.systemDefaultZone(); + } + public static Config getInstance() { return instance; } diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioServerTime.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioServerTime.java new file mode 100644 index 00000000000..8ca9c3b9c7f --- /dev/null +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioServerTime.java @@ -0,0 +1,17 @@ +package org.knowm.xchange.gateio.dto.marketdata; + +import com.fasterxml.jackson.annotation.JsonProperty; +import java.time.Instant; +import lombok.Builder; +import lombok.Data; +import lombok.extern.jackson.Jacksonized; + +@Data +@Builder +@Jacksonized +public class GateioServerTime { + + @JsonProperty("server_time") + Instant time; + +} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioMarketDataService.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioMarketDataService.java index 801e48a921b..3f6c6f62ec0 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioMarketDataService.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioMarketDataService.java @@ -1,6 +1,8 @@ package org.knowm.xchange.gateio.service; import java.io.IOException; +import java.time.Duration; +import java.time.Instant; import java.util.List; import java.util.Map; import java.util.Objects; @@ -11,10 +13,12 @@ import org.knowm.xchange.currency.CurrencyPair; 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.dto.meta.InstrumentMetaData; import org.knowm.xchange.gateio.GateioAdapters; import org.knowm.xchange.gateio.GateioErrorAdapter; import org.knowm.xchange.gateio.GateioExchange; +import org.knowm.xchange.gateio.config.Config; import org.knowm.xchange.gateio.dto.GateioException; import org.knowm.xchange.gateio.dto.marketdata.GateioCurrencyInfo; import org.knowm.xchange.gateio.dto.marketdata.GateioCurrencyPairDetails; @@ -30,12 +34,28 @@ public GateioMarketDataService(GateioExchange exchange) { super(exchange); } + @Override + public ExchangeHealth getExchangeHealth() { + try { + Instant serverTime = getGateioServerTime().getTime(); + Instant localTime = Instant.now(Config.getInstance().getClock()); + + // timestamps shouldn't diverge by more than 10 minutes + if (Duration.between(serverTime, localTime).toMinutes() < 10) { + return ExchangeHealth.ONLINE; + } + } catch (GateioException | IOException e) { + return ExchangeHealth.OFFLINE; + } + + return ExchangeHealth.OFFLINE; + } + @Override public Ticker getTicker(CurrencyPair currencyPair, Object... args) throws IOException { return getTicker((Instrument) currencyPair, args); } - @Override public Ticker getTicker(Instrument instrument, Object... args) throws IOException { Objects.requireNonNull(instrument); diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioMarketDataServiceRaw.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioMarketDataServiceRaw.java index fbf38b5f7ee..3b01b6e8d57 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioMarketDataServiceRaw.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioMarketDataServiceRaw.java @@ -9,6 +9,7 @@ import org.knowm.xchange.gateio.dto.marketdata.GateioCurrencyInfo; import org.knowm.xchange.gateio.dto.marketdata.GateioCurrencyPairDetails; import org.knowm.xchange.gateio.dto.marketdata.GateioOrderBook; +import org.knowm.xchange.gateio.dto.marketdata.GateioServerTime; import org.knowm.xchange.gateio.dto.marketdata.GateioTicker; import org.knowm.xchange.instrument.Instrument; @@ -19,6 +20,11 @@ public GateioMarketDataServiceRaw(GateioExchange exchange) { } + public GateioServerTime getGateioServerTime() throws IOException { + return gateio.getServerTime(); + } + + public List getGateioTickers(Instrument instrument) throws IOException { return gateio.getTickers(GateioAdapters.toString(instrument)); } diff --git a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioMarketDataServiceIntegration.java b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioMarketDataServiceIntegration.java new file mode 100644 index 00000000000..a175ac19db2 --- /dev/null +++ b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioMarketDataServiceIntegration.java @@ -0,0 +1,20 @@ +package org.knowm.xchange.gateio.service; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.Test; +import org.knowm.xchange.ExchangeFactory; +import org.knowm.xchange.dto.meta.ExchangeHealth; +import org.knowm.xchange.gateio.GateioExchange; + +class GateioMarketDataServiceIntegration { + + GateioExchange exchange = ExchangeFactory.INSTANCE.createExchange(GateioExchange.class); + + @Test + void exchange_health() { + ExchangeHealth actual = exchange.getMarketDataService().getExchangeHealth(); + assertThat(actual).isEqualTo(ExchangeHealth.ONLINE); + } + +} \ No newline at end of file diff --git a/xchange-okex/src/main/java/org/knowm/xchange/okex/dto/trade/OkexCancelOrderRequest.java b/xchange-okex/src/main/java/org/knowm/xchange/okex/dto/trade/OkexCancelOrderRequest.java index c1ef466965d..5c586c3f261 100644 --- a/xchange-okex/src/main/java/org/knowm/xchange/okex/dto/trade/OkexCancelOrderRequest.java +++ b/xchange-okex/src/main/java/org/knowm/xchange/okex/dto/trade/OkexCancelOrderRequest.java @@ -12,6 +12,6 @@ public class OkexCancelOrderRequest { @JsonProperty("ordId") private String orderId; - @JsonProperty("clOrderId") + @JsonProperty("clOrdId") private String clientOrderId; } diff --git a/xchange-okex/src/main/java/org/knowm/xchange/okex/dto/trade/OkexOrderRequest.java b/xchange-okex/src/main/java/org/knowm/xchange/okex/dto/trade/OkexOrderRequest.java index bdadcdf4593..bb4d1e29715 100644 --- a/xchange-okex/src/main/java/org/knowm/xchange/okex/dto/trade/OkexOrderRequest.java +++ b/xchange-okex/src/main/java/org/knowm/xchange/okex/dto/trade/OkexOrderRequest.java @@ -16,7 +16,7 @@ public class OkexOrderRequest { @JsonProperty("ccy") private String marginCurrency; - @JsonProperty("clOrderId") + @JsonProperty("clOrdId") private String clientOrderId; @JsonProperty("tag")