Exemplo n.º 1
0
def QA_fetch_get_balance_sheet(ts_code=None, ann_date=None):
    """

    :param start_ann_date:
    :param ts_code:
    :param ann_date:
    :return:
    """
    if (ts_code == None and ann_date == None):
        raise ValueError('either ts_code or ann_date has to be provided')

    import AY.Crius.Utils.logging_util as log
    pro = get_pro()
    logger = log.get_logger('QA_fetch_get_balance_sheet')
    try:
        if (not (ts_code is None) and ann_date is None):
            to_insert = pro.balancesheet_vip(ts_code=ts_code)
            return to_insert
        elif (ts_code is None and not (ann_date is None)):
            to_insert = pro.balancesheet_vip(ann_date=ann_date)
            return to_insert
        else:
            to_insert = pro.balancesheet_vip(ts_code=ts_code, ann_date=ann_date)
            return to_insert
    except Exception as e:
        logger.error(e)
        if (ts_code is None):
            reason = "ann_date " + ann_date
        else:
            reason = "ts_code " + ts_code
        logger.error("error processing data for " + reason)
Exemplo n.º 2
0
def QA_SU_save_balance_sheet(client=DATABASE, start_ann_date=None):
    import AY.Crius.Utils.logging_util as log
    logger = log.get_logger('QA_fetch_stock_financial_indicators')

    __coll = client.balance_sheet

    if (not (start_ann_date is None)):
        if (not (isinstance(start_ann_date, str))):
            start_ann_date = str(start_ann_date)
        dates = trading_calendar_utils.get_trading_days_between(
            start_date=start_ann_date,
            end_date=trading_calendar_utils.get_today_as_str())
        for d in dates:
            data = QA_fetch_get_balance_sheet(ann_date=d)
            if (data is not None):
                __coll.insert_many(QA_util_to_json_from_pandas(data))
                data = None
    else:
        try:
            codes = QA_fetch_get_stock_list()
        except Exception as e:
            logger.error(e)
            logger.error('error fetching stock list')
        for code in codes:
            data = QA_fetch_get_balance_sheet(ts_code=code)
            if (data is not None and data.size > 0):
                __coll.insert_many(QA_util_to_json_from_pandas(data))
                data = None
Exemplo n.º 3
0
def QA_fetch_get_stock_daily_basic(trade_date):
    import AY.Crius.Utils.logging_util as log
    pro = get_pro()
    failed = []
    logger = log.get_logger('QA_fetch_get_stock_daily_basic')
    try:
        to_insert = pro.daily_basic(trade_date=trade_date)
        return to_insert
    except Exception as e:
        logger.error(e)
        logger.error("error processing data for date " + trade_date)
Exemplo n.º 4
0
def QA_SU_save_report_type_table(table_type,
                                 client=DATABASE,
                                 start_ann_date=None):
    import AY.Crius.Utils.logging_util as log
    logger = log.get_logger('QA_fetch_stock_report_type_table')

    if (table_type == data_mining_utils.CASH_FLOW_TYPE_NAME):
        __coll = client.cash_flow
    elif (table_type == data_mining_utils.BALANCE_SHEET_TYPE_NAME):
        __coll = client.balance_sheet
    elif (table_type == data_mining_utils.FINANCIAL_INDICATOR_TYPE_NAME):
        __coll = client.finacial_indicator

    if (not (start_ann_date is None)):
        if (not (isinstance(start_ann_date, str))):
            start_ann_date = str(start_ann_date)
        #always only save up to yesterday
        dates = trading_calendar_utils.get_days_between(
            start_date=start_ann_date,
            end_date=trading_calendar_utils.get_yesterday_as_str())
        for d in dates['date']:
            if (table_type == data_mining_utils.CASH_FLOW_TYPE_NAME):
                data = QA_fetch_get_stock_cashflow(ann_date=d)
            elif (table_type == data_mining_utils.BALANCE_SHEET_TYPE_NAME):
                data = QA_fetch_get_balance_sheet(ann_date=d)
            elif (table_type == data_mining_utils.FINANCIAL_INDICATOR_TYPE_NAME
                  ):
                data = QA_fetch_get_stock_financial_indicators(ann_date=d)
            if (data is not None and data.size > 0):
                __coll.insert_many(QA_util_to_json_from_pandas(data))
                data = None
    else:
        try:
            codes = QA_fetch_get_stock_list()
        except Exception as e:
            logger.error(e)
            logger.error('error fetching stock list')
        for code in codes:
            if (table_type == data_mining_utils.CASH_FLOW_TYPE_NAME):
                data = QA_fetch_get_stock_cashflow(ts_code=code)
            elif (table_type == data_mining_utils.BALANCE_SHEET_TYPE_NAME):
                data = QA_fetch_get_balance_sheet(ts_code=code)
            elif (table_type == data_mining_utils.FINANCIAL_INDICATOR_TYPE_NAME
                  ):
                data = QA_fetch_get_stock_financial_indicators(ts_code=code)
            if (data is not None and data.size > 0):
                __coll.insert_many(QA_util_to_json_from_pandas(data))
                data = None
Exemplo n.º 5
0
def QA_SU_save_finacial_inicator_data(client=DATABASE):
    '''
    save tushare's report data into mongodb
    :param client:
    :return:
    '''
    import AY.Crius.Utils.logging_util as log

    __coll = client.finacial_indicator

    logger = log.get_logger('QA_fetch_stock_financial_indicators')
    data = None
    codes = []
    try:
        codes = QA_fetch_get_stock_list()
    except Exception as e:
        logger.error(e)
        logger.error('error fetching stock list')
    for code in codes:
        data = QA_fetch_get_stock_financial_indicators(code)
        if (data is not None):
            __coll.insert_many(QA_util_to_json_from_pandas(data))
            data = None
Exemplo n.º 6
0
def QA_fetch_get_stock_cashflow(ts_code=None, ann_date=None):
    if (ts_code is None and ann_date is None):
        raise ValueError('either ts_code or ann_date has to be provided')

    import AY.Crius.Utils.logging_util as log
    pro = get_pro()
    logger = log.get_logger('QA_fetch_get_financial_indicators')
    try:
        if (not (ts_code is None) and ann_date is None):
            to_insert = pro.cashflow_vip(ts_code=ts_code)
            return to_insert
        elif (ts_code is None and not (ann_date is None)):
            to_insert = pro.cashflow_vip(ann_date=ann_date)
            return to_insert
        else:
            to_insert = pro.cashflow_vip(ts_code=ts_code, ann_date=ann_date)
            return to_insert
    except Exception as e:
        logger.error(e)
        if (ts_code is None):
            reason = "ann_date " + ann_date
        else:
            reason = "ts_code " + ts_code
        logger.error("error processing data for " + reason)