@@ -41,7 +41,7 @@ def __init__(self, config_file: str | Path | None = None):
4141 Args:
4242 config_file: Optional path to configuration file
4343 """
44- self .config_file = Path (config_file ) if config_file else None
44+ self .config_file : Path | None = Path (config_file ) if config_file else None
4545 self ._config : ProjectXConfig | None = None
4646
4747 def load_config (self ) -> ProjectXConfig :
@@ -79,8 +79,9 @@ def _load_config_file(self) -> dict[str, Any]:
7979 return {}
8080
8181 try :
82- with open (self .config_file ) as f :
83- return json .load (f )
82+ with open (self .config_file , encoding = "utf-8" ) as f :
83+ data = json .load (f )
84+ return dict (data ) if isinstance (data , dict ) else {}
8485 except (json .JSONDecodeError , OSError ) as e :
8586 logger .error (f"Error loading config file: { e } " )
8687 return {}
@@ -117,7 +118,11 @@ def _load_env_config(self) -> dict[str, Any]:
117118
118119 return env_config
119120
120- def save_config (self , config : ProjectXConfig , file_path : str | Path | None = None ):
121+ def save_config (
122+ self ,
123+ config : ProjectXConfig ,
124+ file_path : str | Path | None = None ,
125+ ) -> None :
121126 """
122127 Save configuration to file.
123128
@@ -136,7 +141,7 @@ def save_config(self, config: ProjectXConfig, file_path: str | Path | None = Non
136141
137142 # Convert config to dict and save as JSON
138143 config_dict = asdict (config )
139- with open (target_file , "w" ) as f :
144+ with open (target_file , "w" , encoding = "utf-8" ) as f :
140145 json .dump (config_dict , f , indent = 2 )
141146
142147 logger .info (f"Configuration saved to { target_file } " )
@@ -183,10 +188,15 @@ def validate_config(self, config: ProjectXConfig) -> bool:
183188 Raises:
184189 ValueError: If configuration is invalid
185190 """
186- errors = []
191+ errors : list [ str ] = []
187192
188193 # Validate URLs
189- required_urls = ["api_url" , "realtime_url" , "user_hub_url" , "market_hub_url" ]
194+ required_urls : list [str ] = [
195+ "api_url" ,
196+ "realtime_url" ,
197+ "user_hub_url" ,
198+ "market_hub_url" ,
199+ ]
190200 for url_field in required_urls :
191201 url = getattr (config , url_field )
192202 if not url or not isinstance (url , str ):
@@ -242,7 +252,7 @@ def load_topstepx_config() -> ProjectXConfig:
242252
243253
244254def create_custom_config (
245- user_hub_url : str , market_hub_url : str , ** kwargs
255+ user_hub_url : str , market_hub_url : str , ** kwargs : Any
246256) -> ProjectXConfig :
247257 """
248258 Create custom configuration with specified URLs.
@@ -275,7 +285,7 @@ def create_config_template(file_path: str | Path) -> None:
275285 file_path: Path where to create the template
276286 """
277287 template_config = ProjectXConfig ()
278- config_dict = asdict (template_config )
288+ config_dict : dict [ str , Any ] = asdict (template_config )
279289
280290 # Add comments to the template
281291 template = {
@@ -298,7 +308,7 @@ def create_config_template(file_path: str | Path) -> None:
298308 file_path = Path (file_path )
299309 file_path .parent .mkdir (parents = True , exist_ok = True )
300310
301- with open (file_path , "w" ) as f :
311+ with open (file_path , "w" , encoding = "utf-8" ) as f :
302312 json .dump (template , f , indent = 2 )
303313
304314 logger .info (f"Configuration template created at { file_path } " )
@@ -334,7 +344,7 @@ def check_environment() -> dict[str, Any]:
334344 Returns:
335345 Dictionary with environment status
336346 """
337- status = {
347+ status : dict [ str , Any ] = {
338348 "auth_configured" : False ,
339349 "config_file_exists" : False ,
340350 "environment_overrides" : [],
@@ -357,13 +367,13 @@ def check_environment() -> dict[str, Any]:
357367 status ["missing_required" ].extend (["PROJECT_X_API_KEY" , "PROJECT_X_USERNAME" ])
358368
359369 # Check for config file
360- default_path = get_default_config_path ()
370+ default_path : Path = get_default_config_path ()
361371 if default_path .exists ():
362372 status ["config_file_exists" ] = True
363373 status ["config_file_path" ] = str (default_path )
364374
365375 # Check for environment overrides
366- env_vars = [
376+ env_vars : list [ str ] = [
367377 "PROJECTX_API_URL" ,
368378 "PROJECTX_REALTIME_URL" ,
369379 "PROJECTX_USER_HUB_URL" ,
0 commit comments