Search in sources :

Example 1 with PoloniexLoan

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");
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType) InputStream(java.io.InputStream) PoloniexLoan(org.knowm.xchange.poloniex.dto.account.PoloniexLoan) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 2 with PoloniexLoan

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"));
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) FixedRateLoanOrder(org.knowm.xchange.dto.trade.FixedRateLoanOrder) LoanOrder(org.knowm.xchange.dto.LoanOrder) Date(java.util.Date) FixedRateLoanOrder(org.knowm.xchange.dto.trade.FixedRateLoanOrder) ArrayList(java.util.ArrayList) List(java.util.List) LoanInfo(org.knowm.xchange.poloniex.dto.LoanInfo) HashMap(java.util.HashMap) Map(java.util.Map) PoloniexLoan(org.knowm.xchange.poloniex.dto.account.PoloniexLoan)

Aggregations

PoloniexLoan (org.knowm.xchange.poloniex.dto.account.PoloniexLoan)2 JavaType (com.fasterxml.jackson.databind.JavaType)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Test (org.junit.Test)1 LoanOrder (org.knowm.xchange.dto.LoanOrder)1 FixedRateLoanOrder (org.knowm.xchange.dto.trade.FixedRateLoanOrder)1 LoanInfo (org.knowm.xchange.poloniex.dto.LoanInfo)1