use of org.knowm.xchange.dto.trade.FloatingRateLoanOrder 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);
}
use of org.knowm.xchange.dto.trade.FloatingRateLoanOrder 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);
}
}
use of org.knowm.xchange.dto.trade.FloatingRateLoanOrder in project XChange by knowm.
the class LoanOrderBook method update.
public void update(FloatingRateLoanOrder updatedLoanOrder) {
Iterator<FloatingRateLoanOrder> it;
boolean rateChanged = false;
switch(updatedLoanOrder.getType()) {
case ASK:
it = floatingRateAsks.iterator();
while (it.hasNext()) {
FloatingRateLoanOrder order = it.next();
if (order.getDayPeriod() == updatedLoanOrder.getDayPeriod()) {
it.remove();
}
// check if the rate has changed and whether we know if it has changed
if (!order.getRate().equals(updatedLoanOrder.getRate()) && !rateChanged) {
rateChanged = true;
}
break;
}
floatingRateAsks.add(updatedLoanOrder);
Collections.sort(floatingRateAsks);
break;
case BID:
it = floatingRateBids.iterator();
while (it.hasNext()) {
FloatingRateLoanOrder order = it.next();
if (order.getDayPeriod() == updatedLoanOrder.getDayPeriod()) {
it.remove();
}
// check if the rate has changed and whether we know if it has changed
if (!order.getRate().equals(updatedLoanOrder.getRate()) && !rateChanged) {
rateChanged = true;
}
break;
}
floatingRateBids.add(updatedLoanOrder);
Collections.sort(fixedRateBids);
break;
default:
break;
}
if (rateChanged) {
for (FloatingRateLoanOrder order : floatingRateAsks) {
order.setRate(updatedLoanOrder.getRate());
}
for (FloatingRateLoanOrder order : floatingRateBids) {
order.setRate(updatedLoanOrder.getRate());
}
}
updateTimestamp(updatedLoanOrder.getTimestamp());
}
use of org.knowm.xchange.dto.trade.FloatingRateLoanOrder 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);
}
}
Aggregations