Search in sources :

Example 1 with BitfinexNewOrderMultiRequest

use of org.knowm.xchange.bitfinex.v1.dto.trade.BitfinexNewOrderMultiRequest in project XChange by knowm.

the class BitfinexTradeServiceRaw method placeBitfinexOrderMulti.

public BitfinexNewOrderMultiResponse placeBitfinexOrderMulti(List<? extends Order> orders, BitfinexOrderType bitfinexOrderType) throws IOException {
    BitfinexNewOrder[] bitfinexOrders = new BitfinexNewOrder[orders.size()];
    for (int i = 0; i < bitfinexOrders.length; i++) {
        Order o = orders.get(i);
        if (o instanceof LimitOrder) {
            LimitOrder limitOrder = (LimitOrder) o;
            String pair = BitfinexUtils.toPairStringV1(limitOrder.getCurrencyPair());
            String type = (limitOrder.getType().equals(OrderType.BID) || limitOrder.getType().equals(OrderType.EXIT_ASK)) ? "buy" : "sell";
            String orderType = bitfinexOrderType.toString();
            bitfinexOrders[i] = new BitfinexNewOrder(pair, "bitfinex", type, orderType, limitOrder.getOriginalAmount(), limitOrder.getLimitPrice());
        } else if (o instanceof MarketOrder) {
            MarketOrder marketOrder = (MarketOrder) o;
            String pair = BitfinexUtils.toPairStringV1(marketOrder.getCurrencyPair());
            String type = (marketOrder.getType().equals(OrderType.BID) || marketOrder.getType().equals(OrderType.EXIT_ASK)) ? "buy" : "sell";
            String orderType = bitfinexOrderType.toString();
            bitfinexOrders[i] = new BitfinexNewOrder(pair, "bitfinex", type, orderType, marketOrder.getOriginalAmount(), BigDecimal.ONE);
        }
    }
    BitfinexNewOrderMultiRequest request = new BitfinexNewOrderMultiRequest(String.valueOf(exchange.getNonceFactory().createValue()), bitfinexOrders);
    return decorateApiCall(() -> bitfinex.newOrderMulti(apiKey, payloadCreator, signatureCreator, request)).withRateLimiter(rateLimiter(BITFINEX_RATE_LIMITER)).call();
}
Also used : BitfinexLimitOrder(org.knowm.xchange.bitfinex.v1.dto.trade.BitfinexLimitOrder) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) FixedRateLoanOrder(org.knowm.xchange.dto.trade.FixedRateLoanOrder) Order(org.knowm.xchange.dto.Order) BitfinexNewOrder(org.knowm.xchange.bitfinex.v1.dto.trade.BitfinexNewOrder) ActiveOrder(org.knowm.xchange.bitfinex.v2.dto.trade.ActiveOrder) FloatingRateLoanOrder(org.knowm.xchange.dto.trade.FloatingRateLoanOrder) MarketOrder(org.knowm.xchange.dto.trade.MarketOrder) BitfinexNewOrder(org.knowm.xchange.bitfinex.v1.dto.trade.BitfinexNewOrder) BitfinexNewOrderMultiRequest(org.knowm.xchange.bitfinex.v1.dto.trade.BitfinexNewOrderMultiRequest) MarketOrder(org.knowm.xchange.dto.trade.MarketOrder) BitfinexLimitOrder(org.knowm.xchange.bitfinex.v1.dto.trade.BitfinexLimitOrder) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder)

Aggregations

BitfinexLimitOrder (org.knowm.xchange.bitfinex.v1.dto.trade.BitfinexLimitOrder)1 BitfinexNewOrder (org.knowm.xchange.bitfinex.v1.dto.trade.BitfinexNewOrder)1 BitfinexNewOrderMultiRequest (org.knowm.xchange.bitfinex.v1.dto.trade.BitfinexNewOrderMultiRequest)1 ActiveOrder (org.knowm.xchange.bitfinex.v2.dto.trade.ActiveOrder)1 Order (org.knowm.xchange.dto.Order)1 FixedRateLoanOrder (org.knowm.xchange.dto.trade.FixedRateLoanOrder)1 FloatingRateLoanOrder (org.knowm.xchange.dto.trade.FloatingRateLoanOrder)1 LimitOrder (org.knowm.xchange.dto.trade.LimitOrder)1 MarketOrder (org.knowm.xchange.dto.trade.MarketOrder)1