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/

    StringIO Object to DataFeed

    General Code/Help
    3
    4
    89
    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.
    • *
      *Jenel Videos* last edited by

      I have a csv file containing data from multiple symbols. I extracted them one by one from the main csv file and saved it to memory using StringIO. Does anyone know how I can add the StringIO object to the datafeed?

      d={}
      reader = csv.reader(open("a.csv"))
      for row in reader:
          if(not (row[0] in d.keys())):
              d[row[0]] = StringIO()
              csv.writer(d[row[0]]).writerow(row)
          else:
              csv.writer(d[row[0]]).writerow(row)
      
      data = btfeed.GenericCSVData(
          dataname=d["FETBTC"].getvalue(),
      
          nullvalue=0.0,
      
          dtformat=('%Y-%m-%d'),
      
          datetime=0,
          high=1,
          low=2,
          open=3,
          close=4,
          volume=5,
          openinterest=-1
      )
      
      B 1 Reply Last reply Reply Quote 0
      • *
        *Jenel Videos* last edited by

        See below for the error I came across above code. I also tried the StringIO Object itself but I also got an error TypeError: expected str, bytes or os.PathLike object, not _io.StringIO.

        OSError: [Errno 22] Invalid argument: 'FETBTC,2020-01-13,23:00:00,0.00000507,0.00000511,0.00000503,0.00000504,2515111.00000000\r\nFETBTC,2020-01-14,00:00:00,0.00000503,0.00000506,0.00000498,0.00000503,3023068.00000000\r\nFETBTC,2020-01-14,01:00:00,0.00000504,0.00000505,0.00000498,0.00000502,1640454.00000000
        
        1 Reply Last reply Reply Quote 0
        • A
          ab_trader last edited by

          Probably write new data feed class which reads StringIO objects.

          1 Reply Last reply Reply Quote 0
          • B
            backtrader administrators @*Jenel Videos* last edited by

            @Jenel-Videos said in StringIO Object to DataFeed:

            data = btfeed.GenericCSVData(
            dataname=d["FETBTC"].getvalue(),

            After creating file (a pseudo-file) actually, why do you pass a string instead of the file-like object which you have already created?

            The documentation says it:

                Specific parameters (or specific meaning):
            
                  - ``dataname``: The filename to parse or a file-like object
            
            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(); }); }