Beispiel #1
0
 def get_bars(self, pcontract, dt_start, dt_end):
     self.log.append(HashObject.new(start=dt_start, end=dt_end))
     dt_start = pd.to_datetime(dt_start)
     dt_end = pd.to_datetime(dt_end)
     dt_curr = dt_start
     arr = []
     while dt_curr <= dt_end:
         arr.append({'datetime': dt_curr})
         dt_curr += pcontract.period.to_timedelta()
     data = pd.DataFrame([{'datetime': pd.to_datetime('2010-1-1')}])\
              .set_index('datetime')
     return SourceWrapper(pcontract, data, len(data))
 def get_bars(self, pcontract, dt_start, dt_end):
     try:
         logger.info('trying to load from cache')
         return self.cache.get_bars(pcontract, dt_start, dt_end)
     except LoadCacheException as e:
         logger.info('updating cache')
         missing_range = e.missing_range
         logger.info('missing range: {0}', missing_range)
         missing_data = []
         for start, end in missing_range:
             wrapper = self.datasource.get_bars(pcontract, start, end)
             missing_data.append(
                 HashObject.new(data=wrapper.data, start=start, end=end))
         self.cache.save_data(missing_data, pcontract)
         logger.info('loading cache')
         return self.cache.get_bars(pcontract, dt_start, dt_end)
Beispiel #3
0
 def get_bars(self, pcontract, dt_start, dt_end):
     try:
         logger.info('trying to load from cache')
         return self.cache.get_bars(pcontract, dt_start, dt_end)
     except LoadCacheException as e:
         logger.info('updating cache')
         missing_range = e.missing_range
         logger.info('missing range: {0}', missing_range)
         missing_data = []
         for start, end in missing_range:
             wrapper = self.datasource.get_bars(pcontract, start, end)
             missing_data.append(HashObject.new(data=wrapper.data,
                                                start=start,
                                                end=end))
         self.cache.save_data(missing_data, pcontract)
         logger.info('loading cache')
         return self.cache.get_bars(pcontract, dt_start, dt_end)