This code has been working fine for about a month against a paper trading account, but today it threw this error:
[ERROR] APIError: failed to calculate cost basis
Traceback (most recent call last):
File “/var/task/lambda_main.py”, line 141, in lambda_handler
order = api.submit_order(STOCK_ASSET_ID, shares_to_buy, ‘buy’, ‘market’, ‘day’)
File “/var/task/alpaca_trade_api/rest.py”, line 236, in submit_order
resp = self.post(’/orders’, params)
File “/var/task/alpaca_trade_api/rest.py”, line 152, in post
return self._request(‘POST’, path, data)
File “/var/task/alpaca_trade_api/rest.py”, line 112, in _request
return self._one_request(method, url, opts, retry)
File “/var/task/alpaca_trade_api/rest.py”, line 141, in _one_request
raise APIError(error, http_error)
My code is the lambda_main.py which is calling submit_order on a REST api instance. I traced this down and it appears that the API is calling Alpaca to execute the order but Alpaca is sending back an HTTP 500 error code which triggers the APIError in rest.py line 141.
My code retried this 2 more times over a couple minutes and same problem each time.
I Googled for this error with no luck. Does anyone know what it means?