コード例 #1
0
 def __init__(self, security_code, is_reset, flag):
     self.security_code = security_code
     self.is_reset = is_reset
     self.flag = flag
     log_list = [
         Utils.get_now(),
         Utils.get_info(),
         self.get_classs_name(), self.security_code,
         self.get_method_name()
     ]
     Utils.print_log(log_list)
コード例 #2
0
    def processing_single_security_code(self):
        log_list = [
            Utils.get_now(),
            Utils.get_info(),
            self.get_classs_name(), self.security_code,
            self.get_method_name(), self.security_code + '【【start】】'
        ]
        Utils.print_log(log_list)
        """
        单只股票处理方法
        :return: 
        """
        # 股票日K数据处理方法
        if self.flag:
            self.processing_day_kline()
        self.processing_real_time_kline()

        log_list = [
            Utils.get_now(),
            Utils.get_info(),
            self.get_classs_name(), self.security_code,
            self.get_method_name(), self.security_code + '【【end】】'
        ]
        Utils.print_log(log_list)
コード例 #3
0
 def processing_real_time_kline(self):
     """
     处理单只股票的实时行情
     :return: 
     """
     try:
         current_date = datetime.datetime.now().replace(microsecond=0)
         start_date = current_date.replace(hour=9,
                                           minute=30,
                                           second=0,
                                           microsecond=0)
         end_date = current_date.replace(hour=15,
                                         minute=0,
                                         second=0,
                                         microsecond=0)
         if current_date <= end_date and current_date >= start_date:
             log_list = [
                 Utils.get_now(),
                 Utils.get_info(),
                 self.get_classs_name(), self.security_code,
                 self.get_method_name(), '当日全部5分钟实时行情 开始时间', start_date,
                 '拉取时间', current_date, '结束时间', end_date
             ]
             Utils.print_log(log_list)
             # if True:
             # 5分钟K的实时行情
             day_kline = tt.get_stock_bar(self.security_code, 1)
             # 处理单只股票的实时行情,并入库
             self.analysis_real_time_kline(day_kline, start_date)
         else:
             log_list = [
                 Utils.get_now(),
                 Utils.get_warn(),
                 self.get_classs_name(), self.security_code,
                 self.get_method_name(), '当日全部5分钟实时行情 开始时间', start_date,
                 '拉取时间', current_date, '结束时间', end_date, '【交易结束或不在交易时间段内】'
             ]
             Utils.print_log(log_list)
     except Exception:
         traceback.print_exc()
コード例 #4
0
    def processing_day_kline(self):
        """
        股票日K数据处理,分全量还是增量
        :return: 
        """
        try:
            if self.is_reset:
                max_the_date = datetime.datetime.now().replace(year=1970,
                                                               month=1,
                                                               day=1)
            else:
                max_the_date = self.get_max_the_date()
            diff_days = Utils.diff_days(max_the_date)
            log_list = [
                Utils.get_now(),
                Utils.get_info(),
                self.get_classs_name(), self.security_code,
                self.get_method_name(), '最大交易日', max_the_date, '距今',
                Utils.format_date(datetime.date.today()), '差', diff_days, '天'
            ]
            Utils.print_log(log_list)
            dict_data_pre = None
            if diff_days is None:
                result = tt.get_all_daybar(self.security_code, 'bfq')
            else:
                result = tt.get_last_n_daybar(self.security_code, diff_days,
                                              'bfq')

            if result.empty == False:
                # 按照正序排序,时间小的排前面
                result.sort_index(ascending=True)
                # 需要处理的单只股票进度计数
                add_up = 0
                # 需要处理的单只股票进度打印字符
                process_line = '='
                len_indexes = len(result.index.values)
                for i in range(len_indexes):
                    add_up += 1
                    if i < 9:
                        continue
                    end = i + 1
                    start = i - 9
                    section = result.iloc[start:end, :]
                    dict_data = self.processing_section(section, dict_data_pre)
                    dict_data_pre = dict_data
                    # 批量打印日志
                    if add_up % 200 == 0:
                        process_line += '='
                        progress = Utils.base_round(
                            Utils.division_zero(add_up, len_indexes) * 100, 2)
                        log_list = [
                            Utils.get_now(),
                            Utils.get_info(),
                            self.get_classs_name(), self.security_code,
                            self.get_method_name(), '处理进度', add_up,
                            len_indexes, process_line,
                            str(progress) + '%'
                        ]
                        Utils.print_log(log_list)
                process_line += '='
                progress = Utils.base_round(
                    Utils.division_zero(add_up, len_indexes) * 100, 2)
                log_list = [
                    Utils.get_now(),
                    Utils.get_info(),
                    self.get_classs_name(), self.security_code,
                    self.get_method_name(), '处理进度', add_up, len_indexes,
                    process_line,
                    str(progress) + '%'
                ]
                Utils.print_log(log_list)
                # self.dbService.upsert_many(list_db_data, 'tquant_stock_history_quotation', ['security_code', 'the_date'])
            else:
                log_list = [
                    Utils.get_now(),
                    Utils.get_warn(),
                    self.get_classs_name(), self.security_code,
                    self.get_method_name(), '【日K DataFrame为空】'
                ]
                Utils.print_log(log_list)
        except Exception:
            traceback.print_exc()