alpacahq / alpaca-py

The Official Python SDK for Alpaca API
https://alpaca.markets/sdks/python/getting_started.html
Apache License 2.0
505 stars 125 forks source link

[Bug]: Unable to execute ReplaceOrderRequest on a stop loss order #412

Closed k- closed 5 months ago

k- commented 5 months ago

Is there an existing issue for this?

Current Behavior

Stop orders seemingly can't have their stop price updated. Trying to issue a ReplaceOrderRequest with a new stop limit will throw an error

Expected Behavior

The stop order should be updated to use the new price as specified in the request.

SDK Version I encountered this issue in

Package Version


alpaca-py 0.13.3

Steps To Reproduce

Repro:

  1. Create a stop order (I used a sell side stop order for an equity I owned, in paper)
  2. Copy the ID of that order, put it in order_id_copied_from_web_interface
  3. In python, set up a trading client and issue a ReplaceOrderRequest like so:
order = trading_client.replace_order_by_id(order_id=order_id_copied_from_web_interface,
    order_data=ReplaceOrderRequest(
        stop_loss=53.2 # of course use some value that makes sense in your case
    ))

When you execute that request, you'll get the following error:

alpaca.common.exceptions.APIError: {"code":42210000,"message":"order parameters are not changed"}

Filled out the Steps to Reproduce section?

Anything else?

No response

k- commented 5 months ago

The problem is that I was using stop_loss (carried over from a bracket order) instead of stop_price.