Search in sources :

Example 1 with TradeHistoryParamPaging

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);
}
Also used : FundingRecord(org.knowm.xchange.dto.account.FundingRecord) TradeHistoryParams(org.knowm.xchange.service.trade.params.TradeHistoryParams) TradeHistoryParamPaging(org.knowm.xchange.service.trade.params.TradeHistoryParamPaging) TradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair)

Example 2 with TradeHistoryParamPaging

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

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);
}
Also used : TradeHistoryParamPaging(org.knowm.xchange.service.trade.params.TradeHistoryParamPaging) TradeHistoryParamsIdSpan(org.knowm.xchange.service.trade.params.TradeHistoryParamsIdSpan) BTCMarketsTradeHistoryResponse(org.knowm.xchange.btcmarkets.dto.v3.trade.BTCMarketsTradeHistoryResponse) OpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.OpenOrdersParamCurrencyPair) DefaultOpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.DefaultOpenOrdersParamCurrencyPair) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) TradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair) TradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair)

Example 4 with TradeHistoryParamPaging

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());
}
Also used : TradeHistoryParamsTimeSpan(org.knowm.xchange.service.trade.params.TradeHistoryParamsTimeSpan) NotAvailableFromExchangeException(org.knowm.xchange.exceptions.NotAvailableFromExchangeException) ExchangeException(org.knowm.xchange.exceptions.ExchangeException) TradeHistoryParamPaging(org.knowm.xchange.service.trade.params.TradeHistoryParamPaging) TradeHistoryParamsIdSpan(org.knowm.xchange.service.trade.params.TradeHistoryParamsIdSpan) Date(java.util.Date) TradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair)

Example 5 with TradeHistoryParamPaging

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

TradeHistoryParamPaging (org.knowm.xchange.service.trade.params.TradeHistoryParamPaging)19 TradeHistoryParamCurrencyPair (org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair)11 TradeHistoryParamsTimeSpan (org.knowm.xchange.service.trade.params.TradeHistoryParamsTimeSpan)9 CurrencyPair (org.knowm.xchange.currency.CurrencyPair)8 ArrayList (java.util.ArrayList)7 Date (java.util.Date)7 FundingRecord (org.knowm.xchange.dto.account.FundingRecord)6 TradeHistoryParamCurrency (org.knowm.xchange.service.trade.params.TradeHistoryParamCurrency)5 DefaultTradeHistoryParamPaging (org.knowm.xchange.service.trade.params.DefaultTradeHistoryParamPaging)4 HistoryParamsFundingType (org.knowm.xchange.service.trade.params.HistoryParamsFundingType)4 OpenOrdersParamCurrencyPair (org.knowm.xchange.service.trade.params.orders.OpenOrdersParamCurrencyPair)4 Currency (org.knowm.xchange.currency.Currency)3 ExchangeException (org.knowm.xchange.exceptions.ExchangeException)3 NotAvailableFromExchangeException (org.knowm.xchange.exceptions.NotAvailableFromExchangeException)3 TradeHistoryParamLimit (org.knowm.xchange.service.trade.params.TradeHistoryParamLimit)3 TradeHistoryParamsIdSpan (org.knowm.xchange.service.trade.params.TradeHistoryParamsIdSpan)3 DefaultOpenOrdersParamCurrencyPair (org.knowm.xchange.service.trade.params.orders.DefaultOpenOrdersParamCurrencyPair)3 TradeHistoryParamOffset (org.knowm.xchange.service.trade.params.TradeHistoryParamOffset)2 TradeHistoryParamsSorted (org.knowm.xchange.service.trade.params.TradeHistoryParamsSorted)2 HashSet (java.util.HashSet)1