Exemplo n.º 1
0
 def __parseDate(self, date):
     parser = yahoofeed.RowParser(INSTRUMENT, datetime.time(23, 59), bar.Frequency.DAY)
     row = {
         "Date": date,
         "Close": 0,
         "Open": 0,
         "High": 0,
         "Low": 0,
         "Volume": 0,
         "Adj Close": 0}
     return parser.parseBar(row).getDateTime()
Exemplo n.º 2
0
 def __parseDate(self, date):
     parser = yahoofeed.RowParser(datetime.time(23, 59))
     row = {
         "Date": date,
         "Close": 0,
         "Open": 0,
         "High": 0,
         "Low": 0,
         "Volume": 0,
         "Adj Close": 0
     }
     return parser.parseBar(row).getDateTime()
Exemplo n.º 3
0
    def addBarsFromCSV(self,
                       instrument,
                       path,
                       timezone=None,
                       skipMalformedBars=False):
        """Loads bars for a given instrument from a CSV formatted file.
        The instrument gets registered in the bar feed.

        :param instrument: Instrument identifier.
        :type instrument: string.
        :param path: The path to the CSV file.
        :type path: string.
        :param timezone: The timezone to use to localize bars. Check :mod:`pyalgotrade.marketsession`.
        :type timezone: A pytz timezone.
        :param skipMalformedBars: True to skip errors while parsing bars.
        :type skipMalformedBars: boolean.
        """

        if timezone is None:
            timezone = self.__timezone

        datasource = instrument.datasource()

        if datasource == DATASOURCE_YAHOOFINANCE:
            rowParser = yahoofeed.RowParser(self.getDailyBarTime(),
                                            self.getFrequency(), timezone,
                                            self.__sanitizeBars)
        elif datasource == DATASOURCE_COINMARKETCAP:
            rowParser = coinmarketcapfeed.RowParser(self.getDailyBarTime(),
                                                    self.getFrequency(),
                                                    timezone,
                                                    self.__sanitizeBars)
        else:
            rowParser = csvfeed.GenericRowParser(self.__columnNames,
                                                 self.__dateTimeFormat,
                                                 self.getDailyBarTime(),
                                                 self.getFrequency(), timezone,
                                                 self.__barClass)

        super(Feed, self).addBarsFromCSV(instrument,
                                         path,
                                         rowParser,
                                         skipMalformedBars=skipMalformedBars)