Environment
Language
Python 3.8.5
Alpaca SDK Version
alpaca trade api 0.51
Other Environment Details
Both windows 10 and linux
Problem
Submitting a trailing order returns error for quantity on paper trading:
I have the following position open:
Position({ 'asset_class': 'us_equity',
'asset_id': 'f9700a20-b0fe-4516-87c5-9d7b096d5539',
'avg_entry_price': '29.15',
'change_today': '0.0013490725126476',
'cost_basis': '2157.1',
'current_price': '29.69',
'exchange': 'NYSE',
'lastday_price': '29.65',
'market_value': '2197.06',
'qty': '74',
'side': 'long',
'symbol': 'WFC',
'unrealized_intraday_pl': '2.96',
'unrealized_intraday_plpc': '0.0013490725126476',
'unrealized_pl': '39.96',
'unrealized_plpc': '0.01852487135506'})
and i want to fill a trailing stop order on that position:
order = api.submit_order(symbol='WFC',qty='74',side='sell',type='trailing_stop',trail_percent='1',time_in_force='gtc')
I receive an error on the quantity
APIError: insufficient qty available for order (requested: 74, available: 0)
But as you can see from the position the quantity of 74 is in the position, for that position i have also a cascading order open (take profit and stop loss).
Order({ 'asset_class': 'us_equity',
'asset_id': 'f9700a20-b0fe-4516-87c5-9d7b096d5539',
'canceled_at': None,
'client_order_id': '0c22053e-a918-488a-9711-d19de34d9209',
'created_at': '2020-12-10T15:18:42.75244Z',
'expired_at': None,
'extended_hours': False,
'failed_at': None,
'filled_at': None,
'filled_avg_price': None,
'filled_qty': '0',
'hwm': None,
'id': '3216de28-505b-44a1-842c-f4d0d1dac8af',
'legs': None,
'limit_price': '35.016',
'order_class': 'bracket',
'order_type': 'limit',
'qty': '74',
'replaced_at': None,
'replaced_by': None,
'replaces': None,
'side': 'sell',
'status': 'new',
'stop_price': None,
'submitted_at': '2020-12-10T15:18:42.923835Z',
'symbol': 'WFC',
'time_in_force': 'gtc',
'trail_percent': None,
'trail_price': None,
'type': 'limit',
'updated_at': '2020-12-10T15:18:42.939057Z'})
Let us know if you’re using the paper trading simulator or the live trading API.
Example Code
This is the trailing order function
def alpaca_trailing_sell_order(_symbol,_qty,_trailing_pct):
_order = api.submit_order(symbol=_symbol,qty=_qty,side='sell',type='trailing_stop',trail_percent=_trailing_pct,time_in_force='gtc')
return _order