|
@@ -6,16 +6,24 @@ import threading
|
|
|
from datetime import datetime as dt
|
|
|
import datetime
|
|
|
|
|
|
-auth('18019403367', 'Qwer4321')
|
|
|
+
|
|
|
|
|
|
-stocks = list(get_all_securities(['stock'], date=dt.today().strftime('%Y-%m-%d')).index)
|
|
|
+engine_stocks_list = create_engine('mysql+pymysql://root:r6kEwqWU9!v3@localhost:3307/hlfx_pool?charset=utf8')
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+stocks = pd.read_sql_query(
|
|
|
+ 'select securities from stocks_list', engine_stocks_list)
|
|
|
+stocks = stocks.iloc[-1, 0]
|
|
|
+stocks = stocks.split(",")
|
|
|
+print(len(stocks), type(stocks), stocks)
|
|
|
|
|
|
|
|
|
start = dt.now()
|
|
|
|
|
|
|
|
|
|
|
|
-for fre in ['30m', '1d']:
|
|
|
+for fre in ['1d', '30m']:
|
|
|
start = dt.now()
|
|
|
print(fre)
|
|
|
|
|
@@ -38,97 +46,97 @@ for fre in ['30m', '1d']:
|
|
|
if ('stk%s_%s' % (thd.stock, fre)) in table_list:
|
|
|
|
|
|
index_len = pd.read_sql_table('stk%s_%s' % (thd.stock, fre), con=engine2).iloc[-1, 0]
|
|
|
-
|
|
|
- startdate = pd.read_sql_table('stk%s_%s' % (thd.stock, fre), con=engine2).iloc[-1, 1]
|
|
|
-
|
|
|
- thd.get_price = pd.read_sql_query(
|
|
|
- '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`' % (thd.stock, fre), engine2)
|
|
|
-
|
|
|
- for i in thd.get_price.index:
|
|
|
-
|
|
|
- if (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']) \
|
|
|
- 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)
|
|
|
-
|
|
|
-
|
|
|
- else:
|
|
|
-
|
|
|
-
|
|
|
- if thd.df_day.iloc[-2, 3] > thd.df_day.iloc[-1, 3]:
|
|
|
- thd.df_day.iloc[-1, 3] = min(thd.df_day.iloc[-1, 3], thd.get_price.loc[i, 'high'])
|
|
|
- thd.df_day.iloc[-1, 4] = min(thd.df_day.iloc[-1, 4], thd.get_price.loc[i, 'low'])
|
|
|
+ if index_len > 2:
|
|
|
+
|
|
|
+ startdate = pd.read_sql_table('stk%s_%s' % (thd.stock, fre), con=engine2).iloc[-1, 1]
|
|
|
+
|
|
|
+ thd.get_price = pd.read_sql_query(
|
|
|
+ '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`' % (thd.stock, fre), engine2)
|
|
|
+
|
|
|
+ for i in thd.get_price.index:
|
|
|
+
|
|
|
+ if (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']) \
|
|
|
+ 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)
|
|
|
+
|
|
|
+
|
|
|
else:
|
|
|
-
|
|
|
- thd.df_day.iloc[-1, 3] = max(thd.df_day.iloc[-1, 3], thd.get_price.loc[i, 'high'])
|
|
|
- thd.df_day.iloc[-1, 4] = max(thd.df_day.iloc[-1, 4], thd.get_price.loc[i, 'low'])
|
|
|
-
|
|
|
- if len(thd.df_day.index) > 2:
|
|
|
-
|
|
|
- for x in range(index_len, len(thd.df_day.index)):
|
|
|
- m = x - 1
|
|
|
-
|
|
|
- if ((thd.df_day.loc[x, 'high'] > thd.df_day.loc[x - 1, 'high']) and (
|
|
|
- thd.df_day.loc[x - 2, 'high'] > thd.df_day.loc[x - 1, 'high'])):
|
|
|
-
|
|
|
-
|
|
|
- thd.df_day.loc[x, 'HL'] = 'L*'
|
|
|
- while m:
|
|
|
- if thd.df_day.loc[m, 'HL'] == 'H':
|
|
|
- if (x - m) > 3:
|
|
|
- thd.df_day.loc[x, 'HL'] = 'L'
|
|
|
- if x == len(thd.df_day.index) - 1:
|
|
|
- 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']:
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+ if thd.df_day.iloc[-2, 3] > thd.df_day.iloc[-1, 3]:
|
|
|
+ thd.df_day.iloc[-1, 3] = min(thd.df_day.iloc[-1, 3], thd.get_price.loc[i, 'high'])
|
|
|
+ thd.df_day.iloc[-1, 4] = min(thd.df_day.iloc[-1, 4], thd.get_price.loc[i, 'low'])
|
|
|
+ else:
|
|
|
+
|
|
|
+ thd.df_day.iloc[-1, 3] = max(thd.df_day.iloc[-1, 3], thd.get_price.loc[i, 'high'])
|
|
|
+ thd.df_day.iloc[-1, 4] = max(thd.df_day.iloc[-1, 4], thd.get_price.loc[i, 'low'])
|
|
|
+
|
|
|
+ if len(thd.df_day.index) > 2:
|
|
|
+
|
|
|
+ for x in range(index_len, len(thd.df_day.index)):
|
|
|
+ m = x - 1
|
|
|
+
|
|
|
+ if ((thd.df_day.loc[x, 'high'] > thd.df_day.loc[x - 1, 'high']) and (
|
|
|
+ thd.df_day.loc[x - 2, 'high'] > thd.df_day.loc[x - 1, 'high'])):
|
|
|
+
|
|
|
+
|
|
|
+ thd.df_day.loc[x, 'HL'] = 'L*'
|
|
|
+ while m:
|
|
|
+ if thd.df_day.loc[m, 'HL'] == 'H':
|
|
|
+ if (x - m) > 3:
|
|
|
+ thd.df_day.loc[x, 'HL'] = 'L'
|
|
|
+ if x == len(thd.df_day.index) - 1:
|
|
|
+ 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']:
|
|
|
+
|
|
|
+ thd.df_day.loc[x, 'HL'] = 'L'
|
|
|
+ if x == len(thd.df_day.index) - 1:
|
|
|
+
|
|
|
+ print(thd.stock, '$$$$$$$', '\n', thd.df_day.loc[x, 'date'], '中继后的底————买吗?!')
|
|
|
+ break
|
|
|
+ else:
|
|
|
+ break
|
|
|
+ m = m - 1
|
|
|
+ if m == 0:
|
|
|
thd.df_day.loc[x, 'HL'] = 'L'
|
|
|
- if x == len(thd.df_day.index) - 1:
|
|
|
-
|
|
|
- print(thd.stock, '$$$$$$$', '\n', thd.df_day.loc[x, 'date'], '中继后的底————买吗?!')
|
|
|
+
|
|
|
+ elif ((thd.df_day.loc[x, 'high'] < thd.df_day.loc[x - 1, 'high']) and (
|
|
|
+ thd.df_day.loc[x - 2, 'high'] < thd.df_day.loc[x - 1, 'high'])):
|
|
|
+
|
|
|
+
|
|
|
+ thd.df_day.loc[x, 'HL'] = 'H*'
|
|
|
+ while m:
|
|
|
+ if thd.df_day.loc[m, 'HL'] == 'L':
|
|
|
+ if x - m > 3:
|
|
|
+ thd.df_day.loc[x, 'HL'] = 'H'
|
|
|
+ if x == len(thd.df_day.index) - 1:
|
|
|
+
|
|
|
+ pass
|
|
|
break
|
|
|
- else:
|
|
|
+ elif (thd.df_day.loc[m, 'HL'] == 'H'):
|
|
|
+ if thd.df_day.loc[x - 1, 'high'] > thd.df_day.loc[m - 1, 'high']:
|
|
|
+
|
|
|
+ thd.df_day.loc[x, 'HL'] = 'H'
|
|
|
+ if x == len(thd.df_day.index) - 1:
|
|
|
+ pass
|
|
|
+
|
|
|
+ break
|
|
|
break
|
|
|
- m = m - 1
|
|
|
- if m == 0:
|
|
|
- thd.df_day.loc[x, 'HL'] = 'L'
|
|
|
-
|
|
|
- elif ((thd.df_day.loc[x, 'high'] < thd.df_day.loc[x - 1, 'high']) and (
|
|
|
- thd.df_day.loc[x - 2, 'high'] < thd.df_day.loc[x - 1, 'high'])):
|
|
|
-
|
|
|
-
|
|
|
- thd.df_day.loc[x, 'HL'] = 'H*'
|
|
|
- while m:
|
|
|
- if thd.df_day.loc[m, 'HL'] == 'L':
|
|
|
- if x - m > 3:
|
|
|
+ m = m - 1
|
|
|
+ if m == 0:
|
|
|
thd.df_day.loc[x, 'HL'] = 'H'
|
|
|
- if x == len(thd.df_day.index) - 1:
|
|
|
-
|
|
|
- pass
|
|
|
- thd.df_day.loc[x, 9] = thd.df_day.loc[x, 'close'] - thd.df_day.loc[m, 'close']
|
|
|
- break
|
|
|
- elif (thd.df_day.loc[m, 'HL'] == 'H'):
|
|
|
- if thd.df_day.loc[x - 1, 'high'] > thd.df_day.loc[m - 1, 'high']:
|
|
|
-
|
|
|
- thd.df_day.loc[x, 'HL'] = 'H'
|
|
|
- if x == len(thd.df_day.index) - 1:
|
|
|
- pass
|
|
|
-
|
|
|
- break
|
|
|
- break
|
|
|
- m = m - 1
|
|
|
- if m == 0:
|
|
|
- thd.df_day.loc[x, 'HL'] = 'H'
|
|
|
- else:
|
|
|
- thd.df_day.loc[x, 'HL'] = '-'
|
|
|
+ else:
|
|
|
+ thd.df_day.loc[x, 'HL'] = '-'
|
|
|
|
|
|
-
|
|
|
- thd.df_day[index_len + 1:].to_sql('stk%s_%s' % (thd.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'))
|
|
@@ -197,7 +205,6 @@ for fre in ['30m', '1d']:
|
|
|
if x == len(thd.df_day.index) - 1:
|
|
|
|
|
|
pass
|
|
|
- thd.df_day.loc[x, 9] = thd.df_day.loc[x, 'close'] - thd.df_day.loc[m, 'close']
|
|
|
break
|
|
|
elif (thd.df_day.loc[m, 'HL'] == 'H'):
|
|
|
if thd.df_day.loc[x - 1, 'high'] > thd.df_day.loc[m - 1, 'high']:
|
|
@@ -216,11 +223,12 @@ for fre in ['30m', '1d']:
|
|
|
|
|
|
thd.df_day.to_sql('stk%s_%s' % (thd.stock, fre), con=engine2, index=True, if_exists='append')
|
|
|
|
|
|
- step = 500
|
|
|
+ step = 700
|
|
|
thread_list = []
|
|
|
engine = []
|
|
|
engine2 = []
|
|
|
times_engine = 0
|
|
|
+ print(len(stocks))
|
|
|
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'))
|