-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor - code changes with best practices, add docstrings and impro…
…ved error handling
- Loading branch information
Showing
13 changed files
with
467 additions
and
213 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,39 @@ | ||
import yaml | ||
|
||
from typing import List, Dict, Any | ||
from loguru import logger | ||
from config.settings import Config | ||
from src.env_loader import load_api_keys | ||
|
||
# Load API keys from environment | ||
load_api_keys() | ||
|
||
|
||
def load_config(strategy_name: str) -> Config: | ||
""" | ||
Load configuration for a given strategy from a YAML file. | ||
Args: | ||
strategy_name (str): The name of the strategy to load the configuration for. | ||
Returns: | ||
Config: The configuration object. | ||
Raises: | ||
FileNotFoundError: If the configuration file does not exist. | ||
yaml.YAMLError: If there is an error parsing the YAML file. | ||
TypeError: If the configuration data cannot be converted to a Config object. | ||
""" | ||
config_file = f"config/config_{strategy_name}.yaml" | ||
with open(config_file, "r") as file: | ||
config_data = yaml.safe_load(file) | ||
return Config(**config_data) | ||
try: | ||
with open(config_file, "r") as file: | ||
config_data = yaml.safe_load(file) | ||
return Config(**config_data) | ||
except FileNotFoundError as e: | ||
logger.error(f"Configuration file not found: {config_file}") | ||
raise | ||
except yaml.YAMLError as e: | ||
logger.error(f"Error parsing YAML file: {config_file}") | ||
raise | ||
except TypeError as e: | ||
logger.error(f"Error converting configuration data to Config object: {e}") | ||
raise |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.