From 02536e876766bd62623fd2ff3bdeddf140933b2f Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Wed, 2 Oct 2024 20:40:57 +0200 Subject: [PATCH 01/10] [bitget] Add getting of Currencies and Instruments --- .../service/BitgetMarketDataService.java | 34 +++++++++++++++++++ .../BitgetMarketDataServiceIntegration.java | 20 +++++++++++ 2 files changed, 54 insertions(+) diff --git a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/BitgetMarketDataService.java b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/BitgetMarketDataService.java index f02332cdf9..a5991f1a35 100644 --- a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/BitgetMarketDataService.java +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/BitgetMarketDataService.java @@ -11,7 +11,11 @@ import org.knowm.xchange.bitget.BitgetExchange; import org.knowm.xchange.bitget.config.Config; import org.knowm.xchange.bitget.dto.BitgetException; +import org.knowm.xchange.bitget.dto.marketdata.BitgetCoinDto; +import org.knowm.xchange.bitget.dto.marketdata.BitgetSymbolDto; +import org.knowm.xchange.bitget.dto.marketdata.BitgetSymbolDto.Status; import org.knowm.xchange.bitget.dto.marketdata.BitgetTickerDto; +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; @@ -27,6 +31,36 @@ public BitgetMarketDataService(BitgetExchange exchange) { super(exchange); } + + public List getCurrencies() throws IOException { + try { + return getBitgetCoinDtoList(null).stream() + .map(BitgetCoinDto::getCurrency) + .distinct() + .collect(Collectors.toList()); + } + catch (BitgetException e) { + throw BitgetErrorAdapter.adapt(e); + } + } + + + public List getInstruments() throws IOException { + try { + List metadata = getBitgetSymbolDtos(null); + + return metadata.stream() + .filter(details -> details.getStatus() == Status.ONLINE) + .map(BitgetSymbolDto::getCurrencyPair) + .distinct() + .collect(Collectors.toList()); + } + catch (BitgetException e) { + throw BitgetErrorAdapter.adapt(e); + } + } + + @Override public ExchangeHealth getExchangeHealth() { try { diff --git a/xchange-bitget/src/test/java/org/knowm/xchange/bitget/service/BitgetMarketDataServiceIntegration.java b/xchange-bitget/src/test/java/org/knowm/xchange/bitget/service/BitgetMarketDataServiceIntegration.java index 0a0d09f0bf..ed1e83e3c4 100644 --- a/xchange-bitget/src/test/java/org/knowm/xchange/bitget/service/BitgetMarketDataServiceIntegration.java +++ b/xchange-bitget/src/test/java/org/knowm/xchange/bitget/service/BitgetMarketDataServiceIntegration.java @@ -7,11 +7,13 @@ import java.util.List; import org.junit.jupiter.api.Test; import org.knowm.xchange.bitget.BitgetIntegrationTestParent; +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.exceptions.InstrumentNotValidException; +import org.knowm.xchange.instrument.Instrument; class BitgetMarketDataServiceIntegration extends BitgetIntegrationTestParent { @@ -29,6 +31,24 @@ void valid_single_ticker() throws IOException { } + @Test + void valid_currencies() throws IOException { + List currencies = ((BitgetMarketDataService) exchange.getMarketDataService()).getCurrencies(); + + assertThat(currencies).isNotEmpty(); + assertThat(currencies.stream().distinct().count()).isEqualTo(currencies.size()); + } + + + @Test + void valid_instruments() throws IOException { + List instruments = ((BitgetMarketDataService) exchange.getMarketDataService()).getInstruments(); + + assertThat(instruments).isNotEmpty(); + assertThat(instruments.stream().distinct().count()).isEqualTo(instruments.size()); + } + + @Test void check_exceptions() { assertThatExceptionOfType(InstrumentNotValidException.class) From 32e273339e11f4c38a111b1774a33b2afa7f14b7 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Wed, 2 Oct 2024 23:06:26 +0200 Subject: [PATCH 02/10] [bitget] Update http requests --- xchange-bitget/src/test/resources/rest/sign.js | 3 ++- xchange-bitget/src/test/resources/rest/spot.http | 10 +++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/xchange-bitget/src/test/resources/rest/sign.js b/xchange-bitget/src/test/resources/rest/sign.js index 2daee39999..ba3b7ce1ff 100644 --- a/xchange-bitget/src/test/resources/rest/sign.js +++ b/xchange-bitget/src/test/resources/rest/sign.js @@ -1,5 +1,6 @@ -export function gen_sign(method, request) { +export function gen_sign(request) { const pattern = RegExp("^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?"); + const method = request.method; const url = request.url.tryGetSubstituted(); const matches = url.match(pattern); diff --git a/xchange-bitget/src/test/resources/rest/spot.http b/xchange-bitget/src/test/resources/rest/spot.http index 1fb8850c39..a2233a5479 100644 --- a/xchange-bitget/src/test/resources/rest/spot.http +++ b/xchange-bitget/src/test/resources/rest/spot.http @@ -17,7 +17,7 @@ GET {{api_host}}/api/v2/spot/market/tickers ### Get Account Information < {% import {gen_sign} from 'sign.js' - gen_sign("GET", request); + gen_sign(request); %} GET {{api_host}}/api/v2/spot/account/info ACCESS-KEY: {{api_key}} @@ -29,7 +29,7 @@ ACCESS-PASSPHRASE: {{api_passphrase}} ### Get Account assets < {% import {gen_sign} from 'sign.js' - gen_sign("GET", request); + gen_sign(request); %} GET {{api_host}}/api/v2/spot/account/assets ACCESS-KEY: {{api_key}} @@ -41,7 +41,7 @@ ACCESS-PASSPHRASE: {{api_passphrase}} ### Get Order Info < {% import {gen_sign} from 'sign.js' - gen_sign("GET", request); + gen_sign(request); %} GET {{api_host}}/api/v2/spot/trade/orderInfo?orderId=1213530920130613257 ACCESS-KEY: {{api_key}} @@ -53,7 +53,7 @@ ACCESS-PASSPHRASE: {{api_passphrase}} ### Place Market Buy Order < {% import {gen_sign} from 'sign.js' - gen_sign("POST", request); + gen_sign(request); %} POST {{api_host}}/api/v2/spot/trade/place-order ACCESS-KEY: {{api_key}} @@ -74,7 +74,7 @@ Content-Type: application/json ### Place Market Sell Order < {% import {gen_sign} from 'sign.js' - gen_sign("POST", request); + gen_sign(request); %} POST {{api_host}}/api/v2/spot/trade/place-order ACCESS-KEY: {{api_key}} From ebd494c4c41cba92307eba4458bbbccd1d9947ba Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Wed, 2 Oct 2024 23:24:16 +0200 Subject: [PATCH 03/10] [bitget] Add getting of user trades --- .../knowm/xchange/bitget/BitgetAdapters.java | 8 ++ .../xchange/bitget/BitgetAuthenticated.java | 14 +++ .../bitget/dto/trade/BitgetFillDto.java | 102 ++++++++++++++++++ .../bitget/service/BitgetTradeService.java | 20 ++++ .../bitget/service/BitgetTradeServiceRaw.java | 28 +++++ .../params/BitgetTradeHistoryParams.java | 34 ++++++ .../service/BitgetTradeServiceTest.java | 28 +++++ .../__files/api_v2_spot_trade_fills.json | 27 +++++ .../mappings/api_v2_spot_trade_fills.json | 15 +++ .../src/test/resources/rest/spot.http | 25 +++++ .../params/TradeHistoryParamOrderId.java | 12 +++ .../TradeHistoryParamTransactionId.java | 3 + 12 files changed, 316 insertions(+) create mode 100755 xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/trade/BitgetFillDto.java create mode 100644 xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/params/BitgetTradeHistoryParams.java create mode 100644 xchange-bitget/src/test/resources/__files/api_v2_spot_trade_fills.json create mode 100644 xchange-bitget/src/test/resources/mappings/api_v2_spot_trade_fills.json create mode 100644 xchange-core/src/main/java/org/knowm/xchange/service/trade/params/TradeHistoryParamOrderId.java diff --git a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/BitgetAdapters.java b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/BitgetAdapters.java index 61ab482b91..4c48aff941 100644 --- a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/BitgetAdapters.java +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/BitgetAdapters.java @@ -15,6 +15,7 @@ import org.knowm.xchange.bitget.dto.marketdata.BitgetSymbolDto; import org.knowm.xchange.bitget.dto.marketdata.BitgetSymbolDto.Status; import org.knowm.xchange.bitget.dto.marketdata.BitgetTickerDto; +import org.knowm.xchange.bitget.dto.trade.BitgetFillDto; import org.knowm.xchange.bitget.dto.trade.BitgetOrderInfoDto; import org.knowm.xchange.bitget.dto.trade.BitgetOrderInfoDto.BitgetOrderStatus; import org.knowm.xchange.bitget.dto.trade.BitgetPlaceOrderDto; @@ -30,6 +31,7 @@ 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.instrument.Instrument; @UtilityClass @@ -231,4 +233,10 @@ public BitgetPlaceOrderDto toBitgetPlaceOrderDto(MarketOrder marketOrder) { } + public UserTrade toUserTrade(BitgetFillDto bitgetFillDto) { + return new UserTrade(bitgetFillDto.getOrderSide(), bitgetFillDto.getAssetAmount(), toCurrencyPair(bitgetFillDto.getSymbol()), + bitgetFillDto.getPrice(), toDate(bitgetFillDto.getUpdatedAt()), bitgetFillDto.getTradeId(), bitgetFillDto.getOrderId(), + bitgetFillDto.getFeeDetail().getTotalFee().abs(), bitgetFillDto.getFeeDetail().getCurrency(), null); + } + } diff --git a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/BitgetAuthenticated.java b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/BitgetAuthenticated.java index a22f8f75a1..51ab26cc54 100644 --- a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/BitgetAuthenticated.java +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/BitgetAuthenticated.java @@ -13,6 +13,7 @@ import org.knowm.xchange.bitget.dto.BitgetException; import org.knowm.xchange.bitget.dto.BitgetResponse; import org.knowm.xchange.bitget.dto.account.BitgetBalanceDto; +import org.knowm.xchange.bitget.dto.trade.BitgetFillDto; import org.knowm.xchange.bitget.dto.trade.BitgetOrderInfoDto; import org.knowm.xchange.bitget.dto.trade.BitgetPlaceOrderDto; import si.mazi.rescu.ParamsDigest; @@ -55,4 +56,17 @@ BitgetResponse createOrder( throws IOException, BitgetException; + @GET + @Path("api/v2/spot/trade/fills") + BitgetResponse> fills( + @HeaderParam("ACCESS-KEY") String apiKey, + @HeaderParam("ACCESS-SIGN") ParamsDigest signer, + @HeaderParam("ACCESS-PASSPHRASE") String passphrase, + @HeaderParam("ACCESS-TIMESTAMP") SynchronizedValueFactory timestamp, + @QueryParam("symbol") String symbol, @QueryParam("limit") Integer limit, @QueryParam("orderId") String orderId, + @QueryParam("startTime") Long startTime, @QueryParam("endTime") Long endTime, + @QueryParam("idLessThan") String idLessThan) + throws IOException, BitgetException; + + } diff --git a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/trade/BitgetFillDto.java b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/trade/BitgetFillDto.java new file mode 100755 index 0000000000..e7874aa61e --- /dev/null +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/trade/BitgetFillDto.java @@ -0,0 +1,102 @@ +package org.knowm.xchange.bitget.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.bitget.config.converter.StringToBooleanConverter; +import org.knowm.xchange.bitget.config.converter.StringToCurrencyConverter; +import org.knowm.xchange.bitget.config.converter.StringToOrderTypeConverter; +import org.knowm.xchange.currency.Currency; +import org.knowm.xchange.dto.Order; + +@Data +@Builder +@Jacksonized +public class BitgetFillDto { + + @JsonProperty("userId") + private String acccountId; + + @JsonProperty("symbol") + private String symbol; + + @JsonProperty("orderId") + private String orderId; + + @JsonProperty("tradeId") + private String tradeId; + + @JsonProperty("orderType") + private OrderType orderType; + + @JsonProperty("side") + @JsonDeserialize(converter = StringToOrderTypeConverter.class) + private Order.OrderType orderSide; + + @JsonProperty("priceAvg") + private BigDecimal price; + + @JsonProperty("size") + private BigDecimal assetAmount; + + @JsonProperty("amount") + private BigDecimal quoteAmount; + + @JsonProperty("feeDetail") + private FeeDetail feeDetail; + + @JsonProperty("tradeScope") + private TradeScope tradeScope; + + @JsonProperty("cTime") + private Instant createdAt; + + @JsonProperty("uTime") + private Instant updatedAt; + + + public static enum OrderType { + @JsonProperty("limit") + LIMIT, + + @JsonProperty("market") + MARKET + } + + + public static enum TradeScope { + @JsonProperty("taker") + TAKER, + + @JsonProperty("maker") + MAKER + + } + + + @Data + @Builder + @Jacksonized + public static class FeeDetail { + + @JsonProperty("deduction") + @JsonDeserialize(converter = StringToBooleanConverter.class) + private Boolean deduction; + + @JsonProperty("feeCoin") + @JsonDeserialize(converter = StringToCurrencyConverter.class) + private Currency currency; + + @JsonProperty("totalDeductionFee") + private BigDecimal totalDeductionFee; + + @JsonProperty("totalFee") + private BigDecimal totalFee; + + } + +} diff --git a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/BitgetTradeService.java b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/BitgetTradeService.java index 73a52bf549..4cc4f9f69e 100644 --- a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/BitgetTradeService.java +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/BitgetTradeService.java @@ -3,6 +3,8 @@ 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; import org.knowm.xchange.bitget.BitgetAdapters; import org.knowm.xchange.bitget.BitgetErrorAdapter; @@ -10,8 +12,12 @@ import org.knowm.xchange.bitget.dto.BitgetException; import org.knowm.xchange.bitget.dto.trade.BitgetOrderInfoDto; import org.knowm.xchange.dto.Order; +import org.knowm.xchange.dto.marketdata.Trades.TradeSortType; 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.service.trade.TradeService; +import org.knowm.xchange.service.trade.params.TradeHistoryParams; import org.knowm.xchange.service.trade.params.orders.DefaultQueryOrderParam; import org.knowm.xchange.service.trade.params.orders.OrderQueryParams; @@ -39,6 +45,20 @@ public Collection getOrder(OrderQueryParams... orderQueryParams) throws I } + @Override + public UserTrades getTradeHistory(TradeHistoryParams params) throws IOException { + try { + List userTradeList = bitgetFills(params).stream() + .map(BitgetAdapters::toUserTrade) + .collect(Collectors.toList()); + return new UserTrades(userTradeList, TradeSortType.SortByID); + } + catch (BitgetException e) { + throw BitgetErrorAdapter.adapt(e); + } + } + + @Override public String placeMarketOrder(MarketOrder marketOrder) throws IOException { try { diff --git a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/BitgetTradeServiceRaw.java b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/BitgetTradeServiceRaw.java index 870d26c649..2c99130cbb 100644 --- a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/BitgetTradeServiceRaw.java +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/BitgetTradeServiceRaw.java @@ -2,9 +2,18 @@ import java.io.IOException; import java.util.List; +import org.knowm.xchange.bitget.BitgetAdapters; import org.knowm.xchange.bitget.BitgetExchange; +import org.knowm.xchange.bitget.dto.trade.BitgetFillDto; import org.knowm.xchange.bitget.dto.trade.BitgetOrderInfoDto; import org.knowm.xchange.bitget.dto.trade.BitgetPlaceOrderDto; +import org.knowm.xchange.instrument.Instrument; +import org.knowm.xchange.service.trade.params.TradeHistoryParamInstrument; +import org.knowm.xchange.service.trade.params.TradeHistoryParamLimit; +import org.knowm.xchange.service.trade.params.TradeHistoryParamOrderId; +import org.knowm.xchange.service.trade.params.TradeHistoryParams; +import org.knowm.xchange.service.trade.params.TradeHistoryParamsIdSpan; +import org.knowm.xchange.service.trade.params.TradeHistoryParamsTimeSpan; public class BitgetTradeServiceRaw extends BitgetBaseService { @@ -13,6 +22,25 @@ public BitgetTradeServiceRaw(BitgetExchange exchange) { } + public List bitgetFills(TradeHistoryParams params) throws IOException { + // get arguments + Instrument instrument = params instanceof TradeHistoryParamInstrument ? ((TradeHistoryParamInstrument) params).getInstrument() : null; + Integer limit = params instanceof TradeHistoryParamLimit ? ((TradeHistoryParamLimit) params).getLimit() : null; + String orderId = params instanceof TradeHistoryParamOrderId ? ((TradeHistoryParamOrderId) params).getOrderId() : null; + String lastTradeId = params instanceof TradeHistoryParamsIdSpan ? ((TradeHistoryParamsIdSpan) params).getEndId() : null; + Long from = null; + Long to = null; + if (params instanceof TradeHistoryParamsTimeSpan) { + TradeHistoryParamsTimeSpan paramsTimeSpan = ((TradeHistoryParamsTimeSpan) params); + from = paramsTimeSpan.getStartTime() != null ? paramsTimeSpan.getStartTime().getTime() : null; + to = paramsTimeSpan.getEndTime() != null ? paramsTimeSpan.getEndTime().getTime() : null; + } + + return bitgetAuthenticated.fills(apiKey, bitgetDigest, passphrase, exchange.getNonceFactory(), + BitgetAdapters.toString(instrument), limit, orderId, from, to, lastTradeId).getData(); + } + + public BitgetOrderInfoDto bitgetOrderInfoDto(String orderId) throws IOException { List results = bitgetAuthenticated.orderInfo( apiKey, bitgetDigest, passphrase, exchange.getNonceFactory(), orderId).getData(); diff --git a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/params/BitgetTradeHistoryParams.java b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/params/BitgetTradeHistoryParams.java new file mode 100644 index 0000000000..3b7da570d0 --- /dev/null +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/params/BitgetTradeHistoryParams.java @@ -0,0 +1,34 @@ +package org.knowm.xchange.bitget.service.params; + +import java.util.Date; +import lombok.Data; +import lombok.experimental.SuperBuilder; +import org.knowm.xchange.instrument.Instrument; +import org.knowm.xchange.service.trade.params.TradeHistoryParamInstrument; +import org.knowm.xchange.service.trade.params.TradeHistoryParamLimit; +import org.knowm.xchange.service.trade.params.TradeHistoryParamOrderId; +import org.knowm.xchange.service.trade.params.TradeHistoryParamsIdSpan; +import org.knowm.xchange.service.trade.params.TradeHistoryParamsTimeSpan; + +@Data +@SuperBuilder +public class BitgetTradeHistoryParams implements TradeHistoryParamInstrument, + TradeHistoryParamLimit, TradeHistoryParamsTimeSpan, TradeHistoryParamsIdSpan, + TradeHistoryParamOrderId { + + private Instrument instrument; + + private Integer limit; + + private String orderId; + + private Date startTime; + + private Date endTime; + + private String startId; + + private String endId; + + +} diff --git a/xchange-bitget/src/test/java/org/knowm/xchange/bitget/service/BitgetTradeServiceTest.java b/xchange-bitget/src/test/java/org/knowm/xchange/bitget/service/BitgetTradeServiceTest.java index 50356073bd..b5218c74e1 100644 --- a/xchange-bitget/src/test/java/org/knowm/xchange/bitget/service/BitgetTradeServiceTest.java +++ b/xchange-bitget/src/test/java/org/knowm/xchange/bitget/service/BitgetTradeServiceTest.java @@ -1,6 +1,7 @@ package org.knowm.xchange.bitget.service; import static org.assertj.core.api.Assertions.assertThat; +import static org.knowm.xchange.currency.CurrencyPair.BTC_USDT; import java.io.IOException; import java.math.BigDecimal; @@ -9,11 +10,15 @@ import java.util.Date; import org.junit.jupiter.api.Test; import org.knowm.xchange.bitget.BitgetExchangeWiremock; +import org.knowm.xchange.bitget.service.params.BitgetTradeHistoryParams; +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.MarketOrder; +import org.knowm.xchange.dto.trade.UserTrade; +import org.knowm.xchange.dto.trade.UserTrades; import org.knowm.xchange.service.trade.TradeService; import org.knowm.xchange.service.trade.params.orders.DefaultQueryOrderParamInstrument; @@ -92,4 +97,27 @@ void place_market_sell_order() throws IOException { } + @Test + void trade_history() throws IOException { + UserTrades userTrades = exchange.getTradeService().getTradeHistory( + BitgetTradeHistoryParams.builder() + .instrument(BTC_USDT) + .limit(2) + .orderId("1225475622585147396") + .startTime(Date.from(Instant.ofEpochMilli(1727902077418L))) + .endTime(Date.from(Instant.ofEpochMilli(1727902077420L))) + .endId("1225475622852575236") + .build() + ); + + assertThat(userTrades.getUserTrades()).hasSize(1); + + UserTrade expected = new UserTrade(OrderType.BID, new BigDecimal("0.000246"), BTC_USDT, + new BigDecimal("60775.01"), Date.from(Instant.ofEpochMilli(1727902077419L)), "1225475622852575236", + "1225475622585147396", new BigDecimal("0.000000246"), Currency.BTC, null); + + assertThat(userTrades.getUserTrades()).first().usingRecursiveComparison().isEqualTo(expected); + } + + } \ No newline at end of file diff --git a/xchange-bitget/src/test/resources/__files/api_v2_spot_trade_fills.json b/xchange-bitget/src/test/resources/__files/api_v2_spot_trade_fills.json new file mode 100644 index 0000000000..1e3b507e7c --- /dev/null +++ b/xchange-bitget/src/test/resources/__files/api_v2_spot_trade_fills.json @@ -0,0 +1,27 @@ +{ + "code": "00000", + "msg": "success", + "requestTime": 1727902784656, + "data": [ + { + "userId": "1548914322", + "symbol": "BTCUSDT", + "orderId": "1225475622585147396", + "tradeId": "1225475622852575236", + "orderType": "market", + "side": "buy", + "priceAvg": "60775.01", + "size": "0.000246", + "amount": "14.95065246", + "feeDetail": { + "deduction": "no", + "feeCoin": "BTC", + "totalDeductionFee": "", + "totalFee": "-0.000000246" + }, + "tradeScope": "taker", + "cTime": "1727902077401", + "uTime": "1727902077419" + } + ] +} \ No newline at end of file diff --git a/xchange-bitget/src/test/resources/mappings/api_v2_spot_trade_fills.json b/xchange-bitget/src/test/resources/mappings/api_v2_spot_trade_fills.json new file mode 100644 index 0000000000..e3504d13e3 --- /dev/null +++ b/xchange-bitget/src/test/resources/mappings/api_v2_spot_trade_fills.json @@ -0,0 +1,15 @@ +{ + "id" : "fa553e38-ab6e-4429-9d89-130b81a346a0", + "name" : "api_v2_spot_trade_fills", + "request" : { + "url" : "/api/v2/spot/trade/fills?symbol=BTCUSDT&limit=2&orderId=1225475622585147396&startTime=1727902077418&endTime=1727902077420&idLessThan=1225475622852575236", + "method" : "GET" + }, + "response" : { + "status" : 200, + "bodyFileName" : "api_v2_spot_trade_fills.json" + }, + "uuid" : "fa553e38-ab6e-4429-9d89-130b81a346a0", + "persistent" : true, + "insertionIndex" : 6 +} \ No newline at end of file diff --git a/xchange-bitget/src/test/resources/rest/spot.http b/xchange-bitget/src/test/resources/rest/spot.http index a2233a5479..c5bc747754 100644 --- a/xchange-bitget/src/test/resources/rest/spot.http +++ b/xchange-bitget/src/test/resources/rest/spot.http @@ -92,3 +92,28 @@ Content-Type: application/json } +### Get History Orders +< {% + import {gen_sign} from 'sign.js' + gen_sign(request); +%} +GET {{api_host}}/api/v2/spot/trade/history-orders +ACCESS-KEY: {{api_key}} +ACCESS-SIGN: {{sign}} +ACCESS-TIMESTAMP: {{timestamp}} +ACCESS-PASSPHRASE: {{api_passphrase}} + + +### Get Fills +< {% + import {gen_sign} from 'sign.js' + gen_sign(request); +%} +#GET {{api_host}}/api/v2/spot/trade/fills?symbol=ASMUSDT&limit=1000&orderId=1225428954737188883&startTime=1727890950945&endTime=1727890950947&idLessThan=1225428955008811105 +GET {{api_host}}/api/v2/spot/trade/fills?symbol=BTCUSDT +ACCESS-KEY: {{api_key}} +ACCESS-SIGN: {{sign}} +ACCESS-TIMESTAMP: {{timestamp}} +ACCESS-PASSPHRASE: {{api_passphrase}} + + diff --git a/xchange-core/src/main/java/org/knowm/xchange/service/trade/params/TradeHistoryParamOrderId.java b/xchange-core/src/main/java/org/knowm/xchange/service/trade/params/TradeHistoryParamOrderId.java new file mode 100644 index 0000000000..da9485ed61 --- /dev/null +++ b/xchange-core/src/main/java/org/knowm/xchange/service/trade/params/TradeHistoryParamOrderId.java @@ -0,0 +1,12 @@ +package org.knowm.xchange.service.trade.params; + +/** + * {@link TradeHistoryParams} with order id as param + */ +public interface TradeHistoryParamOrderId extends TradeHistoryParams { + + String getOrderId(); + + void setOrderId(String orderId); + +} diff --git a/xchange-core/src/main/java/org/knowm/xchange/service/trade/params/TradeHistoryParamTransactionId.java b/xchange-core/src/main/java/org/knowm/xchange/service/trade/params/TradeHistoryParamTransactionId.java index f7b5a619e7..bc6ce2d225 100644 --- a/xchange-core/src/main/java/org/knowm/xchange/service/trade/params/TradeHistoryParamTransactionId.java +++ b/xchange-core/src/main/java/org/knowm/xchange/service/trade/params/TradeHistoryParamTransactionId.java @@ -1,5 +1,8 @@ package org.knowm.xchange.service.trade.params; +/** + * {@link TradeHistoryParams} with id of single trade as param + */ public interface TradeHistoryParamTransactionId extends TradeHistoryParams { String getTransactionId(); From e7d6a07d7b72073cb4b37f925758cc7e305990b1 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Thu, 3 Oct 2024 01:36:56 +0200 Subject: [PATCH 04/10] [bitget] Add getting transfer records --- .../knowm/xchange/bitget/BitgetAdapters.java | 9 +++ .../xchange/bitget/BitgetAuthenticated.java | 15 +++++ .../bitget/dto/account/BitgetAccountType.java | 21 +++++++ .../dto/account/BitgetTransferRecordDto.java | 62 +++++++++++++++++++ .../params/BitgetTransferHistoryParams.java | 27 ++++++++ .../service/BitgetAccountServiceRaw.java | 15 +++++ .../service/BitgetAccountServiceRawTest.java | 52 ++++++++++++++++ .../api_v2_spot_account_transferrecords.json | 19 ++++++ .../api_v2_spot_account_transferrecords.json | 15 +++++ .../src/test/resources/rest/spot.http | 25 +++++++- 10 files changed, 259 insertions(+), 1 deletion(-) create mode 100644 xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/account/BitgetAccountType.java create mode 100755 xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/account/BitgetTransferRecordDto.java create mode 100644 xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/account/params/BitgetTransferHistoryParams.java create mode 100644 xchange-bitget/src/test/java/org/knowm/xchange/bitget/service/BitgetAccountServiceRawTest.java create mode 100644 xchange-bitget/src/test/resources/__files/api_v2_spot_account_transferrecords.json create mode 100644 xchange-bitget/src/test/resources/mappings/api_v2_spot_account_transferrecords.json diff --git a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/BitgetAdapters.java b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/BitgetAdapters.java index 4c48aff941..2f0f86979d 100644 --- a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/BitgetAdapters.java +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/BitgetAdapters.java @@ -10,6 +10,7 @@ import java.util.Optional; import java.util.stream.Collectors; import lombok.experimental.UtilityClass; +import org.knowm.xchange.bitget.dto.account.BitgetAccountType; import org.knowm.xchange.bitget.dto.account.BitgetBalanceDto; import org.knowm.xchange.bitget.dto.marketdata.BitgetMarketDepthDto; import org.knowm.xchange.bitget.dto.marketdata.BitgetSymbolDto; @@ -238,5 +239,13 @@ public UserTrade toUserTrade(BitgetFillDto bitgetFillDto) { bitgetFillDto.getPrice(), toDate(bitgetFillDto.getUpdatedAt()), bitgetFillDto.getTradeId(), bitgetFillDto.getOrderId(), bitgetFillDto.getFeeDetail().getTotalFee().abs(), bitgetFillDto.getFeeDetail().getCurrency(), null); } + + + public String toString(BitgetAccountType bitgetAccountType) { + return Optional.ofNullable(bitgetAccountType) + .map(BitgetAccountType::getValue) + .orElse(null); + } + } diff --git a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/BitgetAuthenticated.java b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/BitgetAuthenticated.java index 51ab26cc54..e3c0de1b87 100644 --- a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/BitgetAuthenticated.java +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/BitgetAuthenticated.java @@ -13,6 +13,7 @@ import org.knowm.xchange.bitget.dto.BitgetException; import org.knowm.xchange.bitget.dto.BitgetResponse; import org.knowm.xchange.bitget.dto.account.BitgetBalanceDto; +import org.knowm.xchange.bitget.dto.account.BitgetTransferRecordDto; import org.knowm.xchange.bitget.dto.trade.BitgetFillDto; import org.knowm.xchange.bitget.dto.trade.BitgetOrderInfoDto; import org.knowm.xchange.bitget.dto.trade.BitgetPlaceOrderDto; @@ -69,4 +70,18 @@ BitgetResponse> fills( throws IOException, BitgetException; + @GET + @Path("api/v2/spot/account/transferRecords") + BitgetResponse> transferRecords( + @HeaderParam("ACCESS-KEY") String apiKey, + @HeaderParam("ACCESS-SIGN") ParamsDigest signer, + @HeaderParam("ACCESS-PASSPHRASE") String passphrase, + @HeaderParam("ACCESS-TIMESTAMP") SynchronizedValueFactory timestamp, + @QueryParam("coin") String currency, @QueryParam("limit") Integer limit, @QueryParam("clientOid") String clientOid, + @QueryParam("fromType") String fromType, + @QueryParam("startTime") Long startTime, @QueryParam("endTime") Long endTime, + @QueryParam("idLessThan") String idLessThan) + throws IOException, BitgetException; + + } diff --git a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/account/BitgetAccountType.java b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/account/BitgetAccountType.java new file mode 100644 index 0000000000..9d39db1857 --- /dev/null +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/account/BitgetAccountType.java @@ -0,0 +1,21 @@ +package org.knowm.xchange.bitget.dto.account; + +import com.fasterxml.jackson.annotation.JsonValue; +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public enum BitgetAccountType { + SPOT("spot"), + P2P("p2p"), + COIN_FUTURES("coin_futures"), + USDT_FUTURES("usdt_futures"), + USDC_FUTURES("usdc_futures"), + CROSSED_MARGIN("crossed_margin"), + ISOLATED_MARGIN("isolated_margin"); + + @JsonValue + private final String value; + +} diff --git a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/account/BitgetTransferRecordDto.java b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/account/BitgetTransferRecordDto.java new file mode 100755 index 0000000000..cce4159007 --- /dev/null +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/account/BitgetTransferRecordDto.java @@ -0,0 +1,62 @@ +package org.knowm.xchange.bitget.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.bitget.config.converter.StringToCurrencyConverter; +import org.knowm.xchange.currency.Currency; + +@Data +@Builder +@Jacksonized +public class BitgetTransferRecordDto { + + @JsonProperty("clientOid") + private String clientOid; + + @JsonProperty("transferId") + private String transferId; + + @JsonProperty("coin") + @JsonDeserialize(converter = StringToCurrencyConverter.class) + private Currency currency; + + @JsonProperty("status") + private Status status; + + @JsonProperty("toType") + private BitgetAccountType toAccountType; + + @JsonProperty("toSymbol") + private String toSymbol; + + @JsonProperty("fromType") + private BitgetAccountType fromAccountType; + + @JsonProperty("fromSymbol") + private String fromSymbol; + + @JsonProperty("size") + private BigDecimal size; + + @JsonProperty("ts") + private Instant timestamp; + + + public static enum Status { + @JsonProperty("Successful") + SUCCESSFUL, + + @JsonProperty("Processing") + PROCESSING, + + @JsonProperty("Failed") + FAILED + } + + +} diff --git a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/account/params/BitgetTransferHistoryParams.java b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/account/params/BitgetTransferHistoryParams.java new file mode 100644 index 0000000000..f89d23f755 --- /dev/null +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/account/params/BitgetTransferHistoryParams.java @@ -0,0 +1,27 @@ +package org.knowm.xchange.bitget.dto.account.params; + +import java.time.Instant; +import lombok.Data; +import lombok.experimental.SuperBuilder; +import org.knowm.xchange.bitget.dto.account.BitgetAccountType; +import org.knowm.xchange.currency.Currency; + +@Data +@SuperBuilder +public class BitgetTransferHistoryParams { + + private Currency currency; + + private BitgetAccountType fromAccountType; + + private Instant startTime; + + private Instant endTime; + + private String clientOid; + + private Integer limit; + + private String endId; + +} diff --git a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/BitgetAccountServiceRaw.java b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/BitgetAccountServiceRaw.java index 4ffc0195fe..bbe27b9f2c 100644 --- a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/BitgetAccountServiceRaw.java +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/BitgetAccountServiceRaw.java @@ -2,8 +2,11 @@ import java.io.IOException; import java.util.List; +import org.knowm.xchange.bitget.BitgetAdapters; import org.knowm.xchange.bitget.BitgetExchange; import org.knowm.xchange.bitget.dto.account.BitgetBalanceDto; +import org.knowm.xchange.bitget.dto.account.BitgetTransferRecordDto; +import org.knowm.xchange.bitget.dto.account.params.BitgetTransferHistoryParams; public class BitgetAccountServiceRaw extends BitgetBaseService { @@ -15,4 +18,16 @@ public BitgetAccountServiceRaw(BitgetExchange exchange) { public List getBitgetBalances() throws IOException { return bitgetAuthenticated.balances(apiKey, bitgetDigest, passphrase, exchange.getNonceFactory()).getData(); } + + + public List getBitgetTransferRecords(BitgetTransferHistoryParams params) throws IOException { + Long from = params.getStartTime() != null ? params.getStartTime().toEpochMilli() : null; + Long to = params.getEndTime() != null ? params.getEndTime().toEpochMilli() : null; + + return bitgetAuthenticated.transferRecords(apiKey, bitgetDigest, passphrase, exchange.getNonceFactory(), + BitgetAdapters.toString(params.getCurrency()), params.getLimit(), params.getClientOid(), + BitgetAdapters.toString(params.getFromAccountType()), from, to, params.getEndId()).getData(); + } + + } diff --git a/xchange-bitget/src/test/java/org/knowm/xchange/bitget/service/BitgetAccountServiceRawTest.java b/xchange-bitget/src/test/java/org/knowm/xchange/bitget/service/BitgetAccountServiceRawTest.java new file mode 100644 index 0000000000..d20a1639e3 --- /dev/null +++ b/xchange-bitget/src/test/java/org/knowm/xchange/bitget/service/BitgetAccountServiceRawTest.java @@ -0,0 +1,52 @@ +package org.knowm.xchange.bitget.service; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.knowm.xchange.currency.Currency.USDT; + +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.bitget.BitgetExchangeWiremock; +import org.knowm.xchange.bitget.dto.account.BitgetAccountType; +import org.knowm.xchange.bitget.dto.account.BitgetTransferRecordDto; +import org.knowm.xchange.bitget.dto.account.BitgetTransferRecordDto.Status; +import org.knowm.xchange.bitget.dto.account.params.BitgetTransferHistoryParams; + +class BitgetAccountServiceRawTest extends BitgetExchangeWiremock { + + BitgetAccountServiceRaw bitgetAccountServiceRaw = (BitgetAccountServiceRaw) exchange.getAccountService(); + + + @Test + void transfer_records() throws IOException { + BitgetTransferRecordDto expected = BitgetTransferRecordDto.builder() + .clientOid("1225489997897666560") + .currency(USDT) + .fromAccountType(BitgetAccountType.SPOT) + .fromSymbol("") + .toAccountType(BitgetAccountType.SPOT) + .toSymbol("") + .size(new BigDecimal("1.00000000")) + .status(Status.SUCCESSFUL) + .timestamp(Instant.ofEpochMilli(1727905504678L)) + .transferId("1225489997897666560") + .build(); + + BitgetTransferHistoryParams params = BitgetTransferHistoryParams.builder() + .currency(USDT) + .fromAccountType(BitgetAccountType.SPOT) + .startTime(Instant.ofEpochMilli(1727904561900L)) + .endTime(Instant.ofEpochMilli(1727905505000L)) + .limit(1) + .endId("1225486043893731328") + .build(); + List actual = bitgetAccountServiceRaw.getBitgetTransferRecords(params); + + assertThat(actual).hasSize(1); + assertThat(actual).first().usingRecursiveComparison().isEqualTo(expected); + } + + +} \ No newline at end of file diff --git a/xchange-bitget/src/test/resources/__files/api_v2_spot_account_transferrecords.json b/xchange-bitget/src/test/resources/__files/api_v2_spot_account_transferrecords.json new file mode 100644 index 0000000000..7653caae73 --- /dev/null +++ b/xchange-bitget/src/test/resources/__files/api_v2_spot_account_transferrecords.json @@ -0,0 +1,19 @@ +{ + "code": "00000", + "msg": "success", + "requestTime": 1727909228121, + "data": [ + { + "coin": "USDT", + "status": "Successful", + "toType": "spot", + "toSymbol": "", + "fromType": "spot", + "fromSymbol": "", + "size": "1.00000000", + "ts": "1727905504678", + "clientOid": "1225489997897666560", + "transferId": "1225489997897666560" + } + ] +} \ No newline at end of file diff --git a/xchange-bitget/src/test/resources/mappings/api_v2_spot_account_transferrecords.json b/xchange-bitget/src/test/resources/mappings/api_v2_spot_account_transferrecords.json new file mode 100644 index 0000000000..372e46c3fa --- /dev/null +++ b/xchange-bitget/src/test/resources/mappings/api_v2_spot_account_transferrecords.json @@ -0,0 +1,15 @@ +{ + "id" : "2b0c78d1-70f1-4a68-8f64-629c9c6833ef", + "name" : "api_v2_spot_account_transferrecords", + "request" : { + "url" : "/api/v2/spot/account/transferRecords?coin=USDT&limit=1&fromType=spot&startTime=1727904561900&endTime=1727905505000&idLessThan=1225486043893731328", + "method" : "GET" + }, + "response" : { + "status" : 200, + "bodyFileName" : "api_v2_spot_account_transferrecords.json" + }, + "uuid" : "2b0c78d1-70f1-4a68-8f64-629c9c6833ef", + "persistent" : true, + "insertionIndex" : 7 +} \ No newline at end of file diff --git a/xchange-bitget/src/test/resources/rest/spot.http b/xchange-bitget/src/test/resources/rest/spot.http index c5bc747754..9ffaee1093 100644 --- a/xchange-bitget/src/test/resources/rest/spot.http +++ b/xchange-bitget/src/test/resources/rest/spot.http @@ -109,7 +109,6 @@ ACCESS-PASSPHRASE: {{api_passphrase}} import {gen_sign} from 'sign.js' gen_sign(request); %} -#GET {{api_host}}/api/v2/spot/trade/fills?symbol=ASMUSDT&limit=1000&orderId=1225428954737188883&startTime=1727890950945&endTime=1727890950947&idLessThan=1225428955008811105 GET {{api_host}}/api/v2/spot/trade/fills?symbol=BTCUSDT ACCESS-KEY: {{api_key}} ACCESS-SIGN: {{sign}} @@ -117,3 +116,27 @@ ACCESS-TIMESTAMP: {{timestamp}} ACCESS-PASSPHRASE: {{api_passphrase}} +### Get Transfer Record +< {% + import {gen_sign} from 'sign.js' + gen_sign(request); +%} +GET {{api_host}}/api/v2/spot/account/transferRecords?coin=USDT&fromType=spot&endTime=1727904561971 +ACCESS-KEY: {{api_key}} +ACCESS-SIGN: {{sign}} +ACCESS-TIMESTAMP: {{timestamp}} +ACCESS-PASSPHRASE: {{api_passphrase}} + + +### Get MainSub Transfer Record +< {% + import {gen_sign} from 'sign.js' + gen_sign(request); +%} +GET {{api_host}}/api/v2/spot/account/sub-main-trans-record +ACCESS-KEY: {{api_key}} +ACCESS-SIGN: {{sign}} +ACCESS-TIMESTAMP: {{timestamp}} +ACCESS-PASSPHRASE: {{api_passphrase}} + + From e74b3d64de87be85bfa0a9d9fdd8d2c5013723ad Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Thu, 3 Oct 2024 02:04:49 +0200 Subject: [PATCH 05/10] [bitget] Add getting main-sub transfer records --- .../knowm/xchange/bitget/BitgetAdapters.java | 9 +++ .../xchange/bitget/BitgetAuthenticated.java | 15 +++++ .../BitgetMainSubTransferRecordDto.java | 62 +++++++++++++++++++ .../BitgetMainSubTransferHistoryParams.java | 46 ++++++++++++++ .../service/BitgetAccountServiceRaw.java | 13 ++++ .../service/BitgetAccountServiceRawTest.java | 35 +++++++++++ ...v2_spot_account_sub-main-trans-record.json | 19 ++++++ ...v2_spot_account_sub-main-trans-record.json | 15 +++++ 8 files changed, 214 insertions(+) create mode 100755 xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/account/BitgetMainSubTransferRecordDto.java create mode 100644 xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/account/params/BitgetMainSubTransferHistoryParams.java create mode 100644 xchange-bitget/src/test/resources/__files/api_v2_spot_account_sub-main-trans-record.json create mode 100644 xchange-bitget/src/test/resources/mappings/api_v2_spot_account_sub-main-trans-record.json diff --git a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/BitgetAdapters.java b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/BitgetAdapters.java index 2f0f86979d..6547c1e8c6 100644 --- a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/BitgetAdapters.java +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/BitgetAdapters.java @@ -12,6 +12,8 @@ import lombok.experimental.UtilityClass; import org.knowm.xchange.bitget.dto.account.BitgetAccountType; import org.knowm.xchange.bitget.dto.account.BitgetBalanceDto; +import org.knowm.xchange.bitget.dto.account.params.BitgetMainSubTransferHistoryParams; +import org.knowm.xchange.bitget.dto.account.params.BitgetMainSubTransferHistoryParams.Role; import org.knowm.xchange.bitget.dto.marketdata.BitgetMarketDepthDto; import org.knowm.xchange.bitget.dto.marketdata.BitgetSymbolDto; import org.knowm.xchange.bitget.dto.marketdata.BitgetSymbolDto.Status; @@ -248,4 +250,11 @@ public String toString(BitgetAccountType bitgetAccountType) { } + public String toString(BitgetMainSubTransferHistoryParams.Role role) { + return Optional.ofNullable(role) + .map(Role::getValue) + .orElse(null); + } + + } diff --git a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/BitgetAuthenticated.java b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/BitgetAuthenticated.java index e3c0de1b87..6a69717115 100644 --- a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/BitgetAuthenticated.java +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/BitgetAuthenticated.java @@ -13,6 +13,7 @@ import org.knowm.xchange.bitget.dto.BitgetException; import org.knowm.xchange.bitget.dto.BitgetResponse; import org.knowm.xchange.bitget.dto.account.BitgetBalanceDto; +import org.knowm.xchange.bitget.dto.account.BitgetMainSubTransferRecordDto; import org.knowm.xchange.bitget.dto.account.BitgetTransferRecordDto; import org.knowm.xchange.bitget.dto.trade.BitgetFillDto; import org.knowm.xchange.bitget.dto.trade.BitgetOrderInfoDto; @@ -84,4 +85,18 @@ BitgetResponse> transferRecords( throws IOException, BitgetException; + @GET + @Path("api/v2/spot/account/sub-main-trans-record") + BitgetResponse> mainSubTransferRecords( + @HeaderParam("ACCESS-KEY") String apiKey, + @HeaderParam("ACCESS-SIGN") ParamsDigest signer, + @HeaderParam("ACCESS-PASSPHRASE") String passphrase, + @HeaderParam("ACCESS-TIMESTAMP") SynchronizedValueFactory timestamp, + @QueryParam("coin") String currency, @QueryParam("limit") Integer limit, @QueryParam("clientOid") String clientOid, + @QueryParam("role") String role, @QueryParam("subUid") String subAccountUid, + @QueryParam("startTime") Long startTime, @QueryParam("endTime") Long endTime, + @QueryParam("idLessThan") String idLessThan) + throws IOException, BitgetException; + + } diff --git a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/account/BitgetMainSubTransferRecordDto.java b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/account/BitgetMainSubTransferRecordDto.java new file mode 100755 index 0000000000..e7a1cffc40 --- /dev/null +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/account/BitgetMainSubTransferRecordDto.java @@ -0,0 +1,62 @@ +package org.knowm.xchange.bitget.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.bitget.config.converter.StringToCurrencyConverter; +import org.knowm.xchange.currency.Currency; + +@Data +@Builder +@Jacksonized +public class BitgetMainSubTransferRecordDto { + + @JsonProperty("clientOid") + private String clientOid; + + @JsonProperty("transferId") + private String transferId; + + @JsonProperty("coin") + @JsonDeserialize(converter = StringToCurrencyConverter.class) + private Currency currency; + + @JsonProperty("status") + private Status status; + + @JsonProperty("toType") + private BitgetAccountType toAccountType; + + @JsonProperty("fromType") + private BitgetAccountType fromAccountType; + + @JsonProperty("size") + private BigDecimal size; + + @JsonProperty("ts") + private Instant timestamp; + + @JsonProperty("fromUserId") + private String fromUserId; + + @JsonProperty("toUserId") + private String toUserId; + + + public static enum Status { + @JsonProperty("Successful") + SUCCESSFUL, + + @JsonProperty("Processing") + PROCESSING, + + @JsonProperty("Failed") + FAILED + } + + +} diff --git a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/account/params/BitgetMainSubTransferHistoryParams.java b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/account/params/BitgetMainSubTransferHistoryParams.java new file mode 100644 index 0000000000..4ab3faca46 --- /dev/null +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/account/params/BitgetMainSubTransferHistoryParams.java @@ -0,0 +1,46 @@ +package org.knowm.xchange.bitget.dto.account.params; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import java.time.Instant; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.Getter; +import lombok.experimental.SuperBuilder; +import org.knowm.xchange.currency.Currency; + +@Data +@SuperBuilder +public class BitgetMainSubTransferHistoryParams { + + private Currency currency; + + private Role role; + + private String subAccountUid; + + private Instant startTime; + + private Instant endTime; + + private String clientOid; + + private Integer limit; + + private String endId; + + + @Getter + @AllArgsConstructor + public static enum Role { + INITIATOR("initiator"), + + @JsonProperty + RECEIVER("receiver"); + + @JsonValue + private final String value; + + } + +} diff --git a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/BitgetAccountServiceRaw.java b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/BitgetAccountServiceRaw.java index bbe27b9f2c..01471df4ae 100644 --- a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/BitgetAccountServiceRaw.java +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/BitgetAccountServiceRaw.java @@ -5,7 +5,9 @@ import org.knowm.xchange.bitget.BitgetAdapters; import org.knowm.xchange.bitget.BitgetExchange; import org.knowm.xchange.bitget.dto.account.BitgetBalanceDto; +import org.knowm.xchange.bitget.dto.account.BitgetMainSubTransferRecordDto; import org.knowm.xchange.bitget.dto.account.BitgetTransferRecordDto; +import org.knowm.xchange.bitget.dto.account.params.BitgetMainSubTransferHistoryParams; import org.knowm.xchange.bitget.dto.account.params.BitgetTransferHistoryParams; public class BitgetAccountServiceRaw extends BitgetBaseService { @@ -30,4 +32,15 @@ public List getBitgetTransferRecords(BitgetTransferHist } + public List getBitgetMainSubTransferRecords( + BitgetMainSubTransferHistoryParams params) throws IOException { + Long from = params.getStartTime() != null ? params.getStartTime().toEpochMilli() : null; + Long to = params.getEndTime() != null ? params.getEndTime().toEpochMilli() : null; + + return bitgetAuthenticated.mainSubTransferRecords(apiKey, bitgetDigest, passphrase, exchange.getNonceFactory(), + BitgetAdapters.toString(params.getCurrency()), params.getLimit(), params.getClientOid(), + BitgetAdapters.toString(params.getRole()), params.getSubAccountUid(), from, to, params.getEndId()).getData(); + } + + } diff --git a/xchange-bitget/src/test/java/org/knowm/xchange/bitget/service/BitgetAccountServiceRawTest.java b/xchange-bitget/src/test/java/org/knowm/xchange/bitget/service/BitgetAccountServiceRawTest.java index d20a1639e3..0e591e51ef 100644 --- a/xchange-bitget/src/test/java/org/knowm/xchange/bitget/service/BitgetAccountServiceRawTest.java +++ b/xchange-bitget/src/test/java/org/knowm/xchange/bitget/service/BitgetAccountServiceRawTest.java @@ -10,8 +10,11 @@ import org.junit.jupiter.api.Test; import org.knowm.xchange.bitget.BitgetExchangeWiremock; import org.knowm.xchange.bitget.dto.account.BitgetAccountType; +import org.knowm.xchange.bitget.dto.account.BitgetMainSubTransferRecordDto; import org.knowm.xchange.bitget.dto.account.BitgetTransferRecordDto; import org.knowm.xchange.bitget.dto.account.BitgetTransferRecordDto.Status; +import org.knowm.xchange.bitget.dto.account.params.BitgetMainSubTransferHistoryParams; +import org.knowm.xchange.bitget.dto.account.params.BitgetMainSubTransferHistoryParams.Role; import org.knowm.xchange.bitget.dto.account.params.BitgetTransferHistoryParams; class BitgetAccountServiceRawTest extends BitgetExchangeWiremock { @@ -49,4 +52,36 @@ void transfer_records() throws IOException { } + @Test + void main_sub_transfer_records() throws IOException { + BitgetMainSubTransferRecordDto expected = BitgetMainSubTransferRecordDto.builder() + .clientOid("1225490042499895296") + .currency(USDT) + .fromAccountType(BitgetAccountType.SPOT) + .toAccountType(BitgetAccountType.SPOT) + .fromUserId("7326856338") + .toUserId("1548914322") + .size(new BigDecimal("1.00000000")) + .status(BitgetMainSubTransferRecordDto.Status.SUCCESSFUL) + .timestamp(Instant.ofEpochMilli(1727905515312L)) + .transferId("72990567") + .build(); + + BitgetMainSubTransferHistoryParams params = BitgetMainSubTransferHistoryParams.builder() + .currency(USDT) + .role(Role.INITIATOR) + .subAccountUid("7326856338") + .startTime(Instant.ofEpochMilli(1727905515300L)) + .endTime(Instant.ofEpochMilli(1727905515399L)) + .clientOid("1225490042499895296") + .limit(1) + .endId("1225490042499895296") + .build(); + List actual = bitgetAccountServiceRaw.getBitgetMainSubTransferRecords(params); + + assertThat(actual).hasSize(1); + assertThat(actual).first().usingRecursiveComparison().isEqualTo(expected); + } + + } \ No newline at end of file diff --git a/xchange-bitget/src/test/resources/__files/api_v2_spot_account_sub-main-trans-record.json b/xchange-bitget/src/test/resources/__files/api_v2_spot_account_sub-main-trans-record.json new file mode 100644 index 0000000000..f65ce9d997 --- /dev/null +++ b/xchange-bitget/src/test/resources/__files/api_v2_spot_account_sub-main-trans-record.json @@ -0,0 +1,19 @@ +{ + "code": "00000", + "msg": "success", + "requestTime": 1727913697840, + "data": [ + { + "coin": "USDT", + "status": "Successful", + "toType": "spot", + "fromType": "spot", + "size": "1.00000000", + "ts": "1727905515312", + "clientOid": "1225490042499895296", + "transferId": "72990567", + "fromUserId": "7326856338", + "toUserId": "1548914322" + } + ] +} \ No newline at end of file diff --git a/xchange-bitget/src/test/resources/mappings/api_v2_spot_account_sub-main-trans-record.json b/xchange-bitget/src/test/resources/mappings/api_v2_spot_account_sub-main-trans-record.json new file mode 100644 index 0000000000..28517ceef0 --- /dev/null +++ b/xchange-bitget/src/test/resources/mappings/api_v2_spot_account_sub-main-trans-record.json @@ -0,0 +1,15 @@ +{ + "id" : "f2259cb5-ac09-44cc-8cfe-9f29489abf19", + "name" : "api_v2_spot_account_sub-main-trans-record", + "request" : { + "url" : "/api/v2/spot/account/sub-main-trans-record?coin=USDT&limit=1&clientOid=1225490042499895296&role=initiator&subUid=7326856338&startTime=1727905515300&endTime=1727905515399&idLessThan=1225490042499895296", + "method" : "GET" + }, + "response" : { + "status" : 200, + "bodyFileName" : "api_v2_spot_account_sub-main-trans-record.json" + }, + "uuid" : "f2259cb5-ac09-44cc-8cfe-9f29489abf19", + "persistent" : true, + "insertionIndex" : 8 +} \ No newline at end of file From 72968cb81cc362f34ce15321aa22bcde04fb4972 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Wed, 9 Oct 2024 19:03:38 +0200 Subject: [PATCH 06/10] [bitget] Add getting of deposits- and withdrawals-history --- .../knowm/xchange/bitget/BitgetAdapters.java | 39 ++++++++ .../xchange/bitget/BitgetAuthenticated.java | 28 ++++++ .../StringToFundingRecordStatusConverter.java | 25 ++++++ .../BitgetDepositWithdrawRecordDto.java | 89 +++++++++++++++++++ .../bitget/service/BitgetAccountService.java | 20 +++++ .../service/BitgetAccountServiceRaw.java | 48 ++++++++++ .../params/BitgetFundingHistoryParams.java | 36 ++++++++ .../service/BitgetAccountServiceTest.java | 45 ++++++++++ .../api_v2_spot_wallet_deposit-records.json | 21 +++++ ...api_v2_spot_wallet_withdrawal-records.json | 25 ++++++ .../api_v2_spot_wallet_deposit-records.json | 15 ++++ ...api_v2_spot_wallet_withdrawal-records.json | 15 ++++ .../src/test/resources/rest/spot.http | 24 +++++ .../params/TradeHistoryParamClientOid.java | 12 +++ 14 files changed, 442 insertions(+) create mode 100644 xchange-bitget/src/main/java/org/knowm/xchange/bitget/config/converter/StringToFundingRecordStatusConverter.java create mode 100755 xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/account/BitgetDepositWithdrawRecordDto.java create mode 100644 xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/params/BitgetFundingHistoryParams.java create mode 100644 xchange-bitget/src/test/java/org/knowm/xchange/bitget/service/BitgetAccountServiceTest.java create mode 100644 xchange-bitget/src/test/resources/__files/api_v2_spot_wallet_deposit-records.json create mode 100644 xchange-bitget/src/test/resources/__files/api_v2_spot_wallet_withdrawal-records.json create mode 100644 xchange-bitget/src/test/resources/mappings/api_v2_spot_wallet_deposit-records.json create mode 100644 xchange-bitget/src/test/resources/mappings/api_v2_spot_wallet_withdrawal-records.json create mode 100644 xchange-core/src/main/java/org/knowm/xchange/service/trade/params/TradeHistoryParamClientOid.java diff --git a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/BitgetAdapters.java b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/BitgetAdapters.java index 6547c1e8c6..0704f30738 100644 --- a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/BitgetAdapters.java +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/BitgetAdapters.java @@ -12,6 +12,9 @@ import lombok.experimental.UtilityClass; import org.knowm.xchange.bitget.dto.account.BitgetAccountType; import org.knowm.xchange.bitget.dto.account.BitgetBalanceDto; +import org.knowm.xchange.bitget.dto.account.BitgetDepositWithdrawRecordDto; +import org.knowm.xchange.bitget.dto.account.BitgetDepositWithdrawRecordDto.DepositType; +import org.knowm.xchange.bitget.dto.account.BitgetDepositWithdrawRecordDto.RecordType; import org.knowm.xchange.bitget.dto.account.params.BitgetMainSubTransferHistoryParams; import org.knowm.xchange.bitget.dto.account.params.BitgetMainSubTransferHistoryParams.Role; import org.knowm.xchange.bitget.dto.marketdata.BitgetMarketDepthDto; @@ -28,6 +31,8 @@ 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.Type; import org.knowm.xchange.dto.account.Wallet; import org.knowm.xchange.dto.marketdata.OrderBook; import org.knowm.xchange.dto.marketdata.Ticker; @@ -257,4 +262,38 @@ public String toString(BitgetMainSubTransferHistoryParams.Role role) { } + public FundingRecord toFundingRecord(BitgetDepositWithdrawRecordDto record) { + return new FundingRecord.Builder() + .setInternalId(record.getOrderId()) + .setBlockchainTransactionHash(record.getTradeId()) + .setCurrency(record.getCurrency()) + .setType(toFundingRecordType(record)) + .setAmount(record.getSize()) + .setFee(record.getFee()) + .setStatus(record.getStatus()) + .setAddress(record.getToAddress()) + .setAddressTag(record.getToAddressTag()) + .setDate(toDate(record.getUpdatedAt())) + .build(); + } + + + public FundingRecord.Type toFundingRecordType(BitgetDepositWithdrawRecordDto record) { + if (record.getDepositType() == DepositType.ON_CHAIN && record.getType() == RecordType.WITHDRAW) { + return Type.WITHDRAWAL; + } + if (record.getDepositType() == DepositType.ON_CHAIN && record.getType() == RecordType.DEPOSIT) { + return Type.DEPOSIT; + } + if (record.getDepositType() == DepositType.INTERNAL_TRANSFER && record.getType() == RecordType.WITHDRAW) { + return Type.INTERNAL_WITHDRAWAL; + } + if (record.getDepositType() == DepositType.INTERNAL_TRANSFER && record.getType() == RecordType.DEPOSIT) { + return Type.INTERNAL_DEPOSIT; + } + + return null; + } + + } diff --git a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/BitgetAuthenticated.java b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/BitgetAuthenticated.java index 6a69717115..86eeaaee41 100644 --- a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/BitgetAuthenticated.java +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/BitgetAuthenticated.java @@ -13,6 +13,7 @@ import org.knowm.xchange.bitget.dto.BitgetException; import org.knowm.xchange.bitget.dto.BitgetResponse; import org.knowm.xchange.bitget.dto.account.BitgetBalanceDto; +import org.knowm.xchange.bitget.dto.account.BitgetDepositWithdrawRecordDto; import org.knowm.xchange.bitget.dto.account.BitgetMainSubTransferRecordDto; import org.knowm.xchange.bitget.dto.account.BitgetTransferRecordDto; import org.knowm.xchange.bitget.dto.trade.BitgetFillDto; @@ -99,4 +100,31 @@ BitgetResponse> mainSubTransferRecords( throws IOException, BitgetException; + @GET + @Path("api/v2/spot/wallet/deposit-records") + BitgetResponse> depositRecords( + @HeaderParam("ACCESS-KEY") String apiKey, + @HeaderParam("ACCESS-SIGN") ParamsDigest signer, + @HeaderParam("ACCESS-PASSPHRASE") String passphrase, + @HeaderParam("ACCESS-TIMESTAMP") SynchronizedValueFactory timestamp, + @QueryParam("coin") String currency, @QueryParam("limit") Integer limit, @QueryParam("orderId") String orderId, + @QueryParam("startTime") Long startTime, @QueryParam("endTime") Long endTime, + @QueryParam("idLessThan") String idLessThan) + throws IOException, BitgetException; + + + @GET + @Path("api/v2/spot/wallet/withdrawal-records") + BitgetResponse> withdrawalRecords( + @HeaderParam("ACCESS-KEY") String apiKey, + @HeaderParam("ACCESS-SIGN") ParamsDigest signer, + @HeaderParam("ACCESS-PASSPHRASE") String passphrase, + @HeaderParam("ACCESS-TIMESTAMP") SynchronizedValueFactory timestamp, + @QueryParam("coin") String currency, @QueryParam("limit") Integer limit, + @QueryParam("orderId") String orderId, @QueryParam("clientOid") String clientOid, + @QueryParam("startTime") Long startTime, @QueryParam("endTime") Long endTime, + @QueryParam("idLessThan") String idLessThan) + throws IOException, BitgetException; + + } diff --git a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/config/converter/StringToFundingRecordStatusConverter.java b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/config/converter/StringToFundingRecordStatusConverter.java new file mode 100644 index 0000000000..35ae19b4c0 --- /dev/null +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/config/converter/StringToFundingRecordStatusConverter.java @@ -0,0 +1,25 @@ +package org.knowm.xchange.bitget.config.converter; + +import com.fasterxml.jackson.databind.util.StdConverter; +import java.util.Locale; +import org.knowm.xchange.dto.account.FundingRecord.Status; + +/** + * Converts string to {@code FundingRecord.Status} + */ +public class StringToFundingRecordStatusConverter extends StdConverter { + + @Override + public Status convert(String value) { + switch (value.toUpperCase(Locale.ROOT)) { + case "PENDING": + return Status.PROCESSING; + case "FAIL": + return Status.FAILED; + case "SUCCESS": + return Status.COMPLETE; + default: + throw new IllegalArgumentException("Can't map " + value); + } + } +} diff --git a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/account/BitgetDepositWithdrawRecordDto.java b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/account/BitgetDepositWithdrawRecordDto.java new file mode 100755 index 0000000000..07fbf9ec8f --- /dev/null +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/account/BitgetDepositWithdrawRecordDto.java @@ -0,0 +1,89 @@ +package org.knowm.xchange.bitget.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.bitget.config.converter.StringToCurrencyConverter; +import org.knowm.xchange.bitget.config.converter.StringToFundingRecordStatusConverter; +import org.knowm.xchange.currency.Currency; +import org.knowm.xchange.dto.account.FundingRecord.Status; + +@Data +@Builder +@Jacksonized +public class BitgetDepositWithdrawRecordDto { + + @JsonProperty("orderId") + private String orderId; + + @JsonProperty("tradeId") + private String tradeId; + + @JsonProperty("coin") + @JsonDeserialize(converter = StringToCurrencyConverter.class) + private Currency currency; + + @JsonProperty("clientOid") + private String clientOid; + + @JsonProperty("type") + private RecordType type; + + @JsonProperty("dest") + private DepositType depositType; + + @JsonProperty("size") + private BigDecimal size; + + @JsonProperty("fee") + private BigDecimal fee; + + @JsonProperty("status") + @JsonDeserialize(converter = StringToFundingRecordStatusConverter.class) + private Status status; + + @JsonProperty("fromAddress") + private String fromAddress; + + @JsonProperty("toAddress") + private String toAddress; + + @JsonProperty("chain") + private String chain; + + @JsonProperty("confirm") + private Integer confirmCount; + + @JsonProperty("tag") + private String toAddressTag; + + @JsonProperty("cTime") + private Instant createdAt; + + @JsonProperty("uTime") + private Instant updatedAt; + + + public static enum RecordType { + @JsonProperty("withdraw") + WITHDRAW, + + @JsonProperty("deposit") + DEPOSIT + } + + + public static enum DepositType { + @JsonProperty("on_chain") + ON_CHAIN, + + @JsonProperty("internal_transfer") + INTERNAL_TRANSFER + } + + +} diff --git a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/BitgetAccountService.java b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/BitgetAccountService.java index d8222013fd..43a60bf382 100644 --- a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/BitgetAccountService.java +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/BitgetAccountService.java @@ -2,14 +2,19 @@ import java.io.IOException; import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; import org.knowm.xchange.bitget.BitgetAdapters; import org.knowm.xchange.bitget.BitgetErrorAdapter; import org.knowm.xchange.bitget.BitgetExchange; import org.knowm.xchange.bitget.dto.BitgetException; import org.knowm.xchange.bitget.dto.account.BitgetBalanceDto; +import org.knowm.xchange.bitget.service.params.BitgetFundingHistoryParams; import org.knowm.xchange.dto.account.AccountInfo; +import org.knowm.xchange.dto.account.FundingRecord; import org.knowm.xchange.dto.account.Wallet; import org.knowm.xchange.service.account.AccountService; +import org.knowm.xchange.service.trade.params.TradeHistoryParams; public class BitgetAccountService extends BitgetAccountServiceRaw implements AccountService { @@ -30,4 +35,19 @@ public AccountInfo getAccountInfo() throws IOException { } } + + @Override + public TradeHistoryParams createFundingHistoryParams() { + return BitgetFundingHistoryParams.builder().build(); + } + + + @Override + public List getFundingHistory(TradeHistoryParams params) throws IOException { + // return withdrawals and deposits combined + return Stream.of(getBitgetDepositRecords(params), getBitgetWithdrawRecords(params)) + .flatMap(List::stream) + .map(BitgetAdapters::toFundingRecord) + .collect(Collectors.toList()); + } } diff --git a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/BitgetAccountServiceRaw.java b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/BitgetAccountServiceRaw.java index 01471df4ae..a951360a77 100644 --- a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/BitgetAccountServiceRaw.java +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/BitgetAccountServiceRaw.java @@ -5,10 +5,19 @@ import org.knowm.xchange.bitget.BitgetAdapters; import org.knowm.xchange.bitget.BitgetExchange; import org.knowm.xchange.bitget.dto.account.BitgetBalanceDto; +import org.knowm.xchange.bitget.dto.account.BitgetDepositWithdrawRecordDto; import org.knowm.xchange.bitget.dto.account.BitgetMainSubTransferRecordDto; import org.knowm.xchange.bitget.dto.account.BitgetTransferRecordDto; import org.knowm.xchange.bitget.dto.account.params.BitgetMainSubTransferHistoryParams; import org.knowm.xchange.bitget.dto.account.params.BitgetTransferHistoryParams; +import org.knowm.xchange.currency.Currency; +import org.knowm.xchange.service.trade.params.TradeHistoryParamClientOid; +import org.knowm.xchange.service.trade.params.TradeHistoryParamCurrency; +import org.knowm.xchange.service.trade.params.TradeHistoryParamLimit; +import org.knowm.xchange.service.trade.params.TradeHistoryParamOrderId; +import org.knowm.xchange.service.trade.params.TradeHistoryParams; +import org.knowm.xchange.service.trade.params.TradeHistoryParamsIdSpan; +import org.knowm.xchange.service.trade.params.TradeHistoryParamsTimeSpan; public class BitgetAccountServiceRaw extends BitgetBaseService { @@ -43,4 +52,43 @@ public List getBitgetMainSubTransferRecords( } + public List getBitgetWithdrawRecords(TradeHistoryParams params) throws IOException { + // get arguments + Currency currency = params instanceof TradeHistoryParamCurrency ? ((TradeHistoryParamCurrency) params).getCurrency() : null; + String orderId = params instanceof TradeHistoryParamOrderId ? ((TradeHistoryParamOrderId) params).getOrderId() : null; + String clientOid = params instanceof TradeHistoryParamClientOid ? ((TradeHistoryParamClientOid) params).getClientOid() : null; + Integer limit = params instanceof TradeHistoryParamLimit ? ((TradeHistoryParamLimit) params).getLimit() : null; + String lastTradeId = params instanceof TradeHistoryParamsIdSpan ? ((TradeHistoryParamsIdSpan) params).getEndId() : null; + Long from = null; + Long to = null; + if (params instanceof TradeHistoryParamsTimeSpan) { + TradeHistoryParamsTimeSpan paramsTimeSpan = ((TradeHistoryParamsTimeSpan) params); + from = paramsTimeSpan.getStartTime() != null ? paramsTimeSpan.getStartTime().getTime() : null; + to = paramsTimeSpan.getEndTime() != null ? paramsTimeSpan.getEndTime().getTime() : null; + } + + return bitgetAuthenticated.withdrawalRecords(apiKey, bitgetDigest, passphrase, exchange.getNonceFactory(), + BitgetAdapters.toString(currency), limit, orderId, clientOid, from, to, lastTradeId).getData(); + } + + + public List getBitgetDepositRecords(TradeHistoryParams params) throws IOException { + // get arguments + Currency currency = params instanceof TradeHistoryParamCurrency ? ((TradeHistoryParamCurrency) params).getCurrency() : null; + String orderId = params instanceof TradeHistoryParamOrderId ? ((TradeHistoryParamOrderId) params).getOrderId() : null; + Integer limit = params instanceof TradeHistoryParamLimit ? ((TradeHistoryParamLimit) params).getLimit() : null; + String lastTradeId = params instanceof TradeHistoryParamsIdSpan ? ((TradeHistoryParamsIdSpan) params).getEndId() : null; + Long from = null; + Long to = null; + if (params instanceof TradeHistoryParamsTimeSpan) { + TradeHistoryParamsTimeSpan paramsTimeSpan = ((TradeHistoryParamsTimeSpan) params); + from = paramsTimeSpan.getStartTime() != null ? paramsTimeSpan.getStartTime().getTime() : null; + to = paramsTimeSpan.getEndTime() != null ? paramsTimeSpan.getEndTime().getTime() : null; + } + + return bitgetAuthenticated.depositRecords(apiKey, bitgetDigest, passphrase, exchange.getNonceFactory(), + BitgetAdapters.toString(currency), limit, orderId, from, to, lastTradeId).getData(); + } + + } diff --git a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/params/BitgetFundingHistoryParams.java b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/params/BitgetFundingHistoryParams.java new file mode 100644 index 0000000000..25f8aa3cce --- /dev/null +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/params/BitgetFundingHistoryParams.java @@ -0,0 +1,36 @@ +package org.knowm.xchange.bitget.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.TradeHistoryParamClientOid; +import org.knowm.xchange.service.trade.params.TradeHistoryParamCurrency; +import org.knowm.xchange.service.trade.params.TradeHistoryParamLimit; +import org.knowm.xchange.service.trade.params.TradeHistoryParamOrderId; +import org.knowm.xchange.service.trade.params.TradeHistoryParamsIdSpan; +import org.knowm.xchange.service.trade.params.TradeHistoryParamsTimeSpan; + +@Data +@Builder +public class BitgetFundingHistoryParams implements TradeHistoryParamCurrency, TradeHistoryParamLimit, + TradeHistoryParamOrderId, TradeHistoryParamsTimeSpan, TradeHistoryParamsIdSpan, + TradeHistoryParamClientOid { + + private Currency currency; + + private String orderId; + + private String clientOid; + + private Date startTime; + + private Date endTime; + + private Integer limit; + + private String startId; + + private String endId; + +} diff --git a/xchange-bitget/src/test/java/org/knowm/xchange/bitget/service/BitgetAccountServiceTest.java b/xchange-bitget/src/test/java/org/knowm/xchange/bitget/service/BitgetAccountServiceTest.java new file mode 100644 index 0000000000..1e863ed8a2 --- /dev/null +++ b/xchange-bitget/src/test/java/org/knowm/xchange/bitget/service/BitgetAccountServiceTest.java @@ -0,0 +1,45 @@ +package org.knowm.xchange.bitget.service; + +import static org.assertj.core.api.Assertions.assertThat; + +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.bitget.BitgetExchangeWiremock; +import org.knowm.xchange.bitget.service.params.BitgetFundingHistoryParams; +import org.knowm.xchange.currency.Currency; +import org.knowm.xchange.dto.account.FundingRecord; +import org.knowm.xchange.dto.account.FundingRecord.Status; +import org.knowm.xchange.dto.account.FundingRecord.Type; + +class BitgetAccountServiceTest extends BitgetExchangeWiremock { + + @Test + void funding_history() throws IOException { + List actual = exchange.getAccountService().getFundingHistory( + BitgetFundingHistoryParams.builder() + .startTime(Date.from(Instant.ofEpochMilli(1721643200000L))) + .endTime(Date.from(Instant.ofEpochMilli(1727970869665L))) + .endId("1203378295345901568") + .build()); + + FundingRecord expected = new FundingRecord.Builder() + .setInternalId("1200126632376020992") + .setDate(Date.from(Instant.ofEpochMilli(1721858437064L))) + .setAddress("EQAPOcvrl-4fjsw9W5iUBC8np6UtVgE0QPDzLgfsTJh9NYX5") + .setBlockchainTransactionHash("scWb5s8OtLL_kSE8rQv5fDvreOGUe82wcV9KXrGNNww=") + .setCurrency(Currency.USDT) + .setType(Type.DEPOSIT) + .setAmount(new BigDecimal("100.00000000")) + .setStatus(Status.COMPLETE) + .build(); + + assertThat(actual).hasSize(2); + assertThat(actual).first().usingRecursiveComparison().isEqualTo(expected); + } + + +} \ No newline at end of file diff --git a/xchange-bitget/src/test/resources/__files/api_v2_spot_wallet_deposit-records.json b/xchange-bitget/src/test/resources/__files/api_v2_spot_wallet_deposit-records.json new file mode 100644 index 0000000000..e6ec4efdbc --- /dev/null +++ b/xchange-bitget/src/test/resources/__files/api_v2_spot_wallet_deposit-records.json @@ -0,0 +1,21 @@ +{ + "code": "00000", + "msg": "success", + "requestTime": 1728492259388, + "data": [ + { + "orderId": "1200126632376020992", + "tradeId": "scWb5s8OtLL_kSE8rQv5fDvreOGUe82wcV9KXrGNNww=", + "coin": "USDT", + "type": "deposit", + "size": "100.00000000", + "status": "success", + "toAddress": "EQAPOcvrl-4fjsw9W5iUBC8np6UtVgE0QPDzLgfsTJh9NYX5", + "dest": "on_chain", + "chain": "TON(TON)", + "fromAddress": null, + "cTime": "1721858407110", + "uTime": "1721858437064" + } + ] +} \ No newline at end of file diff --git a/xchange-bitget/src/test/resources/__files/api_v2_spot_wallet_withdrawal-records.json b/xchange-bitget/src/test/resources/__files/api_v2_spot_wallet_withdrawal-records.json new file mode 100644 index 0000000000..3ceb720d67 --- /dev/null +++ b/xchange-bitget/src/test/resources/__files/api_v2_spot_wallet_withdrawal-records.json @@ -0,0 +1,25 @@ +{ + "code": "00000", + "msg": "success", + "requestTime": 1728492260621, + "data": [ + { + "orderId": "1200841097056755712", + "tradeId": "IM-ckdhPIB2PWyOESdTSA5U3o9ufyR810ECUG8Glkbw=", + "coin": "USDT", + "type": "withdraw", + "dest": "on_chain", + "size": "50.00000000", + "fee": "0.00000000", + "status": "success", + "toAddress": "EQBX63RAdgShn34EAFMV73Cut7Z15lUZd1hnVva68SEl7sxi", + "chain": "TON(TON)", + "confirm": "39292494", + "clientOid": null, + "tag": "300570", + "fromAddress": null, + "cTime": "1722028748764", + "uTime": "1722029062010" + } + ] +} \ No newline at end of file diff --git a/xchange-bitget/src/test/resources/mappings/api_v2_spot_wallet_deposit-records.json b/xchange-bitget/src/test/resources/mappings/api_v2_spot_wallet_deposit-records.json new file mode 100644 index 0000000000..6d37b2001e --- /dev/null +++ b/xchange-bitget/src/test/resources/mappings/api_v2_spot_wallet_deposit-records.json @@ -0,0 +1,15 @@ +{ + "id" : "91e2c15a-9f3e-470a-9c7f-48fac9ad545b", + "name" : "api_v2_spot_wallet_deposit-records", + "request" : { + "url" : "/api/v2/spot/wallet/deposit-records?startTime=1721643200000&endTime=1727970869665&idLessThan=1203378295345901568", + "method" : "GET" + }, + "response" : { + "status" : 200, + "bodyFileName" : "api_v2_spot_wallet_deposit-records.json" + }, + "uuid" : "91e2c15a-9f3e-470a-9c7f-48fac9ad545b", + "persistent" : true, + "insertionIndex" : 16 +} \ No newline at end of file diff --git a/xchange-bitget/src/test/resources/mappings/api_v2_spot_wallet_withdrawal-records.json b/xchange-bitget/src/test/resources/mappings/api_v2_spot_wallet_withdrawal-records.json new file mode 100644 index 0000000000..db0481f46f --- /dev/null +++ b/xchange-bitget/src/test/resources/mappings/api_v2_spot_wallet_withdrawal-records.json @@ -0,0 +1,15 @@ +{ + "id" : "f75b148c-563c-49c1-af92-71150505196b", + "name" : "api_v2_spot_wallet_withdrawal-records", + "request" : { + "url" : "/api/v2/spot/wallet/withdrawal-records?startTime=1721643200000&endTime=1727970869665&idLessThan=1203378295345901568", + "method" : "GET" + }, + "response" : { + "status" : 200, + "bodyFileName" : "api_v2_spot_wallet_withdrawal-records.json" + }, + "uuid" : "f75b148c-563c-49c1-af92-71150505196b", + "persistent" : true, + "insertionIndex" : 15 +} \ No newline at end of file diff --git a/xchange-bitget/src/test/resources/rest/spot.http b/xchange-bitget/src/test/resources/rest/spot.http index 9ffaee1093..e7b10ed317 100644 --- a/xchange-bitget/src/test/resources/rest/spot.http +++ b/xchange-bitget/src/test/resources/rest/spot.http @@ -140,3 +140,27 @@ ACCESS-TIMESTAMP: {{timestamp}} ACCESS-PASSPHRASE: {{api_passphrase}} +### Get Deposit Records +< {% + import {gen_sign} from 'sign.js' + gen_sign(request); +%} +GET {{api_host}}/api/v2/spot/wallet/deposit-records?startTime=1721643200000&endTime=1727970869665 +ACCESS-KEY: {{api_key}} +ACCESS-SIGN: {{sign}} +ACCESS-TIMESTAMP: {{timestamp}} +ACCESS-PASSPHRASE: {{api_passphrase}} + + +### Get Withdrawal Records +< {% + import {gen_sign} from 'sign.js' + gen_sign(request); +%} +GET {{api_host}}/api/v2/spot/wallet/withdrawal-records?startTime=1721643200000&endTime=1727970869665 +ACCESS-KEY: {{api_key}} +ACCESS-SIGN: {{sign}} +ACCESS-TIMESTAMP: {{timestamp}} +ACCESS-PASSPHRASE: {{api_passphrase}} + + diff --git a/xchange-core/src/main/java/org/knowm/xchange/service/trade/params/TradeHistoryParamClientOid.java b/xchange-core/src/main/java/org/knowm/xchange/service/trade/params/TradeHistoryParamClientOid.java new file mode 100644 index 0000000000..1bf27c7be7 --- /dev/null +++ b/xchange-core/src/main/java/org/knowm/xchange/service/trade/params/TradeHistoryParamClientOid.java @@ -0,0 +1,12 @@ +package org.knowm.xchange.service.trade.params; + +/** + * {@link TradeHistoryParams} with client order id as param + */ +public interface TradeHistoryParamClientOid extends TradeHistoryParams { + + String getClientOid(); + + void setClientOid(String clientOid); + +} From b2cecf7d8422806f49508613d85928c1abc7072a Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Wed, 9 Oct 2024 19:49:27 +0200 Subject: [PATCH 07/10] [bitget] Add getting of deposits-history of subaccount --- .../xchange/bitget/BitgetAuthenticated.java | 13 +++++++ .../service/BitgetAccountServiceRaw.java | 20 +++++++++++ .../params/BitgetFundingHistoryParams.java | 2 ++ .../service/BitgetAccountServiceRawTest.java | 35 +++++++++++++++++++ ...pot_wallet_subaccount-deposit-records.json | 20 +++++++++++ ...pot_wallet_subaccount-deposit-records.json | 15 ++++++++ .../src/test/resources/rest/spot.http | 24 +++++++++++++ 7 files changed, 129 insertions(+) create mode 100644 xchange-bitget/src/test/resources/__files/api_v2_spot_wallet_subaccount-deposit-records.json create mode 100644 xchange-bitget/src/test/resources/mappings/api_v2_spot_wallet_subaccount-deposit-records.json diff --git a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/BitgetAuthenticated.java b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/BitgetAuthenticated.java index 86eeaaee41..069c67f83c 100644 --- a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/BitgetAuthenticated.java +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/BitgetAuthenticated.java @@ -113,6 +113,19 @@ BitgetResponse> depositRecords( throws IOException, BitgetException; + @GET + @Path("api/v2/spot/wallet/subaccount-deposit-records") + BitgetResponse> subDepositRecords( + @HeaderParam("ACCESS-KEY") String apiKey, + @HeaderParam("ACCESS-SIGN") ParamsDigest signer, + @HeaderParam("ACCESS-PASSPHRASE") String passphrase, + @HeaderParam("ACCESS-TIMESTAMP") SynchronizedValueFactory timestamp, + @QueryParam("coin") String currency, @QueryParam("limit") Integer limit, @QueryParam("subUid") String subAccountUid, + @QueryParam("startTime") Long startTime, @QueryParam("endTime") Long endTime, + @QueryParam("idLessThan") String idLessThan) + throws IOException, BitgetException; + + @GET @Path("api/v2/spot/wallet/withdrawal-records") BitgetResponse> withdrawalRecords( diff --git a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/BitgetAccountServiceRaw.java b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/BitgetAccountServiceRaw.java index a951360a77..4c6d8e9880 100644 --- a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/BitgetAccountServiceRaw.java +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/BitgetAccountServiceRaw.java @@ -10,6 +10,7 @@ import org.knowm.xchange.bitget.dto.account.BitgetTransferRecordDto; import org.knowm.xchange.bitget.dto.account.params.BitgetMainSubTransferHistoryParams; import org.knowm.xchange.bitget.dto.account.params.BitgetTransferHistoryParams; +import org.knowm.xchange.bitget.service.params.BitgetFundingHistoryParams; import org.knowm.xchange.currency.Currency; import org.knowm.xchange.service.trade.params.TradeHistoryParamClientOid; import org.knowm.xchange.service.trade.params.TradeHistoryParamCurrency; @@ -91,4 +92,23 @@ public List getBitgetDepositRecords(TradeHistory } + public List getBitgetSubAccountDepositRecords(TradeHistoryParams params) throws IOException { + // get arguments + Currency currency = params instanceof TradeHistoryParamCurrency ? ((TradeHistoryParamCurrency) params).getCurrency() : null; + String subAccountUid = params instanceof BitgetFundingHistoryParams ? ((BitgetFundingHistoryParams) params).getSubAccountUid() : null; + Integer limit = params instanceof TradeHistoryParamLimit ? ((TradeHistoryParamLimit) params).getLimit() : null; + String lastTradeId = params instanceof TradeHistoryParamsIdSpan ? ((TradeHistoryParamsIdSpan) params).getEndId() : null; + Long from = null; + Long to = null; + if (params instanceof TradeHistoryParamsTimeSpan) { + TradeHistoryParamsTimeSpan paramsTimeSpan = ((TradeHistoryParamsTimeSpan) params); + from = paramsTimeSpan.getStartTime() != null ? paramsTimeSpan.getStartTime().getTime() : null; + to = paramsTimeSpan.getEndTime() != null ? paramsTimeSpan.getEndTime().getTime() : null; + } + + return bitgetAuthenticated.subDepositRecords(apiKey, bitgetDigest, passphrase, exchange.getNonceFactory(), + BitgetAdapters.toString(currency), limit, subAccountUid, from, to, lastTradeId).getData(); + } + + } diff --git a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/params/BitgetFundingHistoryParams.java b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/params/BitgetFundingHistoryParams.java index 25f8aa3cce..c2fa6d7e3c 100644 --- a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/params/BitgetFundingHistoryParams.java +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/params/BitgetFundingHistoryParams.java @@ -19,6 +19,8 @@ public class BitgetFundingHistoryParams implements TradeHistoryParamCurrency, Tr private Currency currency; + private String subAccountUid; + private String orderId; private String clientOid; diff --git a/xchange-bitget/src/test/java/org/knowm/xchange/bitget/service/BitgetAccountServiceRawTest.java b/xchange-bitget/src/test/java/org/knowm/xchange/bitget/service/BitgetAccountServiceRawTest.java index 0e591e51ef..02d40bdf12 100644 --- a/xchange-bitget/src/test/java/org/knowm/xchange/bitget/service/BitgetAccountServiceRawTest.java +++ b/xchange-bitget/src/test/java/org/knowm/xchange/bitget/service/BitgetAccountServiceRawTest.java @@ -6,16 +6,21 @@ 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.bitget.BitgetExchangeWiremock; import org.knowm.xchange.bitget.dto.account.BitgetAccountType; +import org.knowm.xchange.bitget.dto.account.BitgetDepositWithdrawRecordDto; +import org.knowm.xchange.bitget.dto.account.BitgetDepositWithdrawRecordDto.DepositType; import org.knowm.xchange.bitget.dto.account.BitgetMainSubTransferRecordDto; import org.knowm.xchange.bitget.dto.account.BitgetTransferRecordDto; import org.knowm.xchange.bitget.dto.account.BitgetTransferRecordDto.Status; import org.knowm.xchange.bitget.dto.account.params.BitgetMainSubTransferHistoryParams; import org.knowm.xchange.bitget.dto.account.params.BitgetMainSubTransferHistoryParams.Role; import org.knowm.xchange.bitget.dto.account.params.BitgetTransferHistoryParams; +import org.knowm.xchange.bitget.service.params.BitgetFundingHistoryParams; +import org.knowm.xchange.dto.account.FundingRecord; class BitgetAccountServiceRawTest extends BitgetExchangeWiremock { @@ -84,4 +89,34 @@ void main_sub_transfer_records() throws IOException { } + @Test + void sub_account_deposit_records() throws IOException { + BitgetDepositWithdrawRecordDto expected = BitgetDepositWithdrawRecordDto.builder() + .chain("TON(TON)") + .orderId("1227960429565849600") + .tradeId("x_8NF1B51t2lLOu-RYxl-7FOwfM4d6UgPhqlr_CAO8s=") + .currency(USDT) + .depositType(DepositType.ON_CHAIN) + .toAddress("EQCJLo0UPRm6RToIXgD0eMpoak5cuj4BTt99NYCY14yOUcoT") + .size(new BigDecimal("10.00000000")) + .status(FundingRecord.Status.COMPLETE) + .createdAt(Instant.ofEpochMilli(1728494501487L)) + .updatedAt(Instant.ofEpochMilli(1728494528012L)) + .build(); + + BitgetFundingHistoryParams params = BitgetFundingHistoryParams.builder() + .currency(USDT) + .subAccountUid("7831928986") + .startTime(Date.from(Instant.ofEpochMilli(1728494500000L))) + .endTime(Date.from(Instant.ofEpochMilli(1728494529999L))) + .limit(1) + .endId("1227960429565849609") + .build(); + List actual = bitgetAccountServiceRaw.getBitgetSubAccountDepositRecords(params); + + assertThat(actual).hasSize(1); + assertThat(actual).first().usingRecursiveComparison().isEqualTo(expected); + } + + } \ No newline at end of file diff --git a/xchange-bitget/src/test/resources/__files/api_v2_spot_wallet_subaccount-deposit-records.json b/xchange-bitget/src/test/resources/__files/api_v2_spot_wallet_subaccount-deposit-records.json new file mode 100644 index 0000000000..c98f5c65ff --- /dev/null +++ b/xchange-bitget/src/test/resources/__files/api_v2_spot_wallet_subaccount-deposit-records.json @@ -0,0 +1,20 @@ +{ + "code": "00000", + "msg": "success", + "requestTime": 1728495974426, + "data": [ + { + "orderId": "1227960429565849600", + "tradeId": "x_8NF1B51t2lLOu-RYxl-7FOwfM4d6UgPhqlr_CAO8s=", + "coin": "USDT", + "size": "10.00000000", + "status": "success", + "toAddress": "EQCJLo0UPRm6RToIXgD0eMpoak5cuj4BTt99NYCY14yOUcoT", + "dest": "on_chain", + "chain": "TON(TON)", + "fromAddress": null, + "cTime": "1728494501487", + "uTime": "1728494528012" + } + ] +} \ No newline at end of file diff --git a/xchange-bitget/src/test/resources/mappings/api_v2_spot_wallet_subaccount-deposit-records.json b/xchange-bitget/src/test/resources/mappings/api_v2_spot_wallet_subaccount-deposit-records.json new file mode 100644 index 0000000000..89caaec8ef --- /dev/null +++ b/xchange-bitget/src/test/resources/mappings/api_v2_spot_wallet_subaccount-deposit-records.json @@ -0,0 +1,15 @@ +{ + "id" : "1f65d9db-2290-402b-af6f-c27b98930ec6", + "name" : "api_v2_spot_wallet_subaccount-deposit-records", + "request" : { + "url" : "/api/v2/spot/wallet/subaccount-deposit-records?coin=USDT&limit=1&subUid=7831928986&startTime=1728494500000&endTime=1728494529999&idLessThan=1227960429565849609", + "method" : "GET" + }, + "response" : { + "status" : 200, + "bodyFileName" : "api_v2_spot_wallet_subaccount-deposit-records.json" + }, + "uuid" : "1f65d9db-2290-402b-af6f-c27b98930ec6", + "persistent" : true, + "insertionIndex" : 11 +} \ No newline at end of file diff --git a/xchange-bitget/src/test/resources/rest/spot.http b/xchange-bitget/src/test/resources/rest/spot.http index e7b10ed317..12724bf440 100644 --- a/xchange-bitget/src/test/resources/rest/spot.http +++ b/xchange-bitget/src/test/resources/rest/spot.http @@ -38,6 +38,18 @@ ACCESS-TIMESTAMP: {{timestamp}} ACCESS-PASSPHRASE: {{api_passphrase}} +### Get Sub-accounts Assets +< {% + import {gen_sign} from 'sign.js' + gen_sign(request); +%} +GET {{api_host}}/api/v2/spot/account/subaccount-assets +ACCESS-KEY: {{api_key}} +ACCESS-SIGN: {{sign}} +ACCESS-TIMESTAMP: {{timestamp}} +ACCESS-PASSPHRASE: {{api_passphrase}} + + ### Get Order Info < {% import {gen_sign} from 'sign.js' @@ -164,3 +176,15 @@ ACCESS-TIMESTAMP: {{timestamp}} ACCESS-PASSPHRASE: {{api_passphrase}} +### Get SubAccount Deposit Records +< {% + import {gen_sign} from 'sign.js' + gen_sign(request); +%} +GET {{api_host}}/api/v2/spot/wallet/subaccount-deposit-records?subUid=7831928986 +ACCESS-KEY: {{api_key}} +ACCESS-SIGN: {{sign}} +ACCESS-TIMESTAMP: {{timestamp}} +ACCESS-PASSPHRASE: {{api_passphrase}} + + From 3089550cbf4325aeb04371acf898efaa8e9ef4c6 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Thu, 10 Oct 2024 12:30:54 +0200 Subject: [PATCH 08/10] [bitget] Add filtering of balances by currency --- .../java/org/knowm/xchange/bitget/BitgetAuthenticated.java | 3 ++- .../knowm/xchange/bitget/service/BitgetAccountService.java | 2 +- .../xchange/bitget/service/BitgetAccountServiceRaw.java | 5 +++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/BitgetAuthenticated.java b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/BitgetAuthenticated.java index 069c67f83c..913f4077e1 100644 --- a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/BitgetAuthenticated.java +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/BitgetAuthenticated.java @@ -32,7 +32,8 @@ BitgetResponse> balances( @HeaderParam("ACCESS-KEY") String apiKey, @HeaderParam("ACCESS-SIGN") ParamsDigest signer, @HeaderParam("ACCESS-PASSPHRASE") String passphrase, - @HeaderParam("ACCESS-TIMESTAMP") SynchronizedValueFactory timestamp) + @HeaderParam("ACCESS-TIMESTAMP") SynchronizedValueFactory timestamp, + @QueryParam("coin") String currency) throws IOException, BitgetException; diff --git a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/BitgetAccountService.java b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/BitgetAccountService.java index 43a60bf382..e83235d92d 100644 --- a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/BitgetAccountService.java +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/BitgetAccountService.java @@ -26,7 +26,7 @@ public BitgetAccountService(BitgetExchange exchange) { @Override public AccountInfo getAccountInfo() throws IOException { try { - List spotBalances = getBitgetBalances(); + List spotBalances = getBitgetBalances(null); Wallet wallet = BitgetAdapters.toWallet(spotBalances); return new AccountInfo(wallet); diff --git a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/BitgetAccountServiceRaw.java b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/BitgetAccountServiceRaw.java index 4c6d8e9880..5b617dce44 100644 --- a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/BitgetAccountServiceRaw.java +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/BitgetAccountServiceRaw.java @@ -27,8 +27,9 @@ public BitgetAccountServiceRaw(BitgetExchange exchange) { } - public List getBitgetBalances() throws IOException { - return bitgetAuthenticated.balances(apiKey, bitgetDigest, passphrase, exchange.getNonceFactory()).getData(); + public List getBitgetBalances(Currency currency) throws IOException { + return bitgetAuthenticated.balances(apiKey, bitgetDigest, passphrase, exchange.getNonceFactory(), + BitgetAdapters.toString(currency)).getData(); } From 6f7157c23fda296fb1e79f912c6d7fe237084909 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Thu, 10 Oct 2024 13:09:23 +0200 Subject: [PATCH 09/10] [bitget] Add getting of sub-account's balances --- .../xchange/bitget/BitgetAuthenticated.java | 11 +++++++++ .../dto/account/BitgetSubBalanceDto.java | 20 ++++++++++++++++ .../service/BitgetAccountServiceRaw.java | 6 +++++ .../service/BitgetAccountServiceRawTest.java | 23 +++++++++++++++++++ ...api_v2_spot_account_subaccount-assets.json | 20 ++++++++++++++++ ...api_v2_spot_account_subaccount-assets.json | 15 ++++++++++++ 6 files changed, 95 insertions(+) create mode 100755 xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/account/BitgetSubBalanceDto.java create mode 100644 xchange-bitget/src/test/resources/__files/api_v2_spot_account_subaccount-assets.json create mode 100644 xchange-bitget/src/test/resources/mappings/api_v2_spot_account_subaccount-assets.json diff --git a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/BitgetAuthenticated.java b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/BitgetAuthenticated.java index 913f4077e1..7d7f207a03 100644 --- a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/BitgetAuthenticated.java +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/BitgetAuthenticated.java @@ -15,6 +15,7 @@ import org.knowm.xchange.bitget.dto.account.BitgetBalanceDto; import org.knowm.xchange.bitget.dto.account.BitgetDepositWithdrawRecordDto; import org.knowm.xchange.bitget.dto.account.BitgetMainSubTransferRecordDto; +import org.knowm.xchange.bitget.dto.account.BitgetSubBalanceDto; import org.knowm.xchange.bitget.dto.account.BitgetTransferRecordDto; import org.knowm.xchange.bitget.dto.trade.BitgetFillDto; import org.knowm.xchange.bitget.dto.trade.BitgetOrderInfoDto; @@ -37,6 +38,16 @@ BitgetResponse> balances( throws IOException, BitgetException; + @GET + @Path("api/v2/spot/account/subaccount-assets") + BitgetResponse> subBalances( + @HeaderParam("ACCESS-KEY") String apiKey, + @HeaderParam("ACCESS-SIGN") ParamsDigest signer, + @HeaderParam("ACCESS-PASSPHRASE") String passphrase, + @HeaderParam("ACCESS-TIMESTAMP") SynchronizedValueFactory timestamp) + throws IOException, BitgetException; + + @GET @Path("api/v2/spot/trade/orderInfo") BitgetResponse> orderInfo( diff --git a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/account/BitgetSubBalanceDto.java b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/account/BitgetSubBalanceDto.java new file mode 100755 index 0000000000..07d14beffe --- /dev/null +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/account/BitgetSubBalanceDto.java @@ -0,0 +1,20 @@ +package org.knowm.xchange.bitget.dto.account; + +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.List; +import lombok.Builder; +import lombok.Data; +import lombok.extern.jackson.Jacksonized; + +@Data +@Builder +@Jacksonized +public class BitgetSubBalanceDto { + + @JsonProperty("userId") + private String userId; + + @JsonProperty("assetsList") + private List balances; + +} diff --git a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/BitgetAccountServiceRaw.java b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/BitgetAccountServiceRaw.java index 5b617dce44..77a50d99a7 100644 --- a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/BitgetAccountServiceRaw.java +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/BitgetAccountServiceRaw.java @@ -7,6 +7,7 @@ import org.knowm.xchange.bitget.dto.account.BitgetBalanceDto; import org.knowm.xchange.bitget.dto.account.BitgetDepositWithdrawRecordDto; import org.knowm.xchange.bitget.dto.account.BitgetMainSubTransferRecordDto; +import org.knowm.xchange.bitget.dto.account.BitgetSubBalanceDto; import org.knowm.xchange.bitget.dto.account.BitgetTransferRecordDto; import org.knowm.xchange.bitget.dto.account.params.BitgetMainSubTransferHistoryParams; import org.knowm.xchange.bitget.dto.account.params.BitgetTransferHistoryParams; @@ -33,6 +34,11 @@ public List getBitgetBalances(Currency currency) throws IOExce } + public List getSubBitgetBalances() throws IOException { + return bitgetAuthenticated.subBalances(apiKey, bitgetDigest, passphrase, exchange.getNonceFactory()).getData(); + } + + public List getBitgetTransferRecords(BitgetTransferHistoryParams params) throws IOException { Long from = params.getStartTime() != null ? params.getStartTime().toEpochMilli() : null; Long to = params.getEndTime() != null ? params.getEndTime().toEpochMilli() : null; diff --git a/xchange-bitget/src/test/java/org/knowm/xchange/bitget/service/BitgetAccountServiceRawTest.java b/xchange-bitget/src/test/java/org/knowm/xchange/bitget/service/BitgetAccountServiceRawTest.java index 02d40bdf12..9a1bbba30d 100644 --- a/xchange-bitget/src/test/java/org/knowm/xchange/bitget/service/BitgetAccountServiceRawTest.java +++ b/xchange-bitget/src/test/java/org/knowm/xchange/bitget/service/BitgetAccountServiceRawTest.java @@ -6,14 +6,17 @@ import java.io.IOException; import java.math.BigDecimal; import java.time.Instant; +import java.util.Collections; import java.util.Date; import java.util.List; import org.junit.jupiter.api.Test; import org.knowm.xchange.bitget.BitgetExchangeWiremock; import org.knowm.xchange.bitget.dto.account.BitgetAccountType; +import org.knowm.xchange.bitget.dto.account.BitgetBalanceDto; import org.knowm.xchange.bitget.dto.account.BitgetDepositWithdrawRecordDto; import org.knowm.xchange.bitget.dto.account.BitgetDepositWithdrawRecordDto.DepositType; import org.knowm.xchange.bitget.dto.account.BitgetMainSubTransferRecordDto; +import org.knowm.xchange.bitget.dto.account.BitgetSubBalanceDto; import org.knowm.xchange.bitget.dto.account.BitgetTransferRecordDto; import org.knowm.xchange.bitget.dto.account.BitgetTransferRecordDto.Status; import org.knowm.xchange.bitget.dto.account.params.BitgetMainSubTransferHistoryParams; @@ -119,4 +122,24 @@ void sub_account_deposit_records() throws IOException { } + @Test + void sub_account_balances() throws IOException { + BitgetSubBalanceDto expected = BitgetSubBalanceDto.builder() + .userId("7831928986") + .balances(Collections.singletonList(BitgetBalanceDto.builder() + .currency(USDT) + .available(new BigDecimal("55.44646499")) + .limitAvailable(BigDecimal.ZERO) + .frozen(BigDecimal.ZERO) + .locked(BigDecimal.ZERO) + .build())) + .build(); + + List actual = bitgetAccountServiceRaw.getSubBitgetBalances(); + + assertThat(actual).hasSize(1); + assertThat(actual).first().usingRecursiveComparison().isEqualTo(expected); + } + + } \ No newline at end of file diff --git a/xchange-bitget/src/test/resources/__files/api_v2_spot_account_subaccount-assets.json b/xchange-bitget/src/test/resources/__files/api_v2_spot_account_subaccount-assets.json new file mode 100644 index 0000000000..a127da8461 --- /dev/null +++ b/xchange-bitget/src/test/resources/__files/api_v2_spot_account_subaccount-assets.json @@ -0,0 +1,20 @@ +{ + "code": "00000", + "msg": "success", + "requestTime": 1728557910398, + "data": [ + { + "userId": 7831928986, + "assetsList": [ + { + "coin": "USDT", + "available": "55.44646499", + "limitAvailable": "0", + "frozen": "0", + "locked": "0", + "uTime": null + } + ] + } + ] +} \ No newline at end of file diff --git a/xchange-bitget/src/test/resources/mappings/api_v2_spot_account_subaccount-assets.json b/xchange-bitget/src/test/resources/mappings/api_v2_spot_account_subaccount-assets.json new file mode 100644 index 0000000000..777e144bb7 --- /dev/null +++ b/xchange-bitget/src/test/resources/mappings/api_v2_spot_account_subaccount-assets.json @@ -0,0 +1,15 @@ +{ + "id" : "e8bb683e-fc63-4ea4-ad22-ff70537d51f3", + "name" : "api_v2_spot_account_subaccount-assets", + "request" : { + "url" : "/api/v2/spot/account/subaccount-assets", + "method" : "GET" + }, + "response" : { + "status" : 200, + "bodyFileName" : "api_v2_spot_account_subaccount-assets.json" + }, + "uuid" : "e8bb683e-fc63-4ea4-ad22-ff70537d51f3", + "persistent" : true, + "insertionIndex" : 12 +} \ No newline at end of file From 2925331701cb92fea4e932e253be9cea79b938a7 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Sun, 27 Oct 2024 17:33:57 +0100 Subject: [PATCH 10/10] [bitget] Format code --- .../java/org/knowm/xchange/bitget/Bitget.java | 9 +- .../knowm/xchange/bitget/BitgetAdapters.java | 136 ++++++------- .../xchange/bitget/BitgetAuthenticated.java | 58 +++--- .../knowm/xchange/bitget/BitgetExchange.java | 23 +-- .../StringToFundingRecordStatusConverter.java | 4 +- .../deserializer/FeeDetailDeserializer.java | 2 +- .../xchange/bitget/dto/BitgetException.java | 1 - .../xchange/bitget/dto/BitgetResponse.java | 27 ++- .../bitget/dto/account/BitgetAccountType.java | 4 +- .../bitget/dto/account/BitgetBalanceDto.java | 27 ++- .../BitgetDepositWithdrawRecordDto.java | 96 +++++---- .../BitgetMainSubTransferRecordDto.java | 61 +++--- .../dto/account/BitgetSubBalanceDto.java | 9 +- .../dto/account/BitgetTransferRecordDto.java | 61 +++--- .../BitgetMainSubTransferHistoryParams.java | 8 +- .../params/BitgetTransferHistoryParams.java | 1 - .../bitget/dto/marketdata/BitgetChainDto.java | 75 ++++--- .../bitget/dto/marketdata/BitgetCoinDto.java | 25 ++- .../dto/marketdata/BitgetMarketDepthDto.java | 1 - .../dto/marketdata/BitgetServerTime.java | 1 - .../dto/marketdata/BitgetSymbolDto.java | 94 +++++---- .../dto/marketdata/BitgetTickerDto.java | 65 +++---- .../bitget/dto/trade/BitgetFillDto.java | 114 ++++++----- .../bitget/dto/trade/BitgetOrderInfoDto.java | 183 +++++++++--------- .../bitget/dto/trade/BitgetPlaceOrderDto.java | 125 ++++++------ .../bitget/service/BitgetAccountService.java | 3 - .../service/BitgetAccountServiceRaw.java | 181 +++++++++++++---- .../bitget/service/BitgetBaseService.java | 24 ++- .../xchange/bitget/service/BitgetDigest.java | 2 - .../service/BitgetMarketDataService.java | 18 +- .../service/BitgetMarketDataServiceRaw.java | 8 - .../bitget/service/BitgetTradeService.java | 22 +-- .../bitget/service/BitgetTradeServiceRaw.java | 53 +++-- .../params/BitgetFundingHistoryParams.java | 11 +- .../params/BitgetTradeHistoryParams.java | 11 +- .../bitget/BitgetExchangeIntegration.java | 7 +- .../bitget/BitgetExchangeWiremock.java | 2 +- .../bitget/BitgetIntegrationTestParent.java | 5 +- .../BitgetAccountServiceIntegration.java | 6 +- .../service/BitgetAccountServiceRawTest.java | 176 +++++++++-------- .../service/BitgetAccountServiceTest.java | 42 ++-- .../bitget/service/BitgetDigestTest.java | 8 +- .../BitgetMarketDataServiceIntegration.java | 67 ++++--- ...BitgetMarketDataServiceRawIntegration.java | 57 +++--- .../service/BitgetTradeServiceTest.java | 61 +++--- 45 files changed, 1012 insertions(+), 962 deletions(-) diff --git a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/Bitget.java b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/Bitget.java index 2ccacc26cc..a591653fb8 100644 --- a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/Bitget.java +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/Bitget.java @@ -23,28 +23,23 @@ public interface Bitget { @Path("api/v2/public/time") BitgetResponse serverTime() throws IOException, BitgetException; - @GET @Path("api/v2/spot/public/coins") - BitgetResponse> coins(@QueryParam("coin") String coin) throws IOException, BitgetException; - + BitgetResponse> coins(@QueryParam("coin") String coin) + throws IOException, BitgetException; @GET @Path("api/v2/spot/public/symbols") BitgetResponse> symbols(@QueryParam("symbol") String symbol) throws IOException, BitgetException; - @GET @Path("api/v2/spot/market/tickers") BitgetResponse> tickers(@QueryParam("symbol") String symbol) throws IOException, BitgetException; - @GET @Path("api/v2/spot/market/orderbook") BitgetResponse orderbook(@QueryParam("symbol") String symbol) throws IOException, BitgetException; - - } diff --git a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/BitgetAdapters.java b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/BitgetAdapters.java index 0704f30738..12d3d75873 100644 --- a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/BitgetAdapters.java +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/BitgetAdapters.java @@ -47,37 +47,33 @@ public class BitgetAdapters { private final Map SYMBOL_TO_CURRENCY_PAIR = new HashMap<>(); - public CurrencyPair toCurrencyPair(String symbol) { return SYMBOL_TO_CURRENCY_PAIR.get(symbol); } - public String toString(Instrument instrument) { - return instrument == null ? null : instrument.getBase().toString() + instrument.getCounter().toString(); + return instrument == null + ? null + : instrument.getBase().toString() + instrument.getCounter().toString(); } - public String toString(Currency currency) { - return Optional.ofNullable(currency) - .map(Currency::getCurrencyCode) - .orElse(null); + return Optional.ofNullable(currency).map(Currency::getCurrencyCode).orElse(null); } - public void putSymbolMapping(String symbol, CurrencyPair currencyPair) { SYMBOL_TO_CURRENCY_PAIR.put(symbol, currencyPair); } - public InstrumentMetaData toInstrumentMetaData(BitgetSymbolDto bitgetSymbolDto) { - InstrumentMetaData.Builder builder = new InstrumentMetaData.Builder() - .tradingFee(bitgetSymbolDto.getTakerFeeRate()) - .minimumAmount(bitgetSymbolDto.getMinTradeAmount()) - .maximumAmount(bitgetSymbolDto.getMaxTradeAmount()) - .volumeScale(bitgetSymbolDto.getQuantityPrecision()) - .priceScale(bitgetSymbolDto.getPricePrecision()) - .marketOrderEnabled(bitgetSymbolDto.getStatus() == Status.ONLINE); + InstrumentMetaData.Builder builder = + new InstrumentMetaData.Builder() + .tradingFee(bitgetSymbolDto.getTakerFeeRate()) + .minimumAmount(bitgetSymbolDto.getMinTradeAmount()) + .maximumAmount(bitgetSymbolDto.getMaxTradeAmount()) + .volumeScale(bitgetSymbolDto.getQuantityPrecision()) + .priceScale(bitgetSymbolDto.getPricePrecision()) + .marketOrderEnabled(bitgetSymbolDto.getStatus() == Status.ONLINE); // set min quote amount for USDT if (bitgetSymbolDto.getCurrencyPair().getCounter().equals(Currency.USDT)) { @@ -87,7 +83,6 @@ public InstrumentMetaData toInstrumentMetaData(BitgetSymbolDto bitgetSymbolDto) return builder.build(); } - public Ticker toTicker(BitgetTickerDto bitgetTickerDto) { CurrencyPair currencyPair = toCurrencyPair(bitgetTickerDto.getSymbol()); if (currencyPair == null) { @@ -110,14 +105,10 @@ public Ticker toTicker(BitgetTickerDto bitgetTickerDto) { .build(); } - public Date toDate(Instant instant) { - return Optional.ofNullable(instant) - .map(Date::from) - .orElse(null); + return Optional.ofNullable(instant).map(Date::from).orElse(null); } - public Balance toBalance(BitgetBalanceDto balance) { return new Balance.Builder() .currency(balance.getCurrency()) @@ -127,45 +118,43 @@ public Balance toBalance(BitgetBalanceDto balance) { .build(); } - public Wallet toWallet(List bitgetBalanceDtos) { - List balances = bitgetBalanceDtos.stream() - .map(BitgetAdapters::toBalance) - .collect(Collectors.toList()); + List balances = + bitgetBalanceDtos.stream().map(BitgetAdapters::toBalance).collect(Collectors.toList()); return Wallet.Builder.from(balances).id("spot").build(); } - public OrderBook toOrderBook(BitgetMarketDepthDto bitgetMarketDepthDto, Instrument instrument) { - List asks = bitgetMarketDepthDto.getAsks().stream() - .map(priceSizeEntry -> - new LimitOrder( - OrderType.ASK, - priceSizeEntry.getSize(), - instrument, - null, - null, - priceSizeEntry.getPrice()) - ) - .collect(Collectors.toList()); - - List bids = bitgetMarketDepthDto.getBids().stream() - .map(priceSizeEntry -> - new LimitOrder( - OrderType.BID, - priceSizeEntry.getSize(), - instrument, - null, - null, - priceSizeEntry.getPrice()) - ) - .collect(Collectors.toList()); + List asks = + bitgetMarketDepthDto.getAsks().stream() + .map( + priceSizeEntry -> + new LimitOrder( + OrderType.ASK, + priceSizeEntry.getSize(), + instrument, + null, + null, + priceSizeEntry.getPrice())) + .collect(Collectors.toList()); + + List bids = + bitgetMarketDepthDto.getBids().stream() + .map( + priceSizeEntry -> + new LimitOrder( + OrderType.BID, + priceSizeEntry.getSize(), + instrument, + null, + null, + priceSizeEntry.getPrice())) + .collect(Collectors.toList()); return new OrderBook(toDate(bitgetMarketDepthDto.getTimestamp()), asks, bids); } - public Order toOrder(BitgetOrderInfoDto order) { if (order == null) { return null; @@ -181,8 +170,7 @@ public Order toOrder(BitgetOrderInfoDto order) { builder = new MarketOrder.Builder(orderType, instrument); break; case LIMIT: - builder = new LimitOrder.Builder(orderType, instrument) - .limitPrice(order.getPrice()); + builder = new LimitOrder.Builder(orderType, instrument).limitPrice(order.getPrice()); break; default: throw new IllegalArgumentException("Can't map " + order.getOrderType()); @@ -213,7 +201,6 @@ public Order toOrder(BitgetOrderInfoDto order) { .build(); } - public OrderStatus toOrderStatus(BitgetOrderStatus bitgetOrderStatus) { switch (bitgetOrderStatus) { case PENDING: @@ -229,7 +216,6 @@ public OrderStatus toOrderStatus(BitgetOrderStatus bitgetOrderStatus) { } } - public BitgetPlaceOrderDto toBitgetPlaceOrderDto(MarketOrder marketOrder) { return BitgetPlaceOrderDto.builder() .symbol(toString(marketOrder.getInstrument())) @@ -240,28 +226,28 @@ public BitgetPlaceOrderDto toBitgetPlaceOrderDto(MarketOrder marketOrder) { .build(); } - public UserTrade toUserTrade(BitgetFillDto bitgetFillDto) { - return new UserTrade(bitgetFillDto.getOrderSide(), bitgetFillDto.getAssetAmount(), toCurrencyPair(bitgetFillDto.getSymbol()), - bitgetFillDto.getPrice(), toDate(bitgetFillDto.getUpdatedAt()), bitgetFillDto.getTradeId(), bitgetFillDto.getOrderId(), - bitgetFillDto.getFeeDetail().getTotalFee().abs(), bitgetFillDto.getFeeDetail().getCurrency(), null); + return new UserTrade( + bitgetFillDto.getOrderSide(), + bitgetFillDto.getAssetAmount(), + toCurrencyPair(bitgetFillDto.getSymbol()), + bitgetFillDto.getPrice(), + toDate(bitgetFillDto.getUpdatedAt()), + bitgetFillDto.getTradeId(), + bitgetFillDto.getOrderId(), + bitgetFillDto.getFeeDetail().getTotalFee().abs(), + bitgetFillDto.getFeeDetail().getCurrency(), + null); } - - + public String toString(BitgetAccountType bitgetAccountType) { - return Optional.ofNullable(bitgetAccountType) - .map(BitgetAccountType::getValue) - .orElse(null); + return Optional.ofNullable(bitgetAccountType).map(BitgetAccountType::getValue).orElse(null); } - public String toString(BitgetMainSubTransferHistoryParams.Role role) { - return Optional.ofNullable(role) - .map(Role::getValue) - .orElse(null); + return Optional.ofNullable(role).map(Role::getValue).orElse(null); } - public FundingRecord toFundingRecord(BitgetDepositWithdrawRecordDto record) { return new FundingRecord.Builder() .setInternalId(record.getOrderId()) @@ -277,23 +263,23 @@ public FundingRecord toFundingRecord(BitgetDepositWithdrawRecordDto record) { .build(); } - public FundingRecord.Type toFundingRecordType(BitgetDepositWithdrawRecordDto record) { - if (record.getDepositType() == DepositType.ON_CHAIN && record.getType() == RecordType.WITHDRAW) { + if (record.getDepositType() == DepositType.ON_CHAIN + && record.getType() == RecordType.WITHDRAW) { return Type.WITHDRAWAL; } if (record.getDepositType() == DepositType.ON_CHAIN && record.getType() == RecordType.DEPOSIT) { return Type.DEPOSIT; } - if (record.getDepositType() == DepositType.INTERNAL_TRANSFER && record.getType() == RecordType.WITHDRAW) { + if (record.getDepositType() == DepositType.INTERNAL_TRANSFER + && record.getType() == RecordType.WITHDRAW) { return Type.INTERNAL_WITHDRAWAL; } - if (record.getDepositType() == DepositType.INTERNAL_TRANSFER && record.getType() == RecordType.DEPOSIT) { + if (record.getDepositType() == DepositType.INTERNAL_TRANSFER + && record.getType() == RecordType.DEPOSIT) { return Type.INTERNAL_DEPOSIT; } return null; } - - } diff --git a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/BitgetAuthenticated.java b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/BitgetAuthenticated.java index 7d7f207a03..f128c0fffd 100644 --- a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/BitgetAuthenticated.java +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/BitgetAuthenticated.java @@ -37,7 +37,6 @@ BitgetResponse> balances( @QueryParam("coin") String currency) throws IOException, BitgetException; - @GET @Path("api/v2/spot/account/subaccount-assets") BitgetResponse> subBalances( @@ -47,7 +46,6 @@ BitgetResponse> subBalances( @HeaderParam("ACCESS-TIMESTAMP") SynchronizedValueFactory timestamp) throws IOException, BitgetException; - @GET @Path("api/v2/spot/trade/orderInfo") BitgetResponse> orderInfo( @@ -58,7 +56,6 @@ BitgetResponse> orderInfo( @QueryParam("orderId") String orderId) throws IOException, BitgetException; - @POST @Path("api/v2/spot/trade/place-order") @Consumes(MediaType.APPLICATION_JSON) @@ -70,7 +67,6 @@ BitgetResponse createOrder( BitgetPlaceOrderDto bitgetPlaceOrderDto) throws IOException, BitgetException; - @GET @Path("api/v2/spot/trade/fills") BitgetResponse> fills( @@ -78,12 +74,14 @@ BitgetResponse> fills( @HeaderParam("ACCESS-SIGN") ParamsDigest signer, @HeaderParam("ACCESS-PASSPHRASE") String passphrase, @HeaderParam("ACCESS-TIMESTAMP") SynchronizedValueFactory timestamp, - @QueryParam("symbol") String symbol, @QueryParam("limit") Integer limit, @QueryParam("orderId") String orderId, - @QueryParam("startTime") Long startTime, @QueryParam("endTime") Long endTime, + @QueryParam("symbol") String symbol, + @QueryParam("limit") Integer limit, + @QueryParam("orderId") String orderId, + @QueryParam("startTime") Long startTime, + @QueryParam("endTime") Long endTime, @QueryParam("idLessThan") String idLessThan) throws IOException, BitgetException; - @GET @Path("api/v2/spot/account/transferRecords") BitgetResponse> transferRecords( @@ -91,13 +89,15 @@ BitgetResponse> transferRecords( @HeaderParam("ACCESS-SIGN") ParamsDigest signer, @HeaderParam("ACCESS-PASSPHRASE") String passphrase, @HeaderParam("ACCESS-TIMESTAMP") SynchronizedValueFactory timestamp, - @QueryParam("coin") String currency, @QueryParam("limit") Integer limit, @QueryParam("clientOid") String clientOid, + @QueryParam("coin") String currency, + @QueryParam("limit") Integer limit, + @QueryParam("clientOid") String clientOid, @QueryParam("fromType") String fromType, - @QueryParam("startTime") Long startTime, @QueryParam("endTime") Long endTime, + @QueryParam("startTime") Long startTime, + @QueryParam("endTime") Long endTime, @QueryParam("idLessThan") String idLessThan) throws IOException, BitgetException; - @GET @Path("api/v2/spot/account/sub-main-trans-record") BitgetResponse> mainSubTransferRecords( @@ -105,13 +105,16 @@ BitgetResponse> mainSubTransferRecords( @HeaderParam("ACCESS-SIGN") ParamsDigest signer, @HeaderParam("ACCESS-PASSPHRASE") String passphrase, @HeaderParam("ACCESS-TIMESTAMP") SynchronizedValueFactory timestamp, - @QueryParam("coin") String currency, @QueryParam("limit") Integer limit, @QueryParam("clientOid") String clientOid, - @QueryParam("role") String role, @QueryParam("subUid") String subAccountUid, - @QueryParam("startTime") Long startTime, @QueryParam("endTime") Long endTime, + @QueryParam("coin") String currency, + @QueryParam("limit") Integer limit, + @QueryParam("clientOid") String clientOid, + @QueryParam("role") String role, + @QueryParam("subUid") String subAccountUid, + @QueryParam("startTime") Long startTime, + @QueryParam("endTime") Long endTime, @QueryParam("idLessThan") String idLessThan) throws IOException, BitgetException; - @GET @Path("api/v2/spot/wallet/deposit-records") BitgetResponse> depositRecords( @@ -119,12 +122,14 @@ BitgetResponse> depositRecords( @HeaderParam("ACCESS-SIGN") ParamsDigest signer, @HeaderParam("ACCESS-PASSPHRASE") String passphrase, @HeaderParam("ACCESS-TIMESTAMP") SynchronizedValueFactory timestamp, - @QueryParam("coin") String currency, @QueryParam("limit") Integer limit, @QueryParam("orderId") String orderId, - @QueryParam("startTime") Long startTime, @QueryParam("endTime") Long endTime, + @QueryParam("coin") String currency, + @QueryParam("limit") Integer limit, + @QueryParam("orderId") String orderId, + @QueryParam("startTime") Long startTime, + @QueryParam("endTime") Long endTime, @QueryParam("idLessThan") String idLessThan) throws IOException, BitgetException; - @GET @Path("api/v2/spot/wallet/subaccount-deposit-records") BitgetResponse> subDepositRecords( @@ -132,12 +137,14 @@ BitgetResponse> subDepositRecords( @HeaderParam("ACCESS-SIGN") ParamsDigest signer, @HeaderParam("ACCESS-PASSPHRASE") String passphrase, @HeaderParam("ACCESS-TIMESTAMP") SynchronizedValueFactory timestamp, - @QueryParam("coin") String currency, @QueryParam("limit") Integer limit, @QueryParam("subUid") String subAccountUid, - @QueryParam("startTime") Long startTime, @QueryParam("endTime") Long endTime, + @QueryParam("coin") String currency, + @QueryParam("limit") Integer limit, + @QueryParam("subUid") String subAccountUid, + @QueryParam("startTime") Long startTime, + @QueryParam("endTime") Long endTime, @QueryParam("idLessThan") String idLessThan) throws IOException, BitgetException; - @GET @Path("api/v2/spot/wallet/withdrawal-records") BitgetResponse> withdrawalRecords( @@ -145,11 +152,12 @@ BitgetResponse> withdrawalRecords( @HeaderParam("ACCESS-SIGN") ParamsDigest signer, @HeaderParam("ACCESS-PASSPHRASE") String passphrase, @HeaderParam("ACCESS-TIMESTAMP") SynchronizedValueFactory timestamp, - @QueryParam("coin") String currency, @QueryParam("limit") Integer limit, - @QueryParam("orderId") String orderId, @QueryParam("clientOid") String clientOid, - @QueryParam("startTime") Long startTime, @QueryParam("endTime") Long endTime, + @QueryParam("coin") String currency, + @QueryParam("limit") Integer limit, + @QueryParam("orderId") String orderId, + @QueryParam("clientOid") String clientOid, + @QueryParam("startTime") Long startTime, + @QueryParam("endTime") Long endTime, @QueryParam("idLessThan") String idLessThan) throws IOException, BitgetException; - - } diff --git a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/BitgetExchange.java b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/BitgetExchange.java index b7f3ce80ac..0446fb285d 100644 --- a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/BitgetExchange.java +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/BitgetExchange.java @@ -35,23 +35,24 @@ public ExchangeSpecification getDefaultExchangeSpecification() { @Override public void remoteInit() throws IOException { - BitgetMarketDataServiceRaw bitgetMarketDataServiceRaw = (BitgetMarketDataServiceRaw) marketDataService; + BitgetMarketDataServiceRaw bitgetMarketDataServiceRaw = + (BitgetMarketDataServiceRaw) marketDataService; // initialize symbol mappings List bitgetSymbolDtos = bitgetMarketDataServiceRaw.getBitgetSymbolDtos(null); - bitgetSymbolDtos.forEach(bitgetSymbolDto -> { - BitgetAdapters.putSymbolMapping(bitgetSymbolDto.getSymbol(), bitgetSymbolDto.getCurrencyPair()); - }); - + bitgetSymbolDtos.forEach( + bitgetSymbolDto -> { + BitgetAdapters.putSymbolMapping( + bitgetSymbolDto.getSymbol(), bitgetSymbolDto.getCurrencyPair()); + }); // initialize instrument metadata - Map instruments = bitgetSymbolDtos.stream() - .collect(Collectors.toMap( - BitgetSymbolDto::getCurrencyPair, - BitgetAdapters::toInstrumentMetaData) - ); + Map instruments = + bitgetSymbolDtos.stream() + .collect( + Collectors.toMap( + BitgetSymbolDto::getCurrencyPair, BitgetAdapters::toInstrumentMetaData)); exchangeMetaData = new ExchangeMetaData(instruments, null, null, null, null); - } } diff --git a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/config/converter/StringToFundingRecordStatusConverter.java b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/config/converter/StringToFundingRecordStatusConverter.java index 35ae19b4c0..6ad29f0b76 100644 --- a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/config/converter/StringToFundingRecordStatusConverter.java +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/config/converter/StringToFundingRecordStatusConverter.java @@ -4,9 +4,7 @@ import java.util.Locale; import org.knowm.xchange.dto.account.FundingRecord.Status; -/** - * Converts string to {@code FundingRecord.Status} - */ +/** Converts string to {@code FundingRecord.Status} */ public class StringToFundingRecordStatusConverter extends StdConverter { @Override diff --git a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/config/deserializer/FeeDetailDeserializer.java b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/config/deserializer/FeeDetailDeserializer.java index 4628bd65e4..ed13e35df4 100644 --- a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/config/deserializer/FeeDetailDeserializer.java +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/config/deserializer/FeeDetailDeserializer.java @@ -16,4 +16,4 @@ public FeeDetail deserialize(JsonParser p, DeserializationContext ctxt) throws I return objectMapper.readValue(text, FeeDetail.class); } -} \ No newline at end of file +} diff --git a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/BitgetException.java b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/BitgetException.java index 34d33813bd..18fe54a3e1 100644 --- a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/BitgetException.java +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/BitgetException.java @@ -22,5 +22,4 @@ public class BitgetException extends RuntimeException { @JsonProperty("data") Object data; - } diff --git a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/BitgetResponse.java b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/BitgetResponse.java index 82f44b7677..21d0e6eee3 100755 --- a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/BitgetResponse.java +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/BitgetResponse.java @@ -12,23 +12,22 @@ @Jacksonized public class BitgetResponse { - @JsonProperty("code") - private Integer code; + @JsonProperty("code") + private Integer code; - @JsonProperty("msg") - private String message; + @JsonProperty("msg") + private String message; - @JsonProperty("requestTime") - private Instant requestTime; + @JsonProperty("requestTime") + private Instant requestTime; - @JsonProperty("data") - private T data; + @JsonProperty("data") + private T data; - public void setCode(Integer code) { - if (code != 0) { - throw new ExceptionalReturnContentException(String.valueOf(code)); - } - this.code = code; + public void setCode(Integer code) { + if (code != 0) { + throw new ExceptionalReturnContentException(String.valueOf(code)); } - + this.code = code; + } } diff --git a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/account/BitgetAccountType.java b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/account/BitgetAccountType.java index 9d39db1857..7ee2a4a9bd 100644 --- a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/account/BitgetAccountType.java +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/account/BitgetAccountType.java @@ -15,7 +15,5 @@ public enum BitgetAccountType { CROSSED_MARGIN("crossed_margin"), ISOLATED_MARGIN("isolated_margin"); - @JsonValue - private final String value; - + @JsonValue private final String value; } diff --git a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/account/BitgetBalanceDto.java b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/account/BitgetBalanceDto.java index 5e4813d3dd..75625eac27 100755 --- a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/account/BitgetBalanceDto.java +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/account/BitgetBalanceDto.java @@ -15,23 +15,22 @@ @Jacksonized public class BitgetBalanceDto { - @JsonProperty("coin") - @JsonDeserialize(converter = StringToCurrencyConverter.class) - private Currency currency; + @JsonProperty("coin") + @JsonDeserialize(converter = StringToCurrencyConverter.class) + private Currency currency; - @JsonProperty("available") - private BigDecimal available; + @JsonProperty("available") + private BigDecimal available; - @JsonProperty("frozen") - private BigDecimal frozen; + @JsonProperty("frozen") + private BigDecimal frozen; - @JsonProperty("locked") - private BigDecimal locked; + @JsonProperty("locked") + private BigDecimal locked; - @JsonProperty("limitAvailable") - private BigDecimal limitAvailable; - - @JsonProperty("uTime") - private Instant timestamp; + @JsonProperty("limitAvailable") + private BigDecimal limitAvailable; + @JsonProperty("uTime") + private Instant timestamp; } diff --git a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/account/BitgetDepositWithdrawRecordDto.java b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/account/BitgetDepositWithdrawRecordDto.java index 07fbf9ec8f..5a91429df6 100755 --- a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/account/BitgetDepositWithdrawRecordDto.java +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/account/BitgetDepositWithdrawRecordDto.java @@ -17,73 +17,69 @@ @Jacksonized public class BitgetDepositWithdrawRecordDto { - @JsonProperty("orderId") - private String orderId; + @JsonProperty("orderId") + private String orderId; - @JsonProperty("tradeId") - private String tradeId; + @JsonProperty("tradeId") + private String tradeId; - @JsonProperty("coin") - @JsonDeserialize(converter = StringToCurrencyConverter.class) - private Currency currency; + @JsonProperty("coin") + @JsonDeserialize(converter = StringToCurrencyConverter.class) + private Currency currency; - @JsonProperty("clientOid") - private String clientOid; + @JsonProperty("clientOid") + private String clientOid; - @JsonProperty("type") - private RecordType type; + @JsonProperty("type") + private RecordType type; - @JsonProperty("dest") - private DepositType depositType; + @JsonProperty("dest") + private DepositType depositType; - @JsonProperty("size") - private BigDecimal size; + @JsonProperty("size") + private BigDecimal size; - @JsonProperty("fee") - private BigDecimal fee; + @JsonProperty("fee") + private BigDecimal fee; - @JsonProperty("status") - @JsonDeserialize(converter = StringToFundingRecordStatusConverter.class) - private Status status; + @JsonProperty("status") + @JsonDeserialize(converter = StringToFundingRecordStatusConverter.class) + private Status status; - @JsonProperty("fromAddress") - private String fromAddress; + @JsonProperty("fromAddress") + private String fromAddress; - @JsonProperty("toAddress") - private String toAddress; + @JsonProperty("toAddress") + private String toAddress; - @JsonProperty("chain") - private String chain; + @JsonProperty("chain") + private String chain; - @JsonProperty("confirm") - private Integer confirmCount; + @JsonProperty("confirm") + private Integer confirmCount; - @JsonProperty("tag") - private String toAddressTag; + @JsonProperty("tag") + private String toAddressTag; - @JsonProperty("cTime") - private Instant createdAt; + @JsonProperty("cTime") + private Instant createdAt; - @JsonProperty("uTime") - private Instant updatedAt; + @JsonProperty("uTime") + private Instant updatedAt; + public static enum RecordType { + @JsonProperty("withdraw") + WITHDRAW, - public static enum RecordType { - @JsonProperty("withdraw") - WITHDRAW, - - @JsonProperty("deposit") - DEPOSIT - } - - - public static enum DepositType { - @JsonProperty("on_chain") - ON_CHAIN, - - @JsonProperty("internal_transfer") - INTERNAL_TRANSFER - } + @JsonProperty("deposit") + DEPOSIT + } + public static enum DepositType { + @JsonProperty("on_chain") + ON_CHAIN, + @JsonProperty("internal_transfer") + INTERNAL_TRANSFER + } } diff --git a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/account/BitgetMainSubTransferRecordDto.java b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/account/BitgetMainSubTransferRecordDto.java index e7a1cffc40..6c66adb035 100755 --- a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/account/BitgetMainSubTransferRecordDto.java +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/account/BitgetMainSubTransferRecordDto.java @@ -15,48 +15,45 @@ @Jacksonized public class BitgetMainSubTransferRecordDto { - @JsonProperty("clientOid") - private String clientOid; + @JsonProperty("clientOid") + private String clientOid; - @JsonProperty("transferId") - private String transferId; + @JsonProperty("transferId") + private String transferId; - @JsonProperty("coin") - @JsonDeserialize(converter = StringToCurrencyConverter.class) - private Currency currency; + @JsonProperty("coin") + @JsonDeserialize(converter = StringToCurrencyConverter.class) + private Currency currency; - @JsonProperty("status") - private Status status; + @JsonProperty("status") + private Status status; - @JsonProperty("toType") - private BitgetAccountType toAccountType; + @JsonProperty("toType") + private BitgetAccountType toAccountType; - @JsonProperty("fromType") - private BitgetAccountType fromAccountType; + @JsonProperty("fromType") + private BitgetAccountType fromAccountType; - @JsonProperty("size") - private BigDecimal size; + @JsonProperty("size") + private BigDecimal size; - @JsonProperty("ts") - private Instant timestamp; + @JsonProperty("ts") + private Instant timestamp; - @JsonProperty("fromUserId") - private String fromUserId; + @JsonProperty("fromUserId") + private String fromUserId; - @JsonProperty("toUserId") - private String toUserId; + @JsonProperty("toUserId") + private String toUserId; + public static enum Status { + @JsonProperty("Successful") + SUCCESSFUL, - public static enum Status { - @JsonProperty("Successful") - SUCCESSFUL, - - @JsonProperty("Processing") - PROCESSING, - - @JsonProperty("Failed") - FAILED - } - + @JsonProperty("Processing") + PROCESSING, + @JsonProperty("Failed") + FAILED + } } diff --git a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/account/BitgetSubBalanceDto.java b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/account/BitgetSubBalanceDto.java index 07d14beffe..efa75434cf 100755 --- a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/account/BitgetSubBalanceDto.java +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/account/BitgetSubBalanceDto.java @@ -11,10 +11,9 @@ @Jacksonized public class BitgetSubBalanceDto { - @JsonProperty("userId") - private String userId; - - @JsonProperty("assetsList") - private List balances; + @JsonProperty("userId") + private String userId; + @JsonProperty("assetsList") + private List balances; } diff --git a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/account/BitgetTransferRecordDto.java b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/account/BitgetTransferRecordDto.java index cce4159007..0ff31c41d3 100755 --- a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/account/BitgetTransferRecordDto.java +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/account/BitgetTransferRecordDto.java @@ -15,48 +15,45 @@ @Jacksonized public class BitgetTransferRecordDto { - @JsonProperty("clientOid") - private String clientOid; + @JsonProperty("clientOid") + private String clientOid; - @JsonProperty("transferId") - private String transferId; + @JsonProperty("transferId") + private String transferId; - @JsonProperty("coin") - @JsonDeserialize(converter = StringToCurrencyConverter.class) - private Currency currency; + @JsonProperty("coin") + @JsonDeserialize(converter = StringToCurrencyConverter.class) + private Currency currency; - @JsonProperty("status") - private Status status; + @JsonProperty("status") + private Status status; - @JsonProperty("toType") - private BitgetAccountType toAccountType; + @JsonProperty("toType") + private BitgetAccountType toAccountType; - @JsonProperty("toSymbol") - private String toSymbol; + @JsonProperty("toSymbol") + private String toSymbol; - @JsonProperty("fromType") - private BitgetAccountType fromAccountType; + @JsonProperty("fromType") + private BitgetAccountType fromAccountType; - @JsonProperty("fromSymbol") - private String fromSymbol; + @JsonProperty("fromSymbol") + private String fromSymbol; - @JsonProperty("size") - private BigDecimal size; + @JsonProperty("size") + private BigDecimal size; - @JsonProperty("ts") - private Instant timestamp; + @JsonProperty("ts") + private Instant timestamp; + public static enum Status { + @JsonProperty("Successful") + SUCCESSFUL, - public static enum Status { - @JsonProperty("Successful") - SUCCESSFUL, - - @JsonProperty("Processing") - PROCESSING, - - @JsonProperty("Failed") - FAILED - } - + @JsonProperty("Processing") + PROCESSING, + @JsonProperty("Failed") + FAILED + } } diff --git a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/account/params/BitgetMainSubTransferHistoryParams.java b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/account/params/BitgetMainSubTransferHistoryParams.java index 4ab3faca46..bcea573f37 100644 --- a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/account/params/BitgetMainSubTransferHistoryParams.java +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/account/params/BitgetMainSubTransferHistoryParams.java @@ -29,7 +29,6 @@ public class BitgetMainSubTransferHistoryParams { private String endId; - @Getter @AllArgsConstructor public static enum Role { @@ -38,9 +37,6 @@ public static enum Role { @JsonProperty RECEIVER("receiver"); - @JsonValue - private final String value; - - } - + @JsonValue private final String value; + } } diff --git a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/account/params/BitgetTransferHistoryParams.java b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/account/params/BitgetTransferHistoryParams.java index f89d23f755..c45f75cf1b 100644 --- a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/account/params/BitgetTransferHistoryParams.java +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/account/params/BitgetTransferHistoryParams.java @@ -23,5 +23,4 @@ public class BitgetTransferHistoryParams { private Integer limit; private String endId; - } diff --git a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/marketdata/BitgetChainDto.java b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/marketdata/BitgetChainDto.java index 62139145de..ea1dcc33c7 100755 --- a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/marketdata/BitgetChainDto.java +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/marketdata/BitgetChainDto.java @@ -11,59 +11,56 @@ @Jacksonized public class BitgetChainDto { - @JsonProperty("chain") - private String chain; + @JsonProperty("chain") + private String chain; - @JsonProperty("needTag") - private Boolean needTag; + @JsonProperty("needTag") + private Boolean needTag; - @JsonProperty("withdrawable") - private Boolean isWithdrawEnabled; + @JsonProperty("withdrawable") + private Boolean isWithdrawEnabled; - @JsonProperty("rechargeable") - private Boolean isDepositEnabled; + @JsonProperty("rechargeable") + private Boolean isDepositEnabled; - @JsonProperty("withdrawFee") - private BigDecimal withdrawFee; + @JsonProperty("withdrawFee") + private BigDecimal withdrawFee; - @JsonProperty("extraWithdrawFee") - private BigDecimal extraWithdrawFee; + @JsonProperty("extraWithdrawFee") + private BigDecimal extraWithdrawFee; - @JsonProperty("depositConfirm") - private Integer depositConfirmBlockCount; + @JsonProperty("depositConfirm") + private Integer depositConfirmBlockCount; - @JsonProperty("withdrawConfirm") - private Integer withdrawConfirmBlockCount; + @JsonProperty("withdrawConfirm") + private Integer withdrawConfirmBlockCount; - @JsonProperty("minDepositAmount") - private BigDecimal minDepositAmount; + @JsonProperty("minDepositAmount") + private BigDecimal minDepositAmount; - @JsonProperty("minWithdrawAmount") - private BigDecimal minWithdrawAmount; + @JsonProperty("minWithdrawAmount") + private BigDecimal minWithdrawAmount; - @JsonProperty("browserUrl") - private String browserUrl; + @JsonProperty("browserUrl") + private String browserUrl; - @JsonProperty("contractAddress") - private String contractAddress; + @JsonProperty("contractAddress") + private String contractAddress; - @JsonProperty("withdrawStep") - private Integer withdrawStep; + @JsonProperty("withdrawStep") + private Integer withdrawStep; - @JsonProperty("withdrawMinScale") - private Integer withdrawMinScale; + @JsonProperty("withdrawMinScale") + private Integer withdrawMinScale; - @JsonProperty("congestion") - private Congestion congestion; + @JsonProperty("congestion") + private Congestion congestion; + public static enum Congestion { + @JsonProperty("normal") + NORMAL, - public static enum Congestion { - @JsonProperty("normal") - NORMAL, - - @JsonProperty("congested") - CONGESTED; - } - + @JsonProperty("congested") + CONGESTED; + } } - diff --git a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/marketdata/BitgetCoinDto.java b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/marketdata/BitgetCoinDto.java index 60217f85ae..9601b6e41f 100755 --- a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/marketdata/BitgetCoinDto.java +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/marketdata/BitgetCoinDto.java @@ -15,21 +15,20 @@ @Jacksonized public class BitgetCoinDto { - @JsonProperty("coinId") - private String coinId; + @JsonProperty("coinId") + private String coinId; - @JsonProperty("coin") - @JsonDeserialize(converter = StringToCurrencyConverter.class) - private Currency currency; + @JsonProperty("coin") + @JsonDeserialize(converter = StringToCurrencyConverter.class) + private Currency currency; - @JsonProperty("transfer") - private Boolean canTransfer; + @JsonProperty("transfer") + private Boolean canTransfer; - @JsonProperty("areaCoin") - @JsonDeserialize(converter = StringToBooleanConverter.class) - private Boolean isAreaCoin; - - @JsonProperty("chains") - private List chains; + @JsonProperty("areaCoin") + @JsonDeserialize(converter = StringToBooleanConverter.class) + private Boolean isAreaCoin; + @JsonProperty("chains") + private List chains; } diff --git a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/marketdata/BitgetMarketDepthDto.java b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/marketdata/BitgetMarketDepthDto.java index 17746d1e79..733861d1cd 100644 --- a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/marketdata/BitgetMarketDepthDto.java +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/marketdata/BitgetMarketDepthDto.java @@ -23,7 +23,6 @@ public class BitgetMarketDepthDto { @JsonProperty("ts") Instant timestamp; - @Data @Builder @Jacksonized diff --git a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/marketdata/BitgetServerTime.java b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/marketdata/BitgetServerTime.java index 6af7180261..bd21a6f138 100644 --- a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/marketdata/BitgetServerTime.java +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/marketdata/BitgetServerTime.java @@ -13,5 +13,4 @@ public class BitgetServerTime { @JsonProperty("serverTime") private Instant serverTime; - } diff --git a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/marketdata/BitgetSymbolDto.java b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/marketdata/BitgetSymbolDto.java index da353d48c2..05179ccfcb 100755 --- a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/marketdata/BitgetSymbolDto.java +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/marketdata/BitgetSymbolDto.java @@ -16,71 +16,69 @@ @Jacksonized public class BitgetSymbolDto { - @JsonProperty("symbol") - private String symbol; + @JsonProperty("symbol") + private String symbol; - @JsonProperty("baseCoin") - @JsonDeserialize(converter = StringToCurrencyConverter.class) - private Currency base; + @JsonProperty("baseCoin") + @JsonDeserialize(converter = StringToCurrencyConverter.class) + private Currency base; - @JsonProperty("quoteCoin") - @JsonDeserialize(converter = StringToCurrencyConverter.class) - private Currency quote; + @JsonProperty("quoteCoin") + @JsonDeserialize(converter = StringToCurrencyConverter.class) + private Currency quote; - @JsonProperty("minTradeAmount") - private BigDecimal minTradeAmount; + @JsonProperty("minTradeAmount") + private BigDecimal minTradeAmount; - @JsonProperty("maxTradeAmount") - private BigDecimal maxTradeAmount; + @JsonProperty("maxTradeAmount") + private BigDecimal maxTradeAmount; - @JsonProperty("takerFeeRate") - private BigDecimal takerFeeRate; + @JsonProperty("takerFeeRate") + private BigDecimal takerFeeRate; - @JsonProperty("makerFeeRate") - private BigDecimal makerFeeRate; + @JsonProperty("makerFeeRate") + private BigDecimal makerFeeRate; - @JsonProperty("pricePrecision") - private Integer pricePrecision; + @JsonProperty("pricePrecision") + private Integer pricePrecision; - @JsonProperty("quantityPrecision") - private Integer quantityPrecision; + @JsonProperty("quantityPrecision") + private Integer quantityPrecision; - @JsonProperty("quotePrecision") - private Integer quotePrecision; + @JsonProperty("quotePrecision") + private Integer quotePrecision; - @JsonProperty("status") - private Status status; + @JsonProperty("status") + private Status status; - @JsonProperty("minTradeUSDT") - private BigDecimal minTradeUSDT; + @JsonProperty("minTradeUSDT") + private BigDecimal minTradeUSDT; - @JsonProperty("buyLimitPriceRatio") - private BigDecimal buyLimitPriceRatio; + @JsonProperty("buyLimitPriceRatio") + private BigDecimal buyLimitPriceRatio; - @JsonProperty("sellLimitPriceRatio") - private BigDecimal sellLimitPriceRatio; + @JsonProperty("sellLimitPriceRatio") + private BigDecimal sellLimitPriceRatio; - @JsonProperty("areaSymbol") - @JsonDeserialize(converter = StringToBooleanConverter.class) - private Boolean isAreaSymbol; + @JsonProperty("areaSymbol") + @JsonDeserialize(converter = StringToBooleanConverter.class) + private Boolean isAreaSymbol; + public CurrencyPair getCurrencyPair() { + return new CurrencyPair(base, quote); + } - public CurrencyPair getCurrencyPair() { - return new CurrencyPair(base, quote); - } + public static enum Status { + @JsonProperty("offline") + OFFLINE, + @JsonProperty("gray") + GRAY, - public static enum Status { - @JsonProperty("offline") - OFFLINE, + @JsonProperty("online") + ONLINE, - @JsonProperty("gray") - GRAY, - - @JsonProperty("online") - ONLINE, - - @JsonProperty("halt") - HALT - } + @JsonProperty("halt") + HALT + } } diff --git a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/marketdata/BitgetTickerDto.java b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/marketdata/BitgetTickerDto.java index 2fd05042b3..6e1c354da2 100755 --- a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/marketdata/BitgetTickerDto.java +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/marketdata/BitgetTickerDto.java @@ -12,52 +12,51 @@ @Jacksonized public class BitgetTickerDto { - @JsonProperty("symbol") - private String symbol; + @JsonProperty("symbol") + private String symbol; - @JsonProperty("high24h") - private BigDecimal high24h; + @JsonProperty("high24h") + private BigDecimal high24h; - @JsonProperty("open") - private BigDecimal open24h; + @JsonProperty("open") + private BigDecimal open24h; - @JsonProperty("lastPr") - private BigDecimal lastPrice; + @JsonProperty("lastPr") + private BigDecimal lastPrice; - @JsonProperty("low24h") - private BigDecimal low24h; + @JsonProperty("low24h") + private BigDecimal low24h; - @JsonProperty("quoteVolume") - private BigDecimal quoteVolume24h; + @JsonProperty("quoteVolume") + private BigDecimal quoteVolume24h; - @JsonProperty("baseVolume") - private BigDecimal assetVolume24h; + @JsonProperty("baseVolume") + private BigDecimal assetVolume24h; - @JsonProperty("usdtVolume") - private BigDecimal usdtVolume24h; + @JsonProperty("usdtVolume") + private BigDecimal usdtVolume24h; - @JsonProperty("bidPr") - private BigDecimal bestBidPrice; + @JsonProperty("bidPr") + private BigDecimal bestBidPrice; - @JsonProperty("bidSz") - private BigDecimal bestBidSize; + @JsonProperty("bidSz") + private BigDecimal bestBidSize; - @JsonProperty("askPr") - private BigDecimal bestAskPrice; + @JsonProperty("askPr") + private BigDecimal bestAskPrice; - @JsonProperty("askSz") - private BigDecimal bestAskSize; + @JsonProperty("askSz") + private BigDecimal bestAskSize; - @JsonProperty("openUtc") - private BigDecimal openUtc; + @JsonProperty("openUtc") + private BigDecimal openUtc; - @JsonProperty("ts") - private Instant timestamp; + @JsonProperty("ts") + private Instant timestamp; - @JsonProperty("changeUtc24h") - private BigDecimal changeUtc24h; - - @JsonProperty("change24h") - private BigDecimal change24h; + @JsonProperty("changeUtc24h") + private BigDecimal changeUtc24h; + @JsonProperty("change24h") + private BigDecimal change24h; } diff --git a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/trade/BitgetFillDto.java b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/trade/BitgetFillDto.java index e7874aa61e..4728dee134 100755 --- a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/trade/BitgetFillDto.java +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/trade/BitgetFillDto.java @@ -18,85 +18,79 @@ @Jacksonized public class BitgetFillDto { - @JsonProperty("userId") - private String acccountId; + @JsonProperty("userId") + private String acccountId; - @JsonProperty("symbol") - private String symbol; + @JsonProperty("symbol") + private String symbol; - @JsonProperty("orderId") - private String orderId; + @JsonProperty("orderId") + private String orderId; - @JsonProperty("tradeId") - private String tradeId; + @JsonProperty("tradeId") + private String tradeId; - @JsonProperty("orderType") - private OrderType orderType; + @JsonProperty("orderType") + private OrderType orderType; - @JsonProperty("side") - @JsonDeserialize(converter = StringToOrderTypeConverter.class) - private Order.OrderType orderSide; + @JsonProperty("side") + @JsonDeserialize(converter = StringToOrderTypeConverter.class) + private Order.OrderType orderSide; - @JsonProperty("priceAvg") - private BigDecimal price; + @JsonProperty("priceAvg") + private BigDecimal price; - @JsonProperty("size") - private BigDecimal assetAmount; + @JsonProperty("size") + private BigDecimal assetAmount; - @JsonProperty("amount") - private BigDecimal quoteAmount; + @JsonProperty("amount") + private BigDecimal quoteAmount; - @JsonProperty("feeDetail") - private FeeDetail feeDetail; + @JsonProperty("feeDetail") + private FeeDetail feeDetail; - @JsonProperty("tradeScope") - private TradeScope tradeScope; + @JsonProperty("tradeScope") + private TradeScope tradeScope; - @JsonProperty("cTime") - private Instant createdAt; + @JsonProperty("cTime") + private Instant createdAt; - @JsonProperty("uTime") - private Instant updatedAt; + @JsonProperty("uTime") + private Instant updatedAt; + public static enum OrderType { + @JsonProperty("limit") + LIMIT, - public static enum OrderType { - @JsonProperty("limit") - LIMIT, + @JsonProperty("market") + MARKET + } - @JsonProperty("market") - MARKET - } + public static enum TradeScope { + @JsonProperty("taker") + TAKER, + @JsonProperty("maker") + MAKER + } - public static enum TradeScope { - @JsonProperty("taker") - TAKER, + @Data + @Builder + @Jacksonized + public static class FeeDetail { - @JsonProperty("maker") - MAKER + @JsonProperty("deduction") + @JsonDeserialize(converter = StringToBooleanConverter.class) + private Boolean deduction; - } + @JsonProperty("feeCoin") + @JsonDeserialize(converter = StringToCurrencyConverter.class) + private Currency currency; + @JsonProperty("totalDeductionFee") + private BigDecimal totalDeductionFee; - @Data - @Builder - @Jacksonized - public static class FeeDetail { - - @JsonProperty("deduction") - @JsonDeserialize(converter = StringToBooleanConverter.class) - private Boolean deduction; - - @JsonProperty("feeCoin") - @JsonDeserialize(converter = StringToCurrencyConverter.class) - private Currency currency; - - @JsonProperty("totalDeductionFee") - private BigDecimal totalDeductionFee; - - @JsonProperty("totalFee") - private BigDecimal totalFee; - - } - + @JsonProperty("totalFee") + private BigDecimal totalFee; + } } diff --git a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/trade/BitgetOrderInfoDto.java b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/trade/BitgetOrderInfoDto.java index 3a6c9e2dc9..26869c7dc7 100755 --- a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/trade/BitgetOrderInfoDto.java +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/trade/BitgetOrderInfoDto.java @@ -17,131 +17,122 @@ @Jacksonized public class BitgetOrderInfoDto { - @JsonProperty("userId") - private String acccountId; + @JsonProperty("userId") + private String acccountId; - @JsonProperty("symbol") - private String symbol; + @JsonProperty("symbol") + private String symbol; - @JsonProperty("orderId") - private String orderId; + @JsonProperty("orderId") + private String orderId; - @JsonProperty("clientOid") - private String clientOid; + @JsonProperty("clientOid") + private String clientOid; - @JsonProperty("price") - private BigDecimal price; + @JsonProperty("price") + private BigDecimal price; - @JsonProperty("size") - private BigDecimal size; + @JsonProperty("size") + private BigDecimal size; - @JsonProperty("orderType") - private OrderType orderType; + @JsonProperty("orderType") + private OrderType orderType; - @JsonProperty("side") - @JsonDeserialize(converter = StringToOrderTypeConverter.class) - private Order.OrderType orderSide; + @JsonProperty("side") + @JsonDeserialize(converter = StringToOrderTypeConverter.class) + private Order.OrderType orderSide; - @JsonProperty("status") - private BitgetOrderStatus orderStatus; + @JsonProperty("status") + private BitgetOrderStatus orderStatus; - @JsonProperty("priceAvg") - private BigDecimal priceAvg; + @JsonProperty("priceAvg") + private BigDecimal priceAvg; - @JsonProperty("baseVolume") - private BigDecimal baseVolume; + @JsonProperty("baseVolume") + private BigDecimal baseVolume; - @JsonProperty("quoteVolume") - private BigDecimal quoteVolume; + @JsonProperty("quoteVolume") + private BigDecimal quoteVolume; - @JsonProperty("enterPointSource") - private String enterPointSource; + @JsonProperty("enterPointSource") + private String enterPointSource; - @JsonProperty("cTime") - private Instant createdAt; + @JsonProperty("cTime") + private Instant createdAt; - @JsonProperty("uTime") - private Instant updatedAt; + @JsonProperty("uTime") + private Instant updatedAt; - @JsonProperty("orderSource") - private OrderSource orderSource; + @JsonProperty("orderSource") + private OrderSource orderSource; - @JsonProperty("feeDetail") - @JsonDeserialize(using = FeeDetailDeserializer.class) - private FeeDetail feeDetail; + @JsonProperty("feeDetail") + @JsonDeserialize(using = FeeDetailDeserializer.class) + private FeeDetail feeDetail; + public BigDecimal getFee() { + return Optional.ofNullable(feeDetail) + .map(FeeDetail::getNewFees) + .map(NewFees::getTotalFee) + .map(BigDecimal::abs) + .orElse(null); + } - public BigDecimal getFee() { - return Optional.ofNullable(feeDetail) - .map(FeeDetail::getNewFees) - .map(NewFees::getTotalFee) - .map(BigDecimal::abs) - .orElse(null); - } + public static enum OrderType { + @JsonProperty("limit") + LIMIT, + @JsonProperty("market") + MARKET + } - public static enum OrderType { - @JsonProperty("limit") - LIMIT, + public static enum BitgetOrderStatus { + @JsonProperty("live") + PENDING, - @JsonProperty("market") - MARKET - } + @JsonProperty("partially_filled") + PARTIALLY_FILLED, + @JsonProperty("filled") + FILLED, - public static enum BitgetOrderStatus { - @JsonProperty("live") - PENDING, + @JsonProperty("cancelled") + CANCELLED + } - @JsonProperty("partially_filled") - PARTIALLY_FILLED, + public static enum OrderSource { + @JsonProperty("normal") + NORMAL, - @JsonProperty("filled") - FILLED, + @JsonProperty("market") + MARKET, - @JsonProperty("cancelled") - CANCELLED + @JsonProperty("spot_trader_buy") + SPOT_TRADER_BUY, - } + @JsonProperty("spot_follower_buy") + SPOT_FOLLOWER_BUY, + @JsonProperty("spot_trader_sell") + SPOT_TRADER_SELL, - public static enum OrderSource { - @JsonProperty("normal") - NORMAL, + @JsonProperty("spot_follower_sell") + SPOT_FOLLOWER_SELL + } - @JsonProperty("market") - MARKET, - - @JsonProperty("spot_trader_buy") - SPOT_TRADER_BUY, - - @JsonProperty("spot_follower_buy") - SPOT_FOLLOWER_BUY, - - @JsonProperty("spot_trader_sell") - SPOT_TRADER_SELL, - - @JsonProperty("spot_follower_sell") - SPOT_FOLLOWER_SELL - - } - - - @Data - @Builder - @Jacksonized - public static class NewFees { - @JsonProperty("t") - private BigDecimal totalFee; - } - - - @Data - @Builder - @Jacksonized - public static class FeeDetail { - @JsonProperty("newFees") - private NewFees newFees; - } + @Data + @Builder + @Jacksonized + public static class NewFees { + @JsonProperty("t") + private BigDecimal totalFee; + } + @Data + @Builder + @Jacksonized + public static class FeeDetail { + @JsonProperty("newFees") + private NewFees newFees; + } } diff --git a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/trade/BitgetPlaceOrderDto.java b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/trade/BitgetPlaceOrderDto.java index b66048be66..82c140753e 100755 --- a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/trade/BitgetPlaceOrderDto.java +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/trade/BitgetPlaceOrderDto.java @@ -18,94 +18,89 @@ @Jacksonized public class BitgetPlaceOrderDto { - @JsonProperty("symbol") - private String symbol; + @JsonProperty("symbol") + private String symbol; - @JsonProperty("side") - @JsonDeserialize(converter = StringToOrderTypeConverter.class) - @JsonSerialize(converter = OrderTypeToStringConverter.class) - private Order.OrderType orderSide; + @JsonProperty("side") + @JsonDeserialize(converter = StringToOrderTypeConverter.class) + @JsonSerialize(converter = OrderTypeToStringConverter.class) + private Order.OrderType orderSide; - @JsonProperty("orderType") - private OrderType orderType; + @JsonProperty("orderType") + private OrderType orderType; - @JsonProperty("force") - private TimeInForce timeInForce; + @JsonProperty("force") + private TimeInForce timeInForce; - @JsonProperty("price") - private BigDecimal price; + @JsonProperty("price") + private BigDecimal price; - @JsonProperty("size") - private BigDecimal size; + @JsonProperty("size") + private BigDecimal size; - @JsonProperty("clientOid") - private String clientOid; + @JsonProperty("clientOid") + private String clientOid; - @JsonProperty("triggerPrice") - private BigDecimal triggerPrice; + @JsonProperty("triggerPrice") + private BigDecimal triggerPrice; - @JsonProperty("tpslType") - private TpSlType tpSlType; + @JsonProperty("tpslType") + private TpSlType tpSlType; - @JsonProperty("requestTime") - private Instant requestTime; + @JsonProperty("requestTime") + private Instant requestTime; - @JsonProperty("receiveWindow") - private Instant receiveWindow; + @JsonProperty("receiveWindow") + private Instant receiveWindow; - @JsonProperty("stpMode") - private StpMode stpMode; + @JsonProperty("stpMode") + private StpMode stpMode; - @JsonProperty("presetTakeProfitPrice") - private BigDecimal presetTakeProfitPrice; + @JsonProperty("presetTakeProfitPrice") + private BigDecimal presetTakeProfitPrice; - @JsonProperty("executeTakeProfitPrice") - private BigDecimal executeTakeProfitPrice; + @JsonProperty("executeTakeProfitPrice") + private BigDecimal executeTakeProfitPrice; - @JsonProperty("presetStopLossPrice") - private BigDecimal presetStopLossPrice; + @JsonProperty("presetStopLossPrice") + private BigDecimal presetStopLossPrice; - @JsonProperty("executeStopLossPrice") - private BigDecimal executeStopLossPrice; + @JsonProperty("executeStopLossPrice") + private BigDecimal executeStopLossPrice; + public enum TimeInForce { + @JsonProperty("gtc") + GOOD_TIL_CANCELLED, - public enum TimeInForce { - @JsonProperty("gtc") - GOOD_TIL_CANCELLED, + @JsonProperty("post_only") + POST_ONLY, - @JsonProperty("post_only") - POST_ONLY, + @JsonProperty("fok") + FILL_OR_KILL, - @JsonProperty("fok") - FILL_OR_KILL, + @JsonProperty("ioc") + IMMEDIATE_OR_CANCEL + } - @JsonProperty("ioc") - IMMEDIATE_OR_CANCEL - } + public enum TpSlType { + @JsonProperty("normal") + NORMAL, + @JsonProperty("tpsl") + SPOT_TP_SL + } - public enum TpSlType { - @JsonProperty("normal") - NORMAL, + public enum StpMode { + @JsonProperty("none") + NONE, - @JsonProperty("tpsl") - SPOT_TP_SL - } - - - public enum StpMode { - @JsonProperty("none") - NONE, - - @JsonProperty("cancel_taker") - CANCEL_TAKER, - - @JsonProperty("cancel_maker") - CANCEL_MAKER, - - @JsonProperty("cancel_both") - CANCEL_BOTH - } + @JsonProperty("cancel_taker") + CANCEL_TAKER, + @JsonProperty("cancel_maker") + CANCEL_MAKER, + @JsonProperty("cancel_both") + CANCEL_BOTH + } } diff --git a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/BitgetAccountService.java b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/BitgetAccountService.java index e83235d92d..7a64ee15e5 100644 --- a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/BitgetAccountService.java +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/BitgetAccountService.java @@ -22,7 +22,6 @@ public BitgetAccountService(BitgetExchange exchange) { super(exchange); } - @Override public AccountInfo getAccountInfo() throws IOException { try { @@ -35,13 +34,11 @@ public AccountInfo getAccountInfo() throws IOException { } } - @Override public TradeHistoryParams createFundingHistoryParams() { return BitgetFundingHistoryParams.builder().build(); } - @Override public List getFundingHistory(TradeHistoryParams params) throws IOException { // return withdrawals and deposits combined diff --git a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/BitgetAccountServiceRaw.java b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/BitgetAccountServiceRaw.java index 77a50d99a7..536814c70b 100644 --- a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/BitgetAccountServiceRaw.java +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/BitgetAccountServiceRaw.java @@ -27,46 +27,89 @@ public BitgetAccountServiceRaw(BitgetExchange exchange) { super(exchange); } - public List getBitgetBalances(Currency currency) throws IOException { - return bitgetAuthenticated.balances(apiKey, bitgetDigest, passphrase, exchange.getNonceFactory(), - BitgetAdapters.toString(currency)).getData(); + return bitgetAuthenticated + .balances( + apiKey, + bitgetDigest, + passphrase, + exchange.getNonceFactory(), + BitgetAdapters.toString(currency)) + .getData(); } - public List getSubBitgetBalances() throws IOException { - return bitgetAuthenticated.subBalances(apiKey, bitgetDigest, passphrase, exchange.getNonceFactory()).getData(); + return bitgetAuthenticated + .subBalances(apiKey, bitgetDigest, passphrase, exchange.getNonceFactory()) + .getData(); } - - public List getBitgetTransferRecords(BitgetTransferHistoryParams params) throws IOException { + public List getBitgetTransferRecords(BitgetTransferHistoryParams params) + throws IOException { Long from = params.getStartTime() != null ? params.getStartTime().toEpochMilli() : null; Long to = params.getEndTime() != null ? params.getEndTime().toEpochMilli() : null; - return bitgetAuthenticated.transferRecords(apiKey, bitgetDigest, passphrase, exchange.getNonceFactory(), - BitgetAdapters.toString(params.getCurrency()), params.getLimit(), params.getClientOid(), - BitgetAdapters.toString(params.getFromAccountType()), from, to, params.getEndId()).getData(); + return bitgetAuthenticated + .transferRecords( + apiKey, + bitgetDigest, + passphrase, + exchange.getNonceFactory(), + BitgetAdapters.toString(params.getCurrency()), + params.getLimit(), + params.getClientOid(), + BitgetAdapters.toString(params.getFromAccountType()), + from, + to, + params.getEndId()) + .getData(); } - public List getBitgetMainSubTransferRecords( BitgetMainSubTransferHistoryParams params) throws IOException { Long from = params.getStartTime() != null ? params.getStartTime().toEpochMilli() : null; Long to = params.getEndTime() != null ? params.getEndTime().toEpochMilli() : null; - return bitgetAuthenticated.mainSubTransferRecords(apiKey, bitgetDigest, passphrase, exchange.getNonceFactory(), - BitgetAdapters.toString(params.getCurrency()), params.getLimit(), params.getClientOid(), - BitgetAdapters.toString(params.getRole()), params.getSubAccountUid(), from, to, params.getEndId()).getData(); + return bitgetAuthenticated + .mainSubTransferRecords( + apiKey, + bitgetDigest, + passphrase, + exchange.getNonceFactory(), + BitgetAdapters.toString(params.getCurrency()), + params.getLimit(), + params.getClientOid(), + BitgetAdapters.toString(params.getRole()), + params.getSubAccountUid(), + from, + to, + params.getEndId()) + .getData(); } - - public List getBitgetWithdrawRecords(TradeHistoryParams params) throws IOException { + public List getBitgetWithdrawRecords(TradeHistoryParams params) + throws IOException { // get arguments - Currency currency = params instanceof TradeHistoryParamCurrency ? ((TradeHistoryParamCurrency) params).getCurrency() : null; - String orderId = params instanceof TradeHistoryParamOrderId ? ((TradeHistoryParamOrderId) params).getOrderId() : null; - String clientOid = params instanceof TradeHistoryParamClientOid ? ((TradeHistoryParamClientOid) params).getClientOid() : null; - Integer limit = params instanceof TradeHistoryParamLimit ? ((TradeHistoryParamLimit) params).getLimit() : null; - String lastTradeId = params instanceof TradeHistoryParamsIdSpan ? ((TradeHistoryParamsIdSpan) params).getEndId() : null; + Currency currency = + params instanceof TradeHistoryParamCurrency + ? ((TradeHistoryParamCurrency) params).getCurrency() + : null; + String orderId = + params instanceof TradeHistoryParamOrderId + ? ((TradeHistoryParamOrderId) params).getOrderId() + : null; + String clientOid = + params instanceof TradeHistoryParamClientOid + ? ((TradeHistoryParamClientOid) params).getClientOid() + : null; + Integer limit = + params instanceof TradeHistoryParamLimit + ? ((TradeHistoryParamLimit) params).getLimit() + : null; + String lastTradeId = + params instanceof TradeHistoryParamsIdSpan + ? ((TradeHistoryParamsIdSpan) params).getEndId() + : null; Long from = null; Long to = null; if (params instanceof TradeHistoryParamsTimeSpan) { @@ -75,17 +118,41 @@ public List getBitgetWithdrawRecords(TradeHistor to = paramsTimeSpan.getEndTime() != null ? paramsTimeSpan.getEndTime().getTime() : null; } - return bitgetAuthenticated.withdrawalRecords(apiKey, bitgetDigest, passphrase, exchange.getNonceFactory(), - BitgetAdapters.toString(currency), limit, orderId, clientOid, from, to, lastTradeId).getData(); + return bitgetAuthenticated + .withdrawalRecords( + apiKey, + bitgetDigest, + passphrase, + exchange.getNonceFactory(), + BitgetAdapters.toString(currency), + limit, + orderId, + clientOid, + from, + to, + lastTradeId) + .getData(); } - - public List getBitgetDepositRecords(TradeHistoryParams params) throws IOException { + public List getBitgetDepositRecords(TradeHistoryParams params) + throws IOException { // get arguments - Currency currency = params instanceof TradeHistoryParamCurrency ? ((TradeHistoryParamCurrency) params).getCurrency() : null; - String orderId = params instanceof TradeHistoryParamOrderId ? ((TradeHistoryParamOrderId) params).getOrderId() : null; - Integer limit = params instanceof TradeHistoryParamLimit ? ((TradeHistoryParamLimit) params).getLimit() : null; - String lastTradeId = params instanceof TradeHistoryParamsIdSpan ? ((TradeHistoryParamsIdSpan) params).getEndId() : null; + Currency currency = + params instanceof TradeHistoryParamCurrency + ? ((TradeHistoryParamCurrency) params).getCurrency() + : null; + String orderId = + params instanceof TradeHistoryParamOrderId + ? ((TradeHistoryParamOrderId) params).getOrderId() + : null; + Integer limit = + params instanceof TradeHistoryParamLimit + ? ((TradeHistoryParamLimit) params).getLimit() + : null; + String lastTradeId = + params instanceof TradeHistoryParamsIdSpan + ? ((TradeHistoryParamsIdSpan) params).getEndId() + : null; Long from = null; Long to = null; if (params instanceof TradeHistoryParamsTimeSpan) { @@ -94,17 +161,40 @@ public List getBitgetDepositRecords(TradeHistory to = paramsTimeSpan.getEndTime() != null ? paramsTimeSpan.getEndTime().getTime() : null; } - return bitgetAuthenticated.depositRecords(apiKey, bitgetDigest, passphrase, exchange.getNonceFactory(), - BitgetAdapters.toString(currency), limit, orderId, from, to, lastTradeId).getData(); + return bitgetAuthenticated + .depositRecords( + apiKey, + bitgetDigest, + passphrase, + exchange.getNonceFactory(), + BitgetAdapters.toString(currency), + limit, + orderId, + from, + to, + lastTradeId) + .getData(); } - - public List getBitgetSubAccountDepositRecords(TradeHistoryParams params) throws IOException { + public List getBitgetSubAccountDepositRecords( + TradeHistoryParams params) throws IOException { // get arguments - Currency currency = params instanceof TradeHistoryParamCurrency ? ((TradeHistoryParamCurrency) params).getCurrency() : null; - String subAccountUid = params instanceof BitgetFundingHistoryParams ? ((BitgetFundingHistoryParams) params).getSubAccountUid() : null; - Integer limit = params instanceof TradeHistoryParamLimit ? ((TradeHistoryParamLimit) params).getLimit() : null; - String lastTradeId = params instanceof TradeHistoryParamsIdSpan ? ((TradeHistoryParamsIdSpan) params).getEndId() : null; + Currency currency = + params instanceof TradeHistoryParamCurrency + ? ((TradeHistoryParamCurrency) params).getCurrency() + : null; + String subAccountUid = + params instanceof BitgetFundingHistoryParams + ? ((BitgetFundingHistoryParams) params).getSubAccountUid() + : null; + Integer limit = + params instanceof TradeHistoryParamLimit + ? ((TradeHistoryParamLimit) params).getLimit() + : null; + String lastTradeId = + params instanceof TradeHistoryParamsIdSpan + ? ((TradeHistoryParamsIdSpan) params).getEndId() + : null; Long from = null; Long to = null; if (params instanceof TradeHistoryParamsTimeSpan) { @@ -113,9 +203,18 @@ public List getBitgetSubAccountDepositRecords(Tr to = paramsTimeSpan.getEndTime() != null ? paramsTimeSpan.getEndTime().getTime() : null; } - return bitgetAuthenticated.subDepositRecords(apiKey, bitgetDigest, passphrase, exchange.getNonceFactory(), - BitgetAdapters.toString(currency), limit, subAccountUid, from, to, lastTradeId).getData(); + return bitgetAuthenticated + .subDepositRecords( + apiKey, + bitgetDigest, + passphrase, + exchange.getNonceFactory(), + BitgetAdapters.toString(currency), + limit, + subAccountUid, + from, + to, + lastTradeId) + .getData(); } - - } diff --git a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/BitgetBaseService.java b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/BitgetBaseService.java index 5d1f6bace4..ad4d40f44a 100644 --- a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/BitgetBaseService.java +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/BitgetBaseService.java @@ -18,18 +18,24 @@ public class BitgetBaseService extends BaseExchangeService imple public BitgetBaseService(BitgetExchange exchange) { super(exchange); - bitget = ExchangeRestProxyBuilder - .forInterface(Bitget.class, exchange.getExchangeSpecification()) - .clientConfigCustomizer(clientConfig -> clientConfig.setJacksonObjectMapperFactory(new BitgetJacksonObjectMapperFactory())) - .build(); - bitgetAuthenticated = ExchangeRestProxyBuilder - .forInterface(BitgetAuthenticated.class, exchange.getExchangeSpecification()) - .clientConfigCustomizer(clientConfig -> clientConfig.setJacksonObjectMapperFactory(new BitgetJacksonObjectMapperFactory())) - .build(); + bitget = + ExchangeRestProxyBuilder.forInterface(Bitget.class, exchange.getExchangeSpecification()) + .clientConfigCustomizer( + clientConfig -> + clientConfig.setJacksonObjectMapperFactory( + new BitgetJacksonObjectMapperFactory())) + .build(); + bitgetAuthenticated = + ExchangeRestProxyBuilder.forInterface( + BitgetAuthenticated.class, exchange.getExchangeSpecification()) + .clientConfigCustomizer( + clientConfig -> + clientConfig.setJacksonObjectMapperFactory( + new BitgetJacksonObjectMapperFactory())) + .build(); apiKey = exchange.getExchangeSpecification().getApiKey(); passphrase = exchange.getExchangeSpecification().getPassword(); bitgetDigest = BitgetDigest.createInstance(exchange.getExchangeSpecification().getSecretKey()); - } } diff --git a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/BitgetDigest.java b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/BitgetDigest.java index 3d2a4ca24e..1f2e9f1c29 100644 --- a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/BitgetDigest.java +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/BitgetDigest.java @@ -15,12 +15,10 @@ private BitgetDigest(String secretKeyBase64) { super(secretKeyBase64, HMAC_SHA_256); } - public static BitgetDigest createInstance(String secretKeyBase64) { return secretKeyBase64 == null ? null : new BitgetDigest(secretKeyBase64); } - @SneakyThrows @Override public String digestParams(RestInvocation restInvocation) { diff --git a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/BitgetMarketDataService.java b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/BitgetMarketDataService.java index a5991f1a35..bec124dc28 100644 --- a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/BitgetMarketDataService.java +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/BitgetMarketDataService.java @@ -24,27 +24,24 @@ import org.knowm.xchange.service.marketdata.MarketDataService; import org.knowm.xchange.service.marketdata.params.Params; -public class BitgetMarketDataService extends BitgetMarketDataServiceRaw implements - MarketDataService { +public class BitgetMarketDataService extends BitgetMarketDataServiceRaw + implements MarketDataService { public BitgetMarketDataService(BitgetExchange exchange) { super(exchange); } - public List getCurrencies() throws IOException { try { return getBitgetCoinDtoList(null).stream() .map(BitgetCoinDto::getCurrency) .distinct() .collect(Collectors.toList()); - } - catch (BitgetException e) { + } catch (BitgetException e) { throw BitgetErrorAdapter.adapt(e); } } - public List getInstruments() throws IOException { try { List metadata = getBitgetSymbolDtos(null); @@ -54,13 +51,11 @@ public List getInstruments() throws IOException { .map(BitgetSymbolDto::getCurrencyPair) .distinct() .collect(Collectors.toList()); - } - catch (BitgetException e) { + } catch (BitgetException e) { throw BitgetErrorAdapter.adapt(e); } } - @Override public ExchangeHealth getExchangeHealth() { try { @@ -78,13 +73,11 @@ public ExchangeHealth getExchangeHealth() { return ExchangeHealth.OFFLINE; } - @Override public Ticker getTicker(CurrencyPair currencyPair, Object... args) throws IOException { return getTicker((Instrument) currencyPair, args); } - @Override public Ticker getTicker(Instrument instrument, Object... args) throws IOException { try { @@ -96,7 +89,6 @@ public Ticker getTicker(Instrument instrument, Object... args) throws IOExceptio } } - @Override public List getTickers(Params params) throws IOException { try { @@ -110,13 +102,11 @@ public List getTickers(Params params) throws IOException { } } - @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 { Objects.requireNonNull(instrument); diff --git a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/BitgetMarketDataServiceRaw.java b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/BitgetMarketDataServiceRaw.java index ee8882c941..f0c254bd12 100644 --- a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/BitgetMarketDataServiceRaw.java +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/BitgetMarketDataServiceRaw.java @@ -14,35 +14,27 @@ public class BitgetMarketDataServiceRaw extends BitgetBaseService { - public BitgetMarketDataServiceRaw(BitgetExchange exchange) { super(exchange); } - public BitgetServerTime getBitgetServerTime() throws IOException { return bitget.serverTime().getData(); } - public List getBitgetCoinDtoList(Currency currency) throws IOException { return bitget.coins(BitgetAdapters.toString(currency)).getData(); } - public List getBitgetSymbolDtos(Instrument instrument) throws IOException { return bitget.symbols(BitgetAdapters.toString(instrument)).getData(); } - public List getBitgetTickerDtos(Instrument instrument) throws IOException { return bitget.tickers(BitgetAdapters.toString(instrument)).getData(); } - public BitgetMarketDepthDto getBitgetMarketDepthDtos(Instrument instrument) throws IOException { return bitget.orderbook(BitgetAdapters.toString(instrument)).getData(); } - - } diff --git a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/BitgetTradeService.java b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/BitgetTradeService.java index 4cc4f9f69e..208f182297 100644 --- a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/BitgetTradeService.java +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/BitgetTradeService.java @@ -27,7 +27,6 @@ public BitgetTradeService(BitgetExchange exchange) { super(exchange); } - @Override public Collection getOrder(OrderQueryParams... orderQueryParams) throws IOException { Validate.validState(orderQueryParams.length == 1); @@ -37,37 +36,30 @@ public Collection getOrder(OrderQueryParams... orderQueryParams) throws I try { BitgetOrderInfoDto orderStatus = bitgetOrderInfoDto(params.getOrderId()); return Collections.singletonList(BitgetAdapters.toOrder(orderStatus)); - } - catch (BitgetException e) { + } catch (BitgetException e) { throw BitgetErrorAdapter.adapt(e); } - } - @Override public UserTrades getTradeHistory(TradeHistoryParams params) throws IOException { try { - List userTradeList = bitgetFills(params).stream() - .map(BitgetAdapters::toUserTrade) - .collect(Collectors.toList()); + List userTradeList = + bitgetFills(params).stream() + .map(BitgetAdapters::toUserTrade) + .collect(Collectors.toList()); return new UserTrades(userTradeList, TradeSortType.SortByID); - } - catch (BitgetException e) { + } catch (BitgetException e) { throw BitgetErrorAdapter.adapt(e); } } - @Override public String placeMarketOrder(MarketOrder marketOrder) throws IOException { try { return createOrder(BitgetAdapters.toBitgetPlaceOrderDto(marketOrder)).getOrderId(); - } - catch (BitgetException e) { + } catch (BitgetException e) { throw BitgetErrorAdapter.adapt(e); } } - - } diff --git a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/BitgetTradeServiceRaw.java b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/BitgetTradeServiceRaw.java index 2c99130cbb..2f15901efe 100644 --- a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/BitgetTradeServiceRaw.java +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/BitgetTradeServiceRaw.java @@ -21,13 +21,24 @@ public BitgetTradeServiceRaw(BitgetExchange exchange) { super(exchange); } - public List bitgetFills(TradeHistoryParams params) throws IOException { // get arguments - Instrument instrument = params instanceof TradeHistoryParamInstrument ? ((TradeHistoryParamInstrument) params).getInstrument() : null; - Integer limit = params instanceof TradeHistoryParamLimit ? ((TradeHistoryParamLimit) params).getLimit() : null; - String orderId = params instanceof TradeHistoryParamOrderId ? ((TradeHistoryParamOrderId) params).getOrderId() : null; - String lastTradeId = params instanceof TradeHistoryParamsIdSpan ? ((TradeHistoryParamsIdSpan) params).getEndId() : null; + Instrument instrument = + params instanceof TradeHistoryParamInstrument + ? ((TradeHistoryParamInstrument) params).getInstrument() + : null; + Integer limit = + params instanceof TradeHistoryParamLimit + ? ((TradeHistoryParamLimit) params).getLimit() + : null; + String orderId = + params instanceof TradeHistoryParamOrderId + ? ((TradeHistoryParamOrderId) params).getOrderId() + : null; + String lastTradeId = + params instanceof TradeHistoryParamsIdSpan + ? ((TradeHistoryParamsIdSpan) params).getEndId() + : null; Long from = null; Long to = null; if (params instanceof TradeHistoryParamsTimeSpan) { @@ -36,23 +47,37 @@ public List bitgetFills(TradeHistoryParams params) throws IOExcep to = paramsTimeSpan.getEndTime() != null ? paramsTimeSpan.getEndTime().getTime() : null; } - return bitgetAuthenticated.fills(apiKey, bitgetDigest, passphrase, exchange.getNonceFactory(), - BitgetAdapters.toString(instrument), limit, orderId, from, to, lastTradeId).getData(); + return bitgetAuthenticated + .fills( + apiKey, + bitgetDigest, + passphrase, + exchange.getNonceFactory(), + BitgetAdapters.toString(instrument), + limit, + orderId, + from, + to, + lastTradeId) + .getData(); } - public BitgetOrderInfoDto bitgetOrderInfoDto(String orderId) throws IOException { - List results = bitgetAuthenticated.orderInfo( - apiKey, bitgetDigest, passphrase, exchange.getNonceFactory(), orderId).getData(); + List results = + bitgetAuthenticated + .orderInfo(apiKey, bitgetDigest, passphrase, exchange.getNonceFactory(), orderId) + .getData(); if (results.size() != 1) { return null; } return results.get(0); } - - public BitgetOrderInfoDto createOrder(BitgetPlaceOrderDto bitgetPlaceOrderDto) throws IOException { - return bitgetAuthenticated.createOrder(apiKey, bitgetDigest, passphrase, exchange.getNonceFactory(), bitgetPlaceOrderDto).getData(); + public BitgetOrderInfoDto createOrder(BitgetPlaceOrderDto bitgetPlaceOrderDto) + throws IOException { + return bitgetAuthenticated + .createOrder( + apiKey, bitgetDigest, passphrase, exchange.getNonceFactory(), bitgetPlaceOrderDto) + .getData(); } - } diff --git a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/params/BitgetFundingHistoryParams.java b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/params/BitgetFundingHistoryParams.java index c2fa6d7e3c..fd60a988fc 100644 --- a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/params/BitgetFundingHistoryParams.java +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/params/BitgetFundingHistoryParams.java @@ -13,9 +13,13 @@ @Data @Builder -public class BitgetFundingHistoryParams implements TradeHistoryParamCurrency, TradeHistoryParamLimit, - TradeHistoryParamOrderId, TradeHistoryParamsTimeSpan, TradeHistoryParamsIdSpan, - TradeHistoryParamClientOid { +public class BitgetFundingHistoryParams + implements TradeHistoryParamCurrency, + TradeHistoryParamLimit, + TradeHistoryParamOrderId, + TradeHistoryParamsTimeSpan, + TradeHistoryParamsIdSpan, + TradeHistoryParamClientOid { private Currency currency; @@ -34,5 +38,4 @@ public class BitgetFundingHistoryParams implements TradeHistoryParamCurrency, Tr private String startId; private String endId; - } diff --git a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/params/BitgetTradeHistoryParams.java b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/params/BitgetTradeHistoryParams.java index 3b7da570d0..02c84ad61b 100644 --- a/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/params/BitgetTradeHistoryParams.java +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/params/BitgetTradeHistoryParams.java @@ -12,9 +12,12 @@ @Data @SuperBuilder -public class BitgetTradeHistoryParams implements TradeHistoryParamInstrument, - TradeHistoryParamLimit, TradeHistoryParamsTimeSpan, TradeHistoryParamsIdSpan, - TradeHistoryParamOrderId { +public class BitgetTradeHistoryParams + implements TradeHistoryParamInstrument, + TradeHistoryParamLimit, + TradeHistoryParamsTimeSpan, + TradeHistoryParamsIdSpan, + TradeHistoryParamOrderId { private Instrument instrument; @@ -29,6 +32,4 @@ public class BitgetTradeHistoryParams implements TradeHistoryParamInstrument, private String startId; private String endId; - - } diff --git a/xchange-bitget/src/test/java/org/knowm/xchange/bitget/BitgetExchangeIntegration.java b/xchange-bitget/src/test/java/org/knowm/xchange/bitget/BitgetExchangeIntegration.java index e22fc7207c..1b1b5ab581 100644 --- a/xchange-bitget/src/test/java/org/knowm/xchange/bitget/BitgetExchangeIntegration.java +++ b/xchange-bitget/src/test/java/org/knowm/xchange/bitget/BitgetExchangeIntegration.java @@ -13,9 +13,8 @@ class BitgetExchangeIntegration extends BitgetIntegrationTestParent { @Test void valid_metadata() { assertThat(exchange.getExchangeMetaData()).isNotNull(); - Map instruments = exchange.getExchangeMetaData().getInstruments(); + Map instruments = + exchange.getExchangeMetaData().getInstruments(); assertThat(instruments).containsKey(CurrencyPair.BTC_USDT); } - - -} \ No newline at end of file +} diff --git a/xchange-bitget/src/test/java/org/knowm/xchange/bitget/BitgetExchangeWiremock.java b/xchange-bitget/src/test/java/org/knowm/xchange/bitget/BitgetExchangeWiremock.java index 446f4e6a93..418acc55f1 100644 --- a/xchange-bitget/src/test/java/org/knowm/xchange/bitget/BitgetExchangeWiremock.java +++ b/xchange-bitget/src/test/java/org/knowm/xchange/bitget/BitgetExchangeWiremock.java @@ -14,7 +14,7 @@ public abstract class BitgetExchangeWiremock { protected static BitgetExchange exchange; -// private static final boolean IS_RECORDING = true; + // private static final boolean IS_RECORDING = true; private static final boolean IS_RECORDING = false; private static WireMockServer wireMockServer; diff --git a/xchange-bitget/src/test/java/org/knowm/xchange/bitget/BitgetIntegrationTestParent.java b/xchange-bitget/src/test/java/org/knowm/xchange/bitget/BitgetIntegrationTestParent.java index 52bee0a28a..17797877da 100644 --- a/xchange-bitget/src/test/java/org/knowm/xchange/bitget/BitgetIntegrationTestParent.java +++ b/xchange-bitget/src/test/java/org/knowm/xchange/bitget/BitgetIntegrationTestParent.java @@ -19,8 +19,7 @@ static void init() { @BeforeEach void exchange_online() { // skip if offline - assumeThat(exchange.getMarketDataService().getExchangeHealth()).isEqualTo(ExchangeHealth.ONLINE); + assumeThat(exchange.getMarketDataService().getExchangeHealth()) + .isEqualTo(ExchangeHealth.ONLINE); } - - } diff --git a/xchange-bitget/src/test/java/org/knowm/xchange/bitget/service/BitgetAccountServiceIntegration.java b/xchange-bitget/src/test/java/org/knowm/xchange/bitget/service/BitgetAccountServiceIntegration.java index 637d669ef9..fdaffd1358 100644 --- a/xchange-bitget/src/test/java/org/knowm/xchange/bitget/service/BitgetAccountServiceIntegration.java +++ b/xchange-bitget/src/test/java/org/knowm/xchange/bitget/service/BitgetAccountServiceIntegration.java @@ -15,7 +15,6 @@ class BitgetAccountServiceIntegration { static BitgetExchange exchange; - @BeforeAll public static void credentialsPresent() { // skip if there are no credentials @@ -33,12 +32,9 @@ public static void credentialsPresent() { exchange = (BitgetExchange) ExchangeFactory.INSTANCE.createExchange(exSpec); } - @Test void valid_balances() throws IOException { AccountInfo accountInfo = exchange.getAccountService().getAccountInfo(); assertThat(accountInfo.getWallet("spot").getBalances()).isNotEmpty(); } - - -} \ No newline at end of file +} diff --git a/xchange-bitget/src/test/java/org/knowm/xchange/bitget/service/BitgetAccountServiceRawTest.java b/xchange-bitget/src/test/java/org/knowm/xchange/bitget/service/BitgetAccountServiceRawTest.java index 9a1bbba30d..12cadb13ee 100644 --- a/xchange-bitget/src/test/java/org/knowm/xchange/bitget/service/BitgetAccountServiceRawTest.java +++ b/xchange-bitget/src/test/java/org/knowm/xchange/bitget/service/BitgetAccountServiceRawTest.java @@ -27,119 +27,125 @@ class BitgetAccountServiceRawTest extends BitgetExchangeWiremock { - BitgetAccountServiceRaw bitgetAccountServiceRaw = (BitgetAccountServiceRaw) exchange.getAccountService(); - + BitgetAccountServiceRaw bitgetAccountServiceRaw = + (BitgetAccountServiceRaw) exchange.getAccountService(); @Test void transfer_records() throws IOException { - BitgetTransferRecordDto expected = BitgetTransferRecordDto.builder() - .clientOid("1225489997897666560") - .currency(USDT) - .fromAccountType(BitgetAccountType.SPOT) - .fromSymbol("") - .toAccountType(BitgetAccountType.SPOT) - .toSymbol("") - .size(new BigDecimal("1.00000000")) - .status(Status.SUCCESSFUL) - .timestamp(Instant.ofEpochMilli(1727905504678L)) - .transferId("1225489997897666560") - .build(); - - BitgetTransferHistoryParams params = BitgetTransferHistoryParams.builder() - .currency(USDT) - .fromAccountType(BitgetAccountType.SPOT) - .startTime(Instant.ofEpochMilli(1727904561900L)) - .endTime(Instant.ofEpochMilli(1727905505000L)) - .limit(1) - .endId("1225486043893731328") - .build(); + BitgetTransferRecordDto expected = + BitgetTransferRecordDto.builder() + .clientOid("1225489997897666560") + .currency(USDT) + .fromAccountType(BitgetAccountType.SPOT) + .fromSymbol("") + .toAccountType(BitgetAccountType.SPOT) + .toSymbol("") + .size(new BigDecimal("1.00000000")) + .status(Status.SUCCESSFUL) + .timestamp(Instant.ofEpochMilli(1727905504678L)) + .transferId("1225489997897666560") + .build(); + + BitgetTransferHistoryParams params = + BitgetTransferHistoryParams.builder() + .currency(USDT) + .fromAccountType(BitgetAccountType.SPOT) + .startTime(Instant.ofEpochMilli(1727904561900L)) + .endTime(Instant.ofEpochMilli(1727905505000L)) + .limit(1) + .endId("1225486043893731328") + .build(); List actual = bitgetAccountServiceRaw.getBitgetTransferRecords(params); assertThat(actual).hasSize(1); assertThat(actual).first().usingRecursiveComparison().isEqualTo(expected); } - @Test void main_sub_transfer_records() throws IOException { - BitgetMainSubTransferRecordDto expected = BitgetMainSubTransferRecordDto.builder() - .clientOid("1225490042499895296") - .currency(USDT) - .fromAccountType(BitgetAccountType.SPOT) - .toAccountType(BitgetAccountType.SPOT) - .fromUserId("7326856338") - .toUserId("1548914322") - .size(new BigDecimal("1.00000000")) - .status(BitgetMainSubTransferRecordDto.Status.SUCCESSFUL) - .timestamp(Instant.ofEpochMilli(1727905515312L)) - .transferId("72990567") - .build(); - - BitgetMainSubTransferHistoryParams params = BitgetMainSubTransferHistoryParams.builder() - .currency(USDT) - .role(Role.INITIATOR) - .subAccountUid("7326856338") - .startTime(Instant.ofEpochMilli(1727905515300L)) - .endTime(Instant.ofEpochMilli(1727905515399L)) - .clientOid("1225490042499895296") - .limit(1) - .endId("1225490042499895296") - .build(); - List actual = bitgetAccountServiceRaw.getBitgetMainSubTransferRecords(params); + BitgetMainSubTransferRecordDto expected = + BitgetMainSubTransferRecordDto.builder() + .clientOid("1225490042499895296") + .currency(USDT) + .fromAccountType(BitgetAccountType.SPOT) + .toAccountType(BitgetAccountType.SPOT) + .fromUserId("7326856338") + .toUserId("1548914322") + .size(new BigDecimal("1.00000000")) + .status(BitgetMainSubTransferRecordDto.Status.SUCCESSFUL) + .timestamp(Instant.ofEpochMilli(1727905515312L)) + .transferId("72990567") + .build(); + + BitgetMainSubTransferHistoryParams params = + BitgetMainSubTransferHistoryParams.builder() + .currency(USDT) + .role(Role.INITIATOR) + .subAccountUid("7326856338") + .startTime(Instant.ofEpochMilli(1727905515300L)) + .endTime(Instant.ofEpochMilli(1727905515399L)) + .clientOid("1225490042499895296") + .limit(1) + .endId("1225490042499895296") + .build(); + List actual = + bitgetAccountServiceRaw.getBitgetMainSubTransferRecords(params); assertThat(actual).hasSize(1); assertThat(actual).first().usingRecursiveComparison().isEqualTo(expected); } - @Test void sub_account_deposit_records() throws IOException { - BitgetDepositWithdrawRecordDto expected = BitgetDepositWithdrawRecordDto.builder() - .chain("TON(TON)") - .orderId("1227960429565849600") - .tradeId("x_8NF1B51t2lLOu-RYxl-7FOwfM4d6UgPhqlr_CAO8s=") - .currency(USDT) - .depositType(DepositType.ON_CHAIN) - .toAddress("EQCJLo0UPRm6RToIXgD0eMpoak5cuj4BTt99NYCY14yOUcoT") - .size(new BigDecimal("10.00000000")) - .status(FundingRecord.Status.COMPLETE) - .createdAt(Instant.ofEpochMilli(1728494501487L)) - .updatedAt(Instant.ofEpochMilli(1728494528012L)) - .build(); - - BitgetFundingHistoryParams params = BitgetFundingHistoryParams.builder() - .currency(USDT) - .subAccountUid("7831928986") - .startTime(Date.from(Instant.ofEpochMilli(1728494500000L))) - .endTime(Date.from(Instant.ofEpochMilli(1728494529999L))) - .limit(1) - .endId("1227960429565849609") - .build(); - List actual = bitgetAccountServiceRaw.getBitgetSubAccountDepositRecords(params); + BitgetDepositWithdrawRecordDto expected = + BitgetDepositWithdrawRecordDto.builder() + .chain("TON(TON)") + .orderId("1227960429565849600") + .tradeId("x_8NF1B51t2lLOu-RYxl-7FOwfM4d6UgPhqlr_CAO8s=") + .currency(USDT) + .depositType(DepositType.ON_CHAIN) + .toAddress("EQCJLo0UPRm6RToIXgD0eMpoak5cuj4BTt99NYCY14yOUcoT") + .size(new BigDecimal("10.00000000")) + .status(FundingRecord.Status.COMPLETE) + .createdAt(Instant.ofEpochMilli(1728494501487L)) + .updatedAt(Instant.ofEpochMilli(1728494528012L)) + .build(); + + BitgetFundingHistoryParams params = + BitgetFundingHistoryParams.builder() + .currency(USDT) + .subAccountUid("7831928986") + .startTime(Date.from(Instant.ofEpochMilli(1728494500000L))) + .endTime(Date.from(Instant.ofEpochMilli(1728494529999L))) + .limit(1) + .endId("1227960429565849609") + .build(); + List actual = + bitgetAccountServiceRaw.getBitgetSubAccountDepositRecords(params); assertThat(actual).hasSize(1); assertThat(actual).first().usingRecursiveComparison().isEqualTo(expected); } - @Test void sub_account_balances() throws IOException { - BitgetSubBalanceDto expected = BitgetSubBalanceDto.builder() - .userId("7831928986") - .balances(Collections.singletonList(BitgetBalanceDto.builder() - .currency(USDT) - .available(new BigDecimal("55.44646499")) - .limitAvailable(BigDecimal.ZERO) - .frozen(BigDecimal.ZERO) - .locked(BigDecimal.ZERO) - .build())) - .build(); + BitgetSubBalanceDto expected = + BitgetSubBalanceDto.builder() + .userId("7831928986") + .balances( + Collections.singletonList( + BitgetBalanceDto.builder() + .currency(USDT) + .available(new BigDecimal("55.44646499")) + .limitAvailable(BigDecimal.ZERO) + .frozen(BigDecimal.ZERO) + .locked(BigDecimal.ZERO) + .build())) + .build(); List actual = bitgetAccountServiceRaw.getSubBitgetBalances(); assertThat(actual).hasSize(1); assertThat(actual).first().usingRecursiveComparison().isEqualTo(expected); } - - -} \ No newline at end of file +} diff --git a/xchange-bitget/src/test/java/org/knowm/xchange/bitget/service/BitgetAccountServiceTest.java b/xchange-bitget/src/test/java/org/knowm/xchange/bitget/service/BitgetAccountServiceTest.java index 1e863ed8a2..496f70bde7 100644 --- a/xchange-bitget/src/test/java/org/knowm/xchange/bitget/service/BitgetAccountServiceTest.java +++ b/xchange-bitget/src/test/java/org/knowm/xchange/bitget/service/BitgetAccountServiceTest.java @@ -19,27 +19,29 @@ class BitgetAccountServiceTest extends BitgetExchangeWiremock { @Test void funding_history() throws IOException { - List actual = exchange.getAccountService().getFundingHistory( - BitgetFundingHistoryParams.builder() - .startTime(Date.from(Instant.ofEpochMilli(1721643200000L))) - .endTime(Date.from(Instant.ofEpochMilli(1727970869665L))) - .endId("1203378295345901568") - .build()); - - FundingRecord expected = new FundingRecord.Builder() - .setInternalId("1200126632376020992") - .setDate(Date.from(Instant.ofEpochMilli(1721858437064L))) - .setAddress("EQAPOcvrl-4fjsw9W5iUBC8np6UtVgE0QPDzLgfsTJh9NYX5") - .setBlockchainTransactionHash("scWb5s8OtLL_kSE8rQv5fDvreOGUe82wcV9KXrGNNww=") - .setCurrency(Currency.USDT) - .setType(Type.DEPOSIT) - .setAmount(new BigDecimal("100.00000000")) - .setStatus(Status.COMPLETE) - .build(); + List actual = + exchange + .getAccountService() + .getFundingHistory( + BitgetFundingHistoryParams.builder() + .startTime(Date.from(Instant.ofEpochMilli(1721643200000L))) + .endTime(Date.from(Instant.ofEpochMilli(1727970869665L))) + .endId("1203378295345901568") + .build()); + + FundingRecord expected = + new FundingRecord.Builder() + .setInternalId("1200126632376020992") + .setDate(Date.from(Instant.ofEpochMilli(1721858437064L))) + .setAddress("EQAPOcvrl-4fjsw9W5iUBC8np6UtVgE0QPDzLgfsTJh9NYX5") + .setBlockchainTransactionHash("scWb5s8OtLL_kSE8rQv5fDvreOGUe82wcV9KXrGNNww=") + .setCurrency(Currency.USDT) + .setType(Type.DEPOSIT) + .setAmount(new BigDecimal("100.00000000")) + .setStatus(Status.COMPLETE) + .build(); assertThat(actual).hasSize(2); assertThat(actual).first().usingRecursiveComparison().isEqualTo(expected); } - - -} \ No newline at end of file +} diff --git a/xchange-bitget/src/test/java/org/knowm/xchange/bitget/service/BitgetDigestTest.java b/xchange-bitget/src/test/java/org/knowm/xchange/bitget/service/BitgetDigestTest.java index 75fbd049f4..5f19528e09 100644 --- a/xchange-bitget/src/test/java/org/knowm/xchange/bitget/service/BitgetDigestTest.java +++ b/xchange-bitget/src/test/java/org/knowm/xchange/bitget/service/BitgetDigestTest.java @@ -14,9 +14,7 @@ @ExtendWith(MockitoExtension.class) class BitgetDigestTest { - @Mock - RestInvocation restInvocation; - + @Mock RestInvocation restInvocation; @Test void signature_no_query_params() { @@ -35,6 +33,4 @@ void signature_no_query_params() { assertThat(actual).isEqualTo(expected); } - - -} \ No newline at end of file +} diff --git a/xchange-bitget/src/test/java/org/knowm/xchange/bitget/service/BitgetMarketDataServiceIntegration.java b/xchange-bitget/src/test/java/org/knowm/xchange/bitget/service/BitgetMarketDataServiceIntegration.java index ed1e83e3c4..f1f0f018a5 100644 --- a/xchange-bitget/src/test/java/org/knowm/xchange/bitget/service/BitgetMarketDataServiceIntegration.java +++ b/xchange-bitget/src/test/java/org/knowm/xchange/bitget/service/BitgetMarketDataServiceIntegration.java @@ -27,53 +27,53 @@ void valid_single_ticker() throws IOException { if (ticker.getBid().signum() > 0 && ticker.getAsk().signum() > 0) { assertThat(ticker.getBid()).isLessThan(ticker.getAsk()); } - } - @Test void valid_currencies() throws IOException { - List currencies = ((BitgetMarketDataService) exchange.getMarketDataService()).getCurrencies(); + List currencies = + ((BitgetMarketDataService) exchange.getMarketDataService()).getCurrencies(); assertThat(currencies).isNotEmpty(); assertThat(currencies.stream().distinct().count()).isEqualTo(currencies.size()); } - @Test void valid_instruments() throws IOException { - List instruments = ((BitgetMarketDataService) exchange.getMarketDataService()).getInstruments(); + List instruments = + ((BitgetMarketDataService) exchange.getMarketDataService()).getInstruments(); assertThat(instruments).isNotEmpty(); assertThat(instruments.stream().distinct().count()).isEqualTo(instruments.size()); } - @Test void check_exceptions() { assertThatExceptionOfType(InstrumentNotValidException.class) - .isThrownBy(() -> - exchange.getMarketDataService().getTicker(new CurrencyPair("NONEXISTING/NONEXISTING"))); - + .isThrownBy( + () -> + exchange + .getMarketDataService() + .getTicker(new CurrencyPair("NONEXISTING/NONEXISTING"))); } - @Test void valid_tickers() throws IOException { List tickers = exchange.getMarketDataService().getTickers(null); assertThat(tickers).isNotEmpty(); - assertThat(tickers).allSatisfy(ticker -> { - assertThat(ticker.getInstrument()).isNotNull(); - assertThat(ticker.getLast()).isNotNull(); + assertThat(tickers) + .allSatisfy( + ticker -> { + assertThat(ticker.getInstrument()).isNotNull(); + assertThat(ticker.getLast()).isNotNull(); - if (ticker.getBid().signum() > 0 && ticker.getAsk().signum() > 0) { - assertThat(ticker.getBid()).isLessThan(ticker.getAsk()); - } - }); + if (ticker.getBid().signum() > 0 && ticker.getAsk().signum() > 0) { + assertThat(ticker.getBid()).isLessThan(ticker.getAsk()); + } + }); } - @Test void valid_orderbook() throws IOException { OrderBook orderBook = exchange.getMarketDataService().getOrderBook(CurrencyPair.BTC_USDT); @@ -81,18 +81,21 @@ void valid_orderbook() throws IOException { assertThat(orderBook.getBids()).isNotEmpty(); assertThat(orderBook.getAsks()).isNotEmpty(); - assertThat(orderBook.getAsks().get(0).getLimitPrice()).isGreaterThan(orderBook.getBids().get(0).getLimitPrice()); - - assertThat(orderBook.getBids()).allSatisfy(limitOrder -> { - assertThat(limitOrder.getInstrument()).isEqualTo(CurrencyPair.BTC_USDT); - assertThat(limitOrder.getType()).isEqualTo(OrderType.BID); - }); - - assertThat(orderBook.getAsks()).allSatisfy(limitOrder -> { - assertThat(limitOrder.getInstrument()).isEqualTo(CurrencyPair.BTC_USDT); - assertThat(limitOrder.getType()).isEqualTo(OrderType.ASK); - }); + assertThat(orderBook.getAsks().get(0).getLimitPrice()) + .isGreaterThan(orderBook.getBids().get(0).getLimitPrice()); + + assertThat(orderBook.getBids()) + .allSatisfy( + limitOrder -> { + assertThat(limitOrder.getInstrument()).isEqualTo(CurrencyPair.BTC_USDT); + assertThat(limitOrder.getType()).isEqualTo(OrderType.BID); + }); + + assertThat(orderBook.getAsks()) + .allSatisfy( + limitOrder -> { + assertThat(limitOrder.getInstrument()).isEqualTo(CurrencyPair.BTC_USDT); + assertThat(limitOrder.getType()).isEqualTo(OrderType.ASK); + }); } - - -} \ No newline at end of file +} diff --git a/xchange-bitget/src/test/java/org/knowm/xchange/bitget/service/BitgetMarketDataServiceRawIntegration.java b/xchange-bitget/src/test/java/org/knowm/xchange/bitget/service/BitgetMarketDataServiceRawIntegration.java index ee24c10a9b..eda4e94048 100644 --- a/xchange-bitget/src/test/java/org/knowm/xchange/bitget/service/BitgetMarketDataServiceRawIntegration.java +++ b/xchange-bitget/src/test/java/org/knowm/xchange/bitget/service/BitgetMarketDataServiceRawIntegration.java @@ -13,7 +13,8 @@ class BitgetMarketDataServiceRawIntegration extends BitgetIntegrationTestParent { - BitgetMarketDataServiceRaw bitgetMarketDataServiceRaw = (BitgetMarketDataServiceRaw) exchange.getMarketDataService(); + BitgetMarketDataServiceRaw bitgetMarketDataServiceRaw = + (BitgetMarketDataServiceRaw) exchange.getMarketDataService(); @Test void valid_coins() throws IOException { @@ -22,19 +23,21 @@ void valid_coins() throws IOException { assertThat(coins).isNotEmpty(); // validate coins - assertThat(coins).allSatisfy(coin -> { - assertThat(coin.getCoinId()).isNotNull(); - assertThat(coin.getCurrency()).isNotNull(); - - // validate each chain - assertThat(coin.getChains()).allSatisfy(chain -> { - assertThat(chain.getChain()).isNotNull(); - }); - - }); + assertThat(coins) + .allSatisfy( + coin -> { + assertThat(coin.getCoinId()).isNotNull(); + assertThat(coin.getCurrency()).isNotNull(); + + // validate each chain + assertThat(coin.getChains()) + .allSatisfy( + chain -> { + assertThat(chain.getChain()).isNotNull(); + }); + }); } - @Test void valid_coin() throws IOException { List coins = bitgetMarketDataServiceRaw.getBitgetCoinDtoList(Currency.USDT); @@ -43,13 +46,13 @@ void valid_coin() throws IOException { assertThat(coins.get(0).getCurrency()).isEqualTo(Currency.USDT); assertThat(coins.get(0).getCoinId()).isNotNull(); - assertThat(coins.get(0).getChains()).allSatisfy(chain -> { - assertThat(chain.getChain()).isNotNull(); - }); - + assertThat(coins.get(0).getChains()) + .allSatisfy( + chain -> { + assertThat(chain.getChain()).isNotNull(); + }); } - @Test void valid_symbol() throws IOException { List symbols = bitgetMarketDataServiceRaw.getBitgetSymbolDtos(BTC_USDT); @@ -61,10 +64,8 @@ void valid_symbol() throws IOException { assertThat(symbol.getPricePrecision()).isPositive(); assertThat(symbol.getQuantityPrecision()).isPositive(); assertThat(symbol.getQuotePrecision()).isPositive(); - } - @Test void valid_symbols() throws IOException { List symbols = bitgetMarketDataServiceRaw.getBitgetSymbolDtos(null); @@ -72,14 +73,12 @@ void valid_symbols() throws IOException { assertThat(symbols).isNotEmpty(); // validate symbols - assertThat(symbols).allSatisfy(symbol -> { - assertThat(symbol.getCurrencyPair()).isNotNull(); - assertThat(symbol.getBase()).isNotNull(); - assertThat(symbol.getQuote()).isNotNull(); - - }); - + assertThat(symbols) + .allSatisfy( + symbol -> { + assertThat(symbol.getCurrencyPair()).isNotNull(); + assertThat(symbol.getBase()).isNotNull(); + assertThat(symbol.getQuote()).isNotNull(); + }); } - - -} \ No newline at end of file +} diff --git a/xchange-bitget/src/test/java/org/knowm/xchange/bitget/service/BitgetTradeServiceTest.java b/xchange-bitget/src/test/java/org/knowm/xchange/bitget/service/BitgetTradeServiceTest.java index b5218c74e1..bebb6fe165 100644 --- a/xchange-bitget/src/test/java/org/knowm/xchange/bitget/service/BitgetTradeServiceTest.java +++ b/xchange-bitget/src/test/java/org/knowm/xchange/bitget/service/BitgetTradeServiceTest.java @@ -26,7 +26,6 @@ class BitgetTradeServiceTest extends BitgetExchangeWiremock { TradeService tradeService = exchange.getTradeService(); - @Test void sell_order_details() throws IOException { MarketOrder expected = @@ -43,12 +42,13 @@ void sell_order_details() throws IOException { Collection orders = tradeService.getOrder("1214193970718347264"); assertThat(orders).hasSize(1); - assertThat(orders).first() + assertThat(orders) + .first() .usingComparatorForType(BigDecimal::compareTo, BigDecimal.class) - .usingRecursiveComparison().isEqualTo(expected); + .usingRecursiveComparison() + .isEqualTo(expected); } - @Test void buy_order_details() throws IOException { MarketOrder expected = @@ -63,14 +63,16 @@ void buy_order_details() throws IOException { .fee(new BigDecimal("0.0020706")) .build(); - Collection orders = tradeService.getOrder(new DefaultQueryOrderParamInstrument(null, "1214189703404097539")); + Collection orders = + tradeService.getOrder(new DefaultQueryOrderParamInstrument(null, "1214189703404097539")); assertThat(orders).hasSize(1); - assertThat(orders).first() + assertThat(orders) + .first() .usingComparatorForType(BigDecimal::compareTo, BigDecimal.class) - .usingRecursiveComparison().isEqualTo(expected); + .usingRecursiveComparison() + .isEqualTo(expected); } - @Test void place_market_buy_order() throws IOException { MarketOrder marketOrder = @@ -83,7 +85,6 @@ void place_market_buy_order() throws IOException { assertThat(actualResponse).isEqualTo("1214189703404097539"); } - @Test void place_market_sell_order() throws IOException { MarketOrder marketOrder = @@ -96,28 +97,36 @@ void place_market_sell_order() throws IOException { assertThat(actualResponse).isEqualTo("1214193970718347264"); } - @Test void trade_history() throws IOException { - UserTrades userTrades = exchange.getTradeService().getTradeHistory( - BitgetTradeHistoryParams.builder() - .instrument(BTC_USDT) - .limit(2) - .orderId("1225475622585147396") - .startTime(Date.from(Instant.ofEpochMilli(1727902077418L))) - .endTime(Date.from(Instant.ofEpochMilli(1727902077420L))) - .endId("1225475622852575236") - .build() - ); + UserTrades userTrades = + exchange + .getTradeService() + .getTradeHistory( + BitgetTradeHistoryParams.builder() + .instrument(BTC_USDT) + .limit(2) + .orderId("1225475622585147396") + .startTime(Date.from(Instant.ofEpochMilli(1727902077418L))) + .endTime(Date.from(Instant.ofEpochMilli(1727902077420L))) + .endId("1225475622852575236") + .build()); assertThat(userTrades.getUserTrades()).hasSize(1); - UserTrade expected = new UserTrade(OrderType.BID, new BigDecimal("0.000246"), BTC_USDT, - new BigDecimal("60775.01"), Date.from(Instant.ofEpochMilli(1727902077419L)), "1225475622852575236", - "1225475622585147396", new BigDecimal("0.000000246"), Currency.BTC, null); + UserTrade expected = + new UserTrade( + OrderType.BID, + new BigDecimal("0.000246"), + BTC_USDT, + new BigDecimal("60775.01"), + Date.from(Instant.ofEpochMilli(1727902077419L)), + "1225475622852575236", + "1225475622585147396", + new BigDecimal("0.000000246"), + Currency.BTC, + null); assertThat(userTrades.getUserTrades()).first().usingRecursiveComparison().isEqualTo(expected); } - - -} \ No newline at end of file +}