StrategyServiceProxy

StrategyServiceProxy#

class sigtech.framework.services.strategy_service.proxy.StrategyServiceProxy

Baseclasses: StrategyServiceInterface

Proxy class to wrap StrategyService to provide lazy initialisation features as well as a NOOP strategy service when service is sets to inactive.

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 to None if not found, or UnknownSerialisedValue

get_strategy_by_name(strategy_names: Union[str, Sequence[str]]) 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.

Returns:

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

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

Return a list of all keys :param filter_by_environment: filter keys to those generated in the same environment :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]]) None

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

Parameters:

strategy_names – multiple or single Strategy names.

Returns:

None

start() None

Starts the service. It checks the is_available to ensure it is available before calling the factory method.

If not available, StrategyServiceNoop is setup instead.

stop() None

Stops the service. It replaces service with StrategyServiceNoop and clear data in any MemoryBackend.