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());
}
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);
}
Aggregations