pybottrader.datastreamers.yfinance API documentation

# pybottrader.datastreamers.yfinance

Data streamear for yfinance

View Source

     1"""
     2Data streamear for yfinance
     3"""
     4
     5from typing import Union
     6import pandas as pd
     7import yfinance
     8from . import DataStreamer
     9
    10
    11class YFHistory(DataStreamer):
    12    """Using Yahoo Finance to retrieve data"""
    13
    14    index = 0
    15    data: pd.DataFrame
    16
    17    def __init__(self, symbol, *args, **kwargs):
    18        super().__init__()
    19        ticker = yfinance.Ticker(symbol)
    20        self.data = ticker.history(*args, **kwargs)
    21        self.data.columns = [col.lower() for col in self.data.columns]
    22        self.data.index.names = ["time"]
    23        self.data.reset_index(inplace=True)
    24
    25    def next(self) -> Union[dict, None]:
    26        if self.index >= len(self.data):
    27            return None
    28        result = self.data.iloc[self.index].to_dict()
    29        result["time"] = result["time"].to_pydatetime()
    30        self.index += 1
    31        return result

class YFHistory(pybottrader.datastreamers.DataStreamer): View Source

    12class YFHistory(DataStreamer):
    13    """Using Yahoo Finance to retrieve data"""
    14
    15    index = 0
    16    data: pd.DataFrame
    17
    18    def __init__(self, symbol, *args, **kwargs):
    19        super().__init__()
    20        ticker = yfinance.Ticker(symbol)
    21        self.data = ticker.history(*args, **kwargs)
    22        self.data.columns = [col.lower() for col in self.data.columns]
    23        self.data.index.names = ["time"]
    24        self.data.reset_index(inplace=True)
    25
    26    def next(self) -> Union[dict, None]:
    27        if self.index >= len(self.data):
    28            return None
    29        result = self.data.iloc[self.index].to_dict()
    30        result["time"] = result["time"].to_pydatetime()
    31        self.index += 1
    32        return result

Using Yahoo Finance to retrieve data

YFHistory(symbol, *args, **kwargs) View Source

    18    def __init__(self, symbol, *args, **kwargs):
    19        super().__init__()
    20        ticker = yfinance.Ticker(symbol)
    21        self.data = ticker.history(*args, **kwargs)
    22        self.data.columns = [col.lower() for col in self.data.columns]
    23        self.data.index.names = ["time"]
    24        self.data.reset_index(inplace=True)

Init method

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

    26    def next(self) -> Union[dict, None]:
    27        if self.index >= len(self.data):
    28            return None
    29        result = self.data.iloc[self.index].to_dict()
    30        result["time"] = result["time"].to_pydatetime()
    31        self.index += 1
    32        return result

Next method