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/

    Handling CTRL-C when trading live

    General Code/Help
    2
    2
    750
    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.
    • H
      holicst last edited by

      Hi Everybody, dear @backtrader,

      I’d like to handle CTRL-C (SIGINT) when trading Live. In this case I’d like to trigger method runstop(), and in the stop() method I want to save the statistics of my trading to a DB. I googled this and added the recommended code:

          def next(self, frompre=False):
      
              try:
      		...business logic here...
              except KeyboardInterrupt:
                  self.log('CTRL-C detected - stopping')
                  self.stopped=True
                  self.env.runstop()
                  return
      

      However, this does not work apparently:

      2017-05-16T12:27:15,
      2017-05-16T12:27:20,
      2017-05-16T12:27:25, Portfolio value: 99776.2408, cash: 97511.7685
      2017-05-16T12:27:25, Position: USD_CZK, size: 4093.0000, price: 23.8976, value: 97812.9177
      2017-05-16T12:27:25, Position: USD_MXN, size: 10487.0000, price: 18.7057, value: 196167.0954
      2017-05-16T12:27:25, Position: GBP_ZAR, size: 5780.0000, price: 16.9514, value: 97978.9764
      2017-05-16T12:27:25, Position: EUR_TRY, size: 24923.0000, price: 3.9304, value: 97956.6115
      forrtl: error (200): program aborting due to control-C event
      Image              PC                Routine            Line        Source
      libifcoremd.dll    00007FFDA97643E4  Unknown               Unknown  Unknown
      KERNELBASE.dll     00007FFDD2EE717D  Unknown               Unknown  Unknown
      KERNEL32.DLL       00007FFDD5DB2774  Unknown               Unknown  Unknown
      ntdll.dll          00007FFDD5FC0D61  Unknown               Unknown  Unknown
      

      How can I achieve the goal to be able to stop a live trading and in that moment save everything to the DB?

      Thanks and best regards,
      Tamás

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

        https://github.com/ContinuumIO/anaconda-issues/issues/905

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