Esempio n. 1
0
    def _get_from_yahoo(self, date_time, failed_tries=0):
        """Fetch close price of instrument on given date from yahoo"""
        if failed_tries >= config.getint("price_fetch_max_allowed_tries"):
            log.warning(
                "Refusing to fetch {} {} because of {} previous failed attempt. Returning 0.001"
                .format(self.instrument.symbol_yahoo, date_time, failed_tries))
            return 0.001
        log.debug("{}: Fetching {}".format(self.instrument.symbol_yahoo,
                                           date_time))
        try:
            data = Fetcher(self.instrument.symbol_yahoo,
                           [date_time.year, date_time.month, date_time.day])
        except UnboundLocalError:
            log.warning("Failed to fetch price: {} {}".format(
                self.instrument.symbol_yahoo, date_time))
            return self.get(date_time - timedelta(days=1),
                            failed_tries=failed_tries + 1).as_float

        try:
            price_as_float = data.getDatePrice().values[0][1]
        except IndexError:
            log.warning("Failed to fetch price: {} {}".format(
                self.instrument.symbol_yahoo, date_time))
            price_as_float = self.get(date_time - timedelta(days=1),
                                      failed_tries=failed_tries + 1).as_float
        self._write_to_database(price_as_float, date_time)
        return price_as_float
Esempio n. 2
0
def run_Fetcher(stock_name, start, end, cycle):
    #print(stock_name)
    AAPL = Fetcher(stock_name, start, end, cycle)
    date_close = AAPL.getDatePrice()
    close = date_close.ix[:, [1]]

    summ = 0
    ar = np.empty

    for i in range(len(close)):
        summ += close.ix[i][0]
        ar = np.append(ar, close.ix[i][0])

    ar = ar[1:]

    return ar