Backtrader Community

    • 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/

    How to update access token of oanda while paper trading

    General Code/Help
    2
    2
    176
    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.
    • Monil Shah
      Monil Shah last edited by

      Hi,
      I have a problem while doing paper-trading for 15 days. As Oanda token expires and I can not refresh the program as I will lose initial positioning and open orders. Is there any method in which I can update the token in backtrader while the program is running. I have tried to change the token in next() method.

      def next(self):
             self.logdata(self.original)
             if not self.data_live:
                 return
      
      
      
             if self.data_live and not eq_sod < datetime.datetime.now().time() < eq_eod:
                
                 print(datetime.datetime.now())
                 new_access_token=input("Please enter access token:")
                 self.cerebro.stores[0].p.access_token = new_access_token
                 self.cerebro.stores[0].oapi.access_token = new_access_token
                 print(datetime.datetime.now())
                
      

      After updating the token, there is no response from the broker.

      13375,2019-12-23T13:24:00,Original,333.15000,333.50000,333.10000,333.35000,84248.00000
      ***** Original DATA NOTIF: LIVE
      13376,2019-12-23T13:26:00,Original,333.60000,333.65000,333.55000,333.55000,232467653.00000
      2019-12-23 13:26:01.577574
      Please enter access token:a340646bf6d99a52054098961a53abb72d17b007
      2019-12-23 13:27:16.912265
      2019-12-23 13:27:16.912329
      
      1 Reply Last reply Reply Quote 0
      • B
        backtrader administrators last edited by

        You are for sure using:

        • https://github.com/ftomassetti/backtrader-oandav20

        Without looking at the code I would dare to say that the store doesn't re-open the connection simply because you update a couple of attribute members whilst trading.

        You will have to ask the author(s) to add a method to do such a thing, something like this from within the strategy

        self.broker.update_token(my_new_token)
        

        and have this method creating a new connection to Oanda which will replace the existing one.

        1 Reply Last reply Reply Quote 0
        • 1 / 1
        • First post
          Last post
        Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors