Skip to content

BaseFlumine.add_xxx() methods should check for duplicates #759

@mzaja

Description

@mzaja

As of #685 getting merged, BaseStrategy.add() method receives flumine as an argument. This makes it elegant to add e.g. strategy-specific middleware or workers inside the strategy itself. The problem arises when multiple strategies require the same resource and add it multiple times.

As with streams, all the methods outlined below should check whether a resource has already been added and reject duplicates. The test should be if resource not in [resource_1, resource_2, ...] then add_resource(). It would then be expected of the end user to override __eq__() method of each custom resource to determine what constitutes a duplicate.

def add_worker(self, worker: BackgroundWorker) -> None:
logger.info("Adding worker %s", worker.name)
self._workers.append(worker)
def add_client_control(
self, client: BaseClient, client_control: Type[BaseControl], **kwargs
) -> None:
logger.info("Adding client control %s", client_control.NAME)
client.trading_controls.append(client_control(self, client, **kwargs))
def add_trading_control(self, trading_control: Type[BaseControl], **kwargs) -> None:
logger.info("Adding trading control %s", trading_control.NAME)
self.trading_controls.append(trading_control(self, **kwargs))
def add_market_middleware(self, middleware: Middleware) -> None:
logger.info("Adding market middleware %s", middleware)
self._market_middleware.append(middleware)
def add_logging_control(self, logging_control: LoggingControl) -> None:
logger.info("Adding logging control %s", logging_control.NAME)
self._logging_controls.append(logging_control)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions