Exemplo n.º 1
0
def QA_fetch_index_min_adv(code,
                           start,
                           end=None,
                           frequence='1min',
                           if_drop_index=False,
                           collections=DATABASE.index_min):
    '获取股票分钟线'
    if frequence in ['1min', '1m']:
        frequence = '1min'
    elif frequence in ['5min', '5m']:
        frequence = '5min'
    elif frequence in ['15min', '15m']:
        frequence = '15min'
    elif frequence in ['30min', '30m']:
        frequence = '30min'
    elif frequence in ['60min', '60m']:
        frequence = '60min'
    __data = []
    end = start if end is None else end
    if len(start) == 10:
        start = '{} 09:30:00'.format(start)
    if len(end) == 10:
        end = '{} 15:00:00'.format(end)
    if isinstance(code, str):
        for item in collections.find({
                'code': str(code),
                "time_stamp": {
                    "$gte": QA_util_time_stamp(start),
                    "$lte": QA_util_time_stamp(end)
                },
                'type': frequence
        }):

            __data.append([
                str(item['code']),
                float(item['open']),
                float(item['high']),
                float(item['low']),
                float(item['close']),
                float(item['vol']), item['datetime'], item['time_stamp'],
                item['date']
            ])

        __data = DataFrame(__data,
                           columns=[
                               'code', 'open', 'high', 'low', 'close',
                               'volume', 'datetime', 'time_stamp', 'date'
                           ])

        __data['datetime'] = pd.to_datetime(__data['datetime'])
        return QA_DataStruct_Index_min(
            __data.query('volume>1').set_index(['datetime', 'code'],
                                               drop=if_drop_index))

    elif isinstance(code, list):
        return QA_DataStruct_Index_min(
            pd.concat([
                QA_fetch_index_min_adv(code_, start, end, frequence,
                                       if_drop_index).data for code_ in code
            ]).set_index(['datetime', 'code'], drop=if_drop_index))
Exemplo n.º 2
0
def QA_fetch_index_min_adv(code,
                           start,
                           end,
                           type_='1min',
                           if_drop_index=False,
                           collections=QA_Setting.client.quantaxis.index_min):
    '获取股票分钟线'
    if type_ in ['1min', '1m']:
        type_ = '1min'
    elif type_ in ['5min', '5m']:
        type_ = '5min'
    elif type_ in ['15min', '15m']:
        type_ = '15min'
    elif type_ in ['30min', '30m']:
        type_ = '30min'
    elif type_ in ['60min', '60m']:
        type_ = '60min'
    __data = []
    if isinstance(code, str):
        for item in collections.find({
                'code': str(code),
                "time_stamp": {
                    "$gte": QA_util_time_stamp(start),
                    "$lte": QA_util_time_stamp(end)
                },
                'type': type_
        }):

            __data.append([
                str(item['code']),
                float(item['open']),
                float(item['high']),
                float(item['low']),
                float(item['close']),
                float(item['vol']), item['datetime'], item['time_stamp'],
                item['date']
            ])

        __data = DataFrame(__data,
                           columns=[
                               'code', 'open', 'high', 'low', 'close',
                               'volume', 'datetime', 'time_stamp', 'date'
                           ])

        __data['datetime'] = pd.to_datetime(__data['datetime'])
        return QA_DataStruct_Index_min(
            __data.query('volume>1').set_index(['datetime', 'code'],
                                               drop=if_drop_index))

    elif isinstance(code, list):
        return QA_DataStruct_Index_min(
            pd.concat([
                QA_fetch_index_min_adv(code_, start, end, type_,
                                       if_drop_index).data for code_ in code
            ]).set_index(['datetime', 'code'], drop=if_drop_index))
Exemplo n.º 3
0
def QA_fetch_index_min_adv(code,
                           start,
                           end=None,
                           frequence='1min',
                           if_drop_index=False,
                           collections=DATABASE.index_min):
    '获取股票分钟线'
    if frequence in ['1min', '1m']:
        frequence = '1min'
    elif frequence in ['5min', '5m']:
        frequence = '5min'
    elif frequence in ['15min', '15m']:
        frequence = '15min'
    elif frequence in ['30min', '30m']:
        frequence = '30min'
    elif frequence in ['60min', '60m']:
        frequence = '60min'
    __data = []
    end = start if end is None else end
    if len(start) == 10:
        start = '{} 09:30:00'.format(start)
    if len(end) == 10:
        end = '{} 15:00:00'.format(end)
    return QA_DataStruct_Index_min(
        QA_fetch_index_min(code, start, end, format='pd',
                           frequence=frequence).set_index(['datetime', 'code'],
                                                          drop=if_drop_index))
Exemplo n.º 4
0
def QA_fetch_index_min_adv(code,
                           start,
                           end=None,
                           frequence='1min',
                           if_drop_index=True,
                           collections=DATABASE.index_min):
    '''
    '获取股票分钟线'
    :param code:
    :param start:
    :param end:
    :param frequence:
    :param if_drop_index:
    :param collections:
    :return:
    '''
    if frequence in ['1min', '1m']:
        frequence = '1min'
    elif frequence in ['5min', '5m']:
        frequence = '5min'
    elif frequence in ['15min', '15m']:
        frequence = '15min'
    elif frequence in ['30min', '30m']:
        frequence = '30min'
    elif frequence in ['60min', '60m']:
        frequence = '60min'

    # __data = [] 没有使用

    end = start if end is None else end
    if len(start) == 10:
        start = '{} 09:30:00'.format(start)
    if len(end) == 10:
        end = '{} 15:00:00'.format(end)

    # 🛠 todo 报告错误 如果开始时间 在 结束时间之后

    # if start == end:
    # 🛠 todo 如果相等,根据 frequence 获取开始时间的 时间段 QA_fetch_index_min_adv, 不支持start end是相等的
    # print("QA Error QA_fetch_index_min_adv parameter code=%s , start=%s, end=%s is equal, should have time span! " % (code, start, end))
    # return None

    res = QA_fetch_index_min(code,
                             start,
                             end,
                             format='pd',
                             frequence=frequence,
                             collections=collections)
    if res is None:
        print(
            "QA Error QA_fetch_index_min_adv parameter code=%s start=%s end=%s frequence=%s call QA_fetch_index_min return None"
            % (code, start, end, frequence))
    else:
        res_reset_index = res.set_index(['datetime', 'code'],
                                        drop=if_drop_index)
        # if res_reset_index is None:
        #     print("QA Error QA_fetch_index_min_adv set index 'date, code' return None")
        return QA_DataStruct_Index_min(res_reset_index)
Exemplo n.º 5
0
    def get_lof_min(self, codelist, start, end):
        codelist = promise_list(codelist)
        # if 'XS' not in codelist[0]:
        #     codelist = pd.Series(codelist).apply(
        #         lambda x: x+'.XSHG' if x[0] != 6 else x+'.XSHE').tolist()

        columns_raw = [
            'datetime', 'order_book_id', 'open', 'high', 'low', 'close',
            'volume', 'total_turnover'
        ]
        res = self.client.query_dataframe(
            "SELECT * FROM quantaxis.lof_cn_1min  WHERE ((`datetime` >= '{}')) \
                         AND (`datetime` <= '{}') AND (`order_book_id` IN ({}))"
            .format(start, end, "'{}'".format(
                "','".join(codelist)))).loc[:, columns_raw].drop_duplicates(
                    ['datetime', 'order_book_id'])
        return QA_DataStruct_Index_min(
            res.assign(
                datetime=pd.to_datetime(res.datetime),
                code=res.order_book_id,
                amount=res.total_turnover,
                type='1min',
            ).set_index(['datetime', 'code']).sort_index())