Search in sources :

Example 1 with FixedRateLoanOrder

use of org.knowm.xchange.dto.trade.FixedRateLoanOrder in project XChange by knowm.

the class GeminiMarketDataService method getLendOrderBook.

public LoanOrderBook getLendOrderBook(String currency, Object... args) throws IOException {
    // According to API docs, default is 50
    int limitBids = 50;
    int limitAsks = 50;
    if (args != null && args.length == 2) {
        Object arg0 = args[0];
        if (!(arg0 instanceof Integer)) {
            throw new ExchangeException("Argument 0 must be an Integer!");
        } else {
            limitBids = (Integer) arg0;
        }
        Object arg1 = args[1];
        if (!(arg1 instanceof Integer)) {
            throw new ExchangeException("Argument 1 must be an Integer!");
        } else {
            limitAsks = (Integer) arg1;
        }
    }
    GeminiLendDepth GeminiLendDepth = getGeminiLendBook(currency, limitBids, limitAsks);
    List<FixedRateLoanOrder> fixedRateAsks = GeminiAdapters.adaptFixedRateLoanOrders(GeminiLendDepth.getAsks(), currency, "ask", "");
    List<FixedRateLoanOrder> fixedRateBids = GeminiAdapters.adaptFixedRateLoanOrders(GeminiLendDepth.getBids(), currency, "bid", "");
    List<FloatingRateLoanOrder> floatingRateAsks = GeminiAdapters.adaptFloatingRateLoanOrders(GeminiLendDepth.getAsks(), currency, "ask", "");
    List<FloatingRateLoanOrder> floatingRateBids = GeminiAdapters.adaptFloatingRateLoanOrders(GeminiLendDepth.getBids(), currency, "bid", "");
    return new LoanOrderBook(null, fixedRateAsks, fixedRateBids, floatingRateAsks, floatingRateBids);
}
Also used : GeminiLendDepth(org.knowm.xchange.gemini.v1.dto.marketdata.GeminiLendDepth) LoanOrderBook(org.knowm.xchange.dto.marketdata.LoanOrderBook) FixedRateLoanOrder(org.knowm.xchange.dto.trade.FixedRateLoanOrder) ExchangeException(org.knowm.xchange.exceptions.ExchangeException) FloatingRateLoanOrder(org.knowm.xchange.dto.trade.FloatingRateLoanOrder)

Example 2 with FixedRateLoanOrder

use of org.knowm.xchange.dto.trade.FixedRateLoanOrder in project XChange by knowm.

the class BitfinexMarketDataService method getLendOrderBook.

public LoanOrderBook getLendOrderBook(String currency, Object... args) throws IOException {
    try {
        // According to API docs, default is 50
        int limitBids = 50;
        int limitAsks = 50;
        if (args != null && args.length == 2) {
            Object arg0 = args[0];
            if (!(arg0 instanceof Integer)) {
                throw new ExchangeException("Argument 0 must be an Integer!");
            } else {
                limitBids = (Integer) arg0;
            }
            Object arg1 = args[1];
            if (!(arg1 instanceof Integer)) {
                throw new ExchangeException("Argument 1 must be an Integer!");
            } else {
                limitAsks = (Integer) arg1;
            }
        }
        BitfinexLendDepth bitfinexLendDepth = getBitfinexLendBook(currency, limitBids, limitAsks);
        List<FixedRateLoanOrder> fixedRateAsks = BitfinexAdapters.adaptFixedRateLoanOrders(bitfinexLendDepth.getAsks(), currency, "ask", "");
        List<FixedRateLoanOrder> fixedRateBids = BitfinexAdapters.adaptFixedRateLoanOrders(bitfinexLendDepth.getBids(), currency, "bid", "");
        List<FloatingRateLoanOrder> floatingRateAsks = BitfinexAdapters.adaptFloatingRateLoanOrders(bitfinexLendDepth.getAsks(), currency, "ask", "");
        List<FloatingRateLoanOrder> floatingRateBids = BitfinexAdapters.adaptFloatingRateLoanOrders(bitfinexLendDepth.getBids(), currency, "bid", "");
        return new LoanOrderBook(null, fixedRateAsks, fixedRateBids, floatingRateAsks, floatingRateBids);
    } catch (BitfinexException e) {
        throw BitfinexErrorAdapter.adapt(e);
    }
}
Also used : LoanOrderBook(org.knowm.xchange.dto.marketdata.LoanOrderBook) FixedRateLoanOrder(org.knowm.xchange.dto.trade.FixedRateLoanOrder) BitfinexLendDepth(org.knowm.xchange.bitfinex.v1.dto.marketdata.BitfinexLendDepth) ExchangeException(org.knowm.xchange.exceptions.ExchangeException) BitfinexException(org.knowm.xchange.bitfinex.dto.BitfinexException) FloatingRateLoanOrder(org.knowm.xchange.dto.trade.FloatingRateLoanOrder)

Example 3 with FixedRateLoanOrder

use of org.knowm.xchange.dto.trade.FixedRateLoanOrder in project XChange by knowm.

the class LoanOrderBook method update.

public void update(FixedRateLoanOrder updatedLoanOrder) {
    Iterator<FixedRateLoanOrder> it;
    switch(updatedLoanOrder.getType()) {
        case ASK:
            it = fixedRateAsks.iterator();
            while (it.hasNext()) {
                FixedRateLoanOrder order = it.next();
                if (order.getRate().equals(updatedLoanOrder.getRate()) && order.getDayPeriod() == updatedLoanOrder.getDayPeriod()) {
                    it.remove();
                    break;
                }
            }
            fixedRateAsks.add(updatedLoanOrder);
            Collections.sort(fixedRateAsks);
            break;
        case BID:
            it = fixedRateBids.iterator();
            while (it.hasNext()) {
                FixedRateLoanOrder order = it.next();
                if (order.getRate().equals(updatedLoanOrder.getRate()) && order.getDayPeriod() == updatedLoanOrder.getDayPeriod()) {
                    it.remove();
                    break;
                }
            }
            fixedRateBids.add(updatedLoanOrder);
            Collections.sort(fixedRateBids);
            break;
        default:
            break;
    }
    updateTimestamp(updatedLoanOrder.getTimestamp());
}
Also used : FixedRateLoanOrder(org.knowm.xchange.dto.trade.FixedRateLoanOrder)

Example 4 with FixedRateLoanOrder

use of org.knowm.xchange.dto.trade.FixedRateLoanOrder in project XChange by knowm.

the class BitfinexOfferDemo method raw.

private static void raw(Exchange bfx) throws IOException {
    BitfinexTradeServiceRaw tradeService = (BitfinexTradeServiceRaw) bfx.getTradeService();
    BitfinexOfferStatusResponse fixedRateResponse = tradeService.placeBitfinexFixedRateLoanOrder(new FixedRateLoanOrder(OrderType.BID, "USD", new BigDecimal("0.01"), 2, "", null, new BigDecimal("0.01")), BitfinexOrderType.LIMIT);
    System.out.println("Fixed rate order response: " + fixedRateResponse);
    BitfinexOfferStatusResponse floatingRateResponse = tradeService.placeBitfinexFloatingRateLoanOrder(new FloatingRateLoanOrder(OrderType.BID, "USD", new BigDecimal("0.01"), 2, "", null, BigDecimal.ZERO), BitfinexOrderType.MARKET);
    System.out.println("Floating rate order response: " + floatingRateResponse);
    BitfinexCreditResponse[] activeCredits = tradeService.getBitfinexActiveCredits();
    System.out.println("Active credits: " + Arrays.toString(activeCredits));
    BitfinexOfferStatusResponse[] openOffers = tradeService.getBitfinexOpenOffers();
    System.out.println("Open offers response: " + Arrays.toString(openOffers));
    for (BitfinexOfferStatusResponse offer : openOffers) {
        BitfinexOfferStatusResponse cancelResponse = tradeService.cancelBitfinexOffer(Long.toString(offer.getId()));
        System.out.println("Cancel offer response: " + cancelResponse);
    }
}
Also used : FixedRateLoanOrder(org.knowm.xchange.dto.trade.FixedRateLoanOrder) BitfinexOfferStatusResponse(org.knowm.xchange.bitfinex.v1.dto.trade.BitfinexOfferStatusResponse) BitfinexCreditResponse(org.knowm.xchange.bitfinex.v1.dto.trade.BitfinexCreditResponse) BitfinexTradeServiceRaw(org.knowm.xchange.bitfinex.service.BitfinexTradeServiceRaw) BigDecimal(java.math.BigDecimal) FloatingRateLoanOrder(org.knowm.xchange.dto.trade.FloatingRateLoanOrder)

Example 5 with FixedRateLoanOrder

use of org.knowm.xchange.dto.trade.FixedRateLoanOrder 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

FixedRateLoanOrder (org.knowm.xchange.dto.trade.FixedRateLoanOrder)5 FloatingRateLoanOrder (org.knowm.xchange.dto.trade.FloatingRateLoanOrder)3 LoanOrderBook (org.knowm.xchange.dto.marketdata.LoanOrderBook)2 ExchangeException (org.knowm.xchange.exceptions.ExchangeException)2 BigDecimal (java.math.BigDecimal)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 BitfinexException (org.knowm.xchange.bitfinex.dto.BitfinexException)1 BitfinexTradeServiceRaw (org.knowm.xchange.bitfinex.service.BitfinexTradeServiceRaw)1 BitfinexLendDepth (org.knowm.xchange.bitfinex.v1.dto.marketdata.BitfinexLendDepth)1 BitfinexCreditResponse (org.knowm.xchange.bitfinex.v1.dto.trade.BitfinexCreditResponse)1 BitfinexOfferStatusResponse (org.knowm.xchange.bitfinex.v1.dto.trade.BitfinexOfferStatusResponse)1 LoanOrder (org.knowm.xchange.dto.LoanOrder)1 GeminiLendDepth (org.knowm.xchange.gemini.v1.dto.marketdata.GeminiLendDepth)1 LoanInfo (org.knowm.xchange.poloniex.dto.LoanInfo)1 PoloniexLoan (org.knowm.xchange.poloniex.dto.account.PoloniexLoan)1