Skip to content

Commit c4a9c6f

Browse files
committed
Make Yahoo, Alpha Vantage, and Polygon data providers optional extras
- Move yfinance, alpha_vantage, polygon-api-client from required to optional deps - Add poetry extras: [yahoo], [alpha_vantage], [polygon], [all] - Use lazy imports with placeholder classes that raise helpful ImportError - Only include available providers in get_default_data_providers() - Update installation docs with extras install commands - Add install hints to each provider section in data-sources docs
1 parent 33ae330 commit c4a9c6f

5 files changed

Lines changed: 126 additions & 24 deletions

File tree

docusaurus/docs/Data/data-sources.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,8 @@ The framework ships with built-in data providers for multiple markets. Set the `
354354

355355
Free, no API key required. Powered by the [yfinance](https://github.com/ranaroussi/yfinance) library using data from [Yahoo Finance](https://finance.yahoo.com/).
356356

357+
**Installation:** `pip install investing-algorithm-framework[yahoo]`
358+
357359
```python
358360
DataSource(
359361
identifier="aapl_daily",
@@ -379,6 +381,8 @@ DataSource(
379381

380382
Requires an API key from [Polygon.io](https://polygon.io/). Powered by the [polygon-api-client](https://github.com/polygon-io/client-python) library.
381383

384+
**Installation:** `pip install investing-algorithm-framework[polygon]`
385+
382386
```python
383387
from investing_algorithm_framework import MarketCredential
384388

@@ -410,6 +414,8 @@ DataSource(
410414

411415
Requires a free or premium API key from [Alpha Vantage](https://www.alphavantage.co/). Powered by the [alpha_vantage](https://github.com/RomelTorres/alpha_vantage) Python library.
412416

417+
**Installation:** `pip install investing-algorithm-framework[alpha_vantage]`
418+
413419
```python
414420
from investing_algorithm_framework import MarketCredential
415421

docusaurus/docs/Getting Started/installation.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,32 @@ Install the latest stable version from PyPI:
2424
pip install investing-algorithm-framework
2525
```
2626

27+
This installs the core framework with CCXT support for crypto exchanges.
28+
29+
### Optional Data Provider Extras
30+
31+
The framework supports additional data providers that can be installed as optional extras:
32+
33+
```bash
34+
# Yahoo Finance (stocks, ETFs, indices — free, no API key)
35+
pip install investing-algorithm-framework[yahoo]
36+
37+
# Alpha Vantage (stocks, forex, crypto — free API key required)
38+
pip install investing-algorithm-framework[alpha_vantage]
39+
40+
# Polygon.io (US stocks, options, forex, crypto — API key required)
41+
pip install investing-algorithm-framework[polygon]
42+
43+
# Install all optional data providers at once
44+
pip install investing-algorithm-framework[all]
45+
```
46+
47+
You can combine multiple extras:
48+
49+
```bash
50+
pip install investing-algorithm-framework[yahoo,polygon]
51+
```
52+
2753
### Option 2: Install from Source
2854

2955
For the latest development version, install directly from GitHub:

investing_algorithm_framework/infrastructure/data_providers/__init__.py

Lines changed: 69 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,51 @@
22
from .csv import CSVOHLCVDataProvider, CSVTickerDataProvider
33
from .pandas import PandasOHLCVDataProvider
44
from .ohlcv_base import OHLCVDataProviderBase
5-
from .yahoo import YahooOHLCVDataProvider
6-
from .alpha_vantage import AlphaVantageOHLCVDataProvider
7-
from .polygon import PolygonOHLCVDataProvider
5+
6+
7+
def _make_optional_provider_placeholder(name, package, extra):
8+
"""Create a placeholder class that raises ImportError on instantiation."""
9+
10+
class _Placeholder:
11+
def __init__(self, *args, **kwargs):
12+
raise ImportError(
13+
f"{package} is required for {name}. "
14+
f"Install it with: "
15+
f"pip install investing-algorithm-framework[{extra}]"
16+
)
17+
18+
_Placeholder.__name__ = name
19+
_Placeholder.__qualname__ = name
20+
return _Placeholder
21+
22+
23+
# Optional provider imports — only available when extras are installed
24+
try:
25+
from .yahoo import YahooOHLCVDataProvider
26+
_yahoo_available = True
27+
except ImportError:
28+
YahooOHLCVDataProvider = _make_optional_provider_placeholder(
29+
"YahooOHLCVDataProvider", "yfinance", "yahoo"
30+
)
31+
_yahoo_available = False
32+
33+
try:
34+
from .alpha_vantage import AlphaVantageOHLCVDataProvider
35+
_alpha_vantage_available = True
36+
except ImportError:
37+
AlphaVantageOHLCVDataProvider = _make_optional_provider_placeholder(
38+
"AlphaVantageOHLCVDataProvider", "alpha_vantage", "alpha_vantage"
39+
)
40+
_alpha_vantage_available = False
41+
42+
try:
43+
from .polygon import PolygonOHLCVDataProvider
44+
_polygon_available = True
45+
except ImportError:
46+
PolygonOHLCVDataProvider = _make_optional_provider_placeholder(
47+
"PolygonOHLCVDataProvider", "polygon-api-client", "polygon"
48+
)
49+
_polygon_available = False
850

951

1052
def get_default_data_providers():
@@ -14,14 +56,22 @@ def get_default_data_providers():
1456
Returns:
1557
list: List of default data providers.
1658
"""
17-
return [
59+
providers = [
1860
CCXTOHLCVDataProvider(),
1961
CCXTTickerDataProvider(),
20-
YahooOHLCVDataProvider(),
21-
AlphaVantageOHLCVDataProvider(),
22-
PolygonOHLCVDataProvider(),
2362
]
2463

64+
if _yahoo_available:
65+
providers.append(YahooOHLCVDataProvider())
66+
67+
if _alpha_vantage_available:
68+
providers.append(AlphaVantageOHLCVDataProvider())
69+
70+
if _polygon_available:
71+
providers.append(PolygonOHLCVDataProvider())
72+
73+
return providers
74+
2575

2676
def get_default_ohlcv_data_providers():
2777
"""
@@ -30,13 +80,21 @@ def get_default_ohlcv_data_providers():
3080
Returns:
3181
list: List of default OHLCV data providers.
3282
"""
33-
return [
83+
providers = [
3484
CCXTOHLCVDataProvider(),
35-
YahooOHLCVDataProvider(),
36-
AlphaVantageOHLCVDataProvider(),
37-
PolygonOHLCVDataProvider(),
3885
]
3986

87+
if _yahoo_available:
88+
providers.append(YahooOHLCVDataProvider())
89+
90+
if _alpha_vantage_available:
91+
providers.append(AlphaVantageOHLCVDataProvider())
92+
93+
if _polygon_available:
94+
providers.append(PolygonOHLCVDataProvider())
95+
96+
return providers
97+
4098

4199
__all__ = [
42100
'CSVOHLCVDataProvider',

poetry.lock

Lines changed: 16 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,18 @@ azure-mgmt-storage = "^21.2.1"
2929
azure-mgmt-web = "^7.3.1"
3030
azure-mgmt-resource = "^23.2.0"
3131
python-dotenv = "^1.0.1"
32-
yfinance = "^0.2.61"
33-
alpha_vantage = "^3.0.0"
34-
polygon-api-client = "^1.14.0"
32+
yfinance = {version = "^0.2.61", optional = true}
33+
alpha_vantage = {version = "^3.0.0", optional = true}
34+
polygon-api-client = {version = "^1.14.0", optional = true}
3535
plotly = "^6.1.2"
3636
boto3 = "^1.38.41"
3737

38+
[tool.poetry.extras]
39+
yahoo = ["yfinance"]
40+
alpha_vantage = ["alpha_vantage"]
41+
polygon = ["polygon-api-client"]
42+
all = ["yfinance", "alpha_vantage", "polygon-api-client"]
43+
3844
[tool.poetry.group.test.dependencies]
3945
coverage= "7.4.2"
4046
flake8 = "7.0.0"

0 commit comments

Comments
 (0)