Ejemplo n.º 1
0
def report_core_company():
    while True:
        error_count = 0
        email_action = EmailInformer()

        try:
            # StockTradeDay.record_data(provider='joinquant')
            # Stock.record_data(provider='joinquant')
            # FinanceFactor.record_data(provider='eastmoney')
            # BalanceSheet.record_data(provider='eastmoney')

            target_date = to_time_str(now_pd_timestamp())

            my_selector: TargetSelector = FundamentalSelector(
                start_timestamp='2015-01-01', end_timestamp=target_date)
            my_selector.run()

            long_targets = my_selector.get_open_long_targets(
                timestamp=target_date)
            if long_targets:
                stocks = get_entities(provider='joinquant',
                                      entity_schema=Stock,
                                      entity_ids=long_targets,
                                      return_type='domain')

                # add them to eastmoney
                try:
                    try:
                        eastmoneypy.del_group('core')
                    except:
                        pass
                    eastmoneypy.create_group('core')
                    for stock in stocks:
                        eastmoneypy.add_to_group(stock.code, group_name='core')
                except Exception as e:
                    email_action.send_message(
                        "*****@*****.**", f'report_core_company error',
                        'report_core_company error:{}'.format(e))

                info = [f'{stock.name}({stock.code})' for stock in stocks]
                msg = ' '.join(info)
            else:
                msg = 'no targets'

            logger.info(msg)

            email_action.send_message(get_subscriber_emails(),
                                      f'{to_time_str(target_date)} 核心资产选股结果',
                                      msg)
            break
        except Exception as e:
            logger.exception('report_core_company error:{}'.format(e))
            time.sleep(60 * 3)
            error_count = error_count + 1
            if error_count == 10:
                email_action.send_message(
                    "*****@*****.**", f'report_core_company error',
                    'report_core_company error:{}'.format(e))
Ejemplo n.º 2
0
def report_core_company():
    while True:
        error_count = 0
        email_action = EmailInformer()

        try:
            StockTradeDay.record_data(provider='joinquant')
            Stock.record_data(provider='joinquant')
            FinanceFactor.record_data(provider='eastmoney')
            BalanceSheet.record_data(provider='eastmoney')

            latest_day: StockTradeDay = StockTradeDay.query_data(
                order=StockTradeDay.timestamp.desc(),
                limit=1,
                return_type='domain')
            if latest_day:
                target_date = latest_day[0].timestamp
            else:
                target_date = now_pd_timestamp()

            my_selector: TargetSelector = FundamentalSelector(
                start_timestamp='2015-01-01', end_timestamp=target_date)
            my_selector.run()

            long_targets = my_selector.get_open_long_targets(
                timestamp=target_date)
            if long_targets:
                stocks = get_entities(provider='joinquant',
                                      entity_schema=Stock,
                                      entity_ids=long_targets,
                                      return_type='domain')
                info = [f'{stock.name}({stock.code})' for stock in stocks]
                msg = ' '.join(info)
            else:
                msg = 'no targets'

            logger.info(msg)

            email_action.send_message([
                '*****@*****.**', '*****@*****.**',
                '*****@*****.**', '*****@*****.**',
                '*****@*****.**'
            ], f'{to_time_str(target_date)} 核心资产选股结果', msg)

            break
        except Exception as e:
            logger.exception('report_core_company error:{}'.format(e))
            time.sleep(60 * 3)
            error_count = error_count + 1
            if error_count == 10:
                email_action.send_message(
                    "*****@*****.**", f'report_core_company error',
                    'report_core_company error:{}'.format(e))
Ejemplo n.º 3
0
def report_core_company():
    while True:
        error_count = 0
        email_action = EmailInformer()

        try:
            # StockTradeDay.record_data(provider='joinquant')
            # Stock.record_data(provider='joinquant')
            # FinanceFactor.record_data(provider='eastmoney')
            # BalanceSheet.record_data(provider='eastmoney')

            target_date = to_time_str(now_pd_timestamp())

            my_selector: TargetSelector = FundamentalSelector(start_timestamp="2016-01-01", end_timestamp=target_date)
            my_selector.run()

            long_targets = my_selector.get_open_long_targets(timestamp=target_date)
            if long_targets:
                stocks = get_entities(
                    provider="joinquant", entity_schema=Stock, entity_ids=long_targets, return_type="domain"
                )

                # add them to eastmoney
                try:
                    codes = [stock.code for stock in stocks]
                    add_to_eastmoney(codes=codes, entity_type="stock", group="core")
                except Exception as e:
                    email_action.send_message(
                        zvt_config["email_username"],
                        f"report_core_company error",
                        "report_core_company error:{}".format(e),
                    )

                infos = stocks_with_info(stocks)
                msg = "\n".join(infos)
            else:
                msg = "no targets"

            logger.info(msg)

            email_action.send_message(get_subscriber_emails(), f"{to_time_str(target_date)} 核心资产选股结果", msg)
            break
        except Exception as e:
            logger.exception("report_core_company error:{}".format(e))
            time.sleep(60 * 3)
            error_count = error_count + 1
            if error_count == 10:
                email_action.send_message(
                    zvt_config["email_username"], f"report_core_company error", "report_core_company error:{}".format(e)
                )