pybottrader.datastreamers API documentation

# pybottrader.datastreamers

# Data Streamers

Data streamers to read or retrieve sequential data. They provide a `next` method to bring access to the next data item. Current data streamers implemented: `CSVFileStreamer` and `YFinanceStreamer` (based on the `yfinace` library.)

View Source

     1"""
     2# Data Streamers
     3
     4Data streamers to read or retrieve sequential data. They provide a `next` method
     5to bring access to the next data item. Current data streamers implemented:
     6`CSVFileStreamer` and `YFinanceStreamer` (based on the `yfinace` library.)
     7
     8"""
     9
    10from typing import Union
    11import pandas as pd
    12import yfinance
    13
    14
    15class DataStreamer:
    16    """A data streamer abstract class"""
    17
    18    def __init__(self):
    19        """Init method"""
    20
    21    def next(self) -> Union[dict, None]:
    22        """Next method"""
    23
    24
    25class CSVFileStreamer(DataStreamer):
    26    """
    27    An dataframe file streamer
    28    """
    29
    30    data: pd.DataFrame
    31    index: int
    32
    33    def __init__(self, filename: str):
    34        self.index = 0
    35        self.data = pd.read_csv(filename, parse_dates=True)
    36
    37    def next(self) -> Union[dict, None]:
    38        if self.index >= len(self.data):
    39            return None
    40        result = self.data.iloc[self.index].to_dict()
    41        self.index += 1
    42        return result

class DataStreamer: View Source

    16class DataStreamer:
    17    """A data streamer abstract class"""
    18
    19    def __init__(self):
    20        """Init method"""
    21
    22    def next(self) -> Union[dict, None]:
    23        """Next method"""

A data streamer abstract class

DataStreamer() View Source

    19    def __init__(self):
    20        """Init method"""

Init method

def next(self) -> Optional[dict]: View Source

    22    def next(self) -> Union[dict, None]:
    23        """Next method"""

Next method

class CSVFileStreamer(DataStreamer): View Source

    26class CSVFileStreamer(DataStreamer):
    27    """
    28    An dataframe file streamer
    29    """
    30
    31    data: pd.DataFrame
    32    index: int
    33
    34    def __init__(self, filename: str):
    35        self.index = 0
    36        self.data = pd.read_csv(filename, parse_dates=True)
    37
    38    def next(self) -> Union[dict, None]:
    39        if self.index >= len(self.data):
    40            return None
    41        result = self.data.iloc[self.index].to_dict()
    42        self.index += 1
    43        return result

An dataframe file streamer

CSVFileStreamer(filename: str) View Source

    34    def __init__(self, filename: str):
    35        self.index = 0
    36        self.data = pd.read_csv(filename, parse_dates=True)

Init method

data: pandas.core.frame.DataFrame
index: int
def next(self) -> Optional[dict]: View Source

    38    def next(self) -> Union[dict, None]:
    39        if self.index >= len(self.data):
    40            return None
    41        result = self.data.iloc[self.index].to_dict()
    42        self.index += 1
    43        return result

Next method