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/

    idea

    General Discussion
    3
    3
    933
    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.
    • R
      robomotic last edited by

      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.

      B 1 Reply Last reply Reply Quote 0
      • Curtis Miller
        Curtis Miller last edited by

        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.

        1 Reply Last reply Reply Quote 0
        • B
          backtrader administrators @robomotic last edited by

          @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()
          
          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(); }); }