[Bug]: BrokerClient don't support Bearer auth?
- Lenguaje dominante
- Python
- Estrellas
- 1.5k
- Forks
- 398
- Merge medio
- 1 d 16 h
- PR fusionados (30 d)
- 6
Descripción
### Is there an existing issue for this?
- [x] I have searched the existing issues
### Current Behavior
I registered at Broker dashboard. Created sandbox Credentials with "Client Secret" type.
When trying to use them in basic example for BrokerClient from readme file of this repo - it fails due "unauthorized" error.
By checking code i didnt find clues that BrokerClient support non-Basic auth.
Can anyone confirm this? should I create my own Client to use with non-Legacy Credentials?
### Expected Behavior
Authentication must works with Client Secret credentials
### SDK Version I encountered this issue in
alpaca-py==0.43.2
### Steps To Reproduce
```markdown
install alpaca-py==0.43.2
open Python
execute example code for BrokerClient from Readme file using Client Secret sandbox credentials
```
### 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?
```
>>> from alpaca.broker.client import BrokerClient
>>> from alpaca.broker.requests import ListAAccountsRequest
Traceback (most recent call last):
File "", line 1, in
from alpaca.broker.requests import ListAAccountsRequest
ImportError: cannot import name 'ListAAccountsRequest' from 'alpaca.broker.requests' (/home/oleksandr/work/virtual_am/.venv/lib/python3.13/site-packages/alpaca/broker/requests.py)
>>> from alpaca.broker.requests import ListAccountsRequest
>>> from alpaca.broker.enums import AccountEntities
>>> broker_client = BrokerClient('', '')
>>> filter = ListAccountsRequest(entities=[AccountEntities.CONTACT, AccountEntities.IDENTITY])
>>> accounts = broker_client.list_accounts(search_parameters=filter)
Traceback (most recent call last):
File "/home/oleksandr/work/virtual_am/.venv/lib/python3.13/site-packages/alpaca/common/rest.py", line 198, in _one_request
response.raise_for_status()
~~~~~~~~~~~~~~~~~~~~~~~~~^^
File "/home/oleksandr/work/virtual_am/.venv/lib/python3.13/site-packages/requests/models.py", line 1026, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://broker-api.sandbox.alpaca.markets/v1/accounts?sort=desc&entities=contact%2Cidentity
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "", line 1, in
accounts = broker_client.list_accounts(search_parameters=filter)
File "/home/oleksandr/work/virtual_am/.venv/lib/python3.13/site-packages/alpaca/broker/client.py", line 382, in list_accounts
response = self.get(
f"/accounts",
params,
)
File "/home/oleksandr/work/virtual_am/.venv/lib/python3.13/site-packages/alpaca/common/rest.py", line 225, in get
return self._request("GET", path, data, **kwargs)
~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/oleksandr/work/virtual_am/.venv/lib/python3.13/site-packages/alpaca/common/rest.py", line 131, in _request
return self._one_request(method, url, opts, retry)
~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/oleksandr/work/virtual_am/.venv/lib/python3.13/site-packages/alpaca/common/rest.py", line 207, in _one_request
raise APIError(error, http_error)
alpaca.common.exceptions.APIError: {"message": "unauthorized."}
>>> broker_client = BrokerClient(api_key='', secret_key='', sandbox=True)
>>> accounts = broker_client.list_accounts(search_parameters=filter)
Traceback (most recent call last):
File "/home/oleksandr/work/virtual_am/.venv/lib/python3.13/site-packages/alpaca/common/rest.py", line 198, in _one_request
response.raise_for_status()
~~~~~~~~~~~~~~~~~~~~~~~~~^^
File "/home/oleksandr/work/virtual_am/.venv/lib/python3.13/site-packages/requests/models.py", line 1026, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://broker-api.sandbox.alpaca.markets/v1/accounts?sort=desc&entities=contact%2Cidentity
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "", line 1, in
accounts = broker_client.list_accounts(search_parameters=filter)
File "/home/oleksandr/work/virtual_am/.venv/lib/python3.13/site-packages/alpaca/broker/client.py", line 382, in list_accounts
response = self.get(
f"/accounts",
params,
)
File "/home/oleksandr/work/virtual_am/.venv/lib/python3.13/site-packages/alpaca/common/rest.py", line 225, in get
return self._request("GET", path, data, **kwargs)
~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/oleksandr/work/virtual_am/.venv/lib/python3.13/site-packages/alpaca/common/rest.py", line 131, in _request
return self._one_request(method, url, opts, retry)
~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/oleksandr/work/virtual_am/.venv/lib/python3.13/site-packages/alpaca/common/rest.py", line 207, in _one_request
raise APIError(error, http_error)
alpaca.common.exceptions.APIError: {"message": "unauthorized."}
```
Guía de contribución
Evaluación
Este issue todavía no se ha evaluado.