idea



  • Re: Interactive input strategy

    Hello, the commands will be pause/resume trading whereby the strategy will keep resampling the live data but if it receives a pause command it will not place any trading orders (to the broker), once it receives a resume command it will keep placing orders as before.

    Delaying the feed data will be a problem as you are suggesting so I don't think is a good option to follow.

    Hmm what if we have support for a message broker like RabbitMQ whose queue will act as an additional "command" data source and add a method to Strategy called notify_status() that will be called each time there is a new message in the queue (that can be pause/resume), then the Strategy can set an internal state that will know whether to put orders or not.



  • I don't know how the live trading logic works with backtrader but this logic might need to be handled not by backtrader but by other Python functionality or at the OS level.


  • administrators

    @robomotic said in idea:

    Hello, the commands will be pause/resume trading whereby the strategy will keep resampling the live data but if it receives a pause command it will not place any trading orders (to the broker), once it receives a resume command it will keep placing orders as before.

    Isn't that handled just by having a bool in your code which decides if an order will be sent to the broker or not?

    @robomotic said in idea:

    Hmm what if we have support for a message broker like RabbitMQ whose queue will act as an additional "command" data source and add a method to Strategy called notify_status()

    Same as above. Upon entering next you can pull a command, message, value (you name it) from anything and be the source for the bool above which decides if an order is a trading signal will send an order to the broker or not.

    A very generic approach is to pass a callable to the strategy, to fully isolate even your code from the actual details.

    class Strategy(bt.Strategy):
        params = (
            ...  # other params here
            ('msgpull', None),
        )
    
        def next(self):
            cantrade = True
            if self.p.msgpull is not None:
                cantrade = self.p.msgpull()  # or self.p.msgpull(self) to grant full strategy access to the callable
    
            ....  # some other things
    
            if mybuysignal and cantrade:
                self.buy()
    

Log in to reply
 

Looks like your connection to Backtrader Community was lost, please wait while we try to reconnect.