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/

    time data 'x' does not match format '%Y-%m-%d %H:%M:%S'

    Indicators/Strategies/Analyzers
    3
    9
    58
    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.
    • G
      Gleetche last edited by

      Hi there,

      I'm still trying to convert unix timestamp to date, but I just can't get it to work.

      From
      https://www.backtrader.com/docu/datafeed/#genericcsvdata
      16fbacec-61bc-4a8e-b4c4-97b1159c4e5f-image.png

      So I tried it on my code:
      b98a72d9-b7ff-4324-b10a-9e4b646ca660-image.png

      here's a sample of my csv:

      Open Time   ,Open         ,High         ,Low          ,Close        ,Volume     ,Close Time   ,QuoteAssetVol  ,Not ,Takerbuybv , takerbuyqv    ,
      1577836800.0,7195.24000000,7196.25000000,7178.64000000,7179.78000000,95.50913300,1577837099999,686317.13625177,1127,32.77324500,235537.29504531,0
      

      4a34b20c-1309-4df4-8587-b7c1ffb498ee-image.png

      and here's the output:
      079475d2-e562-4022-a919-8434b8e28a9d-image.png

      run-out 1 Reply Last reply Reply Quote 0
      • R
        rajanprabu last edited by

        @Gleetche

        You need to convert the unixtimestamp to date using bt.date2num function.. Have a look at the
        Binary Feed Doc

        You can use open time or close time depending on your choice.

        1 Reply Last reply Reply Quote 1
        • G
          Gleetche last edited by

          @rajanprabu
          thank you for your reply, trying it out!

          1 Reply Last reply Reply Quote 0
          • G
            Gleetche last edited by

            @rajanprabu

            I tried using the
            "VChartData Full Code" at the bottom of
            https://www.backtrader.com/docu/datafeed-develop-general/datafeed-develop-general/

            How do I implement it? In the sample code, there are several "dataname" do I change it to the name of my file or something else? Sorry I don't really understand how to use it :/
            cdeec3b0-2479-4cb2-aa3a-43045673403f-image.png

            1 Reply Last reply Reply Quote 0
            • run-out
              run-out @Gleetche last edited by

              @Gleetche Looking at the docstrings:

               - ``dtformat``: Format used to parse the datetime CSV field. See the
                      python strptime/strftime documentation for the format.
                      If a numeric value is specified, it will be interpreted as follows
                        - ``1``: The value is a Unix timestamp of type ``int`` representing
                          the number of seconds since Jan 1st, 1970
                        - ``2``: The value is a Unix timestamp of type ``float``
              

              Try using numeric value instead of format string.

              1 Reply Last reply Reply Quote 0
              • G
                Gleetche last edited by

                @run-out

                I changed it to dtformat=2 in

                data = (bt.feeds.GenericCSVData(
                	dataname='data/1jan2020.csv',
                	timeframe=bt.TimeFrame.Minutes,
                    compression=5,
                	nullvalue=0.0,
                	dtformat=2,
                	datetime=0,
                	open=1,
                	high=2,
                	low=3,
                	close=4,
                	volume=5,
                	openinterest=-1
                ))
                

                The code is working now, but back like how it originally was, only the date is being shown without the time:
                6ee55950-50c9-467a-97ed-5dbac2317a65-image.png

                run-out 1 Reply Last reply Reply Quote 0
                • R
                  rajanprabu last edited by

                  Please check what are you printing. I did a quick test and it has time as well..

                  1 Reply Last reply Reply Quote 2
                  • run-out
                    run-out @Gleetche last edited by

                    @Gleetche Try printing:

                    self.datetime.datetime()
                    
                    1 Reply Last reply Reply Quote 1
                    • G
                      Gleetche last edited by

                      @run-out @rajanprabu

                      Thank you very much! I got it fixed, I just changed:
                      the logging function from

                          def log(self, txt, dt=None):
                              ''' Logging function for this strategy'''
                              dt = dt or self.datas[0].datetime.date(0)
                              print('%s, %s' % (dt.isoformat(), txt))
                      

                      to

                          def log(self, txt, dt=None):
                              ''' Logging function for this strategy'''
                              dt = dt or self.datas[0].datetime.datetime(0)
                              print('%s, %s' % (dt.isoformat(), txt))
                      
                      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(); }); }