binance-java-api
binance-java-api copied to clipboard
How do I place a futures order and then place take profit and stop loss?
Please show me a an example written in Java as to how to place a futures order followed by take profit and stop loss, I don't understand how to do this, please advise
Hi @KingIthra, you need to open 3 orders in order to do that, i.e:
//original order
client.newOrder(marketSell(pair.toString(), size.toString()));
// tp
NewOrder tpOrder = new NewOrder(pair.toString(), OrderSide.BUY, com.binance.api.client.domain.OrderType.TAKE_PROFIT_LIMIT, TimeInForce.GTC, size.toString(), tp.toString());
tpOrder.stopPrice(tp.toString());
client.newOrder(tpOrder);
// sl
NewOrder slOrder = new NewOrder(pair.toString(), OrderSide.BUY, com.binance.api.client.domain.OrderType.STOP_LOSS_LIMIT, TimeInForce.GTC, size.toString(), sl.toString());
slOrder.stopPrice(sl.toString());
client.newOrder(slOrder);