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
834 stars 627 forks source link

NewOCO execution failed #420

Closed OliverMaas closed 2 years ago

OliverMaas commented 2 years ago

Hi, tried to execute java code with BinanceApiRestClient:

NewOCO oco = new NewOCO("XRPUSDT", OrderSide.SELL, "200", "0.7633", "0.7625");
var response = rs.newOCO(oco);

Error message:

Exception in thread "main" com.binance.api.client.exception.BinanceApiException: Stop loss orders are not supported for this symbol.
at com.binance.api.client.impl.BinanceApiServiceGenerator.executeSync(BinanceApiServiceGenerator.java:93)
at com.binance.api.client.impl.BinanceApiRestClientImpl.newOCO(BinanceApiRestClientImpl.java:203)

I don't understand why I can execute a OCO SELL for XRPUSDT in the android-binance-app, but not with that java code.

OliverMaas commented 2 years ago

How to solve: Open java class NewOCO and change constructor from:

public NewOCO(String symbol, OrderSide side, String quantity, String price, String stopPrice) {
        this.symbol = symbol;
        this.side = side;
        this.quantity = quantity;
        this.price = price;
        this.stopPrice = stopPrice;
        this.timestamp = System.currentTimeMillis();
        this.recvWindow = BinanceApiConstants.DEFAULT_RECEIVING_WINDOW;
    }

to

public NewOCO(String symbol, OrderSide side, String quantity, String price, String stopPrice, String stopLimitPrice, TimeInForce stopLimitTimeInForce) {
        this.symbol = symbol;
        this.side = side;
        this.quantity = quantity;
        this.price = price;
        this.stopPrice = stopPrice;
        this.stopLimitPrice = stopLimitPrice;
        this.stopLimitTimeInForce = stopLimitTimeInForce;
        this.timestamp = System.currentTimeMillis();        
        this.recvWindow = BinanceApiConstants.DEFAULT_RECEIVING_WINDOW;
    }

Now it works :-) <Party smiley.>

joaopsilva commented 2 years ago

Could you please submit a PR with the change @OliverMaas ? Thanks.