期货数据 分钟线

def QA_fetch_get_future_min(code, start, end, frequence='1min', ip=None, port=None):
    '期货数据 分钟线'
    ip, port = get_extensionmarket_ip(ip, port)
    apix = TdxExHq_API()
    type_ = ''
    start_date = str(start)[0:10]
    today_ = datetime.date.today()
    lens = QA_util_get_trade_gap(start_date, today_)
    global extension_market_list
    extension_market_list = QA_fetch_get_extensionmarket_list(
    ) if extension_market_list is None else extension_market_list

    if str(frequence) in ['5', '5m', '5min', 'five']:
        frequence, type_ = 0, '5min'
        lens = 48 * lens * 2.5
    elif str(frequence) in ['1', '1m', '1min', 'one']:
        frequence, type_ = 8, '1min'
        lens = 240 * lens * 2.5
    elif str(frequence) in ['15', '15m', '15min', 'fifteen']:
        frequence, type_ = 1, '15min'
        lens = 16 * lens * 2.5
    elif str(frequence) in ['30', '30m', '30min', 'half']:
        frequence, type_ = 2, '30min'
        lens = 8 * lens * 2.5
    elif str(frequence) in ['60', '60m', '60min', '1h']:
        frequence, type_ = 3, '60min'
        lens = 4 * lens * 2.5
    if lens > 20800:
        lens = 20800

    # print(lens)
    with apix.connect(ip, port):

        code_market = extension_market_list.query(
            'code=="{}"'.format(code)).iloc[0]
        data = pd.concat([apix.to_df(apix.get_instrument_bars(frequence, int(code_market.market), str(
            code), (int(lens / 700) - i) * 700, 700)) for i in range(int(lens / 700) + 1)], axis=0)
        # print(data)
        # print(data.datetime)
        data = data \
            .assign(tradetime=data['datetime'].apply(str), code=str(code)) \
            .assign(datetime=pd.to_datetime(data['datetime'].apply(QA_util_future_to_realdatetime, 1))) \
            .drop(['year', 'month', 'day', 'hour', 'minute'], axis=1, inplace=False) \
            .assign(date=data['datetime'].apply(lambda x: str(x)[0:10])) \
            .assign(date_stamp=data['datetime'].apply(lambda x: QA_util_date_stamp(x))) \
            .assign(time_stamp=data['datetime'].apply(lambda x: QA_util_time_stamp(x))) \
            .assign(type=type_).set_index('datetime', drop=False, inplace=False)
        return data.assign(datetime=data['datetime'].apply(lambda x: str(x)))[start:end].sort_index()