def test_context_persistence_exclude_list(self, tmpdir): class Context(object): def __init__(self, rsi=None, sma=None, trading_client=None, event_manager=None): self.rsi = rsi self.sma = sma self.trading_client = trading_client self.event_manager = event_manager context = Context(rsi=17.2, sma=40.4, trading_client=lambda x: x+3, event_manager=[None, False]) exclude_list = ['trading_client', 'event_manager'] checksum = 'robocop' state_file_path = os.path.join(tmpdir.path, "state_file") store_context(state_file_path, context, checksum, exclude_list) restored_context = Context() load_context(state_file_path, restored_context, checksum) assert restored_context.__dict__.keys() == context.__dict__.keys() assert restored_context.rsi == context.rsi assert restored_context.sma == context.sma assert restored_context.trading_client is None assert restored_context.event_manager is None
def test_context_persistence_exclude_list(self, tmpdir): class Context(object): def __init__(self, rsi=None, sma=None, trading_client=None, event_manager=None): self.rsi = rsi self.sma = sma self.trading_client = trading_client self.event_manager = event_manager context = Context(rsi=17.2, sma=40.4, trading_client=lambda x: x + 3, event_manager=[None, False]) exclude_list = ['trading_client', 'event_manager'] checksum = 'robocop' state_file_path = os.path.join(tmpdir.path, "state_file") store_context(state_file_path, context, checksum, exclude_list) restored_context = Context() load_context(state_file_path, restored_context, checksum) assert restored_context.__dict__.keys() == context.__dict__.keys() assert restored_context.rsi == context.rsi assert restored_context.sma == context.sma assert restored_context.trading_client is None assert restored_context.event_manager is None
def initialize(self, *args, **kwargs): self._context_persistence_excludes = (list(self.__dict__.keys()) + ['trading_client']) if os.path.isfile(self.state_filename): log.info("Loading state from {}".format(self.state_filename)) load_context(self.state_filename, context=self, checksum=self.algo_filename) return with ZiplineAPI(self): super(self.__class__, self).initialize(*args, **kwargs) store_context(self.state_filename, context=self, checksum=self.algo_filename, exclude_list=self._context_persistence_excludes)
def initialize(self, *args, **kwargs): self._context_persistence_excludes = (list(self.__dict__.keys()) + ['trading_client']) if os.path.isfile(self.state_filename): log.info("Loading state from {}".format(self.state_filename)) load_context(self.state_filename, context=self, checksum=self.algo_filename) return with ZiplineAPI(self): super(self.__class__, self).initialize(*args, **kwargs) store_context(self.state_filename, context=self, checksum=self.algo_filename, exclude_list=self._context_persistence_excludes)
def initialize(self, *args, **kwargs): self._context_persistence_excludes = \ self._context_persistence_blacklist + \ [e for e in self.__dict__.keys() if e not in self._context_persistence_whitelist] if os.path.isfile(self.state_filename): log.info("Loading state from {}".format(self.state_filename)) load_context(self.state_filename, context=self, checksum=self.algo_filename) return with ZiplineAPI(self): super(self.__class__, self).initialize(*args, **kwargs) store_context(self.state_filename, context=self, checksum=self.algo_filename, exclude_list=self._context_persistence_excludes)