Beispiel #1
0
def QA_fetch_stock_transaction_adv(code,
                                   start,
                                   end=None,
                                   if_drop_index=True,
                                   collections=DATABASE.stock_transaction):
    '''

    :param code:
    :param start:
    :param end:
    :param if_drop_index:
    :param collections:
    :return:
    '''
    end = start if end is None else end
    data = DataFrame([
        item for item in collections.find({
            'code': str(code),
            "date": {
                "$gte": start,
                "$lte": end
            }
        })
    ])

    data['datetime'] = pd.to_datetime(data['datetime'])
    return QA_DataStruct_Stock_transaction(
        data.set_index('datetime', drop=if_drop_index))
Beispiel #2
0
def QA_fetch_stock_transaction_adv(
    code,
    start,
    end=None,
    frequence='tick',
    if_drop_index=True,
    collections=DATABASE.stock_transaction
):
    '''

    :param code:
    :param start:
    :param end:
    :param if_drop_index:
    :param collections:
    :return:
    '''
    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 start == end:
        # 🛠 todo 如果相等,根据 frequence 获取开始时间的 时间段 QA_fetch_stock_min, 不支持start end是相等的
        print(
            "QA Error QA_fetch_stock_transaction_adv parameter code=%s , start=%s, end=%s is equal, should have time span! "
            % (code,
               start,
               end)
        )
        return None

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

    res = QA_fetch_stock_transaction(
        code,
        start,
        end,
        format='pd',
        frequence=frequence, 
        collections= collections
    )
    if res is None:
        print(
            "QA Error QA_fetch_stock_transaction_adv parameter code=%s , start=%s, end=%s frequence=%s call QA_fetch_stock_transaction return None"
            % (code,
               start,
               end,
               frequence)
        )
        return None
    else:
        res_set_index = res.set_index(['datetime', 'code'], drop=if_drop_index)
        # if res_set_index is None:
        #     print("QA Error QA_fetch_stock_min_adv set index 'datetime, code' return None")
        #     return None
        return QA_DataStruct_Stock_transaction(res_set_index)
Beispiel #3
0
def QA_fetch_stock_transaction_adv(
        code,
        start, end,
        if_drop_index=False,
        collections=QA_Setting.client.quantaxis.stock_transaction):
    data = DataFrame([item for item in collections.find({
        'code': str(code), "date": {
            "$gte": start,
            "$lte": end
        }})]).drop('_id', axis=1, inplace=False)
    data['datetime'] = pd.to_datetime(data['date'] + ' ' + data['time'])
    return QA_DataStruct_Stock_transaction(data.set_index('datetime', drop=if_drop_index))