Exemple #1
0
def plot_kline_chart(code=None,
                     mark=None,
                     start_date='2010-01-01',
                     target='MACD',
                     mark_line_show=False):
    '''
    :param code: 股票代码
    :param mark: 指数 [一级行业指数,主题指数,二级行业指数,价值指数,债券指数,基金指数,成长指数,策略指数,综合指数,规模指数]
    :param start_date:
    :return:
    '''

    if code is None and mark is None:
        logger.error("code and mark is None!")
    if code:
        title = get_name(code)
        data = Data(code, start_date)
        data.get_query_history_k_data_plus()
        data.logout()
        chart = ProfessionalKlineChart(mark_line_show=mark_line_show,
                                       title=title,
                                       target=target)
        return chart.draw(data.query_history_k_data_plus)
    if mark:
        plot_mark(mark=mark,
                  start_date=start_date,
                  mark_line_show=mark_line_show)
        logger.info("draw chart finish")
Exemple #2
0
def send_mail(low, high):
    sender = '*****@*****.**'
    password = '******'
    smtp_server = 'smtp.qq.com'

    receivers = ['*****@*****.**']

    mail_msg = """
    <p>低估产品</p>
    {}
    <p>高估产品</p>
    {}
    """
    mail_msg = mail_msg.format(low.to_html(), high.to_html())
    message = MIMEText(mail_msg, 'html', 'utf-8')
    message['From'] = Header("估值监控", 'utf-8')
    message['To'] = Header("stock", 'utf-8')

    subject = '估值监控'
    message['Subject'] = Header(subject, 'utf-8')

    try:
        smtpObj = smtplib.SMTP_SSL(smtp_server)
        smtpObj.connect(smtp_server, 465)
        smtpObj.login(sender, password)
        smtpObj.sendmail(sender, receivers, message.as_string())
        logger.info("邮件发送成功")
    except smtplib.SMTPException:
        logger.info("Error: 无法发送邮件")
Exemple #3
0
def update_task():
    logger.info('{} start run monitor'.format(
        time.strftime('%Y-%M-%d %H:%M:%S')))
    data = Data()
    data.update_stock_industry()
    monitor_run.monitor_mark()
    monitor_run.monitor_pepb()
    logger.info('{} finish run monitor'.format(
        time.strftime('%Y-%M-%d %H:%M:%S')))
Exemple #4
0
def del_code(code):
    logger.info(code)
    if os.path.exists(os.path.join(PROJECT_PATH, 'mark_cache/monitor')):
        with open(os.path.join(PROJECT_PATH, 'mark_cache/monitor'), 'r') as fr:
            result = json.loads(fr.read())
        if code in result:
            result.remove(code)
        with open(os.path.join(PROJECT_PATH, 'mark_cache/monitor'), 'w') as fw:
            fw.write(json.dumps(result))
Exemple #5
0
def plot_mark(mark, start_date, mark_line_show=False, clear_cache=False):
    cache_data = get_cache(mark, clear_cache)
    path_data_info = os.path.join(PROJECT_PATH, 'data_info')
    mark_info = pd.read_csv(os.path.join(path_data_info, mark + ".csv"))
    i = 0
    start = time.time()
    for code in mark_info['指数代码']:
        name = mark_info.loc[mark_info['指数代码'] == code, '指数简称'].values[0]
        i += 1
        logger.info('\nDraw chart: {}=>{}'.format(mark, name))
        draw = ProfessionalKlineChart(mark_line_show=mark_line_show,
                                      title=name)
        if cache_data is not None and cache_data[cache_data['code'] ==
                                                 code].size > 0:
            start_date = (pd.to_datetime(
                cache_data[cache_data['code'] == code]['date'].max()) +
                          datetime.timedelta(days=1)).strftime('%Y-%m-%d')
        if start_date <= datetime.datetime.now().strftime('%Y-%m-%d'):
            data = Data(code, start_date)
            data.get_query_history_k_data_plus()
            data.logout()
            if cache_data is not None:
                data.query_history_k_data_plus = pd.concat(
                    [
                        cache_data[cache_data['code'] == code],
                        data.query_history_k_data_plus
                    ],
                    ignore_index=True).sort_values(by='date')
            if data.query_history_k_data_plus.size == 0:
                logger.warning(
                    'data.query_history_k_data_plus and cache_data is NULL')
            else:
                data.query_history_k_data_plus.drop_duplicates(
                    subset=['date', 'code'], inplace=True)
                chart = draw.draw(data.query_history_k_data_plus)
                save_html(mark, chart, name)
                cache_data = pd.concat(
                    [cache_data, data.query_history_k_data_plus],
                    ignore_index=True)
                cache_data.drop_duplicates(subset=['date', 'code'],
                                           inplace=True)
        else:
            logger.error("date is out of today!")
        clearout()
        end = time.time()
        logger.info('\r' + '进度 {}/{}:[{}]{:.2f}% {:.2f}s'.format(
            i, len(mark_info),
            emoji.emojize(':rocket:') * int(i * 30 / len(mark_info)) + '   ' *
            int((1 -
                 (i / len(mark_info))) * 30), float(i / len(mark_info) *
                                                    100), end - start))
    save_cache(mark, cache_data)
Exemple #6
0
 def log(self, message, rs):
     if self.verbose == 1:
         logger.info(message + rs.error_msg)
     else:
         if rs.error_code != '0':
             logger.error(message + rs.error_msg)
Exemple #7
0
        rs = bs.query_hs300_stocks(date = date)
        self.log('query_hs300  error_msg:', rs)

        # 打印结果集
        hs300_stocks = []
        while (rs.error_code == '0') & rs.next():
            # 获取一条记录,将记录合并在一起
            hs300_stocks.append(rs.get_row_data())
        result = pd.DataFrame(hs300_stocks, columns=rs.fields)
        return result

    # 中证500成分股
    def query_zz500_stocks(self, date = None):
        '''
        date:查询日期,格式XXXX-XX-XX,为空时默认最新日期。
        '''
        rs = bs.query_zz500_stocks(date = date)
        self.log('query_zz500  error_msg:', rs)

        # 打印结果集
        zz500_stocks = []
        while (rs.error_code == '0') & rs.next():
            # 获取一条记录,将记录合并在一起
            zz500_stocks.append(rs.get_row_data())
        result = pd.DataFrame(zz500_stocks, columns=rs.fields)
        return result

if __name__ == '__main__':
    d = DownData()
    logger.info(d.query_zz500_stocks())
    bs.logout()
Exemple #8
0
'''
Exemple #9
0
    subject = '估值监控'
    message['Subject'] = Header(subject, 'utf-8')

    try:
        smtpObj = smtplib.SMTP_SSL(smtp_server)
        smtpObj.connect(smtp_server, 465)
        smtpObj.login(sender, password)
        smtpObj.sendmail(sender, receivers, message.as_string())
        logger.info("邮件发送成功")
    except smtplib.SMTPException:
        logger.info("Error: 无法发送邮件")


if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='choose function')
    parser.add_argument('--function',
                        nargs='+',
                        default='monitor_mark',
                        help='input batch size for training (default: 64)')
    args = parser.parse_args()
    while True:
        if time.strftime('%H:%M') == '18:00':
            logger.info('{} start run monitor'.format(
                time.strftime('%Y-%M-%d %H:%M:%S')))
            data = Data()
            data.update_stock_industry()
            monitor_mark()
            monitor_pepb()
            logger.info('{} finish run monitor'.format(
                time.strftime('%Y-%M-%d %H:%M:%S')))
        time.sleep(60)