Search in sources :

Example 1 with BitfinexReplaceOrderRequest

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

the class BitfinexTradeServiceRaw method sendLimitOrder.

private BitfinexOrderStatusResponse sendLimitOrder(LimitOrder limitOrder, BitfinexOrderType bitfinexOrderType, long replaceOrderId) throws IOException {
    String pair = BitfinexUtils.toPairStringV1(limitOrder.getCurrencyPair());
    String type = (limitOrder.getType().equals(Order.OrderType.BID) || limitOrder.getType().equals(Order.OrderType.EXIT_ASK)) ? "buy" : "sell";
    String orderType = bitfinexOrderType.toString();
    boolean isHidden;
    if (limitOrder.hasFlag(BitfinexOrderFlags.HIDDEN)) {
        isHidden = true;
    } else {
        isHidden = false;
    }
    boolean isPostOnly;
    if (limitOrder.hasFlag(BitfinexOrderFlags.POST_ONLY)) {
        isPostOnly = true;
    } else {
        isPostOnly = false;
    }
    BitfinexOrderStatusResponse response;
    if (replaceOrderId == Long.MIN_VALUE) {
        // order entry
        BigDecimal ocoAmount = limitOrder instanceof BitfinexLimitOrder ? ((BitfinexLimitOrder) limitOrder).getOcoStopLimit() : null;
        BitfinexNewOrderRequest request = new BitfinexNewOrderRequest(String.valueOf(exchange.getNonceFactory().createValue()), pair, limitOrder.getOriginalAmount(), limitOrder.getLimitPrice(), "bitfinex", type, orderType, isHidden, isPostOnly, ocoAmount);
        response = decorateApiCall(() -> bitfinex.newOrder(apiKey, payloadCreator, signatureCreator, request)).withRateLimiter(rateLimiter(BITFINEX_RATE_LIMITER)).call();
    } else {
        // order amend
        boolean useRemaining = limitOrder.hasFlag(BitfinexOrderFlags.USE_REMAINING);
        BitfinexReplaceOrderRequest request = new BitfinexReplaceOrderRequest(String.valueOf(exchange.getNonceFactory().createValue()), replaceOrderId, pair, limitOrder.getOriginalAmount(), limitOrder.getLimitPrice(), "bitfinex", type, orderType, isHidden, isPostOnly, useRemaining);
        response = decorateApiCall(() -> bitfinex.replaceOrder(apiKey, payloadCreator, signatureCreator, request)).withRateLimiter(rateLimiter(BITFINEX_RATE_LIMITER)).call();
    }
    if (limitOrder instanceof BitfinexLimitOrder) {
        BitfinexLimitOrder bitfinexOrder = (BitfinexLimitOrder) limitOrder;
        bitfinexOrder.setResponse(response);
    }
    return response;
}
Also used : BitfinexNewOrderRequest(org.knowm.xchange.bitfinex.v1.dto.trade.BitfinexNewOrderRequest) BitfinexOrderStatusResponse(org.knowm.xchange.bitfinex.v1.dto.trade.BitfinexOrderStatusResponse) BigDecimal(java.math.BigDecimal) BitfinexLimitOrder(org.knowm.xchange.bitfinex.v1.dto.trade.BitfinexLimitOrder) BitfinexReplaceOrderRequest(org.knowm.xchange.bitfinex.v1.dto.trade.BitfinexReplaceOrderRequest)

Example 2 with BitfinexReplaceOrderRequest

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

the class BitfinexTradeService method changeOrder.

@Override
public String changeOrder(LimitOrder order) throws IOException {
    boolean useRemaining = order.getOriginalAmount() == null || order.hasFlag(BitfinexOrderFlags.USE_REMAINING);
    BitfinexReplaceOrderRequest request = new BitfinexReplaceOrderRequest(String.valueOf(exchange.getNonceFactory().createValue()), Long.valueOf(order.getId()), BitfinexAdapters.adaptCurrencyPair(order.getCurrencyPair()), order.getOriginalAmount(), order.getLimitPrice(), "bitfinex", BitfinexAdapters.adaptOrderType(order.getType()), BitfinexAdapters.adaptOrderFlagsToType(order.getOrderFlags()).getValue(), order.hasFlag(BitfinexOrderFlags.HIDDEN), order.hasFlag(BitfinexOrderFlags.POST_ONLY), useRemaining);
    try {
        BitfinexOrderStatusResponse response = bitfinex.replaceOrder(apiKey, payloadCreator, signatureCreator, request);
        return String.valueOf(response.getId());
    } catch (BitfinexException e) {
        throw BitfinexErrorAdapter.adapt(e);
    }
}
Also used : BitfinexException(org.knowm.xchange.bitfinex.dto.BitfinexException) BitfinexOrderStatusResponse(org.knowm.xchange.bitfinex.v1.dto.trade.BitfinexOrderStatusResponse) BitfinexReplaceOrderRequest(org.knowm.xchange.bitfinex.v1.dto.trade.BitfinexReplaceOrderRequest)

Aggregations

BitfinexOrderStatusResponse (org.knowm.xchange.bitfinex.v1.dto.trade.BitfinexOrderStatusResponse)2 BitfinexReplaceOrderRequest (org.knowm.xchange.bitfinex.v1.dto.trade.BitfinexReplaceOrderRequest)2 BigDecimal (java.math.BigDecimal)1 BitfinexException (org.knowm.xchange.bitfinex.dto.BitfinexException)1 BitfinexLimitOrder (org.knowm.xchange.bitfinex.v1.dto.trade.BitfinexLimitOrder)1 BitfinexNewOrderRequest (org.knowm.xchange.bitfinex.v1.dto.trade.BitfinexNewOrderRequest)1