piker/piker/brokers/__init__.py

49 lines
1.5 KiB
Python
Raw Normal View History

2020-11-06 17:23:14 +00:00
# piker: trading gear for hackers
# Copyright (C) 2018-present Tyler Goodlet (in stewardship of piker0)
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
2018-01-23 06:03:51 +00:00
Broker clients, daemons and general back end machinery.
"""
2018-03-27 20:03:01 +00:00
from importlib import import_module
from types import ModuleType
# TODO: move to urllib3/requests once supported
import asks
asks.init('trio')
2018-03-27 20:03:01 +00:00
__brokers__ = [
'questrade',
'robinhood',
2020-07-03 23:09:57 +00:00
'ib',
2020-07-15 12:20:29 +00:00
'kraken',
2018-03-27 20:03:01 +00:00
]
def get_brokermod(brokername: str) -> ModuleType:
"""Return the imported broker module by name.
"""
module = import_module('.' + brokername, 'piker.brokers')
# we only allow monkeying because it's for internal keying
module.name = module.__name__.split('.')[-1]
return module
2018-03-27 20:03:01 +00:00
def iter_brokermods():
"""Iterate all built-in broker modules.
"""
for name in __brokers__:
yield get_brokermod(name)