Skip to content

Commit

Permalink
Merge pull request #1 from duanemay/testing
Browse files Browse the repository at this point in the history
Fix Withdrawals
  • Loading branch information
duanemay committed Nov 12, 2017
2 parents f56cfa4 + 71ed9de commit 02e41b4
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 15 deletions.
@@ -0,0 +1,44 @@
package com.coinbase.exchange.api.entity;

import java.math.BigDecimal;

/**
* Created by robevansuk on 15/02/2017.
*/
public class CryptoPaymentRequest
{

String currency;
BigDecimal amount;
String crypto_address;

public CryptoPaymentRequest(BigDecimal amount, String currency, String crypto_address) {
this.currency = currency;
this.amount = amount;
this.crypto_address = crypto_address;
}

public String getCurrency() {
return currency;
}

public void setCurrency(String currency) {
this.currency = currency;
}

public BigDecimal getAmount() {
return amount;
}

public void setAmount(BigDecimal amount) {
this.amount = amount;
}

public String getCrypto_address() {
return crypto_address;
}

public void setCrypto_address(String crypto_address) {
this.crypto_address = crypto_address;
}
}
@@ -1,5 +1,7 @@
package com.coinbase.exchange.api.withdrawals;

import com.coinbase.exchange.api.entity.CoinbasePaymentRequest;
import com.coinbase.exchange.api.entity.CryptoPaymentRequest;
import com.coinbase.exchange.api.exchange.GdaxExchange;
import com.coinbase.exchange.api.entity.PaymentRequest;
import com.coinbase.exchange.api.entity.PaymentResponse;
Expand All @@ -17,7 +19,7 @@ public class WithdrawalsService {

static final String WITHDRAWALS_ENDPOINT = "/withdrawals";
static final String PAYMENT_METHOD = "/payment-method";
static final String COINBASE = "/coinbase";
static final String COINBASE = "/coinbase-account";
static final String CRYPTO = "/crypto";


Expand All @@ -26,25 +28,23 @@ public class WithdrawalsService {

// TODO untested - needs a payment method id.
public PaymentResponse makeWithdrawalToPaymentMethod(BigDecimal amount, String currency, String paymentMethodId) {
return makeWithdrawal(amount, currency, paymentMethodId, PAYMENT_METHOD);
PaymentRequest withdrawalRequest = new PaymentRequest(amount, currency, paymentMethodId);
return gdaxExchange.post(WITHDRAWALS_ENDPOINT+ PAYMENT_METHOD,
new ParameterizedTypeReference<PaymentResponse>() {},
withdrawalRequest);
}

// TODO untested - needs coinbase account ID to work.
public PaymentResponse makeWithdrawalToCoinbase(BigDecimal amount, String currency, String paymentMethodId) {
return makeWithdrawal(amount, currency, paymentMethodId, COINBASE);
public PaymentResponse makeWithdrawalToCoinbase(BigDecimal amount, String currency, String coinbaseAccountId) {
CoinbasePaymentRequest withdrawalRequest = new CoinbasePaymentRequest(amount, currency, coinbaseAccountId);
return gdaxExchange.post(WITHDRAWALS_ENDPOINT+ COINBASE,
new ParameterizedTypeReference<PaymentResponse>() {},
withdrawalRequest);
}

// TODO untested - needs a crypto currency account address
public PaymentResponse makeWithdrawalToCryptoAccount(BigDecimal amount, String currency, String cryptoAccount) {
return makeWithdrawal(amount, currency, cryptoAccount, CRYPTO);
}

private PaymentResponse makeWithdrawal(BigDecimal amount,
String currency,
String cryptoAccount,
String withdrawalType) {
PaymentRequest withdrawalRequest = new PaymentRequest(amount, currency, cryptoAccount);
return gdaxExchange.post(WITHDRAWALS_ENDPOINT+ withdrawalType,
public PaymentResponse makeWithdrawalToCryptoAccount(BigDecimal amount, String currency, String cryptoAddress) {
CryptoPaymentRequest withdrawalRequest = new CryptoPaymentRequest(amount, currency, cryptoAddress);
return gdaxExchange.post(WITHDRAWALS_ENDPOINT+ CRYPTO,
new ParameterizedTypeReference<PaymentResponse>() {},
withdrawalRequest);
}
Expand Down

1 comment on commit 02e41b4

@robevansuk
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 looks good and in line with the documentation

Please sign in to comment.