Search in sources :

Example 1 with BitcoindeAccountLedgerWrapper

use of org.knowm.xchange.bitcoinde.v4.dto.account.BitcoindeAccountLedgerWrapper in project XChange by knowm.

the class BitcoindeAdaptersTest method testFundingHistoryAdapter.

@Test
public void testFundingHistoryAdapter() throws IOException {
    final InputStream is = BitcoindeAdaptersTest.class.getResourceAsStream("/org/knowm/xchange/bitcoinde/v4/dto/account_ledger.json");
    // Use Jackson to parse it
    final ObjectMapper mapper = new ObjectMapper();
    BitcoindeAccountLedgerWrapper accountLedgerWrapper = mapper.readValue(is, BitcoindeAccountLedgerWrapper.class);
    final List<FundingRecord> fundingRecords = BitcoindeAdapters.adaptFundingHistory(Currency.BTC, accountLedgerWrapper.getAccountLedgers(), false);
    // Make sure trade values are correct
    assertThat(fundingRecords).isNotEmpty();
    assertThat(fundingRecords.size()).isEqualTo(2);
    assertThat(fundingRecords.get(0).getAddress()).isNull();
    assertThat(fundingRecords.get(0).getAddressTag()).isNull();
    assertThat(fundingRecords.get(0).getDate()).isEqualTo("2015-08-12T13:05:02+02:00");
    assertThat(fundingRecords.get(0).getCurrency()).isEqualByComparingTo(Currency.BTC);
    assertThat(fundingRecords.get(0).getAmount()).isEqualByComparingTo("0.10000000");
    assertThat(fundingRecords.get(0).getInternalId()).isNull();
    assertThat(fundingRecords.get(0).getBlockchainTransactionHash()).isEqualTo("dqwdqwdwqwq4dqw4d5qd45qd45qwd4qw5df45g4r5g4trh4r5j5j4tz5j4tbc");
    assertThat(fundingRecords.get(0).getType()).isEqualByComparingTo(FundingRecord.Type.WITHDRAWAL);
    assertThat(fundingRecords.get(0).getBalance()).isEqualByComparingTo("4.71619794");
    assertThat(fundingRecords.get(0).getStatus()).isEqualByComparingTo(FundingRecord.Status.COMPLETE);
    assertThat(fundingRecords.get(0).getFee()).isNull();
    assertThat(fundingRecords.get(0).getDescription()).isEqualTo(BitcoindeAccountLedgerType.PAYOUT.getValue());
    assertThat(fundingRecords.get(1).getAddress()).isNull();
    assertThat(fundingRecords.get(1).getAddressTag()).isNull();
    assertThat(fundingRecords.get(1).getDate()).isEqualTo("2015-08-12T12:30:01+02:00");
    assertThat(fundingRecords.get(1).getCurrency()).isEqualByComparingTo(Currency.BTC);
    assertThat(fundingRecords.get(1).getAmount()).isEqualByComparingTo("1.91894200");
    assertThat(fundingRecords.get(1).getInternalId()).isNull();
    assertThat(fundingRecords.get(1).getBlockchainTransactionHash()).isEqualTo("bdgwflwguwgr884t34g4g555h4zr5j4fh5j48rg4s5bx2nt4jr5jr45j4r5j4");
    assertThat(fundingRecords.get(1).getType()).isEqualByComparingTo(FundingRecord.Type.WITHDRAWAL);
    assertThat(fundingRecords.get(1).getBalance()).isEqualByComparingTo("4.81619794");
    assertThat(fundingRecords.get(1).getStatus()).isEqualByComparingTo(FundingRecord.Status.COMPLETE);
    assertThat(fundingRecords.get(1).getFee()).isNull();
    assertThat(fundingRecords.get(1).getDescription()).isEqualTo(BitcoindeAccountLedgerType.PAYOUT.getValue());
}
Also used : InputStream(java.io.InputStream) BitcoindeAccountLedgerWrapper(org.knowm.xchange.bitcoinde.v4.dto.account.BitcoindeAccountLedgerWrapper) FundingRecord(org.knowm.xchange.dto.account.FundingRecord) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 2 with BitcoindeAccountLedgerWrapper

use of org.knowm.xchange.bitcoinde.v4.dto.account.BitcoindeAccountLedgerWrapper in project XChange by knowm.

the class BitcoindeAccountService method getFundingHistory.

@Override
public List<FundingRecord> getFundingHistory(TradeHistoryParams params) throws IOException {
    Assert.isTrue(params instanceof TradeHistoryParamCurrency, "You need to provide a currency to retrieve the funding history.");
    if (((TradeHistoryParamCurrency) params).getCurrency() == null) {
        throw new IllegalArgumentException("Currency has to be specified");
    }
    if (params instanceof BitcoindeFundingHistoryParams && ((BitcoindeFundingHistoryParams) params).getType() != null && ((BitcoindeFundingHistoryParams) params).getCustomType() != null) {
        throw new IllegalArgumentException("Only one type can be specified");
    }
    Currency currency = ((TradeHistoryParamCurrency) params).getCurrency();
    BitcoindeAccountLedgerType customType = null;
    boolean leaveFeesSeperate = false;
    Date start = null;
    Date end = null;
    Integer pageNumber = null;
    if (params instanceof HistoryParamsFundingType) {
        if (((HistoryParamsFundingType) params).getType() != null) {
            switch(((HistoryParamsFundingType) params).getType()) {
                case WITHDRAWAL:
                    customType = BitcoindeAccountLedgerType.PAYOUT;
                    break;
                case DEPOSIT:
                    customType = BitcoindeAccountLedgerType.INPAYMENT;
                    break;
                default:
                    throw new IllegalArgumentException("Unsupported FundingRecord.Type: " + ((HistoryParamsFundingType) params).getType() + ". For Bitcoin.de specific types use BitcoindeFundingHistoryParams#customType");
            }
        }
    }
    if (params instanceof BitcoindeFundingHistoryParams) {
        customType = ((BitcoindeFundingHistoryParams) params).getCustomType();
        leaveFeesSeperate = ((BitcoindeFundingHistoryParams) params).isLeaveFeesSeperate();
    }
    if (params instanceof TradeHistoryParamsTimeSpan) {
        start = ((TradeHistoryParamsTimeSpan) params).getStartTime();
        end = ((TradeHistoryParamsTimeSpan) params).getEndTime();
    }
    if (params instanceof TradeHistoryParamPaging) {
        pageNumber = ((TradeHistoryParamPaging) params).getPageNumber();
    }
    BitcoindeAccountLedgerWrapper result = getAccountLedger(currency, customType, start, end, pageNumber);
    List<BitcoindeAccountLedger> ledger = result.getAccountLedgers();
    if (!leaveFeesSeperate && !ledger.isEmpty()) {
        ledger.addAll(checkForAndQueryAdditionalFees(ledger, currency, customType, start, end, pageNumber));
    }
    // Report back paging information to user to enable efficient paging
    if (params instanceof BitcoindeFundingHistoryParams) {
        ((BitcoindeFundingHistoryParams) params).setPageNumber(result.getPage().getCurrent());
        ((BitcoindeFundingHistoryParams) params).setLastPageNumber(result.getPage().getLast());
    }
    return BitcoindeAdapters.adaptFundingHistory(currency, ledger, leaveFeesSeperate);
}
Also used : TradeHistoryParamsTimeSpan(org.knowm.xchange.service.trade.params.TradeHistoryParamsTimeSpan) TradeHistoryParamPaging(org.knowm.xchange.service.trade.params.TradeHistoryParamPaging) Date(java.util.Date) TradeHistoryParamCurrency(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrency) Currency(org.knowm.xchange.currency.Currency) BitcoindeAccountLedgerWrapper(org.knowm.xchange.bitcoinde.v4.dto.account.BitcoindeAccountLedgerWrapper) HistoryParamsFundingType(org.knowm.xchange.service.trade.params.HistoryParamsFundingType) TradeHistoryParamCurrency(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrency) BitcoindeAccountLedgerType(org.knowm.xchange.bitcoinde.v4.dto.BitcoindeAccountLedgerType) BitcoindeAccountLedger(org.knowm.xchange.bitcoinde.v4.dto.account.BitcoindeAccountLedger)

Aggregations

BitcoindeAccountLedgerWrapper (org.knowm.xchange.bitcoinde.v4.dto.account.BitcoindeAccountLedgerWrapper)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 InputStream (java.io.InputStream)1 Date (java.util.Date)1 Test (org.junit.Test)1 BitcoindeAccountLedgerType (org.knowm.xchange.bitcoinde.v4.dto.BitcoindeAccountLedgerType)1 BitcoindeAccountLedger (org.knowm.xchange.bitcoinde.v4.dto.account.BitcoindeAccountLedger)1 Currency (org.knowm.xchange.currency.Currency)1 FundingRecord (org.knowm.xchange.dto.account.FundingRecord)1 HistoryParamsFundingType (org.knowm.xchange.service.trade.params.HistoryParamsFundingType)1 TradeHistoryParamCurrency (org.knowm.xchange.service.trade.params.TradeHistoryParamCurrency)1 TradeHistoryParamPaging (org.knowm.xchange.service.trade.params.TradeHistoryParamPaging)1 TradeHistoryParamsTimeSpan (org.knowm.xchange.service.trade.params.TradeHistoryParamsTimeSpan)1