binance-exchange / 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.
MIT License
831 stars 622 forks source link

How to create a Stop-Limit Orders!? #177

Open greekphilip opened 6 years ago

greekphilip commented 6 years ago

I have gone into the "NewOrder" class and added a constructor which takes the parameter "stopPrice".

public NewOrder(String symbol, OrderSide side, OrderType type, TimeInForce timeInForce, String quantity, String Price, String stopPrice){ this(symbol, side, type, timeInForce, quantity); this.price=price; this.stopPrice=stopPrice; }

I have also added two methods for creating stopLimitBuy and stopLimitSell orders.

public static NewOrder stopLimitSell(String symbol, TimeInForce timeInForce, String quantity, String price, String stopPrice){ return new NewOrder(symbol, OrderSide.SELL, OrderType.STOP_LOSS_LIMIT, timeInForce, quantity, price, stopPrice); }

public static NewOrder stopLimitBuy(String symbol, TimeInForce timeInForce, String quantity, String price, String stopPrice){ return new NewOrder(symbol, OrderSide.BUY, OrderType.STOP_LOSS_LIMIT, timeInForce, quantity, price, stopPrice); }

However when I try to create a new stop-limit order: client.newOrder(stopLimitBuy("BTCUSDT", TimeInForce.GTC, "0.035375", "5000","4999"));

the following error occurs:

Exception in thread "main" com.binance.api.client.exception.BinanceApiException: Mandatory parameter 'price' was not sent, was empty/null, or malformed.

What is going on? I can't find how to create a stop-limit order for java binance API anywhere.

Please help me, Thank you...

kakash commented 6 years ago

+1

kakash commented 6 years ago

bump

net968 commented 5 years ago

NewOrder order = new NewOrder( pair, OrderSide.SELL, OrderType.STOP_LOSS_LIMIT, TimeInForce.GTC, QTY, sellprice);

client.newOrder( order.stopPrice( stopprice ) );

lukasged commented 3 years ago

NewOrder order = new NewOrder( pair, OrderSide.SELL, OrderType.STOP_LOSS_LIMIT, TimeInForce.GTC, QTY, sellprice);

client.newOrder( order.stopPrice( stopprice ) );

Thanks for this reply, quite some time passed, but it still helped me 😅

It seems like this is still not documented, so not so easy to find out