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



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


  • 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
    


  • Probably write new data feed class which reads StringIO objects.


  • administrators

    @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
    

Log in to reply
 

});