requests.exceptions.HTTPError: 422 Client Error: Unprocessable Entity for url

candlesticks = alpaca_api.get_barset(ticker, ‘minute’, limit=1)

The above line threw the below error

ERR> OR: Traceback (most recent call last):

File “/Users/arighna/opt/anaconda3/lib/python3.7/site-packages/alpaca_trade_api/rest.py”, line 140, in _one_request
resp.raise_for_status()
File “/Users/arighna/opt/anaconda3/lib/python3.7/site-packages/requests/models.py”, line 941, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 422 Client Error: Unprocessable Entity for url: https://data.alpaca.markets/v1/bars/minute?symbols=LGF%2FB&limit=1

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “”, line 28, in
curr_price = get_curr_price(rating[‘ticker’], alpaca_api)
File “”, line 133, in get_curr_price
candlesticks = alpaca_api.get_barset(ticker, ‘minute’, limit=1)
File “/Users/arighna/opt/anaconda3/lib/python3.7/site-packages/alpaca_trade_api/rest.py”, line 453, in get_barset
resp = self.data_get(‘/bars/{}’.format(timeframe), params)
File “/Users/arighna/opt/anaconda3/lib/python3.7/site-packages/alpaca_trade_api/rest.py”, line 173, in data_get
‘GET’, path, data, base_url=base_url, api_version=‘v1’
File “/Users/arighna/opt/anaconda3/lib/python3.7/site-packages/alpaca_trade_api/rest.py”, line 119, in _request
return self._one_request(method, url, opts, retry)
File “/Users/arighna/opt/anaconda3/lib/python3.7/site-packages/alpaca_trade_api/rest.py”, line 148, in _one_request
raise APIError(error, http_error)
alpaca_trade_api.rest.APIError: symbols cannot contains slashes

Python error messages save the best for last. Typically look at the very last line to get an idea of the problem. In this case

alpaca_trade_api.rest.APIError: symbols cannot contains slashes

Check the variable ticker. Does it contain a valid ticker (eg IBM) and no slashes? The following works

ticker = 'IBM'
candlesticks = alpaca_api.get_barset(ticker, ‘minute’, limit=1)

While this generates the error you are seeing

ticker = 'IBM/'
candlesticks = alpaca_api.get_barset(ticker, ‘minute’, limit=1)

Hope that helps.

3 Likes

Prepare Market order

market_order_data = ClosePositionRequest(
symbol= str(symbol.upper()),
percentage = str(100)
#qty = str(1.0)
)

Submit Market order

market_order = trading_client.submit_order(
order_data=market_order_data
)

alpaca.common.exceptions.APIError: {“code”: 40010001,“message”:qty or notional is required"}

Kindly help:
What is the correct syntax for ClosePositionRequest for a specific SYMBOL.