Access strategy data or set strategy parameters during live trading from another thread



  • Hi All,

    Does backtrader have the ability to access strategy data or set strategy parameters during live trading? For example, if you wanted to change an indicator parameter without having to restart the live trading session or you wanted to access indicator data when ever you want it.

    If not, does anyone have any recommendations for the best way to do this? I was thinking sockets? Any other suggestions?



  • @yeahaa828

    It's probably not easy to block the bt internal loop and wait for an input. You will have to fetch the parameter from outside the strategy.

    sockets are too low level. If you generate the parameters in another python script and want to serve it, zeromq is a better alternative.

    If you update the parameters manually, just read from a file, or, maybe fancier, redis.



  • @yeahaa828 said in Access strategy data or set strategy parameters during live trading from another thread:

    If not, does anyone have any recommendations for the best way to do this? I was thinking sockets? Any other suggestions?

    If you are accessing from another thread as the title indicates, there is no need to have a provision for anything. You already have access to the strategy.

    How you receive your signal (a socket as you mention) to trigger the change is not relevant. What you need is to make sure that your "parameter-changing" code executes without the main thread code taking over (i.e.: the thread scheduler switches amongst threads)

    The easiest way is a lock which will be acquired by each of the threads, making sure that until the lock is released, no other thread will be able to execute anything.


Log in to reply
 

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