mirror of
https://github.com/wassname/catalyst.git
synced 2026-09-09 11:19:23 +08:00
ENH: An improved error message when calling zipline api functions
outside of a running simulation. Previously, an AttributeError was raised.
This commit is contained in:
@@ -48,7 +48,13 @@ def api_method(f):
|
|||||||
@wraps(f)
|
@wraps(f)
|
||||||
def wrapped(*args, **kwargs):
|
def wrapped(*args, **kwargs):
|
||||||
# Get the instance and call the method
|
# Get the instance and call the method
|
||||||
return getattr(get_algo_instance(), f.__name__)(*args, **kwargs)
|
algo_instance = get_algo_instance()
|
||||||
|
if algo_instance is None:
|
||||||
|
raise RuntimeError(
|
||||||
|
'zipline api method %s must be called during a simulation.'
|
||||||
|
% f.__name__
|
||||||
|
)
|
||||||
|
return getattr(algo_instance, f.__name__)(*args, **kwargs)
|
||||||
# Add functor to zipline.api
|
# Add functor to zipline.api
|
||||||
setattr(zipline.api, f.__name__, wrapped)
|
setattr(zipline.api, f.__name__, wrapped)
|
||||||
zipline.api.__all__.append(f.__name__)
|
zipline.api.__all__.append(f.__name__)
|
||||||
|
|||||||
Reference in New Issue
Block a user