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



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


  • administrators

    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



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


Log in to reply
 

Looks like your connection to Backtrader Community was lost, please wait while we try to reconnect.