Call add() and start() methods of BaseStrategy with flumine as an argument
mzaja opened this issue · 2 comments
Proposal
The proposal is to change the call signature of BaseStrategy.add
and BaseStrategy.start
methods from (self)
to (self, flumine)
. I am aware this would be a breaking change.
Rationale for making the change
- It makes the call consistent with
finish(self, flumine)
. - It raises
add
andstart
methods the same level of utiliy asfinish
method by giving them access to the whole framework.
Practical use case
I have a strategy which I want to test against historical data, then deploy on live markets. These environments are very different as live starategy runs indefinitely on a single core while simulated strategy runs in a subprocess, not to mention that framework types are different.
Currently there is no elegant way to have simulation-only initialisation in add
and start
methods because they are not aware of the framework in which they are executed. There is an option to call self.clients.simulated
from the strategy, but this is not the same as testing flumine.SIMULATED
attribute because the former also returns True
if paper trading on a live market.
Of course, this is a simple example that merely scratches the surface. There may be numerous desirable interactions with the framework to be performed in the add
and start
steps of each strategy, which are currently not feasible because the strategy lacks a reference to the framework in those methods.
Notes
The lack of framework reference is not a limitation for other methods (except process_raw_data
) since a reference is obtainable through the Market
object.
Happy for you to come up with a PR on this, I agree there is sometimes the need to access the framework from various methods and it's not always clear how to do it / you end up obtaining through another class which seems hacky.