예제 #1
0
def fetch_historical(symbol, db_name=None):
    """Fetches historical (EOD) quotes from CBOE and saves them to database.

    Args:
        symbol (str): Symbol to fetch.
        db_name (str): Optional database name.

    Returns:
        int: Number of quotes fetched.
    """
    logger = logging.getLogger(__name__)
    logger.info('Fetching historical futures quotes from CBOE for %s...', \
                symbol)

    lines = 0
    today = datetime.today()
    expirations = dates.get_expirations(symbol)
    for expiration_year in xrange(2015, today.year + 2):
        for expiration_month in xrange(1, 13):
            expiration = dates.find_date(
                expirations, expiration_month, expiration_year)
            if expiration is None:
                continue
            try:
                data = _fetch_historical_data(symbol, expiration)
                if data is None:
                    continue
                lines += _parse_historical_data(
                    symbol, expiration, data, db_name)
            except ValueError:
                break
    logger.info('... quotes retrieved: %d', lines)
    return lines
예제 #2
0
 def test_not_found(self):
     self.assertIsNone(dates.find_date(self.lst, 4, 2015))
예제 #3
0
 def test_found(self):
     self.assertEqual(dates.find_date(self.lst, 2, 2015), date(2015, 2, 14))