|
@@ -16,6 +16,7 @@ start = dt.now()
|
|
|
# 注意修改time delta
|
|
|
# fre = '30m'
|
|
|
for fre in ['30m', '1d']:
|
|
|
+ print(fre)
|
|
|
# 连接数据库
|
|
|
db = pymysql.connect(host='localhost',
|
|
|
user='root',
|
|
@@ -30,20 +31,19 @@ for fre in ['30m', '1d']:
|
|
|
stk = locals()
|
|
|
thd = threading.local()
|
|
|
|
|
|
- def hlfx(table_list, engine, engine2):
|
|
|
- for stock in stocks:
|
|
|
- print(stock)
|
|
|
- if ('stk%s_%s' % (stock, fre)) in table_list:
|
|
|
+ def hlfx(stocks, engine, engine2):
|
|
|
+ for thd.stock in stocks:
|
|
|
+ if ('stk%s_%s' % (thd.stock, fre)) in table_list:
|
|
|
# 有历史数据
|
|
|
- index_len = pd.read_sql_table('stk%s_%s' % (stock, fre), con=engine2).iloc[-1, 0]
|
|
|
+ index_len = pd.read_sql_table('stk%s_%s' % (thd.stock, fre), con=engine2).iloc[-1, 0]
|
|
|
# 注意修改time delta
|
|
|
- startdate = pd.read_sql_table('stk%s_%s' % (stock, fre), con=engine2).iloc[-1, 1]
|
|
|
+ startdate = pd.read_sql_table('stk%s_%s' % (thd.stock, fre), con=engine2).iloc[-1, 1]
|
|
|
# startdate = pd.read_sql_table('stk%s_%s' % (stock, fre), con=engine2).iloc[-1, 1] + datetime.timedelta(minutes= 5)
|
|
|
thd.get_price = pd.read_sql_query(
|
|
|
- 'select date,open,close,high,low,volume,money from `stk%s_%s`' % (stock, fre), engine)
|
|
|
+ 'select date,open,close,high,low,volume,money from `stk%s_%s`' % (thd.stock, fre), engine)
|
|
|
thd.get_price = thd.get_price.loc[thd.get_price['date'] > startdate]
|
|
|
thd.df_day = pd.read_sql_query(
|
|
|
- 'select date,open,close,high,low,volume,money,HL from `stk%s_%s`' % (stock, fre), engine2)
|
|
|
+ 'select date,open,close,high,low,volume,money,HL from `stk%s_%s`' % (thd.stock, fre), engine2)
|
|
|
# 先处理去包含
|
|
|
for i in thd.get_price.index:
|
|
|
# 不包含
|
|
@@ -52,7 +52,7 @@ for fre in ['30m', '1d']:
|
|
|
or (thd.df_day.iloc[-1, 3] < thd.get_price.loc[i, 'high']
|
|
|
and thd.df_day.iloc[-1, 4] < thd.get_price.loc[i, 'low']):
|
|
|
thd.df_day = pd.concat([thd.df_day, thd.get_price.loc[[i]]], ignore_index=True)
|
|
|
- print(thd.df_day)
|
|
|
+ # print(thd.df_day)
|
|
|
# 包含
|
|
|
else:
|
|
|
# (new_df.iloc[-1,3]>=df_day.loc[i,'high'] and new_df.iloc[-1,4]<= df_day.loc[i,'low']):
|
|
@@ -80,7 +80,7 @@ for fre in ['30m', '1d']:
|
|
|
if (x - m) > 3:
|
|
|
thd.df_day.loc[x, 'HL'] = 'L'
|
|
|
if x == len(thd.df_day.index) - 1:
|
|
|
- print(stock, '$$$$$$$', '\n', thd.df_day.loc[x, 'date'], '买买买买买!!')
|
|
|
+ print(thd.stock, '$$$$$$$', '\n', thd.df_day.loc[x, 'date'], '买买买买买!!')
|
|
|
break
|
|
|
elif (thd.df_day.loc[m, 'HL'] == 'L'):
|
|
|
if thd.df_day.loc[x - 1, 'low'] < thd.df_day.loc[m - 1, 'low']:
|
|
@@ -88,7 +88,7 @@ for fre in ['30m', '1d']:
|
|
|
thd.df_day.loc[x, 'HL'] = 'L'
|
|
|
if x == len(thd.df_day.index) - 1:
|
|
|
# pass
|
|
|
- print(stock, '$$$$$$$', '\n', thd.df_day.loc[x, 'date'], '中继后的底————买吗?!')
|
|
|
+ print(thd.stock, '$$$$$$$', '\n', thd.df_day.loc[x, 'date'], '中继后的底————买吗?!')
|
|
|
break
|
|
|
else:
|
|
|
break
|
|
@@ -122,12 +122,12 @@ for fre in ['30m', '1d']:
|
|
|
thd.df_day.loc[x, 'HL'] = '-'
|
|
|
|
|
|
# 更新数据库
|
|
|
- thd.df_day[index_len + 1:].to_sql('stk%s_%s' % (stock, fre), con=engine2, index=True, if_exists='append')
|
|
|
+ thd.df_day[index_len + 1:].to_sql('stk%s_%s' % (thd.stock, fre), con=engine2, index=True, if_exists='append')
|
|
|
else:
|
|
|
# 没有历史数据表
|
|
|
thd.df_day = pd.DataFrame(columns=('date', 'open', 'close', 'high', 'low', 'volume', 'money', 'HL'))
|
|
|
thd.get_price = pd.read_sql_query(
|
|
|
- 'select date,open,close,high,low,volume,money from `stk%s_%s`' % (stock, fre), engine)
|
|
|
+ 'select date,open,close,high,low,volume,money from `stk%s_%s`' % (thd.stock, fre), engine)
|
|
|
# 先处理去包含
|
|
|
for i in thd.get_price.index:
|
|
|
if i == 0 or i == 1:
|
|
@@ -163,7 +163,7 @@ for fre in ['30m', '1d']:
|
|
|
if (x - m) > 3:
|
|
|
thd.df_day.loc[x, 'HL'] = 'L'
|
|
|
if x == len(thd.df_day.index) - 1:
|
|
|
- print(stock, '$$$$$$$', '\n', thd.df_day.loc[x, 'date'], '买买买买买!!')
|
|
|
+ print(thd.stock, '$$$$$$$', '\n', thd.df_day.loc[x, 'date'], '买买买买买!!')
|
|
|
break
|
|
|
elif (thd.df_day.loc[m, 'HL'] == 'L'):
|
|
|
if thd.df_day.loc[x - 1, 'low'] < thd.df_day.loc[m - 1, 'low']:
|
|
@@ -171,7 +171,7 @@ for fre in ['30m', '1d']:
|
|
|
thd.df_day.loc[x, 'HL'] = 'L'
|
|
|
if x == len(thd.df_day.index) - 1:
|
|
|
# pass
|
|
|
- print(stock, '$$$$$$$', '\n', thd.df_day.loc[x, 'date'], '中继后的底————买吗?!')
|
|
|
+ print(thd.stock, '$$$$$$$', '\n', thd.df_day.loc[x, 'date'], '中继后的底————买吗?!')
|
|
|
break
|
|
|
else:
|
|
|
break
|
|
@@ -204,21 +204,22 @@ for fre in ['30m', '1d']:
|
|
|
else:
|
|
|
thd.df_day.loc[x, 'HL'] = '-'
|
|
|
# 更新数据库
|
|
|
- thd.df_day.to_sql('stk%s_%s' % (stock, fre), con=engine2, index=True, if_exists='append')
|
|
|
+ thd.df_day.to_sql('stk%s_%s' % (thd.stock, fre), con=engine2, index=True, if_exists='append')
|
|
|
|
|
|
step = 100
|
|
|
thread_list = []
|
|
|
engine = []
|
|
|
engine2 = []
|
|
|
times_engine = 0
|
|
|
- for i in range(0, len(table_list), step):
|
|
|
- engine.append(create_engine('mysql+pymysql://root:r6kEwqWU9!v3@localhost:3307/qbh?charset=utf8'))
|
|
|
+ for i in range(0, len(stocks), step):
|
|
|
+ engine.append(create_engine('mysql+pymysql://root:r6kEwqWU9!v3@localhost:3307/stocks?charset=utf8'))
|
|
|
engine2.append(create_engine('mysql+pymysql://root:r6kEwqWU9!v3@localhost:3307/hlfx?charset=utf8'))
|
|
|
- thread = threading.Thread(target=hlfx, args=(table_list[i:i + step], engine[times_engine], engine2[times_engine]))
|
|
|
+ thread = threading.Thread(target=hlfx, args=(stocks[i:i + step], engine[times_engine], engine2[times_engine]))
|
|
|
times_engine = times_engine + 1
|
|
|
thread.start()
|
|
|
thread_list.append(thread)
|
|
|
|
|
|
+
|
|
|
for thread in thread_list:
|
|
|
thread.join()
|
|
|
db.close()
|