Skip to content

Commit

Permalink
Working version of BTCE withdrawal support. Not tested.
Browse files Browse the repository at this point in the history
  • Loading branch information
Muffon committed Oct 21, 2015
1 parent bef75f7 commit ad37b70
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 33 deletions.
Expand Up @@ -12,6 +12,7 @@
import javax.ws.rs.core.MediaType;

import com.xeiam.xchange.btce.v3.dto.account.BTCEAccountInfoReturn;
import com.xeiam.xchange.btce.v3.dto.account.BTCEWithDrawInfoReturn;
import com.xeiam.xchange.btce.v3.dto.trade.BTCECancelOrderReturn;
import com.xeiam.xchange.btce.v3.dto.trade.BTCEOpenOrdersReturn;
import com.xeiam.xchange.btce.v3.dto.trade.BTCEOrder;
Expand Down Expand Up @@ -126,4 +127,18 @@ BTCETransHistoryReturn TransHistory(@HeaderParam("Key") String apiKey, @HeaderPa
enum SortOrder {
ASC, DESC
}

/**
* Author: Ondřej Novtný
* @param currency Currency to withdraw
* @param amount Amount of withdrawal
* @param address Withdrawall address
* @return
*/
@POST
@Path("tapi")
@FormParam("method")
BTCEWithDrawInfoReturn Withdraw(@HeaderParam("Key") String apiKey, @HeaderParam("Sign") ParamsDigest signer,
@FormParam("coinName") String coinName, @FormParam("amount") BigDecimal amount, @FormParam("address")String address );

}
@@ -0,0 +1,22 @@
package com.xeiam.xchange.btce.v3.dto.account;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.xeiam.xchange.btce.v3.dto.BTCEReturn;

/**
* @author Ondřej Novotný
*/
public class BTCEWithDrawInfoReturn extends BTCEReturn<BTCEWithdrawInfo> {

/**
* Constructor
*
* @param success True if successful
* @param value The BTC-e account info
* @param error Any error
*/
public BTCEWithDrawInfoReturn(@JsonProperty("success") boolean success, @JsonProperty("return") BTCEWithdrawInfo value,
@JsonProperty("error") String error) {
super(success, value, error);
}
}
@@ -0,0 +1,54 @@
package com.xeiam.xchange.btce.v3.dto.account;

import java.math.BigDecimal;
import java.text.MessageFormat;
import java.util.Map;

import com.fasterxml.jackson.annotation.JsonProperty;

/**
* @author Ondřej Novotný
*/
public class BTCEWithdrawInfo {

private final Map<String, BigDecimal> funds;
private final int tId;


private final int amountSent;

/**
* Constructor
*
* @param tId
* @param amountSent
* @param funds The funds
*/
public BTCEWithdrawInfo(@JsonProperty("tId") int tId, @JsonProperty("amountSent") BigDecimal amountSent,
@JsonProperty("funds") Map<String, BigDecimal> funds) {
this.funds = funds;
this.tId = tId;
this.amountSent = tId;
}

public int gettId() {
return tId;
}

public int getAmountSent() {
return amountSent;
}

public Map<String, BigDecimal> getFunds() {

return funds;
}

@Override
public String toString() {

return MessageFormat.format("BTCEAccountInfo[tId={0}, amountSent={1}, funds=''{2}''']", tId,
amountSent, funds);
}

}
Expand Up @@ -31,11 +31,11 @@ public AccountInfo getAccountInfo() throws IOException {
BTCEAccountInfo info = getBTCEAccountInfo(null, null, null, null, null, null, null);
return BTCEAdapters.adaptAccountInfo(info);
}

@Override
public String withdrawFunds(String currency, BigDecimal amount, String address) throws IOException {

throw new NotAvailableFromExchangeException();
String s = withdrawFunds(currency, amount, address);
return s;
}

@Override
Expand Down
Expand Up @@ -6,6 +6,9 @@
import com.xeiam.xchange.btce.v3.BTCEAuthenticated;
import com.xeiam.xchange.btce.v3.dto.account.BTCEAccountInfo;
import com.xeiam.xchange.btce.v3.dto.account.BTCEAccountInfoReturn;
import com.xeiam.xchange.btce.v3.dto.account.BTCEWithDrawInfoReturn;
import com.xeiam.xchange.btce.v3.dto.account.BTCEWithdrawInfo;
import java.math.BigDecimal;

/**
* Author: brox
Expand Down Expand Up @@ -41,5 +44,19 @@ public BTCEAccountInfo getBTCEAccountInfo(Long from, Long count, Long fromId, Lo
checkResult(info);
return info.getReturnValue();
}

/**
* Author: Ondřej Novtný
* @param currency Currency to withdraw
* @param amount Amount of withdrawal
* @param address Withdrawall address
* @return Transactoin ID
*/
public String withdraw(String currency, BigDecimal amount, String address)
{
BTCEWithDrawInfoReturn info = btce.Withdraw(apiKey, signatureCreator, currency, amount, address);

return String.valueOf(info.getReturnValue().gettId());
}

}
Expand Up @@ -84,36 +84,6 @@ public boolean cancelOrder(String orderId) throws IOException {
return (ret != null);
}

/**
* @param arguments Vararg list of optional (nullable) arguments: (Long) arguments[0] Number of transactions to return (String) arguments[1]
* TradableIdentifier (String) arguments[2] TransactionCurrency (Long) arguments[3] Starting ID
* @return Trades object
* @throws IOException
*/
@Override
public UserTrades getTradeHistory(Object... arguments) throws IOException {

Long numberOfTransactions = Long.MAX_VALUE;
String tradableIdentifier = "";
String transactionCurrency = "";
Long id = null;
try {
numberOfTransactions = (Long) arguments[0];
tradableIdentifier = (String) arguments[1];
transactionCurrency = (String) arguments[2];
id = (Long) arguments[3];
} catch (ArrayIndexOutOfBoundsException e) {
// ignore, can happen if no arg given.
}
String pair = null;
if (!tradableIdentifier.equals("") && !transactionCurrency.equals("")) {
pair = String.format("%s_%s", tradableIdentifier, transactionCurrency).toLowerCase();
}
Map<Long, BTCETradeHistoryResult> resultMap = getBTCETradeHistory(null, numberOfTransactions, id, id, BTCEAuthenticated.SortOrder.DESC, null,
null, pair);
return BTCEAdapters.adaptTradeHistory(resultMap);
}

/**
* Supported parameters: {@link TradeHistoryParamPaging} {@link TradeHistoryParamsIdSpan} {@link TradeHistoryParamsTimeSpan}
* {@link TradeHistoryParamCurrencyPair} You can also override sorting order (default is descending) by using {@link BTCETradeHistoryParams}
Expand Down

0 comments on commit ad37b70

Please sign in to comment.