org.knowm.xchange.livecoin.service.LivecoinAccountService Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of xchange-livecoin Show documentation
Show all versions of xchange-livecoin Show documentation
A convenient way to buy and sell Bitcoin
package org.knowm.xchange.livecoin.service;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.knowm.xchange.currency.Currency;
import org.knowm.xchange.dto.account.AccountInfo;
import org.knowm.xchange.dto.account.FundingRecord;
import org.knowm.xchange.livecoin.LivecoinAdapters;
import org.knowm.xchange.livecoin.LivecoinErrorAdapter;
import org.knowm.xchange.livecoin.LivecoinExchange;
import org.knowm.xchange.livecoin.dto.LivecoinException;
import org.knowm.xchange.service.account.AccountService;
import org.knowm.xchange.service.trade.params.DefaultWithdrawFundsParams;
import org.knowm.xchange.service.trade.params.TradeHistoryParamLimit;
import org.knowm.xchange.service.trade.params.TradeHistoryParamOffset;
import org.knowm.xchange.service.trade.params.TradeHistoryParams;
import org.knowm.xchange.service.trade.params.TradeHistoryParamsTimeSpan;
import org.knowm.xchange.service.trade.params.WithdrawFundsParams;
public class LivecoinAccountService extends LivecoinAccountServiceRaw implements AccountService {
public LivecoinAccountService(LivecoinExchange exchange) {
super(exchange);
}
@Override
public AccountInfo getAccountInfo() throws IOException {
try {
return new AccountInfo(balances(null));
} catch (LivecoinException e) {
throw LivecoinErrorAdapter.adapt(e);
}
}
@Override
public String withdrawFunds(Currency currency, BigDecimal amount, String address)
throws IOException {
return withdrawFunds(new DefaultWithdrawFundsParams(address, currency, amount));
}
@Override
public String withdrawFunds(WithdrawFundsParams params) throws IOException {
try {
if (!(params instanceof DefaultWithdrawFundsParams)) {
throw new IllegalStateException("Unsupported params class " + params.getClass().getName());
}
return withdraw((DefaultWithdrawFundsParams) params);
} catch (LivecoinException e) {
throw LivecoinErrorAdapter.adapt(e);
}
}
@Override
public String requestDepositAddress(Currency currency, String... args) throws IOException {
try {
return walletAddress(currency);
} catch (LivecoinException e) {
throw LivecoinErrorAdapter.adapt(e);
}
}
@Override
public List getFundingHistory(TradeHistoryParams params) throws IOException {
try {
Date start = new Date(0);
Date end = new Date();
if (params instanceof TradeHistoryParamsTimeSpan) {
TradeHistoryParamsTimeSpan tradeHistoryParamsTimeSpan = (TradeHistoryParamsTimeSpan) params;
start = tradeHistoryParamsTimeSpan.getStartTime();
end = tradeHistoryParamsTimeSpan.getEndTime();
}
Long offset = 0L;
if (params instanceof TradeHistoryParamOffset) {
offset = ((TradeHistoryParamOffset) params).getOffset();
}
Integer limit = 100;
if (params instanceof TradeHistoryParamLimit) {
limit = ((TradeHistoryParamLimit) params).getLimit();
}
List