Open tibkiss opened 6 years ago
so how can you know whether the ib_broker file is not there or the dependencies are not there? you want to execute a file exist check, read all imports in the beginning if the file is there and try to import the dependencies in the broker file?
Or maybe make people install snakefood?
pip install snakefood
sfood-imports ib_broker.py
generates:
/usr/local/lib/python2.7/dist-packages/zipline/gens/brokers/ib_broker.py:14: sys /usr/local/lib/python2.7/dist-packages/zipline/gens/brokers/ib_broker.py:15: collections.namedtuple /usr/local/lib/python2.7/dist-packages/zipline/gens/brokers/ib_broker.py:15: collections.defaultdict /usr/local/lib/python2.7/dist-packages/zipline/gens/brokers/ib_broker.py:16: time.sleep /usr/local/lib/python2.7/dist-packages/zipline/gens/brokers/ib_broker.py:17: math.fabs /usr/local/lib/python2.7/dist-packages/zipline/gens/brokers/ib_broker.py:19: six.itervalues /usr/local/lib/python2.7/dist-packages/zipline/gens/brokers/ib_broker.py:20: pandas /usr/local/lib/python2.7/dist-packages/zipline/gens/brokers/ib_broker.py:21: numpy /usr/local/lib/python2.7/dist-packages/zipline/gens/brokers/ib_broker.py:23: zipline.gens.brokers.broker.Broker /usr/local/lib/python2.7/dist-packages/zipline/gens/brokers/ib_broker.py:24: zipline.finance.order.Order /usr/local/lib/python2.7/dist-packages/zipline/gens/brokers/ib_broker.py:24: zipline.finance.order.ORDER_STATUS /usr/local/lib/python2.7/dist-packages/zipline/gens/brokers/ib_broker.py:26: zipline.finance.execution.MarketOrder /usr/local/lib/python2.7/dist-packages/zipline/gens/brokers/ib_broker.py:26: zipline.finance.execution.LimitOrder /usr/local/lib/python2.7/dist-packages/zipline/gens/brokers/ib_broker.py:26: zipline.finance.execution.StopOrder /usr/local/lib/python2.7/dist-packages/zipline/gens/brokers/ib_broker.py:26: zipline.finance.execution.StopLimitOrder /usr/local/lib/python2.7/dist-packages/zipline/gens/brokers/ib_broker.py:30: zipline.protocol /usr/local/lib/python2.7/dist-packages/zipline/gens/brokers/ib_broker.py:31: zipline.api.symbol /usr/local/lib/python2.7/dist-packages/zipline/gens/brokers/ib_broker.py:32: zipline.errors.SymbolNotFound /usr/local/lib/python2.7/dist-packages/zipline/gens/brokers/ib_broker.py:34: ib.ext.EClientSocket.EClientSocket /usr/local/lib/python2.7/dist-packages/zipline/gens/brokers/ib_broker.py:35: ib.ext.EWrapper.EWrapper /usr/local/lib/python2.7/dist-packages/zipline/gens/brokers/ib_broker.py:36: ib.ext.Contract.Contract /usr/local/lib/python2.7/dist-packages/zipline/gens/brokers/ib_broker.py:37: ib.ext.Order.Order /usr/local/lib/python2.7/dist-packages/zipline/gens/brokers/ib_broker.py:38: ib.ext.EClientErrors.EClientErrors /usr/local/lib/python2.7/dist-packages/zipline/gens/brokers/ib_broker.py:40: logbook.Logger
I think we can simply catch ImportError, and then check if the module exists (via pkgutil, to avoid external dependencies) we can print an error about missing dependencies.
you can find usage of pkgutil in here: https://github.com/zipline-live/zipline/pull/63/files
The brokers are dynamically imported in zipline-live based on the value of --broker command line parameter. If a nonexistent broker is specified an error is presented to the user: https://github.com/zipline-live/zipline/blob/0da196947e0271b2f46138e0f5efa44078726c9e/zipline/__main__.py#L240-L245
The following error is also presented if the broker is supported, but its dependencies are not present. We should improve the error message in that case and notify the user about the dependency problem.
Steps to reproduce: