stable/freqtrade/configuration/load_config.py

34 lines
902 B
Python
Raw Normal View History

2019-08-10 12:15:09 +00:00
"""
This module contain functions to load the configuration file
"""
import rapidjson
2019-08-10 12:15:09 +00:00
import logging
import sys
from typing import Any, Dict
from freqtrade.exceptions import OperationalException
2019-08-10 12:15:09 +00:00
logger = logging.getLogger(__name__)
CONFIG_PARSE_MODE = rapidjson.PM_COMMENTS | rapidjson.PM_TRAILING_COMMAS
2019-08-10 12:15:09 +00:00
def load_config_file(path: str) -> Dict[str, Any]:
"""
Loads a config file from the given path
:param path: path as str
:return: configuration as dictionary
"""
try:
# Read config from stdin if requested in the options
with open(path) if path != '-' else sys.stdin as file:
config = rapidjson.load(file, parse_mode=CONFIG_PARSE_MODE)
2019-08-10 12:15:09 +00:00
except FileNotFoundError:
raise OperationalException(
f'Config file "{path}" not found!'
' Please create a config file or check whether it exists.')
return config