def QA_fetch_get_stock_day(code, start_date, end_date, if_fq='00', frequence='day', ip=None, port=None):
    """获取日线及以上级别的数据


    Arguments:
        code {str:6} -- code 是一个单独的code 6位长度的str
        start_date {str:10} -- 10位长度的日期 比如'2017-01-01'
        end_date {str:10} -- 10位长度的日期 比如'2018-01-01'

    Keyword Arguments:
        if_fq {str} -- '00'/'bfq' -- 不复权 '01'/'qfq' -- 前复权 '02'/'hfq' -- 后复权 '03'/'ddqfq' -- 定点前复权 '04'/'ddhfq' --定点后复权
        frequency {str} -- day/week/month/quarter/year 也可以是简写 D/W/M/Q/Y
        ip {str} -- [description] (default: None) ip可以通过select_best_ip()函数重新获取
        port {int} -- [description] (default: {None})


    Returns:
        pd.DataFrame/None -- 返回的是dataframe,如果出错比如只获取了一天,而当天停牌,返回None

    Exception:
        如果出现网络问题/服务器拒绝, 会出现socket:time out 尝试再次获取/更换ip即可, 本函数不做处理
    """
    ip, port = get_mainmarket_ip(ip, port)
    api = TdxHq_API()
    try:
        with api.connect(ip, port, time_out=0.7):

            if frequence in ['day', 'd', 'D', 'DAY', 'Day']:
                frequence = 9
            elif frequence in ['w', 'W', 'Week', 'week']:
                frequence = 5
            elif frequence in ['month', 'M', 'm', 'Month']:
                frequence = 6
            elif frequence in ['quarter', 'Q', 'Quarter', 'q']:
                frequence = 10
            elif frequence in ['y', 'Y', 'year', 'Year']:
                frequence = 11
            start_date = str(start_date)[0:10]
            today_ = datetime.date.today()
            lens = QA_util_get_trade_gap(start_date, today_)

            data = pd.concat([api.to_df(api.get_security_bars(frequence, _select_market_code(
                code), code, (int(lens / 800) - i) * 800, 800)) for i in range(int(lens / 800) + 1)], axis=0)

            # 这里的问题是: 如果只取了一天的股票,而当天停牌, 那么就直接返回None了
            if len(data) < 1:
                return None
            data = data[data['open'] != 0]

            data = data.assign(date=data['datetime'].apply(lambda x: str(x[0:10])),
                               code=str(code),
                               date_stamp=data['datetime'].apply(lambda x: QA_util_date_stamp(str(x)[0:10]))) \
                .set_index('date', drop=False, inplace=False)

            end_date = str(end_date)[0:10]
            data = data.drop(['year', 'month', 'day', 'hour', 'minute', 'datetime'], axis=1)[
                start_date:end_date]
            if if_fq in ['00', 'bfq']:
                return data
            else:
                print('CURRENTLY NOT SUPPORT REALTIME FUQUAN')
                return None
                # xdxr = QA_fetch_get_stock_xdxr(code)
                # if if_fq in ['01','qfq']:
                #     return QA_data_make_qfq(data,xdxr)
                # elif if_fq in ['02','hfq']:
                #     return QA_data_make_hfq(data,xdxr)
    except Exception as e:
        if isinstance(e, TypeError):
            print('Tushare内置的pytdx版本和QUANTAXIS使用的pytdx 版本不同, 请重新安装pytdx以解决此问题')
            print('pip uninstall pytdx')
            print('pip install pytdx')
        else:
            print(e)
def QA_fetch_get_stock_day ( code , start_date , end_date , if_fq = '00' , frequence = 'day' , ip = None , port = None ) : ip , port = get_mainmarket_ip ( ip , port ) api = TdxHq_API ( ) try : with api . connect ( ip , port , time_out = 0.7 ) : if frequence in [ 'day' , 'd' , 'D' , 'DAY' , 'Day' ] : frequence = 9 elif frequence in [ 'w' , 'W' , 'Week' , 'week' ] : frequence = 5 elif frequence in [ 'month' , 'M' , 'm' , 'Month' ] : frequence = 6 elif frequence in [ 'quarter' , 'Q' , 'Quarter' , 'q' ] : frequence = 10 elif frequence in [ 'y' , 'Y' , 'year' , 'Year' ] : frequence = 11 start_date = str ( start_date ) [ 0 : 10 ] today_ = datetime . date . today ( ) lens = QA_util_get_trade_gap ( start_date , today_ ) data = pd . concat ( [ api . to_df ( api . get_security_bars ( frequence , _select_market_code ( code ) , code , ( int ( lens / 800 ) - i ) * 800 , 800 ) ) for i in range ( int ( lens / 800 ) + 1 ) ] , axis = 0 ) if len ( data ) < 1 : return None data = data [ data [ 'open' ] != 0 ] data = data . assign ( date = data [ 'datetime' ] . apply ( lambda x : str ( x [ 0 : 10 ] ) ) , code = str ( code ) , date_stamp = data [ 'datetime' ] . apply ( lambda x : QA_util_date_stamp ( str ( x ) [ 0 : 10 ] ) ) ) . set_index ( 'date' , drop = False , inplace = False ) end_date = str ( end_date ) [ 0 : 10 ] data = data . drop ( [ 'year' , 'month' , 'day' , 'hour' , 'minute' , 'datetime' ] , axis = 1 ) [ start_date : end_date ] if if_fq in [ '00' , 'bfq' ] : return data else : print ( 'CURRENTLY NOT SUPPORT REALTIME FUQUAN' ) return None except Exception as e : if isinstance ( e , TypeError ) : print ( 'Tushare内置的pytdx版本和QUANTAXIS使用的pytdx 版本不同, 请重新安装pytdx以解决此问题' ) print ( 'pip uninstall pytdx' ) print ( 'pip install pytdx' ) else : print ( e )
获取日线及以上级别的数据


    Arguments:
        code {str:6} -- code 是一个单独的code 6位长度的str
        start_date {str:10} -- 10位长度的日期 比如'2017-01-01'
        end_date {str:10} -- 10位长度的日期 比如'2018-01-01'

    Keyword Arguments:
        if_fq {str} -- '00'/'bfq' -- 不复权 '01'/'qfq' -- 前复权 '02'/'hfq' -- 后复权 '03'/'ddqfq' -- 定点前复权 '04'/'ddhfq' --定点后复权
        frequency {str} -- day/week/month/quarter/year 也可以是简写 D/W/M/Q/Y
        ip {str} -- [description] (default: None) ip可以通过select_best_ip()函数重新获取
        port {int} -- [description] (default: {None})


    Returns:
        pd.DataFrame/None -- 返回的是dataframe,如果出错比如只获取了一天,而当天停牌,返回None

    Exception:
        如果出现网络问题/服务器拒绝, 会出现socket:time out 尝试再次获取/更换ip即可, 本函数不做处理