This repository contains scripts and notebooks for handling external data feeds for the LEAN algorithmic trading engine.
This Jupyter notebook is designed to test and demonstrate the functionality of the Databento API. It includes examples of how to fetch and process data using the API.
This Jupyter notebook is designed to convert data fetched from the Databento API into a format that is compatible with LEAN. It includes examples of how to clean and format the data for use in the algorithmic trading engine for local backtesting.
This script is designed to download stock data from the Data Bento API, convert it to a format compatible with the LEAN Local CLI Framework, and save it in the appropriate directory. The script includes functions to:
- Fetch OHLCV data for a given ticker and date range from Data Bento.
- Convert datetime columns from UTC to New York time.
- Convert the downloaded data into a format compatible with LEAN.
- Download and append stock data if necessary, then convert the data to QuantConnect format.
Functions:
- get_data_from_databento(ticker, start_date, end_date): Fetches OHLCV data for a given ticker from Data Bento for the specified date range.
- convert_utc_to_ny(df, datetime_column='ts_event'): Converts a datetime column from UTC to New York time (Eastern Time).
- convert_to_lean_format(csv_file, ticker, frequency='daily'): Converts a CSV file containing stock data into a format compatible with LEAN Local CLI Framework.
- download_and_append_data(ticker, start_date, end_date, folder='databento/downloads', frequency='daily'): Downloads and appends stock data from Data Bento API if necessary, then converts the data to QuantConnect format. Example usage:
- The script can be run directly to download and process data for a list of tickers within a specified date range.
For an explanation of the script, please refer to the databento_sql_ReadMe file
The data fetched by databento_test.ipynb is saved in the following directories:
/databento/downloads/{ticker}.csv: Contains raw data files fetched directly from the Databento API./data/equity/usa/daily/{ticker}.csv: Contains processed data files that have been cleaned and formatted for use in LEAN.
The .env file should contain the following variable:
databento_api_key: Your Databento API key for accessing the data.
Ensure that this file is properly configured before running the notebook to avoid authentication issues.
- Clone the repository.
- Install the required dependencies.
- Set up the
.envfile with your Databento API key. - Run
databento_test.ipynbto fetch and process data.
For more detailed instructions, refer to the comments within the notebook.
- [In Progress] WRDS API Support - Pending new WRDS SQL Query
- Add support for equity options, fx and futures data.
- Add support for different types of equity data (e.g. higher resolution, fundamental data, etc.)
- Add support for further databento formats
Last update: 26SEP24 Daily data is working using databento_test.ipynb To do next is to convert to a .py file, add the questdb integration and test it Finally dagsterize this pipeline
After running databento_test on your desired ticker
Drop the ticker.zip into /data/equity/usa/daily/
Run the following command in the terminal
lean backtest "localdatatest_spy" --data-provider-historical Local