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 a0d2fdc60b4..12d3d758730 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,11 +10,18 @@ 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.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; 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; @@ -24,12 +31,15 @@ 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; 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 @@ -215,4 +225,61 @@ public BitgetPlaceOrderDto toBitgetPlaceOrderDto(MarketOrder marketOrder) { .size(marketOrder.getOriginalAmount()) .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); + } + + public String toString(BitgetAccountType bitgetAccountType) { + return Optional.ofNullable(bitgetAccountType).map(BitgetAccountType::getValue).orElse(null); + } + + public String toString(BitgetMainSubTransferHistoryParams.Role role) { + return Optional.ofNullable(role).map(Role::getValue).orElse(null); + } + + 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 899c566bdf6..f128c0fffdd 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,11 @@ 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.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; import org.knowm.xchange.bitget.dto.trade.BitgetPlaceOrderDto; import si.mazi.rescu.ParamsDigest; @@ -25,6 +30,16 @@ public interface BitgetAuthenticated { @GET @Path("api/v2/spot/account/assets") BitgetResponse> balances( + @HeaderParam("ACCESS-KEY") String apiKey, + @HeaderParam("ACCESS-SIGN") ParamsDigest signer, + @HeaderParam("ACCESS-PASSPHRASE") String passphrase, + @HeaderParam("ACCESS-TIMESTAMP") SynchronizedValueFactory timestamp, + @QueryParam("coin") String currency) + 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, @@ -51,4 +66,98 @@ BitgetResponse createOrder( @HeaderParam("ACCESS-TIMESTAMP") SynchronizedValueFactory timestamp, BitgetPlaceOrderDto bitgetPlaceOrderDto) 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; + + @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; + + @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; + + @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/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( + @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 00000000000..6ad29f0b763 --- /dev/null +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/config/converter/StringToFundingRecordStatusConverter.java @@ -0,0 +1,23 @@ +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/BitgetAccountType.java b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/account/BitgetAccountType.java new file mode 100644 index 00000000000..7ee2a4a9bd7 --- /dev/null +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/account/BitgetAccountType.java @@ -0,0 +1,19 @@ +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/BitgetDepositWithdrawRecordDto.java b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/account/BitgetDepositWithdrawRecordDto.java new file mode 100755 index 00000000000..5a91429df64 --- /dev/null +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/account/BitgetDepositWithdrawRecordDto.java @@ -0,0 +1,85 @@ +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/dto/account/BitgetMainSubTransferRecordDto.java b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/account/BitgetMainSubTransferRecordDto.java new file mode 100755 index 00000000000..6c66adb035c --- /dev/null +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/account/BitgetMainSubTransferRecordDto.java @@ -0,0 +1,59 @@ +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/BitgetSubBalanceDto.java b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/account/BitgetSubBalanceDto.java new file mode 100755 index 00000000000..efa75434cf5 --- /dev/null +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/account/BitgetSubBalanceDto.java @@ -0,0 +1,19 @@ +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/dto/account/BitgetTransferRecordDto.java b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/account/BitgetTransferRecordDto.java new file mode 100755 index 00000000000..0ff31c41d39 --- /dev/null +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/account/BitgetTransferRecordDto.java @@ -0,0 +1,59 @@ +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/BitgetMainSubTransferHistoryParams.java b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/account/params/BitgetMainSubTransferHistoryParams.java new file mode 100644 index 00000000000..bcea573f370 --- /dev/null +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/account/params/BitgetMainSubTransferHistoryParams.java @@ -0,0 +1,42 @@ +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/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 00000000000..c45f75cf1b8 --- /dev/null +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/account/params/BitgetTransferHistoryParams.java @@ -0,0 +1,26 @@ +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/dto/trade/BitgetFillDto.java b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/trade/BitgetFillDto.java new file mode 100755 index 00000000000..4728dee134c --- /dev/null +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/dto/trade/BitgetFillDto.java @@ -0,0 +1,96 @@ +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/BitgetAccountService.java b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/BitgetAccountService.java index 70b3f2113e0..7a64ee15e5d 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 { @@ -20,7 +25,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); @@ -28,4 +33,18 @@ public AccountInfo getAccountInfo() throws IOException { throw BitgetErrorAdapter.adapt(e); } } + + @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 3423c6dc4a8..536814c70b9 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,24 @@ 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.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; +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; +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 { @@ -11,9 +27,194 @@ public BitgetAccountServiceRaw(BitgetExchange exchange) { super(exchange); } - public List getBitgetBalances() throws IOException { + public List getBitgetBalances(Currency currency) throws IOException { return bitgetAuthenticated - .balances(apiKey, bitgetDigest, passphrase, exchange.getNonceFactory()) + .balances( + apiKey, + bitgetDigest, + passphrase, + exchange.getNonceFactory(), + BitgetAdapters.toString(currency)) + .getData(); + } + + 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; + + 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(); + } + + 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(); + } + + 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/BitgetMarketDataService.java b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/BitgetMarketDataService.java index e610a4e6c49..bec124dc286 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,31 @@ 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/main/java/org/knowm/xchange/bitget/service/BitgetTradeService.java b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/BitgetTradeService.java index 2c1cffd754d..208f1822976 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; @@ -35,6 +41,19 @@ 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 31468840a76..2f15901efe4 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 { @@ -12,6 +21,47 @@ 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; + 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 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 00000000000..fd60a988fc1 --- /dev/null +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/params/BitgetFundingHistoryParams.java @@ -0,0 +1,41 @@ +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 subAccountUid; + + 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/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 00000000000..02c84ad61b3 --- /dev/null +++ b/xchange-bitget/src/main/java/org/knowm/xchange/bitget/service/params/BitgetTradeHistoryParams.java @@ -0,0 +1,35 @@ +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/BitgetAccountServiceRawTest.java b/xchange-bitget/src/test/java/org/knowm/xchange/bitget/service/BitgetAccountServiceRawTest.java new file mode 100644 index 00000000000..12cadb13ee6 --- /dev/null +++ b/xchange-bitget/src/test/java/org/knowm/xchange/bitget/service/BitgetAccountServiceRawTest.java @@ -0,0 +1,151 @@ +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.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; +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 { + + 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); + } + + @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); + } + + @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); + } + + @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); + } +} 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 00000000000..496f70bde7d --- /dev/null +++ b/xchange-bitget/src/test/java/org/knowm/xchange/bitget/service/BitgetAccountServiceTest.java @@ -0,0 +1,47 @@ +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); + } +} 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 e3269f87c3e..f1f0f018a5c 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 { @@ -27,6 +29,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) 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 b4156ffe46d..bebb6fe1654 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; @@ -91,4 +96,37 @@ void place_market_sell_order() throws IOException { String actualResponse = exchange.getTradeService().placeMarketOrder(marketOrder); 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()); + + 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); + } } 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 00000000000..f65ce9d9972 --- /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/__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 00000000000..a127da8461e --- /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/__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 00000000000..7653caae735 --- /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/__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 00000000000..1e3b507e7ca --- /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/__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 00000000000..e6ec4efdbc5 --- /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_subaccount-deposit-records.json b/xchange-bitget/src/test/resources/__files/api_v2_spot_wallet_subaccount-deposit-records.json new file mode 100644 index 00000000000..c98f5c65ff1 --- /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/__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 00000000000..3ceb720d67c --- /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_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 00000000000..28517ceef02 --- /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 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 00000000000..777e144bb78 --- /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 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 00000000000..372e46c3fab --- /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/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 00000000000..e3504d13e30 --- /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/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 00000000000..6d37b2001e7 --- /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_subaccount-deposit-records.json b/xchange-bitget/src/test/resources/mappings/api_v2_spot_wallet_subaccount-deposit-records.json new file mode 100644 index 00000000000..89caaec8ef5 --- /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/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 00000000000..db0481f46f7 --- /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/sign.js b/xchange-bitget/src/test/resources/rest/sign.js index 2daee399999..ba3b7ce1ffe 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 1fb8850c39f..12724bf440c 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}} @@ -38,10 +38,22 @@ 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' - gen_sign("GET", request); + gen_sign(request); %} GET {{api_host}}/api/v2/spot/trade/orderInfo?orderId=1213530920130613257 ACCESS-KEY: {{api_key}} @@ -53,7 +65,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 +86,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}} @@ -92,3 +104,87 @@ 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=BTCUSDT +ACCESS-KEY: {{api_key}} +ACCESS-SIGN: {{sign}} +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}} + + +### 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}} + + +### 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}} + + 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 00000000000..1bf27c7be7c --- /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); + +} 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 00000000000..da9485ed614 --- /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 f7b5a619e7c..bc6ce2d2254 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();