def update_all_pic(): """ 更新所有图片 :return: """ # init update pic pool = multiprocessing.Pool(process) hour_pic = { 'h': gen_kind_pic('h', pool), 'h_idx': gen_kind_pic('h_idx', pool) } day_pic = { 'd': gen_kind_pic('d', pool), 'd_idx': gen_kind_pic('d_idx', pool), 'wm': gen_kind_pic('wm', pool) } pool.close() pool.join() # 清空数据,节省管道资源 day_pic = clear_data_dic(day_pic) hour_pic = clear_data_dic(hour_pic) # 解析分析数据 day_pic = get_process_res(day_pic) hour_pic = get_process_res(hour_pic) pipe_proc.send((HOUR_UPDATE_NUM, hour_pic)) pipe_proc.send((DAY_UPDATE_NUM, day_pic)) debug_print_txt('pipe_msg_pro', '', '数据处理模块:向GUI模块发送了全部更新命令!\n', debug)
def check_single_stk_hour_idx_wx(stk_code, source='jq', debug=False): """ 打印常用指标 """ stk_df = get_k_data_JQ(stk_code, count=120, end_date=add_date_str(get_current_date_str(), 1), freq='30m') # 按升序排序 stk_df = stk_df.sort_values(by='datetime', ascending=True) """ 增加指标 'RSI5', 'RSI12', 'RSI30' 'SAR' 'slowk', 'slowd' 'upper', 'middle', 'lower' 'MOM' """ # 删除volume为空值的情况! stk_df = stk_df.loc[ stk_df.apply(lambda x: not (int(x['volume']) == 0), axis=1), :] # 计算index stk_df = add_stk_index_to_df(stk_df).tail(60) result_analysis = [] # 检查SAR sar_tail_origin = stk_df.tail(2) sar_tail = sar_tail_origin.copy() sar_tail['compare'] = sar_tail_origin.apply( lambda x: x['SAR'] - x['close'], axis=1) if sar_tail.head(1)['compare'].values[0] * sar_tail.tail( 1)['compare'].values[0] < 0: if sar_tail.tail(1)['SAR'].values[0] < sar_tail.tail( 1)['close'].values[0]: title_tmp = stk_code + ' ' + code2name( stk_code) + ' 注意 SAR 指标翻转,后续数小时可能上涨!' result_analysis.append(title_tmp) GenPic.set_background_color(bc='b_r') else: title_tmp = stk_code + ' ' + code2name( stk_code) + ' 注意 SAR 指标翻转,后续数小时可能下跌!' result_analysis.append(title_tmp) # 打印过程日志 if debug: txt_name = 'hour_index' # 打印原始数据 debug_print_txt(txt_name, stk_code, stk_df.to_string() + '\n\n') # 打印结果 debug_print_txt(txt_name, stk_code, '结果:\n' + str(result_analysis) + '\n\n') return result_analysis
def bs_judge(self): if (self.current_price - self.b_p_min > self.thh_sale) & ( (self.current_price - self.b_p_min) / self.b_p_min >= self.pcr): str_temp = "\n触发卖出网格!可以考虑卖出! \n" + self.stk_code + code2name(self.stk_code) + \ '\n当前价格:' + str(self.current_price) + \ '\n上次买入价格:' + str(self.b_p_min) + \ '\n买入网格大小:' + '%0.3f' % self.thh_buy + \ '\n卖出网格大小:' + '%0.3f' % self.thh_sale + \ '\n最小操作幅度:' + '%0.3f' % self.pcr + \ '\n上次闪动价格:' + str(self.opt_record.get_config_value('last_prompt_point'))[:4] self.bs_note(str_temp) elif (self.current_price - self.last_p < -self.thh_buy) & ( (self.current_price - self.last_p) / self.b_p_min <= -self.pcr): str_temp = "\n触发买入网格!可以考虑买入!\n" + self.stk_code + code2name(self.stk_code) + \ '\n当前价格:' + str(self.current_price) + \ '\n上次价格:' + str(self.last_p) + \ '\n买入网格大小:' + '%0.2f' % self.thh_buy + \ '\n卖出网格大小:' + '%0.2f' % self.thh_sale + \ '\n最小操作幅度:' + '%0.3f' % self.pcr + \ '\n上次闪动价格:' + str(self.opt_record.get_config_value('last_prompt_point'))[:4] self.bs_note(str_temp) else: str_ = self.stk_code + ':未触发任何警戒线!\n' self.add_msg(str_) debug_print_txt('stk_judge', self.stk_code, str_, self.debug)
def cal_rsv_rank_sub(df, m, debug=False): """ 独立这一函数,主要是为了huice :param df: :param m: :return: """ # 移动平均线+RSV(未成熟随机值) df['low_M' + str(m)] = df['low'].rolling(window=m).mean() df['high_M' + str(m)] = df['high'].rolling(window=m).mean() df['close_M' + str(m)] = df['close'].rolling(window=m).mean() debug_print_txt('rsv_cal', '', df.to_string(), debug) for idx in df.index: if (df.loc[idx, 'high_M' + str(m)] - df.loc[idx, 'low_M' + str(m)] == 0) | (df.loc[idx, 'close_M' + str(m)] - df.loc[idx, 'low_M' + str(m)] == 0): df.loc[idx, 'RSV'] = 0.5 debug_print_txt('rsv_cal', '', '最高点均值-最低点均值=0,近日可能无波动,rsv设置为0.5', True) else: df.loc[idx, 'RSV'] = (df.loc[idx, 'close_M' + str(m)] - df.loc[idx, 'low_M' + str(m)]) / ( df.loc[idx, 'high_M' + str(m)] - df.loc[idx, 'low_M' + str(m)]) return df.tail(1)['RSV'].values[0]
def cal_reseau(self, rsv): """ 调节 buy 和 sale 的threshold """ """ 实时计算网格大小 """ reseau = Reseau() earn_threshold_unit = reseau.get_single_stk_reseau(self.stk_code) stk_name = code2name(self.stk_code) rsv.msg = '' rsv_stk = rsv.get_stk_rsv(self.stk_code) if len(rsv.msg) > 0: self.add_msg(rsv.msg + '\n') self.thh_sale = earn_threshold_unit * 2 * rsv_stk self.thh_buy = earn_threshold_unit * 2 * (1 - rsv_stk) self.buy_price =self.current_price - self.thh_buy self.sell_price = self.thh_sale + self.current_price str1_ = '\nearn_threshold_unit:' + '%0.3f' % earn_threshold_unit + '\nrsv_stk:' + '%0.3f' % rsv_stk + '\nthh_buy = earn_threshold_unit * 2 * (1 - rsv_stk)' +'\n' self.add_msg(str1_) str2_ = '\nstk_code:' + self.stk_code +'\ncurrent_price:' + '%0.3f' % self.current_price + '\n' + stk_name + ' 真卖 5000 ' + '%0.3f' % self.sell_price + '\n' + stk_name + ' 真买 5000 ' + '%0.3f' % self.buy_price + '\n' self.add_msg(str2_) #self.add_note(str2_) str_ = '\n卖出网格大小:' + '%0.3f' % self.thh_sale + '\n买入网格大小:' + '%0.3f' % self.thh_buy + '\n' debug_print_txt('stk_judge', self.stk_code, str_, self.debug) self.add_msg(str_)
def print_analysis_to_win(r_dic, win, flash_flag, debug=False): for page in dict_stk_list.keys(): for stk_info in dict_stk_list[page]: analysis_result = r_dic[page][stk_info[1] + '_res'] if isinstance(analysis_result, str): # 非空说明有情况,闪烁提示 if not pd.isnull(analysis_result): win.on_update_note_tc_a(change_font_color(analysis_result + '\n')) flash_flag = True elif isinstance(analysis_result, list): # 去空值 analysis_result = list(filter(lambda x: not pd.isnull(x), analysis_result)) # 非空说明有情况,闪烁提示 if not pd.isnull(analysis_result): flash_flag = True for str_ in analysis_result: win.on_update_note_tc_a(change_font_color(str_ + '\n')) else: debug_print_txt('hour_analysis', '', '不识别的数据格式', debug) debug_print_txt('hour_analysis', '', str(analysis_result), debug) return flash_flag
def on_timer_ctrl(win, debug=False): """ 控制台定时器响应函数 :return: """ # 清屏 wx.PostEvent(win, ResultEvent(id=MSG_UPDATE_ID_S, data='检测时间:' + get_current_datetime_str() + '\n\n')) # 不在交易时间不使能定时器 if (not is_in_trade_time()) & (not debug): wx.PostEvent(win, ResultEvent( id=MSG_UPDATE_ID_A, data='控制台定时器:当前不属于交易时间!\n')) return buy_stk_list = list(set(read_config()['buy_stk'] + read_config()['index_stk'])) # 局部变量 note_list = [] # 对stk进行检查 for stk in buy_stk_list: str_gui = judge_single_stk(stk_code=stk, stk_amount_last=400, qq='', gui=True, debug=True) if len(str_gui['note']): note_list.append(str_gui['note']) # 打印流水信息 if len(str_gui['msg']): wx.PostEvent(win, ResultEvent( id=MSG_UPDATE_ID_A, data=str_gui['msg'])) # 打印日志 debug_print_txt('timer_ctrl_log', 'total', get_current_datetime_str() + ':\n' + '提示消息:\n' + str(note_list) + '\n' + '流水消息:\n' + str(str_gui['msg'])) # 根据情况打印提示信息,并闪动 if len(note_list): # 清屏 wx.PostEvent(win, ResultEvent( id=NOTE_UPDATE_ID_S, data='检测时间:' + get_current_datetime_str() + '\n\n')) # 打印提示 for note in note_list: wx.PostEvent(win, ResultEvent( id=NOTE_UPDATE_ID_A, data=change_font_color(note))) # 闪动图标提醒 wx.PostEvent(win, ResultEvent( id=FLASH_WINDOW_ID, data=None))
def generate_trade_records(self): #debug_print_txt('main_log', '', self.stk_code + ' inside generate_trade_records \n',True) str2_ = '\nstk_code:' + self.stk_code +'\ncurrent_price:' + '%0.3f' % self.current_price + '\n卖出:' + '%0.3f' % self.sell_price + '\n买入:' + '%0.3f' % self.buy_price + '\n' self.add_msg(str2_) debug_print_txt('main_log', '', str2_ + ' end of generate_trade_records \n',True) buy_input_str = self.stk_code + " 买入 5000 " + '%0.3f' % self.buy_price sell_input_str = self.stk_code + " 卖出 5000 " + '%0.3f' % self.sell_price self.prepare_trade_record(buy_input_str, easytrader_record_file_url) self.prepare_trade_record(sell_input_str, easytrader_record_file_url)
def data_process_callback(pipe_proc, debug=False, process=6): # init update pic pool = multiprocessing.Pool(process) hour_pic = { 'h': gen_kind_pic('h', pool), 'h_idx': gen_kind_pic('h_idx', pool) } day_pic = { 'd': gen_kind_pic('d', pool), 'd_idx': gen_kind_pic('d_idx', pool), 'wm': gen_kind_pic('wm', pool) } pool.close() pool.join() # 清空数据,节省管道资源 day_pic = clear_data_dic(day_pic) hour_pic = clear_data_dic(hour_pic) # 解析分析数据 day_pic = get_process_res(day_pic) hour_pic = get_process_res(hour_pic) pipe_proc.send((HOUR_UPDATE_NUM, hour_pic)) pipe_proc.send((DAY_UPDATE_NUM, day_pic)) # 循环 while True: global last_upt_t upt_flag, last_upt_t = is_time_h_macd_update(last_upt_t) if upt_flag | debug: debug_print_txt('main_log', '', '\n开始半小时分析和更新!') # update hour pic pool = multiprocessing.Pool(process) hour_pic = { 'h': gen_kind_pic('h', pool), 'h_idx': gen_kind_pic('h_idx', pool) } pool.close() pool.join() # 清空数据,节省管道资源 & 解析分析数据 hour_pic = clear_data_dic(hour_pic) hour_pic = get_process_res(hour_pic) pipe_proc.send((HOUR_UPDATE_NUM, hour_pic)) debug_print_txt('main_log', '', '\n完成半小时分析和更新!') time.sleep(5)
def cal_stk_rsv_rank(self, stk_code, m_days, history_length=400): df = get_k_data_JQ(stk_code, count=history_length, end_date=get_current_date_str()) debug_print_txt('rsv_cal', '', code2name(stk_code) + '开始计算rsv:', True) rsv = self.cal_rsv_rank_sub(df, m_days) debug_print_txt('rsv_cal', '', '最终rsv:' + '%0.3f' % rsv, True) return rsv
def analysis_print(pipe_data, win, kind, debug=False): """-------------------- 进行判断 ------------------------""" debug_print_txt('pipe_msg_pro', '', '\n收到' + str(kind) + '分析数据,开始处理!\n', debug) flash_flag = False # 向提示框打印提示 for key in pipe_data[1]: flash_flag = print_analysis_to_win(pipe_data[1][key], win, flash_flag, debug) if flash_flag: win.flash_window() debug_print_txt('pipe_msg_pro', '', '\n' + str(kind) + '判断完成!\n', debug)
def check_single_stk_hour_idx_sub(stk_df, stk_code, debug=False): """ 打印常用指标 """ # 按升序排序 stk_df = stk_df.sort_values(by='datetime', ascending=True) """ 增加指标 'RSI5', 'RSI12', 'RSI30' 'SAR' 'slowk', 'slowd' 'upper', 'middle', 'lower' 'MOM' """ result_analysis = [] # 检查SAR sar_tail_origin = stk_df.tail(2) sar_tail = sar_tail_origin.copy() sar_tail['compare'] = sar_tail_origin.apply( lambda x: x['SAR'] - x['close'], axis=1) if sar_tail.head(1)['compare'].values[0] * sar_tail.tail( 1)['compare'].values[0] < 0: if sar_tail.tail(1)['SAR'].values[0] < sar_tail.tail( 1)['close'].values[0]: title_tmp = stk_code + ' ' + code2name( stk_code) + ' 注意 SAR 指标翻转,后续数小时可能上涨!' result_analysis.append(title_tmp) GenPic.set_background_color(bc='b_r') else: title_tmp = stk_code + ' ' + code2name( stk_code) + ' 注意 SAR 指标翻转,后续数小时可能下跌!' result_analysis.append(title_tmp) # 打印过程日志 if debug: txt_name = 'hour_index' # 打印原始数据 debug_print_txt(txt_name, stk_code, stk_df.to_string() + '\n\n') # 打印结果 debug_print_txt(txt_name, stk_code, '结果:\n' + str(result_analysis) + '\n\n') return result_analysis
def hour_analysis(pipe_master): """ 小时监测(闲置) :return: """ debug_print_txt('main_log', '', 'begin hour_analysis \n', True) debug_print_txt('hour_analysis', '', '\n' + '进入小时判断' + '\n') for stk in list( set(read_config()['buy_stk'] + read_config()['concerned_stk'] + read_config()['index_stk'])): # 阈值条件不满足,该stk直接pass if not read_opt_json(stk, opt_record_file_url)['has_flashed_flag']: pipe_master.send( (MSG_UPDATE_NUM_A, code2name(stk) + '阈值条件不满足,不进行拐点检测\n')) debug_print_txt('hour_analysis', '', '\n' + code2name(stk) + '阈值条件不满足,不进行拐点检测\n') continue hour_idx_str = check_single_stk_hour_idx_wx(stk, source='jq', debug=True) if len(hour_idx_str): for str_tmp in hour_idx_str: pipe_master.send( (NOTE_UPDATE_NUM_A, change_font_color(str_tmp))) # 打印日志 debug_print_txt('hour_analysis', '', '\n' + str(hour_idx_str)) # flash pipe_master.send((FLASH_WINDOW_NUM, None))
def bs_note(self, str_temp): debug_print_txt('stk_judge', self.stk_code, str_temp + '\n在灯神进行bs操作之前,此stk不再进行阈值判断\n', self.debug) if not self.has_flashed_flag: self.add_note(str_temp) # 设置上次闪动价格 self.opt_record.set_config_value('last_prompt_point', self.current_price) # 除非有bs操作,否则不再提示 self.set_has_flashed_flag(opt_record_file_url, self.stk_code, value=True) else: self.add_msg(str_temp)
def get_last_price(self): # 读取上次p和b操作中的最小p,备用 self.last_p = self.opt_record_stk['p_last'] self.b_p_min = np.min([x['p'] for x in self.opt_record_stk['b_opt']]) str_ = '\n上次操作价格:' + str(self.last_p) + \ '\n最小买入价格:' + str(self.b_p_min) + \ '\n买入-波动率:' + '%0.3f' % (100.0 * (self.current_price - self.last_p) / self.last_p) + '%' + \ '\n卖出-波动率:' + '%0.3f' % (100.0 * (self.current_price - self.b_p_min) / self.b_p_min) + '%' + \ '\n买入-波动:' + '%0.2f' % (self.current_price - self.last_p) + \ '\n卖出-波动:' + '%0.2f' % (self.current_price - self.b_p_min) + \ '\n上次闪动价格:' + str(self.opt_record.get_config_value('last_prompt_point'))[:4] debug_print_txt('stk_judge', self.stk_code, str_, self.debug) self.add_msg(str_ + '\n')
def update_rsv_record(self): jq_login() try: code_list = list(set(read_config()['buy_stk'] + read_config()['concerned_stk'] + read_config()['index_stk'])) # global RSV_Record for stk in code_list: RSV_Record[stk] = cal_rsv_rank(stk, 5) except Exception as e: print(str(e)) self.p_ctrl.m_textCtrlMsg.AppendText('RSV数据更新失败!原因:\n' + str(e) + '\n') debug_print_txt('main_log', '', 'RSV数据更新失败!原因:\n' + str(e) + '\n') finally: jq.logout()
def fluctuate_judge(self): l_pp = self.opt_record.get_config_value('last_prompt_point') c_p = self.current_price thh_b = self.thh_buy thh_s = self.thh_sale str_ = '\n\n------------------------------------------------------------\n' \ 'last_pp:%s current_price:%s b_thh:%s s_thh:%s' % ( str(l_pp)[:4], str(c_p)[:4], str(thh_b)[:4], str(thh_s)[:4]) debug_print_txt('fluctuate_judge', self.stk_code, str_ + '\n', self.debug) # 若lpp为None,则将当前p设置为lpp,并返回 if pd.isnull(self.opt_record.get_config_value('last_prompt_point')) | \ (self.opt_record.get_config_value('last_prompt_point') == -1): self.opt_record.set_config_value('last_prompt_point', self.current_price) debug_print_txt('fluctuate_judge', self.stk_code, 'Result: Last_prompt_opint is null or -1' + '\n', self.debug) return elif (self.current_price - self.opt_record.get_config_value('last_prompt_point') > self.thh_sale) & \ (self.opt_record.get_config_value('last_prompt_point') != -1): str_temp = "当前价格距离上次提示的价格的上涨幅度超过卖出网格!\n " + self.stk_code + code2name(self.stk_code) + \ '\n当前价格:' + str(self.current_price) + \ '\n上次买入价格:' + str(self.b_p_min) + \ '\n买入网格大小:' + '%0.3f' % self.thh_buy + \ '\n卖出网格大小:' + '%0.3f' % self.thh_sale + \ '\n最小操作幅度:' + '%0.3f' % self.pcr + \ '\n上次闪动价格:' + str(self.opt_record.get_config_value('last_prompt_point'))[:4] self.add_note(str_temp) debug_print_txt('fluctuate_judge', self.stk_code, 'Result: fluctuate is triggered for sale!' + '\n', self.debug) # 设置上次闪动价格 self.opt_record.set_config_value('last_prompt_point', self.current_price) elif (self.current_price - self.opt_record.get_config_value('last_prompt_point') < -self.thh_buy) & \ (self.opt_record.get_config_value('last_prompt_point') != -1): str_temp = "当前价格距离上次提示的价格的下跌幅度超过买入网格!\n" + self.stk_code + code2name(self.stk_code) + \ '\n当前价格:' + str(self.current_price) + \ '\n上次价格:' + str(self.last_p) + \ '\n买入网格大小:' + '%0.2f' % self.thh_buy + \ '\n卖出网格大小:' + '%0.2f' % self.thh_sale + \ '\n最小操作幅度:' + '%0.3f' % self.pcr + \ '\n上次闪动价格:' + str(self.opt_record.get_config_value('last_prompt_point'))[:4] self.add_note(str_temp) debug_print_txt('fluctuate_judge', self.stk_code, 'Result: fluctuate is triggered for buy!' + '\n', self.debug) # 设置上次闪动价格 self.opt_record.set_config_value('last_prompt_point', self.current_price)
def cal_reseau(self, rsv): """ 调节 buy 和 sale 的threshold """ """ 实时计算网格大小 """ reseau = Reseau() earn_threshold_unit = reseau.get_single_stk_reseau(self.stk_code) rsv.msg = '' rsv_stk = rsv.get_stk_rsv(self.stk_code) if len(rsv.msg) > 0: self.add_msg(rsv.msg + '\n') self.thh_sale = earn_threshold_unit * 2 * rsv_stk self.thh_buy = earn_threshold_unit * 2 * (1 - rsv_stk) str_ = '\n卖出网格大小:' + '%0.3f' % self.thh_sale + '\n买入网格大小:' + '%0.3f' % self.thh_buy + '\n' debug_print_txt('stk_judge', self.stk_code, str_, self.debug) self.add_msg(str_)
def update_rsv_record(self): try: code_list = list( set(read_config()['buy_stk'] + read_config()['concerned_stk'] + read_config()['index_stk'])) # global RSV_Record for stk in code_list: self.rsv[stk] = self.cal_stk_rsv_rank(stk, 5) return True except Exception as e: print(str(e)) self.msg = 'RSV数据更新失败!原因:\n' + str(e) debug_print_txt('main_log', '', 'RSV数据更新失败!原因:\n' + str(e) + '\n') return False
def update_hour_pic(): debug_print_txt('main_log', '', '\n开始半小时分析和更新!') # update hour pic pool = multiprocessing.Pool(process) hour_pic = { 'h': gen_kind_pic('h', pool), 'h_idx': gen_kind_pic('h_idx', pool) } pool.close() pool.join() # 清空数据,节省管道资源 & 解析分析数据 hour_pic = clear_data_dic(hour_pic) hour_pic = get_process_res(hour_pic) pipe_proc.send((HOUR_UPDATE_NUM, hour_pic)) debug_print_txt('main_log', '', '\n完成半小时分析和更新!')
def on_key_down(self, event): key_code = event.GetKeyCode() if key_code == wx.WXK_F1: print('检测到F1按下!') try: # 创建灯神,并显示 ds = DengShen(self, '灯神') ds.Show() except Exception as e: self.on_update_note_tc_a('灯神异常退出! 原因:\n' + str(e)) self.flash_window() debug_print_txt('main_log', '', '灯神异常退出! 原因:\n' + str(e)) finally: event.Skip() elif key_code == wx.WXK_F2: print('检测到F2按下!') try: # 创建realtrader,并显示 #rt = RealTrade(self, 'easytrader') #rt.Show() #rt.input_analysis("查看b记录 东华软件") self.on_update_note_tc_a('call easytrader real trading now!\n') #rt.buy("600095", 5000, 10.22) #rt.sell("600095", 5000, 10.83) rt.sendout_trade_record(easytrader_record_file_url) except Exception as e: self.on_update_note_tc_a('realtrade异常退出! 原因:\n' + str(e)) self.flash_window() debug_print_txt('main_log', '', 'realtrade异常退出! 原因:\n' + str(e)) finally: event.Skip() else: event.Skip()
def check_status(self): #result = self.user.balance() #print(result) #debug_print_txt('main_log', '', str(result[0]) + ' \n inside check_status \n',True) return_str = [] today_opt = [] return_str = self.user.position # Don't add (), otherwise will cause error! pprint.pprint(return_str) today_opt = self.user.today_entrusts print("today_opt:" + str(today_opt)) self.today_done = self.user.today_trades print("today_done:" + str(self.today_done)) length = len(return_str) for i in range(length): stk_code = return_str[i]['证券代码'] amount = return_str[i]['可用余额'] #print(stk_code) #print(amount) self.current_record[stk_code] = {} self.current_record[stk_code]['usable_balance'] = amount pprint.pprint(self.current_record) #print(self.current_record.keys()) debug_print_txt('main_log', '', str(return_str) + ' \n inside check_status \n', True) debug_print_txt( 'main_log', '', str(self.current_record) + ' \n inside check_status \n', True) debug_print_txt('main_log', '', str(today_opt) + ' \n inside check_status \n', True) return self.current_record
def get_opt_record_json(self): """ 判断该股票的opt_record配置是否正常 :return: """ # 如果没有相应的json文件,不进行判断,直接返回 if pd.isnull(self.opt_record_stk) | (not bool(self.opt_record_stk)): str_ = code2name(self.stk_code) + '没有历史操作记录,不进行阈值判断!\n' debug_print_txt('stk_judge', self.stk_code, '函数 judge_single_stk:' + str_, self.debug) self.add_msg(str_) return False elif len(self.opt_record_stk['b_opt']) == 0: str_ = code2name(self.stk_code) + '没有历史操作记录,不进行阈值判断!\n' debug_print_txt('stk_judge', self.stk_code, '函数 judge_single_stk:' + str_, self.debug) self.add_msg(str_) return False else: return True
def get_current_price(self): """ 获取实时价格,返回True表示成功获取价格 :return: """ try: current_price = get_current_price_JQ(self.stk_code) str_ = '实时价格:' + str(current_price) + '\n' debug_print_txt('stk_judge', self.stk_code, str_, self.debug) self.add_msg(str_) if current_price == 0.0: self.add_msg(self.stk_code + 'price==0.0! 返回\n') return False else: self.current_price = current_price return True except Exception as e_: self.add_msg(self.stk_code + '获取实时price失败!\n' + str(e_) + '\n') return False
def add_rsv(df, m, debug=False): """ 向df中增加rsv数据 :return: """ # 移动平均线+RSV(未成熟随机值) df['low_M' + str(m)] = df['low'].rolling(window=m).mean() df['high_M' + str(m)] = df['high'].rolling(window=m).mean() df['close_M' + str(m)] = df['close'].rolling(window=m).mean() debug_print_txt('rsv_cal', '', df.to_string(), debug) for idx in df.index: if (df.loc[idx, 'high_M' + str(m)] - df.loc[idx, 'low_M' + str(m)] == 0) | ( df.loc[idx, 'close_M' + str(m)] - df.loc[idx, 'low_M' + str(m)] == 0): df.loc[idx, 'RSV'] = 0.5 debug_print_txt('rsv_cal', '', '最高点均值-最低点均值=0,近日可能无波动,rsv设置为0.5', debug) else: df.loc[idx, 'RSV'] = (df.loc[idx, 'close_M' + str(m)] - df.loc[idx, 'low_M' + str(m)]) / ( df.loc[idx, 'high_M' + str(m)] - df.loc[idx, 'low_M' + str(m)]) return df
# encoding=utf-8
# encoding=utf-8
def pipe_msg_process(win, pipe_to_master, debug=False): while True: pipe_data = pipe_to_master.recv() debug_print_txt( 'pipe_msg_pro', '', '\n\n==========================================\n收到信息,进行判断!\n', debug) """ ------------------ 管道处理机 ---------------------- """ if pipe_data[0] == HOUR_UPDATE_NUM: debug_print_txt('pipe_msg_pro', '', '\n收到小时更新图片,开始更新!\n', debug) win.on_update_msg_tc_a('开始打印小时图片...\n') pic = load_local_pic_for_wx(pipe_data[1]) win.on_update_hour_pic(pic) win.on_update_msg_tc_a('小时图片打印完成!\n') debug_print_txt('pipe_msg_pro', '', '\n小时图片更新完成!\n', debug) """-------------------- 打印判断 ------------------------""" analysis_print(pipe_data, win, '小时线', debug) # day 图 更新处理 elif pipe_data[0] == DAY_UPDATE_NUM: debug_print_txt( 'pipe_msg_pro', '', '\n收到日线图片更新命令!具体内容如下:\n\n%s \n\n' % str(pipe_data[1]), debug) win.on_update_msg_tc_a('开始打印日线图片...\n') pic = load_local_pic_for_wx(pipe_data[1]) win.on_update_day_pic(pic) win.on_update_msg_tc_a('日线图片打印完成!\n') debug_print_txt('pipe_msg_pro', '', '\n日线图片更新完成!\n', debug) """-------------------- 打印判断 ------------------------""" analysis_print(pipe_data, win, '日线', debug) # 追加msg elif pipe_data[0] == MSG_UPDATE_NUM_A: win.on_update_msg_tc_a(pipe_data[1]) # 设置msg elif pipe_data[0] == MSG_UPDATE_NUM_S: win.on_update_msg_tc_s(pipe_data[1]) # 追加note elif pipe_data[0] == NOTE_UPDATE_NUM_A: win.on_update_note_tc_a(pipe_data[1]) # 设置note elif pipe_data[0] == NOTE_UPDATE_NUM_S: win.on_update_note_tc_s(pipe_data[1]) # 闪烁 elif pipe_data[0] == FLASH_WINDOW_NUM: debug_print_txt('pipe_msg_pro', '', '收到闪动命令,闪动窗口!\n', debug) win.flash_window() # 更新上次时间 elif pipe_data[0] == LAST_TIME_UPDATE_NUM: win.on_update_last_time() # CPT 初始化 elif pipe_data[0] == INIT_CPT_NUM: debug_print_txt('pipe_msg_pro', '', '\n收到初始化命令,开始初始化!\n', debug) win.on_update_msg_tc_a('正在初始化图片...\n'), win.on_update_msg_tc_a(note_init_pic), win.on_init_pic(pipe_data[1]) debug_print_txt('pipe_msg_pro', '', '\n图片初始化完成!\n', debug) # 延时两秒 time.sleep(2)
def bs_info_print(self): """ 打印bs信息 :return: """ # 打印日志 debug_print_txt('stk_judge', self.stk_code, '读取的最小波动率:' + str(self.pcr) + '\n', self.debug) debug_print_txt('stk_judge', self.stk_code, '上次闪动价格:' + str(self.pcr) + '\n', self.debug) debug_print_txt('stk_judge', self.stk_code, '允许阈值判断标志位(True为允许):' + str(self.has_flashed_flag) + '\n', self.debug) debug_print_txt('stk_judge', self.stk_code, '判断是否可以卖出:\ncurrent_price - b_p_min > thh_sale:' + str( self.current_price - self.b_p_min > self.thh_sale) + '\n', self.debug) debug_print_txt('stk_judge', self.stk_code, '(current_price - b_p_min) / b_p_min >= pcr:' + str( (self.current_price - self.b_p_min) / self.b_p_min >= self.pcr) + '\n', self.debug) debug_print_txt('stk_judge', self.stk_code, '判断是否可以买入:\ncurrent_price - last_p < -thh_buy:' + str( self.current_price - self.last_p < -self.thh_buy) + '\n', self.debug) debug_print_txt('stk_judge', self.stk_code, '(current_price - last_p) / b_p_min <= -pcr:' + str( (self.current_price - self.last_p) / self.b_p_min <= -self.pcr) + '\n', self.debug)
def data_process_callback(pipe_proc, debug=False, process=6): def update_all_pic(): """ 更新所有图片 :return: """ # init update pic pool = multiprocessing.Pool(process) hour_pic = { 'h': gen_kind_pic('h', pool), 'h_idx': gen_kind_pic('h_idx', pool) } day_pic = { 'd': gen_kind_pic('d', pool), 'd_idx': gen_kind_pic('d_idx', pool), 'wm': gen_kind_pic('wm', pool) } pool.close() pool.join() # 清空数据,节省管道资源 day_pic = clear_data_dic(day_pic) hour_pic = clear_data_dic(hour_pic) # 解析分析数据 day_pic = get_process_res(day_pic) hour_pic = get_process_res(hour_pic) pipe_proc.send((HOUR_UPDATE_NUM, hour_pic)) pipe_proc.send((DAY_UPDATE_NUM, day_pic)) debug_print_txt('pipe_msg_pro', '', '数据处理模块:向GUI模块发送了全部更新命令!\n', debug) def update_hour_pic(): debug_print_txt('main_log', '', '\n开始半小时分析和更新!') # update hour pic pool = multiprocessing.Pool(process) hour_pic = { 'h': gen_kind_pic('h', pool), 'h_idx': gen_kind_pic('h_idx', pool) } pool.close() pool.join() # 清空数据,节省管道资源 & 解析分析数据 hour_pic = clear_data_dic(hour_pic) hour_pic = get_process_res(hour_pic) pipe_proc.send((HOUR_UPDATE_NUM, hour_pic)) debug_print_txt('main_log', '', '\n完成半小时分析和更新!') update_all_pic() date_last = get_current_date_str() global last_upt_t # 循环 while True: # 次日更新全部图片 if get_current_date_str() != date_last: debug_print_txt('pipe_msg_pro', '', '数据处理模块:新的一天,全部更新pic\n', debug) update_all_pic() date_last = get_current_date_str() last_upt_t = 0 time.sleep(5) # 更新半小时图片 upt_flag, last_upt_t = is_time_h_macd_update(last_upt_t) if upt_flag: update_hour_pic() time.sleep(5)