Exemplo n.º 1
0
    def get_trades(self, pair, start, end):
        """Get trade data from .csv file.

        Args:
            pair (str): Currency pair.
            start (int): Start UNIX of trade data to fetch.
            end (int): End UNIX of trade data to fetch.

        Returns:
            List of trade events, from old to new data.
        """
        dataio = DataIO(savedir=self._savedir, fieldnames=self.FIELDNAMES)
        if dataio.csv_check(pair):
            data = dataio.csv_get(pair)
        else:
            raise ValueError(
                'Bitmex\t| No trades downloaded: {}'.format(pair))

        # look for start and end row indices
        start_index = 0
        end_index = len(data['time']) - 1
        for i, timestamp in enumerate(data['time']):
            if float(timestamp) <= float(start):
                start_index = i
            if float(timestamp) <= float(end):
                end_index = i

        # filter by requested date range
        new_data = {}
        for col_name in data:
            new_data[col_name] = data[col_name][start_index: (end_index + 1)]
        return new_data
Exemplo n.º 2
0
import numpy
from dataio import DataIO

if __name__ == '__main__':

    filename = 'test'
    fieldnames = ['time', 'low', 'high']

    csvio = DataIO('test', fieldnames)
    csvio.csv_newfile(filename)

    test_row1 = {'time': 1.0, 'low': 100, 'high': 101}
    test_row2 = {'time': 2.0, 'low': 101, 'high': 102}
    test_rows = [{'time': 3.0, 'low': 102, 'high': 103},
                 {'time': 4.0, 'low': 103, 'high': 104}]

    exists = csvio.csv_check(filename)
    print(exists)

    print(len(numpy.shape(test_row1)))
    print(len(numpy.shape(test_rows)))

    csvio.csv_append(filename, test_row1)
    csvio.csv_append(filename, test_row2)
    csvio.csv_append(filename, test_rows)

    data = csvio.csv_get(filename)
    print(data)

    csvio.csv_rename(filename, 'test2')