def init_stock_info(self, cdate=None):
        def _set_stock_info(_date, bonus_info, index_info, code_id):
            try:
                if CStock(code_id).set_k_data(bonus_info, index_info, _date):
                    self.logger.info("%s set k data success" % code_id)
                    return (code_id, True)
                else:
                    self.logger.error("%s set k data failed" % code_id)
                    return (code_id, False)
            except Exception as e:
                self.logger.error("%s set k data exception:%s" % (code_id, e))
                return (code_id, False)

        #get stock bonus info
        bonus_info = pd.read_csv("/data/tdx/base/bonus.csv",
                                 sep=',',
                                 dtype={
                                     'code': str,
                                     'market': int,
                                     'type': int,
                                     'money': float,
                                     'price': float,
                                     'count': float,
                                     'rate': float,
                                     'date': int
                                 })

        index_info = CIndex('000001').get_k_data()
        if index_info is None or index_info.empty: return False

        df = self.stock_info_client.get()
        failed_list = df.code.tolist()
        if cdate is None:
            cfunc = partial(_set_stock_info, cdate, bonus_info, index_info)
            return process_concurrent_run(cfunc, failed_list, num=5)
        else:
            succeed = True
            start_date = get_day_nday_ago(cdate, num=10, dformat="%Y-%m-%d")
            for mdate in get_dates_array(start_date, cdate, asending=True):
                if self.cal_client.is_trading_day(mdate):
                    cfunc = partial(_set_stock_info, mdate, bonus_info,
                                    index_info)
                    if not process_concurrent_run(cfunc, failed_list, num=500):
                        succeed = False
            return succeed
Exemple #2
0
    def init_stock_info(self, cdate=None):
        def _set_stock_info(mdate, bonus_info, index_info, code_id):
            try:
                if CStock(code_id).set_k_data(bonus_info, index_info, mdate):
                    self.logger.info("%s set k data success for date:%s",
                                     code_id, mdate)
                    return (code_id, True)
                else:
                    self.logger.error("%s set k data failed for date:%s",
                                      code_id, mdate)
                    return (code_id, False)
            except Exception as e:
                self.logger.error("%s set k data for date %s exception:%s",
                                  code_id, mdate, e)
                return (code_id, False)

        #get stock bonus info
        bonus_info = pd.read_csv("/data/tdx/base/bonus.csv",
                                 sep=',',
                                 dtype={
                                     'code': str,
                                     'market': int,
                                     'type': int,
                                     'money': float,
                                     'price': float,
                                     'count': float,
                                     'rate': float,
                                     'date': int
                                 })

        index_info = CIndex('000001').get_k_data()
        if index_info is None or index_info.empty: return False
        df = self.stock_info_client.get()
        if df.empty: return False
        failed_list = df.code.tolist()
        if cdate is None:
            cfunc = partial(_set_stock_info, cdate, bonus_info, index_info)
            return process_concurrent_run(cfunc, failed_list, num=8)
        else:
            cfunc = partial(_set_stock_info, cdate, bonus_info, index_info)
            succeed = True
            if not process_concurrent_run(cfunc, failed_list, num=8):
                succeed = False
            return succeed
    def init_base_float_profit(self):
        def _set_base_float_profit(code_id):
            return (code_id,
                    True) if CStock(code_id).set_base_floating_profit() else (
                        code_id, False)

        failed_list = self.stock_info_client.get().code.tolist()
        return process_concurrent_run(_set_base_float_profit,
                                      failed_list,
                                      num=500)
Exemple #4
0
 def init_valuation_info(self, cdate=None):
     df = self.stock_info_client.get()
     code_list = df['code'].tolist()
     time2market_list = df['timeToMarket'].tolist()
     code2timedict = dict(zip(code_list, time2market_list))
     cfun = partial(self.cvaluation_client.set_stock_valuation,
                    code2timedict, cdate)
     return process_concurrent_run(cfun,
                                   code_list,
                                   num=15,
                                   black_list=list())
Exemple #5
0
    def init_base_float_profit(self):
        def _set_base_float_profit(code_id):
            if CStock(code_id).set_base_floating_profit():
                self.logger.info("%s set base float profit success" % code_id)
                return (code_id, True)
            else:
                self.logger.error("%s set base float profit failed" % code_id)
                return (code_id, False)

        failed_list = self.stock_info_client.get().code.tolist()
        return process_concurrent_run(_set_base_float_profit,
                                      failed_list,
                                      num=50)