Search in sources :

Example 1 with BitfinexLimitOrder

use of org.knowm.xchange.bitfinex.v1.dto.trade.BitfinexLimitOrder 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)

Aggregations

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