예제 #1
0
파일: pdSql0.py 프로젝트: taolaptop/pytrade
def is_system_risk(indexs=['sh','cyb'],index_exit_data=get_index_exit_data(['sh','cyb']),
                   yh_index_symbol_maps = {'sh':'999999','sz':'399001','zxb':'399005','cyb':'399006',
                         'sh50':'000016','sz300':'399007','zx300':'399008'}):
    exit_data =index_exit_data
    if not exit_data:
        exit_data = get_index_exit_data(indexs)
    index_quot = qq.get_qq_quotations(codes=indexs)
    #overlap_index = list(set(list(exit_data.keys())) & set(list(index_quot.keys())))
    if not exit_data or not index_quot:
        return {}
    risk_data = {}
    for index in indexs:
        this_risk = {}
        index_now = index_quot[index]['now']
        index_exit_half = exit_data[yh_index_symbol_maps[index]]['exit_half']
        index_exit_all = exit_data[yh_index_symbol_maps[index]]['exit_all']
        index_exit_rate = exit_data[yh_index_symbol_maps[index]]['exit_rate']
        risk_state = 0
        if index_exit_all==0:
            last_close = index_quot[index]['close']
            index_exit_all = (1+2*index_exit_rate) * last_close
            index_exit_half = (1+index_exit_rate) * last_close
        else:
            pass
        if index_now<index_exit_all:
            risk_state = 1.0
        elif index_now<index_exit_half:
            risk_state = 0.5
        else:
            pass
        if risk_state>0:
            this_risk['index'] = index
            this_risk['index_value'] = index_now
            this_risk['index_state'] = risk_state
            this_risk['date_time'] = datetime.datetime.now()
        risk_data[index] = this_risk
    print(risk_data)
    return risk_data
예제 #2
0
파일: pdSql.py 프로젝트: taolaptop/pytrade
 def update_sql_index(self, index_list=['sh','sz','zxb','cyb','hs300','sh50'],force_update=False):
     index_symbol_maps = {'sh':'999999','sz':'399001','zxb':'399005','cyb':'399006',
                      'sh50':'000016','sz300':'399007','zx300':'399008','hs300':'000300'}
     FIX_FACTOR = 1.0
     scz_code_str='399001'
     zxb_code_str='399005'
     chy_code_str='399006'
     shz ='999999'
     shz_50 = '000016'
     hs_300 = '000300'
     zx_300 ='399008'
     sz_300 ='399007'
     d_format='%Y/%m/%d'
     last_date_str = tt.get_last_trade_date(date_format=d_format)
     latest_date_str = tt.get_latest_trade_date(date_format=d_format)
     print('last_date_str=',last_date_str)
     print('latest_date_str=',latest_date_str)
     #next_date_str = tt.get_next_trade_date(date_format=d_format)
     #print(next_date_str)
     try:
         quotation_index_df = qq.get_qq_quotations(['sh','sz','zxb','cyb','hs300','sh50'], ['code','date','open','high','low','close','volume','amount'])
         #quotation_index_df = ts.get_index()
     except:
         sleep(3)
         quotation_index_df = qq.get_qq_quotations(['sh','sz','zxb','cyb','hs300','sh50'], ['code','date','open','high','low','close','volume','amount'])
     #quotation_index_df[['open','high','low','close']]=quotation_index_df[['open','high','low','close']].round(2)
     #quotation_index_df['amount'] = quotation_index_df['amount']*(10**8)
     #quotation_index_df['date'] = latest_date_str
     quotation_index_df['factor'] = 1.0
     #print(quotation_index_df)
     need_to_send_mail = []
     sub = ''
     #table_update_times = self.get_table_update_time()
     for index_name in index_list:
         yh_symbol = index_symbol_maps[index_name]
         yh_file_name = YH_SOURCE_DATA_DIR+symbol+'.'+file_type
         #yh_index_df = get_yh_raw_hist_df(code_str=symbol)
         yh_index_df = pd.read_csv(yh_file_name)
         yh_index_df['factor'] = FIX_FACTOR
         try:
             date_data = self.query_data(table=index_name,fields='date',condition="date>='%s'" % last_date_str)
             data_len = len(date_data)
             #this_table_update_time = table_update_times[index_name]
             #print('this_table_update_time=', this_table_update_time)
             if len(date_data)==0: #no update more than two day
                 """需要手动下载银河客户端数据"""
                 print('Need to manual update %s index from YH APP! Please make suere you have sync up YH data' % index_name)
                 need_to_send_mail.append(index_name)
                 sub = '多于两天没有更新指数数据库'
                 self.drop_table(table_name=index_name)
                 self.insert_table(data_frame=yh_index_df,table_name=index_name)
             elif len(date_data) == 1: # update by last date
                 """只需要更新当天数据"""
                 self.update_sql_index_today(index_name,latest_date_str,quotation_index_df,index_symbol_maps)
                 pass
             elif len(date_data) == 2: #update to  latest date
                 """要更新盘中获取的当天数据"""
                 print(' %s index updated to %s.' % (index_name,latest_date_str))
                 if force_update:
                     print(' force update %s index' % index_name)
                     self.delete_data(table_name=index_name,condition="date='%s'" % latest_date_str)
                     self.update_sql_index_today(index_name,latest_date_str,quotation_index_df,index_symbol_maps)
                     pass
                 else:
                     pass
             else:
                 pass
         #print(date_data)
         except:
             sub = '数据表不存在'
             need_to_send_mail.append(index_name)
             print('Table %s not exist.'% index_name)
             try:
                 self.drop_table(table_name=yh_index_df)
             except:
                 pass
             self.insert_table(data_frame=yh_index_df,table_name=index_name,is_index=False)
             print('Created the table %s.' % index_name)
     if need_to_send_mail:
         content = '%s 数据表更新可能异常' % need_to_send_mail
         sm.send_mail(sub,content,mail_to_list=None)
예제 #3
0
파일: pdSql.py 프로젝트: taolaptop/pytrade
 def update_one_stock(self, symbol,force_update=False):
     index_symbol_maps = {'sh':'999999','sz':'399001','zxb':'399005','cyb':'399006',
                      'sh50':'000016','sz300':'399007','zx300':'399008','hs300':'000300'}
     FIX_FACTOR = 1.0
     d_format='%Y/%m/%d'
     last_date_str = tt.get_last_trade_date(date_format=d_format)
     latest_date_str = tt.get_latest_trade_date(date_format=d_format)
     print('last_date_str=',last_date_str)
     print('latest_date_str=',latest_date_str)
     next_date_str = tt.get_next_trade_date(date_format=d_format)
     #print(next_date_str)
     quotation_date = ''
     try:
         quotation_index_df = qq.get_qq_quotations([symbol], ['code','date','open','high','low','close','volume','amount'])
         quotation_date = quotation_index_df.iloc[0]['date']
         #quotation_index_df = ts.get_index()
     except:
         sleep(3)
         quotation_index_df = qq.get_qq_quotations([symbol], ['code','date','open','high','low','close','volume','amount'])
         quotation_date = quotation_index_df.iloc[0]['date']
     print('quotation_date=',quotation_date)
     print(quotation_index_df)
     quotation_index_df['factor'] = 1.0
     quotation_index_df = quotation_index_df[['date','open','high','low','close','volume','amount','factor']]
     #quotation_index_df.iloc[0]['volume'] = 0
     #quotation_index_df.iloc[0]['amount'] = 0
     print(quotation_index_df)
     #print(quotation_index_df)
     need_to_send_mail = []
     sub = ''
     index_name = symbol
     #table_update_times = self.get_table_update_time()
     if quotation_date:
         yh_symbol = symbol
         if symbol in index_symbol_maps.keys():
             yh_symbol = index_symbol_maps[index_name]
         yh_file_name = YH_SOURCE_DATA_DIR+symbol+'.'+file_type
         #yh_index_df = get_yh_raw_hist_df(code_str=symbol)
         yh_index_df = pd.read_csv(yh_file_name)
         yh_index_df['factor'] = FIX_FACTOR
         yh_last_date = yh_index_df.tail(1).iloc[0]['date']
         print('yh_last_date=',yh_last_date)
         print( yh_index_df)#.head(len(yh_index_df)-1))
         if True:
             #date_data = self.query_data(table=index_name,fields='date',condition="date>='%s'" % last_date_str)
             #data_len = len(date_data)
             #this_table_update_time = table_update_times[index_name]
             #print('this_table_update_time=', this_table_update_time)
             if yh_last_date<last_date_str: #no update more than two day
                 """需要手动下载银河客户端数据"""
                 print('Need to manual update %s index from YH APP! Please make suere you have sync up YH data' % index_name)
                 need_to_send_mail.append(index_name)
                 sub = '多于两天没有更新指数数据库'
                 content = '%s 数据表更新可能异常' % need_to_send_mail
                 sm.send_mail(sub,content,mail_to_list=None)
             elif yh_last_date==last_date_str: # update by last date
                 """只需要更新当天数据"""
                 yh_index_df = yh_index_df.append(quotation_index_df, ignore_index=True)
                 print(yh_index_df)
                 pass
             else:# yh_last_date>latest_date_str: #update to  latest date
                 """YH已经更新到今天,要更新盘中获取的当天数据"""
                 print(' %s index updated to %s; not need to update' % (index_name,latest_date_str))
                 if force_update:
                     print(' force update %s index' % index_name)
                     yh_index_df0 = yh_index_df.head(len(yh_index_df)-1)
                     print(yh_index_df0)
                     yh_index_df = yh_index_df0.append(quotation_index_df, ignore_index=True)
                     print(yh_index_df)
                 else:
                     pass
             yh_index_df = yh_index_df.set_index('date')
             dir='C:/hist/day/data/'
             file_name = dir+ '%s.csv' % index_name
             try:
                 os.remove(file_name)
                 print('Delete and update the csv file')
             except:
                 pass
             yh_index_df.to_csv(file_name ,encoding='utf-8')
     return yh_index_df
예제 #4
0
파일: pdSql0.py 프로젝트: taolaptop/pytrade
def update_one_stock(symbol,realtime_update=False,dest_dir='C:/hist/day/data/', force_update_from_YH=False):
    """
    运行之前先下载及导出YH历史数据
    """
    """
    :param symbol: string type, stock code
    :param realtime_update: bool type, True for K data force update during trade time 
    :param dest_dir: string type, like csv dir
    :param force_update_from_YH: bool type, force update K data from YH
    :return: Dataframe, history K data for stock
    """
    index_symbol_maps = {'sh':'999999','sz':'399001','zxb':'399005','cyb':'399006',
                     'sh50':'000016','sz300':'399007','zx300':'399008','hs300':'000300'}
    qq_index_symbol_maps = {'sh':'000001','sz':'399001','zxb':'399005','cyb':'399006',
                         'sh50':'000016','sz300':'399007','zx300':'399008','hs300':'000300'}
    FIX_FACTOR = 1.0
    d_format='%Y/%m/%d'
    last_date_str = tt.get_last_trade_date(date_format=d_format)
    latest_date_str = tt.get_latest_trade_date(date_format=d_format)
    #print('last_date_str=',last_date_str)
    #print('latest_date_str=',latest_date_str)
    next_date_str = tt.get_next_trade_date(date_format=d_format)
    #print(next_date_str)
    dest_file_name = dest_dir+ '%s.csv' % symbol
    dest_df = get_raw_hist_df(code_str=symbol)
    file_type='csv'
    RAW_HIST_DIR = "C:/中国银河证券海王星/T0002/export/"
    yh_file_name = RAW_HIST_DIR+symbol+'.'+file_type
    if dest_df.empty:
        if symbol in index_symbol_maps.keys():
            symbol = index_symbol_maps[symbol]
        yh_file_name = RAW_HIST_DIR+symbol+'.'+file_type
        #yh_index_df = get_yh_raw_hist_df(code_str=symbol)
        yh_index_df = pd.read_csv(yh_file_name)
        yh_index_df['factor'] = 1.0
        yh_df = yh_index_df.set_index('date')
        yh_df.to_csv(dest_file_name ,encoding='utf-8')
        dest_df = yh_index_df
        #del dest_df['rmb']
        return yh_df
    #print(dest_df)
    dest_df_last_date = dest_df.tail(1).iloc[0]['date']
    #print('dest_df_last_date=',dest_df_last_date)
    if dest_df_last_date<latest_date_str:     
        quotation_date = ''
        try:
            quotation_index_df = qq.get_qq_quotations([symbol], ['code','date','open','high','low','close','volume','amount'])
            quotation_date = quotation_index_df.iloc[0]['date']
            if dest_df_last_date==quotation_date:
                return dest_df
            #quotation_index_df = ts.get_index()
        except:
            time.sleep(3)
            quotation_index_df = qq.get_qq_quotations([symbol], ['code','date','open','high','low','close','volume','amount'])
            quotation_date = quotation_index_df.iloc[0]['date']
            if dest_df_last_date==quotation_date:
                return dest_df
        #print('quotation_date=',quotation_date)
        #print(quotation_index_df)
        quotation_index_df['factor'] = 1.0
        quotation_index_df = quotation_index_df[['date','open','high','low','close','volume','amount','factor']]
        #quotation_index_df.iloc[0]['volume'] = 0
        #quotation_index_df.iloc[0]['amount'] = 0
        #print(quotation_index_df)
        #print(quotation_index_df)
        need_to_send_mail = []
        sub = ''
        index_name = symbol
        #table_update_times = self.get_table_update_time()
        
        if quotation_date:
            yh_symbol = symbol
            if symbol in index_symbol_maps.keys():
                yh_symbol = index_symbol_maps[index_name]
            yh_file_name = RAW_HIST_DIR+yh_symbol+'.'+file_type
            #yh_index_df = get_yh_raw_hist_df(code_str=symbol)
            yh_index_df = pd.read_csv(yh_file_name,encoding='GBK')
            yh_index_df['factor'] = FIX_FACTOR
            yh_last_date = yh_index_df.tail(1).iloc[0]['date']
            #print('yh_last_date=',yh_last_date)
            #print( yh_index_df)#.head(len(yh_index_df)-1))
            
            if yh_last_date>dest_df_last_date:  #dest_df_last_date<latest_date_str
                #date_data = self.query_data(table=index_name,fields='date',condition="date>='%s'" % last_date_str)
                #data_len = len(date_data)
                #this_table_update_time = table_update_times[index_name]
                #print('this_table_update_time=', this_table_update_time)
                if yh_last_date<last_date_str: #no update more than two day
                    """需要手动下载银河客户端数据"""
                    print('Need to manual update %s index from YH APP! Please make suere you have sync up YH data' % index_name)
                    need_to_send_mail.append(index_name)
                    sub = '多于两天没有更新指数数据库'
                    content = '%s 数据表更新可能异常' % need_to_send_mail
                    sm.send_mail(sub,content,mail_to_list=None)
                elif yh_last_date==last_date_str: # update by last date
                    """只需要更新当天数据"""
                    if realtime_update and yh_last_date<latest_date_str:
                        print(' force update %s index' % symbol)
                        yh_index_df = yh_index_df.append(quotation_index_df, ignore_index=True)
                        #print(yh_index_df)
                    pass
                else:# yh_last_date>latest_date_str: #update to  latest date
                    """YH已经更新到今天,要更新盘中获取的当天数据"""
                    print(' %s index updated to %s; not need to update' % (index_name,latest_date_str))
                    """
                    if force_update:
                        print(' force update %s index' % index_name)
                        yh_index_df0 = yh_index_df.head(len(yh_index_df)-1)
                        print(yh_index_df0)
                        yh_index_df = yh_index_df0.append(quotation_index_df, ignore_index=True)
                        print(yh_index_df)
                    else:
                        pass
                    """
                yh_index_df = yh_index_df.set_index('date')
                """
                try:
                    os.remove(file_name)
                    print('Delete and update the csv file')
                except:
                    pass
                """
                yh_index_df.to_csv(dest_file_name ,encoding='utf-8')
            else:
                if force_update_from_YH and yh_last_date==dest_df_last_date:
                    yh_index_df = yh_index_df.set_index('date')
                    yh_index_df.to_csv(dest_file_name ,encoding='utf-8')
                pass
    else:
        print('No need to update data')
        if realtime_update:
            quotation_index_df = qq.get_qq_quotations([symbol], ['code','date','open','high','low','close','volume','amount'])
            quotation_index_df['factor'] = 1.0
            quotation_index_df = quotation_index_df[['date','open','high','low','close','volume','amount','factor']]
            #print(quotation_index_df)
            print(' force update %s index' % symbol)
            dest_df0 = dest_df
            if dest_df_last_date==latest_date_str:
                dest_df0 = dest_df.head(len(dest_df)-1)
            #print(dest_df0)
            dest_df = dest_df0.append(quotation_index_df, ignore_index=True)
            #print(dest_df)
            if quotation_index_df.empty:
                pass
            else:
                dest_df.to_csv(dest_file_name ,encoding='utf-8')
        else:
            pass
    return dest_df
예제 #5
0
def is_risk_to_exit0(symbols=['sh','cyb'],init_exit_data={},
                   yh_index_symbol_maps = {'sh':'999999','sz':'399001','zxb':'399005','cyb':'399006',
                         'sh50':'000016','sz300':'399007','zx300':'399008'},mail_count={},
                    demon_sql=None,mail2sql=None,mail_period=20,mailto_list=None,
                    stopped=[]):
    """风险监测和emai告警"""
    #index_exit_data=get_exit_price(['sh','cyb']
    exit_data = init_exit_data
    if not exit_data:
        exit_data = get_exit_price(symbols)
    else:
        pass
    if not mail_count:
        for symbol in symbols:
            mail_count[symbol] = 0
    else:
        pass
    symbol_quot = qq.get_qq_quotations(codes=symbols)
    #overlap_symbol = list(set(list(exit_data.keys())) & set(list(symbol_quot.keys())))
    if not exit_data or not symbol_quot:
        return {}
    risk_data = {}
    symbols = list(set(symbols).difference(set(stopped)))
    for symbol in symbols:
        this_risk = {}
        exit_p = 100000.0
        symbol_now_p = symbol_quot[symbol]['now']
        symbol_now_v = symbol_quot[symbol]['volume']
        if symbol_now_v>=0:  #update stop stocks
            pass
        else:
            if symbol not in stopped:
                stopped.append(symbol)
            else:
                pass
        if symbol=='002766' and demon_sql: #for test
            symbol_now_p = demon_sql.get_demon_value()
        code = symbol
        if code in list(yh_index_symbol_maps.keys()):
            code = yh_index_symbol_maps[symbol]
        index_exit_half = exit_data[code]['exit_half']
        index_exit_all = exit_data[code]['exit_all']
        #index_exit_all = 52.52
        #index_exit_all = 3098.89
        index_exit_rate = exit_data[code]['exit_rate']
        risk_state = 0
        
        if index_exit_all==0:
            last_close = symbol_quot[symbol]['close']
            index_exit_all = (1+2*index_exit_rate) * last_close
            index_exit_half = (1+index_exit_rate) * last_close
        else:
            pass
        #print('symbol=',symbol)
        #print('symbol_now_p=',symbol_now_p)
        #print('index_exit_all',index_exit_all)
        if symbol_now_p<index_exit_all:
            risk_state = 1.0
            exit_p = index_exit_all
        elif symbol_now_p<index_exit_half:
            risk_state = 0.5
            exit_p = index_exit_half
        else:
            pass
        if risk_state>0:
            if  mail_count[symbol]>=0: #email to exit
                mail_count[symbol] = mail_count[symbol] + 1
                this_risk['risk_code'] = symbol
                this_risk['risk_now'] = symbol_now_p
                this_risk['risk_state'] = risk_state
                this_risk['risk_time'] = datetime.datetime.now()
                send_exit_mail(exit_code=symbol,exit_state=risk_state,exit_data=exit_data[code],
                               exit_time=datetime.datetime.now(),mail_to_list=mailto_list,count=mail_count[symbol],
                               to_sql=mail2sql,period_count=mail_period)
                risk_data[symbol] = this_risk
            else:
                print('Have sent email before')
        elif risk_state==0:# not exit or recover
            if mail_count[symbol]==0:
                pass
            elif mail_count[symbol]>=1:
                if mail_count[symbol]==1:
                    send_exit_mail(exit_code=symbol,exit_state=risk_state,exit_data=exit_data[code],
                                   exit_time=datetime.datetime.now(),mail_to_list=mailto_list,count=mail_count[symbol],
                                   clear=1,to_sql=mail2sql,period_count=mail_period)
                    this_risk['risk_code'] = symbol
                    this_risk['risk_now'] = symbol_now_p
                    this_risk['risk_state'] = risk_state
                    this_risk['risk_time'] = datetime.datetime.now()
                    risk_data[symbol] = this_risk
                else:# still not descrease to 0
                    pass
                mail_count[symbol] = mail_count[symbol] - 1
            else:#不存在的情况
               pass 
        else:
            #不存在的情况
            pass
    if stopped:
        stopped=list(set(stopped))
    
    return risk_data,mail_count,stopped
예제 #6
0
def update_one_stock(symbol,realtime_update=False,dest_dir='C:/中国银河证券海王星/T0002/export/', force_update_from_YH=False):
    """
    运行之前先下载及导出YH历史数据
    """
    """
    :param symbol: string type, stock code
    :param realtime_update: bool type, True for K data force update during trade time 
    :param dest_dir: string type, like csv dir
    :param force_update_from_YH: bool type, force update K data from YH
    :return: Dataframe, history K data for stock
    """
    index_symbol_maps = {'sh':'999999','sz':'399001','zxb':'399005','cyb':'399006',
                     'sh50':'000016','sz300':'399007','zx300':'399008','hs300':'000300'}
    qq_index_symbol_maps = {'sh':'000001','sz':'399001','zxb':'399005','cyb':'399006',
                         'sh50':'000016','sz300':'399007','zx300':'399008','hs300':'000300'}
    FIX_FACTOR = 1.0
    d_format='%Y/%m/%d'
    last_date_str = tt.get_last_trade_date(date_format=d_format)
    latest_date_str = tt.get_latest_trade_date(date_format=d_format)
    #print('last_date_str=',last_date_str)
    #print('latest_date_str=',latest_date_str)
    next_date_str = tt.get_next_trade_date(date_format=d_format)
    #print(next_date_str)
    dest_file_name = dest_dir+ '%s.csv' % symbol
    dest_df = get_raw_hist_df(code_str=symbol)
    file_type='csv'
    RAW_HIST_DIR = "C:/中国银河证券海王星/T0002/export/"
    yh_file_name = RAW_HIST_DIR+symbol+'.'+file_type
    if symbol in index_symbol_maps.keys():
        symbol = index_symbol_maps[symbol]
        dest_file_name = dest_dir+ '%s.csv' % symbol
    #print('dest_file_name=',dest_file_name)
    if dest_df.empty:
        if symbol in index_symbol_maps.keys():
            symbol = index_symbol_maps[symbol]
        yh_file_name = RAW_HIST_DIR+symbol+'.'+file_type
        #yh_index_df = get_yh_raw_hist_df(code_str=symbol)
        yh_index_df = pd.read_csv(yh_file_name)
        #yh_index_df['factor'] = 1.0
        yh_df = yh_index_df.set_index('date')
        yh_df.to_csv(dest_file_name ,encoding='utf-8')
        dest_df = yh_index_df
        #del dest_df['rmb']
        return yh_df
    #print(dest_df)
    dest_df_last_date = dest_df.tail(1).iloc[0]['date']
    #print('dest_df_last_date=',dest_df_last_date)
    quotation_datetime = datetime.datetime.now()
    if dest_df_last_date<latest_date_str:     
        quotation_date = ''
        try:
            quotation_index_df = qq.get_qq_quotations_df([symbol], ['code','date','open','high','low','close','volume','amount'])
            quotation_date = quotation_index_df.iloc[0]['date']
            #quotation_date = quotation_index_df.iloc[0]['date']
            #quotation_datetime = quotation_index_df.iloc[0]['datetime']
            #del quotation_index_df['datetime']
            if dest_df_last_date==quotation_date:
                return dest_df
            #quotation_index_df = ts.get_index()
        except:
            time.sleep(3)
            quotation_index_df = qq.get_qq_quotations_df([symbol], ['code','date','open','high','low','close','volume','amount'])
            print(quotation_index_df)
            quotation_date = quotation_index_df.iloc[0]['date']
            #quotation_datetime = quotation_index_df.iloc[0]['datetime']
            #del quotation_index_df['datetime']
            if dest_df_last_date==quotation_date:
                return dest_df
        #print('quotation_date=',quotation_date)
        #print(quotation_index_df)
        #quotation_index_df['factor'] = 1.0
        quotation_index_df = quotation_index_df[['date','open','high','low','close','volume','amount']]#,'factor']]
        #quotation_index_df.iloc[0]['volume'] = 0
        #quotation_index_df.iloc[0]['amount'] = 0
        #print(quotation_index_df)
        #print(quotation_index_df)
        need_to_send_mail = []
        sub = ''
        index_name = symbol
        #table_update_times = self.get_table_update_time()
        
        if quotation_date:
            yh_symbol = symbol
            if symbol in index_symbol_maps.keys():
                yh_symbol = index_symbol_maps[index_name]
            yh_file_name = RAW_HIST_DIR+yh_symbol+'.'+file_type
            #yh_index_df = get_yh_raw_hist_df(code_str=symbol)
            yh_index_df = pd.read_csv(yh_file_name,encoding='GBK')
            #yh_index_df['factor'] = FIX_FACTOR
            yh_last_date = yh_index_df.tail(1).iloc[0]['date']
            #print('yh_last_date=',yh_last_date)
            #print( yh_index_df)#.head(len(yh_index_df)-1))
            
            if yh_last_date>dest_df_last_date:  #dest_df_last_date<latest_date_str
                #date_data = self.query_data(table=index_name,fields='date',condition="date>='%s'" % last_date_str)
                #data_len = len(date_data)
                #this_table_update_time = table_update_times[index_name]
                #print('this_table_update_time=', this_table_update_time)
                if yh_last_date<last_date_str: #no update more than two day
                    """需要手动下载银河客户端数据"""
                    print('Need to manual update %s index from YH APP! Please make suere you have sync up YH data' % index_name)
                    need_to_send_mail.append(index_name)
                    sub = '多于两天没有更新指数数据库'
                    content = '%s 数据表更新可能异常' % need_to_send_mail
                    sm.send_mail(sub,content,mail_to_list=None)
                elif yh_last_date==last_date_str: # update by last date
                    """只需要更新当天数据"""
                    realtime_update = tt.is_trade_time_now()
                    if realtime_update:
                        if yh_last_date<latest_date_str:
                            print(' force update %s index' % symbol)
                            yh_index_df = yh_index_df.append(quotation_index_df, ignore_index=True)
                        
                        #elif yh_last_date==latest_date_str:
                        #    print(' delete last update, then force update %s index' % symbol)
                        #    yh_index_df=yh_index_df[:-1]
                        #    yh_index_df = yh_index_df.append(quotation_index_df, ignore_index=True)
                        
                        else:
                            pass
                        #print(yh_index_df)
                    else:
                        pass
                else:# yh_last_date>latest_date_str: #update to  latest date
                    """YH已经更新到今天,要更新盘中获取的当天数据"""
                    print(' %s index updated to %s; not need to update' % (index_name,latest_date_str))
                    """
                    if force_update:
                        print(' force update %s index' % index_name)
                        yh_index_df0 = yh_index_df.head(len(yh_index_df)-1)
                        print(yh_index_df0)
                        yh_index_df = yh_index_df0.append(quotation_index_df, ignore_index=True)
                        print(yh_index_df)
                    else:
                        pass
                    """
                yh_index_df = yh_index_df.set_index('date')
                """
                try:
                    os.remove(file_name)
                    print('Delete and update the csv file')
                except:
                    pass
                """
                yh_index_df.to_csv(dest_file_name ,encoding='utf-8')
            else:
                if force_update_from_YH and yh_last_date==dest_df_last_date:
                    yh_index_df = yh_index_df.set_index('date')
                    yh_index_df.to_csv(dest_file_name ,encoding='utf-8')
                pass
    elif dest_df_last_date==latest_date_str:
        print('No need to update data')
        realtime_update = tt.is_trade_time_now()
        if realtime_update:
            quotation_index_df = qq.get_qq_quotations([symbol], ['code','date','open','high','low','close','volume','amount'])
            #quotation_index_df['factor'] = 1.0
            quotation_index_df = quotation_index_df[['date','open','high','low','close','volume','amount']]#'factor']]
            #print(quotation_index_df)
            print(' force update %s index' % symbol)
            dest_df0 = dest_df
            if dest_df_last_date==latest_date_str:
                dest_df0 = dest_df.head(len(dest_df)-1)
                #dest_df0 = dest_df0[:-1]
            #print(dest_df0)
            dest_df = dest_df0.append(quotation_index_df, ignore_index=True)
            #print(dest_df)
            if quotation_index_df.empty:
                pass
            else:
                yh_index_df = yh_index_df.set_index('date')
                dest_df.to_csv(dest_file_name ,encoding='utf-8')
        else:
            pass
    else:
        pass
    return dest_df