Search in sources :

Example 1 with HistoryParamsFundingType

use of org.knowm.xchange.service.trade.params.HistoryParamsFundingType in project XChange by knowm.

the class KrakenAccountDemo method fundingHistory.

private static void fundingHistory(AccountService accountService) throws IOException {
    // Get the funds information
    TradeHistoryParams params = accountService.createFundingHistoryParams();
    if (params instanceof TradeHistoryParamsTimeSpan) {
        final TradeHistoryParamsTimeSpan timeSpanParam = (TradeHistoryParamsTimeSpan) params;
        timeSpanParam.setStartTime(new Date(System.currentTimeMillis() - (1 * 12 * 30 * 24 * 60 * 60 * 1000L)));
    }
    if (params instanceof HistoryParamsFundingType) {
        ((HistoryParamsFundingType) params).setType(FundingRecord.Type.DEPOSIT);
    }
    if (params instanceof TradeHistoryParamCurrencies) {
        final TradeHistoryParamCurrencies currenciesParam = (TradeHistoryParamCurrencies) params;
        currenciesParam.setCurrencies(new Currency[] { Currency.BTC, Currency.USD });
    }
    List<FundingRecord> fundingRecords = accountService.getFundingHistory(params);
    AccountServiceTestUtil.printFundingHistory(fundingRecords);
}
Also used : TradeHistoryParamsTimeSpan(org.knowm.xchange.service.trade.params.TradeHistoryParamsTimeSpan) TradeHistoryParamCurrencies(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencies) FundingRecord(org.knowm.xchange.dto.account.FundingRecord) TradeHistoryParams(org.knowm.xchange.service.trade.params.TradeHistoryParams) HistoryParamsFundingType(org.knowm.xchange.service.trade.params.HistoryParamsFundingType) Date(java.util.Date)

Example 2 with HistoryParamsFundingType

use of org.knowm.xchange.service.trade.params.HistoryParamsFundingType in project XChange by knowm.

the class OkexAccountService method getFundingHistory.

@Override
public List<FundingRecord> getFundingHistory(TradeHistoryParams params) throws IOException {
    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(recentWithdrawalHistory().stream().map(OkexAdaptersV3::adaptFundingRecord).collect(Collectors.toList()));
    }
    if (deposits) {
        result.addAll(recentDepositHistory().stream().map(OkexAdaptersV3::adaptFundingRecord).collect(Collectors.toList()));
    }
    Collections.sort(result, (r1, r2) -> r1.getDate().compareTo(r2.getDate()));
    return result;
}
Also used : OkexAdaptersV3(org.knowm.xchange.okcoin.OkexAdaptersV3) FundingRecord(org.knowm.xchange.dto.account.FundingRecord) ArrayList(java.util.ArrayList) HistoryParamsFundingType(org.knowm.xchange.service.trade.params.HistoryParamsFundingType)

Example 3 with HistoryParamsFundingType

use of org.knowm.xchange.service.trade.params.HistoryParamsFundingType 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 4 with HistoryParamsFundingType

use of org.knowm.xchange.service.trade.params.HistoryParamsFundingType 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 5 with HistoryParamsFundingType

use of org.knowm.xchange.service.trade.params.HistoryParamsFundingType 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

HistoryParamsFundingType (org.knowm.xchange.service.trade.params.HistoryParamsFundingType)11 FundingRecord (org.knowm.xchange.dto.account.FundingRecord)10 ArrayList (java.util.ArrayList)8 Currency (org.knowm.xchange.currency.Currency)7 TradeHistoryParamCurrency (org.knowm.xchange.service.trade.params.TradeHistoryParamCurrency)7 TradeHistoryParamsTimeSpan (org.knowm.xchange.service.trade.params.TradeHistoryParamsTimeSpan)6 Date (java.util.Date)5 TradeHistoryParamPaging (org.knowm.xchange.service.trade.params.TradeHistoryParamPaging)4 Type (org.knowm.xchange.dto.account.FundingRecord.Type)2 ExchangeException (org.knowm.xchange.exceptions.ExchangeException)2 TradeHistoryParamCurrencies (org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencies)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 CoinbaseProTransfer (org.knowm.xchange.coinbasepro.dto.CoinbaseProTransfer)1 CoinbaseProTransfers (org.knowm.xchange.coinbasepro.dto.CoinbaseProTransfers)1 NotAvailableFromExchangeException (org.knowm.xchange.exceptions.NotAvailableFromExchangeException)1 KrakenLedger (org.knowm.xchange.kraken.dto.account.KrakenLedger)1