When I try to receive the data from BTC/USD, I receive the following error
{“message”:“Invalid location: CryptoFeed.US ”}
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://data.alpaca.markets/v1beta3/crypto/CryptoFeed.US/bars?start=2023-04-15T00%3A00%3A00Z&end=2023-04-17T00%3A00%3A00Z&timeframe=1Hour&symbols=BTC%2FUSD
During handling of the above exception, another exception occurred:
alpaca.common.exceptions.APIError: {“message”:“Invalid location: CryptoFeed.US ”}
I got the same error…
I believe it is a bug from Alpaca system on the crypto’s? As last week I was getting another error again on the crypto’s on “get_all_assets” (for stock this was working), and I had to upgrade the module to version 0.8.2 to see it fixed. So I suspect something wrong on the crypto’s app has yet to be fixed…
I also tried to replicate their basic procedure for crypto request (Getting Started | Alpaca Docs ), to see if I was doing anything wrong, but I can see the same error again…
Even I got the same error…was anyone able to get it working ?
joshw
May 21, 2023, 10:41pm
4
Having the same problem here.
I found the issue. In the requests URL it seems the parameter for the feed is “CryptoFeed.US ” where in the API docs it is just ‘us’. To fix this in the python SDK I set the feed parameter to ‘feed = “us”’ which fixed the request and validated it. In the URL above you just need to change the ‘CryptoFeed.US ’ part to ‘us’. Let me know if it works for you!
3 Likes
Thank you for recommending the changes…it worked for me.
1 Like
opened 11:06AM - 28 Apr 23 UTC
### Is there an existing issue for this?
- [X] I have searched the existing iss… ues
### Current Behavior
From following the example from https://alpaca.markets/docs/market-data/getting-started/
```from alpaca.data.historical import CryptoHistoricalDataClient
from alpaca.data.requests import CryptoBarsRequest
from alpaca.data.timeframe import TimeFrame
# no keys required for crypto data
client = CryptoHistoricalDataClient()
request_params = CryptoBarsRequest(
symbol_or_symbols=["BTC/USD", "ETH/USD"],
timeframe=TimeFrame.Day,
start=datetime.datetime(2022,07,01)
)
bars = client.get_crypto_bars(request_params)
```
```
File "/opt/homebrew/lib/python3.11/site-packages/alpaca/common/rest.py", line 196, in _one_request
response.raise_for_status()
File "/opt/homebrew/lib/python3.11/site-packages/requests/models.py", line 1021, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: **https://data.alpaca.markets/v1beta3/crypto/CryptoFeed.US/bars?start=2023-01-01T00%3A00%3A00Z&timeframe=1Day&symbols=BTC%2FUSD%2CETH%2FUSD**
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/zaighumrajput/PKM/Projects/CapitalResearch/catalogs/alpaca_client.py", line 50, in <module>
bars = client.get_crypto_bars(request_params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/alpaca/data/historical/crypto.py", line 88, in get_crypto_bars
raw_bars = self._data_get(
^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/alpaca/data/historical/crypto.py", line 358, in _data_get
response = self.get(path=path, data=params, api_version=api_version)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/alpaca/common/rest.py", line 221, in get
return self._request("GET", path, data, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/alpaca/common/rest.py", line 129, in _request
return self._one_request(method, url, opts, retry)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/alpaca/common/rest.py", line 205, in _one_request
raise APIError(error, http_error)
**alpaca.common.exceptions.APIError: {"message":"Invalid location: CryptoFeed.US"}**
```
I believe:
**https://data.alpaca.markets/v1beta3/crypto/CryptoFeed.US/bars?start=2023-01-01T00%3A00%3A00Z&timeframe=1Day&symbols=BTC%2FUSD%2CETH%2FUSD**
is not resolving correctly.
Perhaps, `alpaca.data.enums.CryptoFeed.US` enum does not seem to resolve to 'us'
If I do the following it seems to work fine.
```
bars = client.get_crypto_bars(request_params , feed = "us")
print(bars)
```
### Expected Behavior
_No response_
### SDK Version I encountered this issue in
pip3 show alpaca_py
Name: alpaca-py
Version: 0.8.2
Summary: The Official Python SDK for Alpaca APIs
Home-page: https://github.com/alpacahq/alpaca-py
Author: Rahul Chowdhury
Author-email: rahul.chowdhury@alpaca.markets
License: Apache-2.0
Location: /opt/homebrew/lib/python3.11/site-packages
### Steps To Reproduce
```markdown
alpaca.data.historical import CryptoHistoricalDataClient
from alpaca.data.requests import CryptoBarsRequest
from alpaca.data.timeframe import TimeFrame
# no keys required for crypto data
client = CryptoHistoricalDataClient()
request_params = CryptoBarsRequest(
symbol_or_symbols=["BTC/USD", "ETH/USD"],
timeframe=TimeFrame.Day,
start=datetime.datetime(2022,07,01)
)
bars = client.get_crypto_bars(request_params)
```
### Filled out the Steps to Reproduce section?
- [X] I have entered valid steps to reproduce my issue or have attached a minimally reproducible case in code that shows my issue happening; and understand that without this my issue will be flagged as invalid and closed after 30 days.
### Anything else?
_No response_
This issue is tracked here.
Fixed it by using python 3.8