use of org.knowm.xchange.service.trade.params.TradeHistoryParamPaging in project XChange by knowm.
the class OkCoinAccountDemo method fundingHistory.
private static void fundingHistory(AccountService accountService) throws IOException {
// Get the funds information
TradeHistoryParams params = accountService.createFundingHistoryParams();
if (params instanceof TradeHistoryParamPaging) {
TradeHistoryParamPaging pagingParams = (TradeHistoryParamPaging) params;
pagingParams.setPageLength(50);
pagingParams.setPageNumber(1);
}
if (params instanceof TradeHistoryParamCurrencyPair) {
((TradeHistoryParamCurrencyPair) params).setCurrencyPair(CurrencyPair.BTC_CNY);
}
final List<FundingRecord> fundingRecords = accountService.getFundingHistory(params);
AccountServiceTestUtil.printFundingHistory(fundingRecords);
}
use of org.knowm.xchange.service.trade.params.TradeHistoryParamPaging 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.TradeHistoryParamPaging in project XChange by knowm.
the class BTCMarketsTradeService method getTradeHistory.
@Override
public UserTrades getTradeHistory(TradeHistoryParams params) throws IOException {
Integer limit = 200;
if (params instanceof TradeHistoryParamPaging) {
limit = ((TradeHistoryParamPaging) params).getPageLength();
}
String after = null;
if (params instanceof TradeHistoryParamsIdSpan) {
TradeHistoryParamsIdSpan tradeHistoryParamsIdSpan = (TradeHistoryParamsIdSpan) params;
after = tradeHistoryParamsIdSpan.getStartId();
}
String before = null;
if (params instanceof TradeHistoryParamsIdSpan) {
TradeHistoryParamsIdSpan tradeHistoryParamsIdSpan = (TradeHistoryParamsIdSpan) params;
before = tradeHistoryParamsIdSpan.getEndId();
}
CurrencyPair cp = null;
if (params instanceof TradeHistoryParamCurrencyPair) {
CurrencyPair paramsCp = ((TradeHistoryParamCurrencyPair) params).getCurrencyPair();
if (paramsCp != null) {
cp = paramsCp;
}
}
List<BTCMarketsTradeHistoryResponse> response = getBTCMarketsUserTransactions(cp, before, after, limit);
return BTCMarketsAdapters.adaptTradeHistory(response);
}
use of org.knowm.xchange.service.trade.params.TradeHistoryParamPaging in project XChange by knowm.
the class TheRockTradeService method getTradeHistory.
@Override
public UserTrades getTradeHistory(TradeHistoryParams params) throws IOException {
if (!(params instanceof TradeHistoryParamCurrencyPair)) {
throw new ExchangeException("TheRock API recquires " + TradeHistoryParamCurrencyPair.class);
}
TradeHistoryParamCurrencyPair pairParams = (TradeHistoryParamCurrencyPair) params;
// get all trades starting from a specific trade_id
Long sinceTradeId = null;
if (params instanceof TradeHistoryParamsIdSpan) {
TradeHistoryParamsIdSpan trId = (TradeHistoryParamsIdSpan) params;
try {
sinceTradeId = Long.valueOf(trId.getStartId());
} catch (Throwable ignored) {
}
}
Date after = null;
Date before = null;
if (params instanceof TradeHistoryParamsTimeSpan) {
TradeHistoryParamsTimeSpan time = (TradeHistoryParamsTimeSpan) params;
after = time.getStartTime();
before = time.getEndTime();
}
int pageLength = 200;
int page = 0;
if (params instanceof TradeHistoryParamPaging) {
TradeHistoryParamPaging tradeHistoryParamPaging = (TradeHistoryParamPaging) params;
pageLength = tradeHistoryParamPaging.getPageLength();
page = tradeHistoryParamPaging.getPageNumber();
}
return TheRockAdapters.adaptUserTrades(getTheRockUserTrades(pairParams.getCurrencyPair(), sinceTradeId, after, before, pageLength, page), pairParams.getCurrencyPair());
}
use of org.knowm.xchange.service.trade.params.TradeHistoryParamPaging 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