Search in sources :

Example 1 with Type

use of org.knowm.xchange.dto.account.FundingRecord.Type 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 2 with Type

use of org.knowm.xchange.dto.account.FundingRecord.Type in project XChange by knowm.

the class OkCoinAccountService method getFundingHistory.

@Override
public List<FundingRecord> getFundingHistory(TradeHistoryParams params) throws IOException {
    String symbol = null;
    if (params instanceof TradeHistoryParamCurrency && ((TradeHistoryParamCurrency) params).getCurrency() != null) {
        symbol = OkCoinAdapters.adaptCurrencyToAccountRecordPair(((TradeHistoryParamCurrency) params).getCurrency());
    }
    if (symbol == null) {
        throw new ExchangeException("Symbol must be supplied");
    }
    Integer pageLength = 50;
    Integer pageNumber = null;
    if (params instanceof TradeHistoryParamPaging) {
        TradeHistoryParamPaging pagingParams = (TradeHistoryParamPaging) params;
        if (pagingParams.getPageLength() != null) {
            pageLength = pagingParams.getPageLength();
            if (pageLength > 50) {
                pageLength = 50;
            }
        }
        pageNumber = pagingParams.getPageNumber() != null ? pagingParams.getPageNumber() : 1;
    }
    FundingRecord.Type type = null;
    if (params instanceof HistoryParamsFundingType) {
        type = ((HistoryParamsFundingType) params).getType();
    }
    List<FundingRecord> result = new ArrayList<>();
    if (type == null || type == Type.DEPOSIT) {
        final OkCoinAccountRecords depositRecord = getAccountRecords(symbol, "0", String.valueOf(pageNumber), String.valueOf(pageLength));
        result.addAll(OkCoinAdapters.adaptFundingHistory(depositRecord, Type.DEPOSIT));
    }
    if (type == null || type == Type.WITHDRAWAL) {
        final OkCoinAccountRecords withdrawalRecord = getAccountRecords(symbol, "1", String.valueOf(pageNumber), String.valueOf(pageLength));
        result.addAll(OkCoinAdapters.adaptFundingHistory(withdrawalRecord, Type.WITHDRAWAL));
    }
    return result;
}
Also used : OkCoinAccountRecords(org.knowm.xchange.okcoin.dto.account.OkCoinAccountRecords) FundingRecord(org.knowm.xchange.dto.account.FundingRecord) ArrayList(java.util.ArrayList) NotAvailableFromExchangeException(org.knowm.xchange.exceptions.NotAvailableFromExchangeException) ExchangeException(org.knowm.xchange.exceptions.ExchangeException) DefaultTradeHistoryParamPaging(org.knowm.xchange.service.trade.params.DefaultTradeHistoryParamPaging) TradeHistoryParamPaging(org.knowm.xchange.service.trade.params.TradeHistoryParamPaging) HistoryParamsFundingType(org.knowm.xchange.service.trade.params.HistoryParamsFundingType) TradeHistoryParamCurrency(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrency) Type(org.knowm.xchange.dto.account.FundingRecord.Type)

Aggregations

ArrayList (java.util.ArrayList)2 FundingRecord (org.knowm.xchange.dto.account.FundingRecord)2 Type (org.knowm.xchange.dto.account.FundingRecord.Type)2 HistoryParamsFundingType (org.knowm.xchange.service.trade.params.HistoryParamsFundingType)2 TradeHistoryParamCurrency (org.knowm.xchange.service.trade.params.TradeHistoryParamCurrency)2 BiboxFundsCommandBody (org.knowm.xchange.bibox.dto.account.BiboxFundsCommandBody)1 Currency (org.knowm.xchange.currency.Currency)1 ExchangeException (org.knowm.xchange.exceptions.ExchangeException)1 NotAvailableFromExchangeException (org.knowm.xchange.exceptions.NotAvailableFromExchangeException)1 OkCoinAccountRecords (org.knowm.xchange.okcoin.dto.account.OkCoinAccountRecords)1 DefaultTradeHistoryParamPaging (org.knowm.xchange.service.trade.params.DefaultTradeHistoryParamPaging)1 TradeHistoryParamPaging (org.knowm.xchange.service.trade.params.TradeHistoryParamPaging)1