Example #1
0
def filterPowerCount(df, count=200, down=False, duration=2):

    nowint = cct.get_now_time_int()
    df.sort_values('percent', ascending=False, inplace=True)
    top_temp = df[:count].copy()

    if 915 < nowint <= 945:
        if nowint <= 935:
            top_temp = df[(df.buy > df.llastp) | (df.percent > df['per%sd' %
                                                                  (duration)])]
        else:
            top_temp = df[((df.open > df.llastp) & (df.low >= df.llastp)) |
                          (df.percent > df['per%sd' % (duration)])]
        if len(top_temp) > 0:
            return top_temp
        else:
            log.error("915 open>llastp is None")
            return df[:count].copy()

    if 930 < nowint <= 945:
        top_high = df[((df.open > df.llastp) & (df.low >= df.llastp))]
    elif 945 < nowint:
        if 'nlow' in df.columns:
            # top_high = df[ (df.nlow >= df.llastp) | (df.close >= df.nlow)]
            top_high = df[((df.nlow >= df.llastp) & (df.nlow >= df.low)) |
                          ((df.nlow <= df.low) & (df.open == df.nlow))]
        else:
            top_high = df[((df.open > df.llastp) & (df.low > df.llastp)) |
                          (df.percent > df['per%sd' % (duration)])]
    else:
        top_high = None

    if top_high is not None:
        top_high['upper'] = map(lambda x: round((1 + 11.0 / 100) * x, 1),
                                top_high.ma10d)
        top_high['lower'] = map(lambda x: round((1 - 9.0 / 100) * x, 1),
                                top_high.ma10d)
        top_high['ene'] = map(lambda x, y: round((x + y) / 2, 1),
                              top_high.upper, top_high.lower)
        if 930 < nowint < 1500:
            radio_t = cct.get_work_time_ratio()
        else:
            radio_t = 1

        top_high = top_high[(((top_high.buy > top_high.ene) &
                              (top_high.volume / radio_t > 2))) |
                            (((top_high.lastv1d > top_high.lvol * 1.5)) &
                             (top_high.lastp1d > top_high.ene))]
        if len(top_high) > count:
            top_high = top_high[(top_high.low > top_high.ene) |
                                ((top_high.percent > 1) &
                                 (top_high.volume > 2))]
        top_temp = cct.combine_dataFrame(top_temp,
                                         top_high,
                                         col=None,
                                         compare=None,
                                         append=True,
                                         clean=True)

    return top_temp
Example #2
0
def getconfigBigCount(count=None,write=False):

    conf_ini = cct.get_work_path('stock','JSONData','count.ini')
    fname = 'bigcount_logtime'
    logtime = cct.get_config_value_ramfile(fname)

    # print os.chdir(os.path.dirname(sys.argv[0]))
    # print (os.path.dirname(sys.argv[0]))
    # log.setLevel(LoggerFactory.INFO)
    if os.path.exists(conf_ini):
        log.info("file ok:%s"%conf_ini)
        config = ConfigObj(conf_ini,encoding='UTF8')
        if int(config['BigCount']['type2']) > 0:
            big_last= int(config['BigCount']['type2'])
            if logtime != 0:
                if (time.time() - float(cct.get_config_value_ramfile(fname)) > float(ct.bigcount_logtime)):
                    duratime = cct.get_config_value_ramfile(fname,currvalue=time.time(),xtype='time',update=True)
                    if count is None:
                        big_now = int(sina_json_Big_Count())
                    else:
                        big_now = int(count)
                else:
                    write = False
                    big_now = big_last
            else:
                duratime = cct.get_config_value_ramfile(fname,currvalue=time.time(),xtype='time',update=True)
                write = False
                big_now = big_last

            ratio_t=cct.get_work_time_ratio()
            bigRt=round( big_now / big_last / ratio_t, 1)
            big_v=int(bigRt*int(config['BigCount']['type2']))
            # print big_now,big_last,bigRt
            int_time=cct.get_now_time_int()
            # print int_time
            if write and (int_time < 915 or int_time > 1500 ) and big_now > 0 and big_last != big_now :
                # print write,not cct.get_work_time(),big_now > 0,big_last != big_now
                log.info("big_now update:%s last:%s"%(big_now,big_last))
                config['BigCount']['type2'] = big_now
                rt=float(config['BigCount']['ratio'])
                # if  rt != bigRt:
                log.info("bigRt:%s"%bigRt)
                config['BigCount']['ratio'] = bigRt
                config.write()
                return [big_now,bigRt,big_v]
            else:
                log.info("not work:%s ra:%s"%(big_now,bigRt))
                return [big_now,bigRt,big_v]
    else:
        config = ConfigObj(conf_ini,encoding='UTF8')
        config['BigCount'] = {}
        config['BigCount']['type2'] = sina_json_Big_Count()
        config['BigCount']['ratio'] = 0
        config.write()
    big_v= 0
    cl=[config['BigCount']['type2'],config['BigCount']['ratio'],0]
    return cl
Example #3
0
from JSONData import tdx_data_Day as tdd
from JSONData import sina_data
from JohnsonUtil import LoggerFactory as LoggerFactory
from JohnsonUtil import commonTips as cct

if __name__ == "__main__":
    # parsehtml(downloadpage(url_s))
    # StreamHandler(sys.stdout).push_application()
    log = LoggerFactory.getLogger('Autodata')
    # log.setLevel(LoggerFactory.DEBUG)
    # handler=StderrHandler(format_string='{record.channel}: {record.message) [{record.extra[cwd]}]')
    # log.level = log.debug
    # error_handler = SyslogHandler('Sina-M-Log', level='ERROR')

    try:
        if cct.get_work_day_status() and cct.get_now_time_int() < 1505:
            # tdx_data=tdd.get_tdx_all_day_DayL_DF(market='cyb', dayl=1)
            print sina_data.Sina().get_stock_code_data('300006')
            tdx_data = rl.get_sina_Market_json('cyb')
            if len(tdx_data) < 1:
                raise KeyboardInterrupt("StopTime")
            else:
                print tdx_data[-2:]
            code = '300366'

    except (KeyboardInterrupt) as e:
        pass
    except (IOError, EOFError, Exception) as e:
        print "Error", e
        #traceback.print_exc()
        sleeptime = random.randint(5, 15)
Example #4
0
                    # top_all = top_all[top_all.open > top_all.lasth1d]
                    # top_all = top_all[top_all.low > top_all.llow * ct.changeRatio]
                    # top_all = top_all[top_all.trade > top_all.lhigh * ct.changeRatio]

                    # if cct.get_now_time_int() > 915 and cct.get_now_time_int() <= 926:
                    #     top_all['percent'] = (map(lambda x, y: round(
                    #         (x - y) / y * 100, 1) if int(y) > 0 else 0, top_all.trade, top_all.llastp))

                    # top_all = top_all[top_all.prev_p >= top_all.lhigh]
                    # top_all = top_all.loc[:,
                    # ['name', 'percent', 'ma5d','dff', 'couts', 'volume', 'trade', 'prev_p', 'ratio']]
                    # if cct.get_now_time_int() > 1030 and cct.get_now_time_int() < 1400:
                    #     top_all = top_all[(top_all.volume > ct.VolumeMinR) & (
                    #         top_all.volume < ct.VolumeMaxR)]

                if st_key_sort.split()[0] in ['4','9'] and 915 < cct.get_now_time_int() < 930:
                # if  915 < cct.get_now_time_int() < 930:
                    top_all['dff'] = (list(map(lambda x, y: round((x - y) / y * 100, 1),
                                          top_all['buy'].values, top_all['llastp'].values)))
                    top_all['dff2'] = (list(map(lambda x, y: round((x - y) / y * 100, 1),
                                           top_all['buy'].values, top_all['lastp'].values)))
               
                elif st_key_sort.split()[0] in ['4','9'] and 926 < cct.get_now_time_int() < 1455 and 'lastbuy' in top_all.columns:
                # elif 926 < cct.get_now_time_int() < 1455 and 'lastbuy' in top_all.columns:

                    top_all['dff'] = (list(map(lambda x, y: round((x - y) / y * 100, 1),
                                          top_all['buy'].values, top_all['lastbuy'].values)))
                    top_all['dff2'] = (list(map(lambda x, y: round((x - y) / y * 100, 1),
                                           top_all['buy'].values, top_all['lastp'].values)))
                    # if len(top_all[top_all.lastbuy < 0]) > 0 or len(top_all[top_all.dff < -10]) >0 :
                    #     print top_all.loc['600313'].lastbuy,top_all.loc['600313'].buy,top_all.loc['600313'].lastp
Example #5
0
                            top_all['prev_p'] = 0
                    # for symbol in top_all.index:
                    #     if symbol in top_now.index:

                    #         if 'couts' in top_now.columns.values:
                    #             top_all.loc[symbol, ct.columns_now] = top_now.loc[symbol, ct.columns_now]
                    #         else:
                    #             # top_now.loc[symbol, 'dff'] = round(
                    #             # ((float(top_now.loc[symbol, 'buy']) - float(
                    #             # top_all.loc[symbol, 'lastp'])) / float(top_all.loc[symbol, 'lastp']) * 100),
                    #             # 1)
                    #             top_all.loc[symbol, ct.columns_now] = top_now.loc[symbol, ct.columns_now]
                    top_all = cct.combine_dataFrame(top_all, top_now, col=None)

                # top_dif = top_all.copy()
                if cct.get_now_time_int() > 830 and cct.get_now_time_int(
                ) <= 926:
                    top_dif = top_all[(top_all.topR > 0)
                                      & (top_all.close > top_all.lastp1d)]
                else:
                    top_dif = top_all[(top_all.topR > 0)
                                      & (top_all.low > top_all.lastp1d)]
                    top_dif = top_dif[(top_dif.low >= top_dif.ene)
                                      & (top_dif.low >= top_dif.ma5d)]

                market_sort_value, market_sort_value_key = ct.get_market_sort_value_key(
                    st_key_sort, top_all=top_all)

                log.debug('top_dif:%s' % (len(top_dif)))
                if 'trade' in top_dif.columns:
                    top_dif['buy'] = (list(
Example #6
0
                    log.debug("len:%s" % (len(top_all)))
                    top_list = tdd.compute_jump_du_count(top_all,
                                                         resample=resample)

                elif len(top_all) == 0 and len(lastpTDX_DF) > 0:
                    top_all = top_now
                    top_all = top_all.merge(lastpTDX_DF,
                                            left_index=True,
                                            right_index=True,
                                            how='left')
                    log.info('Top-merge_now:%s' % (top_all[:1]))
                    top_all = top_all[top_all['llow'] > 0]

                else:
                    log.info("start symbol code :%0.2f" %
                             (cct.get_now_time_int()))
                    log.info("diff co:%s" %
                             (set(top_all.columns) - set(top_now.columns)))
                    if 'couts' in top_now.columns.values:
                        if not 'couts' in top_all.columns.values:
                            top_all['couts'] = 0
                            top_all['prev_p'] = 0
                    # for symbol in top_now.index:
                    #     if 'couts' in top_now.columns.values:
                    #         top_all.loc[symbol, ct.columns_now] = top_now.loc[symbol, ct.columns_now]
                    #     else:
                    #         top_all.loc[symbol, ct.columns_now] = top_now.loc[symbol, ct.columns_now]

                    # no_index = top_all.drop([inx for inx in top_all.index  if inx not in top_now.index], axis=0)
                    # no_index.drop([col for col in no_index.columns if col in top_now.columns], axis=1,inplace=True)
                    # no_index = no_index.merge(top_now, left_index=True, right_index=True, how='left')
Example #7
0
                    # top_all = top_all[top_all.trade > top_all.lhigh * ct.changeRatio]

                    # if cct.get_now_time_int() > 915 and cct.get_now_time_int() <= 926:
                    #     top_all['percent'] = (map(lambda x, y: round(
                    #         (x - y) / y * 100, 1) if int(y) > 0 else 0, top_all.trade, top_all.llastp))

                    # top_all = top_all[top_all.prev_p >= top_all.lhigh]
                    # top_all = top_all.loc[:,
                    # ['name', 'percent', 'ma5d','dff', 'couts', 'volume', 'trade', 'prev_p', 'ratio']]
                    # if cct.get_now_time_int() > 1030 and cct.get_now_time_int() < 1400:
                    #     top_all = top_all[(top_all.volume > ct.VolumeMinR) & (
                    #         top_all.volume < ct.VolumeMaxR)]

                if st_key_sort.split()[0] in [
                        '4', '9'
                ] and 915 < cct.get_now_time_int() < 930:
                    # if  915 < cct.get_now_time_int() < 930:
                    top_all['dff'] = (map(
                        lambda x, y: round((x - y) / y * 100, 1),
                        top_all['buy'].values, top_all['llastp'].values))
                    top_all['dff2'] = (map(
                        lambda x, y: round((x - y) / y * 100, 1),
                        top_all['buy'].values, top_all['lastp'].values))

                elif st_key_sort.split()[0] in [
                        '4', '9'
                ] and 926 < cct.get_now_time_int(
                ) < 1455 and 'lastbuy' in top_all.columns:
                    # elif 926 < cct.get_now_time_int() < 1455 and 'lastbuy' in top_all.columns:

                    top_all['dff'] = (map(
Example #8
0
    def format_response_data(self, index=False):
        stocks_detail = ''.join(self.stock_data)
        # print stocks_detail
        result = self.grep_stock_detail.finditer(stocks_detail)
        # stock_dict = dict()
        list_s = []
        for stock_match_object in result:
            stock = stock_match_object.groups()
            # print stock
            # print stock
            # fn=(lambda x:x)
            # list.append(map(fn,stock))
            # df = pd.DataFrame(list,columns=ct.SINA_Total_Columns)
            #     list_s.append({'code'})
            list_s.append({
                'code': stock[0],
                'name': stock[1],
                'open': float(stock[2]),
                'close': float(stock[3]),
                'now': float(stock[4]),
                'high': float(stock[5]),
                'low': float(stock[6]),
                'buy': float(stock[7]),
                'sell': float(stock[8]),
                'volume': int(stock[9]),
                'turnover': float(stock[10]),
                # 'amount': float(stock[10]),
                'b1_v': int(stock[11]),
                'b1': float(stock[12]),
                'b2_v': int(stock[13]),
                'b2': float(stock[14]),
                'b3_v': int(stock[15]),
                'b3': float(stock[16]),
                'b4_v': int(stock[17]),
                'b4': float(stock[18]),
                'b5_v': int(stock[19]),
                'b5': float(stock[20]),
                'a1_v': int(stock[21]),
                'a1': float(stock[22]),
                'a2_v': int(stock[23]),
                'a2': float(stock[24]),
                'a3_v': int(stock[25]),
                'a3': float(stock[26]),
                'a4_v': int(stock[27]),
                'a4': float(stock[28]),
                'a5_v': int(stock[29]),
                'a5': float(stock[30]),
                'dt': (stock[31]),
                'ticktime': (stock[32])
            })


#        print list_s
# df = pd.DataFrame.from_dict(stock_dict,columns=ct.SINA_Total_Columns)
        df = pd.DataFrame(list_s, columns=ct.SINA_Total_Columns)
        # if self.index_status and cct.get_work_time():
        # if self.index_status:
        # if cct.get_work_time() or (cct.get_now_time_int() > 915) :
        # df = df.drop('close', axis=1)
        df.rename(columns={'close': 'llastp'}, inplace=True)
        df['b1_vv'] = df['b1_v']
        if (cct.get_now_time_int() > 915 and cct.get_now_time_int() < 926):
            #            df.rename(columns={'buy': 'close'}, inplace=True)
            df['close'] = df['buy']
            df['low'] = df['buy']
            df['volume'] = ((df['b1_v'] + df['b2_v'])).map(lambda x: x)
            # df['b1_v'] = ((df['b1_v'] + df['b2_v']) / 100 / 10000).map(lambda x: round(x, 1) + 0.01)
            # df['b1_v'] = ((df['b1_v']) / 100 / 10000).map(lambda x: round(x, 1) + 0.01)
            # df['b1_vv'] = map(lambda x: round(x / 100 / 10000, 1) + 0.01, df['b1_v'])

        elif (cct.get_now_time_int() > 830 and cct.get_now_time_int() <= 915):
            #            df.rename(columns={'buy': 'close'}, inplace=True)
            df['buy'] = df['llastp']
            df['close'] = df['buy']
            df['low'] = df['buy']
            # df['b1_v'] = ((df['b1_v']) / df['volume'] * 100).map(lambda x: round(x, 1))

        else:
            # df['b1_v'] = ((df['b1_v']) / df['volume'] * 100).map(lambda x: round(x, 1))
            # df.rename(columns={'now': 'close'}, inplace=True)
            df['close'] = df['now']

        df['nvol'] = df['volume']
        df = df.drop_duplicates('code')
        # df = df.loc[:, ct.SINA_Total_Columns_Clean]
        # df = df.loc[:, ct.SINA_Total_Columns]
        # df.rename(columns={'turnover': 'amount'}, inplace=True)
        df = df.fillna(0)
        #        df = df.sort_values(by='code', ascending=0)
        df = df.set_index('code')
        if index:
            df.index = map(
                (lambda x: str(1000000 - int(x)) if x.startswith('0') else x),
                df.index)
        # print ("Market-df:%s %s time: %s" % (
        # cct.get_now_time()))
        log.info("hdf:all%s %s" % (len(df), len(self.stock_codes)))
        dd = df.copy()
        h5_fname = 'sina_MultiIndex_data'
        h5_table = 'all' + '_' + str(ct.sina_limit_time)
        if cct.get_now_time_int() >= 925 and not index and len(
                df) > 3000 and cct.get_work_time():
            time_s = time.time()
            df.index = df.index.astype(str)
            df.ticktime = df.ticktime.astype(str)
            # df.ticktime = map(lambda x: int(x.replace(':', '')), df.ticktime)
            df.ticktime = map(lambda x, y: str(x) + ' ' + str(y), df.dt,
                              df.ticktime)
            df.ticktime = pd.to_datetime(df.ticktime,
                                         format='%Y-%m-%d %H:%M:%S')
            # df = df.loc[:, ['open', 'high', 'low', 'close', 'llastp', 'volume', 'ticktime']]
            df = df.loc[:, [
                'close', 'high', 'low', 'llastp', 'volume', 'ticktime'
            ]]
            if 'code' not in df.columns:
                df = df.reset_index()
            if 'dt' in df.columns:
                df = df.drop(['dt'], axis=1)
                # df.dt = df.dt.astype(str)
            if 'name' in df.columns:
                # df.name = df.name.astype(str)
                df = df.drop(['name'], axis=1)
            df = df.set_index(['code', 'ticktime'])
            h5a.write_hdf_db(h5_fname,
                             df,
                             table=h5_table,
                             index=False,
                             baseCount=500,
                             append=False,
                             MultiIndex=True)
            log.info("hdf5 class all :%s  time:%0.2f" %
                     (len(df), time.time() - time_s))

        if 'nlow' not in df.columns or 'nhigh' not in df.columns or (
                cct.get_work_time() and 925 < cct.get_now_time_int() < 1500):
            # if 'nlow' not in df.columns or 'nhigh' not in df.columns or cct.get_work_time():
            h5 = h5a.load_hdf_db(h5_fname, h5_table, timelimit=False)

            time_s = time.time()
            if cct.get_work_time() and cct.get_now_time_int() <= 1000:
                run_col = ['low', 'high', 'close']
                startime = '09:25:00'
                # endtime = '10:00:00'
                endtime = '09:45:00'
                dd = self.get_col_agg_df(h5, dd, run_col, all_func, startime,
                                         endtime)
                startime = '09:25:00'
                # endtime = '10:00:00'
                endtime = '10:00:00'
                run_col = {'close': 'std'}
                dd = self.get_col_agg_df(h5, dd, run_col, run_col, startime,
                                         endtime)
                dd.rename(columns={'std': 'nstd'}, inplace=True)
                if dd is not None and len(
                        dd
                ) > 0 and 'nclose' in dd.columns and 'nstd' in dd.columns:
                    for co in ['nclose', 'nstd']:
                        dd[co] = dd[co].apply(lambda x: round(x, 2))

            else:
                run_col = ['low', 'high']
                startime = '09:25:00'
                # endtime = '10:00:00'
                endtime = '09:40:00'
                dd = self.get_col_agg_df(h5, dd, run_col, all_func, startime,
                                         endtime)
                startime = '09:25:00'
                endtime = '15:01:00'
                run_col = ['close']
                # h5 = cct.get_limit_multiIndex_Group(h5, freq='15T', col=run_col,start=startime, end=endtime)
                dd = self.get_col_agg_df(h5, dd, run_col, all_func, startime,
                                         endtime)

                run_col = {'close': 'std'}
                dd = self.get_col_agg_df(h5, dd, run_col, run_col, startime,
                                         endtime)
                dd.rename(columns={'std': 'nstd'}, inplace=True)
                if dd is not None and len(
                        dd
                ) > 0 and 'nclose' in dd.columns and 'nstd' in dd.columns:
                    for co in ['nclose', 'nstd']:
                        dd[co] = dd[co].apply(lambda x: round(x, 2))
            log.info("agg_df_all_time:%0.2f" % (time.time() - time_s))
            # top_temp[:1][['high','nhigh','low','nlow','close','nclose','llastp']]

        h5a.write_hdf_db(self.hdf_name, dd, self.table, index=index)
        log.info("wr end:%0.2f" % (time.time() - self.start_t))
        return dd
Example #9
0
                                           clean=True)
                log.info('agg_df_Row:%.2f h5:%s endtime:%s' %
                         ((time.time() - time_n), len(h5), endtime))
        return dd

    h5_fname = 'sina_MultiIndex_data'
    # h5_fname = 'sina_multi_index'
    h5_table = 'all_10'
    time_s = time.time()
    h5 = h5a.load_hdf_db(h5_fname,
                         table=h5_table,
                         code_l=None,
                         timelimit=False,
                         dratio_limit=0.12)
    print 'h5:', len(h5)
    if cct.get_work_time() and cct.get_now_time_int() <= 1000:
        run_col = ['low', 'high', 'close']
        startime = None
        # endtime = '10:00:00'
        endtime = '09:45:00'
        dd = get_col_agg_df_Test(h5, dd, run_col, all_func, startime, endtime)
    else:
        run_col = ['low', 'high']
        startime = None
        # endtime = '10:00:00'
        endtime = '09:45:00'
        dd = get_col_agg_df_Test(h5, dd, run_col, all_func, startime, endtime)

        startime = '09:30:00'
        endtime = '15:01:00'
        # run_col = ['close']
Example #10
0
def getBollFilter(df=None,
                  boll=ct.bollFilter,
                  duration=ct.PowerCountdl,
                  filter=True,
                  ma5d=True,
                  dl=14,
                  percent=True,
                  resample='d',
                  ene=False,
                  upper=False,
                  down=False,
                  indexdff=True,
                  cuminTrend=False,
                  top10=True):

    # drop_cxg = cct.GlobalValues().getkey('dropcxg')
    # if len(drop_cxg) >0:
    # log.info("stf drop_cxg:%s"%(len(drop_cxg)))
    # drop_cxg = list(set(drop_cxg))
    # drop_t = [ co for co in drop_cxg if co in df.index]
    # if len(drop_t) > 0:
    # df = df.drop(drop_t,axis=0)top
    # log.error("stf drop_cxg:%s"%(len(drop_t)))

    # hvdu max量天数  lvdu  min天数  hv max量  lv 量
    # fib < 2 (max) fibl > 2   lvdu > 3  (hvdu > ? or volume < 5)? ene
    time_s = time.time()
    # df['upper'] = map(lambda x: round((1 + 11.0 / 100) * x, 1), df.ma10d)
    # df['lower'] = map(lambda x: round((1 - 9.0 / 100) * x, 1), df.ma10d)
    # df['ene'] = map(lambda x, y: round((x + y) / 2, 1), df.upper, df.lower)
    '''
    df = df[(df.close > df.ma20d) | (df.close > df.ene)]
    if filter:
        if 'boll' in df.columns:
            df = df[(df.boll >= boll) | (df.buy > df.upper)]
    '''

    # if 'nlow' in df.columns:
    # df = df[ ((df.nlow >= df.llastp) & (df.nlow >= df.low)) | ((df.nlow <= df.low) & (df.open == df.nlow))]
    # if cct.get_work_time() and 'df2' in df.columns:
    #     if 915 < cct.get_now_time_int() < 930:
    #         df['cumnow'] =  map(lambda x, y: 1 if x - y > 0 else 0, df.close, df.cumaxe)
    #     else:
    #         df['cumnow'] =  map(lambda x, y: 1 if x - y > 0 else 0, df.high, df.cumaxe)
    #     df['df2'] = (df['df2'] + df['cumnow']).map(lambda x: int(x))
    # df = df[df.df2 > 1]
    # else:
    # df = df[df.df2 > 0]
    radio_t = cct.get_work_time_ratio()
    df['lvolr%s' % (resample)] = df['volume']
    # df['volume'] = (map(lambda x, y: round(x / y / radio_t, 1), df.nvol.values, df.lvolume.values))
    if cct.get_now_time_int() > 1530:
        df['volume'] = (map(
            lambda x, y, z: round((x / y / radio_t)
                                  if z < 9.9 else (x / y), 1), df.nvol.values,
            df.ma5vol.values, df.percent.values))
    else:
        df['volume'] = (map(
            lambda x, y, z: round((x / y / radio_t)
                                  if z < 9.9 else (x / y), 1), df.nvol.values,
            df.lvol.values, df.percent.values))
    # df['volume'] = (map(lambda x, y,z: round((x / y / radio_t) if z < 9.9 else (x / y) , 1), df.nvol.values, df.ma5vol.values,df.percent.values))
    # df['volume'] = (map(lambda x, y: round(x / y / radio_t, 1), df.nvol.values, df.lastv1d.values))

    indexfibl = cct.GlobalValues().getkey('indexfibl')
    sort_value = cct.GlobalValues().getkey('market_sort_value')
    market_key = cct.GlobalValues().getkey('market_key')
    market_value = cct.GlobalValues().getkey('market_value')

    # if int(market_value) > 1 and 930 < cct.get_now_time_int():

    df = compute_perd_value(df, market_value, 'perc')
    df = compute_perd_value(df, market_value, 'per')

    if sort_value <> 'percent' and (market_key in ['2', '3']
                                    and market_value not in ['1']):
        # print("sort_value:%s,market_key:%s ,market_value:%s" %
        #       (sort_value, market_key, market_value))
        if market_key is not None and market_value is not None:
            # if market_key == '3':

            if market_key == '3':
                market_value = int(market_value)
                log.info("stf market_key:%s" % (market_key))
                idx_k = cct.get_col_in_columns(df, 'perc%sd', market_value)
                # filter percd > idx
                # df= df[(df[("perc%sd" % (idx_k))] >= idx_k) | (df[("perc%sd" % (idx_k))]< -idx_k)]

                # if int(market_value) > 1 and 930 < cct.get_now_time_int():
                #     df= compute_perd_value(df, market_value, 'perc')
                #     df= compute_perd_value(df, market_value, 'per')

            # elif market_key == '2':
            #     if int(market_value) > 1 and 915 < cct.get_now_time_int():
            #         # df['per%d'%(market_value)] = compute_perd_value(df,market_value)
            #         df= compute_perd_value(df, market_value,'per')
            #         df= compute_perd_value(df, market_value, 'perc')

    # if sort_value <> 'percent' and (market_key in ['2','3'] and market_value not in ['1'] ):
    #     if indexfibl is not None:
    #         df = df[df.fibl >= (indexfibl - 1)]
    #     else:
    #         indexfibl = 1
    #     if cuminTrend:
    #         cuminfibl = cct.GlobalValues().getkey('cuminfibl')
    #         if cuminfibl is None:
    #             cuminfibl = cct.get_index_fibl()
    # if cuminfibl > 1:
    #     df = df[df.df2 >= cuminfibl]

    #    print df.loc['300107'][['close','cumine','llastp','cumaxe','cumaxc']]
    #     df = df[ (df.cumine == df.cumaxc) | (df.close >= df.cumine) | (df.llastp >=df.cumaxc) | (df.close >= df.cumaxe) ]
    # else:
    #     upper = True

    if not down:
        if upper:
            # upper_count = len( df[ ( ( df.buy > df.upper)| ( df.lastp0d > df.upper) | ( df.lastp1d > df.upper) | ( df.lastp2d > df.upper) | ( df.lastp3d > df.upper))])
            # # ene_count = len(df[df.buy > df.upper])
            # if upper_count > 30:
            #     df = df[ (  ( df.buy > df.upper)| ( df.lastp0d > df.upper) | ( df.lastp1d > df.upper) | ( df.lastp2d > df.upper) | ( df.lastp3d > df.upper))]
            # else:
            #     df = df[ ( (( df.buy > df.ene ) ) | ( df.buy > df.upper)| ( df.lasth0d > df.upper) | ( df.lasth1d > df.upper) | ( df.lasth2d > df.upper) | ( df.lasth3d > df.upper))]
            df = df[(df.low >= df.upper) | (df.close >= df.upper) |
                    (df.per1d >= 9.5) | (df.lastp1d == df.hmax) |
                    ((df.lastp1d <> df.hmax) & (df.high > df.hmax))]
        else:
            if 935 < cct.get_now_time_int() < 1400:
                df = df[((df.buy > df.ene) | (df.llastp > df.ene) |
                         (df.llastp >= df.max5) | (df.high >= df.max5) |
                         (df.max5 >= df.upper))]
            else:
                df = df[((df.buy > df.ene) | (df.llastp > df.ene) |
                         (df.llastp >= df.max5) | (df.high >= df.max5) |
                         (df.max5 >= df.upper))]

    # df['cumins'] = round(cum_counts.index[0], 2)
    # df['cumine'] = round(cumdf[-1], 2)
    # df['cumax']
    # df.rename(columns={'cumin': 'df2'}, inplace=True)
    if df is None:
        print "dataframe is None"
        return None
    else:
        # top10 = df[ (df.percent >= 9.99) & (df.b1_v > df.a1_v)]

        if resample in ['d', 'w']:
            # if not top10 or (cct.get_now_time_int() < 950 or cct.get_now_time_int() > 1502):
            #     df.loc[((df.b1_v > df.a1_v) & (df.percent > 9)), 'percent'] = 10.1
            #     df.loc[((df.percent >= 9.97) & (df.percent < 10.1)), 'percent'] = 10

            # else:
            #     df.loc[((df.b1_v > df.a1_v) & (df.percent > 9)), 'percent'] = 10.1
            #     df.loc[((df.percent >= 9.97) & (df.percent < 10.1)), 'percent'] = 10

            # df.loc[df.per1d >= 9.99, 'per1d'] = 10
            df['percent'] = df['percent'].apply(lambda x: round(x, 2))
            # time_ss = time.time()
            perc_col = [co for co in df.columns if co.find('perc') == 0]
            per_col = [co for co in df.columns if co.find('per') == 0]
            # per_col = list(set(per_col) - set(perc_col) - set(['per1d', 'perlastp']))
            per_col = list(
                set(per_col) - set(perc_col) - set(['per1d', 'perlastp']))

            perc_col.remove('percent')

            for co in perc_col:
                df[co] = df[co].apply(lambda x: round(x, 2))

            # da, down_zero, down_dn, percent_l = 1, 0, 0, 2
            # da, down_zero, down_dn, percent_l = 1, 0, -1, 1
            # df['perc_n'] = map((lambda h, lh, l, ll, c, lc: (1 if (h - lh) > 0 else down_dn) + (1 if c - lc > 0 else down_dn) + (1 if (l - ll) > 0 else down_dn) + (2 if (c - lh) > 0 else down_zero) + (2 if (l - lc) > 0 else down_zero) + (0 if (h - lc) > 0 else down_dn)), df['high'], df['lasth%sd' % da], df['low'], df['lastl%sd' % da], df['close'],df['lastp%sd' % da])
            # df['perc_n'] = map((lambda c, lc: (1 if (c - lc) > 0 else down_zero) + (1 if (c - lc) / lc * 100 > 3 else down_zero) +
            # (down_dn if (c - lc) / lc * 100 < -3 else down_zero)), df['close'], df['lastp%sd' % da])

            # idx_rnd = random.randint(0, len(df) - 10) if len(df) > 10 else 0

            # print "idx_rnd",idx_rnd,df.ix[idx_rnd].lastp0d ,df.ix[idx_rnd].close,df.ix[idx_rnd].lastp0d != df.ix[idx_rnd].close

            # if not upper:
            #     if cct.get_work_time() or df.ix[idx_rnd].lastp0d <> df.ix[idx_rnd].close:
            #         nowd, per1d = 0, 1
            #         if 'nlow' in df.columns:
            #             df['perc_n'] = map(cct.func_compute_percd2, df['close'], df['llastp'], df['open'],df['lasto%sd' % nowd], df['lasth%sd' %
            #                                                                                                   (nowd)], df['lastl%sd' % (nowd)], df['nhigh'], df['nlow'],df['nvol']/radio_t,df['lastv%sd'%(nowd)], df['hmax'],df['df2'])
            #         else:
            #             df['perc_n'] = map(cct.func_compute_percd2, df['close'], df['llastp'], df['open'],df['lasto%sd' % nowd], df['lasth%sd' %
            #                                                                                                   (nowd)], df['lastl%sd' % (nowd)], df['high'], df['low'],df['nvol']/radio_t,df['lastv%sd'%(nowd)], df['hmax'],df['df2'])
            #     else:
            #         nowd, per1d = 1, 2
            #         # print  df['per%sd' % da+1], df['lastp%sd' % (da)], df['lasth%sd' % (da)], df['lastl%sd' % (da)], df['high'], df['low']
            #         df['perc_n'] = map(cct.func_compute_percd2, df['close'], df['llastp'], df['open'],df['lasto%sd' % nowd], df['lasth%sd' %
            #                                                                                               (nowd)], df['lastl%sd' % (nowd)], df['high'], df['low'], df['hmax'])
            '''
            idx_rnd = random.randint(0, len(df) - 10) if len(df) > 10 else 0
            if not upper:
               # if cct.get_work_time() or df.ix[idx_rnd].lastp1d <> df.ix[idx_rnd].close:
               if cct.get_work_time() :
                   nowd, per1d=1, 1
                   if 'nlow' in df.columns:
                       df['perc_n']=map(cct.func_compute_percd2020, df['open'], df['close'], df['nhigh'], df['nlow'], df['lasto%sd' % nowd], df['llastp'],
                                         df['lasth%sd' % (nowd)], df['lastl%sd' % (nowd)], df['ma5d'], df['ma10d'], df['nvol'] / radio_t, df['lastv%sd' % (nowd)])
                   else:
                       df['perc_n']=map(cct.func_compute_percd2020, df['open'], df['close'], df['high'], df['low'], df['lasto%sd' % nowd], df['llastp'],
                                         df['lasth%sd' % (nowd)], df['lastl%sd' % (nowd)], df['ma5d'], df['ma10d'], df['nvol'] / radio_t, df['lastv%sd' % (nowd)])
               else:
                   nowd, per1d=1, 1
                   # print  df['per%sd' % da+1], df['lastp%sd' % (da)], df['lasth%sd' % (da)], df['lastl%sd' % (da)], df['high'], df['low']
                   df['perc_n']=map(cct.func_compute_percd2020, df['open'], df['close'], df['high'], df['low'], df['lasto%sd' % nowd], df['llastp'],
                                         df['lasth%sd' % (nowd)], df['lastl%sd' % (nowd)], df['ma5d'], df['ma10d'], df['nvol'] / radio_t, df['lastv%sd' % (nowd)])

            for co in perc_col:
                df[co] = (df[co] + df['perc_n']).map(lambda x: int(x))
            '''

            # for co in per_col:
            # df[co] = (df[co] + df['percent']).map(lambda x: int(x))

            # print "percT:%.2f"%(time.time()-time_ss)
        else:
            df['percent'] = (map(
                lambda x, y: round((x - y) / y * 100, 1)
                if int(y) > 0 else 0, df.buy, df.lastp1d))
            # df.loc['002204'].percent
            # -15.4
            # ipdb> df.loc['002204'].ma10d
            # 3.2000000000000002
            # ipdb> df.loc['002204'].ma5d
            # 3.2999999999999998
    if 'fib' not in df.columns:
        df['fib'] = 0
    # else:

    co2int = ['boll', 'op', 'ratio', 'fib', 'fibl', 'df2']
    # co2int.extend([co for co in df.columns.tolist()
    #                if co.startswith('perc') and co.endswith('d')])
    co2int.extend(['top10', 'topR'])
    co2int = [inx for inx in co2int if inx in df.columns]

    for co in co2int:
        df[co] = df[co].astype(int)

    # if down:
    #     # if 'nlow' in df.columns:
    #     #     if 'max5' in df.columns:
    #     #         # df = df[(df.hmax >= df.ene) & (df.nlow >= df.low) & (df.low <> df.high) & (((df.low < df.hmax) & (df.high > df.cmean)) | (df.high > df.max5))]
    #     #         df = df[ (((df.buy > df.ene) & (df.volume / radio_t > 1.5)) ) |  (((df.lastv1d > df.lvol * 1.5) & (df.lastv1d > df.lvol * 1.5)) & (df.lastp1d > df.ene) )]
    #     #     else:
    #     #         df = df[ (((df.buy > df.ene) & (df.volume / radio_t > 1.5)) ) |  (((df.lastv1d > df.lvol * 1.5) )  )]
    #     # else:
    #     #     # df = df[ (df.max5 >= df.ene) & (df.low <> df.high) & (((df.low < df.hmax) & (df.close > df.cmean)) | (df.high > df.cmean))]
    #     #     df = df[ (((df.buy > df.ene) & (df.volume / radio_t > 1.5)) )  | (((df.lastp1d > df.ene) ) | ((df.buy > df.max5)|(df.buy > df.ene)) | (df.max5 >= df.ene)  | (df.high > df.cmean) )]
    #     return df

    if cct.get_work_time() and 'b1_v' in df.columns and 'nvol' in df.columns:
        df = df[(df.b1_v > 0) | (df.nvol > 0)]

    if (cct.get_now_time_int() > 915 and cct.get_now_time_int() < 926):
        df['b1_v'] = df['volume']
    else:
        dd = df[df.percent < 10]
        dd['b1_v'] = dd['volume']
        df = cct.combine_dataFrame(df, dd.loc[:, ['b1_v']])
        # print "t:%0.2f"%(time.time()-time_ss)

        # if int(market_value) < 3 and 930 < cct.get_now_time_int():
        #     if 'nlow' in df.columns:
        #         # df = df[((df.per1d < 3) & (df.nlow >= df.llastp)) | ((df.per1d > 5) & (df.buy > df.llastp))]
        #         df = df[((df.per1d < 3) & (df.nlow >= df.llastp)) | ((df.per1d > 5) & (df.buy > df.llastp))]
        #     else:
        #         df = df[((df.per1d < 3) & (df.open > df.llastp)) | ((df.per1d > 5) & (df.buy > df.llastp))]

    # else:
    #     if 'fib' in df.columns:
    #         df = df[df.fib <= 5]

    # log.error("perc%sd"%(market_value))

    # elif market_key is not None and market_key == '2':
    #     if market_value in ['1', '2']:
    #         df['dff'] = (map(lambda x, y, z: round((x + (y if z > 20 else 3 * y)), 1), df.dff.values, df.volume.values, df.ratio.values))

    # df['df2'] = (map(lambda x, y, z: w=round((x - y) / z * 100, 1), df.high.values, df.low.values, df.llastp.values))
    # df['df2'] = (map(func_compute_df2, df.close.values, df.llastp.values,df.high.values, df.low.values,df.ratio.values))
    # df['df2'] = (map(func_compute_df2, df.close.values, df.llastp.values,df.high.values, df.low.values))
    '''
    filter_up= 'ma5d'
    filter_dn= 'ma10d'
    if ma5d and filter_up in df.columns:
        if filter_dn in df.columns:
            if market_key is not None and market_key == '3':
                df= df[(df.buy >= df[filter_up]) & (
                    df.buy * 1.02 >= df[filter_dn] * ct.changeRatio)]
            else:
                df= df[(df.buy >= df[filter_up])]
        else:
            df= df[df.buy >= df[filter_up] * ct.changeRatio]
    '''

    # df = df[(df.lvolume > df.lvol * 0.9) & (df.lvolume > df.lowvol * 1.1)]

    # if 'nlow' in df.columns and 932 < cct.get_now_time_int() < 1030:

    if ene:
        pass
        if 'nclose' in df.columns:
            # df = df[ ((df.buy > df.ene) ) | ((df.buy > df.upper) & ( df.nclose > df.cmean))]
            df = df[((df.buy > df.llastp)) |
                    ((df['nclose'] > df['ene'] * ct.changeRatio) &
                     (df['percent'] > -3) & (df.volume > 1.5)) |
                    ((df['nclose'] > df['upper'] * ct.changeRatio) &
                     (df['buy'] > df['upper'] * ct.changeRatioUp)) |
                    ((df['llastp'] > df['upper']) &
                     (df['nclose'] > df['upper']))]
        else:
            df = df[((df.buy > df.llastp)) | ((df.buy > df.ene)) |
                    ((df.buy > df.upper) & (df.close > df.cmean))]

        if 'nlow' in df.columns and 930 < cct.get_now_time_int():
            # for col in ['nhigh', 'nclose', 'nlow','nstd']:
            #     df[col] = df[col].apply(lambda x: round(x, 2))
            if 'nhigh' in df.columns and 'nclose' in df.columns:
                # ncloseRatio = map(lambda x, y: x * ct.changeRatio if x * ct.changeRatio > y else y, df.nclose, df.nlow)
                df['ncloseRatio'] = map(lambda x: x * 0.99, df.nclose)
                df['nopenRatio'] = map(lambda x: x * 0.99, df.open)
                # nhighRatio = map(lambda x, y: x * ct.changeRatio if x * ct.changeRatio > y else y, df.nhigh, df.nclose)
                # if cct.get_now_time_int() > ct.nlow_limit_time:

                #           name   open    low   high  close  nclose   nlow  nhigh  nstd  ticktime
                # code
                # 601899  紫金矿业   4.25   4.24   4.69   4.69    4.52   4.24   4.42  0.12  15:00:00
                # 603917  合力科技  27.95  27.69  31.54  31.54   30.46  27.69  30.00  0.70  15:00:00
                # 300713   英可瑞  81.00  81.00  89.82  89.77   87.53  80.90  86.36  1.75  15:02:03
                # 000933  神火股份   9.07   9.02  10.00  10.00    9.71   9.02   9.44  0.24  15:02:03
                # 600050  中国联通   6.49   6.37   6.51   6.41    6.44   6.44   6.51  0.02  15:00:00
                # 002350  北京科锐  10.17  10.17  10.75  10.23   10.31  10.17  10.75  0.07  15:02:03
                # 603363  傲农生物  17.49  16.91  18.35  18.35   17.35  17.18  18.00  0.34  15:00:00
                # 000868  安凯客车   8.77   8.53   8.82   8.82    8.82   8.53   8.82  0.01  15:02:03
                # 002505  大康农业   2.91   2.86   2.99   2.89    2.91   2.90   2.99  0.02  15:02:03
                # 601939  建设银行   7.50   7.41   7.61   7.55    7.50   7.43   7.52  0.05  15:00:00
                # 600392  盛和资源  16.85  16.81  18.63  18.63   17.84  16.81  17.51  0.69  15:00:00 (11, 41)
                # 603676   卫信康  17.44  16.95  17.96  17.82   17.34  17.03  17.77  0.18  15:00:00
                if 'nstd' in df.columns:
                    df['stdv'] = map(lambda x, y: round(x / y * 100, 1),
                                     df.nstd, df.open)

                # top_temp[:40][['nstd','stdv','name','volume','dff','percent']]
                # top_temp.loc['603363'][['nstd','stdv','name','volume','high','nhigh','percent','open','nclose']]

                # df['stdv'] = map(lambda x, y, z: round(z / (x / y * 100), 1), df.nstd, df.open, df.volume)

                # df.loc['002906'][['open','nclose','close','ncloseRatio','nopenRatio','low','nlow']]

                df = df[(df.low > df.upper) |
                        (((df.nopenRatio <= df.nclose) & (df.low >= df.nlow) &
                          (df.close >= df.ncloseRatio)) |
                         ((df.nopenRatio <= df.nclose) &
                          (df.close >= df.ncloseRatio) &
                          (df.high >= df.nhigh)))]
                # else:
                # df = df[(((df.low >= df.nlow) & (df.close >= ncloseRatio)) | ((df.close >= ncloseRatio) & (df.close > nhighRatio)))]
            else:
                df = df[((df.low >= df.nlow) &
                         (df.close > df.llastp * ct.changeRatio))]
            # if 'nhigh' in df.columns and 'nclose' in df.columns:
            #     if cct.get_now_time_int() > ct.nlow_limit_time:
            #         df = df[(df.low >= df.nlow) & ((df.open > df.llastp * ct.changeRatio) & (df.nclose > df.llastp * ct.changeRatio)) &
            #                 (((df.low >= df.nlow) & (df.close >= df.nclose)) | ((df.close >= df.nclose) & (df.close > df.nhigh * ct.changeRatio) & (df.high >= df.nhigh)))]
            #     else:
            #         df = df[((df.open > df.llastp * ct.changeRatio) & (df.close > df.llastp * ct.changeRatio)) &
            #                 (((df.low >= df.nlow) & (df.close >= df.nclose)) | ((df.close >= df.nclose) & (df.close > df.nhigh * ct.changeRatio)))]
            # else:
            #     df = df[((df.low >= df.nlow) & (df.close > df.llastp))]

        if filter:

            if cct.get_now_time_int() > 915 and cct.get_now_time_int() <= 1000:
                df = df[((df.buy > df.llastp)) |
                        (df.buy > df.hmax * ct.changeRatio) |
                        (df.buy < df.lmin * ct.changeRatioUp)]
                # df = df[(df.buy > df.hmax * ct.changeRatio) & (df.low > df.llastp)]
                # df = df[(df.buy > df.cmean * ct.changeRatioUp) | (df.open > df.llastp)]
                # df = df[df.buy > df.cmean]

            elif cct.get_now_time_int() > 1000 and cct.get_now_time_int(
            ) <= 1430:
                df = df[((df.buy > df.llastp)) |
                        (df.buy > df.hmax * ct.changeRatio) |
                        (df.buy < df.lmin * ct.changeRatioUp)]
                # df = df[(df.buy > df.hmax * ct.changeRatio) | (df.low > df.llastp)]
                # df = df[(df.buy > df.hmax * ct.changeRatio) & (df.low > df.llastp)]

                # df = df[(df.buy > df.cmean * ct.changeRatioUp) | (df.open > df.llastp)]
                # df = df[df.buy > df.cmean]
            else:
                df = df[((df.buy > df.llastp)) |
                        (df.buy > df.hmax * ct.changeRatio) |
                        (df.buy < df.lmin * ct.changeRatioUp)]

                # df = df[(df.buy > df.hmax * ct.changeRatio) | (df.low > df.llastp)]
                # df = df[(df.buy > df.hmax * ct.changeRatio) & (df.low > df.llastp)]

                # df = df[(df.buy > df.cmean * ct.changeRatioUp) | (df.open > df.llastp)]
                # df = df[df.buy > df.cmean]

            if 'vstd' in df.columns:
                # df = df[(df.lvol * df.volume > (df.vstd + df.lvol)) | ((df.percent > -10) & (df.hv / df.lv > 1.5))]
                # dd = df.loc['000760'] dd.hv/dd.lv,dd.volume
                df['hvRatio'] = map(
                    lambda x, y: round(x / y / cct.get_work_time_ratio(), 1),
                    df.hv, df.lv)
                df['volRatio'] = (map(lambda x, y: round(x / y / radio_t, 1),
                                      df.nvol.values, df.lv.values))

                # df = df[(df.lvol * df.volume > (df.vstd + df.lvol)) | ((df.percent > -5) & (df.hv / df.lv > 3))]

                # if 1000 < cct.get_now_time_int() < 1450:
                #     df = df[ (3 < df.ratio) & (df.ratio < 20)]
                if 'nclose' in df.columns:
                    # df = df[((df.hvRatio > df.volRatio) & ((df.buy > df.lastp) & (df.nclose > df.lastp))) | ((
                    df = df[(((df.buy > df.lastp) & (df.nclose > df.lastp))) |
                            (((df.percent > -5) &
                              ((df.vstd + df.lvol) * 1.2 < df.nvol) &
                              (df.nvol > (df.vstd + df.lvol))))]
                else:
                    # df = df[((df.hvRatio > df.volRatio) & ((df.buy > df.lastp))) | ((
                    df = df[(((df.buy > df.lastp))) |
                            (((df.percent > -5) &
                              ((df.vstd + df.lvol) * 1.2 < df.nvol) &
                              (df.nvol > (df.vstd + df.lvol))))]
                # [dd.lvol * dd.volume > (dd.vstd + dd.lvol) | dd.lvol * dd.volume >(dd.ldvolume + dd.vstd]
            # print df.loc['000801']

            if percent:
                pass
                '''
                if 'stdv' in df.columns and 926 < cct.get_now_time_int():
                    # df = df[((df.volume > 2 * cct.get_work_time_ratio()) & (df.percent > -3)) | ((df.stdv < 1) &
                    #                (df.percent > 2)) | ((df.lvolume > df.lvol * 0.9) & (df.lvolume > df.lowvol * 1.1))]
                    
                    df_index = tdd.getSinaIndexdf()
                    if isinstance(df_index, type(pd.DataFrame())):
                        df_index['volume'] = (map(lambda x, y: round(x / y / radio_t, 1), df_index.nvol.values, df_index.lastv1d.values))
                        index_vol = df_index.loc['999999'].volume
                        if 'percent' in df_index.columns and '999999' in df_index.index:
                            index_percent = df_index.loc['999999'].percent
                        else:
                            # import ipdb;ipdb.set_trace()
                            log.error("index_percent" is None)
                            index_percent = 0

                        index_boll = df_index.loc['999999'].boll
                        index_op = df_index.loc['999999'].op
                        # df = df[((df.percent > -3) | (df.volume > index_vol)) & (df.percent > index_percent)]
                        # df = df[((df.percent > -1) | (df.volume > index_vol * 1.5)) & (df.percent > index_percent)  & (df.boll >= index_boll)]
                        df = df[((df.percent > -1) | (df.volume > index_vol * 1.5)) & (df.percent > index_percent)]
                    else:
                        print ("df_index is Series",df_index.T)
                else:
                    df = df[((df.volume > 1.2 * cct.get_work_time_ratio()) & (df.percent > -3))]
                '''
                # df = df[((df['buy'] >= df['ene'])) | ((df['buy'] < df['ene']) & (df['low'] > df['lower'])) | ((df['buy'] > df['upper']) & (df['low'] > df['upper']))]
                # df = df[(( df['ene'] * ct.changeRatio < df['open']) & (df['buy'] > df['ene'] * ct.changeRatioUp)) | ((df['low'] > df['upper']) & (df['close'] > df['ene']))]

                # df = df[(( df['ene'] < df['open']) & (df['buy'] < df['ene'] * ct.changeRatioUp))]

                # df = df[(df.per1d > 9) | (df.per2d > 4) | (df.per3d > 6)]
                # df = df[(df.per1d > 0) | (df.per2d > 4) | (df.per3d > 6)]
            # time_ss=time.time()
            # codel = df.index.tolist()
            # dm = tdd.get_sina_data_df(codel)
            # results = cct.to_mp_run_async(getab.Get_BBANDS, codel,'d',5,duration,dm)
            # bolldf = pd.DataFrame(results, columns=['code','boll'])
            # bolldf = bolldf.set_index('code')
            # df = cct.combine_dataFrame(df, bolldf)
            # print "bollt:%0.2f"%(time.time()-time_ss),
            per3d_l = 2
            percent_l = -1
            op_l = 3
            # if 'boll' in df.columns:
            #     if 915 < cct.get_now_time_int() < 950:
            #         # df = df[(df.boll >= boll) | ((df.percent > percent_l) & (df.op > 4)) | ((df.percent > percent_l) & (df.per3d > per3d_l))]
            #         # df = df[((df.percent > percent_l) & (df.op > 4)) | ((df.percent > percent_l) & (df.per3d > per3d_l))]
            #         pass
            #     elif 950 < cct.get_now_time_int() < 1501:
            #         # df = df[(df.boll >= boll) | ((df.low <> 0) & (df.open == df.low) & (((df.percent > percent_l) & (df.op > op_l)) | ((df.percent > percent_l) & (df.per3d > per3d_l))))]
            #         # df = df[(df.boll >= boll) & ((df.low <> 0) & (df.open >= df.low *
            #         # ct.changeRatio) & (((df.percent > percent_l)) | ((df.percent >
            #         # percent_l) & (df.per3d > per3d_l))))]
            #         df = df[(df.boll >= boll)]
            #     # else:
            # df = df[(df.boll >= boll) | ((df.low <> 0) & (df.open == df.low) &
            # (((df.percent > percent_l) & (df.op > op_l)) | ((df.percent > percent_l)
            # & (df.per3d > per3d_l))))]

        # if 945 < cct.get_now_time_int() and market_key is None:
        #     df.loc[df.percent >= 9.94, 'percent'] = -10

    # else:
    #     # df['upper'] = map(lambda x: round((1 + 11.0 / 100) * x, 1), df.ma10d)
    #     # df['lower'] = map(lambda x: round((1 - 9.0 / 100) * x, 1), df.ma10d)
    #     # df['ene'] = map(lambda x, y: round((x + y) / 2, 1), df.upper, df.lower)
    #     # df = df[((df['buy'] >= df['ene'])) | ((df['buy'] < df['ene']) & (df['low'] > df['lower'])) | ((df['buy'] > df['upper']) & (df['low'] > df['upper']))]
    #     # df = df[(( df['ene'] * ct.changeRatio < df['open']) & (df['buy'] > df['ene'] * ct.changeRatioUp)) | ((df['low'] > df['upper']) & (df['close'] > df['ene']))]
    #     if 'nclose' in df.columns:
    #         # df = df[((df['nclose'] > df['ene'] * ct.changeRatio) & (df['percent'] > -3) & (df.volume > 1.5)) |
    #         #         ((df['nclose'] > df['upper'] * ct.changeRatio) & (df['buy'] > df['upper'] * ct.changeRatioUp)) | ((df['llastp'] > df['upper']) & (df['nclose'] > df['upper']))]
    #         df = df[(df.nclose > df.cmean)]
    #     else:
    #         df = df[(df.buy > df.cmean)]

    print("bo:%0.1f" % (time.time() - time_s)),

    df['ral'] = (map(lambda x, y: round((x + y), 1), df.percent, df.ral))
    df['ra'] = (map(lambda x, y: round((x + y), 1), df.percent, df.ra))
    return df
Example #11
0
def get_dfcfw_fund_flow2020(market):
    indexall = ['sh', 'sz', 'cyb']
    url = ''
    if market == "all":
        single = False
        url = ct.DFCFW_FUND_FLOW_URL_2020All
    else:
        log.error("market is not all")
    log.info("url:%s" % (url))
    data = cct.get_url_data_R(url, timeout=20).split('=')
    # vollist=re.findall('{data:(\d+)',code)
    # vol_l = []

    if len(data) > 0:
        # vol_l = re.findall('\"([\d\D]+?)\"', data[1])
        # ['jQuery18308448273886036106_1606189025852({"rc":0,"rt":11,"svr":182994506,"lt":1,"full":1,\
        # "data":{"total":3,"diff":[{"f62":-9060049408.0,"f184":-4.05},{"f62":-9359993344.0,"f184":-3.16},{"f62":-3487613184.0,"f184":-3.08}]}});']
        data_s = eval(re.findall('{[\d\D]*}', data[0])[0])
        data_s = data_s['data']['diff']
    else:
        data_s = ''
        # data_s = data[1]
    dk = {}
    start_inx = 0
    for i in range(len(indexall)):
        dd = {}
        # start_inx = start_inx + i * 24
        # end_inx = start_inx + (i+1)*24

        if len(data_s) > 0:
            data = (data_s[i])
            # [{'f184': -4.05, 'f62': -9060049408.0}, \
            # {'f184': -3.16, 'f62': -9359993344.0}, {'f184': -3.08, 'f62': -3487613184.0}]
            dd['zlr'] = round(float(data['f62']) / 1000 / 1000 / 100, 1)
            dd['zzb'] = round(float(data['f184']), 1)
            dd['sjlr'] = 0
            dd['sjzb'] = 0
            dd['time'] = cct.get_now_time_int()

            # dd['zlr'] = round(float(data[5+i*25] if data[5+i*25] != '-' else 0)/10000, 1)
            # dd['zzb'] = round(float(data[23+i*25].replace("%","")), 1)
            # dd['sjlr'] = round(float(data[9+i*25])/10000, 1)
            # dd['sjzb'] = round(float(data[10+i*25].replace("%","")), 1)
            # dd['time'] = data[24+i*25].split(" ")[1][:5]
            # print dd['time']
        else:
            dd['zlr'] = 0.0
            dd['zzb'] = 0.0
            dd['sjlr'] = 0.0
            dd['sjzb'] = 0.0
            dd['time'] = 0.0
            log.error("Fund_f NO Url:%s" % url)
        if not single:
            url = ct.SINA_JSON_API_URL % ct.INDEX_LIST[indexall[i]]
            data = cct.get_url_data_R(url, timeout=20, headers=sinaheader)
            vol_l = re.findall('\"([\d\D]+?)\"', data)
            if len(vol_l) == 1:
                data = vol_l[0].split(',')
                try:
                    dd['open'] = round(float(data[1]), 2)
                    dd['lastp'] = round(float(data[2]), 2)
                    dd['close'] = round(float(data[3]), 2)
                    dd['high'] = round(float(data[4]), 2)
                    dd['low'] = round(float(data[5]), 2)
                    dd['vol'] = round(float(data[8]) / 100000, 1)
                    dd['amount'] = round(float(data[9]) / 100000000, 1)
                except Exception, e:
                    print e
                    return dd
                else:
                    pass
                finally:
                    pass
                    #     if 'couts' in top_now.columns.values:
                    #         top_all.loc[symbol, ct.columns_now] = top_now.loc[symbol, ct.columns_now]
                    #     else:
                    #         # top_now.loc[symbol, 'dff'] = round(
                    #         # ((float(top_now.loc[symbol, 'buy']) - float(
                    #         # top_all.loc[symbol, 'lastp'])) / float(top_all.loc[symbol, 'lastp']) * 100),
                    #         # 1)
                    #         top_all.loc[symbol, ct.columns_now] = top_now.loc[symbol, ct.columns_now]
                    top_all = cct.combine_dataFrame(top_all, top_now, col=None)

                top_dif = top_all.copy()
                if 'trade' in top_dif.columns:
                    top_dif['buy'] = (list(
                        map(lambda x, y: y if int(x) == 0 else x,
                            top_dif['buy'].values, top_dif['trade'].values)))
                if ct.checkfilter and cct.get_now_time_int(
                ) > 915 and cct.get_now_time_int() < ct.checkfilter_end_timeDu:
                    top_dif = top_dif[top_dif.low > top_dif.llow *
                                      ct.changeRatio]
                    # top_dif = top_dif[top_dif.buy >= top_dif.lhigh * ct.changeRatio]

                # if cct.get_now_time_int() > 915 and cct.get_now_time_int() <= 926:
                # top_dif['percent']= (map(lambda x, y: round((x-y)/y*100,1) if int(y) > 0 else 0, top_dif.buy, top_dif.llastp))

                if cct.get_now_time_int() > 915:
                    top_dif = top_dif[top_dif.buy > 0]

                top_dif['dff'] = (list(
                    map(lambda x, y: round((x - y) / y * 100, 1),
                        top_dif['buy'].values, top_dif['lastp'].values)))
                # print top_dif.loc['600610',:]
                # top_dif = top_dif[top_dif.trade > 0]
                # top_all = top_all[top_all.open>=top_all.low*0.99]
                # top_all = top_all[top_all.buy >= top_all.open*0.99]
                # top_all = top_all[top_all.trade >= top_all.low*0.99]
                # top_all = top_all[top_all.trade >= top_all.high*0.99]
                # top_all = top_all[top_all.buy >= top_all.llastp]
                # top_all = top_all[top_all.percent >= 0]

                # if cct.get_now_time_int() <1500:

                top_dif = top_all.copy()
                top_dif['dff'] = (list(map(lambda x, y: round((x - y) / y * 100, 1),
                                      top_dif['buy'].values, top_dif['lastp'].values)))

                log.info('dif1:%s' % len(top_dif))
                if not (cct.get_now_time_int() > 915 and cct.get_now_time_int() <= 925):
                    top_dif = top_dif[top_dif.lvol > ct.LvolumeSize]
                if cct.get_now_time_int() > 915 and cct.get_now_time_int() < ct.checkfilter_end_time:
                    top_dif = top_dif[top_dif.low > top_dif.llow * ct.changeRatio]
                    # top_dif = top_dif[top_dif.buy >= top_dif.lhigh * ct.changeRatio]
                log.debug('dif2:%s' % len(top_dif))

                # if cct.get_now_time_int() > 915 and cct.get_now_time_int() <= 926:
                # top_dif['percent']= (map(lambda x, y: round((x-y)/y*100,1) if int(y) > 0 else 0, top_dif.buy, top_dif.llastp))

                # if top_dif[:1].llow.values <> 0:
                if len(top_dif[:5][top_dif[:5]['buy'] > 0]) > 3:
                    log.debug('diff2-0-low>0')
                    top_dif = top_dif[top_dif.low >= top_dif.llow * ct.changeRatio]
                    log.debug('diff2-1:%s' % len(top_dif))
Example #14
0
                        ave = get_code_search_loop(num_input, code, dayl=days)
                    else:
                        ave = get_code_search_loop(num_input,
                                                   code,
                                                   dayl=days,
                                                   ave=ave)
                    code = num_input

            # int_time = cct.get_now_time_int()
            # if cct.get_work_time():
            #     if 930 < int_time < 1000:
            #         cct.sleep(45)
            #     else:
            #         cct.sleep(ct.duration_sleep_time)

            int_time = cct.get_now_time_int()
            if cct.get_work_time():
                log.debug('into get_work_time:%s' % (int_time))
                if 915 < int_time < 926:
                    while 1:
                        cct.sleeprandom(15)
                        break
                elif int_time < 930:
                    while 1:
                        cct.sleep(60)
                        if cct.get_now_time_int() < 931:
                            cct.sleep(60)
                            print ".",
                        else:
                            # cct.sleep(random.randint(0, 30))
                            # print "."
Example #15
0
                if len(codelist) > 0:
                    # log.info('toTDXlist:%s' % len(codelist))
                    # top_all = tdd.get_append_lastp_to_df(top_all)
                    # log.info("df:%s" % top_all[:1])
                    radio_t = cct.get_work_time_ratio()
                    log.debug("Second:vol/vol/:%s" % radio_t)
                    # top_all['volume'] = top_all['volume'].apply(lambda x: round(x / radio_t, 1))
                    log.debug("top_diff:vol")
                    top_all['volume'] = (map(
                        lambda x, y: round(x / y / radio_t, 1),
                        top_all['volume'].values, top_all['lvol'].values))
                    top_all['dff'] = (map(
                        lambda x, y: round(
                            ((float(x) - float(y)) / float(y) * 100), 1),
                        top_all['buy'].values, top_all['lastp'].values))
                    if cct.get_now_time_int() > 915 and cct.get_now_time_int(
                    ) < ct.checkfilter_end_time:
                        top_all = top_all[top_all.low > top_all.llow *
                                          ct.changeRatio]
                        # top_all = top_all[top_all.trade > top_all.lhigh * ct.changeRatio]

                    if cct.get_now_time_int() > 915 and cct.get_now_time_int(
                    ) <= 926:
                        top_all['percent'] = (map(
                            lambda x, y: round((x - y) / y * 100, 1)
                            if int(y) > 0 else 0, top_all.trade,
                            top_all.llastp))
                    # if cct.get_now_time_int() > 930 and 'lastp' in top_all.columns:
                    #     top_all = top_all[top_all.trade >= top_all.llastp]
                    # top_all = top_all.loc[:,
                    # ['name', 'percent', 'ma5d','dff', 'couts', 'volume', 'trade', 'prev_p', 'ratio']]
Example #16
0
                #     top_dif =  top_all[(top_all.topR < 2) & (top_all.open > top_all.lastp1d)]
                #     # top_all[(top_all.low >= top_all.nlow)& (top_all.high > top_all.nhigh)]
                # else:
                #     # top_dif =  top_all[(top_all.topR < 2) & ((top_all.low > top_all.lastp1d) | (top_all.low == top_all.open))]
                #     if 'nlow' in top_all.columns and 'nhigh' in top_all.columns:
                #         top_dif = top_all[(top_all.low >= top_all.nlow)& (top_all.close >= top_all.nhigh)]
                #         # top_dif = top_all[(top_all.low >= top_all.nlow)& (top_all.close >= top_all.nhigh) &(top_all.open == top_all.low)]
                #     else:
                #         top_dif = top_all[(top_all.topR >0) & (top_all.low >= top_all.lastp1d)]
                        
                # market_sort_value, market_sort_value_key = ct.get_market_sort_value_key(st_key_sort, top_all=top_all)
                
                if 'trade' in top_dif.columns:
                    top_dif['buy'] = (list(map(lambda x, y: y if int(x) == 0 else x,
                                          top_dif['buy'].values, top_dif['trade'].values)))
                if ct.checkfilter and cct.get_now_time_int() > 915 and cct.get_now_time_int() < ct.checkfilter_end_timeDu:
                    top_dif = top_dif[top_dif.low > top_dif.llow * ct.changeRatio]
                    # top_dif = top_dif[top_dif.buy >= top_dif.lhigh * ct.changeRatio]

#                if cct.get_now_time_int() > 915 and cct.get_now_time_int() <= 926:
#                    top_dif['percent']= (map(lambda x, y: round((x-y)/y*100,1) if int(y) > 0 else 0, top_dif.buy, top_dif.llastp))

                if cct.get_now_time_int() > 915:
                    top_dif = top_dif[top_dif.buy > 0]

                if st_key_sort.split()[0] == '4' and 926 < cct.get_now_time_int() < 1455 and 'lastbuy' in top_dif.columns:
                    top_dif['dff'] = (list(map(lambda x, y: round((x - y) / y * 100, 1),
                                          top_dif['buy'].values, top_dif['lastbuy'].values)))
                    top_dif['dff2'] = (list(map(lambda x, y: round((x - y) / y * 100, 1),
                                          top_dif['buy'].values, top_dif['lastp'].values)))
                else:
Example #17
0
                    #             top_all.loc[symbol, 'buy':'prev_p'] = top_now.loc[
                    #                 symbol, 'buy':'prev_p']
                    #         else:
                    #             top_all.loc[symbol, 'buy':'low'] = top_now.loc[
                    #                 symbol, 'buy':'low']
                    top_all = cct.combine_dataFrame(top_all, top_now, col=None)
                top_dif = top_all.copy()
                market_sort_value, market_sort_value_key = ct.get_market_sort_value_key(
                    st_key_sort, top_all=top_all)

                top_dif = top_dif[top_dif.lvol > ct.LvolumeSize]
                # if top_dif[:1].llow.values <> 0:
                # if not (cct.get_now_time_int() > 915 and cct.get_now_time_int() <= 925):
                if len(top_dif[:5][top_dif[:5]['buy'] > 0]) > 3:
                    log.debug('diff2-0-buy>0')
                    if cct.get_now_time_int() > 915 and cct.get_now_time_int(
                    ) < ct.checkfilter_end_time:
                        top_dif = top_dif[top_dif.low > top_dif.llow *
                                          ct.changeRatio]
                    log.debug('dif4 open>low0.99:%s' % len(top_dif))
                    # top_dif['buy'] = (map(lambda x, y: y if int(x) == 0 else x, top_dif['buy'].values, top_dif['trade'].values))
                    # if 'volumn' in top_dif.columns and 'lvol' in top_dif.columns:
                top_dif['volume'] = (list(
                    map(lambda x, y: round(x / y / radio_t, 1),
                        top_dif['volume'], top_dif['lvol'])))

                # top_dif['dff'] = map(lambda x, y: round((x - y) / y * 100, 1),
                #                      top_dif['buy'].values, top_dif['lastp'].values)

                if st_key_sort.split()[0] in [
                        '4', '9'
Example #18
0
    def all(self):

        self.stockcode = StockCode()
        self.stock_code_path = self.stockcode.stock_code_path
        self.stock_codes = self.stockcode.get_stock_codes()
        self.load_stock_codes()
        # print "stocks:",len(self.stock_codes)
        self.stock_codes = [
            elem for elem in self.stock_codes
            if elem.startswith(('6', '30', '00'))
        ]
        time_s = time.time()
        h5 = h5a.load_hdf_db(self.hdf_name,
                             self.table,
                             code_l=self.stock_codes,
                             limit_time=self.sina_limit_time)
        log.info("h5a stocksTime:%0.2f" % (time.time() - time_s))

        if h5 is not None and len(h5) > 0:
            o_time = h5[h5.timel <> 0].timel
            if len(o_time) > 0:
                o_time = o_time[0]
                l_time = time.time() - o_time
                sina_limit_time = ct.sina_limit_time
                sina_time_status = (cct.get_work_day_status()
                                    and 915 < cct.get_now_time_int() < 926)
                #                return_hdf_status = not cct.get_work_day_status() or (cct.get_work_day_status() and (cct.get_work_time() and l_time < sina_limit_time))
                return_hdf_status = not cct.get_work_time() or (
                    cct.get_work_time() and l_time < sina_limit_time)
                log.info("915:%s sina_time:%0.2f limit:%s" %
                         (sina_time_status, l_time, sina_limit_time))
                if sina_time_status and l_time < 6:
                    log.info("open 915 hdf ok:%s" % (len(h5)))
                    return h5
                elif not sina_time_status and return_hdf_status:
                    log.info("return hdf5 data:%s" % (len(h5)))
                    return h5
                else:
                    log.info("no return  hdf5:%s" % (len(h5)))
        else:
            log.info("no return  hdf5:%s" %
                     (len(h5) if h5 is not None else 'None'))

        # self.stock_with_exchange_list = list(
        # map(lambda stock_code: ('sh%s' if stock_code.startswith(('5', '6', '9')) else 'sz%s') % stock_code,
        # self.stock_codes))
        self.stock_with_exchange_list = list(
            map(
                lambda stock_code: ('sh%s' if stock_code.startswith(
                    ('6')) else 'sz%s') % stock_code, self.stock_codes))
        self.stock_list = []
        self.request_num = len(self.stock_with_exchange_list) // self.max_num
        for range_start in range(self.request_num):
            num_start = self.max_num * range_start
            num_end = self.max_num * (range_start + 1)
            request_list = ','.join(
                self.stock_with_exchange_list[num_start:num_end])
            self.stock_list.append(request_list)
        # print len(self.stock_with_exchange_list), num_end
        if len(self.stock_with_exchange_list) > num_end:
            request_list = ','.join(self.stock_with_exchange_list[num_end:])
            self.stock_list.append(request_list)
            self.request_num += 1
        # a = 0
        # for x in range(self.request_num):
        #     print x
        #     i = len(self.stock_list[x].split(','))
        #     print i
        #     a += i
        #     print a
        log.debug('all:%s' % len(self.stock_list))
        # log.error('all:%s req:%s' %
        #           (len(self.stock_list), len(self.stock_list)))
        return self.get_stock_data()
Example #19
0
                    top_all = cct.combine_dataFrame(top_all, top_now, col=None)

                # top_all=top_all.sort_values(by=['dff','percent','couts'],ascending=[0,0,1])
                # top_all=top_all.sort_values(by=['dff','ratio','percent','couts'],ascending=[0,1,0,1])

                # top_all = top_all[top_all.open>=top_all.low*0.99]
                # top_all = top_all[top_all.buy >= top_all.open*0.99]
                # top_all = top_all[top_all.trade >= top_all.low*0.99]
                # top_all = top_all[top_all.trade >= top_all.high*0.99]
                # top_all = top_all[top_all.buy >= top_all.llastp]
                # top_all = top_all[top_all.percent >= 0]

                # if cct.get_now_time_int() < 1500:

                top_dif = top_all.copy()
                if cct.get_now_time_int(
                ) > 925 and 'lastbuy' in top_dif.columns:
                    top_dif['dff'] = (map(
                        lambda x, y: round((x - y) / y * 100, 1),
                        top_dif['buy'].values, top_dif['lastbuy'].values))
                else:
                    top_dif['dff'] = (map(
                        lambda x, y: round((x - y) / y * 100, 1),
                        top_dif['buy'].values, top_dif['lastp'].values))

                log.info('dif1:%s' % len(top_dif))
                if cct.get_now_time_int() > 915 and cct.get_now_time_int(
                ) < ct.checkfilter_end_time:
                    top_dif = top_dif[top_dif.lvol > ct.LvolumeSize]
                    # log.info(top_dif[:1])
                    # top_dif = top_dif[top_dif.buy > top_dif.llastp * ct.changeRatio]
                    top_dif = top_dif[top_dif.low > top_dif.llow *
                    #         # ((float(top_now.loc[symbol, 'buy']) - float(
                    #         # top_all.loc[symbol, 'lastp'])) / float(top_all.loc[symbol, 'lastp']) * 100),
                    #         # 1)
                    #         top_all.loc[symbol, ct.columns_now] = top_now.loc[symbol, ct.columns_now]
                    top_all = cct.combine_dataFrame(top_all, top_now, col=None)

                top_dif = top_all.copy()
                market_sort_value, market_sort_value_key = ct.get_market_sort_value_key(st_key_sort, top_all=top_all)

                log.debug('top_dif:%s' % (len(top_dif)))
                if 'trade' in top_dif.columns:
                    top_dif['buy'] = (
                        map(lambda x, y: y if int(x) == 0 else x, top_dif['buy'].values, top_dif['trade'].values))

                # log.debug('top_dif:%s'%(len(top_dif)))
                if ct.checkfilter and cct.get_now_time_int() > 915 and cct.get_now_time_int() < ct.checkfilter_end_timeDu:
                    top_dif = top_dif[top_dif.low > top_dif.llow * ct.changeRatio]
                    # top_dif = top_dif[top_dif.buy >= top_dif.lhigh * ct.changeRatio]
                    log.debug('top_dif:%s' % (len(top_dif)))

                if cct.get_now_time_int() > 915:
                    top_dif = top_dif[top_dif.buy > 0]

                log.debug('top_dif:%s' % (len(top_dif)))
                top_dif['dff'] = (
                    map(lambda x, y: round((x - y) / y * 100, 1), top_dif['buy'].values, top_dif['lastp'].values))
                # print top_dif.loc['600610',:]
                # top_dif = top_dif[top_dif.trade > 0]
                # if cct.get_now_time_int() >< 932:

                # top_dif = top_dif[top_dif.low > 0]
                    top_all, lastpTDX_DF = tdd.get_append_lastp_to_df(
                        top_now, lastpTDX_DF=None, dl=duration_date, end=end_date, ptype=ptype, filter=filter, power=ct.lastPower, lastp=False, resample=resample)
                    log.debug("len:%s" % (len(top_all)))
                    top_list = tdd.compute_jump_du_count(top_all,resample=resample)

                elif len(top_all) == 0 and len(lastpTDX_DF) > 0:
                    top_all = top_now
                    top_all = top_all.merge(
                        lastpTDX_DF, left_index=True, right_index=True, how='left')
                    log.info('Top-merge_now:%s' % (top_all[:1]))
                    top_all = top_all[top_all['llow'] > 0]

                else:
                    log.info("start symbol code :%0.2f" %
                             (cct.get_now_time_int()))
                    log.info("diff co:%s" %
                             (set(top_all.columns) - set(top_now.columns)))
                    if 'couts' in top_now.columns.values:
                        if not 'couts' in top_all.columns.values:
                            top_all['couts'] = 0
                            top_all['prev_p'] = 0
                    # for symbol in top_now.index:
                    #     if 'couts' in top_now.columns.values:
                    #         top_all.loc[symbol, ct.columns_now] = top_now.loc[symbol, ct.columns_now]
                    #     else:
                    #         top_all.loc[symbol, ct.columns_now] = top_now.loc[symbol, ct.columns_now]

                    # no_index = top_all.drop([inx for inx in top_all.index  if inx not in top_now.index], axis=0)
                    # no_index.drop([col for col in no_index.columns if col in top_now.columns], axis=1,inplace=True)
                    # no_index = no_index.merge(top_now, left_index=True, right_index=True, how='left')