Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error message at broker import #47

Open
tibkiss opened this issue Aug 24, 2017 · 2 comments
Open

Improve error message at broker import #47

tibkiss opened this issue Aug 24, 2017 · 2 comments

Comments

@tibkiss
Copy link

tibkiss commented Aug 24, 2017

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:

zipline/zipline/__main__.py

Lines 240 to 245 in 0da1969

if broker:
mod_name = 'zipline.gens.brokers.%s_broker' % broker.lower()
try:
bmod = import_module(mod_name)
except ImportError:
ctx.fail("unsupported broker: can't import module %s" % mod_name)

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:

  • Install based on the tutorial
  • Uninstall IbPy2 from virtualenv
  • Start zipline-live with ib broker
  • Observe the error
@peterfabakker
Copy link

peterfabakker commented Nov 9, 2017

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

@tibkiss
Copy link
Author

tibkiss commented Nov 11, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants