mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-02 19:03:42 +08:00
added a decorator for applying an environment to a function context.
This commit is contained in:
@@ -356,3 +356,17 @@ class DailyReturn(object):
|
||||
|
||||
def __repr__(self):
|
||||
return str(self.date) + " - " + str(self.returns)
|
||||
|
||||
|
||||
class use_environment(object):
|
||||
"""A decorator to wrap a method in a particular
|
||||
trading environment."""
|
||||
|
||||
def __init__(self, environment):
|
||||
self.env = environment
|
||||
|
||||
def __call__(self, func):
|
||||
def wrapper(*args, **kwargs):
|
||||
with self.env:
|
||||
return func(*args, **kwargs)
|
||||
return wrapper
|
||||
|
||||
Reference in New Issue
Block a user