ApiDataProvider
QuantConnect.Lean.Engine.DataFeeds.ApiDataProvider
ApiDataProvider()
Bases: BaseDownloaderDataProvider
An instance of the IDataProvider that will download and update data files as needed via QC's Api.
Initialize a new instance of the ApiDataProvider
new_data_request
new_data_request: _EventContainer[
Callable[
[Object, DataProviderNewDataRequestEventArgs], Any
],
Any,
]
Event raised each time data fetch is finished (successfully or not)
download_data
download_data(file_path: str) -> bool
Attempt to download data using the Api for and return a FileStream of that data.
This codeEntityType is protected.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
str
|
The path to store the file |
required |
Returns:
| Type | Description |
|---|---|
bool
|
A FileStream of the data. |
fetch
fetch(key: str) -> Stream
Retrieves data to be used in an algorithm. If file does not exist, an attempt is made to download them from the api
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
File path representing where the data requested |
required |
Returns:
| Type | Description |
|---|---|
Stream
|
A Stream of the data requested. |
need_to_download
need_to_download(file_path: str) -> bool
Main filter to determine if this file needs to be downloaded
This codeEntityType is protected.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
str
|
File we are looking at |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if should download. |
dispose
dispose() -> None
The stream created by this type is passed up the stack to the IStreamReader The stream is closed when the StreamReader that wraps this stream is disposed
on_new_data_request
on_new_data_request(
e: DataProviderNewDataRequestEventArgs,
) -> None
Event invocator for the new_data_request event
This codeEntityType is protected.
download_once
download_once(
key: str, download: Callable[[str], Any]
) -> Stream
Helper method which guarantees each requested key is downloaded only once concurrently if required based on need_to_download
This codeEntityType is protected.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
A string representing where the data is stored |
required |
download
|
Callable[[str], Any]
|
The download operation we want to perform once concurrently per key |
required |
Returns:
| Type | Description |
|---|---|
Stream
|
A Stream of the data requested. |
get_stream
get_stream(key: str) -> Stream
Get's the stream for a given file path
This codeEntityType is protected.