|
@@ -102,9 +102,9 @@ def hlfx(data, stocks, pool_list):
|
|
df_day = pd.read_sql_query(
|
|
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_%s`'
|
|
'select time, open_front, close_front, high_front, low_front, volume_front, amount_front, dif, dea, macd,HL from `%s_%s`'
|
|
% (qmt_stock, fre), engine_stock)
|
|
% (qmt_stock, fre), engine_stock)
|
|
- df_day.columns=['time', 'open', 'close', 'high', 'low', 'volume', 'amount', 'dif', 'dea', 'macd','HL']
|
|
|
|
- except BaseException:
|
|
|
|
- print(qmt_stock)
|
|
|
|
|
|
+ df_day.columns=['time', 'open', 'close', 'high', 'low', 'volume', 'amount', 'dif', 'dea', 'macd', 'HL']
|
|
|
|
+ except BaseException as e:
|
|
|
|
+ print(qmt_stock, '未能读取!', e)
|
|
pass
|
|
pass
|
|
else:
|
|
else:
|
|
# 获得最新价格信息
|
|
# 获得最新价格信息
|
|
@@ -256,12 +256,14 @@ def bridge(data):
|
|
|
|
|
|
to_hlfx_list = []
|
|
to_hlfx_list = []
|
|
keys = list(data.keys())
|
|
keys = list(data.keys())
|
|
- step = math.ceil(len(keys) / (mp.cpu_count()/2))
|
|
|
|
|
|
+ print(len(keys))
|
|
|
|
+ cpu_count = 4
|
|
|
|
+ step = math.ceil(len(keys) / cpu_count)
|
|
for i in range(0, len(keys), step):
|
|
for i in range(0, len(keys), step):
|
|
to_hlfx_list.append([x for x in keys[i:i+step]])
|
|
to_hlfx_list.append([x for x in keys[i:i+step]])
|
|
|
|
|
|
- pool = mp.Pool(processes=int(mp.cpu_count()/2))
|
|
|
|
- for m in range(int(mp.cpu_count()/2)):
|
|
|
|
|
|
+ pool = mp.Pool(processes=cpu_count)
|
|
|
|
+ for m in range(cpu_count):
|
|
pool.apply_async(func=hlfx,
|
|
pool.apply_async(func=hlfx,
|
|
args=(data, to_hlfx_list[m], results,), error_callback=err_call_back)
|
|
args=(data, to_hlfx_list[m], results,), error_callback=err_call_back)
|
|
pool.close()
|
|
pool.close()
|
|
@@ -321,78 +323,3 @@ if __name__ == '__main__':
|
|
|
|
|
|
xtdata.run()
|
|
xtdata.run()
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- start = dt.now()
|
|
|
|
- while True:
|
|
|
|
- now_date = dt.now()
|
|
|
|
- date_morning_begin = now_date.replace(hour=9, minute=25, second=0)
|
|
|
|
- date_morning_end = now_date.replace(hour=11, minute=31, second=0)
|
|
|
|
- date_afternooe_begin = now_date.replace(hour=13, minute=0, second=0)
|
|
|
|
- date_afternooe_end = now_date.replace(hour=15, minute=0, second=0)
|
|
|
|
- # print(now_date,date_morning_begin,date_morning_end,date_afternooe_begin,date_afternooe_end)
|
|
|
|
- # if date_morning_begin < now_date < date_afternooe_end:
|
|
|
|
- if True:
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- for fre in ['1d']:
|
|
|
|
- start = dt.now()
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- stk = locals()
|
|
|
|
- thd = threading.local()
|
|
|
|
- # 进程准备
|
|
|
|
- step = 400
|
|
|
|
- thread_list = []
|
|
|
|
- engine_stock = []
|
|
|
|
- engine_hlfx = []
|
|
|
|
- times_engine = 0
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- df = get_bars(stocks, count=5, unit=fre,
|
|
|
|
- fields=['date', 'open', 'close', 'high', 'low', 'volume', 'money'], include_now=True, df=True)
|
|
|
|
- print(df, type(df))
|
|
|
|
- print(df.loc['603566.XSHG'])
|
|
|
|
- print(dt.now(), 'get_bars 成功')
|
|
|
|
- exit()
|
|
|
|
- for i in range(0, len(stocks), step):
|
|
|
|
- engine_stock.append(create_engine('mysql+pymysql://root:r6kEwqWU9!v3@localhost:3307/stocks?charset=utf8'))
|
|
|
|
- engine_hlfx.append(create_engine('mysql+pymysql://root:r6kEwqWU9!v3@localhost:3307/hlfx?charset=utf8'))
|
|
|
|
- thread = threading.Thread(target=hlfx, args=(stocks[i:i + step], engine_stock[times_engine], engine_hlfx[times_engine]))
|
|
|
|
- times_engine = times_engine + 1
|
|
|
|
- thread.start()
|
|
|
|
- thread_list.append(thread)
|
|
|
|
-
|
|
|
|
- for thread in thread_list:
|
|
|
|
- thread.join()
|
|
|
|
- db.close()
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- time = dt.now().strftime('%Y-%m-%d %H:%M:%S')
|
|
|
|
- results_list =','.join(set(results))
|
|
|
|
- print(set(results))
|
|
|
|
- sql = "INSERT INTO %s (date,value) VALUES('%s','%s')" % (fre, dt.now().strftime('%Y-%m-%d %H:%M:%S'), results_list)
|
|
|
|
- cursor_pool.execute(sql)
|
|
|
|
- db_pool.commit()
|
|
|
|
- print(fre, '\n', '做多:', len(set(results)), set(results))
|
|
|
|
- print('做空', len(set(results_short)), set(results_short))
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- end= dt.now()
|
|
|
|
- print('总时长:', (end - start).seconds)
|
|
|
|
- elif now_date>date_afternooe_end:
|
|
|
|
- pass
|
|
|
|
- # print("HLFX_收盘了",now_date)
|
|
|
|
- # break
|
|
|