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[Strategy, StrategyInstrument, Sequence[Union[Strategy, 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_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
-
get_strategy_by_key(keys: Union[str, Sequence[str]]) Union[Strategy, StrategyInstrument, UnknownSerialisedValue, None, Sequence[Optional[Union[Strategy, StrategyInstrument, 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 toNone
if not found, or UnknownSerialisedValue
-
get_strategy_by_name(strategy_names: Union[str, Sequence[str]], env_date_override: Optional[datetime] = None) Union[Strategy, StrategyInstrument, UnknownSerialisedValue, None, Sequence[Optional[Union[Strategy, StrategyInstrument, 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 isNone
if not found, or UnknownSerialisedValue
-
list_keys(filter_by_environment: bool = True, env_date_override: Optional[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
-
remove_strategy_by_key(keys: Union[str, Sequence[str]]) Union[Strategy, StrategyInstrument, UnknownSerialisedValue, None, Sequence[Optional[Union[Strategy, StrategyInstrument, UnknownSerialisedValue]]]]
Removes strategy from the persistence of the given key(s)
- Parameters:
keys – Key(s) to remove.
- Returns:
None
-
remove_strategy_by_name(strategy_names: Union[str, Sequence[str]], env_date_override: Optional[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