Exemplo n.º 1
0
def test_import_stock():
    log = Logger("import_data.log")
    try:
        stock_data = BasicData()
        stock_num = stock_data.import_stock()
        log.print_info("导入" + str(stock_num) + "条股票数据")
        log.write_info("导入" + str(stock_num) + "条股票数据")
    except Exception as err:
        log.print_error("导入股票基础信息错误:" + str(err))
        log.write_error("导入股票基础信息错误:" + str(err))
Exemplo n.º 2
0
def test_import_daily():
    log = Logger("import_data.log")
    try:
        stock_data = BasicData()
        stock_df = stock_data.query_stock()
        for row in stock_df.itertuples():
            basic_code = getattr(row, 'basic_code')
            last_daily = stock_data.get_last_daily(basic_code)
            if last_daily is None:
                stock_code, daily_num = stock_data.import_stock_daily(basic_code)
            else:
                start_date = last_daily + datetime.timedelta(days=1)
                # 结束日期设置为当前日期
                end_date = datetime.date.today()
                # 导入股票日线行情,交易日期大于当前系统最新的交易日期
                stock_code, daily_num = stock_data.import_stock_daily(basic_code, start_date, end_date)
            log.print_info("导入股票:" + str(stock_code) + "  " + str(daily_num) + "条行情数据")
            time.sleep(1)
        log.print_info("系统导入" + str(stock_df.shape[0]) + "条股票行情数据!")
        log.print_info("系统导入" + str(stock_df.shape[0]) + "条股票行情数据!")
    except Exception as err:
        log.print_error("导入股票日线行情错误:" + str(err))
        log.write_error("导入股票日线行情错误:" + str(err))