Search in sources :

Example 1 with TradeHistoryParamCurrency

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);
}
Also used : TradeHistoryParamCurrency(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrency) Currency(org.knowm.xchange.currency.Currency) TradeHistoryParamCurrency(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrency) TradeHistoryParamLimit(org.knowm.xchange.service.trade.params.TradeHistoryParamLimit)

Example 2 with TradeHistoryParamCurrency

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);
    }
}
Also used : TradeHistoryParamsTimeSpan(org.knowm.xchange.service.trade.params.TradeHistoryParamsTimeSpan) ArrayList(java.util.ArrayList) TradeHistoryParamPaging(org.knowm.xchange.service.trade.params.TradeHistoryParamPaging) Date(java.util.Date) BinanceException(org.knowm.xchange.binance.dto.BinanceException) FundingRecord(org.knowm.xchange.dto.account.FundingRecord) HistoryParamsFundingType(org.knowm.xchange.service.trade.params.HistoryParamsFundingType) TradeHistoryParamCurrency(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrency) TradeHistoryParamLimit(org.knowm.xchange.service.trade.params.TradeHistoryParamLimit)

Example 3 with TradeHistoryParamCurrency

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;
}
Also used : HistoryParamsFundingType(org.knowm.xchange.service.trade.params.HistoryParamsFundingType) Type(org.knowm.xchange.dto.account.FundingRecord.Type) BiboxFundsCommandBody(org.knowm.xchange.bibox.dto.account.BiboxFundsCommandBody) 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)

Example 4 with TradeHistoryParamCurrency

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;
}
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)

Example 5 with TradeHistoryParamCurrency

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;
}
Also used : 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) TradeHistoryParamPaging(org.knowm.xchange.service.trade.params.TradeHistoryParamPaging) HistoryParamsFundingType(org.knowm.xchange.service.trade.params.HistoryParamsFundingType) TradeHistoryParamCurrency(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrency)

Aggregations

TradeHistoryParamCurrency (org.knowm.xchange.service.trade.params.TradeHistoryParamCurrency)13 Currency (org.knowm.xchange.currency.Currency)10 FundingRecord (org.knowm.xchange.dto.account.FundingRecord)10 ArrayList (java.util.ArrayList)9 HistoryParamsFundingType (org.knowm.xchange.service.trade.params.HistoryParamsFundingType)7 TradeHistoryParamLimit (org.knowm.xchange.service.trade.params.TradeHistoryParamLimit)5 TradeHistoryParamPaging (org.knowm.xchange.service.trade.params.TradeHistoryParamPaging)5 TradeHistoryParamsTimeSpan (org.knowm.xchange.service.trade.params.TradeHistoryParamsTimeSpan)5 Date (java.util.Date)4 TradeHistoryParamOffset (org.knowm.xchange.service.trade.params.TradeHistoryParamOffset)3 Type (org.knowm.xchange.dto.account.FundingRecord.Type)2 ExchangeException (org.knowm.xchange.exceptions.ExchangeException)2 BiboxFundsCommandBody (org.knowm.xchange.bibox.dto.account.BiboxFundsCommandBody)1 BinanceException (org.knowm.xchange.binance.dto.BinanceException)1 BitcoindeAccountLedgerType (org.knowm.xchange.bitcoinde.v4.dto.BitcoindeAccountLedgerType)1 BitcoindeAccountLedger (org.knowm.xchange.bitcoinde.v4.dto.account.BitcoindeAccountLedger)1 BitcoindeAccountLedgerWrapper (org.knowm.xchange.bitcoinde.v4.dto.account.BitcoindeAccountLedgerWrapper)1 BitmexAdapters.adaptCurrency (org.knowm.xchange.bitmex.BitmexAdapters.adaptCurrency)1 DsxTransaction (org.knowm.xchange.dsx.dto.DsxTransaction)1 NotAvailableFromExchangeException (org.knowm.xchange.exceptions.NotAvailableFromExchangeException)1