from sqlalchemy import create_engine
import pandas as pd
from xtquant import xtdata

engine = create_engine('mysql+pymysql://root:r6kEwqWU9!v3@localhost:3307/qmt_stocks_tech?charset=utf8')

err_list =[]
stocks = xtdata.get_stock_list_in_sector('沪深A股')
print(len(stocks))
stocks.sort()
print(stocks[0:20])

for stock in stocks:
    try:
        df_day = pd.read_sql_query('select time, open_front, close_front, high_front, low_front, '
                                   'volume_front, amount_front, dif, dea, macd,HL from `%s_1d`'% stock, engine)
    except BaseException as e:
        print(stock, e)
        err_list.append(stock)
    else:
        print(f'{stock}正确！')

print(f'错误的有{len(err_list)}', '\n', err_list)
