use of org.knowm.xchange.service.trade.params.TradeHistoryParamCurrency in project XChange by knowm.
the class BitbayAccountService method getFundingHistory.
@Override
public List<FundingRecord> getFundingHistory(TradeHistoryParams params) throws IOException {
Currency currency = null;
if (params instanceof TradeHistoryParamCurrency) {
TradeHistoryParamCurrency tradeHistoryParamCurrency = (TradeHistoryParamCurrency) params;
currency = tradeHistoryParamCurrency.getCurrency();
}
Integer limit = 1000;
if (params instanceof TradeHistoryParamLimit) {
limit = ((TradeHistoryParamLimit) params).getLimit();
}
return history(currency, limit);
}
use of org.knowm.xchange.service.trade.params.TradeHistoryParamCurrency in project XChange by knowm.
the class BinanceAccountService method getFundingHistory.
@Override
public List<FundingRecord> getFundingHistory(TradeHistoryParams params) throws IOException {
try {
String asset = null;
if (params instanceof TradeHistoryParamCurrency) {
TradeHistoryParamCurrency cp = (TradeHistoryParamCurrency) params;
if (cp.getCurrency() != null) {
asset = cp.getCurrency().getCurrencyCode();
}
}
Integer limit = null;
Integer page = null;
if (params instanceof TradeHistoryParamLimit) {
limit = ((TradeHistoryParamLimit) params).getLimit();
}
if (params instanceof TradeHistoryParamPaging) {
page = ((TradeHistoryParamPaging) params).getPageNumber();
}
boolean withdrawals = true;
boolean deposits = true;
boolean otherInflow = true;
Long startTime = null;
Long endTime = null;
if (params instanceof TradeHistoryParamsTimeSpan) {
TradeHistoryParamsTimeSpan tp = (TradeHistoryParamsTimeSpan) params;
if (tp.getStartTime() != null) {
startTime = tp.getStartTime().getTime();
}
if (tp.getEndTime() != null) {
endTime = tp.getEndTime().getTime();
}
}
if (params instanceof HistoryParamsFundingType) {
HistoryParamsFundingType f = (HistoryParamsFundingType) params;
if (f.getType() != null) {
withdrawals = f.getType() == Type.WITHDRAWAL;
deposits = f.getType() == Type.DEPOSIT;
otherInflow = f.getType() == Type.OTHER_INFLOW;
}
}
String email = null;
boolean subAccount = false;
// Get transfer history from a master account to a sub account
if (params instanceof BinanceMasterAccountTransferHistoryParams) {
email = ((BinanceMasterAccountTransferHistoryParams) params).getEmail();
}
// Get transfer history from a sub account to a master/sub account
if (params instanceof BinanceSubAccountTransferHistoryParams) {
subAccount = true;
}
List<FundingRecord> result = new ArrayList<>();
if (withdrawals) {
super.withdrawHistory(asset, startTime, endTime).forEach(w -> {
result.add(new FundingRecord(w.getAddress(), w.getAddressTag(), BinanceAdapters.toDate(w.getApplyTime()), Currency.getInstance(w.getCoin()), w.getAmount(), w.getId(), w.getTxId(), Type.WITHDRAWAL, withdrawStatus(w.getStatus()), null, w.getTransactionFee(), null));
});
}
if (deposits) {
super.depositHistory(asset, startTime, endTime).forEach(d -> {
result.add(new FundingRecord(d.getAddress(), d.getAddressTag(), new Date(d.getInsertTime()), Currency.getInstance(d.getCoin()), d.getAmount(), null, d.getTxId(), Type.DEPOSIT, depositStatus(d.getStatus()), null, null, null));
});
}
if (otherInflow) {
super.getAssetDividend(asset, startTime, endTime).forEach(a -> {
result.add(new FundingRecord(null, null, new Date(a.getDivTime()), Currency.getInstance(a.getAsset()), a.getAmount(), null, String.valueOf(a.getTranId()), Type.OTHER_INFLOW, Status.COMPLETE, null, null, a.getEnInfo()));
});
}
final String finalEmail = email;
if (email != null) {
super.getTransferHistory(email, startTime, endTime, page, limit).forEach(a -> {
result.add(new FundingRecord.Builder().setAddress(finalEmail).setDate(new Date(a.getTime())).setCurrency(Currency.getInstance(a.getAsset())).setAmount(a.getQty()).setType(Type.INTERNAL_WITHDRAWAL).setStatus(transferHistoryStatus(a.getStatus())).build());
});
}
if (subAccount) {
Integer type = deposits && withdrawals ? null : deposits ? 1 : 0;
super.getSubUserHistory(asset, type, startTime, endTime, limit).forEach(a -> {
result.add(new FundingRecord.Builder().setAddress(a.getEmail()).setDate(new Date(a.getTime())).setCurrency(Currency.getInstance(a.getAsset())).setAmount(a.getQty()).setType(a.getType().equals(1) ? Type.INTERNAL_DEPOSIT : Type.INTERNAL_WITHDRAWAL).setStatus(Status.COMPLETE).build());
});
}
return result;
} catch (BinanceException e) {
throw BinanceErrorAdapter.adapt(e);
}
}
use of org.knowm.xchange.service.trade.params.TradeHistoryParamCurrency in project XChange by knowm.
the class BiboxAccountService method getFundingHistory.
@Override
public List<FundingRecord> getFundingHistory(TradeHistoryParams params) {
if (!(params instanceof TradeHistoryParamCurrency)) {
throw new RuntimeException("You must provide the currency for funding history @ Bibox.");
}
Currency c = ((TradeHistoryParamCurrency) params).getCurrency();
if (c == null) {
throw new RuntimeException("You must provide the currency for funding history @ Bibox.");
}
boolean deposits = false;
boolean withdrawals = false;
if (params instanceof HistoryParamsFundingType) {
HistoryParamsFundingType typeParams = (HistoryParamsFundingType) params;
Type type = typeParams.getType();
deposits = type == null || type == Type.DEPOSIT;
withdrawals = type == null || type == Type.WITHDRAWAL;
}
BiboxFundsCommandBody body = new BiboxFundsCommandBody(c.getCurrencyCode());
ArrayList<FundingRecord> result = new ArrayList<>();
if (deposits) {
requestBiboxDeposits(body).getItems().forEach(d -> result.add(BiboxAdapters.adaptDeposit(d)));
}
if (withdrawals) {
requestBiboxWithdrawals(body).getItems().forEach(d -> result.add(BiboxAdapters.adaptDeposit(d)));
}
return result;
}
use of org.knowm.xchange.service.trade.params.TradeHistoryParamCurrency in project XChange by knowm.
the class TheRockAccountService method getFundingHistory.
@Override
public List<FundingRecord> getFundingHistory(TradeHistoryParams params) throws IOException {
Currency currency = null;
Date after = null;
Date before = null;
FundingRecord.Type type = null;
if (params instanceof TradeHistoryParamCurrency) {
TradeHistoryParamCurrency tradeHistoryParamCurrency = (TradeHistoryParamCurrency) params;
currency = tradeHistoryParamCurrency.getCurrency();
}
if (params instanceof TradeHistoryParamsTimeSpan) {
TradeHistoryParamsTimeSpan tradeHistoryParamsTimeSpan = (TradeHistoryParamsTimeSpan) params;
after = tradeHistoryParamsTimeSpan.getStartTime();
before = tradeHistoryParamsTimeSpan.getEndTime();
}
if (params instanceof HistoryParamsFundingType) {
HistoryParamsFundingType historyParamsFundingType = (HistoryParamsFundingType) params;
type = historyParamsFundingType.getType();
}
List<FundingRecord> all = new ArrayList<>();
if (type == null || type == FundingRecord.Type.DEPOSIT) {
int page = 1;
while (true) {
TheRockTransactions txns = deposits(currency, after, before, page++);
if (txns.getTransactions().length == 0)
break;
for (TheRockTransaction txn : txns.getTransactions()) {
all.add(adapt(txn, FundingRecord.Type.DEPOSIT));
}
}
}
if (type == null || type == FundingRecord.Type.WITHDRAWAL) {
int page = 1;
while (true) {
TheRockTransactions txns = withdrawls(currency, after, before, page++);
if (txns.getTransactions().length == 0)
break;
for (TheRockTransaction txn : txns.getTransactions()) {
all.add(adapt(txn, FundingRecord.Type.WITHDRAWAL));
}
}
}
return all;
}
use of org.knowm.xchange.service.trade.params.TradeHistoryParamCurrency in project XChange by knowm.
the class DragonexAccountService method getFundingHistory.
@Override
public List<FundingRecord> getFundingHistory(TradeHistoryParams params) throws IOException {
if (!(params instanceof TradeHistoryParamCurrency)) {
throw new RuntimeException("Parameter must implement the TradeHistoryParamCurrency interface in order to provide the currency parameter.");
}
Currency c = ((TradeHistoryParamCurrency) params).getCurrency();
if (c == null) {
throw new RuntimeException("Parameter must provide a valid currency parameter.");
}
String currency = c.getCurrencyCode();
Long pageNum = null;
Long pageSize = null;
if (params instanceof TradeHistoryParamPaging) {
TradeHistoryParamPaging p = (TradeHistoryParamPaging) params;
if (p.getPageNumber() != null) {
pageNum = new Long(p.getPageNumber());
}
if (p.getPageLength() != null) {
pageSize = new Long(p.getPageLength());
}
}
boolean withdrawals = true, deposits = true;
if (params instanceof HistoryParamsFundingType) {
HistoryParamsFundingType p = (HistoryParamsFundingType) params;
withdrawals = p.getType() == null || p.getType() == Type.WITHDRAWAL;
deposits = p.getType() == null || p.getType() == Type.DEPOSIT;
}
List<FundingRecord> result = new ArrayList<>();
if (withdrawals) {
result.addAll(coinWithdrawHistory(exchange.getCoinId(currency), pageNum, pageSize).getList().stream().map(cph -> DragonexAdapters.adaptFundingRecord(cph, exchange::getCurrency)).collect(Collectors.toList()));
}
if (deposits) {
result.addAll(coinPrepayHistory(exchange.getCoinId(currency), pageNum, pageSize).getList().stream().map(cph -> DragonexAdapters.adaptFundingRecord(cph, exchange::getCurrency)).collect(Collectors.toList()));
}
return result;
}
Aggregations