Skip to content

Commit

Permalink
[CoinbasePro] Updating/Adding support for specified AccountService en…
Browse files Browse the repository at this point in the history
…dpoints and some for TradeService endpoints.
  • Loading branch information
makarid committed Aug 16, 2023
1 parent 916b9a6 commit 30ca446
Show file tree
Hide file tree
Showing 21 changed files with 722 additions and 538 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
import org.knowm.xchange.coinbasepro.dto.CoinbaseProException;
import org.knowm.xchange.coinbasepro.dto.CoinbaseProTrades;
import org.knowm.xchange.coinbasepro.dto.CoinbaseProTransfers;
import org.knowm.xchange.coinbasepro.dto.account.CoinbaseProAccount;
import org.knowm.xchange.coinbasepro.dto.account.CoinbaseProFee;
import org.knowm.xchange.coinbasepro.dto.account.CoinbaseProLedger;
import org.knowm.xchange.coinbasepro.dto.account.CoinbaseProLedgerDto;
import org.knowm.xchange.coinbasepro.dto.account.CoinbaseProSendMoneyRequest;
import org.knowm.xchange.coinbasepro.dto.account.CoinbaseProWithdrawCryptoResponse;
import org.knowm.xchange.coinbasepro.dto.account.CoinbaseProWithdrawFundsRequest;
Expand All @@ -32,15 +35,14 @@
import org.knowm.xchange.coinbasepro.dto.marketdata.CoinbaseProProductTicker;
import org.knowm.xchange.coinbasepro.dto.marketdata.CoinbaseProStats;
import org.knowm.xchange.coinbasepro.dto.marketdata.CoinbaseProTrade;
import org.knowm.xchange.coinbasepro.dto.trade.CoinbaseProAccount;
import org.knowm.xchange.coinbasepro.dto.trade.CoinbaseProAccountAddress;
import org.knowm.xchange.coinbasepro.dto.trade.CoinbaseProWallet;
import org.knowm.xchange.coinbasepro.dto.trade.CoinbaseProWalletAddress;
import org.knowm.xchange.coinbasepro.dto.trade.CoinbaseProFill;
import org.knowm.xchange.coinbasepro.dto.trade.CoinbaseProIdResponse;
import org.knowm.xchange.coinbasepro.dto.trade.CoinbaseProOrder;
import org.knowm.xchange.coinbasepro.dto.trade.CoinbaseProPlaceOrder;
import org.knowm.xchange.coinbasepro.dto.trade.CoinbaseProSendMoneyResponse;
import org.knowm.xchange.utils.DateUtils;
import si.mazi.rescu.HttpStatusIOException;
import si.mazi.rescu.ParamsDigest;

@Path("/")
Expand Down Expand Up @@ -110,13 +112,23 @@ CoinbaseProCandle[] getHistoricalCandles(
/** Authenticated calls */
@GET
@Path("accounts")
org.knowm.xchange.coinbasepro.dto.account.CoinbaseProAccount[] getAccounts(
CoinbaseProAccount[] getAccounts(
@HeaderParam("CB-ACCESS-KEY") String apiKey,
@HeaderParam("CB-ACCESS-SIGN") ParamsDigest signer,
@HeaderParam("CB-ACCESS-TIMESTAMP") long timestamp,
@HeaderParam("CB-ACCESS-PASSPHRASE") String passphrase)
throws CoinbaseProException, IOException;

@GET
@Path("accounts/{account_id}")
CoinbaseProAccount getAccountById(
@HeaderParam("CB-ACCESS-KEY") String apiKey,
@HeaderParam("CB-ACCESS-SIGN") ParamsDigest signer,
@HeaderParam("CB-ACCESS-TIMESTAMP") long timestamp,
@HeaderParam("CB-ACCESS-PASSPHRASE") String passphrase,
@PathParam("account_id") String accountId)
throws CoinbaseProException, IOException;

@GET
@Path("fees")
CoinbaseProFee getFees(
Expand Down Expand Up @@ -233,32 +245,45 @@ CoinbaseProSendMoneyResponse sendMoney(
@GET
@Path("accounts/{account_id}/ledger")
@Consumes(MediaType.APPLICATION_JSON)
List<Map<?, ?>> ledger(
CoinbaseProLedger ledger(
@HeaderParam("CB-ACCESS-KEY") String apiKey,
@HeaderParam("CB-ACCESS-SIGN") ParamsDigest signer,
@HeaderParam("CB-ACCESS-TIMESTAMP") long timestamp,
@HeaderParam("CB-ACCESS-PASSPHRASE") String passphrase,
@PathParam("account_id") String accountId,
@QueryParam("after") String startingOrderId)
@QueryParam("start_date") String startDate,
@QueryParam("end_date") String endDate,
@QueryParam("before") String beforeId,
@QueryParam("after") String afterId,
@QueryParam("limit") Integer limit,
@QueryParam("profile_id") String profileId)
throws CoinbaseProException, IOException;

/**
* Lists past withdrawals and deposits for an account.
*/
@GET
@Path("accounts/{account_id}/transfers")
@Consumes(MediaType.APPLICATION_JSON)
CoinbaseProTransfers transfers(
CoinbaseProTransfers getTransfersByAccountId(
@HeaderParam("CB-ACCESS-KEY") String apiKey,
@HeaderParam("CB-ACCESS-SIGN") ParamsDigest signer,
@HeaderParam("CB-ACCESS-TIMESTAMP") long timestamp,
@HeaderParam("CB-ACCESS-PASSPHRASE") String passphrase,
@PathParam("account_id") String accountId,
@QueryParam("profile_id") String profileId,
@QueryParam("before") String beforeDate,
@QueryParam("after") String afterDate,
@QueryParam("limit") Integer limit,
@QueryParam("after") String createdAtDate);
@QueryParam("type") String type) // Possible types [deposit, withdraw, internal_deposit, internal_withdraw]
throws CoinbaseProException, IOException;

/**
* Gets a list of in-progress and completed transfers of funds in/out of any of the user's accounts.
*/
@GET
@Path("transfers")
@Consumes(MediaType.APPLICATION_JSON)
CoinbaseProTransfers transfers(
CoinbaseProTransfers getTransfers(
@HeaderParam("CB-ACCESS-KEY") String apiKey,
@HeaderParam("CB-ACCESS-SIGN") ParamsDigest signer,
@HeaderParam("CB-ACCESS-TIMESTAMP") long timestamp,
Expand All @@ -267,7 +292,8 @@ CoinbaseProTransfers transfers(
@QueryParam("profile_id") String profileId,
@QueryParam("before") String beforeDate,
@QueryParam("after") String afterDate,
@QueryParam("limit") Integer limit);
@QueryParam("limit") Integer limit) // Possible types [deposit, withdraw, internal_deposit, internal_withdraw]
throws CoinbaseProException, IOException;

@POST
@Path("reports")
Expand Down Expand Up @@ -301,25 +327,26 @@ CoinbaseProWithdrawCryptoResponse withdrawCrypto(
@HeaderParam("CB-ACCESS-TIMESTAMP") long timestamp,
@HeaderParam("CB-ACCESS-PASSPHRASE") String passphrase,
CoinbaseProWithdrawFundsRequest request)
throws HttpStatusIOException;
throws CoinbaseProException, IOException;

@GET
@Path("coinbase-accounts")
CoinbaseProAccount[] getCoinbaseProAccounts(
CoinbaseProWallet[] getCoinbaseProWallets(
@HeaderParam("CB-ACCESS-KEY") String apiKey,
@HeaderParam("CB-ACCESS-SIGN") ParamsDigest signer,
@HeaderParam("CB-ACCESS-TIMESTAMP") long timestamp,
@HeaderParam("CB-ACCESS-PASSPHRASE") String passphrase)
throws HttpStatusIOException;
throws CoinbaseProException, IOException;

@POST
@Path("coinbase-accounts/{account_id}/addresses")
CoinbaseProAccountAddress getCoinbaseProAccountAddress(
CoinbaseProWalletAddress getCoinbaseProWalletAddress(
@HeaderParam("CB-ACCESS-KEY") String apiKey,
@HeaderParam("CB-ACCESS-SIGN") ParamsDigest signer,
@HeaderParam("CB-ACCESS-TIMESTAMP") long timestamp,
@HeaderParam("CB-ACCESS-PASSPHRASE") String passphrase,
@PathParam("account_id") String accountId);
@PathParam("account_id") String accountId)
throws CoinbaseProException, IOException;

@GET
@Path("/users/self/verify")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public static Wallet adaptAccountInfo(CoinbaseProAccount[] coinbaseProAccounts)
coinbaseProAccount.getHold()));
}

return Wallet.Builder.from(balances).id(coinbaseProAccounts[0].getProfile_id()).build();
return Wallet.Builder.from(balances).id(coinbaseProAccounts[0].getProfileId()).build();
}

@SuppressWarnings("unchecked")
Expand Down Expand Up @@ -386,12 +386,9 @@ public static ExchangeMetaData adaptToExchangeMetaData(
pair,
new InstrumentMetaData.Builder()
.tradingFee(new BigDecimal("0.50"))
.minimumAmount(product.getBaseMinSize())
.maximumAmount(product.getBaseMaxSize())
.volumeScale(baseScale)
.priceScale(priceScale)
.counterMinimumAmount(product.getMinMarketFunds())
.counterMaximumAmount(product.getMaxMarketFunds())
.feeTiers(staticMetaData != null ? staticMetaData.getFeeTiers() : null)
.tradingFeeCurrency(pair.counter)
.marketOrderEnabled(marketOrderAllowed)
Expand Down Expand Up @@ -425,6 +422,12 @@ public static String adaptProductID(CurrencyPair currencyPair) {
: currencyPair.base.getCurrencyCode() + "-" + currencyPair.counter.getCurrencyCode();
}

public static String adaptProductID(Instrument instrument) {
return instrument == null
? null
: instrument.getBase().getCurrencyCode() + "-" + instrument.getCounter().getCurrencyCode();
}

public static CoinbaseProPlaceOrder.Side adaptSide(OrderType orderType) {
return orderType == OrderType.ASK
? CoinbaseProPlaceOrder.Side.sell
Expand Down Expand Up @@ -508,8 +511,8 @@ public static FundingRecord adaptFundingRecord(
Currency currency, 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;
Expand All @@ -523,12 +526,12 @@ public static FundingRecord adaptFundingRecord(
return new FundingRecord(
address,
coinbaseProTransfer.getDetails().getDestinationTag(),
coinbaseProTransfer.createdAt(),
coinbaseProTransfer.getCreatedAt(),
currency,
coinbaseProTransfer.amount(),
coinbaseProTransfer.getAmount(),
coinbaseProTransfer.getId(),
transactionHash,
coinbaseProTransfer.type(),
coinbaseProTransfer.getType(),
status,
null,
null,
Expand Down
Loading

0 comments on commit 30ca446

Please sign in to comment.