Exemplo n.º 1
0
def record_margin_trading():
    email_action = EmailInformer()

    try:
        MarginTrading.record_data(provider=Provider.JoinQuant, sleeping_time=1)
        # email_action.send_message("*****@*****.**", 'joinquant record margin trading finished', '')
    except Exception as e:
        msg = f'joinquant record margin trading:{e}'
        logger.exception(msg)

        email_action.send_message("*****@*****.**",
                                  'joinquant record margin trading error', msg)
        time.sleep(60)
Exemplo n.º 2
0
    def on_trading_signals(self, trading_signals: List[TradingSignal]):
        # 发送交易信号
        target_date = trading_signals[0].happen_timestamp

        # 发送最近20天的交易信号
        if target_date + datetime.timedelta(20) > now_pd_timestamp(
                self.region):
            email_action = EmailInformer()

            msg = ''

            # 目前持仓情况
            positions = self.get_current_positions()
            if positions:
                current_stocks = [position.entity_id for position in positions]
                msg = msg + '目前持仓: ' + entity_ids_to_msg(
                    self.region, current_stocks) + '\n'

            # 多空信号
            long_stocks = []
            short_stocks = []

            for trading_signal in trading_signals:
                if trading_signal.trading_signal_type == TradingSignalType.open_long:
                    long_stocks.append(trading_signal.entity_id)
                elif trading_signal.trading_signal_type == TradingSignalType.close_long:
                    short_stocks.append(trading_signal.entity_id)

            if long_stocks:
                msg = msg + '买入: ' + entity_ids_to_msg(self.region,
                                                       long_stocks) + '\n'

            if short_stocks:
                msg = msg + '卖出: ' + entity_ids_to_msg(self.region,
                                                       short_stocks) + '\n'

            # 账户情况
            account = self.get_current_account()

            pct = round((account.all_value - account.input_money) /
                        account.input_money * 100, 4)

            msg = msg + f'投入金额:{account.input_money},目前总市值:{account.all_value},收益率:{pct}%'

            email_action.send_message("*****@*****.**", f'{target_date} 交易信号',
                                      msg)

        super().on_trading_signals(trading_signals)
Exemplo n.º 3
0
def record_others():
    while True:
        email_action = EmailInformer()

        try:
            Etf.record_data(provider=Provider.JoinQuant, sleeping_time=1)
            EtfStock.record_data(provider=Provider.JoinQuant, sleeping_time=1)

            # email_action.send_message("*****@*****.**", 'joinquant record etf finished', '')
            break
        except Exception as e:
            msg = f'joinquant record etf error:{e}'
            logger.exception(msg)

            email_action.send_message("*****@*****.**",
                                      'joinquant record etf error', msg)
            time.sleep(60)
Exemplo n.º 4
0
def record_stock():
    while True:
        email_action = EmailInformer()

        try:
            Stock.record_data(provider=Provider.JoinQuant, sleeping_time=1)
            StockTradeDay.record_data(provider=Provider.JoinQuant,
                                      sleeping_time=1)
            # email_action.send_message("*****@*****.**", 'joinquant record stock finished', '')
            break
        except Exception as e:
            msg = f'joinquant record stock:{e}'
            logger.exception(msg)

            email_action.send_message("*****@*****.**",
                                      'joinquant record stock error', msg)
            time.sleep(60 * 5)
Exemplo n.º 5
0
def record_valuation():
    while True:
        email_action = EmailInformer()

        try:
            # 个股估值数据
            StockValuation.record_data(provider=Provider.JoinQuant,
                                       sleeping_time=1)

            # email_action.send_message("*****@*****.**", 'joinquant record valuation finished', '')
            break
        except Exception as e:
            msg = f'joinquant record kdata:{e}'
            logger.exception(msg)

            email_action.send_message("*****@*****.**",
                                      'joinquant record valuation error', msg)
            time.sleep(60)
Exemplo n.º 6
0
def record_kdata():
    while True:
        email_action = EmailInformer()

        try:
            # 日线前复权和后复权数据
            # Stock1dKdata.record_data(provider=Provider.JoinQuant, sleeping_time=0)
            Stock1dHfqKdata.record_data(provider=Provider.JoinQuant,
                                        sleeping_time=0)
            # StockMoneyFlow.record_data(provider=Provider.JoinQuant, sleeping_time=0)
            # IndexMoneyFlow.record_data(provider=Provider.JoinQuant, sleeping_time=0)
            # email_action.send_message("*****@*****.**", 'joinquant record kdata finished', '')
            break
        except Exception as e:
            msg = f'joinquant record kdata:{e}'
            logger.exception(msg)

            email_action.send_message("*****@*****.**",
                                      'joinquant record kdata error', msg)
            time.sleep(60 * 5)
def report_core_company(region: Region, provider: Provider):
    while True:
        error_count = 0
        email_action = EmailInformer()

        try:
            # StockTradeDay.record_data(provider=Provider.JoinQuant)
            # Stock.record_data(provider=Provider.JoinQuant)
            # FinanceFactor.record_data(provider=Provider.EastMoney)
            # BalanceSheet.record_data(provider=Provider.EastMoney)

            target_date = to_time_str(now_pd_timestamp(region))

            my_selector: TargetSelector = FundamentalSelector(region=region, 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(region=region, provider=provider, 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("*****@*****.**", '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))
Exemplo n.º 8
0
def record_money_flow():
    while True:
        email_action = EmailInformer()

        try:
            BlockMoneyFlow.record_data(provider=Provider.Sina)

            email_action.send_message("*****@*****.**",
                                      'sina money flow finished', '')
            break
        except Exception as e:
            msg = f'sina money flow error:{e}'
            logger.exception(msg)

            email_action.send_message("*****@*****.**",
                                      'sina money flow error', msg)
            time.sleep(60)
Exemplo n.º 9
0
def run():
    while True:
        email_action = EmailInformer()

        try:
            DividendFinancing.record_data(provider=Provider.EastMoney)
            HolderTrading.record_data(provider=Provider.EastMoney)
            ManagerTrading.record_data(provider=Provider.EastMoney)
            TopTenHolder.record_data(provider=Provider.EastMoney)
            TopTenTradableHolder.record_data(provider=Provider.EastMoney)

            email_action.send_message("*****@*****.**", 'eastmoney runner2 finished', '')
            break
        except Exception as e:
            msg = f'eastmoney runner2 error:{e}'
            logger.exception(msg)

            email_action.send_message("*****@*****.**", 'eastmoney runner2 error', msg)
            time.sleep(60)
Exemplo n.º 10
0
def run():
    while True:
        email_action = EmailInformer()

        try:
            Stock.record_data(provider=Provider.EastMoney)
            StockDetail.record_data(provider=Provider.EastMoney)
            FinanceFactor.record_data(provider=Provider.EastMoney)
            BalanceSheet.record_data(provider=Provider.EastMoney)
            IncomeStatement.record_data(provider=Provider.EastMoney)
            CashFlowStatement.record_data(provider=Provider.EastMoney)

            email_action.send_message("*****@*****.**",
                                      'eastmoney runner1 finished', '')
            break
        except Exception as e:
            msg = f'eastmoney runner1 error:{e}'
            logger.exception(msg)

            email_action.send_message("*****@*****.**",
                                      'eastmoney runner1 error', msg)
            time.sleep(60)
Exemplo n.º 11
0
def report_vol_up_250(region: Region):
    while True:
        error_count = 0
        email_action = EmailInformer()

        try:
            # 抓取k线数据
            # StockTradeDay.record_data(provider=Provider.JoinQuant)
            # Stock1dKdata.record_data(provider=Provider.JoinQuant)

            latest_day: Stock1dHfqKdata = Stock1dHfqKdata.query_data(
                region=region,
                order=Stock1dHfqKdata.timestamp.desc(),
                limit=1,
                return_type='domain')
            target_date = latest_day[0].timestamp

            # 计算均线
            my_selector = TargetSelector(region=region,
                                         start_timestamp='2018-10-01',
                                         end_timestamp=target_date)
            # add the factors
            factor1 = VolumeUpMaFactor(region=region,
                                       start_timestamp='2018-10-01',
                                       end_timestamp=target_date)

            my_selector.add_filter_factor(factor1)

            my_selector.run()

            long_stocks = my_selector.get_open_long_targets(
                timestamp=target_date)

            msg = 'no targets'

            # 过滤亏损股
            # check StockValuation data
            pe_date = target_date - datetime.timedelta(10)
            if StockValuation.query_data(region=region,
                                         start_timestamp=pe_date,
                                         limit=1,
                                         return_type='domain'):
                positive_df = StockValuation.query_data(
                    region=region,
                    provider=Provider.JoinQuant,
                    entity_ids=long_stocks,
                    start_timestamp=pe_date,
                    filters=[StockValuation.pe > 0],
                    columns=['entity_id'])
                bad_stocks = set(long_stocks) - set(
                    positive_df['entity_id'].tolist())
                if bad_stocks:
                    stocks = get_entities(region=region,
                                          provider=Provider.JoinQuant,
                                          entity_schema=Stock,
                                          entity_ids=bad_stocks,
                                          return_type='domain')
                    info = [f'{stock.name}({stock.code})' for stock in stocks]
                    msg = '亏损股:' + ' '.join(info) + '\n'

                long_stocks = set(positive_df['entity_id'].tolist())

            if long_stocks:
                stocks = get_entities(region=region,
                                      provider=Provider.JoinQuant,
                                      entity_schema=Stock,
                                      entity_ids=long_stocks,
                                      return_type='domain')
                # add them to eastmoney
                try:
                    try:
                        eastmoneypy.del_group('tech')
                    except:
                        pass
                    eastmoneypy.create_group('tech')
                    for stock in stocks:
                        eastmoneypy.add_to_group(stock.code, group_name='tech')
                except Exception as e:
                    email_action.send_message(
                        "*****@*****.**", f'report_vol_up_250 error',
                        'report_vol_up_250 error:{}'.format(e))

                info = [f'{stock.name}({stock.code})' for stock in stocks]
                msg = msg + '盈利股:' + ' '.join(info) + '\n'

            logger.info(msg)

            email_action.send_message(get_subscriber_emails(),
                                      f'{target_date} 改进版放量突破年线选股结果', msg)

            break
        except Exception as e:
            logger.exception('report_vol_up_250 error:{}'.format(e))
            time.sleep(60 * 3)
            error_count = error_count + 1
            if error_count == 10:
                email_action.send_message(
                    "*****@*****.**", f'report_vol_up_250 error',
                    'report_vol_up_250 error:{}'.format(e))