Esempio n. 1
0
class MongoTimeSeriesTestCase(MongoTestCase):
    metric = 'price'
    def setUp(self):
        super(MongoTimeSeriesTestCase, self).setUp()
        self.cache = MongoTimeseries(self.collection, self.metric)
        
    def test_get(self):
        import datetime
        metric = self.metric
        symbol, date, price = ('ABC', 
                               datetime.datetime(2012, 12, 1, tzinfo=pytz.UTC), 
                               6.5)
        key = {'symbol' : symbol, 'date' : date}
        data = {'symbol' : symbol,
                metric : price,
                'date' : date}
        self.collection.update(key, data, upsert=True)
        cache_date, cache_price = self.cache.get(symbol=symbol, dates=[date]).next()
        self.assertEqual(cache_price, price)
        self.assertEqual(cache_date, date)

    def test_set(self):
        import datetime
        metric = self.metric
        symbol, date, price = ('ABC',
                                datetime.datetime(2012, 12, 1, tzinfo=pytz.UTC), 
                                6.5)
        self.cache.set(symbol=symbol, records=[(date, price)])
        test_data = self.collection.find({'symbol' : symbol})[0]
        self.assertEqual(test_data[metric], price)
        self.assertEqual(test_data['symbol'], symbol)
        
Esempio n. 2
0
def mongo_price_cache(mongo_host='localhost', mongo_port=27017):
    client = pymongo.MongoClient(mongo_host, mongo_port)
    collection = client.prices.prices
    db = MongoTimeseries(mongo_collection=collection, metric='price')
    cache = FinancialDataTimeSeriesCache(gets_data=get_prices_from_yahoo, 
                                         database=db)
    return cache
Esempio n. 3
0
 def setUp(self):
     super(MongoTimeSeriesTestCase, self).setUp()
     self.cache = MongoTimeseries(self.collection, self.metric)
 def build_mongo_price_cache(cls,
                             mongo_host='localhost', 
                             mongo_port=27017):
     mongo_driver = MongoTimeseries.price_db(host=mongo_host, port=mongo_port)
     cache = cls(gets_data=prices.get_prices_from_yahoo, database=mongo_driver)
     return cache
 def build_mongo_price_cache(cls, mongo_host='localhost', mongo_port=27017):
     mongo_driver = MongoTimeseries.price_db(host=mongo_host,
                                             port=mongo_port)
     cache = cls(gets_data=prices.get_prices_from_yahoo,
                 database=mongo_driver)
     return cache
 def _build_mongo_cache(self):
     db_driver = MongoTimeseries(mongo_collection=self.collection,
                                 metric='Adj Close')
     cache = FinancialDataTimeSeriesCache(
         gets_data=prices.get_prices_from_yahoo, database=db_driver)
     return cache