alpacahq / alpacahq/alpaca-py

[Bug]: News docs suggest no API key is needed but fails assertion when api_key missing

Open
#602 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
1.5k
Forks
398
Avg merge
1d 16h
Merged PRs (30d)
6

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### Current Behavior

When I run the code sample under `Querying News Data` [from the PyPi docs page](https://pypi.org/project/alpaca-py/#data-api-example), it fails because no `api_key` or `secret_key` is supplied, despite the comment reading `# no keys required for news data`:

```python3
from alpaca.data.historical.news import NewsClient
from alpaca.data.requests import NewsRequest
from datetime import datetime

# no keys required for news data
client = NewsClient()

request_params = NewsRequest(
symbols="TSLA",
start=datetime.strptime("2022-07-01", '%Y-%m-%d')
)

news = client.get_news(request_params)

# convert to dataframe
news.df
```

results in the following stack trace:
```sh
File "/path/to/src.py", line 6, in
client = NewsClient()
File "/path/to/venv/lib/python3.13/site-packages/alpaca/data/historical/news.py", line 38, in __init__
super().__init__(
~~~~~~~~~~~~~~~~^
api_key=api_key,
^^^^^^^^^^^^^^^^
...<6 lines>...
raw_data=raw_data,
^^^^^^^^^^^^^^^^^^
)
^
File "/path/to/venv/lib/python3.13/site-packages/alpaca/common/rest.py", line 61, in __init__
self._api_key, self._secret_key, self._oauth_token = self._validate_credentials(
~~~~~~~~~~~~~~~~~~~~~~~~~~^
api_key=api_key, secret_key=secret_key, oauth_token=oauth_token
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/path/to/venv/lib/python3.13/site-packages/alpaca/common/rest.py", line 354, in _validate_credentials
raise ValueError("You must supply a method of authentication")
ValueError: You must supply a method of authentication
```

### Expected Behavior

The code snippet should be a functional example

### SDK Version I encountered this issue in

alpaca-py-0.40.1

### Steps To Reproduce

```markdown
`pip install alpaca-py`
copy and paste snippet from [pypi docs](https://pypi.org/project/alpaca-py/#data-api-example)
run the code
```

### 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?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.