StrategyService#

class sigtech.framework.services.strategy_service.service.StrategyService

Strategy cache service to persist strategy in a multi-level cache for the purpose of sharing between users, as well as saving strategy into relatively durable storage.

Strategy objects are serialised as per backend’s configuration, most typically pickle. The strategy should be built using the framework building blocks, otherwise an exception would be raised during un-pickling for any unknown custom classes.

property is_active: bool

Returns True if strategy service is enabled, otherwise False :return: bool

cache_strategy(strategies: Union[sigtech.framework.strategies.strategy.Strategy, sigtech.framework.internal.strategies.base.StrategyInstrument, Sequence[Union[sigtech.framework.strategies.strategy.Strategy, sigtech.framework.internal.strategies.base.StrategyInstrument]]]) Union[str, None, Sequence[Optional[str]]]

Persist strategies into cache.

Parameters

strategies – single or a list of Strategy object(s) to be persisted.

Returns

single or a list of CacheKey generated and used for caching.

get_strategy_by_key(keys: Union[str, Sequence[str]]) Union[sigtech.framework.strategies.strategy.Strategy, sigtech.framework.internal.strategies.base.StrategyInstrument, sigtech.framework.internal.infra.cache.api.UnknownSerialisedValue, None, Sequence[Optional[Union[sigtech.framework.strategies.strategy.Strategy, sigtech.framework.internal.strategies.base.StrategyInstrument, sigtech.framework.internal.infra.cache.api.UnknownSerialisedValue]]]]

Returns a single cached object or list of objects of the given key(s)

Some lite validation is performed, to compare the current environment dates and the environment dates stored in the metadata. Warnings are logged to stdout.

Parameters

keys – Key(s) to retrieve.

Returns

Strategy object(s) (value or a list), object is set to None if not found, or UnknownSerialisedValue

remove_strategy_by_key(keys: Union[str, Sequence[str]]) Union[sigtech.framework.strategies.strategy.Strategy, sigtech.framework.internal.strategies.base.StrategyInstrument, sigtech.framework.internal.infra.cache.api.UnknownSerialisedValue, None, Sequence[Optional[Union[sigtech.framework.strategies.strategy.Strategy, sigtech.framework.internal.strategies.base.StrategyInstrument, sigtech.framework.internal.infra.cache.api.UnknownSerialisedValue]]]]

Removes strategy from the persistence of the given key(s)

Parameters

keys – Key(s) to remove.

Returns

None

get_strategy_by_name(strategy_names: Union[str, Sequence[str]], env_date_override: Optional[datetime.datetime] = None) Union[sigtech.framework.strategies.strategy.Strategy, sigtech.framework.internal.strategies.base.StrategyInstrument, sigtech.framework.internal.infra.cache.api.UnknownSerialisedValue, None, Sequence[Optional[Union[sigtech.framework.strategies.strategy.Strategy, sigtech.framework.internal.strategies.base.StrategyInstrument, sigtech.framework.internal.infra.cache.api.UnknownSerialisedValue]]]]

Return cached strategy(ies), given strategy name(s). Keys are first constructed from the name, together with the current environment, the cache is then queried for the cached object(s)

Parameters
  • strategy_names – multiple or single Strategy names.

  • env_date_override – Optional. Set this to get a strategy from a previous day. Strategy will be brought up to date automatically when built.

Returns

(single or a list of) cached Strategy object; object is None if not found, or UnknownSerialisedValue

remove_strategy_by_name(strategy_names: Union[str, Sequence[str]], env_date_override: Optional[datetime.datetime] = None) None

Removes strategy from the persistence of the given names(s)

Parameters
  • strategy_names – multiple or single Strategy names.

  • env_date_override – Optional. Set this to remove a strategy from a previous day.

Returns

None

get_keys_by_prefix(prefix: str) Sequence[str]

Return a list of keys which starts with the provided prefix :param prefix: prefix to search for :return: list of keys

list_keys(filter_by_environment: bool = True, env_date_override: Optional[datetime.datetime] = None) Sequence[str]

Return a list of all keys :param filter_by_environment: filter keys to those generated in the same environment :param env_date_override: Optional. Set this to list strategies from a previous day. Strategies from previous days will be brought up to date automatically when retrieved and built. :return: list of keys

list_strategies(filter_by_environment: bool = True) Sequence[str]

Return a list of all strategy names :param filter_by_environment: filter keys to those generated in the same environment :return: list of strategy names