1- import os
21import asyncio
32from dataclasses import dataclass , field
43from typing import Any
5- import httpx
6- import stock_valuation_app .utils as utils
7- from stock_valuation_app .models .stock_models import CombinedModel
8-
9-
10- def get_endpoint (url : str ) -> str :
11- """Get endpoints from the configuration."""
12- api_config = utils .get_section_config ("api" )
13- return api_config .get (f"{ url } " )
14-
15-
16- def get_base_url () -> str :
17- """Get the base URL from the configuration."""
18- return get_endpoint ("base_url" )
194
5+ import httpx
206
21- def get_api_key () -> str :
22- """Get the API key from the .env file."""
23- return os . getenv ( "FMP_API_KEY" , "" )
7+ import utils as utils
8+ from config import settings
9+ from models . stock_models import CombinedModel
2410
2511
2612@dataclass
2713class FMPClient :
2814 """A client for interacting with the Financial Modeling Prep API."""
29- base_url : str = field (default_factory = get_base_url )
30- api_key : str = field (default_factory = get_api_key )
15+
16+ base_url : str = field (default_factory = settings .base_url )
17+ api_key : str = field (default_factory = settings .fmp_api_key )
3118 metric_types : list [str ] = field (
3219 default_factory = lambda : [
3320 "profile" ,
@@ -67,11 +54,14 @@ async def fetch_data(self, ticker: str) -> dict[str, list[dict[str, Any]]]:
6754 "rating" : "ratings" ,
6855 "key-metrics" : "key_metrics" ,
6956 "key-metrics-ttm" : "key_metrics_ttm" ,
70- "financial-growth" : "growth" ,} #
71- new_metric_types = [replace_metric_types .get (item , item ) for item in self .metric_types ]
57+ "financial-growth" : "growth" ,
58+ } #
59+ new_metric_types = [
60+ replace_metric_types .get (item , item ) for item in self .metric_types
61+ ]
7262
7363 # Create combined records dict for validation
7464 records = dict (zip (new_metric_types , results ))
7565
7666 # Validate the combined records
77- return CombinedModel (** records ).model_dump ()
67+ return CombinedModel (** records ).model_dump ()
0 commit comments