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 callback_gui(): towho = '影子2' buy_stk_list = read_config()['buy_stk'] + read_config()['concerned_stk'] for stk in buy_stk_list: str_gui = judge_single_stk(stk_code=stk, stk_amount_last=400, qq=towho, gui=True)
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 update_middle_period_hour_data(): stk_list = read_config()['buy_stk'] + read_config()['concerned_stk'] # stk_list = readConfig()['buy_stk'] # 获取stk的小时数据 result = {} for stk in stk_list: df_hour = get_k_data_JQ(stk, count=None, start_date=add_date_str(get_current_date_str(), -60), freq='60m') result[stk] = list(df_hour['close'].values) with open(data_dir+'middlePeriodHourData.json', 'w') as f: json.dump(result, f)
def sendConcernedStkPicToSelf_T(): """ 将自己关心的数据打印出图,发送到qq :return: """ towho = '影子2' send_qq(towho, '以下是已入的stk的形势图:') stk_buy = read_config()['buy_stk'] for x in stk_buy + ['sh', 'sz', 'cyb']: df = get_k_data_JQ(x, 400) fig, _, attention = genStkPicForQQ(df, x) if attention: send_pic_qq(towho, fig) send_W_M_MACD(x, towho) plt.close() # 打印第二张套图 fig, _, attention = genStkIdxPicForQQ(df, x) if attention: send_pic_qq(towho, fig) plt.close()
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 sendConcernedStkPicToSelf_V2(): """ 将自己关心的数据打印出图,发送到qq 相较于之前版本,本次改进为: 1、使用json文件中的code列表代替数据库中的列表 2、进行判断,出发发送条件再予以发送 :return: """ towho = '影子2' send_qq(towho, '以下是已入的stk的形势图:') code_list = read_config()['buy_stk'] for x in code_list + ['sh', 'sz', 'cyb']: df = get_k_data_JQ(x, 400) fig, _ = genStkPicForQQ(df) plt.title(str(x)) send_pic_qq(towho, fig) # plt.show() plt.close() fig, _ = genStkIdxPicForQQ(df) plt.title(str(x)) send_pic_qq(towho, fig) # plt.show() plt.close() send_W_M_MACD(x, towho)
def add_stk(kind, name, tc): """ 增加持仓 :param name: :param tc: :return: """ # 判断输入的是代码是名称 if 'qh' in name: code = name[2:] elif name.isdigit(): code = name else: code = name2code(name) if code == '未知代码': text_append_color(tc, name + ':不识别的股票名字!请尝试使用股票代码!') return # 向配置文件中写入 增加持仓的stk代码 stk_now = read_config()[kind] if code not in stk_now: stk_now.append(code) write_config(kind, stk_now) text_append_color(tc, '增加“' + name + '”成功!') else: text_append_color(tc, '增加“' + name + '”失败!已存在!')
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 updateRSVRecord(): try: code_list = read_config()['buy_stk'] # global RSV_Record for stk in code_list: RSV_Record[stk] = cal_rsv_rank(stk, 5) except Exception as e: send_qq('影子2', 'RSV数据更新失败!\n' + str(e))
def cat_stk(kind, tc): """ 查看相关stk列表 :param kind: :return: """ stk_list = read_config()[kind] stk_name = str([code2name(x) for x in stk_list]) text_append_color(tc, stk_name.replace('[', '').replace(']', '').replace(',', '\n'))
def on_timer_pic(win, pool, debug=False): """ 图片定时器响应函数(闲置) :return: """ global last_upt_t upt_flag, last_upt_t = is_time_h_macd_update(last_upt_t) wx.PostEvent(win, ResultEvent(id=LAST_TIME_UPDATE_ID, data=last_upt_t)) if not upt_flag: wx.PostEvent(win, ResultEvent(id=MSG_UPDATE_ID_A, data='图片更新定时器:“小时图片”更新时间点未到!\n')) return # 清屏 wx.PostEvent(win, ResultEvent(id=NOTE_UPDATE_ID_S, data='检测时间:' + get_current_datetime_str() + '\n\n')) # 生成更新的图片 wx.PostEvent(win, ResultEvent(id=MSG_UPDATE_ID_A, data='开始更新小时图片...\n')) pic_dict = {'h_macd': gen_kind_pic('h', pool), 'h_idx': gen_kind_pic('h_idx', pool)} wx.PostEvent(win, ResultEvent(id=HOUR_UPDATE_ID, data=pic_dict)) wx.PostEvent(win, ResultEvent(id=MSG_UPDATE_ID_A, data='小时图片更新完成!\n')) # 拐点检测 window_flash_flag = False 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)['threshold_satisfied_flag']: wx.PostEvent(win, ResultEvent(id=MSG_UPDATE_ID_A, data=code2name(stk) + '阈值条件不满足,不进行拐点检测\n')) continue hour_idx_str = check_single_stk_hour_idx_wx(stk, source='jq', debug=True) if len(hour_idx_str): window_flash_flag = True for str_tmp in hour_idx_str: wx.PostEvent(win, ResultEvent(id=NOTE_UPDATE_ID_A, data=change_font_color(str_tmp))) # 窗口闪烁 if window_flash_flag: wx.PostEvent(win, ResultEvent(id=FLASH_WINDOW_ID, data=None)) wx.PostEvent(win, ResultEvent(id=MSG_UPDATE_ID_A, data=note_sar_inflection_point))
def judge_p_change_ratio(stk_code, price_diff_ratio, str_gui, debug=True, gui=False): """ 判断stk的变化是否达到一定的幅度,以杜绝反复上报 :param stk_code: :return: """ global price_diff_ratio_last_dic if debug: str_temp = '函数JudgeSingleStk:进入函数!' if gui: str_gui['msg'] = str_gui['msg'] + str_temp + '\n' else: print('函数JudgeSingleStk:进入函数!') # 变化1个百分点再报,避免重复报 if stk_code in p_diff_ratio_last_dic.keys(): if math.fabs(price_diff_ratio - p_diff_ratio_last_dic[stk_code] ) * 100 > read_config()['pcr']: p_diff_ratio_last_dic[stk_code] = price_diff_ratio if debug: str_temp = '函数JudgeSingleStk:' + str(stk_code) + '价格变化幅度达标,允许推送,并更新振幅记忆!' + \ '\np_ratio_now:' + str(price_diff_ratio) + \ '\np_ratio_last:' + str(p_diff_ratio_last_dic[stk_code]) if gui: str_gui['msg'] = str_gui['msg'] + str_temp + '\n' else: print(str_temp) return True, str_gui else: str_temp = '函数JudgeSingleStk:' + str(stk_code) + '价格变化幅度不够,不许推送!' + \ '\np_ratio_now:' + str(price_diff_ratio) + \ '\np_ratio_last:' + str(p_diff_ratio_last_dic[stk_code]) if gui: str_gui['msg'] = str_gui['msg'] + str_temp + '\n' else: print(str_temp) return False, str_gui else: p_diff_ratio_last_dic[stk_code] = price_diff_ratio if debug: str_temp = '函数JudgeSingleStk:' + str(stk_code) + '首次运行,允许推送!' if gui: str_gui['msg'] = str_gui['msg'] + str_temp + '\n' else: print(str_temp) return True, str_gui
def getMinReseauSize(): """ 从配置文件中获取网格的最小宽度,如果没有该字段,则设置默认为2% :return: """ r = read_config() if 'minReseau' in r.keys(): return r['minReseau'] else: write_config('minReseau', 0.02) return 0.02
def delete_stk(kind, name, tc): """ 从持仓中删除 :param name: :param tc: :return: """ # 判断输入的是代码是名称 if name.isdigit(): code = name else: code = name2code(name) if code == '未知代码': text_append_color(tc, name + ':不识别的股票名字!请尝试使用股票代码!') return # 向配置文件中删除 增加持仓的stk代码 stk_now = read_config()[kind] if code in stk_now: stk_now.remove(code) write_config(kind, stk_now) text_append_color(tc, '删除“' + name + '”成功!') else: text_append_color(tc, '删除“' + name + '”失败!原先关注列表中没有 ' + name)
# 打印日志 reseau_judge.bs_info_print() # 进行bs判断 reseau_judge.bs_judge() return reseau_judge.str_gui if __name__ == '__main__': jq_login() df = get_k_data_JQ('000001', 400) 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, gui=True, debug=True) logout() app = wx.App() pool = multiprocessing.Pool(processes=7) from DataSource.auth_info import *
# # str_gui = myPrint( # str_gui, # str_temp, # method={True: 'gn', False: 'qq'}[gui], # towho=qq) # if not gui: # sendHourMACDToQQ(stk_code, qq, source='jq') return str_gui if __name__ == '__main__': jq_login() 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) logout() app = wx.App() pool = multiprocessing.Pool(processes=7) from DataSource.auth_info import * r = gen_kind_pic('idx', pool) pprint.pprint(r)
def judge_single_stk(stk_code, stk_amount_last, qq, debug=False, gui=False): """ :param stk_code: :param stk_amount_last: :param qq: :param debug: :param gui: :return: """ money_each_opt = 5000 """ 变量声明 """ str_gui = { 'note': '', 'msg': '' } """ 'n':无操作,'b', 's' """ opt_now = 'n' """ ==== 获取该stk的实时价格,如果是大盘指数,使用聚宽数据,否则有限使用tushare ==== """ try: current_price = get_current_price_JQ(stk_code) except: str_gui = myPrint(str_gui, stk_code + '获取实时price失败!', method={True: 'gm', False: 'n'}[gui]) return str_gui debug_print_txt('stk_judge', stk_code, 'realtime_p:' + str(current_price) + '\n', debug) """ ==================== 获取上次price ==================== """ opt_json_stk = read_opt_json(stk_code, opt_record_file_url) # 如果没有相应的json文件,不进行判断,直接返回 if opt_json_stk == {}: debug_print_txt('stk_judge', stk_code, '函数 judge_single_stk:' + code2name(stk_code) + '没有历史操作记录,不进行阈值判断!\n', debug) # print('函数 judge_single_stk:' + code2name(stk_code) + '没有历史操作记录,不进行阈值判断!') return str_gui if len(opt_json_stk['b_opt']) == 0: debug_print_txt('stk_judge', stk_code, '函数 judge_single_stk:' + code2name(stk_code) + '没有历史操作记录,不进行阈值判断!\n', debug) # print('函数 judge_single_stk:' + code2name(stk_code) + '没有历史操作记录,不进行阈值判断!') return str_gui # 读取上次p和b操作中的最小p,备用 last_p = opt_json_stk['p_last'] b_p_min = np.min([x['p'] for x in opt_json_stk['b_opt']]) debug_print_txt('stk_judge', stk_code, '\n上次p:' + str(last_p) + '\n最小p:' + str(b_p_min) + '\nb_change_ratio:' + '%0.2f' % (100.0 * (current_price - last_p) / last_p) + '%' + '\ns_change_ratio:' + '%0.2f' % (100.0 * (current_price - b_p_min) / b_p_min) + '%', debug) """ =========== 实时计算价差,用于“波动提示”和“最小网格限制” ======== """ if debug: str_gui = myPrint( str_gui, '\n\n' + stk_code + ':\np_now:' + str(current_price) + '\np_last:' + str( last_p) + '\np_change_ratio:' + '', method={True: 'gm', False: 'n'}[gui]) """ ========== 排除获取的价格为0的情况,此种情况可能是stop或者时间未到 ========== """ if current_price == 0.0: str_gui = myPrint( str_gui, stk_code + 'price==0.0! 返回!', method={True: 'gm', False: 'n'}[gui]) return str_gui buy_amount = math.floor((money_each_opt / current_price) / 100) * 100 """ 实时计算网格大小 """ earn_threshold_unit = get_single_stk_reseau(stk_code) """ 调节 buy 和 sale 的threshold """ if stk_code in RSV_Record.keys(): thh_sale = earn_threshold_unit * 2 * RSV_Record[stk_code] thh_buy = earn_threshold_unit * 2 * (1 - RSV_Record[stk_code]) debug_print_txt('stk_judge', stk_code, '', debug) else: RSV_Record[stk_code] = cal_rsv_rank(stk_code, 5) thh_sale = earn_threshold_unit * 2 * RSV_Record[stk_code] thh_buy = earn_threshold_unit * 2 * (1 - RSV_Record[stk_code]) debug_print_txt('stk_judge', stk_code, 'thh_sale:' + str(thh_sale) + ' thh_buy:' + str(thh_buy), debug) """ 将操作日志保存到全局变量中 """ if opt_lock.acquire(): try: opt_record.append({ 'stk_code': stk_code, 'p_now': current_price, 'sale_reseau': thh_sale, 'buy_reseau': thh_buy, 'p_last': last_p, # 'opt': opt, 'date_time': get_current_datetime_str() }) except Exception as e: print('函数 JudgeSingleStk:写入操作记录失败!原因:\n' + str(e)) finally: opt_lock.release() if debug: # print('函数 JudgeSingleStk:' + stk_code + '定时处理完成后,操作记录为:\n') # pprint(opt_record) pass """ ==================== 判断波动是否满足“最小网格限制” ================= """ """ config_json = read_config() if not ('minReseau' in config_json.keys()): write_config('minReseau', 0.02) min_reseau = 0.02 else: min_reseau = config_json['minReseau'] if (min_reseau > math.fabs(thh_sale/last_p)) | (min_reseau > math.fabs(thh_buy/last_p)): str_tmp = stk_code + ' ' + code2name(stk_code) + ':\n'\ + 'buy相对宽度:%0.3f \n' % (thh_buy/last_p) +\ 'sale相对宽度:%0.3f\n' % (thh_sale/last_p) +\ '设定波动阈值:%0.3f\n' % min_reseau +\ '波动未达到最小网格宽度,返回!' str_gui = myPrint( str_gui, str_tmp, method={True: 'gm', False: 'n'}[gui]) return str_gui if debug: str_gui = myPrint( str_gui, stk_code + ':\np_change:' + str(price_diff * stk_amount_last) + '\nthreshold:' + str(earn_threshold_unit) + '\nthh_sale:' + str(thh_sale) + '\nthh_buy:' + str(thh_buy), method={True: 'gm', False: 'n'}[gui]) """ """ ============================= 判断是否超过阈值,进行bs操作 ============================== """ pcr = read_config()['pcr'] if (current_price - b_p_min > thh_sale) & ((current_price - b_p_min) / b_p_min >= pcr): str_temp = "触发卖出网格!可以考虑卖出! " + stk_code + code2name(stk_code) + \ '\nAmount:' + str(stk_amount_last) + \ '\n当前价格:' + str(current_price) + \ '\n上次买入价格:' + str(b_p_min) + \ '\n买入网格大小:' + '%0.3f' % thh_buy + \ '\n卖出网格大小:' + '%0.3f' % thh_sale + \ '\n最小操作幅度:' + '%0.3f' % pcr debug_print_txt('stk_judge', stk_code, str_temp, debug) str_gui = myPrint( str_gui, str_temp, method={True: 'gn', False: 'qq'}[gui], towho=qq) if not gui: # sendHourMACDToQQ(stk_code, qq, source='jq') pass elif (current_price - last_p < -thh_buy) & ((current_price - last_p) / b_p_min <= -pcr): str_temp = "触发买入网格!可以考虑买入!" + stk_code + code2name(stk_code) + \ '\nAmount:' + str(buy_amount) + \ '\n当前价格:' + str(current_price) + \ '\n上次价格:' + str(last_p) + \ '\n买入网格大小:' + '%0.2f' % thh_buy + \ '\n卖出网格大小:' + '%0.2f' % thh_sale + \ '\n最小操作幅度:' + '%0.3f' % pcr debug_print_txt('stk_judge', stk_code, str_temp, debug) str_gui = myPrint( str_gui, str_temp, method={True: 'gn', False: 'qq'}[gui], towho=qq) # if not gui: # sendHourMACDToQQ(stk_code, qq, source='jq') else: str_gui = myPrint( str_gui, stk_code + ':未触发任何警戒线!', method={True: 'gm', False: 'n'}[gui]) debug_print_txt('stk_judge', stk_code, stk_code + ':未触发任何警戒线!', debug) """ ========================== 波动检测 =========================== """ # change_flag, str_gui = judge_p_change_ratio(stk_code, (current_price-last_p)/last_p, str_gui=str_gui, gui=gui) # if change_flag: # # str_temp = "波动推送! " + stk_code + code2name(stk_code) +\ # '\nAmount:' + str(buy_amount) +\ # '\n当前价格:' + str(current_price) +\ # '\n上次价格:' + str(last_p) +\ # '\n买入网格大小:' + '%0.2f' % thh_buy +\ # '\n卖出网格大小:' + '%0.2f' % thh_sale # # str_gui = myPrint( # str_gui, # str_temp, # method={True: 'gn', False: 'qq'}[gui], # towho=qq) # if not gui: # sendHourMACDToQQ(stk_code, qq, source='jq') return str_gui
# encoding=utf-8
# coding=utf-8
def get_pcr(self): self.pcr = read_config()['pcr'] / 100.0
def judge_single_stk(stk_code, stk_amount_last, debug=False, gui=False): """ :param stk_code: :param stk_amount_last: :param debug: :param gui: :return: """ """ 变量声明 """ str_gui = { 'note': '', 'msg': '' } str_ = '\n\n\n=============================================\n' + code2name(stk_code) + ':开始进入本周期判断!\n' debug_print_txt('stk_judge', stk_code, str_, debug) str_gui['msg'] = str_gui['msg'] + str_ money_each_opt = 5000 """ ==== 获取该stk的实时价格,如果是大盘指数,使用聚宽数据,否则有限使用tushare ==== """ try: current_price = get_current_price_JQ(stk_code) except: str_gui['msg'] = str_gui['msg'] + stk_code + '获取实时price失败!\n' return str_gui str_ = '实时价格:' + str(current_price) + '\n' debug_print_txt('stk_judge', stk_code, str_, debug) str_gui['msg'] = str_gui['msg'] + str_ """ ==================== 获取上次price ==================== """ opt_json_stk = read_opt_json(stk_code, opt_record_file_url) # 如果没有相应的json文件,不进行判断,直接返回 if opt_json_stk == {}: str_ = code2name(stk_code) + '没有历史操作记录,不进行阈值判断!\n' debug_print_txt('stk_judge', stk_code, '函数 judge_single_stk:' + str_, debug) str_gui['msg'] = str_gui['msg'] + str_ return str_gui if len(opt_json_stk['b_opt']) == 0: str_ = code2name(stk_code) + '没有历史操作记录,不进行阈值判断!\n' debug_print_txt('stk_judge', stk_code, '函数 judge_single_stk:' + str_, debug) str_gui['msg'] = str_gui['msg'] + str_ return str_gui # 读取 threshold_satisfied_flag = opt_json_stk['threshold_satisfied_flag'] str_gui['msg'] = str_gui['msg'] + '已经进行过闪动提示?:' + {False: '是', True: '否'}.get(threshold_satisfied_flag, '未知') + '\n' # 读取上次p和b操作中的最小p,备用 last_p = opt_json_stk['p_last'] b_p_min = np.min([x['p'] for x in opt_json_stk['b_opt']]) str_ = '\n上次操作价格:' + str(last_p) + \ '\n最小买入价格:' + str(b_p_min) + \ '\n买入-波动率:' + '%0.3f' % (100.0 * (current_price - last_p) / last_p) + '%' + \ '\n卖出-波动率:' + '%0.3f' % (100.0 * (current_price - b_p_min) / b_p_min) + '%' + \ '\n买入-波动:' + '%0.2f' % (current_price - last_p) + \ '\n卖出-波动:' + '%0.2f' % (current_price - b_p_min) debug_print_txt('stk_judge', stk_code, str_, debug) str_gui['msg'] = str_gui['msg'] + str_ + '\n' """ =========== 实时计算价差,用于“波动提示”和“最小网格限制” ======== """ """ ========== 排除获取的价格为0的情况,此种情况可能是stop或者时间未到 ========== """ if current_price == 0.0: str_gui = myPrint( str_gui, stk_code + 'price==0.0! 返回!', method={True: 'gm', False: 'n'}[gui]) return str_gui buy_amount = math.floor((money_each_opt / current_price) / 100) * 100 """ 实时计算网格大小 """ earn_threshold_unit = get_single_stk_reseau(stk_code) """ 调节 buy 和 sale 的threshold """ if stk_code in RSV_Record.keys(): thh_sale = earn_threshold_unit * 2 * RSV_Record[stk_code] thh_buy = earn_threshold_unit * 2 * (1 - RSV_Record[stk_code]) debug_print_txt('stk_judge', stk_code, '', debug) else: RSV_Record[stk_code] = cal_rsv_rank(stk_code, 5) thh_sale = earn_threshold_unit * 2 * RSV_Record[stk_code] thh_buy = earn_threshold_unit * 2 * (1 - RSV_Record[stk_code]) str_ = '\n卖出网格大小:' + '%0.3f' % thh_sale + '\n买入网格大小:' + '%0.3f' % thh_buy + '\n' debug_print_txt('stk_judge', stk_code, str_, debug) str_gui['msg'] = str_gui['msg'] + str_ """ 将操作日志保存到全局变量中 """ if opt_lock.acquire(): try: opt_record.append({ 'stk_code': stk_code, 'p_now': current_price, 'sale_reseau': thh_sale, 'buy_reseau': thh_buy, 'p_last': last_p, # 'opt': opt, 'date_time': get_current_datetime_str() }) except Exception as e: print('函数 JudgeSingleStk:写入操作记录失败!原因:\n' + str(e)) finally: opt_lock.release() """ ============================= 判断是否超过阈值,进行bs操作 ============================== """ pcr = read_config()['pcr']/100.0 # 打印日志 debug_print_txt('stk_judge', stk_code, '读取的最小波动率:' + str(pcr) + '\n', debug) debug_print_txt('stk_judge', stk_code, '允许阈值判断标志位(True为允许):' + str(threshold_satisfied_flag) + '\n', debug) debug_print_txt('stk_judge', stk_code, '判断是否可以卖出:\ncurrent_price - b_p_min > thh_sale:' + str(current_price - b_p_min > thh_sale) + '\n', debug) debug_print_txt('stk_judge', stk_code, '(current_price - b_p_min) / b_p_min >= pcr:' + str((current_price - b_p_min) / b_p_min >= pcr) + '\n', debug) debug_print_txt('stk_judge', stk_code, '判断是否可以买入:\ncurrent_price - last_p < -thh_buy:' + str(current_price - last_p < -thh_buy) + '\n', debug) debug_print_txt('stk_judge', stk_code, '(current_price - last_p) / b_p_min <= -pcr:' + str((current_price - last_p) / b_p_min <= -pcr) + '\n', debug) if (current_price - b_p_min > thh_sale) & ((current_price - b_p_min) / b_p_min >= pcr): str_temp = "触发卖出网格!可以考虑卖出! " + stk_code + code2name(stk_code) + \ '\nAmount:' + str(stk_amount_last) + \ '\n当前价格:' + str(current_price) + \ '\n上次买入价格:' + str(b_p_min) + \ '\n买入网格大小:' + '%0.3f' % thh_buy + \ '\n卖出网格大小:' + '%0.3f' % thh_sale + \ '\n最小操作幅度:' + '%0.3f' % pcr debug_print_txt('stk_judge', stk_code, str_temp + '\n在灯神进行bs操作之前,此stk不再进行阈值判断\n', debug) if threshold_satisfied_flag: str_gui['note'] = str_gui['note'] + str_temp # 除非有bs操作,否则不再提示 set_opt_json_threshold_satisfied_flag(opt_record_file_url, stk_code, value=False) else: str_gui['msg'] = str_gui['msg'] + str_temp elif (current_price - last_p < -thh_buy) & ((current_price - last_p) / b_p_min <= -pcr): str_temp = "触发买入网格!可以考虑买入!" + stk_code + code2name(stk_code) + \ '\nAmount:' + str(buy_amount) + \ '\n当前价格:' + str(current_price) + \ '\n上次价格:' + str(last_p) + \ '\n买入网格大小:' + '%0.2f' % thh_buy + \ '\n卖出网格大小:' + '%0.2f' % thh_sale + \ '\n最小操作幅度:' + '%0.3f' % pcr debug_print_txt('stk_judge', stk_code, str_temp + '\n在灯神进行bs操作之前,此stk不再进行阈值判断\n', debug) if threshold_satisfied_flag: str_gui['note'] = str_gui['note'] + str_temp # 除非有bs操作,否则不再提示 set_opt_json_threshold_satisfied_flag(opt_record_file_url, stk_code, value=False) else: str_gui['msg'] = str_gui['msg'] + str_temp else: str_ = stk_code + ':未触发任何警戒线!\n' str_gui['msg'] = str_gui['msg'] + str_ debug_print_txt('stk_judge', stk_code, str_, debug) return str_gui