Slap in brokers.toml template if none exists
parent
2ef5a52521
commit
b6d8c300d4
|
@ -1 +1,2 @@
|
||||||
include README.rst
|
include README.rst
|
||||||
|
include data/brokers.toml
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
[binance]
|
||||||
|
|
||||||
|
[kraken]
|
||||||
|
|
||||||
|
|
||||||
|
# [ib]
|
||||||
|
|
||||||
|
|
||||||
|
# [questrade]
|
|
@ -18,9 +18,12 @@
|
||||||
Broker configuration mgmt.
|
Broker configuration mgmt.
|
||||||
"""
|
"""
|
||||||
import os
|
import os
|
||||||
import configparser
|
from os.path import dirname
|
||||||
|
import shutil
|
||||||
|
|
||||||
import toml
|
import toml
|
||||||
import click
|
import click
|
||||||
|
|
||||||
from ..log import get_logger
|
from ..log import get_logger
|
||||||
|
|
||||||
log = get_logger('broker-config')
|
log = get_logger('broker-config')
|
||||||
|
@ -40,12 +43,28 @@ def get_broker_conf_path():
|
||||||
return os.path.join(_config_dir, _file_name)
|
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(
|
def load(
|
||||||
path: str = None
|
path: str = None
|
||||||
) -> (dict, str):
|
) -> (dict, str):
|
||||||
"""Load broker config.
|
"""Load broker config.
|
||||||
"""
|
"""
|
||||||
path = path or get_broker_conf_path()
|
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)
|
config = toml.load(path)
|
||||||
log.debug(f"Read config file {path}")
|
log.debug(f"Read config file {path}")
|
||||||
return config, path
|
return config, path
|
||||||
|
|
Loading…
Reference in New Issue