2019-07-12 00:26:27 +00:00
|
|
|
import logging
|
|
|
|
from typing import Any, Dict, Optional
|
2019-07-17 18:53:29 +00:00
|
|
|
from pathlib import Path
|
2019-07-12 00:26:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
def create_datadir(config: Dict[str, Any], datadir: Optional[str] = None) -> str:
|
2019-07-17 18:53:29 +00:00
|
|
|
|
2019-07-21 12:32:29 +00:00
|
|
|
folder = Path(datadir) if datadir else Path(f"{config['user_data_dir']}/data")
|
2019-07-12 00:26:27 +00:00
|
|
|
if not datadir:
|
|
|
|
# set datadir
|
|
|
|
exchange_name = config.get('exchange', {}).get('name').lower()
|
2019-07-17 18:53:29 +00:00
|
|
|
folder = folder.joinpath(exchange_name)
|
2019-07-12 00:26:27 +00:00
|
|
|
|
2019-07-17 18:53:29 +00:00
|
|
|
if not folder.is_dir():
|
|
|
|
folder.mkdir(parents=True)
|
2019-07-12 00:26:27 +00:00
|
|
|
logger.info(f'Created data directory: {datadir}')
|
2019-07-17 18:53:29 +00:00
|
|
|
return str(folder)
|
2019-07-21 11:42:56 +00:00
|
|
|
|
|
|
|
|
2019-07-21 12:32:29 +00:00
|
|
|
def create_userdata_dir(directory: str) -> str:
|
2019-07-21 11:42:56 +00:00
|
|
|
sub_dirs = ["backtest_results", "data", "hyperopts", "plots", "strategies", ]
|
|
|
|
folder = Path(directory)
|
|
|
|
if not folder.is_dir():
|
|
|
|
folder.mkdir(parents=True)
|
|
|
|
logger.info(f'Created user-data directory: {folder}')
|
|
|
|
|
|
|
|
# Create required subdirectories
|
|
|
|
for f in sub_dirs:
|
|
|
|
subfolder = folder / f
|
|
|
|
if not subfolder.is_dir():
|
|
|
|
subfolder.mkdir(parents=False)
|
2019-07-21 12:32:29 +00:00
|
|
|
# TODO: convert this to return Path
|
|
|
|
return str(folder.resolve())
|