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/

    Using GenericCSVFeed with JSON data

    General Code/Help
    3
    3
    899
    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.
    • N
      Nir last edited by Nir

      Hi,
      I am fetching JSON OHLC from some endpoint and I wanted to create feed from it.
      Since there is no JSON feed so I'm converting this data into CSV first.
      To avoid writing at disk I'm using String IO buffer (File like object) but seems like the API only supports file path as I'm getting the below error:

      _obj._name, _ = os.path.splitext(os.path.basename(_obj.p.dataname))
      |               |                |                -> <backtrader.feeds.csvgeneric.GenericCSVData object at 0x10e0ad7f0>
      |               |                -> <module 'os' from 'python3.5/os.py'>
      |               -> <module 'os' from 'python3.5/os.py'>
      -> <backtrader.feeds.csvgeneric.GenericCSVData object at 0x10e0ad7f0>
      

      File "../python3.5/posixpath.py", line 139, in basename
      i = p.rfind(sep) + 1
      | -> '/'
      -> <_io.StringIO object at 0x10ad4db88>
      AttributeError: '_io.StringIO' object has no attribute 'rfind'

      Is there any better way of doing this?

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

        Yes the GenericCSVFeed opens the files itself.

        You can subclass directly from CSVDataBase (as GenericCSVFeed does) and simply override _loadline

        It is fully documented here: Docs - CSV Data Feed Development

        1 Reply Last reply Reply Quote 0
        • L
          Laurent Michelizza @Nir last edited by

          @nir
          Why not converting the json to a panda dataframe which you can then load easily?

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