Search in sources :

Example 1 with FundingRecord

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

the class BitstampAdapters method adaptFundingHistory.

public static List<FundingRecord> adaptFundingHistory(List<BitstampUserTransaction> userTransactions) {
    List<FundingRecord> fundingRecords = new ArrayList<>();
    for (BitstampUserTransaction trans : userTransactions) {
        if (trans.isDeposit() || trans.isWithdrawal() || trans.isSubAccountTransfer()) {
            Map.Entry<String, BigDecimal> amount = BitstampAdapters.findNonzeroAmount(trans);
            FundingRecord.Type type = FundingRecord.Type.DEPOSIT;
            if (trans.isWithdrawal()) {
                type = FundingRecord.Type.WITHDRAWAL;
            } else {
                if (trans.isSubAccountTransfer()) {
                    if (amount.getValue().compareTo(BigDecimal.ZERO) > 0) {
                        type = FundingRecord.Type.INTERNAL_DEPOSIT;
                    } else {
                        type = FundingRecord.Type.INTERNAL_WITHDRAWAL;
                    }
                }
            }
            FundingRecord record = new FundingRecord(null, trans.getDatetime(), Currency.getInstance(amount.getKey()), amount.getValue().abs(), String.valueOf(trans.getId()), null, type, FundingRecord.Status.COMPLETE, null, trans.getFee(), null);
            fundingRecords.add(record);
        }
    }
    return fundingRecords;
}
Also used : BitstampUserTransaction(org.knowm.xchange.bitstamp.dto.trade.BitstampUserTransaction) FundingRecord(org.knowm.xchange.dto.account.FundingRecord) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map) BigDecimal(java.math.BigDecimal)

Example 2 with FundingRecord

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

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

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

the class AccountServiceIntegration method testWithdrawalHistory.

@Test
public void testWithdrawalHistory() throws Exception {
    assumeProduction();
    TradeHistoryParams params = accountService.createFundingHistoryParams();
    List<FundingRecord> fundingHistory = accountService.getFundingHistory(params);
    Assert.assertNotNull(fundingHistory);
    fundingHistory.forEach(record -> {
        Assert.assertTrue(record.getAmount().compareTo(BigDecimal.ZERO) > 0);
    });
}
Also used : FundingRecord(org.knowm.xchange.dto.account.FundingRecord) TradeHistoryParams(org.knowm.xchange.service.trade.params.TradeHistoryParams) Test(org.junit.Test)

Example 5 with FundingRecord

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

Aggregations

FundingRecord (org.knowm.xchange.dto.account.FundingRecord)63 ArrayList (java.util.ArrayList)36 BigDecimal (java.math.BigDecimal)22 Date (java.util.Date)19 Currency (org.knowm.xchange.currency.Currency)17 Test (org.junit.Test)11 TradeHistoryParamCurrency (org.knowm.xchange.service.trade.params.TradeHistoryParamCurrency)11 HistoryParamsFundingType (org.knowm.xchange.service.trade.params.HistoryParamsFundingType)10 TradeHistoryParamsTimeSpan (org.knowm.xchange.service.trade.params.TradeHistoryParamsTimeSpan)9 UserTrade (org.knowm.xchange.dto.trade.UserTrade)8 IOException (java.io.IOException)7 Test (org.junit.jupiter.api.Test)7 TradeHistoryParams (org.knowm.xchange.service.trade.params.TradeHistoryParams)7 Map (java.util.Map)6 TradeHistoryParamLimit (org.knowm.xchange.service.trade.params.TradeHistoryParamLimit)6 TradeHistoryParamPaging (org.knowm.xchange.service.trade.params.TradeHistoryParamPaging)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 InputStream (java.io.InputStream)5 TradeHistoryParamOffset (org.knowm.xchange.service.trade.params.TradeHistoryParamOffset)5 AccountService (org.knowm.xchange.service.account.AccountService)4