Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

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

    General Discussion
    5
    6
    1273
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Y
      yeahaa828 last edited by

      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?

      Y P 2 Replies Last reply Reply Quote 0
      • Y
        yangnw @yeahaa828 last edited by

        @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.

        1 Reply Last reply Reply Quote 1
        • P
          Paska Houso @yeahaa828 last edited by

          @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.

          1 Reply Last reply Reply Quote 0
          • Y
            yeahaa828 last edited by

            Hi All,

            Thanks for everyone's input, if anyone's is interested I ended up parsing a queue to my strategy and running it in a separate thread. I used different events inside the queue to trigger inputs and outputs from the strategy while trading live. I could then use the data to display in the main thread which in my case a web application using Flask. It worked well!

            Cheers.

            LarsKlawitter S 2 Replies Last reply Reply Quote 0
            • LarsKlawitter
              LarsKlawitter @yeahaa828 last edited by

              @yeahaa828 I just came across this post. I’m also trying to change parameters for a live trading cerebro instance. Would you mind sharing a code snippet of how you send messages to your strategy’s queue from the other thread?

              1 Reply Last reply Reply Quote 1
              • S
                Saeed Rahman @yeahaa828 last edited by

                @yeahaa828 If you can share the code to that flask app, that would be really useful

                1 Reply Last reply Reply Quote 0
                • 1 / 1
                • First post
                  Last post
                Copyright © 2016, 2017, 2018 NodeBB Forums | Contributors
                $(document).ready(function () { app.coldLoad(); }); }