Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mzaja opened this issue May 22, 2024 · 0 comments
Open

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

mzaja opened this issue May 22, 2024 · 0 comments

Comments

@mzaja
Copy link
Contributor

mzaja commented May 22, 2024

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant