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 02:50:26 +00:00
|
|
|
"""
|
2018-01-23 06:03:51 +00:00
|
|
|
Broker clients, daemons and general back end machinery.
|
2018-01-23 02:50:26 +00:00
|
|
|
"""
|
2018-03-27 20:03:01 +00:00
|
|
|
from importlib import import_module
|
|
|
|
from types import ModuleType
|
|
|
|
|
2019-02-26 01:11:45 +00:00
|
|
|
# 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.
|
|
|
|
"""
|
2018-04-17 21:17:08 +00:00
|
|
|
module = import_module('.' + brokername, 'piker.brokers')
|
2019-03-22 02:01:50 +00:00
|
|
|
# we only allow monkeying because it's for internal keying
|
2018-04-17 21:17:08 +00:00
|
|
|
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)
|