Exemplo n.º 1
0
 def update_bars_by_dates(self,
                          start,
                          end,
                          typ: SeType = SeType.Stock,
                          freq: SeFreq = SeFreq.DAY,
                          codes=None):
     DB_CLIENT.create_index(typ.repo_name(freq), freq.keys_to_index())
     if codes is None:
         codes = self.read_security_codes(typ)
     executor.execute_tasks(codes, self.do_fetch_and_replace_by_dates, typ,
                            start, end, freq)
     print("These codes failed to update: [" + ','.join(self.failed_codes) +
           "]")
Exemplo n.º 2
0
 def update_bars(self,
                 typ: SeType = SeType.Stock,
                 freq: SeFreq = SeFreq.DAY,
                 codes=None,
                 days_to_update=DAYS_TO_UPDATE):
     DB_CLIENT.create_index(typ.repo_name(freq), freq.keys_to_index())
     if codes is None:
         codes = self.read_security_codes(typ)
     end = date_time_utils.Date()
     start = end.get_before(days_to_update)
     executor.execute_tasks(codes, self.do_fetch_and_save_bars, typ,
                            start.as_str(), end.as_str(), freq)
     print("These codes failed to update: [" + ','.join(self.failed_codes) +
           "]")
Exemplo n.º 3
0
 def refetch_and_save_bars(self,
                           typ: SeType,
                           freq: SeFreq = SeFreq.DAY,
                           codes=None):
     if codes is None:
         if self.__confirm_drop():
             self.drop_bar_repo(typ, freq)
             print('删除完成。')
             codes = self.read_security_codes(typ)
         else:
             print("操作已取消。")
             return
     else:
         DB_CLIENT.remove_all_from(typ.repo_name(freq),
                                   query={'code': {
                                       '$in': codes
                                   }})
     DB_CLIENT.create_index(typ.repo_name(freq), freq.keys_to_index())
     end = date_time_utils.Date()
     start = date_time_utils.Date.from_str(MIN_START_TIME)
     executor.execute_tasks(codes, self.do_fetch_and_save_bars, typ,
                            start.as_str(), end.as_str(), freq)
Exemplo n.º 4
0
 def save(self, data):
     DB_CLIENT.create_index(self.repo_name(), self.freq.keys_to_index())
     if data is not None and len(data) > 0:
         repo_name = self.repo_name()
         DB_CLIENT.update_data_append_newer(data, repo_name)
Exemplo n.º 5
0
 def replace_by_dates(self, data, code, start, end):
     DB_CLIENT.delete_by_code_and_dates(self.repo_name(), code, start, end)
     if data is not None and len(data) > 0:
         DB_CLIENT.create_index(self.repo_name(), self.freq.keys_to_index())
         repo_name = self.repo_name()
         DB_CLIENT.replace_data_by_date_range(data, repo_name, start, end)