joaopsilva / binance-java-api

binance-java-api is a lightweight Java library for the Binance API, supporting synchronous and asynchronous requests, as well as event streaming using WebSockets.
208 stars 803 forks source link

How do I place a futures order and then place take profit and stop loss? #52

Open KingIthra opened 2 years ago

KingIthra commented 2 years ago

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

brunobuger commented 1 year ago

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);