use of org.knowm.xchange.poloniex.dto.account.PoloniexLoan in project XChange by knowm.
the class PoloniexLoansDataTest method testUnmarshallLoans.
@Test
public void testUnmarshallLoans() throws JsonParseException, JsonMappingException, IOException {
final InputStream is = PoloniexLoansDataTest.class.getResourceAsStream("/org/knowm/xchange/poloniex/dto/marketdata/loans-info.json");
final ObjectMapper mapper = new ObjectMapper();
final JavaType stringType = mapper.getTypeFactory().constructType(String.class, String.class);
final JavaType loanArray = mapper.getTypeFactory().constructArrayType(PoloniexLoan.class);
final JavaType currencyInfoType = mapper.getTypeFactory().constructMapType(HashMap.class, stringType, loanArray);
final Map<String, PoloniexLoan[]> loansInfo = mapper.readValue(is, currencyInfoType);
assertThat(loansInfo).hasSize(2);
PoloniexLoan[] providedLoans = loansInfo.get("provided");
assertThat(providedLoans).hasSize(2);
assertThat(providedLoans[0].getId()).isEqualTo("75073");
assertThat(providedLoans[0].getCurrency()).isEqualTo(Currency.LTC.getCurrencyCode());
assertThat(providedLoans[0].getRate()).isEqualTo("0.00020000");
assertThat(providedLoans[0].getAmount()).isEqualTo("0.72234880");
assertThat(providedLoans[0].getRange()).isEqualTo(2);
assertThat(providedLoans[0].getDate()).isEqualTo("2015-05-10 23:45:05");
assertThat(providedLoans[0].getFees()).isEqualTo("0.00006000");
assertThat(providedLoans[0].isAutoRenew()).isEqualTo(false);
PoloniexLoan[] usedLoans = loansInfo.get("used");
assertThat(usedLoans).hasSize(1);
assertThat(usedLoans[0].getId()).isEqualTo("75238");
assertThat(usedLoans[0].getCurrency()).isEqualTo(Currency.BTC.getCurrencyCode());
assertThat(usedLoans[0].getRate()).isEqualTo("0.00020000");
assertThat(usedLoans[0].getAmount()).isEqualTo("0.04843834");
assertThat(usedLoans[0].getRange()).isEqualTo(2);
assertThat(usedLoans[0].getDate()).isEqualTo("2015-05-10 23:51:12");
assertThat(usedLoans[0].getFees()).isEqualTo("-0.00000001");
}
use of org.knowm.xchange.poloniex.dto.account.PoloniexLoan in project XChange by knowm.
the class PoloniexAdapters method adaptPoloniexLoans.
public static LoanInfo adaptPoloniexLoans(HashMap<String, PoloniexLoan[]> poloniexLoans) {
Map<String, List<LoanOrder>> loans = new HashMap<>();
for (Map.Entry<String, PoloniexLoan[]> item : poloniexLoans.entrySet()) {
List<LoanOrder> loanOrders = new ArrayList<>();
for (PoloniexLoan poloniexLoan : item.getValue()) {
Date date = PoloniexUtils.stringToDate(poloniexLoan.getDate());
loanOrders.add(new FixedRateLoanOrder(OrderType.ASK, poloniexLoan.getCurrency(), poloniexLoan.getAmount(), poloniexLoan.getRange(), poloniexLoan.getId(), date, // TODO
poloniexLoan.getRate()));
}
loans.put(item.getKey(), loanOrders);
}
return new LoanInfo(loans.get("provided"), loans.get("used"));
}
Aggregations