Petersoj / alpaca-java

A Java API for Alpaca, the commission free, algo friendly, stock trading broker. https://alpaca.markets
https://petersoj.github.io/alpaca-java/
MIT License
197 stars 82 forks source link

error when using requestNewStopLimitBracketOrder #44

Closed peterboivin closed 4 years ago

peterboivin commented 4 years ago
public Order requestNewStopLimitBracketOrder(String symbol, Integer quantity, OrderSide side,
        OrderTimeInForce timeInForce, Double limitPrice, Double stopPrice, Boolean extendedHours,
        Double takeProfitLimitPrice, Double stopLossStopPrice, Double stopLossLimitPrice)
        throws AlpacaAPIRequestException {
    return requestNewOrder(symbol, quantity, side, OrderType.STOP_LIMIT, timeInForce, limitPrice, stopPrice,
            extendedHours, null, OrderClass.BRACKET, takeProfitLimitPrice, stopLossStopPrice, stopLossLimitPrice);
}

Order order = alpacaAPI.requestNewStopLimitBracketOrder(symbol, 1, OrderSide.BUY, OrderTimeInForce.DAY, barPlusList.get(1).getC(), barPlusList.get(1).getC() .10, false, barPlusList.get(1).getC() .10, barPlusList.get(0).getL(), barPlusList.get(0).getL());

io.github.mainstringargs.alpaca.rest.exception.AlpacaAPIRequestException: Alpaca API Request Exception! : Status Code = 422, Status Text = "Unprocessable Entity", API Response Code = 40010001, API Response Message = "bracket orders must be market or limit orders" at io.github.mainstringargs.alpaca.AlpacaAPI.requestNewOrder(AlpacaAPI.java:466) at io.github.mainstringargs.alpaca.AlpacaAPI.requestNewStopLimitBracketOrder(AlpacaAPI.java:677) at com.boivin.TradingApplication.openStopLimitBracketOrder(TradingApplication.java:190) at com.boivin.TradingApplication.trade(TradingApplication.java:154) at com.boivin.TradingApplication.lambda$null$0(TradingApplication.java:120) at java.util.ArrayList.forEach(ArrayList.java:1257) at com.boivin.TradingApplication.lambda$main$2(TradingApplication.java:106) at java.util.ArrayList.forEach(ArrayList.java:1257) at com.boivin.TradingApplication.main(TradingApplication.java:71) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)

Petersoj commented 4 years ago

Status Code = 422, Status Text = "Unprocessable Entity", API Response Code = 40010001, API Response Message = "bracket orders must be market or limit orders" Looks like bracket orders can't have an initial order of stop limit or stop types. I'll make a PR to remove those method signatures. Edit: PR https://github.com/mainstringargs/alpaca-java/pull/45 requested

mainstringargs commented 4 years ago

Included in release 5.0.6