Slap in brokers.toml template if none exists

py3.9
Tyler Goodlet 2021-05-22 15:11:23 -04:00
parent 2ef5a52521
commit b6d8c300d4
3 changed files with 30 additions and 1 deletions

View File

@ -1 +1,2 @@
include README.rst
include data/brokers.toml

View File

@ -0,0 +1,9 @@
[binance]
[kraken]
# [ib]
# [questrade]

View File

@ -18,9 +18,12 @@
Broker configuration mgmt.
"""
import os
import configparser
from os.path import dirname
import shutil
import toml
import click
from ..log import get_logger
log = get_logger('broker-config')
@ -40,12 +43,28 @@ def get_broker_conf_path():
return os.path.join(_config_dir, _file_name)
def repodir():
"""Return the abspath to the repo directory.
"""
dirpath = os.path.abspath(
# we're 3 levels down in **this** module file
dirname(dirname(dirname(os.path.realpath(__file__))))
)
return dirpath
def load(
path: str = None
) -> (dict, str):
"""Load broker config.
"""
path = path or get_broker_conf_path()
if not os.path.isfile(path):
shutil.copyfile(
os.path.join(repodir(), 'data/brokers.toml'),
path,
)
config = toml.load(path)
log.debug(f"Read config file {path}")
return config, path