From 8f218eb20911de76127e5a2bd76824501c450d5f Mon Sep 17 00:00:00 2001 From: makarid Date: Wed, 11 Oct 2023 18:58:53 +0300 Subject: [PATCH] [CoinbasePro] Update implementation with new AccounService functions. --- .../xchange/coinbasepro/CoinbasePro.java | 4 +- .../coinbasepro/CoinbaseProAdapters.java | 147 +++++----- .../coinbasepro/CoinbaseProExchange.java | 16 +- .../service/CoinbaseProAccountService.java | 261 +++++++++++++----- .../service/CoinbaseProAccountServiceRaw.java | 10 +- .../service/CoinbaseProMarketDataService.java | 18 +- .../CoinbaseProPrivateIntegration.java | 148 +++++++++- .../CoinbaseProPrivateRawIntegration.java | 86 ------ .../coinbasepro/CoinbaseProPublicTest.java | 60 +--- .../dto/CoinbaseProMetadataTest.java | 43 --- .../account/params/FundingRecordParamAll.java | 2 +- 11 files changed, 455 insertions(+), 340 deletions(-) delete mode 100644 xchange-coinbasepro/src/test/java/org/knowm/xchange/coinbasepro/dto/CoinbaseProMetadataTest.java diff --git a/xchange-coinbasepro/src/main/java/org/knowm/xchange/coinbasepro/CoinbasePro.java b/xchange-coinbasepro/src/main/java/org/knowm/xchange/coinbasepro/CoinbasePro.java index 9cc89e6e06f..b93a212b0b0 100644 --- a/xchange-coinbasepro/src/main/java/org/knowm/xchange/coinbasepro/CoinbasePro.java +++ b/xchange-coinbasepro/src/main/java/org/knowm/xchange/coinbasepro/CoinbasePro.java @@ -277,8 +277,8 @@ CoinbaseProTransfers getTransfersByAccountId( @HeaderParam("CB-ACCESS-TIMESTAMP") long timestamp, @HeaderParam("CB-ACCESS-PASSPHRASE") String passphrase, @PathParam("account_id") String accountId, - @QueryParam("before") String beforeDate, - @QueryParam("after") String afterDate, + @QueryParam("before") String before, + @QueryParam("after") String after, @QueryParam("limit") Integer limit, @QueryParam("type") String type) // Possible types [deposit, withdraw, internal_deposit, internal_withdraw] throws CoinbaseProException, IOException; diff --git a/xchange-coinbasepro/src/main/java/org/knowm/xchange/coinbasepro/CoinbaseProAdapters.java b/xchange-coinbasepro/src/main/java/org/knowm/xchange/coinbasepro/CoinbaseProAdapters.java index 29e69dff41a..497d6edc745 100644 --- a/xchange-coinbasepro/src/main/java/org/knowm/xchange/coinbasepro/CoinbaseProAdapters.java +++ b/xchange-coinbasepro/src/main/java/org/knowm/xchange/coinbasepro/CoinbaseProAdapters.java @@ -15,9 +15,9 @@ import java.util.stream.Collectors; import org.knowm.xchange.coinbasepro.dto.CoinbaseProTransfer; import org.knowm.xchange.coinbasepro.dto.account.CoinbaseProAccount; +import org.knowm.xchange.coinbasepro.dto.account.CoinbaseProLedger; import org.knowm.xchange.coinbasepro.dto.marketdata.CoinbaseProCurrency; import org.knowm.xchange.coinbasepro.dto.marketdata.CoinbaseProProduct; -import org.knowm.xchange.coinbasepro.dto.marketdata.CoinbaseProProduct.CoinbaseProProductStatus; import org.knowm.xchange.coinbasepro.dto.marketdata.CoinbaseProProductBook; import org.knowm.xchange.coinbasepro.dto.marketdata.CoinbaseProProductBookEntry; import org.knowm.xchange.coinbasepro.dto.marketdata.CoinbaseProProductStats; @@ -38,7 +38,7 @@ 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.FundingRecord.Status; import org.knowm.xchange.dto.account.Wallet; import org.knowm.xchange.dto.marketdata.OrderBook; import org.knowm.xchange.dto.marketdata.Ticker; @@ -46,7 +46,6 @@ import org.knowm.xchange.dto.marketdata.Trades; import org.knowm.xchange.dto.marketdata.Trades.TradeSortType; import org.knowm.xchange.dto.meta.CurrencyMetaData; -import org.knowm.xchange.dto.meta.ExchangeMetaData; import org.knowm.xchange.dto.meta.InstrumentMetaData; import org.knowm.xchange.dto.meta.WalletHealth; import org.knowm.xchange.dto.trade.LimitOrder; @@ -177,7 +176,7 @@ private static List toLimitOrderList( return allLevels; } - public static Wallet adaptAccountInfo(CoinbaseProAccount[] coinbaseProAccounts) { + public static Wallet adaptWallet(CoinbaseProAccount[] coinbaseProAccounts) { List balances = new ArrayList<>(coinbaseProAccounts.length); for (CoinbaseProAccount coinbaseProAccount : coinbaseProAccounts) { @@ -192,6 +191,19 @@ public static Wallet adaptAccountInfo(CoinbaseProAccount[] coinbaseProAccounts) return Wallet.Builder.from(balances).id(coinbaseProAccounts[0].getProfileId()).build(); } + public static Wallet adaptWallet(CoinbaseProAccount coinbaseProAccount) { + List balances = new ArrayList<>(); + + balances.add( + new Balance( + Currency.getInstance(coinbaseProAccount.getCurrency()), + coinbaseProAccount.getBalance(), + coinbaseProAccount.getAvailable(), + coinbaseProAccount.getHold())); + + return Wallet.Builder.from(balances).id(coinbaseProAccount.getProfileId()).build(); + } + @SuppressWarnings("unchecked") public static OpenOrders adaptOpenOrders(CoinbaseProOrder[] coinbaseExOpenOrders) { final Map> twoTypes = @@ -363,62 +375,6 @@ private static int numberOfDecimals(BigDecimal value) { return -(int) Math.round(Math.log10(d)); } - public static ExchangeMetaData adaptToExchangeMetaData( - ExchangeMetaData exchangeMetaData, - CoinbaseProProduct[] products, - CoinbaseProCurrency[] cbCurrencies) { - - Map currencyPairs = - exchangeMetaData == null ? new HashMap<>() : exchangeMetaData.getInstruments(); - - Map currencies = - exchangeMetaData == null ? new HashMap<>() : exchangeMetaData.getCurrencies(); - - for (CoinbaseProProduct product : products) { - if (!product.getStatus().equals(CoinbaseProProductStatus.online)) { - continue; - } - CurrencyPair pair = adaptCurrencyPair(product); - - InstrumentMetaData staticMetaData = currencyPairs.get(pair); - int baseScale = numberOfDecimals(product.getBaseIncrement()); - int priceScale = numberOfDecimals(product.getQuoteIncrement()); - boolean marketOrderAllowed = !product.isLimitOnly(); - - currencyPairs.put( - pair, - new InstrumentMetaData.Builder() - .tradingFee(new BigDecimal("0.50")) - .volumeScale(baseScale) - .priceScale(priceScale) - .counterMinimumAmount(product.getMinMarketFunds()) - .feeTiers(staticMetaData != null ? staticMetaData.getFeeTiers() : null) - .tradingFeeCurrency(pair.counter) - .marketOrderEnabled(marketOrderAllowed) - .build()); - } - - Arrays.stream(cbCurrencies) - .forEach( - currency -> - currencies.put( - adaptCurrency(currency), - new CurrencyMetaData( - numberOfDecimals(currency.getMaxPrecision()), - BigDecimal.ZERO, - currency.getDetails().getMinWithdrawalAmount(), - "online".equals(currency.getStatus()) - ? WalletHealth.ONLINE - : WalletHealth.OFFLINE))); - - return new ExchangeMetaData( - currencyPairs, - currencies, - exchangeMetaData == null ? null : exchangeMetaData.getPublicRateLimits(), - exchangeMetaData == null ? null : exchangeMetaData.getPrivateRateLimits(), - true); - } - public static String adaptProductID(CurrencyPair currencyPair) { return currencyPair == null ? null @@ -510,12 +466,11 @@ public static CoinbaseProPlaceOrder adaptCoinbaseProStopOrder(StopOrder stopOrde .build(); } - public static FundingRecord adaptFundingRecord( - Currency currency, CoinbaseProTransfer coinbaseProTransfer) { + public static FundingRecord adaptFundingRecord(CoinbaseProTransfer coinbaseProTransfer) { FundingRecord.Status status = FundingRecord.Status.PROCESSING; - Date processedAt = coinbaseProTransfer.processedAt(); - Date canceledAt = coinbaseProTransfer.canceledAt(); + Date processedAt = coinbaseProTransfer.getProcessedAt(); + Date canceledAt = coinbaseProTransfer.getCanceledAt(); if (canceledAt != null) status = FundingRecord.Status.CANCELLED; else if (processedAt != null) status = FundingRecord.Status.COMPLETE; @@ -524,17 +479,17 @@ public static FundingRecord adaptFundingRecord( if (address == null) address = coinbaseProTransfer.getDetails().getSentToAddress(); String cryptoTransactionHash = coinbaseProTransfer.getDetails().getCryptoTransactionHash(); - String transactionHash = adaptTransactionHash(currency.getSymbol(), cryptoTransactionHash); + String transactionHash = adaptTransactionHash(coinbaseProTransfer.getCurrency(), cryptoTransactionHash); return FundingRecord.builder() .address(address) .addressTag(coinbaseProTransfer.getDetails().getDestinationTag()) - .date(coinbaseProTransfer.createdAt()) - .currency(currency) - .amount(coinbaseProTransfer.amount()) + .date(coinbaseProTransfer.getCreatedAt()) + .currency(Currency.getInstance(coinbaseProTransfer.getCurrency())) + .amount(coinbaseProTransfer.getAmount()) .internalId(coinbaseProTransfer.getId()) .blockchainTransactionHash(transactionHash) - .type(coinbaseProTransfer.type()) + .type(coinbaseProTransfer.getType()) .status(status) .build(); } @@ -562,4 +517,58 @@ private static String adaptTransactionHash(String currency, String transactionHa } return transactionHash; } + + public static List adaptCoinbaseProLedger(CoinbaseProLedger ledger) { + List records = new ArrayList<>(); + + ledger.forEach( + coinbaseProLedgerDto -> records.add(FundingRecord.builder() + .internalId(coinbaseProLedgerDto.getId()) + .amount(coinbaseProLedgerDto.getAmount()) + .balance(coinbaseProLedgerDto.getBalance()) + .date(coinbaseProLedgerDto.getCreatedAt()) + .status(Status.COMPLETE) + .description(coinbaseProLedgerDto.getType().name()) +// .type(convertCoinbaseProLedgerTxType(coinbaseProLedgerDto.getType())) + .build())); + return records; + } + + + public static Map adaptCoinbaseProCurrencies(CoinbaseProCurrency[] coinbaseProCurrencies) { + Map map = new HashMap<>(); + + Arrays.stream(coinbaseProCurrencies).forEach(coinbaseProCurrency -> map.put(adaptCurrency(coinbaseProCurrency), CurrencyMetaData.builder() + .scale(coinbaseProCurrency.getMinSize().scale()) + .walletHealth("online".equals(coinbaseProCurrency.getStatus()) + ? WalletHealth.ONLINE + : WalletHealth.OFFLINE) + .minWithdrawalAmount((coinbaseProCurrency.getDetails().getMinWithdrawalAmount() != null) + ? coinbaseProCurrency.getDetails().getMinWithdrawalAmount() + : BigDecimal.ZERO) + .build())); + + return map; + } + + public static Map adaptCoinbaseProCurrencyPairs(CoinbaseProProduct[] coinbaseProProducts) { + Map map = new HashMap<>(); + + Arrays.stream(coinbaseProProducts).forEach(coinbaseProProduct -> { + Instrument instrument = adaptCurrencyPair(coinbaseProProduct); + + map.put(instrument, new InstrumentMetaData.Builder() + .tradingFee(new BigDecimal("0.50")) + .volumeScale(numberOfDecimals(coinbaseProProduct.getBaseIncrement())) + .priceScale(numberOfDecimals(coinbaseProProduct.getQuoteIncrement())) + .counterMinimumAmount(coinbaseProProduct.getMinMarketFunds()) + .amountStepSize(coinbaseProProduct.getBaseIncrement()) + .priceStepSize(coinbaseProProduct.getQuoteIncrement()) + .tradingFeeCurrency(instrument.getCounter()) + .marketOrderEnabled(!coinbaseProProduct.isLimitOnly()) + .build()); + }); + + return map; + } } diff --git a/xchange-coinbasepro/src/main/java/org/knowm/xchange/coinbasepro/CoinbaseProExchange.java b/xchange-coinbasepro/src/main/java/org/knowm/xchange/coinbasepro/CoinbaseProExchange.java index f457c39c33a..54a9f7fffa9 100644 --- a/xchange-coinbasepro/src/main/java/org/knowm/xchange/coinbasepro/CoinbaseProExchange.java +++ b/xchange-coinbasepro/src/main/java/org/knowm/xchange/coinbasepro/CoinbaseProExchange.java @@ -13,12 +13,10 @@ import org.knowm.xchange.Exchange; import org.knowm.xchange.ExchangeSpecification; import org.knowm.xchange.client.ResilienceRegistries; -import org.knowm.xchange.coinbasepro.dto.marketdata.CoinbaseProCurrency; -import org.knowm.xchange.coinbasepro.dto.marketdata.CoinbaseProProduct; import org.knowm.xchange.coinbasepro.service.CoinbaseProAccountService; import org.knowm.xchange.coinbasepro.service.CoinbaseProMarketDataService; -import org.knowm.xchange.coinbasepro.service.CoinbaseProMarketDataServiceRaw; import org.knowm.xchange.coinbasepro.service.CoinbaseProTradeService; +import org.knowm.xchange.dto.meta.ExchangeMetaData; import si.mazi.rescu.SynchronizedValueFactory; public class CoinbaseProExchange extends BaseExchange { @@ -121,12 +119,12 @@ public ResilienceRegistries getResilienceRegistries() { @Override public void remoteInit() throws IOException { - CoinbaseProProduct[] products = - ((CoinbaseProMarketDataServiceRaw) marketDataService).getCoinbaseProProducts(); - CoinbaseProCurrency[] currencies = - ((CoinbaseProMarketDataServiceRaw) marketDataService).getCoinbaseProCurrencies(); - exchangeMetaData = - CoinbaseProAdapters.adaptToExchangeMetaData(exchangeMetaData, products, currencies); + exchangeMetaData = new ExchangeMetaData( + marketDataService.getInstruments(), + marketDataService.getCurrencies(), + exchangeMetaData == null ? null : exchangeMetaData.getPublicRateLimits(), + exchangeMetaData == null ? null : exchangeMetaData.getPrivateRateLimits(), + true); } // @NoArgsConstructor(access = AccessLevel.PRIVATE) diff --git a/xchange-coinbasepro/src/main/java/org/knowm/xchange/coinbasepro/service/CoinbaseProAccountService.java b/xchange-coinbasepro/src/main/java/org/knowm/xchange/coinbasepro/service/CoinbaseProAccountService.java index d4c1c1d2740..f031227ace4 100644 --- a/xchange-coinbasepro/src/main/java/org/knowm/xchange/coinbasepro/service/CoinbaseProAccountService.java +++ b/xchange-coinbasepro/src/main/java/org/knowm/xchange/coinbasepro/service/CoinbaseProAccountService.java @@ -15,22 +15,19 @@ import org.knowm.xchange.coinbasepro.dto.account.CoinbaseProFee; import org.knowm.xchange.coinbasepro.dto.account.CoinbaseProFundingHistoryParams; import org.knowm.xchange.coinbasepro.dto.account.CoinbaseProLedger; -import org.knowm.xchange.coinbasepro.dto.account.CoinbaseProLedgerDto; -import org.knowm.xchange.coinbasepro.dto.account.CoinbaseProTransfersWithHeader; import org.knowm.xchange.coinbasepro.dto.trade.CoinbaseProWallet; import org.knowm.xchange.coinbasepro.dto.trade.CoinbaseProWalletAddress; import org.knowm.xchange.coinbasepro.dto.trade.CoinbaseProSendMoneyResponse; -import org.knowm.xchange.coinbasepro.dto.trade.CoinbaseProTradeHistoryParams; import org.knowm.xchange.currency.Currency; import org.knowm.xchange.dto.account.AccountInfo; import org.knowm.xchange.dto.account.AddressWithTag; import org.knowm.xchange.dto.account.Fee; import org.knowm.xchange.dto.account.FundingRecord; -import org.knowm.xchange.dto.account.TransferRecord; +import org.knowm.xchange.dto.account.FundingRecord.Type; +import org.knowm.xchange.dto.account.params.FundingRecordParamAll; import org.knowm.xchange.exceptions.ExchangeException; import org.knowm.xchange.instrument.Instrument; import org.knowm.xchange.service.account.AccountService; -import org.knowm.xchange.service.account.params.TransferHistoryParam; import org.knowm.xchange.service.trade.params.DefaultWithdrawFundsParams; import org.knowm.xchange.service.trade.params.HistoryParamsFundingType; import org.knowm.xchange.service.trade.params.TradeHistoryParams; @@ -50,7 +47,7 @@ public CoinbaseProAccountService( @Override public AccountInfo getAccountInfo() throws IOException { - return new AccountInfo(CoinbaseProAdapters.adaptAccountInfo(getCoinbaseProAccountInfo())); + return new AccountInfo(CoinbaseProAdapters.adaptWallet(getCoinbaseProAccountInfo())); } @Override @@ -152,68 +149,105 @@ public TradeHistoryParams createFundingHistoryParams() { return new CoinbaseProFundingHistoryParams(); } - public List getLedgerWithPagination(TradeHistoryParams params) throws IOException { - - int maxPageSize = 100; + @Override + /* + * Warning - this method makes several API calls. The reason is that the paging functionality + * isn't implemented properly yet. + * + *

It honours TradeHistoryParamCurrency for filtering to a single ccy. + */ + public List getFundingHistory(TradeHistoryParams params) throws IOException { - if(!(params instanceof CoinbaseProFundingHistoryParams)) { - throw new IOException("Params must be "+CoinbaseProFundingHistoryParams.class.getName()+" class only!"); + String fundingRecordType = null; + if (params instanceof HistoryParamsFundingType + && ((HistoryParamsFundingType) params).getType() != null) { + fundingRecordType = ((HistoryParamsFundingType) params).getType().toString().toLowerCase(); } - CoinbaseProFundingHistoryParams fundingParams = (CoinbaseProFundingHistoryParams) params; + int maxPageSize = 100; - List ledgerList = new ArrayList<>(); + List fundingHistory = new ArrayList<>(); - String createdAt = null; + String createdAt = null; // use to get next page while (true) { String createdAtFinal = createdAt; + CoinbaseProTransfers transfers = + getTransfers(fundingRecordType, null, null, createdAtFinal, maxPageSize); - CoinbaseProLedger ledger = - getLedger( - fundingParams.getAccountId(), - null, - null, - null, - createdAtFinal, - fundingParams.getLimit(), - null - ); - - ledgerList.addAll(ledger); + fundingHistory.addAll( + transfers.stream() + .map(CoinbaseProAdapters::adaptFundingRecord) + .collect(Collectors.toList())); - if (ledger.size() < maxPageSize) { + if (transfers.size() < maxPageSize) { break; } - createdAt = ledger.getHeader(CB_AFTER_HEADER); + createdAt = transfers.getHeader(CB_AFTER_HEADER); } - return ledgerList; + return fundingHistory; } - public CoinbaseProTransfersWithHeader getTransfersWithPagination(TradeHistoryParams params) + @Override + public AccountInfo getSubAccountInfo(String subAccountId) throws IOException { + return new AccountInfo(CoinbaseProAdapters.adaptWallet(getCoinbaseProAccountById(subAccountId))); + } + + @Override + public List getInternalTransferHistory(FundingRecordParamAll params) throws IOException { - String fundingRecordType = null; - if (params instanceof HistoryParamsFundingType - && ((HistoryParamsFundingType) params).getType() != null) { - fundingRecordType = ((HistoryParamsFundingType) params).getType().toString().toLowerCase(); + String beforeItem = ""; + String afterItem = ""; + int maxPageSize = 100; + + List fundingHistory = new ArrayList<>(); + + while (true) { + CoinbaseProTransfers transfers = + getTransfers( + null, + null, + beforeItem, + afterItem, + maxPageSize); + + fundingHistory.addAll( + transfers.stream() + .filter(transfer -> transfer.getType().equals(Type.INTERNAL_DEPOSIT) || transfer.getType().equals(Type.INTERNAL_WITHDRAW)) + .map(CoinbaseProAdapters::adaptFundingRecord) + .collect(Collectors.toList())); + + if (!transfers.isEmpty()) { + afterItem = transfers.getHeader(CB_AFTER_HEADER); + beforeItem = transfers.getHeader(CB_BEFORE_HEADER); + } + + if (transfers.size() < maxPageSize) { + break; + } } + return fundingHistory; + } + + @Override + public List getWithdrawHistory(FundingRecordParamAll params) throws IOException { String beforeItem = ""; String afterItem = ""; int maxPageSize = 100; - if (params instanceof CoinbaseProTradeHistoryParams) { - maxPageSize = ((CoinbaseProTradeHistoryParams) params).getLimit(); - afterItem = ((CoinbaseProTradeHistoryParams) params).getAfterTransferId(); - beforeItem = ((CoinbaseProTradeHistoryParams) params).getBeforeTransferId(); - } List fundingHistory = new ArrayList<>(); while (true) { CoinbaseProTransfers transfers = - getTransfers(fundingRecordType, null, beforeItem, afterItem, maxPageSize); + getTransfers( + Type.WITHDRAW.name().toLowerCase(), + null, + beforeItem, + afterItem, + maxPageSize); fundingHistory.addAll( transfers.stream() @@ -230,60 +264,159 @@ public CoinbaseProTransfersWithHeader getTransfersWithPagination(TradeHistoryPar } } - return new CoinbaseProTransfersWithHeader(fundingHistory, afterItem, beforeItem); + return fundingHistory; } @Override - /* - * Warning - this method makes several API calls. The reason is that the paging functionality - * isn't implemented properly yet. - * - *

It honours TradeHistoryParamCurrency for filtering to a single ccy. - */ - public List getFundingHistory(TradeHistoryParams params) throws IOException { + public List getSubAccountDepositHistory(FundingRecordParamAll params) + throws IOException { + String beforeItem = ""; + String afterItem = ""; + int maxPageSize = 100; - String fundingRecordType = null; - if (params instanceof HistoryParamsFundingType - && ((HistoryParamsFundingType) params).getType() != null) { - fundingRecordType = ((HistoryParamsFundingType) params).getType().toString().toLowerCase(); + if(params.getSubAccountId() == null || params.getSubAccountId().isEmpty()){ + throw new IllegalArgumentException("You must provide subAccountId for this call."); } + List fundingHistory = new ArrayList<>(); + + while (true) { + CoinbaseProTransfers transfers = + getTransfersByAccountId( + params.getSubAccountId(), + beforeItem, + afterItem, + maxPageSize, + Type.DEPOSIT.name().toLowerCase()); + + fundingHistory.addAll( + transfers.stream() + .map(CoinbaseProAdapters::adaptFundingRecord) + .collect(Collectors.toList())); + + if (!transfers.isEmpty()) { + afterItem = transfers.getHeader(CB_AFTER_HEADER); + beforeItem = transfers.getHeader(CB_BEFORE_HEADER); + } + + if (transfers.size() < maxPageSize) { + break; + } + } + + return fundingHistory; + } + + @Override + public List getDepositHistory(FundingRecordParamAll params) throws IOException { + String beforeItem = ""; + String afterItem = ""; int maxPageSize = 100; List fundingHistory = new ArrayList<>(); - String createdAt = null; // use to get next page while (true) { - String createdAtFinal = createdAt; CoinbaseProTransfers transfers = - getTransfers(fundingRecordType, null, null, createdAtFinal, maxPageSize); + getTransfers( + Type.DEPOSIT.name().toLowerCase(), + null, + beforeItem, + afterItem, + maxPageSize); fundingHistory.addAll( transfers.stream() .map(CoinbaseProAdapters::adaptFundingRecord) .collect(Collectors.toList())); + if (!transfers.isEmpty()) { + afterItem = transfers.getHeader(CB_AFTER_HEADER); + beforeItem = transfers.getHeader(CB_BEFORE_HEADER); + } + if (transfers.size() < maxPageSize) { break; } - - createdAt = transfers.getHeader(CB_AFTER_HEADER); } return fundingHistory; } @Override - public List getTransferHistory(TransferHistoryParam params) throws IOException { - //TODO - return AccountService.super.getTransferHistory(params); + public List getWalletTransferHistory(FundingRecordParamAll params) + throws IOException { + String beforeItem = ""; + String afterItem = ""; + int maxPageSize = 100; + + if(params.getSubAccountId() == null || params.getSubAccountId().isEmpty()){ + throw new IllegalArgumentException("You must provide subAccountId for this call."); + } + + List fundingHistory = new ArrayList<>(); + + while (true) { + CoinbaseProTransfers transfers = + getTransfersByAccountId( + params.getSubAccountId(), + beforeItem, + afterItem, + maxPageSize, + null); + + fundingHistory.addAll( + transfers.stream() + .map(CoinbaseProAdapters::adaptFundingRecord) + .collect(Collectors.toList())); + + if (!transfers.isEmpty()) { + afterItem = transfers.getHeader(CB_AFTER_HEADER); + beforeItem = transfers.getHeader(CB_BEFORE_HEADER); + } + + if (transfers.size() < maxPageSize) { + break; + } + } + + return fundingHistory; } @Override - public List getInternalTransferHistory(TransferHistoryParam params) - throws IOException { - //TODO - return AccountService.super.getInternalTransferHistory(params); + public List getLedger(FundingRecordParamAll params) throws IOException { + int maxPageSize = 100; + + if(params.getSubAccountId() == null || params.getSubAccountId().isEmpty()) { + throw new IOException("You must provide subAccountId for this call."); + } + + List ledgerList = new ArrayList<>(); + + String createdAt = null; + while (true) { + String createdAtFinal = createdAt; + + CoinbaseProLedger ledger = + getLedger( + params.getSubAccountId(), + params.getStartTime(), + params.getEndTime(), + null, + createdAtFinal, + params.getLimit(), + null + ); + + ledgerList.addAll(CoinbaseProAdapters.adaptCoinbaseProLedger(ledger)); + + if (ledger.size() < maxPageSize) { + break; + } + + createdAt = ledger.getHeader(CB_AFTER_HEADER); + } + + return ledgerList; } public static class CoinbaseProMoveFundsParams implements WithdrawFundsParams { diff --git a/xchange-coinbasepro/src/main/java/org/knowm/xchange/coinbasepro/service/CoinbaseProAccountServiceRaw.java b/xchange-coinbasepro/src/main/java/org/knowm/xchange/coinbasepro/service/CoinbaseProAccountServiceRaw.java index 072f8b0f767..94f7e18bfb8 100644 --- a/xchange-coinbasepro/src/main/java/org/knowm/xchange/coinbasepro/service/CoinbaseProAccountServiceRaw.java +++ b/xchange-coinbasepro/src/main/java/org/knowm/xchange/coinbasepro/service/CoinbaseProAccountServiceRaw.java @@ -2,7 +2,6 @@ import static org.knowm.xchange.coinbasepro.CoinbaseProResilience.PRIVATE_REST_ENDPOINT_RATE_LIMITER; -import com.fasterxml.jackson.databind.JsonNode; import java.io.IOException; import java.math.BigDecimal; import java.util.Date; @@ -16,7 +15,6 @@ import org.knowm.xchange.coinbasepro.dto.account.CoinbaseProFee; import org.knowm.xchange.coinbasepro.dto.account.CoinbaseProLedger; import org.knowm.xchange.coinbasepro.dto.account.CoinbaseProSendMoneyRequest; -import org.knowm.xchange.coinbasepro.dto.account.CoinbaseProWebsocketAuthData; import org.knowm.xchange.coinbasepro.dto.account.CoinbaseProWithdrawCryptoResponse; import org.knowm.xchange.coinbasepro.dto.account.CoinbaseProWithdrawFundsRequest; import org.knowm.xchange.coinbasepro.dto.trade.CoinbaseProWallet; @@ -25,8 +23,6 @@ import org.knowm.xchange.currency.Currency; import org.knowm.xchange.utils.DateUtils; import org.knowm.xchange.utils.timestamp.UnixTimestampFactory; -import si.mazi.rescu.ParamsDigest; -import si.mazi.rescu.RestInvocation; public class CoinbaseProAccountServiceRaw extends CoinbaseProBaseService { @@ -159,7 +155,7 @@ public String requestNewReport(CoinbasePro.CoinbaseProReportRequest reportReques } /** https://docs.pro.coinbase.com/#get-current-exchange-limits */ - public CoinbaseProTransfers getTransfersByAccountId(String accountId, Date before, Date after, int limit, String type) + public CoinbaseProTransfers getTransfersByAccountId(String accountId, String before, String after, int limit, String type) throws CoinbaseProException, IOException { return decorateApiCall( () -> @@ -169,8 +165,8 @@ public CoinbaseProTransfers getTransfersByAccountId(String accountId, Date befor UnixTimestampFactory.INSTANCE.createValue(), passphrase, accountId, - (before == null) ? null : DateUtils.toISODateString(before), - (after == null) ? null : DateUtils.toISODateString(after), + before, + after, limit, type)) .withRateLimiter(rateLimiter(PRIVATE_REST_ENDPOINT_RATE_LIMITER)) diff --git a/xchange-coinbasepro/src/main/java/org/knowm/xchange/coinbasepro/service/CoinbaseProMarketDataService.java b/xchange-coinbasepro/src/main/java/org/knowm/xchange/coinbasepro/service/CoinbaseProMarketDataService.java index ad6f84bec5c..bcf2c03d780 100644 --- a/xchange-coinbasepro/src/main/java/org/knowm/xchange/coinbasepro/service/CoinbaseProMarketDataService.java +++ b/xchange-coinbasepro/src/main/java/org/knowm/xchange/coinbasepro/service/CoinbaseProMarketDataService.java @@ -1,10 +1,8 @@ package org.knowm.xchange.coinbasepro.service; -import static java.util.stream.Collectors.toList; - import java.io.IOException; -import java.util.Arrays; import java.util.List; +import java.util.Map; import org.knowm.xchange.client.ResilienceRegistries; import org.knowm.xchange.coinbasepro.CoinbaseProAdapters; import org.knowm.xchange.coinbasepro.CoinbaseProExchange; @@ -16,6 +14,8 @@ import org.knowm.xchange.dto.marketdata.OrderBook; import org.knowm.xchange.dto.marketdata.Ticker; import org.knowm.xchange.dto.marketdata.Trades; +import org.knowm.xchange.dto.meta.CurrencyMetaData; +import org.knowm.xchange.dto.meta.InstrumentMetaData; import org.knowm.xchange.exceptions.RateLimitExceededException; import org.knowm.xchange.instrument.Instrument; import org.knowm.xchange.service.marketdata.MarketDataService; @@ -134,16 +134,12 @@ public Trades getTrades(CurrencyPair currencyPair, Object... args) } @Override - public List getCurrencies() throws IOException { - return Arrays.stream(getCoinbaseProCurrencies()) - .map(CoinbaseProAdapters::adaptCurrency) - .collect(toList()); + public Map getCurrencies() throws IOException { + return CoinbaseProAdapters.adaptCoinbaseProCurrencies(getCoinbaseProCurrencies()); } @Override - public List getInstruments() throws IOException { - return Arrays.stream(getCoinbaseProProducts()) - .map(CoinbaseProAdapters::adaptCurrencyPair) - .collect(toList()); + public Map getInstruments() throws IOException { + return CoinbaseProAdapters.adaptCoinbaseProCurrencyPairs(getCoinbaseProProducts()); } } diff --git a/xchange-coinbasepro/src/test/java/org/knowm/xchange/coinbasepro/CoinbaseProPrivateIntegration.java b/xchange-coinbasepro/src/test/java/org/knowm/xchange/coinbasepro/CoinbaseProPrivateIntegration.java index 074ebb3bd4d..b6524964fe5 100644 --- a/xchange-coinbasepro/src/test/java/org/knowm/xchange/coinbasepro/CoinbaseProPrivateIntegration.java +++ b/xchange-coinbasepro/src/test/java/org/knowm/xchange/coinbasepro/CoinbaseProPrivateIntegration.java @@ -4,26 +4,35 @@ import java.io.IOException; import java.math.BigDecimal; +import java.util.Date; +import java.util.List; +import org.junit.Ignore; import org.junit.Test; import org.knowm.xchange.Exchange; +import org.knowm.xchange.coinbasepro.dto.account.CoinbaseProAccount; import org.knowm.xchange.coinbasepro.dto.account.CoinbaseProFundingHistoryParams; +import org.knowm.xchange.coinbasepro.service.CoinbaseProAccountService; import org.knowm.xchange.currency.CurrencyPair; import org.knowm.xchange.dto.account.AccountInfo; import org.knowm.xchange.dto.account.FundingRecord; import org.knowm.xchange.dto.account.FundingRecord.Type; import org.knowm.xchange.dto.account.Wallet.WalletFeature; +import org.knowm.xchange.dto.account.params.FundingRecordParamAll; import org.knowm.xchange.dto.trade.UserTrades; import org.knowm.xchange.instrument.Instrument; import org.knowm.xchange.service.trade.params.DefaultTradeHistoryParamInstrument; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +@Ignore public class CoinbaseProPrivateIntegration { private final Exchange exchange = CoinbaseProPrivateInit.getCoinbasePrivateInstance(); private static final Logger LOG = LoggerFactory.getLogger(CoinbaseProPrivateIntegration.class); Instrument instrument = new CurrencyPair("BTC/USD"); + private final String SUB_ACCOUNT_ID = ""; + /** * AccountService tests */ @@ -34,7 +43,122 @@ public void testAccountInfo() throws IOException { LOG.info(accountInfo.toString()); assertThat(accountInfo.getWallet()).isNotNull(); assertThat(accountInfo.getWallet(WalletFeature.FUNDING)).isNotNull(); - assertThat(accountInfo.getWallets().size()).isEqualTo(1); + assertThat(accountInfo.getWallets().size()).isGreaterThanOrEqualTo(1); + } + + @Test + public void testSubAccountInfo() throws IOException { + AccountInfo accountInfo = exchange.getAccountService().getSubAccountInfo(SUB_ACCOUNT_ID); + + LOG.info(accountInfo.toString()); + assertThat(accountInfo.getWallet()).isNotNull(); + assertThat(accountInfo.getWallet(WalletFeature.FUNDING)).isNotNull(); + assertThat(accountInfo.getWallets().size()).isGreaterThanOrEqualTo(1); + } + + @Test + public void testInternalTransfer() throws IOException { + + List internalTransfers = exchange + .getAccountService() + .getInternalTransferHistory(FundingRecordParamAll.builder().build()); + + internalTransfers.forEach( + fundingRecord -> { + LOG.info(fundingRecord.toString()); + assertThat(fundingRecord).isNotNull(); + assertThat(fundingRecord.getDate()).isNotNull(); + assertThat(fundingRecord.getAmount()).isGreaterThanOrEqualTo(BigDecimal.ZERO); + assertThat(fundingRecord.getType()).isInstanceOf(FundingRecord.Type.class); + assertThat(fundingRecord.getStatus()).isInstanceOf(FundingRecord.Status.class); + assertThat(fundingRecord.getCurrency()).isNotNull(); + }); + + assertThat(internalTransfers.size()).isGreaterThanOrEqualTo(1); + } + + @Test + public void testDepositHistory() throws IOException { + + List internalTransfers = exchange + .getAccountService() + .getDepositHistory(FundingRecordParamAll.builder().build()); + + internalTransfers.forEach( + fundingRecord -> { + LOG.info(fundingRecord.toString()); + assertThat(fundingRecord).isNotNull(); + assertThat(fundingRecord.getDate()).isNotNull(); + assertThat(fundingRecord.getAmount()).isGreaterThanOrEqualTo(BigDecimal.ZERO); + assertThat(fundingRecord.getType()).isEqualTo(Type.DEPOSIT); + assertThat(fundingRecord.getStatus()).isInstanceOf(FundingRecord.Status.class); + assertThat(fundingRecord.getCurrency()).isNotNull(); + }); + + assertThat(internalTransfers.size()).isGreaterThanOrEqualTo(1); + } + + @Test + public void testWithdrawHistory() throws IOException { + + List internalTransfers = exchange + .getAccountService() + .getWithdrawHistory(FundingRecordParamAll.builder().build()); + + internalTransfers.forEach( + fundingRecord -> { + LOG.info(fundingRecord.toString()); + assertThat(fundingRecord).isNotNull(); + assertThat(fundingRecord.getDate()).isNotNull(); + assertThat(fundingRecord.getAmount()).isGreaterThanOrEqualTo(BigDecimal.ZERO); + assertThat(fundingRecord.getType()).isEqualTo(Type.WITHDRAW); + assertThat(fundingRecord.getStatus()).isInstanceOf(FundingRecord.Status.class); + assertThat(fundingRecord.getCurrency()).isNotNull(); + }); + + assertThat(internalTransfers.size()).isGreaterThanOrEqualTo(1); + } + + @Test + public void testWalletTransferHistory() throws IOException { + + List internalTransfers = exchange + .getAccountService() + .getWalletTransferHistory(FundingRecordParamAll.builder().subAccountId(SUB_ACCOUNT_ID).build()); + + internalTransfers.forEach( + fundingRecord -> { + LOG.info(fundingRecord.toString()); + assertThat(fundingRecord).isNotNull(); + assertThat(fundingRecord.getDate()).isNotNull(); + assertThat(fundingRecord.getAmount()).isGreaterThanOrEqualTo(BigDecimal.ZERO); + assertThat(fundingRecord.getType()).isInstanceOf(FundingRecord.Type.class); + assertThat(fundingRecord.getStatus()).isInstanceOf(FundingRecord.Status.class); + assertThat(fundingRecord.getCurrency()).isNotNull(); + }); + + assertThat(internalTransfers.size()).isGreaterThanOrEqualTo(1); + } + + @Test + public void testSubAccountDepositHistory() throws IOException { + + List internalTransfers = exchange + .getAccountService() + .getSubAccountDepositHistory(FundingRecordParamAll.builder().subAccountId(SUB_ACCOUNT_ID).build()); + + internalTransfers.forEach( + fundingRecord -> { + LOG.info(fundingRecord.toString()); + assertThat(fundingRecord).isNotNull(); + assertThat(fundingRecord.getDate()).isNotNull(); + assertThat(fundingRecord.getAmount()).isGreaterThanOrEqualTo(BigDecimal.ZERO); + assertThat(fundingRecord.getType()).isInstanceOf(FundingRecord.Type.class); + assertThat(fundingRecord.getStatus()).isInstanceOf(FundingRecord.Status.class); + assertThat(fundingRecord.getCurrency()).isNotNull(); + }); + + assertThat(internalTransfers.size()).isGreaterThanOrEqualTo(1); } @Test @@ -96,4 +220,26 @@ public void testTradeHistory() throws IOException { assertThat(userTrade.getFeeCurrency()).isNotNull(); }); } + + @Test + public void testLedger() throws IOException { + CoinbaseProAccountService service = (CoinbaseProAccountService) exchange.getAccountService(); + CoinbaseProAccount account = service.getCoinbaseProAccountInfo()[1]; + + FundingRecordParamAll params = FundingRecordParamAll.builder() + .subAccountId(account.getId()) + .build(); + + service.getLedger(params).forEach(record -> { + LOG.info(record.toString()); + assertThat(record).isNotNull(); + assertThat(record.getInternalId()).isNotNull(); + assertThat(record.getAmount()).isInstanceOf(BigDecimal.class); + assertThat(record.getDate()).isInstanceOf(Date.class); + assertThat(record.getBalance()).isInstanceOf(BigDecimal.class); + assertThat(record.getType()).isInstanceOf(Type.class); + assertThat(record.getDescription()).isNotNull(); + }); + + } } diff --git a/xchange-coinbasepro/src/test/java/org/knowm/xchange/coinbasepro/CoinbaseProPrivateRawIntegration.java b/xchange-coinbasepro/src/test/java/org/knowm/xchange/coinbasepro/CoinbaseProPrivateRawIntegration.java index 54bc0ebe3d4..db3e5bc1002 100644 --- a/xchange-coinbasepro/src/test/java/org/knowm/xchange/coinbasepro/CoinbaseProPrivateRawIntegration.java +++ b/xchange-coinbasepro/src/test/java/org/knowm/xchange/coinbasepro/CoinbaseProPrivateRawIntegration.java @@ -60,34 +60,6 @@ public void testCoinbaseAccountById() throws IOException { assertThat(account.isTradingEnabled()).isTrue(); } - @Test - public void testLedger() throws IOException { - CoinbaseProAccountService service = (CoinbaseProAccountService) exchange.getAccountService(); - CoinbaseProAccount account = service.getCoinbaseProAccountInfo()[1]; - - CoinbaseProFundingHistoryParams params = new CoinbaseProFundingHistoryParams(); - - params.setAccountId(account.getId()); - - - service.getLedgerWithPagination(params).forEach(coinbaseProLedgerDto -> { - LOG.info(coinbaseProLedgerDto.toString()); - assertThat(coinbaseProLedgerDto).isNotNull(); - assertThat(coinbaseProLedgerDto.getId()).isNotNull(); - assertThat(coinbaseProLedgerDto.getAmount()).isInstanceOf(BigDecimal.class); - assertThat(coinbaseProLedgerDto.getCreatedAt()).isInstanceOf(Date.class); - assertThat(coinbaseProLedgerDto.getBalance()).isInstanceOf(BigDecimal.class); - assertThat(coinbaseProLedgerDto.getType()).isInstanceOf(CoinbaseProLedgerTxType.class); - assertThat(coinbaseProLedgerDto.getDetails()).isNotNull(); - if(coinbaseProLedgerDto.getType().equals(CoinbaseProLedgerTxType.match)){ - assertThat(coinbaseProLedgerDto.getDetails().getOrderId()).isNotNull(); - assertThat(coinbaseProLedgerDto.getDetails().getProductId()).isInstanceOf(Instrument.class); - assertThat(coinbaseProLedgerDto.getDetails().getTradeId()).isNotNull(); - } - }); - - } - /** * TradeServiceRaw tests */ @@ -116,62 +88,4 @@ public void testTradeHistoryRawData() throws IOException { LOG.info(coinbaseProFill.toString()); }); } - - @Test - public void testCoinbaseTransfers() throws IOException { - CoinbaseProAccountServiceRaw raw = (CoinbaseProAccountServiceRaw) exchange.getAccountService(); - - String btcAccountId = Arrays.stream(raw.getCoinbaseProAccountInfo()).filter(coinbaseProAccount -> coinbaseProAccount.getCurrency().equals("BTC")).findFirst().get().getId(); - - CoinbaseProTransfers transfers = - raw.getTransfersByAccountId( - btcAccountId, - null, - Date.from(Instant.now()), - 100, - null); - - assertThat(transfers.getResponseHeaders().size()).isPositive(); - assertThat(transfers.getHeader("Cb-After")).isNotNull(); - - transfers.forEach(coinbaseProTransfer -> { - LOG.info(coinbaseProTransfer.toString()); - assertThat(coinbaseProTransfer).isNotNull(); - assertThat(coinbaseProTransfer.getId()).isNotNull(); - assertThat(coinbaseProTransfer.getType()).isInstanceOf(FundingRecord.Type.class); - assertThat(coinbaseProTransfer.getCreatedAt()).isInstanceOf(Date.class); - assertThat(coinbaseProTransfer.getCompletedAt()).isInstanceOf(Date.class); - if(coinbaseProTransfer.getType().isInflowing()){ - assertThat(coinbaseProTransfer.getProcessedAt()).isInstanceOf(Date.class); - assertThat(coinbaseProTransfer.getAmount()).isGreaterThan(BigDecimal.ZERO); - assertThat(coinbaseProTransfer.getCurrency()).isNotNull(); - assertThat(coinbaseProTransfer.getDetails()).isNotNull(); - assertThat(coinbaseProTransfer.getDetails().getCoinbaseAccountId()).isNotNull(); - assertThat(coinbaseProTransfer.getDetails().getCoinbaseTransactionId()).isNotNull(); - } - }); - - CoinbaseProFundingHistoryParams fundingHistoryParams = (CoinbaseProFundingHistoryParams) exchange.getAccountService().createFundingHistoryParams(); - - fundingHistoryParams.setLimit(50); - fundingHistoryParams.setStartTime(Date.from(Instant.now())); - fundingHistoryParams.setEndTime(Date.from(Instant.now())); - fundingHistoryParams.setType(FundingRecord.Type.WITHDRAW); - - CoinbaseProAccountService accountService = (CoinbaseProAccountService) exchange.getAccountService(); - - accountService.getTransfersWithPagination(fundingHistoryParams).getFundingRecords().forEach(fundingRecord -> { - LOG.info(fundingRecord.toString()); - assertThat(fundingRecord).isNotNull(); - assertThat(fundingRecord.getAddress()).isNotNull(); - assertThat(fundingRecord.getAddressTag()).isNotNull(); - assertThat(fundingRecord.getDate()).isNotNull(); - assertThat(fundingRecord.getCurrency()).isInstanceOf(Currency.class); - assertThat(fundingRecord.getAmount()).isGreaterThanOrEqualTo(BigDecimal.ZERO); - assertThat(fundingRecord.getInternalId()).isNotNull(); - assertThat(fundingRecord.getBlockchainTransactionHash()).isNotNull(); - assertThat(fundingRecord.getType()).isInstanceOf(FundingRecord.Type.class); - assertThat(fundingRecord.getStatus()).isInstanceOf(FundingRecord.Status.class); - }); - } } diff --git a/xchange-coinbasepro/src/test/java/org/knowm/xchange/coinbasepro/CoinbaseProPublicTest.java b/xchange-coinbasepro/src/test/java/org/knowm/xchange/coinbasepro/CoinbaseProPublicTest.java index 471f77365f5..14d4c944f15 100644 --- a/xchange-coinbasepro/src/test/java/org/knowm/xchange/coinbasepro/CoinbaseProPublicTest.java +++ b/xchange-coinbasepro/src/test/java/org/knowm/xchange/coinbasepro/CoinbaseProPublicTest.java @@ -2,13 +2,9 @@ import static org.assertj.core.api.AssertionsForClassTypes.assertThat; -import java.math.BigDecimal; import org.junit.Test; import org.knowm.xchange.Exchange; import org.knowm.xchange.ExchangeFactory; -import org.knowm.xchange.coinbasepro.dto.marketdata.CoinbaseProCurrency; -import org.knowm.xchange.coinbasepro.dto.marketdata.CoinbaseProProduct; -import org.knowm.xchange.coinbasepro.dto.marketdata.CoinbaseProProduct.CoinbaseProProductStatus; import org.knowm.xchange.coinbasepro.service.CoinbaseProMarketDataService; import org.knowm.xchange.currency.Currency; import org.knowm.xchange.currency.CurrencyPair; @@ -23,57 +19,27 @@ public class CoinbaseProPublicTest { @Test public void testCoinbaseInstruments() throws Exception { - for (CoinbaseProProduct coinbaseProProduct : marketDataService.getCoinbaseProProducts()) { - LOG.info(coinbaseProProduct.toString()); - assertThat(coinbaseProProduct).isInstanceOf(CoinbaseProProduct.class); - assertThat(coinbaseProProduct.getId()).isNotNull(); - assertThat(coinbaseProProduct.getBaseCurrency()).isNotNull(); - assertThat(coinbaseProProduct.getQuoteCurrency()).isNotNull(); - assertThat(coinbaseProProduct.getQuoteIncrement()).isGreaterThan(BigDecimal.ZERO); - assertThat(coinbaseProProduct.getBaseIncrement()).isGreaterThan(BigDecimal.ZERO); - assertThat(coinbaseProProduct.getDisplayName()).isNotNull(); - assertThat(coinbaseProProduct.getMinMarketFunds()).isGreaterThan(BigDecimal.ZERO); - assertThat(coinbaseProProduct.isMarginEnabled()).isNotNull(); - assertThat(coinbaseProProduct.isPostOnly()).isNotNull(); - assertThat(coinbaseProProduct.isLimitOnly()).isNotNull(); - assertThat(coinbaseProProduct.isCancelOnly()).isNotNull(); - assertThat(coinbaseProProduct.getStatus()).isInstanceOf(CoinbaseProProductStatus.class); - assertThat(coinbaseProProduct.getStatusMessage()).isNotNull(); - assertThat(coinbaseProProduct.isTradingDisabled()).isNotNull(); - assertThat(coinbaseProProduct.isFxStablecoin()).isNotNull(); - assertThat(coinbaseProProduct.getMaxSlippagePercentage()).isGreaterThan(BigDecimal.ZERO); - assertThat(coinbaseProProduct.isAuctionMode()).isNotNull(); - if(coinbaseProProduct.getBaseCurrency().equals("USDC")){ - assertThat(coinbaseProProduct.getHighBidLimitPercentage()).isGreaterThan(BigDecimal.ZERO); - } - } - marketDataService.getInstruments().forEach(instrument -> { - LOG.info(instrument.toString()); + marketDataService.getInstruments().forEach((instrument, instrumentMetaData) -> { + LOG.info(instrument.toString()+ "--" + instrumentMetaData.toString()); assertThat(instrument).isInstanceOf(CurrencyPair.class); + assertThat(instrumentMetaData.getPriceStepSize()).isNotNull(); + assertThat(instrumentMetaData.getAmountStepSize()).isNotNull(); + assertThat(instrumentMetaData.getVolumeScale()).isNotNull(); + assertThat(instrumentMetaData.getPriceScale()).isNotNull(); + assertThat(instrumentMetaData.getTradingFeeCurrency()).isNotNull(); + assertThat(instrumentMetaData.getTradingFee()).isNotNull(); }); } @Test public void testCoinbaseCurrency() throws Exception { - for (CoinbaseProCurrency coinbaseProCurrency : marketDataService.getCoinbaseProCurrencies()) { - LOG.info(coinbaseProCurrency.toString()); - assertThat(coinbaseProCurrency).isInstanceOf(CoinbaseProCurrency.class); - assertThat(coinbaseProCurrency.getId()).isNotNull(); - assertThat(coinbaseProCurrency.getName()).isNotNull(); - assertThat(coinbaseProCurrency.getMinSize()).isGreaterThan(BigDecimal.ZERO); - assertThat(coinbaseProCurrency.getStatus()).isNotNull(); - assertThat(coinbaseProCurrency.getMessage()).isNotNull(); - assertThat(coinbaseProCurrency.getMaxPrecision()).isGreaterThan(BigDecimal.ZERO); - assertThat(coinbaseProCurrency.getConvertibleTo().size()).isNotNegative(); - assertThat(coinbaseProCurrency.getDetails()).isNotNull(); - assertThat(coinbaseProCurrency.getDefaultNetwork()).isNotNull(); - assertThat(coinbaseProCurrency.getSupportedNetworks().size()).isNotNegative(); - } - - marketDataService.getCurrencies().forEach(currency -> { - LOG.info(currency.toString()); + marketDataService.getCurrencies().forEach((currency, currencyMetaData) -> { + LOG.info(currency.toString() + "--" + currencyMetaData.toString()); assertThat(currency).isInstanceOf(Currency.class); + assertThat(currencyMetaData.getMinWithdrawalAmount()).isNotNull(); + assertThat(currencyMetaData.getWalletHealth()).isNotNull(); + assertThat(currencyMetaData.getScale()).isNotNull(); }); } } diff --git a/xchange-coinbasepro/src/test/java/org/knowm/xchange/coinbasepro/dto/CoinbaseProMetadataTest.java b/xchange-coinbasepro/src/test/java/org/knowm/xchange/coinbasepro/dto/CoinbaseProMetadataTest.java deleted file mode 100644 index e5bdf29e3c9..00000000000 --- a/xchange-coinbasepro/src/test/java/org/knowm/xchange/coinbasepro/dto/CoinbaseProMetadataTest.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.knowm.xchange.coinbasepro.dto; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.fasterxml.jackson.databind.ObjectMapper; -import java.io.IOException; -import java.io.InputStream; -import org.knowm.xchange.Exchange; -import org.knowm.xchange.ExchangeFactory; -import org.knowm.xchange.ExchangeSpecification; -import org.knowm.xchange.coinbasepro.CoinbaseProAdapters; -import org.knowm.xchange.coinbasepro.CoinbaseProExchange; -import org.knowm.xchange.coinbasepro.dto.marketdata.CoinbaseProCurrency; -import org.knowm.xchange.coinbasepro.dto.marketdata.CoinbaseProProduct; -import org.knowm.xchange.currency.CurrencyPair; -import org.knowm.xchange.dto.meta.ExchangeMetaData; -import si.mazi.rescu.serialization.jackson.DefaultJacksonObjectMapperFactory; -import si.mazi.rescu.serialization.jackson.JacksonObjectMapperFactory; - -public class CoinbaseProMetadataTest { - - // @Test - public void unmarshalTest() throws IOException { - - JacksonObjectMapperFactory factory = new DefaultJacksonObjectMapperFactory(); - ObjectMapper mapper = factory.createObjectMapper(); - - InputStream is = - getClass().getResourceAsStream("/org/knowm/xchange/coinbasepro/dto/products.json"); - CoinbaseProProduct[] products = mapper.readValue(is, CoinbaseProProduct[].class); - assertThat(products).hasSize(10); - - ExchangeSpecification specification = new ExchangeSpecification(CoinbaseProExchange.class); - specification.setShouldLoadRemoteMetaData(false); - Exchange exchange = ExchangeFactory.INSTANCE.createExchange(specification); - ExchangeMetaData exchangeMetaData = exchange.getExchangeMetaData(); - exchangeMetaData = - CoinbaseProAdapters.adaptToExchangeMetaData( - exchangeMetaData, products, new CoinbaseProCurrency[] {}); - assertThat(exchangeMetaData.getInstruments().get(CurrencyPair.ETC_BTC).getPriceScale()) - .isEqualTo(5); - } -} diff --git a/xchange-core/src/main/java/org/knowm/xchange/dto/account/params/FundingRecordParamAll.java b/xchange-core/src/main/java/org/knowm/xchange/dto/account/params/FundingRecordParamAll.java index e40f682115d..1165125cf80 100644 --- a/xchange-core/src/main/java/org/knowm/xchange/dto/account/params/FundingRecordParamAll.java +++ b/xchange-core/src/main/java/org/knowm/xchange/dto/account/params/FundingRecordParamAll.java @@ -29,4 +29,4 @@ public class FundingRecordParamAll { public static FundingRecordParamAllBuilder builder() { return new FundingRecordParamAllBuilder().usePagination(true); } -} +} \ No newline at end of file