From 49d290d036d713b19d3190fbfd173f6ad485fe97 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Tue, 27 Mar 2018 16:03:01 -0400 Subject: [PATCH] Add brokermod loader utils --- piker/brokers/__init__.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/piker/brokers/__init__.py b/piker/brokers/__init__.py index 54afc783..8ae3f1dc 100644 --- a/piker/brokers/__init__.py +++ b/piker/brokers/__init__.py @@ -1,3 +1,23 @@ """ Broker clients, daemons and general back end machinery. """ +from importlib import import_module +from types import ModuleType + +__brokers__ = [ + 'questrade', + 'robinhood', +] + + +def get_brokermod(brokername: str) -> ModuleType: + """Return the imported broker module by name. + """ + return import_module('.' + brokername, 'piker.brokers') + + +def iter_brokermods(): + """Iterate all built-in broker modules. + """ + for name in __brokers__: + yield get_brokermod(name)