Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Unexpected Data API Endpoints #556

Open
2 tasks done
kushalj1997 opened this issue Jan 28, 2025 · 4 comments
Open
2 tasks done

[Bug]: Unexpected Data API Endpoints #556

kushalj1997 opened this issue Jan 28, 2025 · 4 comments

Comments

@kushalj1997
Copy link
Contributor

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

Hi,

I've installed alpaca-py 0.33.1 directly by cloning the repo and running pip install -e . so I can work with a developer copy if needed. I'm running into problems with the OptionHistoricalDataClient.

option_bars_request = OptionBarsRequest(
            symbol_or_symbols=symbol,
            timeframe=TimeFrame.Minute,
            start=trading_day + dt.timedelta(hours=9),
            end=trading_day + dt.timedelta(hours=9) + dt.timedelta(minutes=390),
            limit=None,
            sort=Sort.ASC,
        )
Traceback (most recent call last):
  File "/Users/jollygama/dev/repos/alpaca-py/alpaca-py/alpaca/common/rest.py", line 198, in _one_request
    response.raise_for_status()
  File "/opt/homebrew/lib/python3.11/site-packages/requests/models.py", line 1024, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: https://data.alpaca.markets/v1beta1/options/bars?start=2024-11-28T00%3A00%3A00%2B00%3A00&end=2024-11-28T00%3A00%3A00%2B00%3A00&sort=asc&timeframe=1Min&symbols=TSLA

When I log into alpaca to generate keys, the API endpoint is https://api.alpaca.markets - the python API is using the wrong URL, and it seems to also point to the incorrect version of the API. Is the expectation to give up on the python API from alpaca and just use the requests based examples in the API reference page? If so, this repo should be updated to reflect.

Expected Behavior

No response

SDK Version I encountered this issue in

alpaca-py version: 0.33.1

Steps To Reproduce

Even the Option trading example ipynb is broken.

Filled out the Steps to Reproduce section?

  • 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

@hiohiohio
Copy link
Contributor

@kushalj1997 could you please confirm that supplied API key/secret is correct or not? The 403 Forbidden could happen with invalid API key/secret usually. I have got another error by calling the mentioned URL with my API key/secret which is specifying equity symbol (i.e. TSLA) to get options contracts data.

@kushalj1997
Copy link
Contributor Author

yeah verified that my keys are correct by passing them into the API reference documentation page which allows sampling of the API requests

@kushalj1997
Copy link
Contributor Author

kushalj1997 commented Jan 29, 2025

It seems like the error changed from the one I originally posted to the one that you are getting, with not being able to parse "TSLA" as a valid symbol, so I think we have the same errors! Not sure what went wrong in the past couple of days to make the error literally change across the same lines of code.

$ python3 alpaca_data_loader.py
AlpacaDataLoader initialized
Traceback (most recent call last):
  File "/Users/jollygama/dev/repos/alpaca-py/alpaca-py/alpaca/common/rest.py", line 198, in _one_request
    response.raise_for_status()
  File "/opt/homebrew/lib/python3.11/site-packages/requests/models.py", line 1024, 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/v1beta1/options/bars?start=2024-11-28T00%3A00%3A00%2B00%3A00&end=2024-11-28T00%3A00%3A00%2B00%3A00&sort=asc&timeframe=1Min&symbols=AAPL

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/jollygama/dev/projects/deep-trader-0/deep-trader/alpaca_data_loader.py", line 152, in <module>
    alpaca_data_loader.get_option_market_price_bars_training_sample(
  File "/Users/jollygama/dev/projects/deep-trader-0/deep-trader/alpaca_data_loader.py", line 130, in get_option_market_price_bars_training_sample
    option_bar_set = self.option_client.get_option_bars(option_bars_request)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jollygama/dev/repos/alpaca-py/alpaca-py/alpaca/data/historical/option.py", line 88, in get_option_bars
    raw_bars = self._get_marketdata(
               ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jollygama/dev/repos/alpaca-py/alpaca-py/alpaca/common/rest.py", line 393, in _get_marketdata
    response = self.get(path=path, data=params)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jollygama/dev/repos/alpaca-py/alpaca-py/alpaca/common/rest.py", line 225, in get
    return self._request("GET", path, data, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jollygama/dev/repos/alpaca-py/alpaca-py/alpaca/common/rest.py", line 131, in _request
    return self._one_request(method, url, opts, retry)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jollygama/dev/repos/alpaca-py/alpaca-py/alpaca/common/rest.py", line 207, in _one_request
    raise APIError(error, http_error)
alpaca.common.exceptions.APIError: {"message":"invalid symbol: \"AAPL\" does not match ^[A-Z]{1,5}\\d{6,7}[CP]\\d{8}$"}

sounds like the backend is broken - are you guys updating it as you work on multi-leg options?

@hiohiohio
Copy link
Contributor

hiohiohio commented Jan 30, 2025

@kushalj1997 Could you please try to input AAPL250221C00265000 instead of AAPL for symbol_or_symbols of OptionBarsRequest? It should be options contracts symbol not the equity symbol (i.e. underlying_symbol).

Only the option chain API endpoint supports specifying equity symbol (i.e. underlying_symbol) to fetch options market data currently.
https://docs.alpaca.markets/reference/optionchain

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants