Search in sources :

Example 1 with TheRockTransaction

use of org.knowm.xchange.therock.dto.trade.TheRockTransaction 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;
}
Also used : TheRockTransactions(org.knowm.xchange.therock.dto.trade.TheRockTransactions) TradeHistoryParamsTimeSpan(org.knowm.xchange.service.trade.params.TradeHistoryParamsTimeSpan) TradeHistoryParamCurrency(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrency) Currency(org.knowm.xchange.currency.Currency) FundingRecord(org.knowm.xchange.dto.account.FundingRecord) ArrayList(java.util.ArrayList) HistoryParamsFundingType(org.knowm.xchange.service.trade.params.HistoryParamsFundingType) TradeHistoryParamCurrency(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrency) TheRockTransaction(org.knowm.xchange.therock.dto.trade.TheRockTransaction) Date(java.util.Date)

Aggregations

ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Currency (org.knowm.xchange.currency.Currency)1 FundingRecord (org.knowm.xchange.dto.account.FundingRecord)1 HistoryParamsFundingType (org.knowm.xchange.service.trade.params.HistoryParamsFundingType)1 TradeHistoryParamCurrency (org.knowm.xchange.service.trade.params.TradeHistoryParamCurrency)1 TradeHistoryParamsTimeSpan (org.knowm.xchange.service.trade.params.TradeHistoryParamsTimeSpan)1 TheRockTransaction (org.knowm.xchange.therock.dto.trade.TheRockTransaction)1 TheRockTransactions (org.knowm.xchange.therock.dto.trade.TheRockTransactions)1