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;
}
Aggregations