use of org.knowm.xchange.bitfinex.v2.dto.account.Movement in project XChange by knowm.
the class BitfinexAdapters method adaptFundingHistory.
public static List<FundingRecord> adaptFundingHistory(List<Movement> movementHistorys) {
final List<FundingRecord> fundingRecords = new ArrayList<>();
for (Movement movement : movementHistorys) {
Currency currency = Currency.getInstance(movement.getCurency());
FundingRecord.Type type = movement.getAmount().compareTo(BigDecimal.ZERO) < 0 ? FundingRecord.Type.WITHDRAWAL : FundingRecord.Type.DEPOSIT;
FundingRecord.Status status = FundingRecord.Status.resolveStatus(movement.getStatus());
if (status == null && movement.getStatus().equalsIgnoreCase(// there's a spelling mistake in the protocol
"CANCELED"))
status = FundingRecord.Status.CANCELLED;
BigDecimal amount = movement.getAmount().abs();
BigDecimal fee = movement.getFees().abs();
if (fee != null && type.isOutflowing()) {
// The amount reported form Bitfinex on a withdrawal is without the fee, so it has to be
// added to get the full amount withdrawn from the wallet
// Deposits don't seem to have fees, but it seems reasonable to assume that the reported
// value is the full amount added to the wallet
amount = amount.add(fee);
}
FundingRecord fundingRecordEntry = new FundingRecord(movement.getDestinationAddress(), null, movement.getMtsUpdated(), currency, amount, movement.getId(), movement.getTransactionId(), type, status, null, fee, null);
fundingRecords.add(fundingRecordEntry);
}
return fundingRecords;
}
use of org.knowm.xchange.bitfinex.v2.dto.account.Movement in project XChange by knowm.
the class BitfinexAdaptersTest method adaptFundingHistory.
@Test
public void adaptFundingHistory() {
List<Movement> movements = Arrays.asList(new Movement("13105603", "ETH", "", null, null, DateUtils.fromMillisUtc(1569348774000L), DateUtils.fromMillisUtc(1569348774000L), null, null, "COMPLETED", null, null, new BigDecimal("0.26300954"), new BigDecimal("-0.00135"), null, null, "DESTINATION_ADDRESS", null, null, null, "TRANSACTION_ID", null), new Movement("13293039", "ETH", "ETHEREUM", null, null, DateUtils.fromMillisUtc(1574175052000L), DateUtils.fromMillisUtc(1574181326000L), null, null, "CANCELED", null, null, new BigDecimal("-0.24"), new BigDecimal("-0.00135"), null, null, "DESTINATION_ADDRESS", null, null, null, "TRANSACTION_ID", null));
List<FundingRecord> fundingRecords = BitfinexAdapters.adaptFundingHistory(movements);
assertThat(fundingRecords).hasSize(2);
assertThat(fundingRecords.get(0).getAddress()).isEqualTo("DESTINATION_ADDRESS");
assertThat(fundingRecords.get(0).getAddressTag()).isNull();
assertThat(fundingRecords.get(0).getDate()).isEqualTo("2019-09-24T18:12:54Z");
assertThat(fundingRecords.get(0).getCurrency()).isEqualTo(Currency.ETH);
assertThat(fundingRecords.get(0).getAmount()).isEqualByComparingTo("0.26300954");
assertThat(fundingRecords.get(0).getInternalId()).isEqualTo("13105603");
assertThat(fundingRecords.get(0).getBlockchainTransactionHash()).isEqualTo("TRANSACTION_ID");
assertThat(fundingRecords.get(0).getType()).isEqualTo(FundingRecord.Type.DEPOSIT);
assertThat(fundingRecords.get(0).getStatus()).isEqualTo(FundingRecord.Status.COMPLETE);
assertThat(fundingRecords.get(0).getBalance()).isNull();
assertThat(fundingRecords.get(0).getFee()).isEqualByComparingTo("0.00135");
assertThat(fundingRecords.get(0).getDescription()).isNull();
assertThat(fundingRecords.get(1).getAddress()).isEqualTo("DESTINATION_ADDRESS");
assertThat(fundingRecords.get(1).getAddressTag()).isNull();
assertThat(fundingRecords.get(1).getDate()).isEqualTo("2019-11-19T16:35:26Z");
assertThat(fundingRecords.get(1).getCurrency()).isEqualTo(Currency.ETH);
assertThat(fundingRecords.get(1).getAmount()).isEqualByComparingTo("0.24135");
assertThat(fundingRecords.get(1).getInternalId()).isEqualTo("13293039");
assertThat(fundingRecords.get(1).getBlockchainTransactionHash()).isEqualTo("TRANSACTION_ID");
assertThat(fundingRecords.get(1).getType()).isEqualTo(FundingRecord.Type.WITHDRAWAL);
assertThat(fundingRecords.get(1).getStatus()).isEqualTo(FundingRecord.Status.CANCELLED);
assertThat(fundingRecords.get(1).getBalance()).isNull();
assertThat(fundingRecords.get(1).getFee()).isEqualByComparingTo("0.00135");
assertThat(fundingRecords.get(1).getDescription()).isNull();
}
Aggregations