From d2b171f4955d122de5521bf443f6747ca8850cb0 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Wed, 22 Mar 2023 22:53:10 +0100 Subject: [PATCH 001/159] [core] Code cleanup --- .../service/BTCMarketsAccountService.java | 2 +- .../coingi/service/CoingiAccountService.java | 6 +- .../params/DefaultWithdrawFundsParams.java | 69 +++++-------------- .../okcoin/service/OkCoinAccountService.java | 2 +- .../okcoin/v3/service/OkexAccountService.java | 2 +- 5 files changed, 22 insertions(+), 59 deletions(-) diff --git a/xchange-btcmarkets/src/main/java/org/knowm/xchange/btcmarkets/service/BTCMarketsAccountService.java b/xchange-btcmarkets/src/main/java/org/knowm/xchange/btcmarkets/service/BTCMarketsAccountService.java index f5b34fc22ac..75f9bb5f9fb 100644 --- a/xchange-btcmarkets/src/main/java/org/knowm/xchange/btcmarkets/service/BTCMarketsAccountService.java +++ b/xchange-btcmarkets/src/main/java/org/knowm/xchange/btcmarkets/service/BTCMarketsAccountService.java @@ -39,7 +39,7 @@ public AccountInfo getAccountInfo() throws IOException { public String withdrawFunds(WithdrawFundsParams params) throws IOException { if (params instanceof DefaultWithdrawFundsParams) { DefaultWithdrawFundsParams defaultWithdrawFundsParams = (DefaultWithdrawFundsParams) params; - String address = defaultWithdrawFundsParams.address; + String address = defaultWithdrawFundsParams.getAddress(); if (params instanceof RippleWithdrawFundsParams) { address = address + "?dt=" + ((RippleWithdrawFundsParams) params).tag; } diff --git a/xchange-coingi/src/main/java/org/knowm/xchange/coingi/service/CoingiAccountService.java b/xchange-coingi/src/main/java/org/knowm/xchange/coingi/service/CoingiAccountService.java index cf12d790e75..0da2e4ac571 100644 --- a/xchange-coingi/src/main/java/org/knowm/xchange/coingi/service/CoingiAccountService.java +++ b/xchange-coingi/src/main/java/org/knowm/xchange/coingi/service/CoingiAccountService.java @@ -56,9 +56,9 @@ public String withdrawFunds(WithdrawFundsParams p) DefaultWithdrawFundsParams params = (DefaultWithdrawFundsParams) p; CoingiWithdrawalRequest request = new CoingiWithdrawalRequest() - .setAddress(params.address) - .setAmount(params.amount) - .setCurrency(params.currency.getCurrencyCode().toUpperCase()); + .setAddress(params.getAddress()) + .setAmount(params.getAmount()) + .setCurrency(params.getCurrency().getCurrencyCode().toUpperCase()); return withdraw(request).toString(); } diff --git a/xchange-core/src/main/java/org/knowm/xchange/service/trade/params/DefaultWithdrawFundsParams.java b/xchange-core/src/main/java/org/knowm/xchange/service/trade/params/DefaultWithdrawFundsParams.java index d1f8329e00e..566b18af5cc 100644 --- a/xchange-core/src/main/java/org/knowm/xchange/service/trade/params/DefaultWithdrawFundsParams.java +++ b/xchange-core/src/main/java/org/knowm/xchange/service/trade/params/DefaultWithdrawFundsParams.java @@ -1,20 +1,24 @@ package org.knowm.xchange.service.trade.params; import java.math.BigDecimal; -import javax.annotation.Nullable; +import lombok.Value; +import lombok.experimental.NonFinal; import org.knowm.xchange.currency.Currency; import org.knowm.xchange.dto.account.AddressWithTag; +@Value +@NonFinal public class DefaultWithdrawFundsParams implements WithdrawFundsParams { - public final String address; - private final String addressTag; + String address; - public final Currency currency; + String addressTag; - public final BigDecimal amount; + Currency currency; - @Nullable public final BigDecimal commission; + BigDecimal amount; + + BigDecimal commission; public DefaultWithdrawFundsParams(String address, Currency currency, BigDecimal amount) { this(address, currency, amount, null); @@ -24,8 +28,8 @@ public DefaultWithdrawFundsParams(AddressWithTag address, Currency currency, Big this(address, currency, amount, null); } - public DefaultWithdrawFundsParams( - String address, Currency currency, BigDecimal amount, BigDecimal commission) { + public DefaultWithdrawFundsParams(String address, Currency currency, BigDecimal amount, + BigDecimal commission) { this.address = address; this.addressTag = null; this.currency = currency; @@ -33,8 +37,8 @@ public DefaultWithdrawFundsParams( this.commission = commission; } - public DefaultWithdrawFundsParams( - AddressWithTag address, Currency currency, BigDecimal amount, BigDecimal commission) { + public DefaultWithdrawFundsParams(AddressWithTag address, Currency currency, BigDecimal amount, + BigDecimal commission) { this.address = address.getAddress(); this.addressTag = address.getAddressTag(); this.currency = currency; @@ -42,12 +46,8 @@ public DefaultWithdrawFundsParams( this.commission = commission; } - public DefaultWithdrawFundsParams( - String address, - String addressTag, - Currency currency, - BigDecimal amount, - BigDecimal commission) { + public DefaultWithdrawFundsParams(String address, String addressTag, Currency currency, + BigDecimal amount, BigDecimal commission) { this.address = address; this.addressTag = addressTag; this.currency = currency; @@ -55,41 +55,4 @@ public DefaultWithdrawFundsParams( this.commission = commission; } - public String getAddress() { - return address; - } - - public String getAddressTag() { - return addressTag; - } - - public Currency getCurrency() { - return currency; - } - - public BigDecimal getAmount() { - return amount; - } - - @Nullable - public BigDecimal getCommission() { - return commission; - } - - @Override - public String toString() { - return "DefaultWithdrawFundsParams{" - + "address='" - + getAddress() - + ", addressTag=" - + getAddressTag() - + '\'' - + ", currency=" - + getCurrency() - + ", amount=" - + getAmount() - + ", commission=" - + getCommission() - + '}'; - } } diff --git a/xchange-okcoin/src/main/java/org/knowm/xchange/okcoin/service/OkCoinAccountService.java b/xchange-okcoin/src/main/java/org/knowm/xchange/okcoin/service/OkCoinAccountService.java index c8dbfef314e..f47459e6bc3 100644 --- a/xchange-okcoin/src/main/java/org/knowm/xchange/okcoin/service/OkCoinAccountService.java +++ b/xchange-okcoin/src/main/java/org/knowm/xchange/okcoin/service/OkCoinAccountService.java @@ -80,7 +80,7 @@ public String withdrawFunds(Currency currency, BigDecimal amount, String address public String withdrawFunds(WithdrawFundsParams params) throws IOException { if (params instanceof DefaultWithdrawFundsParams) { DefaultWithdrawFundsParams defaultParams = (DefaultWithdrawFundsParams) params; - return withdrawFunds(defaultParams.currency, defaultParams.amount, defaultParams.address); + return withdrawFunds(defaultParams.getCurrency(), defaultParams.getAmount(), defaultParams.getAddress()); } throw new IllegalStateException("Don't know how to withdraw: " + params); } diff --git a/xchange-okcoin/src/main/java/org/knowm/xchange/okcoin/v3/service/OkexAccountService.java b/xchange-okcoin/src/main/java/org/knowm/xchange/okcoin/v3/service/OkexAccountService.java index 2e3fd709e9c..804fded23d9 100644 --- a/xchange-okcoin/src/main/java/org/knowm/xchange/okcoin/v3/service/OkexAccountService.java +++ b/xchange-okcoin/src/main/java/org/knowm/xchange/okcoin/v3/service/OkexAccountService.java @@ -68,7 +68,7 @@ public AccountInfo getAccountInfo() throws IOException { public String withdrawFunds(WithdrawFundsParams params) throws IOException { if (params instanceof DefaultWithdrawFundsParams) { DefaultWithdrawFundsParams p = (DefaultWithdrawFundsParams) params; - return withdrawFunds0(p.currency, p.amount, p.address, p.commission); + return withdrawFunds0(p.getCurrency(), p.getAmount(), p.getAddress(), p.getCommission()); } throw new IllegalStateException("Don't know how to withdraw: " + params); } From 738316a524c3e0ebd5c1699a0381cb4bf3584f8d Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Thu, 23 Mar 2023 09:59:16 +0100 Subject: [PATCH 002/159] [general] Change the scope of lombok to provided --- xchange-bibox/pom.xml | 1 + xchange-binance/pom.xml | 1 + xchange-bitbay/pom.xml | 1 + xchange-bitcoinde/pom.xml | 1 + xchange-bitfinex/pom.xml | 1 + xchange-bitmex/pom.xml | 1 + xchange-bittrex/pom.xml | 1 + xchange-blockchain/pom.xml | 1 + xchange-coinbase/pom.xml | 1 + xchange-coinbasepro/pom.xml | 1 + xchange-coincheck/pom.xml | 2 +- xchange-core/pom.xml | 1 + xchange-cryptowatch/pom.xml | 1 + xchange-deribit/pom.xml | 1 + xchange-enigma/pom.xml | 2 +- xchange-examples/pom.xml | 7 +++++++ xchange-ftx/pom.xml | 1 + xchange-gemini/pom.xml | 1 + xchange-kraken/pom.xml | 1 + xchange-krakenfutures/pom.xml | 1 + xchange-kucoin/pom.xml | 1 + xchange-okcoin/pom.xml | 1 + xchange-simulated/pom.xml | 1 + xchange-stream-binance/pom.xml | 1 + xchange-stream-coincheck/pom.xml | 2 +- xchange-stream-dydx/pom.xml | 2 +- xchange-stream-gateio/pom.xml | 2 +- xchange-stream-krakenfutures/pom.xml | 1 + xchange-stream-okcoin/pom.xml | 1 - xchange-stream-okex/pom.xml | 1 - xchange-tradeogre/pom.xml | 2 +- 31 files changed, 35 insertions(+), 8 deletions(-) diff --git a/xchange-bibox/pom.xml b/xchange-bibox/pom.xml index c6e44d8f323..e4f528da5d0 100644 --- a/xchange-bibox/pom.xml +++ b/xchange-bibox/pom.xml @@ -32,6 +32,7 @@ org.projectlombok lombok + provided diff --git a/xchange-binance/pom.xml b/xchange-binance/pom.xml index 441c7254887..62fc1af590f 100644 --- a/xchange-binance/pom.xml +++ b/xchange-binance/pom.xml @@ -30,6 +30,7 @@ org.projectlombok lombok + provided com.github.tomakehurst diff --git a/xchange-bitbay/pom.xml b/xchange-bitbay/pom.xml index 07281f77f8f..1271566e1ce 100644 --- a/xchange-bitbay/pom.xml +++ b/xchange-bitbay/pom.xml @@ -32,6 +32,7 @@ org.projectlombok lombok + provided diff --git a/xchange-bitcoinde/pom.xml b/xchange-bitcoinde/pom.xml index ea10e065958..cf09b411074 100644 --- a/xchange-bitcoinde/pom.xml +++ b/xchange-bitcoinde/pom.xml @@ -33,6 +33,7 @@ org.projectlombok lombok + provided diff --git a/xchange-bitfinex/pom.xml b/xchange-bitfinex/pom.xml index a80d0449f6e..fb5d5e23321 100644 --- a/xchange-bitfinex/pom.xml +++ b/xchange-bitfinex/pom.xml @@ -32,6 +32,7 @@ org.projectlombok lombok + provided diff --git a/xchange-bitmex/pom.xml b/xchange-bitmex/pom.xml index edd42eb7ef3..207bbadf397 100755 --- a/xchange-bitmex/pom.xml +++ b/xchange-bitmex/pom.xml @@ -38,6 +38,7 @@ org.projectlombok lombok + provided diff --git a/xchange-bittrex/pom.xml b/xchange-bittrex/pom.xml index 6540d86bb36..b8e02456f8d 100644 --- a/xchange-bittrex/pom.xml +++ b/xchange-bittrex/pom.xml @@ -37,6 +37,7 @@ org.projectlombok lombok + provided diff --git a/xchange-blockchain/pom.xml b/xchange-blockchain/pom.xml index 38bcbb09134..e2b92521dae 100644 --- a/xchange-blockchain/pom.xml +++ b/xchange-blockchain/pom.xml @@ -32,6 +32,7 @@ org.projectlombok lombok + provided com.github.tomakehurst diff --git a/xchange-coinbase/pom.xml b/xchange-coinbase/pom.xml index 54a995b0761..ec1f796fcd7 100644 --- a/xchange-coinbase/pom.xml +++ b/xchange-coinbase/pom.xml @@ -32,6 +32,7 @@ org.projectlombok lombok + provided diff --git a/xchange-coinbasepro/pom.xml b/xchange-coinbasepro/pom.xml index d8029fdc581..c6c283cc876 100644 --- a/xchange-coinbasepro/pom.xml +++ b/xchange-coinbasepro/pom.xml @@ -38,6 +38,7 @@ org.projectlombok lombok + provided diff --git a/xchange-coincheck/pom.xml b/xchange-coincheck/pom.xml index 07b315a8765..aeda06e3c7c 100644 --- a/xchange-coincheck/pom.xml +++ b/xchange-coincheck/pom.xml @@ -32,7 +32,7 @@ org.projectlombok lombok - 1.18.22 + provided diff --git a/xchange-core/pom.xml b/xchange-core/pom.xml index 5cc47800b83..53ff6850604 100644 --- a/xchange-core/pom.xml +++ b/xchange-core/pom.xml @@ -54,6 +54,7 @@ org.projectlombok lombok + provided diff --git a/xchange-cryptowatch/pom.xml b/xchange-cryptowatch/pom.xml index e0dba36114f..aad07671eaf 100644 --- a/xchange-cryptowatch/pom.xml +++ b/xchange-cryptowatch/pom.xml @@ -33,6 +33,7 @@ org.projectlombok lombok + provided diff --git a/xchange-deribit/pom.xml b/xchange-deribit/pom.xml index c675f113867..4c51e404e36 100644 --- a/xchange-deribit/pom.xml +++ b/xchange-deribit/pom.xml @@ -33,6 +33,7 @@ org.projectlombok lombok + provided diff --git a/xchange-enigma/pom.xml b/xchange-enigma/pom.xml index 536a30120cb..e710b70c073 100644 --- a/xchange-enigma/pom.xml +++ b/xchange-enigma/pom.xml @@ -31,7 +31,7 @@ org.projectlombok lombok - compile + provided \ No newline at end of file diff --git a/xchange-examples/pom.xml b/xchange-examples/pom.xml index b83acfbc78a..1b99fed7c89 100755 --- a/xchange-examples/pom.xml +++ b/xchange-examples/pom.xml @@ -362,6 +362,13 @@ xchange-deribit ${project.version} + + + org.projectlombok + lombok + provided + + diff --git a/xchange-ftx/pom.xml b/xchange-ftx/pom.xml index d84287ad366..6b8e5219bf5 100644 --- a/xchange-ftx/pom.xml +++ b/xchange-ftx/pom.xml @@ -27,6 +27,7 @@ org.projectlombok lombok + provided diff --git a/xchange-gemini/pom.xml b/xchange-gemini/pom.xml index c49ea50a21d..9991b4951fe 100644 --- a/xchange-gemini/pom.xml +++ b/xchange-gemini/pom.xml @@ -36,6 +36,7 @@ org.projectlombok lombok + provided diff --git a/xchange-kraken/pom.xml b/xchange-kraken/pom.xml index e66fb61e2de..7bcf6e8ef66 100644 --- a/xchange-kraken/pom.xml +++ b/xchange-kraken/pom.xml @@ -32,6 +32,7 @@ org.projectlombok lombok + provided com.github.tomakehurst diff --git a/xchange-krakenfutures/pom.xml b/xchange-krakenfutures/pom.xml index 4f00d0f9aff..5fed94a9c12 100644 --- a/xchange-krakenfutures/pom.xml +++ b/xchange-krakenfutures/pom.xml @@ -32,6 +32,7 @@ org.projectlombok lombok + provided diff --git a/xchange-kucoin/pom.xml b/xchange-kucoin/pom.xml index 253d0a7c20a..68e60ca0fc4 100644 --- a/xchange-kucoin/pom.xml +++ b/xchange-kucoin/pom.xml @@ -31,6 +31,7 @@ org.projectlombok lombok + provided com.google.guava diff --git a/xchange-okcoin/pom.xml b/xchange-okcoin/pom.xml index d3ee6f79348..fd69ee26885 100644 --- a/xchange-okcoin/pom.xml +++ b/xchange-okcoin/pom.xml @@ -31,6 +31,7 @@ org.projectlombok lombok + provided diff --git a/xchange-simulated/pom.xml b/xchange-simulated/pom.xml index 81a98408ef2..8537110e06f 100644 --- a/xchange-simulated/pom.xml +++ b/xchange-simulated/pom.xml @@ -35,6 +35,7 @@ org.projectlombok lombok + provided org.mockito diff --git a/xchange-stream-binance/pom.xml b/xchange-stream-binance/pom.xml index 68b04047490..b207654d107 100644 --- a/xchange-stream-binance/pom.xml +++ b/xchange-stream-binance/pom.xml @@ -31,6 +31,7 @@ org.projectlombok lombok + provided com.google.guava diff --git a/xchange-stream-coincheck/pom.xml b/xchange-stream-coincheck/pom.xml index 0fe36e10b89..20c84345a53 100644 --- a/xchange-stream-coincheck/pom.xml +++ b/xchange-stream-coincheck/pom.xml @@ -35,7 +35,7 @@ org.projectlombok lombok - 1.18.22 + provided diff --git a/xchange-stream-dydx/pom.xml b/xchange-stream-dydx/pom.xml index 2293b980f6e..98272a5352c 100644 --- a/xchange-stream-dydx/pom.xml +++ b/xchange-stream-dydx/pom.xml @@ -24,7 +24,7 @@ org.projectlombok lombok - ${version.lombok} + provided diff --git a/xchange-stream-gateio/pom.xml b/xchange-stream-gateio/pom.xml index a3eab646462..19d0f31e0a7 100644 --- a/xchange-stream-gateio/pom.xml +++ b/xchange-stream-gateio/pom.xml @@ -24,7 +24,7 @@ org.projectlombok lombok - ${version.lombok} + provided \ No newline at end of file diff --git a/xchange-stream-krakenfutures/pom.xml b/xchange-stream-krakenfutures/pom.xml index a57cf1f7e78..23e8622a430 100644 --- a/xchange-stream-krakenfutures/pom.xml +++ b/xchange-stream-krakenfutures/pom.xml @@ -27,6 +27,7 @@ org.projectlombok lombok + provided diff --git a/xchange-stream-okcoin/pom.xml b/xchange-stream-okcoin/pom.xml index ff8ed4ff017..857018aed92 100644 --- a/xchange-stream-okcoin/pom.xml +++ b/xchange-stream-okcoin/pom.xml @@ -42,7 +42,6 @@ org.projectlombok lombok - ${version.lombok} provided diff --git a/xchange-stream-okex/pom.xml b/xchange-stream-okex/pom.xml index 9b7ec6534ce..42ed14106a7 100644 --- a/xchange-stream-okex/pom.xml +++ b/xchange-stream-okex/pom.xml @@ -37,7 +37,6 @@ org.projectlombok lombok - ${version.lombok} provided diff --git a/xchange-tradeogre/pom.xml b/xchange-tradeogre/pom.xml index 2d7fe0448e2..dd85c90e28f 100644 --- a/xchange-tradeogre/pom.xml +++ b/xchange-tradeogre/pom.xml @@ -32,7 +32,7 @@ org.projectlombok lombok - compile + provided From bbe29e758d9d63fe1d22abd0343fed9972ed7b8d Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Fri, 24 Mar 2023 13:05:42 +0100 Subject: [PATCH 003/159] [general] Code cleanup --- .../service/BTCMarketsAccountService.java | 2 +- xchange-core/lombok.config | 1 + .../xchange/dto/account/AddressWithTag.java | 50 ++++--------------- xchange-kucoin/lombok.config | 1 + .../dto/request/ApplyWithdrawApiRequest.java | 26 ++++++---- 5 files changed, 27 insertions(+), 53 deletions(-) create mode 100644 xchange-core/lombok.config create mode 100644 xchange-kucoin/lombok.config diff --git a/xchange-btcmarkets/src/main/java/org/knowm/xchange/btcmarkets/service/BTCMarketsAccountService.java b/xchange-btcmarkets/src/main/java/org/knowm/xchange/btcmarkets/service/BTCMarketsAccountService.java index 75f9bb5f9fb..a9859d67407 100644 --- a/xchange-btcmarkets/src/main/java/org/knowm/xchange/btcmarkets/service/BTCMarketsAccountService.java +++ b/xchange-btcmarkets/src/main/java/org/knowm/xchange/btcmarkets/service/BTCMarketsAccountService.java @@ -41,7 +41,7 @@ public String withdrawFunds(WithdrawFundsParams params) throws IOException { DefaultWithdrawFundsParams defaultWithdrawFundsParams = (DefaultWithdrawFundsParams) params; String address = defaultWithdrawFundsParams.getAddress(); if (params instanceof RippleWithdrawFundsParams) { - address = address + "?dt=" + ((RippleWithdrawFundsParams) params).tag; + address = address + "?dt=" + ((RippleWithdrawFundsParams) params).getTag(); } return withdrawCrypto( address, diff --git a/xchange-core/lombok.config b/xchange-core/lombok.config new file mode 100644 index 00000000000..e572d96336a --- /dev/null +++ b/xchange-core/lombok.config @@ -0,0 +1 @@ +lombok.equalsAndHashCode.callSuper = call \ No newline at end of file diff --git a/xchange-core/src/main/java/org/knowm/xchange/dto/account/AddressWithTag.java b/xchange-core/src/main/java/org/knowm/xchange/dto/account/AddressWithTag.java index 8ec1a4afb3c..a04f831987a 100644 --- a/xchange-core/src/main/java/org/knowm/xchange/dto/account/AddressWithTag.java +++ b/xchange-core/src/main/java/org/knowm/xchange/dto/account/AddressWithTag.java @@ -1,48 +1,16 @@ package org.knowm.xchange.dto.account; -import java.io.Serializable; -import java.util.Objects; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Value; -public final class AddressWithTag implements Serializable { +@Value +@Builder +@AllArgsConstructor +public class AddressWithTag { - private final String address; - private final String addressTag; + String address; - public AddressWithTag(String address, String addressTag) { - this.address = address; - this.addressTag = addressTag; - } + String addressTag; - public String getAddress() { - return address; - } - - public String getAddressTag() { - return addressTag; - } - - @Override - public String toString() { - return "AddressWithTag{" - + "address='" - + address - + '\'' - + ", addressTag='" - + addressTag - + '\'' - + '}'; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - AddressWithTag that = (AddressWithTag) o; - return Objects.equals(address, that.address) && Objects.equals(addressTag, that.addressTag); - } - - @Override - public int hashCode() { - return Objects.hash(address, addressTag); - } } diff --git a/xchange-kucoin/lombok.config b/xchange-kucoin/lombok.config new file mode 100644 index 00000000000..e572d96336a --- /dev/null +++ b/xchange-kucoin/lombok.config @@ -0,0 +1 @@ +lombok.equalsAndHashCode.callSuper = call \ No newline at end of file diff --git a/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/dto/request/ApplyWithdrawApiRequest.java b/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/dto/request/ApplyWithdrawApiRequest.java index 8f14826b1e3..21d68ff7c46 100644 --- a/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/dto/request/ApplyWithdrawApiRequest.java +++ b/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/dto/request/ApplyWithdrawApiRequest.java @@ -4,38 +4,42 @@ import com.fasterxml.jackson.annotation.JsonInclude.Include; import java.math.BigDecimal; import lombok.Builder; -import lombok.Getter; -import lombok.ToString; +import lombok.Value; -@Getter -@ToString +@Value @Builder @JsonInclude(value = Include.NON_EMPTY, content = Include.NON_NULL) public class ApplyWithdrawApiRequest { /** Currency */ - private final String currency; + String currency; + /** Withdrawal address */ - private final String address; + String address; + /** * Withdrawal amount, a positive number which is a multiple of the amount precision (fees * excluded) */ - private final BigDecimal amount; + BigDecimal amount; + /** * [optional] The note that is left on the withdrawal address. When you withdraw from KuCoin to * other platforms, you need to fill in memo(tag). If you don't fill in memo(tag), your withdrawal * may not be available. */ - private final String memo; + String memo; + /** [optional] Internal withdrawal or not. Default setup: false */ - @Builder.Default private final boolean isInner = false; + boolean isInner; + /** [optional] Remark */ - private final String remark; + String remark; + /** * [optional] The chain name of currency, e.g. The available value for USDT are OMNI, ERC20, * TRC20, default is OMNI. This only apply for multi-chain currency, and there is no need for * single chain currency. */ - private final String chain; + String chain; } From ccf8467d7830a5bc2ba0ed711b8ff93cd5fcd629 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Thu, 11 May 2023 16:08:29 +0200 Subject: [PATCH 004/159] Replace constructors in DefaultWithdrawFundsParams with according builders --- .../service/BinanceAccountService.java | 28 +++++- .../bitbay/service/BitbayAccountService.java | 6 +- .../service/BitstampAccountService.java | 15 ++- .../service/BTCMarketsAccountService.java | 4 +- .../service/BTCMarketsAccountServiceTest.java | 9 +- .../service/CoinbaseProAccountService.java | 14 ++- .../coingi/service/CoingiAccountService.java | 12 ++- .../service/account/AccountService.java | 15 ++- .../params/DefaultWithdrawFundsParams.java | 95 +++---------------- .../params/MoneroWithdrawFundsParams.java | 41 ++------ .../params/RippleWithdrawFundsParams.java | 40 +------- .../v2/service/HitbtcAccountService.java | 7 +- .../service/LivecoinAccountService.java | 7 +- .../okcoin/service/OkCoinAccountService.java | 2 +- .../okcoin/v3/service/OkexAccountService.java | 2 +- .../service/PoloniexAccountService.java | 7 +- .../yobit/service/YoBitAccountService.java | 7 +- 17 files changed, 132 insertions(+), 179 deletions(-) diff --git a/xchange-binance/src/main/java/org/knowm/xchange/binance/service/BinanceAccountService.java b/xchange-binance/src/main/java/org/knowm/xchange/binance/service/BinanceAccountService.java index f73ee801f5f..a687461f789 100644 --- a/xchange-binance/src/main/java/org/knowm/xchange/binance/service/BinanceAccountService.java +++ b/xchange-binance/src/main/java/org/knowm/xchange/binance/service/BinanceAccountService.java @@ -4,21 +4,33 @@ import java.math.BigDecimal; import java.math.RoundingMode; import java.time.Instant; -import java.util.*; - +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import org.knowm.xchange.binance.BinanceAdapters; import org.knowm.xchange.binance.BinanceErrorAdapter; import org.knowm.xchange.binance.BinanceExchange; import org.knowm.xchange.binance.dto.BinanceException; -import org.knowm.xchange.binance.dto.account.*; +import org.knowm.xchange.binance.dto.account.AssetDetail; +import org.knowm.xchange.binance.dto.account.BinanceAccountInformation; +import org.knowm.xchange.binance.dto.account.BinanceFundingHistoryParams; import org.knowm.xchange.binance.dto.account.BinanceMasterAccountTransferHistoryParams; import org.knowm.xchange.binance.dto.account.BinanceSubAccountTransferHistoryParams; +import org.knowm.xchange.binance.dto.account.DepositAddress; +import org.knowm.xchange.binance.dto.account.WithdrawResponse; import org.knowm.xchange.binance.dto.account.futures.BinanceFutureAccountInformation; import org.knowm.xchange.client.ResilienceRegistries; import org.knowm.xchange.currency.Currency; -import org.knowm.xchange.dto.account.*; +import org.knowm.xchange.dto.account.AccountInfo; +import org.knowm.xchange.dto.account.AddressWithTag; +import org.knowm.xchange.dto.account.Fee; +import org.knowm.xchange.dto.account.FundingRecord; import org.knowm.xchange.dto.account.FundingRecord.Status; import org.knowm.xchange.dto.account.FundingRecord.Type; +import org.knowm.xchange.dto.account.OpenPosition; +import org.knowm.xchange.dto.account.Wallet; import org.knowm.xchange.instrument.Instrument; import org.knowm.xchange.service.account.AccountService; import org.knowm.xchange.service.trade.params.DefaultWithdrawFundsParams; @@ -155,7 +167,13 @@ public String withdrawFunds(Currency currency, BigDecimal amount, String address @Override public String withdrawFunds(Currency currency, BigDecimal amount, AddressWithTag address) throws IOException { - return withdrawFunds(new DefaultWithdrawFundsParams(address, currency, amount)); + return withdrawFunds(DefaultWithdrawFundsParams.builder() + .address(address.getAddress()) + .address(address.getAddressTag()) + .currency(currency) + .amount(amount) + .build() + ); } @Override diff --git a/xchange-bitbay/src/main/java/org/knowm/xchange/bitbay/service/BitbayAccountService.java b/xchange-bitbay/src/main/java/org/knowm/xchange/bitbay/service/BitbayAccountService.java index cd535346975..349f13f45be 100644 --- a/xchange-bitbay/src/main/java/org/knowm/xchange/bitbay/service/BitbayAccountService.java +++ b/xchange-bitbay/src/main/java/org/knowm/xchange/bitbay/service/BitbayAccountService.java @@ -33,7 +33,11 @@ public AccountInfo getAccountInfo() throws IOException { @Override public String withdrawFunds(Currency currency, BigDecimal amount, String address) throws IOException { - return withdrawFunds(new DefaultWithdrawFundsParams(address, currency, amount)); + return withdrawFunds(DefaultWithdrawFundsParams.builder() + .address(address) + .currency(currency) + .amount(amount) + .build()); } @Override diff --git a/xchange-bitstamp/src/main/java/org/knowm/xchange/bitstamp/service/BitstampAccountService.java b/xchange-bitstamp/src/main/java/org/knowm/xchange/bitstamp/service/BitstampAccountService.java index ab1284f94e4..6e8aee40d57 100644 --- a/xchange-bitstamp/src/main/java/org/knowm/xchange/bitstamp/service/BitstampAccountService.java +++ b/xchange-bitstamp/src/main/java/org/knowm/xchange/bitstamp/service/BitstampAccountService.java @@ -51,13 +51,22 @@ public AccountInfo getAccountInfo() throws IOException { @Override public String withdrawFunds(Currency currency, BigDecimal amount, String address) throws IOException { - return withdrawFunds(new DefaultWithdrawFundsParams(address, currency, amount)); + return withdrawFunds(DefaultWithdrawFundsParams.builder() + .address(address) + .currency(currency) + .amount(amount) + .build()); } public String withdrawFunds( Currency currency, BigDecimal amount, String address, String addressTag) throws IOException { - return withdrawFunds( - new DefaultWithdrawFundsParams(address, addressTag, currency, amount, null)); + return withdrawFunds(DefaultWithdrawFundsParams.builder() + .address(address) + .addressTag(addressTag) + .currency(currency) + .amount(amount) + .build() + ); } @Override diff --git a/xchange-btcmarkets/src/main/java/org/knowm/xchange/btcmarkets/service/BTCMarketsAccountService.java b/xchange-btcmarkets/src/main/java/org/knowm/xchange/btcmarkets/service/BTCMarketsAccountService.java index f5b34fc22ac..a9859d67407 100644 --- a/xchange-btcmarkets/src/main/java/org/knowm/xchange/btcmarkets/service/BTCMarketsAccountService.java +++ b/xchange-btcmarkets/src/main/java/org/knowm/xchange/btcmarkets/service/BTCMarketsAccountService.java @@ -39,9 +39,9 @@ public AccountInfo getAccountInfo() throws IOException { public String withdrawFunds(WithdrawFundsParams params) throws IOException { if (params instanceof DefaultWithdrawFundsParams) { DefaultWithdrawFundsParams defaultWithdrawFundsParams = (DefaultWithdrawFundsParams) params; - String address = defaultWithdrawFundsParams.address; + String address = defaultWithdrawFundsParams.getAddress(); if (params instanceof RippleWithdrawFundsParams) { - address = address + "?dt=" + ((RippleWithdrawFundsParams) params).tag; + address = address + "?dt=" + ((RippleWithdrawFundsParams) params).getTag(); } return withdrawCrypto( address, diff --git a/xchange-btcmarkets/src/test/java/org/knowm/xchange/btcmarkets/service/BTCMarketsAccountServiceTest.java b/xchange-btcmarkets/src/test/java/org/knowm/xchange/btcmarkets/service/BTCMarketsAccountServiceTest.java index f2268b06200..43124784b8a 100644 --- a/xchange-btcmarkets/src/test/java/org/knowm/xchange/btcmarkets/service/BTCMarketsAccountServiceTest.java +++ b/xchange-btcmarkets/src/test/java/org/knowm/xchange/btcmarkets/service/BTCMarketsAccountServiceTest.java @@ -88,8 +88,13 @@ public void withdrawFundsShouldAppendRippleTag() throws IOException { .thenReturn(response); // when - RippleWithdrawFundsParams params = - new RippleWithdrawFundsParams("any address", Currency.BTC, BigDecimal.TEN, "12345"); + RippleWithdrawFundsParams params = RippleWithdrawFundsParams.builder() + .address("any address") + .currency(Currency.BTC) + .amount(BigDecimal.TEN) + .tag("12345") + .build(); + String result = btcMarketsAccountService.withdrawFunds(params); assertThat(captor.getValue().address).isEqualTo("any address?dt=12345"); assertThat(result).isNotNull(); diff --git a/xchange-coinbasepro/src/main/java/org/knowm/xchange/coinbasepro/service/CoinbaseProAccountService.java b/xchange-coinbasepro/src/main/java/org/knowm/xchange/coinbasepro/service/CoinbaseProAccountService.java index decd75831bd..540d49527d9 100644 --- a/xchange-coinbasepro/src/main/java/org/knowm/xchange/coinbasepro/service/CoinbaseProAccountService.java +++ b/xchange-coinbasepro/src/main/java/org/knowm/xchange/coinbasepro/service/CoinbaseProAccountService.java @@ -60,13 +60,23 @@ public Map getDynamicTradingFeesByInstrument() throws IOExcepti @Override public String withdrawFunds(Currency currency, BigDecimal amount, String address) throws IOException { - return withdrawFunds(new DefaultWithdrawFundsParams(address, currency, amount)); + return withdrawFunds(DefaultWithdrawFundsParams.builder() + .address(address) + .currency(currency) + .amount(amount) + .build()); } @Override public String withdrawFunds(Currency currency, BigDecimal amount, AddressWithTag address) throws IOException { - return withdrawFunds(new DefaultWithdrawFundsParams(address, currency, amount)); + return withdrawFunds(DefaultWithdrawFundsParams.builder() + .address(address.getAddress()) + .address(address.getAddressTag()) + .currency(currency) + .amount(amount) + .build() + ); } @Override diff --git a/xchange-coingi/src/main/java/org/knowm/xchange/coingi/service/CoingiAccountService.java b/xchange-coingi/src/main/java/org/knowm/xchange/coingi/service/CoingiAccountService.java index cf12d790e75..303d89350eb 100644 --- a/xchange-coingi/src/main/java/org/knowm/xchange/coingi/service/CoingiAccountService.java +++ b/xchange-coingi/src/main/java/org/knowm/xchange/coingi/service/CoingiAccountService.java @@ -42,7 +42,11 @@ public AccountInfo getAccountInfo() throws IOException { public String withdrawFunds(Currency currency, BigDecimal amount, String address) throws IOException { try { - return withdrawFunds(new DefaultWithdrawFundsParams(address, currency, amount)); + return withdrawFunds(DefaultWithdrawFundsParams.builder() + .address(address) + .currency(currency) + .amount(amount) + .build()); } catch (CoingiException e) { throw CoingiErrorAdapter.adapt(e); } @@ -56,9 +60,9 @@ public String withdrawFunds(WithdrawFundsParams p) DefaultWithdrawFundsParams params = (DefaultWithdrawFundsParams) p; CoingiWithdrawalRequest request = new CoingiWithdrawalRequest() - .setAddress(params.address) - .setAmount(params.amount) - .setCurrency(params.currency.getCurrencyCode().toUpperCase()); + .setAddress(params.getAddress()) + .setAmount(params.getAmount()) + .setCurrency(params.getCurrency().getCurrencyCode().toUpperCase()); return withdraw(request).toString(); } diff --git a/xchange-core/src/main/java/org/knowm/xchange/service/account/AccountService.java b/xchange-core/src/main/java/org/knowm/xchange/service/account/AccountService.java index b10c6ef0ab7..9475e3a29d3 100644 --- a/xchange-core/src/main/java/org/knowm/xchange/service/account/AccountService.java +++ b/xchange-core/src/main/java/org/knowm/xchange/service/account/AccountService.java @@ -65,7 +65,12 @@ default AccountInfo getAccountInfo() throws IOException { */ default String withdrawFunds(Currency currency, BigDecimal amount, String address) throws IOException { - return withdrawFunds(new DefaultWithdrawFundsParams(address, currency, amount)); + return withdrawFunds(DefaultWithdrawFundsParams.builder() + .address(address) + .currency(currency) + .amount(amount) + .build() + ); } /** @@ -85,7 +90,13 @@ default String withdrawFunds(Currency currency, BigDecimal amount, String addres */ default String withdrawFunds(Currency currency, BigDecimal amount, AddressWithTag address) throws IOException { - return withdrawFunds(new DefaultWithdrawFundsParams(address, currency, amount)); + return withdrawFunds(DefaultWithdrawFundsParams.builder() + .address(address.getAddress()) + .address(address.getAddressTag()) + .currency(currency) + .amount(amount) + .build() + ); } /** diff --git a/xchange-core/src/main/java/org/knowm/xchange/service/trade/params/DefaultWithdrawFundsParams.java b/xchange-core/src/main/java/org/knowm/xchange/service/trade/params/DefaultWithdrawFundsParams.java index d1f8329e00e..b510815455a 100644 --- a/xchange-core/src/main/java/org/knowm/xchange/service/trade/params/DefaultWithdrawFundsParams.java +++ b/xchange-core/src/main/java/org/knowm/xchange/service/trade/params/DefaultWithdrawFundsParams.java @@ -1,95 +1,26 @@ package org.knowm.xchange.service.trade.params; import java.math.BigDecimal; -import javax.annotation.Nullable; +import lombok.AllArgsConstructor; +import lombok.Value; +import lombok.experimental.NonFinal; +import lombok.experimental.SuperBuilder; import org.knowm.xchange.currency.Currency; -import org.knowm.xchange.dto.account.AddressWithTag; +@Value +@NonFinal +@SuperBuilder +@AllArgsConstructor public class DefaultWithdrawFundsParams implements WithdrawFundsParams { - public final String address; - private final String addressTag; + String address; - public final Currency currency; + String addressTag; - public final BigDecimal amount; + Currency currency; - @Nullable public final BigDecimal commission; + BigDecimal amount; - public DefaultWithdrawFundsParams(String address, Currency currency, BigDecimal amount) { - this(address, currency, amount, null); - } + BigDecimal commission; - public DefaultWithdrawFundsParams(AddressWithTag address, Currency currency, BigDecimal amount) { - this(address, currency, amount, null); - } - - public DefaultWithdrawFundsParams( - String address, Currency currency, BigDecimal amount, BigDecimal commission) { - this.address = address; - this.addressTag = null; - this.currency = currency; - this.amount = amount; - this.commission = commission; - } - - public DefaultWithdrawFundsParams( - AddressWithTag address, Currency currency, BigDecimal amount, BigDecimal commission) { - this.address = address.getAddress(); - this.addressTag = address.getAddressTag(); - this.currency = currency; - this.amount = amount; - this.commission = commission; - } - - public DefaultWithdrawFundsParams( - String address, - String addressTag, - Currency currency, - BigDecimal amount, - BigDecimal commission) { - this.address = address; - this.addressTag = addressTag; - this.currency = currency; - this.amount = amount; - this.commission = commission; - } - - public String getAddress() { - return address; - } - - public String getAddressTag() { - return addressTag; - } - - public Currency getCurrency() { - return currency; - } - - public BigDecimal getAmount() { - return amount; - } - - @Nullable - public BigDecimal getCommission() { - return commission; - } - - @Override - public String toString() { - return "DefaultWithdrawFundsParams{" - + "address='" - + getAddress() - + ", addressTag=" - + getAddressTag() - + '\'' - + ", currency=" - + getCurrency() - + ", amount=" - + getAmount() - + ", commission=" - + getCommission() - + '}'; - } } diff --git a/xchange-core/src/main/java/org/knowm/xchange/service/trade/params/MoneroWithdrawFundsParams.java b/xchange-core/src/main/java/org/knowm/xchange/service/trade/params/MoneroWithdrawFundsParams.java index 9406fad8c69..fa6db1cb99d 100644 --- a/xchange-core/src/main/java/org/knowm/xchange/service/trade/params/MoneroWithdrawFundsParams.java +++ b/xchange-core/src/main/java/org/knowm/xchange/service/trade/params/MoneroWithdrawFundsParams.java @@ -1,42 +1,13 @@ package org.knowm.xchange.service.trade.params; -import java.math.BigDecimal; -import javax.annotation.Nullable; -import org.knowm.xchange.currency.Currency; +import lombok.Value; +import lombok.experimental.SuperBuilder; -public class MoneroWithdrawFundsParams extends DefaultWithdrawFundsParams { - @Nullable public final String paymentId; // optional - - public MoneroWithdrawFundsParams(String address, Currency currency, BigDecimal amount) { - this(address, currency, amount, null); - } - public MoneroWithdrawFundsParams( - String address, Currency currency, BigDecimal amount, String paymentId) { - super(address, currency, amount); - this.paymentId = paymentId; - } +@Value +@SuperBuilder +public class MoneroWithdrawFundsParams extends DefaultWithdrawFundsParams { - @Override - public String toString() { - return "MoneroWithdrawFundsParams{" - + "address='" - + getAddress() - + '\'' - + ", paymentId='" - + getPaymentId() - + '\'' - + ", currency=" - + getCurrency() - + ", amount=" - + getAmount() - + ", commission=" - + getCommission() - + '}'; - } + String paymentId; - @Nullable - public String getPaymentId() { - return paymentId; - } } diff --git a/xchange-core/src/main/java/org/knowm/xchange/service/trade/params/RippleWithdrawFundsParams.java b/xchange-core/src/main/java/org/knowm/xchange/service/trade/params/RippleWithdrawFundsParams.java index dd1988ba9ca..14f34b47c42 100644 --- a/xchange-core/src/main/java/org/knowm/xchange/service/trade/params/RippleWithdrawFundsParams.java +++ b/xchange-core/src/main/java/org/knowm/xchange/service/trade/params/RippleWithdrawFundsParams.java @@ -1,42 +1,12 @@ package org.knowm.xchange.service.trade.params; -import java.math.BigDecimal; -import javax.annotation.Nullable; -import org.knowm.xchange.currency.Currency; +import lombok.Value; +import lombok.experimental.SuperBuilder; +@Value +@SuperBuilder public class RippleWithdrawFundsParams extends DefaultWithdrawFundsParams { - @Nullable public final String tag; // optional - public RippleWithdrawFundsParams(String address, Currency currency, BigDecimal amount) { - this(address, currency, amount, null); - } + String tag; // optional - public RippleWithdrawFundsParams( - String address, Currency currency, BigDecimal amount, String tag) { - super(address, tag, currency, amount, null); - this.tag = tag; - } - - @Override - public String toString() { - return "RippleWithdrawFundsParams{" - + "address='" - + getAddress() - + '\'' - + ", tag='" - + getTag() - + '\'' - + ", currency=" - + getCurrency() - + ", amount=" - + getAmount() - + ", commission=" - + getCommission() - + '}'; - } - - @Nullable - public String getTag() { - return tag; - } } diff --git a/xchange-hitbtc/src/main/java/org/knowm/xchange/hitbtc/v2/service/HitbtcAccountService.java b/xchange-hitbtc/src/main/java/org/knowm/xchange/hitbtc/v2/service/HitbtcAccountService.java index a5e0820e8ca..552707c3022 100644 --- a/xchange-hitbtc/src/main/java/org/knowm/xchange/hitbtc/v2/service/HitbtcAccountService.java +++ b/xchange-hitbtc/src/main/java/org/knowm/xchange/hitbtc/v2/service/HitbtcAccountService.java @@ -37,7 +37,12 @@ public AccountInfo getAccountInfo() throws IOException { @Override public String withdrawFunds(Currency currency, BigDecimal amount, String address) throws IOException { - return withdrawFunds(new DefaultWithdrawFundsParams(address, currency, amount)); + return withdrawFunds(DefaultWithdrawFundsParams.builder() + .address(address) + .currency(currency) + .amount(amount) + .build() + ); } @Override diff --git a/xchange-livecoin/src/main/java/org/knowm/xchange/livecoin/service/LivecoinAccountService.java b/xchange-livecoin/src/main/java/org/knowm/xchange/livecoin/service/LivecoinAccountService.java index 87e45478bb6..15611c21729 100644 --- a/xchange-livecoin/src/main/java/org/knowm/xchange/livecoin/service/LivecoinAccountService.java +++ b/xchange-livecoin/src/main/java/org/knowm/xchange/livecoin/service/LivecoinAccountService.java @@ -41,7 +41,12 @@ public AccountInfo getAccountInfo() throws IOException { @Override public String withdrawFunds(Currency currency, BigDecimal amount, String address) throws IOException { - return withdrawFunds(new DefaultWithdrawFundsParams(address, currency, amount)); + return withdrawFunds(DefaultWithdrawFundsParams.builder() + .address(address) + .currency(currency) + .amount(amount) + .build() + ); } @Override diff --git a/xchange-okcoin/src/main/java/org/knowm/xchange/okcoin/service/OkCoinAccountService.java b/xchange-okcoin/src/main/java/org/knowm/xchange/okcoin/service/OkCoinAccountService.java index c8dbfef314e..f47459e6bc3 100644 --- a/xchange-okcoin/src/main/java/org/knowm/xchange/okcoin/service/OkCoinAccountService.java +++ b/xchange-okcoin/src/main/java/org/knowm/xchange/okcoin/service/OkCoinAccountService.java @@ -80,7 +80,7 @@ public String withdrawFunds(Currency currency, BigDecimal amount, String address public String withdrawFunds(WithdrawFundsParams params) throws IOException { if (params instanceof DefaultWithdrawFundsParams) { DefaultWithdrawFundsParams defaultParams = (DefaultWithdrawFundsParams) params; - return withdrawFunds(defaultParams.currency, defaultParams.amount, defaultParams.address); + return withdrawFunds(defaultParams.getCurrency(), defaultParams.getAmount(), defaultParams.getAddress()); } throw new IllegalStateException("Don't know how to withdraw: " + params); } diff --git a/xchange-okcoin/src/main/java/org/knowm/xchange/okcoin/v3/service/OkexAccountService.java b/xchange-okcoin/src/main/java/org/knowm/xchange/okcoin/v3/service/OkexAccountService.java index 2e3fd709e9c..804fded23d9 100644 --- a/xchange-okcoin/src/main/java/org/knowm/xchange/okcoin/v3/service/OkexAccountService.java +++ b/xchange-okcoin/src/main/java/org/knowm/xchange/okcoin/v3/service/OkexAccountService.java @@ -68,7 +68,7 @@ public AccountInfo getAccountInfo() throws IOException { public String withdrawFunds(WithdrawFundsParams params) throws IOException { if (params instanceof DefaultWithdrawFundsParams) { DefaultWithdrawFundsParams p = (DefaultWithdrawFundsParams) params; - return withdrawFunds0(p.currency, p.amount, p.address, p.commission); + return withdrawFunds0(p.getCurrency(), p.getAmount(), p.getAddress(), p.getCommission()); } throw new IllegalStateException("Don't know how to withdraw: " + params); } diff --git a/xchange-poloniex/src/main/java/org/knowm/xchange/poloniex/service/PoloniexAccountService.java b/xchange-poloniex/src/main/java/org/knowm/xchange/poloniex/service/PoloniexAccountService.java index a4e7c8a8a9b..a00adb54423 100644 --- a/xchange-poloniex/src/main/java/org/knowm/xchange/poloniex/service/PoloniexAccountService.java +++ b/xchange-poloniex/src/main/java/org/knowm/xchange/poloniex/service/PoloniexAccountService.java @@ -56,7 +56,12 @@ public AccountInfo getAccountInfo() throws IOException { public String withdrawFunds(Currency currency, BigDecimal amount, String address) throws IOException { // does not support XRP withdrawals, use RippleWithdrawFundsParams instead - return withdrawFunds(new DefaultWithdrawFundsParams(address, currency, amount)); + return withdrawFunds(DefaultWithdrawFundsParams.builder() + .address(address) + .currency(currency) + .amount(amount) + .build() + ); } @Override diff --git a/xchange-yobit/src/main/java/org/knowm/xchange/yobit/service/YoBitAccountService.java b/xchange-yobit/src/main/java/org/knowm/xchange/yobit/service/YoBitAccountService.java index 952f7a32b02..b36b280bb69 100644 --- a/xchange-yobit/src/main/java/org/knowm/xchange/yobit/service/YoBitAccountService.java +++ b/xchange-yobit/src/main/java/org/knowm/xchange/yobit/service/YoBitAccountService.java @@ -27,7 +27,12 @@ public AccountInfo getAccountInfo() throws IOException { @Override public String withdrawFunds(Currency currency, BigDecimal amount, String address) throws IOException { - return withdrawFunds(new DefaultWithdrawFundsParams(address, currency, amount)); + return withdrawFunds(DefaultWithdrawFundsParams.builder() + .address(address) + .currency(currency) + .amount(amount) + .build() + ); } @Override From 5abd58c7e09698f5f768e6852aeafe9c9c65c9c0 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Thu, 11 May 2023 16:49:07 +0200 Subject: [PATCH 005/159] Change pom versions --- README.md | 2 +- pom.xml | 2 +- xchange-ascendex/pom.xml | 2 +- xchange-bankera/pom.xml | 2 +- xchange-bibox/pom.xml | 2 +- xchange-binance/pom.xml | 2 +- xchange-bitbay/pom.xml | 2 +- xchange-bitcoinaverage/pom.xml | 2 +- xchange-bitcoincharts/pom.xml | 2 +- xchange-bitcoincore/pom.xml | 2 +- xchange-bitcoinde/pom.xml | 2 +- xchange-bitcointoyou/pom.xml | 2 +- xchange-bitfinex/pom.xml | 2 +- xchange-bitflyer/pom.xml | 2 +- xchange-bithumb/pom.xml | 2 +- xchange-bitmex/pom.xml | 2 +- xchange-bitso/pom.xml | 2 +- xchange-bitstamp/pom.xml | 2 +- xchange-bittrex/pom.xml | 2 +- xchange-bity/pom.xml | 2 +- xchange-bitz/pom.xml | 2 +- xchange-bl3p/pom.xml | 2 +- xchange-bleutrade/pom.xml | 2 +- xchange-blockchain/pom.xml | 2 +- xchange-btcc/pom.xml | 2 +- xchange-btcmarkets/pom.xml | 2 +- xchange-btcturk/pom.xml | 2 +- xchange-bybit/pom.xml | 2 +- xchange-ccex/pom.xml | 2 +- xchange-cexio/pom.xml | 2 +- xchange-coinbase/pom.xml | 2 +- xchange-coinbasepro/pom.xml | 2 +- xchange-coincheck/pom.xml | 2 +- xchange-coindeal/pom.xml | 2 +- xchange-coindirect/pom.xml | 2 +- xchange-coinegg/pom.xml | 2 +- xchange-coinex/pom.xml | 2 +- xchange-coinfloor/pom.xml | 2 +- xchange-coingi/pom.xml | 2 +- xchange-coinjar/pom.xml | 2 +- xchange-coinmarketcap/pom.xml | 2 +- xchange-coinmate/pom.xml | 2 +- xchange-coinone/pom.xml | 2 +- xchange-core/pom.xml | 2 +- xchange-cryptowatch/pom.xml | 2 +- xchange-deribit/pom.xml | 2 +- xchange-dvchain/pom.xml | 2 +- xchange-dydx/pom.xml | 2 +- xchange-enigma/pom.xml | 2 +- xchange-examples/pom.xml | 2 +- xchange-exmo/pom.xml | 2 +- xchange-ftx/pom.xml | 2 +- xchange-gateio/pom.xml | 2 +- xchange-gemini/pom.xml | 2 +- xchange-globitex/pom.xml | 2 +- xchange-hitbtc/pom.xml | 2 +- xchange-huobi/pom.xml | 2 +- xchange-idex/pom.xml | 2 +- xchange-independentreserve/pom.xml | 2 +- xchange-itbit/pom.xml | 2 +- xchange-koineks/pom.xml | 2 +- xchange-koinim/pom.xml | 2 +- xchange-kraken/pom.xml | 2 +- xchange-krakenfutures/pom.xml | 2 +- xchange-kucoin/pom.xml | 2 +- xchange-kuna/pom.xml | 2 +- xchange-latoken/pom.xml | 2 +- xchange-lgo/pom.xml | 2 +- xchange-livecoin/pom.xml | 2 +- xchange-luno/pom.xml | 2 +- xchange-lykke/pom.xml | 2 +- xchange-mercadobitcoin/pom.xml | 2 +- xchange-mexc/pom.xml | 2 +- xchange-okcoin/pom.xml | 2 +- xchange-okex/pom.xml | 2 +- xchange-openexchangerates/pom.xml | 2 +- xchange-paribu/pom.xml | 2 +- xchange-paymium/pom.xml | 2 +- xchange-poloniex/pom.xml | 2 +- xchange-quoine/pom.xml | 2 +- xchange-ripple/pom.xml | 2 +- xchange-serum/pom.xml | 2 +- xchange-simulated/pom.xml | 2 +- xchange-stream-bankera/pom.xml | 2 +- xchange-stream-binance/pom.xml | 2 +- xchange-stream-bitfinex/pom.xml | 2 +- xchange-stream-bitflyer/pom.xml | 2 +- xchange-stream-bitmex/pom.xml | 2 +- xchange-stream-bitstamp/pom.xml | 2 +- xchange-stream-btcmarkets/pom.xml | 2 +- xchange-stream-cexio/pom.xml | 2 +- xchange-stream-coinbasepro/pom.xml | 2 +- xchange-stream-coincheck/pom.xml | 2 +- xchange-stream-coinjar/pom.xml | 2 +- xchange-stream-coinmate/pom.xml | 2 +- xchange-stream-core/pom.xml | 2 +- xchange-stream-dydx/pom.xml | 2 +- xchange-stream-ftx/pom.xml | 2 +- xchange-stream-gateio/pom.xml | 2 +- xchange-stream-gemini-v2/pom.xml | 2 +- xchange-stream-gemini/pom.xml | 2 +- xchange-stream-hitbtc/pom.xml | 2 +- xchange-stream-huobi/pom.xml | 2 +- xchange-stream-kraken/pom.xml | 2 +- xchange-stream-krakenfutures/pom.xml | 2 +- xchange-stream-lgo/pom.xml | 2 +- xchange-stream-okcoin/pom.xml | 2 +- xchange-stream-okex/pom.xml | 2 +- xchange-stream-poloniex2/pom.xml | 2 +- xchange-stream-serum/pom.xml | 2 +- xchange-stream-service-core/pom.xml | 2 +- xchange-stream-service-netty/pom.xml | 2 +- xchange-stream-service-pubnub/pom.xml | 2 +- xchange-therock/pom.xml | 2 +- xchange-tradeogre/pom.xml | 2 +- xchange-truefx/pom.xml | 2 +- xchange-upbit/pom.xml | 2 +- xchange-vaultoro/pom.xml | 2 +- xchange-yobit/pom.xml | 2 +- xchange-zaif/pom.xml | 2 +- 120 files changed, 120 insertions(+), 120 deletions(-) diff --git a/README.md b/README.md index 227cfaadacf..63c4a0dd26d 100644 --- a/README.md +++ b/README.md @@ -179,7 +179,7 @@ For snapshots, add the following repository to your pom.xml file. The current snapshot version is: - 5.1.1-SNAPSHOT + 5.1.99 ## Building with Maven diff --git a/pom.xml b/pom.xml index 43f92cb2649..e4ab3bb6420 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop pom XChange diff --git a/xchange-ascendex/pom.xml b/xchange-ascendex/pom.xml index 91c3f01488f..e9e18272157 100644 --- a/xchange-ascendex/pom.xml +++ b/xchange-ascendex/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-ascendex diff --git a/xchange-bankera/pom.xml b/xchange-bankera/pom.xml index 04661c9454d..b5dd84444d5 100644 --- a/xchange-bankera/pom.xml +++ b/xchange-bankera/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-bankera diff --git a/xchange-bibox/pom.xml b/xchange-bibox/pom.xml index e4f528da5d0..03dbded8bbb 100644 --- a/xchange-bibox/pom.xml +++ b/xchange-bibox/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-bibox diff --git a/xchange-binance/pom.xml b/xchange-binance/pom.xml index 62fc1af590f..35e3f419e2a 100644 --- a/xchange-binance/pom.xml +++ b/xchange-binance/pom.xml @@ -5,7 +5,7 @@ xchange-parent org.knowm.xchange - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-binance diff --git a/xchange-bitbay/pom.xml b/xchange-bitbay/pom.xml index 1271566e1ce..a6f233baa64 100644 --- a/xchange-bitbay/pom.xml +++ b/xchange-bitbay/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-bitbay diff --git a/xchange-bitcoinaverage/pom.xml b/xchange-bitcoinaverage/pom.xml index 43448314fc2..2e03004ce1e 100644 --- a/xchange-bitcoinaverage/pom.xml +++ b/xchange-bitcoinaverage/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-bitcoinaverage diff --git a/xchange-bitcoincharts/pom.xml b/xchange-bitcoincharts/pom.xml index 52e57a39b66..ceb32d127db 100644 --- a/xchange-bitcoincharts/pom.xml +++ b/xchange-bitcoincharts/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-bitcoincharts diff --git a/xchange-bitcoincore/pom.xml b/xchange-bitcoincore/pom.xml index c98da4419e6..a5fae022db6 100644 --- a/xchange-bitcoincore/pom.xml +++ b/xchange-bitcoincore/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-bitcoincore diff --git a/xchange-bitcoinde/pom.xml b/xchange-bitcoinde/pom.xml index cf09b411074..65945d8013c 100644 --- a/xchange-bitcoinde/pom.xml +++ b/xchange-bitcoinde/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-bitcoinde diff --git a/xchange-bitcointoyou/pom.xml b/xchange-bitcointoyou/pom.xml index f6cb7d4773c..74059210dcd 100644 --- a/xchange-bitcointoyou/pom.xml +++ b/xchange-bitcointoyou/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-bitcointoyou diff --git a/xchange-bitfinex/pom.xml b/xchange-bitfinex/pom.xml index fb5d5e23321..9b8a3d61f0f 100644 --- a/xchange-bitfinex/pom.xml +++ b/xchange-bitfinex/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-bitfinex diff --git a/xchange-bitflyer/pom.xml b/xchange-bitflyer/pom.xml index 826bbef2400..bb79f5defd3 100755 --- a/xchange-bitflyer/pom.xml +++ b/xchange-bitflyer/pom.xml @@ -6,7 +6,7 @@ xchange-parent org.knowm.xchange - 5.1.1-SNAPSHOT + 5.1.1.bigscoop diff --git a/xchange-bithumb/pom.xml b/xchange-bithumb/pom.xml index d7ac9f91394..3f8b0c649e2 100644 --- a/xchange-bithumb/pom.xml +++ b/xchange-bithumb/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-bithumb diff --git a/xchange-bitmex/pom.xml b/xchange-bitmex/pom.xml index 207bbadf397..1d19dc007d4 100755 --- a/xchange-bitmex/pom.xml +++ b/xchange-bitmex/pom.xml @@ -4,7 +4,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-bitmex diff --git a/xchange-bitso/pom.xml b/xchange-bitso/pom.xml index b33e203d35a..5af137e13b1 100644 --- a/xchange-bitso/pom.xml +++ b/xchange-bitso/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-bitso diff --git a/xchange-bitstamp/pom.xml b/xchange-bitstamp/pom.xml index 1998f2321c5..b15db03a3d5 100644 --- a/xchange-bitstamp/pom.xml +++ b/xchange-bitstamp/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-bitstamp diff --git a/xchange-bittrex/pom.xml b/xchange-bittrex/pom.xml index b8e02456f8d..98b0724efc4 100644 --- a/xchange-bittrex/pom.xml +++ b/xchange-bittrex/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-bittrex diff --git a/xchange-bity/pom.xml b/xchange-bity/pom.xml index dcde294d79c..8244312308b 100644 --- a/xchange-bity/pom.xml +++ b/xchange-bity/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-bity diff --git a/xchange-bitz/pom.xml b/xchange-bitz/pom.xml index 589d18e2a10..40770a1dde6 100644 --- a/xchange-bitz/pom.xml +++ b/xchange-bitz/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-bitz diff --git a/xchange-bl3p/pom.xml b/xchange-bl3p/pom.xml index f150454e95f..86b844be2ba 100644 --- a/xchange-bl3p/pom.xml +++ b/xchange-bl3p/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-bl3p diff --git a/xchange-bleutrade/pom.xml b/xchange-bleutrade/pom.xml index 4b782365c47..afcec3a7cb8 100644 --- a/xchange-bleutrade/pom.xml +++ b/xchange-bleutrade/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-bleutrade diff --git a/xchange-blockchain/pom.xml b/xchange-blockchain/pom.xml index e2b92521dae..d47c1920a36 100644 --- a/xchange-blockchain/pom.xml +++ b/xchange-blockchain/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-blockchain diff --git a/xchange-btcc/pom.xml b/xchange-btcc/pom.xml index af81e77690b..16b763b5aff 100644 --- a/xchange-btcc/pom.xml +++ b/xchange-btcc/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-btcc diff --git a/xchange-btcmarkets/pom.xml b/xchange-btcmarkets/pom.xml index 912b8819d0a..088e65c512c 100644 --- a/xchange-btcmarkets/pom.xml +++ b/xchange-btcmarkets/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-btcmarkets diff --git a/xchange-btcturk/pom.xml b/xchange-btcturk/pom.xml index a45e95e42e1..997622d6268 100644 --- a/xchange-btcturk/pom.xml +++ b/xchange-btcturk/pom.xml @@ -6,7 +6,7 @@ xchange-parent org.knowm.xchange - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-btcturk diff --git a/xchange-bybit/pom.xml b/xchange-bybit/pom.xml index 559ac72ee8d..0a515eaecd2 100644 --- a/xchange-bybit/pom.xml +++ b/xchange-bybit/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-bybit diff --git a/xchange-ccex/pom.xml b/xchange-ccex/pom.xml index a1031dc0247..a74f3516630 100644 --- a/xchange-ccex/pom.xml +++ b/xchange-ccex/pom.xml @@ -4,7 +4,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-ccex XChange C-Cex diff --git a/xchange-cexio/pom.xml b/xchange-cexio/pom.xml index 978dfbabee5..b777d928708 100644 --- a/xchange-cexio/pom.xml +++ b/xchange-cexio/pom.xml @@ -6,7 +6,7 @@ xchange-parent org.knowm.xchange - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-cexio diff --git a/xchange-coinbase/pom.xml b/xchange-coinbase/pom.xml index ec1f796fcd7..efab6b093e9 100644 --- a/xchange-coinbase/pom.xml +++ b/xchange-coinbase/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-coinbase diff --git a/xchange-coinbasepro/pom.xml b/xchange-coinbasepro/pom.xml index c6c283cc876..0f76a58370e 100644 --- a/xchange-coinbasepro/pom.xml +++ b/xchange-coinbasepro/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-coinbasepro diff --git a/xchange-coincheck/pom.xml b/xchange-coincheck/pom.xml index aeda06e3c7c..dfd64a5a063 100644 --- a/xchange-coincheck/pom.xml +++ b/xchange-coincheck/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-coincheck diff --git a/xchange-coindeal/pom.xml b/xchange-coindeal/pom.xml index b841eb58acc..25c306bc6dc 100644 --- a/xchange-coindeal/pom.xml +++ b/xchange-coindeal/pom.xml @@ -3,7 +3,7 @@ xchange-parent org.knowm.xchange - 5.1.1-SNAPSHOT + 5.1.1.bigscoop 4.0.0 diff --git a/xchange-coindirect/pom.xml b/xchange-coindirect/pom.xml index 3c1db7cc9ca..98665947fdb 100644 --- a/xchange-coindirect/pom.xml +++ b/xchange-coindirect/pom.xml @@ -5,7 +5,7 @@ xchange-parent org.knowm.xchange - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-coindirect diff --git a/xchange-coinegg/pom.xml b/xchange-coinegg/pom.xml index 4092c8e2e31..95cdba46b50 100644 --- a/xchange-coinegg/pom.xml +++ b/xchange-coinegg/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-coinegg diff --git a/xchange-coinex/pom.xml b/xchange-coinex/pom.xml index f54a7e3aaa3..80513cf4bfb 100644 --- a/xchange-coinex/pom.xml +++ b/xchange-coinex/pom.xml @@ -3,7 +3,7 @@ xchange-parent org.knowm.xchange - 5.1.1-SNAPSHOT + 5.1.1.bigscoop 4.0.0 diff --git a/xchange-coinfloor/pom.xml b/xchange-coinfloor/pom.xml index 50cc60bdcf6..07c638a3020 100644 --- a/xchange-coinfloor/pom.xml +++ b/xchange-coinfloor/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-coinfloor diff --git a/xchange-coingi/pom.xml b/xchange-coingi/pom.xml index 18a31b7b2dd..d42d98f4c60 100644 --- a/xchange-coingi/pom.xml +++ b/xchange-coingi/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-coingi diff --git a/xchange-coinjar/pom.xml b/xchange-coinjar/pom.xml index ff54d945c59..f86e5c97233 100644 --- a/xchange-coinjar/pom.xml +++ b/xchange-coinjar/pom.xml @@ -5,7 +5,7 @@ xchange-parent org.knowm.xchange - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-coinjar diff --git a/xchange-coinmarketcap/pom.xml b/xchange-coinmarketcap/pom.xml index 5171b6a57f9..16cdca08ee7 100644 --- a/xchange-coinmarketcap/pom.xml +++ b/xchange-coinmarketcap/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-coinmarketcap diff --git a/xchange-coinmate/pom.xml b/xchange-coinmate/pom.xml index 4f91ee96f48..3068e488687 100644 --- a/xchange-coinmate/pom.xml +++ b/xchange-coinmate/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-coinmate diff --git a/xchange-coinone/pom.xml b/xchange-coinone/pom.xml index 6f05aa7c873..a3efe4f09f9 100644 --- a/xchange-coinone/pom.xml +++ b/xchange-coinone/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-coinone diff --git a/xchange-core/pom.xml b/xchange-core/pom.xml index 53ff6850604..07f1a8f2614 100644 --- a/xchange-core/pom.xml +++ b/xchange-core/pom.xml @@ -3,7 +3,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-core diff --git a/xchange-cryptowatch/pom.xml b/xchange-cryptowatch/pom.xml index aad07671eaf..754fa037a90 100644 --- a/xchange-cryptowatch/pom.xml +++ b/xchange-cryptowatch/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-cryptowatch diff --git a/xchange-deribit/pom.xml b/xchange-deribit/pom.xml index 4c51e404e36..7efea14e01b 100644 --- a/xchange-deribit/pom.xml +++ b/xchange-deribit/pom.xml @@ -4,7 +4,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-deribit diff --git a/xchange-dvchain/pom.xml b/xchange-dvchain/pom.xml index 01307da36ae..f51b8d6898a 100644 --- a/xchange-dvchain/pom.xml +++ b/xchange-dvchain/pom.xml @@ -3,7 +3,7 @@ xchange-parent org.knowm.xchange - 5.1.1-SNAPSHOT + 5.1.1.bigscoop 4.0.0 diff --git a/xchange-dydx/pom.xml b/xchange-dydx/pom.xml index c970a112b35..bf4ed98409a 100644 --- a/xchange-dydx/pom.xml +++ b/xchange-dydx/pom.xml @@ -3,7 +3,7 @@ xchange-parent org.knowm.xchange - 5.1.1-SNAPSHOT + 5.1.1.bigscoop 4.0.0 diff --git a/xchange-enigma/pom.xml b/xchange-enigma/pom.xml index e710b70c073..91e23823d5a 100644 --- a/xchange-enigma/pom.xml +++ b/xchange-enigma/pom.xml @@ -5,7 +5,7 @@ xchange-parent org.knowm.xchange - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-enigma diff --git a/xchange-examples/pom.xml b/xchange-examples/pom.xml index 1b99fed7c89..d95021db1b8 100755 --- a/xchange-examples/pom.xml +++ b/xchange-examples/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-examples diff --git a/xchange-exmo/pom.xml b/xchange-exmo/pom.xml index 63459974f3b..15f649eb6dc 100644 --- a/xchange-exmo/pom.xml +++ b/xchange-exmo/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-exmo diff --git a/xchange-ftx/pom.xml b/xchange-ftx/pom.xml index 6b8e5219bf5..4c751f2a4c2 100644 --- a/xchange-ftx/pom.xml +++ b/xchange-ftx/pom.xml @@ -6,7 +6,7 @@ xchange-parent org.knowm.xchange - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-ftx diff --git a/xchange-gateio/pom.xml b/xchange-gateio/pom.xml index 39f7ff3c9a2..2edf29e2af5 100644 --- a/xchange-gateio/pom.xml +++ b/xchange-gateio/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-gateio diff --git a/xchange-gemini/pom.xml b/xchange-gemini/pom.xml index 9991b4951fe..256ff227ea1 100644 --- a/xchange-gemini/pom.xml +++ b/xchange-gemini/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-gemini diff --git a/xchange-globitex/pom.xml b/xchange-globitex/pom.xml index 017073f1ff9..37564ee3366 100644 --- a/xchange-globitex/pom.xml +++ b/xchange-globitex/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-globitex diff --git a/xchange-hitbtc/pom.xml b/xchange-hitbtc/pom.xml index d9af0b7c655..e3603b03ec9 100644 --- a/xchange-hitbtc/pom.xml +++ b/xchange-hitbtc/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-hitbtc diff --git a/xchange-huobi/pom.xml b/xchange-huobi/pom.xml index 3eaf60913ed..c68b0a31f2e 100644 --- a/xchange-huobi/pom.xml +++ b/xchange-huobi/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-huobi diff --git a/xchange-idex/pom.xml b/xchange-idex/pom.xml index 64b10f25661..b0b01136106 100644 --- a/xchange-idex/pom.xml +++ b/xchange-idex/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-idex diff --git a/xchange-independentreserve/pom.xml b/xchange-independentreserve/pom.xml index 8c6dd6838d4..7c38fdd323c 100644 --- a/xchange-independentreserve/pom.xml +++ b/xchange-independentreserve/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-independentreserve diff --git a/xchange-itbit/pom.xml b/xchange-itbit/pom.xml index e7ac04a0019..a122b4d62a6 100644 --- a/xchange-itbit/pom.xml +++ b/xchange-itbit/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-itbit diff --git a/xchange-koineks/pom.xml b/xchange-koineks/pom.xml index 4abf5d3536c..a3c19a80c5f 100644 --- a/xchange-koineks/pom.xml +++ b/xchange-koineks/pom.xml @@ -3,7 +3,7 @@ xchange-parent org.knowm.xchange - 5.1.1-SNAPSHOT + 5.1.1.bigscoop 4.0.0 diff --git a/xchange-koinim/pom.xml b/xchange-koinim/pom.xml index 2b1028f15fb..93de038abab 100644 --- a/xchange-koinim/pom.xml +++ b/xchange-koinim/pom.xml @@ -3,7 +3,7 @@ xchange-parent org.knowm.xchange - 5.1.1-SNAPSHOT + 5.1.1.bigscoop 4.0.0 diff --git a/xchange-kraken/pom.xml b/xchange-kraken/pom.xml index 7bcf6e8ef66..cfde033b322 100644 --- a/xchange-kraken/pom.xml +++ b/xchange-kraken/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-kraken diff --git a/xchange-krakenfutures/pom.xml b/xchange-krakenfutures/pom.xml index 5fed94a9c12..32c747083bf 100644 --- a/xchange-krakenfutures/pom.xml +++ b/xchange-krakenfutures/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-krakenfutures diff --git a/xchange-kucoin/pom.xml b/xchange-kucoin/pom.xml index 68e60ca0fc4..efd3fa30fb2 100644 --- a/xchange-kucoin/pom.xml +++ b/xchange-kucoin/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-kucoin diff --git a/xchange-kuna/pom.xml b/xchange-kuna/pom.xml index b33de315225..957e07a44a2 100644 --- a/xchange-kuna/pom.xml +++ b/xchange-kuna/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-kuna diff --git a/xchange-latoken/pom.xml b/xchange-latoken/pom.xml index 6d27f6ea484..2f888a75695 100644 --- a/xchange-latoken/pom.xml +++ b/xchange-latoken/pom.xml @@ -5,7 +5,7 @@ xchange-parent org.knowm.xchange - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-latoken diff --git a/xchange-lgo/pom.xml b/xchange-lgo/pom.xml index 21dd723e5a8..9735d70226f 100644 --- a/xchange-lgo/pom.xml +++ b/xchange-lgo/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-lgo diff --git a/xchange-livecoin/pom.xml b/xchange-livecoin/pom.xml index cca3cccfc08..413b9cdc11a 100644 --- a/xchange-livecoin/pom.xml +++ b/xchange-livecoin/pom.xml @@ -3,7 +3,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-livecoin XChange Livecoin diff --git a/xchange-luno/pom.xml b/xchange-luno/pom.xml index 6850ca511bf..63a05efae23 100644 --- a/xchange-luno/pom.xml +++ b/xchange-luno/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-luno diff --git a/xchange-lykke/pom.xml b/xchange-lykke/pom.xml index 67bf7470fdd..f438d39e072 100644 --- a/xchange-lykke/pom.xml +++ b/xchange-lykke/pom.xml @@ -3,7 +3,7 @@ xchange-parent org.knowm.xchange - 5.1.1-SNAPSHOT + 5.1.1.bigscoop 4.0.0 diff --git a/xchange-mercadobitcoin/pom.xml b/xchange-mercadobitcoin/pom.xml index ed27baf0dca..464a3515af5 100644 --- a/xchange-mercadobitcoin/pom.xml +++ b/xchange-mercadobitcoin/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-mercadobitcoin diff --git a/xchange-mexc/pom.xml b/xchange-mexc/pom.xml index 64bb9ec9449..45a31711ecb 100644 --- a/xchange-mexc/pom.xml +++ b/xchange-mexc/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-mexc diff --git a/xchange-okcoin/pom.xml b/xchange-okcoin/pom.xml index fd69ee26885..dfb9f93d028 100644 --- a/xchange-okcoin/pom.xml +++ b/xchange-okcoin/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-okcoin diff --git a/xchange-okex/pom.xml b/xchange-okex/pom.xml index b3ce7aa8f0b..957e14d33e3 100644 --- a/xchange-okex/pom.xml +++ b/xchange-okex/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-okex diff --git a/xchange-openexchangerates/pom.xml b/xchange-openexchangerates/pom.xml index acc11c780f8..983f700dcd8 100644 --- a/xchange-openexchangerates/pom.xml +++ b/xchange-openexchangerates/pom.xml @@ -4,7 +4,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-openexchangerates diff --git a/xchange-paribu/pom.xml b/xchange-paribu/pom.xml index 86245c5272c..c79d1714379 100644 --- a/xchange-paribu/pom.xml +++ b/xchange-paribu/pom.xml @@ -3,7 +3,7 @@ xchange-parent org.knowm.xchange - 5.1.1-SNAPSHOT + 5.1.1.bigscoop 4.0.0 diff --git a/xchange-paymium/pom.xml b/xchange-paymium/pom.xml index 4779e63ce0f..647458f0bde 100644 --- a/xchange-paymium/pom.xml +++ b/xchange-paymium/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-paymium diff --git a/xchange-poloniex/pom.xml b/xchange-poloniex/pom.xml index 9d81302b6a9..49b56c54e29 100755 --- a/xchange-poloniex/pom.xml +++ b/xchange-poloniex/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-poloniex diff --git a/xchange-quoine/pom.xml b/xchange-quoine/pom.xml index 59ad3ec56c3..35c0f76d949 100644 --- a/xchange-quoine/pom.xml +++ b/xchange-quoine/pom.xml @@ -3,7 +3,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-quoine diff --git a/xchange-ripple/pom.xml b/xchange-ripple/pom.xml index 0efb377f889..a7418fd5ffd 100644 --- a/xchange-ripple/pom.xml +++ b/xchange-ripple/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-ripple diff --git a/xchange-serum/pom.xml b/xchange-serum/pom.xml index 2f037834524..c522abb3c05 100644 --- a/xchange-serum/pom.xml +++ b/xchange-serum/pom.xml @@ -3,7 +3,7 @@ xchange-parent org.knowm.xchange - 5.1.1-SNAPSHOT + 5.1.1.bigscoop 4.0.0 diff --git a/xchange-simulated/pom.xml b/xchange-simulated/pom.xml index 8537110e06f..8531b4b5b97 100644 --- a/xchange-simulated/pom.xml +++ b/xchange-simulated/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-simulated diff --git a/xchange-stream-bankera/pom.xml b/xchange-stream-bankera/pom.xml index 91c44b418b2..0074e90adbd 100644 --- a/xchange-stream-bankera/pom.xml +++ b/xchange-stream-bankera/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop XChange Bankera Stream diff --git a/xchange-stream-binance/pom.xml b/xchange-stream-binance/pom.xml index b207654d107..5db3dae84b5 100644 --- a/xchange-stream-binance/pom.xml +++ b/xchange-stream-binance/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop XChange Binance Stream diff --git a/xchange-stream-bitfinex/pom.xml b/xchange-stream-bitfinex/pom.xml index 118498a6145..42ae0b99e4d 100644 --- a/xchange-stream-bitfinex/pom.xml +++ b/xchange-stream-bitfinex/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop XChange Bitfinex Stream diff --git a/xchange-stream-bitflyer/pom.xml b/xchange-stream-bitflyer/pom.xml index c6e655388b1..6b689fb30c0 100644 --- a/xchange-stream-bitflyer/pom.xml +++ b/xchange-stream-bitflyer/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop XChange Bitflyer Stream diff --git a/xchange-stream-bitmex/pom.xml b/xchange-stream-bitmex/pom.xml index 11fbf15628a..cd8b3f315d6 100644 --- a/xchange-stream-bitmex/pom.xml +++ b/xchange-stream-bitmex/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop XChange Bitmex Stream diff --git a/xchange-stream-bitstamp/pom.xml b/xchange-stream-bitstamp/pom.xml index f0a68bdb48a..7bf01611bc9 100644 --- a/xchange-stream-bitstamp/pom.xml +++ b/xchange-stream-bitstamp/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop XChange Bitstamp Stream diff --git a/xchange-stream-btcmarkets/pom.xml b/xchange-stream-btcmarkets/pom.xml index 9cc1955e490..0eeb4442ec2 100644 --- a/xchange-stream-btcmarkets/pom.xml +++ b/xchange-stream-btcmarkets/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop XChange BTCMarkets Stream diff --git a/xchange-stream-cexio/pom.xml b/xchange-stream-cexio/pom.xml index b5748d166c6..8f1c941eae9 100644 --- a/xchange-stream-cexio/pom.xml +++ b/xchange-stream-cexio/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop XChange Cex.io Stream diff --git a/xchange-stream-coinbasepro/pom.xml b/xchange-stream-coinbasepro/pom.xml index 45cc3e7a124..8d4a66c56f1 100644 --- a/xchange-stream-coinbasepro/pom.xml +++ b/xchange-stream-coinbasepro/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop XChange CoinbasePro Stream diff --git a/xchange-stream-coincheck/pom.xml b/xchange-stream-coincheck/pom.xml index 20c84345a53..15d72817f4f 100644 --- a/xchange-stream-coincheck/pom.xml +++ b/xchange-stream-coincheck/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop XChange Coincheck Stream diff --git a/xchange-stream-coinjar/pom.xml b/xchange-stream-coinjar/pom.xml index 96e2d2307b4..960c378e483 100644 --- a/xchange-stream-coinjar/pom.xml +++ b/xchange-stream-coinjar/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop XChange Coinjar Stream diff --git a/xchange-stream-coinmate/pom.xml b/xchange-stream-coinmate/pom.xml index fb4f2973668..232eee56e25 100644 --- a/xchange-stream-coinmate/pom.xml +++ b/xchange-stream-coinmate/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop XChange Coinmate Stream diff --git a/xchange-stream-core/pom.xml b/xchange-stream-core/pom.xml index 373ef95b891..9d96e15523f 100644 --- a/xchange-stream-core/pom.xml +++ b/xchange-stream-core/pom.xml @@ -3,7 +3,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop 4.0.0 diff --git a/xchange-stream-dydx/pom.xml b/xchange-stream-dydx/pom.xml index 98272a5352c..acb0a3e4455 100644 --- a/xchange-stream-dydx/pom.xml +++ b/xchange-stream-dydx/pom.xml @@ -3,7 +3,7 @@ xchange-parent org.knowm.xchange - 5.1.1-SNAPSHOT + 5.1.1.bigscoop 4.0.0 diff --git a/xchange-stream-ftx/pom.xml b/xchange-stream-ftx/pom.xml index b14b66f8879..1d8dc2e4c9f 100644 --- a/xchange-stream-ftx/pom.xml +++ b/xchange-stream-ftx/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop XChange Ftx Stream diff --git a/xchange-stream-gateio/pom.xml b/xchange-stream-gateio/pom.xml index 19d0f31e0a7..4922ceb3539 100644 --- a/xchange-stream-gateio/pom.xml +++ b/xchange-stream-gateio/pom.xml @@ -3,7 +3,7 @@ xchange-parent org.knowm.xchange - 5.1.1-SNAPSHOT + 5.1.1.bigscoop 4.0.0 diff --git a/xchange-stream-gemini-v2/pom.xml b/xchange-stream-gemini-v2/pom.xml index bbda9c81033..d254e1f2469 100644 --- a/xchange-stream-gemini-v2/pom.xml +++ b/xchange-stream-gemini-v2/pom.xml @@ -9,7 +9,7 @@ xchange-parent org.knowm.xchange - 5.1.1-SNAPSHOT + 5.1.1.bigscoop diff --git a/xchange-stream-gemini/pom.xml b/xchange-stream-gemini/pom.xml index ec035a31a1f..74c4d4363bc 100644 --- a/xchange-stream-gemini/pom.xml +++ b/xchange-stream-gemini/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop XChange Gemini Stream diff --git a/xchange-stream-hitbtc/pom.xml b/xchange-stream-hitbtc/pom.xml index 5a3f79401ee..a049cd43373 100644 --- a/xchange-stream-hitbtc/pom.xml +++ b/xchange-stream-hitbtc/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop XChange Hitbtc Stream diff --git a/xchange-stream-huobi/pom.xml b/xchange-stream-huobi/pom.xml index 6ae33aa6dd2..374eb219183 100644 --- a/xchange-stream-huobi/pom.xml +++ b/xchange-stream-huobi/pom.xml @@ -3,7 +3,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop 4.0.0 diff --git a/xchange-stream-kraken/pom.xml b/xchange-stream-kraken/pom.xml index 1cb5a278eee..9165c26fe5f 100644 --- a/xchange-stream-kraken/pom.xml +++ b/xchange-stream-kraken/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop XChange Kraken Stream diff --git a/xchange-stream-krakenfutures/pom.xml b/xchange-stream-krakenfutures/pom.xml index 23e8622a430..5ea97f822f3 100644 --- a/xchange-stream-krakenfutures/pom.xml +++ b/xchange-stream-krakenfutures/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-stream-krakenfutures diff --git a/xchange-stream-lgo/pom.xml b/xchange-stream-lgo/pom.xml index 5699c7f355f..03c7d7df312 100644 --- a/xchange-stream-lgo/pom.xml +++ b/xchange-stream-lgo/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop XChange LGO Stream diff --git a/xchange-stream-okcoin/pom.xml b/xchange-stream-okcoin/pom.xml index 857018aed92..19af5ac0ddf 100644 --- a/xchange-stream-okcoin/pom.xml +++ b/xchange-stream-okcoin/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop XChange OKCoin Stream diff --git a/xchange-stream-okex/pom.xml b/xchange-stream-okex/pom.xml index 42ed14106a7..4c3fdebf24f 100644 --- a/xchange-stream-okex/pom.xml +++ b/xchange-stream-okex/pom.xml @@ -6,7 +6,7 @@ xchange-parent org.knowm.xchange - 5.1.1-SNAPSHOT + 5.1.1.bigscoop XChange Okex Stream diff --git a/xchange-stream-poloniex2/pom.xml b/xchange-stream-poloniex2/pom.xml index 23ecca7cb7d..f708dedf60e 100644 --- a/xchange-stream-poloniex2/pom.xml +++ b/xchange-stream-poloniex2/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop XChange Poloniex 2 Stream diff --git a/xchange-stream-serum/pom.xml b/xchange-stream-serum/pom.xml index 2778be0cedf..311ca5b0522 100644 --- a/xchange-stream-serum/pom.xml +++ b/xchange-stream-serum/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop XChange Serum Stream diff --git a/xchange-stream-service-core/pom.xml b/xchange-stream-service-core/pom.xml index 9a2a333617b..4bc3d9c3049 100644 --- a/xchange-stream-service-core/pom.xml +++ b/xchange-stream-service-core/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop XChange Core Stream Service diff --git a/xchange-stream-service-netty/pom.xml b/xchange-stream-service-netty/pom.xml index aba65d517fd..b99fb4c08bb 100644 --- a/xchange-stream-service-netty/pom.xml +++ b/xchange-stream-service-netty/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop XChange Core Stream Netty diff --git a/xchange-stream-service-pubnub/pom.xml b/xchange-stream-service-pubnub/pom.xml index 6f73e624a4f..1f3c3ba4322 100644 --- a/xchange-stream-service-pubnub/pom.xml +++ b/xchange-stream-service-pubnub/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop XChange Core Stream Pubnub diff --git a/xchange-therock/pom.xml b/xchange-therock/pom.xml index 035c3ccd7cb..cf83b30c605 100644 --- a/xchange-therock/pom.xml +++ b/xchange-therock/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-therock diff --git a/xchange-tradeogre/pom.xml b/xchange-tradeogre/pom.xml index dd85c90e28f..3280008d174 100644 --- a/xchange-tradeogre/pom.xml +++ b/xchange-tradeogre/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-tradeogre diff --git a/xchange-truefx/pom.xml b/xchange-truefx/pom.xml index 7ce3b63e608..0812c77afba 100644 --- a/xchange-truefx/pom.xml +++ b/xchange-truefx/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-truefx diff --git a/xchange-upbit/pom.xml b/xchange-upbit/pom.xml index 7d6cf373af4..90585737b65 100644 --- a/xchange-upbit/pom.xml +++ b/xchange-upbit/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-upbit diff --git a/xchange-vaultoro/pom.xml b/xchange-vaultoro/pom.xml index f402ccf4801..a050d8c4285 100644 --- a/xchange-vaultoro/pom.xml +++ b/xchange-vaultoro/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-vaultoro diff --git a/xchange-yobit/pom.xml b/xchange-yobit/pom.xml index 97bc36a0b87..0edb8654da5 100644 --- a/xchange-yobit/pom.xml +++ b/xchange-yobit/pom.xml @@ -3,7 +3,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-yobit XChange YoBit diff --git a/xchange-zaif/pom.xml b/xchange-zaif/pom.xml index 71bf905b873..5d4b40e7301 100644 --- a/xchange-zaif/pom.xml +++ b/xchange-zaif/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-zaif From e759200e73074b0dce73cc0c5701c824663f4f22 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Sun, 21 May 2023 01:39:28 +0200 Subject: [PATCH 006/159] [gateio-v4] Create module skeleton --- pom.xml | 1 + xchange-gateio-v4/api-specification.txt | 8 + xchange-gateio-v4/pom.xml | 52 + .../java/org/knowm/xchange/gateio/Gateio.java | 100 ++ .../knowm/xchange/gateio/GateioAdapters.java | 364 +++++++ .../xchange/gateio/GateioAuthenticated.java | 127 +++ .../knowm/xchange/gateio/GateioExchange.java | 48 + .../org/knowm/xchange/gateio/GateioUtils.java | 15 + .../xchange/gateio/GateioV4Authenticated.java | 26 + .../gateio/dto/GateioBaseResponse.java | 32 + .../xchange/gateio/dto/GateioOrderType.java | 30 + .../gateio/dto/account/GateioDeposit.java | 56 ++ .../dto/account/GateioDepositAddress.java | 51 + .../account/GateioDepositsWithdrawals.java | 34 + .../gateio/dto/account/GateioFunds.java | 47 + .../dto/account/GateioWithdrawStatus.java | 37 + .../gateio/dto/account/GateioWithdrawal.java | 56 ++ .../marketdata/GateioCandlestickHistory.java | 34 + .../gateio/dto/marketdata/GateioCoin.java | 59 ++ .../dto/marketdata/GateioCoinInfoWrapper.java | 80 ++ .../dto/marketdata/GateioCurrencyChain.java | 44 + .../dto/marketdata/GateioCurrencyInfo.java | 44 + .../dto/marketdata/GateioCurrencyPairs.java | 55 ++ .../gateio/dto/marketdata/GateioDepth.java | 44 + .../gateio/dto/marketdata/GateioFeeInfo.java | 190 ++++ .../gateio/dto/marketdata/GateioKline.java | 54 ++ .../dto/marketdata/GateioKlineInterval.java | 36 + .../marketdata/GateioMarketInfoWrapper.java | 92 ++ .../dto/marketdata/GateioOrderBook.java | 45 + .../dto/marketdata/GateioPublicOrder.java | 57 ++ .../gateio/dto/marketdata/GateioTicker.java | 118 +++ .../dto/marketdata/GateioTradeHistory.java | 104 ++ .../gateio/dto/trade/GateioOpenOrder.java | 116 +++ .../gateio/dto/trade/GateioOpenOrders.java | 38 + .../gateio/dto/trade/GateioOrderStatus.java | 162 ++++ .../dto/trade/GateioPlaceOrderReturn.java | 30 + .../xchange/gateio/dto/trade/GateioTrade.java | 122 +++ .../dto/trade/GateioTradeHistoryReturn.java | 88 ++ .../gateio/service/GateioAccountService.java | 92 ++ .../service/GateioAccountServiceRaw.java | 83 ++ .../gateio/service/GateioBaseService.java | 65 ++ .../service/GateioHmacPostBodyDigest.java | 60 ++ .../GateioJacksonObjectMapperFactory.java | 18 + .../service/GateioMarketDataService.java | 101 ++ .../service/GateioMarketDataServiceRaw.java | 167 ++++ .../gateio/service/GateioTradeService.java | 155 +++ .../gateio/service/GateioTradeServiceRaw.java | 166 ++++ .../gateio/service/GateioV4Digest.java | 68 ++ .../src/main/resources/gateio.json | 901 ++++++++++++++++++ .../xchange/gateio/GateioExchangeTest.java | 28 + .../gateio/GateioExchangeWiremock.java | 53 ++ .../GateioMarketDataServiceRawTest.java | 122 +++ .../service/GateioMarketDataServiceTest.java | 55 ++ .../resources/__files/api_v2_marketinfo.json | 19 + .../__files/api_v4_spot_currencies.json | 47 + .../__files/api_v4_spot_order_book.json | 24 + .../api_v4_wallet_currency_chains.json | 18 + .../src/test/resources/logback.xml | 23 + .../resources/mappings/api_v2_marketinfo.json | 15 + .../mappings/api_v4_spot_currencies.json | 15 + .../mappings/api_v4_spot_order_book.json | 15 + .../api_v4_wallet_currency_chains.json | 15 + 62 files changed, 5021 insertions(+) create mode 100644 xchange-gateio-v4/api-specification.txt create mode 100644 xchange-gateio-v4/pom.xml create mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/Gateio.java create mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java create mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAuthenticated.java create mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioExchange.java create mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioUtils.java create mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java create mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/GateioBaseResponse.java create mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/GateioOrderType.java create mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioDeposit.java create mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioDepositAddress.java create mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioDepositsWithdrawals.java create mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioFunds.java create mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioWithdrawStatus.java create mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioWithdrawal.java create mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioCandlestickHistory.java create mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioCoin.java create mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioCoinInfoWrapper.java create mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioCurrencyChain.java create mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioCurrencyInfo.java create mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioCurrencyPairs.java create mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioDepth.java create mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioFeeInfo.java create mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioKline.java create mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioKlineInterval.java create mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioMarketInfoWrapper.java create mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioOrderBook.java create mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioPublicOrder.java create mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioTicker.java create mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioTradeHistory.java create mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/GateioOpenOrder.java create mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/GateioOpenOrders.java create mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/GateioOrderStatus.java create mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/GateioPlaceOrderReturn.java create mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/GateioTrade.java create mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/GateioTradeHistoryReturn.java create mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountService.java create mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountServiceRaw.java create mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioBaseService.java create mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioHmacPostBodyDigest.java create mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioJacksonObjectMapperFactory.java create mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioMarketDataService.java create mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioMarketDataServiceRaw.java create mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeService.java create mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeServiceRaw.java create mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioV4Digest.java create mode 100644 xchange-gateio-v4/src/main/resources/gateio.json create mode 100644 xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/GateioExchangeTest.java create mode 100644 xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/GateioExchangeWiremock.java create mode 100644 xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioMarketDataServiceRawTest.java create mode 100644 xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioMarketDataServiceTest.java create mode 100644 xchange-gateio-v4/src/test/resources/__files/api_v2_marketinfo.json create mode 100644 xchange-gateio-v4/src/test/resources/__files/api_v4_spot_currencies.json create mode 100644 xchange-gateio-v4/src/test/resources/__files/api_v4_spot_order_book.json create mode 100644 xchange-gateio-v4/src/test/resources/__files/api_v4_wallet_currency_chains.json create mode 100644 xchange-gateio-v4/src/test/resources/logback.xml create mode 100644 xchange-gateio-v4/src/test/resources/mappings/api_v2_marketinfo.json create mode 100644 xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_currencies.json create mode 100644 xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_order_book.json create mode 100644 xchange-gateio-v4/src/test/resources/mappings/api_v4_wallet_currency_chains.json diff --git a/pom.xml b/pom.xml index a994f7ff08a..f8194eef107 100644 --- a/pom.xml +++ b/pom.xml @@ -141,6 +141,7 @@ xchange-examples xchange-ftx xchange-gateio + xchange-gateio-v4 xchange-globitex xchange-gemini xchange-hitbtc diff --git a/xchange-gateio-v4/api-specification.txt b/xchange-gateio-v4/api-specification.txt new file mode 100644 index 00000000000..c57083d9d90 --- /dev/null +++ b/xchange-gateio-v4/api-specification.txt @@ -0,0 +1,8 @@ +Gate.io Exchange API V4 specification +================================ + +Public API + +Documentation +------------- +https://www.gate.io/docs/developers/apiv4 \ No newline at end of file diff --git a/xchange-gateio-v4/pom.xml b/xchange-gateio-v4/pom.xml new file mode 100644 index 00000000000..7876cf64016 --- /dev/null +++ b/xchange-gateio-v4/pom.xml @@ -0,0 +1,52 @@ + + + 4.0.0 + + + org.knowm.xchange + xchange-parent + 5.1.1.bigscoop + + + xchange-gateio-v4 + + XChange Gate.io V4 + XChange implementation for the Gate.io Exchange + + http://knowm.org/open-source/xchange/ + 2012 + + + Knowm Inc. + http://knowm.org/open-source/xchange/ + + + + + + org.knowm.xchange + xchange-core + ${project.version} + + + + com.github.tomakehurst + wiremock-jre8 + test + + + + org.projectlombok + lombok + provided + + + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + ${version.fasterxml} + + + + + 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 new file mode 100644 index 00000000000..2e68fe7ee74 --- /dev/null +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/Gateio.java @@ -0,0 +1,100 @@ +package org.knowm.xchange.gateio; + +import java.io.IOException; +import java.util.List; +import java.util.Map; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; +import org.knowm.xchange.gateio.dto.marketdata.GateioCandlestickHistory; +import org.knowm.xchange.gateio.dto.marketdata.GateioCoinInfoWrapper; +import org.knowm.xchange.gateio.dto.marketdata.GateioCurrencyChain; +import org.knowm.xchange.gateio.dto.marketdata.GateioCurrencyInfo; +import org.knowm.xchange.gateio.dto.marketdata.GateioCurrencyPairs; +import org.knowm.xchange.gateio.dto.marketdata.GateioDepth; +import org.knowm.xchange.gateio.dto.marketdata.GateioMarketInfoWrapper; +import org.knowm.xchange.gateio.dto.marketdata.GateioOrderBook; +import org.knowm.xchange.gateio.dto.marketdata.GateioTicker; +import org.knowm.xchange.gateio.dto.marketdata.GateioTradeHistory; + +@Path("") +@Produces(MediaType.APPLICATION_JSON) +public interface Gateio { + + @GET + @Path("api/v2/marketinfo") + GateioMarketInfoWrapper getMarketInfo() throws IOException; + + @GET + @Path("api2/1/pairs") + GateioCurrencyPairs getPairs() throws IOException; + + @GET + @Path("api2/1/orderBooks") + Map getDepths() throws IOException; + + @GET + @Path("/api2/1/tickers") + Map getTickers() throws IOException; + + @GET + @Path("/api2/1/coininfo") + GateioCoinInfoWrapper getCoinInfo() throws IOException; + + @GET + @Path("api2/1/ticker/{ident}_{currency}") + GateioTicker getTicker( + @PathParam("ident") String tradeableIdentifier, @PathParam("currency") String currency) + throws IOException; + + @GET + @Path("api2/1/orderBook/{ident}_{currency}") + GateioDepth getFullDepth( + @PathParam("ident") String tradeableIdentifier, @PathParam("currency") String currency) + throws IOException; + + @GET + @Path("api2/1/tradeHistory/{ident}_{currency}") + GateioTradeHistory getTradeHistory( + @PathParam("ident") String tradeableIdentifier, @PathParam("currency") String currency) + throws IOException; + + @GET + @Path("api2/1/tradeHistory/{ident}_{currency}/{tradeId}") + GateioTradeHistory getTradeHistorySince( + @PathParam("ident") String tradeableIdentifier, + @PathParam("currency") String currency, + @PathParam("tradeId") String tradeId) + throws IOException; + + @GET + @Path("api2/1/candlestick2/{currency_pair}") + GateioCandlestickHistory getKlinesGate( + @PathParam("currency_pair") String tradePair, + @QueryParam("range_hour") Integer hours, + @QueryParam("group_sec") Long interval) + throws IOException; + + + @GET + @Path("api/v4/spot/currencies") + List getCurrencies(); + + + @GET + @Path("api/v4/spot/order_book") + GateioOrderBook getOrderBook( + @QueryParam("currency_pair") String currencyPair, + @QueryParam("with_id") Boolean withId + ); + + + @GET + @Path("api/v4/wallet/currency_chains") + List getCurrencyChains(@QueryParam("currency") String currency); + + +} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java new file mode 100644 index 00000000000..0334731bf65 --- /dev/null +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java @@ -0,0 +1,364 @@ +package org.knowm.xchange.gateio; + +import java.io.IOException; +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Map.Entry; +import java.util.stream.Collectors; +import org.knowm.xchange.currency.Currency; +import org.knowm.xchange.currency.CurrencyPair; +import org.knowm.xchange.dto.Order.OrderType; +import org.knowm.xchange.dto.account.Balance; +import org.knowm.xchange.dto.account.FundingRecord; +import org.knowm.xchange.dto.account.FundingRecord.Status; +import org.knowm.xchange.dto.account.Wallet; +import org.knowm.xchange.dto.marketdata.OrderBook; +import org.knowm.xchange.dto.marketdata.Ticker; +import org.knowm.xchange.dto.marketdata.Trade; +import org.knowm.xchange.dto.marketdata.Trades; +import org.knowm.xchange.dto.marketdata.Trades.TradeSortType; +import org.knowm.xchange.dto.meta.CurrencyMetaData; +import org.knowm.xchange.dto.meta.ExchangeMetaData; +import org.knowm.xchange.dto.meta.InstrumentMetaData; +import org.knowm.xchange.dto.meta.WalletHealth; +import org.knowm.xchange.dto.trade.LimitOrder; +import org.knowm.xchange.dto.trade.OpenOrders; +import org.knowm.xchange.dto.trade.UserTrade; +import org.knowm.xchange.dto.trade.UserTrades; +import org.knowm.xchange.gateio.dto.GateioOrderType; +import org.knowm.xchange.gateio.dto.account.GateioDepositsWithdrawals; +import org.knowm.xchange.gateio.dto.account.GateioFunds; +import org.knowm.xchange.gateio.dto.marketdata.GateioCoin; +import org.knowm.xchange.gateio.dto.marketdata.GateioDepth; +import org.knowm.xchange.gateio.dto.marketdata.GateioFeeInfo; +import org.knowm.xchange.gateio.dto.marketdata.GateioMarketInfoWrapper.GateioMarketInfo; +import org.knowm.xchange.gateio.dto.marketdata.GateioOrderBook; +import org.knowm.xchange.gateio.dto.marketdata.GateioPublicOrder; +import org.knowm.xchange.gateio.dto.marketdata.GateioTicker; +import org.knowm.xchange.gateio.dto.marketdata.GateioTradeHistory; +import org.knowm.xchange.gateio.dto.trade.GateioOpenOrder; +import org.knowm.xchange.gateio.dto.trade.GateioOpenOrders; +import org.knowm.xchange.gateio.dto.trade.GateioTrade; +import org.knowm.xchange.gateio.service.GateioMarketDataServiceRaw; +import org.knowm.xchange.instrument.Instrument; +import org.knowm.xchange.utils.DateUtils; + +/** Various adapters for converting from Bter DTOs to XChange DTOs */ +public final class GateioAdapters { + + /** private Constructor */ + private GateioAdapters() {} + + public static CurrencyPair adaptCurrencyPair(String pair) { + + final String[] currencies = pair.toUpperCase().split("_"); + return new CurrencyPair(currencies[0], currencies[1]); + } + + + public static String toQueryParam(Instrument instrument) { + return String.format("%s_%s", + instrument.getBase().getCurrencyCode(), + instrument.getCounter().getCurrencyCode()) + .toLowerCase(Locale.ROOT); + } + + + public static Ticker adaptTicker(CurrencyPair currencyPair, GateioTicker gateioTicker) { + + BigDecimal ask = gateioTicker.getLowestAsk(); + BigDecimal bid = gateioTicker.getHighestBid(); + BigDecimal last = gateioTicker.getLast(); + BigDecimal low = gateioTicker.getLow24hr(); + BigDecimal high = gateioTicker.getHigh24hr(); + // Looks like gate.io vocabulary is inverted... + BigDecimal baseVolume = gateioTicker.getQuoteVolume(); + BigDecimal quoteVolume = gateioTicker.getBaseVolume(); + BigDecimal percentageChange = gateioTicker.getPercentChange(); + + return new Ticker.Builder() + .currencyPair(currencyPair) + .ask(ask) + .bid(bid) + .last(last) + .low(low) + .high(high) + .volume(baseVolume) + .quoteVolume(quoteVolume) + .percentageChange(percentageChange) + .build(); + } + + + public static OrderBook toOrderBook(GateioOrderBook gateioOrderBook, Instrument instrument) { + List asks = gateioOrderBook.getAsks().stream() + .map(priceSizeEntry -> new LimitOrder(OrderType.ASK, priceSizeEntry.getSize(), instrument, null, null, priceSizeEntry.getPrice())) + .collect(Collectors.toList()); + + + List bids = gateioOrderBook.getBids().stream() + .map(priceSizeEntry -> new LimitOrder(OrderType.BID, priceSizeEntry.getSize(), instrument, null, null, priceSizeEntry.getPrice())) + .collect(Collectors.toList()); + + return new OrderBook(Date.from(gateioOrderBook.getGeneratedAt()), asks, bids); + } + + + public static LimitOrder adaptOrder( + GateioPublicOrder order, CurrencyPair currencyPair, OrderType orderType) { + + return new LimitOrder(orderType, order.getAmount(), currencyPair, "", null, order.getPrice()); + } + + public static List adaptOrders( + List orders, CurrencyPair currencyPair, OrderType orderType) { + + List limitOrders = new ArrayList<>(); + + for (GateioPublicOrder bterOrder : orders) { + limitOrders.add(adaptOrder(bterOrder, currencyPair, orderType)); + } + + return limitOrders; + } + + public static OrderBook adaptOrderBook(GateioDepth depth, CurrencyPair currencyPair) { + + List asks = + GateioAdapters.adaptOrders(depth.getAsks(), currencyPair, OrderType.ASK); + Collections.reverse(asks); + List bids = + GateioAdapters.adaptOrders(depth.getBids(), currencyPair, OrderType.BID); + + return new OrderBook(null, asks, bids); + } + + public static LimitOrder adaptOrder( + GateioOpenOrder order, Collection currencyPairs) { + + String[] currencyPairSplit = order.getCurrencyPair().split("_"); + CurrencyPair currencyPair = new CurrencyPair(currencyPairSplit[0], currencyPairSplit[1]); + return new LimitOrder( + order.getType().equals("sell") ? OrderType.ASK : OrderType.BID, + order.getAmount(), + currencyPair, + order.getOrderNumber(), + null, + order.getRate()); + } + + public static OpenOrders adaptOpenOrders( + GateioOpenOrders openOrders, Collection currencyPairs) { + + List adaptedOrders = new ArrayList<>(); + for (GateioOpenOrder openOrder : openOrders.getOrders()) { + adaptedOrders.add(adaptOrder(openOrder, currencyPairs)); + } + + return new OpenOrders(adaptedOrders); + } + + public static OrderType adaptOrderType(GateioOrderType cryptoTradeOrderType) { + + return (cryptoTradeOrderType.equals(GateioOrderType.BUY)) ? OrderType.BID : OrderType.ASK; + } + + public static Trade adaptTrade( + GateioTradeHistory.GateioPublicTrade trade, CurrencyPair currencyPair) { + + OrderType orderType = adaptOrderType(trade.getType()); + Date timestamp = DateUtils.fromMillisUtc(trade.getDate() * 1000); + + return new Trade.Builder() + .type(orderType) + .originalAmount(trade.getAmount()) + .currencyPair(currencyPair) + .price(trade.getPrice()) + .timestamp(timestamp) + .id(trade.getTradeId()) + .build(); + } + + public static Trades adaptTrades(GateioTradeHistory tradeHistory, CurrencyPair currencyPair) { + + List tradeList = new ArrayList<>(); + long lastTradeId = 0; + for (GateioTradeHistory.GateioPublicTrade trade : tradeHistory.getTrades()) { + String tradeIdString = trade.getTradeId(); + if (!tradeIdString.isEmpty()) { + long tradeId = Long.valueOf(tradeIdString); + if (tradeId > lastTradeId) { + lastTradeId = tradeId; + } + } + Trade adaptedTrade = adaptTrade(trade, currencyPair); + tradeList.add(adaptedTrade); + } + + return new Trades(tradeList, lastTradeId, TradeSortType.SortByTimestamp); + } + + public static Wallet adaptWallet(GateioFunds bterAccountInfo) { + + List balances = new ArrayList<>(); + for (Entry funds : bterAccountInfo.getAvailableFunds().entrySet()) { + Currency currency = Currency.getInstance(funds.getKey().toUpperCase()); + BigDecimal amount = funds.getValue(); + BigDecimal locked = bterAccountInfo.getLockedFunds().get(currency.toString()); + + balances.add(new Balance(currency, null, amount, locked == null ? BigDecimal.ZERO : locked)); + } + for (Entry funds : bterAccountInfo.getLockedFunds().entrySet()) { + Currency currency = Currency.getInstance(funds.getKey().toUpperCase()); + if (balances.stream().noneMatch(balance -> balance.getCurrency().equals(currency))) { + BigDecimal amount = funds.getValue(); + balances.add(new Balance(currency, null, BigDecimal.ZERO, amount)); + } + } + + return Wallet.Builder.from(balances).build(); + } + + public static UserTrades adaptUserTrades(List userTrades) { + + List trades = new ArrayList<>(); + for (GateioTrade userTrade : userTrades) { + trades.add(adaptUserTrade(userTrade)); + } + + return new UserTrades(trades, TradeSortType.SortByTimestamp); + } + + public static UserTrade adaptUserTrade(GateioTrade gateioTrade) { + + OrderType orderType = adaptOrderType(gateioTrade.getType()); + Date timestamp = DateUtils.fromMillisUtc(gateioTrade.getTimeUnix() * 1000); + CurrencyPair currencyPair = adaptCurrencyPair(gateioTrade.getPair()); + + return new UserTrade.Builder() + .type(orderType) + .originalAmount(gateioTrade.getAmount()) + .currencyPair(currencyPair) + .price(gateioTrade.getRate()) + .timestamp(timestamp) + .id(gateioTrade.getTradeID()) + .orderId(gateioTrade.getOrderNumber()) + .build(); + } + + public static ExchangeMetaData adaptToExchangeMetaData( + GateioMarketDataServiceRaw marketDataService) throws IOException { + + Map currencyPairs = new HashMap<>(); + Map currencies = new HashMap<>(); + + for (Entry entry : + marketDataService.getMarketInfo().entrySet()) { + + CurrencyPair currencyPair = entry.getKey(); + GateioMarketInfo btermarketInfo = entry.getValue(); + + currencyPairs.put(currencyPair, new InstrumentMetaData.Builder() + .tradingFee(btermarketInfo.getFee()) + .minimumAmount(btermarketInfo.getMinAmount()) + .priceScale(btermarketInfo.getDecimalPlaces()) + .build()); + } + + if (marketDataService.getApiKey() != null) { + Map gateioFees = marketDataService.getGateioFees(); + Map coins = marketDataService.getGateioCoinInfo().getCoins(); + for (String coin : coins.keySet()) { + GateioCoin gateioCoin = coins.get(coin); + GateioFeeInfo gateioFeeInfo = gateioFees.get(coin); + if (gateioCoin != null && gateioFeeInfo != null) { + currencies.put(new Currency(coin), adaptCurrencyMetaData(gateioCoin, gateioFeeInfo)); + } + } + } + + return new ExchangeMetaData(currencyPairs, currencies, null, null, null); + } + + private static CurrencyMetaData adaptCurrencyMetaData( + GateioCoin gateioCoin, GateioFeeInfo gateioFeeInfo) { + WalletHealth walletHealth = WalletHealth.ONLINE; + if (gateioCoin.isWithdrawDelayed()) { + walletHealth = WalletHealth.UNKNOWN; + } else if (gateioCoin.isDelisted() + || (gateioCoin.isWithdrawDisabled() && gateioCoin.isDepositDisabled())) { + walletHealth = WalletHealth.OFFLINE; + } else if (gateioCoin.isDepositDisabled()) { + walletHealth = WalletHealth.DEPOSITS_DISABLED; + } else if (gateioCoin.isWithdrawDisabled()) { + walletHealth = WalletHealth.WITHDRAWALS_DISABLED; + } + return new CurrencyMetaData( + 0, + new BigDecimal(gateioFeeInfo.getWithdrawFix()), + gateioFeeInfo.getWithdrawAmountMini(), + walletHealth); + } + + public static List adaptDepositsWithdrawals( + GateioDepositsWithdrawals depositsWithdrawals) { + List result = new ArrayList<>(); + + depositsWithdrawals + .getDeposits() + .forEach( + d -> { + FundingRecord r = + new FundingRecord( + d.address, + d.getTimestamp(), + Currency.getInstance(d.currency), + d.amount, + d.id, + d.txid, + FundingRecord.Type.DEPOSIT, + status(d.status), + null, + null, + null); + result.add(r); + }); + depositsWithdrawals + .getWithdraws() + .forEach( + w -> { + FundingRecord r = + new FundingRecord( + w.address, + w.getTimestamp(), + Currency.getInstance(w.currency), + w.amount, + w.id, + w.txid, + FundingRecord.Type.WITHDRAWAL, + status(w.status), + null, + null, + null); + result.add(r); + }); + + return result; + } + + private static FundingRecord.Status status(String gateioStatus) { + switch (gateioStatus) { + case "DONE": + return Status.COMPLETE; + default: + return Status.PROCESSING; // @TODO which statusses are possible at gate.io? + } + } +} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAuthenticated.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAuthenticated.java new file mode 100644 index 00000000000..9ccf9b1a585 --- /dev/null +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAuthenticated.java @@ -0,0 +1,127 @@ +package org.knowm.xchange.gateio; + +import java.io.IOException; +import java.math.BigDecimal; +import java.util.Map; +import javax.ws.rs.Consumes; +import javax.ws.rs.FormParam; +import javax.ws.rs.HeaderParam; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; +import org.knowm.xchange.gateio.dto.GateioBaseResponse; +import org.knowm.xchange.gateio.dto.account.GateioDepositAddress; +import org.knowm.xchange.gateio.dto.account.GateioDepositsWithdrawals; +import org.knowm.xchange.gateio.dto.account.GateioFunds; +import org.knowm.xchange.gateio.dto.marketdata.GateioFeeInfo; +import org.knowm.xchange.gateio.dto.trade.GateioOpenOrders; +import org.knowm.xchange.gateio.dto.trade.GateioOrderStatus; +import org.knowm.xchange.gateio.dto.trade.GateioPlaceOrderReturn; +import org.knowm.xchange.gateio.dto.trade.GateioTradeHistoryReturn; +import si.mazi.rescu.ParamsDigest; + +@Path("api2/1") +@Consumes(MediaType.APPLICATION_FORM_URLENCODED) +@Produces(MediaType.APPLICATION_JSON) +public interface GateioAuthenticated { + + @POST + @Path("private/balances") + GateioFunds getFunds(@HeaderParam("KEY") String apiKey, @HeaderParam("SIGN") ParamsDigest signer) + throws IOException; + + @POST + @Path("private/depositAddress") + GateioDepositAddress getDepositAddress( + @HeaderParam("KEY") String apiKey, + @HeaderParam("SIGN") ParamsDigest signer, + @FormParam("currency") String currency) + throws IOException; + + @POST + @Path("private/withdraw") + GateioBaseResponse withdraw( + @HeaderParam("KEY") String apiKey, + @HeaderParam("SIGN") ParamsDigest signer, + @FormParam("currency") String currency, + @FormParam("amount") BigDecimal amount, + @FormParam("address") String address) + throws IOException; + + @POST + @Path("private/cancelorder") + GateioBaseResponse cancelOrder( + @FormParam("orderNumber") String orderNumber, + @FormParam("currencyPair") String currencyPair, + @HeaderParam("KEY") String apiKey, + @HeaderParam("SIGN") ParamsDigest signer) + throws IOException; + + @POST + @Path("private/cancelAllOrders") + GateioBaseResponse cancelAllOrders( + @FormParam("type") String type, + @FormParam("currencyPair") String currencyPair, + @HeaderParam("KEY") String apiKey, + @HeaderParam("SIGN") ParamsDigest signer) + throws IOException; + + @POST + @Path("private/buy") + GateioPlaceOrderReturn buy( + @FormParam("currencyPair") String currencyPair, + @FormParam("rate") BigDecimal rate, + @FormParam("amount") BigDecimal amount, + @HeaderParam("KEY") String apiKey, + @HeaderParam("SIGN") ParamsDigest signer) + throws IOException; + + @POST + @Path("private/sell") + GateioPlaceOrderReturn sell( + @FormParam("currencyPair") String currencyPair, + @FormParam("rate") BigDecimal rate, + @FormParam("amount") BigDecimal amount, + @HeaderParam("KEY") String apiKey, + @HeaderParam("SIGN") ParamsDigest signer) + throws IOException; + + @POST + @Path("private/openOrders") + GateioOpenOrders getOpenOrders( + @HeaderParam("KEY") String apiKey, @HeaderParam("SIGN") ParamsDigest signer) + throws IOException; + + @POST + @Path("private/tradeHistory") + GateioTradeHistoryReturn getUserTradeHistory( + @HeaderParam("KEY") String apiKey, + @HeaderParam("SIGN") ParamsDigest signer, + @FormParam("currencyPair") String currencyPair) + throws IOException; + + @POST + @Path("private/depositsWithdrawals") + GateioDepositsWithdrawals getDepositsWithdrawals( + @HeaderParam("KEY") String apiKey, + @HeaderParam("SIGN") ParamsDigest signer, + @FormParam("start") Long startUnixTime, + @FormParam("end") Long endUnixTime) + throws IOException; + + @POST + @Path("private/getorder") + GateioOrderStatus getOrderStatus( + @FormParam("orderNumber") String orderNumber, + @FormParam("currencyPair") String currencyPair, + @HeaderParam("KEY") String apiKey, + @HeaderParam("SIGN") ParamsDigest signer) + throws IOException; + + @POST + @Path("private/feelist") + Map getFeeList( + @HeaderParam("KEY") String apiKey, @HeaderParam("SIGN") ParamsDigest signer) + throws IOException; +} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioExchange.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioExchange.java new file mode 100644 index 00000000000..855af49402b --- /dev/null +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioExchange.java @@ -0,0 +1,48 @@ +package org.knowm.xchange.gateio; + +import java.io.IOException; +import java.util.concurrent.TimeUnit; +import org.knowm.xchange.BaseExchange; +import org.knowm.xchange.Exchange; +import org.knowm.xchange.ExchangeSpecification; +import org.knowm.xchange.gateio.service.GateioAccountService; +import org.knowm.xchange.gateio.service.GateioMarketDataService; +import org.knowm.xchange.gateio.service.GateioTradeService; +import org.knowm.xchange.utils.nonce.CurrentTimeIncrementalNonceFactory; +import si.mazi.rescu.SynchronizedValueFactory; + +public class GateioExchange extends BaseExchange implements Exchange { + + private final SynchronizedValueFactory nonceFactory = + new CurrentTimeIncrementalNonceFactory(TimeUnit.SECONDS); + + + @Override + protected void initServices() { + this.marketDataService = new GateioMarketDataService(this); + this.accountService = new GateioAccountService(this); + this.tradeService = new GateioTradeService(this); + } + + @Override + public ExchangeSpecification getDefaultExchangeSpecification() { + + ExchangeSpecification exchangeSpecification = new ExchangeSpecification(this.getClass()); + exchangeSpecification.setSslUri("https://api.gateio.ws"); + exchangeSpecification.setHost("gate.io"); + exchangeSpecification.setExchangeName("Gateio"); + + return exchangeSpecification; + } + + @Override + public SynchronizedValueFactory getNonceFactory() { + return nonceFactory; + } + + @Override + public void remoteInit() throws IOException { +// exchangeMetaData = +// GateioAdapters.adaptToExchangeMetaData((GateioMarketDataServiceRaw) marketDataService); + } +} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioUtils.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioUtils.java new file mode 100644 index 00000000000..1ce3789c4bf --- /dev/null +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioUtils.java @@ -0,0 +1,15 @@ +package org.knowm.xchange.gateio; + +import org.knowm.xchange.currency.CurrencyPair; + +public class GateioUtils { + + public static String toPairString(CurrencyPair currencyPair) { + + String baseSymbol = currencyPair.base.getCurrencyCode().toLowerCase(); + String counterSymbol = currencyPair.counter.getCurrencyCode().toLowerCase(); + String pair = baseSymbol + "_" + counterSymbol; + + return pair; + } +} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java new file mode 100644 index 00000000000..3afffae8a5c --- /dev/null +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java @@ -0,0 +1,26 @@ +package org.knowm.xchange.gateio; + +import java.io.IOException; +import java.util.List; +import javax.ws.rs.GET; +import javax.ws.rs.HeaderParam; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; +import org.knowm.xchange.gateio.dto.account.GateioWithdrawStatus; +import si.mazi.rescu.ParamsDigest; +import si.mazi.rescu.SynchronizedValueFactory; + +@Path("api/v4") +public interface GateioV4Authenticated { + + @GET + @Produces(MediaType.APPLICATION_JSON) + @Path("wallet/withdraw_status") + List getWithdrawStatus( + @HeaderParam("KEY") String apiKey, + @HeaderParam("Timestamp") SynchronizedValueFactory timestamp, + @HeaderParam("SIGN") ParamsDigest signer) + throws IOException; + +} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/GateioBaseResponse.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/GateioBaseResponse.java new file mode 100644 index 00000000000..6874cd09ccf --- /dev/null +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/GateioBaseResponse.java @@ -0,0 +1,32 @@ +package org.knowm.xchange.gateio.dto; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class GateioBaseResponse { + + private final boolean result; + private final String message; + + protected GateioBaseResponse( + @JsonProperty("result") final boolean result, @JsonProperty("msg") final String message) { + + this.result = result; + this.message = message; + } + + public boolean isResult() { + + return result; + } + + public String getMessage() { + + return message; + } + + @Override + public String toString() { + + return "GateioBaseResponse [result=" + result + ", message=" + message + "]"; + } +} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/GateioOrderType.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/GateioOrderType.java new file mode 100644 index 00000000000..22a7a971fa6 --- /dev/null +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/GateioOrderType.java @@ -0,0 +1,30 @@ +package org.knowm.xchange.gateio.dto; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.ObjectCodec; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import java.io.IOException; +import org.knowm.xchange.gateio.dto.GateioOrderType.BTEROrderTypeDeserializer; + +@JsonDeserialize(using = BTEROrderTypeDeserializer.class) +public enum GateioOrderType { + BUY, + SELL; + + static class BTEROrderTypeDeserializer extends JsonDeserializer { + + @Override + public GateioOrderType deserialize(JsonParser jsonParser, final DeserializationContext ctxt) + throws IOException, JsonProcessingException { + + final ObjectCodec oc = jsonParser.getCodec(); + final JsonNode node = oc.readTree(jsonParser); + final String orderType = node.asText(); + return GateioOrderType.valueOf(orderType.toUpperCase()); + } + } +} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioDeposit.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioDeposit.java new file mode 100644 index 00000000000..a8d78fcf509 --- /dev/null +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioDeposit.java @@ -0,0 +1,56 @@ +package org.knowm.xchange.gateio.dto.account; + +import com.fasterxml.jackson.annotation.JsonProperty; +import java.math.BigDecimal; +import java.util.Date; + +public class GateioDeposit { + + public final String id; + public final String currency; + public final String address; + public final BigDecimal amount; + public final String txid; + public final long timestamp; + public final String status; + + public GateioDeposit( + @JsonProperty("id") String id, + @JsonProperty("currency") String currency, + @JsonProperty("address") String address, + @JsonProperty("amount") BigDecimal amount, + @JsonProperty("txid") String txid, + @JsonProperty("timestamp") long timestamp, + @JsonProperty("status") String status) { + this.id = id; + this.currency = currency; + this.address = address; + this.amount = amount; + this.txid = txid; + this.timestamp = timestamp; + this.status = status; + } + + public Date getTimestamp() { + return new Date(timestamp * 1000); + } + + @Override + public String toString() { + return "GateioDeposit [id=" + + id + + ", currency=" + + currency + + ", address=" + + address + + ", amount=" + + amount + + ", txid=" + + txid + + ", status=" + + status + + ", getTimestamp()=" + + getTimestamp() + + "]"; + } +} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioDepositAddress.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioDepositAddress.java new file mode 100644 index 00000000000..e07dcfc8bc4 --- /dev/null +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioDepositAddress.java @@ -0,0 +1,51 @@ +package org.knowm.xchange.gateio.dto.account; + +import com.fasterxml.jackson.annotation.JsonProperty; +import org.knowm.xchange.gateio.dto.GateioBaseResponse; + +public class GateioDepositAddress extends GateioBaseResponse { + + private final String baseAddress; + + private final String addressTag; + + /** + * Constructor + * + * @param theAvailable + * @param theLocked + */ + public GateioDepositAddress( + @JsonProperty("addr") String addr, + @JsonProperty("result") boolean result, + @JsonProperty("message") final String message) { + + super(result, message); + + String[] addressComponent = addr.split("/"); + this.baseAddress = addressComponent[0]; + if (addressComponent.length > 1) { + this.addressTag = addressComponent[1]; + } else { + this.addressTag = null; + } + } + + public String getBaseAddress() { + return baseAddress; + } + + public String getAddressTag() { + return addressTag; + } + + @Override + public String toString() { + + return "BTERDepositAddressReturn [baseAddress=" + + baseAddress + + ", addressTag=" + + addressTag + + "]"; + } +} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioDepositsWithdrawals.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioDepositsWithdrawals.java new file mode 100644 index 00000000000..474999a7b89 --- /dev/null +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioDepositsWithdrawals.java @@ -0,0 +1,34 @@ +package org.knowm.xchange.gateio.dto.account; + +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.List; +import org.knowm.xchange.gateio.dto.GateioBaseResponse; + +public class GateioDepositsWithdrawals extends GateioBaseResponse { + + private final List deposits; + private final List withdraws; + + public GateioDepositsWithdrawals( + @JsonProperty("result") boolean result, + @JsonProperty("deposits") List deposits, + @JsonProperty("withdraws") List withdraws, + @JsonProperty("message") final String message) { + super(result, message); + this.deposits = deposits; + this.withdraws = withdraws; + } + + public List getDeposits() { + return deposits; + } + + public List getWithdraws() { + return withdraws; + } + + @Override + public String toString() { + return "GateioDepositsWithdrawals [deposits=" + deposits + ", withdraws=" + withdraws + "]"; + } +} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioFunds.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioFunds.java new file mode 100644 index 00000000000..898d9131e37 --- /dev/null +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioFunds.java @@ -0,0 +1,47 @@ +package org.knowm.xchange.gateio.dto.account; + +import com.fasterxml.jackson.annotation.JsonProperty; +import java.math.BigDecimal; +import java.util.HashMap; +import java.util.Map; +import org.knowm.xchange.gateio.dto.GateioBaseResponse; + +public class GateioFunds extends GateioBaseResponse { + + private final Map available; + private final Map locked; + + /** + * Constructor + * + * @param theAvailable + * @param theLocked + */ + public GateioFunds( + @JsonProperty("available") Map theAvailable, + @JsonProperty("locked") Map theLocked, + @JsonProperty("result") boolean result, + @JsonProperty("message") final String message) { + + super(result, message); + + available = theAvailable == null ? new HashMap() : theAvailable; + locked = theLocked == null ? new HashMap() : theLocked; + } + + public Map getAvailableFunds() { + + return available; + } + + public Map getLockedFunds() { + + return locked; + } + + @Override + public String toString() { + + return "BTERAccountInfoReturn [availableFunds=" + available + ", lockedFunds=" + locked + "]"; + } +} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioWithdrawStatus.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioWithdrawStatus.java new file mode 100644 index 00000000000..343b6035c5d --- /dev/null +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioWithdrawStatus.java @@ -0,0 +1,37 @@ +package org.knowm.xchange.gateio.dto.account; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.LinkedHashMap; +import java.util.Map; +import lombok.Builder; +import lombok.Data; +import lombok.extern.jackson.Jacksonized; + +@Data +@Builder +@Jacksonized +public class GateioWithdrawStatus { + + @JsonProperty("currency") + String currency; + + @JsonIgnore + private Map additionalProperties = new LinkedHashMap<>(); + + @JsonAnyGetter + public Map getAdditionalProperties() { + return additionalProperties; + } + + @JsonAnySetter + public void setAdditionalProperty(String name, Object value) { + additionalProperties.put(name, value); + } + + + + +} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioWithdrawal.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioWithdrawal.java new file mode 100644 index 00000000000..ae3002a0c5d --- /dev/null +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioWithdrawal.java @@ -0,0 +1,56 @@ +package org.knowm.xchange.gateio.dto.account; + +import com.fasterxml.jackson.annotation.JsonProperty; +import java.math.BigDecimal; +import java.util.Date; + +public class GateioWithdrawal { + + public final String id; + public final String currency; + public final String address; + public final BigDecimal amount; + public final String txid; + public final long timestamp; + public final String status; + + public GateioWithdrawal( + @JsonProperty("id") String id, + @JsonProperty("currency") String currency, + @JsonProperty("address") String address, + @JsonProperty("amount") BigDecimal amount, + @JsonProperty("txid") String txid, + @JsonProperty("timestamp") long timestamp, + @JsonProperty("status") String status) { + this.id = id; + this.currency = currency; + this.address = address; + this.amount = amount; + this.txid = txid; + this.timestamp = timestamp; + this.status = status; + } + + public Date getTimestamp() { + return new Date(timestamp * 1000); + } + + @Override + public String toString() { + return "GateioDeposit [id=" + + id + + ", currency=" + + currency + + ", address=" + + address + + ", amount=" + + amount + + ", txid=" + + txid + + ", status=" + + status + + ", getTimestamp()=" + + getTimestamp() + + "]"; + } +} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioCandlestickHistory.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioCandlestickHistory.java new file mode 100644 index 00000000000..5635fa5aee1 --- /dev/null +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioCandlestickHistory.java @@ -0,0 +1,34 @@ +package org.knowm.xchange.gateio.dto.marketdata; + +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.List; +import org.knowm.xchange.gateio.dto.GateioBaseResponse; + +public class GateioCandlestickHistory extends GateioBaseResponse { + + private final List> candlesticks; + private final String elapsed; + + private GateioCandlestickHistory( + @JsonProperty("data") List> candlesticks, + @JsonProperty("result") boolean result, + @JsonProperty("elapsed") String elapsed) { + + super(result, null); + this.candlesticks = candlesticks; + this.elapsed = elapsed; + } + + public List> getCandlesticks() { + return candlesticks; + } + + public String getElapsed() { + return elapsed; + } + + @Override + public String toString() { + return "BTERPublicTrades [candlesticks=" + candlesticks + ", elapsed=" + elapsed + "]"; + } +} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioCoin.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioCoin.java new file mode 100644 index 00000000000..ee118643156 --- /dev/null +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioCoin.java @@ -0,0 +1,59 @@ +package org.knowm.xchange.gateio.dto.marketdata; + +public class GateioCoin { + + boolean delisted; + boolean withdrawDisabled; + boolean withdrawDelayed; + boolean depositDisabled; + boolean tradeDisabled; + + public GateioCoin( + boolean delisted, + boolean withdrawDisabled, + boolean withdrawDelayed, + boolean depositDisabled, + boolean tradeDisabled) { + this.delisted = delisted; + this.withdrawDisabled = withdrawDisabled; + this.withdrawDelayed = withdrawDelayed; + this.depositDisabled = depositDisabled; + this.tradeDisabled = tradeDisabled; + } + + @Override + public String toString() { + return "GateioCoin{" + + "delisted=" + + delisted + + ", withdrawDisabled=" + + withdrawDisabled + + ", withdrawDelayed=" + + withdrawDelayed + + ", depositDisabled=" + + depositDisabled + + ", tradeDisabled=" + + tradeDisabled + + '}'; + } + + public boolean isDelisted() { + return delisted; + } + + public boolean isWithdrawDisabled() { + return withdrawDisabled; + } + + public boolean isWithdrawDelayed() { + return withdrawDelayed; + } + + public boolean isDepositDisabled() { + return depositDisabled; + } + + public boolean isTradeDisabled() { + return tradeDisabled; + } +} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioCoinInfoWrapper.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioCoinInfoWrapper.java new file mode 100644 index 00000000000..3545545e27a --- /dev/null +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioCoinInfoWrapper.java @@ -0,0 +1,80 @@ +package org.knowm.xchange.gateio.dto.marketdata; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.ObjectCodec; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import java.io.IOException; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import org.knowm.xchange.exceptions.ExchangeException; + +@JsonDeserialize(using = GateioCoinInfoWrapper.BTERGateioCoinInfoDeserializer.class) +public class GateioCoinInfoWrapper { + + private final Map coins; + + public GateioCoinInfoWrapper(Map coins) { + this.coins = coins; + } + + public Map getCoins() { + return coins; + } + + @Override + public String toString() { + return "GateioCoinInfo{" + "coins=" + coins + '}'; + } + + static class BTERGateioCoinInfoDeserializer extends JsonDeserializer { + + private static final String DELISTED = "delisted"; + private static final String WITHDRAW_DISABLED = "withdraw_disabled"; + private static final String WITHDRAW_DELAYED = "withdraw_delayed"; + private static final String DEPOSIT_DISABLED = "deposit_disabled"; + private static final String TRADE_DISABLED = "trade_disabled"; + + @Override + public GateioCoinInfoWrapper deserialize(JsonParser jp, DeserializationContext ctxt) + throws IOException { + + Map gateioCoinInfoMap = new HashMap<>(); + + ObjectCodec oc = jp.getCodec(); + JsonNode coinsNodeWrapper = oc.readTree(jp); + JsonNode marketNodeList = coinsNodeWrapper.path("coins"); + + if (marketNodeList.isArray()) { + for (JsonNode marketNode : marketNodeList) { + Iterator> iter = marketNode.fields(); + if (iter.hasNext()) { + Map.Entry entry = iter.next(); + String coin = entry.getKey(); + JsonNode marketInfoData = entry.getValue(); + boolean delisted = marketInfoData.path(DELISTED).asInt() == 1; + boolean withdrawDisabled = marketInfoData.path(WITHDRAW_DISABLED).asInt() == 1; + boolean withdrawDelayed = marketInfoData.path(WITHDRAW_DELAYED).asInt() == 1; + boolean depositDisabled = marketInfoData.path(DEPOSIT_DISABLED).asInt() == 1; + boolean tradeDisabled = marketInfoData.path(TRADE_DISABLED).asInt() == 1; + GateioCoin gateioCoin = + new GateioCoin( + delisted, withdrawDisabled, withdrawDelayed, depositDisabled, tradeDisabled); + gateioCoinInfoMap.put(coin, gateioCoin); + } else { + throw new ExchangeException( + "Invalid coin info response received from Gateio." + coinsNodeWrapper); + } + } + } else { + throw new ExchangeException( + "Invalid coin info response received from Gateio." + coinsNodeWrapper); + } + + return new GateioCoinInfoWrapper(gateioCoinInfoMap); + } + } +} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioCurrencyChain.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioCurrencyChain.java new file mode 100644 index 00000000000..47faa37706d --- /dev/null +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioCurrencyChain.java @@ -0,0 +1,44 @@ +package org.knowm.xchange.gateio.dto.marketdata; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Builder; +import lombok.Data; +import lombok.extern.jackson.Jacksonized; + +@Data +@Builder +@Jacksonized +public class GateioCurrencyChain { + + @JsonProperty("chain") + String chain; + + @JsonProperty("name_cn") + String chainNameCN; + + @JsonProperty("name_en") + String chainNameEN; + + @JsonProperty("is_disabled") + Boolean disabled; + + @JsonProperty("is_deposit_disabled") + Boolean depositDisabled; + + @JsonProperty("is_withdraw_disabled") + Boolean withdrawDisabled; + + public boolean isWithdrawEnabled() { + return (withdrawDisabled != null) && !withdrawDisabled; + } + + public boolean isDepositEnabled() { + return (depositDisabled != null) && !depositDisabled; + } + + public boolean isEnabled() { + return (disabled != null) && !disabled; + } + + +} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioCurrencyInfo.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioCurrencyInfo.java new file mode 100644 index 00000000000..2810aa20199 --- /dev/null +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioCurrencyInfo.java @@ -0,0 +1,44 @@ +package org.knowm.xchange.gateio.dto.marketdata; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Builder; +import lombok.Data; +import lombok.extern.jackson.Jacksonized; + +@Data +@Builder +@Jacksonized +public class GateioCurrencyInfo { + + @JsonProperty("currency") + String currency; + + @JsonProperty("delisted") + Boolean delisted; + + @JsonProperty("withdraw_disabled") + Boolean withdrawDisabled; + + @JsonProperty("withdraw_delayed") + Boolean withdrawDelayed; + + @JsonProperty("deposit_disabled") + Boolean depositDisabled; + + @JsonProperty("trade_disabled") + Boolean tradeDisabled; + + @JsonProperty("chain") + String chain; + + + public boolean isWithdrawEnabled() { + return (withdrawDisabled != null) && !withdrawDisabled; + } + + + public boolean isDepositEnabled() { + return (depositDisabled != null) && !depositDisabled; + } + +} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioCurrencyPairs.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioCurrencyPairs.java new file mode 100644 index 00000000000..ad90dfc8789 --- /dev/null +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioCurrencyPairs.java @@ -0,0 +1,55 @@ +package org.knowm.xchange.gateio.dto.marketdata; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.ObjectCodec; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import java.io.IOException; +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; +import org.knowm.xchange.gateio.GateioAdapters; +import org.knowm.xchange.gateio.dto.marketdata.GateioCurrencyPairs.BTERCurrencyPairsDeserializer; +import org.knowm.xchange.instrument.Instrument; + +@JsonDeserialize(using = BTERCurrencyPairsDeserializer.class) +public class GateioCurrencyPairs { + + private final Set pairs; + + private GateioCurrencyPairs(Set pairs) { + + this.pairs = pairs; + } + + public Collection getPairs() { + + return pairs; + } + + @Override + public String toString() { + + return "GateioCurrencyPairs [pairs=" + pairs + "]"; + } + + static class BTERCurrencyPairsDeserializer extends JsonDeserializer { + + @Override + public GateioCurrencyPairs deserialize(JsonParser jp, DeserializationContext ctxt) + throws IOException { + + final Set pairs = new HashSet<>(); + final ObjectCodec oc = jp.getCodec(); + final JsonNode node = oc.readTree(jp); + if (node.isArray()) { + for (JsonNode pairNode : node) { + pairs.add(GateioAdapters.adaptCurrencyPair(pairNode.asText())); + } + } + return new GateioCurrencyPairs(pairs); + } + } +} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioDepth.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioDepth.java new file mode 100644 index 00000000000..61ca16c81d9 --- /dev/null +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioDepth.java @@ -0,0 +1,44 @@ +package org.knowm.xchange.gateio.dto.marketdata; + +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.List; +import org.knowm.xchange.gateio.dto.GateioBaseResponse; + +/** Data object representing depth from Bter */ +public class GateioDepth extends GateioBaseResponse { + + private final List asks; + private final List bids; + + /** + * Constructor + * + * @param asks + * @param bids + */ + private GateioDepth( + @JsonProperty("asks") List asks, + @JsonProperty("bids") List bids, + @JsonProperty("result") boolean result) { + + super(result, null); + this.asks = asks; + this.bids = bids; + } + + public List getAsks() { + + return asks; + } + + public List getBids() { + + return bids; + } + + @Override + public String toString() { + + return "GateioDepth [asks=" + asks.toString() + ", bids=" + bids.toString() + "]"; + } +} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioFeeInfo.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioFeeInfo.java new file mode 100644 index 00000000000..f7c45f54857 --- /dev/null +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioFeeInfo.java @@ -0,0 +1,190 @@ +package org.knowm.xchange.gateio.dto.marketdata; + +import com.fasterxml.jackson.annotation.JsonProperty; +import java.math.BigDecimal; + +public class GateioFeeInfo { + + private final int no; + private final String symbol; + private final String name; + private final String nameCn; + private final String feeUsdt; + private final String feeBtc; + private final String feeEth; + private final String deposit; + private final String withdrawPercent; + private final String withdrawFix; + private final String withdrawDayLimit; + private final BigDecimal withdrawAmountMini; + private final BigDecimal withdrawDayLimitRemain; + private final BigDecimal withdrawEachTimeLimit; + private final BigDecimal withdrawFixOnChainEth; + private final BigDecimal withdrawFixOnChainBtc; + private final BigDecimal withdrawFixOnChainTrx; + private final BigDecimal withdrawFixOnChainEos; + + public GateioFeeInfo( + @JsonProperty("no") int no, + @JsonProperty("symbol") String symbol, + @JsonProperty("name") String name, + @JsonProperty("name_cn") String nameCn, + @JsonProperty("fee_usdt") String feeUsdt, + @JsonProperty("fee_btc") String feeBtc, + @JsonProperty("fee_eth") String feeEth, + @JsonProperty("deposit") String deposit, + @JsonProperty("withdraw_percent") String withdrawPercent, + @JsonProperty("withdraw_fix") String withdrawFix, + @JsonProperty("withdraw_day_limit") String withdrawDayLimit, + @JsonProperty("withdraw_amount_mini") BigDecimal withdrawAmountMini, + @JsonProperty("withdraw_day_limit_remain") BigDecimal withdrawDayLimitRemain, + @JsonProperty("withdraw_eachtime_limit") BigDecimal withdrawEachTimeLimit, + @JsonProperty("withdraw_fix_on_chain_ETH") BigDecimal withdrawFixOnChainEth, + @JsonProperty("withdraw_fix_on_chain_BTC") BigDecimal withdrawFixOnChainBtc, + @JsonProperty("withdraw_fix_on_chain_TRX") BigDecimal withdrawFixOnChainTrx, + @JsonProperty("withdraw_fix_on_chain_EOS") BigDecimal withdrawFixOnChainEos) { + + this.no = no; + this.symbol = symbol; + this.name = name; + this.nameCn = nameCn; + this.feeUsdt = feeUsdt; + this.feeBtc = feeBtc; + this.feeEth = feeEth; + this.deposit = deposit; + this.withdrawPercent = withdrawPercent; + this.withdrawFix = withdrawFix; + this.withdrawDayLimit = withdrawDayLimit; + this.withdrawAmountMini = withdrawAmountMini; + this.withdrawDayLimitRemain = withdrawDayLimitRemain; + this.withdrawEachTimeLimit = withdrawEachTimeLimit; + this.withdrawFixOnChainEth = withdrawFixOnChainEth; + this.withdrawFixOnChainBtc = withdrawFixOnChainBtc; + this.withdrawFixOnChainTrx = withdrawFixOnChainTrx; + this.withdrawFixOnChainEos = withdrawFixOnChainEos; + } + + @Override + public String toString() { + return "GateioFeeInfo{" + + "no=" + + no + + ", symbol='" + + symbol + + '\'' + + ", name='" + + name + + '\'' + + ", nameCn='" + + nameCn + + '\'' + + ", feeUsdt='" + + feeUsdt + + '\'' + + ", feeBtc='" + + feeBtc + + '\'' + + ", feeEth='" + + feeEth + + '\'' + + ", deposit='" + + deposit + + '\'' + + ", withdrawPercent='" + + withdrawPercent + + '\'' + + ", withdrawFix='" + + withdrawFix + + '\'' + + ", withdrawDayLimit='" + + withdrawDayLimit + + '\'' + + ", withdrawAmountMini=" + + withdrawAmountMini + + ", withdrawDayLimitRemain=" + + withdrawDayLimitRemain + + ", withdrawEachTimeLimit=" + + withdrawEachTimeLimit + + ", withdrawFixOnChainEth=" + + withdrawFixOnChainEth + + ", withdrawFixOnChainBtc=" + + withdrawFixOnChainBtc + + ", withdrawFixOnChainTrx=" + + withdrawFixOnChainTrx + + ", withdrawFixOnChainEos=" + + withdrawFixOnChainEos + + '}'; + } + + public int getNo() { + return no; + } + + public String getSymbol() { + return symbol; + } + + public String getName() { + return name; + } + + public String getNameCn() { + return nameCn; + } + + public String getFeeUsdt() { + return feeUsdt; + } + + public String getFeeBtc() { + return feeBtc; + } + + public String getFeeEth() { + return feeEth; + } + + public String getDeposit() { + return deposit; + } + + public String getWithdrawPercent() { + return withdrawPercent; + } + + public String getWithdrawFix() { + return withdrawFix; + } + + public String getWithdrawDayLimit() { + return withdrawDayLimit; + } + + public BigDecimal getWithdrawAmountMini() { + return withdrawAmountMini; + } + + public BigDecimal getWithdrawDayLimitRemain() { + return withdrawDayLimitRemain; + } + + public BigDecimal getWithdrawEachTimeLimit() { + return withdrawEachTimeLimit; + } + + public BigDecimal getWithdrawFixOnChainEth() { + return withdrawFixOnChainEth; + } + + public BigDecimal getWithdrawFixOnChainBtc() { + return withdrawFixOnChainBtc; + } + + public BigDecimal getWithdrawFixOnChainTrx() { + return withdrawFixOnChainTrx; + } + + public BigDecimal getWithdrawFixOnChainEos() { + return withdrawFixOnChainEos; + } +} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioKline.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioKline.java new file mode 100644 index 00000000000..030f1542512 --- /dev/null +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioKline.java @@ -0,0 +1,54 @@ +package org.knowm.xchange.gateio.dto.marketdata; + +import java.math.BigDecimal; + +public class GateioKline { + + private final long id; + private final BigDecimal open; + private final BigDecimal close; + private final BigDecimal low; + private final BigDecimal high; + private final BigDecimal vol; + + public GateioKline( + long id, BigDecimal vol, BigDecimal close, BigDecimal high, BigDecimal low, BigDecimal open) { + this.id = id; + this.open = open; + this.close = close; + this.low = low; + this.high = high; + this.vol = vol; + } + + @Override + public String toString() { + return String.format( + "[id = %d, open = %f, close = %f, low = %f, high = %f, vol = %f]", + getId(), getOpen(), getClose(), getLow(), getHigh(), getVol()); + } + + public long getId() { + return id; + } + + public BigDecimal getOpen() { + return open; + } + + public BigDecimal getClose() { + return close; + } + + public BigDecimal getLow() { + return low; + } + + public BigDecimal getHigh() { + return high; + } + + public BigDecimal getVol() { + return vol; + } +} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioKlineInterval.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioKlineInterval.java new file mode 100644 index 00000000000..49c0738edd6 --- /dev/null +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioKlineInterval.java @@ -0,0 +1,36 @@ +package org.knowm.xchange.gateio.dto.marketdata; + +import static java.util.concurrent.TimeUnit.DAYS; +import static java.util.concurrent.TimeUnit.HOURS; +import static java.util.concurrent.TimeUnit.MINUTES; +import static java.util.concurrent.TimeUnit.SECONDS; + +public enum GateioKlineInterval { + s10("10s", SECONDS.toSeconds(10)), + m1("1m", MINUTES.toSeconds(1)), + m5("5m", MINUTES.toSeconds(5)), + m15("15m", MINUTES.toSeconds(15)), + m30("30m", MINUTES.toSeconds(30)), + h1("1h", HOURS.toSeconds(1)), + h4("4h", HOURS.toSeconds(4)), + h8("8h", HOURS.toSeconds(8)), + + d1("1d", DAYS.toSeconds(1)), + w1("7d", DAYS.toSeconds(7)); + + private final String code; + private final Long seconds; + + private GateioKlineInterval(String code, Long seconds) { + this.seconds = seconds; + this.code = code; + } + + public Long getSeconds() { + return seconds; + } + + public String code() { + return code; + } +} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioMarketInfoWrapper.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioMarketInfoWrapper.java new file mode 100644 index 00000000000..819ce7fa203 --- /dev/null +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioMarketInfoWrapper.java @@ -0,0 +1,92 @@ +package org.knowm.xchange.gateio.dto.marketdata; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.ObjectCodec; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import java.io.IOException; +import java.math.BigDecimal; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Map.Entry; +import lombok.Value; +import org.knowm.xchange.currency.CurrencyPair; +import org.knowm.xchange.exceptions.ExchangeException; +import org.knowm.xchange.gateio.GateioAdapters; +import org.knowm.xchange.gateio.dto.marketdata.GateioMarketInfoWrapper.BTERMarketInfoWrapperDeserializer; + +@JsonDeserialize(using = BTERMarketInfoWrapperDeserializer.class) +public class GateioMarketInfoWrapper { + + private final Map marketInfoMap; + + private GateioMarketInfoWrapper(Map marketInfoMap) { + + this.marketInfoMap = marketInfoMap; + } + + public Map getMarketInfoMap() { + + return marketInfoMap; + } + + @Override + public String toString() { + + return "GateioMarketInfoWrapper [marketInfoMap=" + marketInfoMap + "]"; + } + + @Value + public static class GateioMarketInfo { + + CurrencyPair currencyPair; + int decimalPlaces; + BigDecimal minAmount; + BigDecimal fee; + + } + + static class BTERMarketInfoWrapperDeserializer extends JsonDeserializer { + + @Override + public GateioMarketInfoWrapper deserialize(JsonParser jp, DeserializationContext ctxt) + throws IOException, JsonProcessingException { + + Map marketInfoMap = new HashMap<>(); + + ObjectCodec oc = jp.getCodec(); + JsonNode marketsNodeWrapper = oc.readTree(jp); + JsonNode marketNodeList = marketsNodeWrapper.path("pairs"); + + if (marketNodeList.isArray()) { + for (JsonNode marketNode : marketNodeList) { + Iterator> iter = marketNode.fields(); + if (iter.hasNext()) { + Entry entry = iter.next(); + CurrencyPair currencyPair = GateioAdapters.adaptCurrencyPair(entry.getKey()); + JsonNode marketInfoData = entry.getValue(); + int decimalPlaces = marketInfoData.path("decimal_places").asInt(); + BigDecimal minAmount = new BigDecimal(marketInfoData.path("min_amount").asText()); + BigDecimal fee = new BigDecimal(marketInfoData.path("fee").asText()); + GateioMarketInfo marketInfoObject = + new GateioMarketInfo(currencyPair, decimalPlaces, minAmount, fee); + + marketInfoMap.put(currencyPair, marketInfoObject); + } else { + throw new ExchangeException( + "Invalid market info response received from Gateio." + marketsNodeWrapper); + } + } + } else { + throw new ExchangeException( + "Invalid market info response received from Gateio." + marketsNodeWrapper); + } + + return new GateioMarketInfoWrapper(marketInfoMap); + } + } +} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioOrderBook.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioOrderBook.java new file mode 100644 index 00000000000..e55129efc68 --- /dev/null +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioOrderBook.java @@ -0,0 +1,45 @@ +package org.knowm.xchange.gateio.dto.marketdata; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.math.BigDecimal; +import java.time.Instant; +import java.util.List; +import lombok.Builder; +import lombok.Data; +import lombok.extern.jackson.Jacksonized; + +@Data +@Builder +@Jacksonized +public class GateioOrderBook { + + @JsonProperty("id") + Long id; + + @JsonProperty("current") + Instant generatedAt; + + @JsonProperty("update") + Instant updatedAt; + + @JsonProperty("asks") + List asks; + + @JsonProperty("bids") + List bids; + + + @Data + @Builder + @Jacksonized + @JsonFormat(shape = JsonFormat.Shape.ARRAY) + public static class PriceSizeEntry { + + BigDecimal price; + + BigDecimal size; + + } + +} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioPublicOrder.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioPublicOrder.java new file mode 100644 index 00000000000..3d15ff48a61 --- /dev/null +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioPublicOrder.java @@ -0,0 +1,57 @@ +package org.knowm.xchange.gateio.dto.marketdata; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.ObjectCodec; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import java.io.IOException; +import java.math.BigDecimal; +import org.knowm.xchange.gateio.dto.marketdata.GateioPublicOrder.GateioPublicOrderDeserializer; + +@JsonDeserialize(using = GateioPublicOrderDeserializer.class) +public class GateioPublicOrder { + + private final BigDecimal price; + private final BigDecimal amount; + + private GateioPublicOrder(BigDecimal price, final BigDecimal amount) { + + this.price = price; + this.amount = amount; + } + + public BigDecimal getPrice() { + + return price; + } + + public BigDecimal getAmount() { + + return amount; + } + + @Override + public String toString() { + + return "GateioPublicOrder [price=" + price + ", amount=" + amount + "]"; + } + + static class GateioPublicOrderDeserializer extends JsonDeserializer { + + @Override + public GateioPublicOrder deserialize(JsonParser jp, DeserializationContext ctxt) + throws IOException, JsonProcessingException { + + final ObjectCodec oc = jp.getCodec(); + final JsonNode tickerNode = oc.readTree(jp); + + final BigDecimal price = new BigDecimal(tickerNode.path(0).asText()); + final BigDecimal amount = new BigDecimal(tickerNode.path(1).asText()); + + return new GateioPublicOrder(price, amount); + } + } +} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioTicker.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioTicker.java new file mode 100644 index 00000000000..621e798a2ee --- /dev/null +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioTicker.java @@ -0,0 +1,118 @@ +package org.knowm.xchange.gateio.dto.marketdata; + +import com.fasterxml.jackson.annotation.JsonProperty; +import java.math.BigDecimal; +import org.knowm.xchange.gateio.dto.GateioBaseResponse; + +public class GateioTicker extends GateioBaseResponse { + private BigDecimal highestBid; + + private boolean result; + + private BigDecimal low24hr; + + private BigDecimal last; + + private BigDecimal high24hr; + + private BigDecimal percentChange; + + private BigDecimal lowestAsk; + + private BigDecimal quoteVolume; + + private BigDecimal baseVolume; + + public GateioTicker( + @JsonProperty("result") boolean result, + @JsonProperty("message") String message, + @JsonProperty("highestBid") BigDecimal highestBid, + @JsonProperty("low24hr") BigDecimal low24hr, + @JsonProperty("last") BigDecimal last, + @JsonProperty("high24hr") BigDecimal high24hr, + @JsonProperty("percentChange") BigDecimal percentChange, + @JsonProperty("lowestAsk") BigDecimal lowestAsk, + @JsonProperty("quoteVolume") BigDecimal quoteVolume, + @JsonProperty("baseVolume") BigDecimal baseVolume) { + super(result, message); + this.highestBid = highestBid; + this.result = result; + this.low24hr = low24hr; + this.last = last; + this.high24hr = high24hr; + this.percentChange = percentChange; + this.lowestAsk = lowestAsk; + this.quoteVolume = quoteVolume; + this.baseVolume = baseVolume; + } + + public BigDecimal getHighestBid() { + return highestBid; + } + + @Override + public boolean isResult() { + return result; + } + + public BigDecimal getLow24hr() { + return low24hr; + } + + public BigDecimal getLast() { + return last; + } + + public BigDecimal getHigh24hr() { + return high24hr; + } + + public BigDecimal getPercentChange() { + return percentChange; + } + + public BigDecimal getLowestAsk() { + return lowestAsk; + } + + public BigDecimal getQuoteVolume() { + return quoteVolume; + } + + public BigDecimal getBaseVolume() { + return baseVolume; + } + + @Override + public String toString() { + return "GateioTicker{" + + "highestBid='" + + highestBid + + '\'' + + ", result='" + + result + + '\'' + + ", low24hr='" + + low24hr + + '\'' + + ", last='" + + last + + '\'' + + ", high24hr='" + + high24hr + + '\'' + + ", percentChange='" + + percentChange + + '\'' + + ", lowestAsk='" + + lowestAsk + + '\'' + + ", quoteVolume='" + + quoteVolume + + '\'' + + ", baseVolume='" + + baseVolume + + '\'' + + '}'; + } +} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioTradeHistory.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioTradeHistory.java new file mode 100644 index 00000000000..c1b0998dc08 --- /dev/null +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioTradeHistory.java @@ -0,0 +1,104 @@ +package org.knowm.xchange.gateio.dto.marketdata; + +import com.fasterxml.jackson.annotation.JsonProperty; +import java.math.BigDecimal; +import java.util.List; +import org.knowm.xchange.gateio.dto.GateioBaseResponse; +import org.knowm.xchange.gateio.dto.GateioOrderType; + +public class GateioTradeHistory extends GateioBaseResponse { + + private final List trades; + private final String elapsed; + + private GateioTradeHistory( + @JsonProperty("data") List trades, + @JsonProperty("result") boolean result, + @JsonProperty("elapsed") String elapsed) { + + super(result, null); + this.trades = trades; + this.elapsed = elapsed; + } + + public List getTrades() { + + return trades; + } + + public String getElapsed() { + + return elapsed; + } + + @Override + public String toString() { + + return "BTERPublicTrades [trades=" + trades + ", elapsed=" + elapsed + "]"; + } + + public static class GateioPublicTrade { + + private final long date; + private final BigDecimal price; + private final BigDecimal amount; + private final String tradeId; + private final GateioOrderType type; + + private GateioPublicTrade( + @JsonProperty("date") String date, + @JsonProperty("rate") BigDecimal price, + @JsonProperty("amount") BigDecimal amount, + @JsonProperty("tradeID") String tradeId, + @JsonProperty("timestamp") long timestamp, + @JsonProperty("type") GateioOrderType type) { + + this.date = timestamp; + this.price = price; + this.amount = amount; + this.tradeId = tradeId; + this.type = type; + } + + public long getDate() { + + return date; + } + + public BigDecimal getPrice() { + + return price; + } + + public BigDecimal getAmount() { + + return amount; + } + + public String getTradeId() { + + return tradeId; + } + + public GateioOrderType getType() { + + return type; + } + + @Override + public String toString() { + + return "BTERPublicTrade [date=" + + date + + ", price=" + + price + + ", amount=" + + amount + + ", tradeId=" + + tradeId + + ", type=" + + type + + "]"; + } + } +} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/GateioOpenOrder.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/GateioOpenOrder.java new file mode 100644 index 00000000000..49e2c5f91dc --- /dev/null +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/GateioOpenOrder.java @@ -0,0 +1,116 @@ +package org.knowm.xchange.gateio.dto.trade; + +import com.fasterxml.jackson.annotation.JsonProperty; +import java.math.BigDecimal; + +public class GateioOpenOrder { + + private String timestamp; + + private String total; + + private BigDecimal amount; + + private String id; + + private BigDecimal rate; + + private String status; + + private String orderNumber; + + private String type; + + private String currencyPair; + + /** Constructor */ + private GateioOpenOrder( + @JsonProperty("timestamp") String timestamp, + @JsonProperty("total") String total, + @JsonProperty("amount") BigDecimal amount, + @JsonProperty("id") String id, + @JsonProperty("rate") BigDecimal rate, + @JsonProperty("status") String status, + @JsonProperty("orderNumber") String orderNumber, + @JsonProperty("type") String type, + @JsonProperty("currencyPair") String currencyPair) { + this.timestamp = timestamp; + this.total = total; + this.amount = amount; + this.id = id; + this.rate = rate; + this.status = status; + this.orderNumber = orderNumber; + this.type = type; + this.currencyPair = currencyPair; + } + + public String getTimestamp() { + return timestamp; + } + + public String getTotal() { + return total; + } + + public BigDecimal getAmount() { + return amount; + } + + public String getId() { + return id; + } + + public BigDecimal getRate() { + return rate; + } + + public String getStatus() { + return status; + } + + public String getOrderNumber() { + return orderNumber; + } + + public String getType() { + return type; + } + + public String getCurrencyPair() { + return currencyPair; + } + + @Override + public String toString() { + return "GateioOpenOrder{" + + "timestamp='" + + timestamp + + '\'' + + ", total='" + + total + + '\'' + + ", amount='" + + amount + + '\'' + + ", id='" + + id + + '\'' + + ", rate='" + + rate + + '\'' + + ", status='" + + status + + '\'' + + ", orderNumber='" + + orderNumber + + '\'' + + ", type='" + + type + + '\'' + + ", currencyPair='" + + currencyPair + + '\'' + + '}'; + } +} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/GateioOpenOrders.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/GateioOpenOrders.java new file mode 100644 index 00000000000..bcb0f6ccbea --- /dev/null +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/GateioOpenOrders.java @@ -0,0 +1,38 @@ +package org.knowm.xchange.gateio.dto.trade; + +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.List; +import org.knowm.xchange.gateio.dto.GateioBaseResponse; + +/** Created by David Henry on 2/19/14. */ +public class GateioOpenOrders extends GateioBaseResponse { + + private final List orders; + + /** + * Constructor + * + * @param result + * @param orders + * @param msg + */ + public GateioOpenOrders( + @JsonProperty("result") Boolean result, + @JsonProperty("orders") List orders, + @JsonProperty("msg") String msg) { + + super(result, msg); + this.orders = orders; + } + + public List getOrders() { + + return orders; + } + + @Override + public String toString() { + + return "BTEROpenOrdersReturn [orders=" + orders + "]"; + } +} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/GateioOrderStatus.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/GateioOrderStatus.java new file mode 100644 index 00000000000..1db94be74ff --- /dev/null +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/GateioOrderStatus.java @@ -0,0 +1,162 @@ +package org.knowm.xchange.gateio.dto.trade; + +import com.fasterxml.jackson.annotation.JsonProperty; +import java.math.BigDecimal; +import org.knowm.xchange.currency.CurrencyPair; +import org.knowm.xchange.gateio.GateioAdapters; +import org.knowm.xchange.gateio.dto.GateioBaseResponse; +import org.knowm.xchange.gateio.dto.GateioOrderType; + +/** Created by David Henry on 2/19/14. */ +public class GateioOrderStatus extends GateioBaseResponse { + + private final BTEROrderStatusInfo orderStatusInfo; + + private GateioOrderStatus( + @JsonProperty("order") BTEROrderStatusInfo orderStatusInfo, + @JsonProperty("result") boolean result, + @JsonProperty("message") String msg) { + + super(result, msg); + this.orderStatusInfo = orderStatusInfo; + } + + public String getOrderNumber() { + + return orderStatusInfo.getOrderNumber(); + } + + public String getStatus() { + + return orderStatusInfo.getStatus(); + } + + public CurrencyPair getCurrencyPair() { + + return orderStatusInfo.getCurrencyPair(); + } + + public GateioOrderType getType() { + + return orderStatusInfo.getType(); + } + + public BigDecimal getRate() { + + return orderStatusInfo.getRate(); + } + + public BigDecimal getAmount() { + + return orderStatusInfo.getAmount(); + } + + public BigDecimal getInitialRate() { + + return orderStatusInfo.getInitialRate(); + } + + public BigDecimal getInitialAmount() { + + return orderStatusInfo.getInitialAmount(); + } + + public String toString() { + + return orderStatusInfo.toString(); + } + + public static class BTEROrderStatusInfo { + + private final String orderNumber; + private final String status; + private final CurrencyPair currencyPair; + private final GateioOrderType type; + private final BigDecimal rate; + private final BigDecimal amount; + private final BigDecimal initialRate; + private final BigDecimal initialAmount; + + private BTEROrderStatusInfo( + @JsonProperty("orderNumber") String orderNumber, + @JsonProperty("status") String status, + @JsonProperty("currencyPair") String currencyPair, + @JsonProperty("type") GateioOrderType type, + @JsonProperty("rate") BigDecimal rate, + @JsonProperty("amount") BigDecimal amount, + @JsonProperty("initialRate") BigDecimal initialRate, + @JsonProperty("initialAmount") BigDecimal initialAmount) { + + this.orderNumber = orderNumber; + this.status = status; + this.currencyPair = GateioAdapters.adaptCurrencyPair(currencyPair); + this.type = type; + this.rate = rate; + this.amount = amount; + this.initialRate = initialRate; + this.initialAmount = initialAmount; + } + + public String getOrderNumber() { + + return orderNumber; + } + + public String getStatus() { + + return status; + } + + public CurrencyPair getCurrencyPair() { + + return currencyPair; + } + + public GateioOrderType getType() { + + return type; + } + + public BigDecimal getRate() { + + return rate; + } + + public BigDecimal getAmount() { + + return amount; + } + + public BigDecimal getInitialRate() { + + return initialRate; + } + + public BigDecimal getInitialAmount() { + + return initialAmount; + } + + @Override + public String toString() { + + return "BTEROrderStatusInfo [id=" + + orderNumber + + ", status=" + + status + + ", currencyPair=" + + currencyPair + + ", type=" + + type + + ", rate=" + + rate + + ", amount=" + + amount + + ", initialRate=" + + initialRate + + ", initialAmount=" + + initialAmount + + "]"; + } + } +} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/GateioPlaceOrderReturn.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/GateioPlaceOrderReturn.java new file mode 100644 index 00000000000..5d1f5fc96cd --- /dev/null +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/GateioPlaceOrderReturn.java @@ -0,0 +1,30 @@ +package org.knowm.xchange.gateio.dto.trade; + +import com.fasterxml.jackson.annotation.JsonProperty; +import org.knowm.xchange.gateio.dto.GateioBaseResponse; + +public class GateioPlaceOrderReturn extends GateioBaseResponse { + + private final String orderNumber; + + /** Constructor */ + private GateioPlaceOrderReturn( + @JsonProperty("result") boolean result, + @JsonProperty("orderNumber") String orderNumber, + @JsonProperty("msg") String message) { + + super(result, message); + this.orderNumber = orderNumber; + } + + public String getOrderId() { + + return orderNumber; + } + + @Override + public String toString() { + + return "GateioPlaceOrderReturn [orderNumber=" + orderNumber + "]"; + } +} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/GateioTrade.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/GateioTrade.java new file mode 100644 index 00000000000..ff2b388d1d8 --- /dev/null +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/GateioTrade.java @@ -0,0 +1,122 @@ +package org.knowm.xchange.gateio.dto.trade; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import java.math.BigDecimal; +import java.util.HashMap; +import java.util.Map; +import javax.annotation.Generated; +import org.knowm.xchange.gateio.dto.GateioOrderType; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@Generated("org.jsonschema2pojo") +@JsonPropertyOrder({"tradeID", "orderNumber", "pair", "type", "rate", "amount", "time_unix"}) +public class GateioTrade { + + @JsonProperty("tradeID") + private String tradeID; + + @JsonProperty("orderNumber") + private String orderNumber; + + @JsonProperty("pair") + private String pair; + + @JsonProperty("type") + private GateioOrderType type; + + @JsonProperty("rate") + private BigDecimal rate; + + @JsonProperty("amount") + private BigDecimal amount; + + @JsonProperty("time_unix") + private long timeUnix; + + @JsonIgnore private Map additionalProperties = new HashMap(); + + @JsonProperty("tradeID") + public String getTradeID() { + return tradeID; + } + + @JsonProperty("tradeID") + public void setTradeID(String tradeID) { + this.tradeID = tradeID; + } + + @JsonProperty("orderNumber") + public String getOrderNumber() { + return orderNumber; + } + + @JsonProperty("orderNumber") + public void setOrderNumber(String orderNumber) { + this.orderNumber = orderNumber; + } + + @JsonProperty("pair") + public String getPair() { + return pair; + } + + @JsonProperty("pair") + public void setPair(String pair) { + this.pair = pair; + } + + @JsonProperty("type") + public GateioOrderType getType() { + return type; + } + + @JsonProperty("type") + public void setType(GateioOrderType type) { + this.type = type; + } + + @JsonProperty("rate") + public BigDecimal getRate() { + return rate; + } + + @JsonProperty("rate") + public void setRate(BigDecimal rate) { + this.rate = rate; + } + + @JsonProperty("amount") + public BigDecimal getAmount() { + return amount; + } + + @JsonProperty("amount") + public void setAmount(BigDecimal amount) { + this.amount = amount; + } + + @JsonProperty("time_unix") + public long getTimeUnix() { + return timeUnix; + } + + @JsonProperty("time_unix") + public void setTimeUnix(long timeUnix) { + this.timeUnix = timeUnix; + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + @JsonAnySetter + public void setAdditionalProperty(String name, Object value) { + this.additionalProperties.put(name, value); + } +} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/GateioTradeHistoryReturn.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/GateioTradeHistoryReturn.java new file mode 100644 index 00000000000..dbd3c802ba9 --- /dev/null +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/GateioTradeHistoryReturn.java @@ -0,0 +1,88 @@ +package org.knowm.xchange.gateio.dto.trade; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import javax.annotation.Generated; +import org.knowm.xchange.gateio.dto.GateioBaseResponse; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@Generated("org.jsonschema2pojo") +@JsonPropertyOrder({"result", "trades", "msg"}) +public class GateioTradeHistoryReturn extends GateioBaseResponse { + + @JsonProperty("result") + private Boolean result; + + @JsonProperty("trades") + private List trades = new ArrayList(); + + @JsonProperty("msg") + private String msg; + + @JsonIgnore private Map additionalProperties = new HashMap(); + + protected GateioTradeHistoryReturn( + @JsonProperty("result") boolean result, + @JsonProperty("trades") List trades, + @JsonProperty("msg") String message) { + + super(result, message); + this.trades = trades; + } + + @JsonProperty("result") + public Boolean getResult() { + + return result; + } + + @JsonProperty("result") + public void setResult(Boolean result) { + + this.result = result; + } + + @JsonProperty("trades") + public List getTrades() { + + return trades; + } + + @JsonProperty("trades") + public void setTrades(List trades) { + + this.trades = trades; + } + + @JsonProperty("msg") + public String getMsg() { + + return msg; + } + + @JsonProperty("msg") + public void setMsg(String msg) { + + this.msg = msg; + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + + return this.additionalProperties; + } + + @JsonAnySetter + public void setAdditionalProperty(String name, Object value) { + + this.additionalProperties.put(name, value); + } +} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountService.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountService.java new file mode 100644 index 00000000000..a9f0deca250 --- /dev/null +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountService.java @@ -0,0 +1,92 @@ +package org.knowm.xchange.gateio.service; + +import java.io.IOException; +import java.math.BigDecimal; +import java.util.Date; +import java.util.List; +import org.knowm.xchange.currency.Currency; +import org.knowm.xchange.dto.account.AccountInfo; +import org.knowm.xchange.dto.account.FundingRecord; +import org.knowm.xchange.exceptions.NotAvailableFromExchangeException; +import org.knowm.xchange.gateio.GateioAdapters; +import org.knowm.xchange.gateio.GateioExchange; +import org.knowm.xchange.gateio.dto.account.GateioDepositsWithdrawals; +import org.knowm.xchange.service.account.AccountService; +import org.knowm.xchange.service.trade.params.DefaultWithdrawFundsParams; +import org.knowm.xchange.service.trade.params.MoneroWithdrawFundsParams; +import org.knowm.xchange.service.trade.params.RippleWithdrawFundsParams; +import org.knowm.xchange.service.trade.params.TradeHistoryParams; +import org.knowm.xchange.service.trade.params.TradeHistoryParamsTimeSpan; +import org.knowm.xchange.service.trade.params.WithdrawFundsParams; + +public class GateioAccountService extends GateioAccountServiceRaw implements AccountService { + + /** + * Constructor + * + * @param exchange + */ + public GateioAccountService(GateioExchange exchange) { + super(exchange); + } + + @Override + public AccountInfo getAccountInfo() throws IOException { + + return new AccountInfo(GateioAdapters.adaptWallet(super.getGateioAccountInfo())); + } + + @Override + public String withdrawFunds(Currency currency, BigDecimal amount, String address) + throws IOException { + return withdraw(currency.getCurrencyCode(), amount, address); + } + + @Override + public String withdrawFunds(WithdrawFundsParams params) throws IOException { + if (params instanceof RippleWithdrawFundsParams) { + RippleWithdrawFundsParams xrpParams = (RippleWithdrawFundsParams) params; + return withdraw( + xrpParams.getCurrency(), + xrpParams.getAmount(), + xrpParams.getAddress(), + xrpParams.getTag()); + } else if (params instanceof MoneroWithdrawFundsParams) { + MoneroWithdrawFundsParams xmrParams = (MoneroWithdrawFundsParams) params; + return withdraw( + xmrParams.getCurrency(), + xmrParams.getAmount(), + xmrParams.getAddress(), + xmrParams.getPaymentId()); + } else if (params instanceof DefaultWithdrawFundsParams) { + DefaultWithdrawFundsParams defaultParams = (DefaultWithdrawFundsParams) params; + return withdrawFunds( + defaultParams.getCurrency(), defaultParams.getAmount(), defaultParams.getAddress()); + } + throw new IllegalStateException("Don't know how to withdraw: " + params); + } + + @Override + public String requestDepositAddress(Currency currency, String... args) throws IOException { + + return super.getGateioDepositAddress(currency).getBaseAddress(); + } + + @Override + public TradeHistoryParams createFundingHistoryParams() { + throw new NotAvailableFromExchangeException(); + } + + @Override + public List getFundingHistory(TradeHistoryParams params) throws IOException { + Date start = null; + Date end = null; + if (params instanceof TradeHistoryParamsTimeSpan) { + TradeHistoryParamsTimeSpan timeSpan = (TradeHistoryParamsTimeSpan) params; + start = timeSpan.getStartTime(); + end = timeSpan.getEndTime(); + } + GateioDepositsWithdrawals depositsWithdrawals = getDepositsWithdrawals(start, end); + return GateioAdapters.adaptDepositsWithdrawals(depositsWithdrawals); + } +} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountServiceRaw.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountServiceRaw.java new file mode 100644 index 00000000000..06934eeb96e --- /dev/null +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountServiceRaw.java @@ -0,0 +1,83 @@ +package org.knowm.xchange.gateio.service; + +import java.io.IOException; +import java.math.BigDecimal; +import java.util.Date; +import java.util.List; +import org.knowm.xchange.currency.Currency; +import org.knowm.xchange.exceptions.ExchangeException; +import org.knowm.xchange.gateio.GateioExchange; +import org.knowm.xchange.gateio.dto.GateioBaseResponse; +import org.knowm.xchange.gateio.dto.account.GateioDepositAddress; +import org.knowm.xchange.gateio.dto.account.GateioDepositsWithdrawals; +import org.knowm.xchange.gateio.dto.account.GateioFunds; +import org.knowm.xchange.gateio.dto.account.GateioWithdrawStatus; + +public class GateioAccountServiceRaw extends GateioBaseService { + + /** + * Constructor + * + * @param exchange + */ + public GateioAccountServiceRaw(GateioExchange exchange) { + + super(exchange); + } + + public GateioFunds getGateioAccountInfo() throws IOException { + + GateioFunds gateioFunds = + gateioAuthenticated.getFunds(exchange.getExchangeSpecification().getApiKey(), signatureCreator); + return handleResponse(gateioFunds); + } + + public GateioDepositAddress getGateioDepositAddress(Currency currency) throws IOException { + GateioDepositAddress depositAddress = + gateioAuthenticated.getDepositAddress( + exchange.getExchangeSpecification().getApiKey(), + signatureCreator, + currency.getCurrencyCode()); + return depositAddress; + } + + public String withdraw( + Currency currency, BigDecimal amount, String baseAddress, String addressTag) + throws IOException { + String withdrawAddress = baseAddress; + if (addressTag != null && addressTag.length() > 0) { + withdrawAddress = withdrawAddress + " " + addressTag; + } + return withdraw(currency.getCurrencyCode(), amount, withdrawAddress); + } + + public GateioDepositsWithdrawals getDepositsWithdrawals(Date start, Date end) throws IOException { + GateioDepositsWithdrawals gateioDepositsWithdrawals = + gateioAuthenticated.getDepositsWithdrawals( + exchange.getExchangeSpecification().getApiKey(), + signatureCreator, + start == null ? null : start.getTime() / 1000, + end == null ? null : end.getTime() / 1000); + return handleResponse(gateioDepositsWithdrawals); + } + + public String withdraw(String currency, BigDecimal amount, String address) throws IOException { + GateioBaseResponse withdraw = + gateioAuthenticated.withdraw( + exchange.getExchangeSpecification().getApiKey(), + signatureCreator, + currency, + amount, + address); + if (!withdraw.isResult()) { + throw new ExchangeException(withdraw.getMessage()); + } + // unfortunatelly gate.io does not return any id for the withdrawal + return null; + } + + + public List getWithdrawStatus() throws IOException { + return gateioV4Authenticated.getWithdrawStatus(apiKey, exchange.getNonceFactory(), gateioV4ParamsDigest); + } +} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioBaseService.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioBaseService.java new file mode 100644 index 00000000000..46b3448bf0e --- /dev/null +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioBaseService.java @@ -0,0 +1,65 @@ +package org.knowm.xchange.gateio.service; + +import org.knowm.xchange.client.ExchangeRestProxyBuilder; +import org.knowm.xchange.exceptions.ExchangeException; +import org.knowm.xchange.gateio.Gateio; +import org.knowm.xchange.gateio.GateioAuthenticated; +import org.knowm.xchange.gateio.GateioExchange; +import org.knowm.xchange.gateio.GateioV4Authenticated; +import org.knowm.xchange.gateio.dto.GateioBaseResponse; +import org.knowm.xchange.service.BaseExchangeService; +import org.knowm.xchange.service.BaseService; +import si.mazi.rescu.ParamsDigest; + +public class GateioBaseService extends BaseExchangeService implements BaseService { + + protected final String apiKey; + protected final Gateio gateio; + protected final GateioAuthenticated gateioAuthenticated; + protected final GateioV4Authenticated gateioV4Authenticated; + protected final ParamsDigest signatureCreator; + protected final ParamsDigest gateioV4ParamsDigest; + + /** + * Constructor + * + * @param exchange + */ + public GateioBaseService(GateioExchange exchange) { + + super(exchange); + + gateio = ExchangeRestProxyBuilder + .forInterface(Gateio.class, exchange.getExchangeSpecification()) + .clientConfigCustomizer(clientConfig -> clientConfig.setJacksonObjectMapperFactory(new GateioJacksonObjectMapperFactory())) + .build(); + gateioAuthenticated = ExchangeRestProxyBuilder + .forInterface(GateioAuthenticated.class, exchange.getExchangeSpecification()) + .clientConfigCustomizer(clientConfig -> clientConfig.setJacksonObjectMapperFactory(new GateioJacksonObjectMapperFactory())) + .build(); + apiKey = exchange.getExchangeSpecification().getApiKey(); + signatureCreator = + GateioHmacPostBodyDigest.createInstance(exchange.getExchangeSpecification().getSecretKey()); + + gateioV4Authenticated = ExchangeRestProxyBuilder + .forInterface(GateioV4Authenticated.class, exchange.getExchangeSpecification()) + .clientConfigCustomizer(clientConfig -> clientConfig.setJacksonObjectMapperFactory(new GateioJacksonObjectMapperFactory())) + .build(); + + gateioV4ParamsDigest = + GateioV4Digest.createInstance(exchange.getExchangeSpecification().getSecretKey()); + } + + protected R handleResponse(R response) { + + if (!response.isResult()) { + throw new ExchangeException(response.getMessage()); + } + + return response; + } + + public String getApiKey() { + return apiKey; + } +} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioHmacPostBodyDigest.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioHmacPostBodyDigest.java new file mode 100644 index 00000000000..12751003d2d --- /dev/null +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioHmacPostBodyDigest.java @@ -0,0 +1,60 @@ +package org.knowm.xchange.gateio.service; + +import java.io.UnsupportedEncodingException; +import java.math.BigInteger; +import javax.crypto.Mac; +import org.knowm.xchange.service.BaseParamsDigest; +import si.mazi.rescu.RestInvocation; + +/** + * This may be used as the value of a @HeaderParam, @QueryParam or @PathParam to create a digest of + * the post body (composed of @FormParam's). Don't use as the value of a @FormParam, it will + * probably cause an infinite loop. + * + *

This may be used for REST APIs where some parameters' values must be digests of other + * parameters. An example is the MtGox API v1, where the Rest-Sign header parameter must be a digest + * of the request body (which is composed of @FormParams). + */ +public class GateioHmacPostBodyDigest extends BaseParamsDigest { + + /** + * Constructor + * + * @param secretKeyBase64 + * @throws IllegalArgumentException if key is invalid (cannot be base-64-decoded or the decoded + * key is invalid). + */ + private GateioHmacPostBodyDigest(String secretKeyBase64) { + + super(secretKeyBase64, HMAC_SHA_512); + } + + public static GateioHmacPostBodyDigest createInstance(String secretKeyBase64) { + + return secretKeyBase64 == null ? null : new GateioHmacPostBodyDigest(secretKeyBase64); + } + + @Override + public String digestParams(RestInvocation restInvocation) { + + try { + String postBody = restInvocation.getRequestBody(); + + // little hack here. the post body to create the signature mus not contain the url-encoded + // parameters, they must be in plain form + // passing ie the white space inside the withdraw method (required for XLM and XRP ... to pass + // the tag) results in a plus sing '+', which is the correct encoding, but in this case the + // signature is not created correctly. + // the expected signature must be created using plain parameters. here we simply replace the + + // by a white space, should be fine for now + // see https://support.gate.io/hc/en-us/articles/360000808354-How-to-Withdraw-XRP + postBody = postBody.replace('+', ' '); + Mac mac = getMac(); + mac.update(postBody.getBytes("UTF-8")); + return String.format("%0128x", new BigInteger(1, mac.doFinal())); + } catch (UnsupportedEncodingException e) { + throw new RuntimeException("Illegal encoding, check the code.", e); + } + // return Base64.encodeBytes(mac.doFinal()).trim(); + } +} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioJacksonObjectMapperFactory.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioJacksonObjectMapperFactory.java new file mode 100644 index 00000000000..6a7d27aae21 --- /dev/null +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioJacksonObjectMapperFactory.java @@ -0,0 +1,18 @@ +package org.knowm.xchange.gateio.service; + +import static com.fasterxml.jackson.databind.DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; +import si.mazi.rescu.serialization.jackson.DefaultJacksonObjectMapperFactory; + +public class GateioJacksonObjectMapperFactory extends DefaultJacksonObjectMapperFactory { + + @Override + public void configureObjectMapper(ObjectMapper objectMapper) { + super.configureObjectMapper(objectMapper); + objectMapper.configure(READ_DATE_TIMESTAMPS_AS_NANOSECONDS, false); + // enable parsing to Instant + objectMapper.registerModule(new JavaTimeModule()); + } +} 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 new file mode 100644 index 00000000000..b281a6d5ec6 --- /dev/null +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioMarketDataService.java @@ -0,0 +1,101 @@ +package org.knowm.xchange.gateio.service; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; +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.marketdata.Trades; +import org.knowm.xchange.gateio.GateioAdapters; +import org.knowm.xchange.gateio.GateioExchange; +import org.knowm.xchange.gateio.dto.marketdata.GateioDepth; +import org.knowm.xchange.gateio.dto.marketdata.GateioOrderBook; +import org.knowm.xchange.gateio.dto.marketdata.GateioTicker; +import org.knowm.xchange.gateio.dto.marketdata.GateioTradeHistory; +import org.knowm.xchange.instrument.Instrument; +import org.knowm.xchange.service.marketdata.MarketDataService; +import org.knowm.xchange.service.marketdata.params.CurrencyPairsParam; +import org.knowm.xchange.service.marketdata.params.Params; + +public class GateioMarketDataService extends GateioMarketDataServiceRaw + implements MarketDataService { + + /** + * Constructor + * + * @param exchange + */ + public GateioMarketDataService(GateioExchange exchange) { + + super(exchange); + } + + @Override + public Ticker getTicker(CurrencyPair currencyPair, Object... args) throws IOException { + + GateioTicker ticker = + super.getBTERTicker( + currencyPair.base.getCurrencyCode(), currencyPair.counter.getCurrencyCode()); + + return GateioAdapters.adaptTicker(currencyPair, ticker); + } + + @Override + public List getTickers(Params params) throws IOException { + final List currencyPairs = new ArrayList<>(); + if (params instanceof CurrencyPairsParam) { + currencyPairs.addAll(((CurrencyPairsParam) params).getCurrencyPairs()); + } + return getGateioTickers().values().stream() + .filter( + ticker -> currencyPairs.size() == 0 || currencyPairs.contains(ticker.getCurrencyPair())) + .collect(Collectors.toList()); + } + + @Override + public OrderBook getOrderBook(CurrencyPair currencyPair, Object... args) throws IOException { + return getOrderBook((Instrument) currencyPair, args); + } + + @Override + public OrderBook getOrderBook(Instrument instrument, Object... args) throws IOException { + + GateioOrderBook gateioOrderBook = getGateioOrderBook(instrument); + + return GateioAdapters.toOrderBook(gateioOrderBook, instrument); + + } + + public Map getOrderBooks() throws IOException { + + Map gateioDepths = super.getGateioDepths(); + Map orderBooks = new HashMap<>(gateioDepths.size()); + + gateioDepths.forEach( + (currencyPair, gateioDepth) -> { + OrderBook orderBook = GateioAdapters.adaptOrderBook(gateioDepth, currencyPair); + orderBooks.put(currencyPair, orderBook); + }); + + return orderBooks; + } + + @Override + public Trades getTrades(CurrencyPair currencyPair, Object... args) throws IOException { + + GateioTradeHistory tradeHistory = + (args != null && args.length > 0 && args[0] != null && args[0] instanceof String) + ? super.getBTERTradeHistorySince( + currencyPair.base.getCurrencyCode(), + currencyPair.counter.getCurrencyCode(), + (String) args[0]) + : super.getBTERTradeHistory( + currencyPair.base.getCurrencyCode(), currencyPair.counter.getCurrencyCode()); + + return GateioAdapters.adaptTrades(tradeHistory, currencyPair); + } +} 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 new file mode 100644 index 00000000000..3cb33b1dcf6 --- /dev/null +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioMarketDataServiceRaw.java @@ -0,0 +1,167 @@ +package org.knowm.xchange.gateio.service; + +import java.io.IOException; +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; +import org.knowm.xchange.currency.Currency; +import org.knowm.xchange.currency.CurrencyPair; +import org.knowm.xchange.dto.marketdata.Ticker; +import org.knowm.xchange.exceptions.ExchangeException; +import org.knowm.xchange.gateio.GateioAdapters; +import org.knowm.xchange.gateio.GateioExchange; +import org.knowm.xchange.gateio.dto.marketdata.GateioCandlestickHistory; +import org.knowm.xchange.gateio.dto.marketdata.GateioCoinInfoWrapper; +import org.knowm.xchange.gateio.dto.marketdata.GateioCurrencyChain; +import org.knowm.xchange.gateio.dto.marketdata.GateioCurrencyInfo; +import org.knowm.xchange.gateio.dto.marketdata.GateioDepth; +import org.knowm.xchange.gateio.dto.marketdata.GateioFeeInfo; +import org.knowm.xchange.gateio.dto.marketdata.GateioKline; +import org.knowm.xchange.gateio.dto.marketdata.GateioKlineInterval; +import org.knowm.xchange.gateio.dto.marketdata.GateioMarketInfoWrapper; +import org.knowm.xchange.gateio.dto.marketdata.GateioOrderBook; +import org.knowm.xchange.gateio.dto.marketdata.GateioTicker; +import org.knowm.xchange.gateio.dto.marketdata.GateioTradeHistory; +import org.knowm.xchange.instrument.Instrument; + +public class GateioMarketDataServiceRaw extends GateioBaseService { + + /** + * Constructor + * + * @param exchange + */ + public GateioMarketDataServiceRaw(GateioExchange exchange) { + + super(exchange); + } + + public Map getMarketInfo() + throws IOException { + + GateioMarketInfoWrapper bterMarketInfo = gateio.getMarketInfo(); + + return bterMarketInfo.getMarketInfoMap(); + } + + public GateioCoinInfoWrapper getGateioCoinInfo() throws IOException { + return gateio.getCoinInfo(); + } + + public Map getGateioFees() throws IOException { + return gateioAuthenticated.getFeeList(apiKey, signatureCreator); + } + + public Map getGateioTickers() throws IOException { + + Map gateioTickers = gateio.getTickers(); + Map adaptedTickers = new HashMap<>(gateioTickers.size()); + gateioTickers.forEach( + (currencyPairString, gateioTicker) -> { + String[] currencyPairStringSplit = currencyPairString.split("_"); + CurrencyPair currencyPair = + new CurrencyPair( + Currency.getInstance(currencyPairStringSplit[0].toUpperCase()), + Currency.getInstance(currencyPairStringSplit[1].toUpperCase())); + adaptedTickers.put(currencyPair, GateioAdapters.adaptTicker(currencyPair, gateioTicker)); + }); + + return adaptedTickers; + } + + public Map getGateioDepths() throws IOException { + Map depths = gateio.getDepths(); + Map adaptedDepths = new HashMap<>(depths.size()); + depths.forEach( + (currencyPairString, gateioDepth) -> { + String[] currencyPairStringSplit = currencyPairString.split("_"); + CurrencyPair currencyPair = + new CurrencyPair( + Currency.getInstance(currencyPairStringSplit[0].toUpperCase()), + Currency.getInstance(currencyPairStringSplit[1].toUpperCase())); + adaptedDepths.put(currencyPair, gateioDepth); + }); + return adaptedDepths; + } + + public GateioTicker getBTERTicker(String tradableIdentifier, String currency) throws IOException { + + GateioTicker gateioTicker = + gateio.getTicker(tradableIdentifier.toLowerCase(), currency.toLowerCase()); + + return handleResponse(gateioTicker); + } + + public GateioDepth getBTEROrderBook(String tradeableIdentifier, String currency) + throws IOException { + + GateioDepth gateioDepth = + gateio.getFullDepth(tradeableIdentifier.toLowerCase(), currency.toLowerCase()); + + return handleResponse(gateioDepth); + } + + public GateioTradeHistory getBTERTradeHistory(String tradeableIdentifier, String currency) + throws IOException { + + GateioTradeHistory tradeHistory = gateio.getTradeHistory(tradeableIdentifier, currency); + + return handleResponse(tradeHistory); + } + + public GateioTradeHistory getBTERTradeHistorySince( + String tradeableIdentifier, String currency, String tradeId) throws IOException { + + GateioTradeHistory tradeHistory = + gateio.getTradeHistorySince(tradeableIdentifier, currency, tradeId); + + return handleResponse(tradeHistory); + } + + public List getExchangeSymbols() throws IOException { + + return new ArrayList<>(gateio.getPairs().getPairs()); + } + + public List getKlines(CurrencyPair pair, GateioKlineInterval interval, Integer hours) + throws IOException { + + if (hours != null && hours < 1) + throw new ExchangeException("Variable 'hours' should be more than 0!"); + + GateioCandlestickHistory candlestickHistory = + handleResponse( + gateio.getKlinesGate( + pair.toString().replace('/', '_').toLowerCase(), hours, interval.getSeconds())); + + return candlestickHistory.getCandlesticks().stream() + .map( + data -> + new GateioKline( + Long.parseLong(data.get(0)), + new BigDecimal(data.get(1)), + new BigDecimal(data.get(2)), + new BigDecimal(data.get(3)), + new BigDecimal(data.get(4)), + new BigDecimal(data.get(5)))) + .collect(Collectors.toList()); + } + + + public List getCurrencies() { + return gateio.getCurrencies(); + } + + + public GateioOrderBook getGateioOrderBook(Instrument instrument) { + return gateio.getOrderBook(GateioAdapters.toQueryParam(instrument), false); + } + + + public List getCurrencyChains(Currency currency) { + return gateio.getCurrencyChains(currency.getCurrencyCode()); + } +} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeService.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeService.java new file mode 100644 index 00000000000..c2494f5e0b5 --- /dev/null +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeService.java @@ -0,0 +1,155 @@ +package org.knowm.xchange.gateio.service; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import org.knowm.xchange.currency.CurrencyPair; +import org.knowm.xchange.dto.Order; +import org.knowm.xchange.dto.trade.LimitOrder; +import org.knowm.xchange.dto.trade.MarketOrder; +import org.knowm.xchange.dto.trade.OpenOrders; +import org.knowm.xchange.dto.trade.UserTrades; +import org.knowm.xchange.exceptions.ExchangeException; +import org.knowm.xchange.exceptions.NotAvailableFromExchangeException; +import org.knowm.xchange.gateio.GateioAdapters; +import org.knowm.xchange.gateio.GateioExchange; +import org.knowm.xchange.gateio.dto.trade.GateioOpenOrders; +import org.knowm.xchange.gateio.dto.trade.GateioOrderStatus; +import org.knowm.xchange.gateio.dto.trade.GateioTrade; +import org.knowm.xchange.instrument.Instrument; +import org.knowm.xchange.service.trade.TradeService; +import org.knowm.xchange.service.trade.params.CancelOrderByCurrencyPair; +import org.knowm.xchange.service.trade.params.CancelOrderByIdParams; +import org.knowm.xchange.service.trade.params.CancelOrderParams; +import org.knowm.xchange.service.trade.params.DefaultTradeHistoryParamCurrencyPair; +import org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair; +import org.knowm.xchange.service.trade.params.TradeHistoryParams; +import org.knowm.xchange.service.trade.params.orders.DefaultQueryOrderParamCurrencyPair; +import org.knowm.xchange.service.trade.params.orders.OpenOrdersParams; +import org.knowm.xchange.service.trade.params.orders.OrderQueryParams; + +public class GateioTradeService extends GateioTradeServiceRaw implements TradeService { + + /** + * Constructor + * + * @param exchange + */ + public GateioTradeService(GateioExchange exchange) { + + super(exchange); + } + + @Override + public OpenOrders getOpenOrders() throws IOException { + return getOpenOrders(createOpenOrdersParams()); + } + + @Override + public OpenOrders getOpenOrders(OpenOrdersParams params) throws IOException { + GateioOpenOrders openOrders = super.getGateioOpenOrders(); + Collection currencyPairs = exchange.getExchangeInstruments(); + + return GateioAdapters.adaptOpenOrders(openOrders, currencyPairs); + } + + @Override + public String placeMarketOrder(MarketOrder marketOrder) throws IOException { + + throw new NotAvailableFromExchangeException(); + } + + /** + * Submits a Limit Order to be executed on the Gateio Exchange for the desired market defined by + * {@code CurrencyPair}. WARNING - Gateio will return true regardless of whether or not an order + * actually gets created. The reason for this is that orders are simply submitted to a queue in + * their back-end. One example for why an order might not get created is because there are + * insufficient funds. The best attempt you can make to confirm that the order was created is to + * poll {@link #getOpenOrders}. However, if the order is created and executed before it is caught + * in its open state from calling {@link #getOpenOrders} then the only way to confirm would be + * confirm the expected difference in funds available for your account. + * + * @return String "true"/"false" Used to determine if the order request was submitted + * successfully. + */ + @Override + public String placeLimitOrder(LimitOrder limitOrder) throws IOException { + + return String.valueOf(super.placeGateioLimitOrder(limitOrder)); + } + + @Override + public boolean cancelOrder(String orderId) throws IOException { + throw new NotAvailableFromExchangeException(); + } + + @Override + public Class[] getRequiredCancelOrderParamClasses() { + return new Class[] {CancelOrderByIdParams.class, CancelOrderByCurrencyPair.class}; + } + + @Override + public boolean cancelOrder(CancelOrderParams orderParams) throws IOException { + if (orderParams instanceof CancelOrderByIdParams + && orderParams instanceof CancelOrderByCurrencyPair) { + return cancelOrder( + ((CancelOrderByIdParams) orderParams).getOrderId(), + ((CancelOrderByCurrencyPair) orderParams).getCurrencyPair()); + } else { + return false; + } + } + + /** Required parameter: {@link TradeHistoryParamCurrencyPair} */ + @Override + public UserTrades getTradeHistory(TradeHistoryParams params) + throws ExchangeException, IOException { + + CurrencyPair pair = ((TradeHistoryParamCurrencyPair) params).getCurrencyPair(); + List userTrades = getGateioTradeHistory(pair).getTrades(); + + return GateioAdapters.adaptUserTrades(userTrades); + } + + @Override + public Collection getOrder(OrderQueryParams... orderQueryParams) throws IOException { + List orders = new ArrayList<>(); + for (OrderQueryParams param : orderQueryParams) { + if (!(param instanceof DefaultQueryOrderParamCurrencyPair)) { + throw new NotAvailableFromExchangeException("getOrder in gateio needs orderId and currency pair"); + } + DefaultQueryOrderParamCurrencyPair queryOrderParamCurrencyPair = (DefaultQueryOrderParamCurrencyPair) param; + GateioOrderStatus gateioOrderStatus = getGateioOrderStatus( + queryOrderParamCurrencyPair.getOrderId(), + queryOrderParamCurrencyPair.getCurrencyPair() + ); + + LimitOrder limitOrder = new LimitOrder( + GateioAdapters.adaptOrderType(gateioOrderStatus.getType()), + gateioOrderStatus.getInitialAmount(), + gateioOrderStatus.getInitialAmount().subtract(gateioOrderStatus.getAmount()), + gateioOrderStatus.getCurrencyPair(), + gateioOrderStatus.getOrderNumber(), + null, + gateioOrderStatus.getInitialRate()) { + }; + limitOrder.setAveragePrice(gateioOrderStatus.getRate()); + orders.add(limitOrder); + + } + + return orders; + } + + @Override + public TradeHistoryParamCurrencyPair createTradeHistoryParams() { + + return new DefaultTradeHistoryParamCurrencyPair(); + } + + @Override + public OpenOrdersParams createOpenOrdersParams() { + return null; + } +} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeServiceRaw.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeServiceRaw.java new file mode 100644 index 00000000000..1dda010cb85 --- /dev/null +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeServiceRaw.java @@ -0,0 +1,166 @@ +package org.knowm.xchange.gateio.service; + +import java.io.IOException; +import java.math.BigDecimal; +import org.knowm.xchange.currency.CurrencyPair; +import org.knowm.xchange.dto.Order; +import org.knowm.xchange.dto.trade.LimitOrder; +import org.knowm.xchange.gateio.GateioExchange; +import org.knowm.xchange.gateio.GateioUtils; +import org.knowm.xchange.gateio.dto.GateioBaseResponse; +import org.knowm.xchange.gateio.dto.GateioOrderType; +import org.knowm.xchange.gateio.dto.trade.GateioOpenOrders; +import org.knowm.xchange.gateio.dto.trade.GateioOrderStatus; +import org.knowm.xchange.gateio.dto.trade.GateioPlaceOrderReturn; +import org.knowm.xchange.gateio.dto.trade.GateioTradeHistoryReturn; +import org.knowm.xchange.service.trade.params.CancelOrderByCurrencyPair; +import org.knowm.xchange.service.trade.params.CancelOrderByIdParams; + +public class GateioTradeServiceRaw extends GateioBaseService { + + /** + * Constructor + * + * @param exchange + */ + public GateioTradeServiceRaw(GateioExchange exchange) { + + super(exchange); + } + + /** + * Submits a Limit Order to be executed on the Gateio Exchange for the desired market defined by + * {@code CurrencyPair}. WARNING - Gateio will return true regardless of whether or not an order + * actually gets created. The reason for this is that orders are simply submitted to a queue in + * their back-end. One example for why an order might not get created is because there are + * insufficient funds. The best attempt you can make to confirm that the order was created is to + * poll {@link #getGateioOpenOrders}. However if the order is created and executed before it is + * caught in its open state from calling {@link #getGateioOpenOrders} then the only way to confirm + * would be confirm the expected difference in funds available for your account. + * + * @param limitOrder + * @return String order id of submitted request. + * @throws IOException + */ + public String placeGateioLimitOrder(LimitOrder limitOrder) throws IOException { + + GateioOrderType type = + (limitOrder.getType() == Order.OrderType.BID) ? GateioOrderType.BUY : GateioOrderType.SELL; + + return placeGateioLimitOrder( + limitOrder.getCurrencyPair(), + type, + limitOrder.getLimitPrice(), + limitOrder.getOriginalAmount()); + } + + /** + * Submits a Limit Order to be executed on the Gateio Exchange for the desired market defined by + * {@code currencyPair}. WARNING - Gateio will return true regardless of whether or not an order + * actually gets created. The reason for this is that orders are simply submitted to a queue in + * their back-end. One example for why an order might not get created is because there are + * insufficient funds. The best attempt you can make to confirm that the order was created is to + * poll {@link #getGateioOpenOrders}. However if the order is created and executed before it is + * caught in its open state from calling {@link #getGateioOpenOrders} then the only way to confirm + * would be confirm the expected difference in funds available for your account. + * + * @param currencyPair + * @param orderType + * @param rate + * @param amount + * @return String order id of submitted request. + * @throws IOException + */ + public String placeGateioLimitOrder( + CurrencyPair currencyPair, GateioOrderType orderType, BigDecimal rate, BigDecimal amount) + throws IOException { + + String pair = formatCurrencyPair(currencyPair); + + GateioPlaceOrderReturn orderId; + if (orderType.equals(GateioOrderType.BUY)) { + orderId = gateioAuthenticated.buy(pair, rate, amount, apiKey, signatureCreator); + } else { + orderId = gateioAuthenticated.sell(pair, rate, amount, apiKey, signatureCreator); + } + + return handleResponse(orderId).getOrderId(); + } + + public boolean cancelOrder(String orderId, CurrencyPair currencyPair) throws IOException { + + GateioBaseResponse cancelOrderResult = + gateioAuthenticated.cancelOrder(orderId, GateioUtils.toPairString(currencyPair), apiKey, signatureCreator); + + return handleResponse(cancelOrderResult).isResult(); + } + + /** + * Cancels all orders. See https://gate.io/api2. + * + * @param type order type(0:sell,1:buy,-1:all) + * @param currencyPair currency pair + * @return + * @throws IOException + */ + public boolean cancelAllOrders(String type, CurrencyPair currencyPair) throws IOException { + + GateioBaseResponse cancelAllOrdersResult = + gateioAuthenticated.cancelAllOrders(type, formatCurrencyPair(currencyPair), apiKey, signatureCreator); + + return handleResponse(cancelAllOrdersResult).isResult(); + } + + public GateioOpenOrders getGateioOpenOrders() throws IOException { + + GateioOpenOrders gateioOpenOrdersReturn = gateioAuthenticated.getOpenOrders(apiKey, signatureCreator); + + return handleResponse(gateioOpenOrdersReturn); + } + + public GateioOrderStatus getGateioOrderStatus(String orderId, CurrencyPair currencyPair) + throws IOException { + + GateioOrderStatus orderStatus = + gateioAuthenticated.getOrderStatus( + orderId, GateioUtils.toPairString(currencyPair), apiKey, signatureCreator); + + return handleResponse(orderStatus); + } + + public GateioTradeHistoryReturn getGateioTradeHistory(CurrencyPair currencyPair) + throws IOException { + + GateioTradeHistoryReturn gateioTradeHistoryReturn = + gateioAuthenticated.getUserTradeHistory(apiKey, signatureCreator, GateioUtils.toPairString(currencyPair)); + + return handleResponse(gateioTradeHistoryReturn); + } + + private String formatCurrencyPair(CurrencyPair currencyPair) { + return String.format( + "%s_%s", currencyPair.base.getCurrencyCode(), currencyPair.counter.getCurrencyCode()) + .toLowerCase(); + } + + public static class GateioCancelOrderParams + implements CancelOrderByIdParams, CancelOrderByCurrencyPair { + public final CurrencyPair currencyPair; + public final String orderId; + + public GateioCancelOrderParams(CurrencyPair currencyPair, String orderId) { + this.currencyPair = currencyPair; + this.orderId = orderId; + } + + @Override + public String getOrderId() { + return orderId; + } + + @Override + public CurrencyPair getCurrencyPair() { + return currencyPair; + } + } +} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioV4Digest.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioV4Digest.java new file mode 100644 index 00000000000..a69e183f81f --- /dev/null +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioV4Digest.java @@ -0,0 +1,68 @@ +package org.knowm.xchange.gateio.service; + +import java.io.UnsupportedEncodingException; +import java.security.MessageDigest; +import javax.crypto.Mac; +import lombok.SneakyThrows; +import org.knowm.xchange.service.BaseParamsDigest; +import org.knowm.xchange.utils.DigestUtils; +import si.mazi.rescu.RestInvocation; + +/** + * This may be used as the value of a @HeaderParam, @QueryParam or @PathParam to create a digest of + * the post body (composed of @FormParam's). Don't use as the value of a @FormParam, it will + * probably cause an infinite loop. + * + *

This may be used for REST APIs where some parameters' values must be digests of other + * parameters. An example is the MtGox API v1, where the Rest-Sign header parameter must be a digest + * of the request body (which is composed of @FormParams). + */ +public class GateioV4Digest extends BaseParamsDigest { + + /** + * Constructor + * + * @param secretKeyBase64 + * @throws IllegalArgumentException if key is invalid (cannot be base-64-decoded or the decoded + * key is invalid). + */ + private GateioV4Digest(String secretKeyBase64) { + + super(secretKeyBase64, HMAC_SHA_512); + } + + public static GateioV4Digest createInstance(String secretKeyBase64) { + + return secretKeyBase64 == null ? null : new GateioV4Digest(secretKeyBase64); + } + + @SneakyThrows + @Override + public String digestParams(RestInvocation restInvocation) { + try { + String postBody = restInvocation.getRequestBody(); + String method = restInvocation.getHttpMethod(); + String path = restInvocation.getPath(); + String query = restInvocation.getQueryString(); + + String body = restInvocation.getRequestBody(); + MessageDigest md = MessageDigest.getInstance("SHA-512"); + String hexedHashedBody = DigestUtils.bytesToHex(md.digest(body.getBytes())); + + String timestamp = restInvocation.getHttpHeadersFromParams().get("Timestamp"); + + String payloadToSign = String.format("%s\n/%s\n%s\n%s\n%s", method, path, query, hexedHashedBody, timestamp); + + System.out.println(payloadToSign); + + Mac mac = getMac(); + mac.update(payloadToSign.getBytes("UTF-8")); + return DigestUtils.bytesToHex(mac.doFinal()); +// return String.format("%0128x", new BigInteger(1, mac.doFinal())); + + } catch (UnsupportedEncodingException e) { + throw new RuntimeException("Illegal encoding, check the code.", e); + } + // return Base64.encodeBytes(mac.doFinal()).trim(); + } +} diff --git a/xchange-gateio-v4/src/main/resources/gateio.json b/xchange-gateio-v4/src/main/resources/gateio.json new file mode 100644 index 00000000000..4971fc66d4f --- /dev/null +++ b/xchange-gateio-v4/src/main/resources/gateio.json @@ -0,0 +1,901 @@ +{ + "currency_pairs": { + "XTC/CNY": { + "trading_fee": 0.2, + "min_amount": 0.5, + "price_scale": 4 + }, + "BUK/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "CDC/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "LTS/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "SFR/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "UNITY/NXT": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 2 + }, + "FTC/CNY": { + "trading_fee": 0.2, + "min_amount": 0.5, + "price_scale": 3 + }, + "VRC/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "NXTTY/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "CNC/CNY": { + "trading_fee": 0.2, + "min_amount": 0.5, + "price_scale": 4 + }, + "RED/LTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "BITCNY/CNY": { + "trading_fee": 0.2, + "min_amount": 0.5, + "price_scale": 4 + }, + "FRC/CNY": { + "trading_fee": 0.2, + "min_amount": 0.5, + "price_scale": 4 + }, + "ETH/CNY": { + "trading_fee": 0.2, + "min_amount": 0.5, + "price_scale": 2 + }, + "BTCD/NXT": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "NET/CNY": { + "trading_fee": 0.2, + "min_amount": 0.5, + "price_scale": 5 + }, + "DNS/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "BTS/CNY": { + "trading_fee": 0.2, + "min_amount": 0.5, + "price_scale": 4 + }, + "NFD/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "EXC/CNY": { + "trading_fee": 0.2, + "min_amount": 0.5, + "price_scale": 4 + }, + "BITGLD/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "TBC/CNY": { + "trading_fee": 0.2, + "min_amount": 0.5, + "price_scale": 4 + }, + "TAG/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 7 + }, + "BAY/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "NET/LTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "MAX/CNY": { + "trading_fee": 0.2, + "min_amount": 0.5, + "price_scale": 3 + }, + "VRC/CNY": { + "trading_fee": 0.2, + "min_amount": 0.5, + "price_scale": 4 + }, + "DOGE/USD": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "SPARK/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "CNC/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "FTC/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "NXT/USD": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 4 + }, + "NSR/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "NXTTY/CNY": { + "trading_fee": 0.2, + "min_amount": 0.5, + "price_scale": 4 + }, + "SRC/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "DAO/CNY": { + "trading_fee": 0.2, + "min_amount": 0.5, + "price_scale": 4 + }, + "NFD/LTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "NET/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "DICE/NXT": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "COMM/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "CENT/CNY": { + "trading_fee": 0.2, + "min_amount": 0.5, + "price_scale": 8 + }, + "TIX/LTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "XCN/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "CENT/LTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "DICE/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "AUR/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "SRC/CNY": { + "trading_fee": 0.2, + "min_amount": 0.5, + "price_scale": 4 + }, + "DGC/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "MMC/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "PPC/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 5 + }, + "XEM/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "LTC/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 5 + }, + "NODE/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "TIX/CNY": { + "trading_fee": 0.2, + "min_amount": 0.5, + "price_scale": 7 + }, + "NAS/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "TOKEN/NXT": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "CMC/CNY": { + "trading_fee": 0.2, + "min_amount": 0.5, + "price_scale": 4 + }, + "WDC/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 7 + }, + "EXC/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "FRSH/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "GEMZ/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "SWIFT/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "MGW/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "TOKEN/CNY": { + "trading_fee": 0.2, + "min_amount": 0.5, + "price_scale": 4 + }, + "ROX/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "PTS/CNY": { + "trading_fee": 0.2, + "min_amount": 0.5, + "price_scale": 6 + }, + "QRK/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "TOKEN/BTCD": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "RED/CNY": { + "trading_fee": 0.2, + "min_amount": 0.5, + "price_scale": 4 + }, + "CMC/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "BBR/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "BQC/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 7 + }, + "PRT/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "NBT/CNY": { + "trading_fee": 0.2, + "min_amount": 0.5, + "price_scale": 3 + }, + "MEC/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "DTC/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "XPM/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "FLT/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "TOKEN/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "DGC/CNY": { + "trading_fee": 0.2, + "min_amount": 0.5, + "price_scale": 4 + }, + "ARCH/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "C2/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "MMC/CNY": { + "trading_fee": 0.2, + "min_amount": 0.5, + "price_scale": 4 + }, + "ZET/CNY": { + "trading_fee": 0.2, + "min_amount": 0.5, + "price_scale": 4 + }, + "XCR/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "DOGE/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "XCP/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 5 + }, + "BQC/CNY": { + "trading_fee": 0.2, + "min_amount": 0.5, + "price_scale": 4 + }, + "AC/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 7 + }, + "NMC/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "QRK/CNY": { + "trading_fee": 0.2, + "min_amount": 0.5, + "price_scale": 7 + }, + "BTQ/CNY": { + "trading_fee": 0.5, + "min_amount": 0.5, + "price_scale": 3 + }, + "ZCC/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "PTS/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "MSC/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "DASH/CNY": { + "trading_fee": 0.2, + "min_amount": 0.5, + "price_scale": 2 + }, + "BTB/CNY": { + "trading_fee": 0.2, + "min_amount": 0.5, + "price_scale": 2 + }, + "XCH/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "ZET/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "IFC/CNY": { + "trading_fee": 0.2, + "min_amount": 0.5, + "price_scale": 7 + }, + "NBT/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 6 + }, + "IFC/LTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "QORA/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "BTS/NXT": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 3 + }, + "KDC/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "VIA/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "NXT/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 7 + }, + "DVC/LTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "LTC/CNY": { + "trading_fee": 0.2, + "min_amount": 0.5, + "price_scale": 2 + }, + "NEC/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "ATOMIC/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "BLK/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "PPC/CNY": { + "trading_fee": 0.2, + "min_amount": 0.5, + "price_scale": 2 + }, + "XPM/CNY": { + "trading_fee": 0.2, + "min_amount": 0.5, + "price_scale": 4 + }, + "LTC/USD": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 4 + }, + "DVC/CNY": { + "trading_fee": 0.2, + "min_amount": 0.5, + "price_scale": 6 + }, + "ZCC/CNY": { + "trading_fee": 0.2, + "min_amount": 0.5, + "price_scale": 4 + }, + "WDC/CNY": { + "trading_fee": 0.2, + "min_amount": 0.5, + "price_scale": 4 + }, + "NMC/CNY": { + "trading_fee": 0.2, + "min_amount": 0.5, + "price_scale": 2 + }, + "DASH/USD": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 4 + }, + "NTX/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "BITUSD/USD": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 4 + }, + "MAX/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 7 + }, + "NAV/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "MRKT/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "UNITY/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 5 + }, + "FTP/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "VTC/CNY": { + "trading_fee": 0.2, + "min_amount": 0.5, + "price_scale": 2 + }, + "BTB/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 5 + }, + "CKC/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "GHOST/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "XC/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "DRKC/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "SHELL/CNY": { + "trading_fee": 0.2, + "min_amount": 0.5, + "price_scale": 3 + }, + "XCP/NXT": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "DOGE/CNY": { + "trading_fee": 0.2, + "min_amount": 0.5, + "price_scale": 5 + }, + "NXT/CNY": { + "trading_fee": 0.2, + "min_amount": 0.5, + "price_scale": 4 + }, + "TIPS/CNY": { + "trading_fee": 0.2, + "min_amount": 0.5, + "price_scale": 8 + }, + "GML/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "BLK/CNY": { + "trading_fee": 0.2, + "min_amount": 0.5, + "price_scale": 3 + }, + "YAC/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "BTS/USD": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 4 + }, + "BTC/USD": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 3 + }, + "DAO/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "TIPS/LTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "MINT/CNY": { + "trading_fee": 0.2, + "min_amount": 0.5, + "price_scale": 7 + }, + "BTCD/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "BLOCK/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "DASH/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 5 + }, + "XMR/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "VTC/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 7 + }, + "DTC/CNY": { + "trading_fee": 0.2, + "min_amount": 0.5, + "price_scale": 4 + }, + "TBC/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 6 + }, + "XTC/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "BTC/CNY": { + "trading_fee": 0.2, + "min_amount": 0.5, + "price_scale": 2 + }, + "UNITY/CNY": { + "trading_fee": 0.2, + "min_amount": 0.5, + "price_scale": 2 + }, + "MEC/CNY": { + "trading_fee": 0.2, + "min_amount": 0.5, + "price_scale": 4 + }, + "ETH/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 6 + }, + "BTC/BITUSD": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 4 + }, + "XCP/USD": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 4 + }, + "XCP/CNY": { + "trading_fee": 0.2, + "min_amount": 0.5, + "price_scale": 2 + }, + "FRC/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "YAC/CNY": { + "trading_fee": 0.2, + "min_amount": 0.5, + "price_scale": 4 + }, + "MINT/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "XMR/CNY": { + "trading_fee": 0.2, + "min_amount": 0.5, + "price_scale": 3 + }, + "SLM/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 8 + }, + "TAG/CNY": { + "trading_fee": 0.2, + "min_amount": 0.5, + "price_scale": 3 + }, + "BTS/BTC": { + "trading_fee": 0.2, + "min_amount": 0.00010, + "price_scale": 7 + } + }, + "currencies": { + "BTC": { + "scale": 8, + "withdrawal_fee": 0.002 + }, + "ETH": { + "scale": 8, + "withdrawal_fee": 0.003 + }, + "USDT": { + "scale": 8, + "withdrawal_fee": 25.0 + }, + "LTC": { + "scale": 8, + "withdrawal_fee": 0.002 + }, + "BCH": { + "scale": 8, + "withdrawal_fee": 0.0006 + }, + "BTG": { + "scale": 8, + "withdrawal_fee": 0.002 + }, + "ZEC": { + "scale": 8, + "withdrawal_fee": 0.001 + }, + "ETC": { + "scale": 8, + "withdrawal_fee": 0.010 + }, + "DASH": { + "scale": 8, + "withdrawal_fee": 0.002 + }, + "QTUM": { + "scale": 8, + "withdrawal_fee": 0.010 + }, + "DOGE": { + "scale": 8, + "withdrawal_fee": 10.0 + }, + "REP": { + "scale": 8, + "withdrawal_fee": 0.010 + }, + "BAT": { + "scale": 8, + "withdrawal_fee": 10.0 + } + }, + "public_rate_limits": null, + "private_rate_limits": null, + "share_rate_limits": false +} \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/GateioExchangeTest.java b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/GateioExchangeTest.java new file mode 100644 index 00000000000..c36743ee4bf --- /dev/null +++ b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/GateioExchangeTest.java @@ -0,0 +1,28 @@ +package org.knowm.xchange.gateio; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.math.BigDecimal; +import org.junit.Ignore; +import org.junit.Test; +import org.knowm.xchange.currency.CurrencyPair; +import org.knowm.xchange.dto.meta.InstrumentMetaData; + +@Ignore +public class GateioExchangeTest extends GateioExchangeWiremock { + + @Test + public void metadata_present() { + InstrumentMetaData expected = new InstrumentMetaData.Builder() + .tradingFee(new BigDecimal("0.2")) + .minimumAmount(new BigDecimal("0.0001")) + .priceScale(1) + .marketOrderEnabled(false) + .build(); + + InstrumentMetaData actual = exchange.getExchangeMetaData().getInstruments().get(CurrencyPair.BTC_USDT); + + assertThat(actual).usingRecursiveComparison().isEqualTo(expected); + } + +} \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/GateioExchangeWiremock.java b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/GateioExchangeWiremock.java new file mode 100644 index 00000000000..0794c9f55f3 --- /dev/null +++ b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/GateioExchangeWiremock.java @@ -0,0 +1,53 @@ +package org.knowm.xchange.gateio; + +import com.github.tomakehurst.wiremock.junit.WireMockClassRule; +import com.github.tomakehurst.wiremock.recording.RecordSpecBuilder; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.knowm.xchange.ExchangeFactory; +import org.knowm.xchange.ExchangeSpecification; + +/** + * Sets up the wiremock for exchange + */ +public abstract class GateioExchangeWiremock { + + protected static GateioExchange exchange; + + private static final boolean IS_RECORDING = true; + + @ClassRule + public static WireMockClassRule wireMockRule = new WireMockClassRule(); + + @BeforeClass + public static void initExchange() { + ExchangeSpecification exSpec = new ExchangeSpecification(GateioExchange.class); + exSpec.setSslUri("http://localhost:" + wireMockRule.port()); + + if (IS_RECORDING) { + // use default url and record the requests + wireMockRule.startRecording( + new RecordSpecBuilder() + .forTarget("https://api.gateio.ws") + .matchRequestBodyWithEqualToJson() + .extractTextBodiesOver(1L) + .chooseBodyMatchTypeAutomatically() + ); + + } + + exchange = (GateioExchange) ExchangeFactory.INSTANCE.createExchange(exSpec); + + } + + + @AfterClass + public static void stop() { + if (IS_RECORDING) { + wireMockRule.stopRecording(); + } + } + + +} \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioMarketDataServiceRawTest.java b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioMarketDataServiceRawTest.java new file mode 100644 index 00000000000..423d8984a87 --- /dev/null +++ b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioMarketDataServiceRawTest.java @@ -0,0 +1,122 @@ +package org.knowm.xchange.gateio.service; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.IOException; +import java.math.BigDecimal; +import java.time.Instant; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.junit.Test; +import org.knowm.xchange.currency.Currency; +import org.knowm.xchange.currency.CurrencyPair; +import org.knowm.xchange.gateio.GateioExchangeWiremock; +import org.knowm.xchange.gateio.dto.marketdata.GateioCurrencyChain; +import org.knowm.xchange.gateio.dto.marketdata.GateioCurrencyInfo; +import org.knowm.xchange.gateio.dto.marketdata.GateioMarketInfoWrapper; +import org.knowm.xchange.gateio.dto.marketdata.GateioMarketInfoWrapper.GateioMarketInfo; +import org.knowm.xchange.gateio.dto.marketdata.GateioOrderBook; +import org.knowm.xchange.gateio.dto.marketdata.GateioOrderBook.PriceSizeEntry; + +public class GateioMarketDataServiceRawTest extends GateioExchangeWiremock { + + GateioMarketDataServiceRaw gateioMarketDataServiceRaw = (GateioMarketDataServiceRaw) exchange.getMarketDataService(); + + @Test + public void getMarketInfo_valid() throws IOException { + + Map expected = new HashMap<>(); + expected.put(CurrencyPair.BTC_USDT, + new GateioMarketInfo(CurrencyPair.BTC_USDT, 1, new BigDecimal("0.00010"), new BigDecimal("0.2"))); + expected.put(CurrencyPair.ETH_USDT, + new GateioMarketInfo(CurrencyPair.ETH_USDT, 2, new BigDecimal("0.001"), new BigDecimal("0.2"))); + + Map actual = gateioMarketDataServiceRaw.getMarketInfo(); + assertThat(actual).isEqualTo(expected); + } + + + @Test + public void getCurrencies_valid() { + List actual = gateioMarketDataServiceRaw.getCurrencies(); + + assertThat(actual).hasSize(5); + + GateioCurrencyInfo actualBtc = actual.get(0); + + GateioCurrencyInfo expectedBtc = GateioCurrencyInfo.builder() + .currency("BTC") + .delisted(false) + .withdrawDisabled(false) + .withdrawDelayed(false) + .depositDisabled(false) + .tradeDisabled(false) + .chain("BTC") + .build(); + + assertThat(actualBtc).usingRecursiveComparison().isEqualTo(expectedBtc); + } + + + @Test + public void getGateioOrderBook_valid() { + List expectedAsks = new ArrayList<>(); + expectedAsks.add(PriceSizeEntry.builder() + .price(new BigDecimal("200")) + .size(BigDecimal.ONE) + .build()); + expectedAsks.add(PriceSizeEntry.builder() + .price(new BigDecimal("250")) + .size(BigDecimal.TEN) + .build()); + + List expectedBids = new ArrayList<>(); + expectedBids.add(PriceSizeEntry.builder() + .price(new BigDecimal("150")) + .size(BigDecimal.ONE) + .build()); + expectedBids.add(PriceSizeEntry.builder() + .price(new BigDecimal("100")) + .size(BigDecimal.TEN) + .build()); + + GateioOrderBook expected = GateioOrderBook.builder() + .generatedAt(Instant.parse("2023-05-14T22:10:10.493Z")) + .updatedAt(Instant.parse("2023-05-14T22:10:10.263Z")) + .asks(expectedAsks) + .bids(expectedBids) + .build(); + + GateioOrderBook actual = gateioMarketDataServiceRaw.getGateioOrderBook(CurrencyPair.BTC_USDT); + + assertThat(actual).usingRecursiveComparison().isEqualTo(expected); + } + + + @Test + public void getCurrencyChains_valid_result() { + List expected = new ArrayList<>(); + expected.add(GateioCurrencyChain.builder() + .chain("BTC") + .chainNameCN("比特币 BRC20/Ordinals") + .chainNameEN("Bitcoin BRC20/Ordinals") + .disabled(false) + .depositDisabled(false) + .withdrawDisabled(false) + .build()); + expected.add(GateioCurrencyChain.builder() + .chain("HT") + .chainNameCN("Heco") + .chainNameEN("Heco") + .disabled(true) + .depositDisabled(true) + .withdrawDisabled(true) + .build()); + + List actual = gateioMarketDataServiceRaw.getCurrencyChains(Currency.BTC); + + assertThat(actual).isEqualTo(expected); + } +} \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioMarketDataServiceTest.java b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioMarketDataServiceTest.java new file mode 100644 index 00000000000..c6f14302c9f --- /dev/null +++ b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioMarketDataServiceTest.java @@ -0,0 +1,55 @@ +package org.knowm.xchange.gateio.service; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.IOException; +import java.math.BigDecimal; +import java.time.Instant; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import org.junit.Test; +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.trade.LimitOrder; +import org.knowm.xchange.gateio.GateioExchangeWiremock; + +public class GateioMarketDataServiceTest extends GateioExchangeWiremock { + + GateioMarketDataService gateioMarketDataService = (GateioMarketDataService) exchange.getMarketDataService(); + + + @Test + public void getOrderBook_valid() throws IOException { + OrderBook actual = gateioMarketDataService.getOrderBook(CurrencyPair.BTC_USDT); + + List expectedAsks = new ArrayList<>(); + expectedAsks.add(new LimitOrder.Builder(OrderType.ASK, CurrencyPair.BTC_USDT) + .limitPrice(new BigDecimal("200")) + .originalAmount(BigDecimal.ONE) + .build()); + expectedAsks.add(new LimitOrder.Builder(OrderType.ASK, CurrencyPair.BTC_USDT) + .limitPrice(new BigDecimal("250")) + .originalAmount(BigDecimal.TEN) + .build()); + + List expectedBids = new ArrayList<>(); + expectedBids.add(new LimitOrder.Builder(OrderType.BID, CurrencyPair.BTC_USDT) + .limitPrice(new BigDecimal("150")) + .originalAmount(BigDecimal.ONE) + .build()); + expectedBids.add(new LimitOrder.Builder(OrderType.BID, CurrencyPair.BTC_USDT) + .limitPrice(new BigDecimal("100")) + .originalAmount(BigDecimal.TEN) + .build()); + Date expectedTimestamp = Date.from(Instant.parse("2023-05-14T22:10:10.493Z")); + + OrderBook expected = new OrderBook(expectedTimestamp, expectedAsks, expectedBids); + + assertThat(actual) + .usingRecursiveComparison() + .ignoringFieldsMatchingRegexes(".*userReference") + .isEqualTo(expected); + } +} \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/resources/__files/api_v2_marketinfo.json b/xchange-gateio-v4/src/test/resources/__files/api_v2_marketinfo.json new file mode 100644 index 00000000000..c61cd69db84 --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/__files/api_v2_marketinfo.json @@ -0,0 +1,19 @@ +{ + "result": "true", + "pairs": [ + { + "btc_usdt": { + "decimal_places": 1, + "min_amount": 0.0001, + "fee": 0.2 + } + }, + { + "eth_usdt": { + "decimal_places": 2, + "min_amount": 0.001, + "fee": 0.2 + } + } + ] +} \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/resources/__files/api_v4_spot_currencies.json b/xchange-gateio-v4/src/test/resources/__files/api_v4_spot_currencies.json new file mode 100644 index 00000000000..3883d788716 --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/__files/api_v4_spot_currencies.json @@ -0,0 +1,47 @@ +[ + { + "currency": "BTC", + "delisted": false, + "withdraw_disabled": false, + "withdraw_delayed": false, + "deposit_disabled": false, + "trade_disabled": false, + "chain": "BTC" + }, + { + "currency": "BTC_BSC", + "delisted": false, + "withdraw_disabled": false, + "withdraw_delayed": false, + "deposit_disabled": false, + "trade_disabled": false, + "chain": "BSC" + }, + { + "currency": "BTC_HT", + "delisted": false, + "withdraw_disabled": true, + "withdraw_delayed": false, + "deposit_disabled": true, + "trade_disabled": false, + "chain": "HT" + }, + { + "currency": "ETH", + "delisted": false, + "withdraw_disabled": false, + "withdraw_delayed": false, + "deposit_disabled": false, + "trade_disabled": false, + "chain": "ETH" + }, + { + "currency": "ETH_BSC", + "delisted": false, + "withdraw_disabled": false, + "withdraw_delayed": false, + "deposit_disabled": false, + "trade_disabled": false, + "chain": "BSC" + } +] \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/resources/__files/api_v4_spot_order_book.json b/xchange-gateio-v4/src/test/resources/__files/api_v4_spot_order_book.json new file mode 100644 index 00000000000..e902ce2b312 --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/__files/api_v4_spot_order_book.json @@ -0,0 +1,24 @@ +{ + "current": 1684102210493, + "update": 1684102210263, + "asks": [ + [ + "200", + "1" + ], + [ + "250", + "10" + ] + ], + "bids": [ + [ + "150", + "1" + ], + [ + "100", + "10" + ] + ] +} \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/resources/__files/api_v4_wallet_currency_chains.json b/xchange-gateio-v4/src/test/resources/__files/api_v4_wallet_currency_chains.json new file mode 100644 index 00000000000..576cc113064 --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/__files/api_v4_wallet_currency_chains.json @@ -0,0 +1,18 @@ +[ + { + "chain": "BTC", + "name_cn": "比特币 BRC20\/Ordinals", + "name_en": "Bitcoin BRC20\/Ordinals", + "is_disabled": 0, + "is_deposit_disabled": 0, + "is_withdraw_disabled": 0 + }, + { + "chain": "HT", + "name_cn": "Heco", + "name_en": "Heco", + "is_disabled": 1, + "is_deposit_disabled": 1, + "is_withdraw_disabled": 1 + } +] \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/resources/logback.xml b/xchange-gateio-v4/src/test/resources/logback.xml new file mode 100644 index 00000000000..c823ac40a99 --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/logback.xml @@ -0,0 +1,23 @@ + + + + + + + + + %d{HH:mm:ss.SSS} [%contextName] [%thread] %-5level %logger{36} - %msg %xEx%n + + + + + + + + + + + + + + diff --git a/xchange-gateio-v4/src/test/resources/mappings/api_v2_marketinfo.json b/xchange-gateio-v4/src/test/resources/mappings/api_v2_marketinfo.json new file mode 100644 index 00000000000..bf471787b62 --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/mappings/api_v2_marketinfo.json @@ -0,0 +1,15 @@ +{ + "id" : "b404ad32-1bfb-47b9-b1fb-41e024c7cf03", + "name" : "api_v2_marketinfo", + "request" : { + "url" : "/api/v2/marketinfo", + "method" : "GET" + }, + "response" : { + "status" : 200, + "bodyFileName" : "api_v2_marketinfo.json" + }, + "uuid" : "b404ad32-1bfb-47b9-b1fb-41e024c7cf03", + "persistent" : true, + "insertionIndex" : 1 +} \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_currencies.json b/xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_currencies.json new file mode 100644 index 00000000000..e9addb37ed1 --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_currencies.json @@ -0,0 +1,15 @@ +{ + "id" : "2ad660f8-d92d-4f29-98d2-6e1b1acde382", + "name" : "api_v4_spot_currencies", + "request" : { + "url" : "/api/v4/spot/currencies", + "method" : "GET" + }, + "response" : { + "status" : 200, + "bodyFileName" : "api_v4_spot_currencies.json" + }, + "uuid" : "2ad660f8-d92d-4f29-98d2-6e1b1acde382", + "persistent" : true, + "insertionIndex" : 2 +} \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_order_book.json b/xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_order_book.json new file mode 100644 index 00000000000..1e31db7bd59 --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_order_book.json @@ -0,0 +1,15 @@ +{ + "id" : "b24dfa78-b1a7-4468-b85c-fa299b82170c", + "name" : "api_v4_spot_order_book", + "request" : { + "url" : "/api/v4/spot/order_book?currency_pair=btc_usdt&with_id=false", + "method" : "GET" + }, + "response" : { + "status" : 200, + "bodyFileName" : "api_v4_spot_order_book.json" + }, + "uuid" : "b24dfa78-b1a7-4468-b85c-fa299b82170c", + "persistent" : true, + "insertionIndex" : 3 +} \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/resources/mappings/api_v4_wallet_currency_chains.json b/xchange-gateio-v4/src/test/resources/mappings/api_v4_wallet_currency_chains.json new file mode 100644 index 00000000000..cd0f446a281 --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/mappings/api_v4_wallet_currency_chains.json @@ -0,0 +1,15 @@ +{ + "id" : "19776ad5-01d9-4071-a458-530f6b562dd2", + "name" : "api_v4_wallet_currency_chains", + "request" : { + "url" : "/api/v4/wallet/currency_chains?currency=BTC", + "method" : "GET" + }, + "response" : { + "status" : 200, + "bodyFileName" : "api_v4_wallet_currency_chains.json" + }, + "uuid" : "19776ad5-01d9-4071-a458-530f6b562dd2", + "persistent" : true, + "insertionIndex" : 5 +} \ No newline at end of file From 6a0994f7ba1068b8a9490f07568b596df95eb677 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Sun, 21 May 2023 01:40:38 +0200 Subject: [PATCH 007/159] [gateio-v4] Disable wiremock recording --- .../java/org/knowm/xchange/gateio/GateioExchangeWiremock.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/GateioExchangeWiremock.java b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/GateioExchangeWiremock.java index 0794c9f55f3..9cfb36f7beb 100644 --- a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/GateioExchangeWiremock.java +++ b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/GateioExchangeWiremock.java @@ -15,7 +15,7 @@ public abstract class GateioExchangeWiremock { protected static GateioExchange exchange; - private static final boolean IS_RECORDING = true; + private static final boolean IS_RECORDING = false; @ClassRule public static WireMockClassRule wireMockRule = new WireMockClassRule(); From 9d78d04c0dfb574d6b1cd9901bb70b4bfd5fd8ae Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Sun, 21 May 2023 11:28:58 +0200 Subject: [PATCH 008/159] [gateio-v4] Add sortpom plugin --- xchange-gateio-v4/pom.xml | 51 ++++++++++++++++++++++++++++++++------- 1 file changed, 42 insertions(+), 9 deletions(-) diff --git a/xchange-gateio-v4/pom.xml b/xchange-gateio-v4/pom.xml index 7876cf64016..e52c61fd7ad 100644 --- a/xchange-gateio-v4/pom.xml +++ b/xchange-gateio-v4/pom.xml @@ -1,3 +1,4 @@ + 4.0.0 @@ -21,12 +22,16 @@ http://knowm.org/open-source/xchange/ + + 3.2.0 + + - org.knowm.xchange - xchange-core - ${project.version} + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + ${version.fasterxml} @@ -36,17 +41,45 @@ - org.projectlombok - lombok - provided + org.knowm.xchange + xchange-core + ${project.version} - com.fasterxml.jackson.datatype - jackson-datatype-jsr310 - ${version.fasterxml} + org.projectlombok + lombok + provided + + + + com.github.ekryd.sortpom + sortpom-maven-plugin + ${version.sortpom-maven-plugin} + + true + false + groupId,artifactId + true + 4 + groupId,artifactId + false + + + + + sort + + verify + + + + + + + From aa3d7912b8a1cdb3ed9df5851decad6052bd693e Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Sun, 21 May 2023 11:42:23 +0200 Subject: [PATCH 009/159] [gateio-v4] Add getWithdrawalStatus endpoint --- .../dto/account/GateioWithdrawStatus.java | 48 +++++++++++++------ .../gateio/GateioExchangeWiremock.java | 7 ++- .../service/GateioAccountServiceRawTest.java | 45 +++++++++++++++++ 3 files changed, 85 insertions(+), 15 deletions(-) create mode 100644 xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceRawTest.java diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioWithdrawStatus.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioWithdrawStatus.java index 343b6035c5d..9e6f4d07337 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioWithdrawStatus.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioWithdrawStatus.java @@ -1,14 +1,12 @@ package org.knowm.xchange.gateio.dto.account; -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; -import java.util.LinkedHashMap; +import java.math.BigDecimal; import java.util.Map; import lombok.Builder; import lombok.Data; import lombok.extern.jackson.Jacksonized; +import org.apache.commons.lang3.StringUtils; @Data @Builder @@ -18,20 +16,42 @@ public class GateioWithdrawStatus { @JsonProperty("currency") String currency; - @JsonIgnore - private Map additionalProperties = new LinkedHashMap<>(); + @JsonProperty("name") + String name; - @JsonAnyGetter - public Map getAdditionalProperties() { - return additionalProperties; - } + @JsonProperty("name_cn") + String nameCN; - @JsonAnySetter - public void setAdditionalProperty(String name, Object value) { - additionalProperties.put(name, value); - } + @JsonProperty("deposit") + BigDecimal depositFee; + + @JsonProperty("withdraw_percent") + String withdrawPercent; + + @JsonProperty("withdraw_fix") + BigDecimal withdrawFee; + + @JsonProperty("withdraw_day_limit") + BigDecimal withdrawDailyLimit; + @JsonProperty("withdraw_day_limit_remain") + BigDecimal withdrawDailyLimitLeft; + @JsonProperty("withdraw_amount_mini") + BigDecimal minWithdrawAmount; + @JsonProperty("withdraw_eachtime_limit") + BigDecimal maxWithdrawAmount; + + @JsonProperty("withdraw_fix_on_chains") + Map withdrawFeeByChain; + + + /** + * @return withdraw rate converted from percentage + */ + public BigDecimal getWithdrawRate() { + return new BigDecimal(StringUtils.removeEnd(withdrawPercent, "%")).multiply(new BigDecimal("0.01")); + } } diff --git a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/GateioExchangeWiremock.java b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/GateioExchangeWiremock.java index 9cfb36f7beb..4b40195db3f 100644 --- a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/GateioExchangeWiremock.java +++ b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/GateioExchangeWiremock.java @@ -1,5 +1,7 @@ package org.knowm.xchange.gateio; +import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options; + import com.github.tomakehurst.wiremock.junit.WireMockClassRule; import com.github.tomakehurst.wiremock.recording.RecordSpecBuilder; import org.junit.AfterClass; @@ -18,12 +20,15 @@ public abstract class GateioExchangeWiremock { private static final boolean IS_RECORDING = false; @ClassRule - public static WireMockClassRule wireMockRule = new WireMockClassRule(); + public static WireMockClassRule wireMockRule = new WireMockClassRule(options().dynamicPort()); @BeforeClass public static void initExchange() { ExchangeSpecification exSpec = new ExchangeSpecification(GateioExchange.class); exSpec.setSslUri("http://localhost:" + wireMockRule.port()); + exSpec.setApiKey("a"); + exSpec.setSecretKey("b"); + if (IS_RECORDING) { // use default url and record the requests diff --git a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceRawTest.java b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceRawTest.java new file mode 100644 index 00000000000..6a50d2a2364 --- /dev/null +++ b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceRawTest.java @@ -0,0 +1,45 @@ +package org.knowm.xchange.gateio.service; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.IOException; +import java.math.BigDecimal; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.junit.Test; +import org.knowm.xchange.gateio.GateioExchangeWiremock; +import org.knowm.xchange.gateio.dto.account.GateioWithdrawStatus; + +public class GateioAccountServiceRawTest extends GateioExchangeWiremock { + + GateioAccountServiceRaw gateioAccountServiceRaw = ((GateioAccountServiceRaw) exchange.getAccountService()); + + @Test + public void getWithdrawStatus_valid() throws IOException { + Map expectedWithdrawFeeByChain = new HashMap<>(); + expectedWithdrawFeeByChain.put("ETH", new BigDecimal("0.93")); + expectedWithdrawFeeByChain.put("GTEVM", new BigDecimal("0.0049")); + GateioWithdrawStatus expected = GateioWithdrawStatus.builder() + .currency("GT") + .name("GateToken") + .nameCN("狗头") + .depositFee(BigDecimal.ZERO) + .withdrawPercent("0%") + .withdrawFee(new BigDecimal("0.02")) + .withdrawDailyLimit(new BigDecimal("500000")) + .withdrawDailyLimitLeft(new BigDecimal("499999")) + .minWithdrawAmount(new BigDecimal("0.12")) + .maxWithdrawAmount(new BigDecimal("499999")) + .withdrawFeeByChain(expectedWithdrawFeeByChain) + .build(); + + List status = gateioAccountServiceRaw.getWithdrawStatus(); + + assertThat(status).hasSize(2); + GateioWithdrawStatus actualGt = status.get(0); + assertThat(actualGt).isEqualTo(expected); + assertThat(actualGt.getWithdrawRate()).isEqualTo(new BigDecimal("0.00")); + + } +} \ No newline at end of file From d1bf5441f4c25b61c49669ab5e3260a886e1ec3b Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Sun, 21 May 2023 12:08:15 +0200 Subject: [PATCH 010/159] [gateio-v4] Add getWithdrawalStatus endpoint --- .../api_v4_wallet_withdraw_status.json | 48 +++++++++++++++++++ .../api_v4_wallet_withdraw_status.json | 15 ++++++ 2 files changed, 63 insertions(+) create mode 100644 xchange-gateio-v4/src/test/resources/__files/api_v4_wallet_withdraw_status.json create mode 100644 xchange-gateio-v4/src/test/resources/mappings/api_v4_wallet_withdraw_status.json diff --git a/xchange-gateio-v4/src/test/resources/__files/api_v4_wallet_withdraw_status.json b/xchange-gateio-v4/src/test/resources/__files/api_v4_wallet_withdraw_status.json new file mode 100644 index 00000000000..2d3910834e7 --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/__files/api_v4_wallet_withdraw_status.json @@ -0,0 +1,48 @@ +[ + { + "currency": "GT", + "name": "GateToken", + "name_cn": "狗头", + "deposit": "0", + "withdraw_percent": "0%", + "withdraw_fix": "0.02", + "withdraw_day_limit": "500000", + "withdraw_day_limit_remain": "499999", + "withdraw_amount_mini": "0.12", + "withdraw_eachtime_limit": "499999", + "withdraw_fix_on_chains": { + "ETH": "0.93", + "GTEVM": "0.0049" + } + }, + { + "currency": "USDT", + "name": "Tether", + "name_cn": "Tether", + "deposit": "0", + "withdraw_percent": "0%", + "withdraw_fix": "65", + "withdraw_day_limit": "300000", + "withdraw_day_limit_remain": "299999", + "withdraw_amount_mini": "66", + "withdraw_eachtime_limit": "299999", + "withdraw_fix_on_chains": { + "BTC": "65", + "ETH": "5", + "TRX": "1", + "BSC": "1", + "GTEVM": "0.024", + "EOS": "10", + "HT": "0.5", + "SOL": "0.1", + "ALGO": "5", + "NEAR": "0.5", + "MATIC": "1", + "ARBEVM": "1", + "OPETH": "1", + "KSMSM": "2", + "DOTSM": "2", + "OKT": "1" + } + } +] \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/resources/mappings/api_v4_wallet_withdraw_status.json b/xchange-gateio-v4/src/test/resources/mappings/api_v4_wallet_withdraw_status.json new file mode 100644 index 00000000000..77870809d20 --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/mappings/api_v4_wallet_withdraw_status.json @@ -0,0 +1,15 @@ +{ + "id" : "4b5f7040-4613-4a00-b049-d313e9898515", + "name" : "api_v4_wallet_withdraw_status", + "request" : { + "url" : "/api/v4/wallet/withdraw_status", + "method" : "GET" + }, + "response" : { + "status" : 200, + "bodyFileName" : "api_v4_wallet_withdraw_status.json" + }, + "uuid" : "4b5f7040-4613-4a00-b049-d313e9898515", + "persistent" : true, + "insertionIndex" : 5 +} \ No newline at end of file From a100619b15b603777bbaa1872da35e525e00a9ea Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Sun, 28 May 2023 12:20:20 +0200 Subject: [PATCH 011/159] [gateio-v4] Update withdraw/deposit enabled status --- .../xchange/gateio/dto/marketdata/GateioCurrencyChain.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioCurrencyChain.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioCurrencyChain.java index 47faa37706d..a680ebd8587 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioCurrencyChain.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioCurrencyChain.java @@ -29,11 +29,11 @@ public class GateioCurrencyChain { Boolean withdrawDisabled; public boolean isWithdrawEnabled() { - return (withdrawDisabled != null) && !withdrawDisabled; + return isEnabled() && (withdrawDisabled != null) && !withdrawDisabled; } public boolean isDepositEnabled() { - return (depositDisabled != null) && !depositDisabled; + return isEnabled() && (depositDisabled != null) && !depositDisabled; } public boolean isEnabled() { From 5a666ca837ca0170e706ba409b815873cd2bd14e Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Mon, 29 May 2023 12:32:32 +0200 Subject: [PATCH 012/159] [core] Add support for junit 5 --- pom.xml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 3e8edcd6a30..b3ec551a158 100644 --- a/pom.xml +++ b/pom.xml @@ -36,7 +36,7 @@ 2.14.1 2.1.0 1.7.0 - 4.13.2 + 5.9.3 1.18.22 3.8.2 1.4.5 @@ -387,11 +387,12 @@ - junit - junit + org.junit.vintage + junit-vintage-engine ${version.junit} test + org.assertj assertj-core From e91b5bfac40289c2fb6b9ac99d6434fbfdb114c8 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Mon, 29 May 2023 12:50:48 +0200 Subject: [PATCH 013/159] [core] Add support for junit 5 --- pom.xml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 821b951ff37..2b449ff61f4 100644 --- a/pom.xml +++ b/pom.xml @@ -36,7 +36,7 @@ 2.14.1 2.1.0 1.7.0 - 4.13.2 + 5.9.3 1.18.22 3.8.2 1.4.5 @@ -395,11 +395,12 @@ - junit - junit + org.junit.vintage + junit-vintage-engine ${version.junit} test + org.assertj assertj-core From 82a0a8cf5fb7c4a39b7519b73535df7e9e42fc13 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Mon, 29 May 2023 12:51:09 +0200 Subject: [PATCH 014/159] [core] Fix wrong parent version --- xchange-stream-kucoin/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xchange-stream-kucoin/pom.xml b/xchange-stream-kucoin/pom.xml index 68d8b9a24a5..64f9dd498e6 100644 --- a/xchange-stream-kucoin/pom.xml +++ b/xchange-stream-kucoin/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.0.14-SNAPSHOT + 5.1.1-SNAPSHOT XChange Kucoin Stream From f642e6615ba8dc364d76e144d78ad0b0da2cf371 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Mon, 29 May 2023 20:42:02 +0200 Subject: [PATCH 015/159] [gateio-v4] Add error adapter, migrate to junit 5, add tests --- xchange-gateio-v4/lombok.config | 1 + xchange-gateio-v4/pom.xml | 7 ++++ .../xchange/gateio/GateioErrorAdapter.java | 33 +++++++++++++++++++ .../xchange/gateio/GateioV4Authenticated.java | 7 ++-- .../xchange/gateio/dto/GateioException.java | 19 +++++++++++ .../service/GateioAccountServiceRaw.java | 14 ++++++-- .../gateio/GateioExchangeWiremock.java | 23 +++++++------ .../service/GateioAccountServiceRawTest.java | 26 +++++++++++++-- .../GateioMarketDataServiceRawTest.java | 2 +- .../service/GateioMarketDataServiceTest.java | 2 +- ...llet_withdraw_status-invalid_currency.json | 4 +++ ...v4_wallet_withdraw_status-invalid_key.json | 4 +++ ...let_withdraw_status-invalid_signature.json | 4 +++ ...llet_withdraw_status-invalid_currency.json | 15 +++++++++ ...v4_wallet_withdraw_status-invalid_key.json | 15 +++++++++ ...let_withdraw_status-invalid_signature.json | 15 +++++++++ 16 files changed, 173 insertions(+), 18 deletions(-) create mode 100644 xchange-gateio-v4/lombok.config create mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioErrorAdapter.java create mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/GateioException.java create mode 100644 xchange-gateio-v4/src/test/resources/__files/exceptions/api_v4_wallet_withdraw_status-invalid_currency.json create mode 100644 xchange-gateio-v4/src/test/resources/__files/exceptions/api_v4_wallet_withdraw_status-invalid_key.json create mode 100644 xchange-gateio-v4/src/test/resources/__files/exceptions/api_v4_wallet_withdraw_status-invalid_signature.json create mode 100644 xchange-gateio-v4/src/test/resources/mappings/exceptions/api_v4_wallet_withdraw_status-invalid_currency.json create mode 100644 xchange-gateio-v4/src/test/resources/mappings/exceptions/api_v4_wallet_withdraw_status-invalid_key.json create mode 100644 xchange-gateio-v4/src/test/resources/mappings/exceptions/api_v4_wallet_withdraw_status-invalid_signature.json diff --git a/xchange-gateio-v4/lombok.config b/xchange-gateio-v4/lombok.config new file mode 100644 index 00000000000..e572d96336a --- /dev/null +++ b/xchange-gateio-v4/lombok.config @@ -0,0 +1 @@ +lombok.equalsAndHashCode.callSuper = call \ No newline at end of file diff --git a/xchange-gateio-v4/pom.xml b/xchange-gateio-v4/pom.xml index e52c61fd7ad..68d893d7c9e 100644 --- a/xchange-gateio-v4/pom.xml +++ b/xchange-gateio-v4/pom.xml @@ -40,6 +40,13 @@ test + + org.junit.jupiter + junit-jupiter-engine + ${version.junit} + test + + org.knowm.xchange xchange-core 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 new file mode 100644 index 00000000000..361d756535a --- /dev/null +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioErrorAdapter.java @@ -0,0 +1,33 @@ +package org.knowm.xchange.gateio; + +import lombok.experimental.UtilityClass; +import org.knowm.xchange.exceptions.ExchangeException; +import org.knowm.xchange.exceptions.ExchangeSecurityException; +import org.knowm.xchange.exceptions.InstrumentNotValidException; +import org.knowm.xchange.gateio.dto.GateioException; + +@UtilityClass +public class GateioErrorAdapter { + + public final String INVALID_SIGNATURE = "INVALID_SIGNATURE"; + public final String INVALID_KEY = "INVALID_KEY"; + public final String INVALID_CURRENCY = "INVALID_CURRENCY"; + + + public ExchangeException adapt(GateioException e) { + + switch (e.getLabel()) { + case INVALID_SIGNATURE: + case INVALID_KEY: + return new ExchangeSecurityException(e.getMessage(), e); + + case INVALID_CURRENCY: + return new InstrumentNotValidException(e.getMessage(), e); + + default: + return new ExchangeException(e.getMessage(), e); + } + + } + +} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java index 3afffae8a5c..dc29e8017e6 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java @@ -6,7 +6,9 @@ import javax.ws.rs.HeaderParam; import javax.ws.rs.Path; import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; +import org.knowm.xchange.gateio.dto.GateioException; import org.knowm.xchange.gateio.dto.account.GateioWithdrawStatus; import si.mazi.rescu.ParamsDigest; import si.mazi.rescu.SynchronizedValueFactory; @@ -20,7 +22,8 @@ public interface GateioV4Authenticated { List getWithdrawStatus( @HeaderParam("KEY") String apiKey, @HeaderParam("Timestamp") SynchronizedValueFactory timestamp, - @HeaderParam("SIGN") ParamsDigest signer) - throws IOException; + @HeaderParam("SIGN") ParamsDigest signer, + @QueryParam("currency") String currency) + throws IOException, GateioException; } diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/GateioException.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/GateioException.java new file mode 100644 index 00000000000..e87b1a2dcd0 --- /dev/null +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/GateioException.java @@ -0,0 +1,19 @@ +package org.knowm.xchange.gateio.dto; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Builder; +import lombok.Value; +import lombok.extern.jackson.Jacksonized; + +@Value +@Jacksonized +@Builder +public class GateioException extends RuntimeException { + + @JsonProperty("label") + String label; + + @JsonProperty("message") + String message; + +} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountServiceRaw.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountServiceRaw.java index 06934eeb96e..1d1b86d7f2a 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountServiceRaw.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountServiceRaw.java @@ -6,8 +6,10 @@ import java.util.List; import org.knowm.xchange.currency.Currency; import org.knowm.xchange.exceptions.ExchangeException; +import org.knowm.xchange.gateio.GateioErrorAdapter; import org.knowm.xchange.gateio.GateioExchange; import org.knowm.xchange.gateio.dto.GateioBaseResponse; +import org.knowm.xchange.gateio.dto.GateioException; import org.knowm.xchange.gateio.dto.account.GateioDepositAddress; import org.knowm.xchange.gateio.dto.account.GateioDepositsWithdrawals; import org.knowm.xchange.gateio.dto.account.GateioFunds; @@ -77,7 +79,15 @@ public String withdraw(String currency, BigDecimal amount, String address) throw } - public List getWithdrawStatus() throws IOException { - return gateioV4Authenticated.getWithdrawStatus(apiKey, exchange.getNonceFactory(), gateioV4ParamsDigest); + public List getWithdrawStatus(Currency currency) throws IOException { + String currencyCode = currency == null ? null : currency.getCurrencyCode(); + + try { + return gateioV4Authenticated.getWithdrawStatus(apiKey, exchange.getNonceFactory(), gateioV4ParamsDigest, currencyCode); + } + catch (GateioException e) { + throw GateioErrorAdapter.adapt(e); + } + } } diff --git a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/GateioExchangeWiremock.java b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/GateioExchangeWiremock.java index 4b40195db3f..a85c7586800 100644 --- a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/GateioExchangeWiremock.java +++ b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/GateioExchangeWiremock.java @@ -2,11 +2,10 @@ import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options; -import com.github.tomakehurst.wiremock.junit.WireMockClassRule; +import com.github.tomakehurst.wiremock.WireMockServer; import com.github.tomakehurst.wiremock.recording.RecordSpecBuilder; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.ClassRule; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; import org.knowm.xchange.ExchangeFactory; import org.knowm.xchange.ExchangeSpecification; @@ -19,11 +18,14 @@ public abstract class GateioExchangeWiremock { private static final boolean IS_RECORDING = false; - @ClassRule - public static WireMockClassRule wireMockRule = new WireMockClassRule(options().dynamicPort()); + private static WireMockServer wireMockServer; - @BeforeClass + + @BeforeAll public static void initExchange() { + wireMockServer = new WireMockServer(options().dynamicPort()); + wireMockServer.start(); + ExchangeSpecification exSpec = new ExchangeSpecification(GateioExchange.class); exSpec.setSslUri("http://localhost:" + wireMockRule.port()); exSpec.setApiKey("a"); @@ -32,7 +34,7 @@ public static void initExchange() { if (IS_RECORDING) { // use default url and record the requests - wireMockRule.startRecording( + wireMockServer.startRecording( new RecordSpecBuilder() .forTarget("https://api.gateio.ws") .matchRequestBodyWithEqualToJson() @@ -47,11 +49,12 @@ public static void initExchange() { } - @AfterClass + @AfterAll public static void stop() { if (IS_RECORDING) { - wireMockRule.stopRecording(); + wireMockServer.stopRecording(); } + wireMockServer.stop(); } diff --git a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceRawTest.java b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceRawTest.java index 6a50d2a2364..23f6ca7dca3 100644 --- a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceRawTest.java +++ b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceRawTest.java @@ -1,13 +1,17 @@ package org.knowm.xchange.gateio.service; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import java.io.IOException; import java.math.BigDecimal; import java.util.HashMap; import java.util.List; import java.util.Map; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.knowm.xchange.currency.Currency; +import org.knowm.xchange.exceptions.ExchangeSecurityException; +import org.knowm.xchange.exceptions.InstrumentNotValidException; import org.knowm.xchange.gateio.GateioExchangeWiremock; import org.knowm.xchange.gateio.dto.account.GateioWithdrawStatus; @@ -34,7 +38,7 @@ public void getWithdrawStatus_valid() throws IOException { .withdrawFeeByChain(expectedWithdrawFeeByChain) .build(); - List status = gateioAccountServiceRaw.getWithdrawStatus(); + List status = gateioAccountServiceRaw.getWithdrawStatus(null); assertThat(status).hasSize(2); GateioWithdrawStatus actualGt = status.get(0); @@ -42,4 +46,22 @@ public void getWithdrawStatus_valid() throws IOException { assertThat(actualGt.getWithdrawRate()).isEqualTo(new BigDecimal("0.00")); } + + + @Test + public void http_401_exception_mapped() { + assertThatExceptionOfType(ExchangeSecurityException.class) + .isThrownBy(() -> gateioAccountServiceRaw.getWithdrawStatus(Currency.getInstance("THROW_401"))); + assertThatExceptionOfType(ExchangeSecurityException.class) + .isThrownBy(() -> gateioAccountServiceRaw.getWithdrawStatus(Currency.getInstance("INVALID_KEY"))); + } + + + @Test + public void invalid_currency_exception_mapped() { + assertThatExceptionOfType(InstrumentNotValidException.class) + .isThrownBy(() -> gateioAccountServiceRaw.getWithdrawStatus(Currency.getInstance("invalid-currency"))); + } + + } \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioMarketDataServiceRawTest.java b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioMarketDataServiceRawTest.java index 423d8984a87..310b2bf1e55 100644 --- a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioMarketDataServiceRawTest.java +++ b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioMarketDataServiceRawTest.java @@ -9,7 +9,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.knowm.xchange.currency.Currency; import org.knowm.xchange.currency.CurrencyPair; import org.knowm.xchange.gateio.GateioExchangeWiremock; diff --git a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioMarketDataServiceTest.java b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioMarketDataServiceTest.java index c6f14302c9f..5302ed05631 100644 --- a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioMarketDataServiceTest.java +++ b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioMarketDataServiceTest.java @@ -8,7 +8,7 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.knowm.xchange.currency.CurrencyPair; import org.knowm.xchange.dto.Order.OrderType; import org.knowm.xchange.dto.marketdata.OrderBook; diff --git a/xchange-gateio-v4/src/test/resources/__files/exceptions/api_v4_wallet_withdraw_status-invalid_currency.json b/xchange-gateio-v4/src/test/resources/__files/exceptions/api_v4_wallet_withdraw_status-invalid_currency.json new file mode 100644 index 00000000000..021ac2176de --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/__files/exceptions/api_v4_wallet_withdraw_status-invalid_currency.json @@ -0,0 +1,4 @@ +{ + "label": "INVALID_CURRENCY", + "message": "Invalid currency" +} \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/resources/__files/exceptions/api_v4_wallet_withdraw_status-invalid_key.json b/xchange-gateio-v4/src/test/resources/__files/exceptions/api_v4_wallet_withdraw_status-invalid_key.json new file mode 100644 index 00000000000..85589cd3b7f --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/__files/exceptions/api_v4_wallet_withdraw_status-invalid_key.json @@ -0,0 +1,4 @@ +{ + "message": "Invalid key provided", + "label": "INVALID_KEY" +} diff --git a/xchange-gateio-v4/src/test/resources/__files/exceptions/api_v4_wallet_withdraw_status-invalid_signature.json b/xchange-gateio-v4/src/test/resources/__files/exceptions/api_v4_wallet_withdraw_status-invalid_signature.json new file mode 100644 index 00000000000..b2acf1dd1cd --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/__files/exceptions/api_v4_wallet_withdraw_status-invalid_signature.json @@ -0,0 +1,4 @@ +{ + "label": "INVALID_SIGNATURE", + "message": "Signature mismatch" +} diff --git a/xchange-gateio-v4/src/test/resources/mappings/exceptions/api_v4_wallet_withdraw_status-invalid_currency.json b/xchange-gateio-v4/src/test/resources/mappings/exceptions/api_v4_wallet_withdraw_status-invalid_currency.json new file mode 100644 index 00000000000..4bb6a9d94ed --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/mappings/exceptions/api_v4_wallet_withdraw_status-invalid_currency.json @@ -0,0 +1,15 @@ +{ + "id" : "850454cc-bd9d-41de-ba6e-34717cddc6ac", + "name" : "api_v4_wallet_withdraw_status", + "request" : { + "url" : "/api/v4/wallet/withdraw_status?currency=INVALID-CURRENCY", + "method" : "GET" + }, + "response" : { + "status" : 400, + "bodyFileName" : "exceptions/api_v4_wallet_withdraw_status-invalid_currency.json" + }, + "uuid" : "850454cc-bd9d-41de-ba6e-34717cddc6ac", + "persistent" : true, + "insertionIndex" : 7 +} \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/resources/mappings/exceptions/api_v4_wallet_withdraw_status-invalid_key.json b/xchange-gateio-v4/src/test/resources/mappings/exceptions/api_v4_wallet_withdraw_status-invalid_key.json new file mode 100644 index 00000000000..6372d8d758e --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/mappings/exceptions/api_v4_wallet_withdraw_status-invalid_key.json @@ -0,0 +1,15 @@ +{ + "id" : "b6ca7675-7276-4e62-adb6-bc7a73e4769a", + "name" : "api_v4_wallet_withdraw_status", + "request" : { + "url" : "/api/v4/wallet/withdraw_status?currency=INVALID_KEY", + "method" : "GET" + }, + "response" : { + "status" : 401, + "bodyFileName" : "exceptions/api_v4_wallet_withdraw_status-invalid_key.json" + }, + "uuid" : "b6ca7675-7276-4e62-adb6-bc7a73e4769a", + "persistent" : true, + "insertionIndex" : 8 +} \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/resources/mappings/exceptions/api_v4_wallet_withdraw_status-invalid_signature.json b/xchange-gateio-v4/src/test/resources/mappings/exceptions/api_v4_wallet_withdraw_status-invalid_signature.json new file mode 100644 index 00000000000..291318a8ef6 --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/mappings/exceptions/api_v4_wallet_withdraw_status-invalid_signature.json @@ -0,0 +1,15 @@ +{ + "id" : "56aff0c3-822e-4e4c-adbd-45c89cbd5aad", + "name" : "api_v4_wallet_withdraw_status", + "request" : { + "url" : "/api/v4/wallet/withdraw_status?currency=THROW_401", + "method" : "GET" + }, + "response" : { + "status" : 401, + "bodyFileName" : "exceptions/api_v4_wallet_withdraw_status-invalid_signature.json" + }, + "uuid" : "56aff0c3-822e-4e4c-adbd-45c89cbd5aad", + "persistent" : true, + "insertionIndex" : 9 +} \ No newline at end of file From 6db270a09cecb7daa1be874ed073a6dd63828738 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Mon, 29 May 2023 22:57:25 +0200 Subject: [PATCH 016/159] [gateio-v4] Add getAccountInfo --- .../xchange/gateio/GateioV4Authenticated.java | 18 +++++++++-- .../dto/account/GateioCurrencyBalance.java | 23 ++++++++++++++ .../gateio/service/GateioAccountService.java | 31 ++++++++++++++++++- .../service/GateioAccountServiceRaw.java | 19 +++++++----- .../service/GateioAccountServiceTest.java | 30 ++++++++++++++++++ .../__files/api_v4_spot_accounts.json | 7 +++++ .../mappings/api_v4_spot_accounts.json | 15 +++++++++ 7 files changed, 131 insertions(+), 12 deletions(-) create mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioCurrencyBalance.java create mode 100644 xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceTest.java create mode 100644 xchange-gateio-v4/src/test/resources/__files/api_v4_spot_accounts.json create mode 100644 xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_accounts.json diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java index dc29e8017e6..07616e8ca40 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java @@ -9,21 +9,33 @@ import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; import org.knowm.xchange.gateio.dto.GateioException; +import org.knowm.xchange.gateio.dto.account.GateioCurrencyBalance; import org.knowm.xchange.gateio.dto.account.GateioWithdrawStatus; import si.mazi.rescu.ParamsDigest; import si.mazi.rescu.SynchronizedValueFactory; @Path("api/v4") +@Produces(MediaType.APPLICATION_JSON) public interface GateioV4Authenticated { @GET - @Produces(MediaType.APPLICATION_JSON) @Path("wallet/withdraw_status") List getWithdrawStatus( @HeaderParam("KEY") String apiKey, @HeaderParam("Timestamp") SynchronizedValueFactory timestamp, @HeaderParam("SIGN") ParamsDigest signer, - @QueryParam("currency") String currency) - throws IOException, GateioException; + @QueryParam("currency") String currency + ) throws IOException, GateioException; + + + @GET + @Path("spot/accounts") + List getSpotAccounts( + @HeaderParam("KEY") String apiKey, + @HeaderParam("Timestamp") SynchronizedValueFactory timestamp, + @HeaderParam("SIGN") ParamsDigest signer, + @QueryParam("currency") String currency + ) throws IOException, GateioException; + } diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioCurrencyBalance.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioCurrencyBalance.java new file mode 100644 index 00000000000..73852f043a9 --- /dev/null +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioCurrencyBalance.java @@ -0,0 +1,23 @@ +package org.knowm.xchange.gateio.dto.account; + +import com.fasterxml.jackson.annotation.JsonProperty; +import java.math.BigDecimal; +import lombok.Builder; +import lombok.Data; +import lombok.extern.jackson.Jacksonized; + +@Data +@Builder +@Jacksonized +public class GateioCurrencyBalance { + + @JsonProperty("currency") + String currency; + + @JsonProperty("available") + BigDecimal available; + + @JsonProperty("locked") + BigDecimal locked; + +} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountService.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountService.java index a9f0deca250..5ebd6bcadea 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountService.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountService.java @@ -4,12 +4,18 @@ import java.math.BigDecimal; import java.util.Date; import java.util.List; +import java.util.stream.Collectors; import org.knowm.xchange.currency.Currency; import org.knowm.xchange.dto.account.AccountInfo; +import org.knowm.xchange.dto.account.Balance; import org.knowm.xchange.dto.account.FundingRecord; +import org.knowm.xchange.dto.account.Wallet; import org.knowm.xchange.exceptions.NotAvailableFromExchangeException; import org.knowm.xchange.gateio.GateioAdapters; +import org.knowm.xchange.gateio.GateioErrorAdapter; import org.knowm.xchange.gateio.GateioExchange; +import org.knowm.xchange.gateio.dto.GateioException; +import org.knowm.xchange.gateio.dto.account.GateioCurrencyBalance; import org.knowm.xchange.gateio.dto.account.GateioDepositsWithdrawals; import org.knowm.xchange.service.account.AccountService; import org.knowm.xchange.service.trade.params.DefaultWithdrawFundsParams; @@ -33,7 +39,30 @@ public GateioAccountService(GateioExchange exchange) { @Override public AccountInfo getAccountInfo() throws IOException { - return new AccountInfo(GateioAdapters.adaptWallet(super.getGateioAccountInfo())); + try { + List spotBalances = getSpotBalances(null); + + List balances = spotBalances.stream() + .map(balance -> Balance.builder() + .currency(Currency.getInstance(balance.getCurrency())) + .available(balance.getAvailable()) + .frozen(balance.getLocked()) + .build()) + .collect(Collectors.toList()); + + Wallet wallet = Wallet.Builder + .from(balances) + .id("spot") + .build(); + + return new AccountInfo(wallet); + + } + catch (GateioException e) { + throw GateioErrorAdapter.adapt(e); + } + + } @Override diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountServiceRaw.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountServiceRaw.java index 1d1b86d7f2a..81fdbb6e064 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountServiceRaw.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountServiceRaw.java @@ -10,9 +10,9 @@ import org.knowm.xchange.gateio.GateioExchange; import org.knowm.xchange.gateio.dto.GateioBaseResponse; import org.knowm.xchange.gateio.dto.GateioException; +import org.knowm.xchange.gateio.dto.account.GateioCurrencyBalance; import org.knowm.xchange.gateio.dto.account.GateioDepositAddress; import org.knowm.xchange.gateio.dto.account.GateioDepositsWithdrawals; -import org.knowm.xchange.gateio.dto.account.GateioFunds; import org.knowm.xchange.gateio.dto.account.GateioWithdrawStatus; public class GateioAccountServiceRaw extends GateioBaseService { @@ -27,13 +27,6 @@ public GateioAccountServiceRaw(GateioExchange exchange) { super(exchange); } - public GateioFunds getGateioAccountInfo() throws IOException { - - GateioFunds gateioFunds = - gateioAuthenticated.getFunds(exchange.getExchangeSpecification().getApiKey(), signatureCreator); - return handleResponse(gateioFunds); - } - public GateioDepositAddress getGateioDepositAddress(Currency currency) throws IOException { GateioDepositAddress depositAddress = gateioAuthenticated.getDepositAddress( @@ -90,4 +83,14 @@ public List getWithdrawStatus(Currency currency) throws IO } } + + + public List getSpotBalances(Currency currency) throws IOException { + + String currencyCode = currency == null ? null : currency.getCurrencyCode(); + return gateioV4Authenticated.getSpotAccounts(apiKey, exchange.getNonceFactory(), gateioV4ParamsDigest, currencyCode); + + } + + } diff --git a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceTest.java b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceTest.java new file mode 100644 index 00000000000..c6d5629c95b --- /dev/null +++ b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceTest.java @@ -0,0 +1,30 @@ +package org.knowm.xchange.gateio.service; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.IOException; +import java.math.BigDecimal; +import org.junit.jupiter.api.Test; +import org.knowm.xchange.currency.Currency; +import org.knowm.xchange.dto.account.AccountInfo; +import org.knowm.xchange.dto.account.Balance; +import org.knowm.xchange.gateio.GateioExchangeWiremock; + +class GateioAccountServiceTest extends GateioExchangeWiremock { + + GateioAccountService gateioAccountService = ((GateioAccountService) exchange.getAccountService()); + + + @Test + void getAccountInfo() throws IOException { + + AccountInfo accountInfo = gateioAccountService.getAccountInfo(); + + assertThat(accountInfo.getWallet("spot").balances()).hasSize(1); + + Balance usdtBalance = accountInfo.getWallet().getBalance(Currency.USDT); + assertThat(usdtBalance.getTotal()).isEqualTo(new BigDecimal("5.2")); + assertThat(usdtBalance.getAvailable()).isEqualTo(new BigDecimal("4.1")); + assertThat(usdtBalance.getFrozen()).isEqualTo(new BigDecimal("1.1")); + } +} \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/resources/__files/api_v4_spot_accounts.json b/xchange-gateio-v4/src/test/resources/__files/api_v4_spot_accounts.json new file mode 100644 index 00000000000..7cb352ebaf2 --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/__files/api_v4_spot_accounts.json @@ -0,0 +1,7 @@ +[ + { + "currency": "USDT", + "available": "4.1", + "locked": "1.1" + } +] \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_accounts.json b/xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_accounts.json new file mode 100644 index 00000000000..475e7b19905 --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_accounts.json @@ -0,0 +1,15 @@ +{ + "id" : "2e902638-c6b5-450a-911c-d501d9a5ee44", + "name" : "api_v4_spot_accounts", + "request" : { + "url" : "/api/v4/spot/accounts", + "method" : "GET" + }, + "response" : { + "status" : 200, + "bodyFileName" : "api_v4_spot_accounts.json" + }, + "uuid" : "2e902638-c6b5-450a-911c-d501d9a5ee44", + "persistent" : true, + "insertionIndex" : 10 +} \ No newline at end of file From 4c32e02c8adcb3c63293e58ebfc977dab7314c10 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Tue, 30 May 2023 01:42:53 +0200 Subject: [PATCH 017/159] [gateio-v4] Add error mapping --- .../knowm/xchange/gateio/GateioErrorAdapter.java | 2 ++ .../service/GateioAccountServiceRawTest.java | 7 +++++++ .../api_v4_wallet_withdraw_status-forbidden.json | 4 ++++ .../api_v4_wallet_withdraw_status-forbidden.json | 15 +++++++++++++++ 4 files changed, 28 insertions(+) create mode 100644 xchange-gateio-v4/src/test/resources/__files/exceptions/api_v4_wallet_withdraw_status-forbidden.json create mode 100644 xchange-gateio-v4/src/test/resources/mappings/exceptions/api_v4_wallet_withdraw_status-forbidden.json 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 361d756535a..c682e306c93 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 @@ -11,6 +11,7 @@ public class GateioErrorAdapter { public final String INVALID_SIGNATURE = "INVALID_SIGNATURE"; public final String INVALID_KEY = "INVALID_KEY"; + public final String FORBIDDEN = "FORBIDDEN"; public final String INVALID_CURRENCY = "INVALID_CURRENCY"; @@ -19,6 +20,7 @@ public ExchangeException adapt(GateioException e) { switch (e.getLabel()) { case INVALID_SIGNATURE: case INVALID_KEY: + case FORBIDDEN: return new ExchangeSecurityException(e.getMessage(), e); case INVALID_CURRENCY: diff --git a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceRawTest.java b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceRawTest.java index 23f6ca7dca3..9fade431909 100644 --- a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceRawTest.java +++ b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceRawTest.java @@ -57,6 +57,13 @@ public void http_401_exception_mapped() { } + @Test + public void http_403_exception_mapped() { + assertThatExceptionOfType(ExchangeSecurityException.class) + .isThrownBy(() -> gateioAccountServiceRaw.getWithdrawStatus(Currency.getInstance("RETURN-FORBIDDEN"))); + } + + @Test public void invalid_currency_exception_mapped() { assertThatExceptionOfType(InstrumentNotValidException.class) diff --git a/xchange-gateio-v4/src/test/resources/__files/exceptions/api_v4_wallet_withdraw_status-forbidden.json b/xchange-gateio-v4/src/test/resources/__files/exceptions/api_v4_wallet_withdraw_status-forbidden.json new file mode 100644 index 00000000000..d090b2c43df --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/__files/exceptions/api_v4_wallet_withdraw_status-forbidden.json @@ -0,0 +1,4 @@ +{ + "message": "Request IP not in whitelist: 1.1.1.1", + "label": "FORBIDDEN" +} diff --git a/xchange-gateio-v4/src/test/resources/mappings/exceptions/api_v4_wallet_withdraw_status-forbidden.json b/xchange-gateio-v4/src/test/resources/mappings/exceptions/api_v4_wallet_withdraw_status-forbidden.json new file mode 100644 index 00000000000..0186263e651 --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/mappings/exceptions/api_v4_wallet_withdraw_status-forbidden.json @@ -0,0 +1,15 @@ +{ + "id" : "d6adff40-80fe-4dd1-827a-57de56020d50", + "name" : "api_v4_wallet_withdraw_status", + "request" : { + "url" : "/api/v4/wallet/withdraw_status?currency=RETURN-FORBIDDEN", + "method" : "GET" + }, + "response" : { + "status" : 403, + "bodyFileName" : "exceptions/api_v4_wallet_withdraw_status-forbidden.json" + }, + "uuid" : "d6adff40-80fe-4dd1-827a-57de56020d50", + "persistent" : true, + "insertionIndex" : 16 +} \ No newline at end of file From c97ea0b6fb26b11f6f485b22904736ad1781d3bb Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Wed, 31 May 2023 12:59:59 +0200 Subject: [PATCH 018/159] [gateio-v4] Add more endpoints, refactor --- .../java/org/knowm/xchange/gateio/Gateio.java | 18 +++++-- .../knowm/xchange/gateio/GateioAdapters.java | 13 +++++ .../knowm/xchange/gateio/GateioExchange.java | 10 +++- .../GateioJacksonObjectMapperFactory.java | 7 ++- .../TimestampSecondsToInstantConverter.java | 12 +++++ .../marketdata/GateioCurrencyPairDetails.java | 52 +++++++++++++++++++ .../gateio/service/GateioBaseService.java | 1 + .../service/GateioMarketDataService.java | 22 ++++++++ .../service/GateioMarketDataServiceRaw.java | 19 +++++-- .../xchange/gateio/GateioExchangeTest.java | 6 +-- .../GateioMarketDataServiceRawTest.java | 50 ++++++++++++++++-- .../service/GateioMarketDataServiceTest.java | 4 +- .../__files/api_v4_spot_currency_pairs.json | 40 ++++++++++++++ .../api_v4_spot_currency_pairs_chz_usdt.json | 12 +++++ .../mappings/api_v4_spot_currency_pairs.json | 15 ++++++ .../api_v4_spot_currency_pairs_chz_usdt.json | 15 ++++++ 16 files changed, 276 insertions(+), 20 deletions(-) rename xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/{service => config}/GateioJacksonObjectMapperFactory.java (69%) create mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/TimestampSecondsToInstantConverter.java create mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioCurrencyPairDetails.java create mode 100644 xchange-gateio-v4/src/test/resources/__files/api_v4_spot_currency_pairs.json create mode 100644 xchange-gateio-v4/src/test/resources/__files/api_v4_spot_currency_pairs_chz_usdt.json create mode 100644 xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_currency_pairs.json create mode 100644 xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_currency_pairs_chz_usdt.json 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 2e68fe7ee74..f0bb26a9e81 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 @@ -9,10 +9,12 @@ import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; +import org.knowm.xchange.gateio.dto.GateioException; import org.knowm.xchange.gateio.dto.marketdata.GateioCandlestickHistory; import org.knowm.xchange.gateio.dto.marketdata.GateioCoinInfoWrapper; 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.GateioCurrencyPairs; import org.knowm.xchange.gateio.dto.marketdata.GateioDepth; import org.knowm.xchange.gateio.dto.marketdata.GateioMarketInfoWrapper; @@ -81,7 +83,7 @@ GateioCandlestickHistory getKlinesGate( @GET @Path("api/v4/spot/currencies") - List getCurrencies(); + List getCurrencies() throws IOException, GateioException; @GET @@ -89,12 +91,22 @@ GateioCandlestickHistory getKlinesGate( GateioOrderBook getOrderBook( @QueryParam("currency_pair") String currencyPair, @QueryParam("with_id") Boolean withId - ); + ) throws IOException, GateioException; @GET @Path("api/v4/wallet/currency_chains") - List getCurrencyChains(@QueryParam("currency") String currency); + List getCurrencyChains(@QueryParam("currency") String currency) throws IOException, GateioException; + + + @GET + @Path("api/v4/spot/currency_pairs") + List getCurrencyPairDetails() throws IOException, GateioException; + + + @GET + @Path("api/v4/spot/currency_pairs/{currency_pair}") + GateioCurrencyPairDetails getCurrencyPairDetails(@PathParam("currency_pair") String currencyPair) throws IOException, GateioException; } diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java index 0334731bf65..3537d97e9a5 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java @@ -36,6 +36,7 @@ import org.knowm.xchange.gateio.dto.account.GateioDepositsWithdrawals; import org.knowm.xchange.gateio.dto.account.GateioFunds; import org.knowm.xchange.gateio.dto.marketdata.GateioCoin; +import org.knowm.xchange.gateio.dto.marketdata.GateioCurrencyPairDetails; import org.knowm.xchange.gateio.dto.marketdata.GateioDepth; import org.knowm.xchange.gateio.dto.marketdata.GateioFeeInfo; import org.knowm.xchange.gateio.dto.marketdata.GateioMarketInfoWrapper.GateioMarketInfo; @@ -205,6 +206,18 @@ public static Trades adaptTrades(GateioTradeHistory tradeHistory, CurrencyPair c return new Trades(tradeList, lastTradeId, TradeSortType.SortByTimestamp); } + + public static InstrumentMetaData toInstrumentMetaData(GateioCurrencyPairDetails gateioCurrencyPairDetails) { + return new InstrumentMetaData.Builder() + .tradingFee(gateioCurrencyPairDetails.getFee()) + .minimumAmount(gateioCurrencyPairDetails.getMinAssetAmount()) + .counterMinimumAmount(gateioCurrencyPairDetails.getMinQuoteAmount()) + .volumeScale(gateioCurrencyPairDetails.getAssetScale()) + .priceScale(gateioCurrencyPairDetails.getQuoteScale()) + .build(); + } + + public static Wallet adaptWallet(GateioFunds bterAccountInfo) { List balances = new ArrayList<>(); diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioExchange.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioExchange.java index 855af49402b..d97ff74d1ef 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioExchange.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioExchange.java @@ -1,13 +1,17 @@ package org.knowm.xchange.gateio; import java.io.IOException; +import java.util.Map; import java.util.concurrent.TimeUnit; import org.knowm.xchange.BaseExchange; import org.knowm.xchange.Exchange; import org.knowm.xchange.ExchangeSpecification; +import org.knowm.xchange.dto.meta.ExchangeMetaData; +import org.knowm.xchange.dto.meta.InstrumentMetaData; import org.knowm.xchange.gateio.service.GateioAccountService; import org.knowm.xchange.gateio.service.GateioMarketDataService; import org.knowm.xchange.gateio.service.GateioTradeService; +import org.knowm.xchange.instrument.Instrument; import org.knowm.xchange.utils.nonce.CurrentTimeIncrementalNonceFactory; import si.mazi.rescu.SynchronizedValueFactory; @@ -42,7 +46,9 @@ public SynchronizedValueFactory getNonceFactory() { @Override public void remoteInit() throws IOException { -// exchangeMetaData = -// GateioAdapters.adaptToExchangeMetaData((GateioMarketDataServiceRaw) marketDataService); + + Map instruments = ((GateioMarketDataService) marketDataService).getMetaDataByInstrument(); + + exchangeMetaData = new ExchangeMetaData(instruments, null, null, null, null); } } diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioJacksonObjectMapperFactory.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/GateioJacksonObjectMapperFactory.java similarity index 69% rename from xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioJacksonObjectMapperFactory.java rename to xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/GateioJacksonObjectMapperFactory.java index 6a7d27aae21..a3d257939d9 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioJacksonObjectMapperFactory.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/GateioJacksonObjectMapperFactory.java @@ -1,7 +1,6 @@ -package org.knowm.xchange.gateio.service; - -import static com.fasterxml.jackson.databind.DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS; +package org.knowm.xchange.gateio.config; +import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import si.mazi.rescu.serialization.jackson.DefaultJacksonObjectMapperFactory; @@ -11,7 +10,7 @@ public class GateioJacksonObjectMapperFactory extends DefaultJacksonObjectMapper @Override public void configureObjectMapper(ObjectMapper objectMapper) { super.configureObjectMapper(objectMapper); - objectMapper.configure(READ_DATE_TIMESTAMPS_AS_NANOSECONDS, false); + objectMapper.configure(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS, false); // enable parsing to Instant objectMapper.registerModule(new JavaTimeModule()); } diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/TimestampSecondsToInstantConverter.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/TimestampSecondsToInstantConverter.java new file mode 100644 index 00000000000..58c57486394 --- /dev/null +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/TimestampSecondsToInstantConverter.java @@ -0,0 +1,12 @@ +package org.knowm.xchange.gateio.config; + +import com.fasterxml.jackson.databind.util.StdConverter; +import java.time.Instant; + +public class TimestampSecondsToInstantConverter extends StdConverter { + + @Override + public Instant convert(final Long value) { + return Instant.ofEpochSecond(value); + } +} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioCurrencyPairDetails.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioCurrencyPairDetails.java new file mode 100644 index 00000000000..bfa24aa3144 --- /dev/null +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioCurrencyPairDetails.java @@ -0,0 +1,52 @@ +package org.knowm.xchange.gateio.dto.marketdata; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import java.math.BigDecimal; +import java.time.Instant; +import lombok.Builder; +import lombok.Data; +import lombok.extern.jackson.Jacksonized; +import org.knowm.xchange.gateio.config.TimestampSecondsToInstantConverter; + +@Data +@Builder +@Jacksonized +public class GateioCurrencyPairDetails { + + @JsonProperty("id") + String id; + + @JsonProperty("base") + String asset; + + @JsonProperty("quote") + String quote; + + @JsonProperty("fee") + BigDecimal fee; + + @JsonProperty("min_base_amount") + BigDecimal minAssetAmount; + + @JsonProperty("min_quote_amount") + BigDecimal minQuoteAmount; + + @JsonProperty("amount_precision") + Integer assetScale; + + @JsonProperty("precision") + Integer quoteScale; + + @JsonProperty("trade_status") + String tradeStatus; + + @JsonProperty("sell_start") + @JsonDeserialize(converter = TimestampSecondsToInstantConverter.class) + Instant startOfSells; + + @JsonProperty("buy_start") + @JsonDeserialize(converter = TimestampSecondsToInstantConverter.class) + Instant startOfBuys; + +} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioBaseService.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioBaseService.java index 46b3448bf0e..9ec74fbc25b 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioBaseService.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioBaseService.java @@ -6,6 +6,7 @@ import org.knowm.xchange.gateio.GateioAuthenticated; import org.knowm.xchange.gateio.GateioExchange; import org.knowm.xchange.gateio.GateioV4Authenticated; +import org.knowm.xchange.gateio.config.GateioJacksonObjectMapperFactory; import org.knowm.xchange.gateio.dto.GateioBaseResponse; import org.knowm.xchange.service.BaseExchangeService; import org.knowm.xchange.service.BaseService; 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 b281a6d5ec6..39ad4c22a97 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 @@ -10,8 +10,12 @@ 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.InstrumentMetaData; import org.knowm.xchange.gateio.GateioAdapters; +import org.knowm.xchange.gateio.GateioErrorAdapter; import org.knowm.xchange.gateio.GateioExchange; +import org.knowm.xchange.gateio.dto.GateioException; +import org.knowm.xchange.gateio.dto.marketdata.GateioCurrencyPairDetails; import org.knowm.xchange.gateio.dto.marketdata.GateioDepth; import org.knowm.xchange.gateio.dto.marketdata.GateioOrderBook; import org.knowm.xchange.gateio.dto.marketdata.GateioTicker; @@ -98,4 +102,22 @@ public Trades getTrades(CurrencyPair currencyPair, Object... args) throws IOExce return GateioAdapters.adaptTrades(tradeHistory, currencyPair); } + + + public Map getMetaDataByInstrument() throws IOException { + try { + List metadata = getCurrencyPairDetails(); + + return metadata.stream() + .collect(Collectors.toMap( + gateioCurrencyPairDetails -> new CurrencyPair(gateioCurrencyPairDetails.getAsset(), gateioCurrencyPairDetails.getQuote()), + GateioAdapters::toInstrumentMetaData + )); + } + catch (GateioException e) { + throw GateioErrorAdapter.adapt(e); + } + } + + } 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 3cb33b1dcf6..a6684edba1e 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 @@ -17,6 +17,7 @@ import org.knowm.xchange.gateio.dto.marketdata.GateioCoinInfoWrapper; 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.GateioDepth; import org.knowm.xchange.gateio.dto.marketdata.GateioFeeInfo; import org.knowm.xchange.gateio.dto.marketdata.GateioKline; @@ -151,17 +152,29 @@ public List getKlines(CurrencyPair pair, GateioKlineInterval interv } - public List getCurrencies() { + public List getCurrencies() throws IOException { return gateio.getCurrencies(); } - public GateioOrderBook getGateioOrderBook(Instrument instrument) { + public GateioOrderBook getGateioOrderBook(Instrument instrument) throws IOException { return gateio.getOrderBook(GateioAdapters.toQueryParam(instrument), false); } - public List getCurrencyChains(Currency currency) { + public List getCurrencyChains(Currency currency) throws IOException { return gateio.getCurrencyChains(currency.getCurrencyCode()); } + + + public List getCurrencyPairDetails() throws IOException { + return gateio.getCurrencyPairDetails(); + } + + + public GateioCurrencyPairDetails getCurrencyPairDetails(Instrument instrument) throws IOException { + return gateio.getCurrencyPairDetails(GateioAdapters.toQueryParam(instrument)); + } + + } diff --git a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/GateioExchangeTest.java b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/GateioExchangeTest.java index c36743ee4bf..20cd4173b3e 100644 --- a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/GateioExchangeTest.java +++ b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/GateioExchangeTest.java @@ -3,12 +3,10 @@ import static org.assertj.core.api.Assertions.assertThat; import java.math.BigDecimal; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.knowm.xchange.currency.CurrencyPair; import org.knowm.xchange.dto.meta.InstrumentMetaData; -@Ignore public class GateioExchangeTest extends GateioExchangeWiremock { @Test @@ -16,6 +14,8 @@ public void metadata_present() { InstrumentMetaData expected = new InstrumentMetaData.Builder() .tradingFee(new BigDecimal("0.2")) .minimumAmount(new BigDecimal("0.0001")) + .counterMinimumAmount(BigDecimal.ONE) + .volumeScale(4) .priceScale(1) .marketOrderEnabled(false) .build(); diff --git a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioMarketDataServiceRawTest.java b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioMarketDataServiceRawTest.java index 310b2bf1e55..56a352c1750 100644 --- a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioMarketDataServiceRawTest.java +++ b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioMarketDataServiceRawTest.java @@ -15,6 +15,7 @@ import org.knowm.xchange.gateio.GateioExchangeWiremock; 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.GateioMarketInfoWrapper; import org.knowm.xchange.gateio.dto.marketdata.GateioMarketInfoWrapper.GateioMarketInfo; import org.knowm.xchange.gateio.dto.marketdata.GateioOrderBook; @@ -39,7 +40,7 @@ public void getMarketInfo_valid() throws IOException { @Test - public void getCurrencies_valid() { + public void getCurrencies_valid() throws IOException { List actual = gateioMarketDataServiceRaw.getCurrencies(); assertThat(actual).hasSize(5); @@ -61,7 +62,7 @@ public void getCurrencies_valid() { @Test - public void getGateioOrderBook_valid() { + public void getGateioOrderBook_valid() throws IOException { List expectedAsks = new ArrayList<>(); expectedAsks.add(PriceSizeEntry.builder() .price(new BigDecimal("200")) @@ -96,7 +97,7 @@ public void getGateioOrderBook_valid() { @Test - public void getCurrencyChains_valid_result() { + public void getCurrencyChains_valid_result() throws IOException { List expected = new ArrayList<>(); expected.add(GateioCurrencyChain.builder() .chain("BTC") @@ -119,4 +120,47 @@ public void getCurrencyChains_valid_result() { assertThat(actual).isEqualTo(expected); } + + + @Test + void valid_currencypairs_details() throws IOException { + List details = gateioMarketDataServiceRaw.getCurrencyPairDetails(); + assertThat(details).hasSize(3); + GateioCurrencyPairDetails expectedChz = GateioCurrencyPairDetails.builder() + .id("CHZ_USDT") + .asset("CHZ") + .quote("USDT") + .fee(new BigDecimal("0.2")) + .minQuoteAmount(BigDecimal.ONE) + .assetScale(2) + .quoteScale(5) + .tradeStatus("tradable") + .startOfSells(Instant.parse("2020-12-24T04:00:00.000Z")) + .startOfBuys(Instant.parse("2020-12-24T06:00:00.000Z")) + .build(); + + GateioCurrencyPairDetails actualChz = details.get(1); + + assertThat(actualChz).isEqualTo(expectedChz); + } + + + @Test + void valid_single_currencypair_details() throws IOException { + GateioCurrencyPairDetails actualChz = gateioMarketDataServiceRaw.getCurrencyPairDetails(new CurrencyPair("CHZ/USDT")); + GateioCurrencyPairDetails expectedChz = GateioCurrencyPairDetails.builder() + .id("CHZ_USDT") + .asset("CHZ") + .quote("USDT") + .fee(new BigDecimal("0.2")) + .minQuoteAmount(BigDecimal.ONE) + .assetScale(2) + .quoteScale(5) + .tradeStatus("tradable") + .startOfSells(Instant.parse("2020-12-24T04:00:00.000Z")) + .startOfBuys(Instant.parse("2020-12-24T06:00:00.000Z")) + .build(); + + assertThat(actualChz).isEqualTo(expectedChz); + } } \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioMarketDataServiceTest.java b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioMarketDataServiceTest.java index 5302ed05631..6861584ea98 100644 --- a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioMarketDataServiceTest.java +++ b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioMarketDataServiceTest.java @@ -21,7 +21,7 @@ public class GateioMarketDataServiceTest extends GateioExchangeWiremock { @Test - public void getOrderBook_valid() throws IOException { + void getOrderBook_valid() throws IOException { OrderBook actual = gateioMarketDataService.getOrderBook(CurrencyPair.BTC_USDT); List expectedAsks = new ArrayList<>(); @@ -52,4 +52,4 @@ public void getOrderBook_valid() throws IOException { .ignoringFieldsMatchingRegexes(".*userReference") .isEqualTo(expected); } -} \ No newline at end of file +} diff --git a/xchange-gateio-v4/src/test/resources/__files/api_v4_spot_currency_pairs.json b/xchange-gateio-v4/src/test/resources/__files/api_v4_spot_currency_pairs.json new file mode 100644 index 00000000000..b4d06c20ae8 --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/__files/api_v4_spot_currency_pairs.json @@ -0,0 +1,40 @@ +[ + { + "id": "BTC_USDT", + "base": "BTC", + "quote": "USDT", + "fee": "0.2", + "min_base_amount": "0.0001", + "min_quote_amount": "1", + "amount_precision": 4, + "precision": 1, + "trade_status": "tradable", + "sell_start": 0, + "buy_start": 0 + }, + { + "id": "CHZ_USDT", + "base": "CHZ", + "quote": "USDT", + "fee": "0.2", + "min_quote_amount": "1", + "amount_precision": 2, + "precision": 5, + "trade_status": "tradable", + "sell_start": 1608782400, + "buy_start": 1608789600 + }, + { + "id": "ETH_USDT", + "base": "ETH", + "quote": "USDT", + "fee": "0.2", + "min_base_amount": "0.001", + "min_quote_amount": "1", + "amount_precision": 4, + "precision": 2, + "trade_status": "tradable", + "sell_start": 0, + "buy_start": 0 + } +] \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/resources/__files/api_v4_spot_currency_pairs_chz_usdt.json b/xchange-gateio-v4/src/test/resources/__files/api_v4_spot_currency_pairs_chz_usdt.json new file mode 100644 index 00000000000..3a1bcc29a6b --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/__files/api_v4_spot_currency_pairs_chz_usdt.json @@ -0,0 +1,12 @@ +{ + "id": "CHZ_USDT", + "base": "CHZ", + "quote": "USDT", + "fee": "0.2", + "min_quote_amount": "1", + "amount_precision": 2, + "precision": 5, + "trade_status": "tradable", + "sell_start": 1608782400, + "buy_start": 1608789600 +} \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_currency_pairs.json b/xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_currency_pairs.json new file mode 100644 index 00000000000..288f999c9d9 --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_currency_pairs.json @@ -0,0 +1,15 @@ +{ + "id" : "6a2422dc-c1e6-4f5b-95e9-89a626210111", + "name" : "api_v4_spot_currency_pairs", + "request" : { + "url" : "/api/v4/spot/currency_pairs", + "method" : "GET" + }, + "response" : { + "status" : 200, + "bodyFileName" : "api_v4_spot_currency_pairs.json" + }, + "uuid" : "6a2422dc-c1e6-4f5b-95e9-89a626210111", + "persistent" : true, + "insertionIndex" : 11 +} \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_currency_pairs_chz_usdt.json b/xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_currency_pairs_chz_usdt.json new file mode 100644 index 00000000000..d208b0f612b --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_currency_pairs_chz_usdt.json @@ -0,0 +1,15 @@ +{ + "id" : "9cb9e274-4bf7-419e-9b28-ed6c7dbf8f52", + "name" : "api_v4_spot_currency_pairs_chz_usdt", + "request" : { + "url" : "/api/v4/spot/currency_pairs/chz_usdt", + "method" : "GET" + }, + "response" : { + "status" : 200, + "bodyFileName" : "api_v4_spot_currency_pairs_chz_usdt.json" + }, + "uuid" : "9cb9e274-4bf7-419e-9b28-ed6c7dbf8f52", + "persistent" : true, + "insertionIndex" : 13 +} \ No newline at end of file From 34b72d305e5aa853005b69b3df4159480fe76afe Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Wed, 31 May 2023 21:38:55 +0200 Subject: [PATCH 019/159] [gateio-v4] Add getting deposit address --- .../xchange/gateio/GateioAuthenticated.java | 9 --- .../xchange/gateio/GateioV4Authenticated.java | 11 +++ .../dto/account/GateioDepositAddress.java | 77 +++++++++---------- .../gateio/service/GateioAccountService.java | 5 -- .../service/GateioAccountServiceRaw.java | 22 +++--- .../service/GateioAccountServiceRawTest.java | 44 ++++++++++- ...api_v4_wallet_deposit_address-pending.json | 13 ++++ .../api_v4_wallet_deposit_address-valid.json | 13 ++++ ...api_v4_wallet_deposit_address-pending.json | 15 ++++ .../api_v4_wallet_deposit_address-valid.json | 15 ++++ 10 files changed, 155 insertions(+), 69 deletions(-) create mode 100644 xchange-gateio-v4/src/test/resources/__files/api_v4_wallet_deposit_address-pending.json create mode 100644 xchange-gateio-v4/src/test/resources/__files/api_v4_wallet_deposit_address-valid.json create mode 100644 xchange-gateio-v4/src/test/resources/mappings/api_v4_wallet_deposit_address-pending.json create mode 100644 xchange-gateio-v4/src/test/resources/mappings/api_v4_wallet_deposit_address-valid.json diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAuthenticated.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAuthenticated.java index 9ccf9b1a585..f4e7d4652a1 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAuthenticated.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAuthenticated.java @@ -11,7 +11,6 @@ import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import org.knowm.xchange.gateio.dto.GateioBaseResponse; -import org.knowm.xchange.gateio.dto.account.GateioDepositAddress; import org.knowm.xchange.gateio.dto.account.GateioDepositsWithdrawals; import org.knowm.xchange.gateio.dto.account.GateioFunds; import org.knowm.xchange.gateio.dto.marketdata.GateioFeeInfo; @@ -31,14 +30,6 @@ public interface GateioAuthenticated { GateioFunds getFunds(@HeaderParam("KEY") String apiKey, @HeaderParam("SIGN") ParamsDigest signer) throws IOException; - @POST - @Path("private/depositAddress") - GateioDepositAddress getDepositAddress( - @HeaderParam("KEY") String apiKey, - @HeaderParam("SIGN") ParamsDigest signer, - @FormParam("currency") String currency) - throws IOException; - @POST @Path("private/withdraw") GateioBaseResponse withdraw( diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java index 07616e8ca40..7ebfdee8b93 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java @@ -10,6 +10,7 @@ import javax.ws.rs.core.MediaType; import org.knowm.xchange.gateio.dto.GateioException; import org.knowm.xchange.gateio.dto.account.GateioCurrencyBalance; +import org.knowm.xchange.gateio.dto.account.GateioDepositAddress; import org.knowm.xchange.gateio.dto.account.GateioWithdrawStatus; import si.mazi.rescu.ParamsDigest; import si.mazi.rescu.SynchronizedValueFactory; @@ -18,6 +19,16 @@ @Produces(MediaType.APPLICATION_JSON) public interface GateioV4Authenticated { + @GET + @Path("wallet/deposit_address") + GateioDepositAddress getDepositAddress( + @HeaderParam("KEY") String apiKey, + @HeaderParam("Timestamp") SynchronizedValueFactory timestamp, + @HeaderParam("SIGN") ParamsDigest signer, + @QueryParam("currency") String currency + ) throws IOException, GateioException; + + @GET @Path("wallet/withdraw_status") List getWithdrawStatus( diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioDepositAddress.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioDepositAddress.java index e07dcfc8bc4..c608c3d0110 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioDepositAddress.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioDepositAddress.java @@ -1,51 +1,44 @@ package org.knowm.xchange.gateio.dto.account; import com.fasterxml.jackson.annotation.JsonProperty; -import org.knowm.xchange.gateio.dto.GateioBaseResponse; - -public class GateioDepositAddress extends GateioBaseResponse { - - private final String baseAddress; - - private final String addressTag; - - /** - * Constructor - * - * @param theAvailable - * @param theLocked - */ - public GateioDepositAddress( - @JsonProperty("addr") String addr, - @JsonProperty("result") boolean result, - @JsonProperty("message") final String message) { - - super(result, message); - - String[] addressComponent = addr.split("/"); - this.baseAddress = addressComponent[0]; - if (addressComponent.length > 1) { - this.addressTag = addressComponent[1]; - } else { - this.addressTag = null; - } - } +import java.util.List; +import lombok.Builder; +import lombok.Data; +import lombok.extern.jackson.Jacksonized; - public String getBaseAddress() { - return baseAddress; - } +@Data +@Builder +@Jacksonized +public class GateioDepositAddress { - public String getAddressTag() { - return addressTag; - } + @JsonProperty("currency") + String currency; + + @JsonProperty("multichain_addresses") + List multichainAddresses; + + + @Data + @Builder + @Jacksonized + public static class MultichainAddress { - @Override - public String toString() { + @JsonProperty("chain") + String chain; + + @JsonProperty("address") + String address; + + @JsonProperty("payment_id") + String memo; + + @JsonProperty("payment_name") + String memoType; + + @JsonProperty("obtain_failed") + Boolean failed; - return "BTERDepositAddressReturn [baseAddress=" - + baseAddress - + ", addressTag=" - + addressTag - + "]"; } + + } diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountService.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountService.java index 5ebd6bcadea..c55d2907756 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountService.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountService.java @@ -95,11 +95,6 @@ public String withdrawFunds(WithdrawFundsParams params) throws IOException { throw new IllegalStateException("Don't know how to withdraw: " + params); } - @Override - public String requestDepositAddress(Currency currency, String... args) throws IOException { - - return super.getGateioDepositAddress(currency).getBaseAddress(); - } @Override public TradeHistoryParams createFundingHistoryParams() { diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountServiceRaw.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountServiceRaw.java index 81fdbb6e064..4c6f1133fae 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountServiceRaw.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountServiceRaw.java @@ -27,15 +27,6 @@ public GateioAccountServiceRaw(GateioExchange exchange) { super(exchange); } - public GateioDepositAddress getGateioDepositAddress(Currency currency) throws IOException { - GateioDepositAddress depositAddress = - gateioAuthenticated.getDepositAddress( - exchange.getExchangeSpecification().getApiKey(), - signatureCreator, - currency.getCurrencyCode()); - return depositAddress; - } - public String withdraw( Currency currency, BigDecimal amount, String baseAddress, String addressTag) throws IOException { @@ -72,6 +63,19 @@ public String withdraw(String currency, BigDecimal amount, String address) throw } + public GateioDepositAddress getDepositAddress(Currency currency) throws IOException { + String currencyCode = currency == null ? null : currency.getCurrencyCode(); + + try { + return gateioV4Authenticated.getDepositAddress(apiKey, exchange.getNonceFactory(), gateioV4ParamsDigest, currencyCode); + } + catch (GateioException e) { + throw GateioErrorAdapter.adapt(e); + } + + } + + public List getWithdrawStatus(Currency currency) throws IOException { String currencyCode = currency == null ? null : currency.getCurrencyCode(); diff --git a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceRawTest.java b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceRawTest.java index 9fade431909..5a3830b3b95 100644 --- a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceRawTest.java +++ b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceRawTest.java @@ -13,6 +13,8 @@ import org.knowm.xchange.exceptions.ExchangeSecurityException; import org.knowm.xchange.exceptions.InstrumentNotValidException; import org.knowm.xchange.gateio.GateioExchangeWiremock; +import org.knowm.xchange.gateio.dto.account.GateioDepositAddress; +import org.knowm.xchange.gateio.dto.account.GateioDepositAddress.MultichainAddress; import org.knowm.xchange.gateio.dto.account.GateioWithdrawStatus; public class GateioAccountServiceRawTest extends GateioExchangeWiremock { @@ -20,7 +22,7 @@ public class GateioAccountServiceRawTest extends GateioExchangeWiremock { GateioAccountServiceRaw gateioAccountServiceRaw = ((GateioAccountServiceRaw) exchange.getAccountService()); @Test - public void getWithdrawStatus_valid() throws IOException { + void getWithdrawStatus_valid() throws IOException { Map expectedWithdrawFeeByChain = new HashMap<>(); expectedWithdrawFeeByChain.put("ETH", new BigDecimal("0.93")); expectedWithdrawFeeByChain.put("GTEVM", new BigDecimal("0.0049")); @@ -49,7 +51,7 @@ public void getWithdrawStatus_valid() throws IOException { @Test - public void http_401_exception_mapped() { + void http_401_exception_mapped() { assertThatExceptionOfType(ExchangeSecurityException.class) .isThrownBy(() -> gateioAccountServiceRaw.getWithdrawStatus(Currency.getInstance("THROW_401"))); assertThatExceptionOfType(ExchangeSecurityException.class) @@ -58,17 +60,51 @@ public void http_401_exception_mapped() { @Test - public void http_403_exception_mapped() { + void http_403_exception_mapped() { assertThatExceptionOfType(ExchangeSecurityException.class) .isThrownBy(() -> gateioAccountServiceRaw.getWithdrawStatus(Currency.getInstance("RETURN-FORBIDDEN"))); } @Test - public void invalid_currency_exception_mapped() { + void invalid_currency_exception_mapped() { assertThatExceptionOfType(InstrumentNotValidException.class) .isThrownBy(() -> gateioAccountServiceRaw.getWithdrawStatus(Currency.getInstance("invalid-currency"))); } + @Test + void pending_deposit_address() throws IOException { + GateioDepositAddress a = gateioAccountServiceRaw.getDepositAddress(Currency.getInstance("ITA")); + + MultichainAddress expected = MultichainAddress.builder() + .chain("CHZ") + .failed(true) + .address("") + .memo("") + .memoType("") + .build(); + + assertThat(a.getMultichainAddresses()).hasSize(1); + assertThat(a.getMultichainAddresses().get(0)).isEqualTo(expected); + } + + + @Test + void valid_deposit_address() throws IOException { + GateioDepositAddress a = gateioAccountServiceRaw.getDepositAddress(Currency.getInstance("ABBC")); + + MultichainAddress expected = MultichainAddress.builder() + .chain("ABBC") + .failed(false) + .address("gateioioabbc") + .memo("00cceed3f9cb5069") + .memoType("Memo") + .build(); + + assertThat(a.getMultichainAddresses()).hasSize(1); + assertThat(a.getMultichainAddresses().get(0)).isEqualTo(expected); + } + + } \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/resources/__files/api_v4_wallet_deposit_address-pending.json b/xchange-gateio-v4/src/test/resources/__files/api_v4_wallet_deposit_address-pending.json new file mode 100644 index 00000000000..1b77bda7d40 --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/__files/api_v4_wallet_deposit_address-pending.json @@ -0,0 +1,13 @@ +{ + "currency": "ITA", + "address": "New address is being generated for you, please wait a moment and refresh this page. ", + "multichain_addresses": [ + { + "chain": "CHZ", + "address": "", + "payment_id": "", + "payment_name": "", + "obtain_failed": 1 + } + ] +} \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/resources/__files/api_v4_wallet_deposit_address-valid.json b/xchange-gateio-v4/src/test/resources/__files/api_v4_wallet_deposit_address-valid.json new file mode 100644 index 00000000000..6ab9d153529 --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/__files/api_v4_wallet_deposit_address-valid.json @@ -0,0 +1,13 @@ +{ + "currency": "ABBC", + "address": "gateioioabbc 00cceed3f9cb5069", + "multichain_addresses": [ + { + "chain": "ABBC", + "address": "gateioioabbc", + "payment_id": "00cceed3f9cb5069", + "payment_name": "Memo", + "obtain_failed": 0 + } + ] +} \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/resources/mappings/api_v4_wallet_deposit_address-pending.json b/xchange-gateio-v4/src/test/resources/mappings/api_v4_wallet_deposit_address-pending.json new file mode 100644 index 00000000000..e12e789b1f8 --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/mappings/api_v4_wallet_deposit_address-pending.json @@ -0,0 +1,15 @@ +{ + "id" : "2cfb7047-1b43-4d6a-af84-d2cc987e16c0", + "name" : "api_v4_wallet_deposit_address", + "request" : { + "url" : "/api/v4/wallet/deposit_address?currency=ITA", + "method" : "GET" + }, + "response" : { + "status" : 200, + "bodyFileName" : "api_v4_wallet_deposit_address-pending.json" + }, + "uuid" : "2cfb7047-1b43-4d6a-af84-d2cc987e16c0", + "persistent" : true, + "insertionIndex" : 20 +} \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/resources/mappings/api_v4_wallet_deposit_address-valid.json b/xchange-gateio-v4/src/test/resources/mappings/api_v4_wallet_deposit_address-valid.json new file mode 100644 index 00000000000..6f2b00e943a --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/mappings/api_v4_wallet_deposit_address-valid.json @@ -0,0 +1,15 @@ +{ + "id" : "9dee83de-0703-43c6-a41d-4e74c90b6635", + "name" : "api_v4_wallet_deposit_address", + "request" : { + "url" : "/api/v4/wallet/deposit_address?currency=ABBC", + "method" : "GET" + }, + "response" : { + "status" : 200, + "bodyFileName" : "api_v4_wallet_deposit_address-valid.json" + }, + "uuid" : "9dee83de-0703-43c6-a41d-4e74c90b6635", + "persistent" : true, + "insertionIndex" : 28 +} \ No newline at end of file From 5408d882a9d5e84ffa72b5969a59fdc8621c5c04 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Sat, 3 Jun 2023 19:56:27 +0200 Subject: [PATCH 020/159] [core] Set code level to java 11 --- pom.xml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 2b449ff61f4..be25a9287d8 100644 --- a/pom.xml +++ b/pom.xml @@ -30,7 +30,10 @@ UTF-8 UTF-8 - 1.8 + 11 + 11 + 11 + 3.23.1 3.12.0 2.14.1 From 768df22cd64283db018f077203ce2138eeafbb18 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Sat, 3 Jun 2023 22:12:24 +0200 Subject: [PATCH 021/159] [gateio-v4] Add getting orders list --- .../knowm/xchange/gateio/GateioAdapters.java | 143 ++++-------------- .../xchange/gateio/GateioV4Authenticated.java | 12 ++ .../gateio/dto/account/GateioOrder.java | 108 +++++++++++++ .../gateio/service/GateioTradeServiceRaw.java | 35 +++-- .../service/GateioTradeServiceRawTest.java | 28 ++++ .../__files/api_v4_spot_orders-btc-open.json | 34 +++++ .../mappings/api_v4_spot_orders-btc-open.json | 15 ++ 7 files changed, 247 insertions(+), 128 deletions(-) create mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioOrder.java create mode 100644 xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioTradeServiceRawTest.java create mode 100644 xchange-gateio-v4/src/test/resources/__files/api_v4_spot_orders-btc-open.json create mode 100644 xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_orders-btc-open.json diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java index 3537d97e9a5..2d065f14894 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java @@ -1,45 +1,34 @@ package org.knowm.xchange.gateio; -import java.io.IOException; import java.math.BigDecimal; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Date; -import java.util.HashMap; import java.util.List; import java.util.Locale; -import java.util.Map; -import java.util.Map.Entry; import java.util.stream.Collectors; +import lombok.experimental.UtilityClass; import org.knowm.xchange.currency.Currency; import org.knowm.xchange.currency.CurrencyPair; +import org.knowm.xchange.dto.Order.OrderStatus; import org.knowm.xchange.dto.Order.OrderType; -import org.knowm.xchange.dto.account.Balance; import org.knowm.xchange.dto.account.FundingRecord; import org.knowm.xchange.dto.account.FundingRecord.Status; -import org.knowm.xchange.dto.account.Wallet; import org.knowm.xchange.dto.marketdata.OrderBook; import org.knowm.xchange.dto.marketdata.Ticker; import org.knowm.xchange.dto.marketdata.Trade; import org.knowm.xchange.dto.marketdata.Trades; import org.knowm.xchange.dto.marketdata.Trades.TradeSortType; -import org.knowm.xchange.dto.meta.CurrencyMetaData; -import org.knowm.xchange.dto.meta.ExchangeMetaData; import org.knowm.xchange.dto.meta.InstrumentMetaData; -import org.knowm.xchange.dto.meta.WalletHealth; import org.knowm.xchange.dto.trade.LimitOrder; import org.knowm.xchange.dto.trade.OpenOrders; import org.knowm.xchange.dto.trade.UserTrade; import org.knowm.xchange.dto.trade.UserTrades; import org.knowm.xchange.gateio.dto.GateioOrderType; import org.knowm.xchange.gateio.dto.account.GateioDepositsWithdrawals; -import org.knowm.xchange.gateio.dto.account.GateioFunds; -import org.knowm.xchange.gateio.dto.marketdata.GateioCoin; import org.knowm.xchange.gateio.dto.marketdata.GateioCurrencyPairDetails; import org.knowm.xchange.gateio.dto.marketdata.GateioDepth; -import org.knowm.xchange.gateio.dto.marketdata.GateioFeeInfo; -import org.knowm.xchange.gateio.dto.marketdata.GateioMarketInfoWrapper.GateioMarketInfo; import org.knowm.xchange.gateio.dto.marketdata.GateioOrderBook; import org.knowm.xchange.gateio.dto.marketdata.GateioPublicOrder; import org.knowm.xchange.gateio.dto.marketdata.GateioTicker; @@ -47,24 +36,21 @@ import org.knowm.xchange.gateio.dto.trade.GateioOpenOrder; import org.knowm.xchange.gateio.dto.trade.GateioOpenOrders; import org.knowm.xchange.gateio.dto.trade.GateioTrade; -import org.knowm.xchange.gateio.service.GateioMarketDataServiceRaw; import org.knowm.xchange.instrument.Instrument; import org.knowm.xchange.utils.DateUtils; -/** Various adapters for converting from Bter DTOs to XChange DTOs */ -public final class GateioAdapters { - /** private Constructor */ - private GateioAdapters() {} +@UtilityClass +public final class GateioAdapters { - public static CurrencyPair adaptCurrencyPair(String pair) { + public CurrencyPair adaptCurrencyPair(String pair) { final String[] currencies = pair.toUpperCase().split("_"); return new CurrencyPair(currencies[0], currencies[1]); } - public static String toQueryParam(Instrument instrument) { + public String toQueryParam(Instrument instrument) { return String.format("%s_%s", instrument.getBase().getCurrencyCode(), instrument.getCounter().getCurrencyCode()) @@ -72,7 +58,7 @@ public static String toQueryParam(Instrument instrument) { } - public static Ticker adaptTicker(CurrencyPair currencyPair, GateioTicker gateioTicker) { + public Ticker adaptTicker(CurrencyPair currencyPair, GateioTicker gateioTicker) { BigDecimal ask = gateioTicker.getLowestAsk(); BigDecimal bid = gateioTicker.getHighestBid(); @@ -98,7 +84,7 @@ public static Ticker adaptTicker(CurrencyPair currencyPair, GateioTicker gateioT } - public static OrderBook toOrderBook(GateioOrderBook gateioOrderBook, Instrument instrument) { + public OrderBook toOrderBook(GateioOrderBook gateioOrderBook, Instrument instrument) { List asks = gateioOrderBook.getAsks().stream() .map(priceSizeEntry -> new LimitOrder(OrderType.ASK, priceSizeEntry.getSize(), instrument, null, null, priceSizeEntry.getPrice())) .collect(Collectors.toList()); @@ -112,13 +98,13 @@ public static OrderBook toOrderBook(GateioOrderBook gateioOrderBook, Instrument } - public static LimitOrder adaptOrder( + public LimitOrder adaptOrder( GateioPublicOrder order, CurrencyPair currencyPair, OrderType orderType) { return new LimitOrder(orderType, order.getAmount(), currencyPair, "", null, order.getPrice()); } - public static List adaptOrders( + public List adaptOrders( List orders, CurrencyPair currencyPair, OrderType orderType) { List limitOrders = new ArrayList<>(); @@ -130,7 +116,7 @@ public static List adaptOrders( return limitOrders; } - public static OrderBook adaptOrderBook(GateioDepth depth, CurrencyPair currencyPair) { + public OrderBook adaptOrderBook(GateioDepth depth, CurrencyPair currencyPair) { List asks = GateioAdapters.adaptOrders(depth.getAsks(), currencyPair, OrderType.ASK); @@ -141,7 +127,7 @@ public static OrderBook adaptOrderBook(GateioDepth depth, CurrencyPair currencyP return new OrderBook(null, asks, bids); } - public static LimitOrder adaptOrder( + public LimitOrder adaptOrder( GateioOpenOrder order, Collection currencyPairs) { String[] currencyPairSplit = order.getCurrencyPair().split("_"); @@ -155,7 +141,7 @@ public static LimitOrder adaptOrder( order.getRate()); } - public static OpenOrders adaptOpenOrders( + public OpenOrders adaptOpenOrders( GateioOpenOrders openOrders, Collection currencyPairs) { List adaptedOrders = new ArrayList<>(); @@ -166,12 +152,12 @@ public static OpenOrders adaptOpenOrders( return new OpenOrders(adaptedOrders); } - public static OrderType adaptOrderType(GateioOrderType cryptoTradeOrderType) { + public OrderType adaptOrderType(GateioOrderType cryptoTradeOrderType) { return (cryptoTradeOrderType.equals(GateioOrderType.BUY)) ? OrderType.BID : OrderType.ASK; } - public static Trade adaptTrade( + public Trade adaptTrade( GateioTradeHistory.GateioPublicTrade trade, CurrencyPair currencyPair) { OrderType orderType = adaptOrderType(trade.getType()); @@ -187,7 +173,7 @@ public static Trade adaptTrade( .build(); } - public static Trades adaptTrades(GateioTradeHistory tradeHistory, CurrencyPair currencyPair) { + public Trades adaptTrades(GateioTradeHistory tradeHistory, CurrencyPair currencyPair) { List tradeList = new ArrayList<>(); long lastTradeId = 0; @@ -207,7 +193,7 @@ public static Trades adaptTrades(GateioTradeHistory tradeHistory, CurrencyPair c } - public static InstrumentMetaData toInstrumentMetaData(GateioCurrencyPairDetails gateioCurrencyPairDetails) { + public InstrumentMetaData toInstrumentMetaData(GateioCurrencyPairDetails gateioCurrencyPairDetails) { return new InstrumentMetaData.Builder() .tradingFee(gateioCurrencyPairDetails.getFee()) .minimumAmount(gateioCurrencyPairDetails.getMinAssetAmount()) @@ -218,28 +204,7 @@ public static InstrumentMetaData toInstrumentMetaData(GateioCurrencyPairDetails } - public static Wallet adaptWallet(GateioFunds bterAccountInfo) { - - List balances = new ArrayList<>(); - for (Entry funds : bterAccountInfo.getAvailableFunds().entrySet()) { - Currency currency = Currency.getInstance(funds.getKey().toUpperCase()); - BigDecimal amount = funds.getValue(); - BigDecimal locked = bterAccountInfo.getLockedFunds().get(currency.toString()); - - balances.add(new Balance(currency, null, amount, locked == null ? BigDecimal.ZERO : locked)); - } - for (Entry funds : bterAccountInfo.getLockedFunds().entrySet()) { - Currency currency = Currency.getInstance(funds.getKey().toUpperCase()); - if (balances.stream().noneMatch(balance -> balance.getCurrency().equals(currency))) { - BigDecimal amount = funds.getValue(); - balances.add(new Balance(currency, null, BigDecimal.ZERO, amount)); - } - } - - return Wallet.Builder.from(balances).build(); - } - - public static UserTrades adaptUserTrades(List userTrades) { + public UserTrades adaptUserTrades(List userTrades) { List trades = new ArrayList<>(); for (GateioTrade userTrade : userTrades) { @@ -249,7 +214,7 @@ public static UserTrades adaptUserTrades(List userTrades) { return new UserTrades(trades, TradeSortType.SortByTimestamp); } - public static UserTrade adaptUserTrade(GateioTrade gateioTrade) { + public UserTrade adaptUserTrade(GateioTrade gateioTrade) { OrderType orderType = adaptOrderType(gateioTrade.getType()); Date timestamp = DateUtils.fromMillisUtc(gateioTrade.getTimeUnix() * 1000); @@ -266,61 +231,7 @@ public static UserTrade adaptUserTrade(GateioTrade gateioTrade) { .build(); } - public static ExchangeMetaData adaptToExchangeMetaData( - GateioMarketDataServiceRaw marketDataService) throws IOException { - - Map currencyPairs = new HashMap<>(); - Map currencies = new HashMap<>(); - - for (Entry entry : - marketDataService.getMarketInfo().entrySet()) { - - CurrencyPair currencyPair = entry.getKey(); - GateioMarketInfo btermarketInfo = entry.getValue(); - - currencyPairs.put(currencyPair, new InstrumentMetaData.Builder() - .tradingFee(btermarketInfo.getFee()) - .minimumAmount(btermarketInfo.getMinAmount()) - .priceScale(btermarketInfo.getDecimalPlaces()) - .build()); - } - - if (marketDataService.getApiKey() != null) { - Map gateioFees = marketDataService.getGateioFees(); - Map coins = marketDataService.getGateioCoinInfo().getCoins(); - for (String coin : coins.keySet()) { - GateioCoin gateioCoin = coins.get(coin); - GateioFeeInfo gateioFeeInfo = gateioFees.get(coin); - if (gateioCoin != null && gateioFeeInfo != null) { - currencies.put(new Currency(coin), adaptCurrencyMetaData(gateioCoin, gateioFeeInfo)); - } - } - } - - return new ExchangeMetaData(currencyPairs, currencies, null, null, null); - } - - private static CurrencyMetaData adaptCurrencyMetaData( - GateioCoin gateioCoin, GateioFeeInfo gateioFeeInfo) { - WalletHealth walletHealth = WalletHealth.ONLINE; - if (gateioCoin.isWithdrawDelayed()) { - walletHealth = WalletHealth.UNKNOWN; - } else if (gateioCoin.isDelisted() - || (gateioCoin.isWithdrawDisabled() && gateioCoin.isDepositDisabled())) { - walletHealth = WalletHealth.OFFLINE; - } else if (gateioCoin.isDepositDisabled()) { - walletHealth = WalletHealth.DEPOSITS_DISABLED; - } else if (gateioCoin.isWithdrawDisabled()) { - walletHealth = WalletHealth.WITHDRAWALS_DISABLED; - } - return new CurrencyMetaData( - 0, - new BigDecimal(gateioFeeInfo.getWithdrawFix()), - gateioFeeInfo.getWithdrawAmountMini(), - walletHealth); - } - - public static List adaptDepositsWithdrawals( + public List adaptDepositsWithdrawals( GateioDepositsWithdrawals depositsWithdrawals) { List result = new ArrayList<>(); @@ -366,7 +277,7 @@ public static List adaptDepositsWithdrawals( return result; } - private static FundingRecord.Status status(String gateioStatus) { + private FundingRecord.Status status(String gateioStatus) { switch (gateioStatus) { case "DONE": return Status.COMPLETE; @@ -374,4 +285,16 @@ private static FundingRecord.Status status(String gateioStatus) { return Status.PROCESSING; // @TODO which statusses are possible at gate.io? } } + + + public String toString(OrderStatus orderStatus) { + switch (orderStatus) { + case OPEN: + return "open"; + case CLOSED: + return "finished"; + default: + throw new IllegalArgumentException("Can't map " + orderStatus); + } + } } diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java index 7ebfdee8b93..940056143ee 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java @@ -11,6 +11,7 @@ import org.knowm.xchange.gateio.dto.GateioException; import org.knowm.xchange.gateio.dto.account.GateioCurrencyBalance; import org.knowm.xchange.gateio.dto.account.GateioDepositAddress; +import org.knowm.xchange.gateio.dto.account.GateioOrder; import org.knowm.xchange.gateio.dto.account.GateioWithdrawStatus; import si.mazi.rescu.ParamsDigest; import si.mazi.rescu.SynchronizedValueFactory; @@ -49,4 +50,15 @@ List getSpotAccounts( ) throws IOException, GateioException; + @GET + @Path("spot/orders") + List listOrders( + @HeaderParam("KEY") String apiKey, + @HeaderParam("Timestamp") SynchronizedValueFactory timestamp, + @HeaderParam("SIGN") ParamsDigest signer, + @QueryParam("currency_pair") String currencyPair, + @QueryParam("status") String status + ) throws IOException, GateioException; + + } diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioOrder.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioOrder.java new file mode 100644 index 00000000000..bf5cd4e5dd7 --- /dev/null +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioOrder.java @@ -0,0 +1,108 @@ +package org.knowm.xchange.gateio.dto.account; + +import com.fasterxml.jackson.annotation.JsonProperty; +import java.math.BigDecimal; +import java.time.Instant; +import lombok.Builder; +import lombok.Data; +import lombok.extern.jackson.Jacksonized; + +@Data +@Builder +@Jacksonized +public class GateioOrder { + + @JsonProperty("id") + String id; + + @JsonProperty("text") + String clientOrderId; + + @JsonProperty("amend_text") + String amendText; + + @JsonProperty("create_time_ms") + Instant createdAt; + + @JsonProperty("update_time_ms") + Instant updatedAt; + + @JsonProperty("status") + String status; + + @JsonProperty("currency_pair") + String currencyPair; + + @JsonProperty("type") + String type; + + @JsonProperty("account") + String account; + + @JsonProperty("side") + String side; + + @JsonProperty("amount") + BigDecimal amount; + + @JsonProperty("price") + BigDecimal price; + + @JsonProperty("time_in_force") + String timeInForce; + + @JsonProperty("iceberg") + BigDecimal icebergAmount; + + @JsonProperty("auto_borrow") + Boolean autoBorrow; + + @JsonProperty("auto_repay") + Boolean autoRepay; + + @JsonProperty("left") + BigDecimal amountLeftToFill; + + @JsonProperty("filled_total") + BigDecimal filledTotalQuote; + + @JsonProperty("avg_deal_price") + BigDecimal avgDealPrice; + + @JsonProperty("fee") + BigDecimal fee; + + @JsonProperty("fee_currency") + String feeCurrency; + + @JsonProperty("point_fee") + BigDecimal pointFee; + + @JsonProperty("gt_fee") + BigDecimal gtFee; + + @JsonProperty("gt_maker_fee") + BigDecimal gtMakerFee; + + @JsonProperty("gt_taker_fee") + BigDecimal gtTakerFee; + + @JsonProperty("gt_discount") + Boolean gtDiscount; + + @JsonProperty("rebated_fee") + BigDecimal rebatedFee; + + @JsonProperty("rebated_fee_currency") + String rebatedFeeCurrency; + + @JsonProperty("stp_id") + Integer stpId; + + @JsonProperty("stp_act") + String stpAction; + + @JsonProperty("finish_as") + String finishAs; + +} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeServiceRaw.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeServiceRaw.java index 1dda010cb85..3b9004c9b1a 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeServiceRaw.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeServiceRaw.java @@ -2,19 +2,24 @@ import java.io.IOException; import java.math.BigDecimal; +import java.util.List; +import java.util.Set; +import org.apache.commons.lang3.Validate; import org.knowm.xchange.currency.CurrencyPair; import org.knowm.xchange.dto.Order; +import org.knowm.xchange.dto.Order.OrderStatus; import org.knowm.xchange.dto.trade.LimitOrder; +import org.knowm.xchange.gateio.GateioAdapters; import org.knowm.xchange.gateio.GateioExchange; import org.knowm.xchange.gateio.GateioUtils; import org.knowm.xchange.gateio.dto.GateioBaseResponse; import org.knowm.xchange.gateio.dto.GateioOrderType; +import org.knowm.xchange.gateio.dto.account.GateioOrder; import org.knowm.xchange.gateio.dto.trade.GateioOpenOrders; import org.knowm.xchange.gateio.dto.trade.GateioOrderStatus; import org.knowm.xchange.gateio.dto.trade.GateioPlaceOrderReturn; import org.knowm.xchange.gateio.dto.trade.GateioTradeHistoryReturn; -import org.knowm.xchange.service.trade.params.CancelOrderByCurrencyPair; -import org.knowm.xchange.service.trade.params.CancelOrderByIdParams; +import org.knowm.xchange.instrument.Instrument; public class GateioTradeServiceRaw extends GateioBaseService { @@ -143,24 +148,18 @@ private String formatCurrencyPair(CurrencyPair currencyPair) { .toLowerCase(); } - public static class GateioCancelOrderParams - implements CancelOrderByIdParams, CancelOrderByCurrencyPair { - public final CurrencyPair currencyPair; - public final String orderId; - public GateioCancelOrderParams(CurrencyPair currencyPair, String orderId) { - this.currencyPair = currencyPair; - this.orderId = orderId; - } + public List listOrders(Instrument instrument, OrderStatus orderStatus) throws IOException { + // validate arguments + Validate.notNull(orderStatus); + var allowedOrderStatuses = Set.of(OrderStatus.OPEN, OrderStatus.CLOSED); + Validate.validState(allowedOrderStatuses.contains(orderStatus), "Allowed order statuses are: {}", allowedOrderStatuses); + Validate.notNull(instrument); - @Override - public String getOrderId() { - return orderId; - } + return gateioV4Authenticated.listOrders(apiKey, exchange.getNonceFactory(), + gateioV4ParamsDigest, GateioAdapters.toQueryParam(instrument), GateioAdapters.toString(orderStatus) + ); - @Override - public CurrencyPair getCurrencyPair() { - return currencyPair; - } } + } diff --git a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioTradeServiceRawTest.java b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioTradeServiceRawTest.java new file mode 100644 index 00000000000..0b9239e6305 --- /dev/null +++ b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioTradeServiceRawTest.java @@ -0,0 +1,28 @@ +package org.knowm.xchange.gateio.service; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.IOException; +import java.util.List; +import org.junit.jupiter.api.Test; +import org.knowm.xchange.currency.CurrencyPair; +import org.knowm.xchange.dto.Order.OrderStatus; +import org.knowm.xchange.gateio.GateioExchangeWiremock; +import org.knowm.xchange.gateio.dto.account.GateioOrder; + +class GateioTradeServiceRawTest extends GateioExchangeWiremock { + + GateioTradeServiceRaw gateioTradeServiceRaw = (GateioTradeServiceRaw) exchange.getTradeService(); + + + @Test + void listOrders() throws IOException { + List orders = gateioTradeServiceRaw.listOrders(CurrencyPair.BTC_USDT, OrderStatus.OPEN); + + assertThat(orders).hasSize(1); + assertThat(orders.get(0).getId()).isEqualTo("339440374909"); + assertThat(orders.get(0).getStatus()).isEqualTo("open"); + + } + +} \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/resources/__files/api_v4_spot_orders-btc-open.json b/xchange-gateio-v4/src/test/resources/__files/api_v4_spot_orders-btc-open.json new file mode 100644 index 00000000000..710f1a2b209 --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/__files/api_v4_spot_orders-btc-open.json @@ -0,0 +1,34 @@ +[ + { + "id": "339440374909", + "text": "3", + "amend_text": "-", + "create_time": "1685391045", + "update_time": "1685391045", + "create_time_ms": 1685391045952, + "update_time_ms": 1685391045952, + "status": "open", + "currency_pair": "BTC_USDT", + "type": "limit", + "account": "spot", + "side": "buy", + "amount": "0.0001", + "price": "22053", + "biz_info": "-", + "time_in_force": "gtc", + "iceberg": "0", + "left": "0.0001", + "fill_price": "0", + "filled_total": "0", + "fee": "0", + "fee_currency": "BTC", + "point_fee": "0", + "gt_fee": "0", + "gt_maker_fee": "0", + "gt_taker_fee": "0", + "gt_discount": false, + "rebated_fee": "0", + "rebated_fee_currency": "USDT", + "finish_as": "open" + } +] \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_orders-btc-open.json b/xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_orders-btc-open.json new file mode 100644 index 00000000000..fa26eb61472 --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_orders-btc-open.json @@ -0,0 +1,15 @@ +{ + "id" : "8597ffe9-f28d-40d6-9a47-5f378dd53515", + "name" : "api_v4_spot_orders", + "request" : { + "url" : "/api/v4/spot/orders?currency_pair=btc_usdt&status=open", + "method" : "GET" + }, + "response" : { + "status" : 200, + "bodyFileName" : "api_v4_spot_orders-btc-open.json" + }, + "uuid" : "8597ffe9-f28d-40d6-9a47-5f378dd53515", + "persistent" : true, + "insertionIndex" : 16 +} \ No newline at end of file From 67dc03ebc45850c70971f1f79c4bf9c4bbdc9695 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Sat, 3 Jun 2023 23:10:20 +0200 Subject: [PATCH 022/159] [gateio-v4] Add placing of market order --- .../knowm/xchange/gateio/GateioAdapters.java | 30 ++++++++++++++++++- .../xchange/gateio/GateioErrorAdapter.java | 4 +++ .../xchange/gateio/GateioV4Authenticated.java | 13 ++++++++ .../gateio/dto/account/GateioOrder.java | 3 ++ .../service/GateioMarketDataServiceRaw.java | 4 +-- .../gateio/service/GateioTradeService.java | 12 ++++++-- .../gateio/service/GateioTradeServiceRaw.java | 7 ++++- .../service/GateioTradeServiceTest.java | 30 +++++++++++++++++++ ...api_v4_spot_orders-balance-not-enough.json | 4 +++ ...api_v4_spot_orders-balance-not-enough.json | 20 +++++++++++++ 10 files changed, 121 insertions(+), 6 deletions(-) create mode 100644 xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioTradeServiceTest.java create mode 100644 xchange-gateio-v4/src/test/resources/__files/exceptions/api_v4_spot_orders-balance-not-enough.json create mode 100644 xchange-gateio-v4/src/test/resources/mappings/exceptions/api_v4_spot_orders-balance-not-enough.json diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java index 2d065f14894..937be721224 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java @@ -22,11 +22,13 @@ import org.knowm.xchange.dto.marketdata.Trades.TradeSortType; import org.knowm.xchange.dto.meta.InstrumentMetaData; import org.knowm.xchange.dto.trade.LimitOrder; +import org.knowm.xchange.dto.trade.MarketOrder; import org.knowm.xchange.dto.trade.OpenOrders; import org.knowm.xchange.dto.trade.UserTrade; import org.knowm.xchange.dto.trade.UserTrades; import org.knowm.xchange.gateio.dto.GateioOrderType; import org.knowm.xchange.gateio.dto.account.GateioDepositsWithdrawals; +import org.knowm.xchange.gateio.dto.account.GateioOrder; import org.knowm.xchange.gateio.dto.marketdata.GateioCurrencyPairDetails; import org.knowm.xchange.gateio.dto.marketdata.GateioDepth; import org.knowm.xchange.gateio.dto.marketdata.GateioOrderBook; @@ -50,7 +52,7 @@ public CurrencyPair adaptCurrencyPair(String pair) { } - public String toQueryParam(Instrument instrument) { + public String toString(Instrument instrument) { return String.format("%s_%s", instrument.getBase().getCurrencyCode(), instrument.getCounter().getCurrencyCode()) @@ -297,4 +299,30 @@ public String toString(OrderStatus orderStatus) { throw new IllegalArgumentException("Can't map " + orderStatus); } } + + + public GateioOrder toGateioOrder(MarketOrder marketOrder) { + GateioOrder gateioOrder = GateioOrder.builder() + .currencyPair(toString(marketOrder.getInstrument())) + .side(toString(marketOrder.getType())) + .clientOrderId(marketOrder.getUserReference()) + .type("market") + .timeInForce("ioc") + .amount(marketOrder.getOriginalAmount()) + .build(); + return gateioOrder; + } + + + public String toString(OrderType orderType) { + switch (orderType) { + case BID: + return "buy"; + case ASK: + return "sell"; + default: + throw new IllegalArgumentException("Can't map " + orderType); + } + + } } 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 c682e306c93..7f34d1b721d 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 @@ -3,6 +3,7 @@ import lombok.experimental.UtilityClass; 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.gateio.dto.GateioException; @@ -13,6 +14,7 @@ public class GateioErrorAdapter { public final String INVALID_KEY = "INVALID_KEY"; public final String FORBIDDEN = "FORBIDDEN"; public final String INVALID_CURRENCY = "INVALID_CURRENCY"; + public final String BALANCE_NOT_ENOUGH = "BALANCE_NOT_ENOUGH"; public ExchangeException adapt(GateioException e) { @@ -26,6 +28,8 @@ public ExchangeException adapt(GateioException e) { case INVALID_CURRENCY: return new InstrumentNotValidException(e.getMessage(), e); + case BALANCE_NOT_ENOUGH: + return new FundsExceededException(e.getMessage(), e); default: return new ExchangeException(e.getMessage(), e); } diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java index 940056143ee..38eeb884062 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java @@ -2,8 +2,10 @@ import java.io.IOException; import java.util.List; +import javax.ws.rs.Consumes; import javax.ws.rs.GET; import javax.ws.rs.HeaderParam; +import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; @@ -61,4 +63,15 @@ List listOrders( ) throws IOException, GateioException; + @POST + @Path("spot/orders") + @Consumes(MediaType.APPLICATION_JSON) + GateioOrder createOrder( + @HeaderParam("KEY") String apiKey, + @HeaderParam("Timestamp") SynchronizedValueFactory timestamp, + @HeaderParam("SIGN") ParamsDigest signer, + GateioOrder gateioOrder + ) throws IOException, GateioException; + + } diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioOrder.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioOrder.java index bf5cd4e5dd7..a7a2b06fc32 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioOrder.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioOrder.java @@ -1,5 +1,7 @@ package org.knowm.xchange.gateio.dto.account; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonProperty; import java.math.BigDecimal; import java.time.Instant; @@ -10,6 +12,7 @@ @Data @Builder @Jacksonized +@JsonInclude(value = Include.NON_EMPTY, content = Include.NON_NULL) public class GateioOrder { @JsonProperty("id") 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 a6684edba1e..c2aa789e6fe 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 @@ -158,7 +158,7 @@ public List getCurrencies() throws IOException { public GateioOrderBook getGateioOrderBook(Instrument instrument) throws IOException { - return gateio.getOrderBook(GateioAdapters.toQueryParam(instrument), false); + return gateio.getOrderBook(GateioAdapters.toString(instrument), false); } @@ -173,7 +173,7 @@ public List getCurrencyPairDetails() throws IOExcepti public GateioCurrencyPairDetails getCurrencyPairDetails(Instrument instrument) throws IOException { - return gateio.getCurrencyPairDetails(GateioAdapters.toQueryParam(instrument)); + return gateio.getCurrencyPairDetails(GateioAdapters.toString(instrument)); } diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeService.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeService.java index c2494f5e0b5..497b5432699 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeService.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeService.java @@ -13,7 +13,10 @@ import org.knowm.xchange.exceptions.ExchangeException; import org.knowm.xchange.exceptions.NotAvailableFromExchangeException; import org.knowm.xchange.gateio.GateioAdapters; +import org.knowm.xchange.gateio.GateioErrorAdapter; import org.knowm.xchange.gateio.GateioExchange; +import org.knowm.xchange.gateio.dto.GateioException; +import org.knowm.xchange.gateio.dto.account.GateioOrder; import org.knowm.xchange.gateio.dto.trade.GateioOpenOrders; import org.knowm.xchange.gateio.dto.trade.GateioOrderStatus; import org.knowm.xchange.gateio.dto.trade.GateioTrade; @@ -56,8 +59,13 @@ public OpenOrders getOpenOrders(OpenOrdersParams params) throws IOException { @Override public String placeMarketOrder(MarketOrder marketOrder) throws IOException { - - throw new NotAvailableFromExchangeException(); + try { + GateioOrder order = createOrder(GateioAdapters.toGateioOrder(marketOrder)); + return order.getId(); + } + catch (GateioException e) { + throw GateioErrorAdapter.adapt(e); + } } /** diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeServiceRaw.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeServiceRaw.java index 3b9004c9b1a..b7ee1951515 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeServiceRaw.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeServiceRaw.java @@ -157,9 +157,14 @@ public List listOrders(Instrument instrument, OrderStatus orderStat Validate.notNull(instrument); return gateioV4Authenticated.listOrders(apiKey, exchange.getNonceFactory(), - gateioV4ParamsDigest, GateioAdapters.toQueryParam(instrument), GateioAdapters.toString(orderStatus) + gateioV4ParamsDigest, GateioAdapters.toString(instrument), GateioAdapters.toString(orderStatus) ); } + + public GateioOrder createOrder(GateioOrder gateioOrder) throws IOException { + return gateioV4Authenticated.createOrder(apiKey, exchange.getNonceFactory(), gateioV4ParamsDigest, gateioOrder); + } + } diff --git a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioTradeServiceTest.java b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioTradeServiceTest.java new file mode 100644 index 00000000000..dff21d0d158 --- /dev/null +++ b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioTradeServiceTest.java @@ -0,0 +1,30 @@ +package org.knowm.xchange.gateio.service; + +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; + +import java.math.BigDecimal; +import org.junit.jupiter.api.Test; +import org.knowm.xchange.currency.CurrencyPair; +import org.knowm.xchange.dto.Order.OrderType; +import org.knowm.xchange.dto.trade.MarketOrder; +import org.knowm.xchange.exceptions.FundsExceededException; +import org.knowm.xchange.gateio.GateioExchangeWiremock; + +class GateioTradeServiceTest extends GateioExchangeWiremock { + + GateioTradeService gateioTradeService = (GateioTradeService) exchange.getTradeService(); + + + @Test + void place_order_not_enough_balance() { + MarketOrder marketOrder = new MarketOrder.Builder(OrderType.BID, CurrencyPair.BTC_USDT) + .userReference("t-balance-test") + .originalAmount(BigDecimal.valueOf(100)) + .build(); + + assertThatExceptionOfType(FundsExceededException.class) + .isThrownBy(() -> gateioTradeService.placeMarketOrder(marketOrder)); + } + + +} \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/resources/__files/exceptions/api_v4_spot_orders-balance-not-enough.json b/xchange-gateio-v4/src/test/resources/__files/exceptions/api_v4_spot_orders-balance-not-enough.json new file mode 100644 index 00000000000..47e030a5f86 --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/__files/exceptions/api_v4_spot_orders-balance-not-enough.json @@ -0,0 +1,4 @@ +{ + "label": "BALANCE_NOT_ENOUGH", + "message": "Not enough balance" +} \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/resources/mappings/exceptions/api_v4_spot_orders-balance-not-enough.json b/xchange-gateio-v4/src/test/resources/mappings/exceptions/api_v4_spot_orders-balance-not-enough.json new file mode 100644 index 00000000000..c365e3098a9 --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/mappings/exceptions/api_v4_spot_orders-balance-not-enough.json @@ -0,0 +1,20 @@ +{ + "id" : "87f03a6d-42bc-45a3-81c2-f817403bda44", + "name" : "api_v4_spot_orders", + "request" : { + "url" : "/api/v4/spot/orders", + "method" : "POST", + "bodyPatterns" : [ { + "equalToJson" : "{\"text\":\"t-balance-test\",\"currency_pair\":\"btc_usdt\",\"type\":\"market\",\"side\":\"buy\",\"amount\":100,\"time_in_force\":\"ioc\"}", + "ignoreArrayOrder" : true, + "ignoreExtraElements" : true + } ] + }, + "response" : { + "status" : 400, + "bodyFileName" : "exceptions/api_v4_spot_orders-balance-not-enough.json" + }, + "uuid" : "87f03a6d-42bc-45a3-81c2-f817403bda44", + "persistent" : true, + "insertionIndex" : 17 +} \ No newline at end of file From eb2ffbe76500623d0c9fb23359e666c648692f13 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Sat, 3 Jun 2023 23:51:09 +0200 Subject: [PATCH 023/159] [gateio-v4] Fix wiremocks --- .../src/main/java/org/knowm/xchange/gateio/GateioAdapters.java | 2 +- .../resources/mappings/api_v4_spot_currency_pairs_chz_usdt.json | 2 +- .../src/test/resources/mappings/api_v4_spot_order_book.json | 2 +- .../test/resources/mappings/api_v4_spot_orders-btc-open.json | 2 +- .../exceptions/api_v4_spot_orders-balance-not-enough.json | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java index 937be721224..5d400a91f05 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java @@ -56,7 +56,7 @@ public String toString(Instrument instrument) { return String.format("%s_%s", instrument.getBase().getCurrencyCode(), instrument.getCounter().getCurrencyCode()) - .toLowerCase(Locale.ROOT); + .toUpperCase(Locale.ROOT); } diff --git a/xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_currency_pairs_chz_usdt.json b/xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_currency_pairs_chz_usdt.json index d208b0f612b..07a16b375fa 100644 --- a/xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_currency_pairs_chz_usdt.json +++ b/xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_currency_pairs_chz_usdt.json @@ -2,7 +2,7 @@ "id" : "9cb9e274-4bf7-419e-9b28-ed6c7dbf8f52", "name" : "api_v4_spot_currency_pairs_chz_usdt", "request" : { - "url" : "/api/v4/spot/currency_pairs/chz_usdt", + "url" : "/api/v4/spot/currency_pairs/CHZ_USDT", "method" : "GET" }, "response" : { diff --git a/xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_order_book.json b/xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_order_book.json index 1e31db7bd59..c1e119453fb 100644 --- a/xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_order_book.json +++ b/xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_order_book.json @@ -2,7 +2,7 @@ "id" : "b24dfa78-b1a7-4468-b85c-fa299b82170c", "name" : "api_v4_spot_order_book", "request" : { - "url" : "/api/v4/spot/order_book?currency_pair=btc_usdt&with_id=false", + "url" : "/api/v4/spot/order_book?currency_pair=BTC_USDT&with_id=false", "method" : "GET" }, "response" : { diff --git a/xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_orders-btc-open.json b/xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_orders-btc-open.json index fa26eb61472..ad26c081532 100644 --- a/xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_orders-btc-open.json +++ b/xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_orders-btc-open.json @@ -2,7 +2,7 @@ "id" : "8597ffe9-f28d-40d6-9a47-5f378dd53515", "name" : "api_v4_spot_orders", "request" : { - "url" : "/api/v4/spot/orders?currency_pair=btc_usdt&status=open", + "url" : "/api/v4/spot/orders?currency_pair=BTC_USDT&status=open", "method" : "GET" }, "response" : { diff --git a/xchange-gateio-v4/src/test/resources/mappings/exceptions/api_v4_spot_orders-balance-not-enough.json b/xchange-gateio-v4/src/test/resources/mappings/exceptions/api_v4_spot_orders-balance-not-enough.json index c365e3098a9..a20ad412554 100644 --- a/xchange-gateio-v4/src/test/resources/mappings/exceptions/api_v4_spot_orders-balance-not-enough.json +++ b/xchange-gateio-v4/src/test/resources/mappings/exceptions/api_v4_spot_orders-balance-not-enough.json @@ -5,7 +5,7 @@ "url" : "/api/v4/spot/orders", "method" : "POST", "bodyPatterns" : [ { - "equalToJson" : "{\"text\":\"t-balance-test\",\"currency_pair\":\"btc_usdt\",\"type\":\"market\",\"side\":\"buy\",\"amount\":100,\"time_in_force\":\"ioc\"}", + "equalToJson" : "{\"text\":\"t-balance-test\",\"currency_pair\":\"BTC_USDT\",\"type\":\"market\",\"side\":\"buy\",\"amount\":100,\"time_in_force\":\"ioc\"}", "ignoreArrayOrder" : true, "ignoreExtraElements" : true } ] From a5fdf583eb956d9bb47e906c9493b6befdb19ec0 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Sun, 4 Jun 2023 00:41:10 +0200 Subject: [PATCH 024/159] [gateio-v4] Add order endpoints --- .../knowm/xchange/gateio/GateioAdapters.java | 1 + .../xchange/gateio/GateioV4Authenticated.java | 12 ++ .../gateio/service/GateioTradeServiceRaw.java | 6 + .../service/GateioTradeServiceRawTest.java | 109 ++++++++++++++++++ .../service/GateioTradeServiceTest.java | 16 +++ ...v4_spot_orders-valid-market-buy-order.json | 33 ++++++ ...4_spot_orders-valid-market-sell-order.json | 33 ++++++ .../api_v4_spot_orders_order-details.json | 33 ++++++ ...v4_spot_orders-valid-market-buy-order.json | 20 ++++ ...4_spot_orders-valid-market-sell-order.json | 20 ++++ .../api_v4_spot_orders_order-details.json | 15 +++ 11 files changed, 298 insertions(+) create mode 100644 xchange-gateio-v4/src/test/resources/__files/api_v4_spot_orders-valid-market-buy-order.json create mode 100644 xchange-gateio-v4/src/test/resources/__files/api_v4_spot_orders-valid-market-sell-order.json create mode 100644 xchange-gateio-v4/src/test/resources/__files/api_v4_spot_orders_order-details.json create mode 100644 xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_orders-valid-market-buy-order.json create mode 100644 xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_orders-valid-market-sell-order.json create mode 100644 xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_orders_order-details.json diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java index 5d400a91f05..890c1127986 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java @@ -306,6 +306,7 @@ public GateioOrder toGateioOrder(MarketOrder marketOrder) { .currencyPair(toString(marketOrder.getInstrument())) .side(toString(marketOrder.getType())) .clientOrderId(marketOrder.getUserReference()) + .account("spot") .type("market") .timeInForce("ioc") .amount(marketOrder.getOriginalAmount()) diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java index 38eeb884062..1368de3da6c 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java @@ -7,6 +7,7 @@ import javax.ws.rs.HeaderParam; import javax.ws.rs.POST; import javax.ws.rs.Path; +import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; @@ -63,6 +64,17 @@ List listOrders( ) throws IOException, GateioException; + @GET + @Path("spot/orders/{order_id}") + GateioOrder getOrder( + @HeaderParam("KEY") String apiKey, + @HeaderParam("Timestamp") SynchronizedValueFactory timestamp, + @HeaderParam("SIGN") ParamsDigest signer, + @PathParam("order_id") String orderId, + @QueryParam("currency_pair") String currencyPair + ) throws IOException, GateioException; + + @POST @Path("spot/orders") @Consumes(MediaType.APPLICATION_JSON) diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeServiceRaw.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeServiceRaw.java index b7ee1951515..06e16d28bb2 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeServiceRaw.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeServiceRaw.java @@ -167,4 +167,10 @@ public GateioOrder createOrder(GateioOrder gateioOrder) throws IOException { return gateioV4Authenticated.createOrder(apiKey, exchange.getNonceFactory(), gateioV4ParamsDigest, gateioOrder); } + + public GateioOrder getOrder(String orderId, Instrument instrument) throws IOException { + return gateioV4Authenticated.getOrder(apiKey, exchange.getNonceFactory(), gateioV4ParamsDigest, + orderId, GateioAdapters.toString(instrument)); + } + } diff --git a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioTradeServiceRawTest.java b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioTradeServiceRawTest.java index 0b9239e6305..48b586c9fe5 100644 --- a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioTradeServiceRawTest.java +++ b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioTradeServiceRawTest.java @@ -3,6 +3,8 @@ import static org.assertj.core.api.Assertions.assertThat; import java.io.IOException; +import java.math.BigDecimal; +import java.time.Instant; import java.util.List; import org.junit.jupiter.api.Test; import org.knowm.xchange.currency.CurrencyPair; @@ -14,6 +16,37 @@ class GateioTradeServiceRawTest extends GateioExchangeWiremock { GateioTradeServiceRaw gateioTradeServiceRaw = (GateioTradeServiceRaw) exchange.getTradeService(); + GateioOrder sampleMarketOrder = GateioOrder.builder() + .id("342251629898") + .currencyPair("BTC_USDT") + .clientOrderId("t-valid-market-buy-order") + .amendText("-") + .type("market") + .account("spot") + .side("buy") + .timeInForce("ioc") + .amount(BigDecimal.valueOf(20)) + .createdAt(Instant.parse("2023-06-03T22:07:38.451Z")) + .updatedAt(Instant.parse("2023-06-03T22:07:38.451Z")) + .status("closed") + .icebergAmount(BigDecimal.ZERO) + .amountLeftToFill(new BigDecimal("1.07319")) + .filledTotalQuote(new BigDecimal("18.92681")) + .avgDealPrice(new BigDecimal("27038.3")) + .fee(new BigDecimal("0.0000014")) + .price(BigDecimal.ZERO) + .feeCurrency("BTC") + .pointFee(BigDecimal.ZERO) + .gtFee(BigDecimal.ZERO) + .gtMakerFee(BigDecimal.ZERO) + .gtTakerFee(BigDecimal.ZERO) + .rebatedFee(BigDecimal.ZERO) + .gtDiscount(false) + .rebatedFeeCurrency("USDT") + .finishAs("filled") + .build(); + + @Test void listOrders() throws IOException { @@ -25,4 +58,80 @@ void listOrders() throws IOException { } + + @Test + void valid_market_buy_order() throws IOException { + GateioOrder gateioOrder = GateioOrder.builder() + .currencyPair("BTC_USDT") + .clientOrderId("t-valid-market-buy-order") + .type("market") + .account("spot") + .side("buy") + .timeInForce("ioc") + .amount(BigDecimal.valueOf(20)) + .build(); + + GateioOrder actualResponse = gateioTradeServiceRaw.createOrder(gateioOrder); + assertThat(actualResponse).usingRecursiveComparison().isEqualTo(sampleMarketOrder); + + } + + + @Test + void valid_market_sell_order() throws IOException { + GateioOrder gateioOrder = GateioOrder.builder() + .currencyPair("BTC_USDT") + .clientOrderId("t-valid-market-sell-order") + .type("market") + .account("spot") + .side("sell") + .timeInForce("ioc") + .amount(new BigDecimal("0.0007")) + .build(); + + + GateioOrder actualResponse = gateioTradeServiceRaw.createOrder(gateioOrder); + + GateioOrder expectedResponse = GateioOrder.builder() + .id("342260949533") + .currencyPair("BTC_USDT") + .clientOrderId("t-valid-market-sell-order") + .amendText("-") + .type("market") + .account("spot") + .side("sell") + .timeInForce("ioc") + .amount(new BigDecimal("0.0007")) + .createdAt(Instant.parse("2023-06-03T22:33:21.743Z")) + .updatedAt(Instant.parse("2023-06-03T22:33:21.743Z")) + .status("closed") + .icebergAmount(BigDecimal.ZERO) + .amountLeftToFill(BigDecimal.ZERO) + .filledTotalQuote(new BigDecimal("18.94382")) + .avgDealPrice(new BigDecimal("27062.6")) + .fee(new BigDecimal("0.03788764")) + .price(BigDecimal.ZERO) + .feeCurrency("USDT") + .pointFee(BigDecimal.ZERO) + .gtFee(BigDecimal.ZERO) + .gtMakerFee(BigDecimal.ZERO) + .gtTakerFee(BigDecimal.ZERO) + .rebatedFee(BigDecimal.ZERO) + .gtDiscount(false) + .rebatedFeeCurrency("BTC") + .finishAs("filled") + .build(); + + assertThat(actualResponse).usingRecursiveComparison().isEqualTo(expectedResponse); + + } + + + @Test + void order_details() throws IOException { + var actualResponse = gateioTradeServiceRaw.getOrder("342251629898", CurrencyPair.BTC_USDT); + + assertThat(actualResponse).usingRecursiveComparison().isEqualTo(sampleMarketOrder); + } + } \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioTradeServiceTest.java b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioTradeServiceTest.java index dff21d0d158..a3b988c5243 100644 --- a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioTradeServiceTest.java +++ b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioTradeServiceTest.java @@ -1,7 +1,9 @@ package org.knowm.xchange.gateio.service; +import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import java.io.IOException; import java.math.BigDecimal; import org.junit.jupiter.api.Test; import org.knowm.xchange.currency.CurrencyPair; @@ -27,4 +29,18 @@ void place_order_not_enough_balance() { } + @Test + void valid_market_buy_order() throws IOException { + MarketOrder marketOrder = new MarketOrder.Builder(OrderType.BID, CurrencyPair.BTC_USDT) + .userReference("t-valid-market-buy-order") + .originalAmount(BigDecimal.valueOf(20)) + .build(); + + var actualResponse = gateioTradeService.placeMarketOrder(marketOrder); + assertThat(actualResponse).isEqualTo("342251629898"); + + } + + + } \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/resources/__files/api_v4_spot_orders-valid-market-buy-order.json b/xchange-gateio-v4/src/test/resources/__files/api_v4_spot_orders-valid-market-buy-order.json new file mode 100644 index 00000000000..d2b39003982 --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/__files/api_v4_spot_orders-valid-market-buy-order.json @@ -0,0 +1,33 @@ +{ + "id": "342251629898", + "text": "t-valid-market-buy-order", + "amend_text": "-", + "create_time": "1685830058", + "update_time": "1685830058", + "create_time_ms": 1685830058451, + "update_time_ms": 1685830058451, + "status": "closed", + "currency_pair": "BTC_USDT", + "type": "market", + "account": "spot", + "side": "buy", + "amount": "20", + "price": "0", + "biz_info": "-", + "time_in_force": "ioc", + "iceberg": "0", + "left": "1.07319", + "fill_price": "18.92681", + "filled_total": "18.92681", + "avg_deal_price": "27038.3", + "fee": "0.0000014", + "fee_currency": "BTC", + "point_fee": "0", + "gt_fee": "0", + "gt_maker_fee": "0", + "gt_taker_fee": "0", + "gt_discount": false, + "rebated_fee": "0", + "rebated_fee_currency": "USDT", + "finish_as": "filled" +} \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/resources/__files/api_v4_spot_orders-valid-market-sell-order.json b/xchange-gateio-v4/src/test/resources/__files/api_v4_spot_orders-valid-market-sell-order.json new file mode 100644 index 00000000000..69906f63344 --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/__files/api_v4_spot_orders-valid-market-sell-order.json @@ -0,0 +1,33 @@ +{ + "id": "342260949533", + "text": "t-valid-market-sell-order", + "amend_text": "-", + "create_time": "1685831601", + "update_time": "1685831601", + "create_time_ms": 1685831601743, + "update_time_ms": 1685831601743, + "status": "closed", + "currency_pair": "BTC_USDT", + "type": "market", + "account": "spot", + "side": "sell", + "amount": "0.0007", + "price": "0", + "biz_info": "-", + "time_in_force": "ioc", + "iceberg": "0", + "left": "0", + "fill_price": "18.94382", + "filled_total": "18.94382", + "avg_deal_price": "27062.6", + "fee": "0.03788764", + "fee_currency": "USDT", + "point_fee": "0", + "gt_fee": "0", + "gt_maker_fee": "0", + "gt_taker_fee": "0", + "gt_discount": false, + "rebated_fee": "0", + "rebated_fee_currency": "BTC", + "finish_as": "filled" +} \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/resources/__files/api_v4_spot_orders_order-details.json b/xchange-gateio-v4/src/test/resources/__files/api_v4_spot_orders_order-details.json new file mode 100644 index 00000000000..d2b39003982 --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/__files/api_v4_spot_orders_order-details.json @@ -0,0 +1,33 @@ +{ + "id": "342251629898", + "text": "t-valid-market-buy-order", + "amend_text": "-", + "create_time": "1685830058", + "update_time": "1685830058", + "create_time_ms": 1685830058451, + "update_time_ms": 1685830058451, + "status": "closed", + "currency_pair": "BTC_USDT", + "type": "market", + "account": "spot", + "side": "buy", + "amount": "20", + "price": "0", + "biz_info": "-", + "time_in_force": "ioc", + "iceberg": "0", + "left": "1.07319", + "fill_price": "18.92681", + "filled_total": "18.92681", + "avg_deal_price": "27038.3", + "fee": "0.0000014", + "fee_currency": "BTC", + "point_fee": "0", + "gt_fee": "0", + "gt_maker_fee": "0", + "gt_taker_fee": "0", + "gt_discount": false, + "rebated_fee": "0", + "rebated_fee_currency": "USDT", + "finish_as": "filled" +} \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_orders-valid-market-buy-order.json b/xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_orders-valid-market-buy-order.json new file mode 100644 index 00000000000..7fee2f05c07 --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_orders-valid-market-buy-order.json @@ -0,0 +1,20 @@ +{ + "id" : "3311168b-7ef3-44cc-b356-ffa5737b3bfe", + "name" : "api_v4_spot_orders", + "request" : { + "url" : "/api/v4/spot/orders", + "method" : "POST", + "bodyPatterns" : [ { + "equalToJson" : "{\"text\":\"t-valid-market-buy-order\",\"currency_pair\":\"BTC_USDT\",\"type\":\"market\",\"account\":\"spot\",\"side\":\"buy\",\"amount\":20,\"time_in_force\":\"ioc\"}", + "ignoreArrayOrder" : true, + "ignoreExtraElements" : true + } ] + }, + "response" : { + "status" : 201, + "bodyFileName" : "api_v4_spot_orders-valid-market-buy-order.json" + }, + "uuid" : "3311168b-7ef3-44cc-b356-ffa5737b3bfe", + "persistent" : true, + "insertionIndex" : 18 +} \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_orders-valid-market-sell-order.json b/xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_orders-valid-market-sell-order.json new file mode 100644 index 00000000000..950980d3253 --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_orders-valid-market-sell-order.json @@ -0,0 +1,20 @@ +{ + "id" : "d63d7d0f-8d8b-496e-a00c-db2a6b1305bb", + "name" : "api_v4_spot_orders", + "request" : { + "url" : "/api/v4/spot/orders", + "method" : "POST", + "bodyPatterns" : [ { + "equalToJson" : "{\"text\":\"t-valid-market-sell-order\",\"currency_pair\":\"BTC_USDT\",\"type\":\"market\",\"account\":\"spot\",\"side\":\"sell\",\"amount\":0.0007,\"time_in_force\":\"ioc\"}", + "ignoreArrayOrder" : true, + "ignoreExtraElements" : true + } ] + }, + "response" : { + "status" : 201, + "bodyFileName" : "api_v4_spot_orders-valid-market-sell-order.json" + }, + "uuid" : "d63d7d0f-8d8b-496e-a00c-db2a6b1305bb", + "persistent" : true, + "insertionIndex" : 20 +} \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_orders_order-details.json b/xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_orders_order-details.json new file mode 100644 index 00000000000..bc46b947e8f --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_orders_order-details.json @@ -0,0 +1,15 @@ +{ + "id" : "da0d205d-94ee-4760-bfd1-f4e5871d23e4", + "name" : "api_v4_spot_orders_342251629898", + "request" : { + "url" : "/api/v4/spot/orders/342251629898?currency_pair=BTC_USDT", + "method" : "GET" + }, + "response" : { + "status" : 200, + "bodyFileName" : "api_v4_spot_orders_order-details.json" + }, + "uuid" : "da0d205d-94ee-4760-bfd1-f4e5871d23e4", + "persistent" : true, + "insertionIndex" : 19 +} \ No newline at end of file From 50d87751b44b4f13f18aeb383ccda33ae5993b42 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Sun, 4 Jun 2023 01:58:58 +0200 Subject: [PATCH 025/159] [gateio-v4] Add orders to TradeService --- .../knowm/xchange/gateio/GateioAdapters.java | 78 +++++++++++++++++-- .../gateio/service/GateioTradeService.java | 40 ++++------ .../service/GateioTradeServiceTest.java | 34 ++++++++ 3 files changed, 119 insertions(+), 33 deletions(-) diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java index 890c1127986..6cf093d535b 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java @@ -1,5 +1,8 @@ package org.knowm.xchange.gateio; +import static org.knowm.xchange.dto.Order.OrderType.ASK; +import static org.knowm.xchange.dto.Order.OrderType.BID; + import java.math.BigDecimal; import java.util.ArrayList; import java.util.Collection; @@ -11,6 +14,7 @@ import lombok.experimental.UtilityClass; import org.knowm.xchange.currency.Currency; import org.knowm.xchange.currency.CurrencyPair; +import org.knowm.xchange.dto.Order; import org.knowm.xchange.dto.Order.OrderStatus; import org.knowm.xchange.dto.Order.OrderType; import org.knowm.xchange.dto.account.FundingRecord; @@ -60,6 +64,12 @@ public String toString(Instrument instrument) { } + public Instrument toInstrument(String currencyCode) { + var currencies = currencyCode.split("_"); + return new CurrencyPair(currencies[0], currencies[1]); + } + + public Ticker adaptTicker(CurrencyPair currencyPair, GateioTicker gateioTicker) { BigDecimal ask = gateioTicker.getLowestAsk(); @@ -88,12 +98,12 @@ public Ticker adaptTicker(CurrencyPair currencyPair, GateioTicker gateioTicker) public OrderBook toOrderBook(GateioOrderBook gateioOrderBook, Instrument instrument) { List asks = gateioOrderBook.getAsks().stream() - .map(priceSizeEntry -> new LimitOrder(OrderType.ASK, priceSizeEntry.getSize(), instrument, null, null, priceSizeEntry.getPrice())) + .map(priceSizeEntry -> new LimitOrder(ASK, priceSizeEntry.getSize(), instrument, null, null, priceSizeEntry.getPrice())) .collect(Collectors.toList()); List bids = gateioOrderBook.getBids().stream() - .map(priceSizeEntry -> new LimitOrder(OrderType.BID, priceSizeEntry.getSize(), instrument, null, null, priceSizeEntry.getPrice())) + .map(priceSizeEntry -> new LimitOrder(BID, priceSizeEntry.getSize(), instrument, null, null, priceSizeEntry.getPrice())) .collect(Collectors.toList()); return new OrderBook(Date.from(gateioOrderBook.getGeneratedAt()), asks, bids); @@ -121,10 +131,10 @@ public List adaptOrders( public OrderBook adaptOrderBook(GateioDepth depth, CurrencyPair currencyPair) { List asks = - GateioAdapters.adaptOrders(depth.getAsks(), currencyPair, OrderType.ASK); + GateioAdapters.adaptOrders(depth.getAsks(), currencyPair, ASK); Collections.reverse(asks); List bids = - GateioAdapters.adaptOrders(depth.getBids(), currencyPair, OrderType.BID); + GateioAdapters.adaptOrders(depth.getBids(), currencyPair, BID); return new OrderBook(null, asks, bids); } @@ -135,7 +145,7 @@ public LimitOrder adaptOrder( String[] currencyPairSplit = order.getCurrencyPair().split("_"); CurrencyPair currencyPair = new CurrencyPair(currencyPairSplit[0], currencyPairSplit[1]); return new LimitOrder( - order.getType().equals("sell") ? OrderType.ASK : OrderType.BID, + order.getType().equals("sell") ? ASK : BID, order.getAmount(), currencyPair, order.getOrderNumber(), @@ -156,7 +166,7 @@ public OpenOrders adaptOpenOrders( public OrderType adaptOrderType(GateioOrderType cryptoTradeOrderType) { - return (cryptoTradeOrderType.equals(GateioOrderType.BUY)) ? OrderType.BID : OrderType.ASK; + return (cryptoTradeOrderType.equals(GateioOrderType.BUY)) ? BID : ASK; } public Trade adaptTrade( @@ -301,6 +311,22 @@ public String toString(OrderStatus orderStatus) { } + public OrderStatus toOrderStatus(String gateioOrderStatus) { + switch (gateioOrderStatus) { + case "open": + return OrderStatus.OPEN; + case "filled": + case "closed": + return OrderStatus.FILLED; + case "cancelled": + case "stp": + return OrderStatus.CANCELED; + default: + throw new IllegalArgumentException("Can't map " + gateioOrderStatus); + } + } + + public GateioOrder toGateioOrder(MarketOrder marketOrder) { GateioOrder gateioOrder = GateioOrder.builder() .currencyPair(toString(marketOrder.getInstrument())) @@ -315,6 +341,35 @@ public GateioOrder toGateioOrder(MarketOrder marketOrder) { } + public Order toOrder(GateioOrder gateioOrder) { + Order.Builder order; + Instrument instrument = toInstrument(gateioOrder.getCurrencyPair()); + OrderType orderType = toOrderType(gateioOrder.getSide()); + + switch (gateioOrder.getType()) { + case "market": + order = new MarketOrder.Builder(orderType, instrument); + break; + case "limit": + order = new LimitOrder.Builder(orderType, instrument); + break; + default: + throw new IllegalArgumentException("Can't map " + gateioOrder.getType()); + } + + return order + .id(gateioOrder.getId()) + .originalAmount(gateioOrder.getAmount()) + .userReference(gateioOrder.getClientOrderId()) + .timestamp(Date.from(gateioOrder.getCreatedAt())) + .orderStatus(toOrderStatus(gateioOrder.getStatus())) + .cumulativeAmount(gateioOrder.getFilledTotalQuote()) + .averagePrice(gateioOrder.getAvgDealPrice()) + .fee(gateioOrder.getFee()) + .build(); + } + + public String toString(OrderType orderType) { switch (orderType) { case BID: @@ -324,6 +379,17 @@ public String toString(OrderType orderType) { default: throw new IllegalArgumentException("Can't map " + orderType); } + } + + public OrderType toOrderType(String gateioOrderType) { + switch (gateioOrderType) { + case "buy": + return BID; + case "sell": + return ASK; + default: + throw new IllegalArgumentException("Can't map " + gateioOrderType); + } } } diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeService.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeService.java index 497b5432699..0ac0565d0d3 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeService.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeService.java @@ -1,9 +1,9 @@ package org.knowm.xchange.gateio.service; import java.io.IOException; -import java.util.ArrayList; import java.util.Collection; import java.util.List; +import org.apache.commons.lang3.Validate; import org.knowm.xchange.currency.CurrencyPair; import org.knowm.xchange.dto.Order; import org.knowm.xchange.dto.trade.LimitOrder; @@ -18,7 +18,6 @@ import org.knowm.xchange.gateio.dto.GateioException; import org.knowm.xchange.gateio.dto.account.GateioOrder; import org.knowm.xchange.gateio.dto.trade.GateioOpenOrders; -import org.knowm.xchange.gateio.dto.trade.GateioOrderStatus; import org.knowm.xchange.gateio.dto.trade.GateioTrade; import org.knowm.xchange.instrument.Instrument; import org.knowm.xchange.service.trade.TradeService; @@ -28,8 +27,8 @@ import org.knowm.xchange.service.trade.params.DefaultTradeHistoryParamCurrencyPair; import org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair; import org.knowm.xchange.service.trade.params.TradeHistoryParams; -import org.knowm.xchange.service.trade.params.orders.DefaultQueryOrderParamCurrencyPair; import org.knowm.xchange.service.trade.params.orders.OpenOrdersParams; +import org.knowm.xchange.service.trade.params.orders.OrderQueryParamInstrument; import org.knowm.xchange.service.trade.params.orders.OrderQueryParams; public class GateioTradeService extends GateioTradeServiceRaw implements TradeService { @@ -122,32 +121,19 @@ public UserTrades getTradeHistory(TradeHistoryParams params) @Override public Collection getOrder(OrderQueryParams... orderQueryParams) throws IOException { - List orders = new ArrayList<>(); - for (OrderQueryParams param : orderQueryParams) { - if (!(param instanceof DefaultQueryOrderParamCurrencyPair)) { - throw new NotAvailableFromExchangeException("getOrder in gateio needs orderId and currency pair"); - } - DefaultQueryOrderParamCurrencyPair queryOrderParamCurrencyPair = (DefaultQueryOrderParamCurrencyPair) param; - GateioOrderStatus gateioOrderStatus = getGateioOrderStatus( - queryOrderParamCurrencyPair.getOrderId(), - queryOrderParamCurrencyPair.getCurrencyPair() - ); - - LimitOrder limitOrder = new LimitOrder( - GateioAdapters.adaptOrderType(gateioOrderStatus.getType()), - gateioOrderStatus.getInitialAmount(), - gateioOrderStatus.getInitialAmount().subtract(gateioOrderStatus.getAmount()), - gateioOrderStatus.getCurrencyPair(), - gateioOrderStatus.getOrderNumber(), - null, - gateioOrderStatus.getInitialRate()) { - }; - limitOrder.setAveragePrice(gateioOrderStatus.getRate()); - orders.add(limitOrder); + // todo: implement getting of several orders + Validate.validState(orderQueryParams.length == 1); + Validate.isInstanceOf(OrderQueryParamInstrument.class, orderQueryParams[0]); - } + OrderQueryParamInstrument params = (OrderQueryParamInstrument) orderQueryParams[0]; - return orders; + try { + GateioOrder gateioOrder = getOrder(params.getOrderId(), params.getInstrument()); + return List.of(GateioAdapters.toOrder(gateioOrder)); + } + catch (GateioException e) { + throw GateioErrorAdapter.adapt(e); + } } @Override diff --git a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioTradeServiceTest.java b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioTradeServiceTest.java index a3b988c5243..ac7a02d728e 100644 --- a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioTradeServiceTest.java +++ b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioTradeServiceTest.java @@ -5,12 +5,16 @@ import java.io.IOException; import java.math.BigDecimal; +import java.time.Instant; +import java.util.Date; import org.junit.jupiter.api.Test; import org.knowm.xchange.currency.CurrencyPair; +import org.knowm.xchange.dto.Order.OrderStatus; import org.knowm.xchange.dto.Order.OrderType; import org.knowm.xchange.dto.trade.MarketOrder; import org.knowm.xchange.exceptions.FundsExceededException; import org.knowm.xchange.gateio.GateioExchangeWiremock; +import org.knowm.xchange.service.trade.params.orders.DefaultQueryOrderParamInstrument; class GateioTradeServiceTest extends GateioExchangeWiremock { @@ -42,5 +46,35 @@ void valid_market_buy_order() throws IOException { } + @Test + void valid_market_sell_order() throws IOException { + MarketOrder marketOrder = new MarketOrder.Builder(OrderType.ASK, CurrencyPair.BTC_USDT) + .userReference("t-valid-market-sell-order") + .originalAmount(new BigDecimal("0.0007")) + .build(); + + var actualResponse = gateioTradeService.placeMarketOrder(marketOrder); + assertThat(actualResponse).isEqualTo("342260949533"); + + } + + + @Test + void order_details() throws IOException { + MarketOrder expected = new MarketOrder.Builder(OrderType.BID, CurrencyPair.BTC_USDT) + .id("342251629898") + .userReference("t-valid-market-buy-order") + .timestamp(Date.from(Instant.parse("2023-06-03T22:07:38.451Z"))) + .originalAmount(BigDecimal.valueOf(20)) + .orderStatus(OrderStatus.FILLED) + .cumulativeAmount(new BigDecimal("18.92681")) + .averagePrice(new BigDecimal("27038.3")) + .fee(new BigDecimal("0.0000014")) + .build(); + + var a = gateioTradeService.getOrder(new DefaultQueryOrderParamInstrument(CurrencyPair.BTC_USDT, "342251629898")); + assertThat(a).hasSize(1); + assertThat(a).first().usingRecursiveComparison().isEqualTo(expected); + } } \ No newline at end of file From f40f4590891bc4b4f4ea35204c5bad0c2c8da4c3 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Sun, 4 Jun 2023 10:42:26 +0200 Subject: [PATCH 026/159] [gateio-v4] Add orders to TradeService --- .../xchange/gateio/service/GateioTradeServiceTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioTradeServiceTest.java b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioTradeServiceTest.java index ac7a02d728e..70fd9faeaad 100644 --- a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioTradeServiceTest.java +++ b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioTradeServiceTest.java @@ -72,9 +72,9 @@ void order_details() throws IOException { .fee(new BigDecimal("0.0000014")) .build(); - var a = gateioTradeService.getOrder(new DefaultQueryOrderParamInstrument(CurrencyPair.BTC_USDT, "342251629898")); - assertThat(a).hasSize(1); - assertThat(a).first().usingRecursiveComparison().isEqualTo(expected); + var orders = gateioTradeService.getOrder(new DefaultQueryOrderParamInstrument(CurrencyPair.BTC_USDT, "342251629898")); + assertThat(orders).hasSize(1); + assertThat(orders).first().usingRecursiveComparison().isEqualTo(expected); } } \ No newline at end of file From f978df64c9a5b4284625900e82955f7c92ca1781 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Sun, 4 Jun 2023 22:40:57 +0200 Subject: [PATCH 027/159] [gateio-v4] Add withdrawing funds --- .../knowm/xchange/gateio/GateioAdapters.java | 20 +++++++ .../xchange/gateio/GateioV4Authenticated.java | 23 ++++++++ .../dto/account/GateioWithdrawalRecord.java | 51 ++++++++++++++++++ .../dto/account/GateioWithdrawalRequest.java | 32 +++++++++++ .../gateio/service/GateioAccountService.java | 43 ++++++--------- .../service/GateioAccountServiceRaw.java | 13 +++++ .../DefaultGateioWithdrawFundsParams.java | 15 ++++++ .../xchange/gateio/GateioExchangeTest.java | 2 +- .../service/GateioAccountServiceRawTest.java | 54 +++++++++++++++++++ .../service/GateioAccountServiceTest.java | 17 ++++++ .../api_v4_wallet_withdrawals-records.json | 15 ++++++ .../api_v4_withdrawals-create-new.json | 10 ++++ .../api_v4_wallet_withdrawals-records.json | 15 ++++++ .../api_v4_withdrawals-create-new.json | 20 +++++++ 14 files changed, 301 insertions(+), 29 deletions(-) create mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioWithdrawalRecord.java create mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioWithdrawalRequest.java create mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/params/DefaultGateioWithdrawFundsParams.java create mode 100644 xchange-gateio-v4/src/test/resources/__files/api_v4_wallet_withdrawals-records.json create mode 100644 xchange-gateio-v4/src/test/resources/__files/api_v4_withdrawals-create-new.json create mode 100644 xchange-gateio-v4/src/test/resources/mappings/api_v4_wallet_withdrawals-records.json create mode 100644 xchange-gateio-v4/src/test/resources/mappings/api_v4_withdrawals-create-new.json diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java index 6cf093d535b..08ced09495d 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java @@ -33,6 +33,7 @@ import org.knowm.xchange.gateio.dto.GateioOrderType; import org.knowm.xchange.gateio.dto.account.GateioDepositsWithdrawals; import org.knowm.xchange.gateio.dto.account.GateioOrder; +import org.knowm.xchange.gateio.dto.account.GateioWithdrawalRequest; import org.knowm.xchange.gateio.dto.marketdata.GateioCurrencyPairDetails; import org.knowm.xchange.gateio.dto.marketdata.GateioDepth; import org.knowm.xchange.gateio.dto.marketdata.GateioOrderBook; @@ -42,6 +43,7 @@ import org.knowm.xchange.gateio.dto.trade.GateioOpenOrder; import org.knowm.xchange.gateio.dto.trade.GateioOpenOrders; import org.knowm.xchange.gateio.dto.trade.GateioTrade; +import org.knowm.xchange.gateio.service.params.DefaultGateioWithdrawFundsParams; import org.knowm.xchange.instrument.Instrument; import org.knowm.xchange.utils.DateUtils; @@ -56,6 +58,11 @@ public CurrencyPair adaptCurrencyPair(String pair) { } + public String toString(Currency currency) { + return currency.getCurrencyCode(); + } + + public String toString(Instrument instrument) { return String.format("%s_%s", instrument.getBase().getCurrencyCode(), @@ -392,4 +399,17 @@ public OrderType toOrderType(String gateioOrderType) { throw new IllegalArgumentException("Can't map " + gateioOrderType); } } + + + public GateioWithdrawalRequest toGateioWithdrawalRequest(DefaultGateioWithdrawFundsParams p) { + return GateioWithdrawalRequest.builder() + .clientRecordId(p.getClientRecordId()) + .address(p.getAddress()) + .tag(p.getAddressTag()) + .chain(p.getChain()) + .amount(p.getAmount()) + .currency(toString(p.getCurrency())) + .build(); + + } } diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java index 1368de3da6c..93eba92a786 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java @@ -16,6 +16,8 @@ import org.knowm.xchange.gateio.dto.account.GateioDepositAddress; import org.knowm.xchange.gateio.dto.account.GateioOrder; import org.knowm.xchange.gateio.dto.account.GateioWithdrawStatus; +import org.knowm.xchange.gateio.dto.account.GateioWithdrawalRecord; +import org.knowm.xchange.gateio.dto.account.GateioWithdrawalRequest; import si.mazi.rescu.ParamsDigest; import si.mazi.rescu.SynchronizedValueFactory; @@ -86,4 +88,25 @@ GateioOrder createOrder( ) throws IOException, GateioException; + @GET + @Path("wallet/withdrawals") + List getWithdrawals( + @HeaderParam("KEY") String apiKey, + @HeaderParam("Timestamp") SynchronizedValueFactory timestamp, + @HeaderParam("SIGN") ParamsDigest signer, + @QueryParam("currency") String currency + ) throws IOException, GateioException; + + + @POST + @Path("withdrawals") + @Consumes(MediaType.APPLICATION_JSON) + GateioWithdrawalRecord withdraw( + @HeaderParam("KEY") String apiKey, + @HeaderParam("Timestamp") SynchronizedValueFactory timestamp, + @HeaderParam("SIGN") ParamsDigest signer, + GateioWithdrawalRequest gateioWithdrawalRequest + ) throws IOException, GateioException; + + } diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioWithdrawalRecord.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioWithdrawalRecord.java new file mode 100644 index 00000000000..32df4ab5f70 --- /dev/null +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioWithdrawalRecord.java @@ -0,0 +1,51 @@ +package org.knowm.xchange.gateio.dto.account; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import java.math.BigDecimal; +import java.time.Instant; +import lombok.Builder; +import lombok.Data; +import lombok.extern.jackson.Jacksonized; +import org.knowm.xchange.gateio.config.TimestampSecondsToInstantConverter; + +@Data +@Builder +@Jacksonized +public class GateioWithdrawalRecord { + + @JsonProperty("id") + String id; + + @JsonProperty("txid") + String txId; + + @JsonProperty("withdraw_order_id") + String clientRecordId; + + @JsonProperty("timestamp") + @JsonDeserialize(converter = TimestampSecondsToInstantConverter.class) + Instant createdAt; + + @JsonProperty("amount") + BigDecimal amount; + + @JsonProperty("currency") + String currency; + + @JsonProperty("address") + String address; + + @JsonProperty("memo") + String tag; + + @JsonProperty("status") + String status; + + @JsonProperty("chain") + String chain; + + @JsonProperty("fee") + BigDecimal fee; + +} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioWithdrawalRequest.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioWithdrawalRequest.java new file mode 100644 index 00000000000..b8c680f1b19 --- /dev/null +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioWithdrawalRequest.java @@ -0,0 +1,32 @@ +package org.knowm.xchange.gateio.dto.account; + +import com.fasterxml.jackson.annotation.JsonProperty; +import java.math.BigDecimal; +import lombok.Builder; +import lombok.Data; +import lombok.extern.jackson.Jacksonized; + +@Data +@Builder +@Jacksonized +public class GateioWithdrawalRequest { + + @JsonProperty("withdraw_order_id") + String clientRecordId; + + @JsonProperty("amount") + BigDecimal amount; + + @JsonProperty("currency") + String currency; + + @JsonProperty("address") + String address; + + @JsonProperty("memo") + String tag; + + @JsonProperty("chain") + String chain; + +} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountService.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountService.java index c55d2907756..b1c5b4956bb 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountService.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountService.java @@ -1,10 +1,10 @@ package org.knowm.xchange.gateio.service; import java.io.IOException; -import java.math.BigDecimal; import java.util.Date; import java.util.List; import java.util.stream.Collectors; +import org.apache.commons.lang3.Validate; import org.knowm.xchange.currency.Currency; import org.knowm.xchange.dto.account.AccountInfo; import org.knowm.xchange.dto.account.Balance; @@ -17,10 +17,10 @@ import org.knowm.xchange.gateio.dto.GateioException; import org.knowm.xchange.gateio.dto.account.GateioCurrencyBalance; import org.knowm.xchange.gateio.dto.account.GateioDepositsWithdrawals; +import org.knowm.xchange.gateio.dto.account.GateioWithdrawalRecord; +import org.knowm.xchange.gateio.dto.account.GateioWithdrawalRequest; +import org.knowm.xchange.gateio.service.params.DefaultGateioWithdrawFundsParams; import org.knowm.xchange.service.account.AccountService; -import org.knowm.xchange.service.trade.params.DefaultWithdrawFundsParams; -import org.knowm.xchange.service.trade.params.MoneroWithdrawFundsParams; -import org.knowm.xchange.service.trade.params.RippleWithdrawFundsParams; import org.knowm.xchange.service.trade.params.TradeHistoryParams; import org.knowm.xchange.service.trade.params.TradeHistoryParamsTimeSpan; import org.knowm.xchange.service.trade.params.WithdrawFundsParams; @@ -65,34 +65,21 @@ public AccountInfo getAccountInfo() throws IOException { } - @Override - public String withdrawFunds(Currency currency, BigDecimal amount, String address) - throws IOException { - return withdraw(currency.getCurrencyCode(), amount, address); - } @Override public String withdrawFunds(WithdrawFundsParams params) throws IOException { - if (params instanceof RippleWithdrawFundsParams) { - RippleWithdrawFundsParams xrpParams = (RippleWithdrawFundsParams) params; - return withdraw( - xrpParams.getCurrency(), - xrpParams.getAmount(), - xrpParams.getAddress(), - xrpParams.getTag()); - } else if (params instanceof MoneroWithdrawFundsParams) { - MoneroWithdrawFundsParams xmrParams = (MoneroWithdrawFundsParams) params; - return withdraw( - xmrParams.getCurrency(), - xmrParams.getAmount(), - xmrParams.getAddress(), - xmrParams.getPaymentId()); - } else if (params instanceof DefaultWithdrawFundsParams) { - DefaultWithdrawFundsParams defaultParams = (DefaultWithdrawFundsParams) params; - return withdrawFunds( - defaultParams.getCurrency(), defaultParams.getAmount(), defaultParams.getAddress()); + Validate.isInstanceOf(DefaultGateioWithdrawFundsParams.class, params, "Not enough parameters"); + DefaultGateioWithdrawFundsParams p = (DefaultGateioWithdrawFundsParams) params; + + GateioWithdrawalRequest gateioWithdrawalRequest = GateioAdapters.toGateioWithdrawalRequest(p); + + try { + GateioWithdrawalRecord gateioWithdrawalRecord = withdraw(gateioWithdrawalRequest); + return gateioWithdrawalRecord.getId(); + } + catch (GateioException e) { + throw GateioErrorAdapter.adapt(e); } - throw new IllegalStateException("Don't know how to withdraw: " + params); } diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountServiceRaw.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountServiceRaw.java index 4c6f1133fae..cc203f9cb8c 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountServiceRaw.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountServiceRaw.java @@ -14,6 +14,8 @@ import org.knowm.xchange.gateio.dto.account.GateioDepositAddress; import org.knowm.xchange.gateio.dto.account.GateioDepositsWithdrawals; import org.knowm.xchange.gateio.dto.account.GateioWithdrawStatus; +import org.knowm.xchange.gateio.dto.account.GateioWithdrawalRecord; +import org.knowm.xchange.gateio.dto.account.GateioWithdrawalRequest; public class GateioAccountServiceRaw extends GateioBaseService { @@ -97,4 +99,15 @@ public List getSpotBalances(Currency currency) throws IOE } + public List getWithdrawals(Currency currency) throws IOException { + String currencyCode = currency == null ? null : currency.getCurrencyCode(); + return gateioV4Authenticated.getWithdrawals(apiKey, exchange.getNonceFactory(), gateioV4ParamsDigest, currencyCode); + } + + + public GateioWithdrawalRecord withdraw(GateioWithdrawalRequest gateioWithdrawalRequest) throws IOException { + return gateioV4Authenticated.withdraw(apiKey, exchange.getNonceFactory(), gateioV4ParamsDigest, gateioWithdrawalRequest); + } + + } diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/params/DefaultGateioWithdrawFundsParams.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/params/DefaultGateioWithdrawFundsParams.java new file mode 100644 index 00000000000..291eecb144c --- /dev/null +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/params/DefaultGateioWithdrawFundsParams.java @@ -0,0 +1,15 @@ +package org.knowm.xchange.gateio.service.params; + +import lombok.Value; +import lombok.experimental.SuperBuilder; +import org.knowm.xchange.service.trade.params.DefaultWithdrawFundsParams; + +@Value +@SuperBuilder +public class DefaultGateioWithdrawFundsParams extends DefaultWithdrawFundsParams { + + String clientRecordId; + + String chain; + +} diff --git a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/GateioExchangeTest.java b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/GateioExchangeTest.java index 20cd4173b3e..2f76b5e060c 100644 --- a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/GateioExchangeTest.java +++ b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/GateioExchangeTest.java @@ -10,7 +10,7 @@ public class GateioExchangeTest extends GateioExchangeWiremock { @Test - public void metadata_present() { + void metadata_present() { InstrumentMetaData expected = new InstrumentMetaData.Builder() .tradingFee(new BigDecimal("0.2")) .minimumAmount(new BigDecimal("0.0001")) diff --git a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceRawTest.java b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceRawTest.java index 5a3830b3b95..aff90371933 100644 --- a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceRawTest.java +++ b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceRawTest.java @@ -5,6 +5,7 @@ import java.io.IOException; import java.math.BigDecimal; +import java.time.Instant; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -16,6 +17,8 @@ import org.knowm.xchange.gateio.dto.account.GateioDepositAddress; import org.knowm.xchange.gateio.dto.account.GateioDepositAddress.MultichainAddress; import org.knowm.xchange.gateio.dto.account.GateioWithdrawStatus; +import org.knowm.xchange.gateio.dto.account.GateioWithdrawalRecord; +import org.knowm.xchange.gateio.dto.account.GateioWithdrawalRequest; public class GateioAccountServiceRawTest extends GateioExchangeWiremock { @@ -107,4 +110,55 @@ void valid_deposit_address() throws IOException { } + @Test + void withdrawal_records() throws IOException { + var actual = gateioAccountServiceRaw.getWithdrawals(null); + + GateioWithdrawalRecord expected = GateioWithdrawalRecord.builder() + .id("w35874123") + .currency("LUFFY") + .address("0x3dca2ae4d1d065220a731cf69f5a934914afc435") + .amount(new BigDecimal("1030645.8587")) + .fee(new BigDecimal("10000")) + .txId("0x8f72d42b016a2b7b543149e707ff37fadded2ff3ef6767bee30b6003330f604b") + .chain("ETH") + .createdAt(Instant.parse("2023-06-01T11:34:15Z")) + .status("DONE") + .clientRecordId("a") + .tag("b") + .build(); + + assertThat(actual).hasSize(1); + assertThat(actual).first().usingRecursiveComparison().isEqualTo(expected); + } + + + @Test + void withdraw() throws IOException { + GateioWithdrawalRequest gateioWithdrawalRequest = GateioWithdrawalRequest.builder() + .clientRecordId("valid-withdrawal-id") + .address("6vLyxJ9dBziamyaw2vDcs9n2NwQdW1uk3aooJwrEscnA") + .tag("") + .chain("SOL") + .amount(BigDecimal.valueOf(3)) + .currency("USDT") + .build(); + + GateioWithdrawalRecord actual = gateioAccountServiceRaw.withdraw(gateioWithdrawalRequest); + + GateioWithdrawalRecord expected = GateioWithdrawalRecord.builder() + .id("w35980955") + .clientRecordId("valid-withdrawal-id") + .address("6vLyxJ9dBziamyaw2vDcs9n2NwQdW1uk3aooJwrEscnA ") + .tag("") + .chain("SOL") + .amount(BigDecimal.valueOf(3)) + .currency("USDT") + .status("REQUEST") + .build(); + + assertThat(actual).usingRecursiveComparison().isEqualTo(expected); + + } + } \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceTest.java b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceTest.java index c6d5629c95b..2ede958eaa8 100644 --- a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceTest.java +++ b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceTest.java @@ -9,6 +9,7 @@ import org.knowm.xchange.dto.account.AccountInfo; import org.knowm.xchange.dto.account.Balance; import org.knowm.xchange.gateio.GateioExchangeWiremock; +import org.knowm.xchange.gateio.service.params.DefaultGateioWithdrawFundsParams; class GateioAccountServiceTest extends GateioExchangeWiremock { @@ -27,4 +28,20 @@ void getAccountInfo() throws IOException { assertThat(usdtBalance.getAvailable()).isEqualTo(new BigDecimal("4.1")); assertThat(usdtBalance.getFrozen()).isEqualTo(new BigDecimal("1.1")); } + + + @Test + void withdrawFunds() throws IOException { + DefaultGateioWithdrawFundsParams params = DefaultGateioWithdrawFundsParams.builder() + .clientRecordId("valid-withdrawal-id") + .address("6vLyxJ9dBziamyaw2vDcs9n2NwQdW1uk3aooJwrEscnA") + .addressTag("") + .chain("SOL") + .amount(BigDecimal.valueOf(3)) + .currency(Currency.USDT) + .build(); + + String withdrawalId = gateioAccountService.withdrawFunds(params); + assertThat(withdrawalId).isEqualTo("w35980955"); + } } \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/resources/__files/api_v4_wallet_withdrawals-records.json b/xchange-gateio-v4/src/test/resources/__files/api_v4_wallet_withdrawals-records.json new file mode 100644 index 00000000000..7eea85bc078 --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/__files/api_v4_wallet_withdrawals-records.json @@ -0,0 +1,15 @@ +[ + { + "id": "w35874123", + "currency": "LUFFY", + "address": "0x3dca2ae4d1d065220a731cf69f5a934914afc435", + "amount": "1030645.8587", + "fee": "10000", + "txid": "0x8f72d42b016a2b7b543149e707ff37fadded2ff3ef6767bee30b6003330f604b", + "chain": "ETH", + "timestamp": "1685619255", + "status": "DONE", + "withdraw_order_id": "a", + "memo": "b" + } +] \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/resources/__files/api_v4_withdrawals-create-new.json b/xchange-gateio-v4/src/test/resources/__files/api_v4_withdrawals-create-new.json new file mode 100644 index 00000000000..e1e91e4d738 --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/__files/api_v4_withdrawals-create-new.json @@ -0,0 +1,10 @@ +{ + "id": "w35980955", + "currency": "USDT", + "amount": "3", + "address": "6vLyxJ9dBziamyaw2vDcs9n2NwQdW1uk3aooJwrEscnA ", + "memo": "", + "status": "REQUEST", + "chain": "SOL", + "withdraw_order_id": "valid-withdrawal-id" +} \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/resources/mappings/api_v4_wallet_withdrawals-records.json b/xchange-gateio-v4/src/test/resources/mappings/api_v4_wallet_withdrawals-records.json new file mode 100644 index 00000000000..9f71f98cd27 --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/mappings/api_v4_wallet_withdrawals-records.json @@ -0,0 +1,15 @@ +{ + "id" : "27c5026f-0655-4b5a-a621-04dbc34684e5", + "name" : "api_v4_wallet_withdrawals", + "request" : { + "url" : "/api/v4/wallet/withdrawals", + "method" : "GET" + }, + "response" : { + "status" : 200, + "bodyFileName" : "api_v4_wallet_withdrawals-records.json" + }, + "uuid" : "27c5026f-0655-4b5a-a621-04dbc34684e5", + "persistent" : true, + "insertionIndex" : 21 +} \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/resources/mappings/api_v4_withdrawals-create-new.json b/xchange-gateio-v4/src/test/resources/mappings/api_v4_withdrawals-create-new.json new file mode 100644 index 00000000000..a46d87b5de3 --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/mappings/api_v4_withdrawals-create-new.json @@ -0,0 +1,20 @@ +{ + "id" : "cb6973a2-5831-427d-9430-d5a7d01b9a4d", + "name" : "api_v4_withdrawals", + "request" : { + "url" : "/api/v4/withdrawals", + "method" : "POST", + "bodyPatterns" : [ { + "equalToJson" : "{\"withdraw_order_id\":\"valid-withdrawal-id\",\"amount\":3,\"currency\":\"USDT\",\"address\":\"6vLyxJ9dBziamyaw2vDcs9n2NwQdW1uk3aooJwrEscnA\",\"memo\":\"\",\"chain\":\"SOL\"}", + "ignoreArrayOrder" : true, + "ignoreExtraElements" : true + } ] + }, + "response" : { + "status" : 200, + "bodyFileName" : "api_v4_withdrawals-create-new.json" + }, + "uuid" : "cb6973a2-5831-427d-9430-d5a7d01b9a4d", + "persistent" : true, + "insertionIndex" : 22 +} \ No newline at end of file From 30181150f229d4dba0f3367ba185a98cef9df06d Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Sun, 4 Jun 2023 22:40:57 +0200 Subject: [PATCH 028/159] [gateio-v4] Add withdrawing funds --- .../knowm/xchange/gateio/GateioAdapters.java | 20 +++++++ .../xchange/gateio/GateioV4Authenticated.java | 23 ++++++++ .../dto/account/GateioWithdrawalRecord.java | 51 ++++++++++++++++++ .../dto/account/GateioWithdrawalRequest.java | 32 +++++++++++ .../gateio/service/GateioAccountService.java | 49 ++++++----------- .../service/GateioAccountServiceRaw.java | 13 +++++ .../DefaultGateioWithdrawFundsParams.java | 15 ++++++ .../xchange/gateio/GateioExchangeTest.java | 2 +- .../service/GateioAccountServiceRawTest.java | 54 +++++++++++++++++++ .../service/GateioAccountServiceTest.java | 17 ++++++ .../api_v4_wallet_withdrawals-records.json | 15 ++++++ .../api_v4_withdrawals-create-new.json | 10 ++++ .../api_v4_wallet_withdrawals-records.json | 15 ++++++ .../api_v4_withdrawals-create-new.json | 20 +++++++ 14 files changed, 302 insertions(+), 34 deletions(-) create mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioWithdrawalRecord.java create mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioWithdrawalRequest.java create mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/params/DefaultGateioWithdrawFundsParams.java create mode 100644 xchange-gateio-v4/src/test/resources/__files/api_v4_wallet_withdrawals-records.json create mode 100644 xchange-gateio-v4/src/test/resources/__files/api_v4_withdrawals-create-new.json create mode 100644 xchange-gateio-v4/src/test/resources/mappings/api_v4_wallet_withdrawals-records.json create mode 100644 xchange-gateio-v4/src/test/resources/mappings/api_v4_withdrawals-create-new.json diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java index 6cf093d535b..08ced09495d 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java @@ -33,6 +33,7 @@ import org.knowm.xchange.gateio.dto.GateioOrderType; import org.knowm.xchange.gateio.dto.account.GateioDepositsWithdrawals; import org.knowm.xchange.gateio.dto.account.GateioOrder; +import org.knowm.xchange.gateio.dto.account.GateioWithdrawalRequest; import org.knowm.xchange.gateio.dto.marketdata.GateioCurrencyPairDetails; import org.knowm.xchange.gateio.dto.marketdata.GateioDepth; import org.knowm.xchange.gateio.dto.marketdata.GateioOrderBook; @@ -42,6 +43,7 @@ import org.knowm.xchange.gateio.dto.trade.GateioOpenOrder; import org.knowm.xchange.gateio.dto.trade.GateioOpenOrders; import org.knowm.xchange.gateio.dto.trade.GateioTrade; +import org.knowm.xchange.gateio.service.params.DefaultGateioWithdrawFundsParams; import org.knowm.xchange.instrument.Instrument; import org.knowm.xchange.utils.DateUtils; @@ -56,6 +58,11 @@ public CurrencyPair adaptCurrencyPair(String pair) { } + public String toString(Currency currency) { + return currency.getCurrencyCode(); + } + + public String toString(Instrument instrument) { return String.format("%s_%s", instrument.getBase().getCurrencyCode(), @@ -392,4 +399,17 @@ public OrderType toOrderType(String gateioOrderType) { throw new IllegalArgumentException("Can't map " + gateioOrderType); } } + + + public GateioWithdrawalRequest toGateioWithdrawalRequest(DefaultGateioWithdrawFundsParams p) { + return GateioWithdrawalRequest.builder() + .clientRecordId(p.getClientRecordId()) + .address(p.getAddress()) + .tag(p.getAddressTag()) + .chain(p.getChain()) + .amount(p.getAmount()) + .currency(toString(p.getCurrency())) + .build(); + + } } diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java index 1368de3da6c..93eba92a786 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java @@ -16,6 +16,8 @@ import org.knowm.xchange.gateio.dto.account.GateioDepositAddress; import org.knowm.xchange.gateio.dto.account.GateioOrder; import org.knowm.xchange.gateio.dto.account.GateioWithdrawStatus; +import org.knowm.xchange.gateio.dto.account.GateioWithdrawalRecord; +import org.knowm.xchange.gateio.dto.account.GateioWithdrawalRequest; import si.mazi.rescu.ParamsDigest; import si.mazi.rescu.SynchronizedValueFactory; @@ -86,4 +88,25 @@ GateioOrder createOrder( ) throws IOException, GateioException; + @GET + @Path("wallet/withdrawals") + List getWithdrawals( + @HeaderParam("KEY") String apiKey, + @HeaderParam("Timestamp") SynchronizedValueFactory timestamp, + @HeaderParam("SIGN") ParamsDigest signer, + @QueryParam("currency") String currency + ) throws IOException, GateioException; + + + @POST + @Path("withdrawals") + @Consumes(MediaType.APPLICATION_JSON) + GateioWithdrawalRecord withdraw( + @HeaderParam("KEY") String apiKey, + @HeaderParam("Timestamp") SynchronizedValueFactory timestamp, + @HeaderParam("SIGN") ParamsDigest signer, + GateioWithdrawalRequest gateioWithdrawalRequest + ) throws IOException, GateioException; + + } diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioWithdrawalRecord.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioWithdrawalRecord.java new file mode 100644 index 00000000000..32df4ab5f70 --- /dev/null +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioWithdrawalRecord.java @@ -0,0 +1,51 @@ +package org.knowm.xchange.gateio.dto.account; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import java.math.BigDecimal; +import java.time.Instant; +import lombok.Builder; +import lombok.Data; +import lombok.extern.jackson.Jacksonized; +import org.knowm.xchange.gateio.config.TimestampSecondsToInstantConverter; + +@Data +@Builder +@Jacksonized +public class GateioWithdrawalRecord { + + @JsonProperty("id") + String id; + + @JsonProperty("txid") + String txId; + + @JsonProperty("withdraw_order_id") + String clientRecordId; + + @JsonProperty("timestamp") + @JsonDeserialize(converter = TimestampSecondsToInstantConverter.class) + Instant createdAt; + + @JsonProperty("amount") + BigDecimal amount; + + @JsonProperty("currency") + String currency; + + @JsonProperty("address") + String address; + + @JsonProperty("memo") + String tag; + + @JsonProperty("status") + String status; + + @JsonProperty("chain") + String chain; + + @JsonProperty("fee") + BigDecimal fee; + +} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioWithdrawalRequest.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioWithdrawalRequest.java new file mode 100644 index 00000000000..b8c680f1b19 --- /dev/null +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioWithdrawalRequest.java @@ -0,0 +1,32 @@ +package org.knowm.xchange.gateio.dto.account; + +import com.fasterxml.jackson.annotation.JsonProperty; +import java.math.BigDecimal; +import lombok.Builder; +import lombok.Data; +import lombok.extern.jackson.Jacksonized; + +@Data +@Builder +@Jacksonized +public class GateioWithdrawalRequest { + + @JsonProperty("withdraw_order_id") + String clientRecordId; + + @JsonProperty("amount") + BigDecimal amount; + + @JsonProperty("currency") + String currency; + + @JsonProperty("address") + String address; + + @JsonProperty("memo") + String tag; + + @JsonProperty("chain") + String chain; + +} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountService.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountService.java index c55d2907756..7ff487415a0 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountService.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountService.java @@ -1,10 +1,10 @@ package org.knowm.xchange.gateio.service; import java.io.IOException; -import java.math.BigDecimal; import java.util.Date; import java.util.List; import java.util.stream.Collectors; +import org.apache.commons.lang3.Validate; import org.knowm.xchange.currency.Currency; import org.knowm.xchange.dto.account.AccountInfo; import org.knowm.xchange.dto.account.Balance; @@ -17,25 +17,21 @@ import org.knowm.xchange.gateio.dto.GateioException; import org.knowm.xchange.gateio.dto.account.GateioCurrencyBalance; import org.knowm.xchange.gateio.dto.account.GateioDepositsWithdrawals; +import org.knowm.xchange.gateio.dto.account.GateioWithdrawalRecord; +import org.knowm.xchange.gateio.dto.account.GateioWithdrawalRequest; +import org.knowm.xchange.gateio.service.params.DefaultGateioWithdrawFundsParams; import org.knowm.xchange.service.account.AccountService; -import org.knowm.xchange.service.trade.params.DefaultWithdrawFundsParams; -import org.knowm.xchange.service.trade.params.MoneroWithdrawFundsParams; -import org.knowm.xchange.service.trade.params.RippleWithdrawFundsParams; import org.knowm.xchange.service.trade.params.TradeHistoryParams; import org.knowm.xchange.service.trade.params.TradeHistoryParamsTimeSpan; import org.knowm.xchange.service.trade.params.WithdrawFundsParams; public class GateioAccountService extends GateioAccountServiceRaw implements AccountService { - /** - * Constructor - * - * @param exchange - */ public GateioAccountService(GateioExchange exchange) { super(exchange); } + @Override public AccountInfo getAccountInfo() throws IOException { @@ -65,34 +61,21 @@ public AccountInfo getAccountInfo() throws IOException { } - @Override - public String withdrawFunds(Currency currency, BigDecimal amount, String address) - throws IOException { - return withdraw(currency.getCurrencyCode(), amount, address); - } @Override public String withdrawFunds(WithdrawFundsParams params) throws IOException { - if (params instanceof RippleWithdrawFundsParams) { - RippleWithdrawFundsParams xrpParams = (RippleWithdrawFundsParams) params; - return withdraw( - xrpParams.getCurrency(), - xrpParams.getAmount(), - xrpParams.getAddress(), - xrpParams.getTag()); - } else if (params instanceof MoneroWithdrawFundsParams) { - MoneroWithdrawFundsParams xmrParams = (MoneroWithdrawFundsParams) params; - return withdraw( - xmrParams.getCurrency(), - xmrParams.getAmount(), - xmrParams.getAddress(), - xmrParams.getPaymentId()); - } else if (params instanceof DefaultWithdrawFundsParams) { - DefaultWithdrawFundsParams defaultParams = (DefaultWithdrawFundsParams) params; - return withdrawFunds( - defaultParams.getCurrency(), defaultParams.getAmount(), defaultParams.getAddress()); + Validate.isInstanceOf(DefaultGateioWithdrawFundsParams.class, params, "Not enough parameters"); + DefaultGateioWithdrawFundsParams p = (DefaultGateioWithdrawFundsParams) params; + + GateioWithdrawalRequest gateioWithdrawalRequest = GateioAdapters.toGateioWithdrawalRequest(p); + + try { + GateioWithdrawalRecord gateioWithdrawalRecord = withdraw(gateioWithdrawalRequest); + return gateioWithdrawalRecord.getId(); + } + catch (GateioException e) { + throw GateioErrorAdapter.adapt(e); } - throw new IllegalStateException("Don't know how to withdraw: " + params); } diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountServiceRaw.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountServiceRaw.java index 4c6f1133fae..cc203f9cb8c 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountServiceRaw.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountServiceRaw.java @@ -14,6 +14,8 @@ import org.knowm.xchange.gateio.dto.account.GateioDepositAddress; import org.knowm.xchange.gateio.dto.account.GateioDepositsWithdrawals; import org.knowm.xchange.gateio.dto.account.GateioWithdrawStatus; +import org.knowm.xchange.gateio.dto.account.GateioWithdrawalRecord; +import org.knowm.xchange.gateio.dto.account.GateioWithdrawalRequest; public class GateioAccountServiceRaw extends GateioBaseService { @@ -97,4 +99,15 @@ public List getSpotBalances(Currency currency) throws IOE } + public List getWithdrawals(Currency currency) throws IOException { + String currencyCode = currency == null ? null : currency.getCurrencyCode(); + return gateioV4Authenticated.getWithdrawals(apiKey, exchange.getNonceFactory(), gateioV4ParamsDigest, currencyCode); + } + + + public GateioWithdrawalRecord withdraw(GateioWithdrawalRequest gateioWithdrawalRequest) throws IOException { + return gateioV4Authenticated.withdraw(apiKey, exchange.getNonceFactory(), gateioV4ParamsDigest, gateioWithdrawalRequest); + } + + } diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/params/DefaultGateioWithdrawFundsParams.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/params/DefaultGateioWithdrawFundsParams.java new file mode 100644 index 00000000000..291eecb144c --- /dev/null +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/params/DefaultGateioWithdrawFundsParams.java @@ -0,0 +1,15 @@ +package org.knowm.xchange.gateio.service.params; + +import lombok.Value; +import lombok.experimental.SuperBuilder; +import org.knowm.xchange.service.trade.params.DefaultWithdrawFundsParams; + +@Value +@SuperBuilder +public class DefaultGateioWithdrawFundsParams extends DefaultWithdrawFundsParams { + + String clientRecordId; + + String chain; + +} diff --git a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/GateioExchangeTest.java b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/GateioExchangeTest.java index 20cd4173b3e..2f76b5e060c 100644 --- a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/GateioExchangeTest.java +++ b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/GateioExchangeTest.java @@ -10,7 +10,7 @@ public class GateioExchangeTest extends GateioExchangeWiremock { @Test - public void metadata_present() { + void metadata_present() { InstrumentMetaData expected = new InstrumentMetaData.Builder() .tradingFee(new BigDecimal("0.2")) .minimumAmount(new BigDecimal("0.0001")) diff --git a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceRawTest.java b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceRawTest.java index 5a3830b3b95..aff90371933 100644 --- a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceRawTest.java +++ b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceRawTest.java @@ -5,6 +5,7 @@ import java.io.IOException; import java.math.BigDecimal; +import java.time.Instant; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -16,6 +17,8 @@ import org.knowm.xchange.gateio.dto.account.GateioDepositAddress; import org.knowm.xchange.gateio.dto.account.GateioDepositAddress.MultichainAddress; import org.knowm.xchange.gateio.dto.account.GateioWithdrawStatus; +import org.knowm.xchange.gateio.dto.account.GateioWithdrawalRecord; +import org.knowm.xchange.gateio.dto.account.GateioWithdrawalRequest; public class GateioAccountServiceRawTest extends GateioExchangeWiremock { @@ -107,4 +110,55 @@ void valid_deposit_address() throws IOException { } + @Test + void withdrawal_records() throws IOException { + var actual = gateioAccountServiceRaw.getWithdrawals(null); + + GateioWithdrawalRecord expected = GateioWithdrawalRecord.builder() + .id("w35874123") + .currency("LUFFY") + .address("0x3dca2ae4d1d065220a731cf69f5a934914afc435") + .amount(new BigDecimal("1030645.8587")) + .fee(new BigDecimal("10000")) + .txId("0x8f72d42b016a2b7b543149e707ff37fadded2ff3ef6767bee30b6003330f604b") + .chain("ETH") + .createdAt(Instant.parse("2023-06-01T11:34:15Z")) + .status("DONE") + .clientRecordId("a") + .tag("b") + .build(); + + assertThat(actual).hasSize(1); + assertThat(actual).first().usingRecursiveComparison().isEqualTo(expected); + } + + + @Test + void withdraw() throws IOException { + GateioWithdrawalRequest gateioWithdrawalRequest = GateioWithdrawalRequest.builder() + .clientRecordId("valid-withdrawal-id") + .address("6vLyxJ9dBziamyaw2vDcs9n2NwQdW1uk3aooJwrEscnA") + .tag("") + .chain("SOL") + .amount(BigDecimal.valueOf(3)) + .currency("USDT") + .build(); + + GateioWithdrawalRecord actual = gateioAccountServiceRaw.withdraw(gateioWithdrawalRequest); + + GateioWithdrawalRecord expected = GateioWithdrawalRecord.builder() + .id("w35980955") + .clientRecordId("valid-withdrawal-id") + .address("6vLyxJ9dBziamyaw2vDcs9n2NwQdW1uk3aooJwrEscnA ") + .tag("") + .chain("SOL") + .amount(BigDecimal.valueOf(3)) + .currency("USDT") + .status("REQUEST") + .build(); + + assertThat(actual).usingRecursiveComparison().isEqualTo(expected); + + } + } \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceTest.java b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceTest.java index c6d5629c95b..2ede958eaa8 100644 --- a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceTest.java +++ b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceTest.java @@ -9,6 +9,7 @@ import org.knowm.xchange.dto.account.AccountInfo; import org.knowm.xchange.dto.account.Balance; import org.knowm.xchange.gateio.GateioExchangeWiremock; +import org.knowm.xchange.gateio.service.params.DefaultGateioWithdrawFundsParams; class GateioAccountServiceTest extends GateioExchangeWiremock { @@ -27,4 +28,20 @@ void getAccountInfo() throws IOException { assertThat(usdtBalance.getAvailable()).isEqualTo(new BigDecimal("4.1")); assertThat(usdtBalance.getFrozen()).isEqualTo(new BigDecimal("1.1")); } + + + @Test + void withdrawFunds() throws IOException { + DefaultGateioWithdrawFundsParams params = DefaultGateioWithdrawFundsParams.builder() + .clientRecordId("valid-withdrawal-id") + .address("6vLyxJ9dBziamyaw2vDcs9n2NwQdW1uk3aooJwrEscnA") + .addressTag("") + .chain("SOL") + .amount(BigDecimal.valueOf(3)) + .currency(Currency.USDT) + .build(); + + String withdrawalId = gateioAccountService.withdrawFunds(params); + assertThat(withdrawalId).isEqualTo("w35980955"); + } } \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/resources/__files/api_v4_wallet_withdrawals-records.json b/xchange-gateio-v4/src/test/resources/__files/api_v4_wallet_withdrawals-records.json new file mode 100644 index 00000000000..7eea85bc078 --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/__files/api_v4_wallet_withdrawals-records.json @@ -0,0 +1,15 @@ +[ + { + "id": "w35874123", + "currency": "LUFFY", + "address": "0x3dca2ae4d1d065220a731cf69f5a934914afc435", + "amount": "1030645.8587", + "fee": "10000", + "txid": "0x8f72d42b016a2b7b543149e707ff37fadded2ff3ef6767bee30b6003330f604b", + "chain": "ETH", + "timestamp": "1685619255", + "status": "DONE", + "withdraw_order_id": "a", + "memo": "b" + } +] \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/resources/__files/api_v4_withdrawals-create-new.json b/xchange-gateio-v4/src/test/resources/__files/api_v4_withdrawals-create-new.json new file mode 100644 index 00000000000..e1e91e4d738 --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/__files/api_v4_withdrawals-create-new.json @@ -0,0 +1,10 @@ +{ + "id": "w35980955", + "currency": "USDT", + "amount": "3", + "address": "6vLyxJ9dBziamyaw2vDcs9n2NwQdW1uk3aooJwrEscnA ", + "memo": "", + "status": "REQUEST", + "chain": "SOL", + "withdraw_order_id": "valid-withdrawal-id" +} \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/resources/mappings/api_v4_wallet_withdrawals-records.json b/xchange-gateio-v4/src/test/resources/mappings/api_v4_wallet_withdrawals-records.json new file mode 100644 index 00000000000..9f71f98cd27 --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/mappings/api_v4_wallet_withdrawals-records.json @@ -0,0 +1,15 @@ +{ + "id" : "27c5026f-0655-4b5a-a621-04dbc34684e5", + "name" : "api_v4_wallet_withdrawals", + "request" : { + "url" : "/api/v4/wallet/withdrawals", + "method" : "GET" + }, + "response" : { + "status" : 200, + "bodyFileName" : "api_v4_wallet_withdrawals-records.json" + }, + "uuid" : "27c5026f-0655-4b5a-a621-04dbc34684e5", + "persistent" : true, + "insertionIndex" : 21 +} \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/resources/mappings/api_v4_withdrawals-create-new.json b/xchange-gateio-v4/src/test/resources/mappings/api_v4_withdrawals-create-new.json new file mode 100644 index 00000000000..a46d87b5de3 --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/mappings/api_v4_withdrawals-create-new.json @@ -0,0 +1,20 @@ +{ + "id" : "cb6973a2-5831-427d-9430-d5a7d01b9a4d", + "name" : "api_v4_withdrawals", + "request" : { + "url" : "/api/v4/withdrawals", + "method" : "POST", + "bodyPatterns" : [ { + "equalToJson" : "{\"withdraw_order_id\":\"valid-withdrawal-id\",\"amount\":3,\"currency\":\"USDT\",\"address\":\"6vLyxJ9dBziamyaw2vDcs9n2NwQdW1uk3aooJwrEscnA\",\"memo\":\"\",\"chain\":\"SOL\"}", + "ignoreArrayOrder" : true, + "ignoreExtraElements" : true + } ] + }, + "response" : { + "status" : 200, + "bodyFileName" : "api_v4_withdrawals-create-new.json" + }, + "uuid" : "cb6973a2-5831-427d-9430-d5a7d01b9a4d", + "persistent" : true, + "insertionIndex" : 22 +} \ No newline at end of file From d2e3410f0e1c089c9984fced21d7c4eabd12e30e Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Mon, 5 Jun 2023 00:06:03 +0200 Subject: [PATCH 029/159] [gateio-v4] Add saved addresses --- .../xchange/gateio/GateioV4Authenticated.java | 11 ++++++ .../config/StringToBooleanConverter.java | 11 ++++++ .../dto/account/GateioAddressRecord.java | 34 +++++++++++++++++++ .../service/GateioAccountServiceRaw.java | 8 +++++ .../service/GateioAccountServiceRawTest.java | 19 +++++++++++ .../__files/api_v4_wallet_saved_address.json | 10 ++++++ .../mappings/api_v4_wallet_saved_address.json | 15 ++++++++ 7 files changed, 108 insertions(+) create mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/StringToBooleanConverter.java create mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioAddressRecord.java create mode 100644 xchange-gateio-v4/src/test/resources/__files/api_v4_wallet_saved_address.json create mode 100644 xchange-gateio-v4/src/test/resources/mappings/api_v4_wallet_saved_address.json diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java index 93eba92a786..c23f5aa4c72 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java @@ -12,6 +12,7 @@ import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; import org.knowm.xchange.gateio.dto.GateioException; +import org.knowm.xchange.gateio.dto.account.GateioAddressRecord; import org.knowm.xchange.gateio.dto.account.GateioCurrencyBalance; import org.knowm.xchange.gateio.dto.account.GateioDepositAddress; import org.knowm.xchange.gateio.dto.account.GateioOrder; @@ -88,6 +89,16 @@ GateioOrder createOrder( ) throws IOException, GateioException; + @GET + @Path("wallet/saved_address") + List getSavedAddresses( + @HeaderParam("KEY") String apiKey, + @HeaderParam("Timestamp") SynchronizedValueFactory timestamp, + @HeaderParam("SIGN") ParamsDigest signer, + @QueryParam("currency") String currency + ) throws IOException, GateioException; + + @GET @Path("wallet/withdrawals") List getWithdrawals( diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/StringToBooleanConverter.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/StringToBooleanConverter.java new file mode 100644 index 00000000000..42a5b922cc7 --- /dev/null +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/StringToBooleanConverter.java @@ -0,0 +1,11 @@ +package org.knowm.xchange.gateio.config; + +import com.fasterxml.jackson.databind.util.StdConverter; + +public class StringToBooleanConverter extends StdConverter { + + @Override + public Boolean convert(final String value) { + return "1".equals(value); + } +} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioAddressRecord.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioAddressRecord.java new file mode 100644 index 00000000000..6f4b869c69c --- /dev/null +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioAddressRecord.java @@ -0,0 +1,34 @@ +package org.knowm.xchange.gateio.dto.account; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import lombok.Builder; +import lombok.Data; +import lombok.extern.jackson.Jacksonized; +import org.knowm.xchange.gateio.config.StringToBooleanConverter; + +@Data +@Builder +@Jacksonized +public class GateioAddressRecord { + + @JsonProperty("currency") + String currency; + + @JsonProperty("chain") + String chain; + + @JsonProperty("address") + String address; + + @JsonProperty("name") + String name; + + @JsonProperty("tag") + String tag; + + @JsonProperty("verified") + @JsonDeserialize(converter = StringToBooleanConverter.class) + Boolean verified; + +} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountServiceRaw.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountServiceRaw.java index cc203f9cb8c..6a7d40cb233 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountServiceRaw.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountServiceRaw.java @@ -4,12 +4,14 @@ import java.math.BigDecimal; import java.util.Date; import java.util.List; +import org.apache.commons.lang3.Validate; import org.knowm.xchange.currency.Currency; import org.knowm.xchange.exceptions.ExchangeException; import org.knowm.xchange.gateio.GateioErrorAdapter; import org.knowm.xchange.gateio.GateioExchange; import org.knowm.xchange.gateio.dto.GateioBaseResponse; import org.knowm.xchange.gateio.dto.GateioException; +import org.knowm.xchange.gateio.dto.account.GateioAddressRecord; import org.knowm.xchange.gateio.dto.account.GateioCurrencyBalance; import org.knowm.xchange.gateio.dto.account.GateioDepositAddress; import org.knowm.xchange.gateio.dto.account.GateioDepositsWithdrawals; @@ -110,4 +112,10 @@ public GateioWithdrawalRecord withdraw(GateioWithdrawalRequest gateioWithdrawalR } + public List getSavedAddresses(Currency currency) throws IOException { + Validate.notNull(currency); + return gateioV4Authenticated.getSavedAddresses(apiKey, exchange.getNonceFactory(), gateioV4ParamsDigest, currency.getCurrencyCode()); + } + + } diff --git a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceRawTest.java b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceRawTest.java index aff90371933..743ac0ec179 100644 --- a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceRawTest.java +++ b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceRawTest.java @@ -14,6 +14,7 @@ import org.knowm.xchange.exceptions.ExchangeSecurityException; import org.knowm.xchange.exceptions.InstrumentNotValidException; import org.knowm.xchange.gateio.GateioExchangeWiremock; +import org.knowm.xchange.gateio.dto.account.GateioAddressRecord; import org.knowm.xchange.gateio.dto.account.GateioDepositAddress; import org.knowm.xchange.gateio.dto.account.GateioDepositAddress.MultichainAddress; import org.knowm.xchange.gateio.dto.account.GateioWithdrawStatus; @@ -161,4 +162,22 @@ void withdraw() throws IOException { } + + @Test + void saved_addresses() throws IOException { + List actual = gateioAccountServiceRaw.getSavedAddresses(Currency.USDT); + + GateioAddressRecord expected = GateioAddressRecord.builder() + .address("6vLyxJ9dBziamyaw2vDcs9n2NwQdW1uk3aooJwrEscnA") + .tag("") + .chain("SOL") + .currency("USDT") + .name("stuff") + .verified(true) + .build(); + + assertThat(actual).hasSize(1); + assertThat(actual).first().usingRecursiveComparison().isEqualTo(expected); + } + } \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/resources/__files/api_v4_wallet_saved_address.json b/xchange-gateio-v4/src/test/resources/__files/api_v4_wallet_saved_address.json new file mode 100644 index 00000000000..82fcddf8577 --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/__files/api_v4_wallet_saved_address.json @@ -0,0 +1,10 @@ +[ + { + "currency": "USDT", + "chain": "SOL", + "address": "6vLyxJ9dBziamyaw2vDcs9n2NwQdW1uk3aooJwrEscnA", + "name": "stuff", + "tag": "", + "verified": "1" + } +] \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/resources/mappings/api_v4_wallet_saved_address.json b/xchange-gateio-v4/src/test/resources/mappings/api_v4_wallet_saved_address.json new file mode 100644 index 00000000000..3b3671f9bed --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/mappings/api_v4_wallet_saved_address.json @@ -0,0 +1,15 @@ +{ + "id" : "59a47010-ed6f-4950-9c65-ab57f2e23af3", + "name" : "api_v4_wallet_saved_address", + "request" : { + "url" : "/api/v4/wallet/saved_address?currency=USDT", + "method" : "GET" + }, + "response" : { + "status" : 200, + "bodyFileName" : "api_v4_wallet_saved_address.json" + }, + "uuid" : "59a47010-ed6f-4950-9c65-ab57f2e23af3", + "persistent" : true, + "insertionIndex" : 28 +} \ No newline at end of file From 5c69cc8c95e2666326f4877050150ecf14ac3642 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Mon, 5 Jun 2023 10:24:35 +0200 Subject: [PATCH 030/159] [gateio-v4] Code cleanup --- .../gateio/service/GateioV4Digest.java | 52 +++++-------------- 1 file changed, 13 insertions(+), 39 deletions(-) diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioV4Digest.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioV4Digest.java index a69e183f81f..3625ccc6ff1 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioV4Digest.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioV4Digest.java @@ -1,6 +1,6 @@ package org.knowm.xchange.gateio.service; -import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; import java.security.MessageDigest; import javax.crypto.Mac; import lombok.SneakyThrows; @@ -8,61 +8,35 @@ import org.knowm.xchange.utils.DigestUtils; import si.mazi.rescu.RestInvocation; -/** - * This may be used as the value of a @HeaderParam, @QueryParam or @PathParam to create a digest of - * the post body (composed of @FormParam's). Don't use as the value of a @FormParam, it will - * probably cause an infinite loop. - * - *

This may be used for REST APIs where some parameters' values must be digests of other - * parameters. An example is the MtGox API v1, where the Rest-Sign header parameter must be a digest - * of the request body (which is composed of @FormParams). - */ -public class GateioV4Digest extends BaseParamsDigest { +public final class GateioV4Digest extends BaseParamsDigest { - /** - * Constructor - * - * @param secretKeyBase64 - * @throws IllegalArgumentException if key is invalid (cannot be base-64-decoded or the decoded - * key is invalid). - */ private GateioV4Digest(String secretKeyBase64) { super(secretKeyBase64, HMAC_SHA_512); } public static GateioV4Digest createInstance(String secretKeyBase64) { - return secretKeyBase64 == null ? null : new GateioV4Digest(secretKeyBase64); } @SneakyThrows @Override public String digestParams(RestInvocation restInvocation) { - try { - String postBody = restInvocation.getRequestBody(); - String method = restInvocation.getHttpMethod(); - String path = restInvocation.getPath(); - String query = restInvocation.getQueryString(); - - String body = restInvocation.getRequestBody(); - MessageDigest md = MessageDigest.getInstance("SHA-512"); - String hexedHashedBody = DigestUtils.bytesToHex(md.digest(body.getBytes())); + String method = restInvocation.getHttpMethod(); + String path = restInvocation.getPath(); - String timestamp = restInvocation.getHttpHeadersFromParams().get("Timestamp"); + String query = restInvocation.getQueryString(); + String body = restInvocation.getRequestBody(); + MessageDigest md = MessageDigest.getInstance("SHA-512"); + String hexedHashedBody = DigestUtils.bytesToHex(md.digest(body.getBytes(StandardCharsets.UTF_8))); - String payloadToSign = String.format("%s\n/%s\n%s\n%s\n%s", method, path, query, hexedHashedBody, timestamp); + String timestamp = restInvocation.getHttpHeadersFromParams().get("Timestamp"); - System.out.println(payloadToSign); + String payloadToSign = String.format("%s\n/%s\n%s\n%s\n%s", method, path, query, hexedHashedBody, timestamp); - Mac mac = getMac(); - mac.update(payloadToSign.getBytes("UTF-8")); - return DigestUtils.bytesToHex(mac.doFinal()); -// return String.format("%0128x", new BigInteger(1, mac.doFinal())); + Mac mac = getMac(); + mac.update(payloadToSign.getBytes(StandardCharsets.UTF_8)); - } catch (UnsupportedEncodingException e) { - throw new RuntimeException("Illegal encoding, check the code.", e); - } - // return Base64.encodeBytes(mac.doFinal()).trim(); + return DigestUtils.bytesToHex(mac.doFinal()); } } From 4ea1914cf3d555ff3b9b6073a1ebcf5f47976fb5 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Wed, 7 Jun 2023 01:18:36 +0200 Subject: [PATCH 031/159] [gateio-v4] Add request for idea http client --- xchange-gateio-v4/.gitignore | 1 + .../example.http-client.private.env.json | 6 +++++ xchange-gateio-v4/http-client.env.json | 5 +++++ .../src/test/resources/rest/wallet.http | 22 +++++++++++++++++++ 4 files changed, 34 insertions(+) create mode 100644 xchange-gateio-v4/.gitignore create mode 100644 xchange-gateio-v4/example.http-client.private.env.json create mode 100644 xchange-gateio-v4/http-client.env.json create mode 100644 xchange-gateio-v4/src/test/resources/rest/wallet.http diff --git a/xchange-gateio-v4/.gitignore b/xchange-gateio-v4/.gitignore new file mode 100644 index 00000000000..42c7d2cd0eb --- /dev/null +++ b/xchange-gateio-v4/.gitignore @@ -0,0 +1 @@ +http-client.private.env.json \ No newline at end of file diff --git a/xchange-gateio-v4/example.http-client.private.env.json b/xchange-gateio-v4/example.http-client.private.env.json new file mode 100644 index 00000000000..977c974ecbe --- /dev/null +++ b/xchange-gateio-v4/example.http-client.private.env.json @@ -0,0 +1,6 @@ +{ + "default": { + "api_key": "replace_me", + "api_secret": "replace_me" + } +} \ No newline at end of file diff --git a/xchange-gateio-v4/http-client.env.json b/xchange-gateio-v4/http-client.env.json new file mode 100644 index 00000000000..3038f5935b5 --- /dev/null +++ b/xchange-gateio-v4/http-client.env.json @@ -0,0 +1,5 @@ +{ + "default": { + "api_v4": "https://api.gateio.ws/api/v4" + } +} \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/resources/rest/wallet.http b/xchange-gateio-v4/src/test/resources/rest/wallet.http new file mode 100644 index 00000000000..73d10e2965b --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/rest/wallet.http @@ -0,0 +1,22 @@ +### Retrieve withdrawal status +< {% + const pattern = RegExp("^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?"); + const url = request.url.tryGetSubstituted(); + const matches = url.match(pattern); + const method = "GET"; + const path = matches[5]; + const query = matches[7]; + const hexedHashedBody = crypto.sha512().updateWithText(request.body.tryGetSubstituted() || "").digest().toHex(); + const timestamp = request.headers.findByName("Timestamp").tryGetSubstitutedValue(); + const payloadToSign = `${method}\n${path}\n${query}\n${hexedHashedBody}\n${timestamp}`; + const apiSecret = request.environment.get("api_secret"); + const sign = crypto.hmac.sha512().withTextSecret(apiSecret).updateWithText(payloadToSign).digest().toHex(); + request.variables.set("sign", sign); +%} + +GET {{api_v4}}/wallet/withdraw_status?currency=usdt +KEY: {{api_key}} +SIGN: {{sign}} +Timestamp: {{$timestamp}} +Content-Type: application/json + From 4835ebec9fcdb6aecd595561b19a1d8e3df28f98 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Wed, 7 Jun 2023 23:46:34 +0200 Subject: [PATCH 032/159] [gateio-v4] Fix tests --- .../java/org/knowm/xchange/gateio/GateioExchangeWiremock.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/GateioExchangeWiremock.java b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/GateioExchangeWiremock.java index a85c7586800..bfbd35addd8 100644 --- a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/GateioExchangeWiremock.java +++ b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/GateioExchangeWiremock.java @@ -27,7 +27,7 @@ public static void initExchange() { wireMockServer.start(); ExchangeSpecification exSpec = new ExchangeSpecification(GateioExchange.class); - exSpec.setSslUri("http://localhost:" + wireMockRule.port()); + exSpec.setSslUri("http://localhost:" + wireMockServer.port()); exSpec.setApiKey("a"); exSpec.setSecretKey("b"); From 5a09f2123224290d25e22cbeec258cee44a96089 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Thu, 8 Jun 2023 00:06:05 +0200 Subject: [PATCH 033/159] [kucoin] Extend kucoin support --- .../knowm/xchange/dto/account/Balance.java | 4 + .../kucoin/account/KucoinAccountDemo.java | 2 +- .../xchange/kucoin/KucoinAccountService.java | 134 ++++++++++++++++-- .../kucoin/KucoinAccountServiceRaw.java | 123 ++++++---------- .../knowm/xchange/kucoin/KucoinAdapters.java | 8 +- .../xchange/kucoin/KucoinErrorAdapter.java | 54 +++++++ .../kucoin/KucoinMarketDataService.java | 14 ++ .../kucoin/KucoinMarketDataServiceRaw.java | 10 +- .../xchange/kucoin/dto/KucoinException.java | 19 +++ .../CreateDepositAddressApiRequest.java | 17 +++ .../dto/response/CurrenciesResponse.java | 12 ++ .../kucoin/dto/response/DepositResponse.java | 6 + .../kucoin/dto/response/KucoinResponse.java | 10 ++ .../dto/response/OrderCreateResponse.java | 6 + .../dto/response/WithdrawalResponse.java | 4 + .../xchange/kucoin/service/AccountAPI.java | 5 +- .../xchange/kucoin/service/DepositAPI.java | 13 +- .../xchange/kucoin/service/SymbolAPI.java | 3 +- .../xchange/kucoin/service/WithdrawalAPI.java | 3 +- .../params/KucoinWithdrawFundsParams.java | 15 ++ 20 files changed, 349 insertions(+), 113 deletions(-) create mode 100644 xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/KucoinErrorAdapter.java create mode 100644 xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/dto/KucoinException.java create mode 100644 xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/dto/request/CreateDepositAddressApiRequest.java create mode 100644 xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/service/params/KucoinWithdrawFundsParams.java diff --git a/xchange-core/src/main/java/org/knowm/xchange/dto/account/Balance.java b/xchange-core/src/main/java/org/knowm/xchange/dto/account/Balance.java index c67757c4c7e..37a77d710c7 100644 --- a/xchange-core/src/main/java/org/knowm/xchange/dto/account/Balance.java +++ b/xchange-core/src/main/java/org/knowm/xchange/dto/account/Balance.java @@ -475,6 +475,10 @@ public int compareTo(Balance other) { return comparison; } + public static Builder builder() { + return new Builder(); + } + @JsonPOJOBuilder(withPrefix = "") public static class Builder { diff --git a/xchange-examples/src/main/java/org/knowm/xchange/examples/kucoin/account/KucoinAccountDemo.java b/xchange-examples/src/main/java/org/knowm/xchange/examples/kucoin/account/KucoinAccountDemo.java index df53ad5690d..c8a7215efd4 100644 --- a/xchange-examples/src/main/java/org/knowm/xchange/examples/kucoin/account/KucoinAccountDemo.java +++ b/xchange-examples/src/main/java/org/knowm/xchange/examples/kucoin/account/KucoinAccountDemo.java @@ -36,7 +36,7 @@ private static void raw(KucoinAccountServiceRaw accountService) throws IOExcepti System.out.println("------------RAW-----------"); - List responseBalances = accountService.getKucoinAccounts(); + List responseBalances = accountService.getKucoinAccounts(null, null); System.out.println(responseBalances); // Not yet implemented diff --git a/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/KucoinAccountService.java b/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/KucoinAccountService.java index 064796ff16c..aea31969b24 100644 --- a/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/KucoinAccountService.java +++ b/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/KucoinAccountService.java @@ -5,19 +5,30 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; +import java.util.Locale; +import java.util.Map; import java.util.stream.Collectors; +import org.apache.commons.lang3.Validate; import org.knowm.xchange.client.ResilienceRegistries; import org.knowm.xchange.currency.Currency; import org.knowm.xchange.dto.account.AccountInfo; +import org.knowm.xchange.dto.account.AddressWithTag; +import org.knowm.xchange.dto.account.Balance; import org.knowm.xchange.dto.account.FundingRecord; import org.knowm.xchange.dto.account.FundingRecord.Type; import org.knowm.xchange.dto.account.Wallet; +import org.knowm.xchange.kucoin.dto.KucoinException; +import org.knowm.xchange.kucoin.dto.request.ApplyWithdrawApiRequest; +import org.knowm.xchange.kucoin.dto.request.CreateDepositAddressApiRequest; import org.knowm.xchange.kucoin.dto.response.AccountBalancesResponse; +import org.knowm.xchange.kucoin.dto.response.DepositAddressResponse; +import org.knowm.xchange.kucoin.service.params.KucoinWithdrawFundsParams; import org.knowm.xchange.service.account.AccountService; import org.knowm.xchange.service.trade.params.HistoryParamsFundingType; import org.knowm.xchange.service.trade.params.TradeHistoryParamCurrency; import org.knowm.xchange.service.trade.params.TradeHistoryParams; import org.knowm.xchange.service.trade.params.TradeHistoryParamsTimeSpan; +import org.knowm.xchange.service.trade.params.WithdrawFundsParams; public class KucoinAccountService extends KucoinAccountServiceRaw implements AccountService { @@ -27,21 +38,33 @@ public class KucoinAccountService extends KucoinAccountServiceRaw implements Acc @Override public AccountInfo getAccountInfo() throws IOException { - List accounts = getKucoinAccounts(); - return new AccountInfo( - accounts.stream() - .map(AccountBalancesResponse::getType) - .distinct() - .map( - type -> - Wallet.Builder.from( - accounts.stream() - .filter(a -> a.getType().equals(type)) - .map(KucoinAdapters::adaptBalance) - .collect(toList())) - .id(type) - .build()) - .collect(toList())); + + try { + + List accounts = getKucoinAccounts(null, null); + + // split balances by account type: main, trade, margin + Map> balancesByAccountType = accounts.stream() + .collect(Collectors.groupingBy( + AccountBalancesResponse::getType, + Collectors.mapping(KucoinAdapters::adaptBalance, toList())) + ); + + // convert balances to wallets + List wallets = new ArrayList<>(); + balancesByAccountType.forEach((accountType, balances) -> { + Wallet wallet = Wallet.Builder + .from(balances) + .id(accountType) + .name(accountType) + .build(); + wallets.add(wallet); + }); + + return new AccountInfo(wallets); + } catch (KucoinException e) { + throw KucoinErrorAdapter.adapt(e); + } } public TradeHistoryParams createFundingHistoryParams() { @@ -83,4 +106,85 @@ public List getFundingHistory(TradeHistoryParams params) throws I } return result; } + + + @Override + public String withdrawFunds(WithdrawFundsParams params) throws IOException { + Validate.isInstanceOf(KucoinWithdrawFundsParams.class, params); + + KucoinWithdrawFundsParams withdrawFundsParams = (KucoinWithdrawFundsParams) params; + + ApplyWithdrawApiRequest request = ApplyWithdrawApiRequest.builder() + .currency(withdrawFundsParams.getCurrency().getCurrencyCode()) + .address(withdrawFundsParams.getAddress()) + .amount(withdrawFundsParams.getAmount()) + .memo(withdrawFundsParams.getAddressTag()) + .remark(withdrawFundsParams.getRemark()) + .chain(withdrawFundsParams.getChain()) + .build(); + + try { + return applyWithdraw(request).getWithdrawalId(); + } catch (KucoinException e) { + throw KucoinErrorAdapter.adapt(e); + } + + + } + + + /** + * @param args Chain name + */ + @Override + public AddressWithTag requestDepositAddressData(Currency currency, String... args) + throws IOException { + Validate.isTrue(args.length == 1, "Chain name is missing"); + String chain = args[0]; + + try { + + DepositAddressResponse response = getDepositAddress(currency.getCurrencyCode(), chain); + + return AddressWithTag.builder() + .address(response.getAddress()) + .addressTag(response.getMemo()) + .build(); + + } catch (KucoinException e) { + throw KucoinErrorAdapter.adapt(e); + } + + } + + + public List requestDepositAddressData(Currency currency) + throws IOException { + try { + + return getDepositAddresses(currency.getCurrencyCode()); + + } catch (KucoinException e) { + throw KucoinErrorAdapter.adapt(e); + } + + } + + + public DepositAddressResponse createDepositAddress(Currency currency, String chain) throws IOException { + try { + + CreateDepositAddressApiRequest request = CreateDepositAddressApiRequest.builder() + .currency(currency.getCurrencyCode().toUpperCase(Locale.ROOT)) + .chain(chain) + .build(); + + return createDepositAddress(request); + + } catch (KucoinException e) { + throw KucoinErrorAdapter.adapt(e); + } + + } + } diff --git a/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/KucoinAccountServiceRaw.java b/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/KucoinAccountServiceRaw.java index 3419c4b8342..d0fab7334a2 100644 --- a/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/KucoinAccountServiceRaw.java +++ b/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/KucoinAccountServiceRaw.java @@ -5,9 +5,11 @@ import java.io.IOException; import java.util.List; +import java.util.Locale; import org.knowm.xchange.client.ResilienceRegistries; import org.knowm.xchange.kucoin.dto.request.ApplyWithdrawApiRequest; import org.knowm.xchange.kucoin.dto.request.CreateAccountRequest; +import org.knowm.xchange.kucoin.dto.request.CreateDepositAddressApiRequest; import org.knowm.xchange.kucoin.dto.request.InnerTransferRequest; import org.knowm.xchange.kucoin.dto.response.AccountBalancesResponse; import org.knowm.xchange.kucoin.dto.response.AccountLedgersResponse; @@ -25,17 +27,13 @@ protected KucoinAccountServiceRaw( super(exchange, resilienceRegistries); } - public List getKucoinAccounts() throws IOException { - checkAuthenticated(); - return classifyingExceptions( - () -> - decorateApiCall( - () -> - accountApi.getAccountList( - apiKey, digest, nonceFactory, passphrase, null, null)) - .withRetry(retry("accountList")) - .withRateLimiter(rateLimiter(PRIVATE_REST_ENDPOINT_RATE_LIMITER)) - .call()); + public List getKucoinAccounts(String currency, String accountType) throws IOException { + return decorateApiCall(() -> + accountApi.getAccountList(apiKey, digest, nonceFactory, passphrase, currency, accountType)) + .withRetry(retry("accountList")) + .withRateLimiter(rateLimiter(PRIVATE_REST_ENDPOINT_RATE_LIMITER)) + .call() + .getData(); } public Void createKucoinAccount(String currency, String type) throws IOException { @@ -55,24 +53,17 @@ public Void createKucoinAccount(String currency, String type) throws IOException } public ApplyWithdrawResponse applyWithdraw(ApplyWithdrawApiRequest req) throws IOException { - checkAuthenticated(); - return classifyingExceptions( - () -> - decorateApiCall( - () -> + return decorateApiCall(() -> withdrawalAPI.applyWithdraw(apiKey, digest, nonceFactory, passphrase, req)) .withRateLimiter(rateLimiter(PRIVATE_REST_ENDPOINT_RATE_LIMITER)) - .call()); + .call().getData(); } public InternalTransferResponse innerTransfer(InnerTransferRequest req) throws IOException { - checkAuthenticated(); - return classifyingExceptions( - () -> - decorateApiCall( - () -> accountApi.innerTransfer(apiKey, digest, nonceFactory, passphrase, req)) - .withRateLimiter(rateLimiter(PRIVATE_REST_ENDPOINT_RATE_LIMITER)) - .call()); + return decorateApiCall(() -> + accountApi.innerTransfer(apiKey, digest, nonceFactory, passphrase, req)) + .withRateLimiter(rateLimiter(PRIVATE_REST_ENDPOINT_RATE_LIMITER)) + .call().getData(); } @Deprecated @@ -128,32 +119,14 @@ public Pagination getAccountLedgersWithParams( .call()); } - public Pagination getWithdrawalsList( - String currency, - String status, - Long startAt, - Long endAt, - Integer pageSize, - Integer currentPage) - throws IOException { + public Pagination getWithdrawalsList(String currency, String status, + Long startAt, Long endAt, Integer pageSize, Integer currentPage) throws IOException + { checkAuthenticated(); - return classifyingExceptions( - () -> - decorateApiCall( - () -> - withdrawalAPI.getWithdrawalsList( - apiKey, - digest, - nonceFactory, - passphrase, - currency, - status, - startAt, - endAt, - pageSize, - currentPage)) - .withRateLimiter(rateLimiter(PRIVATE_REST_ENDPOINT_RATE_LIMITER)) - .call()); + return classifyingExceptions(() -> decorateApiCall( + () -> withdrawalAPI.getWithdrawalsList(apiKey, digest, nonceFactory, passphrase, currency, + status, startAt, endAt, pageSize, currentPage)).withRateLimiter( + rateLimiter(PRIVATE_REST_ENDPOINT_RATE_LIMITER)).call()); } public Pagination getDepositList( @@ -184,41 +157,31 @@ public Pagination getDepositList( .call()); } - public DepositAddressResponse createDepositAddress(String currency, String chain) - throws IOException { - checkAuthenticated(); - return classifyingExceptions( - () -> - decorateApiCall( - () -> - depositAPI.createDepositAddress( - apiKey, digest, nonceFactory, passphrase, currency, chain)) - .withRateLimiter(rateLimiter(PRIVATE_REST_ENDPOINT_RATE_LIMITER)) - .call()); + public DepositAddressResponse createDepositAddress(CreateDepositAddressApiRequest request) throws IOException { + return decorateApiCall(() -> + depositAPI.createDepositAddress(apiKey, digest, nonceFactory, passphrase, request)) + .withRateLimiter(rateLimiter(PRIVATE_REST_ENDPOINT_RATE_LIMITER)) + .call() + .getData(); } - public DepositAddressResponse getDepositAddress(String currency, String chain) - throws IOException { - checkAuthenticated(); - return classifyingExceptions( - () -> - decorateApiCall( - () -> - depositAPI.getDepositAddress( - apiKey, digest, nonceFactory, passphrase, currency, chain)) - .withRateLimiter(rateLimiter(PRIVATE_REST_ENDPOINT_RATE_LIMITER)) - .call()); + public DepositAddressResponse getDepositAddress(String currency, String chain) throws IOException { + + // kucoin expects currency to be uppercase + String currencyAdapted = currency.toUpperCase(Locale.ROOT); + + return decorateApiCall(() -> + depositAPI.getDepositAddress(apiKey, digest, nonceFactory, passphrase, currencyAdapted, chain)) + .withRateLimiter(rateLimiter(PRIVATE_REST_ENDPOINT_RATE_LIMITER)) + .call() + .getData(); } public List getDepositAddresses(String currency) throws IOException { - checkAuthenticated(); - return classifyingExceptions( - () -> - decorateApiCall( - () -> - depositAPI.getDepositAddresses( - apiKey, digest, nonceFactory, passphrase, currency)) - .withRateLimiter(rateLimiter(PRIVATE_REST_ENDPOINT_RATE_LIMITER)) - .call()); + return decorateApiCall(() -> + depositAPI.getDepositAddresses(apiKey, digest, nonceFactory, passphrase,currency)) + .withRateLimiter(rateLimiter(PRIVATE_REST_ENDPOINT_RATE_LIMITER)) + .call() + .getData(); } } diff --git a/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/KucoinAdapters.java b/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/KucoinAdapters.java index 22bfd285fc6..3213f47e0c3 100644 --- a/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/KucoinAdapters.java +++ b/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/KucoinAdapters.java @@ -41,7 +41,11 @@ import org.knowm.xchange.dto.marketdata.Trade; import org.knowm.xchange.dto.marketdata.Trades; import org.knowm.xchange.dto.marketdata.Trades.TradeSortType; -import org.knowm.xchange.dto.meta.*; +import org.knowm.xchange.dto.meta.CurrencyMetaData; +import org.knowm.xchange.dto.meta.ExchangeMetaData; +import org.knowm.xchange.dto.meta.FeeTier; +import org.knowm.xchange.dto.meta.InstrumentMetaData; +import org.knowm.xchange.dto.meta.WalletHealth; import org.knowm.xchange.dto.trade.LimitOrder; import org.knowm.xchange.dto.trade.MarketOrder; import org.knowm.xchange.dto.trade.StopOrder; @@ -249,7 +253,7 @@ public static Trades adaptTrades( } public static Balance adaptBalance(AccountBalancesResponse a) { - return new Balance(Currency.getInstance(a.getCurrency()), a.getBalance(), a.getAvailable()); + return new Balance(Currency.getInstance(a.getCurrency()), a.getBalance(), a.getAvailable(), a.getHolds()); } private static Trade adaptTrade(CurrencyPair currencyPair, TradeHistoryResponse trade) { diff --git a/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/KucoinErrorAdapter.java b/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/KucoinErrorAdapter.java new file mode 100644 index 00000000000..fc20c825e76 --- /dev/null +++ b/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/KucoinErrorAdapter.java @@ -0,0 +1,54 @@ +package org.knowm.xchange.kucoin; + +import org.apache.commons.lang3.StringUtils; +import org.knowm.xchange.exceptions.CurrencyPairNotValidException; +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.kucoin.dto.KucoinException; + +public final class KucoinErrorAdapter { + /** + * 200004 Balance insufficient + */ + public static final int BALANCE_INSUFFICIENT = 200004; + + /** + * 400001 Missing security header + */ + public static final int MISSING_SECURITY_HEADER = 400001; + + /** + * 900001 symbol not exists + */ + public static final int SYMBOL_NOT_EXISTS = 900001; + + /** + * 900003 Currency not exists + */ + public static final int CURRENCY_NOT_EXISTS = 900003; + + private KucoinErrorAdapter() { + } + + public static ExchangeException adapt(KucoinException e) { + String message = e.getMessage(); + if (StringUtils.isEmpty(message)) { + message = "Operation failed without any error message"; + } + switch (e.getCode()) { + case BALANCE_INSUFFICIENT: + return new FundsExceededException(e.getMessage(), e); + case SYMBOL_NOT_EXISTS: + return new CurrencyPairNotValidException(e.getMessage(), e); + case CURRENCY_NOT_EXISTS: + return new InstrumentNotValidException(e.getMessage(), e); + case MISSING_SECURITY_HEADER: + return new ExchangeSecurityException(e.getMessage(), e); + default: + return new ExchangeException(message, e); + } + } + +} diff --git a/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/KucoinMarketDataService.java b/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/KucoinMarketDataService.java index 5aa3e6a1b99..40bf256a8fa 100644 --- a/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/KucoinMarketDataService.java +++ b/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/KucoinMarketDataService.java @@ -8,6 +8,8 @@ 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.kucoin.dto.KucoinException; +import org.knowm.xchange.kucoin.dto.response.SymbolResponse; import org.knowm.xchange.service.marketdata.MarketDataService; import org.knowm.xchange.service.marketdata.params.Params; @@ -58,4 +60,16 @@ public OrderBook getOrderBook(CurrencyPair currencyPair, Object... args) throws public Trades getTrades(CurrencyPair currencyPair, Object... args) throws IOException { return KucoinAdapters.adaptTrades(currencyPair, getKucoinTrades(currencyPair)); } + + @Override + public List getKucoinSymbolsV2() throws IOException { + try { + return super.getKucoinSymbolsV2(); + } catch (KucoinException e) { + throw KucoinErrorAdapter.adapt(e); + } + + } + + } diff --git a/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/KucoinMarketDataServiceRaw.java b/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/KucoinMarketDataServiceRaw.java index 94be7c89b2f..69eaea19dd2 100644 --- a/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/KucoinMarketDataServiceRaw.java +++ b/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/KucoinMarketDataServiceRaw.java @@ -105,12 +105,10 @@ public List getKucoinSymbols() throws IOException { } public List getKucoinSymbolsV2() throws IOException { - return classifyingExceptions( - () -> - decorateApiCall(symbolApi::getSymbolsV2) - .withRetry(retry("symbols")) - .withRateLimiter(rateLimiter(PUBLIC_REST_ENDPOINT_RATE_LIMITER)) - .call()); + return decorateApiCall(symbolApi::getSymbolsV2) + .withRetry(retry("symbols")) + .withRateLimiter(rateLimiter(PUBLIC_REST_ENDPOINT_RATE_LIMITER)).call() + .getData(); } public List getKucoinCurrencies() throws IOException { diff --git a/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/dto/KucoinException.java b/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/dto/KucoinException.java new file mode 100644 index 00000000000..76ce0242ba1 --- /dev/null +++ b/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/dto/KucoinException.java @@ -0,0 +1,19 @@ +package org.knowm.xchange.kucoin.dto; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Builder; +import lombok.Value; +import lombok.extern.jackson.Jacksonized; + +@Value +@Jacksonized +@Builder +public class KucoinException extends RuntimeException { + + @JsonProperty("code") + int code; + + @JsonProperty("msg") + String message; + +} diff --git a/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/dto/request/CreateDepositAddressApiRequest.java b/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/dto/request/CreateDepositAddressApiRequest.java new file mode 100644 index 00000000000..6c10cfad3fe --- /dev/null +++ b/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/dto/request/CreateDepositAddressApiRequest.java @@ -0,0 +1,17 @@ +package org.knowm.xchange.kucoin.dto.request; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; +import lombok.Builder; +import lombok.Value; + +@Value +@Builder +@JsonInclude(value = Include.NON_EMPTY, content = Include.NON_NULL) +public class CreateDepositAddressApiRequest { + + String currency; + + String chain; + +} diff --git a/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/dto/response/CurrenciesResponse.java b/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/dto/response/CurrenciesResponse.java index c7e358da37c..096b977d187 100644 --- a/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/dto/response/CurrenciesResponse.java +++ b/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/dto/response/CurrenciesResponse.java @@ -9,16 +9,28 @@ @JsonIgnoreProperties(ignoreUnknown = true) public class CurrenciesResponse { + @JsonProperty("currency") private String currency; + @JsonProperty("name") private String name; + @JsonProperty("fullName") private String fullName; + @JsonProperty("precision") private BigDecimal precision; + @JsonProperty("confirms") + private Integer confirms; + + @JsonProperty("contractAddress") + private String contractAddress; + + @JsonProperty("withdrawalMinSize") private String withdrawalMinSize; + @JsonProperty("withdrawalMinFee") private String withdrawalMinFee; @JsonProperty("isWithdrawEnabled") diff --git a/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/dto/response/DepositResponse.java b/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/dto/response/DepositResponse.java index cc5c346bc89..c2885bce84c 100644 --- a/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/dto/response/DepositResponse.java +++ b/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/dto/response/DepositResponse.java @@ -3,8 +3,10 @@ import java.math.BigDecimal; import java.util.Date; import lombok.Data; +import lombok.extern.jackson.Jacksonized; @Data +@Jacksonized public class DepositResponse { /** Creation time of the database record */ @@ -13,6 +15,10 @@ public class DepositResponse { private BigDecimal amount; /** Deposit address */ private String address; + + /** Chain of currency */ + private String chain; + /** Deposit fee */ private BigDecimal fee; /** diff --git a/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/dto/response/KucoinResponse.java b/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/dto/response/KucoinResponse.java index f9f93eca587..23e722f08c8 100644 --- a/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/dto/response/KucoinResponse.java +++ b/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/dto/response/KucoinResponse.java @@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import java.io.Serializable; import lombok.Data; +import si.mazi.rescu.ExceptionalReturnContentException; /** Created by zicong.lu on 2018/12/14. */ @Data @@ -27,4 +28,13 @@ public String getCode() { public String getMessage() { return msg; } + + public void setCode(String code) { + if (!SUCCESS_CODE.equals(code)) { + throw new ExceptionalReturnContentException(code); + } + this.code = code; + } + + } diff --git a/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/dto/response/OrderCreateResponse.java b/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/dto/response/OrderCreateResponse.java index 919f60ee9fa..794538d2115 100644 --- a/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/dto/response/OrderCreateResponse.java +++ b/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/dto/response/OrderCreateResponse.java @@ -2,11 +2,17 @@ package org.knowm.xchange.kucoin.dto.response; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Data; @Data @JsonIgnoreProperties(ignoreUnknown = true) public class OrderCreateResponse { + @JsonProperty("orderId") private String orderId; + + @JsonProperty("clientOrderId") + private String clientOrderId; + } diff --git a/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/dto/response/WithdrawalResponse.java b/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/dto/response/WithdrawalResponse.java index a66756a6175..3fa1a88050f 100644 --- a/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/dto/response/WithdrawalResponse.java +++ b/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/dto/response/WithdrawalResponse.java @@ -19,6 +19,10 @@ public class WithdrawalResponse { private String memo; /** Currency */ private String currency; + + /** The chain of currency /*/ + private String chain; + /** Withdrawal amount */ private BigDecimal amount; /** Withdrawal fee */ diff --git a/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/service/AccountAPI.java b/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/service/AccountAPI.java index c92429bf70f..833ec8b533a 100644 --- a/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/service/AccountAPI.java +++ b/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/service/AccountAPI.java @@ -12,6 +12,7 @@ import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; +import org.knowm.xchange.kucoin.dto.KucoinException; import org.knowm.xchange.kucoin.dto.request.CreateAccountRequest; import org.knowm.xchange.kucoin.dto.request.InnerTransferRequest; import org.knowm.xchange.kucoin.dto.response.AccountBalancesResponse; @@ -48,7 +49,7 @@ KucoinResponse> getAccountList( @HeaderParam(APIConstants.API_HEADER_PASSPHRASE) String apiPassphrase, @QueryParam("currency") String currency, @QueryParam("type") String type) - throws IOException; + throws IOException, KucoinException; @POST @Path("v1/accounts") @@ -70,7 +71,7 @@ KucoinResponse innerTransfer( @HeaderParam(APIConstants.API_HEADER_TIMESTAMP) SynchronizedValueFactory nonce, @HeaderParam(APIConstants.API_HEADER_PASSPHRASE) String apiPassphrase, InnerTransferRequest req) - throws IOException; + throws IOException, KucoinException; @GET @Path("v1/accounts/{accountId}/ledgers") diff --git a/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/service/DepositAPI.java b/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/service/DepositAPI.java index f85aebf5963..75ef442e443 100644 --- a/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/service/DepositAPI.java +++ b/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/service/DepositAPI.java @@ -2,6 +2,7 @@ import java.io.IOException; import java.util.List; +import javax.ws.rs.Consumes; import javax.ws.rs.GET; import javax.ws.rs.HeaderParam; import javax.ws.rs.POST; @@ -9,6 +10,8 @@ import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; +import org.knowm.xchange.kucoin.dto.KucoinException; +import org.knowm.xchange.kucoin.dto.request.CreateDepositAddressApiRequest; import org.knowm.xchange.kucoin.dto.response.DepositAddressResponse; import org.knowm.xchange.kucoin.dto.response.DepositResponse; import org.knowm.xchange.kucoin.dto.response.KucoinResponse; @@ -49,15 +52,15 @@ KucoinResponse> getDepositList( throws IOException; @POST + @Consumes(MediaType.APPLICATION_JSON) @Path("/v1/deposit-addresses") KucoinResponse createDepositAddress( @HeaderParam(APIConstants.API_HEADER_KEY) String apiKey, @HeaderParam(APIConstants.API_HEADER_SIGN) ParamsDigest signature, @HeaderParam(APIConstants.API_HEADER_TIMESTAMP) SynchronizedValueFactory nonce, @HeaderParam(APIConstants.API_HEADER_PASSPHRASE) String apiPassphrase, - @QueryParam("currency") String currency, - @QueryParam("chain") String chain) - throws IOException; + CreateDepositAddressApiRequest request) + throws IOException, KucoinException; @GET @Path("/v1/deposit-addresses") @@ -68,7 +71,7 @@ KucoinResponse getDepositAddress( @HeaderParam(APIConstants.API_HEADER_PASSPHRASE) String apiPassphrase, @QueryParam("currency") String currency, @QueryParam("chain") String chain) - throws IOException; + throws IOException, KucoinException; @GET @Path("/v2/deposit-addresses") @@ -78,5 +81,5 @@ KucoinResponse> getDepositAddresses( @HeaderParam(APIConstants.API_HEADER_TIMESTAMP) SynchronizedValueFactory nonce, @HeaderParam(APIConstants.API_HEADER_PASSPHRASE) String apiPassphrase, @QueryParam("currency") String currency) - throws IOException; + throws IOException, KucoinException; } diff --git a/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/service/SymbolAPI.java b/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/service/SymbolAPI.java index 1cfa56f1166..ebcb7befdd5 100644 --- a/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/service/SymbolAPI.java +++ b/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/service/SymbolAPI.java @@ -11,6 +11,7 @@ import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; +import org.knowm.xchange.kucoin.dto.KucoinException; import org.knowm.xchange.kucoin.dto.response.AllTickersResponse; import org.knowm.xchange.kucoin.dto.response.CurrenciesResponse; import org.knowm.xchange.kucoin.dto.response.CurrencyResponseV2; @@ -42,7 +43,7 @@ public interface SymbolAPI { */ @GET @Path("/v2/symbols") - KucoinResponse> getSymbolsV2() throws IOException; + KucoinResponse> getSymbolsV2() throws IOException, KucoinException; /** * Get a list of available currencies for trading. diff --git a/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/service/WithdrawalAPI.java b/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/service/WithdrawalAPI.java index 7c64a51c7e4..c9576e55c3b 100644 --- a/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/service/WithdrawalAPI.java +++ b/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/service/WithdrawalAPI.java @@ -9,6 +9,7 @@ import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; +import org.knowm.xchange.kucoin.dto.KucoinException; import org.knowm.xchange.kucoin.dto.request.ApplyWithdrawApiRequest; import org.knowm.xchange.kucoin.dto.response.ApplyWithdrawResponse; import org.knowm.xchange.kucoin.dto.response.KucoinResponse; @@ -35,7 +36,7 @@ KucoinResponse applyWithdraw( @HeaderParam(APIConstants.API_HEADER_TIMESTAMP) SynchronizedValueFactory nonce, @HeaderParam(APIConstants.API_HEADER_PASSPHRASE) String apiPassphrase, ApplyWithdrawApiRequest req) - throws IOException; + throws IOException, KucoinException; /** * Get Withdrawals List. diff --git a/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/service/params/KucoinWithdrawFundsParams.java b/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/service/params/KucoinWithdrawFundsParams.java new file mode 100644 index 00000000000..adfeb217884 --- /dev/null +++ b/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/service/params/KucoinWithdrawFundsParams.java @@ -0,0 +1,15 @@ +package org.knowm.xchange.kucoin.service.params; + +import lombok.Value; +import lombok.experimental.SuperBuilder; +import org.knowm.xchange.service.trade.params.DefaultWithdrawFundsParams; + +@Value +@SuperBuilder +public class KucoinWithdrawFundsParams extends DefaultWithdrawFundsParams { + + String chain; + + String remark; + +} From daa2cd075ff68dbe785084e16e946a4388737b16 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Thu, 8 Jun 2023 00:18:25 +0200 Subject: [PATCH 034/159] [core] Make AddressWithTag writable --- .../java/org/knowm/xchange/dto/account/AddressWithTag.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xchange-core/src/main/java/org/knowm/xchange/dto/account/AddressWithTag.java b/xchange-core/src/main/java/org/knowm/xchange/dto/account/AddressWithTag.java index a04f831987a..253cf577bad 100644 --- a/xchange-core/src/main/java/org/knowm/xchange/dto/account/AddressWithTag.java +++ b/xchange-core/src/main/java/org/knowm/xchange/dto/account/AddressWithTag.java @@ -2,9 +2,9 @@ import lombok.AllArgsConstructor; import lombok.Builder; -import lombok.Value; +import lombok.Data; -@Value +@Data @Builder @AllArgsConstructor public class AddressWithTag { From abead833084174b4e455720226cc00b4c135058c Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Fri, 9 Jun 2023 00:39:51 +0200 Subject: [PATCH 035/159] [gateio-v4] Code cleanup --- .../java/org/knowm/xchange/gateio/Gateio.java | 30 ---- .../knowm/xchange/gateio/GateioAdapters.java | 148 +----------------- .../xchange/gateio/GateioAuthenticated.java | 118 -------------- .../GateioJacksonObjectMapperFactory.java | 3 + .../config/StringToBooleanConverter.java | 3 + .../TimestampSecondsToInstantConverter.java | 3 + .../gateio/dto/account/GateioDeposit.java | 56 ------- .../account/GateioDepositsWithdrawals.java | 34 ---- .../gateio/dto/account/GateioFunds.java | 47 ------ .../gateio/dto/account/GateioWithdrawal.java | 56 ------- .../marketdata/GateioCandlestickHistory.java | 34 ---- .../gateio/dto/marketdata/GateioCoin.java | 59 ------- .../dto/marketdata/GateioCoinInfoWrapper.java | 80 ---------- .../dto/marketdata/GateioCurrencyPairs.java | 55 ------- .../gateio/service/GateioAccountService.java | 25 --- .../service/GateioAccountServiceRaw.java | 49 ------ .../gateio/service/GateioBaseService.java | 19 +-- .../service/GateioHmacPostBodyDigest.java | 60 ------- .../service/GateioMarketDataService.java | 16 -- .../service/GateioMarketDataServiceRaw.java | 71 --------- .../gateio/service/GateioTradeService.java | 89 +---------- .../gateio/service/GateioTradeServiceRaw.java | 126 --------------- .../marketdata/GateioCurrencyChainTest.java | 28 ++++ .../GateioMarketDataServiceRawTest.java | 35 +++-- 24 files changed, 63 insertions(+), 1181 deletions(-) delete mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAuthenticated.java delete mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioDeposit.java delete mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioDepositsWithdrawals.java delete mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioFunds.java delete mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioWithdrawal.java delete mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioCandlestickHistory.java delete mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioCoin.java delete mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioCoinInfoWrapper.java delete mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioCurrencyPairs.java delete mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioHmacPostBodyDigest.java create mode 100644 xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/dto/marketdata/GateioCurrencyChainTest.java 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 f0bb26a9e81..63581d9232f 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 @@ -10,13 +10,9 @@ import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; import org.knowm.xchange.gateio.dto.GateioException; -import org.knowm.xchange.gateio.dto.marketdata.GateioCandlestickHistory; -import org.knowm.xchange.gateio.dto.marketdata.GateioCoinInfoWrapper; 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.GateioCurrencyPairs; -import org.knowm.xchange.gateio.dto.marketdata.GateioDepth; import org.knowm.xchange.gateio.dto.marketdata.GateioMarketInfoWrapper; import org.knowm.xchange.gateio.dto.marketdata.GateioOrderBook; import org.knowm.xchange.gateio.dto.marketdata.GateioTicker; @@ -30,34 +26,16 @@ public interface Gateio { @Path("api/v2/marketinfo") GateioMarketInfoWrapper getMarketInfo() throws IOException; - @GET - @Path("api2/1/pairs") - GateioCurrencyPairs getPairs() throws IOException; - - @GET - @Path("api2/1/orderBooks") - Map getDepths() throws IOException; - @GET @Path("/api2/1/tickers") Map getTickers() throws IOException; - @GET - @Path("/api2/1/coininfo") - GateioCoinInfoWrapper getCoinInfo() throws IOException; - @GET @Path("api2/1/ticker/{ident}_{currency}") GateioTicker getTicker( @PathParam("ident") String tradeableIdentifier, @PathParam("currency") String currency) throws IOException; - @GET - @Path("api2/1/orderBook/{ident}_{currency}") - GateioDepth getFullDepth( - @PathParam("ident") String tradeableIdentifier, @PathParam("currency") String currency) - throws IOException; - @GET @Path("api2/1/tradeHistory/{ident}_{currency}") GateioTradeHistory getTradeHistory( @@ -72,14 +50,6 @@ GateioTradeHistory getTradeHistorySince( @PathParam("tradeId") String tradeId) throws IOException; - @GET - @Path("api2/1/candlestick2/{currency_pair}") - GateioCandlestickHistory getKlinesGate( - @PathParam("currency_pair") String tradePair, - @QueryParam("range_hour") Integer hours, - @QueryParam("group_sec") Long interval) - throws IOException; - @GET @Path("api/v4/spot/currencies") diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java index 08ced09495d..b18addfcef5 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java @@ -1,12 +1,7 @@ package org.knowm.xchange.gateio; -import static org.knowm.xchange.dto.Order.OrderType.ASK; -import static org.knowm.xchange.dto.Order.OrderType.BID; - import java.math.BigDecimal; import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; import java.util.Date; import java.util.List; import java.util.Locale; @@ -17,8 +12,6 @@ import org.knowm.xchange.dto.Order; import org.knowm.xchange.dto.Order.OrderStatus; import org.knowm.xchange.dto.Order.OrderType; -import org.knowm.xchange.dto.account.FundingRecord; -import org.knowm.xchange.dto.account.FundingRecord.Status; import org.knowm.xchange.dto.marketdata.OrderBook; import org.knowm.xchange.dto.marketdata.Ticker; import org.knowm.xchange.dto.marketdata.Trade; @@ -27,32 +20,23 @@ import org.knowm.xchange.dto.meta.InstrumentMetaData; import org.knowm.xchange.dto.trade.LimitOrder; import org.knowm.xchange.dto.trade.MarketOrder; -import org.knowm.xchange.dto.trade.OpenOrders; -import org.knowm.xchange.dto.trade.UserTrade; -import org.knowm.xchange.dto.trade.UserTrades; import org.knowm.xchange.gateio.dto.GateioOrderType; -import org.knowm.xchange.gateio.dto.account.GateioDepositsWithdrawals; import org.knowm.xchange.gateio.dto.account.GateioOrder; import org.knowm.xchange.gateio.dto.account.GateioWithdrawalRequest; import org.knowm.xchange.gateio.dto.marketdata.GateioCurrencyPairDetails; -import org.knowm.xchange.gateio.dto.marketdata.GateioDepth; import org.knowm.xchange.gateio.dto.marketdata.GateioOrderBook; import org.knowm.xchange.gateio.dto.marketdata.GateioPublicOrder; import org.knowm.xchange.gateio.dto.marketdata.GateioTicker; import org.knowm.xchange.gateio.dto.marketdata.GateioTradeHistory; -import org.knowm.xchange.gateio.dto.trade.GateioOpenOrder; -import org.knowm.xchange.gateio.dto.trade.GateioOpenOrders; -import org.knowm.xchange.gateio.dto.trade.GateioTrade; import org.knowm.xchange.gateio.service.params.DefaultGateioWithdrawFundsParams; import org.knowm.xchange.instrument.Instrument; import org.knowm.xchange.utils.DateUtils; @UtilityClass -public final class GateioAdapters { +public class GateioAdapters { public CurrencyPair adaptCurrencyPair(String pair) { - final String[] currencies = pair.toUpperCase().split("_"); return new CurrencyPair(currencies[0], currencies[1]); } @@ -105,12 +89,12 @@ public Ticker adaptTicker(CurrencyPair currencyPair, GateioTicker gateioTicker) public OrderBook toOrderBook(GateioOrderBook gateioOrderBook, Instrument instrument) { List asks = gateioOrderBook.getAsks().stream() - .map(priceSizeEntry -> new LimitOrder(ASK, priceSizeEntry.getSize(), instrument, null, null, priceSizeEntry.getPrice())) + .map(priceSizeEntry -> new LimitOrder(OrderType.ASK, priceSizeEntry.getSize(), instrument, null, null, priceSizeEntry.getPrice())) .collect(Collectors.toList()); List bids = gateioOrderBook.getBids().stream() - .map(priceSizeEntry -> new LimitOrder(BID, priceSizeEntry.getSize(), instrument, null, null, priceSizeEntry.getPrice())) + .map(priceSizeEntry -> new LimitOrder(OrderType.BID, priceSizeEntry.getSize(), instrument, null, null, priceSizeEntry.getPrice())) .collect(Collectors.toList()); return new OrderBook(Date.from(gateioOrderBook.getGeneratedAt()), asks, bids); @@ -135,45 +119,8 @@ public List adaptOrders( return limitOrders; } - public OrderBook adaptOrderBook(GateioDepth depth, CurrencyPair currencyPair) { - - List asks = - GateioAdapters.adaptOrders(depth.getAsks(), currencyPair, ASK); - Collections.reverse(asks); - List bids = - GateioAdapters.adaptOrders(depth.getBids(), currencyPair, BID); - - return new OrderBook(null, asks, bids); - } - - public LimitOrder adaptOrder( - GateioOpenOrder order, Collection currencyPairs) { - - String[] currencyPairSplit = order.getCurrencyPair().split("_"); - CurrencyPair currencyPair = new CurrencyPair(currencyPairSplit[0], currencyPairSplit[1]); - return new LimitOrder( - order.getType().equals("sell") ? ASK : BID, - order.getAmount(), - currencyPair, - order.getOrderNumber(), - null, - order.getRate()); - } - - public OpenOrders adaptOpenOrders( - GateioOpenOrders openOrders, Collection currencyPairs) { - - List adaptedOrders = new ArrayList<>(); - for (GateioOpenOrder openOrder : openOrders.getOrders()) { - adaptedOrders.add(adaptOrder(openOrder, currencyPairs)); - } - - return new OpenOrders(adaptedOrders); - } - public OrderType adaptOrderType(GateioOrderType cryptoTradeOrderType) { - - return (cryptoTradeOrderType.equals(GateioOrderType.BUY)) ? BID : ASK; + return (cryptoTradeOrderType.equals(GateioOrderType.BUY)) ? OrderType.BID : OrderType.ASK; } public Trade adaptTrade( @@ -223,89 +170,6 @@ public InstrumentMetaData toInstrumentMetaData(GateioCurrencyPairDetails gateioC } - public UserTrades adaptUserTrades(List userTrades) { - - List trades = new ArrayList<>(); - for (GateioTrade userTrade : userTrades) { - trades.add(adaptUserTrade(userTrade)); - } - - return new UserTrades(trades, TradeSortType.SortByTimestamp); - } - - public UserTrade adaptUserTrade(GateioTrade gateioTrade) { - - OrderType orderType = adaptOrderType(gateioTrade.getType()); - Date timestamp = DateUtils.fromMillisUtc(gateioTrade.getTimeUnix() * 1000); - CurrencyPair currencyPair = adaptCurrencyPair(gateioTrade.getPair()); - - return new UserTrade.Builder() - .type(orderType) - .originalAmount(gateioTrade.getAmount()) - .currencyPair(currencyPair) - .price(gateioTrade.getRate()) - .timestamp(timestamp) - .id(gateioTrade.getTradeID()) - .orderId(gateioTrade.getOrderNumber()) - .build(); - } - - public List adaptDepositsWithdrawals( - GateioDepositsWithdrawals depositsWithdrawals) { - List result = new ArrayList<>(); - - depositsWithdrawals - .getDeposits() - .forEach( - d -> { - FundingRecord r = - new FundingRecord( - d.address, - d.getTimestamp(), - Currency.getInstance(d.currency), - d.amount, - d.id, - d.txid, - FundingRecord.Type.DEPOSIT, - status(d.status), - null, - null, - null); - result.add(r); - }); - depositsWithdrawals - .getWithdraws() - .forEach( - w -> { - FundingRecord r = - new FundingRecord( - w.address, - w.getTimestamp(), - Currency.getInstance(w.currency), - w.amount, - w.id, - w.txid, - FundingRecord.Type.WITHDRAWAL, - status(w.status), - null, - null, - null); - result.add(r); - }); - - return result; - } - - private FundingRecord.Status status(String gateioStatus) { - switch (gateioStatus) { - case "DONE": - return Status.COMPLETE; - default: - return Status.PROCESSING; // @TODO which statusses are possible at gate.io? - } - } - - public String toString(OrderStatus orderStatus) { switch (orderStatus) { case OPEN: @@ -392,9 +256,9 @@ public String toString(OrderType orderType) { public OrderType toOrderType(String gateioOrderType) { switch (gateioOrderType) { case "buy": - return BID; + return OrderType.BID; case "sell": - return ASK; + return OrderType.ASK; default: throw new IllegalArgumentException("Can't map " + gateioOrderType); } diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAuthenticated.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAuthenticated.java deleted file mode 100644 index f4e7d4652a1..00000000000 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAuthenticated.java +++ /dev/null @@ -1,118 +0,0 @@ -package org.knowm.xchange.gateio; - -import java.io.IOException; -import java.math.BigDecimal; -import java.util.Map; -import javax.ws.rs.Consumes; -import javax.ws.rs.FormParam; -import javax.ws.rs.HeaderParam; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; -import org.knowm.xchange.gateio.dto.GateioBaseResponse; -import org.knowm.xchange.gateio.dto.account.GateioDepositsWithdrawals; -import org.knowm.xchange.gateio.dto.account.GateioFunds; -import org.knowm.xchange.gateio.dto.marketdata.GateioFeeInfo; -import org.knowm.xchange.gateio.dto.trade.GateioOpenOrders; -import org.knowm.xchange.gateio.dto.trade.GateioOrderStatus; -import org.knowm.xchange.gateio.dto.trade.GateioPlaceOrderReturn; -import org.knowm.xchange.gateio.dto.trade.GateioTradeHistoryReturn; -import si.mazi.rescu.ParamsDigest; - -@Path("api2/1") -@Consumes(MediaType.APPLICATION_FORM_URLENCODED) -@Produces(MediaType.APPLICATION_JSON) -public interface GateioAuthenticated { - - @POST - @Path("private/balances") - GateioFunds getFunds(@HeaderParam("KEY") String apiKey, @HeaderParam("SIGN") ParamsDigest signer) - throws IOException; - - @POST - @Path("private/withdraw") - GateioBaseResponse withdraw( - @HeaderParam("KEY") String apiKey, - @HeaderParam("SIGN") ParamsDigest signer, - @FormParam("currency") String currency, - @FormParam("amount") BigDecimal amount, - @FormParam("address") String address) - throws IOException; - - @POST - @Path("private/cancelorder") - GateioBaseResponse cancelOrder( - @FormParam("orderNumber") String orderNumber, - @FormParam("currencyPair") String currencyPair, - @HeaderParam("KEY") String apiKey, - @HeaderParam("SIGN") ParamsDigest signer) - throws IOException; - - @POST - @Path("private/cancelAllOrders") - GateioBaseResponse cancelAllOrders( - @FormParam("type") String type, - @FormParam("currencyPair") String currencyPair, - @HeaderParam("KEY") String apiKey, - @HeaderParam("SIGN") ParamsDigest signer) - throws IOException; - - @POST - @Path("private/buy") - GateioPlaceOrderReturn buy( - @FormParam("currencyPair") String currencyPair, - @FormParam("rate") BigDecimal rate, - @FormParam("amount") BigDecimal amount, - @HeaderParam("KEY") String apiKey, - @HeaderParam("SIGN") ParamsDigest signer) - throws IOException; - - @POST - @Path("private/sell") - GateioPlaceOrderReturn sell( - @FormParam("currencyPair") String currencyPair, - @FormParam("rate") BigDecimal rate, - @FormParam("amount") BigDecimal amount, - @HeaderParam("KEY") String apiKey, - @HeaderParam("SIGN") ParamsDigest signer) - throws IOException; - - @POST - @Path("private/openOrders") - GateioOpenOrders getOpenOrders( - @HeaderParam("KEY") String apiKey, @HeaderParam("SIGN") ParamsDigest signer) - throws IOException; - - @POST - @Path("private/tradeHistory") - GateioTradeHistoryReturn getUserTradeHistory( - @HeaderParam("KEY") String apiKey, - @HeaderParam("SIGN") ParamsDigest signer, - @FormParam("currencyPair") String currencyPair) - throws IOException; - - @POST - @Path("private/depositsWithdrawals") - GateioDepositsWithdrawals getDepositsWithdrawals( - @HeaderParam("KEY") String apiKey, - @HeaderParam("SIGN") ParamsDigest signer, - @FormParam("start") Long startUnixTime, - @FormParam("end") Long endUnixTime) - throws IOException; - - @POST - @Path("private/getorder") - GateioOrderStatus getOrderStatus( - @FormParam("orderNumber") String orderNumber, - @FormParam("currencyPair") String currencyPair, - @HeaderParam("KEY") String apiKey, - @HeaderParam("SIGN") ParamsDigest signer) - throws IOException; - - @POST - @Path("private/feelist") - Map getFeeList( - @HeaderParam("KEY") String apiKey, @HeaderParam("SIGN") ParamsDigest signer) - throws IOException; -} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/GateioJacksonObjectMapperFactory.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/GateioJacksonObjectMapperFactory.java index a3d257939d9..c1ade2df5e1 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/GateioJacksonObjectMapperFactory.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/GateioJacksonObjectMapperFactory.java @@ -10,7 +10,10 @@ public class GateioJacksonObjectMapperFactory extends DefaultJacksonObjectMapper @Override public void configureObjectMapper(ObjectMapper objectMapper) { super.configureObjectMapper(objectMapper); + + // by default read timetamps as milliseconds objectMapper.configure(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS, false); + // enable parsing to Instant objectMapper.registerModule(new JavaTimeModule()); } diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/StringToBooleanConverter.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/StringToBooleanConverter.java index 42a5b922cc7..d70d69376b8 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/StringToBooleanConverter.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/StringToBooleanConverter.java @@ -2,6 +2,9 @@ import com.fasterxml.jackson.databind.util.StdConverter; +/** + * Converts string value "1" to {@code true}, rest to {@code false} + */ public class StringToBooleanConverter extends StdConverter { @Override diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/TimestampSecondsToInstantConverter.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/TimestampSecondsToInstantConverter.java index 58c57486394..dcfe7c020c7 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/TimestampSecondsToInstantConverter.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/TimestampSecondsToInstantConverter.java @@ -3,6 +3,9 @@ import com.fasterxml.jackson.databind.util.StdConverter; import java.time.Instant; +/** + * Converts timestamp in seconds to {@code Instant} + */ public class TimestampSecondsToInstantConverter extends StdConverter { @Override diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioDeposit.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioDeposit.java deleted file mode 100644 index a8d78fcf509..00000000000 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioDeposit.java +++ /dev/null @@ -1,56 +0,0 @@ -package org.knowm.xchange.gateio.dto.account; - -import com.fasterxml.jackson.annotation.JsonProperty; -import java.math.BigDecimal; -import java.util.Date; - -public class GateioDeposit { - - public final String id; - public final String currency; - public final String address; - public final BigDecimal amount; - public final String txid; - public final long timestamp; - public final String status; - - public GateioDeposit( - @JsonProperty("id") String id, - @JsonProperty("currency") String currency, - @JsonProperty("address") String address, - @JsonProperty("amount") BigDecimal amount, - @JsonProperty("txid") String txid, - @JsonProperty("timestamp") long timestamp, - @JsonProperty("status") String status) { - this.id = id; - this.currency = currency; - this.address = address; - this.amount = amount; - this.txid = txid; - this.timestamp = timestamp; - this.status = status; - } - - public Date getTimestamp() { - return new Date(timestamp * 1000); - } - - @Override - public String toString() { - return "GateioDeposit [id=" - + id - + ", currency=" - + currency - + ", address=" - + address - + ", amount=" - + amount - + ", txid=" - + txid - + ", status=" - + status - + ", getTimestamp()=" - + getTimestamp() - + "]"; - } -} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioDepositsWithdrawals.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioDepositsWithdrawals.java deleted file mode 100644 index 474999a7b89..00000000000 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioDepositsWithdrawals.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.knowm.xchange.gateio.dto.account; - -import com.fasterxml.jackson.annotation.JsonProperty; -import java.util.List; -import org.knowm.xchange.gateio.dto.GateioBaseResponse; - -public class GateioDepositsWithdrawals extends GateioBaseResponse { - - private final List deposits; - private final List withdraws; - - public GateioDepositsWithdrawals( - @JsonProperty("result") boolean result, - @JsonProperty("deposits") List deposits, - @JsonProperty("withdraws") List withdraws, - @JsonProperty("message") final String message) { - super(result, message); - this.deposits = deposits; - this.withdraws = withdraws; - } - - public List getDeposits() { - return deposits; - } - - public List getWithdraws() { - return withdraws; - } - - @Override - public String toString() { - return "GateioDepositsWithdrawals [deposits=" + deposits + ", withdraws=" + withdraws + "]"; - } -} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioFunds.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioFunds.java deleted file mode 100644 index 898d9131e37..00000000000 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioFunds.java +++ /dev/null @@ -1,47 +0,0 @@ -package org.knowm.xchange.gateio.dto.account; - -import com.fasterxml.jackson.annotation.JsonProperty; -import java.math.BigDecimal; -import java.util.HashMap; -import java.util.Map; -import org.knowm.xchange.gateio.dto.GateioBaseResponse; - -public class GateioFunds extends GateioBaseResponse { - - private final Map available; - private final Map locked; - - /** - * Constructor - * - * @param theAvailable - * @param theLocked - */ - public GateioFunds( - @JsonProperty("available") Map theAvailable, - @JsonProperty("locked") Map theLocked, - @JsonProperty("result") boolean result, - @JsonProperty("message") final String message) { - - super(result, message); - - available = theAvailable == null ? new HashMap() : theAvailable; - locked = theLocked == null ? new HashMap() : theLocked; - } - - public Map getAvailableFunds() { - - return available; - } - - public Map getLockedFunds() { - - return locked; - } - - @Override - public String toString() { - - return "BTERAccountInfoReturn [availableFunds=" + available + ", lockedFunds=" + locked + "]"; - } -} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioWithdrawal.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioWithdrawal.java deleted file mode 100644 index ae3002a0c5d..00000000000 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioWithdrawal.java +++ /dev/null @@ -1,56 +0,0 @@ -package org.knowm.xchange.gateio.dto.account; - -import com.fasterxml.jackson.annotation.JsonProperty; -import java.math.BigDecimal; -import java.util.Date; - -public class GateioWithdrawal { - - public final String id; - public final String currency; - public final String address; - public final BigDecimal amount; - public final String txid; - public final long timestamp; - public final String status; - - public GateioWithdrawal( - @JsonProperty("id") String id, - @JsonProperty("currency") String currency, - @JsonProperty("address") String address, - @JsonProperty("amount") BigDecimal amount, - @JsonProperty("txid") String txid, - @JsonProperty("timestamp") long timestamp, - @JsonProperty("status") String status) { - this.id = id; - this.currency = currency; - this.address = address; - this.amount = amount; - this.txid = txid; - this.timestamp = timestamp; - this.status = status; - } - - public Date getTimestamp() { - return new Date(timestamp * 1000); - } - - @Override - public String toString() { - return "GateioDeposit [id=" - + id - + ", currency=" - + currency - + ", address=" - + address - + ", amount=" - + amount - + ", txid=" - + txid - + ", status=" - + status - + ", getTimestamp()=" - + getTimestamp() - + "]"; - } -} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioCandlestickHistory.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioCandlestickHistory.java deleted file mode 100644 index 5635fa5aee1..00000000000 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioCandlestickHistory.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.knowm.xchange.gateio.dto.marketdata; - -import com.fasterxml.jackson.annotation.JsonProperty; -import java.util.List; -import org.knowm.xchange.gateio.dto.GateioBaseResponse; - -public class GateioCandlestickHistory extends GateioBaseResponse { - - private final List> candlesticks; - private final String elapsed; - - private GateioCandlestickHistory( - @JsonProperty("data") List> candlesticks, - @JsonProperty("result") boolean result, - @JsonProperty("elapsed") String elapsed) { - - super(result, null); - this.candlesticks = candlesticks; - this.elapsed = elapsed; - } - - public List> getCandlesticks() { - return candlesticks; - } - - public String getElapsed() { - return elapsed; - } - - @Override - public String toString() { - return "BTERPublicTrades [candlesticks=" + candlesticks + ", elapsed=" + elapsed + "]"; - } -} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioCoin.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioCoin.java deleted file mode 100644 index ee118643156..00000000000 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioCoin.java +++ /dev/null @@ -1,59 +0,0 @@ -package org.knowm.xchange.gateio.dto.marketdata; - -public class GateioCoin { - - boolean delisted; - boolean withdrawDisabled; - boolean withdrawDelayed; - boolean depositDisabled; - boolean tradeDisabled; - - public GateioCoin( - boolean delisted, - boolean withdrawDisabled, - boolean withdrawDelayed, - boolean depositDisabled, - boolean tradeDisabled) { - this.delisted = delisted; - this.withdrawDisabled = withdrawDisabled; - this.withdrawDelayed = withdrawDelayed; - this.depositDisabled = depositDisabled; - this.tradeDisabled = tradeDisabled; - } - - @Override - public String toString() { - return "GateioCoin{" - + "delisted=" - + delisted - + ", withdrawDisabled=" - + withdrawDisabled - + ", withdrawDelayed=" - + withdrawDelayed - + ", depositDisabled=" - + depositDisabled - + ", tradeDisabled=" - + tradeDisabled - + '}'; - } - - public boolean isDelisted() { - return delisted; - } - - public boolean isWithdrawDisabled() { - return withdrawDisabled; - } - - public boolean isWithdrawDelayed() { - return withdrawDelayed; - } - - public boolean isDepositDisabled() { - return depositDisabled; - } - - public boolean isTradeDisabled() { - return tradeDisabled; - } -} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioCoinInfoWrapper.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioCoinInfoWrapper.java deleted file mode 100644 index 3545545e27a..00000000000 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioCoinInfoWrapper.java +++ /dev/null @@ -1,80 +0,0 @@ -package org.knowm.xchange.gateio.dto.marketdata; - -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.ObjectCodec; -import com.fasterxml.jackson.databind.DeserializationContext; -import com.fasterxml.jackson.databind.JsonDeserializer; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import java.io.IOException; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; -import org.knowm.xchange.exceptions.ExchangeException; - -@JsonDeserialize(using = GateioCoinInfoWrapper.BTERGateioCoinInfoDeserializer.class) -public class GateioCoinInfoWrapper { - - private final Map coins; - - public GateioCoinInfoWrapper(Map coins) { - this.coins = coins; - } - - public Map getCoins() { - return coins; - } - - @Override - public String toString() { - return "GateioCoinInfo{" + "coins=" + coins + '}'; - } - - static class BTERGateioCoinInfoDeserializer extends JsonDeserializer { - - private static final String DELISTED = "delisted"; - private static final String WITHDRAW_DISABLED = "withdraw_disabled"; - private static final String WITHDRAW_DELAYED = "withdraw_delayed"; - private static final String DEPOSIT_DISABLED = "deposit_disabled"; - private static final String TRADE_DISABLED = "trade_disabled"; - - @Override - public GateioCoinInfoWrapper deserialize(JsonParser jp, DeserializationContext ctxt) - throws IOException { - - Map gateioCoinInfoMap = new HashMap<>(); - - ObjectCodec oc = jp.getCodec(); - JsonNode coinsNodeWrapper = oc.readTree(jp); - JsonNode marketNodeList = coinsNodeWrapper.path("coins"); - - if (marketNodeList.isArray()) { - for (JsonNode marketNode : marketNodeList) { - Iterator> iter = marketNode.fields(); - if (iter.hasNext()) { - Map.Entry entry = iter.next(); - String coin = entry.getKey(); - JsonNode marketInfoData = entry.getValue(); - boolean delisted = marketInfoData.path(DELISTED).asInt() == 1; - boolean withdrawDisabled = marketInfoData.path(WITHDRAW_DISABLED).asInt() == 1; - boolean withdrawDelayed = marketInfoData.path(WITHDRAW_DELAYED).asInt() == 1; - boolean depositDisabled = marketInfoData.path(DEPOSIT_DISABLED).asInt() == 1; - boolean tradeDisabled = marketInfoData.path(TRADE_DISABLED).asInt() == 1; - GateioCoin gateioCoin = - new GateioCoin( - delisted, withdrawDisabled, withdrawDelayed, depositDisabled, tradeDisabled); - gateioCoinInfoMap.put(coin, gateioCoin); - } else { - throw new ExchangeException( - "Invalid coin info response received from Gateio." + coinsNodeWrapper); - } - } - } else { - throw new ExchangeException( - "Invalid coin info response received from Gateio." + coinsNodeWrapper); - } - - return new GateioCoinInfoWrapper(gateioCoinInfoMap); - } - } -} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioCurrencyPairs.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioCurrencyPairs.java deleted file mode 100644 index ad90dfc8789..00000000000 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioCurrencyPairs.java +++ /dev/null @@ -1,55 +0,0 @@ -package org.knowm.xchange.gateio.dto.marketdata; - -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.ObjectCodec; -import com.fasterxml.jackson.databind.DeserializationContext; -import com.fasterxml.jackson.databind.JsonDeserializer; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import java.io.IOException; -import java.util.Collection; -import java.util.HashSet; -import java.util.Set; -import org.knowm.xchange.gateio.GateioAdapters; -import org.knowm.xchange.gateio.dto.marketdata.GateioCurrencyPairs.BTERCurrencyPairsDeserializer; -import org.knowm.xchange.instrument.Instrument; - -@JsonDeserialize(using = BTERCurrencyPairsDeserializer.class) -public class GateioCurrencyPairs { - - private final Set pairs; - - private GateioCurrencyPairs(Set pairs) { - - this.pairs = pairs; - } - - public Collection getPairs() { - - return pairs; - } - - @Override - public String toString() { - - return "GateioCurrencyPairs [pairs=" + pairs + "]"; - } - - static class BTERCurrencyPairsDeserializer extends JsonDeserializer { - - @Override - public GateioCurrencyPairs deserialize(JsonParser jp, DeserializationContext ctxt) - throws IOException { - - final Set pairs = new HashSet<>(); - final ObjectCodec oc = jp.getCodec(); - final JsonNode node = oc.readTree(jp); - if (node.isArray()) { - for (JsonNode pairNode : node) { - pairs.add(GateioAdapters.adaptCurrencyPair(pairNode.asText())); - } - } - return new GateioCurrencyPairs(pairs); - } - } -} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountService.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountService.java index 7ff487415a0..145a341a9cc 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountService.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountService.java @@ -1,28 +1,22 @@ package org.knowm.xchange.gateio.service; import java.io.IOException; -import java.util.Date; import java.util.List; import java.util.stream.Collectors; import org.apache.commons.lang3.Validate; import org.knowm.xchange.currency.Currency; import org.knowm.xchange.dto.account.AccountInfo; import org.knowm.xchange.dto.account.Balance; -import org.knowm.xchange.dto.account.FundingRecord; import org.knowm.xchange.dto.account.Wallet; -import org.knowm.xchange.exceptions.NotAvailableFromExchangeException; import org.knowm.xchange.gateio.GateioAdapters; import org.knowm.xchange.gateio.GateioErrorAdapter; import org.knowm.xchange.gateio.GateioExchange; import org.knowm.xchange.gateio.dto.GateioException; import org.knowm.xchange.gateio.dto.account.GateioCurrencyBalance; -import org.knowm.xchange.gateio.dto.account.GateioDepositsWithdrawals; import org.knowm.xchange.gateio.dto.account.GateioWithdrawalRecord; import org.knowm.xchange.gateio.dto.account.GateioWithdrawalRequest; import org.knowm.xchange.gateio.service.params.DefaultGateioWithdrawFundsParams; import org.knowm.xchange.service.account.AccountService; -import org.knowm.xchange.service.trade.params.TradeHistoryParams; -import org.knowm.xchange.service.trade.params.TradeHistoryParamsTimeSpan; import org.knowm.xchange.service.trade.params.WithdrawFundsParams; public class GateioAccountService extends GateioAccountServiceRaw implements AccountService { @@ -57,8 +51,6 @@ public AccountInfo getAccountInfo() throws IOException { catch (GateioException e) { throw GateioErrorAdapter.adapt(e); } - - } @@ -79,21 +71,4 @@ public String withdrawFunds(WithdrawFundsParams params) throws IOException { } - @Override - public TradeHistoryParams createFundingHistoryParams() { - throw new NotAvailableFromExchangeException(); - } - - @Override - public List getFundingHistory(TradeHistoryParams params) throws IOException { - Date start = null; - Date end = null; - if (params instanceof TradeHistoryParamsTimeSpan) { - TradeHistoryParamsTimeSpan timeSpan = (TradeHistoryParamsTimeSpan) params; - start = timeSpan.getStartTime(); - end = timeSpan.getEndTime(); - } - GateioDepositsWithdrawals depositsWithdrawals = getDepositsWithdrawals(start, end); - return GateioAdapters.adaptDepositsWithdrawals(depositsWithdrawals); - } } diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountServiceRaw.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountServiceRaw.java index 6a7d40cb233..bc7e7e5e364 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountServiceRaw.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountServiceRaw.java @@ -1,72 +1,25 @@ package org.knowm.xchange.gateio.service; import java.io.IOException; -import java.math.BigDecimal; -import java.util.Date; import java.util.List; import org.apache.commons.lang3.Validate; import org.knowm.xchange.currency.Currency; -import org.knowm.xchange.exceptions.ExchangeException; import org.knowm.xchange.gateio.GateioErrorAdapter; import org.knowm.xchange.gateio.GateioExchange; -import org.knowm.xchange.gateio.dto.GateioBaseResponse; import org.knowm.xchange.gateio.dto.GateioException; import org.knowm.xchange.gateio.dto.account.GateioAddressRecord; import org.knowm.xchange.gateio.dto.account.GateioCurrencyBalance; import org.knowm.xchange.gateio.dto.account.GateioDepositAddress; -import org.knowm.xchange.gateio.dto.account.GateioDepositsWithdrawals; import org.knowm.xchange.gateio.dto.account.GateioWithdrawStatus; import org.knowm.xchange.gateio.dto.account.GateioWithdrawalRecord; import org.knowm.xchange.gateio.dto.account.GateioWithdrawalRequest; public class GateioAccountServiceRaw extends GateioBaseService { - /** - * Constructor - * - * @param exchange - */ public GateioAccountServiceRaw(GateioExchange exchange) { - super(exchange); } - public String withdraw( - Currency currency, BigDecimal amount, String baseAddress, String addressTag) - throws IOException { - String withdrawAddress = baseAddress; - if (addressTag != null && addressTag.length() > 0) { - withdrawAddress = withdrawAddress + " " + addressTag; - } - return withdraw(currency.getCurrencyCode(), amount, withdrawAddress); - } - - public GateioDepositsWithdrawals getDepositsWithdrawals(Date start, Date end) throws IOException { - GateioDepositsWithdrawals gateioDepositsWithdrawals = - gateioAuthenticated.getDepositsWithdrawals( - exchange.getExchangeSpecification().getApiKey(), - signatureCreator, - start == null ? null : start.getTime() / 1000, - end == null ? null : end.getTime() / 1000); - return handleResponse(gateioDepositsWithdrawals); - } - - public String withdraw(String currency, BigDecimal amount, String address) throws IOException { - GateioBaseResponse withdraw = - gateioAuthenticated.withdraw( - exchange.getExchangeSpecification().getApiKey(), - signatureCreator, - currency, - amount, - address); - if (!withdraw.isResult()) { - throw new ExchangeException(withdraw.getMessage()); - } - // unfortunatelly gate.io does not return any id for the withdrawal - return null; - } - - public GateioDepositAddress getDepositAddress(Currency currency) throws IOException { String currencyCode = currency == null ? null : currency.getCurrencyCode(); @@ -94,10 +47,8 @@ public List getWithdrawStatus(Currency currency) throws IO public List getSpotBalances(Currency currency) throws IOException { - String currencyCode = currency == null ? null : currency.getCurrencyCode(); return gateioV4Authenticated.getSpotAccounts(apiKey, exchange.getNonceFactory(), gateioV4ParamsDigest, currencyCode); - } diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioBaseService.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioBaseService.java index 9ec74fbc25b..bb6d6db2f4f 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioBaseService.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioBaseService.java @@ -3,7 +3,6 @@ import org.knowm.xchange.client.ExchangeRestProxyBuilder; import org.knowm.xchange.exceptions.ExchangeException; import org.knowm.xchange.gateio.Gateio; -import org.knowm.xchange.gateio.GateioAuthenticated; import org.knowm.xchange.gateio.GateioExchange; import org.knowm.xchange.gateio.GateioV4Authenticated; import org.knowm.xchange.gateio.config.GateioJacksonObjectMapperFactory; @@ -16,31 +15,18 @@ public class GateioBaseService extends BaseExchangeService imple protected final String apiKey; protected final Gateio gateio; - protected final GateioAuthenticated gateioAuthenticated; protected final GateioV4Authenticated gateioV4Authenticated; - protected final ParamsDigest signatureCreator; protected final ParamsDigest gateioV4ParamsDigest; - /** - * Constructor - * - * @param exchange - */ - public GateioBaseService(GateioExchange exchange) { + public GateioBaseService(GateioExchange exchange) { super(exchange); gateio = ExchangeRestProxyBuilder .forInterface(Gateio.class, exchange.getExchangeSpecification()) .clientConfigCustomizer(clientConfig -> clientConfig.setJacksonObjectMapperFactory(new GateioJacksonObjectMapperFactory())) .build(); - gateioAuthenticated = ExchangeRestProxyBuilder - .forInterface(GateioAuthenticated.class, exchange.getExchangeSpecification()) - .clientConfigCustomizer(clientConfig -> clientConfig.setJacksonObjectMapperFactory(new GateioJacksonObjectMapperFactory())) - .build(); apiKey = exchange.getExchangeSpecification().getApiKey(); - signatureCreator = - GateioHmacPostBodyDigest.createInstance(exchange.getExchangeSpecification().getSecretKey()); gateioV4Authenticated = ExchangeRestProxyBuilder .forInterface(GateioV4Authenticated.class, exchange.getExchangeSpecification()) @@ -60,7 +46,4 @@ protected R handleResponse(R response) { return response; } - public String getApiKey() { - return apiKey; - } } diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioHmacPostBodyDigest.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioHmacPostBodyDigest.java deleted file mode 100644 index 12751003d2d..00000000000 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioHmacPostBodyDigest.java +++ /dev/null @@ -1,60 +0,0 @@ -package org.knowm.xchange.gateio.service; - -import java.io.UnsupportedEncodingException; -import java.math.BigInteger; -import javax.crypto.Mac; -import org.knowm.xchange.service.BaseParamsDigest; -import si.mazi.rescu.RestInvocation; - -/** - * This may be used as the value of a @HeaderParam, @QueryParam or @PathParam to create a digest of - * the post body (composed of @FormParam's). Don't use as the value of a @FormParam, it will - * probably cause an infinite loop. - * - *

This may be used for REST APIs where some parameters' values must be digests of other - * parameters. An example is the MtGox API v1, where the Rest-Sign header parameter must be a digest - * of the request body (which is composed of @FormParams). - */ -public class GateioHmacPostBodyDigest extends BaseParamsDigest { - - /** - * Constructor - * - * @param secretKeyBase64 - * @throws IllegalArgumentException if key is invalid (cannot be base-64-decoded or the decoded - * key is invalid). - */ - private GateioHmacPostBodyDigest(String secretKeyBase64) { - - super(secretKeyBase64, HMAC_SHA_512); - } - - public static GateioHmacPostBodyDigest createInstance(String secretKeyBase64) { - - return secretKeyBase64 == null ? null : new GateioHmacPostBodyDigest(secretKeyBase64); - } - - @Override - public String digestParams(RestInvocation restInvocation) { - - try { - String postBody = restInvocation.getRequestBody(); - - // little hack here. the post body to create the signature mus not contain the url-encoded - // parameters, they must be in plain form - // passing ie the white space inside the withdraw method (required for XLM and XRP ... to pass - // the tag) results in a plus sing '+', which is the correct encoding, but in this case the - // signature is not created correctly. - // the expected signature must be created using plain parameters. here we simply replace the + - // by a white space, should be fine for now - // see https://support.gate.io/hc/en-us/articles/360000808354-How-to-Withdraw-XRP - postBody = postBody.replace('+', ' '); - Mac mac = getMac(); - mac.update(postBody.getBytes("UTF-8")); - return String.format("%0128x", new BigInteger(1, mac.doFinal())); - } catch (UnsupportedEncodingException e) { - throw new RuntimeException("Illegal encoding, check the code.", e); - } - // return Base64.encodeBytes(mac.doFinal()).trim(); - } -} 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 39ad4c22a97..bc477a467e0 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 @@ -2,7 +2,6 @@ import java.io.IOException; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -16,7 +15,6 @@ import org.knowm.xchange.gateio.GateioExchange; import org.knowm.xchange.gateio.dto.GateioException; import org.knowm.xchange.gateio.dto.marketdata.GateioCurrencyPairDetails; -import org.knowm.xchange.gateio.dto.marketdata.GateioDepth; import org.knowm.xchange.gateio.dto.marketdata.GateioOrderBook; import org.knowm.xchange.gateio.dto.marketdata.GateioTicker; import org.knowm.xchange.gateio.dto.marketdata.GateioTradeHistory; @@ -74,20 +72,6 @@ public OrderBook getOrderBook(Instrument instrument, Object... args) throws IOEx } - public Map getOrderBooks() throws IOException { - - Map gateioDepths = super.getGateioDepths(); - Map orderBooks = new HashMap<>(gateioDepths.size()); - - gateioDepths.forEach( - (currencyPair, gateioDepth) -> { - OrderBook orderBook = GateioAdapters.adaptOrderBook(gateioDepth, currencyPair); - orderBooks.put(currencyPair, orderBook); - }); - - return orderBooks; - } - @Override public Trades getTrades(CurrencyPair currencyPair, Object... args) throws IOException { 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 c2aa789e6fe..ca431fc4d43 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 @@ -1,27 +1,17 @@ package org.knowm.xchange.gateio.service; import java.io.IOException; -import java.math.BigDecimal; -import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.stream.Collectors; import org.knowm.xchange.currency.Currency; import org.knowm.xchange.currency.CurrencyPair; import org.knowm.xchange.dto.marketdata.Ticker; -import org.knowm.xchange.exceptions.ExchangeException; import org.knowm.xchange.gateio.GateioAdapters; import org.knowm.xchange.gateio.GateioExchange; -import org.knowm.xchange.gateio.dto.marketdata.GateioCandlestickHistory; -import org.knowm.xchange.gateio.dto.marketdata.GateioCoinInfoWrapper; 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.GateioDepth; -import org.knowm.xchange.gateio.dto.marketdata.GateioFeeInfo; -import org.knowm.xchange.gateio.dto.marketdata.GateioKline; -import org.knowm.xchange.gateio.dto.marketdata.GateioKlineInterval; import org.knowm.xchange.gateio.dto.marketdata.GateioMarketInfoWrapper; import org.knowm.xchange.gateio.dto.marketdata.GateioOrderBook; import org.knowm.xchange.gateio.dto.marketdata.GateioTicker; @@ -48,14 +38,6 @@ public Map getMarketInfo return bterMarketInfo.getMarketInfoMap(); } - public GateioCoinInfoWrapper getGateioCoinInfo() throws IOException { - return gateio.getCoinInfo(); - } - - public Map getGateioFees() throws IOException { - return gateioAuthenticated.getFeeList(apiKey, signatureCreator); - } - public Map getGateioTickers() throws IOException { Map gateioTickers = gateio.getTickers(); @@ -73,21 +55,6 @@ public Map getGateioTickers() throws IOException { return adaptedTickers; } - public Map getGateioDepths() throws IOException { - Map depths = gateio.getDepths(); - Map adaptedDepths = new HashMap<>(depths.size()); - depths.forEach( - (currencyPairString, gateioDepth) -> { - String[] currencyPairStringSplit = currencyPairString.split("_"); - CurrencyPair currencyPair = - new CurrencyPair( - Currency.getInstance(currencyPairStringSplit[0].toUpperCase()), - Currency.getInstance(currencyPairStringSplit[1].toUpperCase())); - adaptedDepths.put(currencyPair, gateioDepth); - }); - return adaptedDepths; - } - public GateioTicker getBTERTicker(String tradableIdentifier, String currency) throws IOException { GateioTicker gateioTicker = @@ -96,15 +63,6 @@ public GateioTicker getBTERTicker(String tradableIdentifier, String currency) th return handleResponse(gateioTicker); } - public GateioDepth getBTEROrderBook(String tradeableIdentifier, String currency) - throws IOException { - - GateioDepth gateioDepth = - gateio.getFullDepth(tradeableIdentifier.toLowerCase(), currency.toLowerCase()); - - return handleResponse(gateioDepth); - } - public GateioTradeHistory getBTERTradeHistory(String tradeableIdentifier, String currency) throws IOException { @@ -122,35 +80,6 @@ public GateioTradeHistory getBTERTradeHistorySince( return handleResponse(tradeHistory); } - public List getExchangeSymbols() throws IOException { - - return new ArrayList<>(gateio.getPairs().getPairs()); - } - - public List getKlines(CurrencyPair pair, GateioKlineInterval interval, Integer hours) - throws IOException { - - if (hours != null && hours < 1) - throw new ExchangeException("Variable 'hours' should be more than 0!"); - - GateioCandlestickHistory candlestickHistory = - handleResponse( - gateio.getKlinesGate( - pair.toString().replace('/', '_').toLowerCase(), hours, interval.getSeconds())); - - return candlestickHistory.getCandlesticks().stream() - .map( - data -> - new GateioKline( - Long.parseLong(data.get(0)), - new BigDecimal(data.get(1)), - new BigDecimal(data.get(2)), - new BigDecimal(data.get(3)), - new BigDecimal(data.get(4)), - new BigDecimal(data.get(5)))) - .collect(Collectors.toList()); - } - public List getCurrencies() throws IOException { return gateio.getCurrencies(); diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeService.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeService.java index 0ac0565d0d3..469aa13093e 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeService.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeService.java @@ -4,57 +4,25 @@ import java.util.Collection; import java.util.List; import org.apache.commons.lang3.Validate; -import org.knowm.xchange.currency.CurrencyPair; import org.knowm.xchange.dto.Order; -import org.knowm.xchange.dto.trade.LimitOrder; import org.knowm.xchange.dto.trade.MarketOrder; -import org.knowm.xchange.dto.trade.OpenOrders; -import org.knowm.xchange.dto.trade.UserTrades; -import org.knowm.xchange.exceptions.ExchangeException; -import org.knowm.xchange.exceptions.NotAvailableFromExchangeException; import org.knowm.xchange.gateio.GateioAdapters; import org.knowm.xchange.gateio.GateioErrorAdapter; import org.knowm.xchange.gateio.GateioExchange; import org.knowm.xchange.gateio.dto.GateioException; import org.knowm.xchange.gateio.dto.account.GateioOrder; -import org.knowm.xchange.gateio.dto.trade.GateioOpenOrders; -import org.knowm.xchange.gateio.dto.trade.GateioTrade; -import org.knowm.xchange.instrument.Instrument; import org.knowm.xchange.service.trade.TradeService; -import org.knowm.xchange.service.trade.params.CancelOrderByCurrencyPair; -import org.knowm.xchange.service.trade.params.CancelOrderByIdParams; -import org.knowm.xchange.service.trade.params.CancelOrderParams; import org.knowm.xchange.service.trade.params.DefaultTradeHistoryParamCurrencyPair; import org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair; -import org.knowm.xchange.service.trade.params.TradeHistoryParams; -import org.knowm.xchange.service.trade.params.orders.OpenOrdersParams; import org.knowm.xchange.service.trade.params.orders.OrderQueryParamInstrument; import org.knowm.xchange.service.trade.params.orders.OrderQueryParams; public class GateioTradeService extends GateioTradeServiceRaw implements TradeService { - /** - * Constructor - * - * @param exchange - */ public GateioTradeService(GateioExchange exchange) { - super(exchange); } - @Override - public OpenOrders getOpenOrders() throws IOException { - return getOpenOrders(createOpenOrdersParams()); - } - - @Override - public OpenOrders getOpenOrders(OpenOrdersParams params) throws IOException { - GateioOpenOrders openOrders = super.getGateioOpenOrders(); - Collection currencyPairs = exchange.getExchangeInstruments(); - - return GateioAdapters.adaptOpenOrders(openOrders, currencyPairs); - } @Override public String placeMarketOrder(MarketOrder marketOrder) throws IOException { @@ -67,57 +35,6 @@ public String placeMarketOrder(MarketOrder marketOrder) throws IOException { } } - /** - * Submits a Limit Order to be executed on the Gateio Exchange for the desired market defined by - * {@code CurrencyPair}. WARNING - Gateio will return true regardless of whether or not an order - * actually gets created. The reason for this is that orders are simply submitted to a queue in - * their back-end. One example for why an order might not get created is because there are - * insufficient funds. The best attempt you can make to confirm that the order was created is to - * poll {@link #getOpenOrders}. However, if the order is created and executed before it is caught - * in its open state from calling {@link #getOpenOrders} then the only way to confirm would be - * confirm the expected difference in funds available for your account. - * - * @return String "true"/"false" Used to determine if the order request was submitted - * successfully. - */ - @Override - public String placeLimitOrder(LimitOrder limitOrder) throws IOException { - - return String.valueOf(super.placeGateioLimitOrder(limitOrder)); - } - - @Override - public boolean cancelOrder(String orderId) throws IOException { - throw new NotAvailableFromExchangeException(); - } - - @Override - public Class[] getRequiredCancelOrderParamClasses() { - return new Class[] {CancelOrderByIdParams.class, CancelOrderByCurrencyPair.class}; - } - - @Override - public boolean cancelOrder(CancelOrderParams orderParams) throws IOException { - if (orderParams instanceof CancelOrderByIdParams - && orderParams instanceof CancelOrderByCurrencyPair) { - return cancelOrder( - ((CancelOrderByIdParams) orderParams).getOrderId(), - ((CancelOrderByCurrencyPair) orderParams).getCurrencyPair()); - } else { - return false; - } - } - - /** Required parameter: {@link TradeHistoryParamCurrencyPair} */ - @Override - public UserTrades getTradeHistory(TradeHistoryParams params) - throws ExchangeException, IOException { - - CurrencyPair pair = ((TradeHistoryParamCurrencyPair) params).getCurrencyPair(); - List userTrades = getGateioTradeHistory(pair).getTrades(); - - return GateioAdapters.adaptUserTrades(userTrades); - } @Override public Collection getOrder(OrderQueryParams... orderQueryParams) throws IOException { @@ -138,12 +55,8 @@ public Collection getOrder(OrderQueryParams... orderQueryParams) throws I @Override public TradeHistoryParamCurrencyPair createTradeHistoryParams() { - return new DefaultTradeHistoryParamCurrencyPair(); } - @Override - public OpenOrdersParams createOpenOrdersParams() { - return null; - } + } diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeServiceRaw.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeServiceRaw.java index 06e16d28bb2..23d758c6317 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeServiceRaw.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeServiceRaw.java @@ -1,24 +1,13 @@ package org.knowm.xchange.gateio.service; import java.io.IOException; -import java.math.BigDecimal; import java.util.List; import java.util.Set; import org.apache.commons.lang3.Validate; -import org.knowm.xchange.currency.CurrencyPair; -import org.knowm.xchange.dto.Order; import org.knowm.xchange.dto.Order.OrderStatus; -import org.knowm.xchange.dto.trade.LimitOrder; import org.knowm.xchange.gateio.GateioAdapters; import org.knowm.xchange.gateio.GateioExchange; -import org.knowm.xchange.gateio.GateioUtils; -import org.knowm.xchange.gateio.dto.GateioBaseResponse; -import org.knowm.xchange.gateio.dto.GateioOrderType; import org.knowm.xchange.gateio.dto.account.GateioOrder; -import org.knowm.xchange.gateio.dto.trade.GateioOpenOrders; -import org.knowm.xchange.gateio.dto.trade.GateioOrderStatus; -import org.knowm.xchange.gateio.dto.trade.GateioPlaceOrderReturn; -import org.knowm.xchange.gateio.dto.trade.GateioTradeHistoryReturn; import org.knowm.xchange.instrument.Instrument; public class GateioTradeServiceRaw extends GateioBaseService { @@ -33,121 +22,6 @@ public GateioTradeServiceRaw(GateioExchange exchange) { super(exchange); } - /** - * Submits a Limit Order to be executed on the Gateio Exchange for the desired market defined by - * {@code CurrencyPair}. WARNING - Gateio will return true regardless of whether or not an order - * actually gets created. The reason for this is that orders are simply submitted to a queue in - * their back-end. One example for why an order might not get created is because there are - * insufficient funds. The best attempt you can make to confirm that the order was created is to - * poll {@link #getGateioOpenOrders}. However if the order is created and executed before it is - * caught in its open state from calling {@link #getGateioOpenOrders} then the only way to confirm - * would be confirm the expected difference in funds available for your account. - * - * @param limitOrder - * @return String order id of submitted request. - * @throws IOException - */ - public String placeGateioLimitOrder(LimitOrder limitOrder) throws IOException { - - GateioOrderType type = - (limitOrder.getType() == Order.OrderType.BID) ? GateioOrderType.BUY : GateioOrderType.SELL; - - return placeGateioLimitOrder( - limitOrder.getCurrencyPair(), - type, - limitOrder.getLimitPrice(), - limitOrder.getOriginalAmount()); - } - - /** - * Submits a Limit Order to be executed on the Gateio Exchange for the desired market defined by - * {@code currencyPair}. WARNING - Gateio will return true regardless of whether or not an order - * actually gets created. The reason for this is that orders are simply submitted to a queue in - * their back-end. One example for why an order might not get created is because there are - * insufficient funds. The best attempt you can make to confirm that the order was created is to - * poll {@link #getGateioOpenOrders}. However if the order is created and executed before it is - * caught in its open state from calling {@link #getGateioOpenOrders} then the only way to confirm - * would be confirm the expected difference in funds available for your account. - * - * @param currencyPair - * @param orderType - * @param rate - * @param amount - * @return String order id of submitted request. - * @throws IOException - */ - public String placeGateioLimitOrder( - CurrencyPair currencyPair, GateioOrderType orderType, BigDecimal rate, BigDecimal amount) - throws IOException { - - String pair = formatCurrencyPair(currencyPair); - - GateioPlaceOrderReturn orderId; - if (orderType.equals(GateioOrderType.BUY)) { - orderId = gateioAuthenticated.buy(pair, rate, amount, apiKey, signatureCreator); - } else { - orderId = gateioAuthenticated.sell(pair, rate, amount, apiKey, signatureCreator); - } - - return handleResponse(orderId).getOrderId(); - } - - public boolean cancelOrder(String orderId, CurrencyPair currencyPair) throws IOException { - - GateioBaseResponse cancelOrderResult = - gateioAuthenticated.cancelOrder(orderId, GateioUtils.toPairString(currencyPair), apiKey, signatureCreator); - - return handleResponse(cancelOrderResult).isResult(); - } - - /** - * Cancels all orders. See https://gate.io/api2. - * - * @param type order type(0:sell,1:buy,-1:all) - * @param currencyPair currency pair - * @return - * @throws IOException - */ - public boolean cancelAllOrders(String type, CurrencyPair currencyPair) throws IOException { - - GateioBaseResponse cancelAllOrdersResult = - gateioAuthenticated.cancelAllOrders(type, formatCurrencyPair(currencyPair), apiKey, signatureCreator); - - return handleResponse(cancelAllOrdersResult).isResult(); - } - - public GateioOpenOrders getGateioOpenOrders() throws IOException { - - GateioOpenOrders gateioOpenOrdersReturn = gateioAuthenticated.getOpenOrders(apiKey, signatureCreator); - - return handleResponse(gateioOpenOrdersReturn); - } - - public GateioOrderStatus getGateioOrderStatus(String orderId, CurrencyPair currencyPair) - throws IOException { - - GateioOrderStatus orderStatus = - gateioAuthenticated.getOrderStatus( - orderId, GateioUtils.toPairString(currencyPair), apiKey, signatureCreator); - - return handleResponse(orderStatus); - } - - public GateioTradeHistoryReturn getGateioTradeHistory(CurrencyPair currencyPair) - throws IOException { - - GateioTradeHistoryReturn gateioTradeHistoryReturn = - gateioAuthenticated.getUserTradeHistory(apiKey, signatureCreator, GateioUtils.toPairString(currencyPair)); - - return handleResponse(gateioTradeHistoryReturn); - } - - private String formatCurrencyPair(CurrencyPair currencyPair) { - return String.format( - "%s_%s", currencyPair.base.getCurrencyCode(), currencyPair.counter.getCurrencyCode()) - .toLowerCase(); - } - public List listOrders(Instrument instrument, OrderStatus orderStatus) throws IOException { // validate arguments diff --git a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/dto/marketdata/GateioCurrencyChainTest.java b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/dto/marketdata/GateioCurrencyChainTest.java new file mode 100644 index 00000000000..10e0f6506da --- /dev/null +++ b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/dto/marketdata/GateioCurrencyChainTest.java @@ -0,0 +1,28 @@ +package org.knowm.xchange.gateio.dto.marketdata; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.Test; + +class GateioCurrencyChainTest { + + @Test + void valid_isWithdrawEnabled() { + GateioCurrencyChain gateioCurrencyChain = GateioCurrencyChain.builder().build(); + assertThat(gateioCurrencyChain.isWithdrawEnabled()).isFalse(); + + gateioCurrencyChain.setDisabled(false); + gateioCurrencyChain.setWithdrawDisabled(false); + assertThat(gateioCurrencyChain.isWithdrawEnabled()).isTrue(); + } + + @Test + void valid_isDepositEnabled() { + GateioCurrencyChain gateioCurrencyChain = GateioCurrencyChain.builder().build(); + assertThat(gateioCurrencyChain.isDepositEnabled()).isFalse(); + + gateioCurrencyChain.setDisabled(false); + gateioCurrencyChain.setDepositDisabled(false); + assertThat(gateioCurrencyChain.isDepositEnabled()).isTrue(); + } +} \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioMarketDataServiceRawTest.java b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioMarketDataServiceRawTest.java index 56a352c1750..36a4e186e0b 100644 --- a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioMarketDataServiceRawTest.java +++ b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioMarketDataServiceRawTest.java @@ -98,23 +98,24 @@ public void getGateioOrderBook_valid() throws IOException { @Test public void getCurrencyChains_valid_result() throws IOException { - List expected = new ArrayList<>(); - expected.add(GateioCurrencyChain.builder() - .chain("BTC") - .chainNameCN("比特币 BRC20/Ordinals") - .chainNameEN("Bitcoin BRC20/Ordinals") - .disabled(false) - .depositDisabled(false) - .withdrawDisabled(false) - .build()); - expected.add(GateioCurrencyChain.builder() - .chain("HT") - .chainNameCN("Heco") - .chainNameEN("Heco") - .disabled(true) - .depositDisabled(true) - .withdrawDisabled(true) - .build()); + List expected = List.of( + GateioCurrencyChain.builder() + .chain("BTC") + .chainNameCN("比特币 BRC20/Ordinals") + .chainNameEN("Bitcoin BRC20/Ordinals") + .disabled(false) + .depositDisabled(false) + .withdrawDisabled(false) + .build(), + GateioCurrencyChain.builder() + .chain("HT") + .chainNameCN("Heco") + .chainNameEN("Heco") + .disabled(true) + .depositDisabled(true) + .withdrawDisabled(true) + .build() + ); List actual = gateioMarketDataServiceRaw.getCurrencyChains(Currency.BTC); From 0de634b55bcacd3fefa45a05702176cdaf81d0f1 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Fri, 9 Jun 2023 00:45:24 +0200 Subject: [PATCH 036/159] [gateio-v4] Code cleanup --- .../gateio/dto/marketdata/GateioDepth.java | 44 ---- .../gateio/dto/marketdata/GateioFeeInfo.java | 190 ------------------ .../gateio/dto/marketdata/GateioKline.java | 54 ----- .../dto/marketdata/GateioKlineInterval.java | 36 ---- .../marketdata/GateioCurrencyInfoTest.java | 27 +++ 5 files changed, 27 insertions(+), 324 deletions(-) delete mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioDepth.java delete mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioFeeInfo.java delete mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioKline.java delete mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioKlineInterval.java create mode 100644 xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/dto/marketdata/GateioCurrencyInfoTest.java diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioDepth.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioDepth.java deleted file mode 100644 index 61ca16c81d9..00000000000 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioDepth.java +++ /dev/null @@ -1,44 +0,0 @@ -package org.knowm.xchange.gateio.dto.marketdata; - -import com.fasterxml.jackson.annotation.JsonProperty; -import java.util.List; -import org.knowm.xchange.gateio.dto.GateioBaseResponse; - -/** Data object representing depth from Bter */ -public class GateioDepth extends GateioBaseResponse { - - private final List asks; - private final List bids; - - /** - * Constructor - * - * @param asks - * @param bids - */ - private GateioDepth( - @JsonProperty("asks") List asks, - @JsonProperty("bids") List bids, - @JsonProperty("result") boolean result) { - - super(result, null); - this.asks = asks; - this.bids = bids; - } - - public List getAsks() { - - return asks; - } - - public List getBids() { - - return bids; - } - - @Override - public String toString() { - - return "GateioDepth [asks=" + asks.toString() + ", bids=" + bids.toString() + "]"; - } -} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioFeeInfo.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioFeeInfo.java deleted file mode 100644 index f7c45f54857..00000000000 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioFeeInfo.java +++ /dev/null @@ -1,190 +0,0 @@ -package org.knowm.xchange.gateio.dto.marketdata; - -import com.fasterxml.jackson.annotation.JsonProperty; -import java.math.BigDecimal; - -public class GateioFeeInfo { - - private final int no; - private final String symbol; - private final String name; - private final String nameCn; - private final String feeUsdt; - private final String feeBtc; - private final String feeEth; - private final String deposit; - private final String withdrawPercent; - private final String withdrawFix; - private final String withdrawDayLimit; - private final BigDecimal withdrawAmountMini; - private final BigDecimal withdrawDayLimitRemain; - private final BigDecimal withdrawEachTimeLimit; - private final BigDecimal withdrawFixOnChainEth; - private final BigDecimal withdrawFixOnChainBtc; - private final BigDecimal withdrawFixOnChainTrx; - private final BigDecimal withdrawFixOnChainEos; - - public GateioFeeInfo( - @JsonProperty("no") int no, - @JsonProperty("symbol") String symbol, - @JsonProperty("name") String name, - @JsonProperty("name_cn") String nameCn, - @JsonProperty("fee_usdt") String feeUsdt, - @JsonProperty("fee_btc") String feeBtc, - @JsonProperty("fee_eth") String feeEth, - @JsonProperty("deposit") String deposit, - @JsonProperty("withdraw_percent") String withdrawPercent, - @JsonProperty("withdraw_fix") String withdrawFix, - @JsonProperty("withdraw_day_limit") String withdrawDayLimit, - @JsonProperty("withdraw_amount_mini") BigDecimal withdrawAmountMini, - @JsonProperty("withdraw_day_limit_remain") BigDecimal withdrawDayLimitRemain, - @JsonProperty("withdraw_eachtime_limit") BigDecimal withdrawEachTimeLimit, - @JsonProperty("withdraw_fix_on_chain_ETH") BigDecimal withdrawFixOnChainEth, - @JsonProperty("withdraw_fix_on_chain_BTC") BigDecimal withdrawFixOnChainBtc, - @JsonProperty("withdraw_fix_on_chain_TRX") BigDecimal withdrawFixOnChainTrx, - @JsonProperty("withdraw_fix_on_chain_EOS") BigDecimal withdrawFixOnChainEos) { - - this.no = no; - this.symbol = symbol; - this.name = name; - this.nameCn = nameCn; - this.feeUsdt = feeUsdt; - this.feeBtc = feeBtc; - this.feeEth = feeEth; - this.deposit = deposit; - this.withdrawPercent = withdrawPercent; - this.withdrawFix = withdrawFix; - this.withdrawDayLimit = withdrawDayLimit; - this.withdrawAmountMini = withdrawAmountMini; - this.withdrawDayLimitRemain = withdrawDayLimitRemain; - this.withdrawEachTimeLimit = withdrawEachTimeLimit; - this.withdrawFixOnChainEth = withdrawFixOnChainEth; - this.withdrawFixOnChainBtc = withdrawFixOnChainBtc; - this.withdrawFixOnChainTrx = withdrawFixOnChainTrx; - this.withdrawFixOnChainEos = withdrawFixOnChainEos; - } - - @Override - public String toString() { - return "GateioFeeInfo{" - + "no=" - + no - + ", symbol='" - + symbol - + '\'' - + ", name='" - + name - + '\'' - + ", nameCn='" - + nameCn - + '\'' - + ", feeUsdt='" - + feeUsdt - + '\'' - + ", feeBtc='" - + feeBtc - + '\'' - + ", feeEth='" - + feeEth - + '\'' - + ", deposit='" - + deposit - + '\'' - + ", withdrawPercent='" - + withdrawPercent - + '\'' - + ", withdrawFix='" - + withdrawFix - + '\'' - + ", withdrawDayLimit='" - + withdrawDayLimit - + '\'' - + ", withdrawAmountMini=" - + withdrawAmountMini - + ", withdrawDayLimitRemain=" - + withdrawDayLimitRemain - + ", withdrawEachTimeLimit=" - + withdrawEachTimeLimit - + ", withdrawFixOnChainEth=" - + withdrawFixOnChainEth - + ", withdrawFixOnChainBtc=" - + withdrawFixOnChainBtc - + ", withdrawFixOnChainTrx=" - + withdrawFixOnChainTrx - + ", withdrawFixOnChainEos=" - + withdrawFixOnChainEos - + '}'; - } - - public int getNo() { - return no; - } - - public String getSymbol() { - return symbol; - } - - public String getName() { - return name; - } - - public String getNameCn() { - return nameCn; - } - - public String getFeeUsdt() { - return feeUsdt; - } - - public String getFeeBtc() { - return feeBtc; - } - - public String getFeeEth() { - return feeEth; - } - - public String getDeposit() { - return deposit; - } - - public String getWithdrawPercent() { - return withdrawPercent; - } - - public String getWithdrawFix() { - return withdrawFix; - } - - public String getWithdrawDayLimit() { - return withdrawDayLimit; - } - - public BigDecimal getWithdrawAmountMini() { - return withdrawAmountMini; - } - - public BigDecimal getWithdrawDayLimitRemain() { - return withdrawDayLimitRemain; - } - - public BigDecimal getWithdrawEachTimeLimit() { - return withdrawEachTimeLimit; - } - - public BigDecimal getWithdrawFixOnChainEth() { - return withdrawFixOnChainEth; - } - - public BigDecimal getWithdrawFixOnChainBtc() { - return withdrawFixOnChainBtc; - } - - public BigDecimal getWithdrawFixOnChainTrx() { - return withdrawFixOnChainTrx; - } - - public BigDecimal getWithdrawFixOnChainEos() { - return withdrawFixOnChainEos; - } -} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioKline.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioKline.java deleted file mode 100644 index 030f1542512..00000000000 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioKline.java +++ /dev/null @@ -1,54 +0,0 @@ -package org.knowm.xchange.gateio.dto.marketdata; - -import java.math.BigDecimal; - -public class GateioKline { - - private final long id; - private final BigDecimal open; - private final BigDecimal close; - private final BigDecimal low; - private final BigDecimal high; - private final BigDecimal vol; - - public GateioKline( - long id, BigDecimal vol, BigDecimal close, BigDecimal high, BigDecimal low, BigDecimal open) { - this.id = id; - this.open = open; - this.close = close; - this.low = low; - this.high = high; - this.vol = vol; - } - - @Override - public String toString() { - return String.format( - "[id = %d, open = %f, close = %f, low = %f, high = %f, vol = %f]", - getId(), getOpen(), getClose(), getLow(), getHigh(), getVol()); - } - - public long getId() { - return id; - } - - public BigDecimal getOpen() { - return open; - } - - public BigDecimal getClose() { - return close; - } - - public BigDecimal getLow() { - return low; - } - - public BigDecimal getHigh() { - return high; - } - - public BigDecimal getVol() { - return vol; - } -} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioKlineInterval.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioKlineInterval.java deleted file mode 100644 index 49c0738edd6..00000000000 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioKlineInterval.java +++ /dev/null @@ -1,36 +0,0 @@ -package org.knowm.xchange.gateio.dto.marketdata; - -import static java.util.concurrent.TimeUnit.DAYS; -import static java.util.concurrent.TimeUnit.HOURS; -import static java.util.concurrent.TimeUnit.MINUTES; -import static java.util.concurrent.TimeUnit.SECONDS; - -public enum GateioKlineInterval { - s10("10s", SECONDS.toSeconds(10)), - m1("1m", MINUTES.toSeconds(1)), - m5("5m", MINUTES.toSeconds(5)), - m15("15m", MINUTES.toSeconds(15)), - m30("30m", MINUTES.toSeconds(30)), - h1("1h", HOURS.toSeconds(1)), - h4("4h", HOURS.toSeconds(4)), - h8("8h", HOURS.toSeconds(8)), - - d1("1d", DAYS.toSeconds(1)), - w1("7d", DAYS.toSeconds(7)); - - private final String code; - private final Long seconds; - - private GateioKlineInterval(String code, Long seconds) { - this.seconds = seconds; - this.code = code; - } - - public Long getSeconds() { - return seconds; - } - - public String code() { - return code; - } -} diff --git a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/dto/marketdata/GateioCurrencyInfoTest.java b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/dto/marketdata/GateioCurrencyInfoTest.java new file mode 100644 index 00000000000..4dd47e5eb50 --- /dev/null +++ b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/dto/marketdata/GateioCurrencyInfoTest.java @@ -0,0 +1,27 @@ +package org.knowm.xchange.gateio.dto.marketdata; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.Test; + +class GateioCurrencyInfoTest { + + @Test + void valid_isWithdrawEnabled() { + GateioCurrencyInfo gateioCurrencyInfo = GateioCurrencyInfo.builder().build(); + assertThat(gateioCurrencyInfo.isWithdrawEnabled()).isFalse(); + + gateioCurrencyInfo.setWithdrawDisabled(false); + assertThat(gateioCurrencyInfo.isWithdrawEnabled()).isTrue(); + } + + + @Test + void valid_isDepositEnabled() { + GateioCurrencyInfo gateioCurrencyInfo = GateioCurrencyInfo.builder().build(); + assertThat(gateioCurrencyInfo.isDepositEnabled()).isFalse(); + + gateioCurrencyInfo.setDepositDisabled(false); + assertThat(gateioCurrencyInfo.isDepositEnabled()).isTrue(); + } +} \ No newline at end of file From e5f7d80dbb630cf46ee599b6d014e7e8831130a5 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Sun, 11 Jun 2023 17:19:15 +0200 Subject: [PATCH 037/159] [gateio-v4] Map rate limit exception --- .../xchange/gateio/GateioErrorAdapter.java | 5 ++++ .../service/GateioAccountServiceTest.java | 23 +++++++++++++++++-- .../api_v4_withdrawals_rate-limit.json | 4 ++++ .../api_v4_withdrawals_rate-limit.json | 20 ++++++++++++++++ 4 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 xchange-gateio-v4/src/test/resources/__files/exceptions/api_v4_withdrawals_rate-limit.json create mode 100644 xchange-gateio-v4/src/test/resources/mappings/exceptions/api_v4_withdrawals_rate-limit.json 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 7f34d1b721d..e18489b26e3 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 @@ -5,6 +5,7 @@ import org.knowm.xchange.exceptions.ExchangeSecurityException; import org.knowm.xchange.exceptions.FundsExceededException; import org.knowm.xchange.exceptions.InstrumentNotValidException; +import org.knowm.xchange.exceptions.RateLimitExceededException; import org.knowm.xchange.gateio.dto.GateioException; @UtilityClass @@ -15,6 +16,7 @@ public class GateioErrorAdapter { public final String FORBIDDEN = "FORBIDDEN"; public final String INVALID_CURRENCY = "INVALID_CURRENCY"; public final String BALANCE_NOT_ENOUGH = "BALANCE_NOT_ENOUGH"; + public final String TOO_FAST = "TOO_FAST"; public ExchangeException adapt(GateioException e) { @@ -30,6 +32,9 @@ public ExchangeException adapt(GateioException e) { case BALANCE_NOT_ENOUGH: return new FundsExceededException(e.getMessage(), e); + + case TOO_FAST: + return new RateLimitExceededException(e.getMessage(), e); default: return new ExchangeException(e.getMessage(), e); } diff --git a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceTest.java b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceTest.java index 2ede958eaa8..1cb5651dcf6 100644 --- a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceTest.java +++ b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceTest.java @@ -1,6 +1,7 @@ package org.knowm.xchange.gateio.service; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import java.io.IOException; import java.math.BigDecimal; @@ -8,6 +9,7 @@ import org.knowm.xchange.currency.Currency; import org.knowm.xchange.dto.account.AccountInfo; import org.knowm.xchange.dto.account.Balance; +import org.knowm.xchange.exceptions.RateLimitExceededException; import org.knowm.xchange.gateio.GateioExchangeWiremock; import org.knowm.xchange.gateio.service.params.DefaultGateioWithdrawFundsParams; @@ -29,9 +31,8 @@ void getAccountInfo() throws IOException { assertThat(usdtBalance.getFrozen()).isEqualTo(new BigDecimal("1.1")); } - @Test - void withdrawFunds() throws IOException { + void normal_withdraw() throws IOException { DefaultGateioWithdrawFundsParams params = DefaultGateioWithdrawFundsParams.builder() .clientRecordId("valid-withdrawal-id") .address("6vLyxJ9dBziamyaw2vDcs9n2NwQdW1uk3aooJwrEscnA") @@ -44,4 +45,22 @@ void withdrawFunds() throws IOException { String withdrawalId = gateioAccountService.withdrawFunds(params); assertThat(withdrawalId).isEqualTo("w35980955"); } + + + @Test + void rate_limited_withdraw() { + DefaultGateioWithdrawFundsParams params = DefaultGateioWithdrawFundsParams.builder() + .clientRecordId("rate-limited-id") + .address("6vLyxJ9dBziamyaw2vDcs9n2NwQdW1uk3aooJwrEscnA") + .addressTag("") + .chain("SOL") + .amount(BigDecimal.valueOf(3)) + .currency(Currency.USDT) + .build(); + + assertThatExceptionOfType(RateLimitExceededException.class) + .isThrownBy(() -> gateioAccountService.withdrawFunds(params)); + } + + } \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/resources/__files/exceptions/api_v4_withdrawals_rate-limit.json b/xchange-gateio-v4/src/test/resources/__files/exceptions/api_v4_withdrawals_rate-limit.json new file mode 100644 index 00000000000..a7a2a421dc0 --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/__files/exceptions/api_v4_withdrawals_rate-limit.json @@ -0,0 +1,4 @@ +{ + "label": "TOO_FAST", + "message": "Withdrawal frequency is limited to 10s127.0.0.1" +} diff --git a/xchange-gateio-v4/src/test/resources/mappings/exceptions/api_v4_withdrawals_rate-limit.json b/xchange-gateio-v4/src/test/resources/mappings/exceptions/api_v4_withdrawals_rate-limit.json new file mode 100644 index 00000000000..8a3805064c9 --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/mappings/exceptions/api_v4_withdrawals_rate-limit.json @@ -0,0 +1,20 @@ +{ + "id" : "cb6973a2-5831-427d-9430-d5a7d01b9a4a", + "name" : "api_v4_withdrawals", + "request" : { + "url" : "/api/v4/withdrawals", + "method" : "POST", + "bodyPatterns" : [ { + "equalToJson" : "{\"withdraw_order_id\":\"rate-limited-id\",\"amount\":3,\"currency\":\"USDT\",\"address\":\"6vLyxJ9dBziamyaw2vDcs9n2NwQdW1uk3aooJwrEscnA\",\"memo\":\"\",\"chain\":\"SOL\"}", + "ignoreArrayOrder" : true, + "ignoreExtraElements" : true + } ] + }, + "response" : { + "status" : 400, + "bodyFileName" : "exceptions/api_v4_withdrawals_rate-limit.json" + }, + "uuid" : "cb6973a2-5831-427d-9430-d5a7d01b9a4a", + "persistent" : true, + "insertionIndex" : 23 +} \ No newline at end of file From 5ed734977c851ecd6a6e30a3b530e8535886bef9 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Mon, 12 Jun 2023 00:25:04 +0200 Subject: [PATCH 038/159] [gateio-v4] Code cleanup --- .../java/org/knowm/xchange/gateio/Gateio.java | 23 +---- .../gateio/dto/account/GateioOrder.java | 8 +- .../marketdata/GateioMarketInfoWrapper.java | 92 ------------------- .../service/GateioMarketDataServiceRaw.java | 25 ++--- .../GateioMarketDataServiceRawTest.java | 32 ++----- .../resources/__files/api_v2_marketinfo.json | 19 ---- .../resources/mappings/api_v2_marketinfo.json | 15 --- 7 files changed, 22 insertions(+), 192 deletions(-) delete mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioMarketInfoWrapper.java delete mode 100644 xchange-gateio-v4/src/test/resources/__files/api_v2_marketinfo.json delete mode 100644 xchange-gateio-v4/src/test/resources/mappings/api_v2_marketinfo.json 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 63581d9232f..91481659155 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 @@ -1,31 +1,18 @@ package org.knowm.xchange.gateio; +import org.knowm.xchange.gateio.dto.GateioException; +import org.knowm.xchange.gateio.dto.marketdata.*; + +import javax.ws.rs.*; +import javax.ws.rs.core.MediaType; import java.io.IOException; import java.util.List; import java.util.Map; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.MediaType; -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.GateioMarketInfoWrapper; -import org.knowm.xchange.gateio.dto.marketdata.GateioOrderBook; -import org.knowm.xchange.gateio.dto.marketdata.GateioTicker; -import org.knowm.xchange.gateio.dto.marketdata.GateioTradeHistory; @Path("") @Produces(MediaType.APPLICATION_JSON) public interface Gateio { - @GET - @Path("api/v2/marketinfo") - GateioMarketInfoWrapper getMarketInfo() throws IOException; - @GET @Path("/api2/1/tickers") Map getTickers() throws IOException; diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioOrder.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioOrder.java index a7a2b06fc32..1395a4a465b 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioOrder.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioOrder.java @@ -1,18 +1,16 @@ package org.knowm.xchange.gateio.dto.account; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonProperty; -import java.math.BigDecimal; -import java.time.Instant; import lombok.Builder; import lombok.Data; import lombok.extern.jackson.Jacksonized; +import java.math.BigDecimal; +import java.time.Instant; + @Data @Builder @Jacksonized -@JsonInclude(value = Include.NON_EMPTY, content = Include.NON_NULL) public class GateioOrder { @JsonProperty("id") diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioMarketInfoWrapper.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioMarketInfoWrapper.java deleted file mode 100644 index 819ce7fa203..00000000000 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioMarketInfoWrapper.java +++ /dev/null @@ -1,92 +0,0 @@ -package org.knowm.xchange.gateio.dto.marketdata; - -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.core.ObjectCodec; -import com.fasterxml.jackson.databind.DeserializationContext; -import com.fasterxml.jackson.databind.JsonDeserializer; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import java.io.IOException; -import java.math.BigDecimal; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; -import java.util.Map.Entry; -import lombok.Value; -import org.knowm.xchange.currency.CurrencyPair; -import org.knowm.xchange.exceptions.ExchangeException; -import org.knowm.xchange.gateio.GateioAdapters; -import org.knowm.xchange.gateio.dto.marketdata.GateioMarketInfoWrapper.BTERMarketInfoWrapperDeserializer; - -@JsonDeserialize(using = BTERMarketInfoWrapperDeserializer.class) -public class GateioMarketInfoWrapper { - - private final Map marketInfoMap; - - private GateioMarketInfoWrapper(Map marketInfoMap) { - - this.marketInfoMap = marketInfoMap; - } - - public Map getMarketInfoMap() { - - return marketInfoMap; - } - - @Override - public String toString() { - - return "GateioMarketInfoWrapper [marketInfoMap=" + marketInfoMap + "]"; - } - - @Value - public static class GateioMarketInfo { - - CurrencyPair currencyPair; - int decimalPlaces; - BigDecimal minAmount; - BigDecimal fee; - - } - - static class BTERMarketInfoWrapperDeserializer extends JsonDeserializer { - - @Override - public GateioMarketInfoWrapper deserialize(JsonParser jp, DeserializationContext ctxt) - throws IOException, JsonProcessingException { - - Map marketInfoMap = new HashMap<>(); - - ObjectCodec oc = jp.getCodec(); - JsonNode marketsNodeWrapper = oc.readTree(jp); - JsonNode marketNodeList = marketsNodeWrapper.path("pairs"); - - if (marketNodeList.isArray()) { - for (JsonNode marketNode : marketNodeList) { - Iterator> iter = marketNode.fields(); - if (iter.hasNext()) { - Entry entry = iter.next(); - CurrencyPair currencyPair = GateioAdapters.adaptCurrencyPair(entry.getKey()); - JsonNode marketInfoData = entry.getValue(); - int decimalPlaces = marketInfoData.path("decimal_places").asInt(); - BigDecimal minAmount = new BigDecimal(marketInfoData.path("min_amount").asText()); - BigDecimal fee = new BigDecimal(marketInfoData.path("fee").asText()); - GateioMarketInfo marketInfoObject = - new GateioMarketInfo(currencyPair, decimalPlaces, minAmount, fee); - - marketInfoMap.put(currencyPair, marketInfoObject); - } else { - throw new ExchangeException( - "Invalid market info response received from Gateio." + marketsNodeWrapper); - } - } - } else { - throw new ExchangeException( - "Invalid market info response received from Gateio." + marketsNodeWrapper); - } - - return new GateioMarketInfoWrapper(marketInfoMap); - } - } -} 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 ca431fc4d43..438b6132b16 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 @@ -1,23 +1,18 @@ package org.knowm.xchange.gateio.service; -import java.io.IOException; -import java.util.HashMap; -import java.util.List; -import java.util.Map; import org.knowm.xchange.currency.Currency; import org.knowm.xchange.currency.CurrencyPair; import org.knowm.xchange.dto.marketdata.Ticker; import org.knowm.xchange.gateio.GateioAdapters; import org.knowm.xchange.gateio.GateioExchange; -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.GateioMarketInfoWrapper; -import org.knowm.xchange.gateio.dto.marketdata.GateioOrderBook; -import org.knowm.xchange.gateio.dto.marketdata.GateioTicker; -import org.knowm.xchange.gateio.dto.marketdata.GateioTradeHistory; +import org.knowm.xchange.gateio.dto.marketdata.*; import org.knowm.xchange.instrument.Instrument; +import java.io.IOException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + public class GateioMarketDataServiceRaw extends GateioBaseService { /** @@ -30,14 +25,6 @@ public GateioMarketDataServiceRaw(GateioExchange exchange) { super(exchange); } - public Map getMarketInfo() - throws IOException { - - GateioMarketInfoWrapper bterMarketInfo = gateio.getMarketInfo(); - - return bterMarketInfo.getMarketInfoMap(); - } - public Map getGateioTickers() throws IOException { Map gateioTickers = gateio.getTickers(); diff --git a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioMarketDataServiceRawTest.java b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioMarketDataServiceRawTest.java index 36a4e186e0b..d6132ff65f1 100644 --- a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioMarketDataServiceRawTest.java +++ b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioMarketDataServiceRawTest.java @@ -1,14 +1,5 @@ package org.knowm.xchange.gateio.service; -import static org.assertj.core.api.Assertions.assertThat; - -import java.io.IOException; -import java.math.BigDecimal; -import java.time.Instant; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; import org.junit.jupiter.api.Test; import org.knowm.xchange.currency.Currency; import org.knowm.xchange.currency.CurrencyPair; @@ -16,27 +7,20 @@ 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.GateioMarketInfoWrapper; -import org.knowm.xchange.gateio.dto.marketdata.GateioMarketInfoWrapper.GateioMarketInfo; import org.knowm.xchange.gateio.dto.marketdata.GateioOrderBook; import org.knowm.xchange.gateio.dto.marketdata.GateioOrderBook.PriceSizeEntry; -public class GateioMarketDataServiceRawTest extends GateioExchangeWiremock { - - GateioMarketDataServiceRaw gateioMarketDataServiceRaw = (GateioMarketDataServiceRaw) exchange.getMarketDataService(); +import java.io.IOException; +import java.math.BigDecimal; +import java.time.Instant; +import java.util.ArrayList; +import java.util.List; - @Test - public void getMarketInfo_valid() throws IOException { +import static org.assertj.core.api.Assertions.assertThat; - Map expected = new HashMap<>(); - expected.put(CurrencyPair.BTC_USDT, - new GateioMarketInfo(CurrencyPair.BTC_USDT, 1, new BigDecimal("0.00010"), new BigDecimal("0.2"))); - expected.put(CurrencyPair.ETH_USDT, - new GateioMarketInfo(CurrencyPair.ETH_USDT, 2, new BigDecimal("0.001"), new BigDecimal("0.2"))); +public class GateioMarketDataServiceRawTest extends GateioExchangeWiremock { - Map actual = gateioMarketDataServiceRaw.getMarketInfo(); - assertThat(actual).isEqualTo(expected); - } + GateioMarketDataServiceRaw gateioMarketDataServiceRaw = (GateioMarketDataServiceRaw) exchange.getMarketDataService(); @Test diff --git a/xchange-gateio-v4/src/test/resources/__files/api_v2_marketinfo.json b/xchange-gateio-v4/src/test/resources/__files/api_v2_marketinfo.json deleted file mode 100644 index c61cd69db84..00000000000 --- a/xchange-gateio-v4/src/test/resources/__files/api_v2_marketinfo.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "result": "true", - "pairs": [ - { - "btc_usdt": { - "decimal_places": 1, - "min_amount": 0.0001, - "fee": 0.2 - } - }, - { - "eth_usdt": { - "decimal_places": 2, - "min_amount": 0.001, - "fee": 0.2 - } - } - ] -} \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/resources/mappings/api_v2_marketinfo.json b/xchange-gateio-v4/src/test/resources/mappings/api_v2_marketinfo.json deleted file mode 100644 index bf471787b62..00000000000 --- a/xchange-gateio-v4/src/test/resources/mappings/api_v2_marketinfo.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "id" : "b404ad32-1bfb-47b9-b1fb-41e024c7cf03", - "name" : "api_v2_marketinfo", - "request" : { - "url" : "/api/v2/marketinfo", - "method" : "GET" - }, - "response" : { - "status" : 200, - "bodyFileName" : "api_v2_marketinfo.json" - }, - "uuid" : "b404ad32-1bfb-47b9-b1fb-41e024c7cf03", - "persistent" : true, - "insertionIndex" : 1 -} \ No newline at end of file From 0835196be4d126cc46b0151a0d6ba7c0f3b8779a Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Mon, 12 Jun 2023 10:58:27 +0200 Subject: [PATCH 039/159] [gateio-v4] Add more error mappings --- .../xchange/gateio/GateioErrorAdapter.java | 16 ++++--- .../service/GateioAccountServiceTest.java | 45 ++++++++++++++++--- .../api_v4_withdrawals_invalid-address.json | 4 ++ .../api_v4_withdrawals_min-amount.json | 4 ++ .../api_v4_withdrawals_invalid-address.json | 20 +++++++++ .../api_v4_withdrawals_min-amount.json | 20 +++++++++ 6 files changed, 99 insertions(+), 10 deletions(-) create mode 100644 xchange-gateio-v4/src/test/resources/__files/exceptions/api_v4_withdrawals_invalid-address.json create mode 100644 xchange-gateio-v4/src/test/resources/__files/exceptions/api_v4_withdrawals_min-amount.json create mode 100644 xchange-gateio-v4/src/test/resources/mappings/exceptions/api_v4_withdrawals_invalid-address.json create mode 100644 xchange-gateio-v4/src/test/resources/mappings/exceptions/api_v4_withdrawals_min-amount.json 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 e18489b26e3..e8da85c8e6d 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,11 +1,7 @@ package org.knowm.xchange.gateio; import lombok.experimental.UtilityClass; -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.RateLimitExceededException; +import org.knowm.xchange.exceptions.*; import org.knowm.xchange.gateio.dto.GateioException; @UtilityClass @@ -17,6 +13,7 @@ public class GateioErrorAdapter { public final String INVALID_CURRENCY = "INVALID_CURRENCY"; public final String BALANCE_NOT_ENOUGH = "BALANCE_NOT_ENOUGH"; public final String TOO_FAST = "TOO_FAST"; + public final String INVALID_PARAM_VALUE = "INVALID_PARAM_VALUE"; public ExchangeException adapt(GateioException e) { @@ -35,6 +32,15 @@ public ExchangeException adapt(GateioException e) { case TOO_FAST: return new RateLimitExceededException(e.getMessage(), e); + + case INVALID_PARAM_VALUE: + if (e.getMessage().contains("below minimum")) { + return new OrderAmountUnderMinimumException(e.getMessage(), e); + } + else { + return new OrderNotValidException(e.getMessage(), e); + } + default: return new ExchangeException(e.getMessage(), e); } diff --git a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceTest.java b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceTest.java index 1cb5651dcf6..aba5d4ae9eb 100644 --- a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceTest.java +++ b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceTest.java @@ -1,18 +1,21 @@ package org.knowm.xchange.gateio.service; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; - -import java.io.IOException; -import java.math.BigDecimal; import org.junit.jupiter.api.Test; import org.knowm.xchange.currency.Currency; import org.knowm.xchange.dto.account.AccountInfo; import org.knowm.xchange.dto.account.Balance; +import org.knowm.xchange.exceptions.OrderAmountUnderMinimumException; +import org.knowm.xchange.exceptions.OrderNotValidException; import org.knowm.xchange.exceptions.RateLimitExceededException; import org.knowm.xchange.gateio.GateioExchangeWiremock; import org.knowm.xchange.gateio.service.params.DefaultGateioWithdrawFundsParams; +import java.io.IOException; +import java.math.BigDecimal; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; + class GateioAccountServiceTest extends GateioExchangeWiremock { GateioAccountService gateioAccountService = ((GateioAccountService) exchange.getAccountService()); @@ -63,4 +66,36 @@ void rate_limited_withdraw() { } + @Test + void zero_amount_withdraw() { + DefaultGateioWithdrawFundsParams params = DefaultGateioWithdrawFundsParams.builder() + .clientRecordId("zero-amount-id") + .address("6vLyxJ9dBziamyaw2vDcs9n2NwQdW1uk3aooJwrEscnA") + .addressTag("") + .chain("SOL") + .amount(BigDecimal.ZERO) + .currency(Currency.USDT) + .build(); + + assertThatExceptionOfType(OrderAmountUnderMinimumException.class) + .isThrownBy(() -> gateioAccountService.withdrawFunds(params)); + } + + + @Test + void invalid_address_withdraw() { + DefaultGateioWithdrawFundsParams params = DefaultGateioWithdrawFundsParams.builder() + .clientRecordId("invalid-address-id") + .address("invalid-address") + .addressTag("") + .chain("SOL") + .amount(BigDecimal.ZERO) + .currency(Currency.USDT) + .build(); + + assertThatExceptionOfType(OrderNotValidException.class) + .isThrownBy(() -> gateioAccountService.withdrawFunds(params)); + } + + } \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/resources/__files/exceptions/api_v4_withdrawals_invalid-address.json b/xchange-gateio-v4/src/test/resources/__files/exceptions/api_v4_withdrawals_invalid-address.json new file mode 100644 index 00000000000..3cf6d04f722 --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/__files/exceptions/api_v4_withdrawals_invalid-address.json @@ -0,0 +1,4 @@ +{ + "label": "INVALID_PARAM_VALUE", + "message": "Error: only used addresses or verified addresses are allowed for api withdrawal" +} \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/resources/__files/exceptions/api_v4_withdrawals_min-amount.json b/xchange-gateio-v4/src/test/resources/__files/exceptions/api_v4_withdrawals_min-amount.json new file mode 100644 index 00000000000..fae74d67544 --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/__files/exceptions/api_v4_withdrawals_min-amount.json @@ -0,0 +1,4 @@ +{ + "label": "INVALID_PARAM_VALUE", + "message": "Error: Invalid amount or below minimum amount limit." +} diff --git a/xchange-gateio-v4/src/test/resources/mappings/exceptions/api_v4_withdrawals_invalid-address.json b/xchange-gateio-v4/src/test/resources/mappings/exceptions/api_v4_withdrawals_invalid-address.json new file mode 100644 index 00000000000..41f073e3a19 --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/mappings/exceptions/api_v4_withdrawals_invalid-address.json @@ -0,0 +1,20 @@ +{ + "id" : "abed53fd-b0fb-46df-9bc7-07cb19f48a48", + "name" : "api_v4_withdrawals", + "request" : { + "url" : "/api/v4/withdrawals", + "method" : "POST", + "bodyPatterns" : [ { + "equalToJson" : "{\"withdraw_order_id\":\"invalid-address-id\",\"amount\":0,\"currency\":\"USDT\",\"address\":\"invalid-address\",\"memo\":\"\",\"chain\":\"SOL\"}", + "ignoreArrayOrder" : true, + "ignoreExtraElements" : true + } ] + }, + "response" : { + "status" : 400, + "bodyFileName" : "exceptions/api_v4_withdrawals_invalid-address.json" + }, + "uuid" : "abed53fd-b0fb-46df-9bc7-07cb19f48a48", + "persistent" : true, + "insertionIndex" : 25 +} \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/resources/mappings/exceptions/api_v4_withdrawals_min-amount.json b/xchange-gateio-v4/src/test/resources/mappings/exceptions/api_v4_withdrawals_min-amount.json new file mode 100644 index 00000000000..b21d2339a29 --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/mappings/exceptions/api_v4_withdrawals_min-amount.json @@ -0,0 +1,20 @@ +{ + "id" : "0a1e28bd-882a-47a2-b5fc-1b8b67e3c61c", + "name" : "api_v4_withdrawals", + "request" : { + "url" : "/api/v4/withdrawals", + "method" : "POST", + "bodyPatterns" : [ { + "equalToJson" : "{\"withdraw_order_id\":\"zero-amount-id\",\"amount\":0,\"currency\":\"USDT\",\"address\":\"6vLyxJ9dBziamyaw2vDcs9n2NwQdW1uk3aooJwrEscnA\",\"memo\":\"\",\"chain\":\"SOL\"}", + "ignoreArrayOrder" : true, + "ignoreExtraElements" : true + } ] + }, + "response" : { + "status" : 400, + "bodyFileName" : "exceptions/api_v4_withdrawals_min-amount.json" + }, + "uuid" : "0a1e28bd-882a-47a2-b5fc-1b8b67e3c61c", + "persistent" : true, + "insertionIndex" : 24 +} \ No newline at end of file From 864b00ed5b8f8bd6b636ac387b88ef2ff3a46c73 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Mon, 12 Jun 2023 12:14:09 +0200 Subject: [PATCH 040/159] [gateio-v4] Update http requests --- .../src/test/resources/rest/wallet.http | 7 +++-- .../src/test/resources/rest/withdraw.http | 31 +++++++++++++++++++ 2 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 xchange-gateio-v4/src/test/resources/rest/withdraw.http diff --git a/xchange-gateio-v4/src/test/resources/rest/wallet.http b/xchange-gateio-v4/src/test/resources/rest/wallet.http index 73d10e2965b..36b21002fb5 100644 --- a/xchange-gateio-v4/src/test/resources/rest/wallet.http +++ b/xchange-gateio-v4/src/test/resources/rest/wallet.http @@ -5,18 +5,19 @@ const matches = url.match(pattern); const method = "GET"; const path = matches[5]; - const query = matches[7]; + const query = matches[7] || ""; const hexedHashedBody = crypto.sha512().updateWithText(request.body.tryGetSubstituted() || "").digest().toHex(); - const timestamp = request.headers.findByName("Timestamp").tryGetSubstitutedValue(); + const timestamp = Math.floor(Date.now() / 1000).toFixed(); const payloadToSign = `${method}\n${path}\n${query}\n${hexedHashedBody}\n${timestamp}`; const apiSecret = request.environment.get("api_secret"); const sign = crypto.hmac.sha512().withTextSecret(apiSecret).updateWithText(payloadToSign).digest().toHex(); + request.variables.set("timestamp", timestamp); request.variables.set("sign", sign); %} GET {{api_v4}}/wallet/withdraw_status?currency=usdt KEY: {{api_key}} SIGN: {{sign}} -Timestamp: {{$timestamp}} +Timestamp: {{timestamp}} Content-Type: application/json diff --git a/xchange-gateio-v4/src/test/resources/rest/withdraw.http b/xchange-gateio-v4/src/test/resources/rest/withdraw.http new file mode 100644 index 00000000000..bdc02b8dbbd --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/rest/withdraw.http @@ -0,0 +1,31 @@ +### Withdraw +< {% + const pattern = RegExp("^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?"); + const url = request.url.tryGetSubstituted(); + const matches = url.match(pattern); + const method = "POST"; + const path = matches[5]; + const query = matches[7] || ""; + const body = request.body.tryGetSubstituted(); + const hexedHashedBody = crypto.sha512().updateWithText(request.body.tryGetSubstituted() || "").digest().toHex(); + const timestamp = Math.floor(Date.now() / 1000).toFixed(); + const payloadToSign = `${method}\n${path}\n${query}\n${hexedHashedBody}\n${timestamp}`; + const apiSecret = request.environment.get("api_secret"); + const sign = crypto.hmac.sha512().withTextSecret(apiSecret).updateWithText(payloadToSign).digest().toHex(); + request.variables.set("sign", sign); + request.variables.set("timestamp", timestamp); +%} + +POST {{api_v4}}/withdrawals +KEY: {{api_key}} +SIGN: {{sign}} +Timestamp: {{timestamp}} +Content-Type: application/json + +{ + "amount": 0, + "currency": "usdt", + "address": "0x3dca2ae4d1d065220a731cf69f5a934914afc435", + "memo": "", + "chain": "BSC" +} From 909d1590f8c2c4b926b9a0c52830704371e7ff97 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Mon, 12 Jun 2023 12:14:39 +0200 Subject: [PATCH 041/159] [gateio-v4] Code cleanup --- .../knowm/xchange/gateio/GateioAdapters.java | 32 +++-------- .../dto/marketdata/GateioPublicOrder.java | 57 ------------------- 2 files changed, 7 insertions(+), 82 deletions(-) delete mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioPublicOrder.java diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java index b18addfcef5..3797260dae7 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java @@ -1,11 +1,5 @@ package org.knowm.xchange.gateio; -import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.Locale; -import java.util.stream.Collectors; import lombok.experimental.UtilityClass; import org.knowm.xchange.currency.Currency; import org.knowm.xchange.currency.CurrencyPair; @@ -25,13 +19,19 @@ import org.knowm.xchange.gateio.dto.account.GateioWithdrawalRequest; import org.knowm.xchange.gateio.dto.marketdata.GateioCurrencyPairDetails; import org.knowm.xchange.gateio.dto.marketdata.GateioOrderBook; -import org.knowm.xchange.gateio.dto.marketdata.GateioPublicOrder; import org.knowm.xchange.gateio.dto.marketdata.GateioTicker; import org.knowm.xchange.gateio.dto.marketdata.GateioTradeHistory; import org.knowm.xchange.gateio.service.params.DefaultGateioWithdrawFundsParams; import org.knowm.xchange.instrument.Instrument; import org.knowm.xchange.utils.DateUtils; +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Locale; +import java.util.stream.Collectors; + @UtilityClass public class GateioAdapters { @@ -101,24 +101,6 @@ public OrderBook toOrderBook(GateioOrderBook gateioOrderBook, Instrument instrum } - public LimitOrder adaptOrder( - GateioPublicOrder order, CurrencyPair currencyPair, OrderType orderType) { - - return new LimitOrder(orderType, order.getAmount(), currencyPair, "", null, order.getPrice()); - } - - public List adaptOrders( - List orders, CurrencyPair currencyPair, OrderType orderType) { - - List limitOrders = new ArrayList<>(); - - for (GateioPublicOrder bterOrder : orders) { - limitOrders.add(adaptOrder(bterOrder, currencyPair, orderType)); - } - - return limitOrders; - } - public OrderType adaptOrderType(GateioOrderType cryptoTradeOrderType) { return (cryptoTradeOrderType.equals(GateioOrderType.BUY)) ? OrderType.BID : OrderType.ASK; } diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioPublicOrder.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioPublicOrder.java deleted file mode 100644 index 3d15ff48a61..00000000000 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioPublicOrder.java +++ /dev/null @@ -1,57 +0,0 @@ -package org.knowm.xchange.gateio.dto.marketdata; - -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.core.ObjectCodec; -import com.fasterxml.jackson.databind.DeserializationContext; -import com.fasterxml.jackson.databind.JsonDeserializer; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import java.io.IOException; -import java.math.BigDecimal; -import org.knowm.xchange.gateio.dto.marketdata.GateioPublicOrder.GateioPublicOrderDeserializer; - -@JsonDeserialize(using = GateioPublicOrderDeserializer.class) -public class GateioPublicOrder { - - private final BigDecimal price; - private final BigDecimal amount; - - private GateioPublicOrder(BigDecimal price, final BigDecimal amount) { - - this.price = price; - this.amount = amount; - } - - public BigDecimal getPrice() { - - return price; - } - - public BigDecimal getAmount() { - - return amount; - } - - @Override - public String toString() { - - return "GateioPublicOrder [price=" + price + ", amount=" + amount + "]"; - } - - static class GateioPublicOrderDeserializer extends JsonDeserializer { - - @Override - public GateioPublicOrder deserialize(JsonParser jp, DeserializationContext ctxt) - throws IOException, JsonProcessingException { - - final ObjectCodec oc = jp.getCodec(); - final JsonNode tickerNode = oc.readTree(jp); - - final BigDecimal price = new BigDecimal(tickerNode.path(0).asText()); - final BigDecimal amount = new BigDecimal(tickerNode.path(1).asText()); - - return new GateioPublicOrder(price, amount); - } - } -} From bf6eaed3f91c21778d4b04d841113447c6f0a815 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Mon, 12 Jun 2023 13:01:09 +0200 Subject: [PATCH 042/159] [gateio-v4] Add tickers endpoint --- .../java/org/knowm/xchange/gateio/Gateio.java | 16 +- .../knowm/xchange/gateio/GateioAdapters.java | 55 +++--- .../gateio/dto/marketdata/GateioTicker.java | 169 ++++++------------ .../service/GateioMarketDataService.java | 53 +++--- .../service/GateioMarketDataServiceRaw.java | 29 +-- .../service/GateioMarketDataServiceTest.java | 46 ++++- .../__files/api_v4_spot_tickers.json | 28 +++ .../__files/api_v4_spot_tickers_btc-usdt.json | 13 ++ .../mappings/api_v4_spot_tickers.json | 15 ++ .../api_v4_spot_tickers_btc-usdt.json | 15 ++ 10 files changed, 226 insertions(+), 213 deletions(-) create mode 100644 xchange-gateio-v4/src/test/resources/__files/api_v4_spot_tickers.json create mode 100644 xchange-gateio-v4/src/test/resources/__files/api_v4_spot_tickers_btc-usdt.json create mode 100644 xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_tickers.json create mode 100644 xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_tickers_btc-usdt.json 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 91481659155..52b00bf03e4 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 @@ -7,22 +7,11 @@ import javax.ws.rs.core.MediaType; import java.io.IOException; import java.util.List; -import java.util.Map; @Path("") @Produces(MediaType.APPLICATION_JSON) public interface Gateio { - @GET - @Path("/api2/1/tickers") - Map getTickers() throws IOException; - - @GET - @Path("api2/1/ticker/{ident}_{currency}") - GateioTicker getTicker( - @PathParam("ident") String tradeableIdentifier, @PathParam("currency") String currency) - throws IOException; - @GET @Path("api2/1/tradeHistory/{ident}_{currency}") GateioTradeHistory getTradeHistory( @@ -66,4 +55,9 @@ GateioOrderBook getOrderBook( GateioCurrencyPairDetails getCurrencyPairDetails(@PathParam("currency_pair") String currencyPair) throws IOException, GateioException; + @GET + @Path("api/v4/spot/tickers") + List getTickers(@QueryParam("currency_pair") String currencyPair) throws IOException, GateioException; + + } diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java index 3797260dae7..ab1d5afb553 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java @@ -25,7 +25,6 @@ import org.knowm.xchange.instrument.Instrument; import org.knowm.xchange.utils.DateUtils; -import java.math.BigDecimal; import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -48,10 +47,15 @@ public String toString(Currency currency) { public String toString(Instrument instrument) { - return String.format("%s_%s", - instrument.getBase().getCurrencyCode(), - instrument.getCounter().getCurrencyCode()) - .toUpperCase(Locale.ROOT); + if (instrument == null) { + return null; + } + else { + return String.format("%s_%s", + instrument.getBase().getCurrencyCode(), + instrument.getCounter().getCurrencyCode()) + .toUpperCase(Locale.ROOT); + } } @@ -61,32 +65,6 @@ public Instrument toInstrument(String currencyCode) { } - public Ticker adaptTicker(CurrencyPair currencyPair, GateioTicker gateioTicker) { - - BigDecimal ask = gateioTicker.getLowestAsk(); - BigDecimal bid = gateioTicker.getHighestBid(); - BigDecimal last = gateioTicker.getLast(); - BigDecimal low = gateioTicker.getLow24hr(); - BigDecimal high = gateioTicker.getHigh24hr(); - // Looks like gate.io vocabulary is inverted... - BigDecimal baseVolume = gateioTicker.getQuoteVolume(); - BigDecimal quoteVolume = gateioTicker.getBaseVolume(); - BigDecimal percentageChange = gateioTicker.getPercentChange(); - - return new Ticker.Builder() - .currencyPair(currencyPair) - .ask(ask) - .bid(bid) - .last(last) - .low(low) - .high(high) - .volume(baseVolume) - .quoteVolume(quoteVolume) - .percentageChange(percentageChange) - .build(); - } - - public OrderBook toOrderBook(GateioOrderBook gateioOrderBook, Instrument instrument) { List asks = gateioOrderBook.getAsks().stream() .map(priceSizeEntry -> new LimitOrder(OrderType.ASK, priceSizeEntry.getSize(), instrument, null, null, priceSizeEntry.getPrice())) @@ -258,4 +236,19 @@ public GateioWithdrawalRequest toGateioWithdrawalRequest(DefaultGateioWithdrawFu .build(); } + + + public Ticker toTicker(GateioTicker gateioTicker) { + return new Ticker.Builder() + .instrument(toInstrument(gateioTicker.getCurrencyPair())) + .last(gateioTicker.getLastPrice()) + .bid(gateioTicker.getHighestBid()) + .ask(gateioTicker.getLowestAsk()) + .high(gateioTicker.getMaxPrice24h()) + .low(gateioTicker.getMinPrice24h()) + .volume(gateioTicker.getAssetVolume()) + .quoteVolume(gateioTicker.getQuoteVolume()) + .percentageChange(gateioTicker.getChangePercentage24h()) + .build(); + } } diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioTicker.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioTicker.java index 621e798a2ee..639eaf5e05d 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioTicker.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioTicker.java @@ -1,118 +1,61 @@ package org.knowm.xchange.gateio.dto.marketdata; import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Builder; +import lombok.Data; +import lombok.extern.jackson.Jacksonized; + import java.math.BigDecimal; -import org.knowm.xchange.gateio.dto.GateioBaseResponse; - -public class GateioTicker extends GateioBaseResponse { - private BigDecimal highestBid; - - private boolean result; - - private BigDecimal low24hr; - - private BigDecimal last; - - private BigDecimal high24hr; - - private BigDecimal percentChange; - - private BigDecimal lowestAsk; - - private BigDecimal quoteVolume; - - private BigDecimal baseVolume; - - public GateioTicker( - @JsonProperty("result") boolean result, - @JsonProperty("message") String message, - @JsonProperty("highestBid") BigDecimal highestBid, - @JsonProperty("low24hr") BigDecimal low24hr, - @JsonProperty("last") BigDecimal last, - @JsonProperty("high24hr") BigDecimal high24hr, - @JsonProperty("percentChange") BigDecimal percentChange, - @JsonProperty("lowestAsk") BigDecimal lowestAsk, - @JsonProperty("quoteVolume") BigDecimal quoteVolume, - @JsonProperty("baseVolume") BigDecimal baseVolume) { - super(result, message); - this.highestBid = highestBid; - this.result = result; - this.low24hr = low24hr; - this.last = last; - this.high24hr = high24hr; - this.percentChange = percentChange; - this.lowestAsk = lowestAsk; - this.quoteVolume = quoteVolume; - this.baseVolume = baseVolume; - } - - public BigDecimal getHighestBid() { - return highestBid; - } - - @Override - public boolean isResult() { - return result; - } - - public BigDecimal getLow24hr() { - return low24hr; - } - - public BigDecimal getLast() { - return last; - } - - public BigDecimal getHigh24hr() { - return high24hr; - } - - public BigDecimal getPercentChange() { - return percentChange; - } - - public BigDecimal getLowestAsk() { - return lowestAsk; - } - - public BigDecimal getQuoteVolume() { - return quoteVolume; - } - - public BigDecimal getBaseVolume() { - return baseVolume; - } - - @Override - public String toString() { - return "GateioTicker{" - + "highestBid='" - + highestBid - + '\'' - + ", result='" - + result - + '\'' - + ", low24hr='" - + low24hr - + '\'' - + ", last='" - + last - + '\'' - + ", high24hr='" - + high24hr - + '\'' - + ", percentChange='" - + percentChange - + '\'' - + ", lowestAsk='" - + lowestAsk - + '\'' - + ", quoteVolume='" - + quoteVolume - + '\'' - + ", baseVolume='" - + baseVolume - + '\'' - + '}'; - } +import java.time.Instant; + +@Data +@Builder +@Jacksonized +public class GateioTicker { + + @JsonProperty("currency_pair") + String currencyPair; + + @JsonProperty("last") + BigDecimal lastPrice; + + @JsonProperty("lowest_ask") + BigDecimal lowestAsk; + + @JsonProperty("highest_bid") + BigDecimal highestBid; + + @JsonProperty("change_percentage") + BigDecimal changePercentage24h; + + @JsonProperty("change_utc0") + BigDecimal changePercentage24hUTC0; + + @JsonProperty("change_utc8") + BigDecimal changePercentage24hUTC8; + + @JsonProperty("base_volume") + BigDecimal assetVolume; + + @JsonProperty("quote_volume") + BigDecimal quoteVolume; + + @JsonProperty("high_24h") + BigDecimal maxPrice24h; + + @JsonProperty("low_24h") + BigDecimal minPrice24h; + + @JsonProperty("etf_net_value") + BigDecimal etfNetValue; + + @JsonProperty("etf_pre_net_value") + BigDecimal etfPreNetValue; + + @JsonProperty("etf_pre_timestamp") + Instant etfPreTimestamp; + + @JsonProperty("etf_leverage") + BigDecimal etfLeverage; + } 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 bc477a467e0..63562566bd5 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,10 +1,6 @@ package org.knowm.xchange.gateio.service; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; +import org.apache.commons.lang3.Validate; import org.knowm.xchange.currency.CurrencyPair; import org.knowm.xchange.dto.marketdata.OrderBook; import org.knowm.xchange.dto.marketdata.Ticker; @@ -20,17 +16,15 @@ import org.knowm.xchange.gateio.dto.marketdata.GateioTradeHistory; import org.knowm.xchange.instrument.Instrument; import org.knowm.xchange.service.marketdata.MarketDataService; -import org.knowm.xchange.service.marketdata.params.CurrencyPairsParam; import org.knowm.xchange.service.marketdata.params.Params; -public class GateioMarketDataService extends GateioMarketDataServiceRaw - implements MarketDataService { +import java.io.IOException; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +public class GateioMarketDataService extends GateioMarketDataServiceRaw implements MarketDataService { - /** - * Constructor - * - * @param exchange - */ public GateioMarketDataService(GateioExchange exchange) { super(exchange); @@ -38,24 +32,35 @@ public GateioMarketDataService(GateioExchange exchange) { @Override public Ticker getTicker(CurrencyPair currencyPair, Object... args) throws IOException { + return getTicker((Instrument) currencyPair, args); + } - GateioTicker ticker = - super.getBTERTicker( - currencyPair.base.getCurrencyCode(), currencyPair.counter.getCurrencyCode()); - return GateioAdapters.adaptTicker(currencyPair, ticker); + @Override + public Ticker getTicker(Instrument instrument, Object... args) throws IOException { + Validate.notNull(instrument); + try { + List tickers = getGateioTickers(instrument); + Validate.validState(tickers.size() == 1); + + return GateioAdapters.toTicker(tickers.get(0)); + } catch (GateioException e) { + throw GateioErrorAdapter.adapt(e); + } } + @Override public List getTickers(Params params) throws IOException { - final List currencyPairs = new ArrayList<>(); - if (params instanceof CurrencyPairsParam) { - currencyPairs.addAll(((CurrencyPairsParam) params).getCurrencyPairs()); + try { + List tickers = getGateioTickers(null); + + return tickers.stream() + .map(GateioAdapters::toTicker) + .collect(Collectors.toList()); + } catch (GateioException e) { + throw GateioErrorAdapter.adapt(e); } - return getGateioTickers().values().stream() - .filter( - ticker -> currencyPairs.size() == 0 || currencyPairs.contains(ticker.getCurrencyPair())) - .collect(Collectors.toList()); } @Override 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 438b6132b16..ed34a1c5e7d 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 @@ -1,17 +1,13 @@ package org.knowm.xchange.gateio.service; import org.knowm.xchange.currency.Currency; -import org.knowm.xchange.currency.CurrencyPair; -import org.knowm.xchange.dto.marketdata.Ticker; import org.knowm.xchange.gateio.GateioAdapters; import org.knowm.xchange.gateio.GateioExchange; import org.knowm.xchange.gateio.dto.marketdata.*; import org.knowm.xchange.instrument.Instrument; import java.io.IOException; -import java.util.HashMap; import java.util.List; -import java.util.Map; public class GateioMarketDataServiceRaw extends GateioBaseService { @@ -25,29 +21,8 @@ public GateioMarketDataServiceRaw(GateioExchange exchange) { super(exchange); } - public Map getGateioTickers() throws IOException { - - Map gateioTickers = gateio.getTickers(); - Map adaptedTickers = new HashMap<>(gateioTickers.size()); - gateioTickers.forEach( - (currencyPairString, gateioTicker) -> { - String[] currencyPairStringSplit = currencyPairString.split("_"); - CurrencyPair currencyPair = - new CurrencyPair( - Currency.getInstance(currencyPairStringSplit[0].toUpperCase()), - Currency.getInstance(currencyPairStringSplit[1].toUpperCase())); - adaptedTickers.put(currencyPair, GateioAdapters.adaptTicker(currencyPair, gateioTicker)); - }); - - return adaptedTickers; - } - - public GateioTicker getBTERTicker(String tradableIdentifier, String currency) throws IOException { - - GateioTicker gateioTicker = - gateio.getTicker(tradableIdentifier.toLowerCase(), currency.toLowerCase()); - - return handleResponse(gateioTicker); + public List getGateioTickers(Instrument instrument) throws IOException { + return gateio.getTickers(GateioAdapters.toString(instrument)); } public GateioTradeHistory getBTERTradeHistory(String tradeableIdentifier, String currency) diff --git a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioMarketDataServiceTest.java b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioMarketDataServiceTest.java index 6861584ea98..d14225db360 100644 --- a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioMarketDataServiceTest.java +++ b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioMarketDataServiceTest.java @@ -1,6 +1,12 @@ package org.knowm.xchange.gateio.service; -import static org.assertj.core.api.Assertions.assertThat; +import org.junit.jupiter.api.Test; +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.trade.LimitOrder; +import org.knowm.xchange.gateio.GateioExchangeWiremock; import java.io.IOException; import java.math.BigDecimal; @@ -8,12 +14,8 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; -import org.junit.jupiter.api.Test; -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.trade.LimitOrder; -import org.knowm.xchange.gateio.GateioExchangeWiremock; + +import static org.assertj.core.api.Assertions.assertThat; public class GateioMarketDataServiceTest extends GateioExchangeWiremock { @@ -52,4 +54,34 @@ void getOrderBook_valid() throws IOException { .ignoringFieldsMatchingRegexes(".*userReference") .isEqualTo(expected); } + + + @Test + void getTicker_valid() throws IOException { + var actual = gateioMarketDataService.getTicker(CurrencyPair.BTC_USDT); + + var expected = new Ticker.Builder() + .instrument(CurrencyPair.BTC_USDT) + .last(new BigDecimal("26028.7")) + .ask(new BigDecimal("26026.8")) + .bid(new BigDecimal("26026.7")) + .high(new BigDecimal("26202.4")) + .low(new BigDecimal("25606.3")) + .volume(new BigDecimal("4726.066213526")) + .quoteVolume(new BigDecimal("122407105.4829")) + .percentageChange(new BigDecimal("1.1")) + .build(); + + assertThat(actual).usingRecursiveComparison().isEqualTo(expected); + } + + + @Test + void getTickers_valid() throws IOException { + var actual = gateioMarketDataService.getTickers(null); + + assertThat(actual).hasSize(2); + } + + } diff --git a/xchange-gateio-v4/src/test/resources/__files/api_v4_spot_tickers.json b/xchange-gateio-v4/src/test/resources/__files/api_v4_spot_tickers.json new file mode 100644 index 00000000000..2608edf1357 --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/__files/api_v4_spot_tickers.json @@ -0,0 +1,28 @@ +[ + { + "currency_pair": "BTC_USDT", + "last": "26019.8", + "lowest_ask": "26019.9", + "highest_bid": "26019.8", + "change_percentage": "1.09", + "change_utc0": "0.36", + "change_utc8": "1.04", + "base_volume": "4722.912133756", + "quote_volume": "122324034.68892", + "high_24h": "26202.4", + "low_24h": "25606.3" + }, + { + "currency_pair": "ETH_USDT", + "last": "1752.96", + "lowest_ask": "1752.97", + "highest_bid": "1752.96", + "change_percentage": "0.24", + "change_utc0": "0", + "change_utc8": "0.66", + "base_volume": "34842.614438438", + "quote_volume": "60887901.935971", + "high_24h": "1777.84", + "low_24h": "1719.5" + } +] \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/resources/__files/api_v4_spot_tickers_btc-usdt.json b/xchange-gateio-v4/src/test/resources/__files/api_v4_spot_tickers_btc-usdt.json new file mode 100644 index 00000000000..b0f99c48378 --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/__files/api_v4_spot_tickers_btc-usdt.json @@ -0,0 +1,13 @@ +[ + { + "currency_pair": "BTC_USDT", + "last": "26028.7", + "lowest_ask": "26026.8", + "highest_bid": "26026.7", + "change_percentage": "1.1", + "base_volume": "4726.066213526", + "quote_volume": "122407105.4829", + "high_24h": "26202.4", + "low_24h": "25606.3" + } +] \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_tickers.json b/xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_tickers.json new file mode 100644 index 00000000000..8ca4adae167 --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_tickers.json @@ -0,0 +1,15 @@ +{ + "id" : "b2066635-52eb-404f-880b-0d0b6f6714f3", + "name" : "api_v4_spot_tickers", + "request" : { + "url" : "/api/v4/spot/tickers", + "method" : "GET" + }, + "response" : { + "status" : 200, + "bodyFileName" : "api_v4_spot_tickers.json" + }, + "uuid" : "b2066635-52eb-404f-880b-0d0b6f6714f3", + "persistent" : true, + "insertionIndex" : 26 +} \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_tickers_btc-usdt.json b/xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_tickers_btc-usdt.json new file mode 100644 index 00000000000..af9e50793f5 --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_tickers_btc-usdt.json @@ -0,0 +1,15 @@ +{ + "id" : "9330316c-b079-4bea-9c63-186a5d5bc943", + "name" : "api_v4_spot_tickers", + "request" : { + "url" : "/api/v4/spot/tickers?currency_pair=BTC_USDT", + "method" : "GET" + }, + "response" : { + "status" : 200, + "bodyFileName" : "api_v4_spot_tickers_btc-usdt.json" + }, + "uuid" : "9330316c-b079-4bea-9c63-186a5d5bc943", + "persistent" : true, + "insertionIndex" : 27 +} \ No newline at end of file From 90499c087382656518c3159e1e6e24d803642ff1 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Mon, 12 Jun 2023 13:29:19 +0200 Subject: [PATCH 043/159] [gateio-v4] Code cleanup --- .../java/org/knowm/xchange/gateio/Gateio.java | 29 +- .../knowm/xchange/gateio/GateioAdapters.java | 56 +- .../knowm/xchange/gateio/GateioExchange.java | 31 +- .../org/knowm/xchange/gateio/GateioUtils.java | 15 - .../gateio/dto/GateioBaseResponse.java | 32 - .../xchange/gateio/dto/GateioOrderType.java | 30 - .../dto/marketdata/GateioTradeHistory.java | 104 -- .../gateio/dto/trade/GateioOpenOrder.java | 116 --- .../gateio/dto/trade/GateioOpenOrders.java | 38 - .../gateio/dto/trade/GateioOrderStatus.java | 162 ---- .../dto/trade/GateioPlaceOrderReturn.java | 30 - .../xchange/gateio/dto/trade/GateioTrade.java | 122 --- .../dto/trade/GateioTradeHistoryReturn.java | 88 -- .../gateio/service/GateioBaseService.java | 11 - .../service/GateioMarketDataService.java | 21 - .../service/GateioMarketDataServiceRaw.java | 24 +- .../gateio/service/GateioTradeServiceRaw.java | 13 +- .../src/main/resources/gateio.json | 902 +----------------- 18 files changed, 29 insertions(+), 1795 deletions(-) delete mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioUtils.java delete mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/GateioBaseResponse.java delete mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/GateioOrderType.java delete mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioTradeHistory.java delete mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/GateioOpenOrder.java delete mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/GateioOpenOrders.java delete mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/GateioOrderStatus.java delete mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/GateioPlaceOrderReturn.java delete mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/GateioTrade.java delete mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/GateioTradeHistoryReturn.java 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 52b00bf03e4..90f312c031a 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 @@ -8,32 +8,17 @@ import java.io.IOException; import java.util.List; -@Path("") +@Path("api/v4") @Produces(MediaType.APPLICATION_JSON) public interface Gateio { @GET - @Path("api2/1/tradeHistory/{ident}_{currency}") - GateioTradeHistory getTradeHistory( - @PathParam("ident") String tradeableIdentifier, @PathParam("currency") String currency) - throws IOException; - - @GET - @Path("api2/1/tradeHistory/{ident}_{currency}/{tradeId}") - GateioTradeHistory getTradeHistorySince( - @PathParam("ident") String tradeableIdentifier, - @PathParam("currency") String currency, - @PathParam("tradeId") String tradeId) - throws IOException; - - - @GET - @Path("api/v4/spot/currencies") + @Path("spot/currencies") List getCurrencies() throws IOException, GateioException; @GET - @Path("api/v4/spot/order_book") + @Path("spot/order_book") GateioOrderBook getOrderBook( @QueryParam("currency_pair") String currencyPair, @QueryParam("with_id") Boolean withId @@ -41,22 +26,22 @@ GateioOrderBook getOrderBook( @GET - @Path("api/v4/wallet/currency_chains") + @Path("wallet/currency_chains") List getCurrencyChains(@QueryParam("currency") String currency) throws IOException, GateioException; @GET - @Path("api/v4/spot/currency_pairs") + @Path("spot/currency_pairs") List getCurrencyPairDetails() throws IOException, GateioException; @GET - @Path("api/v4/spot/currency_pairs/{currency_pair}") + @Path("spot/currency_pairs/{currency_pair}") GateioCurrencyPairDetails getCurrencyPairDetails(@PathParam("currency_pair") String currencyPair) throws IOException, GateioException; @GET - @Path("api/v4/spot/tickers") + @Path("spot/tickers") List getTickers(@QueryParam("currency_pair") String currencyPair) throws IOException, GateioException; diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java index ab1d5afb553..a3a2c2df92e 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java @@ -8,24 +8,17 @@ 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.marketdata.Trade; -import org.knowm.xchange.dto.marketdata.Trades; -import org.knowm.xchange.dto.marketdata.Trades.TradeSortType; import org.knowm.xchange.dto.meta.InstrumentMetaData; import org.knowm.xchange.dto.trade.LimitOrder; import org.knowm.xchange.dto.trade.MarketOrder; -import org.knowm.xchange.gateio.dto.GateioOrderType; import org.knowm.xchange.gateio.dto.account.GateioOrder; import org.knowm.xchange.gateio.dto.account.GateioWithdrawalRequest; import org.knowm.xchange.gateio.dto.marketdata.GateioCurrencyPairDetails; import org.knowm.xchange.gateio.dto.marketdata.GateioOrderBook; import org.knowm.xchange.gateio.dto.marketdata.GateioTicker; -import org.knowm.xchange.gateio.dto.marketdata.GateioTradeHistory; import org.knowm.xchange.gateio.service.params.DefaultGateioWithdrawFundsParams; import org.knowm.xchange.instrument.Instrument; -import org.knowm.xchange.utils.DateUtils; -import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Locale; @@ -35,11 +28,6 @@ @UtilityClass public class GateioAdapters { - public CurrencyPair adaptCurrencyPair(String pair) { - final String[] currencies = pair.toUpperCase().split("_"); - return new CurrencyPair(currencies[0], currencies[1]); - } - public String toString(Currency currency) { return currency.getCurrencyCode(); @@ -70,7 +58,6 @@ public OrderBook toOrderBook(GateioOrderBook gateioOrderBook, Instrument instrum .map(priceSizeEntry -> new LimitOrder(OrderType.ASK, priceSizeEntry.getSize(), instrument, null, null, priceSizeEntry.getPrice())) .collect(Collectors.toList()); - List bids = gateioOrderBook.getBids().stream() .map(priceSizeEntry -> new LimitOrder(OrderType.BID, priceSizeEntry.getSize(), instrument, null, null, priceSizeEntry.getPrice())) .collect(Collectors.toList()); @@ -79,46 +66,6 @@ public OrderBook toOrderBook(GateioOrderBook gateioOrderBook, Instrument instrum } - public OrderType adaptOrderType(GateioOrderType cryptoTradeOrderType) { - return (cryptoTradeOrderType.equals(GateioOrderType.BUY)) ? OrderType.BID : OrderType.ASK; - } - - public Trade adaptTrade( - GateioTradeHistory.GateioPublicTrade trade, CurrencyPair currencyPair) { - - OrderType orderType = adaptOrderType(trade.getType()); - Date timestamp = DateUtils.fromMillisUtc(trade.getDate() * 1000); - - return new Trade.Builder() - .type(orderType) - .originalAmount(trade.getAmount()) - .currencyPair(currencyPair) - .price(trade.getPrice()) - .timestamp(timestamp) - .id(trade.getTradeId()) - .build(); - } - - public Trades adaptTrades(GateioTradeHistory tradeHistory, CurrencyPair currencyPair) { - - List tradeList = new ArrayList<>(); - long lastTradeId = 0; - for (GateioTradeHistory.GateioPublicTrade trade : tradeHistory.getTrades()) { - String tradeIdString = trade.getTradeId(); - if (!tradeIdString.isEmpty()) { - long tradeId = Long.valueOf(tradeIdString); - if (tradeId > lastTradeId) { - lastTradeId = tradeId; - } - } - Trade adaptedTrade = adaptTrade(trade, currencyPair); - tradeList.add(adaptedTrade); - } - - return new Trades(tradeList, lastTradeId, TradeSortType.SortByTimestamp); - } - - public InstrumentMetaData toInstrumentMetaData(GateioCurrencyPairDetails gateioCurrencyPairDetails) { return new InstrumentMetaData.Builder() .tradingFee(gateioCurrencyPairDetails.getFee()) @@ -159,7 +106,7 @@ public OrderStatus toOrderStatus(String gateioOrderStatus) { public GateioOrder toGateioOrder(MarketOrder marketOrder) { - GateioOrder gateioOrder = GateioOrder.builder() + return GateioOrder.builder() .currencyPair(toString(marketOrder.getInstrument())) .side(toString(marketOrder.getType())) .clientOrderId(marketOrder.getUserReference()) @@ -168,7 +115,6 @@ public GateioOrder toGateioOrder(MarketOrder marketOrder) { .timeInForce("ioc") .amount(marketOrder.getOriginalAmount()) .build(); - return gateioOrder; } diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioExchange.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioExchange.java index d97ff74d1ef..5225fbab925 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioExchange.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioExchange.java @@ -1,10 +1,6 @@ package org.knowm.xchange.gateio; -import java.io.IOException; -import java.util.Map; -import java.util.concurrent.TimeUnit; import org.knowm.xchange.BaseExchange; -import org.knowm.xchange.Exchange; import org.knowm.xchange.ExchangeSpecification; import org.knowm.xchange.dto.meta.ExchangeMetaData; import org.knowm.xchange.dto.meta.InstrumentMetaData; @@ -15,28 +11,31 @@ import org.knowm.xchange.utils.nonce.CurrentTimeIncrementalNonceFactory; import si.mazi.rescu.SynchronizedValueFactory; -public class GateioExchange extends BaseExchange implements Exchange { +import java.io.IOException; +import java.util.Map; +import java.util.concurrent.TimeUnit; + +public class GateioExchange extends BaseExchange { - private final SynchronizedValueFactory nonceFactory = - new CurrentTimeIncrementalNonceFactory(TimeUnit.SECONDS); + private final SynchronizedValueFactory nonceFactory = new CurrentTimeIncrementalNonceFactory(TimeUnit.SECONDS); @Override protected void initServices() { - this.marketDataService = new GateioMarketDataService(this); - this.accountService = new GateioAccountService(this); - this.tradeService = new GateioTradeService(this); + marketDataService = new GateioMarketDataService(this); + accountService = new GateioAccountService(this); + tradeService = new GateioTradeService(this); } @Override public ExchangeSpecification getDefaultExchangeSpecification() { - ExchangeSpecification exchangeSpecification = new ExchangeSpecification(this.getClass()); - exchangeSpecification.setSslUri("https://api.gateio.ws"); - exchangeSpecification.setHost("gate.io"); - exchangeSpecification.setExchangeName("Gateio"); + ExchangeSpecification specification = new ExchangeSpecification(this.getClass()); + specification.setSslUri("https://api.gateio.ws"); + specification.setHost("gate.io"); + specification.setExchangeName("Gateio"); - return exchangeSpecification; + return specification; } @Override @@ -44,9 +43,9 @@ public SynchronizedValueFactory getNonceFactory() { return nonceFactory; } + @Override public void remoteInit() throws IOException { - Map instruments = ((GateioMarketDataService) marketDataService).getMetaDataByInstrument(); exchangeMetaData = new ExchangeMetaData(instruments, null, null, null, null); diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioUtils.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioUtils.java deleted file mode 100644 index 1ce3789c4bf..00000000000 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioUtils.java +++ /dev/null @@ -1,15 +0,0 @@ -package org.knowm.xchange.gateio; - -import org.knowm.xchange.currency.CurrencyPair; - -public class GateioUtils { - - public static String toPairString(CurrencyPair currencyPair) { - - String baseSymbol = currencyPair.base.getCurrencyCode().toLowerCase(); - String counterSymbol = currencyPair.counter.getCurrencyCode().toLowerCase(); - String pair = baseSymbol + "_" + counterSymbol; - - return pair; - } -} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/GateioBaseResponse.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/GateioBaseResponse.java deleted file mode 100644 index 6874cd09ccf..00000000000 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/GateioBaseResponse.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.knowm.xchange.gateio.dto; - -import com.fasterxml.jackson.annotation.JsonProperty; - -public class GateioBaseResponse { - - private final boolean result; - private final String message; - - protected GateioBaseResponse( - @JsonProperty("result") final boolean result, @JsonProperty("msg") final String message) { - - this.result = result; - this.message = message; - } - - public boolean isResult() { - - return result; - } - - public String getMessage() { - - return message; - } - - @Override - public String toString() { - - return "GateioBaseResponse [result=" + result + ", message=" + message + "]"; - } -} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/GateioOrderType.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/GateioOrderType.java deleted file mode 100644 index 22a7a971fa6..00000000000 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/GateioOrderType.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.knowm.xchange.gateio.dto; - -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.core.ObjectCodec; -import com.fasterxml.jackson.databind.DeserializationContext; -import com.fasterxml.jackson.databind.JsonDeserializer; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import java.io.IOException; -import org.knowm.xchange.gateio.dto.GateioOrderType.BTEROrderTypeDeserializer; - -@JsonDeserialize(using = BTEROrderTypeDeserializer.class) -public enum GateioOrderType { - BUY, - SELL; - - static class BTEROrderTypeDeserializer extends JsonDeserializer { - - @Override - public GateioOrderType deserialize(JsonParser jsonParser, final DeserializationContext ctxt) - throws IOException, JsonProcessingException { - - final ObjectCodec oc = jsonParser.getCodec(); - final JsonNode node = oc.readTree(jsonParser); - final String orderType = node.asText(); - return GateioOrderType.valueOf(orderType.toUpperCase()); - } - } -} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioTradeHistory.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioTradeHistory.java deleted file mode 100644 index c1b0998dc08..00000000000 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioTradeHistory.java +++ /dev/null @@ -1,104 +0,0 @@ -package org.knowm.xchange.gateio.dto.marketdata; - -import com.fasterxml.jackson.annotation.JsonProperty; -import java.math.BigDecimal; -import java.util.List; -import org.knowm.xchange.gateio.dto.GateioBaseResponse; -import org.knowm.xchange.gateio.dto.GateioOrderType; - -public class GateioTradeHistory extends GateioBaseResponse { - - private final List trades; - private final String elapsed; - - private GateioTradeHistory( - @JsonProperty("data") List trades, - @JsonProperty("result") boolean result, - @JsonProperty("elapsed") String elapsed) { - - super(result, null); - this.trades = trades; - this.elapsed = elapsed; - } - - public List getTrades() { - - return trades; - } - - public String getElapsed() { - - return elapsed; - } - - @Override - public String toString() { - - return "BTERPublicTrades [trades=" + trades + ", elapsed=" + elapsed + "]"; - } - - public static class GateioPublicTrade { - - private final long date; - private final BigDecimal price; - private final BigDecimal amount; - private final String tradeId; - private final GateioOrderType type; - - private GateioPublicTrade( - @JsonProperty("date") String date, - @JsonProperty("rate") BigDecimal price, - @JsonProperty("amount") BigDecimal amount, - @JsonProperty("tradeID") String tradeId, - @JsonProperty("timestamp") long timestamp, - @JsonProperty("type") GateioOrderType type) { - - this.date = timestamp; - this.price = price; - this.amount = amount; - this.tradeId = tradeId; - this.type = type; - } - - public long getDate() { - - return date; - } - - public BigDecimal getPrice() { - - return price; - } - - public BigDecimal getAmount() { - - return amount; - } - - public String getTradeId() { - - return tradeId; - } - - public GateioOrderType getType() { - - return type; - } - - @Override - public String toString() { - - return "BTERPublicTrade [date=" - + date - + ", price=" - + price - + ", amount=" - + amount - + ", tradeId=" - + tradeId - + ", type=" - + type - + "]"; - } - } -} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/GateioOpenOrder.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/GateioOpenOrder.java deleted file mode 100644 index 49e2c5f91dc..00000000000 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/GateioOpenOrder.java +++ /dev/null @@ -1,116 +0,0 @@ -package org.knowm.xchange.gateio.dto.trade; - -import com.fasterxml.jackson.annotation.JsonProperty; -import java.math.BigDecimal; - -public class GateioOpenOrder { - - private String timestamp; - - private String total; - - private BigDecimal amount; - - private String id; - - private BigDecimal rate; - - private String status; - - private String orderNumber; - - private String type; - - private String currencyPair; - - /** Constructor */ - private GateioOpenOrder( - @JsonProperty("timestamp") String timestamp, - @JsonProperty("total") String total, - @JsonProperty("amount") BigDecimal amount, - @JsonProperty("id") String id, - @JsonProperty("rate") BigDecimal rate, - @JsonProperty("status") String status, - @JsonProperty("orderNumber") String orderNumber, - @JsonProperty("type") String type, - @JsonProperty("currencyPair") String currencyPair) { - this.timestamp = timestamp; - this.total = total; - this.amount = amount; - this.id = id; - this.rate = rate; - this.status = status; - this.orderNumber = orderNumber; - this.type = type; - this.currencyPair = currencyPair; - } - - public String getTimestamp() { - return timestamp; - } - - public String getTotal() { - return total; - } - - public BigDecimal getAmount() { - return amount; - } - - public String getId() { - return id; - } - - public BigDecimal getRate() { - return rate; - } - - public String getStatus() { - return status; - } - - public String getOrderNumber() { - return orderNumber; - } - - public String getType() { - return type; - } - - public String getCurrencyPair() { - return currencyPair; - } - - @Override - public String toString() { - return "GateioOpenOrder{" - + "timestamp='" - + timestamp - + '\'' - + ", total='" - + total - + '\'' - + ", amount='" - + amount - + '\'' - + ", id='" - + id - + '\'' - + ", rate='" - + rate - + '\'' - + ", status='" - + status - + '\'' - + ", orderNumber='" - + orderNumber - + '\'' - + ", type='" - + type - + '\'' - + ", currencyPair='" - + currencyPair - + '\'' - + '}'; - } -} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/GateioOpenOrders.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/GateioOpenOrders.java deleted file mode 100644 index bcb0f6ccbea..00000000000 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/GateioOpenOrders.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.knowm.xchange.gateio.dto.trade; - -import com.fasterxml.jackson.annotation.JsonProperty; -import java.util.List; -import org.knowm.xchange.gateio.dto.GateioBaseResponse; - -/** Created by David Henry on 2/19/14. */ -public class GateioOpenOrders extends GateioBaseResponse { - - private final List orders; - - /** - * Constructor - * - * @param result - * @param orders - * @param msg - */ - public GateioOpenOrders( - @JsonProperty("result") Boolean result, - @JsonProperty("orders") List orders, - @JsonProperty("msg") String msg) { - - super(result, msg); - this.orders = orders; - } - - public List getOrders() { - - return orders; - } - - @Override - public String toString() { - - return "BTEROpenOrdersReturn [orders=" + orders + "]"; - } -} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/GateioOrderStatus.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/GateioOrderStatus.java deleted file mode 100644 index 1db94be74ff..00000000000 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/GateioOrderStatus.java +++ /dev/null @@ -1,162 +0,0 @@ -package org.knowm.xchange.gateio.dto.trade; - -import com.fasterxml.jackson.annotation.JsonProperty; -import java.math.BigDecimal; -import org.knowm.xchange.currency.CurrencyPair; -import org.knowm.xchange.gateio.GateioAdapters; -import org.knowm.xchange.gateio.dto.GateioBaseResponse; -import org.knowm.xchange.gateio.dto.GateioOrderType; - -/** Created by David Henry on 2/19/14. */ -public class GateioOrderStatus extends GateioBaseResponse { - - private final BTEROrderStatusInfo orderStatusInfo; - - private GateioOrderStatus( - @JsonProperty("order") BTEROrderStatusInfo orderStatusInfo, - @JsonProperty("result") boolean result, - @JsonProperty("message") String msg) { - - super(result, msg); - this.orderStatusInfo = orderStatusInfo; - } - - public String getOrderNumber() { - - return orderStatusInfo.getOrderNumber(); - } - - public String getStatus() { - - return orderStatusInfo.getStatus(); - } - - public CurrencyPair getCurrencyPair() { - - return orderStatusInfo.getCurrencyPair(); - } - - public GateioOrderType getType() { - - return orderStatusInfo.getType(); - } - - public BigDecimal getRate() { - - return orderStatusInfo.getRate(); - } - - public BigDecimal getAmount() { - - return orderStatusInfo.getAmount(); - } - - public BigDecimal getInitialRate() { - - return orderStatusInfo.getInitialRate(); - } - - public BigDecimal getInitialAmount() { - - return orderStatusInfo.getInitialAmount(); - } - - public String toString() { - - return orderStatusInfo.toString(); - } - - public static class BTEROrderStatusInfo { - - private final String orderNumber; - private final String status; - private final CurrencyPair currencyPair; - private final GateioOrderType type; - private final BigDecimal rate; - private final BigDecimal amount; - private final BigDecimal initialRate; - private final BigDecimal initialAmount; - - private BTEROrderStatusInfo( - @JsonProperty("orderNumber") String orderNumber, - @JsonProperty("status") String status, - @JsonProperty("currencyPair") String currencyPair, - @JsonProperty("type") GateioOrderType type, - @JsonProperty("rate") BigDecimal rate, - @JsonProperty("amount") BigDecimal amount, - @JsonProperty("initialRate") BigDecimal initialRate, - @JsonProperty("initialAmount") BigDecimal initialAmount) { - - this.orderNumber = orderNumber; - this.status = status; - this.currencyPair = GateioAdapters.adaptCurrencyPair(currencyPair); - this.type = type; - this.rate = rate; - this.amount = amount; - this.initialRate = initialRate; - this.initialAmount = initialAmount; - } - - public String getOrderNumber() { - - return orderNumber; - } - - public String getStatus() { - - return status; - } - - public CurrencyPair getCurrencyPair() { - - return currencyPair; - } - - public GateioOrderType getType() { - - return type; - } - - public BigDecimal getRate() { - - return rate; - } - - public BigDecimal getAmount() { - - return amount; - } - - public BigDecimal getInitialRate() { - - return initialRate; - } - - public BigDecimal getInitialAmount() { - - return initialAmount; - } - - @Override - public String toString() { - - return "BTEROrderStatusInfo [id=" - + orderNumber - + ", status=" - + status - + ", currencyPair=" - + currencyPair - + ", type=" - + type - + ", rate=" - + rate - + ", amount=" - + amount - + ", initialRate=" - + initialRate - + ", initialAmount=" - + initialAmount - + "]"; - } - } -} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/GateioPlaceOrderReturn.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/GateioPlaceOrderReturn.java deleted file mode 100644 index 5d1f5fc96cd..00000000000 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/GateioPlaceOrderReturn.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.knowm.xchange.gateio.dto.trade; - -import com.fasterxml.jackson.annotation.JsonProperty; -import org.knowm.xchange.gateio.dto.GateioBaseResponse; - -public class GateioPlaceOrderReturn extends GateioBaseResponse { - - private final String orderNumber; - - /** Constructor */ - private GateioPlaceOrderReturn( - @JsonProperty("result") boolean result, - @JsonProperty("orderNumber") String orderNumber, - @JsonProperty("msg") String message) { - - super(result, message); - this.orderNumber = orderNumber; - } - - public String getOrderId() { - - return orderNumber; - } - - @Override - public String toString() { - - return "GateioPlaceOrderReturn [orderNumber=" + orderNumber + "]"; - } -} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/GateioTrade.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/GateioTrade.java deleted file mode 100644 index ff2b388d1d8..00000000000 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/GateioTrade.java +++ /dev/null @@ -1,122 +0,0 @@ -package org.knowm.xchange.gateio.dto.trade; - -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonPropertyOrder; -import java.math.BigDecimal; -import java.util.HashMap; -import java.util.Map; -import javax.annotation.Generated; -import org.knowm.xchange.gateio.dto.GateioOrderType; - -@JsonInclude(JsonInclude.Include.NON_NULL) -@Generated("org.jsonschema2pojo") -@JsonPropertyOrder({"tradeID", "orderNumber", "pair", "type", "rate", "amount", "time_unix"}) -public class GateioTrade { - - @JsonProperty("tradeID") - private String tradeID; - - @JsonProperty("orderNumber") - private String orderNumber; - - @JsonProperty("pair") - private String pair; - - @JsonProperty("type") - private GateioOrderType type; - - @JsonProperty("rate") - private BigDecimal rate; - - @JsonProperty("amount") - private BigDecimal amount; - - @JsonProperty("time_unix") - private long timeUnix; - - @JsonIgnore private Map additionalProperties = new HashMap(); - - @JsonProperty("tradeID") - public String getTradeID() { - return tradeID; - } - - @JsonProperty("tradeID") - public void setTradeID(String tradeID) { - this.tradeID = tradeID; - } - - @JsonProperty("orderNumber") - public String getOrderNumber() { - return orderNumber; - } - - @JsonProperty("orderNumber") - public void setOrderNumber(String orderNumber) { - this.orderNumber = orderNumber; - } - - @JsonProperty("pair") - public String getPair() { - return pair; - } - - @JsonProperty("pair") - public void setPair(String pair) { - this.pair = pair; - } - - @JsonProperty("type") - public GateioOrderType getType() { - return type; - } - - @JsonProperty("type") - public void setType(GateioOrderType type) { - this.type = type; - } - - @JsonProperty("rate") - public BigDecimal getRate() { - return rate; - } - - @JsonProperty("rate") - public void setRate(BigDecimal rate) { - this.rate = rate; - } - - @JsonProperty("amount") - public BigDecimal getAmount() { - return amount; - } - - @JsonProperty("amount") - public void setAmount(BigDecimal amount) { - this.amount = amount; - } - - @JsonProperty("time_unix") - public long getTimeUnix() { - return timeUnix; - } - - @JsonProperty("time_unix") - public void setTimeUnix(long timeUnix) { - this.timeUnix = timeUnix; - } - - @JsonAnyGetter - public Map getAdditionalProperties() { - return this.additionalProperties; - } - - @JsonAnySetter - public void setAdditionalProperty(String name, Object value) { - this.additionalProperties.put(name, value); - } -} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/GateioTradeHistoryReturn.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/GateioTradeHistoryReturn.java deleted file mode 100644 index dbd3c802ba9..00000000000 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/GateioTradeHistoryReturn.java +++ /dev/null @@ -1,88 +0,0 @@ -package org.knowm.xchange.gateio.dto.trade; - -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonPropertyOrder; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import javax.annotation.Generated; -import org.knowm.xchange.gateio.dto.GateioBaseResponse; - -@JsonInclude(JsonInclude.Include.NON_NULL) -@Generated("org.jsonschema2pojo") -@JsonPropertyOrder({"result", "trades", "msg"}) -public class GateioTradeHistoryReturn extends GateioBaseResponse { - - @JsonProperty("result") - private Boolean result; - - @JsonProperty("trades") - private List trades = new ArrayList(); - - @JsonProperty("msg") - private String msg; - - @JsonIgnore private Map additionalProperties = new HashMap(); - - protected GateioTradeHistoryReturn( - @JsonProperty("result") boolean result, - @JsonProperty("trades") List trades, - @JsonProperty("msg") String message) { - - super(result, message); - this.trades = trades; - } - - @JsonProperty("result") - public Boolean getResult() { - - return result; - } - - @JsonProperty("result") - public void setResult(Boolean result) { - - this.result = result; - } - - @JsonProperty("trades") - public List getTrades() { - - return trades; - } - - @JsonProperty("trades") - public void setTrades(List trades) { - - this.trades = trades; - } - - @JsonProperty("msg") - public String getMsg() { - - return msg; - } - - @JsonProperty("msg") - public void setMsg(String msg) { - - this.msg = msg; - } - - @JsonAnyGetter - public Map getAdditionalProperties() { - - return this.additionalProperties; - } - - @JsonAnySetter - public void setAdditionalProperty(String name, Object value) { - - this.additionalProperties.put(name, value); - } -} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioBaseService.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioBaseService.java index bb6d6db2f4f..4dd4a306b25 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioBaseService.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioBaseService.java @@ -1,12 +1,10 @@ package org.knowm.xchange.gateio.service; import org.knowm.xchange.client.ExchangeRestProxyBuilder; -import org.knowm.xchange.exceptions.ExchangeException; import org.knowm.xchange.gateio.Gateio; import org.knowm.xchange.gateio.GateioExchange; import org.knowm.xchange.gateio.GateioV4Authenticated; import org.knowm.xchange.gateio.config.GateioJacksonObjectMapperFactory; -import org.knowm.xchange.gateio.dto.GateioBaseResponse; import org.knowm.xchange.service.BaseExchangeService; import org.knowm.xchange.service.BaseService; import si.mazi.rescu.ParamsDigest; @@ -37,13 +35,4 @@ public GateioBaseService(GateioExchange exchange) { GateioV4Digest.createInstance(exchange.getExchangeSpecification().getSecretKey()); } - protected R handleResponse(R response) { - - if (!response.isResult()) { - throw new ExchangeException(response.getMessage()); - } - - return response; - } - } 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 63562566bd5..b12a77103b1 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 @@ -4,7 +4,6 @@ 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.marketdata.Trades; import org.knowm.xchange.dto.meta.InstrumentMetaData; import org.knowm.xchange.gateio.GateioAdapters; import org.knowm.xchange.gateio.GateioErrorAdapter; @@ -13,7 +12,6 @@ import org.knowm.xchange.gateio.dto.marketdata.GateioCurrencyPairDetails; import org.knowm.xchange.gateio.dto.marketdata.GateioOrderBook; import org.knowm.xchange.gateio.dto.marketdata.GateioTicker; -import org.knowm.xchange.gateio.dto.marketdata.GateioTradeHistory; import org.knowm.xchange.instrument.Instrument; import org.knowm.xchange.service.marketdata.MarketDataService; import org.knowm.xchange.service.marketdata.params.Params; @@ -26,7 +24,6 @@ public class GateioMarketDataService extends GateioMarketDataServiceRaw implements MarketDataService { public GateioMarketDataService(GateioExchange exchange) { - super(exchange); } @@ -70,26 +67,8 @@ public OrderBook getOrderBook(CurrencyPair currencyPair, Object... args) throws @Override public OrderBook getOrderBook(Instrument instrument, Object... args) throws IOException { - GateioOrderBook gateioOrderBook = getGateioOrderBook(instrument); - return GateioAdapters.toOrderBook(gateioOrderBook, instrument); - - } - - @Override - public Trades getTrades(CurrencyPair currencyPair, Object... args) throws IOException { - - GateioTradeHistory tradeHistory = - (args != null && args.length > 0 && args[0] != null && args[0] instanceof String) - ? super.getBTERTradeHistorySince( - currencyPair.base.getCurrencyCode(), - currencyPair.counter.getCurrencyCode(), - (String) args[0]) - : super.getBTERTradeHistory( - currencyPair.base.getCurrencyCode(), currencyPair.counter.getCurrencyCode()); - - return GateioAdapters.adaptTrades(tradeHistory, currencyPair); } 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 ed34a1c5e7d..5c8bcfc19b5 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 @@ -11,37 +11,15 @@ public class GateioMarketDataServiceRaw extends GateioBaseService { - /** - * Constructor - * - * @param exchange - */ public GateioMarketDataServiceRaw(GateioExchange exchange) { - super(exchange); } + public List getGateioTickers(Instrument instrument) throws IOException { return gateio.getTickers(GateioAdapters.toString(instrument)); } - public GateioTradeHistory getBTERTradeHistory(String tradeableIdentifier, String currency) - throws IOException { - - GateioTradeHistory tradeHistory = gateio.getTradeHistory(tradeableIdentifier, currency); - - return handleResponse(tradeHistory); - } - - public GateioTradeHistory getBTERTradeHistorySince( - String tradeableIdentifier, String currency, String tradeId) throws IOException { - - GateioTradeHistory tradeHistory = - gateio.getTradeHistorySince(tradeableIdentifier, currency, tradeId); - - return handleResponse(tradeHistory); - } - public List getCurrencies() throws IOException { return gateio.getCurrencies(); diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeServiceRaw.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeServiceRaw.java index 23d758c6317..c7e8a54be23 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeServiceRaw.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeServiceRaw.java @@ -1,8 +1,5 @@ package org.knowm.xchange.gateio.service; -import java.io.IOException; -import java.util.List; -import java.util.Set; import org.apache.commons.lang3.Validate; import org.knowm.xchange.dto.Order.OrderStatus; import org.knowm.xchange.gateio.GateioAdapters; @@ -10,15 +7,13 @@ import org.knowm.xchange.gateio.dto.account.GateioOrder; import org.knowm.xchange.instrument.Instrument; +import java.io.IOException; +import java.util.List; +import java.util.Set; + public class GateioTradeServiceRaw extends GateioBaseService { - /** - * Constructor - * - * @param exchange - */ public GateioTradeServiceRaw(GateioExchange exchange) { - super(exchange); } diff --git a/xchange-gateio-v4/src/main/resources/gateio.json b/xchange-gateio-v4/src/main/resources/gateio.json index 4971fc66d4f..9e26dfeeb6e 100644 --- a/xchange-gateio-v4/src/main/resources/gateio.json +++ b/xchange-gateio-v4/src/main/resources/gateio.json @@ -1,901 +1 @@ -{ - "currency_pairs": { - "XTC/CNY": { - "trading_fee": 0.2, - "min_amount": 0.5, - "price_scale": 4 - }, - "BUK/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "CDC/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "LTS/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "SFR/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "UNITY/NXT": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 2 - }, - "FTC/CNY": { - "trading_fee": 0.2, - "min_amount": 0.5, - "price_scale": 3 - }, - "VRC/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "NXTTY/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "CNC/CNY": { - "trading_fee": 0.2, - "min_amount": 0.5, - "price_scale": 4 - }, - "RED/LTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "BITCNY/CNY": { - "trading_fee": 0.2, - "min_amount": 0.5, - "price_scale": 4 - }, - "FRC/CNY": { - "trading_fee": 0.2, - "min_amount": 0.5, - "price_scale": 4 - }, - "ETH/CNY": { - "trading_fee": 0.2, - "min_amount": 0.5, - "price_scale": 2 - }, - "BTCD/NXT": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "NET/CNY": { - "trading_fee": 0.2, - "min_amount": 0.5, - "price_scale": 5 - }, - "DNS/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "BTS/CNY": { - "trading_fee": 0.2, - "min_amount": 0.5, - "price_scale": 4 - }, - "NFD/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "EXC/CNY": { - "trading_fee": 0.2, - "min_amount": 0.5, - "price_scale": 4 - }, - "BITGLD/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "TBC/CNY": { - "trading_fee": 0.2, - "min_amount": 0.5, - "price_scale": 4 - }, - "TAG/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 7 - }, - "BAY/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "NET/LTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "MAX/CNY": { - "trading_fee": 0.2, - "min_amount": 0.5, - "price_scale": 3 - }, - "VRC/CNY": { - "trading_fee": 0.2, - "min_amount": 0.5, - "price_scale": 4 - }, - "DOGE/USD": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "SPARK/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "CNC/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "FTC/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "NXT/USD": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 4 - }, - "NSR/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "NXTTY/CNY": { - "trading_fee": 0.2, - "min_amount": 0.5, - "price_scale": 4 - }, - "SRC/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "DAO/CNY": { - "trading_fee": 0.2, - "min_amount": 0.5, - "price_scale": 4 - }, - "NFD/LTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "NET/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "DICE/NXT": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "COMM/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "CENT/CNY": { - "trading_fee": 0.2, - "min_amount": 0.5, - "price_scale": 8 - }, - "TIX/LTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "XCN/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "CENT/LTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "DICE/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "AUR/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "SRC/CNY": { - "trading_fee": 0.2, - "min_amount": 0.5, - "price_scale": 4 - }, - "DGC/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "MMC/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "PPC/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 5 - }, - "XEM/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "LTC/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 5 - }, - "NODE/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "TIX/CNY": { - "trading_fee": 0.2, - "min_amount": 0.5, - "price_scale": 7 - }, - "NAS/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "TOKEN/NXT": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "CMC/CNY": { - "trading_fee": 0.2, - "min_amount": 0.5, - "price_scale": 4 - }, - "WDC/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 7 - }, - "EXC/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "FRSH/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "GEMZ/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "SWIFT/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "MGW/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "TOKEN/CNY": { - "trading_fee": 0.2, - "min_amount": 0.5, - "price_scale": 4 - }, - "ROX/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "PTS/CNY": { - "trading_fee": 0.2, - "min_amount": 0.5, - "price_scale": 6 - }, - "QRK/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "TOKEN/BTCD": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "RED/CNY": { - "trading_fee": 0.2, - "min_amount": 0.5, - "price_scale": 4 - }, - "CMC/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "BBR/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "BQC/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 7 - }, - "PRT/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "NBT/CNY": { - "trading_fee": 0.2, - "min_amount": 0.5, - "price_scale": 3 - }, - "MEC/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "DTC/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "XPM/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "FLT/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "TOKEN/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "DGC/CNY": { - "trading_fee": 0.2, - "min_amount": 0.5, - "price_scale": 4 - }, - "ARCH/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "C2/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "MMC/CNY": { - "trading_fee": 0.2, - "min_amount": 0.5, - "price_scale": 4 - }, - "ZET/CNY": { - "trading_fee": 0.2, - "min_amount": 0.5, - "price_scale": 4 - }, - "XCR/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "DOGE/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "XCP/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 5 - }, - "BQC/CNY": { - "trading_fee": 0.2, - "min_amount": 0.5, - "price_scale": 4 - }, - "AC/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 7 - }, - "NMC/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "QRK/CNY": { - "trading_fee": 0.2, - "min_amount": 0.5, - "price_scale": 7 - }, - "BTQ/CNY": { - "trading_fee": 0.5, - "min_amount": 0.5, - "price_scale": 3 - }, - "ZCC/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "PTS/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "MSC/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "DASH/CNY": { - "trading_fee": 0.2, - "min_amount": 0.5, - "price_scale": 2 - }, - "BTB/CNY": { - "trading_fee": 0.2, - "min_amount": 0.5, - "price_scale": 2 - }, - "XCH/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "ZET/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "IFC/CNY": { - "trading_fee": 0.2, - "min_amount": 0.5, - "price_scale": 7 - }, - "NBT/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 6 - }, - "IFC/LTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "QORA/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "BTS/NXT": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 3 - }, - "KDC/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "VIA/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "NXT/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 7 - }, - "DVC/LTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "LTC/CNY": { - "trading_fee": 0.2, - "min_amount": 0.5, - "price_scale": 2 - }, - "NEC/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "ATOMIC/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "BLK/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "PPC/CNY": { - "trading_fee": 0.2, - "min_amount": 0.5, - "price_scale": 2 - }, - "XPM/CNY": { - "trading_fee": 0.2, - "min_amount": 0.5, - "price_scale": 4 - }, - "LTC/USD": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 4 - }, - "DVC/CNY": { - "trading_fee": 0.2, - "min_amount": 0.5, - "price_scale": 6 - }, - "ZCC/CNY": { - "trading_fee": 0.2, - "min_amount": 0.5, - "price_scale": 4 - }, - "WDC/CNY": { - "trading_fee": 0.2, - "min_amount": 0.5, - "price_scale": 4 - }, - "NMC/CNY": { - "trading_fee": 0.2, - "min_amount": 0.5, - "price_scale": 2 - }, - "DASH/USD": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 4 - }, - "NTX/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "BITUSD/USD": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 4 - }, - "MAX/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 7 - }, - "NAV/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "MRKT/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "UNITY/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 5 - }, - "FTP/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "VTC/CNY": { - "trading_fee": 0.2, - "min_amount": 0.5, - "price_scale": 2 - }, - "BTB/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 5 - }, - "CKC/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "GHOST/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "XC/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "DRKC/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "SHELL/CNY": { - "trading_fee": 0.2, - "min_amount": 0.5, - "price_scale": 3 - }, - "XCP/NXT": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "DOGE/CNY": { - "trading_fee": 0.2, - "min_amount": 0.5, - "price_scale": 5 - }, - "NXT/CNY": { - "trading_fee": 0.2, - "min_amount": 0.5, - "price_scale": 4 - }, - "TIPS/CNY": { - "trading_fee": 0.2, - "min_amount": 0.5, - "price_scale": 8 - }, - "GML/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "BLK/CNY": { - "trading_fee": 0.2, - "min_amount": 0.5, - "price_scale": 3 - }, - "YAC/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "BTS/USD": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 4 - }, - "BTC/USD": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 3 - }, - "DAO/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "TIPS/LTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "MINT/CNY": { - "trading_fee": 0.2, - "min_amount": 0.5, - "price_scale": 7 - }, - "BTCD/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "BLOCK/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "DASH/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 5 - }, - "XMR/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "VTC/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 7 - }, - "DTC/CNY": { - "trading_fee": 0.2, - "min_amount": 0.5, - "price_scale": 4 - }, - "TBC/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 6 - }, - "XTC/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "BTC/CNY": { - "trading_fee": 0.2, - "min_amount": 0.5, - "price_scale": 2 - }, - "UNITY/CNY": { - "trading_fee": 0.2, - "min_amount": 0.5, - "price_scale": 2 - }, - "MEC/CNY": { - "trading_fee": 0.2, - "min_amount": 0.5, - "price_scale": 4 - }, - "ETH/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 6 - }, - "BTC/BITUSD": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 4 - }, - "XCP/USD": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 4 - }, - "XCP/CNY": { - "trading_fee": 0.2, - "min_amount": 0.5, - "price_scale": 2 - }, - "FRC/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "YAC/CNY": { - "trading_fee": 0.2, - "min_amount": 0.5, - "price_scale": 4 - }, - "MINT/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "XMR/CNY": { - "trading_fee": 0.2, - "min_amount": 0.5, - "price_scale": 3 - }, - "SLM/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 8 - }, - "TAG/CNY": { - "trading_fee": 0.2, - "min_amount": 0.5, - "price_scale": 3 - }, - "BTS/BTC": { - "trading_fee": 0.2, - "min_amount": 0.00010, - "price_scale": 7 - } - }, - "currencies": { - "BTC": { - "scale": 8, - "withdrawal_fee": 0.002 - }, - "ETH": { - "scale": 8, - "withdrawal_fee": 0.003 - }, - "USDT": { - "scale": 8, - "withdrawal_fee": 25.0 - }, - "LTC": { - "scale": 8, - "withdrawal_fee": 0.002 - }, - "BCH": { - "scale": 8, - "withdrawal_fee": 0.0006 - }, - "BTG": { - "scale": 8, - "withdrawal_fee": 0.002 - }, - "ZEC": { - "scale": 8, - "withdrawal_fee": 0.001 - }, - "ETC": { - "scale": 8, - "withdrawal_fee": 0.010 - }, - "DASH": { - "scale": 8, - "withdrawal_fee": 0.002 - }, - "QTUM": { - "scale": 8, - "withdrawal_fee": 0.010 - }, - "DOGE": { - "scale": 8, - "withdrawal_fee": 10.0 - }, - "REP": { - "scale": 8, - "withdrawal_fee": 0.010 - }, - "BAT": { - "scale": 8, - "withdrawal_fee": 10.0 - } - }, - "public_rate_limits": null, - "private_rate_limits": null, - "share_rate_limits": false -} \ No newline at end of file +{} \ No newline at end of file From 118558a26316550db03a1e36b215dd03554722dc Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Thu, 29 Jun 2023 11:28:23 +0200 Subject: [PATCH 044/159] [gateio-v4] Add mapping of HTTP 500 --- .../xchange/gateio/GateioErrorAdapter.java | 4 +++ .../service/GateioAccountServiceRawTest.java | 31 +++++++++++-------- ...withdraw_status_internal-server-error.json | 4 +++ ...withdraw_status_internal-server-error.json | 15 +++++++++ 4 files changed, 41 insertions(+), 13 deletions(-) create mode 100644 xchange-gateio-v4/src/test/resources/__files/exceptions/api_v4_wallet_withdraw_status_internal-server-error.json create mode 100644 xchange-gateio-v4/src/test/resources/mappings/exceptions/api_v4_wallet_withdraw_status_internal-server-error.json 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 e8da85c8e6d..805b38d07d9 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 @@ -14,6 +14,7 @@ public class GateioErrorAdapter { public final String BALANCE_NOT_ENOUGH = "BALANCE_NOT_ENOUGH"; public final String TOO_FAST = "TOO_FAST"; public final String INVALID_PARAM_VALUE = "INVALID_PARAM_VALUE"; + public final String SERVER_ERROR = "SERVER_ERROR"; public ExchangeException adapt(GateioException e) { @@ -33,6 +34,9 @@ public ExchangeException adapt(GateioException e) { case TOO_FAST: return new RateLimitExceededException(e.getMessage(), e); + case SERVER_ERROR: + return new InternalServerException(e.getMessage(), e); + case INVALID_PARAM_VALUE: if (e.getMessage().contains("below minimum")) { return new OrderAmountUnderMinimumException(e.getMessage(), e); diff --git a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceRawTest.java b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceRawTest.java index 743ac0ec179..1e921dcf839 100644 --- a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceRawTest.java +++ b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceRawTest.java @@ -1,7 +1,13 @@ package org.knowm.xchange.gateio.service; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import org.junit.jupiter.api.Test; +import org.knowm.xchange.currency.Currency; +import org.knowm.xchange.exceptions.ExchangeSecurityException; +import org.knowm.xchange.exceptions.InstrumentNotValidException; +import org.knowm.xchange.exceptions.InternalServerException; +import org.knowm.xchange.gateio.GateioExchangeWiremock; +import org.knowm.xchange.gateio.dto.account.*; +import org.knowm.xchange.gateio.dto.account.GateioDepositAddress.MultichainAddress; import java.io.IOException; import java.math.BigDecimal; @@ -9,17 +15,9 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.junit.jupiter.api.Test; -import org.knowm.xchange.currency.Currency; -import org.knowm.xchange.exceptions.ExchangeSecurityException; -import org.knowm.xchange.exceptions.InstrumentNotValidException; -import org.knowm.xchange.gateio.GateioExchangeWiremock; -import org.knowm.xchange.gateio.dto.account.GateioAddressRecord; -import org.knowm.xchange.gateio.dto.account.GateioDepositAddress; -import org.knowm.xchange.gateio.dto.account.GateioDepositAddress.MultichainAddress; -import org.knowm.xchange.gateio.dto.account.GateioWithdrawStatus; -import org.knowm.xchange.gateio.dto.account.GateioWithdrawalRecord; -import org.knowm.xchange.gateio.dto.account.GateioWithdrawalRequest; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; public class GateioAccountServiceRawTest extends GateioExchangeWiremock { @@ -70,6 +68,13 @@ void http_403_exception_mapped() { } + @Test + void http_500_exception_mapped() { + assertThatExceptionOfType(InternalServerException.class) + .isThrownBy(() -> gateioAccountServiceRaw.getWithdrawStatus(Currency.getInstance("INTERNAL-SERVER-ERROR"))); + } + + @Test void invalid_currency_exception_mapped() { assertThatExceptionOfType(InstrumentNotValidException.class) diff --git a/xchange-gateio-v4/src/test/resources/__files/exceptions/api_v4_wallet_withdraw_status_internal-server-error.json b/xchange-gateio-v4/src/test/resources/__files/exceptions/api_v4_wallet_withdraw_status_internal-server-error.json new file mode 100644 index 00000000000..5cd34cdc249 --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/__files/exceptions/api_v4_wallet_withdraw_status_internal-server-error.json @@ -0,0 +1,4 @@ +{ + "label": "SERVER_ERROR", + "message": "Internal server error" +} \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/resources/mappings/exceptions/api_v4_wallet_withdraw_status_internal-server-error.json b/xchange-gateio-v4/src/test/resources/mappings/exceptions/api_v4_wallet_withdraw_status_internal-server-error.json new file mode 100644 index 00000000000..c6ea26a7c6e --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/mappings/exceptions/api_v4_wallet_withdraw_status_internal-server-error.json @@ -0,0 +1,15 @@ +{ + "id" : "000454cc-bd9d-41de-ba6e-34717cddc6ac", + "name" : "api_v4_spot_orders_internal-server-error", + "request" : { + "url" : "/api/v4/wallet/withdraw_status?currency=INTERNAL-SERVER-ERROR", + "method" : "GET" + }, + "response" : { + "status" : 500, + "bodyFileName" : "exceptions/api_v4_wallet_withdraw_status_internal-server-error.json" + }, + "uuid" : "000454cc-bd9d-41de-ba6e-34717cddc6ac", + "persistent" : true, + "insertionIndex" : 29 +} \ No newline at end of file From a6b049ac2a8a63bcc9fb6c2a559e1d5fef9ce3c8 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Fri, 28 Jul 2023 01:14:54 +0200 Subject: [PATCH 045/159] [gateio-v4] Implement limit orders --- .../knowm/xchange/gateio/GateioAdapters.java | 14 ++++++++ .../gateio/service/GateioTradeService.java | 20 ++++++++++-- .../service/GateioTradeServiceTest.java | 29 +++++++++++++---- ...v4_spot_orders-valid-limit-sell-order.json | 32 +++++++++++++++++++ ...v4_spot_orders-valid-limit-sell-order.json | 20 ++++++++++++ 5 files changed, 105 insertions(+), 10 deletions(-) create mode 100644 xchange-gateio-v4/src/test/resources/__files/api_v4_spot_orders-valid-limit-sell-order.json create mode 100644 xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_orders-valid-limit-sell-order.json diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java index a3a2c2df92e..6e43de942cf 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java @@ -118,6 +118,20 @@ public GateioOrder toGateioOrder(MarketOrder marketOrder) { } + public GateioOrder toGateioOrder(LimitOrder limitOrder) { + return GateioOrder.builder() + .currencyPair(toString(limitOrder.getInstrument())) + .side(toString(limitOrder.getType())) + .clientOrderId(limitOrder.getUserReference()) + .account("spot") + .type("limit") + .timeInForce("gtc") + .price(limitOrder.getLimitPrice()) + .amount(limitOrder.getOriginalAmount()) + .build(); + } + + public Order toOrder(GateioOrder gateioOrder) { Order.Builder order; Instrument instrument = toInstrument(gateioOrder.getCurrencyPair()); diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeService.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeService.java index 469aa13093e..5c69fad3a8f 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeService.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeService.java @@ -1,10 +1,8 @@ package org.knowm.xchange.gateio.service; -import java.io.IOException; -import java.util.Collection; -import java.util.List; import org.apache.commons.lang3.Validate; import org.knowm.xchange.dto.Order; +import org.knowm.xchange.dto.trade.LimitOrder; import org.knowm.xchange.dto.trade.MarketOrder; import org.knowm.xchange.gateio.GateioAdapters; import org.knowm.xchange.gateio.GateioErrorAdapter; @@ -17,6 +15,10 @@ import org.knowm.xchange.service.trade.params.orders.OrderQueryParamInstrument; import org.knowm.xchange.service.trade.params.orders.OrderQueryParams; +import java.io.IOException; +import java.util.Collection; +import java.util.List; + public class GateioTradeService extends GateioTradeServiceRaw implements TradeService { public GateioTradeService(GateioExchange exchange) { @@ -36,6 +38,18 @@ public String placeMarketOrder(MarketOrder marketOrder) throws IOException { } + @Override + public String placeLimitOrder(LimitOrder limitOrder) throws IOException { + try { + GateioOrder order = createOrder(GateioAdapters.toGateioOrder(limitOrder)); + return order.getId(); + } + catch (GateioException e) { + throw GateioErrorAdapter.adapt(e); + } + } + + @Override public Collection getOrder(OrderQueryParams... orderQueryParams) throws IOException { // todo: implement getting of several orders diff --git a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioTradeServiceTest.java b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioTradeServiceTest.java index 70fd9faeaad..f60facd89df 100644 --- a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioTradeServiceTest.java +++ b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioTradeServiceTest.java @@ -1,21 +1,23 @@ package org.knowm.xchange.gateio.service; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; - -import java.io.IOException; -import java.math.BigDecimal; -import java.time.Instant; -import java.util.Date; import org.junit.jupiter.api.Test; import org.knowm.xchange.currency.CurrencyPair; import org.knowm.xchange.dto.Order.OrderStatus; import org.knowm.xchange.dto.Order.OrderType; +import org.knowm.xchange.dto.trade.LimitOrder; import org.knowm.xchange.dto.trade.MarketOrder; import org.knowm.xchange.exceptions.FundsExceededException; import org.knowm.xchange.gateio.GateioExchangeWiremock; import org.knowm.xchange.service.trade.params.orders.DefaultQueryOrderParamInstrument; +import java.io.IOException; +import java.math.BigDecimal; +import java.time.Instant; +import java.util.Date; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; + class GateioTradeServiceTest extends GateioExchangeWiremock { GateioTradeService gateioTradeService = (GateioTradeService) exchange.getTradeService(); @@ -59,6 +61,19 @@ void valid_market_sell_order() throws IOException { } + @Test + void valid_limit_sell_order() throws IOException { + LimitOrder limitOrder = new LimitOrder.Builder(OrderType.ASK, CurrencyPair.BTC_USDT) + .userReference("t-valid-limit-sell-order") + .originalAmount(new BigDecimal("0.00068")) + .limitPrice(new BigDecimal("29240.7")) + .build(); + + var actualResponse = gateioTradeService.placeLimitOrder(limitOrder); + assertThat(actualResponse).isEqualTo("373824296029"); + } + + @Test void order_details() throws IOException { MarketOrder expected = new MarketOrder.Builder(OrderType.BID, CurrencyPair.BTC_USDT) diff --git a/xchange-gateio-v4/src/test/resources/__files/api_v4_spot_orders-valid-limit-sell-order.json b/xchange-gateio-v4/src/test/resources/__files/api_v4_spot_orders-valid-limit-sell-order.json new file mode 100644 index 00000000000..be96cefa616 --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/__files/api_v4_spot_orders-valid-limit-sell-order.json @@ -0,0 +1,32 @@ +{ + "id": "373824296029", + "text": "t-valid-limit-sell-order", + "amend_text": "-", + "create_time": "1690498746", + "update_time": "1690498746", + "create_time_ms": 1690498746773, + "update_time_ms": 1690498746773, + "status": "open", + "currency_pair": "BTC_USDT", + "type": "limit", + "account": "spot", + "side": "sell", + "amount": "0.00068", + "price": "29240.7", + "biz_info": "-", + "time_in_force": "gtc", + "iceberg": "0", + "left": "0.00068", + "fill_price": "0", + "filled_total": "0", + "fee": "0", + "fee_currency": "USDT", + "point_fee": "0", + "gt_fee": "0", + "gt_maker_fee": "0", + "gt_taker_fee": "0", + "gt_discount": false, + "rebated_fee": "0", + "rebated_fee_currency": "BTC", + "finish_as": "open" +} \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_orders-valid-limit-sell-order.json b/xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_orders-valid-limit-sell-order.json new file mode 100644 index 00000000000..ec557a33834 --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_orders-valid-limit-sell-order.json @@ -0,0 +1,20 @@ +{ + "id" : "ab0ea1a7-de0a-4ddf-b66d-0791d9fd5532", + "name" : "api_v4_spot_orders", + "request" : { + "url" : "/api/v4/spot/orders", + "method" : "POST", + "bodyPatterns" : [ { + "equalToJson" : "{\"id\":null,\"text\":\"t-valid-limit-sell-order\",\"amend_text\":null,\"create_time_ms\":null,\"update_time_ms\":null,\"status\":null,\"currency_pair\":\"BTC_USDT\",\"type\":\"limit\",\"account\":\"spot\",\"side\":\"sell\",\"amount\":0.00068,\"price\":29240.7,\"time_in_force\":\"gtc\",\"iceberg\":null,\"auto_borrow\":null,\"auto_repay\":null,\"left\":null,\"filled_total\":null,\"avg_deal_price\":null,\"fee\":null,\"fee_currency\":null,\"point_fee\":null,\"gt_fee\":null,\"gt_maker_fee\":null,\"gt_taker_fee\":null,\"gt_discount\":null,\"rebated_fee\":null,\"rebated_fee_currency\":null,\"stp_id\":null,\"stp_act\":null,\"finish_as\":null}", + "ignoreArrayOrder" : true, + "ignoreExtraElements" : true + } ] + }, + "response" : { + "status" : 201, + "bodyFileName" : "api_v4_spot_orders-valid-limit-sell-order.json" + }, + "uuid" : "ab0ea1a7-de0a-4ddf-b66d-0791d9fd5532", + "persistent" : true, + "insertionIndex" : 31 +} \ No newline at end of file From 94b995b331bb347e4c197cde6f19a75555a86f46 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Mon, 31 Jul 2023 19:36:43 +0200 Subject: [PATCH 046/159] [core] Revert version to snapshot --- pom.xml | 2 +- xchange-ascendex/pom.xml | 2 +- xchange-bankera/pom.xml | 2 +- xchange-binance/pom.xml | 2 +- xchange-bitbay/pom.xml | 2 +- xchange-bitcoinaverage/pom.xml | 2 +- xchange-bitcoincharts/pom.xml | 2 +- xchange-bitcoincore/pom.xml | 2 +- xchange-bitcoinde/pom.xml | 2 +- xchange-bitfinex/pom.xml | 2 +- xchange-bitflyer/pom.xml | 2 +- xchange-bithumb/pom.xml | 2 +- xchange-bitso/pom.xml | 2 +- xchange-bitstamp/pom.xml | 2 +- xchange-bittrex/pom.xml | 2 +- xchange-bity/pom.xml | 2 +- xchange-bitz/pom.xml | 2 +- xchange-bl3p/pom.xml | 2 +- xchange-bleutrade/pom.xml | 2 +- xchange-blockchain/pom.xml | 2 +- xchange-btcc/pom.xml | 2 +- xchange-btcmarkets/pom.xml | 2 +- xchange-btcturk/pom.xml | 2 +- xchange-bybit/pom.xml | 2 +- xchange-ccex/pom.xml | 2 +- xchange-cexio/pom.xml | 2 +- xchange-coinbase/pom.xml | 2 +- xchange-coinbasepro/pom.xml | 2 +- xchange-coincheck/pom.xml | 2 +- xchange-coindeal/pom.xml | 2 +- xchange-coindirect/pom.xml | 2 +- xchange-coinegg/pom.xml | 2 +- xchange-coinex/pom.xml | 2 +- xchange-coinfloor/pom.xml | 2 +- xchange-coingi/pom.xml | 2 +- xchange-coinjar/pom.xml | 2 +- xchange-coinmarketcap/pom.xml | 2 +- xchange-coinmate/pom.xml | 2 +- xchange-coinone/pom.xml | 2 +- xchange-cryptowatch/pom.xml | 2 +- xchange-dvchain/pom.xml | 2 +- xchange-dydx/pom.xml | 2 +- xchange-enigma/pom.xml | 2 +- xchange-exmo/pom.xml | 2 +- xchange-ftx/pom.xml | 2 +- xchange-gateio/pom.xml | 2 +- xchange-gemini/pom.xml | 2 +- xchange-globitex/pom.xml | 2 +- xchange-hitbtc/pom.xml | 2 +- xchange-huobi/pom.xml | 2 +- xchange-idex/pom.xml | 2 +- xchange-independentreserve/pom.xml | 2 +- xchange-itbit/pom.xml | 2 +- xchange-koineks/pom.xml | 2 +- xchange-koinim/pom.xml | 2 +- xchange-kraken/pom.xml | 2 +- xchange-krakenfutures/pom.xml | 2 +- xchange-kuna/pom.xml | 2 +- xchange-latoken/pom.xml | 2 +- xchange-lgo/pom.xml | 2 +- xchange-livecoin/pom.xml | 2 +- xchange-luno/pom.xml | 2 +- xchange-lykke/pom.xml | 2 +- xchange-mercadobitcoin/pom.xml | 2 +- xchange-mexc/pom.xml | 2 +- xchange-okcoin/pom.xml | 2 +- xchange-okex/pom.xml | 2 +- xchange-openexchangerates/pom.xml | 2 +- xchange-paribu/pom.xml | 2 +- xchange-paymium/pom.xml | 2 +- xchange-poloniex/pom.xml | 2 +- xchange-quoine/pom.xml | 2 +- xchange-ripple/pom.xml | 2 +- xchange-serum/pom.xml | 2 +- xchange-simulated/pom.xml | 2 +- xchange-stream-bankera/pom.xml | 2 +- xchange-stream-binance/pom.xml | 2 +- xchange-stream-bitfinex/pom.xml | 2 +- xchange-stream-bitflyer/pom.xml | 2 +- xchange-stream-bitmex/pom.xml | 2 +- xchange-stream-bitstamp/pom.xml | 2 +- xchange-stream-btcmarkets/pom.xml | 2 +- xchange-stream-cexio/pom.xml | 2 +- xchange-stream-coinbasepro/pom.xml | 2 +- xchange-stream-coincheck/pom.xml | 2 +- xchange-stream-coinjar/pom.xml | 2 +- xchange-stream-coinmate/pom.xml | 2 +- xchange-stream-core/pom.xml | 2 +- xchange-stream-dydx/pom.xml | 2 +- xchange-stream-ftx/pom.xml | 2 +- xchange-stream-gateio/pom.xml | 2 +- xchange-stream-gemini-v2/pom.xml | 2 +- xchange-stream-gemini/pom.xml | 2 +- xchange-stream-hitbtc/pom.xml | 2 +- xchange-stream-huobi/pom.xml | 2 +- xchange-stream-kraken/pom.xml | 2 +- xchange-stream-krakenfutures/pom.xml | 2 +- xchange-stream-lgo/pom.xml | 2 +- xchange-stream-okcoin/pom.xml | 2 +- xchange-stream-okex/pom.xml | 2 +- xchange-stream-poloniex2/pom.xml | 2 +- xchange-stream-serum/pom.xml | 2 +- xchange-stream-service-core/pom.xml | 2 +- xchange-stream-service-netty/pom.xml | 2 +- xchange-stream-service-pubnub/pom.xml | 2 +- xchange-therock/pom.xml | 2 +- xchange-tradeogre/pom.xml | 2 +- xchange-upbit/pom.xml | 2 +- xchange-vaultoro/pom.xml | 2 +- xchange-yobit/pom.xml | 2 +- 110 files changed, 110 insertions(+), 110 deletions(-) diff --git a/pom.xml b/pom.xml index 883f542bcd1..2b449ff61f4 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT pom XChange diff --git a/xchange-ascendex/pom.xml b/xchange-ascendex/pom.xml index e9e18272157..91c3f01488f 100644 --- a/xchange-ascendex/pom.xml +++ b/xchange-ascendex/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-ascendex diff --git a/xchange-bankera/pom.xml b/xchange-bankera/pom.xml index b5dd84444d5..04661c9454d 100644 --- a/xchange-bankera/pom.xml +++ b/xchange-bankera/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-bankera diff --git a/xchange-binance/pom.xml b/xchange-binance/pom.xml index 35e3f419e2a..62fc1af590f 100644 --- a/xchange-binance/pom.xml +++ b/xchange-binance/pom.xml @@ -5,7 +5,7 @@ xchange-parent org.knowm.xchange - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-binance diff --git a/xchange-bitbay/pom.xml b/xchange-bitbay/pom.xml index a6f233baa64..1271566e1ce 100644 --- a/xchange-bitbay/pom.xml +++ b/xchange-bitbay/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-bitbay diff --git a/xchange-bitcoinaverage/pom.xml b/xchange-bitcoinaverage/pom.xml index 2e03004ce1e..43448314fc2 100644 --- a/xchange-bitcoinaverage/pom.xml +++ b/xchange-bitcoinaverage/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-bitcoinaverage diff --git a/xchange-bitcoincharts/pom.xml b/xchange-bitcoincharts/pom.xml index ceb32d127db..52e57a39b66 100644 --- a/xchange-bitcoincharts/pom.xml +++ b/xchange-bitcoincharts/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-bitcoincharts diff --git a/xchange-bitcoincore/pom.xml b/xchange-bitcoincore/pom.xml index a5fae022db6..c98da4419e6 100644 --- a/xchange-bitcoincore/pom.xml +++ b/xchange-bitcoincore/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-bitcoincore diff --git a/xchange-bitcoinde/pom.xml b/xchange-bitcoinde/pom.xml index 65945d8013c..cf09b411074 100644 --- a/xchange-bitcoinde/pom.xml +++ b/xchange-bitcoinde/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-bitcoinde diff --git a/xchange-bitfinex/pom.xml b/xchange-bitfinex/pom.xml index 9b8a3d61f0f..fb5d5e23321 100644 --- a/xchange-bitfinex/pom.xml +++ b/xchange-bitfinex/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-bitfinex diff --git a/xchange-bitflyer/pom.xml b/xchange-bitflyer/pom.xml index bb79f5defd3..826bbef2400 100755 --- a/xchange-bitflyer/pom.xml +++ b/xchange-bitflyer/pom.xml @@ -6,7 +6,7 @@ xchange-parent org.knowm.xchange - 5.1.1.bigscoop + 5.1.1-SNAPSHOT diff --git a/xchange-bithumb/pom.xml b/xchange-bithumb/pom.xml index 3f8b0c649e2..d7ac9f91394 100644 --- a/xchange-bithumb/pom.xml +++ b/xchange-bithumb/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-bithumb diff --git a/xchange-bitso/pom.xml b/xchange-bitso/pom.xml index 5af137e13b1..b33e203d35a 100644 --- a/xchange-bitso/pom.xml +++ b/xchange-bitso/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-bitso diff --git a/xchange-bitstamp/pom.xml b/xchange-bitstamp/pom.xml index b15db03a3d5..1998f2321c5 100644 --- a/xchange-bitstamp/pom.xml +++ b/xchange-bitstamp/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-bitstamp diff --git a/xchange-bittrex/pom.xml b/xchange-bittrex/pom.xml index 98b0724efc4..b8e02456f8d 100644 --- a/xchange-bittrex/pom.xml +++ b/xchange-bittrex/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-bittrex diff --git a/xchange-bity/pom.xml b/xchange-bity/pom.xml index 8244312308b..dcde294d79c 100644 --- a/xchange-bity/pom.xml +++ b/xchange-bity/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-bity diff --git a/xchange-bitz/pom.xml b/xchange-bitz/pom.xml index 40770a1dde6..589d18e2a10 100644 --- a/xchange-bitz/pom.xml +++ b/xchange-bitz/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-bitz diff --git a/xchange-bl3p/pom.xml b/xchange-bl3p/pom.xml index 86b844be2ba..f150454e95f 100644 --- a/xchange-bl3p/pom.xml +++ b/xchange-bl3p/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-bl3p diff --git a/xchange-bleutrade/pom.xml b/xchange-bleutrade/pom.xml index afcec3a7cb8..4b782365c47 100644 --- a/xchange-bleutrade/pom.xml +++ b/xchange-bleutrade/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-bleutrade diff --git a/xchange-blockchain/pom.xml b/xchange-blockchain/pom.xml index d47c1920a36..e2b92521dae 100644 --- a/xchange-blockchain/pom.xml +++ b/xchange-blockchain/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-blockchain diff --git a/xchange-btcc/pom.xml b/xchange-btcc/pom.xml index 16b763b5aff..af81e77690b 100644 --- a/xchange-btcc/pom.xml +++ b/xchange-btcc/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-btcc diff --git a/xchange-btcmarkets/pom.xml b/xchange-btcmarkets/pom.xml index 088e65c512c..912b8819d0a 100644 --- a/xchange-btcmarkets/pom.xml +++ b/xchange-btcmarkets/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-btcmarkets diff --git a/xchange-btcturk/pom.xml b/xchange-btcturk/pom.xml index 997622d6268..a45e95e42e1 100644 --- a/xchange-btcturk/pom.xml +++ b/xchange-btcturk/pom.xml @@ -6,7 +6,7 @@ xchange-parent org.knowm.xchange - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-btcturk diff --git a/xchange-bybit/pom.xml b/xchange-bybit/pom.xml index 0a515eaecd2..559ac72ee8d 100644 --- a/xchange-bybit/pom.xml +++ b/xchange-bybit/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-bybit diff --git a/xchange-ccex/pom.xml b/xchange-ccex/pom.xml index a74f3516630..a1031dc0247 100644 --- a/xchange-ccex/pom.xml +++ b/xchange-ccex/pom.xml @@ -4,7 +4,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-ccex XChange C-Cex diff --git a/xchange-cexio/pom.xml b/xchange-cexio/pom.xml index b777d928708..978dfbabee5 100644 --- a/xchange-cexio/pom.xml +++ b/xchange-cexio/pom.xml @@ -6,7 +6,7 @@ xchange-parent org.knowm.xchange - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-cexio diff --git a/xchange-coinbase/pom.xml b/xchange-coinbase/pom.xml index efab6b093e9..ec1f796fcd7 100644 --- a/xchange-coinbase/pom.xml +++ b/xchange-coinbase/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-coinbase diff --git a/xchange-coinbasepro/pom.xml b/xchange-coinbasepro/pom.xml index 0f76a58370e..c6c283cc876 100644 --- a/xchange-coinbasepro/pom.xml +++ b/xchange-coinbasepro/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-coinbasepro diff --git a/xchange-coincheck/pom.xml b/xchange-coincheck/pom.xml index dfd64a5a063..aeda06e3c7c 100644 --- a/xchange-coincheck/pom.xml +++ b/xchange-coincheck/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-coincheck diff --git a/xchange-coindeal/pom.xml b/xchange-coindeal/pom.xml index 25c306bc6dc..b841eb58acc 100644 --- a/xchange-coindeal/pom.xml +++ b/xchange-coindeal/pom.xml @@ -3,7 +3,7 @@ xchange-parent org.knowm.xchange - 5.1.1.bigscoop + 5.1.1-SNAPSHOT 4.0.0 diff --git a/xchange-coindirect/pom.xml b/xchange-coindirect/pom.xml index 98665947fdb..3c1db7cc9ca 100644 --- a/xchange-coindirect/pom.xml +++ b/xchange-coindirect/pom.xml @@ -5,7 +5,7 @@ xchange-parent org.knowm.xchange - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-coindirect diff --git a/xchange-coinegg/pom.xml b/xchange-coinegg/pom.xml index 95cdba46b50..4092c8e2e31 100644 --- a/xchange-coinegg/pom.xml +++ b/xchange-coinegg/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-coinegg diff --git a/xchange-coinex/pom.xml b/xchange-coinex/pom.xml index 80513cf4bfb..f54a7e3aaa3 100644 --- a/xchange-coinex/pom.xml +++ b/xchange-coinex/pom.xml @@ -3,7 +3,7 @@ xchange-parent org.knowm.xchange - 5.1.1.bigscoop + 5.1.1-SNAPSHOT 4.0.0 diff --git a/xchange-coinfloor/pom.xml b/xchange-coinfloor/pom.xml index 07c638a3020..50cc60bdcf6 100644 --- a/xchange-coinfloor/pom.xml +++ b/xchange-coinfloor/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-coinfloor diff --git a/xchange-coingi/pom.xml b/xchange-coingi/pom.xml index d42d98f4c60..18a31b7b2dd 100644 --- a/xchange-coingi/pom.xml +++ b/xchange-coingi/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-coingi diff --git a/xchange-coinjar/pom.xml b/xchange-coinjar/pom.xml index f86e5c97233..ff54d945c59 100644 --- a/xchange-coinjar/pom.xml +++ b/xchange-coinjar/pom.xml @@ -5,7 +5,7 @@ xchange-parent org.knowm.xchange - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-coinjar diff --git a/xchange-coinmarketcap/pom.xml b/xchange-coinmarketcap/pom.xml index 16cdca08ee7..5171b6a57f9 100644 --- a/xchange-coinmarketcap/pom.xml +++ b/xchange-coinmarketcap/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-coinmarketcap diff --git a/xchange-coinmate/pom.xml b/xchange-coinmate/pom.xml index 3068e488687..4f91ee96f48 100644 --- a/xchange-coinmate/pom.xml +++ b/xchange-coinmate/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-coinmate diff --git a/xchange-coinone/pom.xml b/xchange-coinone/pom.xml index a3efe4f09f9..6f05aa7c873 100644 --- a/xchange-coinone/pom.xml +++ b/xchange-coinone/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-coinone diff --git a/xchange-cryptowatch/pom.xml b/xchange-cryptowatch/pom.xml index 754fa037a90..aad07671eaf 100644 --- a/xchange-cryptowatch/pom.xml +++ b/xchange-cryptowatch/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-cryptowatch diff --git a/xchange-dvchain/pom.xml b/xchange-dvchain/pom.xml index f51b8d6898a..01307da36ae 100644 --- a/xchange-dvchain/pom.xml +++ b/xchange-dvchain/pom.xml @@ -3,7 +3,7 @@ xchange-parent org.knowm.xchange - 5.1.1.bigscoop + 5.1.1-SNAPSHOT 4.0.0 diff --git a/xchange-dydx/pom.xml b/xchange-dydx/pom.xml index bf4ed98409a..c970a112b35 100644 --- a/xchange-dydx/pom.xml +++ b/xchange-dydx/pom.xml @@ -3,7 +3,7 @@ xchange-parent org.knowm.xchange - 5.1.1.bigscoop + 5.1.1-SNAPSHOT 4.0.0 diff --git a/xchange-enigma/pom.xml b/xchange-enigma/pom.xml index 91e23823d5a..e710b70c073 100644 --- a/xchange-enigma/pom.xml +++ b/xchange-enigma/pom.xml @@ -5,7 +5,7 @@ xchange-parent org.knowm.xchange - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-enigma diff --git a/xchange-exmo/pom.xml b/xchange-exmo/pom.xml index 15f649eb6dc..63459974f3b 100644 --- a/xchange-exmo/pom.xml +++ b/xchange-exmo/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-exmo diff --git a/xchange-ftx/pom.xml b/xchange-ftx/pom.xml index 4c751f2a4c2..6b8e5219bf5 100644 --- a/xchange-ftx/pom.xml +++ b/xchange-ftx/pom.xml @@ -6,7 +6,7 @@ xchange-parent org.knowm.xchange - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-ftx diff --git a/xchange-gateio/pom.xml b/xchange-gateio/pom.xml index 3b45bb5a002..7578e8343d7 100644 --- a/xchange-gateio/pom.xml +++ b/xchange-gateio/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-gateio diff --git a/xchange-gemini/pom.xml b/xchange-gemini/pom.xml index 256ff227ea1..9991b4951fe 100644 --- a/xchange-gemini/pom.xml +++ b/xchange-gemini/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-gemini diff --git a/xchange-globitex/pom.xml b/xchange-globitex/pom.xml index 37564ee3366..017073f1ff9 100644 --- a/xchange-globitex/pom.xml +++ b/xchange-globitex/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-globitex diff --git a/xchange-hitbtc/pom.xml b/xchange-hitbtc/pom.xml index e3603b03ec9..d9af0b7c655 100644 --- a/xchange-hitbtc/pom.xml +++ b/xchange-hitbtc/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-hitbtc diff --git a/xchange-huobi/pom.xml b/xchange-huobi/pom.xml index c68b0a31f2e..3eaf60913ed 100644 --- a/xchange-huobi/pom.xml +++ b/xchange-huobi/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-huobi diff --git a/xchange-idex/pom.xml b/xchange-idex/pom.xml index b0b01136106..64b10f25661 100644 --- a/xchange-idex/pom.xml +++ b/xchange-idex/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-idex diff --git a/xchange-independentreserve/pom.xml b/xchange-independentreserve/pom.xml index 7c38fdd323c..8c6dd6838d4 100644 --- a/xchange-independentreserve/pom.xml +++ b/xchange-independentreserve/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-independentreserve diff --git a/xchange-itbit/pom.xml b/xchange-itbit/pom.xml index a122b4d62a6..e7ac04a0019 100644 --- a/xchange-itbit/pom.xml +++ b/xchange-itbit/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-itbit diff --git a/xchange-koineks/pom.xml b/xchange-koineks/pom.xml index a3c19a80c5f..4abf5d3536c 100644 --- a/xchange-koineks/pom.xml +++ b/xchange-koineks/pom.xml @@ -3,7 +3,7 @@ xchange-parent org.knowm.xchange - 5.1.1.bigscoop + 5.1.1-SNAPSHOT 4.0.0 diff --git a/xchange-koinim/pom.xml b/xchange-koinim/pom.xml index 93de038abab..2b1028f15fb 100644 --- a/xchange-koinim/pom.xml +++ b/xchange-koinim/pom.xml @@ -3,7 +3,7 @@ xchange-parent org.knowm.xchange - 5.1.1.bigscoop + 5.1.1-SNAPSHOT 4.0.0 diff --git a/xchange-kraken/pom.xml b/xchange-kraken/pom.xml index cfde033b322..7bcf6e8ef66 100644 --- a/xchange-kraken/pom.xml +++ b/xchange-kraken/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-kraken diff --git a/xchange-krakenfutures/pom.xml b/xchange-krakenfutures/pom.xml index 32c747083bf..5fed94a9c12 100644 --- a/xchange-krakenfutures/pom.xml +++ b/xchange-krakenfutures/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-krakenfutures diff --git a/xchange-kuna/pom.xml b/xchange-kuna/pom.xml index 957e07a44a2..b33de315225 100644 --- a/xchange-kuna/pom.xml +++ b/xchange-kuna/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-kuna diff --git a/xchange-latoken/pom.xml b/xchange-latoken/pom.xml index 2f888a75695..6d27f6ea484 100644 --- a/xchange-latoken/pom.xml +++ b/xchange-latoken/pom.xml @@ -5,7 +5,7 @@ xchange-parent org.knowm.xchange - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-latoken diff --git a/xchange-lgo/pom.xml b/xchange-lgo/pom.xml index 9735d70226f..21dd723e5a8 100644 --- a/xchange-lgo/pom.xml +++ b/xchange-lgo/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-lgo diff --git a/xchange-livecoin/pom.xml b/xchange-livecoin/pom.xml index 413b9cdc11a..cca3cccfc08 100644 --- a/xchange-livecoin/pom.xml +++ b/xchange-livecoin/pom.xml @@ -3,7 +3,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-livecoin XChange Livecoin diff --git a/xchange-luno/pom.xml b/xchange-luno/pom.xml index 63a05efae23..6850ca511bf 100644 --- a/xchange-luno/pom.xml +++ b/xchange-luno/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-luno diff --git a/xchange-lykke/pom.xml b/xchange-lykke/pom.xml index f438d39e072..67bf7470fdd 100644 --- a/xchange-lykke/pom.xml +++ b/xchange-lykke/pom.xml @@ -3,7 +3,7 @@ xchange-parent org.knowm.xchange - 5.1.1.bigscoop + 5.1.1-SNAPSHOT 4.0.0 diff --git a/xchange-mercadobitcoin/pom.xml b/xchange-mercadobitcoin/pom.xml index 464a3515af5..ed27baf0dca 100644 --- a/xchange-mercadobitcoin/pom.xml +++ b/xchange-mercadobitcoin/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-mercadobitcoin diff --git a/xchange-mexc/pom.xml b/xchange-mexc/pom.xml index 45a31711ecb..64bb9ec9449 100644 --- a/xchange-mexc/pom.xml +++ b/xchange-mexc/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-mexc diff --git a/xchange-okcoin/pom.xml b/xchange-okcoin/pom.xml index dfb9f93d028..fd69ee26885 100644 --- a/xchange-okcoin/pom.xml +++ b/xchange-okcoin/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-okcoin diff --git a/xchange-okex/pom.xml b/xchange-okex/pom.xml index 957e14d33e3..b3ce7aa8f0b 100644 --- a/xchange-okex/pom.xml +++ b/xchange-okex/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-okex diff --git a/xchange-openexchangerates/pom.xml b/xchange-openexchangerates/pom.xml index 983f700dcd8..acc11c780f8 100644 --- a/xchange-openexchangerates/pom.xml +++ b/xchange-openexchangerates/pom.xml @@ -4,7 +4,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-openexchangerates diff --git a/xchange-paribu/pom.xml b/xchange-paribu/pom.xml index c79d1714379..86245c5272c 100644 --- a/xchange-paribu/pom.xml +++ b/xchange-paribu/pom.xml @@ -3,7 +3,7 @@ xchange-parent org.knowm.xchange - 5.1.1.bigscoop + 5.1.1-SNAPSHOT 4.0.0 diff --git a/xchange-paymium/pom.xml b/xchange-paymium/pom.xml index 647458f0bde..4779e63ce0f 100644 --- a/xchange-paymium/pom.xml +++ b/xchange-paymium/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-paymium diff --git a/xchange-poloniex/pom.xml b/xchange-poloniex/pom.xml index 49b56c54e29..9d81302b6a9 100755 --- a/xchange-poloniex/pom.xml +++ b/xchange-poloniex/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-poloniex diff --git a/xchange-quoine/pom.xml b/xchange-quoine/pom.xml index 35c0f76d949..59ad3ec56c3 100644 --- a/xchange-quoine/pom.xml +++ b/xchange-quoine/pom.xml @@ -3,7 +3,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-quoine diff --git a/xchange-ripple/pom.xml b/xchange-ripple/pom.xml index a7418fd5ffd..0efb377f889 100644 --- a/xchange-ripple/pom.xml +++ b/xchange-ripple/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-ripple diff --git a/xchange-serum/pom.xml b/xchange-serum/pom.xml index c522abb3c05..2f037834524 100644 --- a/xchange-serum/pom.xml +++ b/xchange-serum/pom.xml @@ -3,7 +3,7 @@ xchange-parent org.knowm.xchange - 5.1.1.bigscoop + 5.1.1-SNAPSHOT 4.0.0 diff --git a/xchange-simulated/pom.xml b/xchange-simulated/pom.xml index 8531b4b5b97..8537110e06f 100644 --- a/xchange-simulated/pom.xml +++ b/xchange-simulated/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-simulated diff --git a/xchange-stream-bankera/pom.xml b/xchange-stream-bankera/pom.xml index 0074e90adbd..91c44b418b2 100644 --- a/xchange-stream-bankera/pom.xml +++ b/xchange-stream-bankera/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT XChange Bankera Stream diff --git a/xchange-stream-binance/pom.xml b/xchange-stream-binance/pom.xml index 5db3dae84b5..b207654d107 100644 --- a/xchange-stream-binance/pom.xml +++ b/xchange-stream-binance/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT XChange Binance Stream diff --git a/xchange-stream-bitfinex/pom.xml b/xchange-stream-bitfinex/pom.xml index 42ae0b99e4d..118498a6145 100644 --- a/xchange-stream-bitfinex/pom.xml +++ b/xchange-stream-bitfinex/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT XChange Bitfinex Stream diff --git a/xchange-stream-bitflyer/pom.xml b/xchange-stream-bitflyer/pom.xml index 6b689fb30c0..c6e655388b1 100644 --- a/xchange-stream-bitflyer/pom.xml +++ b/xchange-stream-bitflyer/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT XChange Bitflyer Stream diff --git a/xchange-stream-bitmex/pom.xml b/xchange-stream-bitmex/pom.xml index cd8b3f315d6..11fbf15628a 100644 --- a/xchange-stream-bitmex/pom.xml +++ b/xchange-stream-bitmex/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT XChange Bitmex Stream diff --git a/xchange-stream-bitstamp/pom.xml b/xchange-stream-bitstamp/pom.xml index 7bf01611bc9..f0a68bdb48a 100644 --- a/xchange-stream-bitstamp/pom.xml +++ b/xchange-stream-bitstamp/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT XChange Bitstamp Stream diff --git a/xchange-stream-btcmarkets/pom.xml b/xchange-stream-btcmarkets/pom.xml index 0eeb4442ec2..9cc1955e490 100644 --- a/xchange-stream-btcmarkets/pom.xml +++ b/xchange-stream-btcmarkets/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT XChange BTCMarkets Stream diff --git a/xchange-stream-cexio/pom.xml b/xchange-stream-cexio/pom.xml index 8f1c941eae9..b5748d166c6 100644 --- a/xchange-stream-cexio/pom.xml +++ b/xchange-stream-cexio/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT XChange Cex.io Stream diff --git a/xchange-stream-coinbasepro/pom.xml b/xchange-stream-coinbasepro/pom.xml index 8d4a66c56f1..45cc3e7a124 100644 --- a/xchange-stream-coinbasepro/pom.xml +++ b/xchange-stream-coinbasepro/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT XChange CoinbasePro Stream diff --git a/xchange-stream-coincheck/pom.xml b/xchange-stream-coincheck/pom.xml index 15d72817f4f..20c84345a53 100644 --- a/xchange-stream-coincheck/pom.xml +++ b/xchange-stream-coincheck/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT XChange Coincheck Stream diff --git a/xchange-stream-coinjar/pom.xml b/xchange-stream-coinjar/pom.xml index 960c378e483..96e2d2307b4 100644 --- a/xchange-stream-coinjar/pom.xml +++ b/xchange-stream-coinjar/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT XChange Coinjar Stream diff --git a/xchange-stream-coinmate/pom.xml b/xchange-stream-coinmate/pom.xml index 232eee56e25..fb4f2973668 100644 --- a/xchange-stream-coinmate/pom.xml +++ b/xchange-stream-coinmate/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT XChange Coinmate Stream diff --git a/xchange-stream-core/pom.xml b/xchange-stream-core/pom.xml index 9d96e15523f..373ef95b891 100644 --- a/xchange-stream-core/pom.xml +++ b/xchange-stream-core/pom.xml @@ -3,7 +3,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT 4.0.0 diff --git a/xchange-stream-dydx/pom.xml b/xchange-stream-dydx/pom.xml index acb0a3e4455..98272a5352c 100644 --- a/xchange-stream-dydx/pom.xml +++ b/xchange-stream-dydx/pom.xml @@ -3,7 +3,7 @@ xchange-parent org.knowm.xchange - 5.1.1.bigscoop + 5.1.1-SNAPSHOT 4.0.0 diff --git a/xchange-stream-ftx/pom.xml b/xchange-stream-ftx/pom.xml index 1d8dc2e4c9f..b14b66f8879 100644 --- a/xchange-stream-ftx/pom.xml +++ b/xchange-stream-ftx/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT XChange Ftx Stream diff --git a/xchange-stream-gateio/pom.xml b/xchange-stream-gateio/pom.xml index 4922ceb3539..19d0f31e0a7 100644 --- a/xchange-stream-gateio/pom.xml +++ b/xchange-stream-gateio/pom.xml @@ -3,7 +3,7 @@ xchange-parent org.knowm.xchange - 5.1.1.bigscoop + 5.1.1-SNAPSHOT 4.0.0 diff --git a/xchange-stream-gemini-v2/pom.xml b/xchange-stream-gemini-v2/pom.xml index d254e1f2469..bbda9c81033 100644 --- a/xchange-stream-gemini-v2/pom.xml +++ b/xchange-stream-gemini-v2/pom.xml @@ -9,7 +9,7 @@ xchange-parent org.knowm.xchange - 5.1.1.bigscoop + 5.1.1-SNAPSHOT diff --git a/xchange-stream-gemini/pom.xml b/xchange-stream-gemini/pom.xml index 74c4d4363bc..ec035a31a1f 100644 --- a/xchange-stream-gemini/pom.xml +++ b/xchange-stream-gemini/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT XChange Gemini Stream diff --git a/xchange-stream-hitbtc/pom.xml b/xchange-stream-hitbtc/pom.xml index a049cd43373..5a3f79401ee 100644 --- a/xchange-stream-hitbtc/pom.xml +++ b/xchange-stream-hitbtc/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT XChange Hitbtc Stream diff --git a/xchange-stream-huobi/pom.xml b/xchange-stream-huobi/pom.xml index 374eb219183..6ae33aa6dd2 100644 --- a/xchange-stream-huobi/pom.xml +++ b/xchange-stream-huobi/pom.xml @@ -3,7 +3,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT 4.0.0 diff --git a/xchange-stream-kraken/pom.xml b/xchange-stream-kraken/pom.xml index 9165c26fe5f..1cb5a278eee 100644 --- a/xchange-stream-kraken/pom.xml +++ b/xchange-stream-kraken/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT XChange Kraken Stream diff --git a/xchange-stream-krakenfutures/pom.xml b/xchange-stream-krakenfutures/pom.xml index 5ea97f822f3..23e8622a430 100644 --- a/xchange-stream-krakenfutures/pom.xml +++ b/xchange-stream-krakenfutures/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-stream-krakenfutures diff --git a/xchange-stream-lgo/pom.xml b/xchange-stream-lgo/pom.xml index 03c7d7df312..5699c7f355f 100644 --- a/xchange-stream-lgo/pom.xml +++ b/xchange-stream-lgo/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT XChange LGO Stream diff --git a/xchange-stream-okcoin/pom.xml b/xchange-stream-okcoin/pom.xml index 19af5ac0ddf..857018aed92 100644 --- a/xchange-stream-okcoin/pom.xml +++ b/xchange-stream-okcoin/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT XChange OKCoin Stream diff --git a/xchange-stream-okex/pom.xml b/xchange-stream-okex/pom.xml index 4c3fdebf24f..42ed14106a7 100644 --- a/xchange-stream-okex/pom.xml +++ b/xchange-stream-okex/pom.xml @@ -6,7 +6,7 @@ xchange-parent org.knowm.xchange - 5.1.1.bigscoop + 5.1.1-SNAPSHOT XChange Okex Stream diff --git a/xchange-stream-poloniex2/pom.xml b/xchange-stream-poloniex2/pom.xml index f708dedf60e..23ecca7cb7d 100644 --- a/xchange-stream-poloniex2/pom.xml +++ b/xchange-stream-poloniex2/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT XChange Poloniex 2 Stream diff --git a/xchange-stream-serum/pom.xml b/xchange-stream-serum/pom.xml index 311ca5b0522..2778be0cedf 100644 --- a/xchange-stream-serum/pom.xml +++ b/xchange-stream-serum/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT XChange Serum Stream diff --git a/xchange-stream-service-core/pom.xml b/xchange-stream-service-core/pom.xml index 4bc3d9c3049..9a2a333617b 100644 --- a/xchange-stream-service-core/pom.xml +++ b/xchange-stream-service-core/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT XChange Core Stream Service diff --git a/xchange-stream-service-netty/pom.xml b/xchange-stream-service-netty/pom.xml index b99fb4c08bb..aba65d517fd 100644 --- a/xchange-stream-service-netty/pom.xml +++ b/xchange-stream-service-netty/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT XChange Core Stream Netty diff --git a/xchange-stream-service-pubnub/pom.xml b/xchange-stream-service-pubnub/pom.xml index 1f3c3ba4322..6f73e624a4f 100644 --- a/xchange-stream-service-pubnub/pom.xml +++ b/xchange-stream-service-pubnub/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT XChange Core Stream Pubnub diff --git a/xchange-therock/pom.xml b/xchange-therock/pom.xml index cf83b30c605..035c3ccd7cb 100644 --- a/xchange-therock/pom.xml +++ b/xchange-therock/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-therock diff --git a/xchange-tradeogre/pom.xml b/xchange-tradeogre/pom.xml index 3280008d174..dd85c90e28f 100644 --- a/xchange-tradeogre/pom.xml +++ b/xchange-tradeogre/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-tradeogre diff --git a/xchange-upbit/pom.xml b/xchange-upbit/pom.xml index 90585737b65..7d6cf373af4 100644 --- a/xchange-upbit/pom.xml +++ b/xchange-upbit/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-upbit diff --git a/xchange-vaultoro/pom.xml b/xchange-vaultoro/pom.xml index a050d8c4285..f402ccf4801 100644 --- a/xchange-vaultoro/pom.xml +++ b/xchange-vaultoro/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-vaultoro diff --git a/xchange-yobit/pom.xml b/xchange-yobit/pom.xml index 0edb8654da5..97bc36a0b87 100644 --- a/xchange-yobit/pom.xml +++ b/xchange-yobit/pom.xml @@ -3,7 +3,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-yobit XChange YoBit From 7485407e96c5000bfcea37e827643256595c48ae Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Mon, 31 Jul 2023 20:09:06 +0200 Subject: [PATCH 047/159] [core] Revert version to snapshot --- xchange-bibox/pom.xml | 2 +- xchange-bitcointoyou/pom.xml | 2 +- xchange-bitmex/pom.xml | 2 +- xchange-core/pom.xml | 2 +- xchange-deribit/pom.xml | 2 +- xchange-examples/pom.xml | 2 +- xchange-kucoin/pom.xml | 2 +- xchange-truefx/pom.xml | 2 +- xchange-zaif/pom.xml | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/xchange-bibox/pom.xml b/xchange-bibox/pom.xml index 03dbded8bbb..e4f528da5d0 100644 --- a/xchange-bibox/pom.xml +++ b/xchange-bibox/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-bibox diff --git a/xchange-bitcointoyou/pom.xml b/xchange-bitcointoyou/pom.xml index 74059210dcd..f6cb7d4773c 100644 --- a/xchange-bitcointoyou/pom.xml +++ b/xchange-bitcointoyou/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-bitcointoyou diff --git a/xchange-bitmex/pom.xml b/xchange-bitmex/pom.xml index 1d19dc007d4..207bbadf397 100755 --- a/xchange-bitmex/pom.xml +++ b/xchange-bitmex/pom.xml @@ -4,7 +4,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-bitmex diff --git a/xchange-core/pom.xml b/xchange-core/pom.xml index 409689dd91b..83988442b10 100644 --- a/xchange-core/pom.xml +++ b/xchange-core/pom.xml @@ -3,7 +3,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-core diff --git a/xchange-deribit/pom.xml b/xchange-deribit/pom.xml index 7efea14e01b..4c51e404e36 100644 --- a/xchange-deribit/pom.xml +++ b/xchange-deribit/pom.xml @@ -4,7 +4,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-deribit diff --git a/xchange-examples/pom.xml b/xchange-examples/pom.xml index d95021db1b8..1b99fed7c89 100755 --- a/xchange-examples/pom.xml +++ b/xchange-examples/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-examples diff --git a/xchange-kucoin/pom.xml b/xchange-kucoin/pom.xml index efd3fa30fb2..68e60ca0fc4 100644 --- a/xchange-kucoin/pom.xml +++ b/xchange-kucoin/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-kucoin diff --git a/xchange-truefx/pom.xml b/xchange-truefx/pom.xml index 0812c77afba..7ce3b63e608 100644 --- a/xchange-truefx/pom.xml +++ b/xchange-truefx/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-truefx diff --git a/xchange-zaif/pom.xml b/xchange-zaif/pom.xml index 5d4b40e7301..71bf905b873 100644 --- a/xchange-zaif/pom.xml +++ b/xchange-zaif/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-zaif From abb60fd3c52cbe29d49e59e99bcd3e69a98a50c2 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Mon, 31 Jul 2023 21:06:21 +0200 Subject: [PATCH 048/159] [core] Change version --- pom.xml | 2 +- xchange-ascendex/pom.xml | 2 +- xchange-bankera/pom.xml | 2 +- xchange-bibox/pom.xml | 2 +- xchange-binance/pom.xml | 2 +- xchange-bitbay/pom.xml | 2 +- xchange-bitcoinaverage/pom.xml | 2 +- xchange-bitcoincharts/pom.xml | 2 +- xchange-bitcoincore/pom.xml | 2 +- xchange-bitcoinde/pom.xml | 2 +- xchange-bitcointoyou/pom.xml | 2 +- xchange-bitfinex/pom.xml | 2 +- xchange-bitflyer/pom.xml | 2 +- xchange-bithumb/pom.xml | 2 +- xchange-bitmex/pom.xml | 2 +- xchange-bitso/pom.xml | 2 +- xchange-bitstamp/pom.xml | 2 +- xchange-bittrex/pom.xml | 2 +- xchange-bity/pom.xml | 2 +- xchange-bitz/pom.xml | 2 +- xchange-bl3p/pom.xml | 2 +- xchange-bleutrade/pom.xml | 2 +- xchange-blockchain/pom.xml | 2 +- xchange-btcc/pom.xml | 2 +- xchange-btcmarkets/pom.xml | 2 +- xchange-btcturk/pom.xml | 2 +- xchange-bybit/pom.xml | 2 +- xchange-ccex/pom.xml | 2 +- xchange-cexio/pom.xml | 2 +- xchange-coinbase/pom.xml | 2 +- xchange-coinbasepro/pom.xml | 2 +- xchange-coincheck/pom.xml | 2 +- xchange-coindeal/pom.xml | 2 +- xchange-coindirect/pom.xml | 2 +- xchange-coinegg/pom.xml | 2 +- xchange-coinex/pom.xml | 2 +- xchange-coinfloor/pom.xml | 2 +- xchange-coingi/pom.xml | 2 +- xchange-coinjar/pom.xml | 2 +- xchange-coinmarketcap/pom.xml | 2 +- xchange-coinmate/pom.xml | 2 +- xchange-coinone/pom.xml | 2 +- xchange-core/pom.xml | 2 +- xchange-cryptowatch/pom.xml | 2 +- xchange-deribit/pom.xml | 2 +- xchange-dvchain/pom.xml | 2 +- xchange-dydx/pom.xml | 2 +- xchange-enigma/pom.xml | 2 +- xchange-examples/pom.xml | 2 +- xchange-exmo/pom.xml | 2 +- xchange-ftx/pom.xml | 2 +- xchange-gateio/pom.xml | 2 +- xchange-gemini/pom.xml | 2 +- xchange-globitex/pom.xml | 2 +- xchange-hitbtc/pom.xml | 2 +- xchange-huobi/pom.xml | 2 +- xchange-idex/pom.xml | 2 +- xchange-independentreserve/pom.xml | 2 +- xchange-itbit/pom.xml | 2 +- xchange-koineks/pom.xml | 2 +- xchange-koinim/pom.xml | 2 +- xchange-kraken/pom.xml | 2 +- xchange-krakenfutures/pom.xml | 2 +- xchange-kucoin/pom.xml | 2 +- xchange-kuna/pom.xml | 2 +- xchange-latoken/pom.xml | 2 +- xchange-lgo/pom.xml | 2 +- xchange-livecoin/pom.xml | 2 +- xchange-luno/pom.xml | 2 +- xchange-lykke/pom.xml | 2 +- xchange-mercadobitcoin/pom.xml | 2 +- xchange-mexc/pom.xml | 2 +- xchange-okcoin/pom.xml | 2 +- xchange-okex/pom.xml | 2 +- xchange-openexchangerates/pom.xml | 2 +- xchange-paribu/pom.xml | 2 +- xchange-paymium/pom.xml | 2 +- xchange-poloniex/pom.xml | 2 +- xchange-quoine/pom.xml | 2 +- xchange-ripple/pom.xml | 2 +- xchange-serum/pom.xml | 2 +- xchange-simulated/pom.xml | 2 +- xchange-stream-bankera/pom.xml | 2 +- xchange-stream-binance/pom.xml | 2 +- xchange-stream-bitfinex/pom.xml | 2 +- xchange-stream-bitflyer/pom.xml | 2 +- xchange-stream-bitmex/pom.xml | 2 +- xchange-stream-bitstamp/pom.xml | 2 +- xchange-stream-btcmarkets/pom.xml | 2 +- xchange-stream-cexio/pom.xml | 2 +- xchange-stream-coinbasepro/pom.xml | 2 +- xchange-stream-coincheck/pom.xml | 2 +- xchange-stream-coinjar/pom.xml | 2 +- xchange-stream-coinmate/pom.xml | 2 +- xchange-stream-core/pom.xml | 2 +- xchange-stream-dydx/pom.xml | 2 +- xchange-stream-ftx/pom.xml | 2 +- xchange-stream-gateio/pom.xml | 2 +- xchange-stream-gemini-v2/pom.xml | 2 +- xchange-stream-gemini/pom.xml | 2 +- xchange-stream-hitbtc/pom.xml | 2 +- xchange-stream-huobi/pom.xml | 2 +- xchange-stream-kraken/pom.xml | 2 +- xchange-stream-krakenfutures/pom.xml | 2 +- xchange-stream-kucoin/pom.xml | 2 +- xchange-stream-lgo/pom.xml | 2 +- xchange-stream-okcoin/pom.xml | 2 +- xchange-stream-okex/pom.xml | 2 +- xchange-stream-poloniex2/pom.xml | 2 +- xchange-stream-serum/pom.xml | 2 +- xchange-stream-service-core/pom.xml | 2 +- xchange-stream-service-netty/pom.xml | 2 +- xchange-stream-service-pubnub/pom.xml | 2 +- xchange-therock/pom.xml | 2 +- xchange-tradeogre/pom.xml | 2 +- xchange-truefx/pom.xml | 2 +- xchange-upbit/pom.xml | 2 +- xchange-vaultoro/pom.xml | 2 +- xchange-yobit/pom.xml | 2 +- xchange-zaif/pom.xml | 2 +- 120 files changed, 120 insertions(+), 120 deletions(-) diff --git a/pom.xml b/pom.xml index e4e9892eec3..da6cfd08f33 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop pom XChange diff --git a/xchange-ascendex/pom.xml b/xchange-ascendex/pom.xml index 91c3f01488f..e9e18272157 100644 --- a/xchange-ascendex/pom.xml +++ b/xchange-ascendex/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-ascendex diff --git a/xchange-bankera/pom.xml b/xchange-bankera/pom.xml index 04661c9454d..b5dd84444d5 100644 --- a/xchange-bankera/pom.xml +++ b/xchange-bankera/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-bankera diff --git a/xchange-bibox/pom.xml b/xchange-bibox/pom.xml index 1a5a12604d3..a3d9f3e7dad 100644 --- a/xchange-bibox/pom.xml +++ b/xchange-bibox/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-bibox diff --git a/xchange-binance/pom.xml b/xchange-binance/pom.xml index 52435ef1f26..8a410c4f434 100644 --- a/xchange-binance/pom.xml +++ b/xchange-binance/pom.xml @@ -5,7 +5,7 @@ xchange-parent org.knowm.xchange - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-binance diff --git a/xchange-bitbay/pom.xml b/xchange-bitbay/pom.xml index 1b444f27c9d..d704c8ff7c2 100644 --- a/xchange-bitbay/pom.xml +++ b/xchange-bitbay/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-bitbay diff --git a/xchange-bitcoinaverage/pom.xml b/xchange-bitcoinaverage/pom.xml index 43448314fc2..2e03004ce1e 100644 --- a/xchange-bitcoinaverage/pom.xml +++ b/xchange-bitcoinaverage/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-bitcoinaverage diff --git a/xchange-bitcoincharts/pom.xml b/xchange-bitcoincharts/pom.xml index 52e57a39b66..ceb32d127db 100644 --- a/xchange-bitcoincharts/pom.xml +++ b/xchange-bitcoincharts/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-bitcoincharts diff --git a/xchange-bitcoincore/pom.xml b/xchange-bitcoincore/pom.xml index c98da4419e6..a5fae022db6 100644 --- a/xchange-bitcoincore/pom.xml +++ b/xchange-bitcoincore/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-bitcoincore diff --git a/xchange-bitcoinde/pom.xml b/xchange-bitcoinde/pom.xml index 5c04b494ff8..787bc848fa5 100644 --- a/xchange-bitcoinde/pom.xml +++ b/xchange-bitcoinde/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-bitcoinde diff --git a/xchange-bitcointoyou/pom.xml b/xchange-bitcointoyou/pom.xml index f6cb7d4773c..74059210dcd 100644 --- a/xchange-bitcointoyou/pom.xml +++ b/xchange-bitcointoyou/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-bitcointoyou diff --git a/xchange-bitfinex/pom.xml b/xchange-bitfinex/pom.xml index a31f2fd7ecc..2103388210e 100644 --- a/xchange-bitfinex/pom.xml +++ b/xchange-bitfinex/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-bitfinex diff --git a/xchange-bitflyer/pom.xml b/xchange-bitflyer/pom.xml index 826bbef2400..bb79f5defd3 100755 --- a/xchange-bitflyer/pom.xml +++ b/xchange-bitflyer/pom.xml @@ -6,7 +6,7 @@ xchange-parent org.knowm.xchange - 5.1.1-SNAPSHOT + 5.1.1.bigscoop diff --git a/xchange-bithumb/pom.xml b/xchange-bithumb/pom.xml index d7ac9f91394..3f8b0c649e2 100644 --- a/xchange-bithumb/pom.xml +++ b/xchange-bithumb/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-bithumb diff --git a/xchange-bitmex/pom.xml b/xchange-bitmex/pom.xml index 4a9b3809b2f..e1e4cf0330c 100755 --- a/xchange-bitmex/pom.xml +++ b/xchange-bitmex/pom.xml @@ -4,7 +4,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-bitmex diff --git a/xchange-bitso/pom.xml b/xchange-bitso/pom.xml index b33e203d35a..5af137e13b1 100644 --- a/xchange-bitso/pom.xml +++ b/xchange-bitso/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-bitso diff --git a/xchange-bitstamp/pom.xml b/xchange-bitstamp/pom.xml index 8e3004aa9cf..df159fe971a 100644 --- a/xchange-bitstamp/pom.xml +++ b/xchange-bitstamp/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-bitstamp diff --git a/xchange-bittrex/pom.xml b/xchange-bittrex/pom.xml index bf13dccc6a2..f0c913e224c 100644 --- a/xchange-bittrex/pom.xml +++ b/xchange-bittrex/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-bittrex diff --git a/xchange-bity/pom.xml b/xchange-bity/pom.xml index dcde294d79c..8244312308b 100644 --- a/xchange-bity/pom.xml +++ b/xchange-bity/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-bity diff --git a/xchange-bitz/pom.xml b/xchange-bitz/pom.xml index 589d18e2a10..40770a1dde6 100644 --- a/xchange-bitz/pom.xml +++ b/xchange-bitz/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-bitz diff --git a/xchange-bl3p/pom.xml b/xchange-bl3p/pom.xml index f150454e95f..86b844be2ba 100644 --- a/xchange-bl3p/pom.xml +++ b/xchange-bl3p/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-bl3p diff --git a/xchange-bleutrade/pom.xml b/xchange-bleutrade/pom.xml index 4b782365c47..afcec3a7cb8 100644 --- a/xchange-bleutrade/pom.xml +++ b/xchange-bleutrade/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-bleutrade diff --git a/xchange-blockchain/pom.xml b/xchange-blockchain/pom.xml index 6da4d450e4e..9b2bcf75ffc 100644 --- a/xchange-blockchain/pom.xml +++ b/xchange-blockchain/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-blockchain diff --git a/xchange-btcc/pom.xml b/xchange-btcc/pom.xml index af81e77690b..16b763b5aff 100644 --- a/xchange-btcc/pom.xml +++ b/xchange-btcc/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-btcc diff --git a/xchange-btcmarkets/pom.xml b/xchange-btcmarkets/pom.xml index 912b8819d0a..088e65c512c 100644 --- a/xchange-btcmarkets/pom.xml +++ b/xchange-btcmarkets/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-btcmarkets diff --git a/xchange-btcturk/pom.xml b/xchange-btcturk/pom.xml index a45e95e42e1..997622d6268 100644 --- a/xchange-btcturk/pom.xml +++ b/xchange-btcturk/pom.xml @@ -6,7 +6,7 @@ xchange-parent org.knowm.xchange - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-btcturk diff --git a/xchange-bybit/pom.xml b/xchange-bybit/pom.xml index 3a4c4d301dc..1744032fd33 100644 --- a/xchange-bybit/pom.xml +++ b/xchange-bybit/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-bybit diff --git a/xchange-ccex/pom.xml b/xchange-ccex/pom.xml index a1031dc0247..a74f3516630 100644 --- a/xchange-ccex/pom.xml +++ b/xchange-ccex/pom.xml @@ -4,7 +4,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-ccex XChange C-Cex diff --git a/xchange-cexio/pom.xml b/xchange-cexio/pom.xml index 978dfbabee5..b777d928708 100644 --- a/xchange-cexio/pom.xml +++ b/xchange-cexio/pom.xml @@ -6,7 +6,7 @@ xchange-parent org.knowm.xchange - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-cexio diff --git a/xchange-coinbase/pom.xml b/xchange-coinbase/pom.xml index af39f7f0f78..da6418c6790 100644 --- a/xchange-coinbase/pom.xml +++ b/xchange-coinbase/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-coinbase diff --git a/xchange-coinbasepro/pom.xml b/xchange-coinbasepro/pom.xml index 749879296f1..2c1e5c65cd9 100644 --- a/xchange-coinbasepro/pom.xml +++ b/xchange-coinbasepro/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-coinbasepro diff --git a/xchange-coincheck/pom.xml b/xchange-coincheck/pom.xml index 4ce1cfd3e26..f996475908c 100644 --- a/xchange-coincheck/pom.xml +++ b/xchange-coincheck/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-coincheck diff --git a/xchange-coindeal/pom.xml b/xchange-coindeal/pom.xml index b841eb58acc..25c306bc6dc 100644 --- a/xchange-coindeal/pom.xml +++ b/xchange-coindeal/pom.xml @@ -3,7 +3,7 @@ xchange-parent org.knowm.xchange - 5.1.1-SNAPSHOT + 5.1.1.bigscoop 4.0.0 diff --git a/xchange-coindirect/pom.xml b/xchange-coindirect/pom.xml index 3c1db7cc9ca..98665947fdb 100644 --- a/xchange-coindirect/pom.xml +++ b/xchange-coindirect/pom.xml @@ -5,7 +5,7 @@ xchange-parent org.knowm.xchange - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-coindirect diff --git a/xchange-coinegg/pom.xml b/xchange-coinegg/pom.xml index 4092c8e2e31..95cdba46b50 100644 --- a/xchange-coinegg/pom.xml +++ b/xchange-coinegg/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-coinegg diff --git a/xchange-coinex/pom.xml b/xchange-coinex/pom.xml index f54a7e3aaa3..80513cf4bfb 100644 --- a/xchange-coinex/pom.xml +++ b/xchange-coinex/pom.xml @@ -3,7 +3,7 @@ xchange-parent org.knowm.xchange - 5.1.1-SNAPSHOT + 5.1.1.bigscoop 4.0.0 diff --git a/xchange-coinfloor/pom.xml b/xchange-coinfloor/pom.xml index 50cc60bdcf6..07c638a3020 100644 --- a/xchange-coinfloor/pom.xml +++ b/xchange-coinfloor/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-coinfloor diff --git a/xchange-coingi/pom.xml b/xchange-coingi/pom.xml index 18a31b7b2dd..d42d98f4c60 100644 --- a/xchange-coingi/pom.xml +++ b/xchange-coingi/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-coingi diff --git a/xchange-coinjar/pom.xml b/xchange-coinjar/pom.xml index ff54d945c59..f86e5c97233 100644 --- a/xchange-coinjar/pom.xml +++ b/xchange-coinjar/pom.xml @@ -5,7 +5,7 @@ xchange-parent org.knowm.xchange - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-coinjar diff --git a/xchange-coinmarketcap/pom.xml b/xchange-coinmarketcap/pom.xml index 5171b6a57f9..16cdca08ee7 100644 --- a/xchange-coinmarketcap/pom.xml +++ b/xchange-coinmarketcap/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-coinmarketcap diff --git a/xchange-coinmate/pom.xml b/xchange-coinmate/pom.xml index 4f91ee96f48..3068e488687 100644 --- a/xchange-coinmate/pom.xml +++ b/xchange-coinmate/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-coinmate diff --git a/xchange-coinone/pom.xml b/xchange-coinone/pom.xml index 6f05aa7c873..a3efe4f09f9 100644 --- a/xchange-coinone/pom.xml +++ b/xchange-coinone/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-coinone diff --git a/xchange-core/pom.xml b/xchange-core/pom.xml index 1c2fe98a13a..b285a74d544 100644 --- a/xchange-core/pom.xml +++ b/xchange-core/pom.xml @@ -3,7 +3,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-core diff --git a/xchange-cryptowatch/pom.xml b/xchange-cryptowatch/pom.xml index fce45a676c1..9a56132e07a 100644 --- a/xchange-cryptowatch/pom.xml +++ b/xchange-cryptowatch/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-cryptowatch diff --git a/xchange-deribit/pom.xml b/xchange-deribit/pom.xml index b1a13b5df07..20f03904b28 100644 --- a/xchange-deribit/pom.xml +++ b/xchange-deribit/pom.xml @@ -4,7 +4,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-deribit diff --git a/xchange-dvchain/pom.xml b/xchange-dvchain/pom.xml index 01307da36ae..f51b8d6898a 100644 --- a/xchange-dvchain/pom.xml +++ b/xchange-dvchain/pom.xml @@ -3,7 +3,7 @@ xchange-parent org.knowm.xchange - 5.1.1-SNAPSHOT + 5.1.1.bigscoop 4.0.0 diff --git a/xchange-dydx/pom.xml b/xchange-dydx/pom.xml index 458d0e761a7..2bc537da874 100644 --- a/xchange-dydx/pom.xml +++ b/xchange-dydx/pom.xml @@ -3,7 +3,7 @@ xchange-parent org.knowm.xchange - 5.1.1-SNAPSHOT + 5.1.1.bigscoop 4.0.0 diff --git a/xchange-enigma/pom.xml b/xchange-enigma/pom.xml index 2963a5d93fc..2206c73383c 100644 --- a/xchange-enigma/pom.xml +++ b/xchange-enigma/pom.xml @@ -5,7 +5,7 @@ xchange-parent org.knowm.xchange - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-enigma diff --git a/xchange-examples/pom.xml b/xchange-examples/pom.xml index 997bf9a00f5..162f7f9b265 100755 --- a/xchange-examples/pom.xml +++ b/xchange-examples/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-examples diff --git a/xchange-exmo/pom.xml b/xchange-exmo/pom.xml index 63459974f3b..15f649eb6dc 100644 --- a/xchange-exmo/pom.xml +++ b/xchange-exmo/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-exmo diff --git a/xchange-ftx/pom.xml b/xchange-ftx/pom.xml index 6c1692ff200..a5e0697d993 100644 --- a/xchange-ftx/pom.xml +++ b/xchange-ftx/pom.xml @@ -6,7 +6,7 @@ xchange-parent org.knowm.xchange - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-ftx diff --git a/xchange-gateio/pom.xml b/xchange-gateio/pom.xml index c1703304be8..8d0faf4c3fc 100644 --- a/xchange-gateio/pom.xml +++ b/xchange-gateio/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-gateio diff --git a/xchange-gemini/pom.xml b/xchange-gemini/pom.xml index 14b04317fac..629e2f87f97 100644 --- a/xchange-gemini/pom.xml +++ b/xchange-gemini/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-gemini diff --git a/xchange-globitex/pom.xml b/xchange-globitex/pom.xml index 017073f1ff9..37564ee3366 100644 --- a/xchange-globitex/pom.xml +++ b/xchange-globitex/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-globitex diff --git a/xchange-hitbtc/pom.xml b/xchange-hitbtc/pom.xml index d9af0b7c655..e3603b03ec9 100644 --- a/xchange-hitbtc/pom.xml +++ b/xchange-hitbtc/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-hitbtc diff --git a/xchange-huobi/pom.xml b/xchange-huobi/pom.xml index 3eaf60913ed..c68b0a31f2e 100644 --- a/xchange-huobi/pom.xml +++ b/xchange-huobi/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-huobi diff --git a/xchange-idex/pom.xml b/xchange-idex/pom.xml index 64b10f25661..b0b01136106 100644 --- a/xchange-idex/pom.xml +++ b/xchange-idex/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-idex diff --git a/xchange-independentreserve/pom.xml b/xchange-independentreserve/pom.xml index 8c6dd6838d4..7c38fdd323c 100644 --- a/xchange-independentreserve/pom.xml +++ b/xchange-independentreserve/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-independentreserve diff --git a/xchange-itbit/pom.xml b/xchange-itbit/pom.xml index e7ac04a0019..a122b4d62a6 100644 --- a/xchange-itbit/pom.xml +++ b/xchange-itbit/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-itbit diff --git a/xchange-koineks/pom.xml b/xchange-koineks/pom.xml index 4abf5d3536c..a3c19a80c5f 100644 --- a/xchange-koineks/pom.xml +++ b/xchange-koineks/pom.xml @@ -3,7 +3,7 @@ xchange-parent org.knowm.xchange - 5.1.1-SNAPSHOT + 5.1.1.bigscoop 4.0.0 diff --git a/xchange-koinim/pom.xml b/xchange-koinim/pom.xml index 2b1028f15fb..93de038abab 100644 --- a/xchange-koinim/pom.xml +++ b/xchange-koinim/pom.xml @@ -3,7 +3,7 @@ xchange-parent org.knowm.xchange - 5.1.1-SNAPSHOT + 5.1.1.bigscoop 4.0.0 diff --git a/xchange-kraken/pom.xml b/xchange-kraken/pom.xml index 45ede20f403..d8217b89ff6 100644 --- a/xchange-kraken/pom.xml +++ b/xchange-kraken/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-kraken diff --git a/xchange-krakenfutures/pom.xml b/xchange-krakenfutures/pom.xml index abf75c4bbe1..0b6f93e3a7d 100644 --- a/xchange-krakenfutures/pom.xml +++ b/xchange-krakenfutures/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-krakenfutures diff --git a/xchange-kucoin/pom.xml b/xchange-kucoin/pom.xml index 5601fc086e4..deb0dc2d133 100644 --- a/xchange-kucoin/pom.xml +++ b/xchange-kucoin/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-kucoin diff --git a/xchange-kuna/pom.xml b/xchange-kuna/pom.xml index b33de315225..957e07a44a2 100644 --- a/xchange-kuna/pom.xml +++ b/xchange-kuna/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-kuna diff --git a/xchange-latoken/pom.xml b/xchange-latoken/pom.xml index 6d27f6ea484..2f888a75695 100644 --- a/xchange-latoken/pom.xml +++ b/xchange-latoken/pom.xml @@ -5,7 +5,7 @@ xchange-parent org.knowm.xchange - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-latoken diff --git a/xchange-lgo/pom.xml b/xchange-lgo/pom.xml index 22509aecf09..5a82f0bb616 100644 --- a/xchange-lgo/pom.xml +++ b/xchange-lgo/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-lgo diff --git a/xchange-livecoin/pom.xml b/xchange-livecoin/pom.xml index cca3cccfc08..413b9cdc11a 100644 --- a/xchange-livecoin/pom.xml +++ b/xchange-livecoin/pom.xml @@ -3,7 +3,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-livecoin XChange Livecoin diff --git a/xchange-luno/pom.xml b/xchange-luno/pom.xml index 6850ca511bf..63a05efae23 100644 --- a/xchange-luno/pom.xml +++ b/xchange-luno/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-luno diff --git a/xchange-lykke/pom.xml b/xchange-lykke/pom.xml index 67bf7470fdd..f438d39e072 100644 --- a/xchange-lykke/pom.xml +++ b/xchange-lykke/pom.xml @@ -3,7 +3,7 @@ xchange-parent org.knowm.xchange - 5.1.1-SNAPSHOT + 5.1.1.bigscoop 4.0.0 diff --git a/xchange-mercadobitcoin/pom.xml b/xchange-mercadobitcoin/pom.xml index ed27baf0dca..464a3515af5 100644 --- a/xchange-mercadobitcoin/pom.xml +++ b/xchange-mercadobitcoin/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-mercadobitcoin diff --git a/xchange-mexc/pom.xml b/xchange-mexc/pom.xml index ba80e3d2729..8f75d41cdd1 100644 --- a/xchange-mexc/pom.xml +++ b/xchange-mexc/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-mexc diff --git a/xchange-okcoin/pom.xml b/xchange-okcoin/pom.xml index 2bfb2cf4223..b0c8c5a8003 100644 --- a/xchange-okcoin/pom.xml +++ b/xchange-okcoin/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-okcoin diff --git a/xchange-okex/pom.xml b/xchange-okex/pom.xml index 75244922842..45741505db0 100644 --- a/xchange-okex/pom.xml +++ b/xchange-okex/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-okex diff --git a/xchange-openexchangerates/pom.xml b/xchange-openexchangerates/pom.xml index acc11c780f8..983f700dcd8 100644 --- a/xchange-openexchangerates/pom.xml +++ b/xchange-openexchangerates/pom.xml @@ -4,7 +4,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-openexchangerates diff --git a/xchange-paribu/pom.xml b/xchange-paribu/pom.xml index 86245c5272c..c79d1714379 100644 --- a/xchange-paribu/pom.xml +++ b/xchange-paribu/pom.xml @@ -3,7 +3,7 @@ xchange-parent org.knowm.xchange - 5.1.1-SNAPSHOT + 5.1.1.bigscoop 4.0.0 diff --git a/xchange-paymium/pom.xml b/xchange-paymium/pom.xml index 4779e63ce0f..647458f0bde 100644 --- a/xchange-paymium/pom.xml +++ b/xchange-paymium/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-paymium diff --git a/xchange-poloniex/pom.xml b/xchange-poloniex/pom.xml index 9d81302b6a9..49b56c54e29 100755 --- a/xchange-poloniex/pom.xml +++ b/xchange-poloniex/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-poloniex diff --git a/xchange-quoine/pom.xml b/xchange-quoine/pom.xml index 59ad3ec56c3..35c0f76d949 100644 --- a/xchange-quoine/pom.xml +++ b/xchange-quoine/pom.xml @@ -3,7 +3,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-quoine diff --git a/xchange-ripple/pom.xml b/xchange-ripple/pom.xml index 0efb377f889..a7418fd5ffd 100644 --- a/xchange-ripple/pom.xml +++ b/xchange-ripple/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-ripple diff --git a/xchange-serum/pom.xml b/xchange-serum/pom.xml index 2f037834524..c522abb3c05 100644 --- a/xchange-serum/pom.xml +++ b/xchange-serum/pom.xml @@ -3,7 +3,7 @@ xchange-parent org.knowm.xchange - 5.1.1-SNAPSHOT + 5.1.1.bigscoop 4.0.0 diff --git a/xchange-simulated/pom.xml b/xchange-simulated/pom.xml index a537c2eeb74..d7ea0bf4d0e 100644 --- a/xchange-simulated/pom.xml +++ b/xchange-simulated/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-simulated diff --git a/xchange-stream-bankera/pom.xml b/xchange-stream-bankera/pom.xml index 91c44b418b2..0074e90adbd 100644 --- a/xchange-stream-bankera/pom.xml +++ b/xchange-stream-bankera/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop XChange Bankera Stream diff --git a/xchange-stream-binance/pom.xml b/xchange-stream-binance/pom.xml index 5e1eb990e06..d6eb2b49a21 100644 --- a/xchange-stream-binance/pom.xml +++ b/xchange-stream-binance/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop XChange Binance Stream diff --git a/xchange-stream-bitfinex/pom.xml b/xchange-stream-bitfinex/pom.xml index 118498a6145..42ae0b99e4d 100644 --- a/xchange-stream-bitfinex/pom.xml +++ b/xchange-stream-bitfinex/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop XChange Bitfinex Stream diff --git a/xchange-stream-bitflyer/pom.xml b/xchange-stream-bitflyer/pom.xml index c6e655388b1..6b689fb30c0 100644 --- a/xchange-stream-bitflyer/pom.xml +++ b/xchange-stream-bitflyer/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop XChange Bitflyer Stream diff --git a/xchange-stream-bitmex/pom.xml b/xchange-stream-bitmex/pom.xml index d41adb8c405..33ddc7ddb42 100644 --- a/xchange-stream-bitmex/pom.xml +++ b/xchange-stream-bitmex/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop XChange Bitmex Stream diff --git a/xchange-stream-bitstamp/pom.xml b/xchange-stream-bitstamp/pom.xml index f0a68bdb48a..7bf01611bc9 100644 --- a/xchange-stream-bitstamp/pom.xml +++ b/xchange-stream-bitstamp/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop XChange Bitstamp Stream diff --git a/xchange-stream-btcmarkets/pom.xml b/xchange-stream-btcmarkets/pom.xml index 9cc1955e490..0eeb4442ec2 100644 --- a/xchange-stream-btcmarkets/pom.xml +++ b/xchange-stream-btcmarkets/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop XChange BTCMarkets Stream diff --git a/xchange-stream-cexio/pom.xml b/xchange-stream-cexio/pom.xml index b5748d166c6..8f1c941eae9 100644 --- a/xchange-stream-cexio/pom.xml +++ b/xchange-stream-cexio/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop XChange Cex.io Stream diff --git a/xchange-stream-coinbasepro/pom.xml b/xchange-stream-coinbasepro/pom.xml index 45cc3e7a124..8d4a66c56f1 100644 --- a/xchange-stream-coinbasepro/pom.xml +++ b/xchange-stream-coinbasepro/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop XChange CoinbasePro Stream diff --git a/xchange-stream-coincheck/pom.xml b/xchange-stream-coincheck/pom.xml index 4b61813b494..07a3d083e0d 100644 --- a/xchange-stream-coincheck/pom.xml +++ b/xchange-stream-coincheck/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop XChange Coincheck Stream diff --git a/xchange-stream-coinjar/pom.xml b/xchange-stream-coinjar/pom.xml index 96e2d2307b4..960c378e483 100644 --- a/xchange-stream-coinjar/pom.xml +++ b/xchange-stream-coinjar/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop XChange Coinjar Stream diff --git a/xchange-stream-coinmate/pom.xml b/xchange-stream-coinmate/pom.xml index fb4f2973668..232eee56e25 100644 --- a/xchange-stream-coinmate/pom.xml +++ b/xchange-stream-coinmate/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop XChange Coinmate Stream diff --git a/xchange-stream-core/pom.xml b/xchange-stream-core/pom.xml index 373ef95b891..9d96e15523f 100644 --- a/xchange-stream-core/pom.xml +++ b/xchange-stream-core/pom.xml @@ -3,7 +3,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop 4.0.0 diff --git a/xchange-stream-dydx/pom.xml b/xchange-stream-dydx/pom.xml index bc35901c74e..9d513650473 100644 --- a/xchange-stream-dydx/pom.xml +++ b/xchange-stream-dydx/pom.xml @@ -3,7 +3,7 @@ xchange-parent org.knowm.xchange - 5.1.1-SNAPSHOT + 5.1.1.bigscoop 4.0.0 diff --git a/xchange-stream-ftx/pom.xml b/xchange-stream-ftx/pom.xml index b14b66f8879..1d8dc2e4c9f 100644 --- a/xchange-stream-ftx/pom.xml +++ b/xchange-stream-ftx/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop XChange Ftx Stream diff --git a/xchange-stream-gateio/pom.xml b/xchange-stream-gateio/pom.xml index c182194bf67..37d7cf2ba87 100644 --- a/xchange-stream-gateio/pom.xml +++ b/xchange-stream-gateio/pom.xml @@ -3,7 +3,7 @@ xchange-parent org.knowm.xchange - 5.1.1-SNAPSHOT + 5.1.1.bigscoop 4.0.0 diff --git a/xchange-stream-gemini-v2/pom.xml b/xchange-stream-gemini-v2/pom.xml index bbda9c81033..d254e1f2469 100644 --- a/xchange-stream-gemini-v2/pom.xml +++ b/xchange-stream-gemini-v2/pom.xml @@ -9,7 +9,7 @@ xchange-parent org.knowm.xchange - 5.1.1-SNAPSHOT + 5.1.1.bigscoop diff --git a/xchange-stream-gemini/pom.xml b/xchange-stream-gemini/pom.xml index ec035a31a1f..74c4d4363bc 100644 --- a/xchange-stream-gemini/pom.xml +++ b/xchange-stream-gemini/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop XChange Gemini Stream diff --git a/xchange-stream-hitbtc/pom.xml b/xchange-stream-hitbtc/pom.xml index 5a3f79401ee..a049cd43373 100644 --- a/xchange-stream-hitbtc/pom.xml +++ b/xchange-stream-hitbtc/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop XChange Hitbtc Stream diff --git a/xchange-stream-huobi/pom.xml b/xchange-stream-huobi/pom.xml index 6ae33aa6dd2..374eb219183 100644 --- a/xchange-stream-huobi/pom.xml +++ b/xchange-stream-huobi/pom.xml @@ -3,7 +3,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop 4.0.0 diff --git a/xchange-stream-kraken/pom.xml b/xchange-stream-kraken/pom.xml index 1cb5a278eee..9165c26fe5f 100644 --- a/xchange-stream-kraken/pom.xml +++ b/xchange-stream-kraken/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop XChange Kraken Stream diff --git a/xchange-stream-krakenfutures/pom.xml b/xchange-stream-krakenfutures/pom.xml index e7f032843d9..6536a6cf5c7 100644 --- a/xchange-stream-krakenfutures/pom.xml +++ b/xchange-stream-krakenfutures/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-stream-krakenfutures diff --git a/xchange-stream-kucoin/pom.xml b/xchange-stream-kucoin/pom.xml index 33beba770dd..24b95b0cda1 100644 --- a/xchange-stream-kucoin/pom.xml +++ b/xchange-stream-kucoin/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop XChange Kucoin Stream diff --git a/xchange-stream-lgo/pom.xml b/xchange-stream-lgo/pom.xml index 5699c7f355f..03c7d7df312 100644 --- a/xchange-stream-lgo/pom.xml +++ b/xchange-stream-lgo/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop XChange LGO Stream diff --git a/xchange-stream-okcoin/pom.xml b/xchange-stream-okcoin/pom.xml index 7f58e7b7054..d57d513ec09 100644 --- a/xchange-stream-okcoin/pom.xml +++ b/xchange-stream-okcoin/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop XChange OKCoin Stream diff --git a/xchange-stream-okex/pom.xml b/xchange-stream-okex/pom.xml index a39c5812218..cce005af2d0 100644 --- a/xchange-stream-okex/pom.xml +++ b/xchange-stream-okex/pom.xml @@ -6,7 +6,7 @@ xchange-parent org.knowm.xchange - 5.1.1-SNAPSHOT + 5.1.1.bigscoop XChange Okex Stream diff --git a/xchange-stream-poloniex2/pom.xml b/xchange-stream-poloniex2/pom.xml index 23ecca7cb7d..f708dedf60e 100644 --- a/xchange-stream-poloniex2/pom.xml +++ b/xchange-stream-poloniex2/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop XChange Poloniex 2 Stream diff --git a/xchange-stream-serum/pom.xml b/xchange-stream-serum/pom.xml index 2778be0cedf..311ca5b0522 100644 --- a/xchange-stream-serum/pom.xml +++ b/xchange-stream-serum/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop XChange Serum Stream diff --git a/xchange-stream-service-core/pom.xml b/xchange-stream-service-core/pom.xml index 9a2a333617b..4bc3d9c3049 100644 --- a/xchange-stream-service-core/pom.xml +++ b/xchange-stream-service-core/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop XChange Core Stream Service diff --git a/xchange-stream-service-netty/pom.xml b/xchange-stream-service-netty/pom.xml index aba65d517fd..b99fb4c08bb 100644 --- a/xchange-stream-service-netty/pom.xml +++ b/xchange-stream-service-netty/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop XChange Core Stream Netty diff --git a/xchange-stream-service-pubnub/pom.xml b/xchange-stream-service-pubnub/pom.xml index 6f73e624a4f..1f3c3ba4322 100644 --- a/xchange-stream-service-pubnub/pom.xml +++ b/xchange-stream-service-pubnub/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop XChange Core Stream Pubnub diff --git a/xchange-therock/pom.xml b/xchange-therock/pom.xml index 035c3ccd7cb..cf83b30c605 100644 --- a/xchange-therock/pom.xml +++ b/xchange-therock/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-therock diff --git a/xchange-tradeogre/pom.xml b/xchange-tradeogre/pom.xml index 589941b3ad5..bbaa789399f 100644 --- a/xchange-tradeogre/pom.xml +++ b/xchange-tradeogre/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-tradeogre diff --git a/xchange-truefx/pom.xml b/xchange-truefx/pom.xml index 7ce3b63e608..0812c77afba 100644 --- a/xchange-truefx/pom.xml +++ b/xchange-truefx/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-truefx diff --git a/xchange-upbit/pom.xml b/xchange-upbit/pom.xml index 7d6cf373af4..90585737b65 100644 --- a/xchange-upbit/pom.xml +++ b/xchange-upbit/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-upbit diff --git a/xchange-vaultoro/pom.xml b/xchange-vaultoro/pom.xml index f402ccf4801..a050d8c4285 100644 --- a/xchange-vaultoro/pom.xml +++ b/xchange-vaultoro/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-vaultoro diff --git a/xchange-yobit/pom.xml b/xchange-yobit/pom.xml index 97bc36a0b87..0edb8654da5 100644 --- a/xchange-yobit/pom.xml +++ b/xchange-yobit/pom.xml @@ -3,7 +3,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-yobit XChange YoBit diff --git a/xchange-zaif/pom.xml b/xchange-zaif/pom.xml index 71bf905b873..5d4b40e7301 100644 --- a/xchange-zaif/pom.xml +++ b/xchange-zaif/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1-SNAPSHOT + 5.1.1.bigscoop xchange-zaif From 4e27207573e7debbf1a12d1a2024b742a7b3ecaf Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Thu, 3 Aug 2023 00:38:16 +0200 Subject: [PATCH 049/159] [gateio-v4] Extend tests --- .../service/GateioTradeServiceTest.java | 28 +++++++++++----- ..._v4_spot_orders-valid-limit-buy-order.json | 32 +++++++++++++++++++ ..._v4_spot_orders-valid-limit-buy-order.json | 20 ++++++++++++ 3 files changed, 72 insertions(+), 8 deletions(-) create mode 100644 xchange-gateio-v4/src/test/resources/__files/api_v4_spot_orders-valid-limit-buy-order.json create mode 100644 xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_orders-valid-limit-buy-order.json diff --git a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioTradeServiceTest.java b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioTradeServiceTest.java index f60facd89df..b61b28b68e7 100644 --- a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioTradeServiceTest.java +++ b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioTradeServiceTest.java @@ -1,5 +1,12 @@ package org.knowm.xchange.gateio.service; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; + +import java.io.IOException; +import java.math.BigDecimal; +import java.time.Instant; +import java.util.Date; import org.junit.jupiter.api.Test; import org.knowm.xchange.currency.CurrencyPair; import org.knowm.xchange.dto.Order.OrderStatus; @@ -10,14 +17,6 @@ import org.knowm.xchange.gateio.GateioExchangeWiremock; import org.knowm.xchange.service.trade.params.orders.DefaultQueryOrderParamInstrument; -import java.io.IOException; -import java.math.BigDecimal; -import java.time.Instant; -import java.util.Date; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; - class GateioTradeServiceTest extends GateioExchangeWiremock { GateioTradeService gateioTradeService = (GateioTradeService) exchange.getTradeService(); @@ -74,6 +73,19 @@ void valid_limit_sell_order() throws IOException { } + @Test + void valid_limit_buy_order() throws IOException { + LimitOrder limitOrder = new LimitOrder.Builder(OrderType.BID, CurrencyPair.BTC_USDT) + .userReference("t-valid-limit-buy-order") + .originalAmount(new BigDecimal("0.00068")) + .limitPrice(new BigDecimal("10000.7")) + .build(); + + var actualResponse = gateioTradeService.placeLimitOrder(limitOrder); + assertThat(actualResponse).isEqualTo("376835979523"); + } + + @Test void order_details() throws IOException { MarketOrder expected = new MarketOrder.Builder(OrderType.BID, CurrencyPair.BTC_USDT) diff --git a/xchange-gateio-v4/src/test/resources/__files/api_v4_spot_orders-valid-limit-buy-order.json b/xchange-gateio-v4/src/test/resources/__files/api_v4_spot_orders-valid-limit-buy-order.json new file mode 100644 index 00000000000..bb7b1ed43a0 --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/__files/api_v4_spot_orders-valid-limit-buy-order.json @@ -0,0 +1,32 @@ +{ + "id": "376835979523", + "text": "t-valid-limit-buy-order", + "amend_text": "-", + "create_time": "1691015713", + "update_time": "1691015713", + "create_time_ms": 1691015713247, + "update_time_ms": 1691015713247, + "status": "open", + "currency_pair": "BTC_USDT", + "type": "limit", + "account": "spot", + "side": "buy", + "amount": "0.00068", + "price": "10000.7", + "biz_info": "-", + "time_in_force": "gtc", + "iceberg": "0", + "left": "0.00068", + "fill_price": "0", + "filled_total": "0", + "fee": "0", + "fee_currency": "BTC", + "point_fee": "0", + "gt_fee": "0", + "gt_maker_fee": "0", + "gt_taker_fee": "0", + "gt_discount": false, + "rebated_fee": "0", + "rebated_fee_currency": "USDT", + "finish_as": "open" +} \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_orders-valid-limit-buy-order.json b/xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_orders-valid-limit-buy-order.json new file mode 100644 index 00000000000..656848548e2 --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_orders-valid-limit-buy-order.json @@ -0,0 +1,20 @@ +{ + "id" : "de1a7911-c7dd-4151-b92e-7f3654aaf1d1", + "name" : "api_v4_spot_orders", + "request" : { + "url" : "/api/v4/spot/orders", + "method" : "POST", + "bodyPatterns" : [ { + "equalToJson" : "{\"id\":null,\"text\":\"t-valid-limit-buy-order\",\"amend_text\":null,\"create_time_ms\":null,\"update_time_ms\":null,\"status\":null,\"currency_pair\":\"BTC_USDT\",\"type\":\"limit\",\"account\":\"spot\",\"side\":\"buy\",\"amount\":0.00068,\"price\":10000.7,\"time_in_force\":\"gtc\",\"iceberg\":null,\"auto_borrow\":null,\"auto_repay\":null,\"left\":null,\"filled_total\":null,\"avg_deal_price\":null,\"fee\":null,\"fee_currency\":null,\"point_fee\":null,\"gt_fee\":null,\"gt_maker_fee\":null,\"gt_taker_fee\":null,\"gt_discount\":null,\"rebated_fee\":null,\"rebated_fee_currency\":null,\"stp_id\":null,\"stp_act\":null,\"finish_as\":null}", + "ignoreArrayOrder" : true, + "ignoreExtraElements" : true + } ] + }, + "response" : { + "status" : 201, + "bodyFileName" : "api_v4_spot_orders-valid-limit-buy-order.json" + }, + "uuid" : "de1a7911-c7dd-4151-b92e-7f3654aaf1d1", + "persistent" : true, + "insertionIndex" : 30 +} \ No newline at end of file From 3af754f398895927ca983204198d6a80683ec40b Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Thu, 3 Aug 2023 00:57:24 +0200 Subject: [PATCH 050/159] [core] Add order cancelling --- .../xchange/gateio/GateioV4Authenticated.java | 12 +++++ .../gateio/service/GateioTradeService.java | 44 +++++++++++++++++-- .../gateio/service/GateioTradeServiceRaw.java | 14 ++++-- .../service/GateioTradeServiceTest.java | 8 ++++ ...api_v4_spot_orders-valid-cancel-order.json | 32 ++++++++++++++ ...api_v4_spot_orders-valid-cancel-order.json | 15 +++++++ 6 files changed, 117 insertions(+), 8 deletions(-) create mode 100644 xchange-gateio-v4/src/test/resources/__files/api_v4_spot_orders-valid-cancel-order.json create mode 100644 xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_orders-valid-cancel-order.json diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java index c23f5aa4c72..fc77308690e 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java @@ -3,6 +3,7 @@ import java.io.IOException; import java.util.List; import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; import javax.ws.rs.GET; import javax.ws.rs.HeaderParam; import javax.ws.rs.POST; @@ -78,6 +79,17 @@ GateioOrder getOrder( ) throws IOException, GateioException; + @DELETE + @Path("spot/orders/{order_id}") + GateioOrder cancelOrder( + @HeaderParam("KEY") String apiKey, + @HeaderParam("Timestamp") SynchronizedValueFactory timestamp, + @HeaderParam("SIGN") ParamsDigest signer, + @PathParam("order_id") String orderId, + @QueryParam("currency_pair") String currencyPair + ) throws IOException, GateioException; + + @POST @Path("spot/orders") @Consumes(MediaType.APPLICATION_JSON) diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeService.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeService.java index 5c69fad3a8f..8bc374a97e3 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeService.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeService.java @@ -1,7 +1,11 @@ package org.knowm.xchange.gateio.service; +import java.io.IOException; +import java.util.Collection; +import java.util.List; import org.apache.commons.lang3.Validate; import org.knowm.xchange.dto.Order; +import org.knowm.xchange.dto.Order.OrderStatus; import org.knowm.xchange.dto.trade.LimitOrder; import org.knowm.xchange.dto.trade.MarketOrder; import org.knowm.xchange.gateio.GateioAdapters; @@ -9,16 +13,15 @@ import org.knowm.xchange.gateio.GateioExchange; import org.knowm.xchange.gateio.dto.GateioException; import org.knowm.xchange.gateio.dto.account.GateioOrder; +import org.knowm.xchange.instrument.Instrument; import org.knowm.xchange.service.trade.TradeService; +import org.knowm.xchange.service.trade.params.CancelOrderParams; +import org.knowm.xchange.service.trade.params.DefaultCancelOrderByInstrumentAndIdParams; import org.knowm.xchange.service.trade.params.DefaultTradeHistoryParamCurrencyPair; import org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair; import org.knowm.xchange.service.trade.params.orders.OrderQueryParamInstrument; import org.knowm.xchange.service.trade.params.orders.OrderQueryParams; -import java.io.IOException; -import java.util.Collection; -import java.util.List; - public class GateioTradeService extends GateioTradeServiceRaw implements TradeService { public GateioTradeService(GateioExchange exchange) { @@ -67,6 +70,39 @@ public Collection getOrder(OrderQueryParams... orderQueryParams) throws I } } + + public Order cancelOrder(String orderId, Instrument instrument) throws IOException { + try { + GateioOrder gateioOrder = cancelOrderRaw(orderId, instrument); + return GateioAdapters.toOrder(gateioOrder); + } + catch (GateioException e) { + throw GateioErrorAdapter.adapt(e); + } + } + + + @Override + public boolean cancelOrder(CancelOrderParams orderParams) throws IOException { + Validate.isInstanceOf(DefaultCancelOrderByInstrumentAndIdParams.class, orderParams); + DefaultCancelOrderByInstrumentAndIdParams params = (DefaultCancelOrderByInstrumentAndIdParams) orderParams; + + try { + Order order = cancelOrder(params.getOrderId(), params.getInstrument()); + return order.getStatus() == OrderStatus.CANCELED; + } + catch (GateioException e) { + throw GateioErrorAdapter.adapt(e); + } + } + + + @Override + public Class[] getRequiredCancelOrderParamClasses() { + return new Class[] {DefaultCancelOrderByInstrumentAndIdParams.class}; + } + + @Override public TradeHistoryParamCurrencyPair createTradeHistoryParams() { return new DefaultTradeHistoryParamCurrencyPair(); diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeServiceRaw.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeServiceRaw.java index c7e8a54be23..5414c6474d2 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeServiceRaw.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeServiceRaw.java @@ -1,5 +1,8 @@ package org.knowm.xchange.gateio.service; +import java.io.IOException; +import java.util.List; +import java.util.Set; import org.apache.commons.lang3.Validate; import org.knowm.xchange.dto.Order.OrderStatus; import org.knowm.xchange.gateio.GateioAdapters; @@ -7,10 +10,6 @@ import org.knowm.xchange.gateio.dto.account.GateioOrder; import org.knowm.xchange.instrument.Instrument; -import java.io.IOException; -import java.util.List; -import java.util.Set; - public class GateioTradeServiceRaw extends GateioBaseService { public GateioTradeServiceRaw(GateioExchange exchange) { @@ -42,4 +41,11 @@ public GateioOrder getOrder(String orderId, Instrument instrument) throws IOExce orderId, GateioAdapters.toString(instrument)); } + + public GateioOrder cancelOrderRaw(String orderId, Instrument instrument) throws IOException { + return gateioV4Authenticated.cancelOrder(apiKey, exchange.getNonceFactory(), gateioV4ParamsDigest, + orderId, GateioAdapters.toString(instrument)); + } + + } diff --git a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioTradeServiceTest.java b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioTradeServiceTest.java index b61b28b68e7..c3314622b45 100644 --- a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioTradeServiceTest.java +++ b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioTradeServiceTest.java @@ -15,6 +15,7 @@ import org.knowm.xchange.dto.trade.MarketOrder; import org.knowm.xchange.exceptions.FundsExceededException; import org.knowm.xchange.gateio.GateioExchangeWiremock; +import org.knowm.xchange.service.trade.params.DefaultCancelOrderByInstrumentAndIdParams; import org.knowm.xchange.service.trade.params.orders.DefaultQueryOrderParamInstrument; class GateioTradeServiceTest extends GateioExchangeWiremock { @@ -73,6 +74,13 @@ void valid_limit_sell_order() throws IOException { } + @Test + void valid_cancel_order() throws IOException { + boolean actual = gateioTradeService.cancelOrder(new DefaultCancelOrderByInstrumentAndIdParams(CurrencyPair.BTC_USDT, "376835979523")); + assertThat(actual).isTrue(); + } + + @Test void valid_limit_buy_order() throws IOException { LimitOrder limitOrder = new LimitOrder.Builder(OrderType.BID, CurrencyPair.BTC_USDT) diff --git a/xchange-gateio-v4/src/test/resources/__files/api_v4_spot_orders-valid-cancel-order.json b/xchange-gateio-v4/src/test/resources/__files/api_v4_spot_orders-valid-cancel-order.json new file mode 100644 index 00000000000..2987151a468 --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/__files/api_v4_spot_orders-valid-cancel-order.json @@ -0,0 +1,32 @@ +{ + "id": "376835979523", + "text": "t-valid-limit-sell-order", + "amend_text": "-", + "create_time": "1691015713", + "update_time": "1691016008", + "create_time_ms": 1691015713247, + "update_time_ms": 1691016008216, + "status": "cancelled", + "currency_pair": "BTC_USDT", + "type": "limit", + "account": "spot", + "side": "buy", + "amount": "0.00068", + "price": "10000.7", + "biz_info": "-", + "time_in_force": "gtc", + "iceberg": "0", + "left": "0.00068", + "fill_price": "0", + "filled_total": "0", + "fee": "0", + "fee_currency": "BTC", + "point_fee": "0", + "gt_fee": "0", + "gt_maker_fee": "0", + "gt_taker_fee": "0", + "gt_discount": false, + "rebated_fee": "0", + "rebated_fee_currency": "USDT", + "finish_as": "cancelled" +} \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_orders-valid-cancel-order.json b/xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_orders-valid-cancel-order.json new file mode 100644 index 00000000000..378a102ab95 --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_orders-valid-cancel-order.json @@ -0,0 +1,15 @@ +{ + "id" : "89473a34-023a-4591-9820-e2b5cbebc2ad", + "name" : "api_v4_spot_orders_376835979523", + "request" : { + "url" : "/api/v4/spot/orders/376835979523?currency_pair=BTC_USDT", + "method" : "DELETE" + }, + "response" : { + "status" : 200, + "bodyFileName" : "api_v4_spot_orders-valid-cancel-order.json" + }, + "uuid" : "89473a34-023a-4591-9820-e2b5cbebc2ad", + "persistent" : true, + "insertionIndex" : 31 +} \ No newline at end of file From 0208faa3441090404002dcea1c26736eb7469275 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Fri, 4 Aug 2023 00:30:03 +0200 Subject: [PATCH 051/159] [gateio-v4] Add price mapping for limit orders --- .../org/knowm/xchange/gateio/GateioAdapters.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java index 6e43de942cf..678ce59585e 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java @@ -1,5 +1,9 @@ package org.knowm.xchange.gateio; +import java.util.Date; +import java.util.List; +import java.util.Locale; +import java.util.stream.Collectors; import lombok.experimental.UtilityClass; import org.knowm.xchange.currency.Currency; import org.knowm.xchange.currency.CurrencyPair; @@ -19,11 +23,6 @@ import org.knowm.xchange.gateio.service.params.DefaultGateioWithdrawFundsParams; import org.knowm.xchange.instrument.Instrument; -import java.util.Date; -import java.util.List; -import java.util.Locale; -import java.util.stream.Collectors; - @UtilityClass public class GateioAdapters { @@ -142,7 +141,8 @@ public Order toOrder(GateioOrder gateioOrder) { order = new MarketOrder.Builder(orderType, instrument); break; case "limit": - order = new LimitOrder.Builder(orderType, instrument); + order = new LimitOrder.Builder(orderType, instrument) + .limitPrice(gateioOrder.getPrice()); break; default: throw new IllegalArgumentException("Can't map " + gateioOrder.getType()); From 93d0b2dafd8233986292369680339b27073a5fd6 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Sun, 6 Aug 2023 14:59:45 +0200 Subject: [PATCH 052/159] [gateio-stream] Code cleanup, organize packages --- .../gateio}/GateioStreamingExchange.java | 3 ++- .../gateio}/GateioStreamingMarketDataService.java | 7 ++++--- .../xchangestream/gateio}/GateioStreamingService.java | 11 ++++++----- .../dto/GateioWebSocketSubscriptionMessage.java | 3 +-- .../gateio}/dto/response/GateioOrderBookResponse.java | 3 +-- .../gateio}/dto/response/GateioTradesResponse.java | 3 +-- .../dto/response/GateioWebSocketTransaction.java | 3 +-- .../xchangestream/gateio}/GateioManualExample.java | 4 ++++ .../gateio}/dto/GateioOrderBookResponseTest.java | 4 ++-- .../gateio}/dto/GateioTradesResponseTest.java | 4 ++-- 10 files changed, 24 insertions(+), 21 deletions(-) rename xchange-stream-gateio/src/main/java/{ => info/bitrich/xchangestream/gateio}/GateioStreamingExchange.java (96%) rename xchange-stream-gateio/src/main/java/{ => info/bitrich/xchangestream/gateio}/GateioStreamingMarketDataService.java (91%) rename xchange-stream-gateio/src/main/java/{ => info/bitrich/xchangestream/gateio}/GateioStreamingService.java (94%) rename xchange-stream-gateio/src/main/java/{ => info/bitrich/xchangestream/gateio}/dto/GateioWebSocketSubscriptionMessage.java (94%) rename xchange-stream-gateio/src/main/java/{ => info/bitrich/xchangestream/gateio}/dto/response/GateioOrderBookResponse.java (96%) rename xchange-stream-gateio/src/main/java/{ => info/bitrich/xchangestream/gateio}/dto/response/GateioTradesResponse.java (94%) rename xchange-stream-gateio/src/main/java/{ => info/bitrich/xchangestream/gateio}/dto/response/GateioWebSocketTransaction.java (82%) rename xchange-stream-gateio/src/test/java/{ => info/bitrich/xchangestream/gateio}/GateioManualExample.java (94%) rename xchange-stream-gateio/src/test/java/{ => info/bitrich/xchangestream/gateio}/dto/GateioOrderBookResponseTest.java (92%) rename xchange-stream-gateio/src/test/java/{ => info/bitrich/xchangestream/gateio}/dto/GateioTradesResponseTest.java (92%) diff --git a/xchange-stream-gateio/src/main/java/GateioStreamingExchange.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingExchange.java similarity index 96% rename from xchange-stream-gateio/src/main/java/GateioStreamingExchange.java rename to xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingExchange.java index 16b1ae05677..1a64385a999 100644 --- a/xchange-stream-gateio/src/main/java/GateioStreamingExchange.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingExchange.java @@ -1,3 +1,5 @@ +package info.bitrich.xchangestream.gateio; + import info.bitrich.xchangestream.core.ProductSubscription; import info.bitrich.xchangestream.core.StreamingExchange; import info.bitrich.xchangestream.core.StreamingMarketDataService; @@ -6,7 +8,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -/** Author: Max Gao (gaamox@tutanota.com) Created: 05-05-2021 */ public class GateioStreamingExchange extends GateioExchange implements StreamingExchange { private static final Logger LOG = LoggerFactory.getLogger(GateioStreamingExchange.class); diff --git a/xchange-stream-gateio/src/main/java/GateioStreamingMarketDataService.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingMarketDataService.java similarity index 91% rename from xchange-stream-gateio/src/main/java/GateioStreamingMarketDataService.java rename to xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingMarketDataService.java index 9eb4ee34381..a23855d6f28 100644 --- a/xchange-stream-gateio/src/main/java/GateioStreamingMarketDataService.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingMarketDataService.java @@ -1,6 +1,8 @@ -import dto.response.GateioOrderBookResponse; -import dto.response.GateioTradesResponse; +package info.bitrich.xchangestream.gateio; + import info.bitrich.xchangestream.core.StreamingMarketDataService; +import info.bitrich.xchangestream.gateio.dto.response.GateioOrderBookResponse; +import info.bitrich.xchangestream.gateio.dto.response.GateioTradesResponse; import io.reactivex.Observable; import java.util.List; import org.knowm.xchange.currency.CurrencyPair; @@ -12,7 +14,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -/** Author: Max Gao (gaamox@tutanota.com) Created: 05-05-2021 */ public class GateioStreamingMarketDataService implements StreamingMarketDataService { private static final Logger LOGGER = LoggerFactory.getLogger(GateioStreamingMarketDataService.class); diff --git a/xchange-stream-gateio/src/main/java/GateioStreamingService.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingService.java similarity index 94% rename from xchange-stream-gateio/src/main/java/GateioStreamingService.java rename to xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingService.java index 878c2f13bee..0af0e26d5d0 100644 --- a/xchange-stream-gateio/src/main/java/GateioStreamingService.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingService.java @@ -1,10 +1,12 @@ +package info.bitrich.xchangestream.gateio; + import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; -import dto.GateioWebSocketSubscriptionMessage; -import dto.response.GateioOrderBookResponse; -import dto.response.GateioTradesResponse; -import dto.response.GateioWebSocketTransaction; import info.bitrich.xchangestream.core.ProductSubscription; +import info.bitrich.xchangestream.gateio.dto.GateioWebSocketSubscriptionMessage; +import info.bitrich.xchangestream.gateio.dto.response.GateioOrderBookResponse; +import info.bitrich.xchangestream.gateio.dto.response.GateioTradesResponse; +import info.bitrich.xchangestream.gateio.dto.response.GateioWebSocketTransaction; import info.bitrich.xchangestream.service.netty.JsonNettyStreamingService; import info.bitrich.xchangestream.service.netty.StreamingObjectMapperHelper; import info.bitrich.xchangestream.service.netty.WebSocketClientCompressionAllowClientNoContextAndServerNoContextHandler; @@ -18,7 +20,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -/** Author: Max Gao (gaamox@tutanota.com) Created: 05-05-2021 */ public class GateioStreamingService extends JsonNettyStreamingService { private static final Logger LOG = LoggerFactory.getLogger(GateioStreamingService.class); private static final String SUBSCRIBE = "subscribe"; diff --git a/xchange-stream-gateio/src/main/java/dto/GateioWebSocketSubscriptionMessage.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/GateioWebSocketSubscriptionMessage.java similarity index 94% rename from xchange-stream-gateio/src/main/java/dto/GateioWebSocketSubscriptionMessage.java rename to xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/GateioWebSocketSubscriptionMessage.java index 6b55c31305e..48d244de18c 100644 --- a/xchange-stream-gateio/src/main/java/dto/GateioWebSocketSubscriptionMessage.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/GateioWebSocketSubscriptionMessage.java @@ -1,4 +1,4 @@ -package dto; +package info.bitrich.xchangestream.gateio.dto; import com.fasterxml.jackson.annotation.JsonProperty; import java.time.Instant; @@ -9,7 +9,6 @@ import lombok.Setter; import org.knowm.xchange.currency.CurrencyPair; -/** Author: Max Gao (gaamox@tutanota.com) Created: 05-05-2021 */ @Setter @NoArgsConstructor public class GateioWebSocketSubscriptionMessage { diff --git a/xchange-stream-gateio/src/main/java/dto/response/GateioOrderBookResponse.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/GateioOrderBookResponse.java similarity index 96% rename from xchange-stream-gateio/src/main/java/dto/response/GateioOrderBookResponse.java rename to xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/GateioOrderBookResponse.java index 854ba11f901..610996d19e2 100644 --- a/xchange-stream-gateio/src/main/java/dto/response/GateioOrderBookResponse.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/GateioOrderBookResponse.java @@ -1,4 +1,4 @@ -package dto.response; +package info.bitrich.xchangestream.gateio.dto.response; import com.fasterxml.jackson.annotation.JsonProperty; import java.math.BigDecimal; @@ -16,7 +16,6 @@ @Getter @Setter -/** Author: Max Gao (gaamox@tutanota.com) Created: 05-05-2021 */ public class GateioOrderBookResponse extends GateioWebSocketTransaction { @JsonProperty("result") private Result result; diff --git a/xchange-stream-gateio/src/main/java/dto/response/GateioTradesResponse.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/GateioTradesResponse.java similarity index 94% rename from xchange-stream-gateio/src/main/java/dto/response/GateioTradesResponse.java rename to xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/GateioTradesResponse.java index 38e751b8be3..c87c702e192 100644 --- a/xchange-stream-gateio/src/main/java/dto/response/GateioTradesResponse.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/GateioTradesResponse.java @@ -1,4 +1,4 @@ -package dto.response; +package info.bitrich.xchangestream.gateio.dto.response; import com.fasterxml.jackson.annotation.JsonProperty; import java.math.BigDecimal; @@ -11,7 +11,6 @@ @Getter @Setter -/** Author: Max Gao (gaamox@tutanota.com) Created: 05-05-2021 */ public class GateioTradesResponse extends GateioWebSocketTransaction { @JsonProperty("result") private Result result; diff --git a/xchange-stream-gateio/src/main/java/dto/response/GateioWebSocketTransaction.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/GateioWebSocketTransaction.java similarity index 82% rename from xchange-stream-gateio/src/main/java/dto/response/GateioWebSocketTransaction.java rename to xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/GateioWebSocketTransaction.java index 93095f1a7ad..81e39bd5f16 100644 --- a/xchange-stream-gateio/src/main/java/dto/response/GateioWebSocketTransaction.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/GateioWebSocketTransaction.java @@ -1,4 +1,4 @@ -package dto.response; +package info.bitrich.xchangestream.gateio.dto.response; import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Getter; @@ -7,7 +7,6 @@ @Getter @Setter -/** Author: Max Gao (gaamox@tutanota.com) Created: 05-05-2021 */ public abstract class GateioWebSocketTransaction { @JsonProperty("time") private int time; diff --git a/xchange-stream-gateio/src/test/java/GateioManualExample.java b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioManualExample.java similarity index 94% rename from xchange-stream-gateio/src/test/java/GateioManualExample.java rename to xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioManualExample.java index be720222698..f9d3994df2a 100644 --- a/xchange-stream-gateio/src/test/java/GateioManualExample.java +++ b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioManualExample.java @@ -1,3 +1,5 @@ +package info.bitrich.xchangestream.gateio; + import info.bitrich.xchangestream.core.ProductSubscription; import info.bitrich.xchangestream.core.StreamingExchangeFactory; import io.reactivex.disposables.Disposable; @@ -10,6 +12,7 @@ public class GateioManualExample { private static final Logger LOG = LoggerFactory.getLogger(GateioManualExample.class); public static void main(String[] args) throws Exception { + System.out.println("aaa"); ProductSubscription productSubscription = ProductSubscription.create() .addOrderbook(CurrencyPair.ETH_USDT) @@ -44,6 +47,7 @@ public static void main(String[] args) throws Exception { .getOrderBook(CurrencyPair.BTC_USDT) .subscribe( orderBook -> { + System.out.println(orderBook.getAsks().get(0)); LOG.info("First ask: {}", orderBook.getAsks().get(0)); LOG.info("First bid: {}", orderBook.getBids().get(0)); }, diff --git a/xchange-stream-gateio/src/test/java/dto/GateioOrderBookResponseTest.java b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/dto/GateioOrderBookResponseTest.java similarity index 92% rename from xchange-stream-gateio/src/test/java/dto/GateioOrderBookResponseTest.java rename to xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/dto/GateioOrderBookResponseTest.java index 286d57bf672..0adaace12c8 100644 --- a/xchange-stream-gateio/src/test/java/dto/GateioOrderBookResponseTest.java +++ b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/dto/GateioOrderBookResponseTest.java @@ -1,7 +1,7 @@ -package dto; +package info.bitrich.xchangestream.gateio.dto; import com.google.common.io.CharStreams; -import dto.response.GateioOrderBookResponse; +import info.bitrich.xchangestream.gateio.dto.response.GateioOrderBookResponse; import info.bitrich.xchangestream.service.netty.StreamingObjectMapperHelper; import java.io.IOException; import java.io.InputStream; diff --git a/xchange-stream-gateio/src/test/java/dto/GateioTradesResponseTest.java b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/dto/GateioTradesResponseTest.java similarity index 92% rename from xchange-stream-gateio/src/test/java/dto/GateioTradesResponseTest.java rename to xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/dto/GateioTradesResponseTest.java index 694308375d2..82633acd79f 100644 --- a/xchange-stream-gateio/src/test/java/dto/GateioTradesResponseTest.java +++ b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/dto/GateioTradesResponseTest.java @@ -1,7 +1,7 @@ -package dto; +package info.bitrich.xchangestream.gateio.dto; import com.google.common.io.CharStreams; -import dto.response.GateioTradesResponse; +import info.bitrich.xchangestream.gateio.dto.response.GateioTradesResponse; import info.bitrich.xchangestream.service.netty.StreamingObjectMapperHelper; import java.io.IOException; import java.io.InputStream; From 6319994283116b7b0bb9ef23d37600c6090daef2 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Sun, 6 Aug 2023 23:27:08 +0200 Subject: [PATCH 053/159] [gateio-stream] Code cleanup --- .../info/bitrich/xchangestream/gateio/GateioManualExample.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioManualExample.java b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioManualExample.java index f9d3994df2a..1d7095c7723 100644 --- a/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioManualExample.java +++ b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioManualExample.java @@ -12,7 +12,6 @@ public class GateioManualExample { private static final Logger LOG = LoggerFactory.getLogger(GateioManualExample.class); public static void main(String[] args) throws Exception { - System.out.println("aaa"); ProductSubscription productSubscription = ProductSubscription.create() .addOrderbook(CurrencyPair.ETH_USDT) @@ -47,7 +46,6 @@ public static void main(String[] args) throws Exception { .getOrderBook(CurrencyPair.BTC_USDT) .subscribe( orderBook -> { - System.out.println(orderBook.getAsks().get(0)); LOG.info("First ask: {}", orderBook.getAsks().get(0)); LOG.info("First bid: {}", orderBook.getBids().get(0)); }, From 87b4c4b348b3915eaffc717af40139895feab9c7 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Wed, 9 Aug 2023 15:16:54 +0200 Subject: [PATCH 054/159] [gateio-streaming] Add test for oder book --- xchange-stream-gateio/pom.xml | 54 ++++++++++++++++--- .../gateio/GateioStreamingExchangeIT.java | 51 ++++++++++++++++++ ...StreamingMarketDataServiceIntegration.java | 24 +++++++++ 3 files changed, 123 insertions(+), 6 deletions(-) create mode 100644 xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingExchangeIT.java create mode 100644 xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingMarketDataServiceIntegration.java diff --git a/xchange-stream-gateio/pom.xml b/xchange-stream-gateio/pom.xml index 37d7cf2ba87..50446e69cf7 100644 --- a/xchange-stream-gateio/pom.xml +++ b/xchange-stream-gateio/pom.xml @@ -1,26 +1,68 @@ + 4.0.0 - xchange-parent org.knowm.xchange + xchange-parent 5.1.1.bigscoop - 4.0.0 + xchange-stream-gateio XChange Gate.io Stream - xchange-stream-gateio + + + 3.2.0 + + + + org.junit.jupiter + junit-jupiter-engine + ${version.junit} + test + + org.knowm.xchange - xchange-stream-core + xchange-gateio-v4 ${project.parent.version} + org.knowm.xchange - xchange-gateio + xchange-stream-core ${project.parent.version} - \ No newline at end of file + + + + + com.github.ekryd.sortpom + sortpom-maven-plugin + ${version.sortpom-maven-plugin} + + true + false + groupId,artifactId + true + 4 + groupId,artifactId + false + + + + + sort + + verify + + + + + + + + diff --git a/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingExchangeIT.java b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingExchangeIT.java new file mode 100644 index 00000000000..f95e24c837b --- /dev/null +++ b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingExchangeIT.java @@ -0,0 +1,51 @@ +package info.bitrich.xchangestream.gateio; + +import static org.junit.jupiter.api.Assumptions.assumeTrue; + +import info.bitrich.xchangestream.core.StreamingExchangeFactory; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.knowm.xchange.ExchangeSpecification; + +public class GateioStreamingExchangeIT { + + public static GateioStreamingExchange exchange; + + @BeforeAll + public static void setup() { + try { + + ExchangeSpecification spec = + StreamingExchangeFactory.INSTANCE + .createExchangeWithoutSpecification(GateioStreamingExchange.class) + .getDefaultExchangeSpecification(); + spec.setShouldLoadRemoteMetaData(false); + + exchange = + (GateioStreamingExchange) StreamingExchangeFactory.INSTANCE.createExchange(spec); + + exchange.connect().blockingAwait(); + } + catch (Exception ignored) { + + } + } + + + @BeforeEach + void exchangeReachable() { + assumeTrue(exchange.isAlive(), "Exchange is unreachable"); + } + + + @AfterAll + public static void cleanup() { + if (exchange.isAlive()) { + exchange.disconnect().blockingAwait(); + } + } + + + +} \ No newline at end of file diff --git a/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingMarketDataServiceIntegration.java b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingMarketDataServiceIntegration.java new file mode 100644 index 00000000000..38472ba1a10 --- /dev/null +++ b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingMarketDataServiceIntegration.java @@ -0,0 +1,24 @@ +package info.bitrich.xchangestream.gateio; + +import io.reactivex.Observable; +import org.junit.jupiter.api.Test; +import org.knowm.xchange.currency.CurrencyPair; +import org.knowm.xchange.dto.marketdata.OrderBook; + +public class GateioStreamingMarketDataServiceIntegration extends GateioStreamingExchangeIT { + + @Test + void order_book() { + Observable observable = exchange + .getStreamingMarketDataService() + .getOrderBook(CurrencyPair.BTC_USDT); + + observable.test() + .assertSubscribed() + .awaitCount(1) + .assertNoTimeout() + .assertValueAt(0, orderBook -> !orderBook.getBids().isEmpty() || !orderBook.getAsks().isEmpty()) + .dispose(); + } + +} \ No newline at end of file From f2a4e44e2cb27911b52c0a395f76012df903518b Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Wed, 9 Aug 2023 15:34:45 +0200 Subject: [PATCH 055/159] [gateio-streaming] Add test for trades --- ...eioStreamingMarketDataServiceIntegration.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingMarketDataServiceIntegration.java b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingMarketDataServiceIntegration.java index 38472ba1a10..b7f94845072 100644 --- a/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingMarketDataServiceIntegration.java +++ b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingMarketDataServiceIntegration.java @@ -4,6 +4,7 @@ import org.junit.jupiter.api.Test; import org.knowm.xchange.currency.CurrencyPair; import org.knowm.xchange.dto.marketdata.OrderBook; +import org.knowm.xchange.dto.marketdata.Trade; public class GateioStreamingMarketDataServiceIntegration extends GateioStreamingExchangeIT { @@ -21,4 +22,19 @@ void order_book() { .dispose(); } + + @Test + void trades() { + Observable observable = exchange + .getStreamingMarketDataService() + .getTrades(CurrencyPair.BTC_USDT); + + observable.test() + .assertSubscribed() + .awaitCount(1) + .assertNoTimeout() + .assertValueAt(0, trade -> trade.getInstrument().equals(CurrencyPair.BTC_USDT)) + .dispose(); + } + } \ No newline at end of file From 36e96f7ced192adb707fa9765e6ff6fd433db8a2 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Wed, 9 Aug 2023 15:51:09 +0200 Subject: [PATCH 056/159] [gateio-streaming] Remove unneeded ProductSubscription at connect --- .../xchangestream/gateio/GateioStreamingExchange.java | 8 ++------ .../gateio/GateioStreamingMarketDataService.java | 9 --------- .../xchangestream/gateio/GateioStreamingService.java | 9 --------- .../xchangestream/gateio/GateioManualExample.java | 9 +-------- 4 files changed, 3 insertions(+), 32 deletions(-) diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingExchange.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingExchange.java index 1a64385a999..e5327faf102 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingExchange.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingExchange.java @@ -20,14 +20,10 @@ public GateioStreamingExchange() {} @Override public Completable connect(ProductSubscription... args) { - if (args == null || args.length == 0) - throw new UnsupportedOperationException("The ProductSubscription must be defined!"); - - this.streamingService = new GateioStreamingService(V4_URL, exchangeSpecification); + streamingService = new GateioStreamingService(V4_URL, exchangeSpecification); applyStreamingSpecification(getExchangeSpecification(), streamingService); - this.streamingMarketDataService = new GateioStreamingMarketDataService(streamingService); + streamingMarketDataService = new GateioStreamingMarketDataService(streamingService); - streamingService.subscribeMultipleCurrencyPairs(args); return streamingService.connect(); } diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingMarketDataService.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingMarketDataService.java index a23855d6f28..bef2308c3ff 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingMarketDataService.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingMarketDataService.java @@ -4,13 +4,11 @@ import info.bitrich.xchangestream.gateio.dto.response.GateioOrderBookResponse; import info.bitrich.xchangestream.gateio.dto.response.GateioTradesResponse; import io.reactivex.Observable; -import java.util.List; 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.marketdata.Trade; import org.knowm.xchange.exceptions.NotYetImplementedForExchangeException; -import org.knowm.xchange.instrument.Instrument; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -23,9 +21,6 @@ public GateioStreamingMarketDataService(GateioStreamingService service) { this.service = service; } - private boolean containsPair(List pairs, CurrencyPair pair) { - return pairs.stream().anyMatch(p -> p.equals(pair)); - } /** * Uses the limited-level snapshot method: @@ -37,10 +32,6 @@ private boolean containsPair(List pairs, CurrencyPair pair) { */ @Override public Observable getOrderBook(CurrencyPair currencyPair, Object... args) { - if (!containsPair(service.getProduct().getOrderBook(), currencyPair)) - throw new UnsupportedOperationException( - String.format("The currency pair %s is not subscribed for orderbook", currencyPair)); - return service .getRawWebSocketTransactions(currencyPair, GateioStreamingService.SPOT_ORDERBOOK_CHANNEL) .map(msg -> ((GateioOrderBookResponse) msg).toOrderBook(currencyPair)); diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingService.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingService.java index 0af0e26d5d0..f13a6b65bbe 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingService.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingService.java @@ -2,7 +2,6 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; -import info.bitrich.xchangestream.core.ProductSubscription; import info.bitrich.xchangestream.gateio.dto.GateioWebSocketSubscriptionMessage; import info.bitrich.xchangestream.gateio.dto.response.GateioOrderBookResponse; import info.bitrich.xchangestream.gateio.dto.response.GateioTradesResponse; @@ -34,7 +33,6 @@ public class GateioStreamingService extends JsonNettyStreamingService { private static final int UPDATE_INTERVAL_DEFAULT = 100; private final String apiUri; - private ProductSubscription productSubscription; private ExchangeSpecification exchangeSpecification; private final Map> subscriptions = new ConcurrentHashMap<>(); @@ -64,13 +62,6 @@ public Observable getRawWebSocketTransactions( .filter(t -> currencyPair.equals(t.getCurrencyPair())); } - public void subscribeMultipleCurrencyPairs(ProductSubscription... products) { - this.productSubscription = products[0]; - } - - public ProductSubscription getProduct() { - return this.productSubscription; - } @Override protected String getChannelNameFromMessage(JsonNode message) { diff --git a/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioManualExample.java b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioManualExample.java index 1d7095c7723..6370cef80d0 100644 --- a/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioManualExample.java +++ b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioManualExample.java @@ -1,6 +1,5 @@ package info.bitrich.xchangestream.gateio; -import info.bitrich.xchangestream.core.ProductSubscription; import info.bitrich.xchangestream.core.StreamingExchangeFactory; import io.reactivex.disposables.Disposable; import org.knowm.xchange.ExchangeSpecification; @@ -12,12 +11,6 @@ public class GateioManualExample { private static final Logger LOG = LoggerFactory.getLogger(GateioManualExample.class); public static void main(String[] args) throws Exception { - ProductSubscription productSubscription = - ProductSubscription.create() - .addOrderbook(CurrencyPair.ETH_USDT) - .addOrderbook(CurrencyPair.BTC_USDT) - .addTrades(CurrencyPair.ETH_USDT) - .build(); ExchangeSpecification spec = StreamingExchangeFactory.INSTANCE @@ -28,7 +21,7 @@ public static void main(String[] args) throws Exception { GateioStreamingExchange exchange = (GateioStreamingExchange) StreamingExchangeFactory.INSTANCE.createExchange(spec); - exchange.connect(productSubscription).blockingAwait(); + exchange.connect().blockingAwait(); Disposable sub1 = exchange From d78b2ee3e36b71dfe621dd45926a243db5517d76 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Wed, 9 Aug 2023 20:02:46 +0200 Subject: [PATCH 057/159] [gateio-streaming] Add ticker stream --- xchange-stream-gateio/lombok.config | 1 + xchange-stream-gateio/pom.xml | 6 +++ .../gateio/GateioStreamingAdapters.java | 51 ++++++++++++++++++ .../GateioStreamingMarketDataService.java | 5 +- .../config/StringToCurrencyPairConverter.java | 15 ++++++ .../TimestampSecondsToInstantConverter.java | 15 ++++++ .../xchangestream/gateio/dto/TickerDTO.java | 41 ++++++++++++++ .../response/GateioTickerNotification.java | 7 +++ .../response/GateioWebSocketNotification.java | 30 +++++++++++ ...StreamingMarketDataServiceIntegration.java | 53 ++++++++++++++++--- 10 files changed, 216 insertions(+), 8 deletions(-) create mode 100644 xchange-stream-gateio/lombok.config create mode 100644 xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingAdapters.java create mode 100644 xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/StringToCurrencyPairConverter.java create mode 100644 xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/TimestampSecondsToInstantConverter.java create mode 100644 xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/TickerDTO.java create mode 100644 xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/GateioTickerNotification.java create mode 100644 xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/GateioWebSocketNotification.java diff --git a/xchange-stream-gateio/lombok.config b/xchange-stream-gateio/lombok.config new file mode 100644 index 00000000000..e572d96336a --- /dev/null +++ b/xchange-stream-gateio/lombok.config @@ -0,0 +1 @@ +lombok.equalsAndHashCode.callSuper = call \ No newline at end of file diff --git a/xchange-stream-gateio/pom.xml b/xchange-stream-gateio/pom.xml index 50446e69cf7..b22a5fa16c2 100644 --- a/xchange-stream-gateio/pom.xml +++ b/xchange-stream-gateio/pom.xml @@ -16,6 +16,12 @@ + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + ${version.fasterxml} + + org.junit.jupiter junit-jupiter-engine diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingAdapters.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingAdapters.java new file mode 100644 index 00000000000..f471d50b571 --- /dev/null +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingAdapters.java @@ -0,0 +1,51 @@ +package info.bitrich.xchangestream.gateio; + +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; +import info.bitrich.xchangestream.gateio.dto.TickerDTO; +import info.bitrich.xchangestream.gateio.dto.response.GateioTickerNotification; +import java.util.Date; +import lombok.SneakyThrows; +import lombok.experimental.UtilityClass; +import org.knowm.xchange.dto.marketdata.Ticker; + +@UtilityClass +public class GateioStreamingAdapters { + + private final ObjectMapper MAPPER = new ObjectMapper(); + + static { + // by default read timetamps as milliseconds + MAPPER.configure(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS, false); + + // don't fail un unknown properties + MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + + // enable parsing to Instant + MAPPER.registerModule(new JavaTimeModule()); + } + + + @SneakyThrows + public Ticker toTicker(JsonNode jsonNode) { + GateioTickerNotification notification = MAPPER.treeToValue(jsonNode, GateioTickerNotification.class); + TickerDTO tickerDTO = notification.getResult(); + + return new Ticker.Builder() + .timestamp(Date.from(notification.getTime())) + .instrument(tickerDTO.getCurrencyPair()) + .last(tickerDTO.getLastPrice()) + .ask(tickerDTO.getLowestAsk()) + .bid(tickerDTO.getHighestBid()) + .percentageChange(tickerDTO.getChangePercent24h()) + .volume(tickerDTO.getBaseVolume()) + .quoteVolume(tickerDTO.getQuoteVolume()) + .high(tickerDTO.getHighPrice24h()) + .low(tickerDTO.getLowPrice24h()) + .build(); + } + + +} diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingMarketDataService.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingMarketDataService.java index bef2308c3ff..89658e922d6 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingMarketDataService.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingMarketDataService.java @@ -8,7 +8,6 @@ import org.knowm.xchange.dto.marketdata.OrderBook; import org.knowm.xchange.dto.marketdata.Ticker; import org.knowm.xchange.dto.marketdata.Trade; -import org.knowm.xchange.exceptions.NotYetImplementedForExchangeException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -39,7 +38,9 @@ public Observable getOrderBook(CurrencyPair currencyPair, Object... a @Override public Observable getTicker(CurrencyPair currencyPair, Object... args) { - throw new NotYetImplementedForExchangeException("Not yet implemented!"); + return service + .subscribeChannel("spot.tickers", currencyPair, args) + .map(GateioStreamingAdapters::toTicker); } @Override diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/StringToCurrencyPairConverter.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/StringToCurrencyPairConverter.java new file mode 100644 index 00000000000..feb7a493e38 --- /dev/null +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/StringToCurrencyPairConverter.java @@ -0,0 +1,15 @@ +package info.bitrich.xchangestream.gateio.config; + +import com.fasterxml.jackson.databind.util.StdConverter; +import org.knowm.xchange.currency.CurrencyPair; + +/** + * Converts string to {@code CurrencyPair} + */ +public class StringToCurrencyPairConverter extends StdConverter { + + @Override + public CurrencyPair convert(String value) { + return new CurrencyPair(value.replace('_', '/')); + } +} diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/TimestampSecondsToInstantConverter.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/TimestampSecondsToInstantConverter.java new file mode 100644 index 00000000000..5a5aad0da10 --- /dev/null +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/TimestampSecondsToInstantConverter.java @@ -0,0 +1,15 @@ +package info.bitrich.xchangestream.gateio.config; + +import com.fasterxml.jackson.databind.util.StdConverter; +import java.time.Instant; + +/** + * Converts timestamp in seconds to {@code Instant} + */ +public class TimestampSecondsToInstantConverter extends StdConverter { + + @Override + public Instant convert(final Long value) { + return Instant.ofEpochSecond(value); + } +} diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/TickerDTO.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/TickerDTO.java new file mode 100644 index 00000000000..f4537e5002a --- /dev/null +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/TickerDTO.java @@ -0,0 +1,41 @@ +package info.bitrich.xchangestream.gateio.dto; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import info.bitrich.xchangestream.gateio.config.StringToCurrencyPairConverter; +import java.math.BigDecimal; +import lombok.Data; +import org.knowm.xchange.currency.CurrencyPair; + +@Data +public class TickerDTO { + + @JsonProperty("currency_pair") + @JsonDeserialize(converter = StringToCurrencyPairConverter.class) + CurrencyPair currencyPair; + + @JsonProperty("last") + BigDecimal lastPrice; + + @JsonProperty("lowest_ask") + BigDecimal lowestAsk; + + @JsonProperty("highest_bid") + BigDecimal highestBid; + + @JsonProperty("change_percentage") + BigDecimal changePercent24h; + + @JsonProperty("base_volume") + BigDecimal baseVolume; + + @JsonProperty("quote_volume") + BigDecimal quoteVolume; + + @JsonProperty("high_24h") + BigDecimal highPrice24h; + + @JsonProperty("low_24h") + BigDecimal lowPrice24h; + +} diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/GateioTickerNotification.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/GateioTickerNotification.java new file mode 100644 index 00000000000..8b85dfdc46d --- /dev/null +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/GateioTickerNotification.java @@ -0,0 +1,7 @@ +package info.bitrich.xchangestream.gateio.dto.response; + +import info.bitrich.xchangestream.gateio.dto.TickerDTO; + +public class GateioTickerNotification extends GateioWebSocketNotification { + +} diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/GateioWebSocketNotification.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/GateioWebSocketNotification.java new file mode 100644 index 00000000000..a24cb05e3c7 --- /dev/null +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/GateioWebSocketNotification.java @@ -0,0 +1,30 @@ +package info.bitrich.xchangestream.gateio.dto.response; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import info.bitrich.xchangestream.gateio.config.TimestampSecondsToInstantConverter; +import java.time.Instant; +import lombok.Data; + +@Data +public class GateioWebSocketNotification { + + @JsonProperty("time") + @JsonDeserialize(converter = TimestampSecondsToInstantConverter.class) + private Instant time; + + @JsonProperty("time_ms") + private Instant timeMs; + + @JsonProperty("channel") + private String channel; + + @JsonProperty("event") + private String event; + + @JsonProperty("error") + private String error; + + @JsonProperty("result") + private T result; +} diff --git a/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingMarketDataServiceIntegration.java b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingMarketDataServiceIntegration.java index b7f94845072..a39ce7a01b9 100644 --- a/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingMarketDataServiceIntegration.java +++ b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingMarketDataServiceIntegration.java @@ -1,9 +1,13 @@ package info.bitrich.xchangestream.gateio; +import static org.assertj.core.api.Assertions.assertThat; + import io.reactivex.Observable; +import io.reactivex.observers.TestObserver; import org.junit.jupiter.api.Test; 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.marketdata.Trade; public class GateioStreamingMarketDataServiceIntegration extends GateioStreamingExchangeIT { @@ -14,12 +18,19 @@ void order_book() { .getStreamingMarketDataService() .getOrderBook(CurrencyPair.BTC_USDT); - observable.test() + TestObserver testObserver = observable.test(); + + OrderBook orderBook = testObserver .assertSubscribed() .awaitCount(1) .assertNoTimeout() - .assertValueAt(0, orderBook -> !orderBook.getBids().isEmpty() || !orderBook.getAsks().isEmpty()) - .dispose(); + .values().get(0); + + testObserver.dispose(); + + assertThat(orderBook).hasNoNullFieldsOrProperties(); + assertThat(orderBook.getBids()).isNotEmpty(); + assertThat(orderBook.getAsks()).isNotEmpty(); } @@ -29,12 +40,42 @@ void trades() { .getStreamingMarketDataService() .getTrades(CurrencyPair.BTC_USDT); - observable.test() + TestObserver testObserver = observable.test(); + + Trade trade = testObserver .assertSubscribed() .awaitCount(1) .assertNoTimeout() - .assertValueAt(0, trade -> trade.getInstrument().equals(CurrencyPair.BTC_USDT)) - .dispose(); + .values().get(0); + + testObserver.dispose(); + + assertThat(trade).hasNoNullFieldsOrPropertiesExcept("makerOrderId", "takerOrderId"); + assertThat(trade.getInstrument()).isEqualTo(CurrencyPair.BTC_USDT); + } + + @Test + void ticker() { + Observable observable = exchange + .getStreamingMarketDataService() + .getTicker(CurrencyPair.BTC_USDT); + + TestObserver testObserver = observable.test(); + + Ticker ticker = testObserver + .assertSubscribed() + .awaitCount(1) + .assertNoTimeout() + .values() + .get(0); + + testObserver.dispose(); + + assertThat(ticker).hasNoNullFieldsOrPropertiesExcept("open", "vwap", "bidSize", "askSize"); + assertThat(ticker.getInstrument()).isEqualTo(CurrencyPair.BTC_USDT); + } + + } \ No newline at end of file From e90938ffdd6c60852fb577f46801260a48582d12 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Thu, 10 Aug 2023 00:00:41 +0200 Subject: [PATCH 058/159] [gateio-streaming] Refactor --- .../gateio/GateioStreamingAdapters.java | 64 ++++++--- .../gateio/GateioStreamingExchange.java | 2 +- .../GateioStreamingMarketDataService.java | 21 ++- .../gateio/GateioStreamingService.java | 135 ++++++++---------- .../config/CurrencyPairToStringConverter.java | 15 ++ .../InstantToTimestampSecondsConverter.java | 15 ++ .../gateio/config/ObjecMapperHelper.java | 35 +++++ .../GateioWebSocketSubscriptionMessage.java | 49 ------- .../dto/request/GateioWebSocketRequest.java | 37 +++++ .../CurrencyPairLevelIntervalPayload.java | 32 +++++ .../request/payload/CurrencyPairPayload.java | 18 +++ .../dto/response/GateioOrderBookResponse.java | 78 ---------- .../response/GateioTickerNotification.java | 7 - .../dto/response/GateioTradesResponse.java | 59 -------- .../response/GateioWebSocketTransaction.java | 21 --- .../GateioOrderBookNotification.java | 7 + .../dto/response/orderbook/OrderBookDTO.java | 49 +++++++ .../ticker/GateioTickerNotification.java | 7 + .../dto/{ => response/ticker}/TickerDTO.java | 2 +- .../trade/GateioTradeNotification.java | 7 + .../gateio/dto/response/trade/TradeDTO.java | 38 +++++ ...StreamingMarketDataServiceIntegration.java | 10 +- .../dto/GateioOrderBookResponseTest.java | 44 ------ .../gateio/dto/GateioTradesResponseTest.java | 39 ----- .../src/test/resources/OrderBookResponse.json | 54 ------- .../src/test/resources/TradeResponses.json | 14 -- .../service/netty/NettyStreamingService.java | 2 +- 27 files changed, 386 insertions(+), 475 deletions(-) create mode 100644 xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/CurrencyPairToStringConverter.java create mode 100644 xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/InstantToTimestampSecondsConverter.java create mode 100644 xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/ObjecMapperHelper.java delete mode 100644 xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/GateioWebSocketSubscriptionMessage.java create mode 100644 xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/request/GateioWebSocketRequest.java create mode 100644 xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/request/payload/CurrencyPairLevelIntervalPayload.java create mode 100644 xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/request/payload/CurrencyPairPayload.java delete mode 100644 xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/GateioOrderBookResponse.java delete mode 100644 xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/GateioTickerNotification.java delete mode 100644 xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/GateioTradesResponse.java delete mode 100644 xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/GateioWebSocketTransaction.java create mode 100644 xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/orderbook/GateioOrderBookNotification.java create mode 100644 xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/orderbook/OrderBookDTO.java create mode 100644 xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/ticker/GateioTickerNotification.java rename xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/{ => response/ticker}/TickerDTO.java (93%) create mode 100644 xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/trade/GateioTradeNotification.java create mode 100644 xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/trade/TradeDTO.java delete mode 100644 xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/dto/GateioOrderBookResponseTest.java delete mode 100644 xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/dto/GateioTradesResponseTest.java delete mode 100644 xchange-stream-gateio/src/test/resources/OrderBookResponse.json delete mode 100644 xchange-stream-gateio/src/test/resources/TradeResponses.json diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingAdapters.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingAdapters.java index f471d50b571..20eecd89d8b 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingAdapters.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingAdapters.java @@ -1,36 +1,32 @@ package info.bitrich.xchangestream.gateio; -import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; -import info.bitrich.xchangestream.gateio.dto.TickerDTO; -import info.bitrich.xchangestream.gateio.dto.response.GateioTickerNotification; +import info.bitrich.xchangestream.gateio.config.ObjecMapperHelper; +import info.bitrich.xchangestream.gateio.dto.response.orderbook.GateioOrderBookNotification; +import info.bitrich.xchangestream.gateio.dto.response.orderbook.OrderBookDTO; +import info.bitrich.xchangestream.gateio.dto.response.ticker.GateioTickerNotification; +import info.bitrich.xchangestream.gateio.dto.response.ticker.TickerDTO; +import info.bitrich.xchangestream.gateio.dto.response.trade.GateioTradeNotification; +import info.bitrich.xchangestream.gateio.dto.response.trade.TradeDTO; import java.util.Date; +import java.util.stream.Stream; import lombok.SneakyThrows; import lombok.experimental.UtilityClass; +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.marketdata.Trade; +import org.knowm.xchange.dto.trade.LimitOrder; @UtilityClass public class GateioStreamingAdapters { - private final ObjectMapper MAPPER = new ObjectMapper(); - - static { - // by default read timetamps as milliseconds - MAPPER.configure(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS, false); - - // don't fail un unknown properties - MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - - // enable parsing to Instant - MAPPER.registerModule(new JavaTimeModule()); - } - + ObjectMapper objectMapper = ObjecMapperHelper.getObjectMapper(); @SneakyThrows public Ticker toTicker(JsonNode jsonNode) { - GateioTickerNotification notification = MAPPER.treeToValue(jsonNode, GateioTickerNotification.class); + GateioTickerNotification notification = objectMapper.treeToValue(jsonNode, GateioTickerNotification.class); TickerDTO tickerDTO = notification.getResult(); return new Ticker.Builder() @@ -48,4 +44,36 @@ public Ticker toTicker(JsonNode jsonNode) { } + @SneakyThrows + public Trade toTrade(JsonNode jsonNode) { + GateioTradeNotification notification = objectMapper.treeToValue(jsonNode, GateioTradeNotification.class); + TradeDTO tradeDTO = notification.getResult(); + + + return new Trade.Builder() + .type("sell".equals(tradeDTO.getSide()) ? OrderType.ASK : OrderType.BID) + .originalAmount(tradeDTO.getAmount()) + .instrument(tradeDTO.getCurrencyPair()) + .price(tradeDTO.getPrice()) + .timestamp(Date.from(tradeDTO.getTime())) + .id(String.valueOf(tradeDTO.getId())) + .build(); + } + + + @SneakyThrows + public OrderBook toOrderBook(JsonNode jsonNode) { + GateioOrderBookNotification notification = objectMapper.treeToValue(jsonNode, GateioOrderBookNotification.class); + OrderBookDTO orderBookDTO = notification.getResult(); + + Stream asks = orderBookDTO.getAsks().stream() + .map(priceSizeEntry -> new LimitOrder(OrderType.ASK, priceSizeEntry.getSize(), orderBookDTO.getCurrencyPair(), null, null, priceSizeEntry.getPrice())); + + Stream bids = orderBookDTO.getAsks().stream() + .map(priceSizeEntry -> new LimitOrder(OrderType.BID, priceSizeEntry.getSize(), orderBookDTO.getCurrencyPair(), null, null, priceSizeEntry.getPrice())); + + return new OrderBook(Date.from(orderBookDTO.getTimestamp()), asks, bids); + } + + } diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingExchange.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingExchange.java index e5327faf102..2c8a9299458 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingExchange.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingExchange.java @@ -20,7 +20,7 @@ public GateioStreamingExchange() {} @Override public Completable connect(ProductSubscription... args) { - streamingService = new GateioStreamingService(V4_URL, exchangeSpecification); + streamingService = new GateioStreamingService(V4_URL); applyStreamingSpecification(getExchangeSpecification(), streamingService); streamingMarketDataService = new GateioStreamingMarketDataService(streamingService); diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingMarketDataService.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingMarketDataService.java index 89658e922d6..2d8ca6b8fc0 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingMarketDataService.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingMarketDataService.java @@ -1,19 +1,14 @@ package info.bitrich.xchangestream.gateio; import info.bitrich.xchangestream.core.StreamingMarketDataService; -import info.bitrich.xchangestream.gateio.dto.response.GateioOrderBookResponse; -import info.bitrich.xchangestream.gateio.dto.response.GateioTradesResponse; import io.reactivex.Observable; 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.marketdata.Trade; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; public class GateioStreamingMarketDataService implements StreamingMarketDataService { - private static final Logger LOGGER = - LoggerFactory.getLogger(GateioStreamingMarketDataService.class); + private final GateioStreamingService service; public GateioStreamingMarketDataService(GateioStreamingService service) { @@ -27,26 +22,28 @@ public GateioStreamingMarketDataService(GateioStreamingService service) { * * @param currencyPair Currency pair of the order book * @param args Optional maxDepth, Optional msgInterval - * @return */ + @Override public Observable getOrderBook(CurrencyPair currencyPair, Object... args) { return service - .getRawWebSocketTransactions(currencyPair, GateioStreamingService.SPOT_ORDERBOOK_CHANNEL) - .map(msg -> ((GateioOrderBookResponse) msg).toOrderBook(currencyPair)); + .subscribeChannel(GateioStreamingService.SPOT_ORDERBOOK_CHANNEL, currencyPair, args) + .map(GateioStreamingAdapters::toOrderBook); } + @Override public Observable getTicker(CurrencyPair currencyPair, Object... args) { return service - .subscribeChannel("spot.tickers", currencyPair, args) + .subscribeChannel(GateioStreamingService.SPOT_TICKERS_CHANNEL, currencyPair, args) .map(GateioStreamingAdapters::toTicker); } + @Override public Observable getTrades(CurrencyPair currencyPair, Object... args) { return service - .getRawWebSocketTransactions(currencyPair, GateioStreamingService.SPOT_TRADES_CHANNEL) - .map(msg -> ((GateioTradesResponse) msg).toTrade()); + .subscribeChannel(GateioStreamingService.SPOT_TRADES_CHANNEL, currencyPair) + .map(GateioStreamingAdapters::toTrade); } } diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingService.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingService.java index f13a6b65bbe..f9a3c94c2e4 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingService.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingService.java @@ -1,26 +1,24 @@ package info.bitrich.xchangestream.gateio; + import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; -import info.bitrich.xchangestream.gateio.dto.GateioWebSocketSubscriptionMessage; -import info.bitrich.xchangestream.gateio.dto.response.GateioOrderBookResponse; -import info.bitrich.xchangestream.gateio.dto.response.GateioTradesResponse; -import info.bitrich.xchangestream.gateio.dto.response.GateioWebSocketTransaction; +import info.bitrich.xchangestream.gateio.config.ObjecMapperHelper; +import info.bitrich.xchangestream.gateio.dto.request.GateioWebSocketRequest; +import info.bitrich.xchangestream.gateio.dto.request.payload.CurrencyPairLevelIntervalPayload; +import info.bitrich.xchangestream.gateio.dto.request.payload.CurrencyPairPayload; import info.bitrich.xchangestream.service.netty.JsonNettyStreamingService; -import info.bitrich.xchangestream.service.netty.StreamingObjectMapperHelper; import info.bitrich.xchangestream.service.netty.WebSocketClientCompressionAllowClientNoContextAndServerNoContextHandler; import io.netty.handler.codec.http.websocketx.extensions.WebSocketClientExtensionHandler; import io.reactivex.Observable; import java.io.IOException; +import java.time.Duration; +import java.time.Instant; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; -import org.knowm.xchange.ExchangeSpecification; import org.knowm.xchange.currency.CurrencyPair; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; public class GateioStreamingService extends JsonNettyStreamingService { - private static final Logger LOG = LoggerFactory.getLogger(GateioStreamingService.class); private static final String SUBSCRIBE = "subscribe"; private static final String UNSUBSCRIBE = "unsubscribe"; private static final String CHANNEL_NAME_DELIMITER = "-"; @@ -32,34 +30,12 @@ public class GateioStreamingService extends JsonNettyStreamingService { private static final int MAX_DEPTH_DEFAULT = 5; private static final int UPDATE_INTERVAL_DEFAULT = 100; - private final String apiUri; - private ExchangeSpecification exchangeSpecification; - private final Map> subscriptions = new ConcurrentHashMap<>(); - private final Map channelSubscriptionMessages = new ConcurrentHashMap<>(); - public GateioStreamingService(String apiUri, ExchangeSpecification exchangeSpecification) { - super(apiUri, Integer.MAX_VALUE); - this.apiUri = apiUri; - this.exchangeSpecification = exchangeSpecification; - } + private final ObjectMapper objectMapper = ObjecMapperHelper.getObjectMapper(); - public Observable getRawWebSocketTransactions( - CurrencyPair currencyPair, String channelName, Object... args) { - final ObjectMapper mapper = StreamingObjectMapperHelper.getObjectMapper(); - - return subscribeChannel(channelName, currencyPair, args) - .map( - msg -> { - switch (channelName) { - case SPOT_ORDERBOOK_CHANNEL: - return mapper.treeToValue(msg, GateioOrderBookResponse.class); - case SPOT_TRADES_CHANNEL: - return mapper.treeToValue(msg, GateioTradesResponse.class); - } - return mapper.treeToValue(msg, GateioWebSocketTransaction.class); - }) - .filter(t -> currencyPair.equals(t.getCurrencyPair())); + public GateioStreamingService(String apiUri) { + super(apiUri, Integer.MAX_VALUE); } @@ -88,17 +64,13 @@ public Observable subscribeChannel(String channelName, Object... args) String currencyPairChannelName = String.format("%s-%s", channelName, currencyPair.toString().replace('/', '_')); - try { - // Example channel name key: spot.order_book_update-ETH_USDT, spot.trades-BTC_USDT - if (!channels.containsKey(currencyPairChannelName) - && !subscriptions.containsKey(currencyPairChannelName)) { - subscriptions.put( - currencyPairChannelName, super.subscribeChannel(currencyPairChannelName, args)); - channelSubscriptionMessages.put( - currencyPairChannelName, getSubscribeMessage(currencyPairChannelName, currencyPair)); - } - } catch (IOException e) { - LOG.error("Failed to subscribe to channel: {}", currencyPairChannelName); + // Example channel name key: spot.order_book_update-ETH_USDT, spot.trades-BTC_USDT + if (!channels.containsKey(currencyPairChannelName) && !subscriptions.containsKey(currencyPairChannelName)) { + // subscribe + Observable observable = super.subscribeChannel(currencyPairChannelName, args); + + // cache channel subscribtion + subscriptions.put(currencyPairChannelName, observable); } return subscriptions.get(currencyPairChannelName); @@ -107,34 +79,54 @@ public Observable subscribeChannel(String channelName, Object... args) /** * Returns a JSON String containing the subscription message. * - * @param channelName - * @param args CurrencyPair to subscribe to - * @return - * @throws IOException + * @param channelName e.g. spot.order_book_update-ETH_USDT + * @param args CurrencyPair to subscribe and additional channel-specific arguments + * @return subscription message */ @Override public String getSubscribeMessage(String channelName, Object... args) throws IOException { - final CurrencyPair currencyPair = - (args.length > 0 && args[0] instanceof CurrencyPair) ? ((CurrencyPair) args[0]) : null; + GateioWebSocketRequest request = getWebSocketRequest(channelName, SUBSCRIBE, args); + return objectMapper.writeValueAsString(request); + } - final int maxDepth = - exchangeSpecification.getExchangeSpecificParametersItem("maxDepth") != null - ? (int) exchangeSpecification.getExchangeSpecificParametersItem("maxDepth") - : MAX_DEPTH_DEFAULT; - final int msgInterval = - exchangeSpecification.getExchangeSpecificParametersItem("updateInterval") != null - ? (int) exchangeSpecification.getExchangeSpecificParametersItem("updateInterval") - : UPDATE_INTERVAL_DEFAULT; - - GateioWebSocketSubscriptionMessage subscribeMessage = - new GateioWebSocketSubscriptionMessage( - channelName.split(CHANNEL_NAME_DELIMITER)[0], - SUBSCRIBE, - currencyPair, - msgInterval, - maxDepth); - - return objectMapper.writeValueAsString(subscribeMessage); + + private GateioWebSocketRequest getWebSocketRequest(String channelName, String event, Object... args) { + // create request common part + String generalChannelName = channelName.split(CHANNEL_NAME_DELIMITER)[0]; + GateioWebSocketRequest request = GateioWebSocketRequest.builder() + .channel(generalChannelName) + .event(event) + .time(Instant.now()) + .build(); + + // create channel specific payload + Object payload; + switch (generalChannelName) { + + case SPOT_TICKERS_CHANNEL: + case SPOT_TRADES_CHANNEL: + payload = CurrencyPairPayload.builder() + .currencyPair(CurrencyPair.BTC_USDT) + .build(); + break; + + case SPOT_ORDERBOOK_CHANNEL: + Integer orderBookLevel = (args.length > 1 && args[1] instanceof Integer) ? (Integer) args[1] : MAX_DEPTH_DEFAULT; + Duration updateSpeed = (args.length > 2 && args[2] instanceof Duration) ? (Duration) args[2] : Duration.ofMillis(UPDATE_INTERVAL_DEFAULT); + + payload = CurrencyPairLevelIntervalPayload.builder() + .currencyPair(CurrencyPair.BTC_USDT) + .orderBookLevel(orderBookLevel) + .updateSpeed(updateSpeed) + .build(); + request.setPayload(payload); + break; + + default: + throw new IllegalStateException("Unexpected value: " + generalChannelName); + } + request.setPayload(payload); + return request; } @Override @@ -144,10 +136,7 @@ protected WebSocketClientExtensionHandler getWebSocketClientExtensionHandler() { @Override public String getUnsubscribeMessage(String channelName, Object... args) throws IOException { - GateioWebSocketSubscriptionMessage unsubscribeMessage = - objectMapper.readValue( - channelSubscriptionMessages.get(channelName), GateioWebSocketSubscriptionMessage.class); - unsubscribeMessage.setEvent(UNSUBSCRIBE); + GateioWebSocketRequest unsubscribeMessage = getWebSocketRequest(channelName, UNSUBSCRIBE, args); return objectMapper.writeValueAsString(unsubscribeMessage); } } diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/CurrencyPairToStringConverter.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/CurrencyPairToStringConverter.java new file mode 100644 index 00000000000..43f6cb79ed0 --- /dev/null +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/CurrencyPairToStringConverter.java @@ -0,0 +1,15 @@ +package info.bitrich.xchangestream.gateio.config; + +import com.fasterxml.jackson.databind.util.StdConverter; +import org.knowm.xchange.currency.CurrencyPair; + +/** + * Converts {@code CurrencyPair} to string + */ +public class CurrencyPairToStringConverter extends StdConverter { + + @Override + public String convert(CurrencyPair value) { + return value.getBase() + "_" + value.getCounter(); + } +} diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/InstantToTimestampSecondsConverter.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/InstantToTimestampSecondsConverter.java new file mode 100644 index 00000000000..f0a1a37479a --- /dev/null +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/InstantToTimestampSecondsConverter.java @@ -0,0 +1,15 @@ +package info.bitrich.xchangestream.gateio.config; + +import com.fasterxml.jackson.databind.util.StdConverter; +import java.time.Instant; + +/** + * Converts {@code Instant} to timestamp in seconds + */ +public class InstantToTimestampSecondsConverter extends StdConverter { + + @Override + public Long convert(Instant value) { + return value.getEpochSecond(); + } +} diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/ObjecMapperHelper.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/ObjecMapperHelper.java new file mode 100644 index 00000000000..3733576554d --- /dev/null +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/ObjecMapperHelper.java @@ -0,0 +1,35 @@ +package info.bitrich.xchangestream.gateio.config; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; +import lombok.experimental.UtilityClass; + +@UtilityClass +public class ObjecMapperHelper { + + private final ObjectMapper MAPPER = new ObjectMapper(); + + static { + // by default read and write timetamps as milliseconds + MAPPER.configure(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS, false); + MAPPER.configure(SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS, false); + + // don't fail un unknown properties + MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + + // don't write nulls + MAPPER.setSerializationInclusion(JsonInclude.Include.NON_NULL); + + // enable parsing to Instant + MAPPER.registerModule(new JavaTimeModule()); + } + + + public ObjectMapper getObjectMapper() { + return MAPPER; + } + +} diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/GateioWebSocketSubscriptionMessage.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/GateioWebSocketSubscriptionMessage.java deleted file mode 100644 index 48d244de18c..00000000000 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/GateioWebSocketSubscriptionMessage.java +++ /dev/null @@ -1,49 +0,0 @@ -package info.bitrich.xchangestream.gateio.dto; - -import com.fasterxml.jackson.annotation.JsonProperty; -import java.time.Instant; -import java.util.Arrays; -import java.util.Objects; -import java.util.stream.Collectors; -import lombok.NoArgsConstructor; -import lombok.Setter; -import org.knowm.xchange.currency.CurrencyPair; - -@Setter -@NoArgsConstructor -public class GateioWebSocketSubscriptionMessage { - @JsonProperty("time") - private int time; - - @JsonProperty("channel") - private String channel; - - @JsonProperty("event") - private String event; - - @JsonProperty("payload") - private String[] payload; - - public GateioWebSocketSubscriptionMessage( - String channelName, CurrencyPair currencyPair, Integer interval) {} - - public GateioWebSocketSubscriptionMessage( - String channelName, - String event, - CurrencyPair currencyPair, - Integer interval, - Integer depth) { - this.time = (int) (Instant.now().getEpochSecond()); - this.channel = channelName; - this.event = event; - this.payload = - Arrays.asList( - currencyPair.toString().replace('/', '_'), - (depth != null && channelName.contains("order_book")) ? Integer.toString(depth) : null, - (interval != null && channelName.contains("order_book")) ? interval + "ms" : null) - .stream() - .filter(Objects::nonNull) - .collect(Collectors.toList()) - .toArray(new String[] {}); - } -} diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/request/GateioWebSocketRequest.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/request/GateioWebSocketRequest.java new file mode 100644 index 00000000000..164ad1c1347 --- /dev/null +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/request/GateioWebSocketRequest.java @@ -0,0 +1,37 @@ +package info.bitrich.xchangestream.gateio.dto.request; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import info.bitrich.xchangestream.gateio.config.InstantToTimestampSecondsConverter; +import info.bitrich.xchangestream.gateio.config.TimestampSecondsToInstantConverter; +import java.time.Instant; +import lombok.Data; +import lombok.experimental.SuperBuilder; +import lombok.extern.jackson.Jacksonized; + +@Data +@SuperBuilder +@Jacksonized +public class GateioWebSocketRequest { + + @JsonProperty("time") + @JsonDeserialize(converter = TimestampSecondsToInstantConverter.class) + @JsonSerialize(converter = InstantToTimestampSecondsConverter.class) + private Instant time; + + @JsonProperty("id") + private Long id; + + @JsonProperty("channel") + private String channel; + + @JsonProperty("event") + private String event; + + @JsonProperty("payload") + @JsonFormat(shape = JsonFormat.Shape.ARRAY) + private Object payload; + +} diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/request/payload/CurrencyPairLevelIntervalPayload.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/request/payload/CurrencyPairLevelIntervalPayload.java new file mode 100644 index 00000000000..e42f8c06a28 --- /dev/null +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/request/payload/CurrencyPairLevelIntervalPayload.java @@ -0,0 +1,32 @@ +package info.bitrich.xchangestream.gateio.dto.request.payload; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonFormat.Shape; +import com.fasterxml.jackson.annotation.JsonGetter; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import info.bitrich.xchangestream.gateio.config.CurrencyPairToStringConverter; +import java.time.Duration; +import lombok.Data; +import lombok.experimental.SuperBuilder; +import lombok.extern.jackson.Jacksonized; +import org.knowm.xchange.currency.CurrencyPair; + +@Data +@SuperBuilder +@Jacksonized +public class CurrencyPairLevelIntervalPayload { + + @JsonSerialize(converter = CurrencyPairToStringConverter.class) + private CurrencyPair currencyPair; + + @JsonFormat(shape = Shape.STRING) + private Integer orderBookLevel; + + private Duration updateSpeed; + + @JsonGetter("updateSpeed") + public String renderUpdateSpeed() { + return updateSpeed.toMillis() + "ms"; + } + +} diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/request/payload/CurrencyPairPayload.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/request/payload/CurrencyPairPayload.java new file mode 100644 index 00000000000..32b6436a69f --- /dev/null +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/request/payload/CurrencyPairPayload.java @@ -0,0 +1,18 @@ +package info.bitrich.xchangestream.gateio.dto.request.payload; + +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import info.bitrich.xchangestream.gateio.config.CurrencyPairToStringConverter; +import lombok.Data; +import lombok.experimental.SuperBuilder; +import lombok.extern.jackson.Jacksonized; +import org.knowm.xchange.currency.CurrencyPair; + +@Data +@SuperBuilder +@Jacksonized +public class CurrencyPairPayload { + + @JsonSerialize(converter = CurrencyPairToStringConverter.class) + private CurrencyPair currencyPair; + +} diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/GateioOrderBookResponse.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/GateioOrderBookResponse.java deleted file mode 100644 index 610996d19e2..00000000000 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/GateioOrderBookResponse.java +++ /dev/null @@ -1,78 +0,0 @@ -package info.bitrich.xchangestream.gateio.dto.response; - -import com.fasterxml.jackson.annotation.JsonProperty; -import java.math.BigDecimal; -import java.time.Instant; -import java.util.Arrays; -import java.util.Date; -import java.util.List; -import java.util.stream.Collectors; -import lombok.Getter; -import lombok.Setter; -import org.knowm.xchange.currency.CurrencyPair; -import org.knowm.xchange.dto.Order; -import org.knowm.xchange.dto.marketdata.OrderBook; -import org.knowm.xchange.dto.trade.LimitOrder; - -@Getter -@Setter -public class GateioOrderBookResponse extends GateioWebSocketTransaction { - @JsonProperty("result") - private Result result; - - @Getter - @Setter - public class Result { - @JsonProperty("t") - private long updateTimeMilliseconds; - - @JsonProperty("lastUpdateId") - private long lastUpdateId; - - @JsonProperty("s") - private String currencyPair; - - @JsonProperty("bids") - private String[][] bids; // Pre-sorted, ascending - [price, amount] - - @JsonProperty("asks") - private String[][] asks; // Pre-sorted, descending - [price, amount] - } - - @Override - public CurrencyPair getCurrencyPair() { - if (result.getCurrencyPair() == null) return null; // Expect to hit this on the success - return new CurrencyPair(result.getCurrencyPair().replace('_', '/')); - } - - public OrderBook toOrderBook(CurrencyPair currencyPair) { - List bids = - Arrays.stream(result.bids) - .map( - rawBid -> - new LimitOrder( - Order.OrderType.BID, - new BigDecimal(rawBid[1]), - currencyPair, - Long.toString(result.lastUpdateId), - null, - new BigDecimal(rawBid[0]))) - .collect(Collectors.toList()); - - List asks = - Arrays.stream(result.asks) - .map( - rawAsk -> - new LimitOrder( - Order.OrderType.ASK, - new BigDecimal(rawAsk[1]), - currencyPair, - Long.toString(result.lastUpdateId), - null, - new BigDecimal(rawAsk[0]))) - .collect(Collectors.toList()); - - return new OrderBook( - Date.from(Instant.ofEpochMilli(result.updateTimeMilliseconds)), asks, bids, false); - } -} diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/GateioTickerNotification.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/GateioTickerNotification.java deleted file mode 100644 index 8b85dfdc46d..00000000000 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/GateioTickerNotification.java +++ /dev/null @@ -1,7 +0,0 @@ -package info.bitrich.xchangestream.gateio.dto.response; - -import info.bitrich.xchangestream.gateio.dto.TickerDTO; - -public class GateioTickerNotification extends GateioWebSocketNotification { - -} diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/GateioTradesResponse.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/GateioTradesResponse.java deleted file mode 100644 index c87c702e192..00000000000 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/GateioTradesResponse.java +++ /dev/null @@ -1,59 +0,0 @@ -package info.bitrich.xchangestream.gateio.dto.response; - -import com.fasterxml.jackson.annotation.JsonProperty; -import java.math.BigDecimal; -import java.util.Date; -import lombok.Getter; -import lombok.Setter; -import org.knowm.xchange.currency.CurrencyPair; -import org.knowm.xchange.dto.Order; -import org.knowm.xchange.dto.marketdata.Trade; - -@Getter -@Setter -public class GateioTradesResponse extends GateioWebSocketTransaction { - @JsonProperty("result") - private Result result; - - @Getter - @Setter - public class Result { - @JsonProperty("id") - private long id; - - @JsonProperty("create_time") - private long createTimeSeconds; - - @JsonProperty("create_time_ms") - private String createTimeMilliseconds; - - @JsonProperty("side") - private String side; - - @JsonProperty("currency_pair") - private String currencyPair; - - @JsonProperty("amount") - private String amount; - - @JsonProperty("price") - private String price; - } - - @Override - public CurrencyPair getCurrencyPair() { - return new CurrencyPair(result.getCurrencyPair().replace('_', '/')); - } - - public Trade toTrade() { - return new Trade( - "sell".equals(this.result.side) ? Order.OrderType.ASK : Order.OrderType.BID, - new BigDecimal(result.amount), - getCurrencyPair(), - new BigDecimal(result.price), - new Date(new BigDecimal(result.createTimeMilliseconds).longValue()), - Long.toString(result.id), - null, - null); - } -} diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/GateioWebSocketTransaction.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/GateioWebSocketTransaction.java deleted file mode 100644 index 81e39bd5f16..00000000000 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/GateioWebSocketTransaction.java +++ /dev/null @@ -1,21 +0,0 @@ -package info.bitrich.xchangestream.gateio.dto.response; - -import com.fasterxml.jackson.annotation.JsonProperty; -import lombok.Getter; -import lombok.Setter; -import org.knowm.xchange.currency.CurrencyPair; - -@Getter -@Setter -public abstract class GateioWebSocketTransaction { - @JsonProperty("time") - private int time; - - @JsonProperty("channel") - private String channel; - - @JsonProperty("event") - private String event; - - public abstract CurrencyPair getCurrencyPair(); -} diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/orderbook/GateioOrderBookNotification.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/orderbook/GateioOrderBookNotification.java new file mode 100644 index 00000000000..15152254c28 --- /dev/null +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/orderbook/GateioOrderBookNotification.java @@ -0,0 +1,7 @@ +package info.bitrich.xchangestream.gateio.dto.response.orderbook; + +import info.bitrich.xchangestream.gateio.dto.response.GateioWebSocketNotification; + +public class GateioOrderBookNotification extends GateioWebSocketNotification { + +} diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/orderbook/OrderBookDTO.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/orderbook/OrderBookDTO.java new file mode 100644 index 00000000000..a6c9deb0546 --- /dev/null +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/orderbook/OrderBookDTO.java @@ -0,0 +1,49 @@ +package info.bitrich.xchangestream.gateio.dto.response.orderbook; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import info.bitrich.xchangestream.gateio.config.StringToCurrencyPairConverter; +import java.math.BigDecimal; +import java.time.Instant; +import java.util.List; +import lombok.Builder; +import lombok.Data; +import lombok.extern.jackson.Jacksonized; +import org.knowm.xchange.currency.CurrencyPair; + +@Data +public class OrderBookDTO { + + @JsonProperty("t") + Instant timestamp; + + @JsonProperty("lastUpdateId") + Long lastUpdateId; + + @JsonProperty("s") + @JsonDeserialize(converter = StringToCurrencyPairConverter.class) + CurrencyPair currencyPair; + + + @JsonProperty("asks") + List asks; + + @JsonProperty("bids") + List bids; + + + @Data + @Builder + @Jacksonized + @JsonFormat(shape = JsonFormat.Shape.ARRAY) + public static class PriceSizeEntry { + + BigDecimal price; + + BigDecimal size; + + } + + +} diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/ticker/GateioTickerNotification.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/ticker/GateioTickerNotification.java new file mode 100644 index 00000000000..93b64b00fe9 --- /dev/null +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/ticker/GateioTickerNotification.java @@ -0,0 +1,7 @@ +package info.bitrich.xchangestream.gateio.dto.response.ticker; + +import info.bitrich.xchangestream.gateio.dto.response.GateioWebSocketNotification; + +public class GateioTickerNotification extends GateioWebSocketNotification { + +} diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/TickerDTO.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/ticker/TickerDTO.java similarity index 93% rename from xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/TickerDTO.java rename to xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/ticker/TickerDTO.java index f4537e5002a..f2909d37f84 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/TickerDTO.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/ticker/TickerDTO.java @@ -1,4 +1,4 @@ -package info.bitrich.xchangestream.gateio.dto; +package info.bitrich.xchangestream.gateio.dto.response.ticker; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/trade/GateioTradeNotification.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/trade/GateioTradeNotification.java new file mode 100644 index 00000000000..7d382f88b95 --- /dev/null +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/trade/GateioTradeNotification.java @@ -0,0 +1,7 @@ +package info.bitrich.xchangestream.gateio.dto.response.trade; + +import info.bitrich.xchangestream.gateio.dto.response.GateioWebSocketNotification; + +public class GateioTradeNotification extends GateioWebSocketNotification { + +} diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/trade/TradeDTO.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/trade/TradeDTO.java new file mode 100644 index 00000000000..4443a49d79f --- /dev/null +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/trade/TradeDTO.java @@ -0,0 +1,38 @@ +package info.bitrich.xchangestream.gateio.dto.response.trade; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import info.bitrich.xchangestream.gateio.config.StringToCurrencyPairConverter; +import info.bitrich.xchangestream.gateio.config.TimestampSecondsToInstantConverter; +import java.math.BigDecimal; +import java.time.Instant; +import lombok.Data; +import org.knowm.xchange.currency.CurrencyPair; + +@Data +public class TradeDTO { + + @JsonProperty("id") + Long id; + + @JsonProperty("create_time") + @JsonDeserialize(converter = TimestampSecondsToInstantConverter.class) + private Instant time; + + @JsonProperty("create_time_ms") + private Instant timeMs; + + @JsonProperty("side") + private String side; + + @JsonProperty("currency_pair") + @JsonDeserialize(converter = StringToCurrencyPairConverter.class) + CurrencyPair currencyPair; + + @JsonProperty("amount") + BigDecimal amount; + + @JsonProperty("price") + BigDecimal price; + +} diff --git a/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingMarketDataServiceIntegration.java b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingMarketDataServiceIntegration.java index a39ce7a01b9..1ea4de8142e 100644 --- a/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingMarketDataServiceIntegration.java +++ b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingMarketDataServiceIntegration.java @@ -3,7 +3,9 @@ import static org.assertj.core.api.Assertions.assertThat; import io.reactivex.Observable; +import io.reactivex.observers.BaseTestConsumer.TestWaitStrategy; import io.reactivex.observers.TestObserver; +import java.time.Duration; import org.junit.jupiter.api.Test; import org.knowm.xchange.currency.CurrencyPair; import org.knowm.xchange.dto.marketdata.OrderBook; @@ -16,13 +18,13 @@ public class GateioStreamingMarketDataServiceIntegration extends GateioStreaming void order_book() { Observable observable = exchange .getStreamingMarketDataService() - .getOrderBook(CurrencyPair.BTC_USDT); + .getOrderBook(CurrencyPair.BTC_USDT, 10, Duration.ofMillis(100)); TestObserver testObserver = observable.test(); OrderBook orderBook = testObserver .assertSubscribed() - .awaitCount(1) + .awaitCount(1, TestWaitStrategy.SLEEP_10MS, 10000) .assertNoTimeout() .values().get(0); @@ -44,7 +46,7 @@ void trades() { Trade trade = testObserver .assertSubscribed() - .awaitCount(1) + .awaitCount(1, TestWaitStrategy.SLEEP_10MS, 10000) .assertNoTimeout() .values().get(0); @@ -66,7 +68,7 @@ void ticker() { Ticker ticker = testObserver .assertSubscribed() - .awaitCount(1) + .awaitCount(1, TestWaitStrategy.SLEEP_10MS, 10000) .assertNoTimeout() .values() .get(0); diff --git a/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/dto/GateioOrderBookResponseTest.java b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/dto/GateioOrderBookResponseTest.java deleted file mode 100644 index 0adaace12c8..00000000000 --- a/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/dto/GateioOrderBookResponseTest.java +++ /dev/null @@ -1,44 +0,0 @@ -package info.bitrich.xchangestream.gateio.dto; - -import com.google.common.io.CharStreams; -import info.bitrich.xchangestream.gateio.dto.response.GateioOrderBookResponse; -import info.bitrich.xchangestream.service.netty.StreamingObjectMapperHelper; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.Reader; -import org.junit.Assert; -import org.junit.Test; - -public class GateioOrderBookResponseTest { - @Test - public void V4_OrderBookResponse_ParsingTest() throws IOException { - InputStream is = getClass().getClassLoader().getResourceAsStream("OrderBookResponse.json"); - String body = null; - try (final Reader reader = new InputStreamReader(is)) { - body = CharStreams.toString(reader); - } - - GateioOrderBookResponse message = - StreamingObjectMapperHelper.getObjectMapper() - .readValue(body, GateioOrderBookResponse.class); - - // Message Metadata - Assert.assertEquals(1606295412, message.getTime()); - Assert.assertEquals("spot.order_book", message.getChannel()); - Assert.assertEquals("update", message.getEvent()); - - // Result data - Assert.assertEquals(1606295412123L, message.getResult().getUpdateTimeMilliseconds()); - Assert.assertEquals(48791820, message.getResult().getLastUpdateId()); - Assert.assertEquals("BTC_USDT", message.getResult().getCurrencyPair()); - - // Bids - Assert.assertEquals("19079.55", message.getResult().getBids()[0][0]); - Assert.assertEquals("0.0195", message.getResult().getBids()[0][1]); - - // Asks - Assert.assertEquals("19080.24", message.getResult().getAsks()[0][0]); - Assert.assertEquals("0.1638", message.getResult().getAsks()[0][1]); - } -} diff --git a/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/dto/GateioTradesResponseTest.java b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/dto/GateioTradesResponseTest.java deleted file mode 100644 index 82633acd79f..00000000000 --- a/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/dto/GateioTradesResponseTest.java +++ /dev/null @@ -1,39 +0,0 @@ -package info.bitrich.xchangestream.gateio.dto; - -import com.google.common.io.CharStreams; -import info.bitrich.xchangestream.gateio.dto.response.GateioTradesResponse; -import info.bitrich.xchangestream.service.netty.StreamingObjectMapperHelper; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.Reader; -import org.junit.Assert; -import org.junit.Test; - -public class GateioTradesResponseTest { - @Test - public void V4_TradeResponse_ParsingTest() throws IOException { - InputStream is = getClass().getClassLoader().getResourceAsStream("TradeResponses.json"); - String body = null; - try (final Reader reader = new InputStreamReader(is)) { - body = CharStreams.toString(reader); - } - - GateioTradesResponse message = - StreamingObjectMapperHelper.getObjectMapper().readValue(body, GateioTradesResponse.class); - - // Message Metadata - Assert.assertEquals(1606292218, message.getTime()); - Assert.assertEquals("spot.trades", message.getChannel()); - Assert.assertEquals("update", message.getEvent()); - - // Result data - Assert.assertEquals(309143071, message.getResult().getId()); - Assert.assertEquals(1606292218, message.getResult().getCreateTimeSeconds()); - Assert.assertEquals("1606292218213.4578", message.getResult().getCreateTimeMilliseconds()); - Assert.assertEquals("GT_USDT", message.getResult().getCurrencyPair()); - Assert.assertEquals("sell", message.getResult().getSide()); - Assert.assertEquals("16.4700000000", message.getResult().getAmount()); - Assert.assertEquals("0.4705000000", message.getResult().getPrice()); - } -} diff --git a/xchange-stream-gateio/src/test/resources/OrderBookResponse.json b/xchange-stream-gateio/src/test/resources/OrderBookResponse.json deleted file mode 100644 index f1774b94836..00000000000 --- a/xchange-stream-gateio/src/test/resources/OrderBookResponse.json +++ /dev/null @@ -1,54 +0,0 @@ -{ - "time": 1606295412, - "channel": "spot.order_book", - "event": "update", - "result": { - "t": 1606295412123, - "lastUpdateId": 48791820, - "s": "BTC_USDT", - "bids": [ - [ - "19079.55", - "0.0195" - ], - [ - "19079.07", - "0.7341" - ], - [ - "19076.23", - "0.00011808" - ], - [ - "19073.9", - "0.105" - ], - [ - "19068.83", - "0.1009" - ] - ], - "asks": [ - [ - "19080.24", - "0.1638" - ], - [ - "19080.91", - "0.1366" - ], - [ - "19080.92", - "0.01" - ], - [ - "19081.29", - "0.01" - ], - [ - "19083.8", - "0.097" - ] - ] - } -} \ No newline at end of file diff --git a/xchange-stream-gateio/src/test/resources/TradeResponses.json b/xchange-stream-gateio/src/test/resources/TradeResponses.json deleted file mode 100644 index 29e96d07612..00000000000 --- a/xchange-stream-gateio/src/test/resources/TradeResponses.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "time": 1606292218, - "channel": "spot.trades", - "event": "update", - "result": { - "id": 309143071, - "create_time": 1606292218, - "create_time_ms": "1606292218213.4578", - "side": "sell", - "currency_pair": "GT_USDT", - "amount": "16.4700000000", - "price": "0.4705000000" - } -} diff --git a/xchange-stream-service-netty/src/main/java/info/bitrich/xchangestream/service/netty/NettyStreamingService.java b/xchange-stream-service-netty/src/main/java/info/bitrich/xchangestream/service/netty/NettyStreamingService.java index 925d9ad1e53..8170ab56b92 100644 --- a/xchange-stream-service-netty/src/main/java/info/bitrich/xchangestream/service/netty/NettyStreamingService.java +++ b/xchange-stream-service-netty/src/main/java/info/bitrich/xchangestream/service/netty/NettyStreamingService.java @@ -419,7 +419,7 @@ public Observable subscribeChannel(String channelName, Object... args) { () -> { if (channels.remove(channelId) != null) { try { - sendMessage(getUnsubscribeMessage(channelId)); + sendMessage(getUnsubscribeMessage(channelId, args)); } catch (IOException e) { LOG.debug("Failed to unsubscribe channel: {} {}", channelId, e.toString()); } catch (Exception e) { From b813af27a1ce2f409ce2fafa259ab316fb62fc73 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Thu, 10 Aug 2023 08:58:11 +0200 Subject: [PATCH 059/159] [gateio-streaming] Improve processing of control events --- .../gateio/GateioStreamingService.java | 16 ++++++ .../gateio/GateioStreamingServiceTest.java | 56 +++++++++++++++++++ .../resources/spot.order_book.update.json | 23 ++++++++ .../test/resources/spot.ticker.update.json | 17 ++++++ .../test/resources/spot.trades.update.json | 15 +++++ .../src/test/resources/subscribe.event.json | 10 ++++ .../src/test/resources/unsubscribe.event.json | 10 ++++ 7 files changed, 147 insertions(+) create mode 100644 xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingServiceTest.java create mode 100644 xchange-stream-gateio/src/test/resources/spot.order_book.update.json create mode 100644 xchange-stream-gateio/src/test/resources/spot.ticker.update.json create mode 100644 xchange-stream-gateio/src/test/resources/spot.trades.update.json create mode 100644 xchange-stream-gateio/src/test/resources/subscribe.event.json create mode 100644 xchange-stream-gateio/src/test/resources/unsubscribe.event.json diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingService.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingService.java index f9a3c94c2e4..abeed1bb1f5 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingService.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingService.java @@ -7,6 +7,7 @@ import info.bitrich.xchangestream.gateio.dto.request.GateioWebSocketRequest; import info.bitrich.xchangestream.gateio.dto.request.payload.CurrencyPairLevelIntervalPayload; import info.bitrich.xchangestream.gateio.dto.request.payload.CurrencyPairPayload; +import info.bitrich.xchangestream.gateio.dto.response.GateioWebSocketNotification; import info.bitrich.xchangestream.service.netty.JsonNettyStreamingService; import info.bitrich.xchangestream.service.netty.WebSocketClientCompressionAllowClientNoContextAndServerNoContextHandler; import io.netty.handler.codec.http.websocketx.extensions.WebSocketClientExtensionHandler; @@ -16,6 +17,8 @@ import java.time.Instant; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import lombok.SneakyThrows; +import org.apache.commons.lang3.RandomUtils; import org.knowm.xchange.currency.CurrencyPair; public class GateioStreamingService extends JsonNettyStreamingService { @@ -94,6 +97,7 @@ private GateioWebSocketRequest getWebSocketRequest(String channelName, String ev // create request common part String generalChannelName = channelName.split(CHANNEL_NAME_DELIMITER)[0]; GateioWebSocketRequest request = GateioWebSocketRequest.builder() + .id(RandomUtils.nextLong()) .channel(generalChannelName) .event(event) .time(Instant.now()) @@ -129,6 +133,18 @@ private GateioWebSocketRequest getWebSocketRequest(String channelName, String ev return request; } + + @SneakyThrows + @Override + protected void handleChannelMessage(String channel, JsonNode message) { + // only process update events + GateioWebSocketNotification notification = objectMapper.treeToValue(message, GateioWebSocketNotification.class); + if (!"update".equals(notification.getEvent())) { + return; + } + super.handleChannelMessage(channel, message); + } + @Override protected WebSocketClientExtensionHandler getWebSocketClientExtensionHandler() { return WebSocketClientCompressionAllowClientNoContextAndServerNoContextHandler.INSTANCE; diff --git a/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingServiceTest.java b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingServiceTest.java new file mode 100644 index 00000000000..d8519c34cae --- /dev/null +++ b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingServiceTest.java @@ -0,0 +1,56 @@ +package info.bitrich.xchangestream.gateio; + + +import static org.assertj.core.api.Assertions.assertThat; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import info.bitrich.xchangestream.gateio.config.ObjecMapperHelper; +import org.junit.jupiter.api.Test; + +public class GateioStreamingServiceTest { + + GateioStreamingService gateioStreamingService = new GateioStreamingService(""); + ObjectMapper objectMapper = ObjecMapperHelper.getObjectMapper(); + + @Test + void channel_name_from_orderbook_update() throws Exception { + JsonNode orderBookUpdate = objectMapper.readTree(getClass().getClassLoader().getResourceAsStream("spot.order_book.update.json")); + String actual = gateioStreamingService.getChannelNameFromMessage(orderBookUpdate); + assertThat(actual).isEqualTo("spot.order_book-BTC_USDT"); + } + + + @Test + void channel_name_from_ticker_update() throws Exception { + JsonNode orderBookUpdate = objectMapper.readTree(getClass().getClassLoader().getResourceAsStream("spot.ticker.update.json")); + String actual = gateioStreamingService.getChannelNameFromMessage(orderBookUpdate); + assertThat(actual).isEqualTo("spot.tickers-BTC_USDT"); + } + + + @Test + void channel_name_from_trade_update() throws Exception { + JsonNode orderBookUpdate = objectMapper.readTree(getClass().getClassLoader().getResourceAsStream("spot.trades.update.json")); + String actual = gateioStreamingService.getChannelNameFromMessage(orderBookUpdate); + assertThat(actual).isEqualTo("spot.trades-BTC_USDT"); + } + + + @Test + void empty_channel_name_from_subscribe_event() throws Exception { + JsonNode orderBookUpdate = objectMapper.readTree(getClass().getClassLoader().getResourceAsStream("subscribe.event.json")); + String actual = gateioStreamingService.getChannelNameFromMessage(orderBookUpdate); + assertThat(actual).isEqualTo("spot.order_book-"); + } + + + @Test + void empty_channel_name_from_unsubscribe_event() throws Exception { + JsonNode orderBookUpdate = objectMapper.readTree(getClass().getClassLoader().getResourceAsStream("unsubscribe.event.json")); + String actual = gateioStreamingService.getChannelNameFromMessage(orderBookUpdate); + assertThat(actual).isEqualTo("spot.trades-"); + } + + +} \ No newline at end of file diff --git a/xchange-stream-gateio/src/test/resources/spot.order_book.update.json b/xchange-stream-gateio/src/test/resources/spot.order_book.update.json new file mode 100644 index 00000000000..6bad4e38425 --- /dev/null +++ b/xchange-stream-gateio/src/test/resources/spot.order_book.update.json @@ -0,0 +1,23 @@ +{ + "time": 1691620594, + "time_ms": 1691620594125, + "channel": "spot.order_book", + "event": "update", + "result": { + "t": 1691620594027, + "lastUpdateId": 14596255957, + "s": "BTC_USDT", + "bids": [ + [ + "29573.6", + "1.69992" + ] + ], + "asks": [ + [ + "29573.7", + "3.29051717" + ] + ] + } +} \ No newline at end of file diff --git a/xchange-stream-gateio/src/test/resources/spot.ticker.update.json b/xchange-stream-gateio/src/test/resources/spot.ticker.update.json new file mode 100644 index 00000000000..69d9dba1b5d --- /dev/null +++ b/xchange-stream-gateio/src/test/resources/spot.ticker.update.json @@ -0,0 +1,17 @@ +{ + "time": 1691620566, + "time_ms": 1691620566926, + "channel": "spot.tickers", + "event": "update", + "result": { + "currency_pair": "BTC_USDT", + "last": "29573.7", + "lowest_ask": "29573.7", + "highest_bid": "29573.6", + "change_percentage": "-0.6601", + "base_volume": "5777.7777606776", + "quote_volume": "171784719.492586746", + "high_24h": "30232.8", + "low_24h": "29176.1" + } +} \ No newline at end of file diff --git a/xchange-stream-gateio/src/test/resources/spot.trades.update.json b/xchange-stream-gateio/src/test/resources/spot.trades.update.json new file mode 100644 index 00000000000..715e2ee38d5 --- /dev/null +++ b/xchange-stream-gateio/src/test/resources/spot.trades.update.json @@ -0,0 +1,15 @@ +{ + "time": 1691620568, + "time_ms": 1691620568796, + "channel": "spot.trades", + "event": "update", + "result": { + "id": 6064666343, + "create_time": 1691620568, + "create_time_ms": "1691620568789.0", + "side": "buy", + "currency_pair": "BTC_USDT", + "amount": "0.0003009", + "price": "29573.7" + } +} \ No newline at end of file diff --git a/xchange-stream-gateio/src/test/resources/subscribe.event.json b/xchange-stream-gateio/src/test/resources/subscribe.event.json new file mode 100644 index 00000000000..70e815c2dc5 --- /dev/null +++ b/xchange-stream-gateio/src/test/resources/subscribe.event.json @@ -0,0 +1,10 @@ +{ + "time": 1691622305, + "time_ms": 1691622305567, + "id": 8578128440611119318, + "channel": "spot.order_book", + "event": "subscribe", + "result": { + "status": "success" + } +} \ No newline at end of file diff --git a/xchange-stream-gateio/src/test/resources/unsubscribe.event.json b/xchange-stream-gateio/src/test/resources/unsubscribe.event.json new file mode 100644 index 00000000000..111be8d2e72 --- /dev/null +++ b/xchange-stream-gateio/src/test/resources/unsubscribe.event.json @@ -0,0 +1,10 @@ +{ + "time": 1691622369, + "time_ms": 1691622369168, + "id": 2644197385697665557, + "channel": "spot.trades", + "event": "unsubscribe", + "result": { + "status": "success" + } +} \ No newline at end of file From 2a4487ab8feaa32240059b8d6c22d273d517104b Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Thu, 10 Aug 2023 09:29:32 +0200 Subject: [PATCH 060/159] [gateio-streaming] Add deserialization based on channel --- .../gateio/GateioStreamingAdapters.java | 4 +- .../GateioStreamingMarketDataService.java | 7 +-- .../gateio/GateioStreamingService.java | 14 +++--- .../{ObjecMapperHelper.java => Config.java} | 15 ++++--- .../response/GateioWebSocketNotification.java | 15 +++++++ ...StreamingMarketDataServiceIntegration.java | 6 +-- .../gateio/GateioStreamingServiceTest.java | 4 +- .../GateioWebSocketNotificationTest.java | 43 +++++++++++++++++++ 8 files changed, 84 insertions(+), 24 deletions(-) rename xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/{ObjecMapperHelper.java => Config.java} (70%) create mode 100644 xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/dto/response/GateioWebSocketNotificationTest.java diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingAdapters.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingAdapters.java index 20eecd89d8b..255a9fab386 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingAdapters.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingAdapters.java @@ -2,7 +2,7 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; -import info.bitrich.xchangestream.gateio.config.ObjecMapperHelper; +import info.bitrich.xchangestream.gateio.config.Config; import info.bitrich.xchangestream.gateio.dto.response.orderbook.GateioOrderBookNotification; import info.bitrich.xchangestream.gateio.dto.response.orderbook.OrderBookDTO; import info.bitrich.xchangestream.gateio.dto.response.ticker.GateioTickerNotification; @@ -22,7 +22,7 @@ @UtilityClass public class GateioStreamingAdapters { - ObjectMapper objectMapper = ObjecMapperHelper.getObjectMapper(); + ObjectMapper objectMapper = Config.getObjectMapper(); @SneakyThrows public Ticker toTicker(JsonNode jsonNode) { diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingMarketDataService.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingMarketDataService.java index 2d8ca6b8fc0..be70df22588 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingMarketDataService.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingMarketDataService.java @@ -1,6 +1,7 @@ package info.bitrich.xchangestream.gateio; import info.bitrich.xchangestream.core.StreamingMarketDataService; +import info.bitrich.xchangestream.gateio.config.Config; import io.reactivex.Observable; import org.knowm.xchange.currency.CurrencyPair; import org.knowm.xchange.dto.marketdata.OrderBook; @@ -27,7 +28,7 @@ public GateioStreamingMarketDataService(GateioStreamingService service) { @Override public Observable getOrderBook(CurrencyPair currencyPair, Object... args) { return service - .subscribeChannel(GateioStreamingService.SPOT_ORDERBOOK_CHANNEL, currencyPair, args) + .subscribeChannel(Config.SPOT_ORDERBOOK_CHANNEL, currencyPair, args) .map(GateioStreamingAdapters::toOrderBook); } @@ -35,7 +36,7 @@ public Observable getOrderBook(CurrencyPair currencyPair, Object... a @Override public Observable getTicker(CurrencyPair currencyPair, Object... args) { return service - .subscribeChannel(GateioStreamingService.SPOT_TICKERS_CHANNEL, currencyPair, args) + .subscribeChannel(Config.SPOT_TICKERS_CHANNEL, currencyPair, args) .map(GateioStreamingAdapters::toTicker); } @@ -43,7 +44,7 @@ public Observable getTicker(CurrencyPair currencyPair, Object... args) { @Override public Observable getTrades(CurrencyPair currencyPair, Object... args) { return service - .subscribeChannel(GateioStreamingService.SPOT_TRADES_CHANNEL, currencyPair) + .subscribeChannel(Config.SPOT_TRADES_CHANNEL, currencyPair) .map(GateioStreamingAdapters::toTrade); } } diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingService.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingService.java index abeed1bb1f5..6bc65c57fa9 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingService.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingService.java @@ -3,7 +3,7 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; -import info.bitrich.xchangestream.gateio.config.ObjecMapperHelper; +import info.bitrich.xchangestream.gateio.config.Config; import info.bitrich.xchangestream.gateio.dto.request.GateioWebSocketRequest; import info.bitrich.xchangestream.gateio.dto.request.payload.CurrencyPairLevelIntervalPayload; import info.bitrich.xchangestream.gateio.dto.request.payload.CurrencyPairPayload; @@ -26,16 +26,12 @@ public class GateioStreamingService extends JsonNettyStreamingService { private static final String UNSUBSCRIBE = "unsubscribe"; private static final String CHANNEL_NAME_DELIMITER = "-"; - public static final String SPOT_ORDERBOOK_CHANNEL = "spot.order_book"; - public static final String SPOT_TRADES_CHANNEL = "spot.trades"; - public static final String SPOT_TICKERS_CHANNEL = "spot.tickers"; - private static final int MAX_DEPTH_DEFAULT = 5; private static final int UPDATE_INTERVAL_DEFAULT = 100; private final Map> subscriptions = new ConcurrentHashMap<>(); - private final ObjectMapper objectMapper = ObjecMapperHelper.getObjectMapper(); + private final ObjectMapper objectMapper = Config.getObjectMapper(); public GateioStreamingService(String apiUri) { super(apiUri, Integer.MAX_VALUE); @@ -107,14 +103,14 @@ private GateioWebSocketRequest getWebSocketRequest(String channelName, String ev Object payload; switch (generalChannelName) { - case SPOT_TICKERS_CHANNEL: - case SPOT_TRADES_CHANNEL: + case Config.SPOT_TICKERS_CHANNEL: + case Config.SPOT_TRADES_CHANNEL: payload = CurrencyPairPayload.builder() .currencyPair(CurrencyPair.BTC_USDT) .build(); break; - case SPOT_ORDERBOOK_CHANNEL: + case Config.SPOT_ORDERBOOK_CHANNEL: Integer orderBookLevel = (args.length > 1 && args[1] instanceof Integer) ? (Integer) args[1] : MAX_DEPTH_DEFAULT; Duration updateSpeed = (args.length > 2 && args[2] instanceof Duration) ? (Duration) args[2] : Duration.ofMillis(UPDATE_INTERVAL_DEFAULT); diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/ObjecMapperHelper.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/Config.java similarity index 70% rename from xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/ObjecMapperHelper.java rename to xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/Config.java index 3733576554d..bba6bae16dc 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/ObjecMapperHelper.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/Config.java @@ -5,12 +5,14 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; -import lombok.experimental.UtilityClass; -@UtilityClass -public class ObjecMapperHelper { +public final class Config { - private final ObjectMapper MAPPER = new ObjectMapper(); + public static final String SPOT_ORDERBOOK_CHANNEL = "spot.order_book"; + public static final String SPOT_TRADES_CHANNEL = "spot.trades"; + public static final String SPOT_TICKERS_CHANNEL = "spot.tickers"; + + private static final ObjectMapper MAPPER = new ObjectMapper(); static { // by default read and write timetamps as milliseconds @@ -27,8 +29,11 @@ public class ObjecMapperHelper { MAPPER.registerModule(new JavaTimeModule()); } + private Config() { + } + - public ObjectMapper getObjectMapper() { + public static ObjectMapper getObjectMapper() { return MAPPER; } diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/GateioWebSocketNotification.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/GateioWebSocketNotification.java index a24cb05e3c7..adfc7d6b5c8 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/GateioWebSocketNotification.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/GateioWebSocketNotification.java @@ -1,11 +1,26 @@ package info.bitrich.xchangestream.gateio.dto.response; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonSubTypes.Type; +import com.fasterxml.jackson.annotation.JsonTypeInfo; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import info.bitrich.xchangestream.gateio.config.Config; import info.bitrich.xchangestream.gateio.config.TimestampSecondsToInstantConverter; +import info.bitrich.xchangestream.gateio.dto.response.orderbook.GateioOrderBookNotification; +import info.bitrich.xchangestream.gateio.dto.response.ticker.GateioTickerNotification; +import info.bitrich.xchangestream.gateio.dto.response.trade.GateioTradeNotification; import java.time.Instant; import lombok.Data; +@JsonTypeInfo( + use = JsonTypeInfo.Id.NAME, + property = "channel") +@JsonSubTypes({ + @Type(value = GateioTradeNotification.class, name = Config.SPOT_TRADES_CHANNEL), + @Type(value = GateioTickerNotification.class, name = Config.SPOT_TICKERS_CHANNEL), + @Type(value = GateioOrderBookNotification.class, name = Config.SPOT_ORDERBOOK_CHANNEL) +}) @Data public class GateioWebSocketNotification { diff --git a/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingMarketDataServiceIntegration.java b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingMarketDataServiceIntegration.java index 1ea4de8142e..22394c32f00 100644 --- a/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingMarketDataServiceIntegration.java +++ b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingMarketDataServiceIntegration.java @@ -24,7 +24,7 @@ void order_book() { OrderBook orderBook = testObserver .assertSubscribed() - .awaitCount(1, TestWaitStrategy.SLEEP_10MS, 10000) + .awaitCount(1, TestWaitStrategy.SLEEP_10MS, 20000) .assertNoTimeout() .values().get(0); @@ -46,7 +46,7 @@ void trades() { Trade trade = testObserver .assertSubscribed() - .awaitCount(1, TestWaitStrategy.SLEEP_10MS, 10000) + .awaitCount(1, TestWaitStrategy.SLEEP_10MS, 20000) .assertNoTimeout() .values().get(0); @@ -68,7 +68,7 @@ void ticker() { Ticker ticker = testObserver .assertSubscribed() - .awaitCount(1, TestWaitStrategy.SLEEP_10MS, 10000) + .awaitCount(1, TestWaitStrategy.SLEEP_10MS, 70000) .assertNoTimeout() .values() .get(0); diff --git a/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingServiceTest.java b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingServiceTest.java index d8519c34cae..6887f0c9076 100644 --- a/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingServiceTest.java +++ b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingServiceTest.java @@ -5,13 +5,13 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; -import info.bitrich.xchangestream.gateio.config.ObjecMapperHelper; +import info.bitrich.xchangestream.gateio.config.Config; import org.junit.jupiter.api.Test; public class GateioStreamingServiceTest { GateioStreamingService gateioStreamingService = new GateioStreamingService(""); - ObjectMapper objectMapper = ObjecMapperHelper.getObjectMapper(); + ObjectMapper objectMapper = Config.getObjectMapper(); @Test void channel_name_from_orderbook_update() throws Exception { diff --git a/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/dto/response/GateioWebSocketNotificationTest.java b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/dto/response/GateioWebSocketNotificationTest.java new file mode 100644 index 00000000000..533b2bcc490 --- /dev/null +++ b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/dto/response/GateioWebSocketNotificationTest.java @@ -0,0 +1,43 @@ +package info.bitrich.xchangestream.gateio.dto.response; + +import static org.assertj.core.api.Assertions.assertThat; + +import com.fasterxml.jackson.databind.ObjectMapper; +import info.bitrich.xchangestream.gateio.config.Config; +import info.bitrich.xchangestream.gateio.dto.response.orderbook.GateioOrderBookNotification; +import info.bitrich.xchangestream.gateio.dto.response.ticker.GateioTickerNotification; +import info.bitrich.xchangestream.gateio.dto.response.trade.GateioTradeNotification; +import org.junit.jupiter.api.Test; + +public class GateioWebSocketNotificationTest { + + ObjectMapper objectMapper = Config.getObjectMapper(); + + @Test + void deserialize_trades() throws Exception { + GateioWebSocketNotification notification = objectMapper.readValue( + getClass().getClassLoader().getResourceAsStream("spot.trades.update.json"), + GateioWebSocketNotification.class); + assertThat(notification).isInstanceOf(GateioTradeNotification.class); + } + + + @Test + void deserialize_ticker() throws Exception { + GateioWebSocketNotification notification = objectMapper.readValue( + getClass().getClassLoader().getResourceAsStream("spot.ticker.update.json"), + GateioWebSocketNotification.class); + assertThat(notification).isInstanceOf(GateioTickerNotification.class); + } + + + @Test + void deserialize_orderbook() throws Exception { + GateioWebSocketNotification notification = objectMapper.readValue( + getClass().getClassLoader().getResourceAsStream("spot.order_book.update.json"), + GateioWebSocketNotification.class); + assertThat(notification).isInstanceOf(GateioOrderBookNotification.class); + } + + +} \ No newline at end of file From ab3c4c75ec65a0d3e314a1b8e89dcf7cb17a62fa Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Thu, 10 Aug 2023 09:57:29 +0200 Subject: [PATCH 061/159] [gateio-streaming] Add enum for event --- .../gateio/GateioStreamingService.java | 11 +++++------ .../xchangestream/gateio/dto/Event.java | 18 ++++++++++++++++++ .../dto/request/GateioWebSocketRequest.java | 3 ++- .../response/GateioWebSocketNotification.java | 3 ++- 4 files changed, 27 insertions(+), 8 deletions(-) create mode 100644 xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/Event.java diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingService.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingService.java index 6bc65c57fa9..1c0b023a743 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingService.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingService.java @@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import info.bitrich.xchangestream.gateio.config.Config; +import info.bitrich.xchangestream.gateio.dto.Event; import info.bitrich.xchangestream.gateio.dto.request.GateioWebSocketRequest; import info.bitrich.xchangestream.gateio.dto.request.payload.CurrencyPairLevelIntervalPayload; import info.bitrich.xchangestream.gateio.dto.request.payload.CurrencyPairPayload; @@ -22,8 +23,6 @@ import org.knowm.xchange.currency.CurrencyPair; public class GateioStreamingService extends JsonNettyStreamingService { - private static final String SUBSCRIBE = "subscribe"; - private static final String UNSUBSCRIBE = "unsubscribe"; private static final String CHANNEL_NAME_DELIMITER = "-"; private static final int MAX_DEPTH_DEFAULT = 5; @@ -84,12 +83,12 @@ public Observable subscribeChannel(String channelName, Object... args) */ @Override public String getSubscribeMessage(String channelName, Object... args) throws IOException { - GateioWebSocketRequest request = getWebSocketRequest(channelName, SUBSCRIBE, args); + GateioWebSocketRequest request = getWebSocketRequest(channelName, Event.SUBSCRIBE , args); return objectMapper.writeValueAsString(request); } - private GateioWebSocketRequest getWebSocketRequest(String channelName, String event, Object... args) { + private GateioWebSocketRequest getWebSocketRequest(String channelName, Event event, Object... args) { // create request common part String generalChannelName = channelName.split(CHANNEL_NAME_DELIMITER)[0]; GateioWebSocketRequest request = GateioWebSocketRequest.builder() @@ -135,7 +134,7 @@ private GateioWebSocketRequest getWebSocketRequest(String channelName, String ev protected void handleChannelMessage(String channel, JsonNode message) { // only process update events GateioWebSocketNotification notification = objectMapper.treeToValue(message, GateioWebSocketNotification.class); - if (!"update".equals(notification.getEvent())) { + if (Event.UPDATE != notification.getEvent()) { return; } super.handleChannelMessage(channel, message); @@ -148,7 +147,7 @@ protected WebSocketClientExtensionHandler getWebSocketClientExtensionHandler() { @Override public String getUnsubscribeMessage(String channelName, Object... args) throws IOException { - GateioWebSocketRequest unsubscribeMessage = getWebSocketRequest(channelName, UNSUBSCRIBE, args); + GateioWebSocketRequest unsubscribeMessage = getWebSocketRequest(channelName, Event.UNSUBSCRIBE, args); return objectMapper.writeValueAsString(unsubscribeMessage); } } diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/Event.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/Event.java new file mode 100644 index 00000000000..701149e1a90 --- /dev/null +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/Event.java @@ -0,0 +1,18 @@ +package info.bitrich.xchangestream.gateio.dto; + +import com.fasterxml.jackson.annotation.JsonValue; +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public enum Event { + SUBSCRIBE("subscribe"), + UNSUBSCRIBE("unsubscribe"), + UPDATE("update"); + + @JsonValue + private final String value; + + +} diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/request/GateioWebSocketRequest.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/request/GateioWebSocketRequest.java index 164ad1c1347..5477b16c056 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/request/GateioWebSocketRequest.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/request/GateioWebSocketRequest.java @@ -6,6 +6,7 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize; import info.bitrich.xchangestream.gateio.config.InstantToTimestampSecondsConverter; import info.bitrich.xchangestream.gateio.config.TimestampSecondsToInstantConverter; +import info.bitrich.xchangestream.gateio.dto.Event; import java.time.Instant; import lombok.Data; import lombok.experimental.SuperBuilder; @@ -28,7 +29,7 @@ public class GateioWebSocketRequest { private String channel; @JsonProperty("event") - private String event; + private Event event; @JsonProperty("payload") @JsonFormat(shape = JsonFormat.Shape.ARRAY) diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/GateioWebSocketNotification.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/GateioWebSocketNotification.java index adfc7d6b5c8..580956f355b 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/GateioWebSocketNotification.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/GateioWebSocketNotification.java @@ -7,6 +7,7 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import info.bitrich.xchangestream.gateio.config.Config; import info.bitrich.xchangestream.gateio.config.TimestampSecondsToInstantConverter; +import info.bitrich.xchangestream.gateio.dto.Event; import info.bitrich.xchangestream.gateio.dto.response.orderbook.GateioOrderBookNotification; import info.bitrich.xchangestream.gateio.dto.response.ticker.GateioTickerNotification; import info.bitrich.xchangestream.gateio.dto.response.trade.GateioTradeNotification; @@ -35,7 +36,7 @@ public class GateioWebSocketNotification { private String channel; @JsonProperty("event") - private String event; + private Event event; @JsonProperty("error") private String error; From 777072468cf2f7013d411235402432a7e278043e Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Thu, 10 Aug 2023 10:53:19 +0200 Subject: [PATCH 062/159] [gateio-streaming] Add suffix to message --- .../gateio/GateioStreamingService.java | 56 +++++++++---------- .../xchangestream/gateio/config/Config.java | 1 + .../response/GateioWebSocketNotification.java | 11 +++- .../gateio/dto/response/SuffixedMessage.java | 7 +++ .../dto/response/orderbook/OrderBookDTO.java | 9 ++- .../gateio/dto/response/ticker/TickerDTO.java | 8 ++- .../gateio/dto/response/trade/TradeDTO.java | 8 ++- .../gateio/GateioStreamingServiceTest.java | 14 ++--- 8 files changed, 73 insertions(+), 41 deletions(-) create mode 100644 xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/SuffixedMessage.java diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingService.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingService.java index 1c0b023a743..94fea3773b6 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingService.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingService.java @@ -23,7 +23,6 @@ import org.knowm.xchange.currency.CurrencyPair; public class GateioStreamingService extends JsonNettyStreamingService { - private static final String CHANNEL_NAME_DELIMITER = "-"; private static final int MAX_DEPTH_DEFAULT = 5; private static final int UPDATE_INTERVAL_DEFAULT = 100; @@ -37,21 +36,11 @@ public GateioStreamingService(String apiUri) { } + @SneakyThrows @Override protected String getChannelNameFromMessage(JsonNode message) { - String channel = message.path("channel") != null ? message.path("channel").asText() : ""; - String currencyPairOrderBook = - message.path("result").path("s") != null ? message.path("result").path("s").asText() : ""; - String currencyPairTradesTickers = - message.path("result").path("currency_pair") != null - ? message.path("result").path("currency_pair").asText() - : ""; - - return new StringBuilder(channel) - .append(CHANNEL_NAME_DELIMITER) - .append(currencyPairOrderBook) - .append(currencyPairTradesTickers) - .toString(); + GateioWebSocketNotification notification = objectMapper.treeToValue(message, GateioWebSocketNotification.class); + return notification.getUniqueChannelName(); } @Override @@ -59,48 +48,48 @@ public Observable subscribeChannel(String channelName, Object... args) final CurrencyPair currencyPair = (args.length > 0 && args[0] instanceof CurrencyPair) ? ((CurrencyPair) args[0]) : null; - String currencyPairChannelName = - String.format("%s-%s", channelName, currencyPair.toString().replace('/', '_')); + String uniqueChannelName = + String.format("%s%s%s", channelName, Config.CHANNEL_NAME_DELIMITER, currencyPair.toString()); // Example channel name key: spot.order_book_update-ETH_USDT, spot.trades-BTC_USDT - if (!channels.containsKey(currencyPairChannelName) && !subscriptions.containsKey(currencyPairChannelName)) { + if (!channels.containsKey(uniqueChannelName) && !subscriptions.containsKey(uniqueChannelName)) { // subscribe - Observable observable = super.subscribeChannel(currencyPairChannelName, args); + Observable observable = super.subscribeChannel(uniqueChannelName, args); // cache channel subscribtion - subscriptions.put(currencyPairChannelName, observable); + subscriptions.put(uniqueChannelName, observable); } - return subscriptions.get(currencyPairChannelName); + return subscriptions.get(uniqueChannelName); } /** * Returns a JSON String containing the subscription message. * - * @param channelName e.g. spot.order_book_update-ETH_USDT + * @param uniqueChannelName e.g. spot.order_book-BTC/USDT * @param args CurrencyPair to subscribe and additional channel-specific arguments * @return subscription message */ @Override - public String getSubscribeMessage(String channelName, Object... args) throws IOException { - GateioWebSocketRequest request = getWebSocketRequest(channelName, Event.SUBSCRIBE , args); + public String getSubscribeMessage(String uniqueChannelName, Object... args) throws IOException { + String generalChannelName = uniqueChannelName.split(Config.CHANNEL_NAME_DELIMITER)[0]; + GateioWebSocketRequest request = getWebSocketRequest(generalChannelName, Event.SUBSCRIBE , args); return objectMapper.writeValueAsString(request); } private GateioWebSocketRequest getWebSocketRequest(String channelName, Event event, Object... args) { // create request common part - String generalChannelName = channelName.split(CHANNEL_NAME_DELIMITER)[0]; GateioWebSocketRequest request = GateioWebSocketRequest.builder() .id(RandomUtils.nextLong()) - .channel(generalChannelName) + .channel(channelName) .event(event) .time(Instant.now()) .build(); // create channel specific payload Object payload; - switch (generalChannelName) { + switch (channelName) { case Config.SPOT_TICKERS_CHANNEL: case Config.SPOT_TRADES_CHANNEL: @@ -122,7 +111,7 @@ private GateioWebSocketRequest getWebSocketRequest(String channelName, Event eve break; default: - throw new IllegalStateException("Unexpected value: " + generalChannelName); + throw new IllegalStateException("Unexpected value: " + channelName); } request.setPayload(payload); return request; @@ -145,9 +134,18 @@ protected WebSocketClientExtensionHandler getWebSocketClientExtensionHandler() { return WebSocketClientCompressionAllowClientNoContextAndServerNoContextHandler.INSTANCE; } + + /** + * Returns a JSON String containing the unsubscribe message. + * + * @param uniqueChannelName e.g. spot.order_book-BTC/USDT + * @param args CurrencyPair to subscribe and additional channel-specific arguments + * @return unsubscribe message + */ @Override - public String getUnsubscribeMessage(String channelName, Object... args) throws IOException { - GateioWebSocketRequest unsubscribeMessage = getWebSocketRequest(channelName, Event.UNSUBSCRIBE, args); + public String getUnsubscribeMessage(String uniqueChannelName, Object... args) throws IOException { + String generalChannelName = uniqueChannelName.split(Config.CHANNEL_NAME_DELIMITER)[0]; + GateioWebSocketRequest unsubscribeMessage = getWebSocketRequest(generalChannelName, Event.UNSUBSCRIBE, args); return objectMapper.writeValueAsString(unsubscribeMessage); } } diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/Config.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/Config.java index bba6bae16dc..faf5e352d99 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/Config.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/Config.java @@ -13,6 +13,7 @@ public final class Config { public static final String SPOT_TICKERS_CHANNEL = "spot.tickers"; private static final ObjectMapper MAPPER = new ObjectMapper(); + public static final String CHANNEL_NAME_DELIMITER = "-"; static { // by default read and write timetamps as milliseconds diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/GateioWebSocketNotification.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/GateioWebSocketNotification.java index 580956f355b..f1dd34b9c41 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/GateioWebSocketNotification.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/GateioWebSocketNotification.java @@ -16,14 +16,15 @@ @JsonTypeInfo( use = JsonTypeInfo.Id.NAME, - property = "channel") + property = "channel", + visible = true) @JsonSubTypes({ @Type(value = GateioTradeNotification.class, name = Config.SPOT_TRADES_CHANNEL), @Type(value = GateioTickerNotification.class, name = Config.SPOT_TICKERS_CHANNEL), @Type(value = GateioOrderBookNotification.class, name = Config.SPOT_ORDERBOOK_CHANNEL) }) @Data -public class GateioWebSocketNotification { +public class GateioWebSocketNotification { @JsonProperty("time") @JsonDeserialize(converter = TimestampSecondsToInstantConverter.class) @@ -43,4 +44,10 @@ public class GateioWebSocketNotification { @JsonProperty("result") private T result; + + + public String getUniqueChannelName() { + return channel + result.getSuffix(); + } + } diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/SuffixedMessage.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/SuffixedMessage.java new file mode 100644 index 00000000000..b3c7ea05d5e --- /dev/null +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/SuffixedMessage.java @@ -0,0 +1,7 @@ +package info.bitrich.xchangestream.gateio.dto.response; + +public interface SuffixedMessage { + + public String getSuffix(); + +} diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/orderbook/OrderBookDTO.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/orderbook/OrderBookDTO.java index a6c9deb0546..e2d806f81e1 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/orderbook/OrderBookDTO.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/orderbook/OrderBookDTO.java @@ -3,7 +3,9 @@ import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import info.bitrich.xchangestream.gateio.config.Config; import info.bitrich.xchangestream.gateio.config.StringToCurrencyPairConverter; +import info.bitrich.xchangestream.gateio.dto.response.SuffixedMessage; import java.math.BigDecimal; import java.time.Instant; import java.util.List; @@ -13,7 +15,7 @@ import org.knowm.xchange.currency.CurrencyPair; @Data -public class OrderBookDTO { +public class OrderBookDTO implements SuffixedMessage { @JsonProperty("t") Instant timestamp; @@ -32,6 +34,11 @@ public class OrderBookDTO { @JsonProperty("bids") List bids; + @Override + public String getSuffix() { + return currencyPair != null ? Config.CHANNEL_NAME_DELIMITER + currencyPair : ""; + } + @Data @Builder diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/ticker/TickerDTO.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/ticker/TickerDTO.java index f2909d37f84..08b7fce222b 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/ticker/TickerDTO.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/ticker/TickerDTO.java @@ -2,13 +2,15 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import info.bitrich.xchangestream.gateio.config.Config; import info.bitrich.xchangestream.gateio.config.StringToCurrencyPairConverter; +import info.bitrich.xchangestream.gateio.dto.response.SuffixedMessage; import java.math.BigDecimal; import lombok.Data; import org.knowm.xchange.currency.CurrencyPair; @Data -public class TickerDTO { +public class TickerDTO implements SuffixedMessage { @JsonProperty("currency_pair") @JsonDeserialize(converter = StringToCurrencyPairConverter.class) @@ -38,4 +40,8 @@ public class TickerDTO { @JsonProperty("low_24h") BigDecimal lowPrice24h; + @Override + public String getSuffix() { + return currencyPair != null ? Config.CHANNEL_NAME_DELIMITER + currencyPair : ""; + } } diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/trade/TradeDTO.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/trade/TradeDTO.java index 4443a49d79f..473dc16c3e6 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/trade/TradeDTO.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/trade/TradeDTO.java @@ -2,15 +2,17 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import info.bitrich.xchangestream.gateio.config.Config; import info.bitrich.xchangestream.gateio.config.StringToCurrencyPairConverter; import info.bitrich.xchangestream.gateio.config.TimestampSecondsToInstantConverter; +import info.bitrich.xchangestream.gateio.dto.response.SuffixedMessage; import java.math.BigDecimal; import java.time.Instant; import lombok.Data; import org.knowm.xchange.currency.CurrencyPair; @Data -public class TradeDTO { +public class TradeDTO implements SuffixedMessage { @JsonProperty("id") Long id; @@ -35,4 +37,8 @@ public class TradeDTO { @JsonProperty("price") BigDecimal price; + @Override + public String getSuffix() { + return currencyPair != null ? Config.CHANNEL_NAME_DELIMITER + currencyPair : ""; + } } diff --git a/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingServiceTest.java b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingServiceTest.java index 6887f0c9076..0fa1bee2388 100644 --- a/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingServiceTest.java +++ b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingServiceTest.java @@ -17,7 +17,7 @@ public class GateioStreamingServiceTest { void channel_name_from_orderbook_update() throws Exception { JsonNode orderBookUpdate = objectMapper.readTree(getClass().getClassLoader().getResourceAsStream("spot.order_book.update.json")); String actual = gateioStreamingService.getChannelNameFromMessage(orderBookUpdate); - assertThat(actual).isEqualTo("spot.order_book-BTC_USDT"); + assertThat(actual).isEqualTo("spot.order_book-BTC/USDT"); } @@ -25,7 +25,7 @@ void channel_name_from_orderbook_update() throws Exception { void channel_name_from_ticker_update() throws Exception { JsonNode orderBookUpdate = objectMapper.readTree(getClass().getClassLoader().getResourceAsStream("spot.ticker.update.json")); String actual = gateioStreamingService.getChannelNameFromMessage(orderBookUpdate); - assertThat(actual).isEqualTo("spot.tickers-BTC_USDT"); + assertThat(actual).isEqualTo("spot.tickers-BTC/USDT"); } @@ -33,23 +33,23 @@ void channel_name_from_ticker_update() throws Exception { void channel_name_from_trade_update() throws Exception { JsonNode orderBookUpdate = objectMapper.readTree(getClass().getClassLoader().getResourceAsStream("spot.trades.update.json")); String actual = gateioStreamingService.getChannelNameFromMessage(orderBookUpdate); - assertThat(actual).isEqualTo("spot.trades-BTC_USDT"); + assertThat(actual).isEqualTo("spot.trades-BTC/USDT"); } @Test - void empty_channel_name_from_subscribe_event() throws Exception { + void channel_name_from_subscribe_event() throws Exception { JsonNode orderBookUpdate = objectMapper.readTree(getClass().getClassLoader().getResourceAsStream("subscribe.event.json")); String actual = gateioStreamingService.getChannelNameFromMessage(orderBookUpdate); - assertThat(actual).isEqualTo("spot.order_book-"); + assertThat(actual).isEqualTo("spot.order_book"); } @Test - void empty_channel_name_from_unsubscribe_event() throws Exception { + void channel_name_from_unsubscribe_event() throws Exception { JsonNode orderBookUpdate = objectMapper.readTree(getClass().getClassLoader().getResourceAsStream("unsubscribe.event.json")); String actual = gateioStreamingService.getChannelNameFromMessage(orderBookUpdate); - assertThat(actual).isEqualTo("spot.trades-"); + assertThat(actual).isEqualTo("spot.trades"); } From e4e96590f7cabcda664ac11e607985c36e51202b Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Thu, 10 Aug 2023 12:51:40 +0200 Subject: [PATCH 063/159] [gateio-streaming] Add lombok annotation --- .../gateio/GateioManualExample.java | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioManualExample.java b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioManualExample.java index 6370cef80d0..87dded8889c 100644 --- a/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioManualExample.java +++ b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioManualExample.java @@ -2,13 +2,12 @@ import info.bitrich.xchangestream.core.StreamingExchangeFactory; import io.reactivex.disposables.Disposable; +import lombok.extern.slf4j.Slf4j; import org.knowm.xchange.ExchangeSpecification; import org.knowm.xchange.currency.CurrencyPair; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +@Slf4j public class GateioManualExample { - private static final Logger LOG = LoggerFactory.getLogger(GateioManualExample.class); public static void main(String[] args) throws Exception { @@ -29,30 +28,30 @@ public static void main(String[] args) throws Exception { .getOrderBook(CurrencyPair.ETH_USDT) .subscribe( orderBook -> { - LOG.info("First ask: {}", orderBook.getAsks().get(0)); - LOG.info("First bid: {}", orderBook.getBids().get(0)); + log.info("First ask: {}", orderBook.getAsks().get(0)); + log.info("First bid: {}", orderBook.getBids().get(0)); }, - throwable -> LOG.error("ERROR in getting order book: ", throwable)); + throwable -> log.error("ERROR in getting order book: ", throwable)); Disposable sub2 = exchange .getStreamingMarketDataService() .getOrderBook(CurrencyPair.BTC_USDT) .subscribe( orderBook -> { - LOG.info("First ask: {}", orderBook.getAsks().get(0)); - LOG.info("First bid: {}", orderBook.getBids().get(0)); + log.info("First ask: {}", orderBook.getAsks().get(0)); + log.info("First bid: {}", orderBook.getBids().get(0)); }, - throwable -> LOG.error("ERROR in getting order book: ", throwable)); + throwable -> log.error("ERROR in getting order book: ", throwable)); Disposable sub3 = exchange .getStreamingMarketDataService() .getTrades(CurrencyPair.BTC_USDT) .subscribe( trade -> { - LOG.info("Trade Price: {}", trade.getPrice()); - LOG.info("Trade Amount: {}", trade.getOriginalAmount()); + log.info("Trade Price: {}", trade.getPrice()); + log.info("Trade Amount: {}", trade.getOriginalAmount()); }, - throwable -> LOG.error("ERROR in getting trade: ", throwable)); + throwable -> log.error("ERROR in getting trade: ", throwable)); Thread.sleep(1000); sub1.dispose(); From 3801e5e21f3a13fe8d212d216f81c0faba9b5322 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Thu, 10 Aug 2023 12:53:11 +0200 Subject: [PATCH 064/159] [gateio-streaming] Refactor streaming service to accept gate-specific jsons --- .../gateio/GateioStreamingAdapters.java | 14 ++---- .../gateio/GateioStreamingExchange.java | 3 -- .../GateioStreamingMarketDataService.java | 6 +++ .../gateio/GateioStreamingService.java | 43 ++++++++++++------- .../gateio/GateioStreamingServiceTest.java | 30 ++++++++----- .../GateioWebSocketNotificationTest.java | 21 +++++---- 6 files changed, 68 insertions(+), 49 deletions(-) diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingAdapters.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingAdapters.java index 255a9fab386..bd08abdfd89 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingAdapters.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingAdapters.java @@ -1,8 +1,5 @@ package info.bitrich.xchangestream.gateio; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import info.bitrich.xchangestream.gateio.config.Config; import info.bitrich.xchangestream.gateio.dto.response.orderbook.GateioOrderBookNotification; import info.bitrich.xchangestream.gateio.dto.response.orderbook.OrderBookDTO; import info.bitrich.xchangestream.gateio.dto.response.ticker.GateioTickerNotification; @@ -22,11 +19,8 @@ @UtilityClass public class GateioStreamingAdapters { - ObjectMapper objectMapper = Config.getObjectMapper(); - @SneakyThrows - public Ticker toTicker(JsonNode jsonNode) { - GateioTickerNotification notification = objectMapper.treeToValue(jsonNode, GateioTickerNotification.class); + public Ticker toTicker(GateioTickerNotification notification) { TickerDTO tickerDTO = notification.getResult(); return new Ticker.Builder() @@ -45,8 +39,7 @@ public Ticker toTicker(JsonNode jsonNode) { @SneakyThrows - public Trade toTrade(JsonNode jsonNode) { - GateioTradeNotification notification = objectMapper.treeToValue(jsonNode, GateioTradeNotification.class); + public Trade toTrade(GateioTradeNotification notification) { TradeDTO tradeDTO = notification.getResult(); @@ -62,8 +55,7 @@ public Trade toTrade(JsonNode jsonNode) { @SneakyThrows - public OrderBook toOrderBook(JsonNode jsonNode) { - GateioOrderBookNotification notification = objectMapper.treeToValue(jsonNode, GateioOrderBookNotification.class); + public OrderBook toOrderBook(GateioOrderBookNotification notification) { OrderBookDTO orderBookDTO = notification.getResult(); Stream asks = orderBookDTO.getAsks().stream() diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingExchange.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingExchange.java index 2c8a9299458..af44b4ba45b 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingExchange.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingExchange.java @@ -5,11 +5,8 @@ import info.bitrich.xchangestream.core.StreamingMarketDataService; import io.reactivex.Completable; import org.knowm.xchange.gateio.GateioExchange; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; public class GateioStreamingExchange extends GateioExchange implements StreamingExchange { - private static final Logger LOG = LoggerFactory.getLogger(GateioStreamingExchange.class); private final String V4_URL = "wss://api.gateio.ws/ws/v4/"; diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingMarketDataService.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingMarketDataService.java index be70df22588..8d1b2b181fb 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingMarketDataService.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingMarketDataService.java @@ -2,6 +2,9 @@ import info.bitrich.xchangestream.core.StreamingMarketDataService; import info.bitrich.xchangestream.gateio.config.Config; +import info.bitrich.xchangestream.gateio.dto.response.orderbook.GateioOrderBookNotification; +import info.bitrich.xchangestream.gateio.dto.response.ticker.GateioTickerNotification; +import info.bitrich.xchangestream.gateio.dto.response.trade.GateioTradeNotification; import io.reactivex.Observable; import org.knowm.xchange.currency.CurrencyPair; import org.knowm.xchange.dto.marketdata.OrderBook; @@ -29,6 +32,7 @@ public GateioStreamingMarketDataService(GateioStreamingService service) { public Observable getOrderBook(CurrencyPair currencyPair, Object... args) { return service .subscribeChannel(Config.SPOT_ORDERBOOK_CHANNEL, currencyPair, args) + .map(GateioOrderBookNotification.class::cast) .map(GateioStreamingAdapters::toOrderBook); } @@ -37,6 +41,7 @@ public Observable getOrderBook(CurrencyPair currencyPair, Object... a public Observable getTicker(CurrencyPair currencyPair, Object... args) { return service .subscribeChannel(Config.SPOT_TICKERS_CHANNEL, currencyPair, args) + .map(GateioTickerNotification.class::cast) .map(GateioStreamingAdapters::toTicker); } @@ -45,6 +50,7 @@ public Observable getTicker(CurrencyPair currencyPair, Object... args) { public Observable getTrades(CurrencyPair currencyPair, Object... args) { return service .subscribeChannel(Config.SPOT_TRADES_CHANNEL, currencyPair) + .map(GateioTradeNotification.class::cast) .map(GateioStreamingAdapters::toTrade); } } diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingService.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingService.java index 94fea3773b6..f4be6ddf6ed 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingService.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingService.java @@ -1,7 +1,6 @@ package info.bitrich.xchangestream.gateio; -import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import info.bitrich.xchangestream.gateio.config.Config; import info.bitrich.xchangestream.gateio.dto.Event; @@ -9,7 +8,7 @@ import info.bitrich.xchangestream.gateio.dto.request.payload.CurrencyPairLevelIntervalPayload; import info.bitrich.xchangestream.gateio.dto.request.payload.CurrencyPairPayload; import info.bitrich.xchangestream.gateio.dto.response.GateioWebSocketNotification; -import info.bitrich.xchangestream.service.netty.JsonNettyStreamingService; +import info.bitrich.xchangestream.service.netty.NettyStreamingService; import info.bitrich.xchangestream.service.netty.WebSocketClientCompressionAllowClientNoContextAndServerNoContextHandler; import io.netty.handler.codec.http.websocketx.extensions.WebSocketClientExtensionHandler; import io.reactivex.Observable; @@ -19,15 +18,17 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import lombok.SneakyThrows; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.RandomUtils; import org.knowm.xchange.currency.CurrencyPair; -public class GateioStreamingService extends JsonNettyStreamingService { +@Slf4j +public class GateioStreamingService extends NettyStreamingService { private static final int MAX_DEPTH_DEFAULT = 5; private static final int UPDATE_INTERVAL_DEFAULT = 100; - private final Map> subscriptions = new ConcurrentHashMap<>(); + private final Map> subscriptions = new ConcurrentHashMap<>(); private final ObjectMapper objectMapper = Config.getObjectMapper(); @@ -35,26 +36,24 @@ public GateioStreamingService(String apiUri) { super(apiUri, Integer.MAX_VALUE); } - - @SneakyThrows @Override - protected String getChannelNameFromMessage(JsonNode message) { - GateioWebSocketNotification notification = objectMapper.treeToValue(message, GateioWebSocketNotification.class); - return notification.getUniqueChannelName(); + protected String getChannelNameFromMessage(GateioWebSocketNotification message) { + return message.getUniqueChannelName(); } @Override - public Observable subscribeChannel(String channelName, Object... args) { + public Observable subscribeChannel(String channelName, Object... args) { final CurrencyPair currencyPair = (args.length > 0 && args[0] instanceof CurrencyPair) ? ((CurrencyPair) args[0]) : null; String uniqueChannelName = String.format("%s%s%s", channelName, Config.CHANNEL_NAME_DELIMITER, currencyPair.toString()); - // Example channel name key: spot.order_book_update-ETH_USDT, spot.trades-BTC_USDT + // Example channel name key: spot.order_book-BTC/USDT if (!channels.containsKey(uniqueChannelName) && !subscriptions.containsKey(uniqueChannelName)) { + // subscribe - Observable observable = super.subscribeChannel(uniqueChannelName, args); + Observable observable = super.subscribeChannel(uniqueChannelName, args); // cache channel subscribtion subscriptions.put(uniqueChannelName, observable); @@ -120,13 +119,12 @@ private GateioWebSocketRequest getWebSocketRequest(String channelName, Event eve @SneakyThrows @Override - protected void handleChannelMessage(String channel, JsonNode message) { + protected void handleChannelMessage(String channel, GateioWebSocketNotification notification) { // only process update events - GateioWebSocketNotification notification = objectMapper.treeToValue(message, GateioWebSocketNotification.class); if (Event.UPDATE != notification.getEvent()) { return; } - super.handleChannelMessage(channel, message); + super.handleChannelMessage(channel, notification); } @Override @@ -148,4 +146,19 @@ public String getUnsubscribeMessage(String uniqueChannelName, Object... args) th GateioWebSocketRequest unsubscribeMessage = getWebSocketRequest(generalChannelName, Event.UNSUBSCRIBE, args); return objectMapper.writeValueAsString(unsubscribeMessage); } + + @Override + public void messageHandler(String message) { + log.debug("Received message: {}", message); + + // Parse incoming message + try { + GateioWebSocketNotification notification = objectMapper.readValue(message, GateioWebSocketNotification.class); + handleMessage(notification); + } catch (IOException e) { + log.error("Error parsing incoming message to JSON: {}", message); + } + + } + } diff --git a/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingServiceTest.java b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingServiceTest.java index 0fa1bee2388..a76a29d56ef 100644 --- a/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingServiceTest.java +++ b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingServiceTest.java @@ -3,9 +3,10 @@ import static org.assertj.core.api.Assertions.assertThat; -import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import info.bitrich.xchangestream.gateio.config.Config; +import info.bitrich.xchangestream.gateio.dto.response.GateioWebSocketNotification; +import java.io.IOException; import org.junit.jupiter.api.Test; public class GateioStreamingServiceTest { @@ -15,42 +16,49 @@ public class GateioStreamingServiceTest { @Test void channel_name_from_orderbook_update() throws Exception { - JsonNode orderBookUpdate = objectMapper.readTree(getClass().getClassLoader().getResourceAsStream("spot.order_book.update.json")); - String actual = gateioStreamingService.getChannelNameFromMessage(orderBookUpdate); + GateioWebSocketNotification notification = readNotification("spot.order_book.update.json"); + String actual = gateioStreamingService.getChannelNameFromMessage(notification); assertThat(actual).isEqualTo("spot.order_book-BTC/USDT"); } @Test void channel_name_from_ticker_update() throws Exception { - JsonNode orderBookUpdate = objectMapper.readTree(getClass().getClassLoader().getResourceAsStream("spot.ticker.update.json")); - String actual = gateioStreamingService.getChannelNameFromMessage(orderBookUpdate); + GateioWebSocketNotification notification = readNotification("spot.ticker.update.json"); + String actual = gateioStreamingService.getChannelNameFromMessage(notification); assertThat(actual).isEqualTo("spot.tickers-BTC/USDT"); } @Test void channel_name_from_trade_update() throws Exception { - JsonNode orderBookUpdate = objectMapper.readTree(getClass().getClassLoader().getResourceAsStream("spot.trades.update.json")); - String actual = gateioStreamingService.getChannelNameFromMessage(orderBookUpdate); + GateioWebSocketNotification notification = readNotification("spot.trades.update.json"); + String actual = gateioStreamingService.getChannelNameFromMessage(notification); assertThat(actual).isEqualTo("spot.trades-BTC/USDT"); } @Test void channel_name_from_subscribe_event() throws Exception { - JsonNode orderBookUpdate = objectMapper.readTree(getClass().getClassLoader().getResourceAsStream("subscribe.event.json")); - String actual = gateioStreamingService.getChannelNameFromMessage(orderBookUpdate); + GateioWebSocketNotification notification = readNotification("subscribe.event.json"); + String actual = gateioStreamingService.getChannelNameFromMessage(notification); assertThat(actual).isEqualTo("spot.order_book"); } @Test void channel_name_from_unsubscribe_event() throws Exception { - JsonNode orderBookUpdate = objectMapper.readTree(getClass().getClassLoader().getResourceAsStream("unsubscribe.event.json")); - String actual = gateioStreamingService.getChannelNameFromMessage(orderBookUpdate); + GateioWebSocketNotification notification = readNotification("unsubscribe.event.json"); + String actual = gateioStreamingService.getChannelNameFromMessage(notification); assertThat(actual).isEqualTo("spot.trades"); } + + private GateioWebSocketNotification readNotification(String resourceName) throws IOException { + return objectMapper.readValue( + getClass().getClassLoader().getResourceAsStream(resourceName), + GateioWebSocketNotification.class + ); + } } \ No newline at end of file diff --git a/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/dto/response/GateioWebSocketNotificationTest.java b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/dto/response/GateioWebSocketNotificationTest.java index 533b2bcc490..1d6dd85380a 100644 --- a/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/dto/response/GateioWebSocketNotificationTest.java +++ b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/dto/response/GateioWebSocketNotificationTest.java @@ -7,6 +7,7 @@ import info.bitrich.xchangestream.gateio.dto.response.orderbook.GateioOrderBookNotification; import info.bitrich.xchangestream.gateio.dto.response.ticker.GateioTickerNotification; import info.bitrich.xchangestream.gateio.dto.response.trade.GateioTradeNotification; +import java.io.IOException; import org.junit.jupiter.api.Test; public class GateioWebSocketNotificationTest { @@ -15,29 +16,31 @@ public class GateioWebSocketNotificationTest { @Test void deserialize_trades() throws Exception { - GateioWebSocketNotification notification = objectMapper.readValue( - getClass().getClassLoader().getResourceAsStream("spot.trades.update.json"), - GateioWebSocketNotification.class); + GateioWebSocketNotification notification = readNotification("spot.trades.update.json"); assertThat(notification).isInstanceOf(GateioTradeNotification.class); } @Test void deserialize_ticker() throws Exception { - GateioWebSocketNotification notification = objectMapper.readValue( - getClass().getClassLoader().getResourceAsStream("spot.ticker.update.json"), - GateioWebSocketNotification.class); + GateioWebSocketNotification notification = readNotification("spot.ticker.update.json"); assertThat(notification).isInstanceOf(GateioTickerNotification.class); } @Test void deserialize_orderbook() throws Exception { - GateioWebSocketNotification notification = objectMapper.readValue( - getClass().getClassLoader().getResourceAsStream("spot.order_book.update.json"), - GateioWebSocketNotification.class); + GateioWebSocketNotification notification = readNotification("spot.order_book.update.json"); assertThat(notification).isInstanceOf(GateioOrderBookNotification.class); } + private GateioWebSocketNotification readNotification(String resourceName) throws IOException { + return objectMapper.readValue( + getClass().getClassLoader().getResourceAsStream(resourceName), + GateioWebSocketNotification.class + ); + } + + } \ No newline at end of file From 8679f56e91335b79747f2065d3d5703ed8858314 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Thu, 10 Aug 2023 16:12:24 +0200 Subject: [PATCH 065/159] [gateio-v4] Fix passing of parameters --- .../GateioStreamingMarketDataService.java | 10 +++++-- .../gateio/GateioStreamingService.java | 26 ++++++++++++------- ...StreamingMarketDataServiceIntegration.java | 4 +-- 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingMarketDataService.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingMarketDataService.java index 8d1b2b181fb..565bb7de85f 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingMarketDataService.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingMarketDataService.java @@ -6,6 +6,8 @@ import info.bitrich.xchangestream.gateio.dto.response.ticker.GateioTickerNotification; import info.bitrich.xchangestream.gateio.dto.response.trade.GateioTradeNotification; import io.reactivex.Observable; +import java.time.Duration; +import org.apache.commons.lang3.ArrayUtils; import org.knowm.xchange.currency.CurrencyPair; import org.knowm.xchange.dto.marketdata.OrderBook; import org.knowm.xchange.dto.marketdata.Ticker; @@ -13,6 +15,8 @@ public class GateioStreamingMarketDataService implements StreamingMarketDataService { + public static final int MAX_DEPTH_DEFAULT = 5; + public static final int UPDATE_INTERVAL_DEFAULT = 100; private final GateioStreamingService service; public GateioStreamingMarketDataService(GateioStreamingService service) { @@ -25,13 +29,15 @@ public GateioStreamingMarketDataService(GateioStreamingService service) { * https://www.gate.io/docs/apiv4/ws/index.html#limited-level-full-order-book-snapshot * * @param currencyPair Currency pair of the order book - * @param args Optional maxDepth, Optional msgInterval + * @param args Order book level: {@link Integer}, update speed: {@link Duration} */ @Override public Observable getOrderBook(CurrencyPair currencyPair, Object... args) { + Integer orderBookLevel = (Integer) ArrayUtils.get(args, 0, MAX_DEPTH_DEFAULT); + Duration updateSpeed = (Duration) ArrayUtils.get(args, 1, UPDATE_INTERVAL_DEFAULT); return service - .subscribeChannel(Config.SPOT_ORDERBOOK_CHANNEL, currencyPair, args) + .subscribeChannel(Config.SPOT_ORDERBOOK_CHANNEL, new Object[]{currencyPair, orderBookLevel, updateSpeed}) .map(GateioOrderBookNotification.class::cast) .map(GateioStreamingAdapters::toOrderBook); } diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingService.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingService.java index f4be6ddf6ed..7f3fc1fa801 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingService.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingService.java @@ -15,19 +15,19 @@ import java.io.IOException; import java.time.Duration; import java.time.Instant; +import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.RandomUtils; +import org.apache.commons.lang3.Validate; import org.knowm.xchange.currency.CurrencyPair; @Slf4j public class GateioStreamingService extends NettyStreamingService { - private static final int MAX_DEPTH_DEFAULT = 5; - private static final int UPDATE_INTERVAL_DEFAULT = 100; - private final Map> subscriptions = new ConcurrentHashMap<>(); private final ObjectMapper objectMapper = Config.getObjectMapper(); @@ -91,23 +91,29 @@ private GateioWebSocketRequest getWebSocketRequest(String channelName, Event eve switch (channelName) { case Config.SPOT_TICKERS_CHANNEL: - case Config.SPOT_TRADES_CHANNEL: + case Config.SPOT_TRADES_CHANNEL: { + CurrencyPair currencyPair = (CurrencyPair) ArrayUtils.get(args, 0); + Validate.notNull(currencyPair); + payload = CurrencyPairPayload.builder() - .currencyPair(CurrencyPair.BTC_USDT) + .currencyPair(currencyPair) .build(); break; + } - case Config.SPOT_ORDERBOOK_CHANNEL: - Integer orderBookLevel = (args.length > 1 && args[1] instanceof Integer) ? (Integer) args[1] : MAX_DEPTH_DEFAULT; - Duration updateSpeed = (args.length > 2 && args[2] instanceof Duration) ? (Duration) args[2] : Duration.ofMillis(UPDATE_INTERVAL_DEFAULT); + case Config.SPOT_ORDERBOOK_CHANNEL: { + CurrencyPair currencyPair = (CurrencyPair) ArrayUtils.get(args, 0); + Integer orderBookLevel = (Integer) ArrayUtils.get(args, 1); + Duration updateSpeed = (Duration) ArrayUtils.get(args, 2); + Validate.noNullElements(List.of(currencyPair, orderBookLevel, updateSpeed)); payload = CurrencyPairLevelIntervalPayload.builder() - .currencyPair(CurrencyPair.BTC_USDT) + .currencyPair(currencyPair) .orderBookLevel(orderBookLevel) .updateSpeed(updateSpeed) .build(); - request.setPayload(payload); break; + } default: throw new IllegalStateException("Unexpected value: " + channelName); diff --git a/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingMarketDataServiceIntegration.java b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingMarketDataServiceIntegration.java index 22394c32f00..e79c037e120 100644 --- a/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingMarketDataServiceIntegration.java +++ b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingMarketDataServiceIntegration.java @@ -31,8 +31,8 @@ void order_book() { testObserver.dispose(); assertThat(orderBook).hasNoNullFieldsOrProperties(); - assertThat(orderBook.getBids()).isNotEmpty(); - assertThat(orderBook.getAsks()).isNotEmpty(); + assertThat(orderBook.getBids()).hasSize(10); + assertThat(orderBook.getAsks()).hasSize(10); } From d268f6b1108a891188af86425f57ecd14199f11b Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Thu, 10 Aug 2023 20:24:48 +0200 Subject: [PATCH 066/159] [gateio-v4] Fix passing of parameters --- .../xchangestream/gateio/GateioStreamingMarketDataService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingMarketDataService.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingMarketDataService.java index 565bb7de85f..462650cfb96 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingMarketDataService.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingMarketDataService.java @@ -46,7 +46,7 @@ public Observable getOrderBook(CurrencyPair currencyPair, Object... a @Override public Observable getTicker(CurrencyPair currencyPair, Object... args) { return service - .subscribeChannel(Config.SPOT_TICKERS_CHANNEL, currencyPair, args) + .subscribeChannel(Config.SPOT_TICKERS_CHANNEL, currencyPair) .map(GateioTickerNotification.class::cast) .map(GateioStreamingAdapters::toTicker); } From cd4d5e76ee17666b8143011b3eef1ef5a872b6f9 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Fri, 11 Aug 2023 00:31:49 +0200 Subject: [PATCH 067/159] [gateio-v4] Fix parsing to instant --- .../gateio/config/DoubleToInstantConverter.java | 15 +++++++++++++++ .../gateio/dto/response/trade/TradeDTO.java | 10 +++------- 2 files changed, 18 insertions(+), 7 deletions(-) create mode 100644 xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/DoubleToInstantConverter.java diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/DoubleToInstantConverter.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/DoubleToInstantConverter.java new file mode 100644 index 00000000000..49069f6542e --- /dev/null +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/DoubleToInstantConverter.java @@ -0,0 +1,15 @@ +package info.bitrich.xchangestream.gateio.config; + +import com.fasterxml.jackson.databind.util.StdConverter; +import java.time.Instant; + +/** + * Converts timestamp as double in milliseconds to {@code Instant} + */ +public class DoubleToInstantConverter extends StdConverter { + + @Override + public Instant convert(final Double value) { + return Instant.ofEpochMilli(value.longValue()); + } +} diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/trade/TradeDTO.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/trade/TradeDTO.java index 473dc16c3e6..db39c693a50 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/trade/TradeDTO.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/trade/TradeDTO.java @@ -2,17 +2,16 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import info.bitrich.xchangestream.gateio.config.Config; +import info.bitrich.xchangestream.gateio.config.DoubleToInstantConverter; import info.bitrich.xchangestream.gateio.config.StringToCurrencyPairConverter; import info.bitrich.xchangestream.gateio.config.TimestampSecondsToInstantConverter; -import info.bitrich.xchangestream.gateio.dto.response.SuffixedMessage; import java.math.BigDecimal; import java.time.Instant; import lombok.Data; import org.knowm.xchange.currency.CurrencyPair; @Data -public class TradeDTO implements SuffixedMessage { +public class TradeDTO { @JsonProperty("id") Long id; @@ -22,6 +21,7 @@ public class TradeDTO implements SuffixedMessage { private Instant time; @JsonProperty("create_time_ms") + @JsonDeserialize(converter = DoubleToInstantConverter.class) private Instant timeMs; @JsonProperty("side") @@ -37,8 +37,4 @@ public class TradeDTO implements SuffixedMessage { @JsonProperty("price") BigDecimal price; - @Override - public String getSuffix() { - return currencyPair != null ? Config.CHANNEL_NAME_DELIMITER + currencyPair : ""; - } } From a9a0d8357280e20d41b850fcdef66888a0fdab9e Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Fri, 11 Aug 2023 00:34:48 +0200 Subject: [PATCH 068/159] [gateio-streaming] Add user trades --- .../gateio/GateioStreamingAdapters.java | 22 ++++ .../gateio/GateioStreamingAuthHelper.java | 29 +++++ .../gateio/GateioStreamingExchange.java | 13 ++- .../gateio/GateioStreamingService.java | 108 +++++++++++++++--- .../gateio/GateioStreamingTradeService.java | 31 +++++ .../xchangestream/gateio/config/Config.java | 4 + .../dto/request/GateioWebSocketRequest.java | 20 ++++ .../dto/request/payload/StringPayload.java | 14 +++ .../response/GateioWebSocketNotification.java | 15 ++- .../gateio/dto/response/SuffixedMessage.java | 7 -- .../GateioOrderBookNotification.java | 19 ++- .../dto/response/orderbook/OrderBookDTO.java | 9 +- .../ticker/GateioTickerNotification.java | 19 ++- .../gateio/dto/response/ticker/TickerDTO.java | 8 +- .../trade/GateioTradeNotification.java | 18 ++- .../GateioMultipleUserTradeNotification.java | 32 ++++++ .../GateioSingleUserTradeNotification.java | 19 +++ .../dto/response/usertrade/UserTradeDTO.java | 65 +++++++++++ .../gateio/GateioStreamingAuthHelperTest.java | 22 ++++ .../gateio/GateioStreamingServiceTest.java | 2 +- ...ateioStreamingTradeServiceIntegration.java | 66 +++++++++++ .../GateioWebSocketNotificationTest.java | 8 ++ .../resources/spot.usertrades.update.json | 27 +++++ 23 files changed, 526 insertions(+), 51 deletions(-) create mode 100644 xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingAuthHelper.java create mode 100644 xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingTradeService.java create mode 100644 xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/request/payload/StringPayload.java delete mode 100644 xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/SuffixedMessage.java create mode 100644 xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/usertrade/GateioMultipleUserTradeNotification.java create mode 100644 xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/usertrade/GateioSingleUserTradeNotification.java create mode 100644 xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/usertrade/UserTradeDTO.java create mode 100644 xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingAuthHelperTest.java create mode 100644 xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingTradeServiceIntegration.java create mode 100644 xchange-stream-gateio/src/test/resources/spot.usertrades.update.json diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingAdapters.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingAdapters.java index bd08abdfd89..4bf4b4e66bc 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingAdapters.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingAdapters.java @@ -6,6 +6,8 @@ import info.bitrich.xchangestream.gateio.dto.response.ticker.TickerDTO; import info.bitrich.xchangestream.gateio.dto.response.trade.GateioTradeNotification; import info.bitrich.xchangestream.gateio.dto.response.trade.TradeDTO; +import info.bitrich.xchangestream.gateio.dto.response.usertrade.GateioSingleUserTradeNotification; +import info.bitrich.xchangestream.gateio.dto.response.usertrade.UserTradeDTO; import java.util.Date; import java.util.stream.Stream; import lombok.SneakyThrows; @@ -15,6 +17,7 @@ import org.knowm.xchange.dto.marketdata.Ticker; import org.knowm.xchange.dto.marketdata.Trade; import org.knowm.xchange.dto.trade.LimitOrder; +import org.knowm.xchange.dto.trade.UserTrade; @UtilityClass public class GateioStreamingAdapters { @@ -54,6 +57,25 @@ public Trade toTrade(GateioTradeNotification notification) { } + @SneakyThrows + public UserTrade toUserTrade(GateioSingleUserTradeNotification notification) { + UserTradeDTO userTradeDTO = notification.getResult(); + + return new UserTrade.Builder() + .type("sell".equals(userTradeDTO.getSide()) ? OrderType.ASK : OrderType.BID) + .originalAmount(userTradeDTO.getAmount()) + .instrument(userTradeDTO.getCurrencyPair()) + .price(userTradeDTO.getPrice()) + .timestamp(Date.from(userTradeDTO.getTime())) + .id(String.valueOf(userTradeDTO.getId())) + .orderId(String.valueOf(userTradeDTO.getOrderId())) + .feeAmount(userTradeDTO.getFee()) + .feeCurrency(userTradeDTO.getFeeCurrency()) + .orderUserReference(userTradeDTO.getRemark()) + .build(); + } + + @SneakyThrows public OrderBook toOrderBook(GateioOrderBookNotification notification) { OrderBookDTO orderBookDTO = notification.getResult(); diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingAuthHelper.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingAuthHelper.java new file mode 100644 index 00000000000..027bc25c7b0 --- /dev/null +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingAuthHelper.java @@ -0,0 +1,29 @@ +package info.bitrich.xchangestream.gateio; + +import java.nio.charset.StandardCharsets; +import javax.crypto.Mac; +import org.knowm.xchange.gateio.service.GateioV4Digest; +import org.knowm.xchange.utils.DigestUtils; + +public class GateioStreamingAuthHelper { + + private final GateioV4Digest gateioV4Digest; + + public GateioStreamingAuthHelper(String apiSecret) { + gateioV4Digest = GateioV4Digest.createInstance(apiSecret); + } + + + /** + * Generates signature based on payload + */ + public String sign(String channel, String event, String timestamp) { + Mac mac = gateioV4Digest.getMac(); + + String payloadToSign = String.format("channel=%s&event=%s&time=%s", channel, event, timestamp); + mac.update(payloadToSign.getBytes(StandardCharsets.UTF_8)); + + return DigestUtils.bytesToHex(mac.doFinal()); + } + +} diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingExchange.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingExchange.java index af44b4ba45b..642229a99cc 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingExchange.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingExchange.java @@ -3,6 +3,7 @@ import info.bitrich.xchangestream.core.ProductSubscription; import info.bitrich.xchangestream.core.StreamingExchange; import info.bitrich.xchangestream.core.StreamingMarketDataService; +import info.bitrich.xchangestream.core.StreamingTradeService; import io.reactivex.Completable; import org.knowm.xchange.gateio.GateioExchange; @@ -12,14 +13,16 @@ public class GateioStreamingExchange extends GateioExchange implements Streaming private GateioStreamingService streamingService; private StreamingMarketDataService streamingMarketDataService; + private StreamingTradeService streamingTradeService; public GateioStreamingExchange() {} @Override public Completable connect(ProductSubscription... args) { - streamingService = new GateioStreamingService(V4_URL); - applyStreamingSpecification(getExchangeSpecification(), streamingService); + streamingService = new GateioStreamingService(V4_URL, exchangeSpecification.getApiKey(), exchangeSpecification.getSecretKey()); + applyStreamingSpecification(exchangeSpecification, streamingService); streamingMarketDataService = new GateioStreamingMarketDataService(streamingService); + streamingTradeService = new GateioStreamingTradeService(streamingService); return streamingService.connect(); } @@ -29,6 +32,7 @@ public Completable disconnect() { GateioStreamingService service = streamingService; streamingService = null; streamingMarketDataService = null; + streamingTradeService = null; return service.disconnect(); } @@ -37,6 +41,11 @@ public StreamingMarketDataService getStreamingMarketDataService() { return streamingMarketDataService; } + @Override + public StreamingTradeService getStreamingTradeService() { + return streamingTradeService; + } + @Override public boolean isAlive() { return streamingService != null && streamingService.isSocketOpen(); diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingService.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingService.java index 7f3fc1fa801..68e0f3f3941 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingService.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingService.java @@ -1,13 +1,18 @@ package info.bitrich.xchangestream.gateio; +import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import info.bitrich.xchangestream.gateio.config.Config; import info.bitrich.xchangestream.gateio.dto.Event; import info.bitrich.xchangestream.gateio.dto.request.GateioWebSocketRequest; +import info.bitrich.xchangestream.gateio.dto.request.GateioWebSocketRequest.AuthInfo; import info.bitrich.xchangestream.gateio.dto.request.payload.CurrencyPairLevelIntervalPayload; import info.bitrich.xchangestream.gateio.dto.request.payload.CurrencyPairPayload; +import info.bitrich.xchangestream.gateio.dto.request.payload.StringPayload; import info.bitrich.xchangestream.gateio.dto.response.GateioWebSocketNotification; +import info.bitrich.xchangestream.gateio.dto.response.usertrade.GateioMultipleUserTradeNotification; +import info.bitrich.xchangestream.gateio.dto.response.usertrade.GateioSingleUserTradeNotification; import info.bitrich.xchangestream.service.netty.NettyStreamingService; import info.bitrich.xchangestream.service.netty.WebSocketClientCompressionAllowClientNoContextAndServerNoContextHandler; import io.netty.handler.codec.http.websocketx.extensions.WebSocketClientExtensionHandler; @@ -15,10 +20,8 @@ import java.io.IOException; import java.time.Duration; import java.time.Instant; -import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; -import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.RandomUtils; @@ -28,12 +31,20 @@ @Slf4j public class GateioStreamingService extends NettyStreamingService { + private static final String USERTRADES_BROADCAST_CHANNEL_NAME = Config.SPOT_USER_TRADES_CHANNEL + Config.CHANNEL_NAME_DELIMITER + "null"; + private final Map> subscriptions = new ConcurrentHashMap<>(); private final ObjectMapper objectMapper = Config.getObjectMapper(); - public GateioStreamingService(String apiUri) { + private final String apiKey; + + private final GateioStreamingAuthHelper gateioStreamingAuthHelper; + + public GateioStreamingService(String apiUri, String apiKey, String apiSecret) { super(apiUri, Integer.MAX_VALUE); + this.apiKey = apiKey; + this.gateioStreamingAuthHelper = new GateioStreamingAuthHelper(apiSecret); } @Override @@ -47,7 +58,7 @@ public Observable subscribeChannel(String channelNa (args.length > 0 && args[0] instanceof CurrencyPair) ? ((CurrencyPair) args[0]) : null; String uniqueChannelName = - String.format("%s%s%s", channelName, Config.CHANNEL_NAME_DELIMITER, currencyPair.toString()); + String.format("%s%s%s", channelName, Config.CHANNEL_NAME_DELIMITER, currencyPair); // Example channel name key: spot.order_book-BTC/USDT if (!channels.containsKey(uniqueChannelName) && !subscriptions.containsKey(uniqueChannelName)) { @@ -90,6 +101,7 @@ private GateioWebSocketRequest getWebSocketRequest(String channelName, Event eve Object payload; switch (channelName) { + // channels require only currency pair in payload case Config.SPOT_TICKERS_CHANNEL: case Config.SPOT_TRADES_CHANNEL: { CurrencyPair currencyPair = (CurrencyPair) ArrayUtils.get(args, 0); @@ -101,11 +113,12 @@ private GateioWebSocketRequest getWebSocketRequest(String channelName, Event eve break; } + // channel requires currency pair, level, interval in payload case Config.SPOT_ORDERBOOK_CHANNEL: { CurrencyPair currencyPair = (CurrencyPair) ArrayUtils.get(args, 0); Integer orderBookLevel = (Integer) ArrayUtils.get(args, 1); Duration updateSpeed = (Duration) ArrayUtils.get(args, 2); - Validate.noNullElements(List.of(currencyPair, orderBookLevel, updateSpeed)); + Validate.noNullElements(new Object[]{currencyPair, orderBookLevel, updateSpeed}); payload = CurrencyPairLevelIntervalPayload.builder() .currencyPair(currencyPair) @@ -115,24 +128,39 @@ private GateioWebSocketRequest getWebSocketRequest(String channelName, Event eve break; } + // channel requires currency pair or default value for all + case Config.SPOT_USER_TRADES_CHANNEL: { + CurrencyPair currencyPair = (CurrencyPair) ArrayUtils.get(args, 0); + if (currencyPair == null) { + payload = StringPayload.builder() + .data("!all") + .build(); + } else { + payload = CurrencyPairPayload.builder() + .currencyPair(currencyPair) + .build(); + } + break; + } + default: throw new IllegalStateException("Unexpected value: " + channelName); } + + // add auth for private channels + if (Config.PRIVATE_CHANNELS.contains(channelName)) { + request.setAuthInfo(AuthInfo.builder() + .method("api_key") + .key(apiKey) + .sign(gateioStreamingAuthHelper.sign(channelName, event.getValue(), String.valueOf(request.getTime().getEpochSecond()))) + .build()); + } + request.setPayload(payload); return request; } - @SneakyThrows - @Override - protected void handleChannelMessage(String channel, GateioWebSocketNotification notification) { - // only process update events - if (Event.UPDATE != notification.getEvent()) { - return; - } - super.handleChannelMessage(channel, notification); - } - @Override protected WebSocketClientExtensionHandler getWebSocketClientExtensionHandler() { return WebSocketClientCompressionAllowClientNoContextAndServerNoContextHandler.INSTANCE; @@ -159,12 +187,58 @@ public void messageHandler(String message) { // Parse incoming message try { - GateioWebSocketNotification notification = objectMapper.readValue(message, GateioWebSocketNotification.class); - handleMessage(notification); + + // process only update messages + JsonNode jsonNode = objectMapper.readTree(message); + String event = jsonNode.path("event") != null ? jsonNode.path("event").asText() : ""; + if (!"update".equals(event)) { + return; + } + + GateioWebSocketNotification notification = objectMapper.treeToValue(jsonNode, GateioWebSocketNotification.class); + + // process arrays in "result" field -> emit each item separately + if (notification instanceof GateioMultipleUserTradeNotification) { + GateioMultipleUserTradeNotification multipleUserTradeNotification = (GateioMultipleUserTradeNotification) notification; + multipleUserTradeNotification.toSingleNotifications().forEach(this::handleMessage); + } + else { + handleMessage(notification); + } } catch (IOException e) { log.error("Error parsing incoming message to JSON: {}", message); } } + + @Override + protected void handleChannelMessage(String channel, GateioWebSocketNotification message) { + if (channel == null) { + log.debug("Channel provided is null"); + return; + } + + // user trade can be emitted to 2 channels + if (message instanceof GateioSingleUserTradeNotification) { + + // subscription that listens to all currency pairs + NettyStreamingService.Subscription broadcast = channels.get( + USERTRADES_BROADCAST_CHANNEL_NAME); + if (broadcast != null && broadcast.getEmitter() != null) { + broadcast.getEmitter().onNext(message); + } + + // subscription that listens to specific currency pair + NettyStreamingService.Subscription specific = channels.get(channel); + if (specific != null && specific.getEmitter() != null) { + specific.getEmitter().onNext(message); + } + + } + else { + super.handleChannelMessage(channel, message); + } + + } } diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingTradeService.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingTradeService.java new file mode 100644 index 00000000000..e375a9268b0 --- /dev/null +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingTradeService.java @@ -0,0 +1,31 @@ +package info.bitrich.xchangestream.gateio; + +import info.bitrich.xchangestream.core.StreamingTradeService; +import info.bitrich.xchangestream.gateio.config.Config; +import info.bitrich.xchangestream.gateio.dto.response.usertrade.GateioSingleUserTradeNotification; +import io.reactivex.Observable; +import org.knowm.xchange.currency.CurrencyPair; +import org.knowm.xchange.dto.trade.UserTrade; + +public class GateioStreamingTradeService implements StreamingTradeService { + + private final GateioStreamingService service; + + public GateioStreamingTradeService(GateioStreamingService service) { + this.service = service; + } + + + @Override + public Observable getUserTrades(CurrencyPair currencyPair, Object... args) { + return service + .subscribeChannel(Config.SPOT_USER_TRADES_CHANNEL, currencyPair) + .map(GateioSingleUserTradeNotification.class::cast) + .map(GateioStreamingAdapters::toUserTrade); + } + + @Override + public Observable getUserTrades() { + return getUserTrades(null); + } +} diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/Config.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/Config.java index faf5e352d99..061d5b1a360 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/Config.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/Config.java @@ -5,12 +5,16 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; +import java.util.List; public final class Config { public static final String SPOT_ORDERBOOK_CHANNEL = "spot.order_book"; public static final String SPOT_TRADES_CHANNEL = "spot.trades"; public static final String SPOT_TICKERS_CHANNEL = "spot.tickers"; + public static final String SPOT_BALANCES_CHANNEL = "spot.balances"; + public static final String SPOT_USER_TRADES_CHANNEL = "spot.usertrades"; + public static final List PRIVATE_CHANNELS = List.of(SPOT_BALANCES_CHANNEL, SPOT_USER_TRADES_CHANNEL); private static final ObjectMapper MAPPER = new ObjectMapper(); public static final String CHANNEL_NAME_DELIMITER = "-"; diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/request/GateioWebSocketRequest.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/request/GateioWebSocketRequest.java index 5477b16c056..eefd9cd1f3e 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/request/GateioWebSocketRequest.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/request/GateioWebSocketRequest.java @@ -31,8 +31,28 @@ public class GateioWebSocketRequest { @JsonProperty("event") private Event event; + @JsonProperty("auth") + private AuthInfo authInfo; + @JsonProperty("payload") @JsonFormat(shape = JsonFormat.Shape.ARRAY) private Object payload; + + @Data + @SuperBuilder + @Jacksonized + public static class AuthInfo { + + @JsonProperty("method") + private String method; + + @JsonProperty("key") + private String key; + + @JsonProperty("sign") + private String sign; + + } + } diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/request/payload/StringPayload.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/request/payload/StringPayload.java new file mode 100644 index 00000000000..4e3b484d6e7 --- /dev/null +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/request/payload/StringPayload.java @@ -0,0 +1,14 @@ +package info.bitrich.xchangestream.gateio.dto.request.payload; + +import lombok.Data; +import lombok.experimental.SuperBuilder; +import lombok.extern.jackson.Jacksonized; + +@Data +@SuperBuilder +@Jacksonized +public class StringPayload { + + private String data; + +} diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/GateioWebSocketNotification.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/GateioWebSocketNotification.java index f1dd34b9c41..0c59f99f5e7 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/GateioWebSocketNotification.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/GateioWebSocketNotification.java @@ -11,8 +11,11 @@ import info.bitrich.xchangestream.gateio.dto.response.orderbook.GateioOrderBookNotification; import info.bitrich.xchangestream.gateio.dto.response.ticker.GateioTickerNotification; import info.bitrich.xchangestream.gateio.dto.response.trade.GateioTradeNotification; +import info.bitrich.xchangestream.gateio.dto.response.usertrade.GateioMultipleUserTradeNotification; import java.time.Instant; import lombok.Data; +import lombok.experimental.SuperBuilder; +import lombok.extern.jackson.Jacksonized; @JsonTypeInfo( use = JsonTypeInfo.Id.NAME, @@ -21,10 +24,13 @@ @JsonSubTypes({ @Type(value = GateioTradeNotification.class, name = Config.SPOT_TRADES_CHANNEL), @Type(value = GateioTickerNotification.class, name = Config.SPOT_TICKERS_CHANNEL), - @Type(value = GateioOrderBookNotification.class, name = Config.SPOT_ORDERBOOK_CHANNEL) + @Type(value = GateioOrderBookNotification.class, name = Config.SPOT_ORDERBOOK_CHANNEL), + @Type(value = GateioMultipleUserTradeNotification.class, name = Config.SPOT_USER_TRADES_CHANNEL) }) @Data -public class GateioWebSocketNotification { +@SuperBuilder +@Jacksonized +public class GateioWebSocketNotification { @JsonProperty("time") @JsonDeserialize(converter = TimestampSecondsToInstantConverter.class) @@ -42,12 +48,9 @@ public class GateioWebSocketNotification { @JsonProperty("error") private String error; - @JsonProperty("result") - private T result; - public String getUniqueChannelName() { - return channel + result.getSuffix(); + return channel; } } diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/SuffixedMessage.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/SuffixedMessage.java deleted file mode 100644 index b3c7ea05d5e..00000000000 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/SuffixedMessage.java +++ /dev/null @@ -1,7 +0,0 @@ -package info.bitrich.xchangestream.gateio.dto.response; - -public interface SuffixedMessage { - - public String getSuffix(); - -} diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/orderbook/GateioOrderBookNotification.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/orderbook/GateioOrderBookNotification.java index 15152254c28..02be6287c0d 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/orderbook/GateioOrderBookNotification.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/orderbook/GateioOrderBookNotification.java @@ -1,7 +1,24 @@ package info.bitrich.xchangestream.gateio.dto.response.orderbook; +import com.fasterxml.jackson.annotation.JsonProperty; +import info.bitrich.xchangestream.gateio.config.Config; import info.bitrich.xchangestream.gateio.dto.response.GateioWebSocketNotification; +import lombok.Data; +import lombok.experimental.SuperBuilder; +import lombok.extern.jackson.Jacksonized; -public class GateioOrderBookNotification extends GateioWebSocketNotification { +@Data +@SuperBuilder +@Jacksonized +public class GateioOrderBookNotification extends GateioWebSocketNotification { + + @JsonProperty("result") + private OrderBookDTO result; + + @Override + public String getUniqueChannelName() { + String suffix = result.getCurrencyPair() != null ? Config.CHANNEL_NAME_DELIMITER + result.getCurrencyPair() : ""; + return super.getUniqueChannelName() + suffix; + } } diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/orderbook/OrderBookDTO.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/orderbook/OrderBookDTO.java index e2d806f81e1..a6c9deb0546 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/orderbook/OrderBookDTO.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/orderbook/OrderBookDTO.java @@ -3,9 +3,7 @@ import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import info.bitrich.xchangestream.gateio.config.Config; import info.bitrich.xchangestream.gateio.config.StringToCurrencyPairConverter; -import info.bitrich.xchangestream.gateio.dto.response.SuffixedMessage; import java.math.BigDecimal; import java.time.Instant; import java.util.List; @@ -15,7 +13,7 @@ import org.knowm.xchange.currency.CurrencyPair; @Data -public class OrderBookDTO implements SuffixedMessage { +public class OrderBookDTO { @JsonProperty("t") Instant timestamp; @@ -34,11 +32,6 @@ public class OrderBookDTO implements SuffixedMessage { @JsonProperty("bids") List bids; - @Override - public String getSuffix() { - return currencyPair != null ? Config.CHANNEL_NAME_DELIMITER + currencyPair : ""; - } - @Data @Builder diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/ticker/GateioTickerNotification.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/ticker/GateioTickerNotification.java index 93b64b00fe9..e6699686e07 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/ticker/GateioTickerNotification.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/ticker/GateioTickerNotification.java @@ -1,7 +1,24 @@ package info.bitrich.xchangestream.gateio.dto.response.ticker; +import com.fasterxml.jackson.annotation.JsonProperty; +import info.bitrich.xchangestream.gateio.config.Config; import info.bitrich.xchangestream.gateio.dto.response.GateioWebSocketNotification; +import lombok.Data; +import lombok.experimental.SuperBuilder; +import lombok.extern.jackson.Jacksonized; -public class GateioTickerNotification extends GateioWebSocketNotification { +@Data +@SuperBuilder +@Jacksonized +public class GateioTickerNotification extends GateioWebSocketNotification { + + @JsonProperty("result") + private TickerDTO result; + + @Override + public String getUniqueChannelName() { + String suffix = result.getCurrencyPair() != null ? Config.CHANNEL_NAME_DELIMITER + result.getCurrencyPair() : ""; + return super.getUniqueChannelName() + suffix; + } } diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/ticker/TickerDTO.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/ticker/TickerDTO.java index 08b7fce222b..f2909d37f84 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/ticker/TickerDTO.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/ticker/TickerDTO.java @@ -2,15 +2,13 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import info.bitrich.xchangestream.gateio.config.Config; import info.bitrich.xchangestream.gateio.config.StringToCurrencyPairConverter; -import info.bitrich.xchangestream.gateio.dto.response.SuffixedMessage; import java.math.BigDecimal; import lombok.Data; import org.knowm.xchange.currency.CurrencyPair; @Data -public class TickerDTO implements SuffixedMessage { +public class TickerDTO { @JsonProperty("currency_pair") @JsonDeserialize(converter = StringToCurrencyPairConverter.class) @@ -40,8 +38,4 @@ public class TickerDTO implements SuffixedMessage { @JsonProperty("low_24h") BigDecimal lowPrice24h; - @Override - public String getSuffix() { - return currencyPair != null ? Config.CHANNEL_NAME_DELIMITER + currencyPair : ""; - } } diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/trade/GateioTradeNotification.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/trade/GateioTradeNotification.java index 7d382f88b95..b6cc3c2bed6 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/trade/GateioTradeNotification.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/trade/GateioTradeNotification.java @@ -1,7 +1,23 @@ package info.bitrich.xchangestream.gateio.dto.response.trade; +import com.fasterxml.jackson.annotation.JsonProperty; +import info.bitrich.xchangestream.gateio.config.Config; import info.bitrich.xchangestream.gateio.dto.response.GateioWebSocketNotification; +import lombok.Data; +import lombok.experimental.SuperBuilder; +import lombok.extern.jackson.Jacksonized; -public class GateioTradeNotification extends GateioWebSocketNotification { +@Data +@SuperBuilder +@Jacksonized +public class GateioTradeNotification extends GateioWebSocketNotification { + @JsonProperty("result") + private TradeDTO result; + + @Override + public String getUniqueChannelName() { + String suffix = result.getCurrencyPair() != null ? Config.CHANNEL_NAME_DELIMITER + result.getCurrencyPair() : ""; + return super.getUniqueChannelName() + suffix; + } } diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/usertrade/GateioMultipleUserTradeNotification.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/usertrade/GateioMultipleUserTradeNotification.java new file mode 100644 index 00000000000..fe5dc758a08 --- /dev/null +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/usertrade/GateioMultipleUserTradeNotification.java @@ -0,0 +1,32 @@ +package info.bitrich.xchangestream.gateio.dto.response.usertrade; + +import com.fasterxml.jackson.annotation.JsonProperty; +import info.bitrich.xchangestream.gateio.dto.response.GateioWebSocketNotification; +import java.util.List; +import java.util.stream.Collectors; +import lombok.Data; +import lombok.experimental.SuperBuilder; +import lombok.extern.jackson.Jacksonized; + +@Data +@SuperBuilder +@Jacksonized +public class GateioMultipleUserTradeNotification extends GateioWebSocketNotification { + + @JsonProperty("result") + private List result; + + + public List toSingleNotifications() { + return result.stream() + .map(userTradeDTO -> GateioSingleUserTradeNotification.builder() + .result(userTradeDTO) + .time(getTime()) + .timeMs(getTimeMs()) + .channel(getChannel()) + .event(getEvent()) + .error(getError()) + .build()) + .collect(Collectors.toList()); + } +} diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/usertrade/GateioSingleUserTradeNotification.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/usertrade/GateioSingleUserTradeNotification.java new file mode 100644 index 00000000000..5a431068e2b --- /dev/null +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/usertrade/GateioSingleUserTradeNotification.java @@ -0,0 +1,19 @@ +package info.bitrich.xchangestream.gateio.dto.response.usertrade; + +import info.bitrich.xchangestream.gateio.config.Config; +import info.bitrich.xchangestream.gateio.dto.response.GateioWebSocketNotification; +import lombok.Data; +import lombok.experimental.SuperBuilder; + +@Data +@SuperBuilder +public class GateioSingleUserTradeNotification extends GateioWebSocketNotification { + + private UserTradeDTO result; + + @Override + public String getUniqueChannelName() { + String suffix = result.getCurrencyPair() != null ? Config.CHANNEL_NAME_DELIMITER + result.getCurrencyPair() : ""; + return super.getUniqueChannelName() + suffix; + } +} diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/usertrade/UserTradeDTO.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/usertrade/UserTradeDTO.java new file mode 100644 index 00000000000..153324376c9 --- /dev/null +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/usertrade/UserTradeDTO.java @@ -0,0 +1,65 @@ +package info.bitrich.xchangestream.gateio.dto.response.usertrade; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import info.bitrich.xchangestream.gateio.config.DoubleToInstantConverter; +import info.bitrich.xchangestream.gateio.config.StringToCurrencyPairConverter; +import info.bitrich.xchangestream.gateio.config.TimestampSecondsToInstantConverter; +import java.math.BigDecimal; +import java.time.Instant; +import lombok.Data; +import org.knowm.xchange.currency.Currency; +import org.knowm.xchange.currency.CurrencyPair; + +@Data +public class UserTradeDTO { + + @JsonProperty("id") + Long id; + + @JsonProperty("user_id") + Long userId; + + @JsonProperty("order_id") + Long orderId; + + @JsonProperty("currency_pair") + @JsonDeserialize(converter = StringToCurrencyPairConverter.class) + CurrencyPair currencyPair; + + @JsonProperty("create_time") + @JsonDeserialize(converter = TimestampSecondsToInstantConverter.class) + private Instant time; + + @JsonProperty("create_time_ms") + @JsonDeserialize(converter = DoubleToInstantConverter.class) + private Instant timeMs; + + @JsonProperty("side") + private String side; + + @JsonProperty("amount") + BigDecimal amount; + + @JsonProperty("role") + String role; + + @JsonProperty("price") + BigDecimal price; + + @JsonProperty("fee") + BigDecimal fee; + + @JsonProperty("fee_currency") + Currency feeCurrency; + + @JsonProperty("point_fee") + BigDecimal pointFee; + + @JsonProperty("gt_fee") + BigDecimal gtFee; + + @JsonProperty("text") + String remark; + +} diff --git a/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingAuthHelperTest.java b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingAuthHelperTest.java new file mode 100644 index 00000000000..0bf85f3adf3 --- /dev/null +++ b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingAuthHelperTest.java @@ -0,0 +1,22 @@ +package info.bitrich.xchangestream.gateio; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.Test; + +class GateioStreamingAuthHelperTest { + + @Test + void sign() { + String time = "1691678147"; + String channel = "spot.balances"; + String event = "subscribe"; + String apiSecret = "a"; + GateioStreamingAuthHelper gateioStreamingAuthHelper = new GateioStreamingAuthHelper(apiSecret); + + String actual = gateioStreamingAuthHelper.sign(channel, event, time); + String expected = "36481b07c37f27bbfda955c312580e70652d856e7626698f7a5250cf31ffb4052be60f2ec42e6e8816c9fb93d7e26d33f8ef245346b7fd2316ad99dd05ad8176"; + assertThat(actual).isEqualTo(expected); + + } +} \ No newline at end of file diff --git a/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingServiceTest.java b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingServiceTest.java index a76a29d56ef..ae9a60aac71 100644 --- a/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingServiceTest.java +++ b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingServiceTest.java @@ -11,7 +11,7 @@ public class GateioStreamingServiceTest { - GateioStreamingService gateioStreamingService = new GateioStreamingService(""); + GateioStreamingService gateioStreamingService = new GateioStreamingService("", null, null); ObjectMapper objectMapper = Config.getObjectMapper(); @Test diff --git a/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingTradeServiceIntegration.java b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingTradeServiceIntegration.java new file mode 100644 index 00000000000..9939f254b67 --- /dev/null +++ b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingTradeServiceIntegration.java @@ -0,0 +1,66 @@ +package info.bitrich.xchangestream.gateio; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assumptions.assumeTrue; + +import io.reactivex.Observable; +import io.reactivex.observers.BaseTestConsumer.TestWaitStrategy; +import io.reactivex.observers.TestObserver; +import org.apache.commons.lang3.StringUtils; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +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") +class GateioStreamingTradeServiceIntegration extends GateioStreamingExchangeIT { + + @BeforeEach + void authConfigured() { + assumeTrue(StringUtils.isNotEmpty(exchange.getExchangeSpecification().getApiKey()), "Needs auth"); + assumeTrue(StringUtils.isNotEmpty(exchange.getExchangeSpecification().getSecretKey()), "Needs auth"); + } + + + @Test + void user_trades_btc() { + Observable observable = exchange + .getStreamingTradeService() + .getUserTrades(CurrencyPair.BTC_USDT); + + TestObserver testObserver = observable.test(); + + UserTrade userTrade = testObserver + .assertSubscribed() + .awaitCount(1, TestWaitStrategy.SLEEP_10MS, 2000000) + .assertNoTimeout() + .values().get(0); + + testObserver.dispose(); + + assertThat(userTrade).hasNoNullFieldsOrPropertiesExcept("makerOrderId", "takerOrderId"); + assertThat(userTrade.getInstrument()).isEqualTo(CurrencyPair.BTC_USDT); + } + + + @Test + void user_trades_all() { + Observable observable = exchange + .getStreamingTradeService() + .getUserTrades(); + + TestObserver testObserver = observable.test(); + + UserTrade userTrade = testObserver + .assertSubscribed() + .awaitCount(1, TestWaitStrategy.SLEEP_10MS, 2000000) + .assertNoTimeout() + .values().get(0); + + testObserver.dispose(); + + assertThat(userTrade).hasNoNullFieldsOrPropertiesExcept("makerOrderId", "takerOrderId"); + } + +} \ No newline at end of file diff --git a/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/dto/response/GateioWebSocketNotificationTest.java b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/dto/response/GateioWebSocketNotificationTest.java index 1d6dd85380a..c3da38355d5 100644 --- a/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/dto/response/GateioWebSocketNotificationTest.java +++ b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/dto/response/GateioWebSocketNotificationTest.java @@ -7,6 +7,7 @@ import info.bitrich.xchangestream.gateio.dto.response.orderbook.GateioOrderBookNotification; import info.bitrich.xchangestream.gateio.dto.response.ticker.GateioTickerNotification; import info.bitrich.xchangestream.gateio.dto.response.trade.GateioTradeNotification; +import info.bitrich.xchangestream.gateio.dto.response.usertrade.GateioMultipleUserTradeNotification; import java.io.IOException; import org.junit.jupiter.api.Test; @@ -35,6 +36,13 @@ void deserialize_orderbook() throws Exception { } + @Test + void deserialize_usertrades() throws Exception { + GateioWebSocketNotification notification = readNotification("spot.usertrades.update.json"); + assertThat(notification).isInstanceOf(GateioMultipleUserTradeNotification.class); + } + + private GateioWebSocketNotification readNotification(String resourceName) throws IOException { return objectMapper.readValue( getClass().getClassLoader().getResourceAsStream(resourceName), diff --git a/xchange-stream-gateio/src/test/resources/spot.usertrades.update.json b/xchange-stream-gateio/src/test/resources/spot.usertrades.update.json new file mode 100644 index 00000000000..c735261ba1d --- /dev/null +++ b/xchange-stream-gateio/src/test/resources/spot.usertrades.update.json @@ -0,0 +1,27 @@ +{ + "time": 1691692159, + "time_ms": 1691692159338, + "channel": "spot.usertrades", + "event": "update", + "result": [ + { + "id": 6068323582, + "user_id": 13439717, + "order_id": "381004078014", + "currency_pair": "BTC_USDT", + "create_time": 1691692159, + "create_time_ms": "1691692159330.475", + "side": "buy", + "amount": "0.00003", + "role": "taker", + "price": "29441.1", + "fee": "0.00000006", + "fee_currency": "BTC", + "point_fee": "0", + "gt_fee": "0", + "text": "3", + "amend_text": "-", + "biz_info": "-" + } + ] +} \ No newline at end of file From 8345a62a291aa1165289128ef7ea6f7614b890a4 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Fri, 11 Aug 2023 00:37:04 +0200 Subject: [PATCH 069/159] [gateio-streaming] Extend test --- .../bitrich/xchangestream/gateio/GateioStreamingExchangeIT.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingExchangeIT.java b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingExchangeIT.java index f95e24c837b..c609599ed9c 100644 --- a/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingExchangeIT.java +++ b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingExchangeIT.java @@ -20,6 +20,8 @@ public static void setup() { StreamingExchangeFactory.INSTANCE .createExchangeWithoutSpecification(GateioStreamingExchange.class) .getDefaultExchangeSpecification(); + spec.setApiKey(System.getenv("GATEIO_API_KEY")); + spec.setSecretKey(System.getenv("GATEIO_API_SECRET")); spec.setShouldLoadRemoteMetaData(false); exchange = From a3c4deeae09e6ba3eb6c7bdd7fc76b12be5e3d02 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Fri, 11 Aug 2023 00:37:57 +0200 Subject: [PATCH 070/159] [gateio-streaming] Add idea rest client files --- xchange-stream-gateio/.gitignore | 1 + xchange-stream-gateio/http-client.env.json | 5 +++ .../http-client.private.env.json.example | 6 +++ .../src/test/resources/rest/order-book.http | 42 +++++++++++++++++++ .../src/test/resources/rest/sign.js | 5 +++ .../src/test/resources/rest/spot-balance.http | 26 ++++++++++++ .../src/test/resources/rest/system.http | 8 ++++ .../src/test/resources/rest/tickers.http | 13 ++++++ .../src/test/resources/rest/user-trades.http | 29 +++++++++++++ 9 files changed, 135 insertions(+) create mode 100644 xchange-stream-gateio/.gitignore create mode 100644 xchange-stream-gateio/http-client.env.json create mode 100644 xchange-stream-gateio/http-client.private.env.json.example create mode 100644 xchange-stream-gateio/src/test/resources/rest/order-book.http create mode 100644 xchange-stream-gateio/src/test/resources/rest/sign.js create mode 100644 xchange-stream-gateio/src/test/resources/rest/spot-balance.http create mode 100644 xchange-stream-gateio/src/test/resources/rest/system.http create mode 100644 xchange-stream-gateio/src/test/resources/rest/tickers.http create mode 100644 xchange-stream-gateio/src/test/resources/rest/user-trades.http diff --git a/xchange-stream-gateio/.gitignore b/xchange-stream-gateio/.gitignore new file mode 100644 index 00000000000..42c7d2cd0eb --- /dev/null +++ b/xchange-stream-gateio/.gitignore @@ -0,0 +1 @@ +http-client.private.env.json \ No newline at end of file diff --git a/xchange-stream-gateio/http-client.env.json b/xchange-stream-gateio/http-client.env.json new file mode 100644 index 00000000000..7d82f548325 --- /dev/null +++ b/xchange-stream-gateio/http-client.env.json @@ -0,0 +1,5 @@ +{ + "default": { + "base_url": "wss://api.gateio.ws/ws/v4/" + } +} \ No newline at end of file diff --git a/xchange-stream-gateio/http-client.private.env.json.example b/xchange-stream-gateio/http-client.private.env.json.example new file mode 100644 index 00000000000..11f254874ee --- /dev/null +++ b/xchange-stream-gateio/http-client.private.env.json.example @@ -0,0 +1,6 @@ +{ + "live": { + "api_key": "replace_me", + "api_secret": "replace_me" + } +} \ No newline at end of file diff --git a/xchange-stream-gateio/src/test/resources/rest/order-book.http b/xchange-stream-gateio/src/test/resources/rest/order-book.http new file mode 100644 index 00000000000..1472dd5c419 --- /dev/null +++ b/xchange-stream-gateio/src/test/resources/rest/order-book.http @@ -0,0 +1,42 @@ +### Best bid or ask price +WEBSOCKET {{base_url}} +Content-Type: application/json + +{ + "time": {{$timestamp}}, + "channel": "spot.book_ticker", + "event": "subscribe", + "payload": [ + "BTC_USDT" + ] +} + + +### Changed order book levels +WEBSOCKET {{base_url}} +Content-Type: application/json + +{ + "time": {{$timestamp}}, + "channel": "spot.order_book_update", + "event": "subscribe", + "payload": [ + "BTC_USDT", "100ms" + ] +} + + +### Limited-Level Full Order Book Snapshot +WEBSOCKET {{base_url}} +Content-Type: application/json + +{ + "time": {{$timestamp}}, + "channel": "spot.order_book", + "event": "subscribe", + "payload": [ + "BTC_USDT", "5", "100ms" + ] +} + + diff --git a/xchange-stream-gateio/src/test/resources/rest/sign.js b/xchange-stream-gateio/src/test/resources/rest/sign.js new file mode 100644 index 00000000000..0a3f134d156 --- /dev/null +++ b/xchange-stream-gateio/src/test/resources/rest/sign.js @@ -0,0 +1,5 @@ +export function gen_sign(channel, event, timestamp) { + const payloadToSign = `channel=${channel}&event=${event}&time=${timestamp}`; + const apiSecret = request.environment.get("api_secret"); + return crypto.hmac.sha512().withTextSecret(apiSecret).updateWithText(payloadToSign).digest().toHex(); +} \ No newline at end of file diff --git a/xchange-stream-gateio/src/test/resources/rest/spot-balance.http b/xchange-stream-gateio/src/test/resources/rest/spot-balance.http new file mode 100644 index 00000000000..05553448a7d --- /dev/null +++ b/xchange-stream-gateio/src/test/resources/rest/spot-balance.http @@ -0,0 +1,26 @@ +### Spot Balance Channel +< {% + import {gen_sign} from 'sign.js' + const event = "subscribe"; + const channel = "spot.balances"; + const timestamp = Math.floor(Date.now() / 1000).toFixed(); + + request.variables.set("timestamp", timestamp); + request.variables.set("channel", channel); + request.variables.set("event", event); + request.variables.set("sign", gen_sign(channel, event, timestamp)); +%} + +WEBSOCKET {{base_url}} +Content-Type: application/json + +{ + "time": {{timestamp}}, + "channel": "{{channel}}", + "event": "{{event}}", + "auth": { + "method": "api_key", + "KEY": "{{api_key}}", + "SIGN": "{{sign}}" + } +} diff --git a/xchange-stream-gateio/src/test/resources/rest/system.http b/xchange-stream-gateio/src/test/resources/rest/system.http new file mode 100644 index 00000000000..413ab4fe560 --- /dev/null +++ b/xchange-stream-gateio/src/test/resources/rest/system.http @@ -0,0 +1,8 @@ +### Application ping pong +WEBSOCKET {{base_url}} +Content-Type: application/json + +{ + "time": {{$timestamp}}, + "channel": "spot.ping" +} diff --git a/xchange-stream-gateio/src/test/resources/rest/tickers.http b/xchange-stream-gateio/src/test/resources/rest/tickers.http new file mode 100644 index 00000000000..4aceb5a87ef --- /dev/null +++ b/xchange-stream-gateio/src/test/resources/rest/tickers.http @@ -0,0 +1,13 @@ +### Tickers Channel +WEBSOCKET {{base_url}} +Content-Type: application/json + +{ + "time": {{$timestamp}}, + "channel": "spot.tickers", + "event": "subscribe", + "payload": [ + "BTC_USDT" + ] +} + diff --git a/xchange-stream-gateio/src/test/resources/rest/user-trades.http b/xchange-stream-gateio/src/test/resources/rest/user-trades.http new file mode 100644 index 00000000000..f089e052457 --- /dev/null +++ b/xchange-stream-gateio/src/test/resources/rest/user-trades.http @@ -0,0 +1,29 @@ +### User Trades Channel +< {% + import {gen_sign} from 'sign.js' + const event = "subscribe"; + const channel = "spot.usertrades"; + const timestamp = Math.floor(Date.now() / 1000).toFixed(); + + request.variables.set("timestamp", timestamp); + request.variables.set("channel", channel); + request.variables.set("event", event); + request.variables.set("sign", gen_sign(channel, event, timestamp)); +%} + +WEBSOCKET {{base_url}} +Content-Type: application/json + +{ + "time": {{timestamp}}, + "channel": "{{channel}}", + "event": "{{event}}", + "payload": [ + "BTC_USDT" + ], + "auth": { + "method": "api_key", + "KEY": "{{api_key}}", + "SIGN": "{{sign}}" + } +} From 10b29d95dbbf0e48f4efce7c9c9b46f66ab42172 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Fri, 11 Aug 2023 01:24:55 +0200 Subject: [PATCH 071/159] [gateio-v4] Add empty payload to subscribe messages --- .../xchangestream/gateio/GateioStreamingService.java | 3 ++- .../gateio/dto/request/payload/EmptyPayload.java | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/request/payload/EmptyPayload.java diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingService.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingService.java index 68e0f3f3941..75585f2633d 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingService.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingService.java @@ -9,6 +9,7 @@ import info.bitrich.xchangestream.gateio.dto.request.GateioWebSocketRequest.AuthInfo; import info.bitrich.xchangestream.gateio.dto.request.payload.CurrencyPairLevelIntervalPayload; import info.bitrich.xchangestream.gateio.dto.request.payload.CurrencyPairPayload; +import info.bitrich.xchangestream.gateio.dto.request.payload.EmptyPayload; import info.bitrich.xchangestream.gateio.dto.request.payload.StringPayload; import info.bitrich.xchangestream.gateio.dto.response.GateioWebSocketNotification; import info.bitrich.xchangestream.gateio.dto.response.usertrade.GateioMultipleUserTradeNotification; @@ -144,7 +145,7 @@ private GateioWebSocketRequest getWebSocketRequest(String channelName, Event eve } default: - throw new IllegalStateException("Unexpected value: " + channelName); + payload = EmptyPayload.builder().build(); } // add auth for private channels diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/request/payload/EmptyPayload.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/request/payload/EmptyPayload.java new file mode 100644 index 00000000000..8481d829958 --- /dev/null +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/request/payload/EmptyPayload.java @@ -0,0 +1,12 @@ +package info.bitrich.xchangestream.gateio.dto.request.payload; + +import lombok.Data; +import lombok.experimental.SuperBuilder; +import lombok.extern.jackson.Jacksonized; + +@Data +@SuperBuilder +@Jacksonized +public class EmptyPayload { + +} From f914ed51927170dca26a6f91eb5931f96643cc26 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Fri, 11 Aug 2023 01:26:23 +0200 Subject: [PATCH 072/159] [gateio-streaming] Add balance changes --- .../gateio/GateioStreamingAccountService.java | 27 +++++++++++ .../gateio/GateioStreamingAdapters.java | 17 +++++++ .../gateio/GateioStreamingExchange.java | 9 ++++ .../gateio/GateioStreamingService.java | 9 +++- .../response/GateioWebSocketNotification.java | 2 + .../dto/response/balance/BalanceDTO.java | 46 +++++++++++++++++++ ...GateioMultipleSpotBalanceNotification.java | 32 +++++++++++++ .../GateioSingleSpotBalanceNotification.java | 21 +++++++++ ...eioStreamingAccountServiceIntegration.java | 46 +++++++++++++++++++ .../GateioWebSocketNotificationTest.java | 8 ++++ .../test/resources/spot.balance.update.json | 20 ++++++++ 11 files changed, 235 insertions(+), 2 deletions(-) create mode 100644 xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingAccountService.java create mode 100644 xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/balance/BalanceDTO.java create mode 100644 xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/balance/GateioMultipleSpotBalanceNotification.java create mode 100644 xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/balance/GateioSingleSpotBalanceNotification.java create mode 100644 xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingAccountServiceIntegration.java create mode 100644 xchange-stream-gateio/src/test/resources/spot.balance.update.json diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingAccountService.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingAccountService.java new file mode 100644 index 00000000000..9e9fb7d0aba --- /dev/null +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingAccountService.java @@ -0,0 +1,27 @@ +package info.bitrich.xchangestream.gateio; + +import info.bitrich.xchangestream.core.StreamingAccountService; +import info.bitrich.xchangestream.gateio.config.Config; +import info.bitrich.xchangestream.gateio.dto.response.balance.GateioSingleSpotBalanceNotification; +import io.reactivex.Observable; +import org.knowm.xchange.currency.Currency; +import org.knowm.xchange.dto.account.Balance; + +public class GateioStreamingAccountService implements StreamingAccountService { + + private final GateioStreamingService service; + + public GateioStreamingAccountService(GateioStreamingService service) { + this.service = service; + } + + + @Override + public Observable getBalanceChanges(Currency currency, Object... args) { + return service + .subscribeChannel(Config.SPOT_BALANCES_CHANNEL) + .map(GateioSingleSpotBalanceNotification.class::cast) + .filter(notification -> (currency == null) || (notification.getResult().getCurrency().equals(currency))) + .map(GateioStreamingAdapters::toBalance); + } +} diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingAdapters.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingAdapters.java index 4bf4b4e66bc..6bc5d14cdc2 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingAdapters.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingAdapters.java @@ -1,5 +1,7 @@ package info.bitrich.xchangestream.gateio; +import info.bitrich.xchangestream.gateio.dto.response.balance.BalanceDTO; +import info.bitrich.xchangestream.gateio.dto.response.balance.GateioSingleSpotBalanceNotification; import info.bitrich.xchangestream.gateio.dto.response.orderbook.GateioOrderBookNotification; import info.bitrich.xchangestream.gateio.dto.response.orderbook.OrderBookDTO; import info.bitrich.xchangestream.gateio.dto.response.ticker.GateioTickerNotification; @@ -13,6 +15,7 @@ import lombok.SneakyThrows; import lombok.experimental.UtilityClass; import org.knowm.xchange.dto.Order.OrderType; +import org.knowm.xchange.dto.account.Balance; import org.knowm.xchange.dto.marketdata.OrderBook; import org.knowm.xchange.dto.marketdata.Ticker; import org.knowm.xchange.dto.marketdata.Trade; @@ -76,6 +79,20 @@ public UserTrade toUserTrade(GateioSingleUserTradeNotification notification) { } + @SneakyThrows + public Balance toBalance(GateioSingleSpotBalanceNotification notification) { + BalanceDTO balanceDTO = notification.getResult(); + + return Balance.builder() + .currency(balanceDTO.getCurrency()) + .total(balanceDTO.getTotal()) + .available(balanceDTO.getAvailable()) + .frozen(balanceDTO.getFreeze()) + .timestamp(Date.from(balanceDTO.getTime())) + .build(); + } + + @SneakyThrows public OrderBook toOrderBook(GateioOrderBookNotification notification) { OrderBookDTO orderBookDTO = notification.getResult(); diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingExchange.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingExchange.java index 642229a99cc..8f70cb7f714 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingExchange.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingExchange.java @@ -1,6 +1,7 @@ package info.bitrich.xchangestream.gateio; import info.bitrich.xchangestream.core.ProductSubscription; +import info.bitrich.xchangestream.core.StreamingAccountService; import info.bitrich.xchangestream.core.StreamingExchange; import info.bitrich.xchangestream.core.StreamingMarketDataService; import info.bitrich.xchangestream.core.StreamingTradeService; @@ -14,6 +15,7 @@ public class GateioStreamingExchange extends GateioExchange implements Streaming private GateioStreamingService streamingService; private StreamingMarketDataService streamingMarketDataService; private StreamingTradeService streamingTradeService; + private StreamingAccountService streamingAccountService; public GateioStreamingExchange() {} @@ -23,6 +25,7 @@ public Completable connect(ProductSubscription... args) { applyStreamingSpecification(exchangeSpecification, streamingService); streamingMarketDataService = new GateioStreamingMarketDataService(streamingService); streamingTradeService = new GateioStreamingTradeService(streamingService); + streamingAccountService = new GateioStreamingAccountService(streamingService); return streamingService.connect(); } @@ -33,6 +36,7 @@ public Completable disconnect() { streamingService = null; streamingMarketDataService = null; streamingTradeService = null; + streamingAccountService = null; return service.disconnect(); } @@ -46,6 +50,11 @@ public StreamingTradeService getStreamingTradeService() { return streamingTradeService; } + @Override + public StreamingAccountService getStreamingAccountService() { + return streamingAccountService; + } + @Override public boolean isAlive() { return streamingService != null && streamingService.isSocketOpen(); diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingService.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingService.java index 75585f2633d..f6f391dce93 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingService.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingService.java @@ -12,6 +12,7 @@ import info.bitrich.xchangestream.gateio.dto.request.payload.EmptyPayload; import info.bitrich.xchangestream.gateio.dto.request.payload.StringPayload; import info.bitrich.xchangestream.gateio.dto.response.GateioWebSocketNotification; +import info.bitrich.xchangestream.gateio.dto.response.balance.GateioMultipleSpotBalanceNotification; import info.bitrich.xchangestream.gateio.dto.response.usertrade.GateioMultipleUserTradeNotification; import info.bitrich.xchangestream.gateio.dto.response.usertrade.GateioSingleUserTradeNotification; import info.bitrich.xchangestream.service.netty.NettyStreamingService; @@ -200,8 +201,12 @@ public void messageHandler(String message) { // process arrays in "result" field -> emit each item separately if (notification instanceof GateioMultipleUserTradeNotification) { - GateioMultipleUserTradeNotification multipleUserTradeNotification = (GateioMultipleUserTradeNotification) notification; - multipleUserTradeNotification.toSingleNotifications().forEach(this::handleMessage); + GateioMultipleUserTradeNotification multipleNotification = (GateioMultipleUserTradeNotification) notification; + multipleNotification.toSingleNotifications().forEach(this::handleMessage); + } + else if (notification instanceof GateioMultipleSpotBalanceNotification) { + GateioMultipleSpotBalanceNotification multipleNotification = (GateioMultipleSpotBalanceNotification) notification; + multipleNotification.toSingleNotifications().forEach(this::handleMessage); } else { handleMessage(notification); diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/GateioWebSocketNotification.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/GateioWebSocketNotification.java index 0c59f99f5e7..3151a7a9d42 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/GateioWebSocketNotification.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/GateioWebSocketNotification.java @@ -8,6 +8,7 @@ import info.bitrich.xchangestream.gateio.config.Config; import info.bitrich.xchangestream.gateio.config.TimestampSecondsToInstantConverter; import info.bitrich.xchangestream.gateio.dto.Event; +import info.bitrich.xchangestream.gateio.dto.response.balance.GateioMultipleSpotBalanceNotification; import info.bitrich.xchangestream.gateio.dto.response.orderbook.GateioOrderBookNotification; import info.bitrich.xchangestream.gateio.dto.response.ticker.GateioTickerNotification; import info.bitrich.xchangestream.gateio.dto.response.trade.GateioTradeNotification; @@ -25,6 +26,7 @@ @Type(value = GateioTradeNotification.class, name = Config.SPOT_TRADES_CHANNEL), @Type(value = GateioTickerNotification.class, name = Config.SPOT_TICKERS_CHANNEL), @Type(value = GateioOrderBookNotification.class, name = Config.SPOT_ORDERBOOK_CHANNEL), + @Type(value = GateioMultipleSpotBalanceNotification.class, name = Config.SPOT_BALANCES_CHANNEL), @Type(value = GateioMultipleUserTradeNotification.class, name = Config.SPOT_USER_TRADES_CHANNEL) }) @Data diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/balance/BalanceDTO.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/balance/BalanceDTO.java new file mode 100644 index 00000000000..f5639b8d27e --- /dev/null +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/balance/BalanceDTO.java @@ -0,0 +1,46 @@ +package info.bitrich.xchangestream.gateio.dto.response.balance; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import info.bitrich.xchangestream.gateio.config.TimestampSecondsToInstantConverter; +import java.math.BigDecimal; +import java.time.Instant; +import lombok.Data; +import org.knowm.xchange.currency.Currency; + +@Data +public class BalanceDTO { + + @JsonProperty("timestamp") + @JsonDeserialize(converter = TimestampSecondsToInstantConverter.class) + private Instant time; + + @JsonProperty("timestamp_ms") + private Instant timeMs; + + @JsonProperty("user") + Long userId; + + @JsonProperty("currency") + Currency currency; + + @JsonProperty("change") + BigDecimal change; + + @JsonProperty("total") + BigDecimal total; + + @JsonProperty("available") + BigDecimal available; + + @JsonProperty("freeze") + BigDecimal freeze; + + @JsonProperty("freeze_change") + BigDecimal freezeChange; + + + @JsonProperty("change_type") + String changeType; + +} diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/balance/GateioMultipleSpotBalanceNotification.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/balance/GateioMultipleSpotBalanceNotification.java new file mode 100644 index 00000000000..83e7b3a594f --- /dev/null +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/balance/GateioMultipleSpotBalanceNotification.java @@ -0,0 +1,32 @@ +package info.bitrich.xchangestream.gateio.dto.response.balance; + +import com.fasterxml.jackson.annotation.JsonProperty; +import info.bitrich.xchangestream.gateio.dto.response.GateioWebSocketNotification; +import java.util.List; +import java.util.stream.Collectors; +import lombok.Data; +import lombok.experimental.SuperBuilder; +import lombok.extern.jackson.Jacksonized; + +@Data +@SuperBuilder +@Jacksonized +public class GateioMultipleSpotBalanceNotification extends GateioWebSocketNotification { + + @JsonProperty("result") + private List result; + + + public List toSingleNotifications() { + return result.stream() + .map(balanceDTO -> GateioSingleSpotBalanceNotification.builder() + .result(balanceDTO) + .time(getTime()) + .timeMs(getTimeMs()) + .channel(getChannel()) + .event(getEvent()) + .error(getError()) + .build()) + .collect(Collectors.toList()); + } +} diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/balance/GateioSingleSpotBalanceNotification.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/balance/GateioSingleSpotBalanceNotification.java new file mode 100644 index 00000000000..24ff6815f1e --- /dev/null +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/balance/GateioSingleSpotBalanceNotification.java @@ -0,0 +1,21 @@ +package info.bitrich.xchangestream.gateio.dto.response.balance; + +import info.bitrich.xchangestream.gateio.config.Config; +import info.bitrich.xchangestream.gateio.dto.response.GateioWebSocketNotification; +import lombok.Data; +import lombok.experimental.SuperBuilder; + +@Data +@SuperBuilder +public class GateioSingleSpotBalanceNotification extends GateioWebSocketNotification { + + private BalanceDTO result; + + @Override + public String getUniqueChannelName() { + // there is no currency specific subscription + return super.getUniqueChannelName() + Config.CHANNEL_NAME_DELIMITER + "null"; + } + + +} diff --git a/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingAccountServiceIntegration.java b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingAccountServiceIntegration.java new file mode 100644 index 00000000000..aaf76323ccf --- /dev/null +++ b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingAccountServiceIntegration.java @@ -0,0 +1,46 @@ +package info.bitrich.xchangestream.gateio; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assumptions.assumeTrue; + +import io.reactivex.Observable; +import io.reactivex.observers.BaseTestConsumer.TestWaitStrategy; +import io.reactivex.observers.TestObserver; +import org.apache.commons.lang3.StringUtils; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.knowm.xchange.currency.Currency; +import org.knowm.xchange.dto.account.Balance; + +@Disabled("Needs authenticated exchange and real balance change. Set env vars GATEIO_API_KEY/GATEIO_API_SECRET") +class GateioStreamingAccountServiceIntegration extends GateioStreamingExchangeIT { + + @BeforeEach + void authConfigured() { + assumeTrue(StringUtils.isNotEmpty(exchange.getExchangeSpecification().getApiKey()), "Needs auth"); + assumeTrue(StringUtils.isNotEmpty(exchange.getExchangeSpecification().getSecretKey()), "Needs auth"); + } + + + @Test + void spot_balances() { + Observable observable = exchange + .getStreamingAccountService() + .getBalanceChanges(Currency.USDT); + + TestObserver testObserver = observable.test(); + + Balance balance = testObserver + .assertSubscribed() + .awaitCount(1, TestWaitStrategy.SLEEP_10MS, 2000000) + .assertNoTimeout() + .values().get(0); + + testObserver.dispose(); + + assertThat(balance).hasNoNullFieldsOrProperties(); + } + + +} \ No newline at end of file diff --git a/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/dto/response/GateioWebSocketNotificationTest.java b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/dto/response/GateioWebSocketNotificationTest.java index c3da38355d5..e1434071521 100644 --- a/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/dto/response/GateioWebSocketNotificationTest.java +++ b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/dto/response/GateioWebSocketNotificationTest.java @@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import info.bitrich.xchangestream.gateio.config.Config; +import info.bitrich.xchangestream.gateio.dto.response.balance.GateioMultipleSpotBalanceNotification; import info.bitrich.xchangestream.gateio.dto.response.orderbook.GateioOrderBookNotification; import info.bitrich.xchangestream.gateio.dto.response.ticker.GateioTickerNotification; import info.bitrich.xchangestream.gateio.dto.response.trade.GateioTradeNotification; @@ -43,6 +44,13 @@ void deserialize_usertrades() throws Exception { } + @Test + void deserialize_balances() throws Exception { + GateioWebSocketNotification notification = readNotification("spot.balance.update.json"); + assertThat(notification).isInstanceOf(GateioMultipleSpotBalanceNotification.class); + } + + private GateioWebSocketNotification readNotification(String resourceName) throws IOException { return objectMapper.readValue( getClass().getClassLoader().getResourceAsStream(resourceName), diff --git a/xchange-stream-gateio/src/test/resources/spot.balance.update.json b/xchange-stream-gateio/src/test/resources/spot.balance.update.json new file mode 100644 index 00000000000..d656efcd6d5 --- /dev/null +++ b/xchange-stream-gateio/src/test/resources/spot.balance.update.json @@ -0,0 +1,20 @@ +{ + "time": 1691707273, + "time_ms": 1691707273893, + "channel": "spot.balances", + "event": "update", + "result": [ + { + "timestamp": "1691707273", + "timestamp_ms": "1691707273890", + "user": "13439717", + "currency": "USDT", + "change": "0", + "total": "43.06583427604872431142", + "available": "42.06583427604872431142", + "freeze": "1", + "freeze_change": "1.00000000000", + "change_type": "order-create" + } + ] +} \ No newline at end of file From 945a9eb4d1380f7d0a97997c4f265787421fdde2 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Fri, 11 Aug 2023 10:15:17 +0200 Subject: [PATCH 073/159] [gateio-streaming] Refactor config --- .../gateio/GateioStreamingExchange.java | 13 ++++++++++--- .../bitrich/xchangestream/gateio/config/Config.java | 2 ++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingExchange.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingExchange.java index 8f70cb7f714..8fc525fac93 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingExchange.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingExchange.java @@ -5,13 +5,13 @@ import info.bitrich.xchangestream.core.StreamingExchange; import info.bitrich.xchangestream.core.StreamingMarketDataService; import info.bitrich.xchangestream.core.StreamingTradeService; +import info.bitrich.xchangestream.gateio.config.Config; import io.reactivex.Completable; +import org.knowm.xchange.ExchangeSpecification; import org.knowm.xchange.gateio.GateioExchange; public class GateioStreamingExchange extends GateioExchange implements StreamingExchange { - private final String V4_URL = "wss://api.gateio.ws/ws/v4/"; - private GateioStreamingService streamingService; private StreamingMarketDataService streamingMarketDataService; private StreamingTradeService streamingTradeService; @@ -21,7 +21,7 @@ public GateioStreamingExchange() {} @Override public Completable connect(ProductSubscription... args) { - streamingService = new GateioStreamingService(V4_URL, exchangeSpecification.getApiKey(), exchangeSpecification.getSecretKey()); + streamingService = new GateioStreamingService(exchangeSpecification.getSslUri(), exchangeSpecification.getApiKey(), exchangeSpecification.getSecretKey()); applyStreamingSpecification(exchangeSpecification, streamingService); streamingMarketDataService = new GateioStreamingMarketDataService(streamingService); streamingTradeService = new GateioStreamingTradeService(streamingService); @@ -64,4 +64,11 @@ public boolean isAlive() { public void useCompressedMessages(boolean compressedMessages) { streamingService.useCompressedMessages(compressedMessages); } + + @Override + public ExchangeSpecification getDefaultExchangeSpecification() { + ExchangeSpecification specification = super.getDefaultExchangeSpecification(); + specification.setSslUri(Config.V4_URL); + return specification; + } } diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/Config.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/Config.java index 061d5b1a360..ea65f5802af 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/Config.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/Config.java @@ -9,6 +9,8 @@ public final class Config { + public static final String V4_URL = "wss://api.gateio.ws/ws/v4/"; + public static final String SPOT_ORDERBOOK_CHANNEL = "spot.order_book"; public static final String SPOT_TRADES_CHANNEL = "spot.trades"; public static final String SPOT_TICKERS_CHANNEL = "spot.tickers"; From c29ae9b5858d9dcc17b3edc904b63f73bebd4442 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Fri, 11 Aug 2023 14:00:42 +0200 Subject: [PATCH 074/159] [gateio-streaming] Add clock, IdGenerator, archunit test --- xchange-stream-gateio/pom.xml | 8 +++++ .../gateio/GateioStreamingService.java | 9 ++--- .../xchangestream/gateio/config/Config.java | 34 ++++++++++++------- .../gateio/config/IdGenerator.java | 22 ++++++++++++ .../gateio/ArchitectureTest.java | 27 +++++++++++++++ .../gateio/GateioStreamingServiceTest.java | 4 +-- .../GateioWebSocketNotificationTest.java | 2 +- 7 files changed, 87 insertions(+), 19 deletions(-) create mode 100644 xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/IdGenerator.java create mode 100644 xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/ArchitectureTest.java diff --git a/xchange-stream-gateio/pom.xml b/xchange-stream-gateio/pom.xml index b22a5fa16c2..e7a26931d3d 100644 --- a/xchange-stream-gateio/pom.xml +++ b/xchange-stream-gateio/pom.xml @@ -11,6 +11,7 @@ XChange Gate.io Stream + 1.0.1 3.2.0 @@ -22,6 +23,13 @@ ${version.fasterxml} + + com.tngtech.archunit + archunit-junit5 + ${version.archunit} + test + + org.junit.jupiter junit-jupiter-engine diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingService.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingService.java index f6f391dce93..b9d144656e8 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingService.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingService.java @@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import info.bitrich.xchangestream.gateio.config.Config; +import info.bitrich.xchangestream.gateio.config.IdGenerator; import info.bitrich.xchangestream.gateio.dto.Event; import info.bitrich.xchangestream.gateio.dto.request.GateioWebSocketRequest; import info.bitrich.xchangestream.gateio.dto.request.GateioWebSocketRequest.AuthInfo; @@ -26,7 +27,6 @@ import java.util.concurrent.ConcurrentHashMap; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.ArrayUtils; -import org.apache.commons.lang3.RandomUtils; import org.apache.commons.lang3.Validate; import org.knowm.xchange.currency.CurrencyPair; @@ -37,7 +37,7 @@ public class GateioStreamingService extends NettyStreamingService> subscriptions = new ConcurrentHashMap<>(); - private final ObjectMapper objectMapper = Config.getObjectMapper(); + private final ObjectMapper objectMapper = Config.getInstance().getObjectMapper(); private final String apiKey; @@ -92,11 +92,12 @@ public String getSubscribeMessage(String uniqueChannelName, Object... args) thro private GateioWebSocketRequest getWebSocketRequest(String channelName, Event event, Object... args) { // create request common part + GateioWebSocketRequest request = GateioWebSocketRequest.builder() - .id(RandomUtils.nextLong()) + .id(IdGenerator.getInstance().requestId()) .channel(channelName) .event(event) - .time(Instant.now()) + .time(Instant.now(Config.getInstance().getClock())) .build(); // create channel specific payload diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/Config.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/Config.java index ea65f5802af..b3d60b86bfe 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/Config.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/Config.java @@ -5,8 +5,12 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; +import java.time.Clock; +import java.time.ZoneId; import java.util.List; +import lombok.Data; +@Data public final class Config { public static final String V4_URL = "wss://api.gateio.ws/ws/v4/"; @@ -18,30 +22,36 @@ public final class Config { public static final String SPOT_USER_TRADES_CHANNEL = "spot.usertrades"; public static final List PRIVATE_CHANNELS = List.of(SPOT_BALANCES_CHANNEL, SPOT_USER_TRADES_CHANNEL); - private static final ObjectMapper MAPPER = new ObjectMapper(); public static final String CHANNEL_NAME_DELIMITER = "-"; - static { + private ObjectMapper objectMapper; + private Clock clock; + + private static Config instance = new Config(); + + private Config() { + clock = Clock.tickMillis(ZoneId.systemDefault()); + + objectMapper = new ObjectMapper(); + // by default read and write timetamps as milliseconds - MAPPER.configure(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS, false); - MAPPER.configure(SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS, false); + objectMapper.configure(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS, false); + objectMapper.configure(SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS, false); // don't fail un unknown properties - MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); // don't write nulls - MAPPER.setSerializationInclusion(JsonInclude.Include.NON_NULL); + objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); // enable parsing to Instant - MAPPER.registerModule(new JavaTimeModule()); + objectMapper.registerModule(new JavaTimeModule()); } - private Config() { - } - - public static ObjectMapper getObjectMapper() { - return MAPPER; + public static Config getInstance() { + return instance; } + } diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/IdGenerator.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/IdGenerator.java new file mode 100644 index 00000000000..4be60bf6a8e --- /dev/null +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/IdGenerator.java @@ -0,0 +1,22 @@ +package info.bitrich.xchangestream.gateio.config; + +import org.apache.commons.lang3.RandomUtils; + +public final class IdGenerator { + + private static IdGenerator instance = new IdGenerator(); + + private IdGenerator() { + } + + public static IdGenerator getInstance() { + return instance; + } + + + public Long requestId() { + return RandomUtils.nextLong(); + } +} + + diff --git a/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/ArchitectureTest.java b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/ArchitectureTest.java new file mode 100644 index 00000000000..c986aa46eb7 --- /dev/null +++ b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/ArchitectureTest.java @@ -0,0 +1,27 @@ +package info.bitrich.xchangestream.gateio; + + +import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.noClasses; + +import com.tngtech.archunit.core.domain.JavaClasses; +import com.tngtech.archunit.core.importer.ClassFileImporter; +import com.tngtech.archunit.lang.ArchRule; +import java.time.Instant; +import java.time.LocalDateTime; +import org.junit.jupiter.api.Test; + +public class ArchitectureTest { + + @Test + void use_clock_for_now_timestamps() { + JavaClasses classes = new ClassFileImporter() + .importPackagesOf(GateioStreamingExchange.class); + + ArchRule rule = noClasses() + .should().callMethod(LocalDateTime.class, "now") + .orShould().callMethod(Instant.class, "now") + .because("we want to use variant with clock instead"); + + rule.check(classes); + } +} \ No newline at end of file diff --git a/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingServiceTest.java b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingServiceTest.java index ae9a60aac71..90fafda4af4 100644 --- a/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingServiceTest.java +++ b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingServiceTest.java @@ -12,7 +12,7 @@ public class GateioStreamingServiceTest { GateioStreamingService gateioStreamingService = new GateioStreamingService("", null, null); - ObjectMapper objectMapper = Config.getObjectMapper(); + ObjectMapper objectMapper = Config.getInstance().getObjectMapper(); @Test void channel_name_from_orderbook_update() throws Exception { @@ -52,7 +52,7 @@ void channel_name_from_unsubscribe_event() throws Exception { String actual = gateioStreamingService.getChannelNameFromMessage(notification); assertThat(actual).isEqualTo("spot.trades"); } - + private GateioWebSocketNotification readNotification(String resourceName) throws IOException { return objectMapper.readValue( getClass().getClassLoader().getResourceAsStream(resourceName), diff --git a/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/dto/response/GateioWebSocketNotificationTest.java b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/dto/response/GateioWebSocketNotificationTest.java index e1434071521..cd4feafdab4 100644 --- a/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/dto/response/GateioWebSocketNotificationTest.java +++ b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/dto/response/GateioWebSocketNotificationTest.java @@ -14,7 +14,7 @@ public class GateioWebSocketNotificationTest { - ObjectMapper objectMapper = Config.getObjectMapper(); + ObjectMapper objectMapper = Config.getInstance().getObjectMapper(); @Test void deserialize_trades() throws Exception { From d6efa05fcecbdb85c7b4584f9eed59841087ba75 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Fri, 11 Aug 2023 15:01:11 +0200 Subject: [PATCH 075/159] [gateio-streaming] Add unit tests for Market data --- xchange-stream-gateio/pom.xml | 8 + .../gateio/GateioStreamingAdapters.java | 8 +- .../GateioStreamingMarketDataServiceTest.java | 140 ++++++++++++++++++ .../resources/spot.order_book.update.json | 88 ++++++++++- 4 files changed, 232 insertions(+), 12 deletions(-) create mode 100644 xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingMarketDataServiceTest.java diff --git a/xchange-stream-gateio/pom.xml b/xchange-stream-gateio/pom.xml index e7a26931d3d..85d64568b1c 100644 --- a/xchange-stream-gateio/pom.xml +++ b/xchange-stream-gateio/pom.xml @@ -12,6 +12,7 @@ 1.0.1 + 5.3.1 3.2.0 @@ -49,6 +50,13 @@ ${project.parent.version} + + org.mockito + mockito-junit-jupiter + ${version.mockito} + test + + diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingAdapters.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingAdapters.java index 6bc5d14cdc2..44cc18d1458 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingAdapters.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingAdapters.java @@ -30,7 +30,7 @@ public Ticker toTicker(GateioTickerNotification notification) { TickerDTO tickerDTO = notification.getResult(); return new Ticker.Builder() - .timestamp(Date.from(notification.getTime())) + .timestamp(Date.from(notification.getTimeMs())) .instrument(tickerDTO.getCurrencyPair()) .last(tickerDTO.getLastPrice()) .ask(tickerDTO.getLowestAsk()) @@ -54,7 +54,7 @@ public Trade toTrade(GateioTradeNotification notification) { .originalAmount(tradeDTO.getAmount()) .instrument(tradeDTO.getCurrencyPair()) .price(tradeDTO.getPrice()) - .timestamp(Date.from(tradeDTO.getTime())) + .timestamp(Date.from(tradeDTO.getTimeMs())) .id(String.valueOf(tradeDTO.getId())) .build(); } @@ -69,7 +69,7 @@ public UserTrade toUserTrade(GateioSingleUserTradeNotification notification) { .originalAmount(userTradeDTO.getAmount()) .instrument(userTradeDTO.getCurrencyPair()) .price(userTradeDTO.getPrice()) - .timestamp(Date.from(userTradeDTO.getTime())) + .timestamp(Date.from(userTradeDTO.getTimeMs())) .id(String.valueOf(userTradeDTO.getId())) .orderId(String.valueOf(userTradeDTO.getOrderId())) .feeAmount(userTradeDTO.getFee()) @@ -88,7 +88,7 @@ public Balance toBalance(GateioSingleSpotBalanceNotification notification) { .total(balanceDTO.getTotal()) .available(balanceDTO.getAvailable()) .frozen(balanceDTO.getFreeze()) - .timestamp(Date.from(balanceDTO.getTime())) + .timestamp(Date.from(balanceDTO.getTimeMs())) .build(); } diff --git a/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingMarketDataServiceTest.java b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingMarketDataServiceTest.java new file mode 100644 index 00000000000..6a86adece71 --- /dev/null +++ b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingMarketDataServiceTest.java @@ -0,0 +1,140 @@ +package info.bitrich.xchangestream.gateio; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.when; + +import com.fasterxml.jackson.databind.ObjectMapper; +import info.bitrich.xchangestream.gateio.config.Config; +import info.bitrich.xchangestream.gateio.dto.response.GateioWebSocketNotification; +import io.reactivex.Observable; +import io.reactivex.observers.TestObserver; +import java.io.IOException; +import java.math.BigDecimal; +import java.time.Duration; +import java.time.Instant; +import java.util.Date; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +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.marketdata.Trade; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +@ExtendWith(MockitoExtension.class) +class GateioStreamingMarketDataServiceTest { + + @Mock + GateioStreamingService gateioStreamingService; + GateioStreamingMarketDataService gateioStreamingMarketDataService; + + ObjectMapper objectMapper = Config.getInstance().getObjectMapper(); + + @BeforeEach + public void setup() { + gateioStreamingMarketDataService = new GateioStreamingMarketDataService(gateioStreamingService); + } + + + @Test + void order_book() throws Exception { + GateioWebSocketNotification notification = readNotification("spot.order_book.update.json"); + when(gateioStreamingService.subscribeChannel(eq("spot.order_book"), eq(CurrencyPair.BTC_USDT), eq(10), eq(Duration.ofMillis(100)))) + .thenReturn(Observable.just(notification)); + + Observable observable = gateioStreamingMarketDataService + .getOrderBook(CurrencyPair.BTC_USDT, 10, Duration.ofMillis(100)); + + TestObserver testObserver = observable.test(); + + OrderBook actual = testObserver + .assertSubscribed() + .awaitCount(1) + .assertNoTimeout() + .values().get(0); + + testObserver.dispose(); + + assertThat(actual.getTimeStamp()).isEqualTo(Date.from(Instant.ofEpochMilli(1691757151367L))); + assertThat(actual.getBids()).hasSize(10); + assertThat(actual.getAsks()).hasSize(10); + } + + + @Test + void ticker() throws Exception { + GateioWebSocketNotification notification = readNotification("spot.ticker.update.json"); + when(gateioStreamingService.subscribeChannel(eq("spot.tickers"), eq(CurrencyPair.BTC_USDT))) + .thenReturn(Observable.just(notification)); + + Observable observable = gateioStreamingMarketDataService.getTicker(CurrencyPair.BTC_USDT); + + TestObserver testObserver = observable.test(); + + Ticker actual = testObserver + .assertSubscribed() + .awaitCount(1) + .assertNoTimeout() + .values().get(0); + + testObserver.dispose(); + + Ticker expected = new Ticker.Builder() + .instrument(CurrencyPair.BTC_USDT) + .timestamp(Date.from(Instant.ofEpochMilli(1691620566926L))) + .ask(new BigDecimal("29573.7")) + .bid(new BigDecimal("29573.6")) + .high(new BigDecimal("30232.8")) + .low(new BigDecimal("29176.1")) + .last(new BigDecimal("29573.7")) + .percentageChange(new BigDecimal("-0.6601")) + .quoteVolume(new BigDecimal("171784719.492586746")) + .volume(new BigDecimal("5777.7777606776")) + .build(); + + assertThat(actual).usingRecursiveComparison().isEqualTo(expected); + } + + @Test + void trades() throws Exception { + GateioWebSocketNotification notification = readNotification("spot.trades.update.json"); + when(gateioStreamingService.subscribeChannel(eq("spot.trades"), eq(CurrencyPair.BTC_USDT))) + .thenReturn(Observable.just(notification)); + + Observable observable = gateioStreamingMarketDataService.getTrades(CurrencyPair.BTC_USDT); + + TestObserver testObserver = observable.test(); + + Trade actual = testObserver + .assertSubscribed() + .awaitCount(1) + .assertNoTimeout() + .values().get(0); + + testObserver.dispose(); + + Trade expected = new Trade.Builder() + .instrument(CurrencyPair.BTC_USDT) + .id("6064666343") + .originalAmount(new BigDecimal("0.0003009")) + .price(new BigDecimal("29573.7")) + .timestamp(Date.from(Instant.ofEpochMilli(1691620568789L))) + .type(OrderType.BID) + .build(); + + assertThat(actual).usingRecursiveComparison().isEqualTo(expected); + } + + + private GateioWebSocketNotification readNotification(String resourceName) throws IOException { + return objectMapper.readValue( + getClass().getClassLoader().getResourceAsStream(resourceName), + GateioWebSocketNotification.class + ); + } + +} \ No newline at end of file diff --git a/xchange-stream-gateio/src/test/resources/spot.order_book.update.json b/xchange-stream-gateio/src/test/resources/spot.order_book.update.json index 6bad4e38425..87a391a2c5a 100644 --- a/xchange-stream-gateio/src/test/resources/spot.order_book.update.json +++ b/xchange-stream-gateio/src/test/resources/spot.order_book.update.json @@ -1,22 +1,94 @@ { - "time": 1691620594, - "time_ms": 1691620594125, + "time": 1691757151, + "time_ms": 1691757151420, "channel": "spot.order_book", "event": "update", "result": { - "t": 1691620594027, - "lastUpdateId": 14596255957, + "t": 1691757151367, + "lastUpdateId": 14604776153, "s": "BTC_USDT", "bids": [ [ - "29573.6", - "1.69992" + "29426.3", + "1.12547" + ], + [ + "29424.5", + "1.15" + ], + [ + "29424.4", + "0.00074" + ], + [ + "29424.2", + "0.01371" + ], + [ + "29424.1", + "0.036" + ], + [ + "29423.8", + "1.15" + ], + [ + "29423.7", + "0.0434" + ], + [ + "29422.5", + "0.0331" + ], + [ + "29421.4", + "1" + ], + [ + "29421.2", + "0.27187" ] ], "asks": [ [ - "29573.7", - "3.29051717" + "29426.4", + "2.42147" + ], + [ + "29426.5", + "1.15" + ], + [ + "29426.6", + "0.03" + ], + [ + "29426.7", + "2.47262" + ], + [ + "29426.8", + "1" + ], + [ + "29427.8", + "0.00037" + ], + [ + "29427.9", + "0.0005" + ], + [ + "29428", + "0.00012" + ], + [ + "29428.9", + "0.00051" + ], + [ + "29429", + "0.00025" ] ] } From 7d22acf6fe45d0f74b2801712c11a4415be89c1f Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Fri, 11 Aug 2023 15:28:38 +0200 Subject: [PATCH 076/159] [gateio-streaming] Code cleanup --- .../xchangestream/gateio/GateioStreamingAdapters.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingAdapters.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingAdapters.java index 44cc18d1458..07f0bc51358 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingAdapters.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingAdapters.java @@ -12,7 +12,6 @@ import info.bitrich.xchangestream.gateio.dto.response.usertrade.UserTradeDTO; import java.util.Date; import java.util.stream.Stream; -import lombok.SneakyThrows; import lombok.experimental.UtilityClass; import org.knowm.xchange.dto.Order.OrderType; import org.knowm.xchange.dto.account.Balance; @@ -25,7 +24,6 @@ @UtilityClass public class GateioStreamingAdapters { - @SneakyThrows public Ticker toTicker(GateioTickerNotification notification) { TickerDTO tickerDTO = notification.getResult(); @@ -44,7 +42,6 @@ public Ticker toTicker(GateioTickerNotification notification) { } - @SneakyThrows public Trade toTrade(GateioTradeNotification notification) { TradeDTO tradeDTO = notification.getResult(); @@ -60,7 +57,6 @@ public Trade toTrade(GateioTradeNotification notification) { } - @SneakyThrows public UserTrade toUserTrade(GateioSingleUserTradeNotification notification) { UserTradeDTO userTradeDTO = notification.getResult(); @@ -79,7 +75,6 @@ public UserTrade toUserTrade(GateioSingleUserTradeNotification notification) { } - @SneakyThrows public Balance toBalance(GateioSingleSpotBalanceNotification notification) { BalanceDTO balanceDTO = notification.getResult(); @@ -93,7 +88,6 @@ public Balance toBalance(GateioSingleSpotBalanceNotification notification) { } - @SneakyThrows public OrderBook toOrderBook(GateioOrderBookNotification notification) { OrderBookDTO orderBookDTO = notification.getResult(); From 8341dd1654ff1c4bbe7d938ec50af82cf73f6f12 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Fri, 11 Aug 2023 15:28:48 +0200 Subject: [PATCH 077/159] [gateio-streaming] Add unit tests --- .../GateioStreamingAccountServiceTest.java | 82 +++++++++++++++++ .../GateioStreamingTradeServiceTest.java | 88 +++++++++++++++++++ 2 files changed, 170 insertions(+) create mode 100644 xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingAccountServiceTest.java create mode 100644 xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingTradeServiceTest.java diff --git a/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingAccountServiceTest.java b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingAccountServiceTest.java new file mode 100644 index 00000000000..14ad5b2f73f --- /dev/null +++ b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingAccountServiceTest.java @@ -0,0 +1,82 @@ +package info.bitrich.xchangestream.gateio; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.when; + +import com.fasterxml.jackson.databind.ObjectMapper; +import info.bitrich.xchangestream.gateio.config.Config; +import info.bitrich.xchangestream.gateio.dto.response.GateioWebSocketNotification; +import info.bitrich.xchangestream.gateio.dto.response.balance.GateioMultipleSpotBalanceNotification; +import io.reactivex.Observable; +import io.reactivex.observers.TestObserver; +import java.io.IOException; +import java.math.BigDecimal; +import java.time.Instant; +import java.util.Date; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.knowm.xchange.currency.Currency; +import org.knowm.xchange.dto.account.Balance; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +@ExtendWith(MockitoExtension.class) +class GateioStreamingAccountServiceTest { + + @Mock + GateioStreamingService gateioStreamingService; + GateioStreamingAccountService gateioStreamingAccountService; + + ObjectMapper objectMapper = Config.getInstance().getObjectMapper(); + + + @BeforeEach + public void setup() { + gateioStreamingAccountService = new GateioStreamingAccountService(gateioStreamingService); + } + + + @Test + void spot_balances() throws Exception { + GateioWebSocketNotification multipleNotification = readNotification("spot.balance.update.json"); + assertThat(multipleNotification).isInstanceOf(GateioMultipleSpotBalanceNotification.class); + GateioWebSocketNotification notification = ((GateioMultipleSpotBalanceNotification) multipleNotification).toSingleNotifications().get(0); + + when(gateioStreamingService.subscribeChannel(eq("spot.balances"))) + .thenReturn(Observable.just(notification)); + + Observable observable = gateioStreamingAccountService.getBalanceChanges(Currency.USDT); + + TestObserver testObserver = observable.test(); + + Balance actual = testObserver + .assertSubscribed() + .awaitCount(1) + .assertNoTimeout() + .values().get(0); + + testObserver.dispose(); + + Balance expected = Balance.builder() + .available(new BigDecimal("42.06583427604872431142")) + .currency(Currency.USDT) + .frozen(BigDecimal.ONE) + .timestamp(Date.from(Instant.ofEpochMilli(1691707273890L))) + .total(new BigDecimal("43.06583427604872431142")) + .build(); + + assertThat(actual).usingRecursiveComparison().isEqualTo(expected); + } + + + private GateioWebSocketNotification readNotification(String resourceName) throws IOException { + return objectMapper.readValue( + getClass().getClassLoader().getResourceAsStream(resourceName), + GateioWebSocketNotification.class + ); + } + + +} \ No newline at end of file diff --git a/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingTradeServiceTest.java b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingTradeServiceTest.java new file mode 100644 index 00000000000..479cd8083e3 --- /dev/null +++ b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingTradeServiceTest.java @@ -0,0 +1,88 @@ +package info.bitrich.xchangestream.gateio; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.when; + +import com.fasterxml.jackson.databind.ObjectMapper; +import info.bitrich.xchangestream.gateio.config.Config; +import info.bitrich.xchangestream.gateio.dto.response.GateioWebSocketNotification; +import info.bitrich.xchangestream.gateio.dto.response.usertrade.GateioMultipleUserTradeNotification; +import io.reactivex.Observable; +import io.reactivex.observers.TestObserver; +import java.io.IOException; +import java.math.BigDecimal; +import java.time.Instant; +import java.util.Date; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.knowm.xchange.currency.Currency; +import org.knowm.xchange.currency.CurrencyPair; +import org.knowm.xchange.dto.Order.OrderType; +import org.knowm.xchange.dto.trade.UserTrade; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +@ExtendWith(MockitoExtension.class) +class GateioStreamingTradeServiceTest { + + @Mock + GateioStreamingService gateioStreamingService; + GateioStreamingTradeService gateioStreamingTradeService; + + ObjectMapper objectMapper = Config.getInstance().getObjectMapper(); + + @BeforeEach + public void setup() { + gateioStreamingTradeService = new GateioStreamingTradeService(gateioStreamingService); + } + + + @Test + void user_trades_btc() throws Exception { + GateioWebSocketNotification multipleNotification = readNotification("spot.usertrades.update.json"); + assertThat(multipleNotification).isInstanceOf(GateioMultipleUserTradeNotification.class); + GateioWebSocketNotification notification = ((GateioMultipleUserTradeNotification) multipleNotification).toSingleNotifications().get(0); + + when(gateioStreamingService.subscribeChannel(eq("spot.usertrades"), eq(CurrencyPair.BTC_USDT))) + .thenReturn(Observable.just(notification)); + + Observable observable = gateioStreamingTradeService.getUserTrades(CurrencyPair.BTC_USDT); + + TestObserver testObserver = observable.test(); + + UserTrade actual = testObserver + .assertSubscribed() + .awaitCount(1) + .assertNoTimeout() + .values().get(0); + + testObserver.dispose(); + + UserTrade expected = new UserTrade.Builder() + .instrument(CurrencyPair.BTC_USDT) + .id("6068323582") + .orderId("381004078014") + .orderUserReference("3") + .originalAmount(new BigDecimal("0.00003")) + .feeAmount(new BigDecimal("0.00000006")) + .feeCurrency(Currency.BTC) + .price(new BigDecimal("29441.1")) + .timestamp(Date.from(Instant.ofEpochMilli(1691692159330L))) + .type(OrderType.BID) + .build(); + + assertThat(actual).usingRecursiveComparison().isEqualTo(expected); + } + + + private GateioWebSocketNotification readNotification(String resourceName) throws IOException { + return objectMapper.readValue( + getClass().getClassLoader().getResourceAsStream(resourceName), + GateioWebSocketNotification.class + ); + } + + +} \ No newline at end of file From 00296b86f68d76dfa44a250c16b5497fc14a551b Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Fri, 11 Aug 2023 17:34:20 +0200 Subject: [PATCH 078/159] [gateio-v4] Add test for digest --- .../gateio/service/GateioV4DigestTest.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioV4DigestTest.java diff --git a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioV4DigestTest.java b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioV4DigestTest.java new file mode 100644 index 00000000000..7f8cacff37c --- /dev/null +++ b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioV4DigestTest.java @@ -0,0 +1,35 @@ +package org.knowm.xchange.gateio.service; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.when; + +import java.util.Map; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import si.mazi.rescu.RestInvocation; + +@ExtendWith(MockitoExtension.class) +class GateioV4DigestTest { + + @Mock + RestInvocation restInvocation; + + @Test + void signature() { + GateioV4Digest gateioV4Digest = GateioV4Digest.createInstance("b"); + + when(restInvocation.getHttpMethod()).thenReturn("POST"); + when(restInvocation.getPath()).thenReturn("a"); + when(restInvocation.getQueryString()).thenReturn("?b=c"); + when(restInvocation.getRequestBody()).thenReturn("{a:1}"); + when(restInvocation.getHttpHeadersFromParams()).thenReturn(Map.of("Timestamp", "1691707273890")); + + var actual = gateioV4Digest.digestParams(restInvocation); + var expected = "de31e211a60623ba2c41e65a3c21e550400ffccfef55578173e09f2b34cf46b426c587f01b4c12474608dc856b1ba226a71004f7989603236c885c23275d5577"; + + assertThat(actual).isEqualTo(expected); + } + +} \ No newline at end of file From 6ac9d2f6d42ca8d55277cd7fccfbea856a8a3749 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Fri, 11 Aug 2023 17:35:00 +0200 Subject: [PATCH 079/159] [gateio-streaming] Add getting currency/currencypairs --- xchange-gateio-v4/pom.xml | 8 ++++ .../service/GateioMarketDataService.java | 42 ++++++++++++++++--- .../service/GateioMarketDataServiceRaw.java | 13 +++--- .../GateioMarketDataServiceRawTest.java | 17 ++++---- .../service/GateioMarketDataServiceTest.java | 34 +++++++++++---- 5 files changed, 86 insertions(+), 28 deletions(-) diff --git a/xchange-gateio-v4/pom.xml b/xchange-gateio-v4/pom.xml index 9fa0a43d53d..f5c8f899aa0 100644 --- a/xchange-gateio-v4/pom.xml +++ b/xchange-gateio-v4/pom.xml @@ -23,6 +23,7 @@ + 5.3.1 3.2.0 @@ -53,6 +54,13 @@ ${project.version} + + org.mockito + mockito-junit-jupiter + ${version.mockito} + test + + 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 b12a77103b1..6b7bc678a22 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,12 @@ package org.knowm.xchange.gateio.service; +import java.io.IOException; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.Validate; +import org.knowm.xchange.currency.Currency; import org.knowm.xchange.currency.CurrencyPair; import org.knowm.xchange.dto.marketdata.OrderBook; import org.knowm.xchange.dto.marketdata.Ticker; @@ -9,6 +15,7 @@ import org.knowm.xchange.gateio.GateioErrorAdapter; import org.knowm.xchange.gateio.GateioExchange; import org.knowm.xchange.gateio.dto.GateioException; +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.GateioTicker; @@ -16,11 +23,6 @@ import org.knowm.xchange.service.marketdata.MarketDataService; import org.knowm.xchange.service.marketdata.params.Params; -import java.io.IOException; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - public class GateioMarketDataService extends GateioMarketDataServiceRaw implements MarketDataService { public GateioMarketDataService(GateioExchange exchange) { @@ -72,6 +74,36 @@ public OrderBook getOrderBook(Instrument instrument, Object... args) throws IOEx } + public List getCurrencies() throws IOException { + try { + List currencyInfos = getGateioCurrencyInfos(); + return currencyInfos.stream() + .filter(gateioCurrencyInfo -> !gateioCurrencyInfo.getDelisted()) + .map(o -> StringUtils.removeEnd(o.getCurrency(), "_" + o.getChain())) + .distinct() + .map(Currency::getInstance) + .collect(Collectors.toList()); + } catch (GateioException e) { + throw GateioErrorAdapter.adapt(e); + } + } + + + public List getCurrencyPairs() throws IOException { + try { + List metadata = getCurrencyPairDetails(); + + return metadata.stream() + .filter(details -> "tradable".equals(details.getTradeStatus())) + .map(details -> new CurrencyPair(details.getAsset(), details.getQuote())) + .collect(Collectors.toList()); + } + catch (GateioException e) { + throw GateioErrorAdapter.adapt(e); + } + } + + public Map getMetaDataByInstrument() throws IOException { try { List metadata = getCurrencyPairDetails(); 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 5c8bcfc19b5..fbf38b5f7ee 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 @@ -1,14 +1,17 @@ package org.knowm.xchange.gateio.service; +import java.io.IOException; +import java.util.List; import org.knowm.xchange.currency.Currency; import org.knowm.xchange.gateio.GateioAdapters; import org.knowm.xchange.gateio.GateioExchange; -import org.knowm.xchange.gateio.dto.marketdata.*; +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.GateioTicker; import org.knowm.xchange.instrument.Instrument; -import java.io.IOException; -import java.util.List; - public class GateioMarketDataServiceRaw extends GateioBaseService { public GateioMarketDataServiceRaw(GateioExchange exchange) { @@ -21,7 +24,7 @@ public List getGateioTickers(Instrument instrument) throws IOExcep } - public List getCurrencies() throws IOException { + public List getGateioCurrencyInfos() throws IOException { return gateio.getCurrencies(); } diff --git a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioMarketDataServiceRawTest.java b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioMarketDataServiceRawTest.java index d6132ff65f1..e53f6bbf937 100644 --- a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioMarketDataServiceRawTest.java +++ b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioMarketDataServiceRawTest.java @@ -1,5 +1,12 @@ package org.knowm.xchange.gateio.service; +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.IOException; +import java.math.BigDecimal; +import java.time.Instant; +import java.util.ArrayList; +import java.util.List; import org.junit.jupiter.api.Test; import org.knowm.xchange.currency.Currency; import org.knowm.xchange.currency.CurrencyPair; @@ -10,14 +17,6 @@ import org.knowm.xchange.gateio.dto.marketdata.GateioOrderBook; import org.knowm.xchange.gateio.dto.marketdata.GateioOrderBook.PriceSizeEntry; -import java.io.IOException; -import java.math.BigDecimal; -import java.time.Instant; -import java.util.ArrayList; -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; - public class GateioMarketDataServiceRawTest extends GateioExchangeWiremock { GateioMarketDataServiceRaw gateioMarketDataServiceRaw = (GateioMarketDataServiceRaw) exchange.getMarketDataService(); @@ -25,7 +24,7 @@ public class GateioMarketDataServiceRawTest extends GateioExchangeWiremock { @Test public void getCurrencies_valid() throws IOException { - List actual = gateioMarketDataServiceRaw.getCurrencies(); + List actual = gateioMarketDataServiceRaw.getGateioCurrencyInfos(); assertThat(actual).hasSize(5); diff --git a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioMarketDataServiceTest.java b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioMarketDataServiceTest.java index d14225db360..b7b168b732e 100644 --- a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioMarketDataServiceTest.java +++ b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioMarketDataServiceTest.java @@ -1,12 +1,6 @@ package org.knowm.xchange.gateio.service; -import org.junit.jupiter.api.Test; -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.trade.LimitOrder; -import org.knowm.xchange.gateio.GateioExchangeWiremock; +import static org.assertj.core.api.Assertions.assertThat; import java.io.IOException; import java.math.BigDecimal; @@ -14,8 +8,14 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; +import org.junit.jupiter.api.Test; +import org.knowm.xchange.currency.Currency; +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.trade.LimitOrder; +import org.knowm.xchange.gateio.GateioExchangeWiremock; public class GateioMarketDataServiceTest extends GateioExchangeWiremock { @@ -84,4 +84,20 @@ void getTickers_valid() throws IOException { } + @Test + void getCurrencies_valid() throws IOException { + var actual = gateioMarketDataService.getCurrencies(); + + assertThat(actual).containsOnly(Currency.BTC, Currency.ETH); + } + + + @Test + void getCurrencyPairs_valid() throws IOException { + var actual = gateioMarketDataService.getCurrencyPairs(); + + assertThat(actual).containsOnly(CurrencyPair.BTC_USDT, CurrencyPair.ETH_USDT, new CurrencyPair("CHZ/USDT")); + } + + } From 58c1685a6f48b5a2a678ce4dd89e46e8b34a7242 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Sat, 12 Aug 2023 00:10:53 +0200 Subject: [PATCH 080/159] [gateio-v4] Implement user trades --- .../knowm/xchange/gateio/GateioAdapters.java | 18 ++++++ .../xchange/gateio/GateioV4Authenticated.java | 17 +++++ .../config/DoubleToInstantConverter.java | 15 +++++ .../gateio/dto/trade/GateioUserTrade.java | 63 +++++++++++++++++++ .../gateio/service/GateioTradeService.java | 24 +++++-- .../gateio/service/GateioTradeServiceRaw.java | 28 +++++++++ .../params/GateioTradeHistoryParams.java | 30 +++++++++ .../service/GateioTradeServiceTest.java | 36 +++++++++++ .../__files/api_v4_spot_my_trades.json | 34 ++++++++++ .../mappings/api_v4_spot_my_trades.json | 15 +++++ .../src/test/resources/rest/spot.http | 23 +++++++ 11 files changed, 299 insertions(+), 4 deletions(-) create mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/DoubleToInstantConverter.java create mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/GateioUserTrade.java create mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/params/GateioTradeHistoryParams.java create mode 100644 xchange-gateio-v4/src/test/resources/__files/api_v4_spot_my_trades.json create mode 100644 xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_my_trades.json create mode 100644 xchange-gateio-v4/src/test/resources/rest/spot.http diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java index 678ce59585e..874a9157f60 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java @@ -15,11 +15,13 @@ import org.knowm.xchange.dto.meta.InstrumentMetaData; import org.knowm.xchange.dto.trade.LimitOrder; import org.knowm.xchange.dto.trade.MarketOrder; +import org.knowm.xchange.dto.trade.UserTrade; import org.knowm.xchange.gateio.dto.account.GateioOrder; import org.knowm.xchange.gateio.dto.account.GateioWithdrawalRequest; import org.knowm.xchange.gateio.dto.marketdata.GateioCurrencyPairDetails; import org.knowm.xchange.gateio.dto.marketdata.GateioOrderBook; import org.knowm.xchange.gateio.dto.marketdata.GateioTicker; +import org.knowm.xchange.gateio.dto.trade.GateioUserTrade; import org.knowm.xchange.gateio.service.params.DefaultGateioWithdrawFundsParams; import org.knowm.xchange.instrument.Instrument; @@ -161,6 +163,22 @@ public Order toOrder(GateioOrder gateioOrder) { } + public UserTrade toUserTrade(GateioUserTrade gateioUserTrade) { + return UserTrade.builder() + .id(String.valueOf(gateioUserTrade.getId())) + .orderId(String.valueOf(gateioUserTrade.getOrderId())) + .feeAmount(gateioUserTrade.getFee()) + .feeCurrency(gateioUserTrade.getFeeCurrency()) + .orderUserReference(gateioUserTrade.getRemark()) + .type(toOrderType(gateioUserTrade.getSide())) + .instrument(toInstrument(gateioUserTrade.getCurrencyPair())) + .price(gateioUserTrade.getPrice()) + .timestamp(Date.from(gateioUserTrade.getTimeMs())) + .originalAmount(gateioUserTrade.getAmount()) + .build(); + } + + public String toString(OrderType orderType) { switch (orderType) { case BID: diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java index fc77308690e..2ecb3ad5895 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java @@ -20,6 +20,7 @@ import org.knowm.xchange.gateio.dto.account.GateioWithdrawStatus; import org.knowm.xchange.gateio.dto.account.GateioWithdrawalRecord; import org.knowm.xchange.gateio.dto.account.GateioWithdrawalRequest; +import org.knowm.xchange.gateio.dto.trade.GateioUserTrade; import si.mazi.rescu.ParamsDigest; import si.mazi.rescu.SynchronizedValueFactory; @@ -101,6 +102,22 @@ GateioOrder createOrder( ) throws IOException, GateioException; + @GET + @Path("spot/my_trades") + List getTradingHistory( + @HeaderParam("KEY") String apiKey, + @HeaderParam("Timestamp") SynchronizedValueFactory timestamp, + @HeaderParam("SIGN") ParamsDigest signer, + @QueryParam("currency_pair") String currencyPair, + @QueryParam("limit") Integer pageLength, + @QueryParam("page") Integer pageNumber, + @QueryParam("order_id") String orderId, + @QueryParam("account") String account, + @QueryParam("from") Long from, + @QueryParam("to") Long to + ) throws IOException, GateioException; + + @GET @Path("wallet/saved_address") List getSavedAddresses( diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/DoubleToInstantConverter.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/DoubleToInstantConverter.java new file mode 100644 index 00000000000..8e2bd855bc9 --- /dev/null +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/DoubleToInstantConverter.java @@ -0,0 +1,15 @@ +package org.knowm.xchange.gateio.config; + +import com.fasterxml.jackson.databind.util.StdConverter; +import java.time.Instant; + +/** + * Converts timestamp as double in milliseconds to {@code Instant} + */ +public class DoubleToInstantConverter extends StdConverter { + + @Override + public Instant convert(final Double value) { + return Instant.ofEpochMilli(value.longValue()); + } +} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/GateioUserTrade.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/GateioUserTrade.java new file mode 100644 index 00000000000..d5b80c76d53 --- /dev/null +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/GateioUserTrade.java @@ -0,0 +1,63 @@ +package org.knowm.xchange.gateio.dto.trade; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import java.math.BigDecimal; +import java.time.Instant; +import lombok.Builder; +import lombok.Data; +import lombok.extern.jackson.Jacksonized; +import org.knowm.xchange.currency.Currency; +import org.knowm.xchange.gateio.config.DoubleToInstantConverter; +import org.knowm.xchange.gateio.config.TimestampSecondsToInstantConverter; + +@Data +@Builder +@Jacksonized +public class GateioUserTrade { + + @JsonProperty("id") + Long id; + + @JsonProperty("create_time") + @JsonDeserialize(converter = TimestampSecondsToInstantConverter.class) + private Instant time; + + @JsonProperty("create_time_ms") + @JsonDeserialize(converter = DoubleToInstantConverter.class) + private Instant timeMs; + + @JsonProperty("currency_pair") + String currencyPair; + + @JsonProperty("side") + private String side; + + @JsonProperty("role") + String role; + + @JsonProperty("amount") + BigDecimal amount; + + @JsonProperty("price") + BigDecimal price; + + @JsonProperty("order_id") + Long orderId; + + @JsonProperty("fee") + BigDecimal fee; + + @JsonProperty("fee_currency") + Currency feeCurrency; + + @JsonProperty("point_fee") + BigDecimal pointFee; + + @JsonProperty("gt_fee") + BigDecimal gtFee; + + @JsonProperty("amend_text") + String remark; + +} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeService.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeService.java index 8bc374a97e3..904e9da03df 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeService.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeService.java @@ -3,22 +3,26 @@ import java.io.IOException; import java.util.Collection; import java.util.List; +import java.util.stream.Collectors; import org.apache.commons.lang3.Validate; import org.knowm.xchange.dto.Order; import org.knowm.xchange.dto.Order.OrderStatus; +import org.knowm.xchange.dto.marketdata.Trades.TradeSortType; import org.knowm.xchange.dto.trade.LimitOrder; import org.knowm.xchange.dto.trade.MarketOrder; +import org.knowm.xchange.dto.trade.UserTrade; +import org.knowm.xchange.dto.trade.UserTrades; import org.knowm.xchange.gateio.GateioAdapters; import org.knowm.xchange.gateio.GateioErrorAdapter; import org.knowm.xchange.gateio.GateioExchange; import org.knowm.xchange.gateio.dto.GateioException; import org.knowm.xchange.gateio.dto.account.GateioOrder; +import org.knowm.xchange.gateio.service.params.GateioTradeHistoryParams; import org.knowm.xchange.instrument.Instrument; import org.knowm.xchange.service.trade.TradeService; import org.knowm.xchange.service.trade.params.CancelOrderParams; import org.knowm.xchange.service.trade.params.DefaultCancelOrderByInstrumentAndIdParams; -import org.knowm.xchange.service.trade.params.DefaultTradeHistoryParamCurrencyPair; -import org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair; +import org.knowm.xchange.service.trade.params.TradeHistoryParams; import org.knowm.xchange.service.trade.params.orders.OrderQueryParamInstrument; import org.knowm.xchange.service.trade.params.orders.OrderQueryParams; @@ -96,6 +100,18 @@ public boolean cancelOrder(CancelOrderParams orderParams) throws IOException { } } + @Override + public UserTrades getTradeHistory(TradeHistoryParams params) throws IOException { + try { + List userTradeList = getGateioUserTrades(params).stream() + .map(GateioAdapters::toUserTrade) + .collect(Collectors.toList()); + return new UserTrades(userTradeList, TradeSortType.SortByID); + } + catch (GateioException e) { + throw GateioErrorAdapter.adapt(e); + } + } @Override public Class[] getRequiredCancelOrderParamClasses() { @@ -104,8 +120,8 @@ public Class[] getRequiredCancelOrderParamClasses() { @Override - public TradeHistoryParamCurrencyPair createTradeHistoryParams() { - return new DefaultTradeHistoryParamCurrencyPair(); + public TradeHistoryParams createTradeHistoryParams() { + return GateioTradeHistoryParams.builder().build(); } diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeServiceRaw.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeServiceRaw.java index 5414c6474d2..560c75a165e 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeServiceRaw.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeServiceRaw.java @@ -4,11 +4,19 @@ import java.util.List; import java.util.Set; import org.apache.commons.lang3.Validate; +import org.knowm.xchange.currency.CurrencyPair; import org.knowm.xchange.dto.Order.OrderStatus; import org.knowm.xchange.gateio.GateioAdapters; import org.knowm.xchange.gateio.GateioExchange; import org.knowm.xchange.gateio.dto.account.GateioOrder; +import org.knowm.xchange.gateio.dto.trade.GateioUserTrade; import org.knowm.xchange.instrument.Instrument; +import org.knowm.xchange.service.trade.params.CurrencyPairParam; +import org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair; +import org.knowm.xchange.service.trade.params.TradeHistoryParamPaging; +import org.knowm.xchange.service.trade.params.TradeHistoryParamTransactionId; +import org.knowm.xchange.service.trade.params.TradeHistoryParams; +import org.knowm.xchange.service.trade.params.TradeHistoryParamsTimeSpan; public class GateioTradeServiceRaw extends GateioBaseService { @@ -31,6 +39,26 @@ public List listOrders(Instrument instrument, OrderStatus orderStat } + public List getGateioUserTrades(TradeHistoryParams params) throws IOException { + // get arguments + CurrencyPair currencyPair = params instanceof TradeHistoryParamCurrencyPair ? ((CurrencyPairParam) params).getCurrencyPair() : null; + Integer pageLength = params instanceof TradeHistoryParamPaging ? ((TradeHistoryParamPaging) params).getPageLength() : null; + Integer pageNumber = params instanceof TradeHistoryParamPaging ? ((TradeHistoryParamPaging) params).getPageNumber() : null; + String orderId = params instanceof TradeHistoryParamTransactionId ? ((TradeHistoryParamTransactionId) params).getTransactionId() : null; + Long from = null; + Long to = null; + if (params instanceof TradeHistoryParamsTimeSpan) { + TradeHistoryParamsTimeSpan paramsTimeSpan = ((TradeHistoryParamsTimeSpan) params); + from = paramsTimeSpan.getStartTime() != null ? paramsTimeSpan.getStartTime().getTime() / 1000 : null; + to = paramsTimeSpan.getEndTime() != null ? paramsTimeSpan.getEndTime().getTime() / 1000 : null; + } + + return gateioV4Authenticated.getTradingHistory(apiKey, exchange.getNonceFactory(), + gateioV4ParamsDigest, GateioAdapters.toString(currencyPair), + pageLength, pageNumber, orderId, null, from, to); + } + + public GateioOrder createOrder(GateioOrder gateioOrder) throws IOException { return gateioV4Authenticated.createOrder(apiKey, exchange.getNonceFactory(), gateioV4ParamsDigest, gateioOrder); } diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/params/GateioTradeHistoryParams.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/params/GateioTradeHistoryParams.java new file mode 100644 index 00000000000..d0f708c4b46 --- /dev/null +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/params/GateioTradeHistoryParams.java @@ -0,0 +1,30 @@ +package org.knowm.xchange.gateio.service.params; + +import java.util.Date; +import lombok.Data; +import lombok.experimental.SuperBuilder; +import org.knowm.xchange.currency.CurrencyPair; +import org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair; +import org.knowm.xchange.service.trade.params.TradeHistoryParamPaging; +import org.knowm.xchange.service.trade.params.TradeHistoryParamTransactionId; +import org.knowm.xchange.service.trade.params.TradeHistoryParamsTimeSpan; + +@Data +@SuperBuilder +public class GateioTradeHistoryParams implements TradeHistoryParamCurrencyPair, + TradeHistoryParamPaging, TradeHistoryParamTransactionId, TradeHistoryParamsTimeSpan { + + private CurrencyPair currencyPair; + + private Integer pageLength; + + private Integer pageNumber; + + private String transactionId; + + private Date startTime; + + private Date endTime; + + +} diff --git a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioTradeServiceTest.java b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioTradeServiceTest.java index c3314622b45..fe5968f28ea 100644 --- a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioTradeServiceTest.java +++ b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioTradeServiceTest.java @@ -8,13 +8,17 @@ import java.time.Instant; import java.util.Date; import org.junit.jupiter.api.Test; +import org.knowm.xchange.currency.Currency; import org.knowm.xchange.currency.CurrencyPair; import org.knowm.xchange.dto.Order.OrderStatus; import org.knowm.xchange.dto.Order.OrderType; import org.knowm.xchange.dto.trade.LimitOrder; import org.knowm.xchange.dto.trade.MarketOrder; +import org.knowm.xchange.dto.trade.UserTrade; +import org.knowm.xchange.dto.trade.UserTrades; import org.knowm.xchange.exceptions.FundsExceededException; import org.knowm.xchange.gateio.GateioExchangeWiremock; +import org.knowm.xchange.gateio.service.params.GateioTradeHistoryParams; import org.knowm.xchange.service.trade.params.DefaultCancelOrderByInstrumentAndIdParams; import org.knowm.xchange.service.trade.params.orders.DefaultQueryOrderParamInstrument; @@ -112,4 +116,36 @@ void order_details() throws IOException { assertThat(orders).first().usingRecursiveComparison().isEqualTo(expected); } + + @Test + void trade_history() throws IOException { + UserTrades userTrades = gateioTradeService.getTradeHistory(GateioTradeHistoryParams.builder() + .currencyPair(CurrencyPair.BTC_USDT) + .pageLength(2) + .pageNumber(2) + .startTime(Date.from(Instant.ofEpochSecond(1691617924))) + .endTime(Date.from(Instant.ofEpochSecond(1691704324))) + .build()); + + assertThat(userTrades.getUserTrades()).hasSize(2); + + UserTrade expected = new UserTrade.Builder() + .instrument(CurrencyPair.BTC_USDT) + .id("6068789332") + .orderId("381064942553") + .orderUserReference("-") + .originalAmount(new BigDecimal("0.00005")) + .feeAmount(new BigDecimal("0.00294472")) + .feeCurrency(Currency.USDT) + .price(new BigDecimal("29447.2")) + .timestamp(Date.from(Instant.ofEpochMilli(1691702286356L))) + .type(OrderType.ASK) + .build(); + + UserTrade actual = userTrades.getUserTrades().get(0); + + assertThat(actual).isEqualTo(expected); + } + + } \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/resources/__files/api_v4_spot_my_trades.json b/xchange-gateio-v4/src/test/resources/__files/api_v4_spot_my_trades.json new file mode 100644 index 00000000000..1fbc87c560f --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/__files/api_v4_spot_my_trades.json @@ -0,0 +1,34 @@ +[ + { + "id": "6068816979", + "create_time": "1691702924", + "create_time_ms": "1691702924010.071000", + "currency_pair": "BTC_USDT", + "side": "buy", + "role": "taker", + "amount": "0.00003", + "price": "29454.6", + "order_id": "381068734893", + "fee": "0.00000006", + "fee_currency": "BTC", + "point_fee": "0", + "gt_fee": "0", + "amend_text": "-" + }, + { + "id": "6068789332", + "create_time": "1691702286", + "create_time_ms": "1691702286356.911000", + "currency_pair": "BTC_USDT", + "side": "sell", + "role": "taker", + "amount": "0.00005", + "price": "29447.2", + "order_id": "381064942553", + "fee": "0.00294472", + "fee_currency": "USDT", + "point_fee": "0", + "gt_fee": "0", + "amend_text": "-" + } +] \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_my_trades.json b/xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_my_trades.json new file mode 100644 index 00000000000..bdc77e06f16 --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_my_trades.json @@ -0,0 +1,15 @@ +{ + "id" : "8542120c-f98f-4b9a-9230-b81ee6ffe102", + "name" : "api_v4_spot_my_trades", + "request" : { + "url" : "/api/v4/spot/my_trades?currency_pair=BTC_USDT&limit=2&page=2&from=1691617924&to=1691704324", + "method" : "GET" + }, + "response" : { + "status" : 200, + "bodyFileName" : "api_v4_spot_my_trades.json" + }, + "uuid" : "8542120c-f98f-4b9a-9230-b81ee6ffe102", + "persistent" : true, + "insertionIndex" : 32 +} \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/resources/rest/spot.http b/xchange-gateio-v4/src/test/resources/rest/spot.http new file mode 100644 index 00000000000..a63da276e23 --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/rest/spot.http @@ -0,0 +1,23 @@ +### List personal trading history +< {% + const pattern = RegExp("^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?"); + const url = request.url.tryGetSubstituted(); + const matches = url.match(pattern); + const method = "GET"; + const path = matches[5]; + const query = matches[7] || ""; + const hexedHashedBody = crypto.sha512().updateWithText(request.body.tryGetSubstituted() || "").digest().toHex(); + const timestamp = Math.floor(Date.now() / 1000).toFixed(); + const payloadToSign = `${method}\n${path}\n${query}\n${hexedHashedBody}\n${timestamp}`; + const apiSecret = request.environment.get("api_secret"); + const sign = crypto.hmac.sha512().withTextSecret(apiSecret).updateWithText(payloadToSign).digest().toHex(); + request.variables.set("timestamp", timestamp); + request.variables.set("sign", sign); +%} + +GET {{api_v4}}/spot/my_trades +KEY: {{api_key}} +SIGN: {{sign}} +Timestamp: {{timestamp}} +Content-Type: application/json + From d8239e25887c5a73d44dbe0616a802165dfa117c Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Sat, 12 Aug 2023 00:46:14 +0200 Subject: [PATCH 081/159] [gateio-v4] Implement history of sub-account transfers --- .../xchange/gateio/GateioV4Authenticated.java | 15 ++++++ .../dto/account/GateioSubAccountTransfer.java | 46 +++++++++++++++++ .../GateioSubAccountTransfersParams.java | 21 ++++++++ .../service/GateioAccountServiceRaw.java | 11 ++++ .../service/GateioAccountServiceRawTest.java | 50 +++++++++++++++---- .../api_v4_wallet_sub_account_transfers.json | 13 +++++ .../api_v4_wallet_sub_account_transfers.json | 15 ++++++ .../src/test/resources/rest/wallet.http | 23 +++++++++ 8 files changed, 183 insertions(+), 11 deletions(-) create mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioSubAccountTransfer.java create mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/params/GateioSubAccountTransfersParams.java create mode 100644 xchange-gateio-v4/src/test/resources/__files/api_v4_wallet_sub_account_transfers.json create mode 100644 xchange-gateio-v4/src/test/resources/mappings/api_v4_wallet_sub_account_transfers.json diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java index 2ecb3ad5895..9f87bb2abb2 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java @@ -17,6 +17,7 @@ import org.knowm.xchange.gateio.dto.account.GateioCurrencyBalance; import org.knowm.xchange.gateio.dto.account.GateioDepositAddress; import org.knowm.xchange.gateio.dto.account.GateioOrder; +import org.knowm.xchange.gateio.dto.account.GateioSubAccountTransfer; import org.knowm.xchange.gateio.dto.account.GateioWithdrawStatus; import org.knowm.xchange.gateio.dto.account.GateioWithdrawalRecord; import org.knowm.xchange.gateio.dto.account.GateioWithdrawalRequest; @@ -128,6 +129,20 @@ List getSavedAddresses( ) throws IOException, GateioException; + @GET + @Path("wallet/sub_account_transfers") + List getSubAccountTransfers( + @HeaderParam("KEY") String apiKey, + @HeaderParam("Timestamp") SynchronizedValueFactory timestamp, + @HeaderParam("SIGN") ParamsDigest signer, + @QueryParam("sub_uid") String subAccountId, + @QueryParam("from") Long from, + @QueryParam("to") Long to, + @QueryParam("limit") Integer pageLength, + @QueryParam("offset") Integer zeroBasedPageNumber + ) throws IOException, GateioException; + + @GET @Path("wallet/withdrawals") List getWithdrawals( diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioSubAccountTransfer.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioSubAccountTransfer.java new file mode 100644 index 00000000000..be5f890368a --- /dev/null +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioSubAccountTransfer.java @@ -0,0 +1,46 @@ +package org.knowm.xchange.gateio.dto.account; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import java.math.BigDecimal; +import java.time.Instant; +import lombok.Builder; +import lombok.Data; +import lombok.extern.jackson.Jacksonized; +import org.knowm.xchange.currency.Currency; +import org.knowm.xchange.gateio.config.TimestampSecondsToInstantConverter; + +@Data +@Builder +@Jacksonized +public class GateioSubAccountTransfer { + + @JsonProperty("uid") + Integer mainAccountId; + + @JsonProperty("timest") + @JsonDeserialize(converter = TimestampSecondsToInstantConverter.class) + private Instant timestamp; + + @JsonProperty("source") + String source; + + @JsonProperty("client_order_id") + String clientOrderId; + + @JsonProperty("currency") + Currency currency; + + @JsonProperty("sub_account") + Integer subAccountId; + + @JsonProperty("direction") + String direction; + + @JsonProperty("amount") + BigDecimal amount; + + @JsonProperty("sub_account_type") + String subAccountType; + +} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/params/GateioSubAccountTransfersParams.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/params/GateioSubAccountTransfersParams.java new file mode 100644 index 00000000000..d2f19ad882a --- /dev/null +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/params/GateioSubAccountTransfersParams.java @@ -0,0 +1,21 @@ +package org.knowm.xchange.gateio.dto.account.params; + +import java.time.Instant; +import lombok.Data; +import lombok.experimental.SuperBuilder; + +@Data +@SuperBuilder +public class GateioSubAccountTransfersParams { + + private String subAccountId; + + private Integer pageLength; + + private Integer zeroBasedPageNumber; + + private Instant startTime; + + private Instant endTime; + +} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountServiceRaw.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountServiceRaw.java index bc7e7e5e364..c71e5407d28 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountServiceRaw.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountServiceRaw.java @@ -10,9 +10,11 @@ import org.knowm.xchange.gateio.dto.account.GateioAddressRecord; import org.knowm.xchange.gateio.dto.account.GateioCurrencyBalance; import org.knowm.xchange.gateio.dto.account.GateioDepositAddress; +import org.knowm.xchange.gateio.dto.account.GateioSubAccountTransfer; import org.knowm.xchange.gateio.dto.account.GateioWithdrawStatus; import org.knowm.xchange.gateio.dto.account.GateioWithdrawalRecord; import org.knowm.xchange.gateio.dto.account.GateioWithdrawalRequest; +import org.knowm.xchange.gateio.dto.account.params.GateioSubAccountTransfersParams; public class GateioAccountServiceRaw extends GateioBaseService { @@ -69,4 +71,13 @@ public List getSavedAddresses(Currency currency) throws IOE } + List getSubAccountTransfers(GateioSubAccountTransfersParams params) throws IOException { + Long from = params.getStartTime() != null ? params.getStartTime().getEpochSecond() : null; + Long to = params.getEndTime() != null ? params.getEndTime().getEpochSecond() : null; + + return gateioV4Authenticated.getSubAccountTransfers(apiKey, exchange.getNonceFactory(), gateioV4ParamsDigest, + params.getSubAccountId(), from, to, params.getPageLength(), params.getZeroBasedPageNumber()); + } + + } diff --git a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceRawTest.java b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceRawTest.java index 1e921dcf839..5c608f5249d 100644 --- a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceRawTest.java +++ b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceRawTest.java @@ -1,13 +1,7 @@ package org.knowm.xchange.gateio.service; -import org.junit.jupiter.api.Test; -import org.knowm.xchange.currency.Currency; -import org.knowm.xchange.exceptions.ExchangeSecurityException; -import org.knowm.xchange.exceptions.InstrumentNotValidException; -import org.knowm.xchange.exceptions.InternalServerException; -import org.knowm.xchange.gateio.GateioExchangeWiremock; -import org.knowm.xchange.gateio.dto.account.*; -import org.knowm.xchange.gateio.dto.account.GateioDepositAddress.MultichainAddress; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import java.io.IOException; import java.math.BigDecimal; @@ -15,9 +9,20 @@ import java.util.HashMap; import java.util.List; import java.util.Map; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import org.junit.jupiter.api.Test; +import org.knowm.xchange.currency.Currency; +import org.knowm.xchange.exceptions.ExchangeSecurityException; +import org.knowm.xchange.exceptions.InstrumentNotValidException; +import org.knowm.xchange.exceptions.InternalServerException; +import org.knowm.xchange.gateio.GateioExchangeWiremock; +import org.knowm.xchange.gateio.dto.account.GateioAddressRecord; +import org.knowm.xchange.gateio.dto.account.GateioDepositAddress; +import org.knowm.xchange.gateio.dto.account.GateioDepositAddress.MultichainAddress; +import org.knowm.xchange.gateio.dto.account.GateioSubAccountTransfer; +import org.knowm.xchange.gateio.dto.account.GateioWithdrawStatus; +import org.knowm.xchange.gateio.dto.account.GateioWithdrawalRecord; +import org.knowm.xchange.gateio.dto.account.GateioWithdrawalRequest; +import org.knowm.xchange.gateio.dto.account.params.GateioSubAccountTransfersParams; public class GateioAccountServiceRawTest extends GateioExchangeWiremock { @@ -185,4 +190,27 @@ void saved_addresses() throws IOException { assertThat(actual).first().usingRecursiveComparison().isEqualTo(expected); } + + @Test + void sub_account_transfers() throws IOException { + + List actual = gateioAccountServiceRaw.getSubAccountTransfers( + GateioSubAccountTransfersParams.builder().build()); + + GateioSubAccountTransfer expected = GateioSubAccountTransfer.builder() + .mainAccountId(10001) + .timestamp(Instant.ofEpochSecond(1592809000)) + .source("web") + .clientOrderId("da3ce7a088c8b0372b741419c7829033") + .currency(Currency.BTC) + .subAccountId(10002) + .direction("to") + .amount(BigDecimal.ONE) + .subAccountType("spot") + .build(); + + assertThat(actual).hasSize(1); + assertThat(actual).first().usingRecursiveComparison().isEqualTo(expected); + } + } \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/resources/__files/api_v4_wallet_sub_account_transfers.json b/xchange-gateio-v4/src/test/resources/__files/api_v4_wallet_sub_account_transfers.json new file mode 100644 index 00000000000..36a1df1da6f --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/__files/api_v4_wallet_sub_account_transfers.json @@ -0,0 +1,13 @@ +[ + { + "uid": "10001", + "timest": "1592809000", + "source": "web", + "client_order_id": "da3ce7a088c8b0372b741419c7829033", + "currency": "BTC", + "sub_account": "10002", + "direction": "to", + "amount": "1", + "sub_account_type": "spot" + } +] \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/resources/mappings/api_v4_wallet_sub_account_transfers.json b/xchange-gateio-v4/src/test/resources/mappings/api_v4_wallet_sub_account_transfers.json new file mode 100644 index 00000000000..c05901d39dc --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/mappings/api_v4_wallet_sub_account_transfers.json @@ -0,0 +1,15 @@ +{ + "id" : "0fa9195b-5201-4082-9876-cd2285cc96c2", + "name" : "api_v4_wallet_sub_account_transfers", + "request" : { + "url" : "/api/v4/wallet/sub_account_transfers", + "method" : "GET" + }, + "response" : { + "status" : 200, + "bodyFileName" : "api_v4_wallet_sub_account_transfers.json" + }, + "uuid" : "0fa9195b-5201-4082-9876-cd2285cc96c2", + "persistent" : true, + "insertionIndex" : 33 +} \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/resources/rest/wallet.http b/xchange-gateio-v4/src/test/resources/rest/wallet.http index 36b21002fb5..b48f040c192 100644 --- a/xchange-gateio-v4/src/test/resources/rest/wallet.http +++ b/xchange-gateio-v4/src/test/resources/rest/wallet.http @@ -21,3 +21,26 @@ SIGN: {{sign}} Timestamp: {{timestamp}} Content-Type: application/json + +### Retrieve transfer records between main and sub accounts +< {% + const pattern = RegExp("^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?"); + const url = request.url.tryGetSubstituted(); + const matches = url.match(pattern); + const method = "GET"; + const path = matches[5]; + const query = matches[7] || ""; + const hexedHashedBody = crypto.sha512().updateWithText(request.body.tryGetSubstituted() || "").digest().toHex(); + const timestamp = Math.floor(Date.now() / 1000).toFixed(); + const payloadToSign = `${method}\n${path}\n${query}\n${hexedHashedBody}\n${timestamp}`; + const apiSecret = request.environment.get("api_secret"); + const sign = crypto.hmac.sha512().withTextSecret(apiSecret).updateWithText(payloadToSign).digest().toHex(); + request.variables.set("timestamp", timestamp); + request.variables.set("sign", sign); +%} + +GET {{api_v4}}/wallet/sub_account_transfers +KEY: {{api_key}} +SIGN: {{sign}} +Timestamp: {{timestamp}} +Content-Type: application/json From 38dbf0baa230bffe8f191239382ad3aaf5d5a551 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Sat, 12 Aug 2023 01:05:06 +0200 Subject: [PATCH 082/159] [gateio-v4] Extend parameters for withdrawals history --- .../xchange/gateio/GateioV4Authenticated.java | 6 ++++- .../service/GateioAccountServiceRaw.java | 10 ++++++--- .../params/GateioWithdrawalsParams.java | 22 +++++++++++++++++++ .../service/GateioAccountServiceRawTest.java | 3 ++- 4 files changed, 36 insertions(+), 5 deletions(-) create mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/params/GateioWithdrawalsParams.java diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java index 9f87bb2abb2..f8e4fad122b 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java @@ -149,7 +149,11 @@ List getWithdrawals( @HeaderParam("KEY") String apiKey, @HeaderParam("Timestamp") SynchronizedValueFactory timestamp, @HeaderParam("SIGN") ParamsDigest signer, - @QueryParam("currency") String currency + @QueryParam("currency") String currency, + @QueryParam("from") Long from, + @QueryParam("to") Long to, + @QueryParam("limit") Integer pageLength, + @QueryParam("offset") Integer zeroBasedPageNumber ) throws IOException, GateioException; diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountServiceRaw.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountServiceRaw.java index c71e5407d28..c6d1ea6ded1 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountServiceRaw.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountServiceRaw.java @@ -15,6 +15,7 @@ import org.knowm.xchange.gateio.dto.account.GateioWithdrawalRecord; import org.knowm.xchange.gateio.dto.account.GateioWithdrawalRequest; import org.knowm.xchange.gateio.dto.account.params.GateioSubAccountTransfersParams; +import org.knowm.xchange.gateio.service.params.GateioWithdrawalsParams; public class GateioAccountServiceRaw extends GateioBaseService { @@ -54,9 +55,12 @@ public List getSpotBalances(Currency currency) throws IOE } - public List getWithdrawals(Currency currency) throws IOException { - String currencyCode = currency == null ? null : currency.getCurrencyCode(); - return gateioV4Authenticated.getWithdrawals(apiKey, exchange.getNonceFactory(), gateioV4ParamsDigest, currencyCode); + public List getWithdrawals(GateioWithdrawalsParams params) throws IOException { + String currency = params.getCurrency() != null ? params.getCurrency().toString() : null; + Long from = params.getStartTime() != null ? params.getStartTime().getEpochSecond() : null; + Long to = params.getEndTime() != null ? params.getEndTime().getEpochSecond() : null; + return gateioV4Authenticated.getWithdrawals(apiKey, exchange.getNonceFactory(), gateioV4ParamsDigest, + currency, from, to, params.getPageLength(), params.getZeroBasedPageNumber()); } diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/params/GateioWithdrawalsParams.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/params/GateioWithdrawalsParams.java new file mode 100644 index 00000000000..f8d0c73d906 --- /dev/null +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/params/GateioWithdrawalsParams.java @@ -0,0 +1,22 @@ +package org.knowm.xchange.gateio.service.params; + +import java.time.Instant; +import lombok.Builder; +import lombok.Data; +import org.knowm.xchange.currency.Currency; + +@Data +@Builder +public class GateioWithdrawalsParams { + + private Currency currency; + + private Integer pageLength; + + private Integer zeroBasedPageNumber; + + private Instant startTime; + + private Instant endTime; + +} diff --git a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceRawTest.java b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceRawTest.java index 5c608f5249d..2bae7b15ceb 100644 --- a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceRawTest.java +++ b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceRawTest.java @@ -23,6 +23,7 @@ import org.knowm.xchange.gateio.dto.account.GateioWithdrawalRecord; import org.knowm.xchange.gateio.dto.account.GateioWithdrawalRequest; import org.knowm.xchange.gateio.dto.account.params.GateioSubAccountTransfersParams; +import org.knowm.xchange.gateio.service.params.GateioWithdrawalsParams; public class GateioAccountServiceRawTest extends GateioExchangeWiremock { @@ -123,7 +124,7 @@ void valid_deposit_address() throws IOException { @Test void withdrawal_records() throws IOException { - var actual = gateioAccountServiceRaw.getWithdrawals(null); + var actual = gateioAccountServiceRaw.getWithdrawals(GateioWithdrawalsParams.builder().build()); GateioWithdrawalRecord expected = GateioWithdrawalRecord.builder() .id("w35874123") From 606a5709c53607ff095fc5654d3be2fe715a6ccb Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Sat, 12 Aug 2023 01:23:03 +0200 Subject: [PATCH 083/159] [gateio-v4] Add StringToCurrencyConverter --- .../gateio/config/StringToCurrencyConverter.java | 15 +++++++++++++++ .../dto/account/GateioSubAccountTransfer.java | 2 ++ .../dto/account/GateioWithdrawalRecord.java | 5 ++++- .../xchange/gateio/dto/trade/GateioUserTrade.java | 2 ++ .../service/GateioAccountServiceRawTest.java | 6 +++--- 5 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/StringToCurrencyConverter.java diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/StringToCurrencyConverter.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/StringToCurrencyConverter.java new file mode 100644 index 00000000000..52d8c7cc2e7 --- /dev/null +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/StringToCurrencyConverter.java @@ -0,0 +1,15 @@ +package org.knowm.xchange.gateio.config; + +import com.fasterxml.jackson.databind.util.StdConverter; +import org.knowm.xchange.currency.Currency; + +/** + * Converts string value {@code Currency} + */ +public class StringToCurrencyConverter extends StdConverter { + + @Override + public Currency convert(String value) { + return Currency.getInstance(value); + } +} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioSubAccountTransfer.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioSubAccountTransfer.java index be5f890368a..6cc6666275d 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioSubAccountTransfer.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioSubAccountTransfer.java @@ -8,6 +8,7 @@ import lombok.Data; import lombok.extern.jackson.Jacksonized; import org.knowm.xchange.currency.Currency; +import org.knowm.xchange.gateio.config.StringToCurrencyConverter; import org.knowm.xchange.gateio.config.TimestampSecondsToInstantConverter; @Data @@ -29,6 +30,7 @@ public class GateioSubAccountTransfer { String clientOrderId; @JsonProperty("currency") + @JsonDeserialize(converter = StringToCurrencyConverter.class) Currency currency; @JsonProperty("sub_account") diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioWithdrawalRecord.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioWithdrawalRecord.java index 32df4ab5f70..36e6cf2b549 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioWithdrawalRecord.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioWithdrawalRecord.java @@ -7,6 +7,8 @@ import lombok.Builder; import lombok.Data; import lombok.extern.jackson.Jacksonized; +import org.knowm.xchange.currency.Currency; +import org.knowm.xchange.gateio.config.StringToCurrencyConverter; import org.knowm.xchange.gateio.config.TimestampSecondsToInstantConverter; @Data @@ -31,7 +33,8 @@ public class GateioWithdrawalRecord { BigDecimal amount; @JsonProperty("currency") - String currency; + @JsonDeserialize(converter = StringToCurrencyConverter.class) + Currency currency; @JsonProperty("address") String address; diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/GateioUserTrade.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/GateioUserTrade.java index d5b80c76d53..591583e362d 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/GateioUserTrade.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/GateioUserTrade.java @@ -9,6 +9,7 @@ import lombok.extern.jackson.Jacksonized; import org.knowm.xchange.currency.Currency; import org.knowm.xchange.gateio.config.DoubleToInstantConverter; +import org.knowm.xchange.gateio.config.StringToCurrencyConverter; import org.knowm.xchange.gateio.config.TimestampSecondsToInstantConverter; @Data @@ -49,6 +50,7 @@ public class GateioUserTrade { BigDecimal fee; @JsonProperty("fee_currency") + @JsonDeserialize(converter = StringToCurrencyConverter.class) Currency feeCurrency; @JsonProperty("point_fee") diff --git a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceRawTest.java b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceRawTest.java index 2bae7b15ceb..84e7ba63a4e 100644 --- a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceRawTest.java +++ b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceRawTest.java @@ -124,11 +124,11 @@ void valid_deposit_address() throws IOException { @Test void withdrawal_records() throws IOException { - var actual = gateioAccountServiceRaw.getWithdrawals(GateioWithdrawalsParams.builder().build()); + List actual = gateioAccountServiceRaw.getWithdrawals(GateioWithdrawalsParams.builder().build()); GateioWithdrawalRecord expected = GateioWithdrawalRecord.builder() .id("w35874123") - .currency("LUFFY") + .currency(Currency.getInstance("LUFFY")) .address("0x3dca2ae4d1d065220a731cf69f5a934914afc435") .amount(new BigDecimal("1030645.8587")) .fee(new BigDecimal("10000")) @@ -165,7 +165,7 @@ void withdraw() throws IOException { .tag("") .chain("SOL") .amount(BigDecimal.valueOf(3)) - .currency("USDT") + .currency(Currency.USDT) .status("REQUEST") .build(); From 82c3043ba665d426ab3909ba92adb39b0b0ad516 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Sat, 12 Aug 2023 01:23:28 +0200 Subject: [PATCH 084/159] [gateio-v4] Implement deposits history --- .../xchange/gateio/GateioV4Authenticated.java | 15 ++++++ .../dto/account/GateioDepositRecord.java | 51 +++++++++++++++++++ .../service/GateioAccountServiceRaw.java | 11 ++++ .../service/params/GateioDepositsParams.java | 22 ++++++++ .../service/GateioAccountServiceRawTest.java | 26 ++++++++++ .../__files/api_v4_wallet_deposits.json | 24 +++++++++ .../mappings/api_v4_wallet_deposits.json | 15 ++++++ 7 files changed, 164 insertions(+) create mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioDepositRecord.java create mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/params/GateioDepositsParams.java create mode 100644 xchange-gateio-v4/src/test/resources/__files/api_v4_wallet_deposits.json create mode 100644 xchange-gateio-v4/src/test/resources/mappings/api_v4_wallet_deposits.json diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java index f8e4fad122b..249a27ee44b 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java @@ -16,6 +16,7 @@ import org.knowm.xchange.gateio.dto.account.GateioAddressRecord; import org.knowm.xchange.gateio.dto.account.GateioCurrencyBalance; import org.knowm.xchange.gateio.dto.account.GateioDepositAddress; +import org.knowm.xchange.gateio.dto.account.GateioDepositRecord; import org.knowm.xchange.gateio.dto.account.GateioOrder; import org.knowm.xchange.gateio.dto.account.GateioSubAccountTransfer; import org.knowm.xchange.gateio.dto.account.GateioWithdrawStatus; @@ -157,6 +158,20 @@ List getWithdrawals( ) throws IOException, GateioException; + @GET + @Path("wallet/deposits") + List getDeposits( + @HeaderParam("KEY") String apiKey, + @HeaderParam("Timestamp") SynchronizedValueFactory timestamp, + @HeaderParam("SIGN") ParamsDigest signer, + @QueryParam("currency") String currency, + @QueryParam("from") Long from, + @QueryParam("to") Long to, + @QueryParam("limit") Integer pageLength, + @QueryParam("offset") Integer zeroBasedPageNumber + ) throws IOException, GateioException; + + @POST @Path("withdrawals") @Consumes(MediaType.APPLICATION_JSON) diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioDepositRecord.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioDepositRecord.java new file mode 100644 index 00000000000..e4e6400b16b --- /dev/null +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioDepositRecord.java @@ -0,0 +1,51 @@ +package org.knowm.xchange.gateio.dto.account; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import java.math.BigDecimal; +import java.time.Instant; +import lombok.Builder; +import lombok.Data; +import lombok.extern.jackson.Jacksonized; +import org.knowm.xchange.currency.Currency; +import org.knowm.xchange.gateio.config.StringToCurrencyConverter; +import org.knowm.xchange.gateio.config.TimestampSecondsToInstantConverter; + +@Data +@Builder +@Jacksonized +public class GateioDepositRecord { + + @JsonProperty("id") + String id; + + @JsonProperty("txid") + String txId; + + @JsonProperty("withdraw_order_id") + String clientRecordId; + + @JsonProperty("timestamp") + @JsonDeserialize(converter = TimestampSecondsToInstantConverter.class) + Instant createdAt; + + @JsonProperty("amount") + BigDecimal amount; + + @JsonProperty("currency") + @JsonDeserialize(converter = StringToCurrencyConverter.class) + Currency currency; + + @JsonProperty("address") + String address; + + @JsonProperty("memo") + String tag; + + @JsonProperty("status") + String status; + + @JsonProperty("chain") + String chain; + +} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountServiceRaw.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountServiceRaw.java index c6d1ea6ded1..706ada398e1 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountServiceRaw.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountServiceRaw.java @@ -10,11 +10,13 @@ import org.knowm.xchange.gateio.dto.account.GateioAddressRecord; import org.knowm.xchange.gateio.dto.account.GateioCurrencyBalance; import org.knowm.xchange.gateio.dto.account.GateioDepositAddress; +import org.knowm.xchange.gateio.dto.account.GateioDepositRecord; import org.knowm.xchange.gateio.dto.account.GateioSubAccountTransfer; import org.knowm.xchange.gateio.dto.account.GateioWithdrawStatus; import org.knowm.xchange.gateio.dto.account.GateioWithdrawalRecord; import org.knowm.xchange.gateio.dto.account.GateioWithdrawalRequest; import org.knowm.xchange.gateio.dto.account.params.GateioSubAccountTransfersParams; +import org.knowm.xchange.gateio.service.params.GateioDepositsParams; import org.knowm.xchange.gateio.service.params.GateioWithdrawalsParams; public class GateioAccountServiceRaw extends GateioBaseService { @@ -64,6 +66,15 @@ public List getWithdrawals(GateioWithdrawalsParams param } + public List getDeposits(GateioDepositsParams params) throws IOException { + String currency = params.getCurrency() != null ? params.getCurrency().toString() : null; + Long from = params.getStartTime() != null ? params.getStartTime().getEpochSecond() : null; + Long to = params.getEndTime() != null ? params.getEndTime().getEpochSecond() : null; + return gateioV4Authenticated.getDeposits(apiKey, exchange.getNonceFactory(), gateioV4ParamsDigest, + currency, from, to, params.getPageLength(), params.getZeroBasedPageNumber()); + } + + public GateioWithdrawalRecord withdraw(GateioWithdrawalRequest gateioWithdrawalRequest) throws IOException { return gateioV4Authenticated.withdraw(apiKey, exchange.getNonceFactory(), gateioV4ParamsDigest, gateioWithdrawalRequest); } diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/params/GateioDepositsParams.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/params/GateioDepositsParams.java new file mode 100644 index 00000000000..4bef2686aa6 --- /dev/null +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/params/GateioDepositsParams.java @@ -0,0 +1,22 @@ +package org.knowm.xchange.gateio.service.params; + +import java.time.Instant; +import lombok.Builder; +import lombok.Data; +import org.knowm.xchange.currency.Currency; + +@Data +@Builder +public class GateioDepositsParams { + + private Currency currency; + + private Integer pageLength; + + private Integer zeroBasedPageNumber; + + private Instant startTime; + + private Instant endTime; + +} diff --git a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceRawTest.java b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceRawTest.java index 84e7ba63a4e..90274ccb008 100644 --- a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceRawTest.java +++ b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceRawTest.java @@ -18,11 +18,13 @@ import org.knowm.xchange.gateio.dto.account.GateioAddressRecord; import org.knowm.xchange.gateio.dto.account.GateioDepositAddress; import org.knowm.xchange.gateio.dto.account.GateioDepositAddress.MultichainAddress; +import org.knowm.xchange.gateio.dto.account.GateioDepositRecord; import org.knowm.xchange.gateio.dto.account.GateioSubAccountTransfer; import org.knowm.xchange.gateio.dto.account.GateioWithdrawStatus; import org.knowm.xchange.gateio.dto.account.GateioWithdrawalRecord; import org.knowm.xchange.gateio.dto.account.GateioWithdrawalRequest; import org.knowm.xchange.gateio.dto.account.params.GateioSubAccountTransfersParams; +import org.knowm.xchange.gateio.service.params.GateioDepositsParams; import org.knowm.xchange.gateio.service.params.GateioWithdrawalsParams; public class GateioAccountServiceRawTest extends GateioExchangeWiremock { @@ -145,6 +147,30 @@ void withdrawal_records() throws IOException { } + @Test + void deposit_records() throws IOException { + List actual = gateioAccountServiceRaw.getDeposits(GateioDepositsParams.builder() + .startTime(Instant.ofEpochSecond(1685833987)) + .endTime(Instant.ofEpochSecond(1688339587)) + .build()); + + GateioDepositRecord expected = GateioDepositRecord.builder() + .id("d95198946") + .currency(Currency.getInstance("OMN")) + .address("0x04A09F5712F527584BAC0C7be40Ae7946f9A9587") + .amount(new BigDecimal("2353")) + .txId("0x34a89edf400a85a9a6a2747ebc2074ef65895345b9b7400f164602085e9b4a2e") + .chain("OMN") + .createdAt(Instant.parse("2023-07-01T14:12:26Z")) + .status("DONE") + .tag("") + .build(); + + assertThat(actual).hasSize(2); + assertThat(actual).first().usingRecursiveComparison().isEqualTo(expected); + } + + @Test void withdraw() throws IOException { GateioWithdrawalRequest gateioWithdrawalRequest = GateioWithdrawalRequest.builder() diff --git a/xchange-gateio-v4/src/test/resources/__files/api_v4_wallet_deposits.json b/xchange-gateio-v4/src/test/resources/__files/api_v4_wallet_deposits.json new file mode 100644 index 00000000000..51061679bef --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/__files/api_v4_wallet_deposits.json @@ -0,0 +1,24 @@ +[ + { + "id": "d95198946", + "currency": "OMN", + "address": "0x04A09F5712F527584BAC0C7be40Ae7946f9A9587", + "amount": "2353", + "txid": "0x34a89edf400a85a9a6a2747ebc2074ef65895345b9b7400f164602085e9b4a2e", + "chain": "OMN", + "timestamp": "1688220746", + "status": "DONE", + "memo": "" + }, + { + "id": "d95194166", + "currency": "NAP", + "address": "0x04A09F5712F527584BAC0C7be40Ae7946f9A9587", + "amount": "5", + "txid": "0xe4145981e135f2742fe5b08ab4fed5cc6f18bd8fc9e47feb7923f39a87a21ec3", + "chain": "CHZ", + "timestamp": "1688213581", + "status": "DONE", + "memo": "" + } +] \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/resources/mappings/api_v4_wallet_deposits.json b/xchange-gateio-v4/src/test/resources/mappings/api_v4_wallet_deposits.json new file mode 100644 index 00000000000..1e7a7152db9 --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/mappings/api_v4_wallet_deposits.json @@ -0,0 +1,15 @@ +{ + "id" : "ace4cfb1-40e9-42ca-b7c9-eb6b97d70351", + "name" : "api_v4_wallet_deposits", + "request" : { + "url" : "/api/v4/wallet/deposits?from=1685833987&to=1688339587", + "method" : "GET" + }, + "response" : { + "status" : 200, + "bodyFileName" : "api_v4_wallet_deposits.json" + }, + "uuid" : "ace4cfb1-40e9-42ca-b7c9-eb6b97d70351", + "persistent" : true, + "insertionIndex" : 34 +} \ No newline at end of file From b08a34c3ea50c04ae0d7a6125ca6e3a40ee86572 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Sat, 12 Aug 2023 01:30:18 +0200 Subject: [PATCH 085/159] [gateio-v4] Parse payload as Currency --- .../xchange/gateio/dto/account/GateioAddressRecord.java | 5 ++++- .../xchange/gateio/dto/account/GateioCurrencyBalance.java | 6 +++++- .../xchange/gateio/dto/account/GateioDepositAddress.java | 6 +++++- .../xchange/gateio/dto/account/GateioWithdrawStatus.java | 6 +++++- .../knowm/xchange/gateio/service/GateioAccountService.java | 3 +-- .../xchange/gateio/service/GateioAccountServiceRawTest.java | 4 ++-- 6 files changed, 22 insertions(+), 8 deletions(-) diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioAddressRecord.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioAddressRecord.java index 6f4b869c69c..6726d977542 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioAddressRecord.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioAddressRecord.java @@ -5,7 +5,9 @@ import lombok.Builder; import lombok.Data; import lombok.extern.jackson.Jacksonized; +import org.knowm.xchange.currency.Currency; import org.knowm.xchange.gateio.config.StringToBooleanConverter; +import org.knowm.xchange.gateio.config.StringToCurrencyConverter; @Data @Builder @@ -13,7 +15,8 @@ public class GateioAddressRecord { @JsonProperty("currency") - String currency; + @JsonDeserialize(converter = StringToCurrencyConverter.class) + Currency currency; @JsonProperty("chain") String chain; diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioCurrencyBalance.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioCurrencyBalance.java index 73852f043a9..065cf01560f 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioCurrencyBalance.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioCurrencyBalance.java @@ -1,10 +1,13 @@ package org.knowm.xchange.gateio.dto.account; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import java.math.BigDecimal; import lombok.Builder; import lombok.Data; import lombok.extern.jackson.Jacksonized; +import org.knowm.xchange.currency.Currency; +import org.knowm.xchange.gateio.config.StringToCurrencyConverter; @Data @Builder @@ -12,7 +15,8 @@ public class GateioCurrencyBalance { @JsonProperty("currency") - String currency; + @JsonDeserialize(converter = StringToCurrencyConverter.class) + Currency currency; @JsonProperty("available") BigDecimal available; diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioDepositAddress.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioDepositAddress.java index c608c3d0110..834780ece27 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioDepositAddress.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioDepositAddress.java @@ -1,10 +1,13 @@ package org.knowm.xchange.gateio.dto.account; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import java.util.List; import lombok.Builder; import lombok.Data; import lombok.extern.jackson.Jacksonized; +import org.knowm.xchange.currency.Currency; +import org.knowm.xchange.gateio.config.StringToCurrencyConverter; @Data @Builder @@ -12,7 +15,8 @@ public class GateioDepositAddress { @JsonProperty("currency") - String currency; + @JsonDeserialize(converter = StringToCurrencyConverter.class) + Currency currency; @JsonProperty("multichain_addresses") List multichainAddresses; diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioWithdrawStatus.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioWithdrawStatus.java index 9e6f4d07337..24d0ecbf441 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioWithdrawStatus.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioWithdrawStatus.java @@ -1,12 +1,15 @@ package org.knowm.xchange.gateio.dto.account; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import java.math.BigDecimal; import java.util.Map; import lombok.Builder; import lombok.Data; import lombok.extern.jackson.Jacksonized; import org.apache.commons.lang3.StringUtils; +import org.knowm.xchange.currency.Currency; +import org.knowm.xchange.gateio.config.StringToCurrencyConverter; @Data @Builder @@ -14,7 +17,8 @@ public class GateioWithdrawStatus { @JsonProperty("currency") - String currency; + @JsonDeserialize(converter = StringToCurrencyConverter.class) + Currency currency; @JsonProperty("name") String name; diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountService.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountService.java index 145a341a9cc..d2b20d56dac 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountService.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountService.java @@ -4,7 +4,6 @@ import java.util.List; import java.util.stream.Collectors; import org.apache.commons.lang3.Validate; -import org.knowm.xchange.currency.Currency; import org.knowm.xchange.dto.account.AccountInfo; import org.knowm.xchange.dto.account.Balance; import org.knowm.xchange.dto.account.Wallet; @@ -34,7 +33,7 @@ public AccountInfo getAccountInfo() throws IOException { List balances = spotBalances.stream() .map(balance -> Balance.builder() - .currency(Currency.getInstance(balance.getCurrency())) + .currency(balance.getCurrency()) .available(balance.getAvailable()) .frozen(balance.getLocked()) .build()) diff --git a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceRawTest.java b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceRawTest.java index 90274ccb008..f75e699baae 100644 --- a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceRawTest.java +++ b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceRawTest.java @@ -37,7 +37,7 @@ void getWithdrawStatus_valid() throws IOException { expectedWithdrawFeeByChain.put("ETH", new BigDecimal("0.93")); expectedWithdrawFeeByChain.put("GTEVM", new BigDecimal("0.0049")); GateioWithdrawStatus expected = GateioWithdrawStatus.builder() - .currency("GT") + .currency(Currency.getInstance("GT")) .name("GateToken") .nameCN("狗头") .depositFee(BigDecimal.ZERO) @@ -208,7 +208,7 @@ void saved_addresses() throws IOException { .address("6vLyxJ9dBziamyaw2vDcs9n2NwQdW1uk3aooJwrEscnA") .tag("") .chain("SOL") - .currency("USDT") + .currency(Currency.USDT) .name("stuff") .verified(true) .build(); From 613c73f88b7c612dda5d62dc1ff6a608fcc2e1ea Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Sat, 12 Aug 2023 23:55:13 +0200 Subject: [PATCH 086/159] [gateio-v4] Rename class --- .../knowm/xchange/gateio/GateioAdapters.java | 4 ++-- .../gateio/service/GateioAccountService.java | 6 +++--- ...ms.java => GateioWithdrawFundsParams.java} | 2 +- .../service/GateioAccountServiceTest.java | 21 +++++++++---------- 4 files changed, 16 insertions(+), 17 deletions(-) rename xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/params/{DefaultGateioWithdrawFundsParams.java => GateioWithdrawFundsParams.java} (75%) diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java index 874a9157f60..a1928973ee4 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java @@ -22,7 +22,7 @@ import org.knowm.xchange.gateio.dto.marketdata.GateioOrderBook; import org.knowm.xchange.gateio.dto.marketdata.GateioTicker; import org.knowm.xchange.gateio.dto.trade.GateioUserTrade; -import org.knowm.xchange.gateio.service.params.DefaultGateioWithdrawFundsParams; +import org.knowm.xchange.gateio.service.params.GateioWithdrawFundsParams; import org.knowm.xchange.instrument.Instrument; @@ -203,7 +203,7 @@ public OrderType toOrderType(String gateioOrderType) { } - public GateioWithdrawalRequest toGateioWithdrawalRequest(DefaultGateioWithdrawFundsParams p) { + public GateioWithdrawalRequest toGateioWithdrawalRequest(GateioWithdrawFundsParams p) { return GateioWithdrawalRequest.builder() .clientRecordId(p.getClientRecordId()) .address(p.getAddress()) diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountService.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountService.java index d2b20d56dac..704c5a93449 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountService.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountService.java @@ -14,7 +14,7 @@ import org.knowm.xchange.gateio.dto.account.GateioCurrencyBalance; import org.knowm.xchange.gateio.dto.account.GateioWithdrawalRecord; import org.knowm.xchange.gateio.dto.account.GateioWithdrawalRequest; -import org.knowm.xchange.gateio.service.params.DefaultGateioWithdrawFundsParams; +import org.knowm.xchange.gateio.service.params.GateioWithdrawFundsParams; import org.knowm.xchange.service.account.AccountService; import org.knowm.xchange.service.trade.params.WithdrawFundsParams; @@ -55,8 +55,8 @@ public AccountInfo getAccountInfo() throws IOException { @Override public String withdrawFunds(WithdrawFundsParams params) throws IOException { - Validate.isInstanceOf(DefaultGateioWithdrawFundsParams.class, params, "Not enough parameters"); - DefaultGateioWithdrawFundsParams p = (DefaultGateioWithdrawFundsParams) params; + Validate.isInstanceOf(GateioWithdrawFundsParams.class, params); + GateioWithdrawFundsParams p = (GateioWithdrawFundsParams) params; GateioWithdrawalRequest gateioWithdrawalRequest = GateioAdapters.toGateioWithdrawalRequest(p); diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/params/DefaultGateioWithdrawFundsParams.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/params/GateioWithdrawFundsParams.java similarity index 75% rename from xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/params/DefaultGateioWithdrawFundsParams.java rename to xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/params/GateioWithdrawFundsParams.java index 291eecb144c..1ebcb3b235a 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/params/DefaultGateioWithdrawFundsParams.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/params/GateioWithdrawFundsParams.java @@ -6,7 +6,7 @@ @Value @SuperBuilder -public class DefaultGateioWithdrawFundsParams extends DefaultWithdrawFundsParams { +public class GateioWithdrawFundsParams extends DefaultWithdrawFundsParams { String clientRecordId; diff --git a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceTest.java b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceTest.java index aba5d4ae9eb..90a00961cce 100644 --- a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceTest.java +++ b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceTest.java @@ -1,5 +1,10 @@ package org.knowm.xchange.gateio.service; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; + +import java.io.IOException; +import java.math.BigDecimal; import org.junit.jupiter.api.Test; import org.knowm.xchange.currency.Currency; import org.knowm.xchange.dto.account.AccountInfo; @@ -8,13 +13,7 @@ import org.knowm.xchange.exceptions.OrderNotValidException; import org.knowm.xchange.exceptions.RateLimitExceededException; import org.knowm.xchange.gateio.GateioExchangeWiremock; -import org.knowm.xchange.gateio.service.params.DefaultGateioWithdrawFundsParams; - -import java.io.IOException; -import java.math.BigDecimal; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import org.knowm.xchange.gateio.service.params.GateioWithdrawFundsParams; class GateioAccountServiceTest extends GateioExchangeWiremock { @@ -36,7 +35,7 @@ void getAccountInfo() throws IOException { @Test void normal_withdraw() throws IOException { - DefaultGateioWithdrawFundsParams params = DefaultGateioWithdrawFundsParams.builder() + GateioWithdrawFundsParams params = GateioWithdrawFundsParams.builder() .clientRecordId("valid-withdrawal-id") .address("6vLyxJ9dBziamyaw2vDcs9n2NwQdW1uk3aooJwrEscnA") .addressTag("") @@ -52,7 +51,7 @@ void normal_withdraw() throws IOException { @Test void rate_limited_withdraw() { - DefaultGateioWithdrawFundsParams params = DefaultGateioWithdrawFundsParams.builder() + GateioWithdrawFundsParams params = GateioWithdrawFundsParams.builder() .clientRecordId("rate-limited-id") .address("6vLyxJ9dBziamyaw2vDcs9n2NwQdW1uk3aooJwrEscnA") .addressTag("") @@ -68,7 +67,7 @@ void rate_limited_withdraw() { @Test void zero_amount_withdraw() { - DefaultGateioWithdrawFundsParams params = DefaultGateioWithdrawFundsParams.builder() + GateioWithdrawFundsParams params = GateioWithdrawFundsParams.builder() .clientRecordId("zero-amount-id") .address("6vLyxJ9dBziamyaw2vDcs9n2NwQdW1uk3aooJwrEscnA") .addressTag("") @@ -84,7 +83,7 @@ void zero_amount_withdraw() { @Test void invalid_address_withdraw() { - DefaultGateioWithdrawFundsParams params = DefaultGateioWithdrawFundsParams.builder() + GateioWithdrawFundsParams params = GateioWithdrawFundsParams.builder() .clientRecordId("invalid-address-id") .address("invalid-address") .addressTag("") From c0e43ee3be4f5429c8fbf8309ae1c6272b28172b Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Sun, 13 Aug 2023 00:40:08 +0200 Subject: [PATCH 087/159] [gateio-v4] Implement account book and funding history --- .../knowm/xchange/gateio/GateioAdapters.java | 16 ++++++++ .../xchange/gateio/GateioV4Authenticated.java | 16 ++++++++ .../dto/account/GateioAccountBookRecord.java | 37 +++++++++++++++++++ .../gateio/service/GateioAccountService.java | 13 +++++++ .../service/GateioAccountServiceRaw.java | 25 +++++++++++++ .../params/GateioFundingHistoryParams.java | 26 +++++++++++++ .../service/GateioAccountServiceTest.java | 32 ++++++++++++++++ .../__files/api_v4_spot_account_book.json | 18 +++++++++ .../mappings/api_v4_spot_account_book.json | 15 ++++++++ .../src/test/resources/rest/spot.http | 24 ++++++++++++ 10 files changed, 222 insertions(+) create mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioAccountBookRecord.java create mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/params/GateioFundingHistoryParams.java create mode 100644 xchange-gateio-v4/src/test/resources/__files/api_v4_spot_account_book.json create mode 100644 xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_account_book.json diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java index a1928973ee4..624d63d4627 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java @@ -10,12 +10,15 @@ import org.knowm.xchange.dto.Order; import org.knowm.xchange.dto.Order.OrderStatus; import org.knowm.xchange.dto.Order.OrderType; +import org.knowm.xchange.dto.account.FundingRecord; +import org.knowm.xchange.dto.account.FundingRecord.Type; import org.knowm.xchange.dto.marketdata.OrderBook; import org.knowm.xchange.dto.marketdata.Ticker; import org.knowm.xchange.dto.meta.InstrumentMetaData; import org.knowm.xchange.dto.trade.LimitOrder; import org.knowm.xchange.dto.trade.MarketOrder; import org.knowm.xchange.dto.trade.UserTrade; +import org.knowm.xchange.gateio.dto.account.GateioAccountBookRecord; import org.knowm.xchange.gateio.dto.account.GateioOrder; import org.knowm.xchange.gateio.dto.account.GateioWithdrawalRequest; import org.knowm.xchange.gateio.dto.marketdata.GateioCurrencyPairDetails; @@ -229,4 +232,17 @@ public Ticker toTicker(GateioTicker gateioTicker) { .percentageChange(gateioTicker.getChangePercentage24h()) .build(); } + + + public FundingRecord toFundingRecords(GateioAccountBookRecord gateioAccountBookRecord) { + return new FundingRecord.Builder() + .setInternalId(gateioAccountBookRecord.getId()) + .setDate(Date.from(gateioAccountBookRecord.getTimestamp())) + .setCurrency(gateioAccountBookRecord.getCurrency()) + .setBalance(gateioAccountBookRecord.getBalance()) + .setType(gateioAccountBookRecord.getChange().signum() > 0 ? Type.OTHER_INFLOW : Type.OTHER_OUTFLOW) + .setAmount(gateioAccountBookRecord.getChange().abs()) + .setDescription(gateioAccountBookRecord.getType()) + .build(); + } } diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java index 249a27ee44b..47e520be9d9 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java @@ -13,6 +13,7 @@ import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; import org.knowm.xchange.gateio.dto.GateioException; +import org.knowm.xchange.gateio.dto.account.GateioAccountBookRecord; import org.knowm.xchange.gateio.dto.account.GateioAddressRecord; import org.knowm.xchange.gateio.dto.account.GateioCurrencyBalance; import org.knowm.xchange.gateio.dto.account.GateioDepositAddress; @@ -60,6 +61,21 @@ List getSpotAccounts( ) throws IOException, GateioException; + @GET + @Path("spot/account_book") + List getAccountBookRecords( + @HeaderParam("KEY") String apiKey, + @HeaderParam("Timestamp") SynchronizedValueFactory timestamp, + @HeaderParam("SIGN") ParamsDigest signer, + @QueryParam("currency") String currency, + @QueryParam("from") Long from, + @QueryParam("to") Long to, + @QueryParam("limit") Integer pageLength, + @QueryParam("offset") Integer zeroBasedPageNumber, + @QueryParam("type") String type + ) throws IOException, GateioException; + + @GET @Path("spot/orders") List listOrders( diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioAccountBookRecord.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioAccountBookRecord.java new file mode 100644 index 00000000000..220b60aba54 --- /dev/null +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioAccountBookRecord.java @@ -0,0 +1,37 @@ +package org.knowm.xchange.gateio.dto.account; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import java.math.BigDecimal; +import java.time.Instant; +import lombok.Builder; +import lombok.Data; +import lombok.extern.jackson.Jacksonized; +import org.knowm.xchange.currency.Currency; +import org.knowm.xchange.gateio.config.StringToCurrencyConverter; + +@Data +@Builder +@Jacksonized +public class GateioAccountBookRecord { + + @JsonProperty("id") + String id; + + @JsonProperty("time") + Instant timestamp; + + @JsonProperty("currency") + @JsonDeserialize(converter = StringToCurrencyConverter.class) + Currency currency; + + @JsonProperty("change") + BigDecimal change; + + @JsonProperty("balance") + BigDecimal balance; + + @JsonProperty("type") + String type; + +} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountService.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountService.java index 704c5a93449..8af25ae2f9b 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountService.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountService.java @@ -6,6 +6,7 @@ import org.apache.commons.lang3.Validate; import org.knowm.xchange.dto.account.AccountInfo; import org.knowm.xchange.dto.account.Balance; +import org.knowm.xchange.dto.account.FundingRecord; import org.knowm.xchange.dto.account.Wallet; import org.knowm.xchange.gateio.GateioAdapters; import org.knowm.xchange.gateio.GateioErrorAdapter; @@ -16,6 +17,7 @@ import org.knowm.xchange.gateio.dto.account.GateioWithdrawalRequest; import org.knowm.xchange.gateio.service.params.GateioWithdrawFundsParams; import org.knowm.xchange.service.account.AccountService; +import org.knowm.xchange.service.trade.params.TradeHistoryParams; import org.knowm.xchange.service.trade.params.WithdrawFundsParams; public class GateioAccountService extends GateioAccountServiceRaw implements AccountService { @@ -70,4 +72,15 @@ public String withdrawFunds(WithdrawFundsParams params) throws IOException { } + @Override + public List getFundingHistory(TradeHistoryParams params) throws IOException { + try { + return getAccountBookRecords(params).stream() + .map(GateioAdapters::toFundingRecords) + .collect(Collectors.toList()); + } + catch (GateioException e) { + throw GateioErrorAdapter.adapt(e); + } + } } diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountServiceRaw.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountServiceRaw.java index 706ada398e1..6f8ef6c7202 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountServiceRaw.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountServiceRaw.java @@ -7,6 +7,7 @@ import org.knowm.xchange.gateio.GateioErrorAdapter; import org.knowm.xchange.gateio.GateioExchange; import org.knowm.xchange.gateio.dto.GateioException; +import org.knowm.xchange.gateio.dto.account.GateioAccountBookRecord; import org.knowm.xchange.gateio.dto.account.GateioAddressRecord; import org.knowm.xchange.gateio.dto.account.GateioCurrencyBalance; import org.knowm.xchange.gateio.dto.account.GateioDepositAddress; @@ -17,7 +18,11 @@ import org.knowm.xchange.gateio.dto.account.GateioWithdrawalRequest; import org.knowm.xchange.gateio.dto.account.params.GateioSubAccountTransfersParams; import org.knowm.xchange.gateio.service.params.GateioDepositsParams; +import org.knowm.xchange.gateio.service.params.GateioFundingHistoryParams; import org.knowm.xchange.gateio.service.params.GateioWithdrawalsParams; +import org.knowm.xchange.service.trade.params.TradeHistoryParamPaging; +import org.knowm.xchange.service.trade.params.TradeHistoryParams; +import org.knowm.xchange.service.trade.params.TradeHistoryParamsTimeSpan; public class GateioAccountServiceRaw extends GateioBaseService { @@ -86,6 +91,26 @@ public List getSavedAddresses(Currency currency) throws IOE } + public List getAccountBookRecords(TradeHistoryParams params) throws IOException { + // get arguments + Currency currency = params instanceof GateioFundingHistoryParams ? ((GateioFundingHistoryParams) params).getCurrency() : null; + String currencyCode = currency != null ? currency.toString() : null; + String type = params instanceof GateioFundingHistoryParams ? ((GateioFundingHistoryParams) params).getType() : null; + Integer pageLength = params instanceof TradeHistoryParamPaging ? ((TradeHistoryParamPaging) params).getPageLength() : null; + Integer pageNumber = params instanceof TradeHistoryParamPaging ? ((TradeHistoryParamPaging) params).getPageNumber() : null; + Long from = null; + Long to = null; + if (params instanceof TradeHistoryParamsTimeSpan) { + TradeHistoryParamsTimeSpan paramsTimeSpan = ((TradeHistoryParamsTimeSpan) params); + from = paramsTimeSpan.getStartTime() != null ? paramsTimeSpan.getStartTime().getTime() / 1000 : null; + to = paramsTimeSpan.getEndTime() != null ? paramsTimeSpan.getEndTime().getTime() / 1000 : null; + } + + return gateioV4Authenticated.getAccountBookRecords(apiKey, exchange.getNonceFactory(), gateioV4ParamsDigest, + currencyCode, from, to, pageLength, pageNumber, type); + } + + List getSubAccountTransfers(GateioSubAccountTransfersParams params) throws IOException { Long from = params.getStartTime() != null ? params.getStartTime().getEpochSecond() : null; Long to = params.getEndTime() != null ? params.getEndTime().getEpochSecond() : null; diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/params/GateioFundingHistoryParams.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/params/GateioFundingHistoryParams.java new file mode 100644 index 00000000000..8980c09239c --- /dev/null +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/params/GateioFundingHistoryParams.java @@ -0,0 +1,26 @@ +package org.knowm.xchange.gateio.service.params; + +import java.util.Date; +import lombok.Builder; +import lombok.Data; +import org.knowm.xchange.currency.Currency; +import org.knowm.xchange.service.trade.params.TradeHistoryParamPaging; +import org.knowm.xchange.service.trade.params.TradeHistoryParamsTimeSpan; + +@Data +@Builder +public class GateioFundingHistoryParams implements TradeHistoryParamPaging, TradeHistoryParamsTimeSpan { + + private Currency currency; + + private Integer pageLength; + + private Integer pageNumber; + + private Date startTime; + + private Date endTime; + + private String type; + +} diff --git a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceTest.java b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceTest.java index 90a00961cce..466f0f748fd 100644 --- a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceTest.java +++ b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceTest.java @@ -5,14 +5,20 @@ import java.io.IOException; import java.math.BigDecimal; +import java.time.Instant; +import java.util.Date; +import java.util.List; import org.junit.jupiter.api.Test; import org.knowm.xchange.currency.Currency; import org.knowm.xchange.dto.account.AccountInfo; import org.knowm.xchange.dto.account.Balance; +import org.knowm.xchange.dto.account.FundingRecord; +import org.knowm.xchange.dto.account.FundingRecord.Type; import org.knowm.xchange.exceptions.OrderAmountUnderMinimumException; import org.knowm.xchange.exceptions.OrderNotValidException; import org.knowm.xchange.exceptions.RateLimitExceededException; import org.knowm.xchange.gateio.GateioExchangeWiremock; +import org.knowm.xchange.gateio.service.params.GateioFundingHistoryParams; import org.knowm.xchange.gateio.service.params.GateioWithdrawFundsParams; class GateioAccountServiceTest extends GateioExchangeWiremock { @@ -97,4 +103,30 @@ void invalid_address_withdraw() { } + @Test + void funding_history() throws IOException { + List actual = gateioAccountService.getFundingHistory(GateioFundingHistoryParams.builder() + .currency(Currency.USDT) + .startTime(Date.from(Instant.ofEpochSecond(1691447482))) + .endTime(Date.from(Instant.ofEpochSecond(1691533882))) + .pageLength(2) + .pageNumber(1) + .type("order_fee") + .build()); + + FundingRecord expected = new FundingRecord.Builder() + .setInternalId("40558668441") + .setDate(Date.from(Instant.ofEpochMilli(1691510538067L))) + .setCurrency(Currency.USDT) + .setBalance(new BigDecimal("16.00283141582979715942")) + .setType(Type.OTHER_OUTFLOW) + .setAmount(new BigDecimal("0.0113918056")) + .setDescription("order_fee") + .build(); + + assertThat(actual).hasSize(2); + assertThat(actual).first().usingRecursiveComparison().isEqualTo(expected); + } + + } \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/resources/__files/api_v4_spot_account_book.json b/xchange-gateio-v4/src/test/resources/__files/api_v4_spot_account_book.json new file mode 100644 index 00000000000..fd07274dc7d --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/__files/api_v4_spot_account_book.json @@ -0,0 +1,18 @@ +[ + { + "id": "40558668441", + "time": 1691510538067, + "currency": "USDT", + "change": "-0.0113918056", + "balance": "16.00283141582979715942", + "type": "order_fee" + }, + { + "id": "40558668438", + "time": 1691510538067, + "currency": "USDT", + "change": "-0.0187363344", + "balance": "10.31832042142979715942", + "type": "order_fee" + } +] \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_account_book.json b/xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_account_book.json new file mode 100644 index 00000000000..007846253c9 --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_account_book.json @@ -0,0 +1,15 @@ +{ + "id" : "0f4c0848-df10-4f1e-b5e7-1b5213fa2f18", + "name" : "api_v4_spot_account_book", + "request" : { + "url" : "/api/v4/spot/account_book?currency=USDT&from=1691447482&to=1691533882&limit=2&offset=1&type=order_fee", + "method" : "GET" + }, + "response" : { + "status" : 200, + "bodyFileName" : "api_v4_spot_account_book.json" + }, + "uuid" : "0f4c0848-df10-4f1e-b5e7-1b5213fa2f18", + "persistent" : true, + "insertionIndex" : 35 +} \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/resources/rest/spot.http b/xchange-gateio-v4/src/test/resources/rest/spot.http index a63da276e23..d80a6bf5e3e 100644 --- a/xchange-gateio-v4/src/test/resources/rest/spot.http +++ b/xchange-gateio-v4/src/test/resources/rest/spot.http @@ -21,3 +21,27 @@ SIGN: {{sign}} Timestamp: {{timestamp}} Content-Type: application/json + +### Query account book +< {% + const pattern = RegExp("^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?"); + const url = request.url.tryGetSubstituted(); + const matches = url.match(pattern); + const method = "GET"; + const path = matches[5]; + const query = matches[7] || ""; + const hexedHashedBody = crypto.sha512().updateWithText(request.body.tryGetSubstituted() || "").digest().toHex(); + const timestamp = Math.floor(Date.now() / 1000).toFixed(); + const payloadToSign = `${method}\n${path}\n${query}\n${hexedHashedBody}\n${timestamp}`; + const apiSecret = request.environment.get("api_secret"); + const sign = crypto.hmac.sha512().withTextSecret(apiSecret).updateWithText(payloadToSign).digest().toHex(); + request.variables.set("timestamp", timestamp); + request.variables.set("sign", sign); +%} + +GET {{api_v4}}/spot/account_book +KEY: {{api_key}} +SIGN: {{sign}} +Timestamp: {{timestamp}} +Content-Type: application/json + From b1a25ccee16bed76221397f96ed3754cfc249ecf Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Sun, 13 Aug 2023 00:51:24 +0200 Subject: [PATCH 088/159] [gateio-v4] Add converters between CurrencyPair and String --- .../org/knowm/xchange/gateio/GateioAdapters.java | 16 +++++----------- .../config/CurrencyPairToStringConverter.java | 15 +++++++++++++++ .../config/StringToCurrencyPairConverter.java | 15 +++++++++++++++ .../xchange/gateio/dto/account/GateioOrder.java | 14 ++++++++++---- .../gateio/dto/marketdata/GateioTicker.java | 11 +++++++---- .../gateio/dto/trade/GateioUserTrade.java | 5 ++++- .../service/GateioTradeServiceRawTest.java | 8 ++++---- 7 files changed, 60 insertions(+), 24 deletions(-) create mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/CurrencyPairToStringConverter.java create mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/StringToCurrencyPairConverter.java diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java index 624d63d4627..7a94c00fbbc 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java @@ -51,12 +51,6 @@ public String toString(Instrument instrument) { } - public Instrument toInstrument(String currencyCode) { - var currencies = currencyCode.split("_"); - return new CurrencyPair(currencies[0], currencies[1]); - } - - public OrderBook toOrderBook(GateioOrderBook gateioOrderBook, Instrument instrument) { List asks = gateioOrderBook.getAsks().stream() .map(priceSizeEntry -> new LimitOrder(OrderType.ASK, priceSizeEntry.getSize(), instrument, null, null, priceSizeEntry.getPrice())) @@ -111,7 +105,7 @@ public OrderStatus toOrderStatus(String gateioOrderStatus) { public GateioOrder toGateioOrder(MarketOrder marketOrder) { return GateioOrder.builder() - .currencyPair(toString(marketOrder.getInstrument())) + .currencyPair((CurrencyPair) marketOrder.getInstrument()) .side(toString(marketOrder.getType())) .clientOrderId(marketOrder.getUserReference()) .account("spot") @@ -124,7 +118,7 @@ public GateioOrder toGateioOrder(MarketOrder marketOrder) { public GateioOrder toGateioOrder(LimitOrder limitOrder) { return GateioOrder.builder() - .currencyPair(toString(limitOrder.getInstrument())) + .currencyPair((CurrencyPair) limitOrder.getInstrument()) .side(toString(limitOrder.getType())) .clientOrderId(limitOrder.getUserReference()) .account("spot") @@ -138,7 +132,7 @@ public GateioOrder toGateioOrder(LimitOrder limitOrder) { public Order toOrder(GateioOrder gateioOrder) { Order.Builder order; - Instrument instrument = toInstrument(gateioOrder.getCurrencyPair()); + Instrument instrument = gateioOrder.getCurrencyPair(); OrderType orderType = toOrderType(gateioOrder.getSide()); switch (gateioOrder.getType()) { @@ -174,7 +168,7 @@ public UserTrade toUserTrade(GateioUserTrade gateioUserTrade) { .feeCurrency(gateioUserTrade.getFeeCurrency()) .orderUserReference(gateioUserTrade.getRemark()) .type(toOrderType(gateioUserTrade.getSide())) - .instrument(toInstrument(gateioUserTrade.getCurrencyPair())) + .instrument(gateioUserTrade.getCurrencyPair()) .price(gateioUserTrade.getPrice()) .timestamp(Date.from(gateioUserTrade.getTimeMs())) .originalAmount(gateioUserTrade.getAmount()) @@ -221,7 +215,7 @@ public GateioWithdrawalRequest toGateioWithdrawalRequest(GateioWithdrawFundsPara public Ticker toTicker(GateioTicker gateioTicker) { return new Ticker.Builder() - .instrument(toInstrument(gateioTicker.getCurrencyPair())) + .instrument(gateioTicker.getCurrencyPair()) .last(gateioTicker.getLastPrice()) .bid(gateioTicker.getHighestBid()) .ask(gateioTicker.getLowestAsk()) diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/CurrencyPairToStringConverter.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/CurrencyPairToStringConverter.java new file mode 100644 index 00000000000..d9186c49cd2 --- /dev/null +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/CurrencyPairToStringConverter.java @@ -0,0 +1,15 @@ +package org.knowm.xchange.gateio.config; + +import com.fasterxml.jackson.databind.util.StdConverter; +import org.knowm.xchange.currency.CurrencyPair; + +/** + * Converts {@code CurrencyPair} to string + */ +public class CurrencyPairToStringConverter extends StdConverter { + + @Override + public String convert(CurrencyPair value) { + return value.getBase() + "_" + value.getCounter(); + } +} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/StringToCurrencyPairConverter.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/StringToCurrencyPairConverter.java new file mode 100644 index 00000000000..5b2aec7027a --- /dev/null +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/StringToCurrencyPairConverter.java @@ -0,0 +1,15 @@ +package org.knowm.xchange.gateio.config; + +import com.fasterxml.jackson.databind.util.StdConverter; +import org.knowm.xchange.currency.CurrencyPair; + +/** + * Converts string to {@code CurrencyPair} + */ +public class StringToCurrencyPairConverter extends StdConverter { + + @Override + public CurrencyPair convert(String value) { + return new CurrencyPair(value.replace('_', '/')); + } +} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioOrder.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioOrder.java index 1395a4a465b..f121902d0f5 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioOrder.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioOrder.java @@ -1,12 +1,16 @@ package org.knowm.xchange.gateio.dto.account; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import java.math.BigDecimal; +import java.time.Instant; import lombok.Builder; import lombok.Data; import lombok.extern.jackson.Jacksonized; - -import java.math.BigDecimal; -import java.time.Instant; +import org.knowm.xchange.currency.CurrencyPair; +import org.knowm.xchange.gateio.config.CurrencyPairToStringConverter; +import org.knowm.xchange.gateio.config.StringToCurrencyPairConverter; @Data @Builder @@ -32,7 +36,9 @@ public class GateioOrder { String status; @JsonProperty("currency_pair") - String currencyPair; + @JsonDeserialize(converter = StringToCurrencyPairConverter.class) + @JsonSerialize(converter = CurrencyPairToStringConverter.class) + CurrencyPair currencyPair; @JsonProperty("type") String type; diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioTicker.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioTicker.java index 639eaf5e05d..0efc4b9bf7f 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioTicker.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioTicker.java @@ -1,12 +1,14 @@ package org.knowm.xchange.gateio.dto.marketdata; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import java.math.BigDecimal; +import java.time.Instant; import lombok.Builder; import lombok.Data; import lombok.extern.jackson.Jacksonized; - -import java.math.BigDecimal; -import java.time.Instant; +import org.knowm.xchange.currency.CurrencyPair; +import org.knowm.xchange.gateio.config.StringToCurrencyPairConverter; @Data @Builder @@ -14,7 +16,8 @@ public class GateioTicker { @JsonProperty("currency_pair") - String currencyPair; + @JsonDeserialize(converter = StringToCurrencyPairConverter.class) + CurrencyPair currencyPair; @JsonProperty("last") BigDecimal lastPrice; diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/GateioUserTrade.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/GateioUserTrade.java index 591583e362d..6a9aae0444b 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/GateioUserTrade.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/GateioUserTrade.java @@ -8,8 +8,10 @@ import lombok.Data; import lombok.extern.jackson.Jacksonized; import org.knowm.xchange.currency.Currency; +import org.knowm.xchange.currency.CurrencyPair; import org.knowm.xchange.gateio.config.DoubleToInstantConverter; import org.knowm.xchange.gateio.config.StringToCurrencyConverter; +import org.knowm.xchange.gateio.config.StringToCurrencyPairConverter; import org.knowm.xchange.gateio.config.TimestampSecondsToInstantConverter; @Data @@ -29,7 +31,8 @@ public class GateioUserTrade { private Instant timeMs; @JsonProperty("currency_pair") - String currencyPair; + @JsonDeserialize(converter = StringToCurrencyPairConverter.class) + CurrencyPair currencyPair; @JsonProperty("side") private String side; diff --git a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioTradeServiceRawTest.java b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioTradeServiceRawTest.java index 48b586c9fe5..15251f7446d 100644 --- a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioTradeServiceRawTest.java +++ b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioTradeServiceRawTest.java @@ -18,7 +18,7 @@ class GateioTradeServiceRawTest extends GateioExchangeWiremock { GateioOrder sampleMarketOrder = GateioOrder.builder() .id("342251629898") - .currencyPair("BTC_USDT") + .currencyPair(CurrencyPair.BTC_USDT) .clientOrderId("t-valid-market-buy-order") .amendText("-") .type("market") @@ -62,7 +62,7 @@ void listOrders() throws IOException { @Test void valid_market_buy_order() throws IOException { GateioOrder gateioOrder = GateioOrder.builder() - .currencyPair("BTC_USDT") + .currencyPair(CurrencyPair.BTC_USDT) .clientOrderId("t-valid-market-buy-order") .type("market") .account("spot") @@ -80,7 +80,7 @@ void valid_market_buy_order() throws IOException { @Test void valid_market_sell_order() throws IOException { GateioOrder gateioOrder = GateioOrder.builder() - .currencyPair("BTC_USDT") + .currencyPair(CurrencyPair.BTC_USDT) .clientOrderId("t-valid-market-sell-order") .type("market") .account("spot") @@ -94,7 +94,7 @@ void valid_market_sell_order() throws IOException { GateioOrder expectedResponse = GateioOrder.builder() .id("342260949533") - .currencyPair("BTC_USDT") + .currencyPair(CurrencyPair.BTC_USDT) .clientOrderId("t-valid-market-sell-order") .amendText("-") .type("market") From ca2f8a61ac3207308d75708fcc62a3d2c90e7e89 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Sun, 13 Aug 2023 01:00:57 +0200 Subject: [PATCH 089/159] [gateio-v4] Add enum for deposit record status --- .../dto/account/GateioDepositRecord.java | 26 ++++++++++++++++++- .../service/GateioAccountServiceRawTest.java | 3 ++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioDepositRecord.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioDepositRecord.java index e4e6400b16b..ec98e2456ef 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioDepositRecord.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioDepositRecord.java @@ -4,8 +4,10 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import java.math.BigDecimal; import java.time.Instant; +import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; +import lombok.Getter; import lombok.extern.jackson.Jacksonized; import org.knowm.xchange.currency.Currency; import org.knowm.xchange.gateio.config.StringToCurrencyConverter; @@ -43,9 +45,31 @@ public class GateioDepositRecord { String tag; @JsonProperty("status") - String status; + Status status; @JsonProperty("chain") String chain; + + @Getter + @AllArgsConstructor + public static enum Status { + DONE("done"), + CANCEL("cancelled"), + REQUEST("requesting"), + MANUAL("pending manual approval"), + BCODE("GateCode operation"), + EXTPEND("pending confirm after sending"), + FAIL("pending confirm when fail"), + INVALID("invalid order"), + VERIFY("verifying"), + PROCES("processing"), + PEND("pending"), + DMOVE("required manual approval"), + SPLITPEND("the order is automatically split due to large amount"); + + private final String description; + + } + } diff --git a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceRawTest.java b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceRawTest.java index f75e699baae..02f2b49e320 100644 --- a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceRawTest.java +++ b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceRawTest.java @@ -19,6 +19,7 @@ import org.knowm.xchange.gateio.dto.account.GateioDepositAddress; import org.knowm.xchange.gateio.dto.account.GateioDepositAddress.MultichainAddress; import org.knowm.xchange.gateio.dto.account.GateioDepositRecord; +import org.knowm.xchange.gateio.dto.account.GateioDepositRecord.Status; import org.knowm.xchange.gateio.dto.account.GateioSubAccountTransfer; import org.knowm.xchange.gateio.dto.account.GateioWithdrawStatus; import org.knowm.xchange.gateio.dto.account.GateioWithdrawalRecord; @@ -162,7 +163,7 @@ void deposit_records() throws IOException { .txId("0x34a89edf400a85a9a6a2747ebc2074ef65895345b9b7400f164602085e9b4a2e") .chain("OMN") .createdAt(Instant.parse("2023-07-01T14:12:26Z")) - .status("DONE") + .status(Status.DONE) .tag("") .build(); From 38e21474aab008132689d57a221aaeba8663df15 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Sun, 13 Aug 2023 16:02:09 +0200 Subject: [PATCH 090/159] [gateio-v4] Improve type parsing of FundingRecord --- .../knowm/xchange/gateio/GateioAdapters.java | 5 ++--- .../dto/account/GateioAccountBookRecord.java | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java index 7a94c00fbbc..78f183a7e68 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java @@ -11,7 +11,6 @@ import org.knowm.xchange.dto.Order.OrderStatus; import org.knowm.xchange.dto.Order.OrderType; import org.knowm.xchange.dto.account.FundingRecord; -import org.knowm.xchange.dto.account.FundingRecord.Type; import org.knowm.xchange.dto.marketdata.OrderBook; import org.knowm.xchange.dto.marketdata.Ticker; import org.knowm.xchange.dto.meta.InstrumentMetaData; @@ -234,9 +233,9 @@ public FundingRecord toFundingRecords(GateioAccountBookRecord gateioAccountBookR .setDate(Date.from(gateioAccountBookRecord.getTimestamp())) .setCurrency(gateioAccountBookRecord.getCurrency()) .setBalance(gateioAccountBookRecord.getBalance()) - .setType(gateioAccountBookRecord.getChange().signum() > 0 ? Type.OTHER_INFLOW : Type.OTHER_OUTFLOW) + .setType(gateioAccountBookRecord.getType()) .setAmount(gateioAccountBookRecord.getChange().abs()) - .setDescription(gateioAccountBookRecord.getType()) + .setDescription(gateioAccountBookRecord.getTypeDescription()) .build(); } } diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioAccountBookRecord.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioAccountBookRecord.java index 220b60aba54..c7d455c33ed 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioAccountBookRecord.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioAccountBookRecord.java @@ -8,6 +8,8 @@ import lombok.Data; import lombok.extern.jackson.Jacksonized; import org.knowm.xchange.currency.Currency; +import org.knowm.xchange.dto.account.FundingRecord; +import org.knowm.xchange.dto.account.FundingRecord.Type; import org.knowm.xchange.gateio.config.StringToCurrencyConverter; @Data @@ -32,6 +34,19 @@ public class GateioAccountBookRecord { BigDecimal balance; @JsonProperty("type") - String type; + String typeDescription; + + + public FundingRecord.Type getType() { + switch (typeDescription) { + case "withdraw": + return Type.WITHDRAWAL; + case "deposit": + return Type.DEPOSIT; + default: + return change.signum() > 0 ? Type.OTHER_INFLOW : Type.OTHER_OUTFLOW; + } + } + } From d5669b0ac330d900d3e1b3f60acc413bae17390b Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Sun, 13 Aug 2023 16:25:28 +0200 Subject: [PATCH 091/159] [gateio-v4] Improve type parsing --- .../knowm/xchange/gateio/GateioAdapters.java | 40 +++---------------- .../config/OrderTypeToStringConverter.java | 22 ++++++++++ .../config/StringToOrderTypeConverter.java | 22 ++++++++++ .../gateio/dto/account/GateioOrder.java | 7 +++- .../dto/account/GateioWithdrawalRequest.java | 3 +- .../dto/marketdata/GateioCurrencyInfo.java | 2 +- .../gateio/dto/trade/GateioUserTrade.java | 12 ++++-- .../service/GateioMarketDataService.java | 2 +- .../service/GateioAccountServiceRawTest.java | 2 +- .../GateioMarketDataServiceRawTest.java | 2 +- .../service/GateioTradeServiceRawTest.java | 9 +++-- 11 files changed, 75 insertions(+), 48 deletions(-) create mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/OrderTypeToStringConverter.java create mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/StringToOrderTypeConverter.java diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java index 78f183a7e68..a2a36b3e3eb 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java @@ -5,7 +5,6 @@ import java.util.Locale; import java.util.stream.Collectors; import lombok.experimental.UtilityClass; -import org.knowm.xchange.currency.Currency; import org.knowm.xchange.currency.CurrencyPair; import org.knowm.xchange.dto.Order; import org.knowm.xchange.dto.Order.OrderStatus; @@ -32,11 +31,6 @@ public class GateioAdapters { - public String toString(Currency currency) { - return currency.getCurrencyCode(); - } - - public String toString(Instrument instrument) { if (instrument == null) { return null; @@ -105,7 +99,7 @@ public OrderStatus toOrderStatus(String gateioOrderStatus) { public GateioOrder toGateioOrder(MarketOrder marketOrder) { return GateioOrder.builder() .currencyPair((CurrencyPair) marketOrder.getInstrument()) - .side(toString(marketOrder.getType())) + .side(marketOrder.getType()) .clientOrderId(marketOrder.getUserReference()) .account("spot") .type("market") @@ -118,7 +112,7 @@ public GateioOrder toGateioOrder(MarketOrder marketOrder) { public GateioOrder toGateioOrder(LimitOrder limitOrder) { return GateioOrder.builder() .currencyPair((CurrencyPair) limitOrder.getInstrument()) - .side(toString(limitOrder.getType())) + .side(limitOrder.getType()) .clientOrderId(limitOrder.getUserReference()) .account("spot") .type("limit") @@ -132,7 +126,7 @@ public GateioOrder toGateioOrder(LimitOrder limitOrder) { public Order toOrder(GateioOrder gateioOrder) { Order.Builder order; Instrument instrument = gateioOrder.getCurrencyPair(); - OrderType orderType = toOrderType(gateioOrder.getSide()); + OrderType orderType = gateioOrder.getSide(); switch (gateioOrder.getType()) { case "market": @@ -166,7 +160,7 @@ public UserTrade toUserTrade(GateioUserTrade gateioUserTrade) { .feeAmount(gateioUserTrade.getFee()) .feeCurrency(gateioUserTrade.getFeeCurrency()) .orderUserReference(gateioUserTrade.getRemark()) - .type(toOrderType(gateioUserTrade.getSide())) + .type(gateioUserTrade.getSide()) .instrument(gateioUserTrade.getCurrencyPair()) .price(gateioUserTrade.getPrice()) .timestamp(Date.from(gateioUserTrade.getTimeMs())) @@ -175,30 +169,6 @@ public UserTrade toUserTrade(GateioUserTrade gateioUserTrade) { } - public String toString(OrderType orderType) { - switch (orderType) { - case BID: - return "buy"; - case ASK: - return "sell"; - default: - throw new IllegalArgumentException("Can't map " + orderType); - } - } - - - public OrderType toOrderType(String gateioOrderType) { - switch (gateioOrderType) { - case "buy": - return OrderType.BID; - case "sell": - return OrderType.ASK; - default: - throw new IllegalArgumentException("Can't map " + gateioOrderType); - } - } - - public GateioWithdrawalRequest toGateioWithdrawalRequest(GateioWithdrawFundsParams p) { return GateioWithdrawalRequest.builder() .clientRecordId(p.getClientRecordId()) @@ -206,7 +176,7 @@ public GateioWithdrawalRequest toGateioWithdrawalRequest(GateioWithdrawFundsPara .tag(p.getAddressTag()) .chain(p.getChain()) .amount(p.getAmount()) - .currency(toString(p.getCurrency())) + .currency(p.getCurrency()) .build(); } diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/OrderTypeToStringConverter.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/OrderTypeToStringConverter.java new file mode 100644 index 00000000000..f7277bc74db --- /dev/null +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/OrderTypeToStringConverter.java @@ -0,0 +1,22 @@ +package org.knowm.xchange.gateio.config; + +import com.fasterxml.jackson.databind.util.StdConverter; +import org.knowm.xchange.dto.Order.OrderType; + +/** + * Converts {@code OrderType} to string + */ +public class OrderTypeToStringConverter extends StdConverter { + + @Override + public String convert(OrderType value) { + switch (value) { + case BID: + return "buy"; + case ASK: + return "sell"; + default: + throw new IllegalArgumentException("Can't map " + value); + } + } +} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/StringToOrderTypeConverter.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/StringToOrderTypeConverter.java new file mode 100644 index 00000000000..ebc3e891a73 --- /dev/null +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/StringToOrderTypeConverter.java @@ -0,0 +1,22 @@ +package org.knowm.xchange.gateio.config; + +import com.fasterxml.jackson.databind.util.StdConverter; +import org.knowm.xchange.dto.Order.OrderType; + +/** + * Converts string to {@code OrderType} + */ +public class StringToOrderTypeConverter extends StdConverter { + + @Override + public OrderType convert(String value) { + switch (value) { + case "buy": + return OrderType.BID; + case "sell": + return OrderType.ASK; + default: + throw new IllegalArgumentException("Can't map " + value); + } + } +} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioOrder.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioOrder.java index f121902d0f5..37521af06f0 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioOrder.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioOrder.java @@ -9,8 +9,11 @@ import lombok.Data; import lombok.extern.jackson.Jacksonized; import org.knowm.xchange.currency.CurrencyPair; +import org.knowm.xchange.dto.Order.OrderType; import org.knowm.xchange.gateio.config.CurrencyPairToStringConverter; +import org.knowm.xchange.gateio.config.OrderTypeToStringConverter; import org.knowm.xchange.gateio.config.StringToCurrencyPairConverter; +import org.knowm.xchange.gateio.config.StringToOrderTypeConverter; @Data @Builder @@ -47,7 +50,9 @@ public class GateioOrder { String account; @JsonProperty("side") - String side; + @JsonDeserialize(converter = StringToOrderTypeConverter.class) + @JsonSerialize(converter = OrderTypeToStringConverter.class) + OrderType side; @JsonProperty("amount") BigDecimal amount; diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioWithdrawalRequest.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioWithdrawalRequest.java index b8c680f1b19..8c4afd3e3d5 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioWithdrawalRequest.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioWithdrawalRequest.java @@ -5,6 +5,7 @@ import lombok.Builder; import lombok.Data; import lombok.extern.jackson.Jacksonized; +import org.knowm.xchange.currency.Currency; @Data @Builder @@ -18,7 +19,7 @@ public class GateioWithdrawalRequest { BigDecimal amount; @JsonProperty("currency") - String currency; + Currency currency; @JsonProperty("address") String address; diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioCurrencyInfo.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioCurrencyInfo.java index 2810aa20199..7a66bda9bcb 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioCurrencyInfo.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioCurrencyInfo.java @@ -11,7 +11,7 @@ public class GateioCurrencyInfo { @JsonProperty("currency") - String currency; + String currencyWithChain; @JsonProperty("delisted") Boolean delisted; diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/GateioUserTrade.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/GateioUserTrade.java index 6a9aae0444b..b844e870f6e 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/GateioUserTrade.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/GateioUserTrade.java @@ -2,6 +2,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; import java.math.BigDecimal; import java.time.Instant; import lombok.Builder; @@ -9,9 +10,12 @@ import lombok.extern.jackson.Jacksonized; import org.knowm.xchange.currency.Currency; import org.knowm.xchange.currency.CurrencyPair; +import org.knowm.xchange.dto.Order.OrderType; import org.knowm.xchange.gateio.config.DoubleToInstantConverter; +import org.knowm.xchange.gateio.config.OrderTypeToStringConverter; import org.knowm.xchange.gateio.config.StringToCurrencyConverter; import org.knowm.xchange.gateio.config.StringToCurrencyPairConverter; +import org.knowm.xchange.gateio.config.StringToOrderTypeConverter; import org.knowm.xchange.gateio.config.TimestampSecondsToInstantConverter; @Data @@ -24,18 +28,20 @@ public class GateioUserTrade { @JsonProperty("create_time") @JsonDeserialize(converter = TimestampSecondsToInstantConverter.class) - private Instant time; + Instant time; @JsonProperty("create_time_ms") @JsonDeserialize(converter = DoubleToInstantConverter.class) - private Instant timeMs; + Instant timeMs; @JsonProperty("currency_pair") @JsonDeserialize(converter = StringToCurrencyPairConverter.class) CurrencyPair currencyPair; @JsonProperty("side") - private String side; + @JsonDeserialize(converter = StringToOrderTypeConverter.class) + @JsonSerialize(converter = OrderTypeToStringConverter.class) + OrderType side; @JsonProperty("role") String role; 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 6b7bc678a22..2fb450e370d 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 @@ -79,7 +79,7 @@ public List getCurrencies() throws IOException { List currencyInfos = getGateioCurrencyInfos(); return currencyInfos.stream() .filter(gateioCurrencyInfo -> !gateioCurrencyInfo.getDelisted()) - .map(o -> StringUtils.removeEnd(o.getCurrency(), "_" + o.getChain())) + .map(o -> StringUtils.removeEnd(o.getCurrencyWithChain(), "_" + o.getChain())) .distinct() .map(Currency::getInstance) .collect(Collectors.toList()); diff --git a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceRawTest.java b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceRawTest.java index 02f2b49e320..c7066f036f2 100644 --- a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceRawTest.java +++ b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceRawTest.java @@ -180,7 +180,7 @@ void withdraw() throws IOException { .tag("") .chain("SOL") .amount(BigDecimal.valueOf(3)) - .currency("USDT") + .currency(Currency.USDT) .build(); GateioWithdrawalRecord actual = gateioAccountServiceRaw.withdraw(gateioWithdrawalRequest); diff --git a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioMarketDataServiceRawTest.java b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioMarketDataServiceRawTest.java index e53f6bbf937..4751a5bb95a 100644 --- a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioMarketDataServiceRawTest.java +++ b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioMarketDataServiceRawTest.java @@ -31,7 +31,7 @@ public void getCurrencies_valid() throws IOException { GateioCurrencyInfo actualBtc = actual.get(0); GateioCurrencyInfo expectedBtc = GateioCurrencyInfo.builder() - .currency("BTC") + .currencyWithChain("BTC") .delisted(false) .withdrawDisabled(false) .withdrawDelayed(false) diff --git a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioTradeServiceRawTest.java b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioTradeServiceRawTest.java index 15251f7446d..2c1c24fc8e2 100644 --- a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioTradeServiceRawTest.java +++ b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioTradeServiceRawTest.java @@ -9,6 +9,7 @@ import org.junit.jupiter.api.Test; import org.knowm.xchange.currency.CurrencyPair; import org.knowm.xchange.dto.Order.OrderStatus; +import org.knowm.xchange.dto.Order.OrderType; import org.knowm.xchange.gateio.GateioExchangeWiremock; import org.knowm.xchange.gateio.dto.account.GateioOrder; @@ -23,7 +24,7 @@ class GateioTradeServiceRawTest extends GateioExchangeWiremock { .amendText("-") .type("market") .account("spot") - .side("buy") + .side(OrderType.BID) .timeInForce("ioc") .amount(BigDecimal.valueOf(20)) .createdAt(Instant.parse("2023-06-03T22:07:38.451Z")) @@ -66,7 +67,7 @@ void valid_market_buy_order() throws IOException { .clientOrderId("t-valid-market-buy-order") .type("market") .account("spot") - .side("buy") + .side(OrderType.BID) .timeInForce("ioc") .amount(BigDecimal.valueOf(20)) .build(); @@ -84,7 +85,7 @@ void valid_market_sell_order() throws IOException { .clientOrderId("t-valid-market-sell-order") .type("market") .account("spot") - .side("sell") + .side(OrderType.ASK) .timeInForce("ioc") .amount(new BigDecimal("0.0007")) .build(); @@ -99,7 +100,7 @@ void valid_market_sell_order() throws IOException { .amendText("-") .type("market") .account("spot") - .side("sell") + .side(OrderType.ASK) .timeInForce("ioc") .amount(new BigDecimal("0.0007")) .createdAt(Instant.parse("2023-06-03T22:33:21.743Z")) From 0c3e7743d36b6ea43d386909ecad02640d27dfa2 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Sun, 13 Aug 2023 16:26:14 +0200 Subject: [PATCH 092/159] [gateio-v4] Move converters to separate package --- .../CurrencyPairToStringConverter.java | 2 +- .../{ => converter}/DoubleToInstantConverter.java | 2 +- .../{ => converter}/OrderTypeToStringConverter.java | 2 +- .../{ => converter}/StringToBooleanConverter.java | 2 +- .../{ => converter}/StringToCurrencyConverter.java | 2 +- .../StringToCurrencyPairConverter.java | 2 +- .../{ => converter}/StringToOrderTypeConverter.java | 2 +- .../TimestampSecondsToInstantConverter.java | 2 +- .../gateio/dto/account/GateioAccountBookRecord.java | 2 +- .../gateio/dto/account/GateioAddressRecord.java | 4 ++-- .../gateio/dto/account/GateioCurrencyBalance.java | 2 +- .../gateio/dto/account/GateioDepositAddress.java | 2 +- .../gateio/dto/account/GateioDepositRecord.java | 4 ++-- .../xchange/gateio/dto/account/GateioOrder.java | 8 ++++---- .../gateio/dto/account/GateioSubAccountTransfer.java | 4 ++-- .../gateio/dto/account/GateioWithdrawStatus.java | 2 +- .../gateio/dto/account/GateioWithdrawalRecord.java | 4 ++-- .../dto/marketdata/GateioCurrencyPairDetails.java | 2 +- .../xchange/gateio/dto/marketdata/GateioTicker.java | 2 +- .../xchange/gateio/dto/trade/GateioUserTrade.java | 12 ++++++------ 20 files changed, 32 insertions(+), 32 deletions(-) rename xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/{ => converter}/CurrencyPairToStringConverter.java (87%) rename xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/{ => converter}/DoubleToInstantConverter.java (87%) rename xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/{ => converter}/OrderTypeToStringConverter.java (90%) rename xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/{ => converter}/StringToBooleanConverter.java (85%) rename xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/{ => converter}/StringToCurrencyConverter.java (86%) rename xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/{ => converter}/StringToCurrencyPairConverter.java (87%) rename xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/{ => converter}/StringToOrderTypeConverter.java (90%) rename xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/{ => converter}/TimestampSecondsToInstantConverter.java (86%) diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/CurrencyPairToStringConverter.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/converter/CurrencyPairToStringConverter.java similarity index 87% rename from xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/CurrencyPairToStringConverter.java rename to xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/converter/CurrencyPairToStringConverter.java index d9186c49cd2..de64a9e0dab 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/CurrencyPairToStringConverter.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/converter/CurrencyPairToStringConverter.java @@ -1,4 +1,4 @@ -package org.knowm.xchange.gateio.config; +package org.knowm.xchange.gateio.config.converter; import com.fasterxml.jackson.databind.util.StdConverter; import org.knowm.xchange.currency.CurrencyPair; diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/DoubleToInstantConverter.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/converter/DoubleToInstantConverter.java similarity index 87% rename from xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/DoubleToInstantConverter.java rename to xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/converter/DoubleToInstantConverter.java index 8e2bd855bc9..fe2a7078702 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/DoubleToInstantConverter.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/converter/DoubleToInstantConverter.java @@ -1,4 +1,4 @@ -package org.knowm.xchange.gateio.config; +package org.knowm.xchange.gateio.config.converter; import com.fasterxml.jackson.databind.util.StdConverter; import java.time.Instant; diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/OrderTypeToStringConverter.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/converter/OrderTypeToStringConverter.java similarity index 90% rename from xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/OrderTypeToStringConverter.java rename to xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/converter/OrderTypeToStringConverter.java index f7277bc74db..9fa46e700eb 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/OrderTypeToStringConverter.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/converter/OrderTypeToStringConverter.java @@ -1,4 +1,4 @@ -package org.knowm.xchange.gateio.config; +package org.knowm.xchange.gateio.config.converter; import com.fasterxml.jackson.databind.util.StdConverter; import org.knowm.xchange.dto.Order.OrderType; diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/StringToBooleanConverter.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/converter/StringToBooleanConverter.java similarity index 85% rename from xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/StringToBooleanConverter.java rename to xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/converter/StringToBooleanConverter.java index d70d69376b8..2cb8ae6738a 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/StringToBooleanConverter.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/converter/StringToBooleanConverter.java @@ -1,4 +1,4 @@ -package org.knowm.xchange.gateio.config; +package org.knowm.xchange.gateio.config.converter; import com.fasterxml.jackson.databind.util.StdConverter; diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/StringToCurrencyConverter.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/converter/StringToCurrencyConverter.java similarity index 86% rename from xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/StringToCurrencyConverter.java rename to xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/converter/StringToCurrencyConverter.java index 52d8c7cc2e7..a6445b19cbb 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/StringToCurrencyConverter.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/converter/StringToCurrencyConverter.java @@ -1,4 +1,4 @@ -package org.knowm.xchange.gateio.config; +package org.knowm.xchange.gateio.config.converter; import com.fasterxml.jackson.databind.util.StdConverter; import org.knowm.xchange.currency.Currency; diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/StringToCurrencyPairConverter.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/converter/StringToCurrencyPairConverter.java similarity index 87% rename from xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/StringToCurrencyPairConverter.java rename to xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/converter/StringToCurrencyPairConverter.java index 5b2aec7027a..a9b4cf104de 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/StringToCurrencyPairConverter.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/converter/StringToCurrencyPairConverter.java @@ -1,4 +1,4 @@ -package org.knowm.xchange.gateio.config; +package org.knowm.xchange.gateio.config.converter; import com.fasterxml.jackson.databind.util.StdConverter; import org.knowm.xchange.currency.CurrencyPair; diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/StringToOrderTypeConverter.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/converter/StringToOrderTypeConverter.java similarity index 90% rename from xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/StringToOrderTypeConverter.java rename to xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/converter/StringToOrderTypeConverter.java index ebc3e891a73..418888c54c0 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/StringToOrderTypeConverter.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/converter/StringToOrderTypeConverter.java @@ -1,4 +1,4 @@ -package org.knowm.xchange.gateio.config; +package org.knowm.xchange.gateio.config.converter; import com.fasterxml.jackson.databind.util.StdConverter; import org.knowm.xchange.dto.Order.OrderType; diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/TimestampSecondsToInstantConverter.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/converter/TimestampSecondsToInstantConverter.java similarity index 86% rename from xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/TimestampSecondsToInstantConverter.java rename to xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/converter/TimestampSecondsToInstantConverter.java index dcfe7c020c7..a4142f1f0ae 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/TimestampSecondsToInstantConverter.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/converter/TimestampSecondsToInstantConverter.java @@ -1,4 +1,4 @@ -package org.knowm.xchange.gateio.config; +package org.knowm.xchange.gateio.config.converter; import com.fasterxml.jackson.databind.util.StdConverter; import java.time.Instant; diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioAccountBookRecord.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioAccountBookRecord.java index c7d455c33ed..47f6ce16e8f 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioAccountBookRecord.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioAccountBookRecord.java @@ -10,7 +10,7 @@ import org.knowm.xchange.currency.Currency; import org.knowm.xchange.dto.account.FundingRecord; import org.knowm.xchange.dto.account.FundingRecord.Type; -import org.knowm.xchange.gateio.config.StringToCurrencyConverter; +import org.knowm.xchange.gateio.config.converter.StringToCurrencyConverter; @Data @Builder diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioAddressRecord.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioAddressRecord.java index 6726d977542..029fe1f9556 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioAddressRecord.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioAddressRecord.java @@ -6,8 +6,8 @@ import lombok.Data; import lombok.extern.jackson.Jacksonized; import org.knowm.xchange.currency.Currency; -import org.knowm.xchange.gateio.config.StringToBooleanConverter; -import org.knowm.xchange.gateio.config.StringToCurrencyConverter; +import org.knowm.xchange.gateio.config.converter.StringToBooleanConverter; +import org.knowm.xchange.gateio.config.converter.StringToCurrencyConverter; @Data @Builder diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioCurrencyBalance.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioCurrencyBalance.java index 065cf01560f..0b15a5a8d24 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioCurrencyBalance.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioCurrencyBalance.java @@ -7,7 +7,7 @@ import lombok.Data; import lombok.extern.jackson.Jacksonized; import org.knowm.xchange.currency.Currency; -import org.knowm.xchange.gateio.config.StringToCurrencyConverter; +import org.knowm.xchange.gateio.config.converter.StringToCurrencyConverter; @Data @Builder diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioDepositAddress.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioDepositAddress.java index 834780ece27..25eaf92343d 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioDepositAddress.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioDepositAddress.java @@ -7,7 +7,7 @@ import lombok.Data; import lombok.extern.jackson.Jacksonized; import org.knowm.xchange.currency.Currency; -import org.knowm.xchange.gateio.config.StringToCurrencyConverter; +import org.knowm.xchange.gateio.config.converter.StringToCurrencyConverter; @Data @Builder diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioDepositRecord.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioDepositRecord.java index ec98e2456ef..bc039679da2 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioDepositRecord.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioDepositRecord.java @@ -10,8 +10,8 @@ import lombok.Getter; import lombok.extern.jackson.Jacksonized; import org.knowm.xchange.currency.Currency; -import org.knowm.xchange.gateio.config.StringToCurrencyConverter; -import org.knowm.xchange.gateio.config.TimestampSecondsToInstantConverter; +import org.knowm.xchange.gateio.config.converter.StringToCurrencyConverter; +import org.knowm.xchange.gateio.config.converter.TimestampSecondsToInstantConverter; @Data @Builder diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioOrder.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioOrder.java index 37521af06f0..9d1dd4154c5 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioOrder.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioOrder.java @@ -10,10 +10,10 @@ import lombok.extern.jackson.Jacksonized; import org.knowm.xchange.currency.CurrencyPair; import org.knowm.xchange.dto.Order.OrderType; -import org.knowm.xchange.gateio.config.CurrencyPairToStringConverter; -import org.knowm.xchange.gateio.config.OrderTypeToStringConverter; -import org.knowm.xchange.gateio.config.StringToCurrencyPairConverter; -import org.knowm.xchange.gateio.config.StringToOrderTypeConverter; +import org.knowm.xchange.gateio.config.converter.CurrencyPairToStringConverter; +import org.knowm.xchange.gateio.config.converter.OrderTypeToStringConverter; +import org.knowm.xchange.gateio.config.converter.StringToCurrencyPairConverter; +import org.knowm.xchange.gateio.config.converter.StringToOrderTypeConverter; @Data @Builder diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioSubAccountTransfer.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioSubAccountTransfer.java index 6cc6666275d..f8a203174ff 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioSubAccountTransfer.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioSubAccountTransfer.java @@ -8,8 +8,8 @@ import lombok.Data; import lombok.extern.jackson.Jacksonized; import org.knowm.xchange.currency.Currency; -import org.knowm.xchange.gateio.config.StringToCurrencyConverter; -import org.knowm.xchange.gateio.config.TimestampSecondsToInstantConverter; +import org.knowm.xchange.gateio.config.converter.StringToCurrencyConverter; +import org.knowm.xchange.gateio.config.converter.TimestampSecondsToInstantConverter; @Data @Builder diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioWithdrawStatus.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioWithdrawStatus.java index 24d0ecbf441..befd5c281e8 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioWithdrawStatus.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioWithdrawStatus.java @@ -9,7 +9,7 @@ import lombok.extern.jackson.Jacksonized; import org.apache.commons.lang3.StringUtils; import org.knowm.xchange.currency.Currency; -import org.knowm.xchange.gateio.config.StringToCurrencyConverter; +import org.knowm.xchange.gateio.config.converter.StringToCurrencyConverter; @Data @Builder diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioWithdrawalRecord.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioWithdrawalRecord.java index 36e6cf2b549..39e153ecdb1 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioWithdrawalRecord.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioWithdrawalRecord.java @@ -8,8 +8,8 @@ import lombok.Data; import lombok.extern.jackson.Jacksonized; import org.knowm.xchange.currency.Currency; -import org.knowm.xchange.gateio.config.StringToCurrencyConverter; -import org.knowm.xchange.gateio.config.TimestampSecondsToInstantConverter; +import org.knowm.xchange.gateio.config.converter.StringToCurrencyConverter; +import org.knowm.xchange.gateio.config.converter.TimestampSecondsToInstantConverter; @Data @Builder diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioCurrencyPairDetails.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioCurrencyPairDetails.java index bfa24aa3144..d3438f52240 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioCurrencyPairDetails.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioCurrencyPairDetails.java @@ -7,7 +7,7 @@ import lombok.Builder; import lombok.Data; import lombok.extern.jackson.Jacksonized; -import org.knowm.xchange.gateio.config.TimestampSecondsToInstantConverter; +import org.knowm.xchange.gateio.config.converter.TimestampSecondsToInstantConverter; @Data @Builder diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioTicker.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioTicker.java index 0efc4b9bf7f..209a3e1bca9 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioTicker.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioTicker.java @@ -8,7 +8,7 @@ import lombok.Data; import lombok.extern.jackson.Jacksonized; import org.knowm.xchange.currency.CurrencyPair; -import org.knowm.xchange.gateio.config.StringToCurrencyPairConverter; +import org.knowm.xchange.gateio.config.converter.StringToCurrencyPairConverter; @Data @Builder diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/GateioUserTrade.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/GateioUserTrade.java index b844e870f6e..aebb1c128d6 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/GateioUserTrade.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/GateioUserTrade.java @@ -11,12 +11,12 @@ import org.knowm.xchange.currency.Currency; import org.knowm.xchange.currency.CurrencyPair; import org.knowm.xchange.dto.Order.OrderType; -import org.knowm.xchange.gateio.config.DoubleToInstantConverter; -import org.knowm.xchange.gateio.config.OrderTypeToStringConverter; -import org.knowm.xchange.gateio.config.StringToCurrencyConverter; -import org.knowm.xchange.gateio.config.StringToCurrencyPairConverter; -import org.knowm.xchange.gateio.config.StringToOrderTypeConverter; -import org.knowm.xchange.gateio.config.TimestampSecondsToInstantConverter; +import org.knowm.xchange.gateio.config.converter.DoubleToInstantConverter; +import org.knowm.xchange.gateio.config.converter.OrderTypeToStringConverter; +import org.knowm.xchange.gateio.config.converter.StringToCurrencyConverter; +import org.knowm.xchange.gateio.config.converter.StringToCurrencyPairConverter; +import org.knowm.xchange.gateio.config.converter.StringToOrderTypeConverter; +import org.knowm.xchange.gateio.config.converter.TimestampSecondsToInstantConverter; @Data @Builder From 0e1fe8fcc1052aaad225df091c7a01ce43001cb8 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Sun, 13 Aug 2023 16:26:42 +0200 Subject: [PATCH 093/159] [gateio-streaming] Move converters to separate package --- .../{ => converter}/CurrencyPairToStringConverter.java | 2 +- .../config/{ => converter}/DoubleToInstantConverter.java | 2 +- .../{ => converter}/InstantToTimestampSecondsConverter.java | 2 +- .../{ => converter}/StringToCurrencyPairConverter.java | 2 +- .../{ => converter}/TimestampSecondsToInstantConverter.java | 2 +- .../gateio/dto/request/GateioWebSocketRequest.java | 4 ++-- .../request/payload/CurrencyPairLevelIntervalPayload.java | 2 +- .../gateio/dto/request/payload/CurrencyPairPayload.java | 2 +- .../gateio/dto/response/GateioWebSocketNotification.java | 2 +- .../gateio/dto/response/balance/BalanceDTO.java | 2 +- .../gateio/dto/response/orderbook/OrderBookDTO.java | 2 +- .../xchangestream/gateio/dto/response/ticker/TickerDTO.java | 2 +- .../xchangestream/gateio/dto/response/trade/TradeDTO.java | 6 +++--- .../gateio/dto/response/usertrade/UserTradeDTO.java | 6 +++--- 14 files changed, 19 insertions(+), 19 deletions(-) rename xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/{ => converter}/CurrencyPairToStringConverter.java (85%) rename xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/{ => converter}/DoubleToInstantConverter.java (85%) rename xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/{ => converter}/InstantToTimestampSecondsConverter.java (84%) rename xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/{ => converter}/StringToCurrencyPairConverter.java (85%) rename xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/{ => converter}/TimestampSecondsToInstantConverter.java (84%) diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/CurrencyPairToStringConverter.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/converter/CurrencyPairToStringConverter.java similarity index 85% rename from xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/CurrencyPairToStringConverter.java rename to xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/converter/CurrencyPairToStringConverter.java index 43f6cb79ed0..1e5a550c2b7 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/CurrencyPairToStringConverter.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/converter/CurrencyPairToStringConverter.java @@ -1,4 +1,4 @@ -package info.bitrich.xchangestream.gateio.config; +package info.bitrich.xchangestream.gateio.config.converter; import com.fasterxml.jackson.databind.util.StdConverter; import org.knowm.xchange.currency.CurrencyPair; diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/DoubleToInstantConverter.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/converter/DoubleToInstantConverter.java similarity index 85% rename from xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/DoubleToInstantConverter.java rename to xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/converter/DoubleToInstantConverter.java index 49069f6542e..3a9c8f512be 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/DoubleToInstantConverter.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/converter/DoubleToInstantConverter.java @@ -1,4 +1,4 @@ -package info.bitrich.xchangestream.gateio.config; +package info.bitrich.xchangestream.gateio.config.converter; import com.fasterxml.jackson.databind.util.StdConverter; import java.time.Instant; diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/InstantToTimestampSecondsConverter.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/converter/InstantToTimestampSecondsConverter.java similarity index 84% rename from xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/InstantToTimestampSecondsConverter.java rename to xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/converter/InstantToTimestampSecondsConverter.java index f0a1a37479a..ff5e75d0a39 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/InstantToTimestampSecondsConverter.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/converter/InstantToTimestampSecondsConverter.java @@ -1,4 +1,4 @@ -package info.bitrich.xchangestream.gateio.config; +package info.bitrich.xchangestream.gateio.config.converter; import com.fasterxml.jackson.databind.util.StdConverter; import java.time.Instant; diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/StringToCurrencyPairConverter.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/converter/StringToCurrencyPairConverter.java similarity index 85% rename from xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/StringToCurrencyPairConverter.java rename to xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/converter/StringToCurrencyPairConverter.java index feb7a493e38..a0afaa1aa5f 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/StringToCurrencyPairConverter.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/converter/StringToCurrencyPairConverter.java @@ -1,4 +1,4 @@ -package info.bitrich.xchangestream.gateio.config; +package info.bitrich.xchangestream.gateio.config.converter; import com.fasterxml.jackson.databind.util.StdConverter; import org.knowm.xchange.currency.CurrencyPair; diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/TimestampSecondsToInstantConverter.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/converter/TimestampSecondsToInstantConverter.java similarity index 84% rename from xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/TimestampSecondsToInstantConverter.java rename to xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/converter/TimestampSecondsToInstantConverter.java index 5a5aad0da10..f09a7be9caa 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/TimestampSecondsToInstantConverter.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/converter/TimestampSecondsToInstantConverter.java @@ -1,4 +1,4 @@ -package info.bitrich.xchangestream.gateio.config; +package info.bitrich.xchangestream.gateio.config.converter; import com.fasterxml.jackson.databind.util.StdConverter; import java.time.Instant; diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/request/GateioWebSocketRequest.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/request/GateioWebSocketRequest.java index eefd9cd1f3e..ce774ceec67 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/request/GateioWebSocketRequest.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/request/GateioWebSocketRequest.java @@ -4,8 +4,8 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonSerialize; -import info.bitrich.xchangestream.gateio.config.InstantToTimestampSecondsConverter; -import info.bitrich.xchangestream.gateio.config.TimestampSecondsToInstantConverter; +import info.bitrich.xchangestream.gateio.config.converter.InstantToTimestampSecondsConverter; +import info.bitrich.xchangestream.gateio.config.converter.TimestampSecondsToInstantConverter; import info.bitrich.xchangestream.gateio.dto.Event; import java.time.Instant; import lombok.Data; diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/request/payload/CurrencyPairLevelIntervalPayload.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/request/payload/CurrencyPairLevelIntervalPayload.java index e42f8c06a28..c2fa9e216cb 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/request/payload/CurrencyPairLevelIntervalPayload.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/request/payload/CurrencyPairLevelIntervalPayload.java @@ -4,7 +4,7 @@ import com.fasterxml.jackson.annotation.JsonFormat.Shape; import com.fasterxml.jackson.annotation.JsonGetter; import com.fasterxml.jackson.databind.annotation.JsonSerialize; -import info.bitrich.xchangestream.gateio.config.CurrencyPairToStringConverter; +import info.bitrich.xchangestream.gateio.config.converter.CurrencyPairToStringConverter; import java.time.Duration; import lombok.Data; import lombok.experimental.SuperBuilder; diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/request/payload/CurrencyPairPayload.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/request/payload/CurrencyPairPayload.java index 32b6436a69f..2992f6129c3 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/request/payload/CurrencyPairPayload.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/request/payload/CurrencyPairPayload.java @@ -1,7 +1,7 @@ package info.bitrich.xchangestream.gateio.dto.request.payload; import com.fasterxml.jackson.databind.annotation.JsonSerialize; -import info.bitrich.xchangestream.gateio.config.CurrencyPairToStringConverter; +import info.bitrich.xchangestream.gateio.config.converter.CurrencyPairToStringConverter; import lombok.Data; import lombok.experimental.SuperBuilder; import lombok.extern.jackson.Jacksonized; diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/GateioWebSocketNotification.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/GateioWebSocketNotification.java index 3151a7a9d42..0d201fff030 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/GateioWebSocketNotification.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/GateioWebSocketNotification.java @@ -6,7 +6,7 @@ import com.fasterxml.jackson.annotation.JsonTypeInfo; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import info.bitrich.xchangestream.gateio.config.Config; -import info.bitrich.xchangestream.gateio.config.TimestampSecondsToInstantConverter; +import info.bitrich.xchangestream.gateio.config.converter.TimestampSecondsToInstantConverter; import info.bitrich.xchangestream.gateio.dto.Event; import info.bitrich.xchangestream.gateio.dto.response.balance.GateioMultipleSpotBalanceNotification; import info.bitrich.xchangestream.gateio.dto.response.orderbook.GateioOrderBookNotification; diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/balance/BalanceDTO.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/balance/BalanceDTO.java index f5639b8d27e..fdc9d7873d1 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/balance/BalanceDTO.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/balance/BalanceDTO.java @@ -2,7 +2,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import info.bitrich.xchangestream.gateio.config.TimestampSecondsToInstantConverter; +import info.bitrich.xchangestream.gateio.config.converter.TimestampSecondsToInstantConverter; import java.math.BigDecimal; import java.time.Instant; import lombok.Data; diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/orderbook/OrderBookDTO.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/orderbook/OrderBookDTO.java index a6c9deb0546..992cd92c611 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/orderbook/OrderBookDTO.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/orderbook/OrderBookDTO.java @@ -3,7 +3,7 @@ import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import info.bitrich.xchangestream.gateio.config.StringToCurrencyPairConverter; +import info.bitrich.xchangestream.gateio.config.converter.StringToCurrencyPairConverter; import java.math.BigDecimal; import java.time.Instant; import java.util.List; diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/ticker/TickerDTO.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/ticker/TickerDTO.java index f2909d37f84..6568448b758 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/ticker/TickerDTO.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/ticker/TickerDTO.java @@ -2,7 +2,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import info.bitrich.xchangestream.gateio.config.StringToCurrencyPairConverter; +import info.bitrich.xchangestream.gateio.config.converter.StringToCurrencyPairConverter; import java.math.BigDecimal; import lombok.Data; import org.knowm.xchange.currency.CurrencyPair; diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/trade/TradeDTO.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/trade/TradeDTO.java index db39c693a50..0eafb47643e 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/trade/TradeDTO.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/trade/TradeDTO.java @@ -2,9 +2,9 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import info.bitrich.xchangestream.gateio.config.DoubleToInstantConverter; -import info.bitrich.xchangestream.gateio.config.StringToCurrencyPairConverter; -import info.bitrich.xchangestream.gateio.config.TimestampSecondsToInstantConverter; +import info.bitrich.xchangestream.gateio.config.converter.DoubleToInstantConverter; +import info.bitrich.xchangestream.gateio.config.converter.StringToCurrencyPairConverter; +import info.bitrich.xchangestream.gateio.config.converter.TimestampSecondsToInstantConverter; import java.math.BigDecimal; import java.time.Instant; import lombok.Data; diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/usertrade/UserTradeDTO.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/usertrade/UserTradeDTO.java index 153324376c9..f5358080b57 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/usertrade/UserTradeDTO.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/usertrade/UserTradeDTO.java @@ -2,9 +2,9 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import info.bitrich.xchangestream.gateio.config.DoubleToInstantConverter; -import info.bitrich.xchangestream.gateio.config.StringToCurrencyPairConverter; -import info.bitrich.xchangestream.gateio.config.TimestampSecondsToInstantConverter; +import info.bitrich.xchangestream.gateio.config.converter.DoubleToInstantConverter; +import info.bitrich.xchangestream.gateio.config.converter.StringToCurrencyPairConverter; +import info.bitrich.xchangestream.gateio.config.converter.TimestampSecondsToInstantConverter; import java.math.BigDecimal; import java.time.Instant; import lombok.Data; From 706b4c54314fa2bb99cb1f81807f00a48619ca1b Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Sun, 13 Aug 2023 16:33:45 +0200 Subject: [PATCH 094/159] [gateio-streaming] Reference converters from xchange-gateio-v4 --- .../converter/CurrencyPairToStringConverter.java | 15 --------------- .../converter/DoubleToInstantConverter.java | 15 --------------- .../converter/StringToCurrencyPairConverter.java | 15 --------------- .../TimestampSecondsToInstantConverter.java | 15 --------------- .../dto/request/GateioWebSocketRequest.java | 2 +- .../payload/CurrencyPairLevelIntervalPayload.java | 2 +- .../dto/request/payload/CurrencyPairPayload.java | 2 +- .../dto/response/GateioWebSocketNotification.java | 2 +- .../gateio/dto/response/balance/BalanceDTO.java | 2 +- .../dto/response/orderbook/OrderBookDTO.java | 2 +- .../gateio/dto/response/ticker/TickerDTO.java | 2 +- .../gateio/dto/response/trade/TradeDTO.java | 6 +++--- .../dto/response/usertrade/UserTradeDTO.java | 6 +++--- 13 files changed, 13 insertions(+), 73 deletions(-) delete mode 100644 xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/converter/CurrencyPairToStringConverter.java delete mode 100644 xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/converter/DoubleToInstantConverter.java delete mode 100644 xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/converter/StringToCurrencyPairConverter.java delete mode 100644 xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/converter/TimestampSecondsToInstantConverter.java diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/converter/CurrencyPairToStringConverter.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/converter/CurrencyPairToStringConverter.java deleted file mode 100644 index 1e5a550c2b7..00000000000 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/converter/CurrencyPairToStringConverter.java +++ /dev/null @@ -1,15 +0,0 @@ -package info.bitrich.xchangestream.gateio.config.converter; - -import com.fasterxml.jackson.databind.util.StdConverter; -import org.knowm.xchange.currency.CurrencyPair; - -/** - * Converts {@code CurrencyPair} to string - */ -public class CurrencyPairToStringConverter extends StdConverter { - - @Override - public String convert(CurrencyPair value) { - return value.getBase() + "_" + value.getCounter(); - } -} diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/converter/DoubleToInstantConverter.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/converter/DoubleToInstantConverter.java deleted file mode 100644 index 3a9c8f512be..00000000000 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/converter/DoubleToInstantConverter.java +++ /dev/null @@ -1,15 +0,0 @@ -package info.bitrich.xchangestream.gateio.config.converter; - -import com.fasterxml.jackson.databind.util.StdConverter; -import java.time.Instant; - -/** - * Converts timestamp as double in milliseconds to {@code Instant} - */ -public class DoubleToInstantConverter extends StdConverter { - - @Override - public Instant convert(final Double value) { - return Instant.ofEpochMilli(value.longValue()); - } -} diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/converter/StringToCurrencyPairConverter.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/converter/StringToCurrencyPairConverter.java deleted file mode 100644 index a0afaa1aa5f..00000000000 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/converter/StringToCurrencyPairConverter.java +++ /dev/null @@ -1,15 +0,0 @@ -package info.bitrich.xchangestream.gateio.config.converter; - -import com.fasterxml.jackson.databind.util.StdConverter; -import org.knowm.xchange.currency.CurrencyPair; - -/** - * Converts string to {@code CurrencyPair} - */ -public class StringToCurrencyPairConverter extends StdConverter { - - @Override - public CurrencyPair convert(String value) { - return new CurrencyPair(value.replace('_', '/')); - } -} diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/converter/TimestampSecondsToInstantConverter.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/converter/TimestampSecondsToInstantConverter.java deleted file mode 100644 index f09a7be9caa..00000000000 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/converter/TimestampSecondsToInstantConverter.java +++ /dev/null @@ -1,15 +0,0 @@ -package info.bitrich.xchangestream.gateio.config.converter; - -import com.fasterxml.jackson.databind.util.StdConverter; -import java.time.Instant; - -/** - * Converts timestamp in seconds to {@code Instant} - */ -public class TimestampSecondsToInstantConverter extends StdConverter { - - @Override - public Instant convert(final Long value) { - return Instant.ofEpochSecond(value); - } -} diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/request/GateioWebSocketRequest.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/request/GateioWebSocketRequest.java index ce774ceec67..e00ae3fb1a9 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/request/GateioWebSocketRequest.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/request/GateioWebSocketRequest.java @@ -5,12 +5,12 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import info.bitrich.xchangestream.gateio.config.converter.InstantToTimestampSecondsConverter; -import info.bitrich.xchangestream.gateio.config.converter.TimestampSecondsToInstantConverter; import info.bitrich.xchangestream.gateio.dto.Event; import java.time.Instant; import lombok.Data; import lombok.experimental.SuperBuilder; import lombok.extern.jackson.Jacksonized; +import org.knowm.xchange.gateio.config.converter.TimestampSecondsToInstantConverter; @Data @SuperBuilder diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/request/payload/CurrencyPairLevelIntervalPayload.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/request/payload/CurrencyPairLevelIntervalPayload.java index c2fa9e216cb..7a4256633f8 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/request/payload/CurrencyPairLevelIntervalPayload.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/request/payload/CurrencyPairLevelIntervalPayload.java @@ -4,12 +4,12 @@ import com.fasterxml.jackson.annotation.JsonFormat.Shape; import com.fasterxml.jackson.annotation.JsonGetter; import com.fasterxml.jackson.databind.annotation.JsonSerialize; -import info.bitrich.xchangestream.gateio.config.converter.CurrencyPairToStringConverter; import java.time.Duration; import lombok.Data; import lombok.experimental.SuperBuilder; import lombok.extern.jackson.Jacksonized; import org.knowm.xchange.currency.CurrencyPair; +import org.knowm.xchange.gateio.config.converter.CurrencyPairToStringConverter; @Data @SuperBuilder diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/request/payload/CurrencyPairPayload.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/request/payload/CurrencyPairPayload.java index 2992f6129c3..6c329092686 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/request/payload/CurrencyPairPayload.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/request/payload/CurrencyPairPayload.java @@ -1,11 +1,11 @@ package info.bitrich.xchangestream.gateio.dto.request.payload; import com.fasterxml.jackson.databind.annotation.JsonSerialize; -import info.bitrich.xchangestream.gateio.config.converter.CurrencyPairToStringConverter; import lombok.Data; import lombok.experimental.SuperBuilder; import lombok.extern.jackson.Jacksonized; import org.knowm.xchange.currency.CurrencyPair; +import org.knowm.xchange.gateio.config.converter.CurrencyPairToStringConverter; @Data @SuperBuilder diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/GateioWebSocketNotification.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/GateioWebSocketNotification.java index 0d201fff030..707fa46e0b6 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/GateioWebSocketNotification.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/GateioWebSocketNotification.java @@ -6,7 +6,6 @@ import com.fasterxml.jackson.annotation.JsonTypeInfo; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import info.bitrich.xchangestream.gateio.config.Config; -import info.bitrich.xchangestream.gateio.config.converter.TimestampSecondsToInstantConverter; import info.bitrich.xchangestream.gateio.dto.Event; import info.bitrich.xchangestream.gateio.dto.response.balance.GateioMultipleSpotBalanceNotification; import info.bitrich.xchangestream.gateio.dto.response.orderbook.GateioOrderBookNotification; @@ -17,6 +16,7 @@ import lombok.Data; import lombok.experimental.SuperBuilder; import lombok.extern.jackson.Jacksonized; +import org.knowm.xchange.gateio.config.converter.TimestampSecondsToInstantConverter; @JsonTypeInfo( use = JsonTypeInfo.Id.NAME, diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/balance/BalanceDTO.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/balance/BalanceDTO.java index fdc9d7873d1..91e18478bbe 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/balance/BalanceDTO.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/balance/BalanceDTO.java @@ -2,11 +2,11 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import info.bitrich.xchangestream.gateio.config.converter.TimestampSecondsToInstantConverter; import java.math.BigDecimal; import java.time.Instant; import lombok.Data; import org.knowm.xchange.currency.Currency; +import org.knowm.xchange.gateio.config.converter.TimestampSecondsToInstantConverter; @Data public class BalanceDTO { diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/orderbook/OrderBookDTO.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/orderbook/OrderBookDTO.java index 992cd92c611..307aea45a70 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/orderbook/OrderBookDTO.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/orderbook/OrderBookDTO.java @@ -3,7 +3,6 @@ import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import info.bitrich.xchangestream.gateio.config.converter.StringToCurrencyPairConverter; import java.math.BigDecimal; import java.time.Instant; import java.util.List; @@ -11,6 +10,7 @@ import lombok.Data; import lombok.extern.jackson.Jacksonized; import org.knowm.xchange.currency.CurrencyPair; +import org.knowm.xchange.gateio.config.converter.StringToCurrencyPairConverter; @Data public class OrderBookDTO { diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/ticker/TickerDTO.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/ticker/TickerDTO.java index 6568448b758..6f1e525ba5e 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/ticker/TickerDTO.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/ticker/TickerDTO.java @@ -2,10 +2,10 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import info.bitrich.xchangestream.gateio.config.converter.StringToCurrencyPairConverter; import java.math.BigDecimal; import lombok.Data; import org.knowm.xchange.currency.CurrencyPair; +import org.knowm.xchange.gateio.config.converter.StringToCurrencyPairConverter; @Data public class TickerDTO { diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/trade/TradeDTO.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/trade/TradeDTO.java index 0eafb47643e..4dfcb404a5b 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/trade/TradeDTO.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/trade/TradeDTO.java @@ -2,13 +2,13 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import info.bitrich.xchangestream.gateio.config.converter.DoubleToInstantConverter; -import info.bitrich.xchangestream.gateio.config.converter.StringToCurrencyPairConverter; -import info.bitrich.xchangestream.gateio.config.converter.TimestampSecondsToInstantConverter; import java.math.BigDecimal; import java.time.Instant; import lombok.Data; import org.knowm.xchange.currency.CurrencyPair; +import org.knowm.xchange.gateio.config.converter.DoubleToInstantConverter; +import org.knowm.xchange.gateio.config.converter.StringToCurrencyPairConverter; +import org.knowm.xchange.gateio.config.converter.TimestampSecondsToInstantConverter; @Data public class TradeDTO { diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/usertrade/UserTradeDTO.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/usertrade/UserTradeDTO.java index f5358080b57..ec990ac5c0d 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/usertrade/UserTradeDTO.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/usertrade/UserTradeDTO.java @@ -2,14 +2,14 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import info.bitrich.xchangestream.gateio.config.converter.DoubleToInstantConverter; -import info.bitrich.xchangestream.gateio.config.converter.StringToCurrencyPairConverter; -import info.bitrich.xchangestream.gateio.config.converter.TimestampSecondsToInstantConverter; import java.math.BigDecimal; import java.time.Instant; import lombok.Data; import org.knowm.xchange.currency.Currency; import org.knowm.xchange.currency.CurrencyPair; +import org.knowm.xchange.gateio.config.converter.DoubleToInstantConverter; +import org.knowm.xchange.gateio.config.converter.StringToCurrencyPairConverter; +import org.knowm.xchange.gateio.config.converter.TimestampSecondsToInstantConverter; @Data public class UserTradeDTO { From c2c16a4e6e897dd414e308d4df65c8acbde9b4c6 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Sun, 13 Aug 2023 16:37:13 +0200 Subject: [PATCH 095/159] [gateio-streaming] Rename classes --- .../gateio/GateioStreamingAdapters.java | 90 +++++++++---------- .../gateio/GateioStreamingService.java | 32 +++---- ...ocketRequest.java => GateioWsRequest.java} | 2 +- ...ication.java => GateioWsNotification.java} | 2 +- .../{BalanceDTO.java => BalancePayload.java} | 2 +- ...GateioMultipleSpotBalanceNotification.java | 10 +-- .../GateioSingleSpotBalanceNotification.java | 6 +- .../GateioOrderBookNotification.java | 6 +- ...rderBookDTO.java => OrderBookPayload.java} | 2 +- .../ticker/GateioTickerNotification.java | 6 +- .../{TickerDTO.java => TickerPayload.java} | 2 +- .../trade/GateioTradeNotification.java | 6 +- .../{TradeDTO.java => TradePayload.java} | 2 +- .../GateioMultipleUserTradeNotification.java | 10 +-- .../GateioSingleUserTradeNotification.java | 6 +- ...serTradeDTO.java => UserTradePayload.java} | 2 +- .../GateioStreamingAccountServiceTest.java | 10 +-- .../GateioStreamingMarketDataServiceTest.java | 12 +-- .../gateio/GateioStreamingServiceTest.java | 16 ++-- .../GateioStreamingTradeServiceTest.java | 10 +-- ...est.java => GateioWsNotificationTest.java} | 16 ++-- 21 files changed, 125 insertions(+), 125 deletions(-) rename xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/request/{GateioWebSocketRequest.java => GateioWsRequest.java} (97%) rename xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/{GateioWebSocketNotification.java => GateioWsNotification.java} (98%) rename xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/balance/{BalanceDTO.java => BalancePayload.java} (97%) rename xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/orderbook/{OrderBookDTO.java => OrderBookPayload.java} (97%) rename xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/ticker/{TickerDTO.java => TickerPayload.java} (97%) rename xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/trade/{TradeDTO.java => TradePayload.java} (97%) rename xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/usertrade/{UserTradeDTO.java => UserTradePayload.java} (97%) rename xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/dto/response/{GateioWebSocketNotificationTest.java => GateioWsNotificationTest.java} (71%) diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingAdapters.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingAdapters.java index 07f0bc51358..dbead01fe5a 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingAdapters.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingAdapters.java @@ -1,15 +1,15 @@ package info.bitrich.xchangestream.gateio; -import info.bitrich.xchangestream.gateio.dto.response.balance.BalanceDTO; +import info.bitrich.xchangestream.gateio.dto.response.balance.BalancePayload; import info.bitrich.xchangestream.gateio.dto.response.balance.GateioSingleSpotBalanceNotification; import info.bitrich.xchangestream.gateio.dto.response.orderbook.GateioOrderBookNotification; -import info.bitrich.xchangestream.gateio.dto.response.orderbook.OrderBookDTO; +import info.bitrich.xchangestream.gateio.dto.response.orderbook.OrderBookPayload; import info.bitrich.xchangestream.gateio.dto.response.ticker.GateioTickerNotification; -import info.bitrich.xchangestream.gateio.dto.response.ticker.TickerDTO; +import info.bitrich.xchangestream.gateio.dto.response.ticker.TickerPayload; import info.bitrich.xchangestream.gateio.dto.response.trade.GateioTradeNotification; -import info.bitrich.xchangestream.gateio.dto.response.trade.TradeDTO; +import info.bitrich.xchangestream.gateio.dto.response.trade.TradePayload; import info.bitrich.xchangestream.gateio.dto.response.usertrade.GateioSingleUserTradeNotification; -import info.bitrich.xchangestream.gateio.dto.response.usertrade.UserTradeDTO; +import info.bitrich.xchangestream.gateio.dto.response.usertrade.UserTradePayload; import java.util.Date; import java.util.stream.Stream; import lombok.experimental.UtilityClass; @@ -25,79 +25,79 @@ public class GateioStreamingAdapters { public Ticker toTicker(GateioTickerNotification notification) { - TickerDTO tickerDTO = notification.getResult(); + TickerPayload tickerPayload = notification.getResult(); return new Ticker.Builder() .timestamp(Date.from(notification.getTimeMs())) - .instrument(tickerDTO.getCurrencyPair()) - .last(tickerDTO.getLastPrice()) - .ask(tickerDTO.getLowestAsk()) - .bid(tickerDTO.getHighestBid()) - .percentageChange(tickerDTO.getChangePercent24h()) - .volume(tickerDTO.getBaseVolume()) - .quoteVolume(tickerDTO.getQuoteVolume()) - .high(tickerDTO.getHighPrice24h()) - .low(tickerDTO.getLowPrice24h()) + .instrument(tickerPayload.getCurrencyPair()) + .last(tickerPayload.getLastPrice()) + .ask(tickerPayload.getLowestAsk()) + .bid(tickerPayload.getHighestBid()) + .percentageChange(tickerPayload.getChangePercent24h()) + .volume(tickerPayload.getBaseVolume()) + .quoteVolume(tickerPayload.getQuoteVolume()) + .high(tickerPayload.getHighPrice24h()) + .low(tickerPayload.getLowPrice24h()) .build(); } public Trade toTrade(GateioTradeNotification notification) { - TradeDTO tradeDTO = notification.getResult(); + TradePayload tradePayload = notification.getResult(); return new Trade.Builder() - .type("sell".equals(tradeDTO.getSide()) ? OrderType.ASK : OrderType.BID) - .originalAmount(tradeDTO.getAmount()) - .instrument(tradeDTO.getCurrencyPair()) - .price(tradeDTO.getPrice()) - .timestamp(Date.from(tradeDTO.getTimeMs())) - .id(String.valueOf(tradeDTO.getId())) + .type("sell".equals(tradePayload.getSide()) ? OrderType.ASK : OrderType.BID) + .originalAmount(tradePayload.getAmount()) + .instrument(tradePayload.getCurrencyPair()) + .price(tradePayload.getPrice()) + .timestamp(Date.from(tradePayload.getTimeMs())) + .id(String.valueOf(tradePayload.getId())) .build(); } public UserTrade toUserTrade(GateioSingleUserTradeNotification notification) { - UserTradeDTO userTradeDTO = notification.getResult(); + UserTradePayload userTradePayload = notification.getResult(); return new UserTrade.Builder() - .type("sell".equals(userTradeDTO.getSide()) ? OrderType.ASK : OrderType.BID) - .originalAmount(userTradeDTO.getAmount()) - .instrument(userTradeDTO.getCurrencyPair()) - .price(userTradeDTO.getPrice()) - .timestamp(Date.from(userTradeDTO.getTimeMs())) - .id(String.valueOf(userTradeDTO.getId())) - .orderId(String.valueOf(userTradeDTO.getOrderId())) - .feeAmount(userTradeDTO.getFee()) - .feeCurrency(userTradeDTO.getFeeCurrency()) - .orderUserReference(userTradeDTO.getRemark()) + .type("sell".equals(userTradePayload.getSide()) ? OrderType.ASK : OrderType.BID) + .originalAmount(userTradePayload.getAmount()) + .instrument(userTradePayload.getCurrencyPair()) + .price(userTradePayload.getPrice()) + .timestamp(Date.from(userTradePayload.getTimeMs())) + .id(String.valueOf(userTradePayload.getId())) + .orderId(String.valueOf(userTradePayload.getOrderId())) + .feeAmount(userTradePayload.getFee()) + .feeCurrency(userTradePayload.getFeeCurrency()) + .orderUserReference(userTradePayload.getRemark()) .build(); } public Balance toBalance(GateioSingleSpotBalanceNotification notification) { - BalanceDTO balanceDTO = notification.getResult(); + BalancePayload balancePayload = notification.getResult(); return Balance.builder() - .currency(balanceDTO.getCurrency()) - .total(balanceDTO.getTotal()) - .available(balanceDTO.getAvailable()) - .frozen(balanceDTO.getFreeze()) - .timestamp(Date.from(balanceDTO.getTimeMs())) + .currency(balancePayload.getCurrency()) + .total(balancePayload.getTotal()) + .available(balancePayload.getAvailable()) + .frozen(balancePayload.getFreeze()) + .timestamp(Date.from(balancePayload.getTimeMs())) .build(); } public OrderBook toOrderBook(GateioOrderBookNotification notification) { - OrderBookDTO orderBookDTO = notification.getResult(); + OrderBookPayload orderBookPayload = notification.getResult(); - Stream asks = orderBookDTO.getAsks().stream() - .map(priceSizeEntry -> new LimitOrder(OrderType.ASK, priceSizeEntry.getSize(), orderBookDTO.getCurrencyPair(), null, null, priceSizeEntry.getPrice())); + Stream asks = orderBookPayload.getAsks().stream() + .map(priceSizeEntry -> new LimitOrder(OrderType.ASK, priceSizeEntry.getSize(), orderBookPayload.getCurrencyPair(), null, null, priceSizeEntry.getPrice())); - Stream bids = orderBookDTO.getAsks().stream() - .map(priceSizeEntry -> new LimitOrder(OrderType.BID, priceSizeEntry.getSize(), orderBookDTO.getCurrencyPair(), null, null, priceSizeEntry.getPrice())); + Stream bids = orderBookPayload.getAsks().stream() + .map(priceSizeEntry -> new LimitOrder(OrderType.BID, priceSizeEntry.getSize(), orderBookPayload.getCurrencyPair(), null, null, priceSizeEntry.getPrice())); - return new OrderBook(Date.from(orderBookDTO.getTimestamp()), asks, bids); + return new OrderBook(Date.from(orderBookPayload.getTimestamp()), asks, bids); } diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingService.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingService.java index b9d144656e8..38cb5ed145d 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingService.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingService.java @@ -6,13 +6,13 @@ import info.bitrich.xchangestream.gateio.config.Config; import info.bitrich.xchangestream.gateio.config.IdGenerator; import info.bitrich.xchangestream.gateio.dto.Event; -import info.bitrich.xchangestream.gateio.dto.request.GateioWebSocketRequest; -import info.bitrich.xchangestream.gateio.dto.request.GateioWebSocketRequest.AuthInfo; +import info.bitrich.xchangestream.gateio.dto.request.GateioWsRequest; +import info.bitrich.xchangestream.gateio.dto.request.GateioWsRequest.AuthInfo; import info.bitrich.xchangestream.gateio.dto.request.payload.CurrencyPairLevelIntervalPayload; import info.bitrich.xchangestream.gateio.dto.request.payload.CurrencyPairPayload; import info.bitrich.xchangestream.gateio.dto.request.payload.EmptyPayload; import info.bitrich.xchangestream.gateio.dto.request.payload.StringPayload; -import info.bitrich.xchangestream.gateio.dto.response.GateioWebSocketNotification; +import info.bitrich.xchangestream.gateio.dto.response.GateioWsNotification; import info.bitrich.xchangestream.gateio.dto.response.balance.GateioMultipleSpotBalanceNotification; import info.bitrich.xchangestream.gateio.dto.response.usertrade.GateioMultipleUserTradeNotification; import info.bitrich.xchangestream.gateio.dto.response.usertrade.GateioSingleUserTradeNotification; @@ -31,11 +31,11 @@ import org.knowm.xchange.currency.CurrencyPair; @Slf4j -public class GateioStreamingService extends NettyStreamingService { +public class GateioStreamingService extends NettyStreamingService { private static final String USERTRADES_BROADCAST_CHANNEL_NAME = Config.SPOT_USER_TRADES_CHANNEL + Config.CHANNEL_NAME_DELIMITER + "null"; - private final Map> subscriptions = new ConcurrentHashMap<>(); + private final Map> subscriptions = new ConcurrentHashMap<>(); private final ObjectMapper objectMapper = Config.getInstance().getObjectMapper(); @@ -50,12 +50,12 @@ public GateioStreamingService(String apiUri, String apiKey, String apiSecret) { } @Override - protected String getChannelNameFromMessage(GateioWebSocketNotification message) { + protected String getChannelNameFromMessage(GateioWsNotification message) { return message.getUniqueChannelName(); } @Override - public Observable subscribeChannel(String channelName, Object... args) { + public Observable subscribeChannel(String channelName, Object... args) { final CurrencyPair currencyPair = (args.length > 0 && args[0] instanceof CurrencyPair) ? ((CurrencyPair) args[0]) : null; @@ -66,7 +66,7 @@ public Observable subscribeChannel(String channelNa if (!channels.containsKey(uniqueChannelName) && !subscriptions.containsKey(uniqueChannelName)) { // subscribe - Observable observable = super.subscribeChannel(uniqueChannelName, args); + Observable observable = super.subscribeChannel(uniqueChannelName, args); // cache channel subscribtion subscriptions.put(uniqueChannelName, observable); @@ -85,15 +85,15 @@ public Observable subscribeChannel(String channelNa @Override public String getSubscribeMessage(String uniqueChannelName, Object... args) throws IOException { String generalChannelName = uniqueChannelName.split(Config.CHANNEL_NAME_DELIMITER)[0]; - GateioWebSocketRequest request = getWebSocketRequest(generalChannelName, Event.SUBSCRIBE , args); + GateioWsRequest request = getWsRequest(generalChannelName, Event.SUBSCRIBE , args); return objectMapper.writeValueAsString(request); } - private GateioWebSocketRequest getWebSocketRequest(String channelName, Event event, Object... args) { + private GateioWsRequest getWsRequest(String channelName, Event event, Object... args) { // create request common part - GateioWebSocketRequest request = GateioWebSocketRequest.builder() + GateioWsRequest request = GateioWsRequest.builder() .id(IdGenerator.getInstance().requestId()) .channel(channelName) .event(event) @@ -180,7 +180,7 @@ protected WebSocketClientExtensionHandler getWebSocketClientExtensionHandler() { @Override public String getUnsubscribeMessage(String uniqueChannelName, Object... args) throws IOException { String generalChannelName = uniqueChannelName.split(Config.CHANNEL_NAME_DELIMITER)[0]; - GateioWebSocketRequest unsubscribeMessage = getWebSocketRequest(generalChannelName, Event.UNSUBSCRIBE, args); + GateioWsRequest unsubscribeMessage = getWsRequest(generalChannelName, Event.UNSUBSCRIBE, args); return objectMapper.writeValueAsString(unsubscribeMessage); } @@ -198,7 +198,7 @@ public void messageHandler(String message) { return; } - GateioWebSocketNotification notification = objectMapper.treeToValue(jsonNode, GateioWebSocketNotification.class); + GateioWsNotification notification = objectMapper.treeToValue(jsonNode, GateioWsNotification.class); // process arrays in "result" field -> emit each item separately if (notification instanceof GateioMultipleUserTradeNotification) { @@ -220,7 +220,7 @@ else if (notification instanceof GateioMultipleSpotBalanceNotification) { @Override - protected void handleChannelMessage(String channel, GateioWebSocketNotification message) { + protected void handleChannelMessage(String channel, GateioWsNotification message) { if (channel == null) { log.debug("Channel provided is null"); return; @@ -230,14 +230,14 @@ protected void handleChannelMessage(String channel, GateioWebSocketNotification if (message instanceof GateioSingleUserTradeNotification) { // subscription that listens to all currency pairs - NettyStreamingService.Subscription broadcast = channels.get( + NettyStreamingService.Subscription broadcast = channels.get( USERTRADES_BROADCAST_CHANNEL_NAME); if (broadcast != null && broadcast.getEmitter() != null) { broadcast.getEmitter().onNext(message); } // subscription that listens to specific currency pair - NettyStreamingService.Subscription specific = channels.get(channel); + NettyStreamingService.Subscription specific = channels.get(channel); if (specific != null && specific.getEmitter() != null) { specific.getEmitter().onNext(message); } diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/request/GateioWebSocketRequest.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/request/GateioWsRequest.java similarity index 97% rename from xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/request/GateioWebSocketRequest.java rename to xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/request/GateioWsRequest.java index e00ae3fb1a9..6c55d44ce4e 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/request/GateioWebSocketRequest.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/request/GateioWsRequest.java @@ -15,7 +15,7 @@ @Data @SuperBuilder @Jacksonized -public class GateioWebSocketRequest { +public class GateioWsRequest { @JsonProperty("time") @JsonDeserialize(converter = TimestampSecondsToInstantConverter.class) diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/GateioWebSocketNotification.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/GateioWsNotification.java similarity index 98% rename from xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/GateioWebSocketNotification.java rename to xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/GateioWsNotification.java index 707fa46e0b6..e983b8efea5 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/GateioWebSocketNotification.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/GateioWsNotification.java @@ -32,7 +32,7 @@ @Data @SuperBuilder @Jacksonized -public class GateioWebSocketNotification { +public class GateioWsNotification { @JsonProperty("time") @JsonDeserialize(converter = TimestampSecondsToInstantConverter.class) diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/balance/BalanceDTO.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/balance/BalancePayload.java similarity index 97% rename from xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/balance/BalanceDTO.java rename to xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/balance/BalancePayload.java index 91e18478bbe..fc70c5eb980 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/balance/BalanceDTO.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/balance/BalancePayload.java @@ -9,7 +9,7 @@ import org.knowm.xchange.gateio.config.converter.TimestampSecondsToInstantConverter; @Data -public class BalanceDTO { +public class BalancePayload { @JsonProperty("timestamp") @JsonDeserialize(converter = TimestampSecondsToInstantConverter.class) diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/balance/GateioMultipleSpotBalanceNotification.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/balance/GateioMultipleSpotBalanceNotification.java index 83e7b3a594f..3d6e8617ef5 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/balance/GateioMultipleSpotBalanceNotification.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/balance/GateioMultipleSpotBalanceNotification.java @@ -1,7 +1,7 @@ package info.bitrich.xchangestream.gateio.dto.response.balance; import com.fasterxml.jackson.annotation.JsonProperty; -import info.bitrich.xchangestream.gateio.dto.response.GateioWebSocketNotification; +import info.bitrich.xchangestream.gateio.dto.response.GateioWsNotification; import java.util.List; import java.util.stream.Collectors; import lombok.Data; @@ -11,16 +11,16 @@ @Data @SuperBuilder @Jacksonized -public class GateioMultipleSpotBalanceNotification extends GateioWebSocketNotification { +public class GateioMultipleSpotBalanceNotification extends GateioWsNotification { @JsonProperty("result") - private List result; + private List result; public List toSingleNotifications() { return result.stream() - .map(balanceDTO -> GateioSingleSpotBalanceNotification.builder() - .result(balanceDTO) + .map(balancePayload -> GateioSingleSpotBalanceNotification.builder() + .result(balancePayload) .time(getTime()) .timeMs(getTimeMs()) .channel(getChannel()) diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/balance/GateioSingleSpotBalanceNotification.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/balance/GateioSingleSpotBalanceNotification.java index 24ff6815f1e..db22e18e605 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/balance/GateioSingleSpotBalanceNotification.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/balance/GateioSingleSpotBalanceNotification.java @@ -1,15 +1,15 @@ package info.bitrich.xchangestream.gateio.dto.response.balance; import info.bitrich.xchangestream.gateio.config.Config; -import info.bitrich.xchangestream.gateio.dto.response.GateioWebSocketNotification; +import info.bitrich.xchangestream.gateio.dto.response.GateioWsNotification; import lombok.Data; import lombok.experimental.SuperBuilder; @Data @SuperBuilder -public class GateioSingleSpotBalanceNotification extends GateioWebSocketNotification { +public class GateioSingleSpotBalanceNotification extends GateioWsNotification { - private BalanceDTO result; + private BalancePayload result; @Override public String getUniqueChannelName() { diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/orderbook/GateioOrderBookNotification.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/orderbook/GateioOrderBookNotification.java index 02be6287c0d..2960524f807 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/orderbook/GateioOrderBookNotification.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/orderbook/GateioOrderBookNotification.java @@ -2,7 +2,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import info.bitrich.xchangestream.gateio.config.Config; -import info.bitrich.xchangestream.gateio.dto.response.GateioWebSocketNotification; +import info.bitrich.xchangestream.gateio.dto.response.GateioWsNotification; import lombok.Data; import lombok.experimental.SuperBuilder; import lombok.extern.jackson.Jacksonized; @@ -10,10 +10,10 @@ @Data @SuperBuilder @Jacksonized -public class GateioOrderBookNotification extends GateioWebSocketNotification { +public class GateioOrderBookNotification extends GateioWsNotification { @JsonProperty("result") - private OrderBookDTO result; + private OrderBookPayload result; @Override public String getUniqueChannelName() { diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/orderbook/OrderBookDTO.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/orderbook/OrderBookPayload.java similarity index 97% rename from xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/orderbook/OrderBookDTO.java rename to xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/orderbook/OrderBookPayload.java index 307aea45a70..ebb8698a5ad 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/orderbook/OrderBookDTO.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/orderbook/OrderBookPayload.java @@ -13,7 +13,7 @@ import org.knowm.xchange.gateio.config.converter.StringToCurrencyPairConverter; @Data -public class OrderBookDTO { +public class OrderBookPayload { @JsonProperty("t") Instant timestamp; diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/ticker/GateioTickerNotification.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/ticker/GateioTickerNotification.java index e6699686e07..c75e9141128 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/ticker/GateioTickerNotification.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/ticker/GateioTickerNotification.java @@ -2,7 +2,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import info.bitrich.xchangestream.gateio.config.Config; -import info.bitrich.xchangestream.gateio.dto.response.GateioWebSocketNotification; +import info.bitrich.xchangestream.gateio.dto.response.GateioWsNotification; import lombok.Data; import lombok.experimental.SuperBuilder; import lombok.extern.jackson.Jacksonized; @@ -10,10 +10,10 @@ @Data @SuperBuilder @Jacksonized -public class GateioTickerNotification extends GateioWebSocketNotification { +public class GateioTickerNotification extends GateioWsNotification { @JsonProperty("result") - private TickerDTO result; + private TickerPayload result; @Override public String getUniqueChannelName() { diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/ticker/TickerDTO.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/ticker/TickerPayload.java similarity index 97% rename from xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/ticker/TickerDTO.java rename to xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/ticker/TickerPayload.java index 6f1e525ba5e..b182cdf77f8 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/ticker/TickerDTO.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/ticker/TickerPayload.java @@ -8,7 +8,7 @@ import org.knowm.xchange.gateio.config.converter.StringToCurrencyPairConverter; @Data -public class TickerDTO { +public class TickerPayload { @JsonProperty("currency_pair") @JsonDeserialize(converter = StringToCurrencyPairConverter.class) diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/trade/GateioTradeNotification.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/trade/GateioTradeNotification.java index b6cc3c2bed6..12eae15ae9d 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/trade/GateioTradeNotification.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/trade/GateioTradeNotification.java @@ -2,7 +2,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import info.bitrich.xchangestream.gateio.config.Config; -import info.bitrich.xchangestream.gateio.dto.response.GateioWebSocketNotification; +import info.bitrich.xchangestream.gateio.dto.response.GateioWsNotification; import lombok.Data; import lombok.experimental.SuperBuilder; import lombok.extern.jackson.Jacksonized; @@ -10,10 +10,10 @@ @Data @SuperBuilder @Jacksonized -public class GateioTradeNotification extends GateioWebSocketNotification { +public class GateioTradeNotification extends GateioWsNotification { @JsonProperty("result") - private TradeDTO result; + private TradePayload result; @Override public String getUniqueChannelName() { diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/trade/TradeDTO.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/trade/TradePayload.java similarity index 97% rename from xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/trade/TradeDTO.java rename to xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/trade/TradePayload.java index 4dfcb404a5b..818375709f4 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/trade/TradeDTO.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/trade/TradePayload.java @@ -11,7 +11,7 @@ import org.knowm.xchange.gateio.config.converter.TimestampSecondsToInstantConverter; @Data -public class TradeDTO { +public class TradePayload { @JsonProperty("id") Long id; diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/usertrade/GateioMultipleUserTradeNotification.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/usertrade/GateioMultipleUserTradeNotification.java index fe5dc758a08..2ba4bb69064 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/usertrade/GateioMultipleUserTradeNotification.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/usertrade/GateioMultipleUserTradeNotification.java @@ -1,7 +1,7 @@ package info.bitrich.xchangestream.gateio.dto.response.usertrade; import com.fasterxml.jackson.annotation.JsonProperty; -import info.bitrich.xchangestream.gateio.dto.response.GateioWebSocketNotification; +import info.bitrich.xchangestream.gateio.dto.response.GateioWsNotification; import java.util.List; import java.util.stream.Collectors; import lombok.Data; @@ -11,16 +11,16 @@ @Data @SuperBuilder @Jacksonized -public class GateioMultipleUserTradeNotification extends GateioWebSocketNotification { +public class GateioMultipleUserTradeNotification extends GateioWsNotification { @JsonProperty("result") - private List result; + private List result; public List toSingleNotifications() { return result.stream() - .map(userTradeDTO -> GateioSingleUserTradeNotification.builder() - .result(userTradeDTO) + .map(userTradePayload -> GateioSingleUserTradeNotification.builder() + .result(userTradePayload) .time(getTime()) .timeMs(getTimeMs()) .channel(getChannel()) diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/usertrade/GateioSingleUserTradeNotification.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/usertrade/GateioSingleUserTradeNotification.java index 5a431068e2b..be5238c780d 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/usertrade/GateioSingleUserTradeNotification.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/usertrade/GateioSingleUserTradeNotification.java @@ -1,15 +1,15 @@ package info.bitrich.xchangestream.gateio.dto.response.usertrade; import info.bitrich.xchangestream.gateio.config.Config; -import info.bitrich.xchangestream.gateio.dto.response.GateioWebSocketNotification; +import info.bitrich.xchangestream.gateio.dto.response.GateioWsNotification; import lombok.Data; import lombok.experimental.SuperBuilder; @Data @SuperBuilder -public class GateioSingleUserTradeNotification extends GateioWebSocketNotification { +public class GateioSingleUserTradeNotification extends GateioWsNotification { - private UserTradeDTO result; + private UserTradePayload result; @Override public String getUniqueChannelName() { diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/usertrade/UserTradeDTO.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/usertrade/UserTradePayload.java similarity index 97% rename from xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/usertrade/UserTradeDTO.java rename to xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/usertrade/UserTradePayload.java index ec990ac5c0d..f136f34b3f3 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/usertrade/UserTradeDTO.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/usertrade/UserTradePayload.java @@ -12,7 +12,7 @@ import org.knowm.xchange.gateio.config.converter.TimestampSecondsToInstantConverter; @Data -public class UserTradeDTO { +public class UserTradePayload { @JsonProperty("id") Long id; diff --git a/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingAccountServiceTest.java b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingAccountServiceTest.java index 14ad5b2f73f..cf0fb5c5234 100644 --- a/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingAccountServiceTest.java +++ b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingAccountServiceTest.java @@ -6,7 +6,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import info.bitrich.xchangestream.gateio.config.Config; -import info.bitrich.xchangestream.gateio.dto.response.GateioWebSocketNotification; +import info.bitrich.xchangestream.gateio.dto.response.GateioWsNotification; import info.bitrich.xchangestream.gateio.dto.response.balance.GateioMultipleSpotBalanceNotification; import io.reactivex.Observable; import io.reactivex.observers.TestObserver; @@ -40,9 +40,9 @@ public void setup() { @Test void spot_balances() throws Exception { - GateioWebSocketNotification multipleNotification = readNotification("spot.balance.update.json"); + GateioWsNotification multipleNotification = readNotification("spot.balance.update.json"); assertThat(multipleNotification).isInstanceOf(GateioMultipleSpotBalanceNotification.class); - GateioWebSocketNotification notification = ((GateioMultipleSpotBalanceNotification) multipleNotification).toSingleNotifications().get(0); + GateioWsNotification notification = ((GateioMultipleSpotBalanceNotification) multipleNotification).toSingleNotifications().get(0); when(gateioStreamingService.subscribeChannel(eq("spot.balances"))) .thenReturn(Observable.just(notification)); @@ -71,10 +71,10 @@ void spot_balances() throws Exception { } - private GateioWebSocketNotification readNotification(String resourceName) throws IOException { + private GateioWsNotification readNotification(String resourceName) throws IOException { return objectMapper.readValue( getClass().getClassLoader().getResourceAsStream(resourceName), - GateioWebSocketNotification.class + GateioWsNotification.class ); } diff --git a/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingMarketDataServiceTest.java b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingMarketDataServiceTest.java index 6a86adece71..5c644a47763 100644 --- a/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingMarketDataServiceTest.java +++ b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingMarketDataServiceTest.java @@ -6,7 +6,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import info.bitrich.xchangestream.gateio.config.Config; -import info.bitrich.xchangestream.gateio.dto.response.GateioWebSocketNotification; +import info.bitrich.xchangestream.gateio.dto.response.GateioWsNotification; import io.reactivex.Observable; import io.reactivex.observers.TestObserver; import java.io.IOException; @@ -42,7 +42,7 @@ public void setup() { @Test void order_book() throws Exception { - GateioWebSocketNotification notification = readNotification("spot.order_book.update.json"); + GateioWsNotification notification = readNotification("spot.order_book.update.json"); when(gateioStreamingService.subscribeChannel(eq("spot.order_book"), eq(CurrencyPair.BTC_USDT), eq(10), eq(Duration.ofMillis(100)))) .thenReturn(Observable.just(notification)); @@ -67,7 +67,7 @@ void order_book() throws Exception { @Test void ticker() throws Exception { - GateioWebSocketNotification notification = readNotification("spot.ticker.update.json"); + GateioWsNotification notification = readNotification("spot.ticker.update.json"); when(gateioStreamingService.subscribeChannel(eq("spot.tickers"), eq(CurrencyPair.BTC_USDT))) .thenReturn(Observable.just(notification)); @@ -101,7 +101,7 @@ void ticker() throws Exception { @Test void trades() throws Exception { - GateioWebSocketNotification notification = readNotification("spot.trades.update.json"); + GateioWsNotification notification = readNotification("spot.trades.update.json"); when(gateioStreamingService.subscribeChannel(eq("spot.trades"), eq(CurrencyPair.BTC_USDT))) .thenReturn(Observable.just(notification)); @@ -130,10 +130,10 @@ void trades() throws Exception { } - private GateioWebSocketNotification readNotification(String resourceName) throws IOException { + private GateioWsNotification readNotification(String resourceName) throws IOException { return objectMapper.readValue( getClass().getClassLoader().getResourceAsStream(resourceName), - GateioWebSocketNotification.class + GateioWsNotification.class ); } diff --git a/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingServiceTest.java b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingServiceTest.java index 90fafda4af4..43dc7a8b4eb 100644 --- a/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingServiceTest.java +++ b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingServiceTest.java @@ -5,7 +5,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import info.bitrich.xchangestream.gateio.config.Config; -import info.bitrich.xchangestream.gateio.dto.response.GateioWebSocketNotification; +import info.bitrich.xchangestream.gateio.dto.response.GateioWsNotification; import java.io.IOException; import org.junit.jupiter.api.Test; @@ -16,7 +16,7 @@ public class GateioStreamingServiceTest { @Test void channel_name_from_orderbook_update() throws Exception { - GateioWebSocketNotification notification = readNotification("spot.order_book.update.json"); + GateioWsNotification notification = readNotification("spot.order_book.update.json"); String actual = gateioStreamingService.getChannelNameFromMessage(notification); assertThat(actual).isEqualTo("spot.order_book-BTC/USDT"); } @@ -24,7 +24,7 @@ void channel_name_from_orderbook_update() throws Exception { @Test void channel_name_from_ticker_update() throws Exception { - GateioWebSocketNotification notification = readNotification("spot.ticker.update.json"); + GateioWsNotification notification = readNotification("spot.ticker.update.json"); String actual = gateioStreamingService.getChannelNameFromMessage(notification); assertThat(actual).isEqualTo("spot.tickers-BTC/USDT"); } @@ -32,7 +32,7 @@ void channel_name_from_ticker_update() throws Exception { @Test void channel_name_from_trade_update() throws Exception { - GateioWebSocketNotification notification = readNotification("spot.trades.update.json"); + GateioWsNotification notification = readNotification("spot.trades.update.json"); String actual = gateioStreamingService.getChannelNameFromMessage(notification); assertThat(actual).isEqualTo("spot.trades-BTC/USDT"); } @@ -40,7 +40,7 @@ void channel_name_from_trade_update() throws Exception { @Test void channel_name_from_subscribe_event() throws Exception { - GateioWebSocketNotification notification = readNotification("subscribe.event.json"); + GateioWsNotification notification = readNotification("subscribe.event.json"); String actual = gateioStreamingService.getChannelNameFromMessage(notification); assertThat(actual).isEqualTo("spot.order_book"); } @@ -48,15 +48,15 @@ void channel_name_from_subscribe_event() throws Exception { @Test void channel_name_from_unsubscribe_event() throws Exception { - GateioWebSocketNotification notification = readNotification("unsubscribe.event.json"); + GateioWsNotification notification = readNotification("unsubscribe.event.json"); String actual = gateioStreamingService.getChannelNameFromMessage(notification); assertThat(actual).isEqualTo("spot.trades"); } - private GateioWebSocketNotification readNotification(String resourceName) throws IOException { + private GateioWsNotification readNotification(String resourceName) throws IOException { return objectMapper.readValue( getClass().getClassLoader().getResourceAsStream(resourceName), - GateioWebSocketNotification.class + GateioWsNotification.class ); } diff --git a/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingTradeServiceTest.java b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingTradeServiceTest.java index 479cd8083e3..7ff2c905165 100644 --- a/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingTradeServiceTest.java +++ b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingTradeServiceTest.java @@ -6,7 +6,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import info.bitrich.xchangestream.gateio.config.Config; -import info.bitrich.xchangestream.gateio.dto.response.GateioWebSocketNotification; +import info.bitrich.xchangestream.gateio.dto.response.GateioWsNotification; import info.bitrich.xchangestream.gateio.dto.response.usertrade.GateioMultipleUserTradeNotification; import io.reactivex.Observable; import io.reactivex.observers.TestObserver; @@ -41,9 +41,9 @@ public void setup() { @Test void user_trades_btc() throws Exception { - GateioWebSocketNotification multipleNotification = readNotification("spot.usertrades.update.json"); + GateioWsNotification multipleNotification = readNotification("spot.usertrades.update.json"); assertThat(multipleNotification).isInstanceOf(GateioMultipleUserTradeNotification.class); - GateioWebSocketNotification notification = ((GateioMultipleUserTradeNotification) multipleNotification).toSingleNotifications().get(0); + GateioWsNotification notification = ((GateioMultipleUserTradeNotification) multipleNotification).toSingleNotifications().get(0); when(gateioStreamingService.subscribeChannel(eq("spot.usertrades"), eq(CurrencyPair.BTC_USDT))) .thenReturn(Observable.just(notification)); @@ -77,10 +77,10 @@ void user_trades_btc() throws Exception { } - private GateioWebSocketNotification readNotification(String resourceName) throws IOException { + private GateioWsNotification readNotification(String resourceName) throws IOException { return objectMapper.readValue( getClass().getClassLoader().getResourceAsStream(resourceName), - GateioWebSocketNotification.class + GateioWsNotification.class ); } diff --git a/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/dto/response/GateioWebSocketNotificationTest.java b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/dto/response/GateioWsNotificationTest.java similarity index 71% rename from xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/dto/response/GateioWebSocketNotificationTest.java rename to xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/dto/response/GateioWsNotificationTest.java index cd4feafdab4..d4d615fab28 100644 --- a/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/dto/response/GateioWebSocketNotificationTest.java +++ b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/dto/response/GateioWsNotificationTest.java @@ -12,49 +12,49 @@ import java.io.IOException; import org.junit.jupiter.api.Test; -public class GateioWebSocketNotificationTest { +public class GateioWsNotificationTest { ObjectMapper objectMapper = Config.getInstance().getObjectMapper(); @Test void deserialize_trades() throws Exception { - GateioWebSocketNotification notification = readNotification("spot.trades.update.json"); + GateioWsNotification notification = readNotification("spot.trades.update.json"); assertThat(notification).isInstanceOf(GateioTradeNotification.class); } @Test void deserialize_ticker() throws Exception { - GateioWebSocketNotification notification = readNotification("spot.ticker.update.json"); + GateioWsNotification notification = readNotification("spot.ticker.update.json"); assertThat(notification).isInstanceOf(GateioTickerNotification.class); } @Test void deserialize_orderbook() throws Exception { - GateioWebSocketNotification notification = readNotification("spot.order_book.update.json"); + GateioWsNotification notification = readNotification("spot.order_book.update.json"); assertThat(notification).isInstanceOf(GateioOrderBookNotification.class); } @Test void deserialize_usertrades() throws Exception { - GateioWebSocketNotification notification = readNotification("spot.usertrades.update.json"); + GateioWsNotification notification = readNotification("spot.usertrades.update.json"); assertThat(notification).isInstanceOf(GateioMultipleUserTradeNotification.class); } @Test void deserialize_balances() throws Exception { - GateioWebSocketNotification notification = readNotification("spot.balance.update.json"); + GateioWsNotification notification = readNotification("spot.balance.update.json"); assertThat(notification).isInstanceOf(GateioMultipleSpotBalanceNotification.class); } - private GateioWebSocketNotification readNotification(String resourceName) throws IOException { + private GateioWsNotification readNotification(String resourceName) throws IOException { return objectMapper.readValue( getClass().getClassLoader().getResourceAsStream(resourceName), - GateioWebSocketNotification.class + GateioWsNotification.class ); } From f1171dd2a1fe370dd95bcc97c5345cab89462e32 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Sun, 13 Aug 2023 16:52:30 +0200 Subject: [PATCH 096/159] [gateio-streaming] Extract signature script --- .../src/test/resources/rest/sign.js | 16 ++++++++++ .../src/test/resources/rest/spot.http | 30 +++---------------- .../src/test/resources/rest/wallet.http | 30 +++---------------- .../src/test/resources/rest/withdraw.http | 16 ++-------- 4 files changed, 26 insertions(+), 66 deletions(-) create mode 100644 xchange-gateio-v4/src/test/resources/rest/sign.js diff --git a/xchange-gateio-v4/src/test/resources/rest/sign.js b/xchange-gateio-v4/src/test/resources/rest/sign.js new file mode 100644 index 00000000000..3f84077e02d --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/rest/sign.js @@ -0,0 +1,16 @@ +export function gen_sign(method, request) { + const pattern = RegExp("^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?"); + const url = request.url.tryGetSubstituted(); + const matches = url.match(pattern); + + const path = matches[5]; + const query = matches[7] || ""; + const hexedHashedBody = crypto.sha512().updateWithText(request.body.tryGetSubstituted() || "").digest().toHex(); + const timestamp = Math.floor(Date.now() / 1000).toFixed(); + const payloadToSign = `${method}\n${path}\n${query}\n${hexedHashedBody}\n${timestamp}`; + const apiSecret = request.environment.get("api_secret"); + const sign = crypto.hmac.sha512().withTextSecret(apiSecret).updateWithText(payloadToSign).digest().toHex(); + + request.variables.set("timestamp", timestamp); + request.variables.set("sign", sign); +} \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/resources/rest/spot.http b/xchange-gateio-v4/src/test/resources/rest/spot.http index d80a6bf5e3e..afce84383fd 100644 --- a/xchange-gateio-v4/src/test/resources/rest/spot.http +++ b/xchange-gateio-v4/src/test/resources/rest/spot.http @@ -1,18 +1,7 @@ ### List personal trading history < {% - const pattern = RegExp("^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?"); - const url = request.url.tryGetSubstituted(); - const matches = url.match(pattern); - const method = "GET"; - const path = matches[5]; - const query = matches[7] || ""; - const hexedHashedBody = crypto.sha512().updateWithText(request.body.tryGetSubstituted() || "").digest().toHex(); - const timestamp = Math.floor(Date.now() / 1000).toFixed(); - const payloadToSign = `${method}\n${path}\n${query}\n${hexedHashedBody}\n${timestamp}`; - const apiSecret = request.environment.get("api_secret"); - const sign = crypto.hmac.sha512().withTextSecret(apiSecret).updateWithText(payloadToSign).digest().toHex(); - request.variables.set("timestamp", timestamp); - request.variables.set("sign", sign); + import {gen_sign} from 'sign.js' + gen_sign("GET", request); %} GET {{api_v4}}/spot/my_trades @@ -24,19 +13,8 @@ Content-Type: application/json ### Query account book < {% - const pattern = RegExp("^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?"); - const url = request.url.tryGetSubstituted(); - const matches = url.match(pattern); - const method = "GET"; - const path = matches[5]; - const query = matches[7] || ""; - const hexedHashedBody = crypto.sha512().updateWithText(request.body.tryGetSubstituted() || "").digest().toHex(); - const timestamp = Math.floor(Date.now() / 1000).toFixed(); - const payloadToSign = `${method}\n${path}\n${query}\n${hexedHashedBody}\n${timestamp}`; - const apiSecret = request.environment.get("api_secret"); - const sign = crypto.hmac.sha512().withTextSecret(apiSecret).updateWithText(payloadToSign).digest().toHex(); - request.variables.set("timestamp", timestamp); - request.variables.set("sign", sign); + import {gen_sign} from 'sign.js' + gen_sign("GET", request); %} GET {{api_v4}}/spot/account_book diff --git a/xchange-gateio-v4/src/test/resources/rest/wallet.http b/xchange-gateio-v4/src/test/resources/rest/wallet.http index b48f040c192..39e06302337 100644 --- a/xchange-gateio-v4/src/test/resources/rest/wallet.http +++ b/xchange-gateio-v4/src/test/resources/rest/wallet.http @@ -1,18 +1,7 @@ ### Retrieve withdrawal status < {% - const pattern = RegExp("^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?"); - const url = request.url.tryGetSubstituted(); - const matches = url.match(pattern); - const method = "GET"; - const path = matches[5]; - const query = matches[7] || ""; - const hexedHashedBody = crypto.sha512().updateWithText(request.body.tryGetSubstituted() || "").digest().toHex(); - const timestamp = Math.floor(Date.now() / 1000).toFixed(); - const payloadToSign = `${method}\n${path}\n${query}\n${hexedHashedBody}\n${timestamp}`; - const apiSecret = request.environment.get("api_secret"); - const sign = crypto.hmac.sha512().withTextSecret(apiSecret).updateWithText(payloadToSign).digest().toHex(); - request.variables.set("timestamp", timestamp); - request.variables.set("sign", sign); + import {gen_sign} from 'sign.js' + gen_sign("GET", request); %} GET {{api_v4}}/wallet/withdraw_status?currency=usdt @@ -24,19 +13,8 @@ Content-Type: application/json ### Retrieve transfer records between main and sub accounts < {% - const pattern = RegExp("^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?"); - const url = request.url.tryGetSubstituted(); - const matches = url.match(pattern); - const method = "GET"; - const path = matches[5]; - const query = matches[7] || ""; - const hexedHashedBody = crypto.sha512().updateWithText(request.body.tryGetSubstituted() || "").digest().toHex(); - const timestamp = Math.floor(Date.now() / 1000).toFixed(); - const payloadToSign = `${method}\n${path}\n${query}\n${hexedHashedBody}\n${timestamp}`; - const apiSecret = request.environment.get("api_secret"); - const sign = crypto.hmac.sha512().withTextSecret(apiSecret).updateWithText(payloadToSign).digest().toHex(); - request.variables.set("timestamp", timestamp); - request.variables.set("sign", sign); + import {gen_sign} from 'sign.js' + gen_sign("GET", request); %} GET {{api_v4}}/wallet/sub_account_transfers diff --git a/xchange-gateio-v4/src/test/resources/rest/withdraw.http b/xchange-gateio-v4/src/test/resources/rest/withdraw.http index bdc02b8dbbd..081f29c2976 100644 --- a/xchange-gateio-v4/src/test/resources/rest/withdraw.http +++ b/xchange-gateio-v4/src/test/resources/rest/withdraw.http @@ -1,19 +1,7 @@ ### Withdraw < {% - const pattern = RegExp("^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?"); - const url = request.url.tryGetSubstituted(); - const matches = url.match(pattern); - const method = "POST"; - const path = matches[5]; - const query = matches[7] || ""; - const body = request.body.tryGetSubstituted(); - const hexedHashedBody = crypto.sha512().updateWithText(request.body.tryGetSubstituted() || "").digest().toHex(); - const timestamp = Math.floor(Date.now() / 1000).toFixed(); - const payloadToSign = `${method}\n${path}\n${query}\n${hexedHashedBody}\n${timestamp}`; - const apiSecret = request.environment.get("api_secret"); - const sign = crypto.hmac.sha512().withTextSecret(apiSecret).updateWithText(payloadToSign).digest().toHex(); - request.variables.set("sign", sign); - request.variables.set("timestamp", timestamp); + import {gen_sign} from 'sign.js' + gen_sign("POST", request); %} POST {{api_v4}}/withdrawals From dead07b886590b6da67ff244190e255331616508 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Sun, 13 Aug 2023 17:28:53 +0200 Subject: [PATCH 097/159] Revert version --- pom.xml | 2 +- xchange-ascendex/pom.xml | 2 +- xchange-bankera/pom.xml | 2 +- xchange-bibox/pom.xml | 2 +- xchange-binance/pom.xml | 2 +- xchange-bitbay/pom.xml | 2 +- xchange-bitcoinaverage/pom.xml | 2 +- xchange-bitcoincharts/pom.xml | 2 +- xchange-bitcoincore/pom.xml | 2 +- xchange-bitcoinde/pom.xml | 2 +- xchange-bitcointoyou/pom.xml | 2 +- xchange-bitfinex/pom.xml | 2 +- xchange-bitflyer/pom.xml | 2 +- xchange-bithumb/pom.xml | 2 +- xchange-bitmex/pom.xml | 2 +- xchange-bitso/pom.xml | 2 +- xchange-bitstamp/pom.xml | 2 +- xchange-bittrex/pom.xml | 2 +- xchange-bity/pom.xml | 2 +- xchange-bitz/pom.xml | 2 +- xchange-bl3p/pom.xml | 2 +- xchange-bleutrade/pom.xml | 2 +- xchange-blockchain/pom.xml | 2 +- xchange-btcc/pom.xml | 2 +- xchange-btcmarkets/pom.xml | 2 +- xchange-btcturk/pom.xml | 2 +- xchange-bybit/pom.xml | 2 +- xchange-ccex/pom.xml | 2 +- xchange-cexio/pom.xml | 2 +- xchange-coinbase/pom.xml | 2 +- xchange-coinbasepro/pom.xml | 2 +- xchange-coincheck/pom.xml | 2 +- xchange-coindeal/pom.xml | 2 +- xchange-coindirect/pom.xml | 2 +- xchange-coinegg/pom.xml | 2 +- xchange-coinex/pom.xml | 2 +- xchange-coinfloor/pom.xml | 2 +- xchange-coingi/pom.xml | 2 +- xchange-coinjar/pom.xml | 2 +- xchange-coinmarketcap/pom.xml | 2 +- xchange-coinmate/pom.xml | 2 +- xchange-coinone/pom.xml | 2 +- xchange-core/pom.xml | 2 +- xchange-cryptowatch/pom.xml | 2 +- xchange-deribit/pom.xml | 2 +- xchange-dvchain/pom.xml | 2 +- xchange-dydx/pom.xml | 2 +- xchange-enigma/pom.xml | 2 +- xchange-examples/pom.xml | 2 +- xchange-exmo/pom.xml | 2 +- xchange-ftx/pom.xml | 2 +- xchange-gateio-v4/pom.xml | 2 +- xchange-gateio/pom.xml | 2 +- xchange-gemini/pom.xml | 2 +- xchange-globitex/pom.xml | 2 +- xchange-hitbtc/pom.xml | 2 +- xchange-huobi/pom.xml | 2 +- xchange-idex/pom.xml | 2 +- xchange-independentreserve/pom.xml | 2 +- xchange-itbit/pom.xml | 2 +- xchange-koineks/pom.xml | 2 +- xchange-koinim/pom.xml | 2 +- xchange-kraken/pom.xml | 2 +- xchange-krakenfutures/pom.xml | 2 +- xchange-kucoin/pom.xml | 2 +- xchange-kuna/pom.xml | 2 +- xchange-latoken/pom.xml | 2 +- xchange-lgo/pom.xml | 2 +- xchange-livecoin/pom.xml | 2 +- xchange-luno/pom.xml | 2 +- xchange-lykke/pom.xml | 2 +- xchange-mercadobitcoin/pom.xml | 2 +- xchange-mexc/pom.xml | 2 +- xchange-okcoin/pom.xml | 2 +- xchange-okex/pom.xml | 2 +- xchange-openexchangerates/pom.xml | 2 +- xchange-paribu/pom.xml | 2 +- xchange-paymium/pom.xml | 2 +- xchange-poloniex/pom.xml | 2 +- xchange-quoine/pom.xml | 2 +- xchange-ripple/pom.xml | 2 +- xchange-serum/pom.xml | 2 +- xchange-simulated/pom.xml | 2 +- xchange-stream-bankera/pom.xml | 2 +- xchange-stream-binance/pom.xml | 2 +- xchange-stream-bitfinex/pom.xml | 2 +- xchange-stream-bitflyer/pom.xml | 2 +- xchange-stream-bitmex/pom.xml | 2 +- xchange-stream-bitstamp/pom.xml | 2 +- xchange-stream-btcmarkets/pom.xml | 2 +- xchange-stream-cexio/pom.xml | 2 +- xchange-stream-coinbasepro/pom.xml | 2 +- xchange-stream-coincheck/pom.xml | 2 +- xchange-stream-coinjar/pom.xml | 2 +- xchange-stream-coinmate/pom.xml | 2 +- xchange-stream-core/pom.xml | 2 +- xchange-stream-dydx/pom.xml | 2 +- xchange-stream-ftx/pom.xml | 2 +- xchange-stream-gateio/pom.xml | 2 +- xchange-stream-gemini-v2/pom.xml | 2 +- xchange-stream-gemini/pom.xml | 2 +- xchange-stream-hitbtc/pom.xml | 2 +- xchange-stream-huobi/pom.xml | 2 +- xchange-stream-kraken/pom.xml | 2 +- xchange-stream-krakenfutures/pom.xml | 2 +- xchange-stream-kucoin/pom.xml | 2 +- xchange-stream-lgo/pom.xml | 2 +- xchange-stream-okcoin/pom.xml | 2 +- xchange-stream-okex/pom.xml | 2 +- xchange-stream-poloniex2/pom.xml | 2 +- xchange-stream-serum/pom.xml | 2 +- xchange-stream-service-core/pom.xml | 2 +- xchange-stream-service-netty/pom.xml | 2 +- xchange-stream-service-pubnub/pom.xml | 2 +- xchange-therock/pom.xml | 2 +- xchange-tradeogre/pom.xml | 2 +- xchange-truefx/pom.xml | 2 +- xchange-upbit/pom.xml | 2 +- xchange-vaultoro/pom.xml | 2 +- xchange-yobit/pom.xml | 2 +- xchange-zaif/pom.xml | 2 +- 121 files changed, 121 insertions(+), 121 deletions(-) diff --git a/pom.xml b/pom.xml index eed4a5a7650..dda9db2a57e 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT pom XChange diff --git a/xchange-ascendex/pom.xml b/xchange-ascendex/pom.xml index e9e18272157..91c3f01488f 100644 --- a/xchange-ascendex/pom.xml +++ b/xchange-ascendex/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-ascendex diff --git a/xchange-bankera/pom.xml b/xchange-bankera/pom.xml index b5dd84444d5..04661c9454d 100644 --- a/xchange-bankera/pom.xml +++ b/xchange-bankera/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-bankera diff --git a/xchange-bibox/pom.xml b/xchange-bibox/pom.xml index a3d9f3e7dad..1a5a12604d3 100644 --- a/xchange-bibox/pom.xml +++ b/xchange-bibox/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-bibox diff --git a/xchange-binance/pom.xml b/xchange-binance/pom.xml index 8a410c4f434..52435ef1f26 100644 --- a/xchange-binance/pom.xml +++ b/xchange-binance/pom.xml @@ -5,7 +5,7 @@ xchange-parent org.knowm.xchange - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-binance diff --git a/xchange-bitbay/pom.xml b/xchange-bitbay/pom.xml index d704c8ff7c2..1b444f27c9d 100644 --- a/xchange-bitbay/pom.xml +++ b/xchange-bitbay/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-bitbay diff --git a/xchange-bitcoinaverage/pom.xml b/xchange-bitcoinaverage/pom.xml index 2e03004ce1e..43448314fc2 100644 --- a/xchange-bitcoinaverage/pom.xml +++ b/xchange-bitcoinaverage/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-bitcoinaverage diff --git a/xchange-bitcoincharts/pom.xml b/xchange-bitcoincharts/pom.xml index ceb32d127db..52e57a39b66 100644 --- a/xchange-bitcoincharts/pom.xml +++ b/xchange-bitcoincharts/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-bitcoincharts diff --git a/xchange-bitcoincore/pom.xml b/xchange-bitcoincore/pom.xml index a5fae022db6..c98da4419e6 100644 --- a/xchange-bitcoincore/pom.xml +++ b/xchange-bitcoincore/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-bitcoincore diff --git a/xchange-bitcoinde/pom.xml b/xchange-bitcoinde/pom.xml index 787bc848fa5..5c04b494ff8 100644 --- a/xchange-bitcoinde/pom.xml +++ b/xchange-bitcoinde/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-bitcoinde diff --git a/xchange-bitcointoyou/pom.xml b/xchange-bitcointoyou/pom.xml index 74059210dcd..f6cb7d4773c 100644 --- a/xchange-bitcointoyou/pom.xml +++ b/xchange-bitcointoyou/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-bitcointoyou diff --git a/xchange-bitfinex/pom.xml b/xchange-bitfinex/pom.xml index 2103388210e..a31f2fd7ecc 100644 --- a/xchange-bitfinex/pom.xml +++ b/xchange-bitfinex/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-bitfinex diff --git a/xchange-bitflyer/pom.xml b/xchange-bitflyer/pom.xml index bb79f5defd3..826bbef2400 100755 --- a/xchange-bitflyer/pom.xml +++ b/xchange-bitflyer/pom.xml @@ -6,7 +6,7 @@ xchange-parent org.knowm.xchange - 5.1.1.bigscoop + 5.1.1-SNAPSHOT diff --git a/xchange-bithumb/pom.xml b/xchange-bithumb/pom.xml index 3f8b0c649e2..d7ac9f91394 100644 --- a/xchange-bithumb/pom.xml +++ b/xchange-bithumb/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-bithumb diff --git a/xchange-bitmex/pom.xml b/xchange-bitmex/pom.xml index e1e4cf0330c..4a9b3809b2f 100755 --- a/xchange-bitmex/pom.xml +++ b/xchange-bitmex/pom.xml @@ -4,7 +4,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-bitmex diff --git a/xchange-bitso/pom.xml b/xchange-bitso/pom.xml index 5af137e13b1..b33e203d35a 100644 --- a/xchange-bitso/pom.xml +++ b/xchange-bitso/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-bitso diff --git a/xchange-bitstamp/pom.xml b/xchange-bitstamp/pom.xml index df159fe971a..8e3004aa9cf 100644 --- a/xchange-bitstamp/pom.xml +++ b/xchange-bitstamp/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-bitstamp diff --git a/xchange-bittrex/pom.xml b/xchange-bittrex/pom.xml index f0c913e224c..bf13dccc6a2 100644 --- a/xchange-bittrex/pom.xml +++ b/xchange-bittrex/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-bittrex diff --git a/xchange-bity/pom.xml b/xchange-bity/pom.xml index 8244312308b..dcde294d79c 100644 --- a/xchange-bity/pom.xml +++ b/xchange-bity/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-bity diff --git a/xchange-bitz/pom.xml b/xchange-bitz/pom.xml index 40770a1dde6..589d18e2a10 100644 --- a/xchange-bitz/pom.xml +++ b/xchange-bitz/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-bitz diff --git a/xchange-bl3p/pom.xml b/xchange-bl3p/pom.xml index 86b844be2ba..f150454e95f 100644 --- a/xchange-bl3p/pom.xml +++ b/xchange-bl3p/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-bl3p diff --git a/xchange-bleutrade/pom.xml b/xchange-bleutrade/pom.xml index afcec3a7cb8..4b782365c47 100644 --- a/xchange-bleutrade/pom.xml +++ b/xchange-bleutrade/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-bleutrade diff --git a/xchange-blockchain/pom.xml b/xchange-blockchain/pom.xml index 9b2bcf75ffc..6da4d450e4e 100644 --- a/xchange-blockchain/pom.xml +++ b/xchange-blockchain/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-blockchain diff --git a/xchange-btcc/pom.xml b/xchange-btcc/pom.xml index 16b763b5aff..af81e77690b 100644 --- a/xchange-btcc/pom.xml +++ b/xchange-btcc/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-btcc diff --git a/xchange-btcmarkets/pom.xml b/xchange-btcmarkets/pom.xml index 088e65c512c..912b8819d0a 100644 --- a/xchange-btcmarkets/pom.xml +++ b/xchange-btcmarkets/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-btcmarkets diff --git a/xchange-btcturk/pom.xml b/xchange-btcturk/pom.xml index 997622d6268..a45e95e42e1 100644 --- a/xchange-btcturk/pom.xml +++ b/xchange-btcturk/pom.xml @@ -6,7 +6,7 @@ xchange-parent org.knowm.xchange - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-btcturk diff --git a/xchange-bybit/pom.xml b/xchange-bybit/pom.xml index 1744032fd33..3a4c4d301dc 100644 --- a/xchange-bybit/pom.xml +++ b/xchange-bybit/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-bybit diff --git a/xchange-ccex/pom.xml b/xchange-ccex/pom.xml index a74f3516630..a1031dc0247 100644 --- a/xchange-ccex/pom.xml +++ b/xchange-ccex/pom.xml @@ -4,7 +4,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-ccex XChange C-Cex diff --git a/xchange-cexio/pom.xml b/xchange-cexio/pom.xml index b777d928708..978dfbabee5 100644 --- a/xchange-cexio/pom.xml +++ b/xchange-cexio/pom.xml @@ -6,7 +6,7 @@ xchange-parent org.knowm.xchange - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-cexio diff --git a/xchange-coinbase/pom.xml b/xchange-coinbase/pom.xml index da6418c6790..af39f7f0f78 100644 --- a/xchange-coinbase/pom.xml +++ b/xchange-coinbase/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-coinbase diff --git a/xchange-coinbasepro/pom.xml b/xchange-coinbasepro/pom.xml index 2c1e5c65cd9..749879296f1 100644 --- a/xchange-coinbasepro/pom.xml +++ b/xchange-coinbasepro/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-coinbasepro diff --git a/xchange-coincheck/pom.xml b/xchange-coincheck/pom.xml index f996475908c..4ce1cfd3e26 100644 --- a/xchange-coincheck/pom.xml +++ b/xchange-coincheck/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-coincheck diff --git a/xchange-coindeal/pom.xml b/xchange-coindeal/pom.xml index 25c306bc6dc..b841eb58acc 100644 --- a/xchange-coindeal/pom.xml +++ b/xchange-coindeal/pom.xml @@ -3,7 +3,7 @@ xchange-parent org.knowm.xchange - 5.1.1.bigscoop + 5.1.1-SNAPSHOT 4.0.0 diff --git a/xchange-coindirect/pom.xml b/xchange-coindirect/pom.xml index 98665947fdb..3c1db7cc9ca 100644 --- a/xchange-coindirect/pom.xml +++ b/xchange-coindirect/pom.xml @@ -5,7 +5,7 @@ xchange-parent org.knowm.xchange - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-coindirect diff --git a/xchange-coinegg/pom.xml b/xchange-coinegg/pom.xml index 95cdba46b50..4092c8e2e31 100644 --- a/xchange-coinegg/pom.xml +++ b/xchange-coinegg/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-coinegg diff --git a/xchange-coinex/pom.xml b/xchange-coinex/pom.xml index 80513cf4bfb..f54a7e3aaa3 100644 --- a/xchange-coinex/pom.xml +++ b/xchange-coinex/pom.xml @@ -3,7 +3,7 @@ xchange-parent org.knowm.xchange - 5.1.1.bigscoop + 5.1.1-SNAPSHOT 4.0.0 diff --git a/xchange-coinfloor/pom.xml b/xchange-coinfloor/pom.xml index 07c638a3020..50cc60bdcf6 100644 --- a/xchange-coinfloor/pom.xml +++ b/xchange-coinfloor/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-coinfloor diff --git a/xchange-coingi/pom.xml b/xchange-coingi/pom.xml index d42d98f4c60..18a31b7b2dd 100644 --- a/xchange-coingi/pom.xml +++ b/xchange-coingi/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-coingi diff --git a/xchange-coinjar/pom.xml b/xchange-coinjar/pom.xml index f86e5c97233..ff54d945c59 100644 --- a/xchange-coinjar/pom.xml +++ b/xchange-coinjar/pom.xml @@ -5,7 +5,7 @@ xchange-parent org.knowm.xchange - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-coinjar diff --git a/xchange-coinmarketcap/pom.xml b/xchange-coinmarketcap/pom.xml index 16cdca08ee7..5171b6a57f9 100644 --- a/xchange-coinmarketcap/pom.xml +++ b/xchange-coinmarketcap/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-coinmarketcap diff --git a/xchange-coinmate/pom.xml b/xchange-coinmate/pom.xml index 3068e488687..4f91ee96f48 100644 --- a/xchange-coinmate/pom.xml +++ b/xchange-coinmate/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-coinmate diff --git a/xchange-coinone/pom.xml b/xchange-coinone/pom.xml index a3efe4f09f9..6f05aa7c873 100644 --- a/xchange-coinone/pom.xml +++ b/xchange-coinone/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-coinone diff --git a/xchange-core/pom.xml b/xchange-core/pom.xml index b285a74d544..1c2fe98a13a 100644 --- a/xchange-core/pom.xml +++ b/xchange-core/pom.xml @@ -3,7 +3,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-core diff --git a/xchange-cryptowatch/pom.xml b/xchange-cryptowatch/pom.xml index 9a56132e07a..fce45a676c1 100644 --- a/xchange-cryptowatch/pom.xml +++ b/xchange-cryptowatch/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-cryptowatch diff --git a/xchange-deribit/pom.xml b/xchange-deribit/pom.xml index 20f03904b28..b1a13b5df07 100644 --- a/xchange-deribit/pom.xml +++ b/xchange-deribit/pom.xml @@ -4,7 +4,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-deribit diff --git a/xchange-dvchain/pom.xml b/xchange-dvchain/pom.xml index f51b8d6898a..01307da36ae 100644 --- a/xchange-dvchain/pom.xml +++ b/xchange-dvchain/pom.xml @@ -3,7 +3,7 @@ xchange-parent org.knowm.xchange - 5.1.1.bigscoop + 5.1.1-SNAPSHOT 4.0.0 diff --git a/xchange-dydx/pom.xml b/xchange-dydx/pom.xml index 2bc537da874..458d0e761a7 100644 --- a/xchange-dydx/pom.xml +++ b/xchange-dydx/pom.xml @@ -3,7 +3,7 @@ xchange-parent org.knowm.xchange - 5.1.1.bigscoop + 5.1.1-SNAPSHOT 4.0.0 diff --git a/xchange-enigma/pom.xml b/xchange-enigma/pom.xml index 2206c73383c..2963a5d93fc 100644 --- a/xchange-enigma/pom.xml +++ b/xchange-enigma/pom.xml @@ -5,7 +5,7 @@ xchange-parent org.knowm.xchange - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-enigma diff --git a/xchange-examples/pom.xml b/xchange-examples/pom.xml index 162f7f9b265..997bf9a00f5 100755 --- a/xchange-examples/pom.xml +++ b/xchange-examples/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-examples diff --git a/xchange-exmo/pom.xml b/xchange-exmo/pom.xml index 15f649eb6dc..63459974f3b 100644 --- a/xchange-exmo/pom.xml +++ b/xchange-exmo/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-exmo diff --git a/xchange-ftx/pom.xml b/xchange-ftx/pom.xml index a5e0697d993..6c1692ff200 100644 --- a/xchange-ftx/pom.xml +++ b/xchange-ftx/pom.xml @@ -6,7 +6,7 @@ xchange-parent org.knowm.xchange - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-ftx diff --git a/xchange-gateio-v4/pom.xml b/xchange-gateio-v4/pom.xml index f5c8f899aa0..11bf6d07365 100644 --- a/xchange-gateio-v4/pom.xml +++ b/xchange-gateio-v4/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-gateio-v4 diff --git a/xchange-gateio/pom.xml b/xchange-gateio/pom.xml index 8d0faf4c3fc..c1703304be8 100644 --- a/xchange-gateio/pom.xml +++ b/xchange-gateio/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-gateio diff --git a/xchange-gemini/pom.xml b/xchange-gemini/pom.xml index 629e2f87f97..14b04317fac 100644 --- a/xchange-gemini/pom.xml +++ b/xchange-gemini/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-gemini diff --git a/xchange-globitex/pom.xml b/xchange-globitex/pom.xml index 37564ee3366..017073f1ff9 100644 --- a/xchange-globitex/pom.xml +++ b/xchange-globitex/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-globitex diff --git a/xchange-hitbtc/pom.xml b/xchange-hitbtc/pom.xml index e3603b03ec9..d9af0b7c655 100644 --- a/xchange-hitbtc/pom.xml +++ b/xchange-hitbtc/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-hitbtc diff --git a/xchange-huobi/pom.xml b/xchange-huobi/pom.xml index c68b0a31f2e..3eaf60913ed 100644 --- a/xchange-huobi/pom.xml +++ b/xchange-huobi/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-huobi diff --git a/xchange-idex/pom.xml b/xchange-idex/pom.xml index b0b01136106..64b10f25661 100644 --- a/xchange-idex/pom.xml +++ b/xchange-idex/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-idex diff --git a/xchange-independentreserve/pom.xml b/xchange-independentreserve/pom.xml index 7c38fdd323c..8c6dd6838d4 100644 --- a/xchange-independentreserve/pom.xml +++ b/xchange-independentreserve/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-independentreserve diff --git a/xchange-itbit/pom.xml b/xchange-itbit/pom.xml index a122b4d62a6..e7ac04a0019 100644 --- a/xchange-itbit/pom.xml +++ b/xchange-itbit/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-itbit diff --git a/xchange-koineks/pom.xml b/xchange-koineks/pom.xml index a3c19a80c5f..4abf5d3536c 100644 --- a/xchange-koineks/pom.xml +++ b/xchange-koineks/pom.xml @@ -3,7 +3,7 @@ xchange-parent org.knowm.xchange - 5.1.1.bigscoop + 5.1.1-SNAPSHOT 4.0.0 diff --git a/xchange-koinim/pom.xml b/xchange-koinim/pom.xml index 93de038abab..2b1028f15fb 100644 --- a/xchange-koinim/pom.xml +++ b/xchange-koinim/pom.xml @@ -3,7 +3,7 @@ xchange-parent org.knowm.xchange - 5.1.1.bigscoop + 5.1.1-SNAPSHOT 4.0.0 diff --git a/xchange-kraken/pom.xml b/xchange-kraken/pom.xml index d8217b89ff6..45ede20f403 100644 --- a/xchange-kraken/pom.xml +++ b/xchange-kraken/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-kraken diff --git a/xchange-krakenfutures/pom.xml b/xchange-krakenfutures/pom.xml index 0b6f93e3a7d..abf75c4bbe1 100644 --- a/xchange-krakenfutures/pom.xml +++ b/xchange-krakenfutures/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-krakenfutures diff --git a/xchange-kucoin/pom.xml b/xchange-kucoin/pom.xml index deb0dc2d133..5601fc086e4 100644 --- a/xchange-kucoin/pom.xml +++ b/xchange-kucoin/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-kucoin diff --git a/xchange-kuna/pom.xml b/xchange-kuna/pom.xml index 957e07a44a2..b33de315225 100644 --- a/xchange-kuna/pom.xml +++ b/xchange-kuna/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-kuna diff --git a/xchange-latoken/pom.xml b/xchange-latoken/pom.xml index 2f888a75695..6d27f6ea484 100644 --- a/xchange-latoken/pom.xml +++ b/xchange-latoken/pom.xml @@ -5,7 +5,7 @@ xchange-parent org.knowm.xchange - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-latoken diff --git a/xchange-lgo/pom.xml b/xchange-lgo/pom.xml index 5a82f0bb616..22509aecf09 100644 --- a/xchange-lgo/pom.xml +++ b/xchange-lgo/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-lgo diff --git a/xchange-livecoin/pom.xml b/xchange-livecoin/pom.xml index 413b9cdc11a..cca3cccfc08 100644 --- a/xchange-livecoin/pom.xml +++ b/xchange-livecoin/pom.xml @@ -3,7 +3,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-livecoin XChange Livecoin diff --git a/xchange-luno/pom.xml b/xchange-luno/pom.xml index 63a05efae23..6850ca511bf 100644 --- a/xchange-luno/pom.xml +++ b/xchange-luno/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-luno diff --git a/xchange-lykke/pom.xml b/xchange-lykke/pom.xml index f438d39e072..67bf7470fdd 100644 --- a/xchange-lykke/pom.xml +++ b/xchange-lykke/pom.xml @@ -3,7 +3,7 @@ xchange-parent org.knowm.xchange - 5.1.1.bigscoop + 5.1.1-SNAPSHOT 4.0.0 diff --git a/xchange-mercadobitcoin/pom.xml b/xchange-mercadobitcoin/pom.xml index 464a3515af5..ed27baf0dca 100644 --- a/xchange-mercadobitcoin/pom.xml +++ b/xchange-mercadobitcoin/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-mercadobitcoin diff --git a/xchange-mexc/pom.xml b/xchange-mexc/pom.xml index 8f75d41cdd1..ba80e3d2729 100644 --- a/xchange-mexc/pom.xml +++ b/xchange-mexc/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-mexc diff --git a/xchange-okcoin/pom.xml b/xchange-okcoin/pom.xml index b0c8c5a8003..2bfb2cf4223 100644 --- a/xchange-okcoin/pom.xml +++ b/xchange-okcoin/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-okcoin diff --git a/xchange-okex/pom.xml b/xchange-okex/pom.xml index 45741505db0..75244922842 100644 --- a/xchange-okex/pom.xml +++ b/xchange-okex/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-okex diff --git a/xchange-openexchangerates/pom.xml b/xchange-openexchangerates/pom.xml index 983f700dcd8..acc11c780f8 100644 --- a/xchange-openexchangerates/pom.xml +++ b/xchange-openexchangerates/pom.xml @@ -4,7 +4,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-openexchangerates diff --git a/xchange-paribu/pom.xml b/xchange-paribu/pom.xml index c79d1714379..86245c5272c 100644 --- a/xchange-paribu/pom.xml +++ b/xchange-paribu/pom.xml @@ -3,7 +3,7 @@ xchange-parent org.knowm.xchange - 5.1.1.bigscoop + 5.1.1-SNAPSHOT 4.0.0 diff --git a/xchange-paymium/pom.xml b/xchange-paymium/pom.xml index 647458f0bde..4779e63ce0f 100644 --- a/xchange-paymium/pom.xml +++ b/xchange-paymium/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-paymium diff --git a/xchange-poloniex/pom.xml b/xchange-poloniex/pom.xml index 49b56c54e29..9d81302b6a9 100755 --- a/xchange-poloniex/pom.xml +++ b/xchange-poloniex/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-poloniex diff --git a/xchange-quoine/pom.xml b/xchange-quoine/pom.xml index 35c0f76d949..59ad3ec56c3 100644 --- a/xchange-quoine/pom.xml +++ b/xchange-quoine/pom.xml @@ -3,7 +3,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-quoine diff --git a/xchange-ripple/pom.xml b/xchange-ripple/pom.xml index a7418fd5ffd..0efb377f889 100644 --- a/xchange-ripple/pom.xml +++ b/xchange-ripple/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-ripple diff --git a/xchange-serum/pom.xml b/xchange-serum/pom.xml index c522abb3c05..2f037834524 100644 --- a/xchange-serum/pom.xml +++ b/xchange-serum/pom.xml @@ -3,7 +3,7 @@ xchange-parent org.knowm.xchange - 5.1.1.bigscoop + 5.1.1-SNAPSHOT 4.0.0 diff --git a/xchange-simulated/pom.xml b/xchange-simulated/pom.xml index d7ea0bf4d0e..a537c2eeb74 100644 --- a/xchange-simulated/pom.xml +++ b/xchange-simulated/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-simulated diff --git a/xchange-stream-bankera/pom.xml b/xchange-stream-bankera/pom.xml index 0074e90adbd..91c44b418b2 100644 --- a/xchange-stream-bankera/pom.xml +++ b/xchange-stream-bankera/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT XChange Bankera Stream diff --git a/xchange-stream-binance/pom.xml b/xchange-stream-binance/pom.xml index d6eb2b49a21..5e1eb990e06 100644 --- a/xchange-stream-binance/pom.xml +++ b/xchange-stream-binance/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT XChange Binance Stream diff --git a/xchange-stream-bitfinex/pom.xml b/xchange-stream-bitfinex/pom.xml index 42ae0b99e4d..118498a6145 100644 --- a/xchange-stream-bitfinex/pom.xml +++ b/xchange-stream-bitfinex/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT XChange Bitfinex Stream diff --git a/xchange-stream-bitflyer/pom.xml b/xchange-stream-bitflyer/pom.xml index 6b689fb30c0..c6e655388b1 100644 --- a/xchange-stream-bitflyer/pom.xml +++ b/xchange-stream-bitflyer/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT XChange Bitflyer Stream diff --git a/xchange-stream-bitmex/pom.xml b/xchange-stream-bitmex/pom.xml index 33ddc7ddb42..d41adb8c405 100644 --- a/xchange-stream-bitmex/pom.xml +++ b/xchange-stream-bitmex/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT XChange Bitmex Stream diff --git a/xchange-stream-bitstamp/pom.xml b/xchange-stream-bitstamp/pom.xml index 7bf01611bc9..f0a68bdb48a 100644 --- a/xchange-stream-bitstamp/pom.xml +++ b/xchange-stream-bitstamp/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT XChange Bitstamp Stream diff --git a/xchange-stream-btcmarkets/pom.xml b/xchange-stream-btcmarkets/pom.xml index 0eeb4442ec2..9cc1955e490 100644 --- a/xchange-stream-btcmarkets/pom.xml +++ b/xchange-stream-btcmarkets/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT XChange BTCMarkets Stream diff --git a/xchange-stream-cexio/pom.xml b/xchange-stream-cexio/pom.xml index 8f1c941eae9..b5748d166c6 100644 --- a/xchange-stream-cexio/pom.xml +++ b/xchange-stream-cexio/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT XChange Cex.io Stream diff --git a/xchange-stream-coinbasepro/pom.xml b/xchange-stream-coinbasepro/pom.xml index 8d4a66c56f1..45cc3e7a124 100644 --- a/xchange-stream-coinbasepro/pom.xml +++ b/xchange-stream-coinbasepro/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT XChange CoinbasePro Stream diff --git a/xchange-stream-coincheck/pom.xml b/xchange-stream-coincheck/pom.xml index 07a3d083e0d..4b61813b494 100644 --- a/xchange-stream-coincheck/pom.xml +++ b/xchange-stream-coincheck/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT XChange Coincheck Stream diff --git a/xchange-stream-coinjar/pom.xml b/xchange-stream-coinjar/pom.xml index 960c378e483..96e2d2307b4 100644 --- a/xchange-stream-coinjar/pom.xml +++ b/xchange-stream-coinjar/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT XChange Coinjar Stream diff --git a/xchange-stream-coinmate/pom.xml b/xchange-stream-coinmate/pom.xml index 232eee56e25..fb4f2973668 100644 --- a/xchange-stream-coinmate/pom.xml +++ b/xchange-stream-coinmate/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT XChange Coinmate Stream diff --git a/xchange-stream-core/pom.xml b/xchange-stream-core/pom.xml index 9d96e15523f..373ef95b891 100644 --- a/xchange-stream-core/pom.xml +++ b/xchange-stream-core/pom.xml @@ -3,7 +3,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT 4.0.0 diff --git a/xchange-stream-dydx/pom.xml b/xchange-stream-dydx/pom.xml index 9d513650473..bc35901c74e 100644 --- a/xchange-stream-dydx/pom.xml +++ b/xchange-stream-dydx/pom.xml @@ -3,7 +3,7 @@ xchange-parent org.knowm.xchange - 5.1.1.bigscoop + 5.1.1-SNAPSHOT 4.0.0 diff --git a/xchange-stream-ftx/pom.xml b/xchange-stream-ftx/pom.xml index 1d8dc2e4c9f..b14b66f8879 100644 --- a/xchange-stream-ftx/pom.xml +++ b/xchange-stream-ftx/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT XChange Ftx Stream diff --git a/xchange-stream-gateio/pom.xml b/xchange-stream-gateio/pom.xml index 85d64568b1c..96d14334aa5 100644 --- a/xchange-stream-gateio/pom.xml +++ b/xchange-stream-gateio/pom.xml @@ -4,7 +4,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-stream-gateio diff --git a/xchange-stream-gemini-v2/pom.xml b/xchange-stream-gemini-v2/pom.xml index d254e1f2469..bbda9c81033 100644 --- a/xchange-stream-gemini-v2/pom.xml +++ b/xchange-stream-gemini-v2/pom.xml @@ -9,7 +9,7 @@ xchange-parent org.knowm.xchange - 5.1.1.bigscoop + 5.1.1-SNAPSHOT diff --git a/xchange-stream-gemini/pom.xml b/xchange-stream-gemini/pom.xml index 74c4d4363bc..ec035a31a1f 100644 --- a/xchange-stream-gemini/pom.xml +++ b/xchange-stream-gemini/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT XChange Gemini Stream diff --git a/xchange-stream-hitbtc/pom.xml b/xchange-stream-hitbtc/pom.xml index a049cd43373..5a3f79401ee 100644 --- a/xchange-stream-hitbtc/pom.xml +++ b/xchange-stream-hitbtc/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT XChange Hitbtc Stream diff --git a/xchange-stream-huobi/pom.xml b/xchange-stream-huobi/pom.xml index 374eb219183..6ae33aa6dd2 100644 --- a/xchange-stream-huobi/pom.xml +++ b/xchange-stream-huobi/pom.xml @@ -3,7 +3,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT 4.0.0 diff --git a/xchange-stream-kraken/pom.xml b/xchange-stream-kraken/pom.xml index 9165c26fe5f..1cb5a278eee 100644 --- a/xchange-stream-kraken/pom.xml +++ b/xchange-stream-kraken/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT XChange Kraken Stream diff --git a/xchange-stream-krakenfutures/pom.xml b/xchange-stream-krakenfutures/pom.xml index 6536a6cf5c7..e7f032843d9 100644 --- a/xchange-stream-krakenfutures/pom.xml +++ b/xchange-stream-krakenfutures/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-stream-krakenfutures diff --git a/xchange-stream-kucoin/pom.xml b/xchange-stream-kucoin/pom.xml index 24b95b0cda1..33beba770dd 100644 --- a/xchange-stream-kucoin/pom.xml +++ b/xchange-stream-kucoin/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT XChange Kucoin Stream diff --git a/xchange-stream-lgo/pom.xml b/xchange-stream-lgo/pom.xml index 03c7d7df312..5699c7f355f 100644 --- a/xchange-stream-lgo/pom.xml +++ b/xchange-stream-lgo/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT XChange LGO Stream diff --git a/xchange-stream-okcoin/pom.xml b/xchange-stream-okcoin/pom.xml index d57d513ec09..7f58e7b7054 100644 --- a/xchange-stream-okcoin/pom.xml +++ b/xchange-stream-okcoin/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT XChange OKCoin Stream diff --git a/xchange-stream-okex/pom.xml b/xchange-stream-okex/pom.xml index cce005af2d0..a39c5812218 100644 --- a/xchange-stream-okex/pom.xml +++ b/xchange-stream-okex/pom.xml @@ -6,7 +6,7 @@ xchange-parent org.knowm.xchange - 5.1.1.bigscoop + 5.1.1-SNAPSHOT XChange Okex Stream diff --git a/xchange-stream-poloniex2/pom.xml b/xchange-stream-poloniex2/pom.xml index f708dedf60e..23ecca7cb7d 100644 --- a/xchange-stream-poloniex2/pom.xml +++ b/xchange-stream-poloniex2/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT XChange Poloniex 2 Stream diff --git a/xchange-stream-serum/pom.xml b/xchange-stream-serum/pom.xml index 311ca5b0522..2778be0cedf 100644 --- a/xchange-stream-serum/pom.xml +++ b/xchange-stream-serum/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT XChange Serum Stream diff --git a/xchange-stream-service-core/pom.xml b/xchange-stream-service-core/pom.xml index 4bc3d9c3049..9a2a333617b 100644 --- a/xchange-stream-service-core/pom.xml +++ b/xchange-stream-service-core/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT XChange Core Stream Service diff --git a/xchange-stream-service-netty/pom.xml b/xchange-stream-service-netty/pom.xml index b99fb4c08bb..aba65d517fd 100644 --- a/xchange-stream-service-netty/pom.xml +++ b/xchange-stream-service-netty/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT XChange Core Stream Netty diff --git a/xchange-stream-service-pubnub/pom.xml b/xchange-stream-service-pubnub/pom.xml index 1f3c3ba4322..6f73e624a4f 100644 --- a/xchange-stream-service-pubnub/pom.xml +++ b/xchange-stream-service-pubnub/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT XChange Core Stream Pubnub diff --git a/xchange-therock/pom.xml b/xchange-therock/pom.xml index cf83b30c605..035c3ccd7cb 100644 --- a/xchange-therock/pom.xml +++ b/xchange-therock/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-therock diff --git a/xchange-tradeogre/pom.xml b/xchange-tradeogre/pom.xml index bbaa789399f..589941b3ad5 100644 --- a/xchange-tradeogre/pom.xml +++ b/xchange-tradeogre/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-tradeogre diff --git a/xchange-truefx/pom.xml b/xchange-truefx/pom.xml index 0812c77afba..7ce3b63e608 100644 --- a/xchange-truefx/pom.xml +++ b/xchange-truefx/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-truefx diff --git a/xchange-upbit/pom.xml b/xchange-upbit/pom.xml index 90585737b65..7d6cf373af4 100644 --- a/xchange-upbit/pom.xml +++ b/xchange-upbit/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-upbit diff --git a/xchange-vaultoro/pom.xml b/xchange-vaultoro/pom.xml index a050d8c4285..f402ccf4801 100644 --- a/xchange-vaultoro/pom.xml +++ b/xchange-vaultoro/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-vaultoro diff --git a/xchange-yobit/pom.xml b/xchange-yobit/pom.xml index 0edb8654da5..97bc36a0b87 100644 --- a/xchange-yobit/pom.xml +++ b/xchange-yobit/pom.xml @@ -3,7 +3,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-yobit XChange YoBit diff --git a/xchange-zaif/pom.xml b/xchange-zaif/pom.xml index 5d4b40e7301..71bf905b873 100644 --- a/xchange-zaif/pom.xml +++ b/xchange-zaif/pom.xml @@ -5,7 +5,7 @@ org.knowm.xchange xchange-parent - 5.1.1.bigscoop + 5.1.1-SNAPSHOT xchange-zaif From 10e3e4e4a44122317c6cc05eb9ccd9293551093e Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Sun, 13 Aug 2023 17:29:39 +0200 Subject: [PATCH 098/159] Revert version --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 63c4a0dd26d..227cfaadacf 100644 --- a/README.md +++ b/README.md @@ -179,7 +179,7 @@ For snapshots, add the following repository to your pom.xml file. The current snapshot version is: - 5.1.99 + 5.1.1-SNAPSHOT ## Building with Maven From 57e70f743593c60b6f1198c4c4d1d0a3bd2c0112 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Sun, 13 Aug 2023 18:57:44 +0200 Subject: [PATCH 099/159] Revert code style to java 8 --- pom.xml | 5 +---- .../xchange/gateio/service/GateioTradeService.java | 3 ++- .../gateio/service/GateioTradeServiceRaw.java | 3 ++- .../service/GateioMarketDataServiceRawTest.java | 3 ++- .../gateio/service/GateioMarketDataServiceTest.java | 10 +++++----- .../gateio/service/GateioTradeServiceRawTest.java | 2 +- .../gateio/service/GateioTradeServiceTest.java | 12 +++++++----- .../xchange/gateio/service/GateioV4DigestTest.java | 9 ++++++--- .../bitrich/xchangestream/gateio/config/Config.java | 6 +++--- 9 files changed, 29 insertions(+), 24 deletions(-) diff --git a/pom.xml b/pom.xml index dda9db2a57e..bc48780d1fe 100644 --- a/pom.xml +++ b/pom.xml @@ -30,10 +30,7 @@ UTF-8 UTF-8 - 11 - 11 - 11 - + 1.8 3.24.2 3.12.0 2.14.1 diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeService.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeService.java index 904e9da03df..44e55432b64 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeService.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeService.java @@ -2,6 +2,7 @@ import java.io.IOException; import java.util.Collection; +import java.util.Collections; import java.util.List; import java.util.stream.Collectors; import org.apache.commons.lang3.Validate; @@ -67,7 +68,7 @@ public Collection getOrder(OrderQueryParams... orderQueryParams) throws I try { GateioOrder gateioOrder = getOrder(params.getOrderId(), params.getInstrument()); - return List.of(GateioAdapters.toOrder(gateioOrder)); + return Collections.singletonList(GateioAdapters.toOrder(gateioOrder)); } catch (GateioException e) { throw GateioErrorAdapter.adapt(e); diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeServiceRaw.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeServiceRaw.java index 560c75a165e..a4cde452b95 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeServiceRaw.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeServiceRaw.java @@ -1,6 +1,7 @@ package org.knowm.xchange.gateio.service; import java.io.IOException; +import java.util.EnumSet; import java.util.List; import java.util.Set; import org.apache.commons.lang3.Validate; @@ -28,7 +29,7 @@ public GateioTradeServiceRaw(GateioExchange exchange) { public List listOrders(Instrument instrument, OrderStatus orderStatus) throws IOException { // validate arguments Validate.notNull(orderStatus); - var allowedOrderStatuses = Set.of(OrderStatus.OPEN, OrderStatus.CLOSED); + Set allowedOrderStatuses = EnumSet.of(OrderStatus.OPEN, OrderStatus.CLOSED); Validate.validState(allowedOrderStatuses.contains(orderStatus), "Allowed order statuses are: {}", allowedOrderStatuses); Validate.notNull(instrument); diff --git a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioMarketDataServiceRawTest.java b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioMarketDataServiceRawTest.java index 4751a5bb95a..3e52b4693a7 100644 --- a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioMarketDataServiceRawTest.java +++ b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioMarketDataServiceRawTest.java @@ -6,6 +6,7 @@ import java.math.BigDecimal; import java.time.Instant; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.junit.jupiter.api.Test; import org.knowm.xchange.currency.Currency; @@ -81,7 +82,7 @@ public void getGateioOrderBook_valid() throws IOException { @Test public void getCurrencyChains_valid_result() throws IOException { - List expected = List.of( + List expected = Arrays.asList( GateioCurrencyChain.builder() .chain("BTC") .chainNameCN("比特币 BRC20/Ordinals") diff --git a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioMarketDataServiceTest.java b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioMarketDataServiceTest.java index b7b168b732e..5a5f5fbd8f4 100644 --- a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioMarketDataServiceTest.java +++ b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioMarketDataServiceTest.java @@ -58,9 +58,9 @@ void getOrderBook_valid() throws IOException { @Test void getTicker_valid() throws IOException { - var actual = gateioMarketDataService.getTicker(CurrencyPair.BTC_USDT); + Ticker actual = gateioMarketDataService.getTicker(CurrencyPair.BTC_USDT); - var expected = new Ticker.Builder() + Ticker expected = new Ticker.Builder() .instrument(CurrencyPair.BTC_USDT) .last(new BigDecimal("26028.7")) .ask(new BigDecimal("26026.8")) @@ -78,7 +78,7 @@ void getTicker_valid() throws IOException { @Test void getTickers_valid() throws IOException { - var actual = gateioMarketDataService.getTickers(null); + List actual = gateioMarketDataService.getTickers(null); assertThat(actual).hasSize(2); } @@ -86,7 +86,7 @@ void getTickers_valid() throws IOException { @Test void getCurrencies_valid() throws IOException { - var actual = gateioMarketDataService.getCurrencies(); + List actual = gateioMarketDataService.getCurrencies(); assertThat(actual).containsOnly(Currency.BTC, Currency.ETH); } @@ -94,7 +94,7 @@ void getCurrencies_valid() throws IOException { @Test void getCurrencyPairs_valid() throws IOException { - var actual = gateioMarketDataService.getCurrencyPairs(); + List actual = gateioMarketDataService.getCurrencyPairs(); assertThat(actual).containsOnly(CurrencyPair.BTC_USDT, CurrencyPair.ETH_USDT, new CurrencyPair("CHZ/USDT")); } diff --git a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioTradeServiceRawTest.java b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioTradeServiceRawTest.java index 2c1c24fc8e2..e5234101fba 100644 --- a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioTradeServiceRawTest.java +++ b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioTradeServiceRawTest.java @@ -130,7 +130,7 @@ void valid_market_sell_order() throws IOException { @Test void order_details() throws IOException { - var actualResponse = gateioTradeServiceRaw.getOrder("342251629898", CurrencyPair.BTC_USDT); + GateioOrder actualResponse = gateioTradeServiceRaw.getOrder("342251629898", CurrencyPair.BTC_USDT); assertThat(actualResponse).usingRecursiveComparison().isEqualTo(sampleMarketOrder); } diff --git a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioTradeServiceTest.java b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioTradeServiceTest.java index fe5968f28ea..6780afdbfad 100644 --- a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioTradeServiceTest.java +++ b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioTradeServiceTest.java @@ -6,10 +6,12 @@ import java.io.IOException; import java.math.BigDecimal; import java.time.Instant; +import java.util.Collection; import java.util.Date; import org.junit.jupiter.api.Test; import org.knowm.xchange.currency.Currency; import org.knowm.xchange.currency.CurrencyPair; +import org.knowm.xchange.dto.Order; import org.knowm.xchange.dto.Order.OrderStatus; import org.knowm.xchange.dto.Order.OrderType; import org.knowm.xchange.dto.trade.LimitOrder; @@ -46,7 +48,7 @@ void valid_market_buy_order() throws IOException { .originalAmount(BigDecimal.valueOf(20)) .build(); - var actualResponse = gateioTradeService.placeMarketOrder(marketOrder); + String actualResponse = gateioTradeService.placeMarketOrder(marketOrder); assertThat(actualResponse).isEqualTo("342251629898"); } @@ -59,7 +61,7 @@ void valid_market_sell_order() throws IOException { .originalAmount(new BigDecimal("0.0007")) .build(); - var actualResponse = gateioTradeService.placeMarketOrder(marketOrder); + String actualResponse = gateioTradeService.placeMarketOrder(marketOrder); assertThat(actualResponse).isEqualTo("342260949533"); } @@ -73,7 +75,7 @@ void valid_limit_sell_order() throws IOException { .limitPrice(new BigDecimal("29240.7")) .build(); - var actualResponse = gateioTradeService.placeLimitOrder(limitOrder); + String actualResponse = gateioTradeService.placeLimitOrder(limitOrder); assertThat(actualResponse).isEqualTo("373824296029"); } @@ -93,7 +95,7 @@ void valid_limit_buy_order() throws IOException { .limitPrice(new BigDecimal("10000.7")) .build(); - var actualResponse = gateioTradeService.placeLimitOrder(limitOrder); + String actualResponse = gateioTradeService.placeLimitOrder(limitOrder); assertThat(actualResponse).isEqualTo("376835979523"); } @@ -111,7 +113,7 @@ void order_details() throws IOException { .fee(new BigDecimal("0.0000014")) .build(); - var orders = gateioTradeService.getOrder(new DefaultQueryOrderParamInstrument(CurrencyPair.BTC_USDT, "342251629898")); + Collection orders = gateioTradeService.getOrder(new DefaultQueryOrderParamInstrument(CurrencyPair.BTC_USDT, "342251629898")); assertThat(orders).hasSize(1); assertThat(orders).first().usingRecursiveComparison().isEqualTo(expected); } diff --git a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioV4DigestTest.java b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioV4DigestTest.java index 7f8cacff37c..472a6c6cb73 100644 --- a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioV4DigestTest.java +++ b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioV4DigestTest.java @@ -3,6 +3,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.when; +import java.util.HashMap; import java.util.Map; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -24,10 +25,12 @@ void signature() { when(restInvocation.getPath()).thenReturn("a"); when(restInvocation.getQueryString()).thenReturn("?b=c"); when(restInvocation.getRequestBody()).thenReturn("{a:1}"); - when(restInvocation.getHttpHeadersFromParams()).thenReturn(Map.of("Timestamp", "1691707273890")); + Map headers = new HashMap<>(); + headers.put("Timestamp", "1691707273890"); + when(restInvocation.getHttpHeadersFromParams()).thenReturn(headers); - var actual = gateioV4Digest.digestParams(restInvocation); - var expected = "de31e211a60623ba2c41e65a3c21e550400ffccfef55578173e09f2b34cf46b426c587f01b4c12474608dc856b1ba226a71004f7989603236c885c23275d5577"; + String actual = gateioV4Digest.digestParams(restInvocation); + String expected = "de31e211a60623ba2c41e65a3c21e550400ffccfef55578173e09f2b34cf46b426c587f01b4c12474608dc856b1ba226a71004f7989603236c885c23275d5577"; assertThat(actual).isEqualTo(expected); } diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/Config.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/Config.java index b3d60b86bfe..0d373586d85 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/Config.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/config/Config.java @@ -6,7 +6,7 @@ import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import java.time.Clock; -import java.time.ZoneId; +import java.util.Arrays; import java.util.List; import lombok.Data; @@ -20,7 +20,7 @@ public final class Config { public static final String SPOT_TICKERS_CHANNEL = "spot.tickers"; public static final String SPOT_BALANCES_CHANNEL = "spot.balances"; public static final String SPOT_USER_TRADES_CHANNEL = "spot.usertrades"; - public static final List PRIVATE_CHANNELS = List.of(SPOT_BALANCES_CHANNEL, SPOT_USER_TRADES_CHANNEL); + public static final List PRIVATE_CHANNELS = Arrays.asList(SPOT_BALANCES_CHANNEL, SPOT_USER_TRADES_CHANNEL); public static final String CHANNEL_NAME_DELIMITER = "-"; @@ -30,7 +30,7 @@ public final class Config { private static Config instance = new Config(); private Config() { - clock = Clock.tickMillis(ZoneId.systemDefault()); + clock = Clock.systemDefaultZone(); objectMapper = new ObjectMapper(); From 0119ea446a2c82f5dac3fa87b28ca75b7aa72e0b Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Sun, 13 Aug 2023 19:25:16 +0200 Subject: [PATCH 100/159] Revert "[kucoin] Extend kucoin support" This reverts commit 5a09f2123224290d25e22cbeec258cee44a96089. --- .../knowm/xchange/dto/account/Balance.java | 4 - .../kucoin/account/KucoinAccountDemo.java | 2 +- .../xchange/kucoin/KucoinAccountService.java | 134 ++---------------- .../kucoin/KucoinAccountServiceRaw.java | 123 ++++++++++------ .../knowm/xchange/kucoin/KucoinAdapters.java | 8 +- .../xchange/kucoin/KucoinErrorAdapter.java | 54 ------- .../kucoin/KucoinMarketDataService.java | 14 -- .../kucoin/KucoinMarketDataServiceRaw.java | 10 +- .../xchange/kucoin/dto/KucoinException.java | 19 --- .../CreateDepositAddressApiRequest.java | 17 --- .../dto/response/CurrenciesResponse.java | 12 -- .../kucoin/dto/response/DepositResponse.java | 6 - .../kucoin/dto/response/KucoinResponse.java | 10 -- .../dto/response/OrderCreateResponse.java | 6 - .../dto/response/WithdrawalResponse.java | 4 - .../xchange/kucoin/service/AccountAPI.java | 5 +- .../xchange/kucoin/service/DepositAPI.java | 13 +- .../xchange/kucoin/service/SymbolAPI.java | 3 +- .../xchange/kucoin/service/WithdrawalAPI.java | 3 +- .../params/KucoinWithdrawFundsParams.java | 15 -- 20 files changed, 113 insertions(+), 349 deletions(-) delete mode 100644 xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/KucoinErrorAdapter.java delete mode 100644 xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/dto/KucoinException.java delete mode 100644 xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/dto/request/CreateDepositAddressApiRequest.java delete mode 100644 xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/service/params/KucoinWithdrawFundsParams.java diff --git a/xchange-core/src/main/java/org/knowm/xchange/dto/account/Balance.java b/xchange-core/src/main/java/org/knowm/xchange/dto/account/Balance.java index 37a77d710c7..c67757c4c7e 100644 --- a/xchange-core/src/main/java/org/knowm/xchange/dto/account/Balance.java +++ b/xchange-core/src/main/java/org/knowm/xchange/dto/account/Balance.java @@ -475,10 +475,6 @@ public int compareTo(Balance other) { return comparison; } - public static Builder builder() { - return new Builder(); - } - @JsonPOJOBuilder(withPrefix = "") public static class Builder { diff --git a/xchange-examples/src/main/java/org/knowm/xchange/examples/kucoin/account/KucoinAccountDemo.java b/xchange-examples/src/main/java/org/knowm/xchange/examples/kucoin/account/KucoinAccountDemo.java index c8a7215efd4..df53ad5690d 100644 --- a/xchange-examples/src/main/java/org/knowm/xchange/examples/kucoin/account/KucoinAccountDemo.java +++ b/xchange-examples/src/main/java/org/knowm/xchange/examples/kucoin/account/KucoinAccountDemo.java @@ -36,7 +36,7 @@ private static void raw(KucoinAccountServiceRaw accountService) throws IOExcepti System.out.println("------------RAW-----------"); - List responseBalances = accountService.getKucoinAccounts(null, null); + List responseBalances = accountService.getKucoinAccounts(); System.out.println(responseBalances); // Not yet implemented diff --git a/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/KucoinAccountService.java b/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/KucoinAccountService.java index aea31969b24..064796ff16c 100644 --- a/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/KucoinAccountService.java +++ b/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/KucoinAccountService.java @@ -5,30 +5,19 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; -import java.util.Locale; -import java.util.Map; import java.util.stream.Collectors; -import org.apache.commons.lang3.Validate; import org.knowm.xchange.client.ResilienceRegistries; import org.knowm.xchange.currency.Currency; import org.knowm.xchange.dto.account.AccountInfo; -import org.knowm.xchange.dto.account.AddressWithTag; -import org.knowm.xchange.dto.account.Balance; import org.knowm.xchange.dto.account.FundingRecord; import org.knowm.xchange.dto.account.FundingRecord.Type; import org.knowm.xchange.dto.account.Wallet; -import org.knowm.xchange.kucoin.dto.KucoinException; -import org.knowm.xchange.kucoin.dto.request.ApplyWithdrawApiRequest; -import org.knowm.xchange.kucoin.dto.request.CreateDepositAddressApiRequest; import org.knowm.xchange.kucoin.dto.response.AccountBalancesResponse; -import org.knowm.xchange.kucoin.dto.response.DepositAddressResponse; -import org.knowm.xchange.kucoin.service.params.KucoinWithdrawFundsParams; import org.knowm.xchange.service.account.AccountService; import org.knowm.xchange.service.trade.params.HistoryParamsFundingType; import org.knowm.xchange.service.trade.params.TradeHistoryParamCurrency; import org.knowm.xchange.service.trade.params.TradeHistoryParams; import org.knowm.xchange.service.trade.params.TradeHistoryParamsTimeSpan; -import org.knowm.xchange.service.trade.params.WithdrawFundsParams; public class KucoinAccountService extends KucoinAccountServiceRaw implements AccountService { @@ -38,33 +27,21 @@ public class KucoinAccountService extends KucoinAccountServiceRaw implements Acc @Override public AccountInfo getAccountInfo() throws IOException { - - try { - - List accounts = getKucoinAccounts(null, null); - - // split balances by account type: main, trade, margin - Map> balancesByAccountType = accounts.stream() - .collect(Collectors.groupingBy( - AccountBalancesResponse::getType, - Collectors.mapping(KucoinAdapters::adaptBalance, toList())) - ); - - // convert balances to wallets - List wallets = new ArrayList<>(); - balancesByAccountType.forEach((accountType, balances) -> { - Wallet wallet = Wallet.Builder - .from(balances) - .id(accountType) - .name(accountType) - .build(); - wallets.add(wallet); - }); - - return new AccountInfo(wallets); - } catch (KucoinException e) { - throw KucoinErrorAdapter.adapt(e); - } + List accounts = getKucoinAccounts(); + return new AccountInfo( + accounts.stream() + .map(AccountBalancesResponse::getType) + .distinct() + .map( + type -> + Wallet.Builder.from( + accounts.stream() + .filter(a -> a.getType().equals(type)) + .map(KucoinAdapters::adaptBalance) + .collect(toList())) + .id(type) + .build()) + .collect(toList())); } public TradeHistoryParams createFundingHistoryParams() { @@ -106,85 +83,4 @@ public List getFundingHistory(TradeHistoryParams params) throws I } return result; } - - - @Override - public String withdrawFunds(WithdrawFundsParams params) throws IOException { - Validate.isInstanceOf(KucoinWithdrawFundsParams.class, params); - - KucoinWithdrawFundsParams withdrawFundsParams = (KucoinWithdrawFundsParams) params; - - ApplyWithdrawApiRequest request = ApplyWithdrawApiRequest.builder() - .currency(withdrawFundsParams.getCurrency().getCurrencyCode()) - .address(withdrawFundsParams.getAddress()) - .amount(withdrawFundsParams.getAmount()) - .memo(withdrawFundsParams.getAddressTag()) - .remark(withdrawFundsParams.getRemark()) - .chain(withdrawFundsParams.getChain()) - .build(); - - try { - return applyWithdraw(request).getWithdrawalId(); - } catch (KucoinException e) { - throw KucoinErrorAdapter.adapt(e); - } - - - } - - - /** - * @param args Chain name - */ - @Override - public AddressWithTag requestDepositAddressData(Currency currency, String... args) - throws IOException { - Validate.isTrue(args.length == 1, "Chain name is missing"); - String chain = args[0]; - - try { - - DepositAddressResponse response = getDepositAddress(currency.getCurrencyCode(), chain); - - return AddressWithTag.builder() - .address(response.getAddress()) - .addressTag(response.getMemo()) - .build(); - - } catch (KucoinException e) { - throw KucoinErrorAdapter.adapt(e); - } - - } - - - public List requestDepositAddressData(Currency currency) - throws IOException { - try { - - return getDepositAddresses(currency.getCurrencyCode()); - - } catch (KucoinException e) { - throw KucoinErrorAdapter.adapt(e); - } - - } - - - public DepositAddressResponse createDepositAddress(Currency currency, String chain) throws IOException { - try { - - CreateDepositAddressApiRequest request = CreateDepositAddressApiRequest.builder() - .currency(currency.getCurrencyCode().toUpperCase(Locale.ROOT)) - .chain(chain) - .build(); - - return createDepositAddress(request); - - } catch (KucoinException e) { - throw KucoinErrorAdapter.adapt(e); - } - - } - } diff --git a/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/KucoinAccountServiceRaw.java b/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/KucoinAccountServiceRaw.java index d0fab7334a2..3419c4b8342 100644 --- a/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/KucoinAccountServiceRaw.java +++ b/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/KucoinAccountServiceRaw.java @@ -5,11 +5,9 @@ import java.io.IOException; import java.util.List; -import java.util.Locale; import org.knowm.xchange.client.ResilienceRegistries; import org.knowm.xchange.kucoin.dto.request.ApplyWithdrawApiRequest; import org.knowm.xchange.kucoin.dto.request.CreateAccountRequest; -import org.knowm.xchange.kucoin.dto.request.CreateDepositAddressApiRequest; import org.knowm.xchange.kucoin.dto.request.InnerTransferRequest; import org.knowm.xchange.kucoin.dto.response.AccountBalancesResponse; import org.knowm.xchange.kucoin.dto.response.AccountLedgersResponse; @@ -27,13 +25,17 @@ protected KucoinAccountServiceRaw( super(exchange, resilienceRegistries); } - public List getKucoinAccounts(String currency, String accountType) throws IOException { - return decorateApiCall(() -> - accountApi.getAccountList(apiKey, digest, nonceFactory, passphrase, currency, accountType)) - .withRetry(retry("accountList")) - .withRateLimiter(rateLimiter(PRIVATE_REST_ENDPOINT_RATE_LIMITER)) - .call() - .getData(); + public List getKucoinAccounts() throws IOException { + checkAuthenticated(); + return classifyingExceptions( + () -> + decorateApiCall( + () -> + accountApi.getAccountList( + apiKey, digest, nonceFactory, passphrase, null, null)) + .withRetry(retry("accountList")) + .withRateLimiter(rateLimiter(PRIVATE_REST_ENDPOINT_RATE_LIMITER)) + .call()); } public Void createKucoinAccount(String currency, String type) throws IOException { @@ -53,17 +55,24 @@ public Void createKucoinAccount(String currency, String type) throws IOException } public ApplyWithdrawResponse applyWithdraw(ApplyWithdrawApiRequest req) throws IOException { - return decorateApiCall(() -> + checkAuthenticated(); + return classifyingExceptions( + () -> + decorateApiCall( + () -> withdrawalAPI.applyWithdraw(apiKey, digest, nonceFactory, passphrase, req)) .withRateLimiter(rateLimiter(PRIVATE_REST_ENDPOINT_RATE_LIMITER)) - .call().getData(); + .call()); } public InternalTransferResponse innerTransfer(InnerTransferRequest req) throws IOException { - return decorateApiCall(() -> - accountApi.innerTransfer(apiKey, digest, nonceFactory, passphrase, req)) - .withRateLimiter(rateLimiter(PRIVATE_REST_ENDPOINT_RATE_LIMITER)) - .call().getData(); + checkAuthenticated(); + return classifyingExceptions( + () -> + decorateApiCall( + () -> accountApi.innerTransfer(apiKey, digest, nonceFactory, passphrase, req)) + .withRateLimiter(rateLimiter(PRIVATE_REST_ENDPOINT_RATE_LIMITER)) + .call()); } @Deprecated @@ -119,14 +128,32 @@ public Pagination getAccountLedgersWithParams( .call()); } - public Pagination getWithdrawalsList(String currency, String status, - Long startAt, Long endAt, Integer pageSize, Integer currentPage) throws IOException - { + public Pagination getWithdrawalsList( + String currency, + String status, + Long startAt, + Long endAt, + Integer pageSize, + Integer currentPage) + throws IOException { checkAuthenticated(); - return classifyingExceptions(() -> decorateApiCall( - () -> withdrawalAPI.getWithdrawalsList(apiKey, digest, nonceFactory, passphrase, currency, - status, startAt, endAt, pageSize, currentPage)).withRateLimiter( - rateLimiter(PRIVATE_REST_ENDPOINT_RATE_LIMITER)).call()); + return classifyingExceptions( + () -> + decorateApiCall( + () -> + withdrawalAPI.getWithdrawalsList( + apiKey, + digest, + nonceFactory, + passphrase, + currency, + status, + startAt, + endAt, + pageSize, + currentPage)) + .withRateLimiter(rateLimiter(PRIVATE_REST_ENDPOINT_RATE_LIMITER)) + .call()); } public Pagination getDepositList( @@ -157,31 +184,41 @@ public Pagination getDepositList( .call()); } - public DepositAddressResponse createDepositAddress(CreateDepositAddressApiRequest request) throws IOException { - return decorateApiCall(() -> - depositAPI.createDepositAddress(apiKey, digest, nonceFactory, passphrase, request)) - .withRateLimiter(rateLimiter(PRIVATE_REST_ENDPOINT_RATE_LIMITER)) - .call() - .getData(); + public DepositAddressResponse createDepositAddress(String currency, String chain) + throws IOException { + checkAuthenticated(); + return classifyingExceptions( + () -> + decorateApiCall( + () -> + depositAPI.createDepositAddress( + apiKey, digest, nonceFactory, passphrase, currency, chain)) + .withRateLimiter(rateLimiter(PRIVATE_REST_ENDPOINT_RATE_LIMITER)) + .call()); } - public DepositAddressResponse getDepositAddress(String currency, String chain) throws IOException { - - // kucoin expects currency to be uppercase - String currencyAdapted = currency.toUpperCase(Locale.ROOT); - - return decorateApiCall(() -> - depositAPI.getDepositAddress(apiKey, digest, nonceFactory, passphrase, currencyAdapted, chain)) - .withRateLimiter(rateLimiter(PRIVATE_REST_ENDPOINT_RATE_LIMITER)) - .call() - .getData(); + public DepositAddressResponse getDepositAddress(String currency, String chain) + throws IOException { + checkAuthenticated(); + return classifyingExceptions( + () -> + decorateApiCall( + () -> + depositAPI.getDepositAddress( + apiKey, digest, nonceFactory, passphrase, currency, chain)) + .withRateLimiter(rateLimiter(PRIVATE_REST_ENDPOINT_RATE_LIMITER)) + .call()); } public List getDepositAddresses(String currency) throws IOException { - return decorateApiCall(() -> - depositAPI.getDepositAddresses(apiKey, digest, nonceFactory, passphrase,currency)) - .withRateLimiter(rateLimiter(PRIVATE_REST_ENDPOINT_RATE_LIMITER)) - .call() - .getData(); + checkAuthenticated(); + return classifyingExceptions( + () -> + decorateApiCall( + () -> + depositAPI.getDepositAddresses( + apiKey, digest, nonceFactory, passphrase, currency)) + .withRateLimiter(rateLimiter(PRIVATE_REST_ENDPOINT_RATE_LIMITER)) + .call()); } } diff --git a/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/KucoinAdapters.java b/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/KucoinAdapters.java index 3213f47e0c3..22bfd285fc6 100644 --- a/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/KucoinAdapters.java +++ b/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/KucoinAdapters.java @@ -41,11 +41,7 @@ import org.knowm.xchange.dto.marketdata.Trade; import org.knowm.xchange.dto.marketdata.Trades; import org.knowm.xchange.dto.marketdata.Trades.TradeSortType; -import org.knowm.xchange.dto.meta.CurrencyMetaData; -import org.knowm.xchange.dto.meta.ExchangeMetaData; -import org.knowm.xchange.dto.meta.FeeTier; -import org.knowm.xchange.dto.meta.InstrumentMetaData; -import org.knowm.xchange.dto.meta.WalletHealth; +import org.knowm.xchange.dto.meta.*; import org.knowm.xchange.dto.trade.LimitOrder; import org.knowm.xchange.dto.trade.MarketOrder; import org.knowm.xchange.dto.trade.StopOrder; @@ -253,7 +249,7 @@ public static Trades adaptTrades( } public static Balance adaptBalance(AccountBalancesResponse a) { - return new Balance(Currency.getInstance(a.getCurrency()), a.getBalance(), a.getAvailable(), a.getHolds()); + return new Balance(Currency.getInstance(a.getCurrency()), a.getBalance(), a.getAvailable()); } private static Trade adaptTrade(CurrencyPair currencyPair, TradeHistoryResponse trade) { diff --git a/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/KucoinErrorAdapter.java b/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/KucoinErrorAdapter.java deleted file mode 100644 index fc20c825e76..00000000000 --- a/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/KucoinErrorAdapter.java +++ /dev/null @@ -1,54 +0,0 @@ -package org.knowm.xchange.kucoin; - -import org.apache.commons.lang3.StringUtils; -import org.knowm.xchange.exceptions.CurrencyPairNotValidException; -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.kucoin.dto.KucoinException; - -public final class KucoinErrorAdapter { - /** - * 200004 Balance insufficient - */ - public static final int BALANCE_INSUFFICIENT = 200004; - - /** - * 400001 Missing security header - */ - public static final int MISSING_SECURITY_HEADER = 400001; - - /** - * 900001 symbol not exists - */ - public static final int SYMBOL_NOT_EXISTS = 900001; - - /** - * 900003 Currency not exists - */ - public static final int CURRENCY_NOT_EXISTS = 900003; - - private KucoinErrorAdapter() { - } - - public static ExchangeException adapt(KucoinException e) { - String message = e.getMessage(); - if (StringUtils.isEmpty(message)) { - message = "Operation failed without any error message"; - } - switch (e.getCode()) { - case BALANCE_INSUFFICIENT: - return new FundsExceededException(e.getMessage(), e); - case SYMBOL_NOT_EXISTS: - return new CurrencyPairNotValidException(e.getMessage(), e); - case CURRENCY_NOT_EXISTS: - return new InstrumentNotValidException(e.getMessage(), e); - case MISSING_SECURITY_HEADER: - return new ExchangeSecurityException(e.getMessage(), e); - default: - return new ExchangeException(message, e); - } - } - -} diff --git a/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/KucoinMarketDataService.java b/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/KucoinMarketDataService.java index 40bf256a8fa..5aa3e6a1b99 100644 --- a/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/KucoinMarketDataService.java +++ b/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/KucoinMarketDataService.java @@ -8,8 +8,6 @@ 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.kucoin.dto.KucoinException; -import org.knowm.xchange.kucoin.dto.response.SymbolResponse; import org.knowm.xchange.service.marketdata.MarketDataService; import org.knowm.xchange.service.marketdata.params.Params; @@ -60,16 +58,4 @@ public OrderBook getOrderBook(CurrencyPair currencyPair, Object... args) throws public Trades getTrades(CurrencyPair currencyPair, Object... args) throws IOException { return KucoinAdapters.adaptTrades(currencyPair, getKucoinTrades(currencyPair)); } - - @Override - public List getKucoinSymbolsV2() throws IOException { - try { - return super.getKucoinSymbolsV2(); - } catch (KucoinException e) { - throw KucoinErrorAdapter.adapt(e); - } - - } - - } diff --git a/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/KucoinMarketDataServiceRaw.java b/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/KucoinMarketDataServiceRaw.java index 69eaea19dd2..94be7c89b2f 100644 --- a/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/KucoinMarketDataServiceRaw.java +++ b/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/KucoinMarketDataServiceRaw.java @@ -105,10 +105,12 @@ public List getKucoinSymbols() throws IOException { } public List getKucoinSymbolsV2() throws IOException { - return decorateApiCall(symbolApi::getSymbolsV2) - .withRetry(retry("symbols")) - .withRateLimiter(rateLimiter(PUBLIC_REST_ENDPOINT_RATE_LIMITER)).call() - .getData(); + return classifyingExceptions( + () -> + decorateApiCall(symbolApi::getSymbolsV2) + .withRetry(retry("symbols")) + .withRateLimiter(rateLimiter(PUBLIC_REST_ENDPOINT_RATE_LIMITER)) + .call()); } public List getKucoinCurrencies() throws IOException { diff --git a/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/dto/KucoinException.java b/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/dto/KucoinException.java deleted file mode 100644 index 76ce0242ba1..00000000000 --- a/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/dto/KucoinException.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.knowm.xchange.kucoin.dto; - -import com.fasterxml.jackson.annotation.JsonProperty; -import lombok.Builder; -import lombok.Value; -import lombok.extern.jackson.Jacksonized; - -@Value -@Jacksonized -@Builder -public class KucoinException extends RuntimeException { - - @JsonProperty("code") - int code; - - @JsonProperty("msg") - String message; - -} diff --git a/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/dto/request/CreateDepositAddressApiRequest.java b/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/dto/request/CreateDepositAddressApiRequest.java deleted file mode 100644 index 6c10cfad3fe..00000000000 --- a/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/dto/request/CreateDepositAddressApiRequest.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.knowm.xchange.kucoin.dto.request; - -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonInclude.Include; -import lombok.Builder; -import lombok.Value; - -@Value -@Builder -@JsonInclude(value = Include.NON_EMPTY, content = Include.NON_NULL) -public class CreateDepositAddressApiRequest { - - String currency; - - String chain; - -} diff --git a/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/dto/response/CurrenciesResponse.java b/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/dto/response/CurrenciesResponse.java index 096b977d187..c7e358da37c 100644 --- a/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/dto/response/CurrenciesResponse.java +++ b/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/dto/response/CurrenciesResponse.java @@ -9,28 +9,16 @@ @JsonIgnoreProperties(ignoreUnknown = true) public class CurrenciesResponse { - @JsonProperty("currency") private String currency; - @JsonProperty("name") private String name; - @JsonProperty("fullName") private String fullName; - @JsonProperty("precision") private BigDecimal precision; - @JsonProperty("confirms") - private Integer confirms; - - @JsonProperty("contractAddress") - private String contractAddress; - - @JsonProperty("withdrawalMinSize") private String withdrawalMinSize; - @JsonProperty("withdrawalMinFee") private String withdrawalMinFee; @JsonProperty("isWithdrawEnabled") diff --git a/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/dto/response/DepositResponse.java b/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/dto/response/DepositResponse.java index c2885bce84c..cc5c346bc89 100644 --- a/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/dto/response/DepositResponse.java +++ b/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/dto/response/DepositResponse.java @@ -3,10 +3,8 @@ import java.math.BigDecimal; import java.util.Date; import lombok.Data; -import lombok.extern.jackson.Jacksonized; @Data -@Jacksonized public class DepositResponse { /** Creation time of the database record */ @@ -15,10 +13,6 @@ public class DepositResponse { private BigDecimal amount; /** Deposit address */ private String address; - - /** Chain of currency */ - private String chain; - /** Deposit fee */ private BigDecimal fee; /** diff --git a/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/dto/response/KucoinResponse.java b/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/dto/response/KucoinResponse.java index 23e722f08c8..f9f93eca587 100644 --- a/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/dto/response/KucoinResponse.java +++ b/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/dto/response/KucoinResponse.java @@ -4,7 +4,6 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import java.io.Serializable; import lombok.Data; -import si.mazi.rescu.ExceptionalReturnContentException; /** Created by zicong.lu on 2018/12/14. */ @Data @@ -28,13 +27,4 @@ public String getCode() { public String getMessage() { return msg; } - - public void setCode(String code) { - if (!SUCCESS_CODE.equals(code)) { - throw new ExceptionalReturnContentException(code); - } - this.code = code; - } - - } diff --git a/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/dto/response/OrderCreateResponse.java b/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/dto/response/OrderCreateResponse.java index 794538d2115..919f60ee9fa 100644 --- a/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/dto/response/OrderCreateResponse.java +++ b/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/dto/response/OrderCreateResponse.java @@ -2,17 +2,11 @@ package org.knowm.xchange.kucoin.dto.response; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Data; @Data @JsonIgnoreProperties(ignoreUnknown = true) public class OrderCreateResponse { - @JsonProperty("orderId") private String orderId; - - @JsonProperty("clientOrderId") - private String clientOrderId; - } diff --git a/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/dto/response/WithdrawalResponse.java b/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/dto/response/WithdrawalResponse.java index 3fa1a88050f..a66756a6175 100644 --- a/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/dto/response/WithdrawalResponse.java +++ b/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/dto/response/WithdrawalResponse.java @@ -19,10 +19,6 @@ public class WithdrawalResponse { private String memo; /** Currency */ private String currency; - - /** The chain of currency /*/ - private String chain; - /** Withdrawal amount */ private BigDecimal amount; /** Withdrawal fee */ diff --git a/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/service/AccountAPI.java b/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/service/AccountAPI.java index 833ec8b533a..c92429bf70f 100644 --- a/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/service/AccountAPI.java +++ b/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/service/AccountAPI.java @@ -12,7 +12,6 @@ import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; -import org.knowm.xchange.kucoin.dto.KucoinException; import org.knowm.xchange.kucoin.dto.request.CreateAccountRequest; import org.knowm.xchange.kucoin.dto.request.InnerTransferRequest; import org.knowm.xchange.kucoin.dto.response.AccountBalancesResponse; @@ -49,7 +48,7 @@ KucoinResponse> getAccountList( @HeaderParam(APIConstants.API_HEADER_PASSPHRASE) String apiPassphrase, @QueryParam("currency") String currency, @QueryParam("type") String type) - throws IOException, KucoinException; + throws IOException; @POST @Path("v1/accounts") @@ -71,7 +70,7 @@ KucoinResponse innerTransfer( @HeaderParam(APIConstants.API_HEADER_TIMESTAMP) SynchronizedValueFactory nonce, @HeaderParam(APIConstants.API_HEADER_PASSPHRASE) String apiPassphrase, InnerTransferRequest req) - throws IOException, KucoinException; + throws IOException; @GET @Path("v1/accounts/{accountId}/ledgers") diff --git a/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/service/DepositAPI.java b/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/service/DepositAPI.java index 75ef442e443..f85aebf5963 100644 --- a/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/service/DepositAPI.java +++ b/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/service/DepositAPI.java @@ -2,7 +2,6 @@ import java.io.IOException; import java.util.List; -import javax.ws.rs.Consumes; import javax.ws.rs.GET; import javax.ws.rs.HeaderParam; import javax.ws.rs.POST; @@ -10,8 +9,6 @@ import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; -import org.knowm.xchange.kucoin.dto.KucoinException; -import org.knowm.xchange.kucoin.dto.request.CreateDepositAddressApiRequest; import org.knowm.xchange.kucoin.dto.response.DepositAddressResponse; import org.knowm.xchange.kucoin.dto.response.DepositResponse; import org.knowm.xchange.kucoin.dto.response.KucoinResponse; @@ -52,15 +49,15 @@ KucoinResponse> getDepositList( throws IOException; @POST - @Consumes(MediaType.APPLICATION_JSON) @Path("/v1/deposit-addresses") KucoinResponse createDepositAddress( @HeaderParam(APIConstants.API_HEADER_KEY) String apiKey, @HeaderParam(APIConstants.API_HEADER_SIGN) ParamsDigest signature, @HeaderParam(APIConstants.API_HEADER_TIMESTAMP) SynchronizedValueFactory nonce, @HeaderParam(APIConstants.API_HEADER_PASSPHRASE) String apiPassphrase, - CreateDepositAddressApiRequest request) - throws IOException, KucoinException; + @QueryParam("currency") String currency, + @QueryParam("chain") String chain) + throws IOException; @GET @Path("/v1/deposit-addresses") @@ -71,7 +68,7 @@ KucoinResponse getDepositAddress( @HeaderParam(APIConstants.API_HEADER_PASSPHRASE) String apiPassphrase, @QueryParam("currency") String currency, @QueryParam("chain") String chain) - throws IOException, KucoinException; + throws IOException; @GET @Path("/v2/deposit-addresses") @@ -81,5 +78,5 @@ KucoinResponse> getDepositAddresses( @HeaderParam(APIConstants.API_HEADER_TIMESTAMP) SynchronizedValueFactory nonce, @HeaderParam(APIConstants.API_HEADER_PASSPHRASE) String apiPassphrase, @QueryParam("currency") String currency) - throws IOException, KucoinException; + throws IOException; } diff --git a/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/service/SymbolAPI.java b/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/service/SymbolAPI.java index ebcb7befdd5..1cfa56f1166 100644 --- a/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/service/SymbolAPI.java +++ b/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/service/SymbolAPI.java @@ -11,7 +11,6 @@ import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; -import org.knowm.xchange.kucoin.dto.KucoinException; import org.knowm.xchange.kucoin.dto.response.AllTickersResponse; import org.knowm.xchange.kucoin.dto.response.CurrenciesResponse; import org.knowm.xchange.kucoin.dto.response.CurrencyResponseV2; @@ -43,7 +42,7 @@ public interface SymbolAPI { */ @GET @Path("/v2/symbols") - KucoinResponse> getSymbolsV2() throws IOException, KucoinException; + KucoinResponse> getSymbolsV2() throws IOException; /** * Get a list of available currencies for trading. diff --git a/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/service/WithdrawalAPI.java b/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/service/WithdrawalAPI.java index c9576e55c3b..7c64a51c7e4 100644 --- a/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/service/WithdrawalAPI.java +++ b/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/service/WithdrawalAPI.java @@ -9,7 +9,6 @@ import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; -import org.knowm.xchange.kucoin.dto.KucoinException; import org.knowm.xchange.kucoin.dto.request.ApplyWithdrawApiRequest; import org.knowm.xchange.kucoin.dto.response.ApplyWithdrawResponse; import org.knowm.xchange.kucoin.dto.response.KucoinResponse; @@ -36,7 +35,7 @@ KucoinResponse applyWithdraw( @HeaderParam(APIConstants.API_HEADER_TIMESTAMP) SynchronizedValueFactory nonce, @HeaderParam(APIConstants.API_HEADER_PASSPHRASE) String apiPassphrase, ApplyWithdrawApiRequest req) - throws IOException, KucoinException; + throws IOException; /** * Get Withdrawals List. diff --git a/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/service/params/KucoinWithdrawFundsParams.java b/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/service/params/KucoinWithdrawFundsParams.java deleted file mode 100644 index adfeb217884..00000000000 --- a/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/service/params/KucoinWithdrawFundsParams.java +++ /dev/null @@ -1,15 +0,0 @@ -package org.knowm.xchange.kucoin.service.params; - -import lombok.Value; -import lombok.experimental.SuperBuilder; -import org.knowm.xchange.service.trade.params.DefaultWithdrawFundsParams; - -@Value -@SuperBuilder -public class KucoinWithdrawFundsParams extends DefaultWithdrawFundsParams { - - String chain; - - String remark; - -} From 37a27654b103871092a32dfd8d858deb7a28027c Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Sun, 13 Aug 2023 19:34:18 +0200 Subject: [PATCH 101/159] Revert "Replace constructors in DefaultWithdrawFundsParams with according builders" This reverts commit ccf8467d7830a5bc2ba0ed711b8ff93cd5fcd629. --- .../service/BinanceAccountService.java | 28 +----- .../bitbay/service/BitbayAccountService.java | 6 +- .../service/BitstampAccountService.java | 15 +-- .../service/BTCMarketsAccountService.java | 4 +- .../service/BTCMarketsAccountServiceTest.java | 9 +- .../service/CoinbaseProAccountService.java | 14 +-- .../coingi/service/CoingiAccountService.java | 12 +-- .../service/account/AccountService.java | 15 +-- .../params/DefaultWithdrawFundsParams.java | 95 ++++++++++++++++--- .../params/MoneroWithdrawFundsParams.java | 41 ++++++-- .../params/RippleWithdrawFundsParams.java | 40 +++++++- .../v2/service/HitbtcAccountService.java | 7 +- .../service/LivecoinAccountService.java | 7 +- .../okcoin/service/OkCoinAccountService.java | 2 +- .../okcoin/v3/service/OkexAccountService.java | 2 +- .../service/PoloniexAccountService.java | 7 +- .../yobit/service/YoBitAccountService.java | 7 +- 17 files changed, 179 insertions(+), 132 deletions(-) diff --git a/xchange-binance/src/main/java/org/knowm/xchange/binance/service/BinanceAccountService.java b/xchange-binance/src/main/java/org/knowm/xchange/binance/service/BinanceAccountService.java index 12504a7a6e8..6aab63f855e 100644 --- a/xchange-binance/src/main/java/org/knowm/xchange/binance/service/BinanceAccountService.java +++ b/xchange-binance/src/main/java/org/knowm/xchange/binance/service/BinanceAccountService.java @@ -4,33 +4,21 @@ import java.math.BigDecimal; import java.math.RoundingMode; import java.time.Instant; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; + import org.knowm.xchange.binance.BinanceAdapters; import org.knowm.xchange.binance.BinanceErrorAdapter; import org.knowm.xchange.binance.BinanceExchange; import org.knowm.xchange.binance.dto.BinanceException; -import org.knowm.xchange.binance.dto.account.AssetDetail; -import org.knowm.xchange.binance.dto.account.BinanceAccountInformation; -import org.knowm.xchange.binance.dto.account.BinanceFundingHistoryParams; +import org.knowm.xchange.binance.dto.account.*; import org.knowm.xchange.binance.dto.account.BinanceMasterAccountTransferHistoryParams; import org.knowm.xchange.binance.dto.account.BinanceSubAccountTransferHistoryParams; -import org.knowm.xchange.binance.dto.account.DepositAddress; -import org.knowm.xchange.binance.dto.account.WithdrawResponse; import org.knowm.xchange.binance.dto.account.futures.BinanceFutureAccountInformation; import org.knowm.xchange.client.ResilienceRegistries; import org.knowm.xchange.currency.Currency; -import org.knowm.xchange.dto.account.AccountInfo; -import org.knowm.xchange.dto.account.AddressWithTag; -import org.knowm.xchange.dto.account.Fee; -import org.knowm.xchange.dto.account.FundingRecord; +import org.knowm.xchange.dto.account.*; import org.knowm.xchange.dto.account.FundingRecord.Status; import org.knowm.xchange.dto.account.FundingRecord.Type; -import org.knowm.xchange.dto.account.OpenPosition; -import org.knowm.xchange.dto.account.Wallet; import org.knowm.xchange.instrument.Instrument; import org.knowm.xchange.service.account.AccountService; import org.knowm.xchange.service.trade.params.DefaultWithdrawFundsParams; @@ -168,13 +156,7 @@ public String withdrawFunds(Currency currency, BigDecimal amount, String address @Override public String withdrawFunds(Currency currency, BigDecimal amount, AddressWithTag address) throws IOException { - return withdrawFunds(DefaultWithdrawFundsParams.builder() - .address(address.getAddress()) - .address(address.getAddressTag()) - .currency(currency) - .amount(amount) - .build() - ); + return withdrawFunds(new DefaultWithdrawFundsParams(address, currency, amount)); } @Override diff --git a/xchange-bitbay/src/main/java/org/knowm/xchange/bitbay/service/BitbayAccountService.java b/xchange-bitbay/src/main/java/org/knowm/xchange/bitbay/service/BitbayAccountService.java index 349f13f45be..cd535346975 100644 --- a/xchange-bitbay/src/main/java/org/knowm/xchange/bitbay/service/BitbayAccountService.java +++ b/xchange-bitbay/src/main/java/org/knowm/xchange/bitbay/service/BitbayAccountService.java @@ -33,11 +33,7 @@ public AccountInfo getAccountInfo() throws IOException { @Override public String withdrawFunds(Currency currency, BigDecimal amount, String address) throws IOException { - return withdrawFunds(DefaultWithdrawFundsParams.builder() - .address(address) - .currency(currency) - .amount(amount) - .build()); + return withdrawFunds(new DefaultWithdrawFundsParams(address, currency, amount)); } @Override diff --git a/xchange-bitstamp/src/main/java/org/knowm/xchange/bitstamp/service/BitstampAccountService.java b/xchange-bitstamp/src/main/java/org/knowm/xchange/bitstamp/service/BitstampAccountService.java index 6e8aee40d57..ab1284f94e4 100644 --- a/xchange-bitstamp/src/main/java/org/knowm/xchange/bitstamp/service/BitstampAccountService.java +++ b/xchange-bitstamp/src/main/java/org/knowm/xchange/bitstamp/service/BitstampAccountService.java @@ -51,22 +51,13 @@ public AccountInfo getAccountInfo() throws IOException { @Override public String withdrawFunds(Currency currency, BigDecimal amount, String address) throws IOException { - return withdrawFunds(DefaultWithdrawFundsParams.builder() - .address(address) - .currency(currency) - .amount(amount) - .build()); + return withdrawFunds(new DefaultWithdrawFundsParams(address, currency, amount)); } public String withdrawFunds( Currency currency, BigDecimal amount, String address, String addressTag) throws IOException { - return withdrawFunds(DefaultWithdrawFundsParams.builder() - .address(address) - .addressTag(addressTag) - .currency(currency) - .amount(amount) - .build() - ); + return withdrawFunds( + new DefaultWithdrawFundsParams(address, addressTag, currency, amount, null)); } @Override diff --git a/xchange-btcmarkets/src/main/java/org/knowm/xchange/btcmarkets/service/BTCMarketsAccountService.java b/xchange-btcmarkets/src/main/java/org/knowm/xchange/btcmarkets/service/BTCMarketsAccountService.java index a9859d67407..f5b34fc22ac 100644 --- a/xchange-btcmarkets/src/main/java/org/knowm/xchange/btcmarkets/service/BTCMarketsAccountService.java +++ b/xchange-btcmarkets/src/main/java/org/knowm/xchange/btcmarkets/service/BTCMarketsAccountService.java @@ -39,9 +39,9 @@ public AccountInfo getAccountInfo() throws IOException { public String withdrawFunds(WithdrawFundsParams params) throws IOException { if (params instanceof DefaultWithdrawFundsParams) { DefaultWithdrawFundsParams defaultWithdrawFundsParams = (DefaultWithdrawFundsParams) params; - String address = defaultWithdrawFundsParams.getAddress(); + String address = defaultWithdrawFundsParams.address; if (params instanceof RippleWithdrawFundsParams) { - address = address + "?dt=" + ((RippleWithdrawFundsParams) params).getTag(); + address = address + "?dt=" + ((RippleWithdrawFundsParams) params).tag; } return withdrawCrypto( address, diff --git a/xchange-btcmarkets/src/test/java/org/knowm/xchange/btcmarkets/service/BTCMarketsAccountServiceTest.java b/xchange-btcmarkets/src/test/java/org/knowm/xchange/btcmarkets/service/BTCMarketsAccountServiceTest.java index 43124784b8a..f2268b06200 100644 --- a/xchange-btcmarkets/src/test/java/org/knowm/xchange/btcmarkets/service/BTCMarketsAccountServiceTest.java +++ b/xchange-btcmarkets/src/test/java/org/knowm/xchange/btcmarkets/service/BTCMarketsAccountServiceTest.java @@ -88,13 +88,8 @@ public void withdrawFundsShouldAppendRippleTag() throws IOException { .thenReturn(response); // when - RippleWithdrawFundsParams params = RippleWithdrawFundsParams.builder() - .address("any address") - .currency(Currency.BTC) - .amount(BigDecimal.TEN) - .tag("12345") - .build(); - + RippleWithdrawFundsParams params = + new RippleWithdrawFundsParams("any address", Currency.BTC, BigDecimal.TEN, "12345"); String result = btcMarketsAccountService.withdrawFunds(params); assertThat(captor.getValue().address).isEqualTo("any address?dt=12345"); assertThat(result).isNotNull(); diff --git a/xchange-coinbasepro/src/main/java/org/knowm/xchange/coinbasepro/service/CoinbaseProAccountService.java b/xchange-coinbasepro/src/main/java/org/knowm/xchange/coinbasepro/service/CoinbaseProAccountService.java index 540d49527d9..decd75831bd 100644 --- a/xchange-coinbasepro/src/main/java/org/knowm/xchange/coinbasepro/service/CoinbaseProAccountService.java +++ b/xchange-coinbasepro/src/main/java/org/knowm/xchange/coinbasepro/service/CoinbaseProAccountService.java @@ -60,23 +60,13 @@ public Map getDynamicTradingFeesByInstrument() throws IOExcepti @Override public String withdrawFunds(Currency currency, BigDecimal amount, String address) throws IOException { - return withdrawFunds(DefaultWithdrawFundsParams.builder() - .address(address) - .currency(currency) - .amount(amount) - .build()); + return withdrawFunds(new DefaultWithdrawFundsParams(address, currency, amount)); } @Override public String withdrawFunds(Currency currency, BigDecimal amount, AddressWithTag address) throws IOException { - return withdrawFunds(DefaultWithdrawFundsParams.builder() - .address(address.getAddress()) - .address(address.getAddressTag()) - .currency(currency) - .amount(amount) - .build() - ); + return withdrawFunds(new DefaultWithdrawFundsParams(address, currency, amount)); } @Override diff --git a/xchange-coingi/src/main/java/org/knowm/xchange/coingi/service/CoingiAccountService.java b/xchange-coingi/src/main/java/org/knowm/xchange/coingi/service/CoingiAccountService.java index 303d89350eb..cf12d790e75 100644 --- a/xchange-coingi/src/main/java/org/knowm/xchange/coingi/service/CoingiAccountService.java +++ b/xchange-coingi/src/main/java/org/knowm/xchange/coingi/service/CoingiAccountService.java @@ -42,11 +42,7 @@ public AccountInfo getAccountInfo() throws IOException { public String withdrawFunds(Currency currency, BigDecimal amount, String address) throws IOException { try { - return withdrawFunds(DefaultWithdrawFundsParams.builder() - .address(address) - .currency(currency) - .amount(amount) - .build()); + return withdrawFunds(new DefaultWithdrawFundsParams(address, currency, amount)); } catch (CoingiException e) { throw CoingiErrorAdapter.adapt(e); } @@ -60,9 +56,9 @@ public String withdrawFunds(WithdrawFundsParams p) DefaultWithdrawFundsParams params = (DefaultWithdrawFundsParams) p; CoingiWithdrawalRequest request = new CoingiWithdrawalRequest() - .setAddress(params.getAddress()) - .setAmount(params.getAmount()) - .setCurrency(params.getCurrency().getCurrencyCode().toUpperCase()); + .setAddress(params.address) + .setAmount(params.amount) + .setCurrency(params.currency.getCurrencyCode().toUpperCase()); return withdraw(request).toString(); } diff --git a/xchange-core/src/main/java/org/knowm/xchange/service/account/AccountService.java b/xchange-core/src/main/java/org/knowm/xchange/service/account/AccountService.java index 9475e3a29d3..b10c6ef0ab7 100644 --- a/xchange-core/src/main/java/org/knowm/xchange/service/account/AccountService.java +++ b/xchange-core/src/main/java/org/knowm/xchange/service/account/AccountService.java @@ -65,12 +65,7 @@ default AccountInfo getAccountInfo() throws IOException { */ default String withdrawFunds(Currency currency, BigDecimal amount, String address) throws IOException { - return withdrawFunds(DefaultWithdrawFundsParams.builder() - .address(address) - .currency(currency) - .amount(amount) - .build() - ); + return withdrawFunds(new DefaultWithdrawFundsParams(address, currency, amount)); } /** @@ -90,13 +85,7 @@ default String withdrawFunds(Currency currency, BigDecimal amount, String addres */ default String withdrawFunds(Currency currency, BigDecimal amount, AddressWithTag address) throws IOException { - return withdrawFunds(DefaultWithdrawFundsParams.builder() - .address(address.getAddress()) - .address(address.getAddressTag()) - .currency(currency) - .amount(amount) - .build() - ); + return withdrawFunds(new DefaultWithdrawFundsParams(address, currency, amount)); } /** diff --git a/xchange-core/src/main/java/org/knowm/xchange/service/trade/params/DefaultWithdrawFundsParams.java b/xchange-core/src/main/java/org/knowm/xchange/service/trade/params/DefaultWithdrawFundsParams.java index b510815455a..d1f8329e00e 100644 --- a/xchange-core/src/main/java/org/knowm/xchange/service/trade/params/DefaultWithdrawFundsParams.java +++ b/xchange-core/src/main/java/org/knowm/xchange/service/trade/params/DefaultWithdrawFundsParams.java @@ -1,26 +1,95 @@ package org.knowm.xchange.service.trade.params; import java.math.BigDecimal; -import lombok.AllArgsConstructor; -import lombok.Value; -import lombok.experimental.NonFinal; -import lombok.experimental.SuperBuilder; +import javax.annotation.Nullable; import org.knowm.xchange.currency.Currency; +import org.knowm.xchange.dto.account.AddressWithTag; -@Value -@NonFinal -@SuperBuilder -@AllArgsConstructor public class DefaultWithdrawFundsParams implements WithdrawFundsParams { + public final String address; - String address; + private final String addressTag; - String addressTag; + public final Currency currency; - Currency currency; + public final BigDecimal amount; - BigDecimal amount; + @Nullable public final BigDecimal commission; - BigDecimal commission; + public DefaultWithdrawFundsParams(String address, Currency currency, BigDecimal amount) { + this(address, currency, amount, null); + } + public DefaultWithdrawFundsParams(AddressWithTag address, Currency currency, BigDecimal amount) { + this(address, currency, amount, null); + } + + public DefaultWithdrawFundsParams( + String address, Currency currency, BigDecimal amount, BigDecimal commission) { + this.address = address; + this.addressTag = null; + this.currency = currency; + this.amount = amount; + this.commission = commission; + } + + public DefaultWithdrawFundsParams( + AddressWithTag address, Currency currency, BigDecimal amount, BigDecimal commission) { + this.address = address.getAddress(); + this.addressTag = address.getAddressTag(); + this.currency = currency; + this.amount = amount; + this.commission = commission; + } + + public DefaultWithdrawFundsParams( + String address, + String addressTag, + Currency currency, + BigDecimal amount, + BigDecimal commission) { + this.address = address; + this.addressTag = addressTag; + this.currency = currency; + this.amount = amount; + this.commission = commission; + } + + public String getAddress() { + return address; + } + + public String getAddressTag() { + return addressTag; + } + + public Currency getCurrency() { + return currency; + } + + public BigDecimal getAmount() { + return amount; + } + + @Nullable + public BigDecimal getCommission() { + return commission; + } + + @Override + public String toString() { + return "DefaultWithdrawFundsParams{" + + "address='" + + getAddress() + + ", addressTag=" + + getAddressTag() + + '\'' + + ", currency=" + + getCurrency() + + ", amount=" + + getAmount() + + ", commission=" + + getCommission() + + '}'; + } } diff --git a/xchange-core/src/main/java/org/knowm/xchange/service/trade/params/MoneroWithdrawFundsParams.java b/xchange-core/src/main/java/org/knowm/xchange/service/trade/params/MoneroWithdrawFundsParams.java index fa6db1cb99d..9406fad8c69 100644 --- a/xchange-core/src/main/java/org/knowm/xchange/service/trade/params/MoneroWithdrawFundsParams.java +++ b/xchange-core/src/main/java/org/knowm/xchange/service/trade/params/MoneroWithdrawFundsParams.java @@ -1,13 +1,42 @@ package org.knowm.xchange.service.trade.params; -import lombok.Value; -import lombok.experimental.SuperBuilder; +import java.math.BigDecimal; +import javax.annotation.Nullable; +import org.knowm.xchange.currency.Currency; - -@Value -@SuperBuilder public class MoneroWithdrawFundsParams extends DefaultWithdrawFundsParams { + @Nullable public final String paymentId; // optional + + public MoneroWithdrawFundsParams(String address, Currency currency, BigDecimal amount) { + this(address, currency, amount, null); + } + + public MoneroWithdrawFundsParams( + String address, Currency currency, BigDecimal amount, String paymentId) { + super(address, currency, amount); + this.paymentId = paymentId; + } - String paymentId; + @Override + public String toString() { + return "MoneroWithdrawFundsParams{" + + "address='" + + getAddress() + + '\'' + + ", paymentId='" + + getPaymentId() + + '\'' + + ", currency=" + + getCurrency() + + ", amount=" + + getAmount() + + ", commission=" + + getCommission() + + '}'; + } + @Nullable + public String getPaymentId() { + return paymentId; + } } diff --git a/xchange-core/src/main/java/org/knowm/xchange/service/trade/params/RippleWithdrawFundsParams.java b/xchange-core/src/main/java/org/knowm/xchange/service/trade/params/RippleWithdrawFundsParams.java index 14f34b47c42..dd1988ba9ca 100644 --- a/xchange-core/src/main/java/org/knowm/xchange/service/trade/params/RippleWithdrawFundsParams.java +++ b/xchange-core/src/main/java/org/knowm/xchange/service/trade/params/RippleWithdrawFundsParams.java @@ -1,12 +1,42 @@ package org.knowm.xchange.service.trade.params; -import lombok.Value; -import lombok.experimental.SuperBuilder; +import java.math.BigDecimal; +import javax.annotation.Nullable; +import org.knowm.xchange.currency.Currency; -@Value -@SuperBuilder public class RippleWithdrawFundsParams extends DefaultWithdrawFundsParams { + @Nullable public final String tag; // optional - String tag; // optional + public RippleWithdrawFundsParams(String address, Currency currency, BigDecimal amount) { + this(address, currency, amount, null); + } + public RippleWithdrawFundsParams( + String address, Currency currency, BigDecimal amount, String tag) { + super(address, tag, currency, amount, null); + this.tag = tag; + } + + @Override + public String toString() { + return "RippleWithdrawFundsParams{" + + "address='" + + getAddress() + + '\'' + + ", tag='" + + getTag() + + '\'' + + ", currency=" + + getCurrency() + + ", amount=" + + getAmount() + + ", commission=" + + getCommission() + + '}'; + } + + @Nullable + public String getTag() { + return tag; + } } diff --git a/xchange-hitbtc/src/main/java/org/knowm/xchange/hitbtc/v2/service/HitbtcAccountService.java b/xchange-hitbtc/src/main/java/org/knowm/xchange/hitbtc/v2/service/HitbtcAccountService.java index 552707c3022..a5e0820e8ca 100644 --- a/xchange-hitbtc/src/main/java/org/knowm/xchange/hitbtc/v2/service/HitbtcAccountService.java +++ b/xchange-hitbtc/src/main/java/org/knowm/xchange/hitbtc/v2/service/HitbtcAccountService.java @@ -37,12 +37,7 @@ public AccountInfo getAccountInfo() throws IOException { @Override public String withdrawFunds(Currency currency, BigDecimal amount, String address) throws IOException { - return withdrawFunds(DefaultWithdrawFundsParams.builder() - .address(address) - .currency(currency) - .amount(amount) - .build() - ); + return withdrawFunds(new DefaultWithdrawFundsParams(address, currency, amount)); } @Override diff --git a/xchange-livecoin/src/main/java/org/knowm/xchange/livecoin/service/LivecoinAccountService.java b/xchange-livecoin/src/main/java/org/knowm/xchange/livecoin/service/LivecoinAccountService.java index 15611c21729..87e45478bb6 100644 --- a/xchange-livecoin/src/main/java/org/knowm/xchange/livecoin/service/LivecoinAccountService.java +++ b/xchange-livecoin/src/main/java/org/knowm/xchange/livecoin/service/LivecoinAccountService.java @@ -41,12 +41,7 @@ public AccountInfo getAccountInfo() throws IOException { @Override public String withdrawFunds(Currency currency, BigDecimal amount, String address) throws IOException { - return withdrawFunds(DefaultWithdrawFundsParams.builder() - .address(address) - .currency(currency) - .amount(amount) - .build() - ); + return withdrawFunds(new DefaultWithdrawFundsParams(address, currency, amount)); } @Override diff --git a/xchange-okcoin/src/main/java/org/knowm/xchange/okcoin/service/OkCoinAccountService.java b/xchange-okcoin/src/main/java/org/knowm/xchange/okcoin/service/OkCoinAccountService.java index f47459e6bc3..c8dbfef314e 100644 --- a/xchange-okcoin/src/main/java/org/knowm/xchange/okcoin/service/OkCoinAccountService.java +++ b/xchange-okcoin/src/main/java/org/knowm/xchange/okcoin/service/OkCoinAccountService.java @@ -80,7 +80,7 @@ public String withdrawFunds(Currency currency, BigDecimal amount, String address public String withdrawFunds(WithdrawFundsParams params) throws IOException { if (params instanceof DefaultWithdrawFundsParams) { DefaultWithdrawFundsParams defaultParams = (DefaultWithdrawFundsParams) params; - return withdrawFunds(defaultParams.getCurrency(), defaultParams.getAmount(), defaultParams.getAddress()); + return withdrawFunds(defaultParams.currency, defaultParams.amount, defaultParams.address); } throw new IllegalStateException("Don't know how to withdraw: " + params); } diff --git a/xchange-okcoin/src/main/java/org/knowm/xchange/okcoin/v3/service/OkexAccountService.java b/xchange-okcoin/src/main/java/org/knowm/xchange/okcoin/v3/service/OkexAccountService.java index 804fded23d9..2e3fd709e9c 100644 --- a/xchange-okcoin/src/main/java/org/knowm/xchange/okcoin/v3/service/OkexAccountService.java +++ b/xchange-okcoin/src/main/java/org/knowm/xchange/okcoin/v3/service/OkexAccountService.java @@ -68,7 +68,7 @@ public AccountInfo getAccountInfo() throws IOException { public String withdrawFunds(WithdrawFundsParams params) throws IOException { if (params instanceof DefaultWithdrawFundsParams) { DefaultWithdrawFundsParams p = (DefaultWithdrawFundsParams) params; - return withdrawFunds0(p.getCurrency(), p.getAmount(), p.getAddress(), p.getCommission()); + return withdrawFunds0(p.currency, p.amount, p.address, p.commission); } throw new IllegalStateException("Don't know how to withdraw: " + params); } diff --git a/xchange-poloniex/src/main/java/org/knowm/xchange/poloniex/service/PoloniexAccountService.java b/xchange-poloniex/src/main/java/org/knowm/xchange/poloniex/service/PoloniexAccountService.java index a00adb54423..a4e7c8a8a9b 100644 --- a/xchange-poloniex/src/main/java/org/knowm/xchange/poloniex/service/PoloniexAccountService.java +++ b/xchange-poloniex/src/main/java/org/knowm/xchange/poloniex/service/PoloniexAccountService.java @@ -56,12 +56,7 @@ public AccountInfo getAccountInfo() throws IOException { public String withdrawFunds(Currency currency, BigDecimal amount, String address) throws IOException { // does not support XRP withdrawals, use RippleWithdrawFundsParams instead - return withdrawFunds(DefaultWithdrawFundsParams.builder() - .address(address) - .currency(currency) - .amount(amount) - .build() - ); + return withdrawFunds(new DefaultWithdrawFundsParams(address, currency, amount)); } @Override diff --git a/xchange-yobit/src/main/java/org/knowm/xchange/yobit/service/YoBitAccountService.java b/xchange-yobit/src/main/java/org/knowm/xchange/yobit/service/YoBitAccountService.java index b36b280bb69..952f7a32b02 100644 --- a/xchange-yobit/src/main/java/org/knowm/xchange/yobit/service/YoBitAccountService.java +++ b/xchange-yobit/src/main/java/org/knowm/xchange/yobit/service/YoBitAccountService.java @@ -27,12 +27,7 @@ public AccountInfo getAccountInfo() throws IOException { @Override public String withdrawFunds(Currency currency, BigDecimal amount, String address) throws IOException { - return withdrawFunds(DefaultWithdrawFundsParams.builder() - .address(address) - .currency(currency) - .amount(amount) - .build() - ); + return withdrawFunds(new DefaultWithdrawFundsParams(address, currency, amount)); } @Override From 7f67aef4829767d70175ead3c19c85d9d0417cf0 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Sun, 13 Aug 2023 20:20:16 +0200 Subject: [PATCH 102/159] Remove unrelated changes --- .../params/DefaultWithdrawFundsParams.java | 2 ++ .../gateio/service/GateioAccountService.java | 2 +- xchange-kucoin/lombok.config | 1 - .../dto/request/ApplyWithdrawApiRequest.java | 26 ++++++++----------- .../gateio/GateioStreamingAdapters.java | 2 +- .../GateioStreamingAccountServiceTest.java | 2 +- 6 files changed, 16 insertions(+), 19 deletions(-) delete mode 100644 xchange-kucoin/lombok.config diff --git a/xchange-core/src/main/java/org/knowm/xchange/service/trade/params/DefaultWithdrawFundsParams.java b/xchange-core/src/main/java/org/knowm/xchange/service/trade/params/DefaultWithdrawFundsParams.java index d1f8329e00e..ffa85174ea2 100644 --- a/xchange-core/src/main/java/org/knowm/xchange/service/trade/params/DefaultWithdrawFundsParams.java +++ b/xchange-core/src/main/java/org/knowm/xchange/service/trade/params/DefaultWithdrawFundsParams.java @@ -2,9 +2,11 @@ import java.math.BigDecimal; import javax.annotation.Nullable; +import lombok.experimental.SuperBuilder; import org.knowm.xchange.currency.Currency; import org.knowm.xchange.dto.account.AddressWithTag; +@SuperBuilder public class DefaultWithdrawFundsParams implements WithdrawFundsParams { public final String address; diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountService.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountService.java index 8af25ae2f9b..9b79d7b0dff 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountService.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountService.java @@ -34,7 +34,7 @@ public AccountInfo getAccountInfo() throws IOException { List spotBalances = getSpotBalances(null); List balances = spotBalances.stream() - .map(balance -> Balance.builder() + .map(balance -> new Balance.Builder() .currency(balance.getCurrency()) .available(balance.getAvailable()) .frozen(balance.getLocked()) diff --git a/xchange-kucoin/lombok.config b/xchange-kucoin/lombok.config deleted file mode 100644 index e572d96336a..00000000000 --- a/xchange-kucoin/lombok.config +++ /dev/null @@ -1 +0,0 @@ -lombok.equalsAndHashCode.callSuper = call \ No newline at end of file diff --git a/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/dto/request/ApplyWithdrawApiRequest.java b/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/dto/request/ApplyWithdrawApiRequest.java index 21d68ff7c46..8f14826b1e3 100644 --- a/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/dto/request/ApplyWithdrawApiRequest.java +++ b/xchange-kucoin/src/main/java/org/knowm/xchange/kucoin/dto/request/ApplyWithdrawApiRequest.java @@ -4,42 +4,38 @@ import com.fasterxml.jackson.annotation.JsonInclude.Include; import java.math.BigDecimal; import lombok.Builder; -import lombok.Value; +import lombok.Getter; +import lombok.ToString; -@Value +@Getter +@ToString @Builder @JsonInclude(value = Include.NON_EMPTY, content = Include.NON_NULL) public class ApplyWithdrawApiRequest { /** Currency */ - String currency; - + private final String currency; /** Withdrawal address */ - String address; - + private final String address; /** * Withdrawal amount, a positive number which is a multiple of the amount precision (fees * excluded) */ - BigDecimal amount; - + private final BigDecimal amount; /** * [optional] The note that is left on the withdrawal address. When you withdraw from KuCoin to * other platforms, you need to fill in memo(tag). If you don't fill in memo(tag), your withdrawal * may not be available. */ - String memo; - + private final String memo; /** [optional] Internal withdrawal or not. Default setup: false */ - boolean isInner; - + @Builder.Default private final boolean isInner = false; /** [optional] Remark */ - String remark; - + private final String remark; /** * [optional] The chain name of currency, e.g. The available value for USDT are OMNI, ERC20, * TRC20, default is OMNI. This only apply for multi-chain currency, and there is no need for * single chain currency. */ - String chain; + private final String chain; } diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingAdapters.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingAdapters.java index dbead01fe5a..d181b78f8ec 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingAdapters.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingAdapters.java @@ -78,7 +78,7 @@ public UserTrade toUserTrade(GateioSingleUserTradeNotification notification) { public Balance toBalance(GateioSingleSpotBalanceNotification notification) { BalancePayload balancePayload = notification.getResult(); - return Balance.builder() + return new Balance.Builder() .currency(balancePayload.getCurrency()) .total(balancePayload.getTotal()) .available(balancePayload.getAvailable()) diff --git a/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingAccountServiceTest.java b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingAccountServiceTest.java index cf0fb5c5234..00f2195920a 100644 --- a/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingAccountServiceTest.java +++ b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingAccountServiceTest.java @@ -59,7 +59,7 @@ void spot_balances() throws Exception { testObserver.dispose(); - Balance expected = Balance.builder() + Balance expected = new Balance.Builder() .available(new BigDecimal("42.06583427604872431142")) .currency(Currency.USDT) .frozen(BigDecimal.ONE) From dd2300e5ce9924132dc99bfc19abff9012a36d4c Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Tue, 15 Aug 2023 00:51:40 +0200 Subject: [PATCH 103/159] [gateio-v4] Add error mapping --- .../main/java/org/knowm/xchange/gateio/GateioErrorAdapter.java | 2 ++ 1 file changed, 2 insertions(+) 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 805b38d07d9..169b4a2e99d 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 @@ -13,6 +13,7 @@ public class GateioErrorAdapter { public final String INVALID_CURRENCY = "INVALID_CURRENCY"; public final String BALANCE_NOT_ENOUGH = "BALANCE_NOT_ENOUGH"; public final String TOO_FAST = "TOO_FAST"; + public final String TOO_MANY_REQUESTS = "TOO_MANY_REQUESTS"; public final String INVALID_PARAM_VALUE = "INVALID_PARAM_VALUE"; public final String SERVER_ERROR = "SERVER_ERROR"; @@ -32,6 +33,7 @@ public ExchangeException adapt(GateioException e) { return new FundsExceededException(e.getMessage(), e); case TOO_FAST: + case TOO_MANY_REQUESTS: return new RateLimitExceededException(e.getMessage(), e); case SERVER_ERROR: From 7f2441aadbce5cc0475d112c5dcc0abb6c8a1b88 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Tue, 15 Aug 2023 13:18:30 +0200 Subject: [PATCH 104/159] [core] Add mvn wrapper files to .gitignore --- .gitignore | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.gitignore b/.gitignore index 9d82f82f739..5aebb76c393 100644 --- a/.gitignore +++ b/.gitignore @@ -25,6 +25,12 @@ bin/ log/ classes/ +# maven wrapper +.mvn +mvnw +mvnw.cmd + + # Misc. .DS_Store *.swp From b997c03cb8bd21e4598fd20c4086f80e15c3182b Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Wed, 16 Aug 2023 18:06:44 +0200 Subject: [PATCH 105/159] [gateio-v4] Add raw data for user trades --- .../xchange/gateio/GateioV4Authenticated.java | 17 ++++++++++++++++ .../gateio/service/GateioTradeServiceRaw.java | 20 +++++++++++++++++++ .../service/GateioTradeServiceRawTest.java | 16 +++++++++++++++ 3 files changed, 53 insertions(+) diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java index 3d18aae63b6..3995d3e40a9 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java @@ -136,6 +136,23 @@ List getTradingHistory( ) throws IOException, GateioException; + @GET + @Path("spot/my_trades") + @Produces(MediaType.TEXT_PLAIN) + String getTradingHistoryRaw( + @HeaderParam("KEY") String apiKey, + @HeaderParam("Timestamp") SynchronizedValueFactory timestamp, + @HeaderParam("SIGN") ParamsDigest signer, + @QueryParam("currency_pair") String currencyPair, + @QueryParam("limit") Integer pageLength, + @QueryParam("page") Integer pageNumber, + @QueryParam("order_id") String orderId, + @QueryParam("account") String account, + @QueryParam("from") Long from, + @QueryParam("to") Long to + ) throws IOException; + + @GET @Path("wallet/saved_address") List getSavedAddresses( diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeServiceRaw.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeServiceRaw.java index a4cde452b95..dec4244fc6e 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeServiceRaw.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeServiceRaw.java @@ -60,6 +60,26 @@ public List getGateioUserTrades(TradeHistoryParams params) thro } + public String getGateioUserTradesRaw(TradeHistoryParams params) throws IOException { + // get arguments + CurrencyPair currencyPair = params instanceof TradeHistoryParamCurrencyPair ? ((CurrencyPairParam) params).getCurrencyPair() : null; + Integer pageLength = params instanceof TradeHistoryParamPaging ? ((TradeHistoryParamPaging) params).getPageLength() : null; + Integer pageNumber = params instanceof TradeHistoryParamPaging ? ((TradeHistoryParamPaging) params).getPageNumber() : null; + String orderId = params instanceof TradeHistoryParamTransactionId ? ((TradeHistoryParamTransactionId) params).getTransactionId() : null; + Long from = null; + Long to = null; + if (params instanceof TradeHistoryParamsTimeSpan) { + TradeHistoryParamsTimeSpan paramsTimeSpan = ((TradeHistoryParamsTimeSpan) params); + from = paramsTimeSpan.getStartTime() != null ? paramsTimeSpan.getStartTime().getTime() / 1000 : null; + to = paramsTimeSpan.getEndTime() != null ? paramsTimeSpan.getEndTime().getTime() / 1000 : null; + } + + return gateioV4Authenticated.getTradingHistoryRaw(apiKey, exchange.getNonceFactory(), + gateioV4ParamsDigest, GateioAdapters.toString(currencyPair), + pageLength, pageNumber, orderId, null, from, to); + } + + public GateioOrder createOrder(GateioOrder gateioOrder) throws IOException { return gateioV4Authenticated.createOrder(apiKey, exchange.getNonceFactory(), gateioV4ParamsDigest, gateioOrder); } diff --git a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioTradeServiceRawTest.java b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioTradeServiceRawTest.java index e5234101fba..7db16997c6e 100644 --- a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioTradeServiceRawTest.java +++ b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioTradeServiceRawTest.java @@ -5,6 +5,7 @@ import java.io.IOException; import java.math.BigDecimal; import java.time.Instant; +import java.util.Date; import java.util.List; import org.junit.jupiter.api.Test; import org.knowm.xchange.currency.CurrencyPair; @@ -12,6 +13,7 @@ import org.knowm.xchange.dto.Order.OrderType; import org.knowm.xchange.gateio.GateioExchangeWiremock; import org.knowm.xchange.gateio.dto.account.GateioOrder; +import org.knowm.xchange.gateio.service.params.GateioTradeHistoryParams; class GateioTradeServiceRawTest extends GateioExchangeWiremock { @@ -135,4 +137,18 @@ void order_details() throws IOException { assertThat(actualResponse).usingRecursiveComparison().isEqualTo(sampleMarketOrder); } + @Test + void trade_history_raw() throws IOException { + String actual = gateioTradeServiceRaw.getGateioUserTradesRaw(GateioTradeHistoryParams.builder() + .currencyPair(CurrencyPair.BTC_USDT) + .pageLength(2) + .pageNumber(2) + .startTime(Date.from(Instant.ofEpochSecond(1691617924))) + .endTime(Date.from(Instant.ofEpochSecond(1691704324))) + .build()); + + assertThat(actual).startsWith("[ { \"id\": \"6068816979\""); + } + + } \ No newline at end of file From ac2a90c07204c4bb99ed22813b5d7b37d0abb138 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Thu, 17 Aug 2023 00:16:17 +0200 Subject: [PATCH 106/159] [gateio-v4] Add role field to user trade --- .../knowm/xchange/gateio/GateioAdapters.java | 20 ++-- .../xchange/gateio/GateioV4Authenticated.java | 4 +- .../gateio/dto/trade/GateioUserTrade.java | 98 ++++++------------- .../gateio/dto/trade/GateioUserTradeRaw.java | 74 ++++++++++++++ .../knowm/xchange/gateio/dto/trade/Role.java | 17 ++++ .../gateio/service/GateioTradeServiceRaw.java | 4 +- .../service/GateioTradeServiceTest.java | 19 ++-- 7 files changed, 140 insertions(+), 96 deletions(-) create mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/GateioUserTradeRaw.java create mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/Role.java diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java index a2a36b3e3eb..0147a34afee 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java @@ -23,6 +23,7 @@ import org.knowm.xchange.gateio.dto.marketdata.GateioOrderBook; import org.knowm.xchange.gateio.dto.marketdata.GateioTicker; import org.knowm.xchange.gateio.dto.trade.GateioUserTrade; +import org.knowm.xchange.gateio.dto.trade.GateioUserTradeRaw; import org.knowm.xchange.gateio.service.params.GateioWithdrawFundsParams; import org.knowm.xchange.instrument.Instrument; @@ -153,19 +154,12 @@ public Order toOrder(GateioOrder gateioOrder) { } - public UserTrade toUserTrade(GateioUserTrade gateioUserTrade) { - return UserTrade.builder() - .id(String.valueOf(gateioUserTrade.getId())) - .orderId(String.valueOf(gateioUserTrade.getOrderId())) - .feeAmount(gateioUserTrade.getFee()) - .feeCurrency(gateioUserTrade.getFeeCurrency()) - .orderUserReference(gateioUserTrade.getRemark()) - .type(gateioUserTrade.getSide()) - .instrument(gateioUserTrade.getCurrencyPair()) - .price(gateioUserTrade.getPrice()) - .timestamp(Date.from(gateioUserTrade.getTimeMs())) - .originalAmount(gateioUserTrade.getAmount()) - .build(); + public UserTrade toUserTrade(GateioUserTradeRaw gateioUserTradeRaw) { + return new GateioUserTrade(gateioUserTradeRaw.getSide(), gateioUserTradeRaw.getAmount(), gateioUserTradeRaw.getCurrencyPair(), + gateioUserTradeRaw.getPrice(), Date.from(gateioUserTradeRaw.getTimeMs()), String.valueOf( + gateioUserTradeRaw.getId()), + String.valueOf(gateioUserTradeRaw.getOrderId()), gateioUserTradeRaw.getFee(), gateioUserTradeRaw.getFeeCurrency(), + gateioUserTradeRaw.getRemark(), gateioUserTradeRaw.getRole()); } diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java index 3995d3e40a9..cca685612b4 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java @@ -23,7 +23,7 @@ import org.knowm.xchange.gateio.dto.account.GateioWithdrawStatus; import org.knowm.xchange.gateio.dto.account.GateioWithdrawalRecord; import org.knowm.xchange.gateio.dto.account.GateioWithdrawalRequest; -import org.knowm.xchange.gateio.dto.trade.GateioUserTrade; +import org.knowm.xchange.gateio.dto.trade.GateioUserTradeRaw; import si.mazi.rescu.ParamsDigest; import si.mazi.rescu.SynchronizedValueFactory; @@ -122,7 +122,7 @@ GateioOrder createOrder( @GET @Path("spot/my_trades") - List getTradingHistory( + List getTradingHistory( @HeaderParam("KEY") String apiKey, @HeaderParam("Timestamp") SynchronizedValueFactory timestamp, @HeaderParam("SIGN") ParamsDigest signer, diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/GateioUserTrade.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/GateioUserTrade.java index aebb1c128d6..7e5ffe5902f 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/GateioUserTrade.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/GateioUserTrade.java @@ -1,74 +1,40 @@ package org.knowm.xchange.gateio.dto.trade; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; import java.math.BigDecimal; -import java.time.Instant; -import lombok.Builder; -import lombok.Data; -import lombok.extern.jackson.Jacksonized; +import java.util.Date; +import lombok.Value; import org.knowm.xchange.currency.Currency; -import org.knowm.xchange.currency.CurrencyPair; import org.knowm.xchange.dto.Order.OrderType; -import org.knowm.xchange.gateio.config.converter.DoubleToInstantConverter; -import org.knowm.xchange.gateio.config.converter.OrderTypeToStringConverter; -import org.knowm.xchange.gateio.config.converter.StringToCurrencyConverter; -import org.knowm.xchange.gateio.config.converter.StringToCurrencyPairConverter; -import org.knowm.xchange.gateio.config.converter.StringToOrderTypeConverter; -import org.knowm.xchange.gateio.config.converter.TimestampSecondsToInstantConverter; +import org.knowm.xchange.dto.trade.UserTrade; +import org.knowm.xchange.instrument.Instrument; + +@Value +public class GateioUserTrade extends UserTrade { + + Role role; + + /** + * @param type The trade type (BID side or ASK side) + * @param originalAmount The depth of this trade + * @param instrument The exchange identifier (e.g. "BTC/USD") + * @param price The price (either the bid or the ask) + * @param timestamp The timestamp of the trade + * @param id The id of the trade + * @param orderId The id of the order responsible for execution of this trade + * @param feeAmount The fee that was charged by the exchange for this trade + * @param feeCurrency The symbol of the currency in which the fee was charged + * @param orderUserReference The id that the user has insert to the trade + * @param role Trade role + */ + public GateioUserTrade(OrderType type, + BigDecimal originalAmount, Instrument instrument, + BigDecimal price, Date timestamp, String id, String orderId, + BigDecimal feeAmount, Currency feeCurrency, + String orderUserReference, Role role) { + super(type, originalAmount, instrument, price, timestamp, id, orderId, feeAmount, feeCurrency, + orderUserReference); + this.role = role; + } -@Data -@Builder -@Jacksonized -public class GateioUserTrade { - - @JsonProperty("id") - Long id; - - @JsonProperty("create_time") - @JsonDeserialize(converter = TimestampSecondsToInstantConverter.class) - Instant time; - - @JsonProperty("create_time_ms") - @JsonDeserialize(converter = DoubleToInstantConverter.class) - Instant timeMs; - - @JsonProperty("currency_pair") - @JsonDeserialize(converter = StringToCurrencyPairConverter.class) - CurrencyPair currencyPair; - - @JsonProperty("side") - @JsonDeserialize(converter = StringToOrderTypeConverter.class) - @JsonSerialize(converter = OrderTypeToStringConverter.class) - OrderType side; - - @JsonProperty("role") - String role; - - @JsonProperty("amount") - BigDecimal amount; - - @JsonProperty("price") - BigDecimal price; - - @JsonProperty("order_id") - Long orderId; - - @JsonProperty("fee") - BigDecimal fee; - - @JsonProperty("fee_currency") - @JsonDeserialize(converter = StringToCurrencyConverter.class) - Currency feeCurrency; - - @JsonProperty("point_fee") - BigDecimal pointFee; - - @JsonProperty("gt_fee") - BigDecimal gtFee; - - @JsonProperty("amend_text") - String remark; } diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/GateioUserTradeRaw.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/GateioUserTradeRaw.java new file mode 100644 index 00000000000..e0a67fd79e2 --- /dev/null +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/GateioUserTradeRaw.java @@ -0,0 +1,74 @@ +package org.knowm.xchange.gateio.dto.trade; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import java.math.BigDecimal; +import java.time.Instant; +import lombok.Builder; +import lombok.Data; +import lombok.extern.jackson.Jacksonized; +import org.knowm.xchange.currency.Currency; +import org.knowm.xchange.currency.CurrencyPair; +import org.knowm.xchange.dto.Order.OrderType; +import org.knowm.xchange.gateio.config.converter.DoubleToInstantConverter; +import org.knowm.xchange.gateio.config.converter.OrderTypeToStringConverter; +import org.knowm.xchange.gateio.config.converter.StringToCurrencyConverter; +import org.knowm.xchange.gateio.config.converter.StringToCurrencyPairConverter; +import org.knowm.xchange.gateio.config.converter.StringToOrderTypeConverter; +import org.knowm.xchange.gateio.config.converter.TimestampSecondsToInstantConverter; + +@Data +@Builder +@Jacksonized +public class GateioUserTradeRaw { + + @JsonProperty("id") + Long id; + + @JsonProperty("create_time") + @JsonDeserialize(converter = TimestampSecondsToInstantConverter.class) + Instant time; + + @JsonProperty("create_time_ms") + @JsonDeserialize(converter = DoubleToInstantConverter.class) + Instant timeMs; + + @JsonProperty("currency_pair") + @JsonDeserialize(converter = StringToCurrencyPairConverter.class) + CurrencyPair currencyPair; + + @JsonProperty("side") + @JsonDeserialize(converter = StringToOrderTypeConverter.class) + @JsonSerialize(converter = OrderTypeToStringConverter.class) + OrderType side; + + @JsonProperty("role") + Role role; + + @JsonProperty("amount") + BigDecimal amount; + + @JsonProperty("price") + BigDecimal price; + + @JsonProperty("order_id") + Long orderId; + + @JsonProperty("fee") + BigDecimal fee; + + @JsonProperty("fee_currency") + @JsonDeserialize(converter = StringToCurrencyConverter.class) + Currency feeCurrency; + + @JsonProperty("point_fee") + BigDecimal pointFee; + + @JsonProperty("gt_fee") + BigDecimal gtFee; + + @JsonProperty("amend_text") + String remark; + +} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/Role.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/Role.java new file mode 100644 index 00000000000..db867b5f499 --- /dev/null +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/trade/Role.java @@ -0,0 +1,17 @@ +package org.knowm.xchange.gateio.dto.trade; + +import com.fasterxml.jackson.annotation.JsonValue; +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public enum Role { + TAKER("taker"), + MAKER("maker"); + + @JsonValue + private final String value; + + +} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeServiceRaw.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeServiceRaw.java index dec4244fc6e..26653a99629 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeServiceRaw.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeServiceRaw.java @@ -10,7 +10,7 @@ import org.knowm.xchange.gateio.GateioAdapters; import org.knowm.xchange.gateio.GateioExchange; import org.knowm.xchange.gateio.dto.account.GateioOrder; -import org.knowm.xchange.gateio.dto.trade.GateioUserTrade; +import org.knowm.xchange.gateio.dto.trade.GateioUserTradeRaw; import org.knowm.xchange.instrument.Instrument; import org.knowm.xchange.service.trade.params.CurrencyPairParam; import org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair; @@ -40,7 +40,7 @@ public List listOrders(Instrument instrument, OrderStatus orderStat } - public List getGateioUserTrades(TradeHistoryParams params) throws IOException { + public List getGateioUserTrades(TradeHistoryParams params) throws IOException { // get arguments CurrencyPair currencyPair = params instanceof TradeHistoryParamCurrencyPair ? ((CurrencyPairParam) params).getCurrencyPair() : null; Integer pageLength = params instanceof TradeHistoryParamPaging ? ((TradeHistoryParamPaging) params).getPageLength() : null; diff --git a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioTradeServiceTest.java b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioTradeServiceTest.java index 6780afdbfad..22996089711 100644 --- a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioTradeServiceTest.java +++ b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioTradeServiceTest.java @@ -20,6 +20,8 @@ import org.knowm.xchange.dto.trade.UserTrades; import org.knowm.xchange.exceptions.FundsExceededException; import org.knowm.xchange.gateio.GateioExchangeWiremock; +import org.knowm.xchange.gateio.dto.trade.GateioUserTrade; +import org.knowm.xchange.gateio.dto.trade.Role; import org.knowm.xchange.gateio.service.params.GateioTradeHistoryParams; import org.knowm.xchange.service.trade.params.DefaultCancelOrderByInstrumentAndIdParams; import org.knowm.xchange.service.trade.params.orders.DefaultQueryOrderParamInstrument; @@ -131,22 +133,13 @@ void trade_history() throws IOException { assertThat(userTrades.getUserTrades()).hasSize(2); - UserTrade expected = new UserTrade.Builder() - .instrument(CurrencyPair.BTC_USDT) - .id("6068789332") - .orderId("381064942553") - .orderUserReference("-") - .originalAmount(new BigDecimal("0.00005")) - .feeAmount(new BigDecimal("0.00294472")) - .feeCurrency(Currency.USDT) - .price(new BigDecimal("29447.2")) - .timestamp(Date.from(Instant.ofEpochMilli(1691702286356L))) - .type(OrderType.ASK) - .build(); + GateioUserTrade expected = new GateioUserTrade(OrderType.ASK, new BigDecimal("0.00005"), CurrencyPair.BTC_USDT, + new BigDecimal("29447.2"), Date.from(Instant.ofEpochMilli(1691702286356L)), "6068789332", + "381064942553", new BigDecimal("0.00294472"), Currency.USDT, "-", Role.TAKER); UserTrade actual = userTrades.getUserTrades().get(0); - assertThat(actual).isEqualTo(expected); + assertThat(actual).usingRecursiveComparison().isEqualTo(expected); } From 958bd75be52730e406245839a3a4b5ab176c1049 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Thu, 17 Aug 2023 00:24:51 +0200 Subject: [PATCH 107/159] [gateio-v4] Fix string representation of child classes --- xchange-gateio-v4/lombok.config | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/xchange-gateio-v4/lombok.config b/xchange-gateio-v4/lombok.config index e572d96336a..22b090cc4b6 100644 --- a/xchange-gateio-v4/lombok.config +++ b/xchange-gateio-v4/lombok.config @@ -1 +1,2 @@ -lombok.equalsAndHashCode.callSuper = call \ No newline at end of file +lombok.equalsAndHashCode.callSuper = call +lombok.tostring.callsuper = call \ No newline at end of file From 1446687ab0c219667df0d865e5bc6b3184d3f878 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Thu, 17 Aug 2023 01:00:32 +0200 Subject: [PATCH 108/159] [gateio-v4] Add getting all pages --- .../gateio/service/GateioTradeServiceRaw.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeServiceRaw.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeServiceRaw.java index 26653a99629..9d0364bb673 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeServiceRaw.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeServiceRaw.java @@ -1,9 +1,11 @@ package org.knowm.xchange.gateio.service; import java.io.IOException; +import java.util.ArrayList; import java.util.EnumSet; import java.util.List; import java.util.Set; +import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.Validate; import org.knowm.xchange.currency.CurrencyPair; import org.knowm.xchange.dto.Order.OrderStatus; @@ -54,6 +56,24 @@ public List getGateioUserTrades(TradeHistoryParams params) t to = paramsTimeSpan.getEndTime() != null ? paramsTimeSpan.getEndTime().getTime() / 1000 : null; } + // if no pagination is given, get all records in chunks + if (ObjectUtils.allNull(pageLength, pageNumber)) { + List result = new ArrayList<>(); + List chunk; + Integer currentPageNumber = 1; + + do { + chunk = gateioV4Authenticated.getTradingHistory(apiKey, exchange.getNonceFactory(), + gateioV4ParamsDigest, GateioAdapters.toString(currencyPair), + 1000, currentPageNumber, orderId, null, from, to); + currentPageNumber++; + result.addAll(chunk); + } + while (!chunk.isEmpty()); + + return result; + } + return gateioV4Authenticated.getTradingHistory(apiKey, exchange.getNonceFactory(), gateioV4ParamsDigest, GateioAdapters.toString(currencyPair), pageLength, pageNumber, orderId, null, from, to); From f3411f319dafd22322815c6470cf88f89c02cdcf Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Thu, 17 Aug 2023 11:16:00 +0200 Subject: [PATCH 109/159] [gateio-v4] Add enum for withdrawal status --- .../dto/account/GateioWithdrawalRecord.java | 26 ++++++++++++++++++- .../service/GateioAccountServiceRawTest.java | 4 +-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioWithdrawalRecord.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioWithdrawalRecord.java index 39e153ecdb1..c199e49ecfb 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioWithdrawalRecord.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioWithdrawalRecord.java @@ -4,8 +4,10 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import java.math.BigDecimal; import java.time.Instant; +import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; +import lombok.Getter; import lombok.extern.jackson.Jacksonized; import org.knowm.xchange.currency.Currency; import org.knowm.xchange.gateio.config.converter.StringToCurrencyConverter; @@ -43,7 +45,7 @@ public class GateioWithdrawalRecord { String tag; @JsonProperty("status") - String status; + Status status; @JsonProperty("chain") String chain; @@ -51,4 +53,26 @@ public class GateioWithdrawalRecord { @JsonProperty("fee") BigDecimal fee; + + @Getter + @AllArgsConstructor + public static enum Status { + DONE("done"), + CANCEL("cancelled"), + REQUEST("requesting"), + MANUAL("pending manual approval"), + BCODE("GateCode operation"), + EXTPEND("pending confirm after sending"), + FAIL("pending confirm when fail"), + INVALID("invalid order"), + VERIFY("verifying"), + PROCES("processing"), + PEND("pending"), + DMOVE("required manual approval"), + SPLITPEND("the order is automatically split due to large amount"); + + private final String description; + + } + } diff --git a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceRawTest.java b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceRawTest.java index c7066f036f2..93e7c0c44bb 100644 --- a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceRawTest.java +++ b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceRawTest.java @@ -138,7 +138,7 @@ void withdrawal_records() throws IOException { .txId("0x8f72d42b016a2b7b543149e707ff37fadded2ff3ef6767bee30b6003330f604b") .chain("ETH") .createdAt(Instant.parse("2023-06-01T11:34:15Z")) - .status("DONE") + .status(GateioWithdrawalRecord.Status.DONE) .clientRecordId("a") .tag("b") .build(); @@ -193,7 +193,7 @@ void withdraw() throws IOException { .chain("SOL") .amount(BigDecimal.valueOf(3)) .currency(Currency.USDT) - .status("REQUEST") + .status(GateioWithdrawalRecord.Status.REQUEST) .build(); assertThat(actual).usingRecursiveComparison().isEqualTo(expected); From f140cf2c384e48c7d410dbb3b59c0a6a8e12d76d Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Thu, 17 Aug 2023 11:30:40 +0200 Subject: [PATCH 110/159] [gateio-v4] Fix wrong query param --- .../java/org/knowm/xchange/gateio/GateioV4Authenticated.java | 2 +- .../src/test/resources/mappings/api_v4_spot_account_book.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java index cca685612b4..3357133fde8 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java @@ -71,7 +71,7 @@ List getAccountBookRecords( @QueryParam("from") Long from, @QueryParam("to") Long to, @QueryParam("limit") Integer pageLength, - @QueryParam("offset") Integer zeroBasedPageNumber, + @QueryParam("page") Integer pageNumber, @QueryParam("type") String type ) throws IOException, GateioException; diff --git a/xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_account_book.json b/xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_account_book.json index 007846253c9..ad55b447d4c 100644 --- a/xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_account_book.json +++ b/xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_account_book.json @@ -2,7 +2,7 @@ "id" : "0f4c0848-df10-4f1e-b5e7-1b5213fa2f18", "name" : "api_v4_spot_account_book", "request" : { - "url" : "/api/v4/spot/account_book?currency=USDT&from=1691447482&to=1691533882&limit=2&offset=1&type=order_fee", + "url" : "/api/v4/spot/account_book?currency=USDT&from=1691447482&to=1691533882&limit=2&page=1&type=order_fee", "method" : "GET" }, "response" : { From 46ed4e15836f9f7a6861c537473a6fc040d86190 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Thu, 17 Aug 2023 11:59:46 +0200 Subject: [PATCH 111/159] [gateio-streaming] Add enums for side and role --- .../gateio/dto/response/trade/TradePayload.java | 12 +++++++++--- .../dto/response/usertrade/UserTradePayload.java | 15 +++++++++++---- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/trade/TradePayload.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/trade/TradePayload.java index 818375709f4..b4e1e8e366f 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/trade/TradePayload.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/trade/TradePayload.java @@ -2,12 +2,16 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; import java.math.BigDecimal; import java.time.Instant; import lombok.Data; import org.knowm.xchange.currency.CurrencyPair; +import org.knowm.xchange.dto.Order.OrderType; import org.knowm.xchange.gateio.config.converter.DoubleToInstantConverter; +import org.knowm.xchange.gateio.config.converter.OrderTypeToStringConverter; import org.knowm.xchange.gateio.config.converter.StringToCurrencyPairConverter; +import org.knowm.xchange.gateio.config.converter.StringToOrderTypeConverter; import org.knowm.xchange.gateio.config.converter.TimestampSecondsToInstantConverter; @Data @@ -18,14 +22,16 @@ public class TradePayload { @JsonProperty("create_time") @JsonDeserialize(converter = TimestampSecondsToInstantConverter.class) - private Instant time; + Instant time; @JsonProperty("create_time_ms") @JsonDeserialize(converter = DoubleToInstantConverter.class) - private Instant timeMs; + Instant timeMs; @JsonProperty("side") - private String side; + @JsonDeserialize(converter = StringToOrderTypeConverter.class) + @JsonSerialize(converter = OrderTypeToStringConverter.class) + OrderType side; @JsonProperty("currency_pair") @JsonDeserialize(converter = StringToCurrencyPairConverter.class) diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/usertrade/UserTradePayload.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/usertrade/UserTradePayload.java index f136f34b3f3..adb9f9caf2b 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/usertrade/UserTradePayload.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/dto/response/usertrade/UserTradePayload.java @@ -2,14 +2,19 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; import java.math.BigDecimal; import java.time.Instant; import lombok.Data; import org.knowm.xchange.currency.Currency; import org.knowm.xchange.currency.CurrencyPair; +import org.knowm.xchange.dto.Order.OrderType; import org.knowm.xchange.gateio.config.converter.DoubleToInstantConverter; +import org.knowm.xchange.gateio.config.converter.OrderTypeToStringConverter; import org.knowm.xchange.gateio.config.converter.StringToCurrencyPairConverter; +import org.knowm.xchange.gateio.config.converter.StringToOrderTypeConverter; import org.knowm.xchange.gateio.config.converter.TimestampSecondsToInstantConverter; +import org.knowm.xchange.gateio.dto.trade.Role; @Data public class UserTradePayload { @@ -29,20 +34,22 @@ public class UserTradePayload { @JsonProperty("create_time") @JsonDeserialize(converter = TimestampSecondsToInstantConverter.class) - private Instant time; + Instant time; @JsonProperty("create_time_ms") @JsonDeserialize(converter = DoubleToInstantConverter.class) - private Instant timeMs; + Instant timeMs; @JsonProperty("side") - private String side; + @JsonDeserialize(converter = StringToOrderTypeConverter.class) + @JsonSerialize(converter = OrderTypeToStringConverter.class) + OrderType side; @JsonProperty("amount") BigDecimal amount; @JsonProperty("role") - String role; + Role role; @JsonProperty("price") BigDecimal price; From ccb2e5c9ee94b2e12c6cba4423c5c34cbbc3a0e5 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Thu, 17 Aug 2023 15:06:22 +0200 Subject: [PATCH 112/159] [gateio-v4] Add config for custom RestProxyFactory with example --- .../xchange/gateio/GateioV4Authenticated.java | 17 ----------- .../knowm/xchange/gateio/config/Config.java | 18 +++++++++++ .../gateio/service/GateioBaseService.java | 4 +++ .../gateio/service/GateioTradeServiceRaw.java | 20 ------------- .../service/GateioAccountServiceTest.java | 7 +++++ .../gateio/service/GateioBaseServiceTest.java | 30 +++++++++++++++++++ .../service/GateioTradeServiceRawTest.java | 15 ---------- .../BodyLoggingRestInvocationHandler.java | 24 +++++++++++++++ .../rescu/CustomRestProxyFactoryImpl.java | 17 +++++++++++ 9 files changed, 100 insertions(+), 52 deletions(-) create mode 100644 xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/Config.java create mode 100644 xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioBaseServiceTest.java create mode 100644 xchange-gateio-v4/src/test/java/si/mazi/rescu/BodyLoggingRestInvocationHandler.java create mode 100644 xchange-gateio-v4/src/test/java/si/mazi/rescu/CustomRestProxyFactoryImpl.java diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java index 3357133fde8..84ad6bc5b18 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioV4Authenticated.java @@ -136,23 +136,6 @@ List getTradingHistory( ) throws IOException, GateioException; - @GET - @Path("spot/my_trades") - @Produces(MediaType.TEXT_PLAIN) - String getTradingHistoryRaw( - @HeaderParam("KEY") String apiKey, - @HeaderParam("Timestamp") SynchronizedValueFactory timestamp, - @HeaderParam("SIGN") ParamsDigest signer, - @QueryParam("currency_pair") String currencyPair, - @QueryParam("limit") Integer pageLength, - @QueryParam("page") Integer pageNumber, - @QueryParam("order_id") String orderId, - @QueryParam("account") String account, - @QueryParam("from") Long from, - @QueryParam("to") Long to - ) throws IOException; - - @GET @Path("wallet/saved_address") List getSavedAddresses( 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 new file mode 100644 index 00000000000..e99b200e06b --- /dev/null +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/config/Config.java @@ -0,0 +1,18 @@ +package org.knowm.xchange.gateio.config; + +import lombok.Data; +import si.mazi.rescu.IRestProxyFactory; +import si.mazi.rescu.RestProxyFactoryImpl; + +@Data +public class Config { + + private Class restProxyFactoryClass = RestProxyFactoryImpl.class; + + private static Config instance = new Config(); + + public static Config getInstance() { + return instance; + } + +} diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioBaseService.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioBaseService.java index 4dd4a306b25..ec3c397aa85 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioBaseService.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioBaseService.java @@ -1,9 +1,11 @@ package org.knowm.xchange.gateio.service; +import lombok.SneakyThrows; import org.knowm.xchange.client.ExchangeRestProxyBuilder; import org.knowm.xchange.gateio.Gateio; import org.knowm.xchange.gateio.GateioExchange; import org.knowm.xchange.gateio.GateioV4Authenticated; +import org.knowm.xchange.gateio.config.Config; import org.knowm.xchange.gateio.config.GateioJacksonObjectMapperFactory; import org.knowm.xchange.service.BaseExchangeService; import org.knowm.xchange.service.BaseService; @@ -17,12 +19,14 @@ public class GateioBaseService extends BaseExchangeService imple protected final ParamsDigest gateioV4ParamsDigest; + @SneakyThrows public GateioBaseService(GateioExchange exchange) { super(exchange); gateio = ExchangeRestProxyBuilder .forInterface(Gateio.class, exchange.getExchangeSpecification()) .clientConfigCustomizer(clientConfig -> clientConfig.setJacksonObjectMapperFactory(new GateioJacksonObjectMapperFactory())) + .restProxyFactory(Config.getInstance().getRestProxyFactoryClass().getDeclaredConstructor().newInstance()) .build(); apiKey = exchange.getExchangeSpecification().getApiKey(); diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeServiceRaw.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeServiceRaw.java index 9d0364bb673..94e516240d5 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeServiceRaw.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioTradeServiceRaw.java @@ -80,26 +80,6 @@ public List getGateioUserTrades(TradeHistoryParams params) t } - public String getGateioUserTradesRaw(TradeHistoryParams params) throws IOException { - // get arguments - CurrencyPair currencyPair = params instanceof TradeHistoryParamCurrencyPair ? ((CurrencyPairParam) params).getCurrencyPair() : null; - Integer pageLength = params instanceof TradeHistoryParamPaging ? ((TradeHistoryParamPaging) params).getPageLength() : null; - Integer pageNumber = params instanceof TradeHistoryParamPaging ? ((TradeHistoryParamPaging) params).getPageNumber() : null; - String orderId = params instanceof TradeHistoryParamTransactionId ? ((TradeHistoryParamTransactionId) params).getTransactionId() : null; - Long from = null; - Long to = null; - if (params instanceof TradeHistoryParamsTimeSpan) { - TradeHistoryParamsTimeSpan paramsTimeSpan = ((TradeHistoryParamsTimeSpan) params); - from = paramsTimeSpan.getStartTime() != null ? paramsTimeSpan.getStartTime().getTime() / 1000 : null; - to = paramsTimeSpan.getEndTime() != null ? paramsTimeSpan.getEndTime().getTime() / 1000 : null; - } - - return gateioV4Authenticated.getTradingHistoryRaw(apiKey, exchange.getNonceFactory(), - gateioV4ParamsDigest, GateioAdapters.toString(currencyPair), - pageLength, pageNumber, orderId, null, from, to); - } - - public GateioOrder createOrder(GateioOrder gateioOrder) throws IOException { return gateioV4Authenticated.createOrder(apiKey, exchange.getNonceFactory(), gateioV4ParamsDigest, gateioOrder); } diff --git a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceTest.java b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceTest.java index 466f0f748fd..1107887502e 100644 --- a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceTest.java +++ b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioAccountServiceTest.java @@ -18,11 +18,18 @@ import org.knowm.xchange.exceptions.OrderNotValidException; import org.knowm.xchange.exceptions.RateLimitExceededException; import org.knowm.xchange.gateio.GateioExchangeWiremock; +import org.knowm.xchange.gateio.config.Config; import org.knowm.xchange.gateio.service.params.GateioFundingHistoryParams; import org.knowm.xchange.gateio.service.params.GateioWithdrawFundsParams; +import si.mazi.rescu.CustomRestProxyFactoryImpl; class GateioAccountServiceTest extends GateioExchangeWiremock { + + static { + Config.getInstance().setRestProxyFactoryClass(CustomRestProxyFactoryImpl.class); + } + GateioAccountService gateioAccountService = ((GateioAccountService) exchange.getAccountService()); diff --git a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioBaseServiceTest.java b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioBaseServiceTest.java new file mode 100644 index 00000000000..6e29d262443 --- /dev/null +++ b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioBaseServiceTest.java @@ -0,0 +1,30 @@ +package org.knowm.xchange.gateio.service; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.lang.reflect.Proxy; +import org.junit.jupiter.api.Test; +import org.knowm.xchange.gateio.GateioExchangeWiremock; +import org.knowm.xchange.gateio.config.Config; +import si.mazi.rescu.BodyLoggingRestInvocationHandler; +import si.mazi.rescu.CustomRestProxyFactoryImpl; + +/** + * Contains the example of overriding of RestProxyFactory for exchange for some specific logic + */ +class GateioBaseServiceTest extends GateioExchangeWiremock { + + // set custom proxy factory before creating the exchange + static { + Config.getInstance().setRestProxyFactoryClass(CustomRestProxyFactoryImpl.class); + } + + + @Test + void correct_proxy_factory() { + GateioBaseService service = ((GateioBaseService) exchange.getAccountService()); + assertThat(Proxy.getInvocationHandler(service.gateio) instanceof BodyLoggingRestInvocationHandler).isTrue(); + } + + +} \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioTradeServiceRawTest.java b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioTradeServiceRawTest.java index 7db16997c6e..18febb5a30c 100644 --- a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioTradeServiceRawTest.java +++ b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioTradeServiceRawTest.java @@ -5,7 +5,6 @@ import java.io.IOException; import java.math.BigDecimal; import java.time.Instant; -import java.util.Date; import java.util.List; import org.junit.jupiter.api.Test; import org.knowm.xchange.currency.CurrencyPair; @@ -13,7 +12,6 @@ import org.knowm.xchange.dto.Order.OrderType; import org.knowm.xchange.gateio.GateioExchangeWiremock; import org.knowm.xchange.gateio.dto.account.GateioOrder; -import org.knowm.xchange.gateio.service.params.GateioTradeHistoryParams; class GateioTradeServiceRawTest extends GateioExchangeWiremock { @@ -137,18 +135,5 @@ void order_details() throws IOException { assertThat(actualResponse).usingRecursiveComparison().isEqualTo(sampleMarketOrder); } - @Test - void trade_history_raw() throws IOException { - String actual = gateioTradeServiceRaw.getGateioUserTradesRaw(GateioTradeHistoryParams.builder() - .currencyPair(CurrencyPair.BTC_USDT) - .pageLength(2) - .pageNumber(2) - .startTime(Date.from(Instant.ofEpochSecond(1691617924))) - .endTime(Date.from(Instant.ofEpochSecond(1691704324))) - .build()); - - assertThat(actual).startsWith("[ { \"id\": \"6068816979\""); - } - } \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/java/si/mazi/rescu/BodyLoggingRestInvocationHandler.java b/xchange-gateio-v4/src/test/java/si/mazi/rescu/BodyLoggingRestInvocationHandler.java new file mode 100644 index 00000000000..d955cd17b8c --- /dev/null +++ b/xchange-gateio-v4/src/test/java/si/mazi/rescu/BodyLoggingRestInvocationHandler.java @@ -0,0 +1,24 @@ +package si.mazi.rescu; + +import java.io.IOException; +import lombok.extern.slf4j.Slf4j; + +/** + * Invocation handler that logs the raw textual response body + */ +@Slf4j +public class BodyLoggingRestInvocationHandler extends RestInvocationHandler { + + BodyLoggingRestInvocationHandler(Class restInterface, String url, ClientConfig config) { + super(restInterface, url, config); + } + + @Override + protected Object mapInvocationResult(InvocationResult invocationResult, RestMethodMetadata methodMetadata) throws IOException { + // log the body + log.info(invocationResult.getHttpBody()); + + // do the normal processing + return super.mapInvocationResult(invocationResult, methodMetadata); + } +} diff --git a/xchange-gateio-v4/src/test/java/si/mazi/rescu/CustomRestProxyFactoryImpl.java b/xchange-gateio-v4/src/test/java/si/mazi/rescu/CustomRestProxyFactoryImpl.java new file mode 100644 index 00000000000..6594f8ec2d1 --- /dev/null +++ b/xchange-gateio-v4/src/test/java/si/mazi/rescu/CustomRestProxyFactoryImpl.java @@ -0,0 +1,17 @@ +package si.mazi.rescu; + +/** + * The implementation of {@link IRestProxyFactory} that instantiates {@link BodyLoggingRestInvocationHandler} + */ +public class CustomRestProxyFactoryImpl implements IRestProxyFactory { + + @Override + public I createProxy(Class restInterface, String baseUrl, ClientConfig config, Interceptor... interceptors) { + return RestProxyFactory.createProxy(restInterface, RestProxyFactory.wrap(new BodyLoggingRestInvocationHandler(restInterface, baseUrl, config), interceptors)); + } + + @Override + public I createProxy(Class restInterface, String baseUrl) { + return createProxy(restInterface, baseUrl, null); + } +} From 917162cd9da8b42696743a774f40e9ede8ca3d2c Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Wed, 23 Aug 2023 22:57:22 +0200 Subject: [PATCH 113/159] [gateio-v4] Fix method visibility --- .../knowm/xchange/gateio/service/GateioAccountServiceRaw.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountServiceRaw.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountServiceRaw.java index 6f8ef6c7202..9f5bddfb8f6 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountServiceRaw.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioAccountServiceRaw.java @@ -111,7 +111,7 @@ public List getAccountBookRecords(TradeHistoryParams pa } - List getSubAccountTransfers(GateioSubAccountTransfersParams params) throws IOException { + public List getSubAccountTransfers(GateioSubAccountTransfersParams params) throws IOException { Long from = params.getStartTime() != null ? params.getStartTime().getEpochSecond() : null; Long to = params.getEndTime() != null ? params.getEndTime().getEpochSecond() : null; From 6ebe46221dd03debb3146c4f35770c35ddb86ead Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Wed, 23 Aug 2023 22:57:34 +0200 Subject: [PATCH 114/159] [gateio-v4] Add constructors --- .../xchange/gateio/service/params/GateioDepositsParams.java | 4 ++++ .../gateio/service/params/GateioWithdrawalsParams.java | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/params/GateioDepositsParams.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/params/GateioDepositsParams.java index 4bef2686aa6..88678aecc4b 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/params/GateioDepositsParams.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/params/GateioDepositsParams.java @@ -1,11 +1,15 @@ package org.knowm.xchange.gateio.service.params; import java.time.Instant; +import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; +import lombok.NoArgsConstructor; import org.knowm.xchange.currency.Currency; @Data +@AllArgsConstructor +@NoArgsConstructor @Builder public class GateioDepositsParams { diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/params/GateioWithdrawalsParams.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/params/GateioWithdrawalsParams.java index f8d0c73d906..ce906635abb 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/params/GateioWithdrawalsParams.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/params/GateioWithdrawalsParams.java @@ -1,11 +1,15 @@ package org.knowm.xchange.gateio.service.params; import java.time.Instant; +import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; +import lombok.NoArgsConstructor; import org.knowm.xchange.currency.Currency; @Data +@AllArgsConstructor +@NoArgsConstructor @Builder public class GateioWithdrawalsParams { From 3e8c11b4a409114c8a9cd349ae67a3e6baea33e1 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Thu, 24 Aug 2023 18:45:56 +0200 Subject: [PATCH 115/159] [gateio-streaming] Fix default specification --- .../bitrich/xchangestream/gateio/GateioStreamingExchange.java | 1 + 1 file changed, 1 insertion(+) diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingExchange.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingExchange.java index 8fc525fac93..c36b8f5a9e9 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingExchange.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingExchange.java @@ -68,6 +68,7 @@ public void useCompressedMessages(boolean compressedMessages) { @Override public ExchangeSpecification getDefaultExchangeSpecification() { ExchangeSpecification specification = super.getDefaultExchangeSpecification(); + specification.setShouldLoadRemoteMetaData(false); specification.setSslUri(Config.V4_URL); return specification; } From 600875bbb80de72ee740dd4577283378b255cdc1 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Thu, 24 Aug 2023 23:51:56 +0200 Subject: [PATCH 116/159] [gateio-streaming] Code cleanup --- .../info/bitrich/xchangestream/gateio/GateioManualExample.java | 1 - .../bitrich/xchangestream/gateio/GateioStreamingExchangeIT.java | 1 - 2 files changed, 2 deletions(-) diff --git a/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioManualExample.java b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioManualExample.java index 87dded8889c..97624b63e49 100644 --- a/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioManualExample.java +++ b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioManualExample.java @@ -15,7 +15,6 @@ public static void main(String[] args) throws Exception { StreamingExchangeFactory.INSTANCE .createExchangeWithoutSpecification(GateioStreamingExchange.class) .getDefaultExchangeSpecification(); - spec.setShouldLoadRemoteMetaData(false); GateioStreamingExchange exchange = (GateioStreamingExchange) StreamingExchangeFactory.INSTANCE.createExchange(spec); diff --git a/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingExchangeIT.java b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingExchangeIT.java index c609599ed9c..8553614e150 100644 --- a/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingExchangeIT.java +++ b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingExchangeIT.java @@ -22,7 +22,6 @@ public static void setup() { .getDefaultExchangeSpecification(); spec.setApiKey(System.getenv("GATEIO_API_KEY")); spec.setSecretKey(System.getenv("GATEIO_API_SECRET")); - spec.setShouldLoadRemoteMetaData(false); exchange = (GateioStreamingExchange) StreamingExchangeFactory.INSTANCE.createExchange(spec); From c0b58ccd88c661e68cd89d48a09971361c8898cc Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Tue, 29 Aug 2023 12:27:23 +0200 Subject: [PATCH 117/159] [gateio-streaming] Fix wrong order side mapping --- .../bitrich/xchangestream/gateio/GateioStreamingAdapters.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingAdapters.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingAdapters.java index d181b78f8ec..4b5dd913dc7 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingAdapters.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingAdapters.java @@ -47,7 +47,7 @@ public Trade toTrade(GateioTradeNotification notification) { return new Trade.Builder() - .type("sell".equals(tradePayload.getSide()) ? OrderType.ASK : OrderType.BID) + .type(tradePayload.getSide()) .originalAmount(tradePayload.getAmount()) .instrument(tradePayload.getCurrencyPair()) .price(tradePayload.getPrice()) @@ -61,7 +61,7 @@ public UserTrade toUserTrade(GateioSingleUserTradeNotification notification) { UserTradePayload userTradePayload = notification.getResult(); return new UserTrade.Builder() - .type("sell".equals(userTradePayload.getSide()) ? OrderType.ASK : OrderType.BID) + .type(userTradePayload.getSide()) .originalAmount(userTradePayload.getAmount()) .instrument(userTradePayload.getCurrencyPair()) .price(userTradePayload.getPrice()) From 3fcbe72c4c831d4f6b61b718da54245843b82523 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Tue, 29 Aug 2023 13:59:46 +0200 Subject: [PATCH 118/159] [gateio-v4] Add RestProxyFactory to authenticated client --- .../java/org/knowm/xchange/gateio/service/GateioBaseService.java | 1 + 1 file changed, 1 insertion(+) diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioBaseService.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioBaseService.java index ec3c397aa85..9be973588ef 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioBaseService.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/service/GateioBaseService.java @@ -33,6 +33,7 @@ public GateioBaseService(GateioExchange exchange) { gateioV4Authenticated = ExchangeRestProxyBuilder .forInterface(GateioV4Authenticated.class, exchange.getExchangeSpecification()) .clientConfigCustomizer(clientConfig -> clientConfig.setJacksonObjectMapperFactory(new GateioJacksonObjectMapperFactory())) + .restProxyFactory(Config.getInstance().getRestProxyFactoryClass().getDeclaredConstructor().newInstance()) .build(); gateioV4ParamsDigest = From 45f41cc7c92fee737d30535505fccfa6c1ee006d Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Wed, 6 Sep 2023 21:01:13 +0200 Subject: [PATCH 119/159] [gateio-v4] Pom housekeeping --- xchange-gateio-v4/pom.xml | 53 +++++++++++++++++++++++++++++------ xchange-stream-gateio/pom.xml | 21 ++++++++++++++ 2 files changed, 66 insertions(+), 8 deletions(-) diff --git a/xchange-gateio-v4/pom.xml b/xchange-gateio-v4/pom.xml index 11bf6d07365..94184429d1d 100644 --- a/xchange-gateio-v4/pom.xml +++ b/xchange-gateio-v4/pom.xml @@ -14,15 +14,8 @@ XChange Gate.io V4 XChange implementation for the Gate.io Exchange - http://knowm.org/open-source/xchange/ - 2012 - - - Knowm Inc. - http://knowm.org/open-source/xchange/ - - + 3.2.1 5.3.1 3.2.0 @@ -41,6 +34,30 @@ test + + io.github.resilience4j + resilience4j-ratelimiter + ${version.resilience4j} + + + org.slf4j + slf4j-api + + + + + + io.github.resilience4j + resilience4j-retry + ${version.resilience4j} + + + org.slf4j + slf4j-api + + + + org.junit.jupiter junit-jupiter-engine @@ -88,6 +105,26 @@ + + maven-enforcer-plugin + ${version.maven-enforcer-plugin} + + + enforce + + enforce + + + + + + + + + + + + diff --git a/xchange-stream-gateio/pom.xml b/xchange-stream-gateio/pom.xml index 96d14334aa5..68db540cc84 100644 --- a/xchange-stream-gateio/pom.xml +++ b/xchange-stream-gateio/pom.xml @@ -12,6 +12,7 @@ 1.0.1 + 3.2.1 5.3.1 3.2.0 @@ -84,6 +85,26 @@ + + maven-enforcer-plugin + ${version.maven-enforcer-plugin} + + + enforce + + enforce + + + + + + + + + + + + From c894035a32c2d7c1abbab6c6b764deb5b89b94b6 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Wed, 6 Sep 2023 22:59:26 +0200 Subject: [PATCH 120/159] [gateio-v4] Pom housekeeping --- pom.xml | 7 +++++++ xchange-gateio-v4/pom.xml | 1 - xchange-stream-gateio/pom.xml | 1 - 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 2845f784729..7ac4941c0a3 100644 --- a/pom.xml +++ b/pom.xml @@ -327,6 +327,13 @@ test + + org.junit.jupiter + junit-jupiter-engine + ${version.junit} + test + + ch.qos.logback diff --git a/xchange-gateio-v4/pom.xml b/xchange-gateio-v4/pom.xml index 94184429d1d..276f8644331 100644 --- a/xchange-gateio-v4/pom.xml +++ b/xchange-gateio-v4/pom.xml @@ -61,7 +61,6 @@ org.junit.jupiter junit-jupiter-engine - ${version.junit} test diff --git a/xchange-stream-gateio/pom.xml b/xchange-stream-gateio/pom.xml index 68db540cc84..319e19740ab 100644 --- a/xchange-stream-gateio/pom.xml +++ b/xchange-stream-gateio/pom.xml @@ -35,7 +35,6 @@ org.junit.jupiter junit-jupiter-engine - ${version.junit} test From 9895f1b5e8b0a3e860288d8a579295033f1363b7 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Sun, 15 Oct 2023 13:16:10 +0200 Subject: [PATCH 121/159] [gateio-v4] Add exception mapping --- .../xchange/gateio/service/GateioMarketDataService.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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 2fb450e370d..70a785c6973 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 @@ -69,8 +69,12 @@ public OrderBook getOrderBook(CurrencyPair currencyPair, Object... args) throws @Override public OrderBook getOrderBook(Instrument instrument, Object... args) throws IOException { - GateioOrderBook gateioOrderBook = getGateioOrderBook(instrument); - return GateioAdapters.toOrderBook(gateioOrderBook, instrument); + try { + GateioOrderBook gateioOrderBook = getGateioOrderBook(instrument); + return GateioAdapters.toOrderBook(gateioOrderBook, instrument); + } catch (GateioException e) { + throw GateioErrorAdapter.adapt(e); + } } From 9400af402a13c5c4436723420978e22340047a35 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Thu, 26 Oct 2023 11:42:27 +0200 Subject: [PATCH 122/159] [gateio-v4] Extend api --- .../xchange/gateio/dto/marketdata/GateioCurrencyChain.java | 3 +++ .../gateio/service/GateioMarketDataServiceRawTest.java | 4 +++- .../resources/__files/api_v4_wallet_currency_chains.json | 6 ++++-- xchange-gateio-v4/src/test/resources/rest/wallet.http | 5 +++++ 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioCurrencyChain.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioCurrencyChain.java index a680ebd8587..aa0d4fdb4be 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioCurrencyChain.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioCurrencyChain.java @@ -28,6 +28,9 @@ public class GateioCurrencyChain { @JsonProperty("is_withdraw_disabled") Boolean withdrawDisabled; + @JsonProperty("contract_address") + String contractAddress; + public boolean isWithdrawEnabled() { return isEnabled() && (withdrawDisabled != null) && !withdrawDisabled; } diff --git a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioMarketDataServiceRawTest.java b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioMarketDataServiceRawTest.java index 3e52b4693a7..b2b00fc470f 100644 --- a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioMarketDataServiceRawTest.java +++ b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioMarketDataServiceRawTest.java @@ -90,6 +90,7 @@ public void getCurrencyChains_valid_result() throws IOException { .disabled(false) .depositDisabled(false) .withdrawDisabled(false) + .contractAddress("") .build(), GateioCurrencyChain.builder() .chain("HT") @@ -98,12 +99,13 @@ public void getCurrencyChains_valid_result() throws IOException { .disabled(true) .depositDisabled(true) .withdrawDisabled(true) + .contractAddress("0x66a79d23e58475d2738179ca52cd0b41d73f0bea") .build() ); List actual = gateioMarketDataServiceRaw.getCurrencyChains(Currency.BTC); - assertThat(actual).isEqualTo(expected); + assertThat(actual).usingRecursiveComparison().isEqualTo(expected); } diff --git a/xchange-gateio-v4/src/test/resources/__files/api_v4_wallet_currency_chains.json b/xchange-gateio-v4/src/test/resources/__files/api_v4_wallet_currency_chains.json index 576cc113064..522f3f762a5 100644 --- a/xchange-gateio-v4/src/test/resources/__files/api_v4_wallet_currency_chains.json +++ b/xchange-gateio-v4/src/test/resources/__files/api_v4_wallet_currency_chains.json @@ -5,7 +5,8 @@ "name_en": "Bitcoin BRC20\/Ordinals", "is_disabled": 0, "is_deposit_disabled": 0, - "is_withdraw_disabled": 0 + "is_withdraw_disabled": 0, + "contract_address": "" }, { "chain": "HT", @@ -13,6 +14,7 @@ "name_en": "Heco", "is_disabled": 1, "is_deposit_disabled": 1, - "is_withdraw_disabled": 1 + "is_withdraw_disabled": 1, + "contract_address": "0x66a79d23e58475d2738179ca52cd0b41d73f0bea" } ] \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/resources/rest/wallet.http b/xchange-gateio-v4/src/test/resources/rest/wallet.http index 39e06302337..f267392faa5 100644 --- a/xchange-gateio-v4/src/test/resources/rest/wallet.http +++ b/xchange-gateio-v4/src/test/resources/rest/wallet.http @@ -22,3 +22,8 @@ KEY: {{api_key}} SIGN: {{sign}} Timestamp: {{timestamp}} Content-Type: application/json + + +### List chains supported for specified currency +GET {{api_v4}}/wallet/currency_chains?currency=BTC +Content-Type: application/json From 2bc4db1d51ba0d60ce45147ea914218b33848255 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Thu, 26 Oct 2023 11:44:28 +0200 Subject: [PATCH 123/159] [gateio-v4] Add Currency deserializer --- .../knowm/xchange/gateio/dto/account/GateioOrder.java | 8 ++++++-- .../org/knowm/xchange/gateio/GateioExchangeWiremock.java | 1 + .../gateio/service/GateioTradeServiceRawTest.java | 9 +++++---- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioOrder.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioOrder.java index 9d1dd4154c5..e655a618f2f 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioOrder.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/dto/account/GateioOrder.java @@ -8,10 +8,12 @@ import lombok.Builder; import lombok.Data; import lombok.extern.jackson.Jacksonized; +import org.knowm.xchange.currency.Currency; import org.knowm.xchange.currency.CurrencyPair; import org.knowm.xchange.dto.Order.OrderType; import org.knowm.xchange.gateio.config.converter.CurrencyPairToStringConverter; import org.knowm.xchange.gateio.config.converter.OrderTypeToStringConverter; +import org.knowm.xchange.gateio.config.converter.StringToCurrencyConverter; import org.knowm.xchange.gateio.config.converter.StringToCurrencyPairConverter; import org.knowm.xchange.gateio.config.converter.StringToOrderTypeConverter; @@ -85,7 +87,8 @@ public class GateioOrder { BigDecimal fee; @JsonProperty("fee_currency") - String feeCurrency; + @JsonDeserialize(converter = StringToCurrencyConverter.class) + Currency feeCurrency; @JsonProperty("point_fee") BigDecimal pointFee; @@ -106,7 +109,8 @@ public class GateioOrder { BigDecimal rebatedFee; @JsonProperty("rebated_fee_currency") - String rebatedFeeCurrency; + @JsonDeserialize(converter = StringToCurrencyConverter.class) + Currency rebatedFeeCurrency; @JsonProperty("stp_id") Integer stpId; diff --git a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/GateioExchangeWiremock.java b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/GateioExchangeWiremock.java index bfbd35addd8..2ddf34b0d82 100644 --- a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/GateioExchangeWiremock.java +++ b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/GateioExchangeWiremock.java @@ -16,6 +16,7 @@ public abstract class GateioExchangeWiremock { protected static GateioExchange exchange; +// private static final boolean IS_RECORDING = true; private static final boolean IS_RECORDING = false; private static WireMockServer wireMockServer; diff --git a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioTradeServiceRawTest.java b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioTradeServiceRawTest.java index 18febb5a30c..19271898ae0 100644 --- a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioTradeServiceRawTest.java +++ b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioTradeServiceRawTest.java @@ -7,6 +7,7 @@ import java.time.Instant; import java.util.List; import org.junit.jupiter.api.Test; +import org.knowm.xchange.currency.Currency; import org.knowm.xchange.currency.CurrencyPair; import org.knowm.xchange.dto.Order.OrderStatus; import org.knowm.xchange.dto.Order.OrderType; @@ -36,14 +37,14 @@ class GateioTradeServiceRawTest extends GateioExchangeWiremock { .avgDealPrice(new BigDecimal("27038.3")) .fee(new BigDecimal("0.0000014")) .price(BigDecimal.ZERO) - .feeCurrency("BTC") + .feeCurrency(Currency.BTC) .pointFee(BigDecimal.ZERO) .gtFee(BigDecimal.ZERO) .gtMakerFee(BigDecimal.ZERO) .gtTakerFee(BigDecimal.ZERO) .rebatedFee(BigDecimal.ZERO) .gtDiscount(false) - .rebatedFeeCurrency("USDT") + .rebatedFeeCurrency(Currency.USDT) .finishAs("filled") .build(); @@ -112,14 +113,14 @@ void valid_market_sell_order() throws IOException { .avgDealPrice(new BigDecimal("27062.6")) .fee(new BigDecimal("0.03788764")) .price(BigDecimal.ZERO) - .feeCurrency("USDT") + .feeCurrency(Currency.USDT) .pointFee(BigDecimal.ZERO) .gtFee(BigDecimal.ZERO) .gtMakerFee(BigDecimal.ZERO) .gtTakerFee(BigDecimal.ZERO) .rebatedFee(BigDecimal.ZERO) .gtDiscount(false) - .rebatedFeeCurrency("BTC") + .rebatedFeeCurrency(Currency.BTC) .finishAs("filled") .build(); From 71c9f57b3dcb235f9f0aaa3a804e865eaa1bb178 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Thu, 2 Nov 2023 19:30:04 +0100 Subject: [PATCH 124/159] [gateio-v4] Fix amount mapping for sell orders --- .../knowm/xchange/gateio/GateioAdapters.java | 22 ++++++++++--- .../service/GateioTradeServiceTest.java | 21 +++++++++++- ...api_v4_spot_orders_buy-order-details.json} | 0 ...api_v4_spot_orders_sell-order-details.json | 33 +++++++++++++++++++ ...api_v4_spot_orders_buy-order-details.json} | 2 +- ...api_v4_spot_orders_sell-order-details.json | 15 +++++++++ .../src/test/resources/rest/spot.http | 13 ++++++++ 7 files changed, 99 insertions(+), 7 deletions(-) rename xchange-gateio-v4/src/test/resources/__files/{api_v4_spot_orders_order-details.json => api_v4_spot_orders_buy-order-details.json} (100%) create mode 100644 xchange-gateio-v4/src/test/resources/__files/api_v4_spot_orders_sell-order-details.json rename xchange-gateio-v4/src/test/resources/mappings/{api_v4_spot_orders_order-details.json => api_v4_spot_orders_buy-order-details.json} (84%) create mode 100644 xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_orders_sell-order-details.json diff --git a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java index 0147a34afee..8cfa3ae57fd 100644 --- a/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java +++ b/xchange-gateio-v4/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java @@ -1,5 +1,7 @@ package org.knowm.xchange.gateio; +import java.math.BigDecimal; +import java.math.MathContext; import java.util.Date; import java.util.List; import java.util.Locale; @@ -125,29 +127,39 @@ public GateioOrder toGateioOrder(LimitOrder limitOrder) { public Order toOrder(GateioOrder gateioOrder) { - Order.Builder order; + Order.Builder builder; Instrument instrument = gateioOrder.getCurrencyPair(); OrderType orderType = gateioOrder.getSide(); switch (gateioOrder.getType()) { case "market": - order = new MarketOrder.Builder(orderType, instrument); + builder = new MarketOrder.Builder(orderType, instrument); break; case "limit": - order = new LimitOrder.Builder(orderType, instrument) + builder = new LimitOrder.Builder(orderType, instrument) .limitPrice(gateioOrder.getPrice()); break; default: throw new IllegalArgumentException("Can't map " + gateioOrder.getType()); } - return order + if (orderType == OrderType.BID) { + builder.cumulativeAmount(gateioOrder.getFilledTotalQuote()); + } + else if (orderType == OrderType.ASK) { + BigDecimal filledAssetAmount = gateioOrder.getFilledTotalQuote().divide(gateioOrder.getAvgDealPrice(), MathContext.DECIMAL32); + builder.cumulativeAmount(filledAssetAmount); + } + else { + throw new IllegalArgumentException("Can't map " + orderType); + } + + return builder .id(gateioOrder.getId()) .originalAmount(gateioOrder.getAmount()) .userReference(gateioOrder.getClientOrderId()) .timestamp(Date.from(gateioOrder.getCreatedAt())) .orderStatus(toOrderStatus(gateioOrder.getStatus())) - .cumulativeAmount(gateioOrder.getFilledTotalQuote()) .averagePrice(gateioOrder.getAvgDealPrice()) .fee(gateioOrder.getFee()) .build(); diff --git a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioTradeServiceTest.java b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioTradeServiceTest.java index 22996089711..87af88e91f5 100644 --- a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioTradeServiceTest.java +++ b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioTradeServiceTest.java @@ -103,7 +103,7 @@ void valid_limit_buy_order() throws IOException { @Test - void order_details() throws IOException { + void buy_order_details() throws IOException { MarketOrder expected = new MarketOrder.Builder(OrderType.BID, CurrencyPair.BTC_USDT) .id("342251629898") .userReference("t-valid-market-buy-order") @@ -121,6 +121,25 @@ void order_details() throws IOException { } + @Test + void sell_order_details() throws IOException { + MarketOrder expected = new MarketOrder.Builder(OrderType.ASK, new CurrencyPair("VAI/USDT")) + .id("425539509181") + .userReference("t-valid-market-sell-order") + .timestamp(Date.from(Instant.parse("2023-10-28T18:40:02.006Z"))) + .originalAmount(new BigDecimal("105.58")) + .orderStatus(OrderStatus.FILLED) + .cumulativeAmount(new BigDecimal("105.58")) + .averagePrice(new BigDecimal("0.079888")) + .fee(new BigDecimal("0.01686915008")) + .build(); + + Collection orders = gateioTradeService.getOrder(new DefaultQueryOrderParamInstrument(new CurrencyPair("VAI/USDT"), "425539509181")); + assertThat(orders).hasSize(1); + assertThat(orders).first().usingRecursiveComparison().isEqualTo(expected); + } + + @Test void trade_history() throws IOException { UserTrades userTrades = gateioTradeService.getTradeHistory(GateioTradeHistoryParams.builder() diff --git a/xchange-gateio-v4/src/test/resources/__files/api_v4_spot_orders_order-details.json b/xchange-gateio-v4/src/test/resources/__files/api_v4_spot_orders_buy-order-details.json similarity index 100% rename from xchange-gateio-v4/src/test/resources/__files/api_v4_spot_orders_order-details.json rename to xchange-gateio-v4/src/test/resources/__files/api_v4_spot_orders_buy-order-details.json diff --git a/xchange-gateio-v4/src/test/resources/__files/api_v4_spot_orders_sell-order-details.json b/xchange-gateio-v4/src/test/resources/__files/api_v4_spot_orders_sell-order-details.json new file mode 100644 index 00000000000..d2f9df60cf1 --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/__files/api_v4_spot_orders_sell-order-details.json @@ -0,0 +1,33 @@ +{ + "id": "425539509181", + "text": "t-valid-market-sell-order", + "amend_text": "-", + "create_time": "1698518402", + "update_time": "1698518402", + "create_time_ms": 1698518402006, + "update_time_ms": 1698518402006, + "status": "closed", + "currency_pair": "VAI_USDT", + "type": "market", + "account": "spot", + "side": "sell", + "amount": "105.58", + "price": "0", + "biz_info": "-", + "time_in_force": "ioc", + "iceberg": "0", + "left": "0.00", + "fill_price": "8.43457504", + "filled_total": "8.43457504", + "avg_deal_price": "0.079888", + "fee": "0.01686915008", + "fee_currency": "USDT", + "point_fee": "0", + "gt_fee": "0", + "gt_maker_fee": "0", + "gt_taker_fee": "0", + "gt_discount": false, + "rebated_fee": "0", + "rebated_fee_currency": "VAI", + "finish_as": "filled" +} \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_orders_order-details.json b/xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_orders_buy-order-details.json similarity index 84% rename from xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_orders_order-details.json rename to xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_orders_buy-order-details.json index bc46b947e8f..62a00cc036d 100644 --- a/xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_orders_order-details.json +++ b/xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_orders_buy-order-details.json @@ -7,7 +7,7 @@ }, "response" : { "status" : 200, - "bodyFileName" : "api_v4_spot_orders_order-details.json" + "bodyFileName" : "api_v4_spot_orders_buy-order-details.json" }, "uuid" : "da0d205d-94ee-4760-bfd1-f4e5871d23e4", "persistent" : true, diff --git a/xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_orders_sell-order-details.json b/xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_orders_sell-order-details.json new file mode 100644 index 00000000000..53c9adb8878 --- /dev/null +++ b/xchange-gateio-v4/src/test/resources/mappings/api_v4_spot_orders_sell-order-details.json @@ -0,0 +1,15 @@ +{ + "id" : "b1d0529b-1196-4a9c-a74b-fe474197b70f", + "name" : "api_v4_spot_orders_425539509181", + "request" : { + "url" : "/api/v4/spot/orders/425539509181?currency_pair=VAI_USDT", + "method" : "GET" + }, + "response" : { + "status" : 200, + "bodyFileName" : "api_v4_spot_orders_sell-order-details.json" + }, + "uuid" : "b1d0529b-1196-4a9c-a74b-fe474197b70f", + "persistent" : true, + "insertionIndex" : 35 +} \ No newline at end of file diff --git a/xchange-gateio-v4/src/test/resources/rest/spot.http b/xchange-gateio-v4/src/test/resources/rest/spot.http index afce84383fd..f698d9c9e4e 100644 --- a/xchange-gateio-v4/src/test/resources/rest/spot.http +++ b/xchange-gateio-v4/src/test/resources/rest/spot.http @@ -23,3 +23,16 @@ SIGN: {{sign}} Timestamp: {{timestamp}} Content-Type: application/json + +### List orders +< {% + import {gen_sign} from 'sign.js' + gen_sign("GET", request); +%} + +GET {{api_v4}}/spot/orders?currency_pair=VAI_USDT&status=finished +KEY: {{api_key}} +SIGN: {{sign}} +Timestamp: {{timestamp}} +Content-Type: application/json + From a3512a6df3d62520f90690dd0e0f63fa6c5e1468 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Fri, 1 Dec 2023 13:59:21 +0100 Subject: [PATCH 125/159] [gateio-v4] Merge develop branch --- xchange-gateio-v4/pom.xml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/xchange-gateio-v4/pom.xml b/xchange-gateio-v4/pom.xml index 276f8644331..1cb2dd8bed9 100644 --- a/xchange-gateio-v4/pom.xml +++ b/xchange-gateio-v4/pom.xml @@ -28,12 +28,6 @@ ${version.fasterxml} - - com.github.tomakehurst - wiremock-jre8 - test - - io.github.resilience4j resilience4j-ratelimiter @@ -77,6 +71,12 @@ test + + org.wiremock + wiremock + test + + From 849c71da9578b8830a80ae29b57608682100c2cc Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Fri, 8 Dec 2023 01:14:46 +0100 Subject: [PATCH 126/159] [gateio-v4] Add error mapping --- .../main/java/org/knowm/xchange/gateio/GateioErrorAdapter.java | 2 ++ 1 file changed, 2 insertions(+) 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 169b4a2e99d..11324b523f1 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 @@ -11,6 +11,7 @@ public class GateioErrorAdapter { public final String INVALID_KEY = "INVALID_KEY"; public final String FORBIDDEN = "FORBIDDEN"; public final String INVALID_CURRENCY = "INVALID_CURRENCY"; + public final String INVALID_CURRENCY_PAIR = "INVALID_CURRENCY_PAIR"; public final String BALANCE_NOT_ENOUGH = "BALANCE_NOT_ENOUGH"; public final String TOO_FAST = "TOO_FAST"; public final String TOO_MANY_REQUESTS = "TOO_MANY_REQUESTS"; @@ -27,6 +28,7 @@ public ExchangeException adapt(GateioException e) { return new ExchangeSecurityException(e.getMessage(), e); case INVALID_CURRENCY: + case INVALID_CURRENCY_PAIR: return new InstrumentNotValidException(e.getMessage(), e); case BALANCE_NOT_ENOUGH: From 33f9174f9eabddc52d9c238d12353d58a6ff80cd Mon Sep 17 00:00:00 2001 From: Roman Shterenzon Date: Mon, 11 Dec 2023 11:50:02 +0200 Subject: [PATCH 127/159] Change MathContext to 64, as 32 is not enough for some coins --- .../main/java/org/knowm/xchange/utils/BigDecimalUtils.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xchange-core/src/main/java/org/knowm/xchange/utils/BigDecimalUtils.java b/xchange-core/src/main/java/org/knowm/xchange/utils/BigDecimalUtils.java index 8f90c2e25c8..8248e049dda 100644 --- a/xchange-core/src/main/java/org/knowm/xchange/utils/BigDecimalUtils.java +++ b/xchange-core/src/main/java/org/knowm/xchange/utils/BigDecimalUtils.java @@ -14,7 +14,7 @@ public static BigDecimal roundToStepSize(BigDecimal value, BigDecimal stepSize) public static BigDecimal roundToStepSize( BigDecimal value, BigDecimal stepSize, RoundingMode roundingMode) { - BigDecimal divided = value.divide(stepSize, MathContext.DECIMAL32).setScale(0, roundingMode); - return divided.multiply(stepSize, MathContext.DECIMAL32).stripTrailingZeros(); + BigDecimal divided = value.divide(stepSize, MathContext.DECIMAL64).setScale(0, roundingMode); + return divided.multiply(stepSize, MathContext.DECIMAL64).stripTrailingZeros(); } } From 8df3be5c4cae665f2b2f09efd1b1780db1613f23 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 25 Dec 2023 12:29:48 +0000 Subject: [PATCH 128/159] Bump org.apache.maven.plugins:maven-compiler-plugin Bumps [org.apache.maven.plugins:maven-compiler-plugin](https://github.com/apache/maven-compiler-plugin) from 3.10.1 to 3.12.1. - [Release notes](https://github.com/apache/maven-compiler-plugin/releases) - [Commits](https://github.com/apache/maven-compiler-plugin/compare/maven-compiler-plugin-3.10.1...maven-compiler-plugin-3.12.1) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-compiler-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 0250003299b..4dbf5848730 100644 --- a/pom.xml +++ b/pom.xml @@ -489,7 +489,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.10.1 + 3.12.1 ${version.java} ${version.java} From a25b5813585325bc40fbe60320ac9540b1d24518 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 10 Jan 2024 12:19:02 +0000 Subject: [PATCH 129/159] Bump org.apache.maven.plugins:maven-failsafe-plugin from 3.0.0 to 3.2.5 Bumps [org.apache.maven.plugins:maven-failsafe-plugin](https://github.com/apache/maven-surefire) from 3.0.0 to 3.2.5. - [Release notes](https://github.com/apache/maven-surefire/releases) - [Commits](https://github.com/apache/maven-surefire/compare/surefire-3.0.0...surefire-3.2.5) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-failsafe-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 0250003299b..7410a41234c 100644 --- a/pom.xml +++ b/pom.xml @@ -547,7 +547,7 @@ org.apache.maven.plugins maven-failsafe-plugin - 3.0.0 + 3.2.5 From 31d141d4958c385d62d36eda80461bf0ec1ab606 Mon Sep 17 00:00:00 2001 From: Juan Date: Wed, 17 Jan 2024 14:30:55 +0100 Subject: [PATCH 130/159] Add support for bitstamp instant market orders --- .../bitstamp/BitstampAuthenticatedV2.java | 31 ++++++++++++++- .../dto/trade/BitstampOrderFlags.java | 18 +++++++++ .../service/BitstampTradeService.java | 35 ++++++++++++++++- .../service/BitstampTradeServiceRaw.java | 39 +++++++++++++++++++ .../dto/trade/PlaceInstantOrderJSONTest.java | 29 ++++++++++++++ .../trade/example-place-instant-order.json | 7 ++++ 6 files changed, 157 insertions(+), 2 deletions(-) create mode 100644 xchange-bitstamp/src/main/java/org/knowm/xchange/bitstamp/dto/trade/BitstampOrderFlags.java create mode 100644 xchange-bitstamp/src/test/java/org/knowm/xchange/bitstamp/dto/trade/PlaceInstantOrderJSONTest.java create mode 100644 xchange-bitstamp/src/test/resources/org/knowm/xchange/bitstamp/dto/trade/example-place-instant-order.json 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 3b016d34310..b510b685f86 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 @@ -745,6 +745,35 @@ DepositTransaction[] getUnconfirmedBTCDeposits( @HeaderParam("X-Auth-Version") String version) throws BitstampException, IOException; + @POST + @Path("{side}/instant/{pair}/") + @Consumes(MediaType.APPLICATION_FORM_URLENCODED) + BitstampOrder placeInstantMarketOrder( + @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, + @PathParam("side") Side side, + @PathParam("pair") BitstampV2.Pair pair, + @FormParam("amount") BigDecimal amount) + throws BitstampException, IOException; + + @POST + @Path("{side}/instant/{pair}/") + @Consumes(MediaType.APPLICATION_FORM_URLENCODED) + BitstampOrder placeInstantSellMarketOrder( + @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, + @PathParam("side") Side side, + @PathParam("pair") BitstampV2.Pair pair, + @FormParam("amount") BigDecimal amount, + @FormParam("amount_in_counter") boolean amountInCounter) + throws BitstampException, IOException; + enum Side { buy, sell @@ -1176,4 +1205,4 @@ enum BankCurrency { ZMW, ZWL } -} +} \ No newline at end of file diff --git a/xchange-bitstamp/src/main/java/org/knowm/xchange/bitstamp/dto/trade/BitstampOrderFlags.java b/xchange-bitstamp/src/main/java/org/knowm/xchange/bitstamp/dto/trade/BitstampOrderFlags.java new file mode 100644 index 00000000000..2df4bedf17c --- /dev/null +++ b/xchange-bitstamp/src/main/java/org/knowm/xchange/bitstamp/dto/trade/BitstampOrderFlags.java @@ -0,0 +1,18 @@ +package org.knowm.xchange.bitstamp.dto.trade; + +import org.knowm.xchange.dto.Order.IOrderFlags; + +public enum BitstampOrderFlags implements IOrderFlags { + /** + * This type of market order allows setting the amount in either counter or base currency, + * (the opposite of the usual market order) + * For buys, the amount is in the counter currency. + * For sells, the amount is in the base currency. + */ + INSTANT_MARKET, + + /** + * Set amount in counter currency (only supported for sell orders). + */ + INSTANT_AMOUNT_IN_COUNTER +} diff --git a/xchange-bitstamp/src/main/java/org/knowm/xchange/bitstamp/service/BitstampTradeService.java b/xchange-bitstamp/src/main/java/org/knowm/xchange/bitstamp/service/BitstampTradeService.java index b57e622afa0..ec6203eb4e0 100644 --- a/xchange-bitstamp/src/main/java/org/knowm/xchange/bitstamp/service/BitstampTradeService.java +++ b/xchange-bitstamp/src/main/java/org/knowm/xchange/bitstamp/service/BitstampTradeService.java @@ -10,10 +10,12 @@ import org.knowm.xchange.Exchange; import org.knowm.xchange.bitstamp.BitstampAdapters; import org.knowm.xchange.bitstamp.BitstampAuthenticatedV2; +import org.knowm.xchange.bitstamp.BitstampAuthenticatedV2.Side; import org.knowm.xchange.bitstamp.BitstampUtils; import org.knowm.xchange.bitstamp.BitstampV2; import org.knowm.xchange.bitstamp.dto.BitstampException; import org.knowm.xchange.bitstamp.dto.trade.BitstampOrder; +import org.knowm.xchange.bitstamp.dto.trade.BitstampOrderFlags; import org.knowm.xchange.bitstamp.dto.trade.BitstampUserTransaction; import org.knowm.xchange.currency.CurrencyPair; import org.knowm.xchange.dto.Order; @@ -80,17 +82,48 @@ public OpenOrders getOpenOrders(OpenOrdersParams params) throws ExchangeExceptio return new OpenOrders(limitOrders); } - @Override + private String placeInstantMarketOrder(MarketOrder order) throws IOException, BitstampException { + BitstampAuthenticatedV2.Side side = + order.getType().equals(BID) + ? BitstampAuthenticatedV2.Side.buy + : BitstampAuthenticatedV2.Side.sell; + + BitstampOrder bitstampOrder; + if (side == Side.sell) { + boolean amountInCounter = order.hasFlag(BitstampOrderFlags.INSTANT_AMOUNT_IN_COUNTER); + bitstampOrder = + placeBitstampInstantSellMarketOrder(order.getCurrencyPair(), side, order.getOriginalAmount(), amountInCounter); + } else { + bitstampOrder = + placeBitstampInstantMarketOrder(order.getCurrencyPair(), side, order.getOriginalAmount()); + + } + + if (bitstampOrder.getErrorMessage() != null) { + throw new ExchangeException(bitstampOrder.getErrorMessage()); + } + + return Long.toString(bitstampOrder.getId()); + } + + @Override public String placeMarketOrder(MarketOrder order) throws IOException, BitstampException { BitstampAuthenticatedV2.Side side = order.getType().equals(BID) ? BitstampAuthenticatedV2.Side.buy : BitstampAuthenticatedV2.Side.sell; + + if (order.hasFlag(BitstampOrderFlags.INSTANT_MARKET)) { + return placeInstantMarketOrder(order); + } + BitstampOrder bitstampOrder = placeBitstampMarketOrder(order.getCurrencyPair(), side, order.getOriginalAmount()); + if (bitstampOrder.getErrorMessage() != null) { throw new ExchangeException(bitstampOrder.getErrorMessage()); } + return Long.toString(bitstampOrder.getId()); } diff --git a/xchange-bitstamp/src/main/java/org/knowm/xchange/bitstamp/service/BitstampTradeServiceRaw.java b/xchange-bitstamp/src/main/java/org/knowm/xchange/bitstamp/service/BitstampTradeServiceRaw.java index d0e2fe85dcf..78636bb741a 100644 --- a/xchange-bitstamp/src/main/java/org/knowm/xchange/bitstamp/service/BitstampTradeServiceRaw.java +++ b/xchange-bitstamp/src/main/java/org/knowm/xchange/bitstamp/service/BitstampTradeServiceRaw.java @@ -112,6 +112,45 @@ public BitstampOrder placeBitstampOrder( } } + public BitstampOrder placeBitstampInstantSellMarketOrder( + CurrencyPair pair, BitstampAuthenticatedV2.Side side, BigDecimal amount, boolean amountInCounter) + throws IOException { + + try { + return bitstampAuthenticatedV2.placeInstantSellMarketOrder( + apiKeyForV2Requests, + signatureCreatorV2, + uuidNonceFactory, + timestampFactory, + API_VERSION, + side, + new BitstampV2.Pair(pair), + amount, + amountInCounter); + } catch (BitstampException e) { + throw handleError(e); + } + } + + public BitstampOrder placeBitstampInstantMarketOrder( + CurrencyPair pair, BitstampAuthenticatedV2.Side side, BigDecimal amount) + throws IOException { + + try { + return bitstampAuthenticatedV2.placeInstantMarketOrder( + apiKeyForV2Requests, + signatureCreatorV2, + uuidNonceFactory, + timestampFactory, + API_VERSION, + side, + new BitstampV2.Pair(pair), + amount); + } catch (BitstampException e) { + throw handleError(e); + } + } + public boolean cancelBitstampOrder(long orderId) throws IOException { try { diff --git a/xchange-bitstamp/src/test/java/org/knowm/xchange/bitstamp/dto/trade/PlaceInstantOrderJSONTest.java b/xchange-bitstamp/src/test/java/org/knowm/xchange/bitstamp/dto/trade/PlaceInstantOrderJSONTest.java new file mode 100644 index 00000000000..e3d23772ff8 --- /dev/null +++ b/xchange-bitstamp/src/test/java/org/knowm/xchange/bitstamp/dto/trade/PlaceInstantOrderJSONTest.java @@ -0,0 +1,29 @@ +package org.knowm.xchange.bitstamp.dto.trade; + +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 org.junit.Test; + +public class PlaceInstantOrderJSONTest { + @Test + public void testUnmarshal() throws IOException { + + // Read in the JSON from the example resources + InputStream is = + PlaceLimitOrderJSONTest.class.getResourceAsStream( + "/org/knowm/xchange/bitstamp/dto/trade/example-place-instant-order.json"); + + // Use Jackson to parse it + ObjectMapper mapper = new ObjectMapper(); + BitstampOrder newOrder = mapper.readValue(is, BitstampOrder.class); + + assertThat(newOrder.getId()).isEqualTo(1273070); + assertThat(newOrder.getAmount()).isEqualTo(BigDecimal.ONE); + assertThat(newOrder.getPrice()).isEqualTo(new BigDecimal("1.25")); + assertThat(newOrder.getType()).isEqualTo(0); + } +} diff --git a/xchange-bitstamp/src/test/resources/org/knowm/xchange/bitstamp/dto/trade/example-place-instant-order.json b/xchange-bitstamp/src/test/resources/org/knowm/xchange/bitstamp/dto/trade/example-place-instant-order.json new file mode 100644 index 00000000000..3f59b1a327a --- /dev/null +++ b/xchange-bitstamp/src/test/resources/org/knowm/xchange/bitstamp/dto/trade/example-place-instant-order.json @@ -0,0 +1,7 @@ +{ + "id": "1273070", + "datetime": "2022-01-31 14:43:15.796000", + "type": "0", + "price": "1.25", + "amount": "1" +} \ No newline at end of file From 8201b1d326ff0335664dc29344e70f235fbd2367 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Fri, 26 Jan 2024 11:38:27 +0100 Subject: [PATCH 131/159] [gateio-v4] Disable test with example code --- .../org/knowm/xchange/gateio/service/GateioBaseServiceTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioBaseServiceTest.java b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioBaseServiceTest.java index 6e29d262443..e7b7fbb410d 100644 --- a/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioBaseServiceTest.java +++ b/xchange-gateio-v4/src/test/java/org/knowm/xchange/gateio/service/GateioBaseServiceTest.java @@ -3,6 +3,7 @@ import static org.assertj.core.api.Assertions.assertThat; import java.lang.reflect.Proxy; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.knowm.xchange.gateio.GateioExchangeWiremock; import org.knowm.xchange.gateio.config.Config; @@ -20,6 +21,7 @@ class GateioBaseServiceTest extends GateioExchangeWiremock { } + @Disabled @Test void correct_proxy_factory() { GateioBaseService service = ((GateioBaseService) exchange.getAccountService()); From 2a3fe2612904f1b3da2636ecb3ece60772164e46 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 5 Feb 2024 12:26:03 +0000 Subject: [PATCH 132/159] Bump org.junit.vintage:junit-vintage-engine from 5.9.3 to 5.10.2 Bumps [org.junit.vintage:junit-vintage-engine](https://github.com/junit-team/junit5) from 5.9.3 to 5.10.2. - [Release notes](https://github.com/junit-team/junit5/releases) - [Commits](https://github.com/junit-team/junit5/compare/r5.9.3...r5.10.2) --- updated-dependencies: - dependency-name: org.junit.vintage:junit-vintage-engine dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 0250003299b..43aca4c55ee 100644 --- a/pom.xml +++ b/pom.xml @@ -36,7 +36,7 @@ 2.14.3 3.0 1.7.0 - 5.9.3 + 5.10.2 1.18.26 3.8.6 1.4.12 From db79725defc3a8d7e823a94df8267675450d93a3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 6 Feb 2024 12:32:57 +0000 Subject: [PATCH 133/159] Bump org.slf4j:slf4j-api from 2.0.6 to 2.0.12 Bumps org.slf4j:slf4j-api from 2.0.6 to 2.0.12. --- updated-dependencies: - dependency-name: org.slf4j:slf4j-api dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 0250003299b..a51115e466f 100644 --- a/pom.xml +++ b/pom.xml @@ -41,7 +41,7 @@ 3.8.6 1.4.12 0.10.2 - 2.0.6 + 2.0.12 5.0.0 4.4.0 3.2.0 From ebafeede10484507bc7013c8179b7eca7621b5ef Mon Sep 17 00:00:00 2001 From: martinkyov Date: Mon, 12 Feb 2024 09:16:13 +0100 Subject: [PATCH 134/159] bugfix/ETD-1130 - added LedgerType SALE ( tx - spend and received. https://support.kraken.com/hc/en-us/articles/360001169383-How-to-interpret-Ledger-history-fields "sale" = this shows only as a filter option when viewing your Ledger history while signed in to your account, it is not shown in history exports. "Sale" is a filter that brings up all "Spend" and "Receive" entries from orders placed via the new Kraken app or Buy Crypto button. --- .../java/org/knowm/xchange/kraken/dto/account/LedgerType.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/xchange-kraken/src/main/java/org/knowm/xchange/kraken/dto/account/LedgerType.java b/xchange-kraken/src/main/java/org/knowm/xchange/kraken/dto/account/LedgerType.java index 6f72ec6d4b9..6d112ef33ca 100644 --- a/xchange-kraken/src/main/java/org/knowm/xchange/kraken/dto/account/LedgerType.java +++ b/xchange-kraken/src/main/java/org/knowm/xchange/kraken/dto/account/LedgerType.java @@ -23,7 +23,8 @@ public enum LedgerType { STAKING, ROLLOVER, TRANSFER, - ADJUSTMENT; + ADJUSTMENT, + SALE; private static final Map fromString = new HashMap<>(); From ce692ca1a4be9594ed13bb4dfb78945bacdaeb58 Mon Sep 17 00:00:00 2001 From: martinkyov Date: Tue, 13 Feb 2024 13:47:26 +0100 Subject: [PATCH 135/159] bugfix/ETD-1130 - added LedgerType SALE ( tx - spend and received. https://support.kraken.com/hc/en-us/articles/360001169383-How-to-interpret-Ledger-history-fields spend" = shown for transactions made via the Buy Crypto button or new Kraken app, this indicates the amount of the asset being debited from the account "receive" = shown for transactions made via the Buy Crypto button or new Kraken app, this indicates the amount of the asset being credited to the account. --- .../java/org/knowm/xchange/kraken/dto/account/LedgerType.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/xchange-kraken/src/main/java/org/knowm/xchange/kraken/dto/account/LedgerType.java b/xchange-kraken/src/main/java/org/knowm/xchange/kraken/dto/account/LedgerType.java index 6d112ef33ca..bef033d0493 100644 --- a/xchange-kraken/src/main/java/org/knowm/xchange/kraken/dto/account/LedgerType.java +++ b/xchange-kraken/src/main/java/org/knowm/xchange/kraken/dto/account/LedgerType.java @@ -24,7 +24,9 @@ public enum LedgerType { ROLLOVER, TRANSFER, ADJUSTMENT, - SALE; + SALE, + SPEND, + RECEIVE; private static final Map fromString = new HashMap<>(); From bb28f18f2de8c9b1ee35acddce90108ea7cd2d72 Mon Sep 17 00:00:00 2001 From: Martin Stachon Date: Wed, 6 Mar 2024 12:43:04 +0100 Subject: [PATCH 136/159] * Remove DASH currency * update JSON config * add new API call for generic crypto withdrawal/deposit * add new API call for uncorimed deposits * introduce enum for AmountType and TransferHistoryOrder * add txid field for TransferHistoryOrder --- .../coinmate/CoinmateAuthenticated.java | 78 +++-- .../coinmate/dto/account/AmountType.java | 6 + .../dto/account/TransferHistoryOrder.java | 5 + .../dto/account/UnconfirmedDeposits.java | 41 +++ .../account/UnconfirmedDepositsResponse.java | 16 + .../trade/CoinmateTransferHistoryEntry.java | 9 +- .../service/CoinmateAccountService.java | 33 +- .../service/CoinmateAccountServiceRaw.java | 96 ++++-- .../src/main/resources/coinmate.json | 289 +++++++++--------- 9 files changed, 365 insertions(+), 208 deletions(-) create mode 100644 xchange-coinmate/src/main/java/org/knowm/xchange/coinmate/dto/account/AmountType.java create mode 100644 xchange-coinmate/src/main/java/org/knowm/xchange/coinmate/dto/account/TransferHistoryOrder.java create mode 100644 xchange-coinmate/src/main/java/org/knowm/xchange/coinmate/dto/account/UnconfirmedDeposits.java create mode 100644 xchange-coinmate/src/main/java/org/knowm/xchange/coinmate/dto/account/UnconfirmedDepositsResponse.java diff --git a/xchange-coinmate/src/main/java/org/knowm/xchange/coinmate/CoinmateAuthenticated.java b/xchange-coinmate/src/main/java/org/knowm/xchange/coinmate/CoinmateAuthenticated.java index e494e772c57..7c0342114ce 100644 --- a/xchange-coinmate/src/main/java/org/knowm/xchange/coinmate/CoinmateAuthenticated.java +++ b/xchange-coinmate/src/main/java/org/knowm/xchange/coinmate/CoinmateAuthenticated.java @@ -31,11 +31,27 @@ import jakarta.ws.rs.core.MediaType; import java.io.IOException; import java.math.BigDecimal; +import org.knowm.xchange.coinmate.dto.account.AmountType; import org.knowm.xchange.coinmate.dto.account.CoinmateBalance; import org.knowm.xchange.coinmate.dto.account.CoinmateDepositAddresses; import org.knowm.xchange.coinmate.dto.account.CoinmateTradingFeesResponse; import org.knowm.xchange.coinmate.dto.account.FeePriority; -import org.knowm.xchange.coinmate.dto.trade.*; +import org.knowm.xchange.coinmate.dto.account.TransferHistoryOrder; +import org.knowm.xchange.coinmate.dto.account.UnconfirmedDepositsResponse; +import org.knowm.xchange.coinmate.dto.trade.CoinmateBuyFixRateResponse; +import org.knowm.xchange.coinmate.dto.trade.CoinmateCancelOrderResponse; +import org.knowm.xchange.coinmate.dto.trade.CoinmateCancelOrderWithInfoResponse; +import org.knowm.xchange.coinmate.dto.trade.CoinmateOpenOrders; +import org.knowm.xchange.coinmate.dto.trade.CoinmateOrder; +import org.knowm.xchange.coinmate.dto.trade.CoinmateOrderHistory; +import org.knowm.xchange.coinmate.dto.trade.CoinmateOrders; +import org.knowm.xchange.coinmate.dto.trade.CoinmateReplaceResponse; +import org.knowm.xchange.coinmate.dto.trade.CoinmateSellFixRateResponse; +import org.knowm.xchange.coinmate.dto.trade.CoinmateTradeHistory; +import org.knowm.xchange.coinmate.dto.trade.CoinmateTradeResponse; +import org.knowm.xchange.coinmate.dto.trade.CoinmateTransactionHistory; +import org.knowm.xchange.coinmate.dto.trade.CoinmateTransferDetail; +import org.knowm.xchange.coinmate.dto.trade.CoinmateTransferHistory; import si.mazi.rescu.ParamsDigest; import si.mazi.rescu.SynchronizedValueFactory; @@ -266,6 +282,42 @@ CoinmateTradeResponse sellQuickFix( // withdrawal and deposits // bitcoin + + @POST + @Path("withdrawVirtualCurrency") + CoinmateTradeResponse withdrawVirtualCurrency( + @FormParam("publicKey") String publicKey, + @FormParam("clientId") String clientId, + @FormParam("signature") ParamsDigest signer, + @FormParam("nonce") SynchronizedValueFactory nonce, + @FormParam("currencyName") String currencyName, + @FormParam("amount") BigDecimal amount, + @FormParam("destinationTag") String destinationTag, + @FormParam("amountType") AmountType amountType, + @FormParam("address") String address, + @FormParam("feePriority") FeePriority feePriority) + throws IOException; + + @POST + @Path("virtualCurrencyDepositAddresses") + CoinmateDepositAddresses virtualCurrencyDepositAddresses( + @FormParam("publicKey") String publicKey, + @FormParam("clientId") String clientId, + @FormParam("signature") ParamsDigest signer, + @FormParam("nonce") SynchronizedValueFactory nonce, + @FormParam("currencyName") String currencyName) + throws IOException; + + @POST + @Path("unconfirmedVirtualCurrencyDeposits") + UnconfirmedDepositsResponse unconfirmedVirtualCurrencyDeposits( + @FormParam("publicKey") String publicKey, + @FormParam("clientId") String clientId, + @FormParam("signature") ParamsDigest signer, + @FormParam("nonce") SynchronizedValueFactory nonce, + @FormParam("currencyName") String currencyName) + throws IOException; + @POST @Path("bitcoinWithdrawal") CoinmateTradeResponse bitcoinWithdrawal( @@ -352,28 +404,6 @@ CoinmateDepositAddresses rippleDepositAddresses( @FormParam("nonce") SynchronizedValueFactory nonce) throws IOException; - // dash - - @POST - @Path("dashWithdrawal") - CoinmateTradeResponse dashWithdrawal( - @FormParam("publicKey") String publicKey, - @FormParam("clientId") String clientId, - @FormParam("signature") ParamsDigest signer, - @FormParam("nonce") SynchronizedValueFactory nonce, - @FormParam("amount") BigDecimal amount, - @FormParam("address") String address) - throws IOException; - - @POST - @Path("dashDepositAddresses") - CoinmateDepositAddresses dashDepositAddresses( - @FormParam("publicKey") String publicKey, - @FormParam("clientId") String clientId, - @FormParam("signature") ParamsDigest signer, - @FormParam("nonce") SynchronizedValueFactory nonce) - throws IOException; - @POST @Path("adaWithdrawal") CoinmateTradeResponse adaWithdrawal( @@ -452,7 +482,7 @@ CoinmateTransferHistory getTransferHistory( @FormParam("nonce") SynchronizedValueFactory nonce, @FormParam("limit") Integer limit, @FormParam("lastId") Integer lastId, - @FormParam("sort") String sort, + @FormParam("sort") TransferHistoryOrder sort, @FormParam("timestampFrom") Long timestampFrom, @FormParam("timestampTo") Long timestampTo, @FormParam("currency") String currency) diff --git a/xchange-coinmate/src/main/java/org/knowm/xchange/coinmate/dto/account/AmountType.java b/xchange-coinmate/src/main/java/org/knowm/xchange/coinmate/dto/account/AmountType.java new file mode 100644 index 00000000000..e5d8dbd2fba --- /dev/null +++ b/xchange-coinmate/src/main/java/org/knowm/xchange/coinmate/dto/account/AmountType.java @@ -0,0 +1,6 @@ +package org.knowm.xchange.coinmate.dto.account; + +public enum AmountType { + NET, + GROSS +} diff --git a/xchange-coinmate/src/main/java/org/knowm/xchange/coinmate/dto/account/TransferHistoryOrder.java b/xchange-coinmate/src/main/java/org/knowm/xchange/coinmate/dto/account/TransferHistoryOrder.java new file mode 100644 index 00000000000..914b4fc40d1 --- /dev/null +++ b/xchange-coinmate/src/main/java/org/knowm/xchange/coinmate/dto/account/TransferHistoryOrder.java @@ -0,0 +1,5 @@ +package org.knowm.xchange.coinmate.dto.account; + +public enum TransferHistoryOrder { + ASC, DESC +} diff --git a/xchange-coinmate/src/main/java/org/knowm/xchange/coinmate/dto/account/UnconfirmedDeposits.java b/xchange-coinmate/src/main/java/org/knowm/xchange/coinmate/dto/account/UnconfirmedDeposits.java new file mode 100644 index 00000000000..b9ef8a98aff --- /dev/null +++ b/xchange-coinmate/src/main/java/org/knowm/xchange/coinmate/dto/account/UnconfirmedDeposits.java @@ -0,0 +1,41 @@ +package org.knowm.xchange.coinmate.dto.account; + +import com.fasterxml.jackson.annotation.JsonProperty; +import java.math.BigDecimal; + +public class UnconfirmedDeposits { + private final Long id; + + private final BigDecimal amount; + + private final String address; + + private final Long confirmations; + + public UnconfirmedDeposits( + @JsonProperty Long id, + @JsonProperty BigDecimal amount, + @JsonProperty String address, + @JsonProperty Long confirmations) { + this.id = id; + this.amount = amount; + this.address = address; + this.confirmations = confirmations; + } + + public Long getId() { + return id; + } + + public BigDecimal getAmount() { + return amount; + } + + public String getAddress() { + return address; + } + + public Long getConfirmations() { + return confirmations; + } +} diff --git a/xchange-coinmate/src/main/java/org/knowm/xchange/coinmate/dto/account/UnconfirmedDepositsResponse.java b/xchange-coinmate/src/main/java/org/knowm/xchange/coinmate/dto/account/UnconfirmedDepositsResponse.java new file mode 100644 index 00000000000..4f16605c40a --- /dev/null +++ b/xchange-coinmate/src/main/java/org/knowm/xchange/coinmate/dto/account/UnconfirmedDepositsResponse.java @@ -0,0 +1,16 @@ +package org.knowm.xchange.coinmate.dto.account; + +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.ArrayList; +import org.knowm.xchange.coinmate.dto.CoinmateBaseResponse; + +public class UnconfirmedDepositsResponse + extends CoinmateBaseResponse> { + public UnconfirmedDepositsResponse( + @JsonProperty("error") boolean error, + @JsonProperty("errorMessage") String errorMessage, + @JsonProperty("data") ArrayList data) { + + super(error, errorMessage, data); + } +} diff --git a/xchange-coinmate/src/main/java/org/knowm/xchange/coinmate/dto/trade/CoinmateTransferHistoryEntry.java b/xchange-coinmate/src/main/java/org/knowm/xchange/coinmate/dto/trade/CoinmateTransferHistoryEntry.java index 201c7bb7adb..f10d6b49655 100644 --- a/xchange-coinmate/src/main/java/org/knowm/xchange/coinmate/dto/trade/CoinmateTransferHistoryEntry.java +++ b/xchange-coinmate/src/main/java/org/knowm/xchange/coinmate/dto/trade/CoinmateTransferHistoryEntry.java @@ -14,6 +14,7 @@ public class CoinmateTransferHistoryEntry { private final String walletType; private final String destination; private final String destinationTag; + private final String txid; public CoinmateTransferHistoryEntry( @JsonProperty("transactionId") long id, @@ -25,8 +26,9 @@ public CoinmateTransferHistoryEntry( @JsonProperty("amountCurrency") String amountCurrency, @JsonProperty("walletType") String walletType, @JsonProperty("destination") String destination, - @JsonProperty("destinationTag") String destinationTag) { - + @JsonProperty("destinationTag") String destinationTag, + @JsonProperty("txid") String txid + ) { this.fee = fee; this.transferType = transferType; this.timestamp = timestamp; @@ -37,6 +39,7 @@ public CoinmateTransferHistoryEntry( this.walletType = walletType; this.destination = destination; this.destinationTag = destinationTag; + this.txid = txid; } public long getId() { @@ -78,4 +81,6 @@ public String getDestination() { public String getDestinationTag() { return destinationTag; } + + public String getTxid() { return txid; } } diff --git a/xchange-coinmate/src/main/java/org/knowm/xchange/coinmate/service/CoinmateAccountService.java b/xchange-coinmate/src/main/java/org/knowm/xchange/coinmate/service/CoinmateAccountService.java index 78e37dc1dee..e268cdb5a7d 100644 --- a/xchange-coinmate/src/main/java/org/knowm/xchange/coinmate/service/CoinmateAccountService.java +++ b/xchange-coinmate/src/main/java/org/knowm/xchange/coinmate/service/CoinmateAccountService.java @@ -34,14 +34,17 @@ import org.knowm.xchange.Exchange; import org.knowm.xchange.coinmate.CoinmateAdapters; import org.knowm.xchange.coinmate.CoinmateUtils; +import org.knowm.xchange.coinmate.dto.account.AmountType; import org.knowm.xchange.coinmate.dto.account.CoinmateDepositAddresses; import org.knowm.xchange.coinmate.dto.account.CoinmateTradingFeesResponseData; +import org.knowm.xchange.coinmate.dto.account.FeePriority; import org.knowm.xchange.coinmate.dto.trade.CoinmateTradeResponse; import org.knowm.xchange.coinmate.dto.trade.CoinmateTransactionHistory; import org.knowm.xchange.coinmate.dto.trade.CoinmateTransferDetail; import org.knowm.xchange.coinmate.dto.trade.CoinmateTransferHistory; import org.knowm.xchange.currency.Currency; import org.knowm.xchange.dto.account.AccountInfo; +import org.knowm.xchange.dto.account.AddressWithTag; import org.knowm.xchange.dto.account.Fee; import org.knowm.xchange.dto.account.FundingRecord; import org.knowm.xchange.instrument.Instrument; @@ -97,12 +100,13 @@ public String withdrawFunds(Currency currency, BigDecimal amount, String address response = coinmateEthereumWithdrawal(amount, address); } else if (currency.equals(Currency.XRP)) { response = coinmateRippleWithdrawal(amount, address); - } else if (currency.equals(Currency.DASH)) { - response = coinmateDashWithdrawal(amount, address); } else if (currency.equals(Currency.ADA)) { response = coinmateCardanoWithdrawal(amount, address); } else if (currency.equals(Currency.SOL)) { response = coinmateSolanaWithdrawal(amount, address); + } else if (currency.equals(Currency.USDT)) { + Long tradeId = coinmateWithdrawVirtualCurrency(amount, address, Currency.USDT.getCurrencyCode(), AmountType.GROSS, FeePriority.HIGH, null); + return Long.toString(tradeId); } else { throw new IOException( "Wallet for currency" + currency.getCurrencyCode() + " is currently not supported"); @@ -111,10 +115,27 @@ public String withdrawFunds(Currency currency, BigDecimal amount, String address return Long.toString(response.getData()); } + @Override + public String withdrawFunds(Currency currency, BigDecimal amount, AddressWithTag address) + throws IOException { + if (currency.equals(Currency.XRP)) { + Long tradeId = coinmateWithdrawVirtualCurrency(amount, address.getAddress(), currency.getCurrencyCode(), AmountType.GROSS, FeePriority.HIGH, address.getAddressTag()); + return Long.toString(tradeId); + } else { + return withdrawFunds(currency, amount, address.getAddress()); + } + } + @Override public String withdrawFunds(WithdrawFundsParams params) throws IOException { if (params instanceof DefaultWithdrawFundsParams) { DefaultWithdrawFundsParams defaultParams = (DefaultWithdrawFundsParams) params; + + if (defaultParams.getCurrency().equals(Currency.XRP)) { + Long tradeId = coinmateWithdrawVirtualCurrency(defaultParams.getAmount(), defaultParams.getAddress(), defaultParams.getCurrency().getCurrencyCode(), AmountType.GROSS, FeePriority.HIGH, defaultParams.getAddressTag()); + return Long.toString(tradeId); + } + return withdrawFunds( defaultParams.getCurrency(), defaultParams.getAmount(), defaultParams.getAddress()); } @@ -132,12 +153,16 @@ public String requestDepositAddress(Currency currency, String... args) throws IO addresses = coinmateEthereumDepositAddresses(); } else if (currency.equals(Currency.XRP)) { addresses = coinmateRippleDepositAddresses(); - } else if (currency.equals(Currency.DASH)) { - addresses = coinmateDashDepositAddresses(); } else if (currency.equals(Currency.ADA)) { addresses = coinmateCardanoDepositAddresses(); } else if (currency.equals(Currency.SOL)) { addresses = coinmateSolanaDepositAddresses(); + } else if (currency.equals(Currency.USDT)) { + List addressesAll = coinmateVirtualCurrencyDepositAddresses(currency.getCurrencyCode()); + if (addressesAll.isEmpty()) { + return null; + } + return addressesAll.get(0); } else { throw new IOException( "Wallet for currency" + currency.getCurrencyCode() + " is currently not supported"); diff --git a/xchange-coinmate/src/main/java/org/knowm/xchange/coinmate/service/CoinmateAccountServiceRaw.java b/xchange-coinmate/src/main/java/org/knowm/xchange/coinmate/service/CoinmateAccountServiceRaw.java index 5c2579ac18d..e89d6dd016f 100644 --- a/xchange-coinmate/src/main/java/org/knowm/xchange/coinmate/service/CoinmateAccountServiceRaw.java +++ b/xchange-coinmate/src/main/java/org/knowm/xchange/coinmate/service/CoinmateAccountServiceRaw.java @@ -25,14 +25,20 @@ import java.io.IOException; import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.List; import org.knowm.xchange.Exchange; import org.knowm.xchange.client.ExchangeRestProxyBuilder; import org.knowm.xchange.coinmate.CoinmateAuthenticated; +import org.knowm.xchange.coinmate.dto.account.AmountType; import org.knowm.xchange.coinmate.dto.account.CoinmateBalance; import org.knowm.xchange.coinmate.dto.account.CoinmateDepositAddresses; import org.knowm.xchange.coinmate.dto.account.CoinmateTradingFeesResponse; import org.knowm.xchange.coinmate.dto.account.CoinmateTradingFeesResponseData; import org.knowm.xchange.coinmate.dto.account.FeePriority; +import org.knowm.xchange.coinmate.dto.account.TransferHistoryOrder; +import org.knowm.xchange.coinmate.dto.account.UnconfirmedDeposits; +import org.knowm.xchange.coinmate.dto.account.UnconfirmedDepositsResponse; import org.knowm.xchange.coinmate.dto.trade.CoinmateTradeResponse; import org.knowm.xchange.coinmate.dto.trade.CoinmateTransactionHistory; import org.knowm.xchange.coinmate.dto.trade.CoinmateTransferDetail; @@ -89,6 +95,65 @@ public CoinmateTradingFeesResponseData getCoinmateTraderFees(String currencyPair return response.getData(); } + public Long coinmateWithdrawVirtualCurrency( + BigDecimal amount, + String address, + String currencyName, + AmountType amountType, + FeePriority feePriority, + String destinationTag + ) + throws IOException { + CoinmateTradeResponse response =coinmateAuthenticated.withdrawVirtualCurrency( + exchange.getExchangeSpecification().getApiKey(), + exchange.getExchangeSpecification().getUserName(), + signatureCreator, + exchange.getNonceFactory(), + currencyName, + amount, + destinationTag, + amountType, + address, + feePriority + ); + + throwExceptionIfError(response); + + return response.getData(); + } + + public ArrayList coinmateVirtualCurrencyDepositAddresses(String currencyName) + throws IOException { + CoinmateDepositAddresses response = + coinmateAuthenticated.virtualCurrencyDepositAddresses( + exchange.getExchangeSpecification().getApiKey(), + exchange.getExchangeSpecification().getUserName(), + signatureCreator, + exchange.getNonceFactory(), + currencyName + ); + + throwExceptionIfError(response); + + return response.getData(); + } + + public List coinmateUnconfirmedVirtualCurrencyDeposits(String currencyName) + throws IOException { + UnconfirmedDepositsResponse response = + coinmateAuthenticated.unconfirmedVirtualCurrencyDeposits( + exchange.getExchangeSpecification().getApiKey(), + exchange.getExchangeSpecification().getUserName(), + signatureCreator, + exchange.getNonceFactory(), + currencyName + ); + + throwExceptionIfError(response); + + return response.getData(); + } + public CoinmateTradeResponse coinmateBitcoinWithdrawal(BigDecimal amount, String address) throws IOException { return coinmateBitcoinWithdrawal(amount, address, FeePriority.HIGH); @@ -211,35 +276,6 @@ public CoinmateDepositAddresses coinmateRippleDepositAddresses() throws IOExcept return addresses; } - public CoinmateTradeResponse coinmateDashWithdrawal(BigDecimal amount, String address) - throws IOException { - CoinmateTradeResponse response = - coinmateAuthenticated.dashWithdrawal( - exchange.getExchangeSpecification().getApiKey(), - exchange.getExchangeSpecification().getUserName(), - signatureCreator, - exchange.getNonceFactory(), - amount, - address); - - throwExceptionIfError(response); - - return response; - } - - public CoinmateDepositAddresses coinmateDashDepositAddresses() throws IOException { - CoinmateDepositAddresses addresses = - coinmateAuthenticated.dashDepositAddresses( - exchange.getExchangeSpecification().getApiKey(), - exchange.getExchangeSpecification().getUserName(), - signatureCreator, - exchange.getNonceFactory()); - - throwExceptionIfError(addresses); - - return addresses; - } - public CoinmateTradeResponse coinmateCardanoWithdrawal(BigDecimal amount, String address) throws IOException { CoinmateTradeResponse response = @@ -327,7 +363,7 @@ public CoinmateTransferHistory getTransfersData( public CoinmateTransferHistory getCoinmateTransferHistory( Integer limit, Integer lastId, - String sort, + TransferHistoryOrder sort, Long timestampFrom, Long timestampTo, String currency) diff --git a/xchange-coinmate/src/main/resources/coinmate.json b/xchange-coinmate/src/main/resources/coinmate.json index cc880fea8c0..381f91a4735 100644 --- a/xchange-coinmate/src/main/resources/coinmate.json +++ b/xchange-coinmate/src/main/resources/coinmate.json @@ -1,164 +1,157 @@ { - "currency_pairs" : { - "DASH/BTC" : { - "price_scale" : 5, - "min_amount" : 0.001, - "base_scale" : 8 - }, - "DASH/CZK" : { - "price_scale" : 1, - "min_amount" : 0.001, - "base_scale" : 8 - }, - "ETH/DAI" : { - "price_scale" : 2, - "min_amount" : 0.001, - "base_scale" : 8 - }, - "XRP/EUR" : { - "price_scale" : 5, - "min_amount" : 1, - "base_scale" : 8 - }, - "BCH/EUR" : { - "price_scale" : 2, - "min_amount" : 0.001, - "base_scale" : 8 - }, - "ETH/BTC" : { - "price_scale" : 5, - "min_amount" : 0.001, - "base_scale" : 8 - }, - "LTC/BTC" : { - "price_scale" : 6, - "min_amount" : 0.01, - "base_scale" : 8 - }, - "ADA/CZK" : { - "price_scale" : 4, - "min_amount" : 1, - "base_scale" : 6 - }, - "ETH/CZK" : { - "price_scale" : 1, - "min_amount" : 0.001, - "base_scale" : 8 - }, - "SOL/CZK" : { - "price_scale" : 4, - "min_amount" : 0.01, - "base_scale" : 8 - }, - "BTC/CZK" : { - "price_scale" : 0, - "min_amount" : 0.0001, - "base_scale" : 8 - }, - "BCH/CZK" : { - "price_scale" : 1, - "min_amount" : 0.001, - "base_scale" : 8 - }, - "DASH/EUR" : { - "price_scale" : 2, - "min_amount" : 0.001, - "base_scale" : 8 - }, - "DAI/EUR" : { - "price_scale" : 4, - "min_amount" : 1, - "base_scale" : 2 - }, - "XRP/CZK" : { - "price_scale" : 4, - "min_amount" : 1, - "base_scale" : 8 - }, - "BCH/BTC" : { - "price_scale" : 5, - "min_amount" : 0.001, - "base_scale" : 8 - }, - "BTC/DAI" : { - "price_scale" : 2, - "min_amount" : 0.0001, - "base_scale" : 8 - }, - "LTC/CZK" : { - "price_scale" : 1, - "min_amount" : 0.01, - "base_scale" : 8 - }, - "XRP/BTC" : { - "price_scale" : 8, - "min_amount" : 1, - "base_scale" : 8 - }, - "LTC/EUR" : { - "price_scale" : 2, - "min_amount" : 0.01, - "base_scale" : 8 - }, - "ADA/EUR" : { - "price_scale" : 5, - "min_amount" : 1, - "base_scale" : 6 - }, - "SOL/EUR" : { - "price_scale" : 5, - "min_amount" : 0.01, - "base_scale" : 8 - }, - "BTC/EUR" : { - "price_scale" : 1, - "min_amount" : 0.0001, - "base_scale" : 8 - }, - "ETH/EUR" : { - "price_scale" : 2, - "min_amount" : 0.001, - "base_scale" : 8 + "currency_pairs": { + "XRP/EUR": { + "price_scale": 5, + "min_amount": 1, + "base_scale": 8 + }, + "BTC/USDT": { + "price_scale": 1, + "min_amount": 0.0001, + "base_scale": 8 + }, + "USDT/EUR": { + "price_scale": 4, + "min_amount": 1, + "base_scale": 2 + }, + "ETH/BTC": { + "price_scale": 5, + "min_amount": 0.001, + "base_scale": 8 + }, + "LTC/BTC": { + "price_scale": 6, + "min_amount": 0.01, + "base_scale": 8 + }, + "ADA/CZK": { + "price_scale": 4, + "min_amount": 1, + "base_scale": 6 + }, + "ETH/CZK": { + "price_scale": 1, + "min_amount": 0.001, + "base_scale": 8 + }, + "SOL/CZK": { + "price_scale": 4, + "min_amount": 0.01, + "base_scale": 8 + }, + "BTC/CZK": { + "price_scale": 0, + "min_amount": 0.0001, + "base_scale": 8 + }, + "XRP/CZK": { + "price_scale": 4, + "min_amount": 1, + "base_scale": 8 + }, + "LTC/CZK": { + "price_scale": 1, + "min_amount": 0.01, + "base_scale": 8 + }, + "XRP/BTC": { + "price_scale": 8, + "min_amount": 1, + "base_scale": 8 + }, + "ADA/EUR": { + "price_scale": 5, + "min_amount": 1, + "base_scale": 6 + }, + "LTC/EUR": { + "price_scale": 2, + "min_amount": 0.01, + "base_scale": 8 + }, + "SOL/EUR": { + "price_scale": 5, + "min_amount": 0.01, + "base_scale": 8 + }, + "USDT/CZK": { + "price_scale": 3, + "min_amount": 1, + "base_scale": 2 + }, + "BTC/EUR": { + "price_scale": 1, + "min_amount": 0.0001, + "base_scale": 8 + }, + "ETH/EUR": { + "price_scale": 2, + "min_amount": 0.001, + "base_scale": 8 } }, - "currencies" : { - "BTC" : { - "scale" : 8 + "currencies": { + "EUR": { + "scale": 2 }, - "SOL" : { - "scale" : 8 + "BCH": { + "scale": 8 }, - "EUR" : { - "scale" : 2 + "USD": { + "scale": 2 }, - "CZK" : { - "scale" : 2 + "USDT": { + "scale": 2 }, - "BCH" : { - "scale" : 8 + "DASH": { + "scale": 8 }, - "XRP" : { - "scale" : 8 + "DAI": { + "scale": 2 }, - "ETH" : { - "scale" : 8 + "BTC": { + "scale": 8 }, - "LTC" : { - "scale" : 8 + "SOL": { + "scale": 8 }, - "DASH" : { - "scale" : 8 + "PLN": { + "scale": 2 }, - "DAI" : { - "scale" : 2 + "GBP": { + "scale": 2 }, - "ADA" : { - "scale" : 6 + "CZK": { + "scale": 2 + }, + "XRP": { + "scale": 8 + }, + "ETH": { + "scale": 8 + }, + "HUF": { + "scale": 2 + }, + "LTC": { + "scale": 8 + }, + "TRX": { + "scale": 8 + }, + "ADA": { + "scale": 6 + }, + "LUNA": { + "scale": 8 } }, - "private_rate_limits" : [ { - "calls" : 100, - "time_unit" : "minutes" - } ], - "share_rate_limits" : true + "private_rate_limits": [ + { + "calls": 100, + "time_unit": "minutes" + } + ], + "share_rate_limits": true } \ No newline at end of file From f825acb80eef6d8cb72bae0470d2d793c6ca47d7 Mon Sep 17 00:00:00 2001 From: sydowma Date: Sun, 17 Mar 2024 20:27:39 +0800 Subject: [PATCH 137/159] compatible BinanceKline closed --- .../knowm/xchange/binance/dto/marketdata/BinanceKline.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/xchange-binance/src/main/java/org/knowm/xchange/binance/dto/marketdata/BinanceKline.java b/xchange-binance/src/main/java/org/knowm/xchange/binance/dto/marketdata/BinanceKline.java index ef1bcd451f2..55d08e59fb6 100644 --- a/xchange-binance/src/main/java/org/knowm/xchange/binance/dto/marketdata/BinanceKline.java +++ b/xchange-binance/src/main/java/org/knowm/xchange/binance/dto/marketdata/BinanceKline.java @@ -38,7 +38,11 @@ public BinanceKline(Instrument instrument, KlineInterval interval, Object[] obj) this.numberOfTrades = Long.parseLong(obj[8].toString()); this.takerBuyBaseAssetVolume = new BigDecimal(obj[9].toString()); this.takerBuyQuoteAssetVolume = new BigDecimal(obj[10].toString()); - this.closed = (Boolean) obj[11]; + if ("0".equals(obj[11])) { + this.closed = false; + } else { + this.closed = (Boolean) obj[11]; + } } public BigDecimal getAveragePrice() { From 6b019260e277ad4faa8b4edf14e278d1c3814c9f Mon Sep 17 00:00:00 2001 From: sydowma Date: Sun, 17 Mar 2024 21:58:55 +0800 Subject: [PATCH 138/159] optimize closed check --- .../knowm/xchange/binance/dto/marketdata/BinanceKline.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/xchange-binance/src/main/java/org/knowm/xchange/binance/dto/marketdata/BinanceKline.java b/xchange-binance/src/main/java/org/knowm/xchange/binance/dto/marketdata/BinanceKline.java index 55d08e59fb6..bf503b809f6 100644 --- a/xchange-binance/src/main/java/org/knowm/xchange/binance/dto/marketdata/BinanceKline.java +++ b/xchange-binance/src/main/java/org/knowm/xchange/binance/dto/marketdata/BinanceKline.java @@ -38,11 +38,7 @@ public BinanceKline(Instrument instrument, KlineInterval interval, Object[] obj) this.numberOfTrades = Long.parseLong(obj[8].toString()); this.takerBuyBaseAssetVolume = new BigDecimal(obj[9].toString()); this.takerBuyQuoteAssetVolume = new BigDecimal(obj[10].toString()); - if ("0".equals(obj[11])) { - this.closed = false; - } else { - this.closed = (Boolean) obj[11]; - } + this.closed = Boolean.parseBoolean(obj[11].toString()); } public BigDecimal getAveragePrice() { From f32a673c280297be97ce2aac9fe3ea97aa294d69 Mon Sep 17 00:00:00 2001 From: Donald Jackson Date: Thu, 28 Mar 2024 15:50:24 +0100 Subject: [PATCH 139/159] [kraken] added support for deposit addresses with alternative networks --- .../DepositAddressAmbiguousException.java | 25 ++++ .../DepositAddressCreationException.java | 17 +++ .../DepositAddressNotFoundException.java | 17 +++ .../service/account/AccountService.java | 38 +++++ .../DefaultRequestDepositAddressParams.java | 27 ++++ .../params/RequestDepositAddressParams.java | 13 ++ .../kraken/service/KrakenAccountService.java | 83 ++++++++--- .../service/KrakenAccountServiceRaw.java | 70 +++++++-- .../kraken/service/BaseWiremockTest.java | 10 ++ .../service/KrakenAccountServiceTest.java | 135 ++++++++++++++++++ .../example-deposit-addresses-trx.json | 10 ++ .../example-deposit-addresses-xrp.json | 11 ++ .../account/example-deposit-addresses.json | 10 ++ .../account/example-deposit-methods-trx.json | 11 ++ .../account/example-deposit-methods-usdt.json | 42 ++++++ .../account/example-deposit-methods-xrp.json | 11 ++ 16 files changed, 497 insertions(+), 33 deletions(-) create mode 100644 xchange-core/src/main/java/org/knowm/xchange/exceptions/DepositAddressAmbiguousException.java create mode 100644 xchange-core/src/main/java/org/knowm/xchange/exceptions/DepositAddressCreationException.java create mode 100644 xchange-core/src/main/java/org/knowm/xchange/exceptions/DepositAddressNotFoundException.java create mode 100644 xchange-core/src/main/java/org/knowm/xchange/service/account/params/DefaultRequestDepositAddressParams.java create mode 100644 xchange-core/src/main/java/org/knowm/xchange/service/account/params/RequestDepositAddressParams.java create mode 100644 xchange-kraken/src/test/java/org/knowm/xchange/kraken/service/KrakenAccountServiceTest.java create mode 100644 xchange-kraken/src/test/resources/org/knowm/xchange/kraken/dto/account/example-deposit-addresses-trx.json create mode 100644 xchange-kraken/src/test/resources/org/knowm/xchange/kraken/dto/account/example-deposit-addresses-xrp.json create mode 100644 xchange-kraken/src/test/resources/org/knowm/xchange/kraken/dto/account/example-deposit-addresses.json create mode 100644 xchange-kraken/src/test/resources/org/knowm/xchange/kraken/dto/account/example-deposit-methods-trx.json create mode 100644 xchange-kraken/src/test/resources/org/knowm/xchange/kraken/dto/account/example-deposit-methods-usdt.json create mode 100644 xchange-kraken/src/test/resources/org/knowm/xchange/kraken/dto/account/example-deposit-methods-xrp.json diff --git a/xchange-core/src/main/java/org/knowm/xchange/exceptions/DepositAddressAmbiguousException.java b/xchange-core/src/main/java/org/knowm/xchange/exceptions/DepositAddressAmbiguousException.java new file mode 100644 index 00000000000..663cfc28698 --- /dev/null +++ b/xchange-core/src/main/java/org/knowm/xchange/exceptions/DepositAddressAmbiguousException.java @@ -0,0 +1,25 @@ +package org.knowm.xchange.exceptions; + +import java.util.List; +import lombok.Getter; + +/** Exception indicating a requested deposit address has multiple networks and network required */ +@Getter +public class DepositAddressAmbiguousException extends ExchangeException { + private final List networks; + + public DepositAddressAmbiguousException(List networks) { + super("Deposit Address Not Found"); + this.networks = networks; + } + + public DepositAddressAmbiguousException(List networks, String message) { + super(message); + this.networks = networks; + } + + public DepositAddressAmbiguousException(List networks, String message, Throwable cause) { + super(message, cause); + this.networks = networks; + } +} diff --git a/xchange-core/src/main/java/org/knowm/xchange/exceptions/DepositAddressCreationException.java b/xchange-core/src/main/java/org/knowm/xchange/exceptions/DepositAddressCreationException.java new file mode 100644 index 00000000000..aaf34d8e2bb --- /dev/null +++ b/xchange-core/src/main/java/org/knowm/xchange/exceptions/DepositAddressCreationException.java @@ -0,0 +1,17 @@ +package org.knowm.xchange.exceptions; + +/** Exception indicating a deposit address could not be created */ +public class DepositAddressCreationException extends ExchangeException { + + public DepositAddressCreationException() { + super("Deposit Address Could Not Be Created"); + } + + public DepositAddressCreationException(String message) { + super(message); + } + + public DepositAddressCreationException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/xchange-core/src/main/java/org/knowm/xchange/exceptions/DepositAddressNotFoundException.java b/xchange-core/src/main/java/org/knowm/xchange/exceptions/DepositAddressNotFoundException.java new file mode 100644 index 00000000000..2575deb6b8e --- /dev/null +++ b/xchange-core/src/main/java/org/knowm/xchange/exceptions/DepositAddressNotFoundException.java @@ -0,0 +1,17 @@ +package org.knowm.xchange.exceptions; + +/** Exception indicating a requested deposit address was not found */ +public class DepositAddressNotFoundException extends ExchangeException { + + public DepositAddressNotFoundException() { + super("Deposit Address Not Found"); + } + + public DepositAddressNotFoundException(String message) { + super(message); + } + + public DepositAddressNotFoundException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/xchange-core/src/main/java/org/knowm/xchange/service/account/AccountService.java b/xchange-core/src/main/java/org/knowm/xchange/service/account/AccountService.java index b10c6ef0ab7..5a3aa9c4bd4 100644 --- a/xchange-core/src/main/java/org/knowm/xchange/service/account/AccountService.java +++ b/xchange-core/src/main/java/org/knowm/xchange/service/account/AccountService.java @@ -15,6 +15,7 @@ import org.knowm.xchange.exceptions.NotYetImplementedForExchangeException; import org.knowm.xchange.instrument.Instrument; import org.knowm.xchange.service.BaseService; +import org.knowm.xchange.service.account.params.RequestDepositAddressParams; import org.knowm.xchange.service.trade.params.DefaultWithdrawFundsParams; import org.knowm.xchange.service.trade.params.TradeHistoryParams; import org.knowm.xchange.service.trade.params.WithdrawFundsParams; @@ -125,6 +126,24 @@ default String requestDepositAddress(Currency currency, String... args) throws I throw new NotYetImplementedForExchangeException("requestDepositAddress"); } + /** + * Request a digital currency address to fund this account. Allows to fund the exchange account + * with digital currency from an external address + * + * @param params The deposit address request parameters + * @return the internal deposit address to send funds to + * @throws ExchangeException - Indication that the exchange reported some kind of error with the + * request or response + * @throws NotAvailableFromExchangeException - Indication that the exchange does not support the + * requested function or data + * @throws NotYetImplementedForExchangeException - Indication that the exchange supports the + * requested function or data, but it has not yet been implemented + * @throws IOException - Indication that a networking error occurred while fetching JSON data + */ + default String requestDepositAddress(RequestDepositAddressParams params) throws IOException { + return requestDepositAddress(params.getCurrency(), params.getExtraArguments()); + } + /** * Request a digital currency address to fund this account. Allows to fund the exchange account * with digital currency from an external address @@ -144,6 +163,25 @@ default AddressWithTag requestDepositAddressData(Currency currency, String... ar throw new NotYetImplementedForExchangeException("requestDepositAddressData"); } + /** + * Request a digital currency address to fund this account. Allows to fund the exchange account + * with digital currency from an external address + * + * @param params The deposit address request parameters + * @return the internal deposit address to send funds to + * @throws ExchangeException - Indication that the exchange reported some kind of error with the + * request or response + * @throws NotAvailableFromExchangeException - Indication that the exchange does not support the + * requested function or data + * @throws NotYetImplementedForExchangeException - Indication that the exchange supports the + * requested function or data, but it has not yet been implemented + * @throws IOException - Indication that a networking error occurred while fetching JSON data + */ + default AddressWithTag requestDepositAddressData(RequestDepositAddressParams params) + throws IOException { + return requestDepositAddressData(params.getCurrency(), params.getExtraArguments()); + } + /** * Create {@link TradeHistoryParams} object specific to this exchange. Object created by this * method may be used to discover supported and required {@link diff --git a/xchange-core/src/main/java/org/knowm/xchange/service/account/params/DefaultRequestDepositAddressParams.java b/xchange-core/src/main/java/org/knowm/xchange/service/account/params/DefaultRequestDepositAddressParams.java new file mode 100644 index 00000000000..291b31e3a5c --- /dev/null +++ b/xchange-core/src/main/java/org/knowm/xchange/service/account/params/DefaultRequestDepositAddressParams.java @@ -0,0 +1,27 @@ +package org.knowm.xchange.service.account.params; + +import lombok.Builder; +import lombok.Value; +import lombok.experimental.NonFinal; +import lombok.extern.jackson.Jacksonized; +import org.knowm.xchange.currency.Currency; + +@Value +@NonFinal +@Builder +@Jacksonized +public class DefaultRequestDepositAddressParams implements RequestDepositAddressParams { + Currency currency; + String network; + + @Builder.Default boolean newAddress = false; + + String[] extraArguments; + + public static DefaultRequestDepositAddressParams create(Currency currency, String... args) { + return DefaultRequestDepositAddressParams.builder() + .currency(currency) + .extraArguments(args) + .build(); + } +} diff --git a/xchange-core/src/main/java/org/knowm/xchange/service/account/params/RequestDepositAddressParams.java b/xchange-core/src/main/java/org/knowm/xchange/service/account/params/RequestDepositAddressParams.java new file mode 100644 index 00000000000..9061ad96216 --- /dev/null +++ b/xchange-core/src/main/java/org/knowm/xchange/service/account/params/RequestDepositAddressParams.java @@ -0,0 +1,13 @@ +package org.knowm.xchange.service.account.params; + +import org.knowm.xchange.currency.Currency; + +public interface RequestDepositAddressParams { + Currency getCurrency(); + + String getNetwork(); + + boolean isNewAddress(); + + String[] getExtraArguments(); +} diff --git a/xchange-kraken/src/main/java/org/knowm/xchange/kraken/service/KrakenAccountService.java b/xchange-kraken/src/main/java/org/knowm/xchange/kraken/service/KrakenAccountService.java index 047f92aba3f..cf48b98301a 100644 --- a/xchange-kraken/src/main/java/org/knowm/xchange/kraken/service/KrakenAccountService.java +++ b/xchange-kraken/src/main/java/org/knowm/xchange/kraken/service/KrakenAccountService.java @@ -11,9 +11,12 @@ import org.knowm.xchange.currency.Currency; import org.knowm.xchange.currency.CurrencyPair; import org.knowm.xchange.dto.account.AccountInfo; +import org.knowm.xchange.dto.account.AddressWithTag; import org.knowm.xchange.dto.account.Fee; import org.knowm.xchange.dto.account.FundingRecord; import org.knowm.xchange.dto.account.Wallet; +import org.knowm.xchange.exceptions.DepositAddressCreationException; +import org.knowm.xchange.exceptions.DepositAddressNotFoundException; import org.knowm.xchange.instrument.Instrument; import org.knowm.xchange.kraken.KrakenAdapters; import org.knowm.xchange.kraken.KrakenUtils; @@ -22,6 +25,8 @@ import org.knowm.xchange.kraken.dto.account.KrakenTradeBalanceInfo; import org.knowm.xchange.kraken.dto.account.LedgerType; import org.knowm.xchange.service.account.AccountService; +import org.knowm.xchange.service.account.params.DefaultRequestDepositAddressParams; +import org.knowm.xchange.service.account.params.RequestDepositAddressParams; import org.knowm.xchange.service.trade.params.DefaultTradeHistoryParamsTimeSpan; import org.knowm.xchange.service.trade.params.DefaultWithdrawFundsParams; import org.knowm.xchange.service.trade.params.HistoryParamsFundingType; @@ -89,50 +94,88 @@ public String withdrawFunds(WithdrawFundsParams params) throws IOException { throw new IllegalStateException("Don't know how to withdraw: " + params); } + @Override + public AddressWithTag requestDepositAddressData(Currency currency, String... args) + throws IOException { + return requestDepositAddressData(DefaultRequestDepositAddressParams.create(currency, args)); + } + @Override public String requestDepositAddress(Currency currency, String... args) throws IOException { + return requestDepositAddressData(DefaultRequestDepositAddressParams.create(currency, args)) + .getAddress(); + } + + @Override + public String requestDepositAddress(RequestDepositAddressParams requestDepositAddressParams) + throws IOException { + return requestDepositAddressData(requestDepositAddressParams).getAddress(); + } + + @Override + public AddressWithTag requestDepositAddressData( + RequestDepositAddressParams requestDepositAddressParams) throws IOException { + Currency currency = requestDepositAddressParams.getCurrency(); + boolean newAddress = requestDepositAddressParams.isNewAddress(); + String depositMethod = null; + KrakenDepositAddress[] depositAddresses; if (Currency.BTC.equals(currency)) { - depositAddresses = getDepositAddresses(currency.toString(), "Bitcoin", false); + depositAddresses = getDepositAddresses(currency.toString(), "Bitcoin", newAddress); } else if (Currency.LTC.equals(currency)) { - depositAddresses = getDepositAddresses(currency.toString(), "Litecoin", false); + depositAddresses = getDepositAddresses(currency.toString(), "Litecoin", newAddress); } else if (Currency.ETH.equals(currency)) { - depositAddresses = getDepositAddresses(currency.toString(), "Ethereum (ERC20)", false); + depositAddresses = getDepositAddresses(currency.toString(), "Ethereum (ERC20)", newAddress); } else if (Currency.ZEC.equals(currency)) { - depositAddresses = getDepositAddresses(currency.toString(), "Zcash (Transparent)", false); + depositAddresses = + getDepositAddresses(currency.toString(), "Zcash (Transparent)", newAddress); } else if (Currency.ADA.equals(currency)) { - depositAddresses = getDepositAddresses(currency.toString(), "ADA", false); + depositAddresses = getDepositAddresses(currency.toString(), "ADA", newAddress); } else if (Currency.XMR.equals(currency)) { - depositAddresses = getDepositAddresses(currency.toString(), "Monero", false); + depositAddresses = getDepositAddresses(currency.toString(), "Monero", newAddress); } else if (Currency.XRP.equals(currency)) { - depositAddresses = getDepositAddresses(currency.toString(), "Ripple XRP", false); + depositAddresses = getDepositAddresses(currency.toString(), "Ripple XRP", newAddress); } else if (Currency.XLM.equals(currency)) { - depositAddresses = getDepositAddresses(currency.toString(), "Stellar XLM", false); + depositAddresses = getDepositAddresses(currency.toString(), "Stellar XLM", newAddress); } else if (Currency.BCH.equals(currency)) { - depositAddresses = getDepositAddresses(currency.toString(), "Bitcoin Cash", false); + depositAddresses = getDepositAddresses(currency.toString(), "Bitcoin Cash", newAddress); } else if (Currency.REP.equals(currency)) { - depositAddresses = getDepositAddresses(currency.toString(), "REP", false); + depositAddresses = getDepositAddresses(currency.toString(), "REP", newAddress); } else if (Currency.USD.equals(currency)) { - depositAddresses = getDepositAddresses(currency.toString(), "SynapsePay (US Wire)", false); + depositAddresses = + getDepositAddresses(currency.toString(), "SynapsePay (US Wire)", newAddress); } else if (Currency.XDG.equals(currency)) { - depositAddresses = getDepositAddresses(currency.toString(), "Dogecoin", false); + depositAddresses = getDepositAddresses(currency.toString(), "Dogecoin", newAddress); } else if (Currency.MLN.equals(currency)) { - depositAddresses = getDepositAddresses(currency.toString(), "MLN", false); + depositAddresses = getDepositAddresses(currency.toString(), "MLN", newAddress); } else if (Currency.GNO.equals(currency)) { - depositAddresses = getDepositAddresses(currency.toString(), "GNO", false); + depositAddresses = getDepositAddresses(currency.toString(), "GNO", newAddress); } else if (Currency.QTUM.equals(currency)) { - depositAddresses = getDepositAddresses(currency.toString(), "QTUM", false); + depositAddresses = getDepositAddresses(currency.toString(), "QTUM", newAddress); } else if (Currency.XTZ.equals(currency)) { - depositAddresses = getDepositAddresses(currency.toString(), "XTZ", false); + depositAddresses = getDepositAddresses(currency.toString(), "XTZ", newAddress); } else if (Currency.ATOM.equals(currency)) { - depositAddresses = getDepositAddresses(currency.toString(), "Cosmos", false); + depositAddresses = getDepositAddresses(currency.toString(), "Cosmos", newAddress); } else if (Currency.EOS.equals(currency)) { - depositAddresses = getDepositAddresses(currency.toString(), "EOS", false); + depositAddresses = getDepositAddresses(currency.toString(), "EOS", newAddress); } else if (Currency.DASH.equals(currency)) { - depositAddresses = getDepositAddresses(currency.toString(), "Dash", false); + depositAddresses = getDepositAddresses(currency.toString(), "Dash", newAddress); } else { - throw new RuntimeException("Not implemented yet, Kraken works only for BTC and LTC"); + depositMethod = findDepositMethod(currency, requestDepositAddressParams.getNetwork()); + depositAddresses = getDepositAddresses(currency.toString(), depositMethod, newAddress); + } + + if (depositAddresses.length == 0 && !newAddress) { + throw new DepositAddressNotFoundException( + String.format("No deposit addresses found for %s method: %s", currency, depositMethod)); + } + + if (depositAddresses.length == 0) { + throw new DepositAddressCreationException( + String.format( + "Deposit address could not be created for %s method: %s", currency, depositMethod)); } + return KrakenAdapters.adaptKrakenDepositAddress(depositAddresses); } diff --git a/xchange-kraken/src/main/java/org/knowm/xchange/kraken/service/KrakenAccountServiceRaw.java b/xchange-kraken/src/main/java/org/knowm/xchange/kraken/service/KrakenAccountServiceRaw.java index c816d4297f6..9624443f761 100644 --- a/xchange-kraken/src/main/java/org/knowm/xchange/kraken/service/KrakenAccountServiceRaw.java +++ b/xchange-kraken/src/main/java/org/knowm/xchange/kraken/service/KrakenAccountServiceRaw.java @@ -2,12 +2,16 @@ import java.io.IOException; import java.math.BigDecimal; +import java.util.Arrays; import java.util.Date; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; +import lombok.extern.slf4j.Slf4j; import org.knowm.xchange.Exchange; import org.knowm.xchange.currency.Currency; import org.knowm.xchange.currency.CurrencyPair; +import org.knowm.xchange.exceptions.DepositAddressAmbiguousException; import org.knowm.xchange.kraken.KrakenUtils; import org.knowm.xchange.kraken.dto.account.DepostitStatus; import org.knowm.xchange.kraken.dto.account.KrakenDepositAddress; @@ -23,7 +27,6 @@ import org.knowm.xchange.kraken.dto.account.results.DepositStatusResult; import org.knowm.xchange.kraken.dto.account.results.KrakenBalanceResult; import org.knowm.xchange.kraken.dto.account.results.KrakenDepositAddressResult; -import org.knowm.xchange.kraken.dto.account.results.KrakenDepositMethodsResults; import org.knowm.xchange.kraken.dto.account.results.KrakenLedgerResult; import org.knowm.xchange.kraken.dto.account.results.KrakenQueryLedgerResult; import org.knowm.xchange.kraken.dto.account.results.KrakenTradeBalanceInfoResult; @@ -34,18 +37,18 @@ import org.knowm.xchange.kraken.dto.account.results.WithdrawStatusResult; import org.knowm.xchange.utils.DateUtils; -/** - * @author jamespedwards42 - */ +/** @author jamespedwards42 */ +@Slf4j public class KrakenAccountServiceRaw extends KrakenBaseService { + private KrakenDepositMethods[] depositMethods; + /** * Constructor * * @param exchange */ public KrakenAccountServiceRaw(Exchange exchange) { - super(exchange); } @@ -82,14 +85,47 @@ public KrakenDepositAddress[] getDepositAddresses( public KrakenDepositMethods[] getDepositMethods(String assetPairs, String assets) throws IOException { - KrakenDepositMethodsResults depositMethods = - kraken.getDepositMethods( - assetPairs, - assets, - exchange.getExchangeSpecification().getApiKey(), - signatureCreator, - exchange.getNonceFactory()); - return checkResult(depositMethods); + if (shouldCacheDepositMethods() && depositMethods != null) { + return depositMethods; + } + + depositMethods = + checkResult( + kraken.getDepositMethods( + assetPairs, + assets, + exchange.getExchangeSpecification().getApiKey(), + signatureCreator, + exchange.getNonceFactory())); + + return depositMethods; + } + + protected String findDepositMethod(Currency currency, String network) throws IOException { + KrakenDepositMethods[] depositMethods = getDepositMethods(null, currency.toString()); + + if (depositMethods == null || depositMethods.length == 0) { + return network; + } + + if (depositMethods.length == 1) { + return depositMethods[0].getMethod(); + } + + log.warn( + "Multiple methods for currency {} {}", + currency, + Arrays.stream(depositMethods).map(KrakenDepositMethods::getMethod).toArray()); + + if (network == null) { + throw new DepositAddressAmbiguousException( + Arrays.stream(depositMethods) + .map(KrakenDepositMethods::getMethod) + .collect(Collectors.toList()), + "Multiple deposit methods available for " + currency + ", require to specify network"); + } + + return network; // Use network if requested } public WithdrawInfo getWithdrawInfo( @@ -305,4 +341,12 @@ public KrakenTradeVolume getTradeVolume(CurrencyPair... currencyPairs) throws IO exchange.getNonceFactory()); return checkResult(result); } + + private boolean shouldCacheDepositMethods() { + return (boolean) + exchange + .getExchangeSpecification() + .getExchangeSpecificParameters() + .getOrDefault("cacheDepositMethods", false); + } } diff --git a/xchange-kraken/src/test/java/org/knowm/xchange/kraken/service/BaseWiremockTest.java b/xchange-kraken/src/test/java/org/knowm/xchange/kraken/service/BaseWiremockTest.java index 68fb2ee2515..6c5edf6f182 100644 --- a/xchange-kraken/src/test/java/org/knowm/xchange/kraken/service/BaseWiremockTest.java +++ b/xchange-kraken/src/test/java/org/knowm/xchange/kraken/service/BaseWiremockTest.java @@ -2,8 +2,11 @@ import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; +import com.fasterxml.jackson.databind.ObjectMapper; import com.github.tomakehurst.wiremock.junit.WireMockRule; import com.google.common.collect.ImmutableMap; +import lombok.SneakyThrows; +import org.apache.commons.io.IOUtils; import org.junit.Rule; import org.knowm.xchange.Exchange; import org.knowm.xchange.ExchangeFactory; @@ -17,6 +20,8 @@ public class BaseWiremockTest { @Rule public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort()); + private final ObjectMapper objectMapper = new ObjectMapper(); + public Exchange createExchange() { KrakenUtils.setKrakenAssets(ASSETS); KrakenUtils.setKrakenAssetPairs(ASSET_PAIRS); @@ -31,6 +36,11 @@ public Exchange createExchange() { return exchange; } + @SneakyThrows + protected byte[] loadFile(String path) { + return IOUtils.toByteArray(getClass().getResourceAsStream(path)); + } + public static final ImmutableMap ASSETS = ImmutableMap.of( "XXBT", new KrakenAsset("XBT", "currency", 8, 6), diff --git a/xchange-kraken/src/test/java/org/knowm/xchange/kraken/service/KrakenAccountServiceTest.java b/xchange-kraken/src/test/java/org/knowm/xchange/kraken/service/KrakenAccountServiceTest.java new file mode 100644 index 00000000000..3e4572571c1 --- /dev/null +++ b/xchange-kraken/src/test/java/org/knowm/xchange/kraken/service/KrakenAccountServiceTest.java @@ -0,0 +1,135 @@ +package org.knowm.xchange.kraken.service; + +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.post; +import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; +import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import lombok.SneakyThrows; +import lombok.extern.slf4j.Slf4j; +import org.junit.Before; +import org.junit.Test; +import org.knowm.xchange.currency.Currency; +import org.knowm.xchange.dto.account.AddressWithTag; +import org.knowm.xchange.exceptions.DepositAddressAmbiguousException; +import org.knowm.xchange.service.account.params.DefaultRequestDepositAddressParams; + +@Slf4j +public class KrakenAccountServiceTest extends BaseWiremockTest { + + private KrakenAccountService classUnderTest; + + @Before + public void setup() { + classUnderTest = (KrakenAccountService) createExchange().getAccountService(); + } + + @Test + @SneakyThrows + public void testRequestDepositAddressUnknownCurrency() { + stubFor( + post(urlPathEqualTo("/0/private/DepositMethods")) + .willReturn( + aResponse() + .withStatus(200) + .withHeader("Content-Type", "application/json") + .withBody( + loadFile( + "/org/knowm/xchange/kraken/dto/account/example-deposit-methods-trx.json")))); + + stubFor( + post(urlPathEqualTo("/0/private/DepositAddresses")) + .willReturn( + aResponse() + .withStatus(200) + .withHeader("Content-Type", "application/json") + .withBody( + loadFile( + "/org/knowm/xchange/kraken/dto/account/example-deposit-addresses-trx.json")))); + + DefaultRequestDepositAddressParams params = + DefaultRequestDepositAddressParams.builder().currency(Currency.TRX).build(); + + String address = classUnderTest.requestDepositAddress(params); + + assertThat(address).isEqualTo("TYAnp8VW1aq5Jbtxgoai7BDo3jKSRe6VNR"); + } + + @Test + @SneakyThrows + public void testRequestDepositAddressKnownCurrency() { + stubFor( + post(urlPathEqualTo("/0/private/DepositAddresses")) + .willReturn( + aResponse() + .withStatus(200) + .withHeader("Content-Type", "application/json") + .withBody( + loadFile( + "/org/knowm/xchange/kraken/dto/account/example-deposit-addresses.json")))); + + DefaultRequestDepositAddressParams params = + DefaultRequestDepositAddressParams.builder().currency(Currency.BTC).build(); + + String address = classUnderTest.requestDepositAddress(params); + + assertThat(address).isEqualTo("testBtcAddress"); + } + + @Test + @SneakyThrows + public void testRequestDepositAddressUnknownCurrencyMultipleMethods() { + stubFor( + post(urlPathEqualTo("/0/private/DepositMethods")) + .willReturn( + aResponse() + .withStatus(200) + .withHeader("Content-Type", "application/json") + .withBody( + loadFile( + "/org/knowm/xchange/kraken/dto/account/example-deposit-methods-usdt.json")))); + + assertThatThrownBy( + () -> { + DefaultRequestDepositAddressParams params = + DefaultRequestDepositAddressParams.builder().currency(Currency.USDT).build(); + + classUnderTest.requestDepositAddress(params); + }) + .isInstanceOf(DepositAddressAmbiguousException.class); + } + + @Test + @SneakyThrows + public void testRequestDepositAddressUnknownCurrencyMultipleMethodsWithNetwork() { + stubFor( + post(urlPathEqualTo("/0/private/DepositMethods")) + .willReturn( + aResponse() + .withStatus(200) + .withHeader("Content-Type", "application/json") + .withBody( + loadFile( + "/org/knowm/xchange/kraken/dto/account/example-deposit-methods-xrp.json")))); + + stubFor( + post(urlPathEqualTo("/0/private/DepositAddresses")) + .willReturn( + aResponse() + .withStatus(200) + .withHeader("Content-Type", "application/json") + .withBody( + loadFile( + "/org/knowm/xchange/kraken/dto/account/example-deposit-addresses-xrp.json")))); + + DefaultRequestDepositAddressParams params = + DefaultRequestDepositAddressParams.builder().currency(Currency.XRP).build(); + + AddressWithTag address = classUnderTest.requestDepositAddressData(params); + + assertThat(address.getAddress()).isEqualTo("testXrpAddress"); + assertThat(address.getAddressTag()).isEqualTo("123"); + } +} diff --git a/xchange-kraken/src/test/resources/org/knowm/xchange/kraken/dto/account/example-deposit-addresses-trx.json b/xchange-kraken/src/test/resources/org/knowm/xchange/kraken/dto/account/example-deposit-addresses-trx.json new file mode 100644 index 00000000000..406a9f0af40 --- /dev/null +++ b/xchange-kraken/src/test/resources/org/knowm/xchange/kraken/dto/account/example-deposit-addresses-trx.json @@ -0,0 +1,10 @@ +{ + "error": [], + "result": [ + { + "address": "TYAnp8VW1aq5Jbtxgoai7BDo3jKSRe6VNR", + "expiretm": "0", + "new": true + } + ] +} \ No newline at end of file diff --git a/xchange-kraken/src/test/resources/org/knowm/xchange/kraken/dto/account/example-deposit-addresses-xrp.json b/xchange-kraken/src/test/resources/org/knowm/xchange/kraken/dto/account/example-deposit-addresses-xrp.json new file mode 100644 index 00000000000..2ba6c97210f --- /dev/null +++ b/xchange-kraken/src/test/resources/org/knowm/xchange/kraken/dto/account/example-deposit-addresses-xrp.json @@ -0,0 +1,11 @@ +{ + "error": [], + "result": [ + { + "address": "testXrpAddress", + "expiretm": "0", + "new": true, + "tag": "123" + } + ] +} \ No newline at end of file diff --git a/xchange-kraken/src/test/resources/org/knowm/xchange/kraken/dto/account/example-deposit-addresses.json b/xchange-kraken/src/test/resources/org/knowm/xchange/kraken/dto/account/example-deposit-addresses.json new file mode 100644 index 00000000000..531c0c67317 --- /dev/null +++ b/xchange-kraken/src/test/resources/org/knowm/xchange/kraken/dto/account/example-deposit-addresses.json @@ -0,0 +1,10 @@ +{ + "error": [], + "result": [ + { + "address": "testBtcAddress", + "expiretm": "0", + "new": true + } + ] +} \ No newline at end of file diff --git a/xchange-kraken/src/test/resources/org/knowm/xchange/kraken/dto/account/example-deposit-methods-trx.json b/xchange-kraken/src/test/resources/org/knowm/xchange/kraken/dto/account/example-deposit-methods-trx.json new file mode 100644 index 00000000000..48e4bd47000 --- /dev/null +++ b/xchange-kraken/src/test/resources/org/knowm/xchange/kraken/dto/account/example-deposit-methods-trx.json @@ -0,0 +1,11 @@ +{ + "error": [], + "result": [ + { + "method": "Tron", + "limit": false, + "gen-address": true, + "minimum": "2.000000" + } + ] +} \ No newline at end of file diff --git a/xchange-kraken/src/test/resources/org/knowm/xchange/kraken/dto/account/example-deposit-methods-usdt.json b/xchange-kraken/src/test/resources/org/knowm/xchange/kraken/dto/account/example-deposit-methods-usdt.json new file mode 100644 index 00000000000..8a5498cef1d --- /dev/null +++ b/xchange-kraken/src/test/resources/org/knowm/xchange/kraken/dto/account/example-deposit-methods-usdt.json @@ -0,0 +1,42 @@ +{ + "error": [], + "result": [ + { + "method": "USDT - Ethereum (Unified)", + "limit": false, + "gen-address": true, + "minimum": "7.11000000" + }, + { + "method": "Tether USD (TRC20)", + "limit": false, + "gen-address": true, + "minimum": "5.00000000" + }, + { + "method": "Tether USD (SPL)", + "limit": false, + "fee": "0.00000000", + "gen-address": true, + "minimum": "0.40000000" + }, + { + "method": "USDT - Polygon (Unified)", + "limit": false, + "gen-address": true, + "minimum": "2.00000000" + }, + { + "method": "USDT - Arbitrum One (Unified)", + "limit": false, + "gen-address": true, + "minimum": "2.50000000" + }, + { + "method": "USDT - Optimism (Unified)", + "limit": false, + "gen-address": true, + "minimum": "2.50000000" + } + ] +} diff --git a/xchange-kraken/src/test/resources/org/knowm/xchange/kraken/dto/account/example-deposit-methods-xrp.json b/xchange-kraken/src/test/resources/org/knowm/xchange/kraken/dto/account/example-deposit-methods-xrp.json new file mode 100644 index 00000000000..e435b6cb859 --- /dev/null +++ b/xchange-kraken/src/test/resources/org/knowm/xchange/kraken/dto/account/example-deposit-methods-xrp.json @@ -0,0 +1,11 @@ +{ + "error": [], + "result": [ + { + "method": "Ripple XRP", + "limit": false, + "gen-address": true, + "minimum": "1" + } + ] +} From e3443cb268f675dd927a71d65ce67f2188502e51 Mon Sep 17 00:00:00 2001 From: Donald Jackson Date: Thu, 28 Mar 2024 16:11:12 +0100 Subject: [PATCH 140/159] [kraken] add tests for deposit method caching --- .../knowm/xchange/kraken/KrakenAdapters.java | 7 +- .../service/KrakenAccountServiceRaw.java | 40 +++++++--- .../service/KrakenAccountServiceTest.java | 76 ++++++++++++++++++- 3 files changed, 108 insertions(+), 15 deletions(-) diff --git a/xchange-kraken/src/main/java/org/knowm/xchange/kraken/KrakenAdapters.java b/xchange-kraken/src/main/java/org/knowm/xchange/kraken/KrakenAdapters.java index 111e6bd6995..f6b55472c67 100644 --- a/xchange-kraken/src/main/java/org/knowm/xchange/kraken/KrakenAdapters.java +++ b/xchange-kraken/src/main/java/org/knowm/xchange/kraken/KrakenAdapters.java @@ -18,6 +18,7 @@ import org.knowm.xchange.dto.Order; import org.knowm.xchange.dto.Order.OrderStatus; import org.knowm.xchange.dto.Order.OrderType; +import org.knowm.xchange.dto.account.AddressWithTag; import org.knowm.xchange.dto.account.Balance; import org.knowm.xchange.dto.account.Fee; import org.knowm.xchange.dto.account.FundingRecord; @@ -332,8 +333,10 @@ public static OrderType adaptOrderType(KrakenType krakenType) { return krakenType.equals(KrakenType.BUY) ? OrderType.BID : OrderType.ASK; } - public static String adaptKrakenDepositAddress(KrakenDepositAddress[] krakenDepositAddress) { - return krakenDepositAddress[0].getAddress(); + public static AddressWithTag adaptKrakenDepositAddress(KrakenDepositAddress[] krakenDepositAddress) { + return AddressWithTag.builder() + .address(krakenDepositAddress[0].getAddress()) + .addressTag(krakenDepositAddress[0].getTag()).build(); } public static String adaptOrderId(KrakenOrderResponse orderResponse) { diff --git a/xchange-kraken/src/main/java/org/knowm/xchange/kraken/service/KrakenAccountServiceRaw.java b/xchange-kraken/src/main/java/org/knowm/xchange/kraken/service/KrakenAccountServiceRaw.java index 9624443f761..b94a4f8cff0 100644 --- a/xchange-kraken/src/main/java/org/knowm/xchange/kraken/service/KrakenAccountServiceRaw.java +++ b/xchange-kraken/src/main/java/org/knowm/xchange/kraken/service/KrakenAccountServiceRaw.java @@ -6,6 +6,7 @@ import java.util.Date; import java.util.List; import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Collectors; import lombok.extern.slf4j.Slf4j; import org.knowm.xchange.Exchange; @@ -41,7 +42,7 @@ @Slf4j public class KrakenAccountServiceRaw extends KrakenBaseService { - private KrakenDepositMethods[] depositMethods; + private ConcurrentHashMap depositMethods = new ConcurrentHashMap<>(); /** * Constructor @@ -85,20 +86,35 @@ public KrakenDepositAddress[] getDepositAddresses( public KrakenDepositMethods[] getDepositMethods(String assetPairs, String assets) throws IOException { - if (shouldCacheDepositMethods() && depositMethods != null) { - return depositMethods; + if (shouldCacheDepositMethods()) { + try { + return depositMethods.computeIfAbsent(String.format("%s%s", assetPairs, assets), k -> { + try { + return getDepositMethodsFromRemote(assetPairs, assets); + } catch (IOException e) { + throw new RuntimeException(e); + } + }); + } catch(RuntimeException e) { + if (e.getCause() instanceof IOException) { + throw (IOException) e.getCause(); + } + throw e; + } } - depositMethods = - checkResult( - kraken.getDepositMethods( - assetPairs, - assets, - exchange.getExchangeSpecification().getApiKey(), - signatureCreator, - exchange.getNonceFactory())); + return getDepositMethodsFromRemote(assetPairs, assets); + } - return depositMethods; + private KrakenDepositMethods[] getDepositMethodsFromRemote(String assetPairs, String assets) + throws IOException { + return checkResult( + kraken.getDepositMethods( + assetPairs, + assets, + exchange.getExchangeSpecification().getApiKey(), + signatureCreator, + exchange.getNonceFactory())); } protected String findDepositMethod(Currency currency, String network) throws IOException { diff --git a/xchange-kraken/src/test/java/org/knowm/xchange/kraken/service/KrakenAccountServiceTest.java b/xchange-kraken/src/test/java/org/knowm/xchange/kraken/service/KrakenAccountServiceTest.java index 3e4572571c1..3315d356277 100644 --- a/xchange-kraken/src/test/java/org/knowm/xchange/kraken/service/KrakenAccountServiceTest.java +++ b/xchange-kraken/src/test/java/org/knowm/xchange/kraken/service/KrakenAccountServiceTest.java @@ -2,8 +2,11 @@ import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; import static com.github.tomakehurst.wiremock.client.WireMock.post; +import static com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor; import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; +import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; +import static com.github.tomakehurst.wiremock.client.WireMock.verify; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -11,6 +14,7 @@ import lombok.extern.slf4j.Slf4j; import org.junit.Before; import org.junit.Test; +import org.knowm.xchange.Exchange; import org.knowm.xchange.currency.Currency; import org.knowm.xchange.dto.account.AddressWithTag; import org.knowm.xchange.exceptions.DepositAddressAmbiguousException; @@ -20,10 +24,12 @@ public class KrakenAccountServiceTest extends BaseWiremockTest { private KrakenAccountService classUnderTest; + private Exchange exchange; @Before public void setup() { - classUnderTest = (KrakenAccountService) createExchange().getAccountService(); + exchange = createExchange(); + classUnderTest = (KrakenAccountService) exchange.getAccountService(); } @Test @@ -132,4 +138,72 @@ public void testRequestDepositAddressUnknownCurrencyMultipleMethodsWithNetwork() assertThat(address.getAddress()).isEqualTo("testXrpAddress"); assertThat(address.getAddressTag()).isEqualTo("123"); } + + @Test + @SneakyThrows + public void testRequestDepositMethodCaching() { + stubFor( + post(urlPathEqualTo("/0/private/DepositMethods")) + .willReturn( + aResponse() + .withStatus(200) + .withHeader("Content-Type", "application/json") + .withBody( + loadFile( + "/org/knowm/xchange/kraken/dto/account/example-deposit-methods-trx.json")))); + + stubFor( + post(urlPathEqualTo("/0/private/DepositAddresses")) + .willReturn( + aResponse() + .withStatus(200) + .withHeader("Content-Type", "application/json") + .withBody( + loadFile( + "/org/knowm/xchange/kraken/dto/account/example-deposit-addresses-trx.json")))); + + exchange.getExchangeSpecification().setExchangeSpecificParametersItem("cacheDepositMethods", true); + + DefaultRequestDepositAddressParams params = + DefaultRequestDepositAddressParams.builder().currency(Currency.TRX).build(); + + classUnderTest.requestDepositAddress(params); + classUnderTest.requestDepositAddress(params); + + verify(1, postRequestedFor(urlEqualTo("/0/private/DepositMethods"))); + } + + @Test + @SneakyThrows + public void testRequestDepositMethodNoCache() { + stubFor( + post(urlPathEqualTo("/0/private/DepositMethods")) + .willReturn( + aResponse() + .withStatus(200) + .withHeader("Content-Type", "application/json") + .withBody( + loadFile( + "/org/knowm/xchange/kraken/dto/account/example-deposit-methods-trx.json")))); + + stubFor( + post(urlPathEqualTo("/0/private/DepositAddresses")) + .willReturn( + aResponse() + .withStatus(200) + .withHeader("Content-Type", "application/json") + .withBody( + loadFile( + "/org/knowm/xchange/kraken/dto/account/example-deposit-addresses-trx.json")))); + + DefaultRequestDepositAddressParams params = + DefaultRequestDepositAddressParams.builder().currency(Currency.TRX).build(); + + exchange.getExchangeSpecification().setExchangeSpecificParametersItem("cacheDepositMethods", false); + + classUnderTest.requestDepositAddress(params); + classUnderTest.requestDepositAddress(params); + + verify(2, postRequestedFor(urlEqualTo("/0/private/DepositMethods"))); + } } From 1136d614d088836166547039b4bbc75dc2d96a88 Mon Sep 17 00:00:00 2001 From: Donald Jackson Date: Thu, 28 Mar 2024 19:53:04 +0100 Subject: [PATCH 141/159] [kraken] apply formatting with com.spotify.fmt --- .../knowm/xchange/kraken/KrakenAdapters.java | 6 +++-- .../service/KrakenAccountServiceRaw.java | 25 +++++++++++-------- .../service/KrakenAccountServiceTest.java | 8 ++++-- 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/xchange-kraken/src/main/java/org/knowm/xchange/kraken/KrakenAdapters.java b/xchange-kraken/src/main/java/org/knowm/xchange/kraken/KrakenAdapters.java index f6b55472c67..5967272aa76 100644 --- a/xchange-kraken/src/main/java/org/knowm/xchange/kraken/KrakenAdapters.java +++ b/xchange-kraken/src/main/java/org/knowm/xchange/kraken/KrakenAdapters.java @@ -333,10 +333,12 @@ public static OrderType adaptOrderType(KrakenType krakenType) { return krakenType.equals(KrakenType.BUY) ? OrderType.BID : OrderType.ASK; } - public static AddressWithTag adaptKrakenDepositAddress(KrakenDepositAddress[] krakenDepositAddress) { + public static AddressWithTag adaptKrakenDepositAddress( + KrakenDepositAddress[] krakenDepositAddress) { return AddressWithTag.builder() .address(krakenDepositAddress[0].getAddress()) - .addressTag(krakenDepositAddress[0].getTag()).build(); + .addressTag(krakenDepositAddress[0].getTag()) + .build(); } public static String adaptOrderId(KrakenOrderResponse orderResponse) { diff --git a/xchange-kraken/src/main/java/org/knowm/xchange/kraken/service/KrakenAccountServiceRaw.java b/xchange-kraken/src/main/java/org/knowm/xchange/kraken/service/KrakenAccountServiceRaw.java index b94a4f8cff0..726690c2fc9 100644 --- a/xchange-kraken/src/main/java/org/knowm/xchange/kraken/service/KrakenAccountServiceRaw.java +++ b/xchange-kraken/src/main/java/org/knowm/xchange/kraken/service/KrakenAccountServiceRaw.java @@ -38,11 +38,14 @@ import org.knowm.xchange.kraken.dto.account.results.WithdrawStatusResult; import org.knowm.xchange.utils.DateUtils; -/** @author jamespedwards42 */ +/** + * @author jamespedwards42 + */ @Slf4j public class KrakenAccountServiceRaw extends KrakenBaseService { - private ConcurrentHashMap depositMethods = new ConcurrentHashMap<>(); + private ConcurrentHashMap depositMethods = + new ConcurrentHashMap<>(); /** * Constructor @@ -88,14 +91,16 @@ public KrakenDepositMethods[] getDepositMethods(String assetPairs, String assets throws IOException { if (shouldCacheDepositMethods()) { try { - return depositMethods.computeIfAbsent(String.format("%s%s", assetPairs, assets), k -> { - try { - return getDepositMethodsFromRemote(assetPairs, assets); - } catch (IOException e) { - throw new RuntimeException(e); - } - }); - } catch(RuntimeException e) { + return depositMethods.computeIfAbsent( + String.format("%s%s", assetPairs, assets), + k -> { + try { + return getDepositMethodsFromRemote(assetPairs, assets); + } catch (IOException e) { + throw new RuntimeException(e); + } + }); + } catch (RuntimeException e) { if (e.getCause() instanceof IOException) { throw (IOException) e.getCause(); } diff --git a/xchange-kraken/src/test/java/org/knowm/xchange/kraken/service/KrakenAccountServiceTest.java b/xchange-kraken/src/test/java/org/knowm/xchange/kraken/service/KrakenAccountServiceTest.java index 3315d356277..8f1d262a402 100644 --- a/xchange-kraken/src/test/java/org/knowm/xchange/kraken/service/KrakenAccountServiceTest.java +++ b/xchange-kraken/src/test/java/org/knowm/xchange/kraken/service/KrakenAccountServiceTest.java @@ -162,7 +162,9 @@ public void testRequestDepositMethodCaching() { loadFile( "/org/knowm/xchange/kraken/dto/account/example-deposit-addresses-trx.json")))); - exchange.getExchangeSpecification().setExchangeSpecificParametersItem("cacheDepositMethods", true); + exchange + .getExchangeSpecification() + .setExchangeSpecificParametersItem("cacheDepositMethods", true); DefaultRequestDepositAddressParams params = DefaultRequestDepositAddressParams.builder().currency(Currency.TRX).build(); @@ -199,7 +201,9 @@ public void testRequestDepositMethodNoCache() { DefaultRequestDepositAddressParams params = DefaultRequestDepositAddressParams.builder().currency(Currency.TRX).build(); - exchange.getExchangeSpecification().setExchangeSpecificParametersItem("cacheDepositMethods", false); + exchange + .getExchangeSpecification() + .setExchangeSpecificParametersItem("cacheDepositMethods", false); classUnderTest.requestDepositAddress(params); classUnderTest.requestDepositAddress(params); From 06b1b3f1c1ee6abdf5deea2210876ec0c7930f1e Mon Sep 17 00:00:00 2001 From: rizer1980 <4340180@gmail.com> Date: Wed, 10 Apr 2024 17:27:18 +0300 Subject: [PATCH 142/159] fix bybit futures error "symbol invalid" --- .../xchange/bybit/BybitAuthenticated.java | 27 ++---- .../dto/trade/BybitPlaceOrderPayload.java | 37 ++++++++ .../bybit/service/BybitTradeServiceRaw.java | 28 ++---- .../org/knowm/xchange/bybit/TradeExample.java | 94 +++++++++++++++++++ xchange-bybit/src/test/resources/logback.xml | 2 +- 5 files changed, 149 insertions(+), 39 deletions(-) create mode 100644 xchange-bybit/src/main/java/org/knowm/xchange/bybit/dto/trade/BybitPlaceOrderPayload.java create mode 100644 xchange-bybit/src/test/java/org/knowm/xchange/bybit/TradeExample.java diff --git a/xchange-bybit/src/main/java/org/knowm/xchange/bybit/BybitAuthenticated.java b/xchange-bybit/src/main/java/org/knowm/xchange/bybit/BybitAuthenticated.java index 9b39862e6ed..16fb0dea3d8 100644 --- a/xchange-bybit/src/main/java/org/knowm/xchange/bybit/BybitAuthenticated.java +++ b/xchange-bybit/src/main/java/org/knowm/xchange/bybit/BybitAuthenticated.java @@ -4,7 +4,7 @@ import static org.knowm.xchange.bybit.service.BybitDigest.X_BAPI_SIGN; import static org.knowm.xchange.bybit.service.BybitDigest.X_BAPI_TIMESTAMP; -import jakarta.ws.rs.FormParam; +import jakarta.ws.rs.Consumes; import jakarta.ws.rs.GET; import jakarta.ws.rs.HeaderParam; import jakarta.ws.rs.POST; @@ -13,7 +13,7 @@ import jakarta.ws.rs.QueryParam; import jakarta.ws.rs.core.MediaType; import java.io.IOException; -import java.math.BigDecimal; +import org.knowm.xchange.bybit.dto.trade.BybitPlaceOrderPayload; import org.knowm.xchange.bybit.dto.BybitResult; import org.knowm.xchange.bybit.dto.account.allcoins.BybitAllCoinsBalance; import org.knowm.xchange.bybit.dto.account.feerates.BybitFeeRates; @@ -84,16 +84,12 @@ BybitResult> getOpenOrders( */ @POST @Path("/order/create") + @Consumes(MediaType.APPLICATION_JSON) BybitResult placeMarketOrder( @HeaderParam(X_BAPI_API_KEY) String apiKey, @HeaderParam(X_BAPI_SIGN) ParamsDigest signature, @HeaderParam(X_BAPI_TIMESTAMP) SynchronizedValueFactory timestamp, - @FormParam("category") String category, - @FormParam("symbol") String symbol, - @FormParam("side") String side, - @FormParam("orderType") String orderType, - @FormParam("qty") BigDecimal qty, - @FormParam("orderLinkId") String orderLinkId) + BybitPlaceOrderPayload payload) throws IOException, BybitException; /** @@ -101,18 +97,13 @@ BybitResult placeMarketOrder( */ @POST @Path("/order/create") + @Consumes(MediaType.APPLICATION_JSON) BybitResult placeLimitOrder( @HeaderParam(X_BAPI_API_KEY) String apiKey, @HeaderParam(X_BAPI_SIGN) ParamsDigest signature, @HeaderParam(X_BAPI_TIMESTAMP) SynchronizedValueFactory timestamp, - @FormParam("category") String category, - @FormParam("symbol") String symbol, - @FormParam("side") String side, - @FormParam("orderType") String orderType, - @FormParam("qty") BigDecimal qty, - @FormParam("price") BigDecimal price, - @FormParam("positionIdx") Integer positionIdx, - @FormParam("orderLinkId") String orderLinkId, - @FormParam("reduceOnly") Boolean reduceOnly) - throws IOException, BybitException; + BybitPlaceOrderPayload payload) +// @FormParam("positionIdx") +// @FormParam("reduceOnly") + throws IOException,BybitException; } diff --git a/xchange-bybit/src/main/java/org/knowm/xchange/bybit/dto/trade/BybitPlaceOrderPayload.java b/xchange-bybit/src/main/java/org/knowm/xchange/bybit/dto/trade/BybitPlaceOrderPayload.java new file mode 100644 index 00000000000..3a870d035d9 --- /dev/null +++ b/xchange-bybit/src/main/java/org/knowm/xchange/bybit/dto/trade/BybitPlaceOrderPayload.java @@ -0,0 +1,37 @@ +package org.knowm.xchange.bybit.dto.trade; + +import java.math.BigDecimal; +import lombok.Getter; + +@Getter +public class BybitPlaceOrderPayload { + + private String category; + private String symbol; + private String side; + private String orderType; + private String qty; + private String orderLinkId; + private String price; + + public BybitPlaceOrderPayload(String category, String symbol, String side, String orderType, + BigDecimal qty, + String orderLinkId) { + this.category = category; + this.symbol = symbol; + this.side = side; + this.orderType = orderType; + this.qty = qty.toString(); + this.orderLinkId = orderLinkId; + } + public BybitPlaceOrderPayload(String category, String symbol, String side, String orderType, + BigDecimal qty, String orderLinkId, BigDecimal price) { + this.category = category; + this.symbol = symbol; + this.side = side; + this.orderType = orderType; + this.qty = qty.toString(); + this.orderLinkId = orderLinkId; + this.price = price.toString(); + } +} diff --git a/xchange-bybit/src/main/java/org/knowm/xchange/bybit/service/BybitTradeServiceRaw.java b/xchange-bybit/src/main/java/org/knowm/xchange/bybit/service/BybitTradeServiceRaw.java index db89d7312e0..37e2f4f430f 100644 --- a/xchange-bybit/src/main/java/org/knowm/xchange/bybit/service/BybitTradeServiceRaw.java +++ b/xchange-bybit/src/main/java/org/knowm/xchange/bybit/service/BybitTradeServiceRaw.java @@ -6,6 +6,7 @@ import java.math.BigDecimal; import org.knowm.xchange.Exchange; import org.knowm.xchange.bybit.dto.BybitCategory; +import org.knowm.xchange.bybit.dto.trade.BybitPlaceOrderPayload; import org.knowm.xchange.bybit.dto.BybitResult; import org.knowm.xchange.bybit.dto.trade.BybitOrderResponse; import org.knowm.xchange.bybit.dto.trade.BybitOrderType; @@ -33,17 +34,14 @@ public BybitResult> getBybitOrder( public BybitResult placeMarketOrder( BybitCategory category, String symbol, BybitSide side, BigDecimal qty, String orderLinkId) throws IOException { + BybitPlaceOrderPayload payload = new BybitPlaceOrderPayload(category.getValue(), + symbol, side.getValue(), BybitOrderType.MARKET.getValue(), qty, orderLinkId); BybitResult placeOrder = bybitAuthenticated.placeMarketOrder( apiKey, signatureCreator, nonceFactory, - category.getValue(), - symbol, - side.getValue(), - BybitOrderType.MARKET.getValue(), - qty, - orderLinkId); + payload); if (!placeOrder.isSuccess()) { throw createBybitExceptionFromResult(placeOrder); } @@ -51,27 +49,17 @@ public BybitResult placeMarketOrder( } public BybitResult placeLimitOrder( - BybitCategory category, - String symbol, - BybitSide side, - BigDecimal qty, - BigDecimal limitPrice, + BybitCategory category, String symbol, BybitSide side, BigDecimal qty, BigDecimal limitPrice, String orderLinkId) throws IOException { + BybitPlaceOrderPayload payload = new BybitPlaceOrderPayload(category.getValue(), + symbol, side.getValue(), BybitOrderType.LIMIT.getValue(), qty, orderLinkId, limitPrice); BybitResult placeOrder = bybitAuthenticated.placeLimitOrder( apiKey, signatureCreator, nonceFactory, - category.getValue(), - symbol, - side.getValue(), - BybitOrderType.LIMIT.getValue(), - qty, - limitPrice, - 0, - orderLinkId, - false); + payload); if (!placeOrder.isSuccess()) { throw createBybitExceptionFromResult(placeOrder); } diff --git a/xchange-bybit/src/test/java/org/knowm/xchange/bybit/TradeExample.java b/xchange-bybit/src/test/java/org/knowm/xchange/bybit/TradeExample.java new file mode 100644 index 00000000000..401da4889c1 --- /dev/null +++ b/xchange-bybit/src/test/java/org/knowm/xchange/bybit/TradeExample.java @@ -0,0 +1,94 @@ +package org.knowm.xchange.bybit; + +import static org.knowm.xchange.bybit.BybitExchange.SPECIFIC_PARAM_ACCOUNT_TYPE; + +import java.io.IOException; +import java.math.BigDecimal; +import org.knowm.xchange.Exchange; +import org.knowm.xchange.ExchangeFactory; +import org.knowm.xchange.ExchangeSpecification; +import org.knowm.xchange.bybit.dto.account.walletbalance.BybitAccountType; +import org.knowm.xchange.currency.CurrencyPair; +import org.knowm.xchange.derivative.FuturesContract; +import org.knowm.xchange.dto.Order.OrderType; +import org.knowm.xchange.dto.marketdata.Ticker; +import org.knowm.xchange.dto.trade.LimitOrder; +import org.knowm.xchange.dto.trade.MarketOrder; +import org.knowm.xchange.instrument.Instrument; + +public class TradeExample { + + public static void main(String[] args) throws InterruptedException { + try { + testTrade(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + public static void testTrade() throws IOException { + ExchangeSpecification exchangeSpecification = + new BybitExchange().getDefaultExchangeSpecification(); + exchangeSpecification.setApiKey(System.getProperty("test_api_key")); + exchangeSpecification.setSecretKey(System.getProperty("test_secret_key")); + exchangeSpecification.setExchangeSpecificParametersItem( + SPECIFIC_PARAM_ACCOUNT_TYPE, BybitAccountType.UNIFIED); // or FUND + Exchange exchange = ExchangeFactory.INSTANCE.createExchange( + exchangeSpecification); + Instrument ETH_USDT = new CurrencyPair("ETH/USDT"); + Instrument BTC_USDT_PERP = new FuturesContract(new CurrencyPair("BTC/USDT"), "PERP"); + Instrument ETH_USDT_PERP = new FuturesContract(new CurrencyPair("ETH/USDT"), "PERP"); + + System.out.printf("Wallets: %n%s%n", + exchange.getAccountService().getAccountInfo().getWallets()); + Ticker ticker = exchange + .getMarketDataService() + .getTicker(ETH_USDT_PERP); + System.out.println(ticker.toString()); + + System.out.printf("Instrument %s:%n %s", ETH_USDT, exchange.getExchangeMetaData() + .getInstruments().get(ETH_USDT)); + System.out.printf("Instrument %s:%n %s", ETH_USDT_PERP, exchange.getExchangeMetaData() + .getInstruments().get(ETH_USDT_PERP)); + + BigDecimal minAmountSpot = exchange.getExchangeMetaData().getInstruments().get(ETH_USDT) + .getMinimumAmount(); + BigDecimal minUSDTSpot = minAmountSpot.multiply(ticker.getLast()); + //buy + String marketSpotOrderId = + exchange + .getTradeService() + .placeMarketOrder( + new MarketOrder(OrderType.BID, minUSDTSpot, ETH_USDT)); + System.out.println("Market Spot order id: " + marketSpotOrderId); + //sell + marketSpotOrderId = + exchange + .getTradeService() + .placeMarketOrder( + new MarketOrder(OrderType.ASK, minAmountSpot, ETH_USDT)); + + System.out.println("Market Spot order id: " + marketSpotOrderId); + + BigDecimal minAmountFuture = exchange.getExchangeMetaData().getInstruments().get(ETH_USDT_PERP) + .getMinimumAmount(); + + //long + String marketFutureOrderId = + exchange + .getTradeService() + .placeMarketOrder( + new MarketOrder(OrderType.BID, minAmountFuture, ETH_USDT_PERP)); + System.out.println("Market Future order id: " + marketFutureOrderId); + + //short + String limitFutureOrderId = + exchange + .getTradeService() + .placeLimitOrder( + new LimitOrder(OrderType.ASK, minAmountFuture, ETH_USDT_PERP, "123213", null, + ticker.getLast())); + System.out.println("Limit Future order id: " + limitFutureOrderId); + } + +} diff --git a/xchange-bybit/src/test/resources/logback.xml b/xchange-bybit/src/test/resources/logback.xml index b193ec04c03..2a586567a6e 100644 --- a/xchange-bybit/src/test/resources/logback.xml +++ b/xchange-bybit/src/test/resources/logback.xml @@ -18,6 +18,6 @@ - + \ No newline at end of file From 78d67569f9a12d5a73d8c2ca7e9dae1af1ac2a0d Mon Sep 17 00:00:00 2001 From: rizer1980 <4340180@gmail.com> Date: Wed, 10 Apr 2024 18:06:08 +0300 Subject: [PATCH 143/159] fix bybit and deribit parse locale --- .../src/main/java/org/knowm/xchange/bybit/BybitAdapters.java | 3 ++- .../java/org/knowm/xchange/deribit/v2/DeribitAdapters.java | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) 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 a34ce5881e3..032a3928a53 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 @@ -7,6 +7,7 @@ import java.util.Arrays; import java.util.Date; import java.util.List; +import java.util.Locale; import org.knowm.xchange.bybit.dto.BybitCategory; import org.knowm.xchange.bybit.dto.BybitResult; import org.knowm.xchange.bybit.dto.account.allcoins.BybitAllCoinBalance; @@ -44,7 +45,7 @@ public class BybitAdapters { - private static final SimpleDateFormat OPTION_DATE_FORMAT = new SimpleDateFormat("ddMMMyy"); + private static final SimpleDateFormat OPTION_DATE_FORMAT = new SimpleDateFormat("ddMMMyy", Locale.US); public static final List QUOTE_CURRENCIES = Arrays.asList("USDT", "USDC", "BTC", "DAI"); public static Wallet adaptBybitBalances(List coinWalletBalances) { diff --git a/xchange-deribit/src/main/java/org/knowm/xchange/deribit/v2/DeribitAdapters.java b/xchange-deribit/src/main/java/org/knowm/xchange/deribit/v2/DeribitAdapters.java index ea5fcdb43ef..8ccc526757e 100644 --- a/xchange-deribit/src/main/java/org/knowm/xchange/deribit/v2/DeribitAdapters.java +++ b/xchange-deribit/src/main/java/org/knowm/xchange/deribit/v2/DeribitAdapters.java @@ -9,6 +9,7 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; +import java.util.Locale; import java.util.TreeMap; import java.util.stream.Collectors; import org.knowm.xchange.currency.Currency; @@ -53,7 +54,7 @@ public class DeribitAdapters { private static final String PERPETUAL = "PERPETUAL"; private static final int CURRENCY_SCALE = 8; private static final ThreadLocal DATE_PARSER = - ThreadLocal.withInitial(() -> new SimpleDateFormat("ddMMMyy")); + ThreadLocal.withInitial(() -> new SimpleDateFormat("ddMMMyy", Locale.US)); public static String adaptInstrumentName(Instrument instrument) { if (instrument instanceof FuturesContract) { From 5039eb5bed1a56d608650efc0c28e372e8389517 Mon Sep 17 00:00:00 2001 From: rizer1980 <4340180@gmail.com> Date: Fri, 12 Apr 2024 07:56:59 +0300 Subject: [PATCH 144/159] [bybit-stream] initial commit --- .../xchange/bybit/service/BybitDigest.java | 6 +- xchange-stream-bybit/pom.xml | 31 ++++ .../main/java/dto/BybitSubscribeMessage.java | 13 ++ .../java/dto/marketdata/BybitOrderbook.java | 22 +++ .../dto/marketdata/BybitOrderbookData.java | 33 ++++ .../java/dto/marketdata/BybitPublicOrder.java | 18 ++ .../src/main/java/dto/trade/BybitTrade.java | 42 +++++ .../bybit/BybitStreamAdapters.java | 62 +++++++ .../bybit/BybitStreamingExchange.java | 76 ++++++++ .../BybitStreamingMarketDataService.java | 170 ++++++++++++++++++ .../bybit/BybitStreamingService.java | 107 +++++++++++ .../bybit/BybitStreamExample.java | 139 ++++++++++++++ .../src/test/resources/logback.xml | 27 +++ 13 files changed, 745 insertions(+), 1 deletion(-) create mode 100644 xchange-stream-bybit/pom.xml create mode 100644 xchange-stream-bybit/src/main/java/dto/BybitSubscribeMessage.java create mode 100644 xchange-stream-bybit/src/main/java/dto/marketdata/BybitOrderbook.java create mode 100644 xchange-stream-bybit/src/main/java/dto/marketdata/BybitOrderbookData.java create mode 100644 xchange-stream-bybit/src/main/java/dto/marketdata/BybitPublicOrder.java create mode 100644 xchange-stream-bybit/src/main/java/dto/trade/BybitTrade.java create mode 100644 xchange-stream-bybit/src/main/java/info/bitrich/xchangestream/bybit/BybitStreamAdapters.java create mode 100644 xchange-stream-bybit/src/main/java/info/bitrich/xchangestream/bybit/BybitStreamingExchange.java create mode 100644 xchange-stream-bybit/src/main/java/info/bitrich/xchangestream/bybit/BybitStreamingMarketDataService.java create mode 100644 xchange-stream-bybit/src/main/java/info/bitrich/xchangestream/bybit/BybitStreamingService.java create mode 100644 xchange-stream-bybit/src/test/java/info/bitrich/xchangestream/bybit/BybitStreamExample.java create mode 100644 xchange-stream-bybit/src/test/resources/logback.xml diff --git a/xchange-bybit/src/main/java/org/knowm/xchange/bybit/service/BybitDigest.java b/xchange-bybit/src/main/java/org/knowm/xchange/bybit/service/BybitDigest.java index bb1e26e4ff3..e1642efa265 100644 --- a/xchange-bybit/src/main/java/org/knowm/xchange/bybit/service/BybitDigest.java +++ b/xchange-bybit/src/main/java/org/knowm/xchange/bybit/service/BybitDigest.java @@ -28,7 +28,11 @@ public BybitDigest(String secretKeyBase64) { } public static ParamsDigest createInstance(String secretKeyBase64) { - return new BybitDigest(secretKeyBase64); + if (secretKeyBase64 != null) { + return new BybitDigest(secretKeyBase64); + } else { + return null; + } } @SneakyThrows diff --git a/xchange-stream-bybit/pom.xml b/xchange-stream-bybit/pom.xml new file mode 100644 index 00000000000..71b2943843b --- /dev/null +++ b/xchange-stream-bybit/pom.xml @@ -0,0 +1,31 @@ + + + + 4.0.0 + + + org.knowm.xchange + xchange-parent + 5.1.2-SNAPSHOT + + + XChange Bybit Stream + xchange-stream-bybit + + + + org.knowm.xchange + xchange-stream-core + ${project.parent.version} + + + org.knowm.xchange + xchange-bybit + ${project.parent.version} + + + + + \ No newline at end of file diff --git a/xchange-stream-bybit/src/main/java/dto/BybitSubscribeMessage.java b/xchange-stream-bybit/src/main/java/dto/BybitSubscribeMessage.java new file mode 100644 index 00000000000..e3c01595d52 --- /dev/null +++ b/xchange-stream-bybit/src/main/java/dto/BybitSubscribeMessage.java @@ -0,0 +1,13 @@ +package dto; + +import java.util.List; +import lombok.AllArgsConstructor; +import lombok.Data; + +@Data +@AllArgsConstructor +public class BybitSubscribeMessage { + private final String op; + private final List args; + } + diff --git a/xchange-stream-bybit/src/main/java/dto/marketdata/BybitOrderbook.java b/xchange-stream-bybit/src/main/java/dto/marketdata/BybitOrderbook.java new file mode 100644 index 00000000000..7ba6df89560 --- /dev/null +++ b/xchange-stream-bybit/src/main/java/dto/marketdata/BybitOrderbook.java @@ -0,0 +1,22 @@ +package dto.marketdata; + +import java.beans.ConstructorProperties; +import lombok.Getter; + +@Getter +public class BybitOrderbook { + + private final String topic; + private final String dataType; + private final String ts; + private final BybitOrderbookData data; + + @ConstructorProperties({"topic","type","ts","data"}) + public BybitOrderbook(String topic, String dataType, String ts, BybitOrderbookData data) { + this.topic = topic; + this.dataType = dataType; + this.ts = ts; + this.data = data; + } + +} diff --git a/xchange-stream-bybit/src/main/java/dto/marketdata/BybitOrderbookData.java b/xchange-stream-bybit/src/main/java/dto/marketdata/BybitOrderbookData.java new file mode 100644 index 00000000000..fc613a392ce --- /dev/null +++ b/xchange-stream-bybit/src/main/java/dto/marketdata/BybitOrderbookData.java @@ -0,0 +1,33 @@ +package dto.marketdata; + +import java.beans.ConstructorProperties; +import java.util.List; +import lombok.Getter; + +@Getter +public class BybitOrderbookData { + + private final String symbolName; + private final List bid; + private final List ask; + // Update ID. Is a sequence. Occasionally, you'll receive "u"=1, which is a snapshot data due to + // the restart of the service. So please overwrite your local orderbook + private final Integer u; + // Cross sequence + // You can use this field to compare different levels orderbook data, and for the smaller seq, + // then it means the data is generated earlier. + // in docs says than it is Integer, but in fact, we get in response bigger numbers + private final Long seq; + + @ConstructorProperties({"s", "b", "a", "u", "seq"}) + public BybitOrderbookData(String symbolName, List bid, + List ask, + Integer u, + Long seq) { + this.symbolName = symbolName; + this.bid = bid; + this.ask = ask; + this.u = u; + this.seq = seq; + } +} diff --git a/xchange-stream-bybit/src/main/java/dto/marketdata/BybitPublicOrder.java b/xchange-stream-bybit/src/main/java/dto/marketdata/BybitPublicOrder.java new file mode 100644 index 00000000000..55954ca82a1 --- /dev/null +++ b/xchange-stream-bybit/src/main/java/dto/marketdata/BybitPublicOrder.java @@ -0,0 +1,18 @@ +package dto.marketdata; + +import com.fasterxml.jackson.annotation.JsonCreator; +import lombok.Getter; + +@Getter +public class BybitPublicOrder { + + private final String price; + private final String size; + + @JsonCreator + public BybitPublicOrder(String[] data) { + this.price = data[0]; + this.size = data[1]; + } +} + diff --git a/xchange-stream-bybit/src/main/java/dto/trade/BybitTrade.java b/xchange-stream-bybit/src/main/java/dto/trade/BybitTrade.java new file mode 100644 index 00000000000..a0ac503f2ef --- /dev/null +++ b/xchange-stream-bybit/src/main/java/dto/trade/BybitTrade.java @@ -0,0 +1,42 @@ +package dto.trade; + +import com.fasterxml.jackson.annotation.JsonProperty; +import java.math.BigDecimal; +import java.util.Date; +import lombok.Getter; +import org.knowm.xchange.bybit.dto.trade.BybitSide; + +@Getter +public class BybitTrade { + + //https://bybit-exchange.github.io/docs/v5/websocket/public/trad + //The timestamp (ms) that the order is filled + private final Date timestamp; + //Symbol name + private final String instId; + //Side of taker. Buy,Sell + private final BybitSide side; + private final BigDecimal tradeSize; + private final BigDecimal tradePrice; + //L string Direction of price change. Unique field for future + private final String direction; + private final String tradeId; + //boolean Whether it is a block trade order or not + private final boolean bT; + + + public BybitTrade(@JsonProperty("T") Date timestamp, @JsonProperty("s") String instId, + @JsonProperty("S") String side, @JsonProperty("v") BigDecimal tradeSize, + @JsonProperty("p") BigDecimal tradePrice, @JsonProperty("L") String direction, + @JsonProperty("i") String tradeId, @JsonProperty("BT") boolean bT) { + this.timestamp = timestamp; + this.instId = instId; + this.side = BybitSide.valueOf(side.toUpperCase()); + this.tradeSize = tradeSize; + this.tradePrice = tradePrice; + this.direction = direction; + this.tradeId = tradeId; + this.bT = bT; + } +} + diff --git a/xchange-stream-bybit/src/main/java/info/bitrich/xchangestream/bybit/BybitStreamAdapters.java b/xchange-stream-bybit/src/main/java/info/bitrich/xchangestream/bybit/BybitStreamAdapters.java new file mode 100644 index 00000000000..d5b1808cc01 --- /dev/null +++ b/xchange-stream-bybit/src/main/java/info/bitrich/xchangestream/bybit/BybitStreamAdapters.java @@ -0,0 +1,62 @@ +package info.bitrich.xchangestream.bybit; + +import static org.knowm.xchange.bybit.BybitAdapters.getOrderType; + +import dto.marketdata.BybitPublicOrder; +import dto.trade.BybitTrade; +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import dto.marketdata.BybitOrderbook; +import org.knowm.xchange.dto.Order; +import org.knowm.xchange.dto.Order.OrderType; +import org.knowm.xchange.dto.marketdata.OrderBook; +import org.knowm.xchange.dto.marketdata.Trade; +import org.knowm.xchange.dto.marketdata.Trades; +import org.knowm.xchange.dto.trade.LimitOrder; +import org.knowm.xchange.instrument.Instrument; + +public class BybitStreamAdapters { + public static OrderBook adaptOrderBook(BybitOrderbook bybitOrderbooks, Instrument instrument) { + List asks = new ArrayList<>(); + List bids = new ArrayList<>(); + Date timestamp = new Date(Long.parseLong(bybitOrderbooks.getTs())); + bybitOrderbooks.getData().getAsk() + .forEach(bybitAsk -> asks.add( + adaptOrderBookOrder(bybitAsk, instrument, OrderType.ASK,timestamp))); + + bybitOrderbooks.getData().getBid() + .forEach(bybitBid -> bids.add( + adaptOrderBookOrder(bybitBid, instrument, OrderType.BID,timestamp))); + + return new OrderBook(timestamp,asks, bids); + } + + public static Trades adaptTrades(List bybitTrades, Instrument instrument) { + List trades = new ArrayList<>(); + + bybitTrades.forEach( + bybitTrade -> + trades.add( + new Trade.Builder() + .id(bybitTrade.getTradeId()) + .instrument(instrument) + .originalAmount(bybitTrade.getTradeSize()) + .price(bybitTrade.getTradePrice()) + .timestamp(bybitTrade.getTimestamp()) + .type(getOrderType(bybitTrade.getSide())) + .build())); + + return new Trades(trades); + } + + public static LimitOrder adaptOrderBookOrder(BybitPublicOrder bybitPublicOrder, + Instrument instrument, Order.OrderType orderType, Date timestamp) { + + return new LimitOrder(orderType, new BigDecimal(bybitPublicOrder.getSize()), instrument, "", + timestamp, new BigDecimal(bybitPublicOrder.getPrice())); + } + + +} diff --git a/xchange-stream-bybit/src/main/java/info/bitrich/xchangestream/bybit/BybitStreamingExchange.java b/xchange-stream-bybit/src/main/java/info/bitrich/xchangestream/bybit/BybitStreamingExchange.java new file mode 100644 index 00000000000..5482484bb0e --- /dev/null +++ b/xchange-stream-bybit/src/main/java/info/bitrich/xchangestream/bybit/BybitStreamingExchange.java @@ -0,0 +1,76 @@ +package info.bitrich.xchangestream.bybit; + +import info.bitrich.xchangestream.core.ProductSubscription; +import info.bitrich.xchangestream.core.StreamingExchange; +import io.reactivex.Completable; +import org.knowm.xchange.bybit.BybitExchange; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class BybitStreamingExchange extends BybitExchange implements StreamingExchange { + + private final Logger LOG = LoggerFactory.getLogger(BybitStreamingExchange.class); + + //https://bybit-exchange.github.io/docs/v5/ws/connect + public static final String URI = "wss://stream.bybit.com/v5/public"; + public static final String TESTNET_URI = "wss://stream-testnet.bybit.com/v5/public"; + public static final String AUTH_URI = "wss://stream.bybit.com/v5/private"; + public static final String TESTNET_AUTH_URI = "wss://stream-testnet.bybit.com/v5/private"; + + //spot, linear, inverse or option + public static final String EXCHANGE_TYPE = "EXCHANGE_TYPE"; + + private BybitStreamingService streamingService; + private BybitStreamingMarketDataService streamingMarketDataService; + + @Override + protected void initServices() { + super.initServices(); + this.streamingService = new BybitStreamingService(getApiUrl(), + exchangeSpecification.getExchangeSpecificParametersItem(EXCHANGE_TYPE)); + this.streamingMarketDataService = new BybitStreamingMarketDataService(streamingService); + } + + private String getApiUrl() { + String apiUrl = null; + if (exchangeSpecification.getApiKey() == null) { + if (Boolean.TRUE.equals( + exchangeSpecification.getExchangeSpecificParametersItem(USE_SANDBOX))) { + apiUrl = TESTNET_URI; + } else { + apiUrl = URI; + } + apiUrl += "/" + exchangeSpecification.getExchangeSpecificParametersItem(EXCHANGE_TYPE); + } +// TODO auth + return apiUrl; + } + + @Override + public Completable connect(ProductSubscription... args) { + LOG.info("Connect to BybitStream"); + return streamingService.connect(); + } + + @Override + public Completable disconnect() { + streamingService.pingPongDisconnectIfConnected(); + return streamingService.disconnect(); + } + + @Override + public boolean isAlive() { + return streamingService != null && streamingService.isSocketOpen(); + } + + @Override + public void useCompressedMessages(boolean compressedMessages) { + streamingService.useCompressedMessages(compressedMessages); + } + + @Override + public BybitStreamingMarketDataService getStreamingMarketDataService() { + return streamingMarketDataService; + } + +} diff --git a/xchange-stream-bybit/src/main/java/info/bitrich/xchangestream/bybit/BybitStreamingMarketDataService.java b/xchange-stream-bybit/src/main/java/info/bitrich/xchangestream/bybit/BybitStreamingMarketDataService.java new file mode 100644 index 00000000000..0b52b6b248b --- /dev/null +++ b/xchange-stream-bybit/src/main/java/info/bitrich/xchangestream/bybit/BybitStreamingMarketDataService.java @@ -0,0 +1,170 @@ +package info.bitrich.xchangestream.bybit; + +import static org.knowm.xchange.bybit.BybitAdapters.convertToBybitSymbol; + +import com.fasterxml.jackson.databind.ObjectMapper; +import dto.marketdata.BybitPublicOrder; +import info.bitrich.xchangestream.core.StreamingMarketDataService; +import info.bitrich.xchangestream.service.netty.StreamingObjectMapperHelper; +import io.reactivex.Observable; +import io.reactivex.subjects.PublishSubject; +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import dto.marketdata.BybitOrderbook; +import dto.trade.BybitTrade; +import org.knowm.xchange.dto.Order; +import org.knowm.xchange.dto.marketdata.OrderBook; +import org.knowm.xchange.dto.marketdata.OrderBookUpdate; +import org.knowm.xchange.dto.marketdata.Trade; +import org.knowm.xchange.instrument.Instrument; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class BybitStreamingMarketDataService implements StreamingMarketDataService { + + private final Logger LOG = LoggerFactory.getLogger(BybitStreamingMarketDataService.class); + private final BybitStreamingService streamingService; + private final ObjectMapper mapper = StreamingObjectMapperHelper.getObjectMapper(); + public static final String TRADE = "publicTrade."; + public static final String ORDERBOOK = "orderbook."; + public static final String TICKER = "tickers."; + + private final Map orderBookMap = new HashMap<>(); + private long orderBookUpdateIdPrev; + private final Map>> + orderBookUpdatesSubscriptions; + + public BybitStreamingMarketDataService(BybitStreamingService streamingService) { + this.streamingService = streamingService; + this.orderBookUpdatesSubscriptions = new ConcurrentHashMap<>(); + } + + /** + * Linear & inverse: Level 1 data, push frequency: 10ms Level 50 data, push frequency: 20ms Level + * 200 data, push frequency: 100ms Level 500 data, push frequency: 100ms Spot: Level 1 data, push + * frequency: 10ms Level 50 data, push frequency: 20ms Level 200 data, push frequency: 200ms + * + * @param args - orderbook depth + **/ + @Override + public Observable getOrderBook(Instrument instrument, Object... args) { + String depth = "50"; + if (args.length > 0 && args[0] != null) { + depth = args[0].toString(); + } + String channelUniqueId = + ORDERBOOK + depth + "." + convertToBybitSymbol(instrument); + return streamingService + .subscribeChannel(channelUniqueId) + .flatMap( + jsonNode -> { + BybitOrderbook bybitOrderbooks = + mapper.treeToValue(jsonNode, BybitOrderbook.class); + String type = bybitOrderbooks.getDataType(); + if (type.equalsIgnoreCase("snapshot")) { + OrderBook orderBook = BybitStreamAdapters.adaptOrderBook(bybitOrderbooks, instrument); + orderBookUpdateIdPrev = bybitOrderbooks.getData().getU(); + orderBookMap.put(channelUniqueId, orderBook); + return Observable.just(orderBook); + } else if (type.equalsIgnoreCase("delta")) { + return applyDeltaSnapshot(channelUniqueId, instrument, bybitOrderbooks); + } + return Observable.fromIterable(new LinkedList<>()); + }); + } + + private Observable applyDeltaSnapshot(String channelUniqueId, Instrument instrument, + BybitOrderbook bybitOrderBookUpdate) { + OrderBook orderBook = orderBookMap.getOrDefault(channelUniqueId, null); + if (orderBook == null) { + LOG.error("Failed to get orderBook, channelUniqueId= {}", channelUniqueId); + return Observable.fromIterable(new LinkedList<>()); + } + orderBookUpdateIdPrev++; + if (orderBookUpdateIdPrev == bybitOrderBookUpdate.getData().getU()) { + LOG.debug("orderBookUpdate id {}, seq {} ", bybitOrderBookUpdate.getData().getU(), + bybitOrderBookUpdate.getData().getSeq()); + List asks = bybitOrderBookUpdate.getData().getAsk(); + List bids = bybitOrderBookUpdate.getData().getBid(); + Date timestamp = new Date(Long.parseLong(bybitOrderBookUpdate.getTs())); + asks.forEach( + bybitPublicOrder -> + orderBook.update( + BybitStreamAdapters.adaptOrderBookOrder( + bybitPublicOrder, instrument, Order.OrderType.ASK, timestamp))); + bids.forEach( + bybitPublicOrder -> + orderBook.update( + BybitStreamAdapters.adaptOrderBookOrder( + bybitPublicOrder, instrument, Order.OrderType.BID, timestamp))); + if (orderBookUpdatesSubscriptions.get(instrument) != null) { + orderBookUpdatesSubscriptions(instrument, asks, bids, timestamp); + } + return Observable.just(orderBook); + } else { + LOG.error("orderBookUpdate id sequence failed, expected {}, in fact {}", + orderBookUpdateIdPrev, + bybitOrderBookUpdate.getData().getU()); + // resubscribe or what here? + return Observable.fromIterable(new LinkedList<>()); + } + } + + public Observable> getOrderBookUpdates(Instrument instrument) { + return orderBookUpdatesSubscriptions.computeIfAbsent(instrument, v -> PublishSubject.create()); + } + + private void orderBookUpdatesSubscriptions( + Instrument instrument, List asks, List bids, Date date) { + List orderBookUpdates = new ArrayList<>(); + for (BybitPublicOrder ask : asks) { + OrderBookUpdate o = + new OrderBookUpdate( + Order.OrderType.ASK, + new BigDecimal(ask.getSize()), + instrument, + new BigDecimal(ask.getPrice()), + date, + new BigDecimal(ask.getSize())); + orderBookUpdates.add(o); + } + for (BybitPublicOrder bid : bids) { + OrderBookUpdate o = + new OrderBookUpdate( + Order.OrderType.BID, + new BigDecimal(bid.getSize()), + instrument, + new BigDecimal(bid.getPrice()), + date, + new BigDecimal(bid.getSize())); + orderBookUpdates.add(o); + } + orderBookUpdatesSubscriptions.get(instrument).onNext(orderBookUpdates); + } + + @Override + public Observable getTrades(Instrument instrument, Object... args) { + String channelUniqueId = + TRADE + convertToBybitSymbol(instrument); + + return streamingService + .subscribeChannel(channelUniqueId) + .filter(message -> message.has("data")) + .flatMap( + jsonNode -> { + List bybitTradeList = + mapper.treeToValue( + jsonNode.get("data"), + mapper.getTypeFactory() + .constructCollectionType(List.class, BybitTrade.class)); + return Observable.fromIterable( + BybitStreamAdapters.adaptTrades(bybitTradeList, instrument).getTrades()); + }); + } +} diff --git a/xchange-stream-bybit/src/main/java/info/bitrich/xchangestream/bybit/BybitStreamingService.java b/xchange-stream-bybit/src/main/java/info/bitrich/xchangestream/bybit/BybitStreamingService.java new file mode 100644 index 00000000000..d1d0e57006b --- /dev/null +++ b/xchange-stream-bybit/src/main/java/info/bitrich/xchangestream/bybit/BybitStreamingService.java @@ -0,0 +1,107 @@ +package info.bitrich.xchangestream.bybit; + +import com.fasterxml.jackson.databind.JsonNode; +import dto.BybitSubscribeMessage; +import info.bitrich.xchangestream.service.netty.JsonNettyStreamingService; +import info.bitrich.xchangestream.service.netty.WebSocketClientCompressionAllowClientNoContextAndServerNoContextHandler; +import io.netty.handler.codec.http.websocketx.extensions.WebSocketClientExtensionHandler; +import io.reactivex.Completable; +import io.reactivex.CompletableSource; +import io.reactivex.Observable; +import io.reactivex.disposables.Disposable; +import java.io.IOException; +import java.util.Collections; +import java.util.concurrent.TimeUnit; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class BybitStreamingService extends JsonNettyStreamingService { + + private final Logger LOG = LoggerFactory.getLogger(BybitStreamingService.class); + public final String exchange_type; + private final Observable pingPongSrc = Observable.interval(15, 20, TimeUnit.SECONDS); + private Disposable pingPongSubscription; + + public BybitStreamingService(String apiUrl, Object exchange_type) { + super(apiUrl); + this.exchange_type = (String) exchange_type; +// this.setEnableLoggingHandler(true); + } + + @Override + public Completable connect() { + Completable conn = super.connect(); + return conn.andThen( + (CompletableSource) + (completable) -> { + pingPongDisconnectIfConnected(); + pingPongSubscription = pingPongSrc.subscribe( + o -> this.sendMessage("{\"op\":\"ping\"}")); + completable.onComplete(); + }); + } + + @Override + protected String getChannelNameFromMessage(JsonNode message) { + if (message.has("topic")) { + return message.get("topic").asText(); + } + return ""; + } + + @Override + public String getSubscribeMessage(String channelName, Object... args) throws IOException { + LOG.info(" getSubscribeMessage {}", channelName); + return objectMapper.writeValueAsString( + new BybitSubscribeMessage("subscribe", Collections.singletonList(channelName))); + } + + @Override + public String getUnsubscribeMessage(String channelName, Object... args) throws IOException { + LOG.info(" getUnsubscribeMessage {}", channelName); + return objectMapper.writeValueAsString( + new BybitSubscribeMessage("unsubscribe", Collections.singletonList(channelName))); + } + + @Override + public void messageHandler(String message) { + LOG.debug("Received message: {}", message); + JsonNode jsonNode; + try { + jsonNode = objectMapper.readTree(message); + } catch (IOException e) { + LOG.error("Error parsing incoming message to JSON: {}", message); + return; + } + String op = ""; + boolean success = false; + if (jsonNode.has("op")) { + op = jsonNode.get("op").asText(); + } + if (jsonNode.has("success")) { + success = jsonNode.get("success").asBoolean(); + } + if (success) { + switch (op) { + case "pong": + case "subscribe": + case "unsubscribe": { + break; + } + } + return; + } + handleMessage(jsonNode); + } + + public void pingPongDisconnectIfConnected() { + if (pingPongSubscription != null && !pingPongSubscription.isDisposed()) { + pingPongSubscription.dispose(); + } + } + + @Override + protected WebSocketClientExtensionHandler getWebSocketClientExtensionHandler() { + return WebSocketClientCompressionAllowClientNoContextAndServerNoContextHandler.INSTANCE; + } +} diff --git a/xchange-stream-bybit/src/test/java/info/bitrich/xchangestream/bybit/BybitStreamExample.java b/xchange-stream-bybit/src/test/java/info/bitrich/xchangestream/bybit/BybitStreamExample.java new file mode 100644 index 00000000000..8c3ce8e3969 --- /dev/null +++ b/xchange-stream-bybit/src/test/java/info/bitrich/xchangestream/bybit/BybitStreamExample.java @@ -0,0 +1,139 @@ +package info.bitrich.xchangestream.bybit; + +import static org.knowm.xchange.Exchange.USE_SANDBOX; +import static org.knowm.xchange.bybit.BybitExchange.SPECIFIC_PARAM_ACCOUNT_TYPE; + +import info.bitrich.xchangestream.core.StreamingExchange; +import info.bitrich.xchangestream.core.StreamingExchangeFactory; +import io.reactivex.disposables.Disposable; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import org.knowm.xchange.ExchangeSpecification; +import org.knowm.xchange.bybit.dto.BybitCategory; +import org.knowm.xchange.bybit.dto.account.walletbalance.BybitAccountType; +import org.knowm.xchange.currency.CurrencyPair; +import org.knowm.xchange.derivative.FuturesContract; +import org.knowm.xchange.derivative.OptionsContract; +import org.knowm.xchange.instrument.Instrument; + + +public class BybitStreamExample { + + public static void main(String[] args) { + try { + spot(); + + } catch (IOException e) { + throw new RuntimeException(e); + } + futures(); + } + + private static final Instrument BTC_PERP = new FuturesContract("BTC/USDT/PERP"); + private static final Instrument ETH_PERP = new CurrencyPair("ETH/USDT/PERP"); + private static final Instrument BTC_SPOT = new CurrencyPair("BTC/USDT"); + private static final Instrument ETH_SPOT = new CurrencyPair("ETH/USDT"); + + public static void spot() throws IOException { + ExchangeSpecification exchangeSpecification = + new ExchangeSpecification(BybitStreamingExchange.class); + exchangeSpecification.setExchangeSpecificParametersItem(USE_SANDBOX, true); + exchangeSpecification.setExchangeSpecificParametersItem(BybitStreamingExchange.EXCHANGE_TYPE, + BybitCategory.SPOT.getValue()); + exchangeSpecification.setExchangeSpecificParametersItem(SPECIFIC_PARAM_ACCOUNT_TYPE, + BybitAccountType.UNIFIED); + StreamingExchange exchange = StreamingExchangeFactory.INSTANCE.createExchange( + exchangeSpecification); + exchange.connect().blockingAwait(); + int count_currencyPair = 0; + int count_futureContractPerp = 0; + int count_futureContractDate = 0; + List instruments = new ArrayList<>(exchange + .getExchangeMetaData() + .getInstruments().keySet()); + for (Instrument instrument : instruments) { + if (instrument instanceof CurrencyPair) { + count_currencyPair++; + } + if (instrument instanceof FuturesContract) { + count_futureContractPerp++; + } + if (instrument instanceof OptionsContract) { + count_futureContractDate++; + } + } + System.out.println("Currency pairs: " + count_currencyPair); + System.out.println("Futures: " + count_futureContractPerp); + System.out.println("Futures date: " + count_futureContractDate); + + System.out.println(exchange.getMarketDataService().getTicker(BTC_SPOT)); + System.out.println(exchange.getMarketDataService().getTicker(BTC_PERP)); + List tradesDisposable = new ArrayList<>(); + Disposable bookDisposable = + exchange + .getStreamingMarketDataService() + .getOrderBook(ETH_SPOT) + .subscribe(); + tradesDisposable.add(exchange + .getStreamingMarketDataService().getTrades(ETH_SPOT).subscribe( + trade -> System.out.println("trade: " + trade))); + tradesDisposable.add(exchange + .getStreamingMarketDataService().getTrades(BTC_SPOT).subscribe( + trade -> System.out.println("trade: " + trade))); + try { + Thread.sleep(2000); + } catch ( + InterruptedException ignored) { + } + bookDisposable.dispose(); + for(Disposable disposable:tradesDisposable) + disposable.dispose(); + + try { + Thread.sleep(5000); + } catch ( + InterruptedException ignored) { + } + exchange.disconnect().blockingAwait(); + } + + + public static void futures() { + ExchangeSpecification exchangeSpecification = + new ExchangeSpecification(BybitStreamingExchange.class); + exchangeSpecification.setExchangeSpecificParametersItem(SPECIFIC_PARAM_ACCOUNT_TYPE, + BybitAccountType.UNIFIED); + exchangeSpecification.setExchangeSpecificParametersItem(BybitStreamingExchange.EXCHANGE_TYPE, + BybitCategory.LINEAR.getValue()); + StreamingExchange exchange = StreamingExchangeFactory.INSTANCE.createExchange( + exchangeSpecification); + exchange.connect().blockingAwait(); + List tradesDisposable = new ArrayList<>(); + Disposable booksDisposable = + exchange + .getStreamingMarketDataService() + .getOrderBook(BTC_PERP) + .subscribe(); + + tradesDisposable.add(exchange + .getStreamingMarketDataService().getTrades(ETH_PERP).subscribe( + trade -> System.out.println("trade: " + trade))); + try { + Thread.sleep(2000); + } catch (InterruptedException ignored) { + + } + booksDisposable.dispose(); + for(Disposable disposable:tradesDisposable) + disposable.dispose(); + + try { + Thread.sleep(5000); + } catch (InterruptedException ignored) { + + } + exchange.disconnect().blockingAwait(); + } + +} diff --git a/xchange-stream-bybit/src/test/resources/logback.xml b/xchange-stream-bybit/src/test/resources/logback.xml new file mode 100644 index 00000000000..fabc864484c --- /dev/null +++ b/xchange-stream-bybit/src/test/resources/logback.xml @@ -0,0 +1,27 @@ + + + + + + + + + %d{HH:mm:ss.SSS} [%contextName] [%thread] %-5level %logger{36} - %msg %xEx%n + + + + + + + + + + + + + + + + + + \ No newline at end of file From 91015addd09715e716419ff3110a023c5aba06ea Mon Sep 17 00:00:00 2001 From: rizer1980 <4340180@gmail.com> Date: Fri, 12 Apr 2024 14:54:54 +0300 Subject: [PATCH 145/159] [bybit-stream] fix --- pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pom.xml b/pom.xml index 0250003299b..1d03b5371fd 100644 --- a/pom.xml +++ b/pom.xml @@ -188,6 +188,7 @@ xchange-stream-bitmex xchange-stream-bitstamp xchange-stream-btcmarkets + xchange-stream-bybit xchange-stream-cexio xchange-stream-coinbasepro xchange-stream-coinjar From ca33bd99a382e7dd74edc23f678a56f736546462 Mon Sep 17 00:00:00 2001 From: rizer1980 <4340180@gmail.com> Date: Fri, 12 Apr 2024 19:12:50 +0300 Subject: [PATCH 146/159] [bybit-stream] fix --- .../BybitStreamingMarketDataService.java | 3 +- .../bybit/BybitStreamExample.java | 54 +++++++++++++------ 2 files changed, 39 insertions(+), 18 deletions(-) diff --git a/xchange-stream-bybit/src/main/java/info/bitrich/xchangestream/bybit/BybitStreamingMarketDataService.java b/xchange-stream-bybit/src/main/java/info/bitrich/xchangestream/bybit/BybitStreamingMarketDataService.java index 0b52b6b248b..52206e02509 100644 --- a/xchange-stream-bybit/src/main/java/info/bitrich/xchangestream/bybit/BybitStreamingMarketDataService.java +++ b/xchange-stream-bybit/src/main/java/info/bitrich/xchangestream/bybit/BybitStreamingMarketDataService.java @@ -116,7 +116,8 @@ private Observable applyDeltaSnapshot(String channelUniqueId, Instrum } } - public Observable> getOrderBookUpdates(Instrument instrument) { + @Override + public Observable> getOrderBookUpdates(Instrument instrument,Object... args) { return orderBookUpdatesSubscriptions.computeIfAbsent(instrument, v -> PublishSubject.create()); } diff --git a/xchange-stream-bybit/src/test/java/info/bitrich/xchangestream/bybit/BybitStreamExample.java b/xchange-stream-bybit/src/test/java/info/bitrich/xchangestream/bybit/BybitStreamExample.java index 8c3ce8e3969..966045c7454 100644 --- a/xchange-stream-bybit/src/test/java/info/bitrich/xchangestream/bybit/BybitStreamExample.java +++ b/xchange-stream-bybit/src/test/java/info/bitrich/xchangestream/bybit/BybitStreamExample.java @@ -21,12 +21,11 @@ public class BybitStreamExample { public static void main(String[] args) { - try { - spot(); - - } catch (IOException e) { - throw new RuntimeException(e); - } +// try { +// spot(); +// } catch (IOException e) { +// throw new RuntimeException(e); +// } futures(); } @@ -69,7 +68,7 @@ public static void spot() throws IOException { System.out.println(exchange.getMarketDataService().getTicker(BTC_SPOT)); System.out.println(exchange.getMarketDataService().getTicker(BTC_PERP)); - List tradesDisposable = new ArrayList<>(); + List tradesDisposable = new ArrayList<>(); Disposable bookDisposable = exchange .getStreamingMarketDataService() @@ -87,8 +86,9 @@ public static void spot() throws IOException { InterruptedException ignored) { } bookDisposable.dispose(); - for(Disposable disposable:tradesDisposable) + for (Disposable disposable : tradesDisposable) { disposable.dispose(); + } try { Thread.sleep(5000); @@ -110,12 +110,27 @@ public static void futures() { exchangeSpecification); exchange.connect().blockingAwait(); List tradesDisposable = new ArrayList<>(); - Disposable booksDisposable = - exchange - .getStreamingMarketDataService() - .getOrderBook(BTC_PERP) - .subscribe(); - + List booksDisposable = new ArrayList<>(); + List booksUpdatesDisposable = new ArrayList<>(); + booksDisposable.add(exchange + .getStreamingMarketDataService() + .getOrderBook(BTC_PERP) + .subscribe()); + booksDisposable.add(exchange + .getStreamingMarketDataService() + .getOrderBook(ETH_PERP) + .subscribe()); + booksUpdatesDisposable.add(exchange + .getStreamingMarketDataService() + .getOrderBookUpdates(BTC_PERP) + .subscribe()); + booksUpdatesDisposable.add(exchange + .getStreamingMarketDataService() + .getOrderBookUpdates(ETH_PERP) + .subscribe()); + tradesDisposable.add(exchange + .getStreamingMarketDataService().getTrades(BTC_PERP).subscribe( + trade -> System.out.println("trade: " + trade))); tradesDisposable.add(exchange .getStreamingMarketDataService().getTrades(ETH_PERP).subscribe( trade -> System.out.println("trade: " + trade))); @@ -124,10 +139,15 @@ public static void futures() { } catch (InterruptedException ignored) { } - booksDisposable.dispose(); - for(Disposable disposable:tradesDisposable) + for (Disposable disposable : booksUpdatesDisposable) { disposable.dispose(); - + } + for (Disposable disposable : booksDisposable) { + disposable.dispose(); + } + for (Disposable disposable : tradesDisposable) { + disposable.dispose(); + } try { Thread.sleep(5000); } catch (InterruptedException ignored) { From 023e78a22fcbe7bdb89f513b8b5624c08dd61c88 Mon Sep 17 00:00:00 2001 From: rizer1980 <4340180@gmail.com> Date: Fri, 12 Apr 2024 20:58:32 +0300 Subject: [PATCH 147/159] [bybit-stream] fix --- .../bybit/BybitStreamingMarketDataService.java | 12 ++++++------ .../bybit/BybitStreamExample.java | 18 +++++++++++------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/xchange-stream-bybit/src/main/java/info/bitrich/xchangestream/bybit/BybitStreamingMarketDataService.java b/xchange-stream-bybit/src/main/java/info/bitrich/xchangestream/bybit/BybitStreamingMarketDataService.java index 52206e02509..2fd375b44c5 100644 --- a/xchange-stream-bybit/src/main/java/info/bitrich/xchangestream/bybit/BybitStreamingMarketDataService.java +++ b/xchange-stream-bybit/src/main/java/info/bitrich/xchangestream/bybit/BybitStreamingMarketDataService.java @@ -18,6 +18,7 @@ import java.util.concurrent.ConcurrentHashMap; import dto.marketdata.BybitOrderbook; import dto.trade.BybitTrade; +import java.util.concurrent.atomic.AtomicLong; import org.knowm.xchange.dto.Order; import org.knowm.xchange.dto.marketdata.OrderBook; import org.knowm.xchange.dto.marketdata.OrderBookUpdate; @@ -36,7 +37,6 @@ public class BybitStreamingMarketDataService implements StreamingMarketDataServi public static final String TICKER = "tickers."; private final Map orderBookMap = new HashMap<>(); - private long orderBookUpdateIdPrev; private final Map>> orderBookUpdatesSubscriptions; @@ -55,6 +55,7 @@ public BybitStreamingMarketDataService(BybitStreamingService streamingService) { @Override public Observable getOrderBook(Instrument instrument, Object... args) { String depth = "50"; + AtomicLong orderBookUpdateIdPrev = new AtomicLong(); if (args.length > 0 && args[0] != null) { depth = args[0].toString(); } @@ -69,25 +70,24 @@ public Observable getOrderBook(Instrument instrument, Object... args) String type = bybitOrderbooks.getDataType(); if (type.equalsIgnoreCase("snapshot")) { OrderBook orderBook = BybitStreamAdapters.adaptOrderBook(bybitOrderbooks, instrument); - orderBookUpdateIdPrev = bybitOrderbooks.getData().getU(); + orderBookUpdateIdPrev.set(bybitOrderbooks.getData().getU()); orderBookMap.put(channelUniqueId, orderBook); return Observable.just(orderBook); } else if (type.equalsIgnoreCase("delta")) { - return applyDeltaSnapshot(channelUniqueId, instrument, bybitOrderbooks); + return applyDeltaSnapshot(channelUniqueId, instrument, bybitOrderbooks, orderBookUpdateIdPrev); } return Observable.fromIterable(new LinkedList<>()); }); } private Observable applyDeltaSnapshot(String channelUniqueId, Instrument instrument, - BybitOrderbook bybitOrderBookUpdate) { + BybitOrderbook bybitOrderBookUpdate,AtomicLong orderBookUpdateIdPrev) { OrderBook orderBook = orderBookMap.getOrDefault(channelUniqueId, null); if (orderBook == null) { LOG.error("Failed to get orderBook, channelUniqueId= {}", channelUniqueId); return Observable.fromIterable(new LinkedList<>()); } - orderBookUpdateIdPrev++; - if (orderBookUpdateIdPrev == bybitOrderBookUpdate.getData().getU()) { + if (orderBookUpdateIdPrev.incrementAndGet() == bybitOrderBookUpdate.getData().getU()) { LOG.debug("orderBookUpdate id {}, seq {} ", bybitOrderBookUpdate.getData().getU(), bybitOrderBookUpdate.getData().getSeq()); List asks = bybitOrderBookUpdate.getData().getAsk(); diff --git a/xchange-stream-bybit/src/test/java/info/bitrich/xchangestream/bybit/BybitStreamExample.java b/xchange-stream-bybit/src/test/java/info/bitrich/xchangestream/bybit/BybitStreamExample.java index 966045c7454..5a3dc135d6d 100644 --- a/xchange-stream-bybit/src/test/java/info/bitrich/xchangestream/bybit/BybitStreamExample.java +++ b/xchange-stream-bybit/src/test/java/info/bitrich/xchangestream/bybit/BybitStreamExample.java @@ -21,11 +21,11 @@ public class BybitStreamExample { public static void main(String[] args) { -// try { -// spot(); -// } catch (IOException e) { -// throw new RuntimeException(e); -// } + try { + spot(); + } catch (IOException e) { + throw new RuntimeException(e); + } futures(); } @@ -123,11 +123,15 @@ public static void futures() { booksUpdatesDisposable.add(exchange .getStreamingMarketDataService() .getOrderBookUpdates(BTC_PERP) - .subscribe()); + .subscribe( + orderBookUpdates -> System.out.printf("orderBookUpdates: %s\n", orderBookUpdates) + )); booksUpdatesDisposable.add(exchange .getStreamingMarketDataService() .getOrderBookUpdates(ETH_PERP) - .subscribe()); + .subscribe( + orderBookUpdates -> System.out.printf("orderBookUpdates: %s\n", orderBookUpdates) + )); tradesDisposable.add(exchange .getStreamingMarketDataService().getTrades(BTC_PERP).subscribe( trade -> System.out.println("trade: " + trade))); From ed62a32b639ea215236c8e49390479190c6d851a Mon Sep 17 00:00:00 2001 From: rizer1980 <4340180@gmail.com> Date: Tue, 16 Apr 2024 15:18:13 +0300 Subject: [PATCH 148/159] [bybit] add demo-api url --- .../org/knowm/xchange/bybit/BybitExchange.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/xchange-bybit/src/main/java/org/knowm/xchange/bybit/BybitExchange.java b/xchange-bybit/src/main/java/org/knowm/xchange/bybit/BybitExchange.java index 5adb148d243..11c7dc77425 100644 --- a/xchange-bybit/src/main/java/org/knowm/xchange/bybit/BybitExchange.java +++ b/xchange-bybit/src/main/java/org/knowm/xchange/bybit/BybitExchange.java @@ -2,6 +2,7 @@ import java.io.IOException; import org.knowm.xchange.BaseExchange; +import org.knowm.xchange.Exchange; import org.knowm.xchange.ExchangeSpecification; import org.knowm.xchange.bybit.dto.BybitCategory; import org.knowm.xchange.bybit.dto.account.walletbalance.BybitAccountType; @@ -17,6 +18,8 @@ public class BybitExchange extends BaseExchange { public static final String SPECIFIC_PARAM_ACCOUNT_TYPE = "accountType"; + private static final String BASE_URL = "https://api.bybit.com"; + private static final String DEMO_URL = "https://api-demo.bybit.com"; @Override protected void initServices() { @@ -33,7 +36,7 @@ protected void initServices() { @Override public ExchangeSpecification getDefaultExchangeSpecification() { ExchangeSpecification exchangeSpecification = new ExchangeSpecification(this.getClass()); - exchangeSpecification.setSslUri("https://api.bybit.com"); + exchangeSpecification.setSslUri(BASE_URL); exchangeSpecification.setHost("bybit.com"); exchangeSpecification.setPort(80); exchangeSpecification.setExchangeName("Bybit"); @@ -97,4 +100,14 @@ public void remoteInit() throws IOException, ExchangeException { BybitAdapters.symbolToCurrencyPairMetaData( (BybitOptionInstrumentInfo) instrumentInfo))); } + + @Override + public void applySpecification(ExchangeSpecification exchangeSpecification) { + if (exchangeSpecification + .getExchangeSpecificParametersItem(Exchange.USE_SANDBOX) + .equals(true)) { + exchangeSpecification.setSslUri(DEMO_URL); + } + super.applySpecification(exchangeSpecification); + } } From f9ed6ecc00f1545505ba31b32afecc54d10f6546 Mon Sep 17 00:00:00 2001 From: Johan Lindkvist Date: Tue, 16 Apr 2024 15:50:33 +0200 Subject: [PATCH 149/159] Implement crypto withdrawal with path param for crypto Use new withdrawal method instead of method reflection --- .../bitstamp/BitstampAuthenticatedV2.java | 21 ++++++++ .../service/BitstampAccountServiceRaw.java | 52 ++++++------------- 2 files changed, 36 insertions(+), 37 deletions(-) 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 b510b685f86..f94a2d393cc 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 @@ -160,6 +160,27 @@ BitstampUserTransaction[] getUserTransactions( @FormParam("since_id") String sinceId) throws BitstampException, IOException; + @POST + @Path("{currency}_withdrawal/") + @Consumes(MediaType.APPLICATION_FORM_URLENCODED) + BitstampWithdrawal withdrawCrypto( + @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, + @PathParam("currency") String currency, + @FormParam("address") String address, + @FormParam("amount") BigDecimal amount, + @FormParam("contact_thirdparty") Boolean contactThirdparty, + @FormParam("contact_uuid") String contactUuid, + @FormParam("destination_tag") String destinationTag, + @FormParam("memo_id") String memoId, + @FormParam("network") String network, + @FormParam("transfer_id") Integer transferId, + @FormParam("vasp_uuid") String vaspUuid) + throws BitstampException, IOException; + /** * please keep in mind that the methods below are called through reflections with naming pattern * "withdraw" + Currency code 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 a32fd3ae8cd..2b2bd571574 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 @@ -113,7 +113,21 @@ public BitstampWithdrawal withdrawBitstampFunds( } else if (currency.equals(Currency.XLM)) { response = withdrawXLM(amount, address, tag); } else { - response = withdrawAddrAmount(currency, amount, address); + response = checkAndReturnWithdrawal(bitstampAuthenticatedV2.withdrawCrypto(apiKeyForV2Requests, + signatureCreatorV2, + uuidNonceFactory, + timestampFactory, + API_VERSION, + currency.getCurrencyCode().toLowerCase(), + address, + amount, + null, + null, + null, + null, + null, + null, + null)); } if (response.error != null) { @@ -127,42 +141,6 @@ public BitstampWithdrawal withdrawBitstampFunds( return response; } - /** To prevent code repetition we try to resolve client method */ - public BitstampWithdrawal withdrawAddrAmount( - Currency currency, BigDecimal amount, String address) { - try { - Class clientClass = bitstampAuthenticatedV2.getClass(); - Method withdrawMethod = - clientClass.getMethod( - "withdraw" + currency.getCurrencyCode(), - String.class, - ParamsDigest.class, - SynchronizedValueFactory.class, - SynchronizedValueFactory.class, - String.class, - BigDecimal.class, - String.class); - - BitstampWithdrawal response = - (BitstampWithdrawal) - withdrawMethod.invoke( - bitstampAuthenticatedV2, - apiKeyForV2Requests, - signatureCreatorV2, - uuidNonceFactory, - timestampFactory, - API_VERSION, - amount, - address); - return checkAndReturnWithdrawal(response); - } catch (BitstampException e) { - throw handleError(e); - } catch (Exception e) { - throw new RuntimeException( - "Failed to call bitstamp withdraw method on authenticated client", e); - } - } - public BitstampWithdrawal withdrawRippleFunds( BigDecimal amount, String address, Long destinationTag) throws IOException { BitstampRippleDepositAddress addressAndDt; From 9e41a191fad21762f849efb81662953e579746eb Mon Sep 17 00:00:00 2001 From: rizer1980 <4340180@gmail.com> Date: Tue, 16 Apr 2024 18:12:21 +0300 Subject: [PATCH 150/159] [bybit] fix --- .../src/main/java/org/knowm/xchange/bybit/BybitExchange.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/xchange-bybit/src/main/java/org/knowm/xchange/bybit/BybitExchange.java b/xchange-bybit/src/main/java/org/knowm/xchange/bybit/BybitExchange.java index 11c7dc77425..c69031864eb 100644 --- a/xchange-bybit/src/main/java/org/knowm/xchange/bybit/BybitExchange.java +++ b/xchange-bybit/src/main/java/org/knowm/xchange/bybit/BybitExchange.java @@ -43,6 +43,8 @@ public ExchangeSpecification getDefaultExchangeSpecification() { exchangeSpecification.setExchangeDescription("BYBIT"); exchangeSpecification.setExchangeSpecificParametersItem( SPECIFIC_PARAM_ACCOUNT_TYPE, BybitAccountType.UNIFIED); + exchangeSpecification.setExchangeSpecificParametersItem( + Exchange.USE_SANDBOX, false); return exchangeSpecification; } From 0226e29a03e14eac80a76640c94f3783e20011bf Mon Sep 17 00:00:00 2001 From: Tim Molter Date: Sat, 20 Apr 2024 11:51:25 +0200 Subject: [PATCH 151/159] fix slf4j problem --- .github/dependabot.yml | 15 --------------- pom.xml | 2 +- xchange-gateio-v4/pom.xml | 13 ------------- xchange-stream-gateio/pom.xml | 1 - 4 files changed, 1 insertion(+), 30 deletions(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 648d4107a6d..e49f2297495 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -6,18 +6,3 @@ updates: interval: daily time: "12:00" open-pull-requests-limit: 10 - ignore: - - dependency-name: com.fasterxml.jackson.core:jackson-databind - versions: - - 2.12.1 - - 2.12.2 - - dependency-name: com.fasterxml.jackson.dataformat:jackson-dataformat-csv - versions: - - 2.12.1 - - 2.12.2 - - dependency-name: io.netty:netty-all - versions: - - 4.1.61.Final - - dependency-name: com.pubnub:pubnub-gson - versions: - - 4.35.0 diff --git a/pom.xml b/pom.xml index 77ddd53e48c..ef55e5b3bab 100644 --- a/pom.xml +++ b/pom.xml @@ -41,7 +41,7 @@ 3.8.6 1.4.12 0.10.2 - 2.0.12 + 2.0.13 5.0.0 4.4.0 3.2.0 diff --git a/xchange-gateio-v4/pom.xml b/xchange-gateio-v4/pom.xml index fd3ff519462..2e4ecfd3198 100644 --- a/xchange-gateio-v4/pom.xml +++ b/xchange-gateio-v4/pom.xml @@ -32,24 +32,12 @@ io.github.resilience4j resilience4j-ratelimiter ${version.resilience4j} - - - org.slf4j - slf4j-api - - io.github.resilience4j resilience4j-retry ${version.resilience4j} - - - org.slf4j - slf4j-api - - @@ -115,7 +103,6 @@ - diff --git a/xchange-stream-gateio/pom.xml b/xchange-stream-gateio/pom.xml index d28b5e945e9..17df3b1c94c 100644 --- a/xchange-stream-gateio/pom.xml +++ b/xchange-stream-gateio/pom.xml @@ -95,7 +95,6 @@ - From d6586c13cbd5f7691c195d7e20b980084309f3ce Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 20 Apr 2024 09:52:50 +0000 Subject: [PATCH 152/159] Bump org.apache.maven.plugins:maven-gpg-plugin from 3.0.1 to 3.2.4 Bumps [org.apache.maven.plugins:maven-gpg-plugin](https://github.com/apache/maven-gpg-plugin) from 3.0.1 to 3.2.4. - [Release notes](https://github.com/apache/maven-gpg-plugin/releases) - [Commits](https://github.com/apache/maven-gpg-plugin/compare/maven-gpg-plugin-3.0.1...maven-gpg-plugin-3.2.4) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-gpg-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index ef55e5b3bab..c8193d53705 100644 --- a/pom.xml +++ b/pom.xml @@ -434,7 +434,7 @@ org.apache.maven.plugins maven-gpg-plugin - 3.0.1 + 3.2.4 sign-artifacts From 3a4245a0bf3de91b4f6bf9a6ac679d75c0bbb0b5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 20 Apr 2024 09:52:59 +0000 Subject: [PATCH 153/159] Bump org.knowm.xchart:xchart from 3.8.6 to 3.8.7 Bumps [org.knowm.xchart:xchart](https://github.com/knowm/XChart) from 3.8.6 to 3.8.7. - [Commits](https://github.com/knowm/XChart/compare/xchart-3.8.6...xchart-3.8.7) --- updated-dependencies: - dependency-name: org.knowm.xchart:xchart dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index ef55e5b3bab..5663e6450a6 100644 --- a/pom.xml +++ b/pom.xml @@ -38,7 +38,7 @@ 1.7.0 5.9.3 1.18.26 - 3.8.6 + 3.8.7 1.4.12 0.10.2 2.0.13 From ff6346ee6dceae075a9efea13c39ba74077db93c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 20 Apr 2024 09:55:43 +0000 Subject: [PATCH 154/159] Bump org.projectlombok:lombok from 1.18.26 to 1.18.32 Bumps [org.projectlombok:lombok](https://github.com/projectlombok/lombok) from 1.18.26 to 1.18.32. - [Changelog](https://github.com/projectlombok/lombok/blob/master/doc/changelog.markdown) - [Commits](https://github.com/projectlombok/lombok/compare/v1.18.26...v1.18.32) --- updated-dependencies: - dependency-name: org.projectlombok:lombok dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index f8c2d3ba5e1..062721e5268 100644 --- a/pom.xml +++ b/pom.xml @@ -37,7 +37,7 @@ 3.0 1.7.0 5.10.2 - 1.18.26 + 1.18.32 3.8.7 1.4.12 0.10.2 From d12d79c9ed11ed04175b36d010f0b2a5cc3f2d39 Mon Sep 17 00:00:00 2001 From: Tim Molter Date: Sat, 20 Apr 2024 12:37:39 +0200 Subject: [PATCH 155/159] remove problematic code --- pom.xml | 2 +- xchange-gateio-v4/pom.xml | 48 ---------------- xchange-stream-gateio/pom.xml | 55 ------------------- .../gateio/ArchitectureTest.java | 27 --------- 4 files changed, 1 insertion(+), 131 deletions(-) delete mode 100644 xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/ArchitectureTest.java diff --git a/pom.xml b/pom.xml index ef55e5b3bab..062f39cabf5 100644 --- a/pom.xml +++ b/pom.xml @@ -434,7 +434,7 @@ org.apache.maven.plugins maven-gpg-plugin - 3.0.1 + 3.2.3 sign-artifacts diff --git a/xchange-gateio-v4/pom.xml b/xchange-gateio-v4/pom.xml index 2e4ecfd3198..1a8805f5a3f 100644 --- a/xchange-gateio-v4/pom.xml +++ b/xchange-gateio-v4/pom.xml @@ -15,9 +15,7 @@ XChange implementation for the Gate.io Exchange - 3.2.1 5.3.1 - 3.2.0 @@ -67,51 +65,5 @@ - - - - com.github.ekryd.sortpom - sortpom-maven-plugin - ${version.sortpom-maven-plugin} - - true - false - groupId,artifactId - true - 4 - groupId,artifactId - false - - - - - sort - - verify - - - - - - maven-enforcer-plugin - ${version.maven-enforcer-plugin} - - - enforce - - enforce - - - - - - - - - - - - - diff --git a/xchange-stream-gateio/pom.xml b/xchange-stream-gateio/pom.xml index 17df3b1c94c..a8f8c5e5c9e 100644 --- a/xchange-stream-gateio/pom.xml +++ b/xchange-stream-gateio/pom.xml @@ -11,10 +11,7 @@ XChange Gate.io Stream - 1.0.1 - 3.2.1 5.3.1 - 3.2.0 @@ -25,12 +22,6 @@ ${version.fasterxml} - - com.tngtech.archunit - archunit-junit5 - ${version.archunit} - test - org.junit.jupiter @@ -59,51 +50,5 @@ - - - - com.github.ekryd.sortpom - sortpom-maven-plugin - ${version.sortpom-maven-plugin} - - true - false - groupId,artifactId - true - 4 - groupId,artifactId - false - - - - - sort - - verify - - - - - - maven-enforcer-plugin - ${version.maven-enforcer-plugin} - - - enforce - - enforce - - - - - - - - - - - - - diff --git a/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/ArchitectureTest.java b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/ArchitectureTest.java deleted file mode 100644 index c986aa46eb7..00000000000 --- a/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/ArchitectureTest.java +++ /dev/null @@ -1,27 +0,0 @@ -package info.bitrich.xchangestream.gateio; - - -import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.noClasses; - -import com.tngtech.archunit.core.domain.JavaClasses; -import com.tngtech.archunit.core.importer.ClassFileImporter; -import com.tngtech.archunit.lang.ArchRule; -import java.time.Instant; -import java.time.LocalDateTime; -import org.junit.jupiter.api.Test; - -public class ArchitectureTest { - - @Test - void use_clock_for_now_timestamps() { - JavaClasses classes = new ClassFileImporter() - .importPackagesOf(GateioStreamingExchange.class); - - ArchRule rule = noClasses() - .should().callMethod(LocalDateTime.class, "now") - .orShould().callMethod(Instant.class, "now") - .because("we want to use variant with clock instead"); - - rule.check(classes); - } -} \ No newline at end of file From 4abdcb28fa7a435a2a9488e24adcb148dddf43f4 Mon Sep 17 00:00:00 2001 From: Tim Molter Date: Sat, 20 Apr 2024 14:39:04 +0200 Subject: [PATCH 156/159] update deps --- LICENSE | 2 +- pom.xml | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/LICENSE b/LICENSE index 547b7d2e140..d7a74109833 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright 2015-2023 Knowm Inc. (http://knowm.org) and contributors. +Copyright 2015-2024 Knowm Inc. (http://knowm.org) and contributors. Copyright 2012-2015 Xeiam LLC (http://xeiam.com) and contributors. Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/pom.xml b/pom.xml index 062f39cabf5..5808350357a 100644 --- a/pom.xml +++ b/pom.xml @@ -31,13 +31,13 @@ UTF-8 1.8 - 3.24.2 + 3.25.3 3.14.0 2.14.3 3.0 1.7.0 - 5.9.3 - 1.18.26 + 5.10.2 + 1.18.32 3.8.6 1.4.12 0.10.2 @@ -231,6 +231,11 @@ true + + maven_central + Maven Central + https://repo.maven.apache.org/maven2/ + From a8794fc9f86313cee8c5a8bb678f46e7a58c202d Mon Sep 17 00:00:00 2001 From: Tim Molter Date: Sat, 20 Apr 2024 17:16:26 +0200 Subject: [PATCH 157/159] update resilience4j --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 5808350357a..bc8ff25e72a 100644 --- a/pom.xml +++ b/pom.xml @@ -35,7 +35,7 @@ 3.14.0 2.14.3 3.0 - 1.7.0 + 1.7.1 5.10.2 1.18.32 3.8.6 From 47733ed387a0975de3a4306723ec765b6c6d693a Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Fri, 26 Apr 2024 10:09:37 +0200 Subject: [PATCH 158/159] [gateio-stream] Fix getting of orderbook --- .../bitrich/xchangestream/gateio/GateioStreamingAdapters.java | 2 +- .../gateio/GateioStreamingMarketDataServiceIntegration.java | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingAdapters.java b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingAdapters.java index 4b5dd913dc7..e3da0b187d4 100644 --- a/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingAdapters.java +++ b/xchange-stream-gateio/src/main/java/info/bitrich/xchangestream/gateio/GateioStreamingAdapters.java @@ -94,7 +94,7 @@ public OrderBook toOrderBook(GateioOrderBookNotification notification) { Stream asks = orderBookPayload.getAsks().stream() .map(priceSizeEntry -> new LimitOrder(OrderType.ASK, priceSizeEntry.getSize(), orderBookPayload.getCurrencyPair(), null, null, priceSizeEntry.getPrice())); - Stream bids = orderBookPayload.getAsks().stream() + Stream bids = orderBookPayload.getBids().stream() .map(priceSizeEntry -> new LimitOrder(OrderType.BID, priceSizeEntry.getSize(), orderBookPayload.getCurrencyPair(), null, null, priceSizeEntry.getPrice())); return new OrderBook(Date.from(orderBookPayload.getTimestamp()), asks, bids); diff --git a/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingMarketDataServiceIntegration.java b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingMarketDataServiceIntegration.java index e79c037e120..9b69d6517f5 100644 --- a/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingMarketDataServiceIntegration.java +++ b/xchange-stream-gateio/src/test/java/info/bitrich/xchangestream/gateio/GateioStreamingMarketDataServiceIntegration.java @@ -33,6 +33,9 @@ void order_book() { assertThat(orderBook).hasNoNullFieldsOrProperties(); assertThat(orderBook.getBids()).hasSize(10); assertThat(orderBook.getAsks()).hasSize(10); + + // bids should be lower than asks + assertThat(orderBook.getBids().get(0).getLimitPrice()).isLessThan(orderBook.getAsks().get(0).getLimitPrice()); } From 19c7d991506e14f12e123aac7f698b4e69ae50bb Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Sat, 27 Apr 2024 11:29:18 +0200 Subject: [PATCH 159/159] [bankera] Remove obsolete exchange --- pom.xml | 2 - xchange-bankera/api-specification.txt | 8 - xchange-bankera/pom.xml | 35 --- .../org/knowm/xchange/bankera/Bankera.java | 48 ---- .../xchange/bankera/BankeraAdapters.java | 241 ------------------ .../xchange/bankera/BankeraAuthenticated.java | 71 ------ .../xchange/bankera/BankeraExchange.java | 55 ---- .../xchange/bankera/dto/BankeraException.java | 19 -- .../xchange/bankera/dto/BankeraToken.java | 110 -------- .../bankera/dto/BaseBankeraRequest.java | 15 -- .../bankera/dto/CreateOrderRequest.java | 85 ------ .../bankera/dto/account/BankeraUser.java | 25 -- .../bankera/dto/account/BankeraUserInfo.java | 15 -- .../bankera/dto/account/BankeraWallet.java | 44 ---- .../bankera/dto/marketdata/BankeraMarket.java | 32 --- .../dto/marketdata/BankeraMarketInfo.java | 19 -- .../dto/marketdata/BankeraOrderBook.java | 53 ---- .../bankera/dto/marketdata/BankeraTicker.java | 81 ------ .../dto/marketdata/BankeraTickerResponse.java | 19 -- .../bankera/dto/marketdata/BankeraTrade.java | 45 ---- .../dto/marketdata/BankeraTradesResponse.java | 17 -- .../bankera/dto/trade/BankeraOpenOrders.java | 18 -- .../bankera/dto/trade/BankeraOrder.java | 129 ---------- .../bankera/dto/trade/BankeraTransaction.java | 87 ------- .../bankera/dto/trade/BankeraUserTrade.java | 80 ------ .../bankera/dto/trade/BankeraUserTrades.java | 18 -- .../service/BankeraAccountService.java | 19 -- .../service/BankeraAccountServiceRaw.java | 25 -- .../bankera/service/BankeraBaseService.java | 33 --- .../service/BankeraMarketDataService.java | 37 --- .../service/BankeraMarketDataServiceRaw.java | 65 ----- .../bankera/service/BankeraTradeService.java | 150 ----------- .../service/BankeraTradeServiceRaw.java | 155 ----------- .../src/main/resources/bankera.json | 1 - .../knowm/xchange/bankera/ExchangeUtils.java | 41 --- .../dto/account/BankeraUserInfoTest.java | 38 --- .../service/AccountInfoFetchIntegration.java | 30 --- .../service/MarketDataServiceIntegration.java | 58 ----- .../service/TradeServiceIntegration.java | 110 -------- .../src/test/resources/logback.xml | 23 -- .../xchange/bankera/configuration.properties | 3 - .../bankera/dto/account/user_info.json | 69 ----- .../knowm/xchange/currency/CurrencyPair.java | 2 +- xchange-examples/pom.xml | 5 - .../bankera/BankeraAccountServiceDemo.java | 17 -- .../examples/bankera/BankeraDemoUtils.java | 18 -- .../bankera/BankeraMarketDataServiceDemo.java | 18 -- .../bankera/BankeraTradeServiceDemo.java | 17 -- xchange-stream-bankera/pom.xml | 32 --- .../bankera/BankeraStreamingExchange.java | 78 ------ .../BankeraStreamingMarketDataService.java | 104 -------- .../bankera/BankeraStreamingService.java | 37 --- .../BankeraWebSocketSubscriptionMessage.java | 39 --- .../bankera/BankeraManualExample.java | 39 --- .../src/test/resources/logback.xml | 23 -- 55 files changed, 1 insertion(+), 2656 deletions(-) delete mode 100644 xchange-bankera/api-specification.txt delete mode 100644 xchange-bankera/pom.xml delete mode 100644 xchange-bankera/src/main/java/org/knowm/xchange/bankera/Bankera.java delete mode 100644 xchange-bankera/src/main/java/org/knowm/xchange/bankera/BankeraAdapters.java delete mode 100644 xchange-bankera/src/main/java/org/knowm/xchange/bankera/BankeraAuthenticated.java delete mode 100644 xchange-bankera/src/main/java/org/knowm/xchange/bankera/BankeraExchange.java delete mode 100644 xchange-bankera/src/main/java/org/knowm/xchange/bankera/dto/BankeraException.java delete mode 100644 xchange-bankera/src/main/java/org/knowm/xchange/bankera/dto/BankeraToken.java delete mode 100644 xchange-bankera/src/main/java/org/knowm/xchange/bankera/dto/BaseBankeraRequest.java delete mode 100644 xchange-bankera/src/main/java/org/knowm/xchange/bankera/dto/CreateOrderRequest.java delete mode 100644 xchange-bankera/src/main/java/org/knowm/xchange/bankera/dto/account/BankeraUser.java delete mode 100644 xchange-bankera/src/main/java/org/knowm/xchange/bankera/dto/account/BankeraUserInfo.java delete mode 100644 xchange-bankera/src/main/java/org/knowm/xchange/bankera/dto/account/BankeraWallet.java delete mode 100644 xchange-bankera/src/main/java/org/knowm/xchange/bankera/dto/marketdata/BankeraMarket.java delete mode 100644 xchange-bankera/src/main/java/org/knowm/xchange/bankera/dto/marketdata/BankeraMarketInfo.java delete mode 100644 xchange-bankera/src/main/java/org/knowm/xchange/bankera/dto/marketdata/BankeraOrderBook.java delete mode 100644 xchange-bankera/src/main/java/org/knowm/xchange/bankera/dto/marketdata/BankeraTicker.java delete mode 100644 xchange-bankera/src/main/java/org/knowm/xchange/bankera/dto/marketdata/BankeraTickerResponse.java delete mode 100644 xchange-bankera/src/main/java/org/knowm/xchange/bankera/dto/marketdata/BankeraTrade.java delete mode 100644 xchange-bankera/src/main/java/org/knowm/xchange/bankera/dto/marketdata/BankeraTradesResponse.java delete mode 100644 xchange-bankera/src/main/java/org/knowm/xchange/bankera/dto/trade/BankeraOpenOrders.java delete mode 100644 xchange-bankera/src/main/java/org/knowm/xchange/bankera/dto/trade/BankeraOrder.java delete mode 100644 xchange-bankera/src/main/java/org/knowm/xchange/bankera/dto/trade/BankeraTransaction.java delete mode 100644 xchange-bankera/src/main/java/org/knowm/xchange/bankera/dto/trade/BankeraUserTrade.java delete mode 100644 xchange-bankera/src/main/java/org/knowm/xchange/bankera/dto/trade/BankeraUserTrades.java delete mode 100644 xchange-bankera/src/main/java/org/knowm/xchange/bankera/service/BankeraAccountService.java delete mode 100644 xchange-bankera/src/main/java/org/knowm/xchange/bankera/service/BankeraAccountServiceRaw.java delete mode 100644 xchange-bankera/src/main/java/org/knowm/xchange/bankera/service/BankeraBaseService.java delete mode 100644 xchange-bankera/src/main/java/org/knowm/xchange/bankera/service/BankeraMarketDataService.java delete mode 100644 xchange-bankera/src/main/java/org/knowm/xchange/bankera/service/BankeraMarketDataServiceRaw.java delete mode 100644 xchange-bankera/src/main/java/org/knowm/xchange/bankera/service/BankeraTradeService.java delete mode 100644 xchange-bankera/src/main/java/org/knowm/xchange/bankera/service/BankeraTradeServiceRaw.java delete mode 100644 xchange-bankera/src/main/resources/bankera.json delete mode 100644 xchange-bankera/src/test/java/org/knowm/xchange/bankera/ExchangeUtils.java delete mode 100644 xchange-bankera/src/test/java/org/knowm/xchange/bankera/dto/account/BankeraUserInfoTest.java delete mode 100644 xchange-bankera/src/test/java/org/knowm/xchange/bankera/service/AccountInfoFetchIntegration.java delete mode 100644 xchange-bankera/src/test/java/org/knowm/xchange/bankera/service/MarketDataServiceIntegration.java delete mode 100644 xchange-bankera/src/test/java/org/knowm/xchange/bankera/service/TradeServiceIntegration.java delete mode 100644 xchange-bankera/src/test/resources/logback.xml delete mode 100644 xchange-bankera/src/test/resources/org/knowm/xchange/bankera/configuration.properties delete mode 100644 xchange-bankera/src/test/resources/org/knowm/xchange/bankera/dto/account/user_info.json delete mode 100644 xchange-examples/src/main/java/org/knowm/xchange/examples/bankera/BankeraAccountServiceDemo.java delete mode 100644 xchange-examples/src/main/java/org/knowm/xchange/examples/bankera/BankeraDemoUtils.java delete mode 100644 xchange-examples/src/main/java/org/knowm/xchange/examples/bankera/BankeraMarketDataServiceDemo.java delete mode 100644 xchange-examples/src/main/java/org/knowm/xchange/examples/bankera/BankeraTradeServiceDemo.java delete mode 100644 xchange-stream-bankera/pom.xml delete mode 100644 xchange-stream-bankera/src/main/java/info/bitrich/xchangestream/bankera/BankeraStreamingExchange.java delete mode 100644 xchange-stream-bankera/src/main/java/info/bitrich/xchangestream/bankera/BankeraStreamingMarketDataService.java delete mode 100644 xchange-stream-bankera/src/main/java/info/bitrich/xchangestream/bankera/BankeraStreamingService.java delete mode 100644 xchange-stream-bankera/src/main/java/info/bitrich/xchangestream/bankera/dto/BankeraWebSocketSubscriptionMessage.java delete mode 100644 xchange-stream-bankera/src/test/java/info/bitrich/xchangestream/bankera/BankeraManualExample.java delete mode 100644 xchange-stream-bankera/src/test/resources/logback.xml diff --git a/pom.xml b/pom.xml index bc8ff25e72a..633f6ea6d69 100644 --- a/pom.xml +++ b/pom.xml @@ -91,7 +91,6 @@ - xchange-bankera xchange-bibox xchange-binance xchange-bitbay @@ -182,7 +181,6 @@ xchange-enigma - xchange-stream-bankera xchange-stream-binance xchange-stream-bitfinex xchange-stream-bitflyer diff --git a/xchange-bankera/api-specification.txt b/xchange-bankera/api-specification.txt deleted file mode 100644 index e1450540ecc..00000000000 --- a/xchange-bankera/api-specification.txt +++ /dev/null @@ -1,8 +0,0 @@ -Bankera api spec - -url: https://exchange.bankera.com -doc: https://exchange.bankera.com/api-documentation.html - -You need an extra parameters: -exSpec.setExchangeSpecificParametersItem("clientId", "clientId"); -exSpec.setExchangeSpecificParametersItem("clientSecret", "clientSecret"); \ No newline at end of file diff --git a/xchange-bankera/pom.xml b/xchange-bankera/pom.xml deleted file mode 100644 index cc7911e43f6..00000000000 --- a/xchange-bankera/pom.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - 4.0.0 - - - org.knowm.xchange - xchange-parent - 5.1.2-SNAPSHOT - - - xchange-bankera - - XChange Bankera - XChange implementation for the Bankera Exchange - - http://knowm.org/open-source/xchange/ - 2012 - - - Knowm Inc. - http://knowm.org/open-source/xchange/ - - - - - - - org.knowm.xchange - xchange-core - ${project.version} - - - - - diff --git a/xchange-bankera/src/main/java/org/knowm/xchange/bankera/Bankera.java b/xchange-bankera/src/main/java/org/knowm/xchange/bankera/Bankera.java deleted file mode 100644 index ac8f2cf8ef5..00000000000 --- a/xchange-bankera/src/main/java/org/knowm/xchange/bankera/Bankera.java +++ /dev/null @@ -1,48 +0,0 @@ -package org.knowm.xchange.bankera; - -import jakarta.ws.rs.FormParam; -import jakarta.ws.rs.GET; -import jakarta.ws.rs.POST; -import jakarta.ws.rs.Path; -import jakarta.ws.rs.PathParam; -import jakarta.ws.rs.Produces; -import jakarta.ws.rs.core.MediaType; -import java.io.IOException; -import org.knowm.xchange.bankera.dto.BankeraException; -import org.knowm.xchange.bankera.dto.BankeraToken; -import org.knowm.xchange.bankera.dto.marketdata.BankeraMarketInfo; -import org.knowm.xchange.bankera.dto.marketdata.BankeraOrderBook; -import org.knowm.xchange.bankera.dto.marketdata.BankeraTickerResponse; -import org.knowm.xchange.bankera.dto.marketdata.BankeraTradesResponse; - -@Path("/") -@Produces(MediaType.APPLICATION_JSON) -public interface Bankera { - - @POST - @Path("/oauth/token") - BankeraToken getToken( - @FormParam("grant_type") String grantType, - @FormParam("client_id") String clientId, - @FormParam("client_secret") String clientSecret) - throws BankeraException; - - @GET - @Path("/tickers/{market}") - BankeraTickerResponse getMarketTicker(@PathParam("market") String market) - throws BankeraException, IOException; - - @GET - @Path("/orderbooks/{market}") - BankeraOrderBook getOrderbook(@PathParam("market") String market) - throws BankeraException, IOException; - - @GET - @Path("/trades/{market}") - BankeraTradesResponse getRecentTrades(@PathParam("market") String market) - throws BankeraException, IOException; - - @GET - @Path("/general/info") - BankeraMarketInfo getMarketInfo() throws BankeraException, IOException; -} diff --git a/xchange-bankera/src/main/java/org/knowm/xchange/bankera/BankeraAdapters.java b/xchange-bankera/src/main/java/org/knowm/xchange/bankera/BankeraAdapters.java deleted file mode 100644 index c6de13e9581..00000000000 --- a/xchange-bankera/src/main/java/org/knowm/xchange/bankera/BankeraAdapters.java +++ /dev/null @@ -1,241 +0,0 @@ -package org.knowm.xchange.bankera; - -import java.math.BigDecimal; -import java.text.DecimalFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.stream.Collectors; -import org.knowm.xchange.bankera.dto.BankeraException; -import org.knowm.xchange.bankera.dto.account.BankeraUserInfo; -import org.knowm.xchange.bankera.dto.account.BankeraWallet; -import org.knowm.xchange.bankera.dto.marketdata.BankeraOrderBook; -import org.knowm.xchange.bankera.dto.marketdata.BankeraTickerResponse; -import org.knowm.xchange.bankera.dto.marketdata.BankeraTrade; -import org.knowm.xchange.bankera.dto.marketdata.BankeraTradesResponse; -import org.knowm.xchange.bankera.dto.trade.BankeraOpenOrders; -import org.knowm.xchange.bankera.dto.trade.BankeraOrder; -import org.knowm.xchange.bankera.dto.trade.BankeraUserTrades; -import org.knowm.xchange.currency.Currency; -import org.knowm.xchange.currency.CurrencyPair; -import org.knowm.xchange.dto.Order; -import org.knowm.xchange.dto.Order.OrderType; -import org.knowm.xchange.dto.account.AccountInfo; -import org.knowm.xchange.dto.account.Balance; -import org.knowm.xchange.dto.account.Wallet; -import org.knowm.xchange.dto.marketdata.OrderBook; -import org.knowm.xchange.dto.marketdata.Ticker; -import org.knowm.xchange.dto.marketdata.Trade; -import org.knowm.xchange.dto.marketdata.Trades; -import org.knowm.xchange.dto.trade.LimitOrder; -import org.knowm.xchange.dto.trade.UserTrade; -import org.knowm.xchange.exceptions.ExchangeException; -import org.knowm.xchange.exceptions.ExchangeSecurityException; - -public final class BankeraAdapters { - - private static final String ORDER_SIDE_BUY = "buy"; - - private BankeraAdapters() {} - - public static AccountInfo adaptAccountInfo(BankeraUserInfo userInfo) { - return new AccountInfo( - String.valueOf(userInfo.getUser().getId()), adaptWallet(userInfo.getUser().getWallets())); - } - - public static Wallet adaptWallet(List wallets) { - List balances = - wallets.stream() - .map( - w -> - new Balance.Builder() - .total(new BigDecimal(w.getTotal())) - .available(new BigDecimal(w.getBalance())) - .frozen(new BigDecimal(w.getReserved())) - .currency(new Currency(w.getCurrency())) - .build()) - .collect(Collectors.toList()); - return Wallet.Builder.from(balances).build(); - } - - public static ExchangeException adaptError(BankeraException exception) { - return exception.getHttpStatusCode() == 403 - ? new ExchangeSecurityException() - : new ExchangeException(exception.getError(), exception); - } - - /** - * Adapts Bankera BankeraTickerResponse to a Ticker - * - * @param ticker Specific ticker - * @param currencyPair BankeraCurrency pair (e.g. ETH/BTC) - * @return Ticker - */ - public static Ticker adaptTicker(BankeraTickerResponse ticker, CurrencyPair currencyPair) { - - BigDecimal high = new BigDecimal(ticker.getTicker().getHigh()); - BigDecimal low = new BigDecimal(ticker.getTicker().getLow()); - BigDecimal bid = new BigDecimal(ticker.getTicker().getBid()); - BigDecimal ask = new BigDecimal(ticker.getTicker().getAsk()); - BigDecimal last = new BigDecimal(ticker.getTicker().getLast()); - BigDecimal volume = new BigDecimal(ticker.getTicker().getVolume()); - Date timestamp = new Date(ticker.getTicker().getTimestamp()); - - return new Ticker.Builder() - .currencyPair(currencyPair) - .high(high) - .low(low) - .bid(bid) - .ask(ask) - .last(last) - .volume(volume) - .timestamp(timestamp) - .build(); - } - - public static OrderBook adaptOrderBook(BankeraOrderBook orderbook, CurrencyPair currencyPair) { - - List bids = createOrders(currencyPair, OrderType.BID, orderbook.getBids()); - List asks = createOrders(currencyPair, OrderType.ASK, orderbook.getAsks()); - - return new OrderBook(null, asks, bids); - } - - public static Trades adaptTrades( - BankeraTradesResponse tradesResponse, CurrencyPair currencyPair) { - - List bankeraTrades = tradesResponse.getTrades(); - List tradesList = new ArrayList<>(); - - bankeraTrades.forEach( - bankeraTrade -> { - BigDecimal amount = new BigDecimal(bankeraTrade.getAmount()); - BigDecimal price = new BigDecimal(bankeraTrade.getPrice()); - Date date = new Date(Long.parseLong(bankeraTrade.getTime())); - OrderType type = - bankeraTrade.getSide().equalsIgnoreCase(ORDER_SIDE_BUY) - ? OrderType.BID - : OrderType.ASK; - tradesList.add( - new Trade.Builder() - .type(type) - .originalAmount(amount) - .currencyPair(currencyPair) - .price(price) - .timestamp(date) - .build()); - }); - return new Trades(tradesList, 0L, Trades.TradeSortType.SortByTimestamp); - } - - private static List createOrders( - CurrencyPair currencyPair, - OrderType orderType, - List ordersList) { - - List limitOrders = new ArrayList<>(); - if (ordersList == null) return limitOrders; - - ordersList.forEach( - order -> { - limitOrders.add( - new LimitOrder( - orderType, - new BigDecimal(order.getAmount()), - currencyPair, - String.valueOf(order.getId()), - null, - new BigDecimal(order.getPrice()))); - }); - - return limitOrders; - } - - public static List adaptOpenOrders(BankeraOpenOrders openOrders) { - - List orderList = new ArrayList<>(); - - openOrders - .getOpenOrders() - .forEach( - bankeraOrder -> { - String[] currencies = bankeraOrder.getMarket().split("-"); - CurrencyPair pair = new CurrencyPair(currencies[0], currencies[1]); - orderList.add( - new LimitOrder( - bankeraOrder.getSide().equalsIgnoreCase("buy") - ? OrderType.BID - : OrderType.ASK, - new BigDecimal(bankeraOrder.getAmount()), - new BigDecimal(bankeraOrder.getRemainingAmount()), - pair, - String.valueOf(bankeraOrder.getId()), - new Date(Long.valueOf(bankeraOrder.getCreatedAt())), - new BigDecimal(bankeraOrder.getPrice()))); - }); - - return orderList; - } - - public static List adaptUserTrades(BankeraUserTrades userTrades) { - List tradeList = new ArrayList<>(); - - userTrades - .getTrades() - .forEach( - trade -> { - String[] currencies = trade.getMarket().split("-"); - CurrencyPair pair = new CurrencyPair(currencies[0], currencies[1]); - Currency feeCurrency = new Currency(currencies[1]); - tradeList.add( - UserTrade.builder() - .type(trade.getSide().equalsIgnoreCase("buy") ? OrderType.BID : OrderType.ASK) - .originalAmount(new BigDecimal(trade.getAmount())) - .currencyPair(pair) - .price(new BigDecimal(trade.getPrice())) - .timestamp(new Date(Long.parseLong(trade.getCompletedAt()))) - .id(String.valueOf(trade.getId())) - .orderId(String.valueOf(trade.getOrderId())) - .feeAmount(new BigDecimal(trade.getFeeAmount())) - .feeCurrency(feeCurrency) - .build()); - }); - - return tradeList; - } - - public static Order adaptOrder(BankeraOrder bankeraOrder) { - String[] currencies = bankeraOrder.getMarket().split("-"); - CurrencyPair pair = new CurrencyPair(currencies[0], currencies[1]); - DecimalFormat format = new DecimalFormat(); - format.setParseBigDecimal(true); - return new LimitOrder( - bankeraOrder.getSide().equalsIgnoreCase("buy") ? OrderType.BID : OrderType.ASK, - new BigDecimal(bankeraOrder.getAmount()), - pair, - String.valueOf(bankeraOrder.getId()), - new Date(Long.parseLong(bankeraOrder.getCreatedAt())), - new BigDecimal(bankeraOrder.getPrice()), - new BigDecimal(bankeraOrder.getPrice()), - new BigDecimal(bankeraOrder.getExecutedAmount()), - bankeraOrder.getTotalFee(), - adaptOrderStatus(bankeraOrder.getStatus())); - } - - private static Order.OrderStatus adaptOrderStatus(String status) { - switch (status.toLowerCase()) { - case "open": - return Order.OrderStatus.NEW; - case "completed": - return Order.OrderStatus.FILLED; - case "cancelled": - return Order.OrderStatus.CANCELED; - case "rejected": - return Order.OrderStatus.REJECTED; - case "pending cancel": - return Order.OrderStatus.PENDING_CANCEL; - default: - return Order.OrderStatus.UNKNOWN; - } - } -} diff --git a/xchange-bankera/src/main/java/org/knowm/xchange/bankera/BankeraAuthenticated.java b/xchange-bankera/src/main/java/org/knowm/xchange/bankera/BankeraAuthenticated.java deleted file mode 100644 index 670f76bb452..00000000000 --- a/xchange-bankera/src/main/java/org/knowm/xchange/bankera/BankeraAuthenticated.java +++ /dev/null @@ -1,71 +0,0 @@ -package org.knowm.xchange.bankera; - -import jakarta.ws.rs.Consumes; -import jakarta.ws.rs.GET; -import jakarta.ws.rs.HeaderParam; -import jakarta.ws.rs.POST; -import jakarta.ws.rs.Path; -import jakarta.ws.rs.PathParam; -import jakarta.ws.rs.Produces; -import jakarta.ws.rs.QueryParam; -import jakarta.ws.rs.core.MediaType; -import java.io.IOException; -import java.util.List; -import org.knowm.xchange.bankera.dto.BankeraException; -import org.knowm.xchange.bankera.dto.BaseBankeraRequest; -import org.knowm.xchange.bankera.dto.CreateOrderRequest; -import org.knowm.xchange.bankera.dto.account.BankeraUserInfo; -import org.knowm.xchange.bankera.dto.trade.BankeraOpenOrders; -import org.knowm.xchange.bankera.dto.trade.BankeraOrder; -import org.knowm.xchange.bankera.dto.trade.BankeraUserTrades; - -@Path("/") -@Produces(MediaType.APPLICATION_JSON) -public interface BankeraAuthenticated extends Bankera { - @GET - @Path("users/info") - BankeraUserInfo getUserInfo(@HeaderParam("Authorization") String authorization) - throws BankeraException, IOException; - - @POST - @Consumes(MediaType.APPLICATION_JSON) - @Path("orders/new") - BankeraOrder placeOrder( - @HeaderParam("Authorization") String authorization, CreateOrderRequest request) - throws BankeraException, IOException; - - @GET - @Path("orders/open") - BankeraOpenOrders getOpenOrders( - @HeaderParam("Authorization") String authorization, - @QueryParam("market") String market, - @QueryParam("limit") Integer limit, - @QueryParam("offset") Integer offset) - throws BankeraException, IOException; - - @POST - @Consumes(MediaType.APPLICATION_JSON) - @Path("orders/cancel/{orderId}") - BankeraOrder cancelOrder( - @HeaderParam("Authorization") String authorization, - @PathParam("orderId") Long orderId, - BaseBankeraRequest request) - throws BankeraException, IOException; - - @POST - @Path("orders/cancel/all") - List cancelAllOrders(@HeaderParam("Authorization") String authorization) - throws BankeraException, IOException; - - @GET - @Path("trades/history") - BankeraUserTrades getUserTrades( - @HeaderParam("Authorization") String authorization, @QueryParam("market") String market) - throws BankeraException, IOException; - - @GET - @Path("orders/details") - BankeraOrder getUserOrder( - @HeaderParam("Authorization") String authorization, @QueryParam("orderId") String orderId) - throws BankeraException, IOException; -} diff --git a/xchange-bankera/src/main/java/org/knowm/xchange/bankera/BankeraExchange.java b/xchange-bankera/src/main/java/org/knowm/xchange/bankera/BankeraExchange.java deleted file mode 100644 index db68f176674..00000000000 --- a/xchange-bankera/src/main/java/org/knowm/xchange/bankera/BankeraExchange.java +++ /dev/null @@ -1,55 +0,0 @@ -package org.knowm.xchange.bankera; - -import org.knowm.xchange.BaseExchange; -import org.knowm.xchange.Exchange; -import org.knowm.xchange.ExchangeSpecification; -import org.knowm.xchange.bankera.dto.BankeraException; -import org.knowm.xchange.bankera.dto.BankeraToken; -import org.knowm.xchange.bankera.service.BankeraAccountService; -import org.knowm.xchange.bankera.service.BankeraBaseService; -import org.knowm.xchange.bankera.service.BankeraMarketDataService; -import org.knowm.xchange.bankera.service.BankeraTradeService; -import org.knowm.xchange.utils.nonce.TimestampIncrementingNonceFactory; -import si.mazi.rescu.SynchronizedValueFactory; - -public class BankeraExchange extends BaseExchange implements Exchange { - - private SynchronizedValueFactory nonceFactory = new TimestampIncrementingNonceFactory(); - protected BankeraToken token; - - @Override - protected void initServices() { - this.accountService = new BankeraAccountService(this); - this.marketDataService = new BankeraMarketDataService(this); - this.tradeService = new BankeraTradeService(this); - } - - @Override - public ExchangeSpecification getDefaultExchangeSpecification() { - - ExchangeSpecification exchangeSpecification = new ExchangeSpecification(this.getClass()); - exchangeSpecification.setSslUri("https://api-exchange.bankera.com"); - exchangeSpecification.setHost("api-exchange.bankera.com"); - exchangeSpecification.setPort(443); - exchangeSpecification.setExchangeName("Bankera"); - exchangeSpecification.setExchangeDescription("The Bankera exchange."); - - return exchangeSpecification; - } - - @Override - public SynchronizedValueFactory getNonceFactory() { - return nonceFactory; - } - - public BankeraToken getToken() { - if (token == null || token.getExpirationTime() < System.currentTimeMillis() + 30000L) { - try { - token = ((BankeraBaseService) accountService).createToken(); - } catch (BankeraException e) { - throw BankeraAdapters.adaptError(e); - } - } - return token; - } -} diff --git a/xchange-bankera/src/main/java/org/knowm/xchange/bankera/dto/BankeraException.java b/xchange-bankera/src/main/java/org/knowm/xchange/bankera/dto/BankeraException.java deleted file mode 100644 index 574e637df0f..00000000000 --- a/xchange-bankera/src/main/java/org/knowm/xchange/bankera/dto/BankeraException.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.knowm.xchange.bankera.dto; - -import com.fasterxml.jackson.annotation.JsonProperty; -import si.mazi.rescu.HttpStatusExceptionSupport; - -public class BankeraException extends HttpStatusExceptionSupport { - - private final String error; - - public BankeraException( - @JsonProperty("status") Integer status, @JsonProperty("error") String error) { - super(error); - this.error = error; - } - - public String getError() { - return error; - } -} diff --git a/xchange-bankera/src/main/java/org/knowm/xchange/bankera/dto/BankeraToken.java b/xchange-bankera/src/main/java/org/knowm/xchange/bankera/dto/BankeraToken.java deleted file mode 100644 index c4636d0ab4c..00000000000 --- a/xchange-bankera/src/main/java/org/knowm/xchange/bankera/dto/BankeraToken.java +++ /dev/null @@ -1,110 +0,0 @@ -package org.knowm.xchange.bankera.dto; - -import com.fasterxml.jackson.annotation.JsonProperty; - -public class BankeraToken { - private String accessToken; - private String tokenType; - private int expiresIn; - private Long expirationTime; - private String scope; - private String userId; - private String userName; - private String environmentCode; - private String loginIp; - private String jti; - - public BankeraToken( - @JsonProperty("access_token") final String accessToken, - @JsonProperty("token_type") final String tokenType, - @JsonProperty("expires_in") final int expiresIn, - @JsonProperty("scope") final String scope, - @JsonProperty("user_id") final String userId, - @JsonProperty("user_name") final String userName, - @JsonProperty("environment_code") final String environmentCode, - @JsonProperty("login_ip") final String loginIp, - @JsonProperty("jti") final String jti) { - this.accessToken = accessToken; - this.tokenType = tokenType; - this.expiresIn = expiresIn; - this.scope = scope; - this.userId = userId; - this.userName = userName; - this.environmentCode = environmentCode; - this.loginIp = loginIp; - this.jti = jti; - this.expirationTime = System.currentTimeMillis() + (this.expiresIn * 1000L); - } - - public String getAccessToken() { - return accessToken; - } - - public String getTokenType() { - return tokenType; - } - - public int getExpiresIn() { - return expiresIn; - } - - public Long getExpirationTime() { - return expirationTime; - } - - public String getScope() { - return scope; - } - - public String getUserId() { - return userId; - } - - public String getUserName() { - return userName; - } - - public String getEnvironmentCode() { - return environmentCode; - } - - public String getLoginIp() { - return loginIp; - } - - public String getJti() { - return jti; - } - - @Override - public String toString() { - return "BankeraToken{" - + "accessToken='" - + accessToken - + '\'' - + ", tokenType='" - + tokenType - + '\'' - + ", expiresIn=" - + expiresIn - + ", scope='" - + scope - + '\'' - + ", userId='" - + userId - + '\'' - + ", userName='" - + userName - + '\'' - + ", environmentCode='" - + environmentCode - + '\'' - + ", loginIp='" - + loginIp - + '\'' - + ", jti='" - + jti - + '\'' - + '}'; - } -} diff --git a/xchange-bankera/src/main/java/org/knowm/xchange/bankera/dto/BaseBankeraRequest.java b/xchange-bankera/src/main/java/org/knowm/xchange/bankera/dto/BaseBankeraRequest.java deleted file mode 100644 index b6b57769624..00000000000 --- a/xchange-bankera/src/main/java/org/knowm/xchange/bankera/dto/BaseBankeraRequest.java +++ /dev/null @@ -1,15 +0,0 @@ -package org.knowm.xchange.bankera.dto; - -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; - -@JsonInclude(JsonInclude.Include.NON_EMPTY) -public class BaseBankeraRequest { - - @JsonProperty("nonce") - private final Long nonce; - - public BaseBankeraRequest(Long nonce) { - this.nonce = nonce; - } -} diff --git a/xchange-bankera/src/main/java/org/knowm/xchange/bankera/dto/CreateOrderRequest.java b/xchange-bankera/src/main/java/org/knowm/xchange/bankera/dto/CreateOrderRequest.java deleted file mode 100644 index a8fcb35bd2e..00000000000 --- a/xchange-bankera/src/main/java/org/knowm/xchange/bankera/dto/CreateOrderRequest.java +++ /dev/null @@ -1,85 +0,0 @@ -package org.knowm.xchange.bankera.dto; - -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import java.math.BigDecimal; -import org.apache.commons.lang3.StringUtils; - -@JsonInclude(JsonInclude.Include.NON_EMPTY) -public class CreateOrderRequest { - - private static final String LIMIT_ORDER_TYPE = "limit"; - private static final String MARKET_ORDER_TYPE = "market"; - - @JsonProperty("market") - private final String market; - - @JsonProperty("side") - private final String side; - - @JsonProperty("type") - private final String type; - - @JsonProperty("price") - private final String price; - - @JsonProperty("amount") - private final String amount; - - @JsonProperty("client_order_id") - private final String clientOrderId; - - @JsonProperty("nonce") - private final Long nonce; - - public CreateOrderRequest( - String market, String side, BigDecimal amount, String clientOrderId, Long nonce) { - this.market = market; - this.side = side; - this.amount = amount.toPlainString(); - this.type = MARKET_ORDER_TYPE; - this.price = StringUtils.EMPTY; - this.clientOrderId = clientOrderId; - this.nonce = nonce; - } - - public CreateOrderRequest( - String market, - String side, - BigDecimal amount, - BigDecimal price, - String clientOrderId, - Long nonce) { - this.market = market; - this.side = side; - this.amount = amount.toPlainString(); - this.type = LIMIT_ORDER_TYPE; - this.price = price.toPlainString(); - this.clientOrderId = clientOrderId; - this.nonce = nonce; - } - - public enum Side { - BUY("buy"), - SELL("sell"); - - private String side; - - Side(String side) { - this.side = side; - } - - public String getSide() { - return this.side; - } - - public static Side getEnum(String side) { - for (Side currentEnum : Side.values()) { - if (currentEnum.getSide().equalsIgnoreCase(side)) { - return currentEnum; - } - } - throw new UnsupportedOperationException("Unknown order side: " + side); - } - } -} diff --git a/xchange-bankera/src/main/java/org/knowm/xchange/bankera/dto/account/BankeraUser.java b/xchange-bankera/src/main/java/org/knowm/xchange/bankera/dto/account/BankeraUser.java deleted file mode 100644 index c39d553dba0..00000000000 --- a/xchange-bankera/src/main/java/org/knowm/xchange/bankera/dto/account/BankeraUser.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.knowm.xchange.bankera.dto.account; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; -import java.util.List; - -@JsonIgnoreProperties(ignoreUnknown = true) -public class BankeraUser { - private int id; - private List wallets; - - public BankeraUser( - @JsonProperty("id") int id, @JsonProperty("wallets") List wallets) { - this.id = id; - this.wallets = wallets; - } - - public int getId() { - return id; - } - - public List getWallets() { - return wallets; - } -} diff --git a/xchange-bankera/src/main/java/org/knowm/xchange/bankera/dto/account/BankeraUserInfo.java b/xchange-bankera/src/main/java/org/knowm/xchange/bankera/dto/account/BankeraUserInfo.java deleted file mode 100644 index b689c5b6fe1..00000000000 --- a/xchange-bankera/src/main/java/org/knowm/xchange/bankera/dto/account/BankeraUserInfo.java +++ /dev/null @@ -1,15 +0,0 @@ -package org.knowm.xchange.bankera.dto.account; - -import com.fasterxml.jackson.annotation.JsonProperty; - -public class BankeraUserInfo { - private BankeraUser user; - - public BankeraUserInfo(@JsonProperty("user") BankeraUser user) { - this.user = user; - } - - public BankeraUser getUser() { - return user; - } -} diff --git a/xchange-bankera/src/main/java/org/knowm/xchange/bankera/dto/account/BankeraWallet.java b/xchange-bankera/src/main/java/org/knowm/xchange/bankera/dto/account/BankeraWallet.java deleted file mode 100644 index 12f9113d35c..00000000000 --- a/xchange-bankera/src/main/java/org/knowm/xchange/bankera/dto/account/BankeraWallet.java +++ /dev/null @@ -1,44 +0,0 @@ -package org.knowm.xchange.bankera.dto.account; - -import com.fasterxml.jackson.annotation.JsonProperty; - -public class BankeraWallet { - private int id; - private String balance; - private String reserved; - private String total; - private String currency; - - public BankeraWallet( - @JsonProperty("id") int id, - @JsonProperty("balance") String balance, - @JsonProperty("reserved") String reserved, - @JsonProperty("total") String total, - @JsonProperty("currency") String currency) { - this.id = id; - this.balance = balance; - this.reserved = reserved; - this.total = total; - this.currency = currency; - } - - public int getId() { - return id; - } - - public String getBalance() { - return balance; - } - - public String getReserved() { - return reserved; - } - - public String getTotal() { - return total; - } - - public String getCurrency() { - return currency; - } -} diff --git a/xchange-bankera/src/main/java/org/knowm/xchange/bankera/dto/marketdata/BankeraMarket.java b/xchange-bankera/src/main/java/org/knowm/xchange/bankera/dto/marketdata/BankeraMarket.java deleted file mode 100644 index 8c1c8138fa5..00000000000 --- a/xchange-bankera/src/main/java/org/knowm/xchange/bankera/dto/marketdata/BankeraMarket.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.knowm.xchange.bankera.dto.marketdata; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; - -@JsonIgnoreProperties(ignoreUnknown = true) -public class BankeraMarket { - private int id; - private String slug; - private String name; - - public BankeraMarket( - @JsonProperty("id") int id, - @JsonProperty("slug") String slug, - @JsonProperty("name") String name) { - this.id = id; - this.slug = slug; - this.name = name; - } - - public int getId() { - return id; - } - - public String getSlug() { - return slug; - } - - public String getName() { - return name; - } -} diff --git a/xchange-bankera/src/main/java/org/knowm/xchange/bankera/dto/marketdata/BankeraMarketInfo.java b/xchange-bankera/src/main/java/org/knowm/xchange/bankera/dto/marketdata/BankeraMarketInfo.java deleted file mode 100644 index 1bf81f6dc6c..00000000000 --- a/xchange-bankera/src/main/java/org/knowm/xchange/bankera/dto/marketdata/BankeraMarketInfo.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.knowm.xchange.bankera.dto.marketdata; - -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import java.util.List; - -@JsonInclude(JsonInclude.Include.NON_NULL) -public class BankeraMarketInfo { - - private List markets; - - public BankeraMarketInfo(@JsonProperty("markets") List markets) { - this.markets = markets; - } - - public List getMarkets() { - return markets; - } -} diff --git a/xchange-bankera/src/main/java/org/knowm/xchange/bankera/dto/marketdata/BankeraOrderBook.java b/xchange-bankera/src/main/java/org/knowm/xchange/bankera/dto/marketdata/BankeraOrderBook.java deleted file mode 100644 index 5211d0527e8..00000000000 --- a/xchange-bankera/src/main/java/org/knowm/xchange/bankera/dto/marketdata/BankeraOrderBook.java +++ /dev/null @@ -1,53 +0,0 @@ -package org.knowm.xchange.bankera.dto.marketdata; - -import com.fasterxml.jackson.annotation.JsonProperty; -import java.util.List; - -public class BankeraOrderBook { - - private final List bids; - private final List asks; - - public BankeraOrderBook( - @JsonProperty("bids") List bids, - @JsonProperty("asks") List asks) { - this.asks = asks; - this.bids = bids; - } - - public List getBids() { - return bids; - } - - public List getAsks() { - return asks; - } - - public static final class OrderBookOrder { - private final Integer id; - private final String price; - private final String amount; - - public OrderBookOrder( - @JsonProperty("id") Integer id, - @JsonProperty("price") String price, - @JsonProperty("amount") String amount) { - - this.id = id; - this.price = price; - this.amount = amount; - } - - public Integer getId() { - return id; - } - - public String getPrice() { - return price; - } - - public String getAmount() { - return amount; - } - } -} diff --git a/xchange-bankera/src/main/java/org/knowm/xchange/bankera/dto/marketdata/BankeraTicker.java b/xchange-bankera/src/main/java/org/knowm/xchange/bankera/dto/marketdata/BankeraTicker.java deleted file mode 100644 index cfd6b1f5420..00000000000 --- a/xchange-bankera/src/main/java/org/knowm/xchange/bankera/dto/marketdata/BankeraTicker.java +++ /dev/null @@ -1,81 +0,0 @@ -package org.knowm.xchange.bankera.dto.marketdata; - -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; - -@JsonInclude(JsonInclude.Include.NON_NULL) -public class BankeraTicker { - - private final Integer id; - private final String high; - private final String low; - private final String bid; - private final String ask; - private final String last; - private final String volume; - private final long timestamp; - - /** - * Constructor - * - * @param id - * @param high - * @param low - * @param bid - * @param ask - * @param last - * @param volume - * @param timestamp - */ - public BankeraTicker( - @JsonProperty("id") Integer id, - @JsonProperty("high") String high, - @JsonProperty("low") String low, - @JsonProperty("bid") String bid, - @JsonProperty("ask") String ask, - @JsonProperty("last") String last, - @JsonProperty("volume") String volume, - @JsonProperty("timestamp") long timestamp) { - - this.id = id; - this.high = high; - this.low = low; - this.bid = bid; - this.ask = ask; - this.last = last; - this.volume = volume; - this.timestamp = timestamp; - } - - public Integer getId() { - return id; - } - - public String getHigh() { - return high; - } - - public String getLow() { - return low; - } - - public String getBid() { - return bid; - } - - public String getAsk() { - return ask; - } - - public String getLast() { - return last; - } - - public String getVolume() { - return volume; - } - - public long getTimestamp() { - return timestamp; - } -} diff --git a/xchange-bankera/src/main/java/org/knowm/xchange/bankera/dto/marketdata/BankeraTickerResponse.java b/xchange-bankera/src/main/java/org/knowm/xchange/bankera/dto/marketdata/BankeraTickerResponse.java deleted file mode 100644 index 2703b5b98df..00000000000 --- a/xchange-bankera/src/main/java/org/knowm/xchange/bankera/dto/marketdata/BankeraTickerResponse.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.knowm.xchange.bankera.dto.marketdata; - -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; - -@JsonInclude(JsonInclude.Include.NON_NULL) -public class BankeraTickerResponse { - - private final BankeraTicker ticker; - - public BankeraTickerResponse(@JsonProperty("ticker") BankeraTicker ticker) { - this.ticker = ticker; - } - - @JsonProperty("ticker") - public BankeraTicker getTicker() { - return ticker; - } -} diff --git a/xchange-bankera/src/main/java/org/knowm/xchange/bankera/dto/marketdata/BankeraTrade.java b/xchange-bankera/src/main/java/org/knowm/xchange/bankera/dto/marketdata/BankeraTrade.java deleted file mode 100644 index 9e6ead11913..00000000000 --- a/xchange-bankera/src/main/java/org/knowm/xchange/bankera/dto/marketdata/BankeraTrade.java +++ /dev/null @@ -1,45 +0,0 @@ -package org.knowm.xchange.bankera.dto.marketdata; - -import com.fasterxml.jackson.annotation.JsonProperty; - -public class BankeraTrade { - - private final String market; - private final String amount; - private final String price; - private final String side; - private final String time; - - public BankeraTrade( - @JsonProperty("market") String market, - @JsonProperty("amount") String amount, - @JsonProperty("price") String price, - @JsonProperty("side") String side, - @JsonProperty("time") String time) { - this.market = market; - this.amount = amount; - this.price = price; - this.side = side; - this.time = time; - } - - public String getMarket() { - return market; - } - - public String getAmount() { - return amount; - } - - public String getPrice() { - return price; - } - - public String getSide() { - return side; - } - - public String getTime() { - return time; - } -} diff --git a/xchange-bankera/src/main/java/org/knowm/xchange/bankera/dto/marketdata/BankeraTradesResponse.java b/xchange-bankera/src/main/java/org/knowm/xchange/bankera/dto/marketdata/BankeraTradesResponse.java deleted file mode 100644 index a43c97ef0f3..00000000000 --- a/xchange-bankera/src/main/java/org/knowm/xchange/bankera/dto/marketdata/BankeraTradesResponse.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.knowm.xchange.bankera.dto.marketdata; - -import com.fasterxml.jackson.annotation.JsonProperty; -import java.util.List; - -public class BankeraTradesResponse { - - private final List trades; - - public BankeraTradesResponse(@JsonProperty("deals") List trades) { - this.trades = trades; - } - - public List getTrades() { - return trades; - } -} diff --git a/xchange-bankera/src/main/java/org/knowm/xchange/bankera/dto/trade/BankeraOpenOrders.java b/xchange-bankera/src/main/java/org/knowm/xchange/bankera/dto/trade/BankeraOpenOrders.java deleted file mode 100644 index a82e09272a2..00000000000 --- a/xchange-bankera/src/main/java/org/knowm/xchange/bankera/dto/trade/BankeraOpenOrders.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.knowm.xchange.bankera.dto.trade; - -import com.fasterxml.jackson.annotation.JsonProperty; -import java.util.List; - -public class BankeraOpenOrders { - - private final List openOrders; - - public BankeraOpenOrders(@JsonProperty("orders") List openOrders) { - - this.openOrders = openOrders; - } - - public List getOpenOrders() { - return openOrders; - } -} diff --git a/xchange-bankera/src/main/java/org/knowm/xchange/bankera/dto/trade/BankeraOrder.java b/xchange-bankera/src/main/java/org/knowm/xchange/bankera/dto/trade/BankeraOrder.java deleted file mode 100644 index 00500d1453c..00000000000 --- a/xchange-bankera/src/main/java/org/knowm/xchange/bankera/dto/trade/BankeraOrder.java +++ /dev/null @@ -1,129 +0,0 @@ -package org.knowm.xchange.bankera.dto.trade; - -import com.fasterxml.jackson.annotation.JsonProperty; -import java.math.BigDecimal; -import java.util.List; -import java.util.function.Function; - -public class BankeraOrder { - - private final long id; - private final String market; - private final String price; - private final String side; - private final String type; - private final String status; - private final String amount; - private final String remainingAmount; - private final String executedAmount; - private final String clientOrderId; - private final String createdAt; - private final String updatedAt; - private final String cancelledAt; - private final List transactions; - - /** - * @param id id of order - * @param market order market name - * @param price order price - * @param side order side (buy/sell) - * @param type order type (limit/market) - * @param status order status - * @param amount order amount - * @param clientOrderId custom or generated client order id - */ - public BankeraOrder( - @JsonProperty("id") long id, - @JsonProperty("market") String market, - @JsonProperty("price") String price, - @JsonProperty("side") String side, - @JsonProperty("type") String type, - @JsonProperty("status") String status, - @JsonProperty("amount") String amount, - @JsonProperty("executed_amount") String executedAmount, - @JsonProperty("remaining_amount") String remainingAmount, - @JsonProperty("client_order_id") String clientOrderId, - @JsonProperty("created_at") String createdAt, - @JsonProperty("updated_at") String updatedAt, - @JsonProperty("cancelled_at") String cancelledAt, - @JsonProperty("transactions") List transactions) { - - this.id = id; - this.market = market; - this.price = price; - this.side = side; - this.type = type; - this.status = status; - this.amount = amount; - this.clientOrderId = clientOrderId; - this.executedAmount = executedAmount; - this.remainingAmount = remainingAmount; - this.createdAt = createdAt; - this.updatedAt = updatedAt; - this.cancelledAt = cancelledAt; - this.transactions = transactions; - } - - public long getId() { - return id; - } - - public String getMarket() { - return market; - } - - public String getPrice() { - return price; - } - - public String getSide() { - return side; - } - - public String getType() { - return type; - } - - public String getStatus() { - return status; - } - - public String getAmount() { - return amount; - } - - public String getClientOrderId() { - return clientOrderId; - } - - public String getRemainingAmount() { - return remainingAmount; - } - - public String getExecutedAmount() { - return executedAmount; - } - - public String getCreatedAt() { - return createdAt; - } - - public String getUpdatedAt() { - return updatedAt; - } - - public String getCancelledAt() { - return cancelledAt; - } - - public List getTransactions() { - return transactions; - } - - public BigDecimal getTotalFee() { - Function totalMapper = tx -> new BigDecimal(tx.getFee()); - return transactions.size() > 0 - ? transactions.stream().map(totalMapper).reduce(BigDecimal.ZERO, BigDecimal::add) - : BigDecimal.ZERO; - } -} diff --git a/xchange-bankera/src/main/java/org/knowm/xchange/bankera/dto/trade/BankeraTransaction.java b/xchange-bankera/src/main/java/org/knowm/xchange/bankera/dto/trade/BankeraTransaction.java deleted file mode 100644 index fa8f74485cb..00000000000 --- a/xchange-bankera/src/main/java/org/knowm/xchange/bankera/dto/trade/BankeraTransaction.java +++ /dev/null @@ -1,87 +0,0 @@ -package org.knowm.xchange.bankera.dto.trade; - -import com.fasterxml.jackson.annotation.JsonProperty; - -public class BankeraTransaction { - - private final long id; - private final long orderId; - private final String market; - private final String amount; - private final String fee; - private final String price; - private final String total; - private final String status; - private final String type; - private final String platform; - private final String completedAt; - - public BankeraTransaction( - @JsonProperty("id") long id, - @JsonProperty("orderId") long orderId, - @JsonProperty("market") String market, - @JsonProperty("amount") String amount, - @JsonProperty("fee") String fee, - @JsonProperty("price") String price, - @JsonProperty("total") String total, - @JsonProperty("status") String status, - @JsonProperty("type") String type, - @JsonProperty("platform") String platform, - @JsonProperty("completed_at") String completedAt) { - this.id = id; - this.orderId = orderId; - this.market = market; - this.amount = amount; - this.fee = fee; - this.price = price; - this.total = total; - this.status = status; - this.type = type; - this.platform = platform; - this.completedAt = completedAt; - } - - public long getId() { - return id; - } - - public long getOrderId() { - return orderId; - } - - public String getMarket() { - return market; - } - - public String getAmount() { - return amount; - } - - public String getFee() { - return fee; - } - - public String getPrice() { - return price; - } - - public String getTotal() { - return total; - } - - public String getStatus() { - return status; - } - - public String getType() { - return type; - } - - public String getPlatform() { - return platform; - } - - public String getCompletedAt() { - return completedAt; - } -} diff --git a/xchange-bankera/src/main/java/org/knowm/xchange/bankera/dto/trade/BankeraUserTrade.java b/xchange-bankera/src/main/java/org/knowm/xchange/bankera/dto/trade/BankeraUserTrade.java deleted file mode 100644 index 39a233ead23..00000000000 --- a/xchange-bankera/src/main/java/org/knowm/xchange/bankera/dto/trade/BankeraUserTrade.java +++ /dev/null @@ -1,80 +0,0 @@ -package org.knowm.xchange.bankera.dto.trade; - -import com.fasterxml.jackson.annotation.JsonProperty; - -public class BankeraUserTrade { - - private final long id; - private final long orderId; - private final String market; - private final String amount; - private final String price; - private final String feeAmount; - private final String total; - private final String status; - private final String side; - private final String completedAt; - - public BankeraUserTrade( - @JsonProperty("id") long id, - @JsonProperty("order_id") long orderId, - @JsonProperty("market") String market, - @JsonProperty("price") String price, - @JsonProperty("amount") String amount, - @JsonProperty("fee_amount") String feeAmount, - @JsonProperty("total") String total, - @JsonProperty("status") String status, - @JsonProperty("side") String side, - @JsonProperty("completed_at") String completedAt) { - this.id = id; - this.orderId = orderId; - this.market = market; - this.amount = amount; - this.feeAmount = feeAmount; - this.total = total; - this.status = status; - this.side = side; - this.completedAt = completedAt; - this.price = price; - } - - public long getId() { - return id; - } - - public long getOrderId() { - return orderId; - } - - public String getMarket() { - return market; - } - - public String getAmount() { - return amount; - } - - public String getFeeAmount() { - return feeAmount; - } - - public String getTotal() { - return total; - } - - public String getStatus() { - return status; - } - - public String getSide() { - return side; - } - - public String getCompletedAt() { - return completedAt; - } - - public String getPrice() { - return price; - } -} diff --git a/xchange-bankera/src/main/java/org/knowm/xchange/bankera/dto/trade/BankeraUserTrades.java b/xchange-bankera/src/main/java/org/knowm/xchange/bankera/dto/trade/BankeraUserTrades.java deleted file mode 100644 index e7f37f4cbc5..00000000000 --- a/xchange-bankera/src/main/java/org/knowm/xchange/bankera/dto/trade/BankeraUserTrades.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.knowm.xchange.bankera.dto.trade; - -import com.fasterxml.jackson.annotation.JsonProperty; -import java.util.List; - -public class BankeraUserTrades { - - private final List trades; - - public BankeraUserTrades(@JsonProperty("trades") List trades) { - - this.trades = trades; - } - - public List getTrades() { - return trades; - } -} diff --git a/xchange-bankera/src/main/java/org/knowm/xchange/bankera/service/BankeraAccountService.java b/xchange-bankera/src/main/java/org/knowm/xchange/bankera/service/BankeraAccountService.java deleted file mode 100644 index 39e7b23546d..00000000000 --- a/xchange-bankera/src/main/java/org/knowm/xchange/bankera/service/BankeraAccountService.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.knowm.xchange.bankera.service; - -import java.io.IOException; -import org.knowm.xchange.Exchange; -import org.knowm.xchange.bankera.BankeraAdapters; -import org.knowm.xchange.dto.account.AccountInfo; -import org.knowm.xchange.service.account.AccountService; - -public class BankeraAccountService extends BankeraAccountServiceRaw implements AccountService { - - public BankeraAccountService(Exchange exchange) { - super(exchange); - } - - @Override - public AccountInfo getAccountInfo() throws IOException { - return BankeraAdapters.adaptAccountInfo(getUserInfo()); - } -} diff --git a/xchange-bankera/src/main/java/org/knowm/xchange/bankera/service/BankeraAccountServiceRaw.java b/xchange-bankera/src/main/java/org/knowm/xchange/bankera/service/BankeraAccountServiceRaw.java deleted file mode 100644 index 785e9cd450a..00000000000 --- a/xchange-bankera/src/main/java/org/knowm/xchange/bankera/service/BankeraAccountServiceRaw.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.knowm.xchange.bankera.service; - -import java.io.IOException; -import org.knowm.xchange.Exchange; -import org.knowm.xchange.bankera.BankeraAdapters; -import org.knowm.xchange.bankera.BankeraExchange; -import org.knowm.xchange.bankera.dto.BankeraException; -import org.knowm.xchange.bankera.dto.account.BankeraUserInfo; - -public class BankeraAccountServiceRaw extends BankeraBaseService { - - public BankeraAccountServiceRaw(Exchange exchange) { - super(exchange); - } - - public BankeraUserInfo getUserInfo() throws IOException { - try { - BankeraExchange bankeraExchange = (BankeraExchange) exchange; - String auth = "Bearer " + bankeraExchange.getToken().getAccessToken(); - return bankeraAuthenticated.getUserInfo(auth); - } catch (BankeraException e) { - throw BankeraAdapters.adaptError(e); - } - } -} diff --git a/xchange-bankera/src/main/java/org/knowm/xchange/bankera/service/BankeraBaseService.java b/xchange-bankera/src/main/java/org/knowm/xchange/bankera/service/BankeraBaseService.java deleted file mode 100644 index 038361a4aa3..00000000000 --- a/xchange-bankera/src/main/java/org/knowm/xchange/bankera/service/BankeraBaseService.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.knowm.xchange.bankera.service; - -import org.knowm.xchange.Exchange; -import org.knowm.xchange.bankera.Bankera; -import org.knowm.xchange.bankera.BankeraAuthenticated; -import org.knowm.xchange.bankera.dto.BankeraException; -import org.knowm.xchange.bankera.dto.BankeraToken; -import org.knowm.xchange.client.ExchangeRestProxyBuilder; -import org.knowm.xchange.service.BaseExchangeService; -import org.knowm.xchange.service.BaseService; - -public class BankeraBaseService extends BaseExchangeService implements BaseService { - - protected final Bankera bankera; - protected final BankeraAuthenticated bankeraAuthenticated; - - public BankeraBaseService(Exchange exchange) { - super(exchange); - bankera = - ExchangeRestProxyBuilder.forInterface(Bankera.class, exchange.getExchangeSpecification()) - .build(); - bankeraAuthenticated = - ExchangeRestProxyBuilder.forInterface( - BankeraAuthenticated.class, exchange.getExchangeSpecification()) - .build(); - } - - public BankeraToken createToken() throws BankeraException { - String clientId = (String) exchange.getExchangeSpecification().getParameter("clientId"); - String clientSecret = (String) exchange.getExchangeSpecification().getParameter("clientSecret"); - return bankera.getToken("client_credentials", clientId, clientSecret); - } -} diff --git a/xchange-bankera/src/main/java/org/knowm/xchange/bankera/service/BankeraMarketDataService.java b/xchange-bankera/src/main/java/org/knowm/xchange/bankera/service/BankeraMarketDataService.java deleted file mode 100644 index 0b2bd0a3473..00000000000 --- a/xchange-bankera/src/main/java/org/knowm/xchange/bankera/service/BankeraMarketDataService.java +++ /dev/null @@ -1,37 +0,0 @@ -package org.knowm.xchange.bankera.service; - -import java.io.IOException; -import org.knowm.xchange.Exchange; -import org.knowm.xchange.bankera.BankeraAdapters; -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.marketdata.Trades; -import org.knowm.xchange.service.marketdata.MarketDataService; - -public class BankeraMarketDataService extends BankeraMarketDataServiceRaw - implements MarketDataService { - - public BankeraMarketDataService(Exchange exchange) { - - super(exchange); - } - - @Override - public Ticker getTicker(CurrencyPair currencyPair, Object... args) throws IOException { - - return BankeraAdapters.adaptTicker(getBankeraTicker(currencyPair), currencyPair); - } - - @Override - public OrderBook getOrderBook(CurrencyPair currencyPair, Object... args) throws IOException { - - return BankeraAdapters.adaptOrderBook(getOrderbook(currencyPair), currencyPair); - } - - @Override - public Trades getTrades(CurrencyPair currencyPair, Object... args) throws IOException { - - return BankeraAdapters.adaptTrades(getRecentTrades(currencyPair), currencyPair); - } -} diff --git a/xchange-bankera/src/main/java/org/knowm/xchange/bankera/service/BankeraMarketDataServiceRaw.java b/xchange-bankera/src/main/java/org/knowm/xchange/bankera/service/BankeraMarketDataServiceRaw.java deleted file mode 100644 index 1fe6c892719..00000000000 --- a/xchange-bankera/src/main/java/org/knowm/xchange/bankera/service/BankeraMarketDataServiceRaw.java +++ /dev/null @@ -1,65 +0,0 @@ -package org.knowm.xchange.bankera.service; - -import java.io.IOException; -import org.knowm.xchange.Exchange; -import org.knowm.xchange.bankera.BankeraAdapters; -import org.knowm.xchange.bankera.dto.BankeraException; -import org.knowm.xchange.bankera.dto.marketdata.BankeraMarketInfo; -import org.knowm.xchange.bankera.dto.marketdata.BankeraOrderBook; -import org.knowm.xchange.bankera.dto.marketdata.BankeraTickerResponse; -import org.knowm.xchange.bankera.dto.marketdata.BankeraTradesResponse; -import org.knowm.xchange.currency.CurrencyPair; - -public class BankeraMarketDataServiceRaw extends BankeraBaseService { - - public BankeraMarketDataServiceRaw(Exchange exchange) { - super(exchange); - } - - public BankeraTickerResponse getBankeraTicker(CurrencyPair currencyPair) throws IOException { - - try { - return bankera.getMarketTicker(getMarketNameFromPair(currencyPair)); - } catch (BankeraException e) { - throw BankeraAdapters.adaptError(e); - } - } - - public BankeraOrderBook getOrderbook(CurrencyPair currencyPair) throws IOException { - - try { - return bankera.getOrderbook(getMarketNameFromPair(currencyPair)); - } catch (BankeraException e) { - throw BankeraAdapters.adaptError(e); - } - } - - public BankeraMarketInfo getMarketInfo() throws IOException { - - try { - return bankera.getMarketInfo(); - } catch (BankeraException e) { - throw BankeraAdapters.adaptError(e); - } - } - - public BankeraTradesResponse getRecentTrades(CurrencyPair currencyPair) throws IOException { - - try { - return bankera.getRecentTrades(getMarketNameFromPair(currencyPair)); - } catch (BankeraException e) { - throw BankeraAdapters.adaptError(e); - } - } - - private static String getMarketNameFromPair(CurrencyPair pair) { - - return pair == null - ? null - : new StringBuilder() - .append(pair.base.getCurrencyCode()) - .append("-") - .append(pair.counter.getCurrencyCode()) - .toString(); - } -} diff --git a/xchange-bankera/src/main/java/org/knowm/xchange/bankera/service/BankeraTradeService.java b/xchange-bankera/src/main/java/org/knowm/xchange/bankera/service/BankeraTradeService.java deleted file mode 100644 index f0c325bd985..00000000000 --- a/xchange-bankera/src/main/java/org/knowm/xchange/bankera/service/BankeraTradeService.java +++ /dev/null @@ -1,150 +0,0 @@ -package org.knowm.xchange.bankera.service; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import org.knowm.xchange.Exchange; -import org.knowm.xchange.bankera.BankeraAdapters; -import org.knowm.xchange.bankera.dto.trade.BankeraOrder; -import org.knowm.xchange.bankera.dto.trade.BankeraUserTrades; -import org.knowm.xchange.currency.CurrencyPair; -import org.knowm.xchange.dto.Order; -import org.knowm.xchange.dto.marketdata.Trades; -import org.knowm.xchange.dto.trade.LimitOrder; -import org.knowm.xchange.dto.trade.MarketOrder; -import org.knowm.xchange.dto.trade.OpenOrders; -import org.knowm.xchange.dto.trade.UserTrades; -import org.knowm.xchange.exceptions.NotYetImplementedForExchangeException; -import org.knowm.xchange.service.trade.TradeService; -import org.knowm.xchange.service.trade.params.CancelOrderParams; -import org.knowm.xchange.service.trade.params.DefaultTradeHistoryParamCurrencyPair; -import org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair; -import org.knowm.xchange.service.trade.params.TradeHistoryParams; -import org.knowm.xchange.service.trade.params.orders.*; - -public class BankeraTradeService extends BankeraTradeServiceRaw implements TradeService { - - public BankeraTradeService(Exchange exchange) { - - super(exchange); - } - - @Override - public OpenOrders getOpenOrders() throws IOException { - return getOpenOrders(null); - } - - @Override - public OpenOrders getOpenOrders(OpenOrdersParams params) throws IOException { - return new OpenOrders(BankeraAdapters.adaptOpenOrders(getBankeraOpenOrders(params))); - } - - @Override - public String placeMarketOrder(MarketOrder marketOrder) throws IOException { - BankeraOrder order = placeBankeraMarketOrder(marketOrder); - return Long.toString(order.getId()); - } - - @Override - public String placeLimitOrder(LimitOrder limitOrder) throws IOException { - BankeraOrder order = placeBankeraLimitOrder(limitOrder); - return Long.toString(order.getId()); - } - - @Override - public boolean cancelOrder(String orderId) throws IOException { - BankeraOrder order = cancelBankeraOrder(orderId); - return order != null; - } - - @Override - public boolean cancelOrder(CancelOrderParams orderParams) throws IOException { - throw new NotYetImplementedForExchangeException(); - } - - @Override - public UserTrades getTradeHistory(TradeHistoryParams params) throws IOException { - - CurrencyPair currencyPair = null; - if (params instanceof TradeHistoryParamCurrencyPair) { - TradeHistoryParamCurrencyPair tradeHistoryParamCurrencyPair = - (TradeHistoryParamCurrencyPair) params; - currencyPair = tradeHistoryParamCurrencyPair.getCurrencyPair(); - } - - BankeraUserTrades trades = getUserTrades(currencyPair); - return new UserTrades( - BankeraAdapters.adaptUserTrades(trades), Trades.TradeSortType.SortByTimestamp); - } - - @Override - public TradeHistoryParams createTradeHistoryParams() { - return new DefaultTradeHistoryParamCurrencyPair(); - } - - @Override - public OpenOrdersParams createOpenOrdersParams() { - return new BankeraOpenOrderParams(); - } - - public static class BankeraOpenOrderParams - implements OpenOrdersParams, - OpenOrdersParamLimit, - OpenOrdersParamCurrencyPair, - OpenOrdersParamOffset { - - private Integer limit = 100; - private Integer offset = 0; - private CurrencyPair currencyPair; - - public BankeraOpenOrderParams() {} - - @Override - public boolean accept(LimitOrder order) { - return OpenOrdersParamCurrencyPair.super.accept(order); - } - - @Override - public Integer getLimit() { - return limit; - } - - @Override - public void setLimit(Integer limit) { - this.limit = limit; - } - - @Override - public Integer getOffset() { - return offset; - } - - @Override - public void setOffset(Integer offset) { - this.offset = offset; - } - - @Override - public CurrencyPair getCurrencyPair() { - return currencyPair; - } - - @Override - public void setCurrencyPair(CurrencyPair pair) { - this.currencyPair = pair; - } - } - - @Override - public Collection getOrder(OrderQueryParams... orderQueryParams) throws IOException { - List orders = new ArrayList<>(orderQueryParams.length); - - for (OrderQueryParams orderQueryParam : orderQueryParams) { - BankeraOrder order = getUserOrder(orderQueryParam.getOrderId()); - orders.add(BankeraAdapters.adaptOrder(order)); - } - - return orders; - } -} diff --git a/xchange-bankera/src/main/java/org/knowm/xchange/bankera/service/BankeraTradeServiceRaw.java b/xchange-bankera/src/main/java/org/knowm/xchange/bankera/service/BankeraTradeServiceRaw.java deleted file mode 100644 index e3e027eb4e9..00000000000 --- a/xchange-bankera/src/main/java/org/knowm/xchange/bankera/service/BankeraTradeServiceRaw.java +++ /dev/null @@ -1,155 +0,0 @@ -package org.knowm.xchange.bankera.service; - -import java.io.IOException; -import java.util.List; -import org.knowm.xchange.Exchange; -import org.knowm.xchange.bankera.BankeraAdapters; -import org.knowm.xchange.bankera.BankeraExchange; -import org.knowm.xchange.bankera.dto.BankeraException; -import org.knowm.xchange.bankera.dto.BaseBankeraRequest; -import org.knowm.xchange.bankera.dto.CreateOrderRequest; -import org.knowm.xchange.bankera.dto.trade.BankeraOpenOrders; -import org.knowm.xchange.bankera.dto.trade.BankeraOrder; -import org.knowm.xchange.bankera.dto.trade.BankeraUserTrades; -import org.knowm.xchange.currency.CurrencyPair; -import org.knowm.xchange.dto.Order; -import org.knowm.xchange.dto.trade.LimitOrder; -import org.knowm.xchange.dto.trade.MarketOrder; -import org.knowm.xchange.service.trade.params.orders.OpenOrdersParamCurrencyPair; -import org.knowm.xchange.service.trade.params.orders.OpenOrdersParamLimit; -import org.knowm.xchange.service.trade.params.orders.OpenOrdersParamOffset; -import org.knowm.xchange.service.trade.params.orders.OpenOrdersParams; - -public class BankeraTradeServiceRaw extends BankeraBaseService { - - public BankeraTradeServiceRaw(Exchange exchange) { - - super(exchange); - } - - public BankeraOpenOrders getBankeraOpenOrders(OpenOrdersParams params) throws IOException { - try { - BankeraExchange bankeraExchange = (BankeraExchange) exchange; - String auth = "Bearer " + bankeraExchange.getToken().getAccessToken(); - String market = null; - Integer limit = 100; - Integer offset = 0; - if (params instanceof OpenOrdersParamCurrencyPair) { - CurrencyPair currencyPair = ((OpenOrdersParamCurrencyPair) params).getCurrencyPair(); - market = getMarketNameFromPair(currencyPair); - } - if (params instanceof OpenOrdersParamLimit) { - limit = ((OpenOrdersParamLimit) params).getLimit(); - } - if (params instanceof OpenOrdersParamOffset) { - offset = ((OpenOrdersParamOffset) params).getOffset(); - } - return bankeraAuthenticated.getOpenOrders(auth, market, limit, offset); - } catch (BankeraException e) { - throw BankeraAdapters.adaptError(e); - } - } - - public BankeraOrder placeBankeraLimitOrder(LimitOrder limitOrder) throws IOException { - try { - BankeraExchange bankeraExchange = (BankeraExchange) exchange; - String auth = "Bearer " + bankeraExchange.getToken().getAccessToken(); - String market = getMarketNameFromPair(limitOrder.getCurrencyPair()); - - return bankeraAuthenticated.placeOrder( - auth, - new CreateOrderRequest( - market, - (limitOrder.getType() == Order.OrderType.BID - ? CreateOrderRequest.Side.BUY.getSide() - : CreateOrderRequest.Side.SELL.getSide()), - limitOrder.getOriginalAmount(), - limitOrder.getLimitPrice(), - limitOrder.getId(), - exchange.getNonceFactory().createValue())); - } catch (BankeraException e) { - throw BankeraAdapters.adaptError(e); - } - } - - public BankeraOrder placeBankeraMarketOrder(MarketOrder marketOrder) throws IOException { - - try { - BankeraExchange bankeraExchange = (BankeraExchange) exchange; - String auth = "Bearer " + bankeraExchange.getToken().getAccessToken(); - String market = getMarketNameFromPair(marketOrder.getCurrencyPair()); - - return bankeraAuthenticated.placeOrder( - auth, - new CreateOrderRequest( - market, - (marketOrder.getType() == Order.OrderType.BID - ? CreateOrderRequest.Side.BUY.getSide() - : CreateOrderRequest.Side.SELL.getSide()), - marketOrder.getOriginalAmount(), - marketOrder.getId(), - exchange.getNonceFactory().createValue())); - } catch (BankeraException e) { - throw BankeraAdapters.adaptError(e); - } - } - - public BankeraOrder cancelBankeraOrder(String orderId) throws IOException { - - try { - BankeraExchange bankeraExchange = (BankeraExchange) exchange; - String auth = "Bearer " + bankeraExchange.getToken().getAccessToken(); - return bankeraAuthenticated.cancelOrder( - auth, - Long.valueOf(orderId), - new BaseBankeraRequest(exchange.getNonceFactory().createValue())); - } catch (BankeraException e) { - throw BankeraAdapters.adaptError(e); - } - } - - public List cancelAllBankeraOrders() throws IOException { - - try { - BankeraExchange bankeraExchange = (BankeraExchange) exchange; - String auth = "Bearer " + bankeraExchange.getToken().getAccessToken(); - return bankeraAuthenticated.cancelAllOrders(auth); - } catch (BankeraException e) { - throw BankeraAdapters.adaptError(e); - } - } - - public BankeraUserTrades getUserTrades(CurrencyPair currencyPair) throws IOException { - - try { - BankeraExchange bankeraExchange = (BankeraExchange) exchange; - String auth = "Bearer " + bankeraExchange.getToken().getAccessToken(); - String market = getMarketNameFromPair(currencyPair); - return bankeraAuthenticated.getUserTrades(auth, market); - } catch (BankeraException e) { - throw BankeraAdapters.adaptError(e); - } - } - - public BankeraOrder getUserOrder(String orderId) throws IOException { - - try { - BankeraExchange bankeraExchange = (BankeraExchange) exchange; - String auth = "Bearer " + bankeraExchange.getToken().getAccessToken(); - return bankeraAuthenticated.getUserOrder(auth, orderId); - } catch (BankeraException e) { - throw BankeraAdapters.adaptError(e); - } - } - - private static String getMarketNameFromPair(CurrencyPair pair) { - - return pair == null - ? null - : new StringBuilder() - .append(pair.base.getCurrencyCode()) - .append("-") - .append(pair.counter.getCurrencyCode()) - .toString(); - } -} diff --git a/xchange-bankera/src/main/resources/bankera.json b/xchange-bankera/src/main/resources/bankera.json deleted file mode 100644 index 9e26dfeeb6e..00000000000 --- a/xchange-bankera/src/main/resources/bankera.json +++ /dev/null @@ -1 +0,0 @@ -{} \ No newline at end of file diff --git a/xchange-bankera/src/test/java/org/knowm/xchange/bankera/ExchangeUtils.java b/xchange-bankera/src/test/java/org/knowm/xchange/bankera/ExchangeUtils.java deleted file mode 100644 index 7d11f7a95ed..00000000000 --- a/xchange-bankera/src/test/java/org/knowm/xchange/bankera/ExchangeUtils.java +++ /dev/null @@ -1,41 +0,0 @@ -package org.knowm.xchange.bankera; - -import java.io.InputStream; -import java.util.Properties; -import org.knowm.xchange.Exchange; -import org.knowm.xchange.ExchangeFactory; -import org.knowm.xchange.ExchangeSpecification; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class ExchangeUtils { - private static final Logger logger = LoggerFactory.getLogger(ExchangeUtils.class); - - public static Exchange createExchangeFromProperties() { - - ExchangeSpecification exSpec = new ExchangeSpecification(BankeraExchange.class); - - InputStream is = - ExchangeUtils.class.getResourceAsStream( - "/org/knowm/xchange/bankera/configuration.properties"); - Properties props = new Properties(); - - try { - props.load(is); - logger.debug(props.toString()); - - if (props.getProperty("client-id") != null) { - exSpec.setExchangeSpecificParametersItem("clientId", props.getProperty("client-id")); - } - if (props.getProperty("client-secret") != null) { - exSpec.setExchangeSpecificParametersItem( - "clientSecret", props.getProperty("client-secret")); - } - } catch (Exception e) { - logger.warn("Error while loading integration test properties", e); - return null; - } - - return ExchangeFactory.INSTANCE.createExchange(exSpec); - } -} diff --git a/xchange-bankera/src/test/java/org/knowm/xchange/bankera/dto/account/BankeraUserInfoTest.java b/xchange-bankera/src/test/java/org/knowm/xchange/bankera/dto/account/BankeraUserInfoTest.java deleted file mode 100644 index 1df347b7103..00000000000 --- a/xchange-bankera/src/test/java/org/knowm/xchange/bankera/dto/account/BankeraUserInfoTest.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.knowm.xchange.bankera.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.util.Arrays; -import java.util.List; -import org.junit.Test; - -public class BankeraUserInfoTest { - @Test - public void jsonMapperTest() throws IOException { - InputStream is = - getClass().getResourceAsStream("/org/knowm/xchange/bankera/dto/account/user_info.json"); - ObjectMapper mapper = new ObjectMapper(); - final BankeraUserInfo userInfo = mapper.readValue(is, BankeraUserInfo.class); - assertThat(userInfo).isNotNull(); - assertThat(userInfo.getUser()).isNotNull(); - BankeraUser user = userInfo.getUser(); - assertThat(user.getId()).isEqualTo(7); - assertThat(user.getWallets()).isNotEmpty().hasSize(5); - - List wallets = user.getWallets(); - - wallets.stream() - .forEach( - w -> { - assertThat(w.getBalance()).isEqualTo("10.000000000000000000000000000000"); - assertThat(w.getTotal()).isEqualTo("30.000000000000000000000000000000"); - assertThat(w.getReserved()).isEqualTo("20.000000000000000000000000000000"); - assertThat(w.getCurrency()).isNotNull(); - assertThat(Arrays.asList("BTC", "ETH", "BNK", "DASH", "XEM")) - .contains(w.getCurrency()); - }); - } -} diff --git a/xchange-bankera/src/test/java/org/knowm/xchange/bankera/service/AccountInfoFetchIntegration.java b/xchange-bankera/src/test/java/org/knowm/xchange/bankera/service/AccountInfoFetchIntegration.java deleted file mode 100644 index 690e604ac45..00000000000 --- a/xchange-bankera/src/test/java/org/knowm/xchange/bankera/service/AccountInfoFetchIntegration.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.knowm.xchange.bankera.service; - -import static org.junit.Assert.assertNotNull; - -import org.junit.Before; -import org.junit.Test; -import org.knowm.xchange.Exchange; -import org.knowm.xchange.bankera.ExchangeUtils; -import org.knowm.xchange.dto.account.AccountInfo; -import org.knowm.xchange.service.account.AccountService; - -public class AccountInfoFetchIntegration { - - private Exchange exchange; - - @Before - public void setUp() { - - exchange = ExchangeUtils.createExchangeFromProperties(); - } - - @Test - public void fetchAccountInfoTest() throws Exception { - AccountService service = exchange.getAccountService(); - assertNotNull(service); - // verify account info exists - AccountInfo info = service.getAccountInfo(); - assertNotNull(info); - } -} diff --git a/xchange-bankera/src/test/java/org/knowm/xchange/bankera/service/MarketDataServiceIntegration.java b/xchange-bankera/src/test/java/org/knowm/xchange/bankera/service/MarketDataServiceIntegration.java deleted file mode 100644 index 55be94b138d..00000000000 --- a/xchange-bankera/src/test/java/org/knowm/xchange/bankera/service/MarketDataServiceIntegration.java +++ /dev/null @@ -1,58 +0,0 @@ -package org.knowm.xchange.bankera.service; - -import static org.junit.Assert.assertNotNull; - -import org.junit.BeforeClass; -import org.junit.Test; -import org.knowm.xchange.Exchange; -import org.knowm.xchange.bankera.ExchangeUtils; -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.marketdata.Trades; -import org.knowm.xchange.exceptions.ExchangeException; -import org.knowm.xchange.service.marketdata.MarketDataService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class MarketDataServiceIntegration { - - private final Logger logger = LoggerFactory.getLogger(this.getClass()); - private static MarketDataService marketDataService; - - @BeforeClass - public static void init() { - - Exchange exchange = ExchangeUtils.createExchangeFromProperties(); - marketDataService = exchange.getMarketDataService(); - } - - @Test - public void getTickerTest() throws Exception { - - Ticker ticker = marketDataService.getTicker(CurrencyPair.ETH_BTC); - assertNotNull(ticker); - logger.info("Response: {}", ticker); - } - - @Test(expected = ExchangeException.class) - public void getTickerInvalidMarketTest() throws Exception { - marketDataService.getTicker(CurrencyPair.ADA_BNB); - } - - @Test - public void getOrderBookTest() throws Exception { - - OrderBook orderBook = marketDataService.getOrderBook(CurrencyPair.BNK_USDT); - assertNotNull(orderBook); - logger.info("Response: {}", orderBook); - } - - @Test - public void getTradesTest() throws Exception { - - Trades trades = marketDataService.getTrades(CurrencyPair.ETH_BTC); - assertNotNull(trades); - logger.info("Response: {}", trades); - } -} diff --git a/xchange-bankera/src/test/java/org/knowm/xchange/bankera/service/TradeServiceIntegration.java b/xchange-bankera/src/test/java/org/knowm/xchange/bankera/service/TradeServiceIntegration.java deleted file mode 100644 index 82d9e20d9a5..00000000000 --- a/xchange-bankera/src/test/java/org/knowm/xchange/bankera/service/TradeServiceIntegration.java +++ /dev/null @@ -1,110 +0,0 @@ -package org.knowm.xchange.bankera.service; - -import java.math.BigDecimal; -import java.util.Collection; -import java.util.Date; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runners.MethodSorters; -import org.knowm.xchange.Exchange; -import org.knowm.xchange.bankera.ExchangeUtils; -import org.knowm.xchange.currency.CurrencyPair; -import org.knowm.xchange.dto.Order; -import org.knowm.xchange.dto.trade.LimitOrder; -import org.knowm.xchange.dto.trade.MarketOrder; -import org.knowm.xchange.dto.trade.OpenOrders; -import org.knowm.xchange.dto.trade.UserTrades; -import org.knowm.xchange.exceptions.NotYetImplementedForExchangeException; -import org.knowm.xchange.service.trade.TradeService; -import org.knowm.xchange.service.trade.params.DefaultCancelOrderParamId; -import org.knowm.xchange.service.trade.params.DefaultTradeHistoryParamCurrencyPair; -import org.knowm.xchange.service.trade.params.orders.DefaultOpenOrdersParamCurrencyPair; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class TradeServiceIntegration { - - private final Logger logger = LoggerFactory.getLogger(this.getClass()); - private static String orderId; - private static TradeService tradeService; - - @BeforeClass - public static void init() { - Exchange exchange = ExchangeUtils.createExchangeFromProperties(); - tradeService = exchange.getTradeService(); - } - - @Test - public void testAcreateLimitOrderTest() throws Exception { - - LimitOrder limitOrder = - new LimitOrder( - Order.OrderType.BID, - BigDecimal.valueOf(0.01), - CurrencyPair.ETH_BTC, - "", - new Date(), - BigDecimal.valueOf(0.000001)); - String createdOrderId = tradeService.placeLimitOrder(limitOrder); - Assert.assertNotNull(createdOrderId); - orderId = createdOrderId; - logger.info("Response: {}", orderId); - } - - @Test - public void testBcreateMarketOrderTest() throws Exception { - - MarketOrder marketOrder = - new MarketOrder( - Order.OrderType.ASK, BigDecimal.valueOf(0.01), CurrencyPair.ETH_BTC, "", new Date()); - - Assert.assertNotNull(tradeService.placeMarketOrder(marketOrder)); - } - - @Test - public void testCgetOpenOrdersByMarketTest() throws Exception { - - DefaultOpenOrdersParamCurrencyPair currencyPair = new DefaultOpenOrdersParamCurrencyPair(); - currencyPair.setCurrencyPair(CurrencyPair.ETH_BTC); - OpenOrders openOrders = tradeService.getOpenOrders(currencyPair); - logger.info("Response: {}", openOrders); - } - - @Test - public void testDgetAllOpenOrdersTest() throws Exception { - - OpenOrders openOrders = tradeService.getOpenOrders(); - logger.info("Response: {}", openOrders); - } - - @Test - public void testFcancelOrderTest() throws Exception { - - Assert.assertTrue(tradeService.cancelOrder(this.orderId)); - } - - @Test(expected = NotYetImplementedForExchangeException.class) - public void testGcancelAllOrdersTest() throws Exception { - - Assert.assertTrue(tradeService.cancelOrder(new DefaultCancelOrderParamId())); - } - - @Test - public void testEgetUserOrder() throws Exception { - - Collection orders = tradeService.getOrder(this.orderId); - logger.info("Response: {}", orders); - } - - @Test - public void testHgetUserTrades() throws Exception { - - DefaultTradeHistoryParamCurrencyPair currencyPair = new DefaultTradeHistoryParamCurrencyPair(); - currencyPair.setCurrencyPair(CurrencyPair.ETH_BTC); - UserTrades trades = tradeService.getTradeHistory(currencyPair); - logger.info("Response: {}", trades.getUserTrades()); - } -} diff --git a/xchange-bankera/src/test/resources/logback.xml b/xchange-bankera/src/test/resources/logback.xml deleted file mode 100644 index 5809b573500..00000000000 --- a/xchange-bankera/src/test/resources/logback.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - - %d{HH:mm:ss.SSS} [%contextName] [%thread] %-5level %logger{36} - %msg %xEx%n - - - - - - - - - - - - - - diff --git a/xchange-bankera/src/test/resources/org/knowm/xchange/bankera/configuration.properties b/xchange-bankera/src/test/resources/org/knowm/xchange/bankera/configuration.properties deleted file mode 100644 index 4fe558a00c9..00000000000 --- a/xchange-bankera/src/test/resources/org/knowm/xchange/bankera/configuration.properties +++ /dev/null @@ -1,3 +0,0 @@ -#uncomment and fill those fields to test authenticated api in integration tests -#client-id= -#client-secret= \ No newline at end of file diff --git a/xchange-bankera/src/test/resources/org/knowm/xchange/bankera/dto/account/user_info.json b/xchange-bankera/src/test/resources/org/knowm/xchange/bankera/dto/account/user_info.json deleted file mode 100644 index e4c9689ab24..00000000000 --- a/xchange-bankera/src/test/resources/org/knowm/xchange/bankera/dto/account/user_info.json +++ /dev/null @@ -1,69 +0,0 @@ -{ - "user":{ - "id":7, - "verification":{"status":"Unsubmitted","last_declined_reason":null}, - "personal_profile":{ - "first_name":"John", - "last_name":"Doe", - "country":{ - "id":5, - "name":"AMERICAN SAMOA", - "iso2":"AS", - "iso3":"ASM" - }, - "phone":"12345647", - "birth_date":"2018-11-09 00:00:00", - "address":"Street 1", - "city":"Vilnius", - "zip_code":"11111", - "is_user_agree_for_news":false - }, - "business_profile":null, - "fee_set":{ - "fees":[ - {"buy_percent":"0.200000000000000000000000000000","sell_percent":"0.200000000000000000000000000000","market_id":1}, - {"buy_percent":"0.200000000000000000000000000000","sell_percent":"0.200000000000000000000000000000","market_id":2}, - {"buy_percent":"0.200000000000000000000000000000","sell_percent":"0.200000000000000000000000000000","market_id":3}, - {"buy_percent":"0.200000000000000000000000000000","sell_percent":"0.200000000000000000000000000000","market_id":4}, - {"buy_percent":"0.200000000000000000000000000000","sell_percent":"0.200000000000000000000000000000","market_id":5} - ] - }, - "wallets":[ - { - "id":16, - "currency":"DASH", - "balance":"10.000000000000000000000000000000", - "reserved":"20.000000000000000000000000000000", - "total":"30.000000000000000000000000000000" - }, - { - "id":18, - "currency":"XEM", - "balance":"10.000000000000000000000000000000", - "reserved":"20.000000000000000000000000000000", - "total":"30.000000000000000000000000000000" - }, - { - "id":20, - "currency":"BTC", - "balance":"10.000000000000000000000000000000", - "reserved":"20.000000000000000000000000000000", - "total":"30.000000000000000000000000000000" - }, - { - "id":22, - "currency":"ETH", - "balance":"10.000000000000000000000000000000", - "reserved":"20.000000000000000000000000000000", - "total":"30.000000000000000000000000000000" - }, - { - "id":24, - "currency":"BNK", - "balance":"10.000000000000000000000000000000", - "reserved":"20.000000000000000000000000000000", - "total":"30.000000000000000000000000000000" - } - ] - } -} \ No newline at end of file diff --git a/xchange-core/src/main/java/org/knowm/xchange/currency/CurrencyPair.java b/xchange-core/src/main/java/org/knowm/xchange/currency/CurrencyPair.java index ea54d40fbb8..2cbe5ade84c 100644 --- a/xchange-core/src/main/java/org/knowm/xchange/currency/CurrencyPair.java +++ b/xchange-core/src/main/java/org/knowm/xchange/currency/CurrencyPair.java @@ -364,7 +364,7 @@ public class CurrencyPair extends Instrument implements Comparable public static final CurrencyPair ETC_7D = new CurrencyPair(Currency.ETC, Currency.getInstance("7D")); - // Bankera Exchange pairs + // Bankera pairs public static final CurrencyPair BNK_BTC = new CurrencyPair(Currency.BNK, Currency.BTC); public static final CurrencyPair BNK_ETH = new CurrencyPair(Currency.BNK, Currency.ETH); public static final CurrencyPair BNK_USDT = new CurrencyPair(Currency.BNK, Currency.USDT); diff --git a/xchange-examples/pom.xml b/xchange-examples/pom.xml index 54d9e0345c4..a2213ffe8c0 100755 --- a/xchange-examples/pom.xml +++ b/xchange-examples/pom.xml @@ -342,11 +342,6 @@ xchange-dvchain ${project.version} - - ${project.groupId} - xchange-bankera - ${project.version} - org.knowm.xchange xchange-enigma diff --git a/xchange-examples/src/main/java/org/knowm/xchange/examples/bankera/BankeraAccountServiceDemo.java b/xchange-examples/src/main/java/org/knowm/xchange/examples/bankera/BankeraAccountServiceDemo.java deleted file mode 100644 index 1d58e5bb7b1..00000000000 --- a/xchange-examples/src/main/java/org/knowm/xchange/examples/bankera/BankeraAccountServiceDemo.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.knowm.xchange.examples.bankera; - -import java.io.IOException; -import org.knowm.xchange.Exchange; -import org.knowm.xchange.dto.account.AccountInfo; -import org.knowm.xchange.service.account.AccountService; - -public class BankeraAccountServiceDemo { - public static void main(String[] args) throws IOException { - Exchange exchange = BankeraDemoUtils.createExchange(); - AccountService accountService = exchange.getAccountService(); - - // Get the account information - AccountInfo accountInfo = accountService.getAccountInfo(); - System.out.println("AccountInfo as String: " + accountInfo.toString()); - } -} diff --git a/xchange-examples/src/main/java/org/knowm/xchange/examples/bankera/BankeraDemoUtils.java b/xchange-examples/src/main/java/org/knowm/xchange/examples/bankera/BankeraDemoUtils.java deleted file mode 100644 index f7abd15a013..00000000000 --- a/xchange-examples/src/main/java/org/knowm/xchange/examples/bankera/BankeraDemoUtils.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.knowm.xchange.examples.bankera; - -import org.knowm.xchange.Exchange; -import org.knowm.xchange.ExchangeFactory; -import org.knowm.xchange.ExchangeSpecification; -import org.knowm.xchange.bankera.BankeraExchange; - -public class BankeraDemoUtils { - public static Exchange createExchange() { - - ExchangeSpecification exSpec = new ExchangeSpecification(BankeraExchange.class); - - exSpec.setExchangeSpecificParametersItem("clientId", ""); - exSpec.setExchangeSpecificParametersItem("clientSecret", ""); - - return ExchangeFactory.INSTANCE.createExchange(exSpec); - } -} diff --git a/xchange-examples/src/main/java/org/knowm/xchange/examples/bankera/BankeraMarketDataServiceDemo.java b/xchange-examples/src/main/java/org/knowm/xchange/examples/bankera/BankeraMarketDataServiceDemo.java deleted file mode 100644 index f6de7644bc9..00000000000 --- a/xchange-examples/src/main/java/org/knowm/xchange/examples/bankera/BankeraMarketDataServiceDemo.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.knowm.xchange.examples.bankera; - -import java.io.IOException; -import org.knowm.xchange.Exchange; -import org.knowm.xchange.currency.CurrencyPair; -import org.knowm.xchange.dto.marketdata.Ticker; -import org.knowm.xchange.service.marketdata.MarketDataService; - -public class BankeraMarketDataServiceDemo { - public static void main(String[] args) throws IOException { - Exchange exchange = BankeraDemoUtils.createExchange(); - MarketDataService marketDataService = exchange.getMarketDataService(); - - // Get the market data ticker - Ticker ticker = marketDataService.getTicker(CurrencyPair.ETH_BTC); - System.out.println("Ticker as String: " + ticker.toString()); - } -} diff --git a/xchange-examples/src/main/java/org/knowm/xchange/examples/bankera/BankeraTradeServiceDemo.java b/xchange-examples/src/main/java/org/knowm/xchange/examples/bankera/BankeraTradeServiceDemo.java deleted file mode 100644 index b50cecde8e2..00000000000 --- a/xchange-examples/src/main/java/org/knowm/xchange/examples/bankera/BankeraTradeServiceDemo.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.knowm.xchange.examples.bankera; - -import java.io.IOException; -import org.knowm.xchange.Exchange; -import org.knowm.xchange.dto.trade.OpenOrders; -import org.knowm.xchange.service.trade.TradeService; - -public class BankeraTradeServiceDemo { - public static void main(String[] args) throws IOException { - Exchange exchange = BankeraDemoUtils.createExchange(); - TradeService tradeService = exchange.getTradeService(); - - // Get the open orders - OpenOrders openOrders = tradeService.getOpenOrders(); - System.out.println("OpenOrders as String: " + openOrders.toString()); - } -} diff --git a/xchange-stream-bankera/pom.xml b/xchange-stream-bankera/pom.xml deleted file mode 100644 index ca312e01464..00000000000 --- a/xchange-stream-bankera/pom.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - 4.0.0 - - - org.knowm.xchange - xchange-parent - 5.1.2-SNAPSHOT - - - XChange Bankera Stream - xchange-stream-bankera - - - - org.knowm.xchange - xchange-stream-core - ${project.parent.version} - - - org.knowm.xchange - xchange-stream-service-netty - ${project.parent.version} - - - org.knowm.xchange - xchange-bankera - ${project.parent.version} - - - \ No newline at end of file diff --git a/xchange-stream-bankera/src/main/java/info/bitrich/xchangestream/bankera/BankeraStreamingExchange.java b/xchange-stream-bankera/src/main/java/info/bitrich/xchangestream/bankera/BankeraStreamingExchange.java deleted file mode 100644 index 3dfa3052408..00000000000 --- a/xchange-stream-bankera/src/main/java/info/bitrich/xchangestream/bankera/BankeraStreamingExchange.java +++ /dev/null @@ -1,78 +0,0 @@ -package info.bitrich.xchangestream.bankera; - -import info.bitrich.xchangestream.core.ProductSubscription; -import info.bitrich.xchangestream.core.StreamingExchange; -import info.bitrich.xchangestream.core.StreamingMarketDataService; -import info.bitrich.xchangestream.service.netty.ConnectionStateModel.State; -import io.reactivex.Completable; -import io.reactivex.Observable; -import org.knowm.xchange.ExchangeSpecification; -import org.knowm.xchange.bankera.BankeraExchange; -import org.knowm.xchange.bankera.service.BankeraMarketDataService; - -public class BankeraStreamingExchange extends BankeraExchange implements StreamingExchange { - - private static final String WS_URI = "wss://api-exchange.bankera.com/ws"; - private final BankeraStreamingService streamingService; - private BankeraStreamingMarketDataService streamingMarketDataService; - - public BankeraStreamingExchange() { - this.streamingService = new BankeraStreamingService(WS_URI); - } - - @Override - protected void initServices() { - super.initServices(); - streamingMarketDataService = - new BankeraStreamingMarketDataService( - streamingService, (BankeraMarketDataService) marketDataService); - } - - @Override - public Completable connect(ProductSubscription... args) { - return streamingService.connect(); - } - - @Override - public Completable disconnect() { - return streamingService.disconnect(); - } - - @Override - public boolean isAlive() { - return streamingService.isSocketOpen(); - } - - @Override - public Observable reconnectFailure() { - return streamingService.subscribeReconnectFailure(); - } - - @Override - public Observable connectionSuccess() { - return streamingService.subscribeConnectionSuccess(); - } - - @Override - public Observable connectionStateObservable() { - return streamingService.subscribeConnectionState(); - } - - @Override - public ExchangeSpecification getDefaultExchangeSpecification() { - ExchangeSpecification spec = super.getDefaultExchangeSpecification(); - spec.setShouldLoadRemoteMetaData(false); - - return spec; - } - - @Override - public StreamingMarketDataService getStreamingMarketDataService() { - return streamingMarketDataService; - } - - @Override - public void useCompressedMessages(boolean compressedMessages) { - streamingService.useCompressedMessages(compressedMessages); - } -} diff --git a/xchange-stream-bankera/src/main/java/info/bitrich/xchangestream/bankera/BankeraStreamingMarketDataService.java b/xchange-stream-bankera/src/main/java/info/bitrich/xchangestream/bankera/BankeraStreamingMarketDataService.java deleted file mode 100644 index 77c88da4eda..00000000000 --- a/xchange-stream-bankera/src/main/java/info/bitrich/xchangestream/bankera/BankeraStreamingMarketDataService.java +++ /dev/null @@ -1,104 +0,0 @@ -package info.bitrich.xchangestream.bankera; - -import info.bitrich.xchangestream.core.StreamingMarketDataService; -import io.reactivex.Observable; -import java.io.IOException; -import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.Optional; -import org.knowm.xchange.bankera.BankeraAdapters; -import org.knowm.xchange.bankera.dto.BankeraException; -import org.knowm.xchange.bankera.dto.marketdata.BankeraMarket; -import org.knowm.xchange.bankera.dto.marketdata.BankeraMarketInfo; -import org.knowm.xchange.bankera.dto.marketdata.BankeraOrderBook; -import org.knowm.xchange.bankera.service.BankeraMarketDataService; -import org.knowm.xchange.currency.CurrencyPair; -import org.knowm.xchange.dto.Order; -import org.knowm.xchange.dto.marketdata.OrderBook; -import org.knowm.xchange.dto.marketdata.Ticker; -import org.knowm.xchange.dto.marketdata.Trade; -import org.knowm.xchange.exceptions.NotAvailableFromExchangeException; - -public class BankeraStreamingMarketDataService implements StreamingMarketDataService { - - private final BankeraStreamingService service; - private final BankeraMarketDataService marketDataService; - - public BankeraStreamingMarketDataService( - BankeraStreamingService service, BankeraMarketDataService marketDataService) { - this.service = service; - this.marketDataService = marketDataService; - } - - @Override - public Observable getOrderBook(CurrencyPair currencyPair, Object... args) { - BankeraMarket market = getMarketInfo(currencyPair); - return service - .subscribeChannel("market-orderbook", market.getId()) - .map( - o -> { - List listBids = new ArrayList<>(); - List listAsks = new ArrayList<>(); - o.get("data") - .get("bids") - .forEach( - b -> - listBids.add( - new BankeraOrderBook.OrderBookOrder( - 0, b.get("price").asText(), b.get("amount").asText()))); - o.get("data") - .get("asks") - .forEach( - b -> - listAsks.add( - new BankeraOrderBook.OrderBookOrder( - 0, b.get("price").asText(), b.get("amount").asText()))); - return BankeraAdapters.adaptOrderBook( - new BankeraOrderBook(listBids, listAsks), currencyPair); - }); - } - - @Override - public Observable getTicker(CurrencyPair currencyPair, Object... args) { - throw new NotAvailableFromExchangeException(); - } - - @Override - public Observable getTrades(CurrencyPair currencyPair, Object... args) { - BankeraMarket market = getMarketInfo(currencyPair); - return service - .subscribeChannel("market-trade", market.getId()) - .map( - t -> - new Trade.Builder() - .currencyPair(currencyPair) - .id("-1") - .price(new BigDecimal(t.get("data").get("price").asText())) - .originalAmount(new BigDecimal(t.get("data").get("amount").asText())) - .timestamp(new Date(t.get("data").get("time").asLong())) - .type( - t.get("data").get("side").asText().equals("SELL") - ? Order.OrderType.ASK - : Order.OrderType.BID) - .build()); - } - - private BankeraMarket getMarketInfo(CurrencyPair currencyPair) { - try { - BankeraMarketInfo info = this.marketDataService.getMarketInfo(); - Optional market = - info.getMarkets().stream() - .filter(m -> m.getName().equals(currencyPair.toString().replace("/", "-"))) - .findFirst(); - - if (market.isPresent()) { - return market.get(); - } - throw new BankeraException(404, "Unable to find market."); - } catch (IOException e) { - throw new BankeraException(404, "Unable to find market."); - } - } -} diff --git a/xchange-stream-bankera/src/main/java/info/bitrich/xchangestream/bankera/BankeraStreamingService.java b/xchange-stream-bankera/src/main/java/info/bitrich/xchangestream/bankera/BankeraStreamingService.java deleted file mode 100644 index 44f8fe64558..00000000000 --- a/xchange-stream-bankera/src/main/java/info/bitrich/xchangestream/bankera/BankeraStreamingService.java +++ /dev/null @@ -1,37 +0,0 @@ -package info.bitrich.xchangestream.bankera; - -import com.fasterxml.jackson.databind.JsonNode; -import info.bitrich.xchangestream.bankera.dto.BankeraWebSocketSubscriptionMessage; -import info.bitrich.xchangestream.service.netty.JsonNettyStreamingService; -import io.netty.handler.codec.http.websocketx.extensions.WebSocketClientExtensionHandler; -import java.io.IOException; - -public class BankeraStreamingService extends JsonNettyStreamingService { - - public BankeraStreamingService(String uri) { - super(uri, Integer.MAX_VALUE); - } - - @Override - protected String getChannelNameFromMessage(JsonNode message) throws IOException { - return message.get("type").asText(); - } - - @Override - public String getSubscribeMessage(String channelName, Object... args) throws IOException { - if (args.length != 1) throw new IOException("SubscribeMessage: Insufficient arguments"); - BankeraWebSocketSubscriptionMessage subscribeMessage = - new BankeraWebSocketSubscriptionMessage(String.valueOf(args[0])); - return objectMapper.writeValueAsString(subscribeMessage); - } - - @Override - public String getUnsubscribeMessage(String channelName, Object... args) throws IOException { - return null; - } - - @Override - protected WebSocketClientExtensionHandler getWebSocketClientExtensionHandler() { - return null; - } -} diff --git a/xchange-stream-bankera/src/main/java/info/bitrich/xchangestream/bankera/dto/BankeraWebSocketSubscriptionMessage.java b/xchange-stream-bankera/src/main/java/info/bitrich/xchangestream/bankera/dto/BankeraWebSocketSubscriptionMessage.java deleted file mode 100644 index 3ad9d635e9e..00000000000 --- a/xchange-stream-bankera/src/main/java/info/bitrich/xchangestream/bankera/dto/BankeraWebSocketSubscriptionMessage.java +++ /dev/null @@ -1,39 +0,0 @@ -package info.bitrich.xchangestream.bankera.dto; - -import com.fasterxml.jackson.annotation.JsonProperty; - -public class BankeraWebSocketSubscriptionMessage { - - @JsonProperty("e") - private String event; - - @JsonProperty("marketId") - private String marketId; - - @JsonProperty("chartInterval") - private String chartInterval; - - public BankeraWebSocketSubscriptionMessage(String marketId) { - this.event = "market"; - this.marketId = marketId; - this.chartInterval = "1m"; - } - - public BankeraWebSocketSubscriptionMessage(String marketId, String chartInterval) { - this.event = "market"; - this.marketId = marketId; - this.chartInterval = chartInterval; - } - - public String getEvent() { - return event; - } - - public String getMarketId() { - return marketId; - } - - public String getChartInterval() { - return chartInterval; - } -} diff --git a/xchange-stream-bankera/src/test/java/info/bitrich/xchangestream/bankera/BankeraManualExample.java b/xchange-stream-bankera/src/test/java/info/bitrich/xchangestream/bankera/BankeraManualExample.java deleted file mode 100644 index e98b7605eb1..00000000000 --- a/xchange-stream-bankera/src/test/java/info/bitrich/xchangestream/bankera/BankeraManualExample.java +++ /dev/null @@ -1,39 +0,0 @@ -package info.bitrich.xchangestream.bankera; - -import info.bitrich.xchangestream.core.StreamingExchange; -import info.bitrich.xchangestream.core.StreamingExchangeFactory; -import org.knowm.xchange.currency.CurrencyPair; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class BankeraManualExample { - private static final Logger LOGGER = LoggerFactory.getLogger(BankeraManualExample.class); - - public static void main(String[] args) { - StreamingExchange exchange = - StreamingExchangeFactory.INSTANCE.createExchange(BankeraStreamingExchange.class); - - exchange.connect().blockingAwait(); - exchange - .getStreamingMarketDataService() - .getOrderBook(CurrencyPair.ETH_BTC) - .subscribe( - orderBook -> LOGGER.debug("ORDERBOOK: {}", orderBook.toString()), - throwable -> LOGGER.error("ERROR in getting order book: ", throwable)); - - exchange - .getStreamingMarketDataService() - .getTrades(CurrencyPair.ETH_BTC) - .subscribe( - trade -> LOGGER.debug("TRADES: {}", trade.toString()), - throwable -> LOGGER.error("ERROR in getting trade ", throwable)); - - try { - Thread.sleep(10000); - } catch (InterruptedException e) { - e.printStackTrace(); - } - - exchange.disconnect().subscribe(() -> LOGGER.info("Disconnected")); - } -} diff --git a/xchange-stream-bankera/src/test/resources/logback.xml b/xchange-stream-bankera/src/test/resources/logback.xml deleted file mode 100644 index 5809b573500..00000000000 --- a/xchange-stream-bankera/src/test/resources/logback.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - - %d{HH:mm:ss.SSS} [%contextName] [%thread] %-5level %logger{36} - %msg %xEx%n - - - - - - - - - - - - - -