From b6d8c300d412a4d39fef989bfa9fbc8d7672faa7 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Sat, 22 May 2021 15:11:23 -0400 Subject: [PATCH] Slap in brokers.toml template if none exists --- MANIFEST.in | 1 + data/brokers.toml | 9 +++++++++ piker/brokers/config.py | 21 ++++++++++++++++++++- 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 data/brokers.toml diff --git a/MANIFEST.in b/MANIFEST.in index 9561fb10..7f3499c6 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1 +1,2 @@ include README.rst +include data/brokers.toml diff --git a/data/brokers.toml b/data/brokers.toml new file mode 100644 index 00000000..54b3df16 --- /dev/null +++ b/data/brokers.toml @@ -0,0 +1,9 @@ +[binance] + +[kraken] + + +# [ib] + + +# [questrade] diff --git a/piker/brokers/config.py b/piker/brokers/config.py index 6718e794..a8ba7ff2 100644 --- a/piker/brokers/config.py +++ b/piker/brokers/config.py @@ -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