Hi,
I’m using alpaca-py Python API. I’m trying to submit a market order, and try to protect it with a stop-loss and a limit-order as a profit-target. Since quantities are different (limit-order is only taking a fraction of the position), I can’t use the bracket market order.
Submitting the market order works:
req = MarketOrderRequest(
symbol = ‘AAPL’,
qty = 10,
side = OrderSide.BUY,
type = OrderType.MARKET,
time_in_force = TimeInForce.DAY
)
order = self.trade_client.submit_order(req)
Submitting the stop-loss order works (waited until market order is filled):
req = StopOrderRequest(
symbol = ‘AAPL’,
qty = 10,
side = OrderSide.SELL,
stop_price = <any price below market price>,
time_in_force= TimeInForce.DAY
)
order = self.trade_client.submit_order(order_data=req)
Submitting a limit-oder fails with the following error:
req = LimitOrderRequest(
symbol = 'AAPL',
qty = 5,
side = OrderSide.SELL,
limit_price = <any price above current price>,
time_in_force= TimeInForce.DAY
)
order = self.trade_client.submit_order(order_data=req)
requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: https://paper-api.alpaca.markets/v2/orders
alpaca.common.exceptions.APIError: {"available":"0","code":40310000,"existing_qty":"10","held_for_orders":"10","message":"insufficient qty available for order (requested: 5, available: 0)","symbol":"AAPL"}
How can I submit a stop-loss and limit-oder, which seems pretty straight forward, but Alpaca is rejecting?