Data Feeds¶
PolarsDataFeed¶
PolarsDataFeed
¶
Bases: DataFeed
Data feed that loads market data from Polars dataframes.
Source code in alphaflow/data_feeds/polars_data_feed.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | |
__init__(df_or_file_path, *, col_timestamp='Date', col_symbol='Symbol', col_open='Open', col_high='High', col_low='Low', col_close='Close', col_volume='Volume')
¶
Initialize the Polars data feed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df_or_file_path
|
Path | str | DataFrame | LazyFrame
|
Polars dataframe or path to the Polars dataframe containing market data. |
required |
col_timestamp
|
str
|
Name of the timestamp column. |
'Date'
|
col_symbol
|
str
|
Name of the symbol column. |
'Symbol'
|
col_open
|
str
|
Name of the open price column. |
'Open'
|
col_high
|
str
|
Name of the high price column. |
'High'
|
col_low
|
str
|
Name of the low price column. |
'Low'
|
col_close
|
str
|
Name of the close price column. |
'Close'
|
col_volume
|
str
|
Name of the volume column. |
'Volume'
|
Source code in alphaflow/data_feeds/polars_data_feed.py
run(symbol, start_timestamp, end_timestamp)
¶
Load and yield market data events from the Polars dataframe.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
str
|
The ticker symbol to load data for. |
required |
start_timestamp
|
datetime | None
|
Optional start time for filtering data. |
required |
end_timestamp
|
datetime | None
|
Optional end time for filtering data. |
required |
Yields:
| Type | Description |
|---|---|
MarketDataEvent
|
MarketDataEvent objects containing OHLCV data. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If required columns are missing from the Polars dataframe. |
Source code in alphaflow/data_feeds/polars_data_feed.py
AlphaVantageFeed¶
AlphaVantageFeed
¶
Bases: DataFeed
Data feed that loads market data from Alpha Vantage API.
Source code in alphaflow/data_feeds/alpha_vantage_data_feed.py
__init__(use_cache=False, api_key=None, rate_limit_retries=3, rate_limit_backoff=60.0, rate_limit_backoff_multiplier=1.0)
¶
Initialize the Alpha Vantage data feed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
use_cache
|
bool
|
Whether to cache API responses (not yet implemented). |
False
|
api_key
|
str | None
|
Alpha Vantage API key. Falls back to ALPHA_VANTAGE_API_KEY env var. |
None
|
rate_limit_retries
|
int
|
Number of retry attempts for 429 rate limit errors (default: 3). |
3
|
rate_limit_backoff
|
float
|
Initial backoff delay in seconds for rate limit errors (default: 60). |
60.0
|
rate_limit_backoff_multiplier
|
float
|
Multiplier for exponential backoff (default: 1.0). |
1.0
|
Source code in alphaflow/data_feeds/alpha_vantage_data_feed.py
run(symbol, start_timestamp, end_timestamp)
¶
Load and yield market data events from Alpha Vantage API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
str
|
The ticker symbol to load data for. |
required |
start_timestamp
|
datetime | None
|
Optional start time for filtering data. |
required |
end_timestamp
|
datetime | None
|
Optional end time for filtering data. |
required |
Yields:
| Type | Description |
|---|---|
MarketDataEvent
|
MarketDataEvent objects containing OHLCV data. |
Source code in alphaflow/data_feeds/alpha_vantage_data_feed.py
FMPDataFeed¶
FMPDataFeed
¶
Bases: DataFeed
Data feed that loads market data from Financial Modeling Prep API.
Source code in alphaflow/data_feeds/fmp_data_feed.py
__init__(use_cache=False, api_key=None, rate_limit_retries=3, rate_limit_backoff=60.0, rate_limit_backoff_multiplier=1.0)
¶
Initialize the FMP data feed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
use_cache
|
bool
|
Whether to cache API responses (not yet implemented). |
False
|
api_key
|
str | None
|
FMP API key. Falls back to FMP_API_KEY env var. |
None
|
rate_limit_retries
|
int
|
Number of retry attempts for 429 rate limit errors (default: 3). |
3
|
rate_limit_backoff
|
float
|
Initial backoff delay in seconds for rate limit errors (default: 60). |
60.0
|
rate_limit_backoff_multiplier
|
float
|
Multiplier for exponential backoff (default: 1.0). |
1.0
|
Source code in alphaflow/data_feeds/fmp_data_feed.py
run(symbol, start_timestamp, end_timestamp)
¶
Load and yield market data events from FMP API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
str
|
The ticker symbol to load data for. |
required |
start_timestamp
|
datetime | None
|
Optional start time for filtering data. |
required |
end_timestamp
|
datetime | None
|
Optional end time for filtering data. |
required |
Yields:
| Type | Description |
|---|---|
MarketDataEvent
|
MarketDataEvent objects containing OHLCV data. |
Source code in alphaflow/data_feeds/fmp_data_feed.py
PolygonDataFeed¶
PolygonDataFeed
¶
Bases: DataFeed
Data feed that loads market data from Polygon.io API.
Supports daily and intraday OHLCV data. See https://polygon.io for API documentation and pricing.
Source code in alphaflow/data_feeds/polygon_data_feed.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | |
__init__(api_key=None, timeframe='day', multiplier=1, rate_limit_retries=3, rate_limit_backoff=60.0, rate_limit_backoff_multiplier=1.0)
¶
Initialize the Polygon.io data feed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
api_key
|
str | None
|
Polygon.io API key. Falls back to POLYGON_API_KEY env var. |
None
|
timeframe
|
str
|
Timeframe for bars ('minute', 'hour', 'day', 'week', 'month'). |
'day'
|
multiplier
|
int
|
Multiplier for the timeframe (e.g., 5 for 5-minute bars). |
1
|
rate_limit_retries
|
int
|
Number of retry attempts for 429 rate limit errors (default: 3). |
3
|
rate_limit_backoff
|
float
|
Initial backoff delay in seconds for rate limit errors (default: 60). |
60.0
|
rate_limit_backoff_multiplier
|
float
|
Multiplier for exponential backoff (default: 1.0). |
1.0
|
Source code in alphaflow/data_feeds/polygon_data_feed.py
run(symbol, start_timestamp, end_timestamp)
¶
Load and yield market data events from Polygon.io API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
str
|
The ticker symbol to load data for. |
required |
start_timestamp
|
datetime | None
|
Start time for data range (required). |
required |
end_timestamp
|
datetime | None
|
End time for data range (required). |
required |
Yields:
| Type | Description |
|---|---|
MarketDataEvent
|
MarketDataEvent objects containing OHLCV data and optionally bid/ask. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If start_timestamp or end_timestamp is None, or API request fails. |
Source code in alphaflow/data_feeds/polygon_data_feed.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | |