Beispiel #1
0
 def connectTo(self, connections, **kwargs):
     ''' Set up allowed data sources '''
     tz = kwargs.get('timezone', self.tz)
     log = kwargs.get('logger', None)
     lvl = kwargs.get('lvl', 'debug')
     if 'database' in connections:
         db_name = kwargs.get('db_name', str(os.environ['QTRADEDB']))
         self.db = QuantSQLite(db_name, timezone=tz, logger=log, lvl=lvl)
         self._logger.info('Database location provided, Connected to %s' %
                           db_name)
         self.connected['database'] = True
     if 'remote' in connections:
         self.remote = Fetcher(timezone=tz, logger=log, lvl=lvl)
         self.connected['remote'] = True
     if 'csv' in connections:
         raise NotImplementedError()
Beispiel #2
0

if __name__ == '__main__':
    # Configuration
    assert len(sys.argv) == 2
    if sys.argv[1] == 'twitter':
        database = 'feeds.db'
        script = 'twitterBuild.sql'
    elif sys.argv[1] == 'stocks':
        database = 'stocks.db'
        script = 'stocksBuild.sql'
    else:
        raise NotImplementedError()

    # Open or create the desired sqlite database
    db = QuantSQLite(database)
    # Test everything is alright
    print db.execute('select sqlite_version()')

    # Execute sql script
    db.queryFromScript(script)
    db.close()

    if sys.argv[1] == 'stocks':
        # getQuotes() method will fetch data that is not available in database and then store it
        timestamp = pd.date_range(pd.datetime(2005, 1, 1, tzinfo=pytz.utc),
                                  pd.datetime(2012, 11, 30, tzinfo=pytz.utc),
                                  freq=pd.datetools.BDay())
        tickers = ['starbucks', 'google', 'apple', 'altair']
        fill_quotes(tickers, timestamp)