"300380", "300399", "300117", "000029", "300372", ] #'300372' 创业板第一退市 # except_stocks = ['000029','300372'] #'000029' 数据错误:11.4.0 # given_codes = ['300128', '002288', '002156', '300126','300162','002717','002799','300515','300516','600519', # '000418','002673','600060','600887','000810','600115','600567','600199','000596','000538','002274','600036','600030','601398'] given_codes = [] all_code, latest_time = pds.get_dir_latest_modify_time("c:/hist/day/data/") print("latest_time= ", latest_time) # easyhistory.init('D', export='csv', path="C:/hist",stock_codes=given_codes) easyhistory.update(path="C:/hist", stock_codes=given_codes) print("First update completed: ", datetime.datetime.now()) last_year_date = datetime.datetime.now() + datetime.timedelta(days=-365) date_str = last_year_date.strftime("%Y-%m-%d") mybt.back_test(k_num=date_str, given_codes=[], except_stocks=except_stock, type="stock") print("First back_test completed: ", datetime.datetime.now()) updated_date_count = 1 while True: # this_time=datetime.datetime.now() # hour=this_time.hour # minute=this_time.minute stock_sql = pds.StockSQL() last_year_date = datetime.datetime.now() + datetime.timedelta(days=-365) date_str = last_year_date.strftime("%Y-%m-%d") sleep_seconds = 60 if tt.is_trade_date():
import easyhistory easyhistory.update()
}) stock_sql.update_sql_position(users={ 'account': '38736', 'broker': 'yh', 'json': 'yh1.json' }) hold_df, hold_stocks = stock_sql.get_hold_stocks( accounts=['36005', '38736']) print('hold_stocks=', hold_stocks) print(hold_df) elif update_type == 'stock': #从新浪 qq网页更新股票 #easyhistory.init(path="C:/hist",stock_codes=hold_stocks) #easyhistory.update(path="C:/hist",stock_codes=hold_stocks) #easyhistory.init(path="C:/hist")#,stock_codes=all_codes) easyhistory.update(path="C:/hist", stock_codes=all_stocks) #+b_stock) else: pass """ update_data = stock_sql.get_table_update_time() print('last_position_update_time=',update_data['hold']) print('last_index_update_time=',update_data['sh']) print(stock_sql.hold) """ #""" """ print(update_data) broker = 'yh' need_data = 'yh.json' user = easytrader.use('yh') user.prepare('yh.json')
def update_k_data(update_type='yh'): stock_sql = StockSQL() hold_df, hold_stocks, available_sells = stock_sql.get_hold_stocks( accounts=['36005', '38736']) print('hold_stocks=', hold_stocks) print('available_sells=', available_sells) #pds.get_exit_price(hold_codes=['002521'],data_path='C:/中国银河证券海王星/T0002/export/' ) #print(hold_df) """从新浪 qq网页更新股票""" #easyhistory.init(path="C:/hist",stock_codes=hold_stocks) #easyhistory.update(path="C:/hist",stock_codes=hold_stocks) """从银河更新股票""" #for stock in hold_stocks: #pds.update_one_stock(symbol=stock,realtime_update=False,dest_dir='C:/hist/day/data/', force_update_from_YH=False) # pass #stock_sql.update_sql_position(users={'account':'36005','broker':'yh','json':'yh.json'}) #stock_sql.update_sql_position(users={'account':'38736','broker':'yh','json':'yh1.json'}) #hold_df,hold_stocks,available_sells = stock_sql.get_hold_stocks(accounts = ['36005', '38736']) #print('hold_stocks=',hold_stocks) #print(hold_df) #pds.update_one_stock(symbol='sh',force_update=False) #pds.update_codes_from_YH(realtime_update=False) """从银河更新指数""" #pds.update_codes_from_YH(realtime_update=False,dest_dir='C:/hist/day/data/', force_update_from_YH=True) #pds.update_codes_from_YH(realtime_update=False,dest_dir='C:/hist/day/data/', force_update_from_YH=True) #indexs = ['zxb', 'sh50', 'hs300', 'sz300', 'cyb', 'sz', 'zx300', 'sh'] """ potential_df = stock_sql.query_data(table='potential',fields='category_id,code,valid,name',condition='valid>=1') print(potential_df) lanchou_df = potential_df[potential_df['category_id']==1] print(lanchou_df['code'].values.tolist()) """ #""" last_date_str = pds.tt.get_last_trade_date(date_format='%Y/%m/%d') latest_date_str = pds.tt.get_latest_trade_date(date_format='%Y/%m/%d') next_date_str = pds.tt.get_next_trade_date(date_format='%Y/%m/%d') print('last_date = ', last_date_str) print('latest_date_str=', latest_date_str) print('next_date_str=', next_date_str) indexs, funds, b_stock, all_stocks = pds.get_different_symbols() if update_type == 'index': #从银河更新指数 #stock_sql.update_sql_index(index_list=['sh','sz','zxb','cyb','hs300','sh50'],force_update=False) #stock_sql.download_hist_as_csv(indexs = ['sh','sz','zxb','cyb','hs300','sh50'],dir='C:/hist/day/data/') pds.update_codes_from_YH(indexs, realtime_update=False, dest_dir='C:/hist/day/data/', force_update_from_YH=True) elif update_type == 'fund': #从银河更新基金 all_codes = pds.get_all_code(hist_dir='C:/中国银河证券海王星/T0002/export/') funds = [] for code in all_codes: if code.startswith('1') or code.startswith('5'): funds.append(code) pds.update_codes_from_YH(funds, realtime_update=False, dest_dir='C:/hist/day/data/', force_update_from_YH=True) elif update_type == 'position': #更新仓位 #stock_sql.update_sql_position(users={'36005':{'broker':'yh','json':'yh.json'},'38736':{'broker':'yh','json':'yh1.json'}}) stock_sql.update_sql_position(users={ 'account': '36005', 'broker': 'yh', 'json': 'yh.json' }) stock_sql.update_sql_position(users={ 'account': '38736', 'broker': 'yh', 'json': 'yh1.json' }) hold_df, hold_stocks, available_sells = stock_sql.get_hold_stocks( accounts=['36005', '38736']) print('hold_stocks=', hold_stocks) print(hold_df) elif update_type == 'stock': #从新浪 qq网页更新股票 #easyhistory.init(path="C:/hist",stock_codes=hold_stocks) #easyhistory.update(path="C:/hist",stock_codes=hold_stocks) #easyhistory.init(path="C:/hist")#,stock_codes=all_codes) easyhistory.update(path="C:/hist", stock_codes=all_stocks) #+b_stock) elif update_type == 'YH' or update_type == 'yh': all_codes = pds.get_all_code(hist_dir='C:/中国银河证券海王星/T0002/export/') #all_codes = ['999999', '000016', '399007', '399008', '399006', '000300', '399005', '399001', # '399004','399106','000009','000010','000903','000905'] #all_codes=['300162'] """ code_list_dict = seprate_list(all_codes,4) print('code_list_dict=',code_list_dict) print('Parent process %s.' % os.getpid()) #update_yh_hist_data(codes_list=[],process_id=0) p = Pool() for i in range(4): p.apply_async(update_yh_hist_data, args=(code_list_dict[i],i)) print('Waiting for all subprocesses done...') p.close() p.join() print('All subprocesses done.') """ all_count = len(all_codes) latest_count = 0 count = 0 pc0 = 0 for code in all_codes: df, has_tdx_last_string = pds.get_yh_raw_hist_df(code, latest_count=None) count = count + 1 pc = round(round(count, 2) / all_count, 2) * 100 if pc > pc0: print('count=', count) print('完成数据更新百分之%s' % pc) pc0 = pc if len(df) >= 1: last_code_trade_date = df.tail(1).iloc[0].date if last_code_trade_date == latest_date_str: latest_count = latest_count + 1 latest_update_rate = round(round(latest_count, 2) / all_count, 2) print('latest_update_rate=', latest_update_rate) #""" else: pass
'300240', '603789', '300433', '300295', '002544', '300395', '002605', '300403', '002225', '002297', '600572', '000333', '300413', '002285', '002312', '002509', '600305', '002631', '603718', '002496', '002600', '603198', '002444', '300238', '300467', '300028', '300033', '300126', '300135', '300143', '300380', '300399', '300117', '000029', '300372' ] #'300372' 创业板第一退市 #except_stocks = ['000029','300372'] #'000029' 数据错误:11.4.0 #given_codes = ['300128', '002288', '002156', '300126','300162','002717','002799','300515','300516','600519', # '000418','002673','600060','600887','000810','600115','600567','600199','000596','000538','002274','600036','600030','601398'] given_codes = [] all_code, latest_time = pds.get_dir_latest_modify_time('c:/hist/day/data/') print('latest_time= ', latest_time) #easyhistory.init('D', export='csv', path="C:/hist",stock_codes=given_codes) easyhistory.update(path="C:/hist", stock_codes=given_codes) print('First update completed: ', datetime.datetime.now()) last_year_date = datetime.datetime.now() + datetime.timedelta(days=-365) date_str = last_year_date.strftime('%Y-%m-%d') mybt.back_test(k_num=date_str, given_codes=[], except_stocks=except_stock, type='stock') print('First back_test completed: ', datetime.datetime.now()) updated_date_count = 1 while True: #this_time=datetime.datetime.now() #hour=this_time.hour #minute=this_time.minute stock_sql = pds.StockSQL() last_year_date = datetime.datetime.now() + datetime.timedelta(
import easyhistory easyhistory.update('D', export='csv', path='out')
funds.append(code) pds.update_codes_from_YH(funds,realtime_update=False,dest_dir='C:/hist/day/data/', force_update_from_YH=True) elif update_type == 'position': #更新仓位 #stock_sql.update_sql_position(users={'36005':{'broker':'yh','json':'yh.json'},'38736':{'broker':'yh','json':'yh1.json'}}) stock_sql.update_sql_position(users={'account':'36005','broker':'yh','json':'yh.json'}) stock_sql.update_sql_position(users={'account':'38736','broker':'yh','json':'yh1.json'}) hold_df,hold_stocks,available_sells = stock_sql.get_hold_stocks(accounts = ['36005', '38736']) print('hold_stocks=',hold_stocks) print(hold_df) elif update_type == 'stock': #从新浪 qq网页更新股票 #easyhistory.init(path="C:/hist",stock_codes=hold_stocks) #easyhistory.update(path="C:/hist",stock_codes=hold_stocks) #easyhistory.init(path="C:/hist")#,stock_codes=all_codes) easyhistory.update(path="C:/hist",stock_codes=all_stocks)#+b_stock) elif update_type == 'YH' or update_type == 'yh': all_codes = pds.get_all_code(hist_dir='C:/中国银河证券海王星/T0002/export/') #all_codes = ['999999', '000016', '399007', '399008', '399006', '000300', '399005', '399001', # '399004','399106','000009','000010','000903','000905'] #all_codes=['300162'] for code in all_codes: pds.get_yh_raw_hist_df(code,latest_count=None) else: pass """ update_data = stock_sql.get_table_update_time() print('last_position_update_time=',update_data['hold']) print('last_index_update_time=',update_data['sh']) print(stock_sql.hold)