From 8218790ab15e752d982ee9c0df156ceea849c9a9 Mon Sep 17 00:00:00 2001 From: Administrator <admin@example.com> Date: 星期一, 05 十二月 2022 22:02:47 +0800 Subject: [PATCH] 策略优化,增加买1价格的影响 --- l2_data_manager_new.py | 111 +++++++++++++++++++++++++++++++++++++++++++------------ 1 files changed, 87 insertions(+), 24 deletions(-) diff --git a/l2_data_manager_new.py b/l2_data_manager_new.py index 52f1f4f..7a795bd 100644 --- a/l2_data_manager_new.py +++ b/l2_data_manager_new.py @@ -17,7 +17,9 @@ import redis_manager import ths_industry_util import tool +import trade_data_manager import trade_manager +import trade_queue_manager from l2_data_manager import L2DataException, TradePointManager, local_today_datas, L2DataUtil, load_l2_data, \ local_today_num_operate_map from log import logger_l2_trade, logger_l2_trade_cancel, logger_l2_trade_buy, logger_l2_process, logger_buy_1_volumn @@ -151,6 +153,7 @@ random_key = {} l2BigNumForMProcessor = L2BigNumForMProcessor() __codeActualPriceProcessor = CodeActualPriceProcessor() + buy1PriceManager = trade_queue_manager.Buy1PriceManager() @classmethod def debug(cls, code, content, *args): @@ -280,31 +283,70 @@ @classmethod def __buy(cls, code, capture_timestamp, last_data, last_data_index): can, reason = cls.__can_buy(code) - # 涓嶈兘璐拱 - if not can: - cls.debug(code, "涓嶅彲浠ヤ笅鍗曪紝鍘熷洜锛歿}", reason) - return - else: - cls.debug(code, "鍙互涓嬪崟锛屽師鍥狅細{}", reason) - # 鍒犻櫎铏氭嫙涓嬪崟 if code in cls.unreal_buy_dict: cls.unreal_buy_dict.pop(code) - cls.debug(code, "寮�濮嬫墽琛屼拱鍏�") - try: - trade_manager.start_buy(code, capture_timestamp, last_data, - last_data_index) - l2_data_manager.TradePointManager.delete_buy_cancel_point(code) - cls.debug(code, "鎵ц涔板叆鎴愬姛") - except Exception as e: - cls.debug(code, "鎵ц涔板叆寮傚父:{}", str(e)) - pass - finally: - cls.debug(code, "m鍊煎奖鍝嶅洜瀛愶細{}", l2_trade_factor.L2TradeFactorUtil.factors_to_string(code)) + + if not can: + cls.debug(code, "涓嶅彲浠ヤ笅鍗曪紝鍘熷洜锛歿}", reason) + if not reason.startswith("涔�1浠蜂笉涓烘定鍋滀环"): + # 涓柇涔板叆 + trade_manager.break_buy(code, reason) + return + else: + cls.debug(code, "鍙互涓嬪崟锛屽師鍥狅細{}", reason) + try: + cls.debug(code, "寮�濮嬫墽琛屼拱鍏�") + trade_manager.start_buy(code, capture_timestamp, last_data, + last_data_index) + l2_data_manager.TradePointManager.delete_buy_cancel_point(code) + cls.debug(code, "鎵ц涔板叆鎴愬姛") + except Exception as e: + cls.debug(code, "鎵ц涔板叆寮傚父:{}", str(e)) + pass + finally: + cls.debug(code, "m鍊煎奖鍝嶅洜瀛愶細{}", l2_trade_factor.L2TradeFactorUtil.factors_to_string(code)) + + # 鏄惁鍙互鍙栨秷 + @classmethod + def __can_cancel(cls, code): + # 14鐐瑰悗濡傛灉鏄澘鍧楄�佸ぇ灏变笉闇�瑕佸彇娑堜簡 + now_time_str = tool.get_now_time_str() + if int(now_time_str.replace(":", "")) >= 140000: + industry, codes = ths_industry_util.get_same_industry_codes(code, gpcode_manager.get_gp_list()) + if industry is None: + return True, "娌℃湁鑾峰彇鍒拌涓�" + codes_index = limit_up_time_manager.sort_code_by_limit_time(codes) + if codes_index is not None and codes_index.get(code) is not None: + # 鍚屼竴鏉垮潡涓�佷簩鍚庨潰鐨勪笉鑳戒拱 + if codes_index.get(code) == 0: + return False, "14:00鍚庤�佸ぇ涓嶈兘鎾ゅ崟" + elif codes_index.get(code) == 1: + # 鍒ゆ柇鑰佸ぇ鏄惁閮芥槸09锛�30锛�00娑ㄥ仠鐨� + # 鍚�1鏉垮潡鑰佸ぇ鏄�09:30:00娑ㄥ仠锛岃�佷簩14锛�00鐮稿紑鐨勪笉鎾� + first_count = 0 + for key in codes_index: + if codes_index[key] == 0: + first_count += 1 + if limit_up_time_manager.get_limit_up_time(key) == "09:30:00": + first_count -= 1 + if first_count == 0: + return False, "14:00鍚庤�佸ぇ閮藉紑鐩樻定鍋滐紝鑰佷簩涓嶈兘鎾ゅ崟" + + return True, "" # 鏄惁鍙互涔� @classmethod def __can_buy(cls, code): + # 涔�1浠锋牸蹇呴』涓烘定鍋滀环鎵嶈兘涔� + # buy1_price = cls.buy1PriceManager.get_price(code) + # if buy1_price is None: + # return False, "涔�1浠峰皻鏈幏鍙栧埌" + # limit_up_price = gpcode_manager.get_limit_up_price(code) + # if limit_up_price is None: + # return False, "灏氭湭鑾峰彇鍒版定鍋滀环" + # if abs(float(buy1_price) - float(limit_up_price)) >= 0.01: + # return False, "涔�1浠蜂笉涓烘定鍋滀环锛屼拱1浠�-{} 娑ㄥ仠浠�-{}".format(buy1_price, limit_up_price) # 閲忔瘮瓒呰繃1.3鐨勪笉鑳戒拱 volumn_rate = l2_trade_factor.L2TradeFactorUtil.get_volumn_rate_by_code(code) @@ -389,6 +431,12 @@ @classmethod def cancel_buy(cls, code, msg=None): + can_cancel, reason = cls.__can_cancel(code) + if not can_cancel: + # 涓嶈兘鍙栨秷 + cls.cancel_debug(code, "鎾ゅ崟涓柇锛屽師鍥狅細{}", reason) + return + l2_data_manager.L2ContinueLimitUpCountManager.del_data(code) if code in cls.unreal_buy_dict: cls.unreal_buy_dict.pop(code) @@ -580,7 +628,8 @@ count = threshold_count - sub_threshold_count if count < 3: count = 3 - return count + return round(count*buy1_factor) + _start_time = t.time() total_datas = local_today_datas[code] # 璁$畻浠庝拱鍏ヤ俊鍙峰紑濮嬪埌璁$畻寮�濮嬩綅缃殑澶у崟鏁伴噺 @@ -591,10 +640,22 @@ buy_nums = origin_num buy_count = origin_count limit_up_price = gpcode_manager.get_limit_up_price(code) + buy1_price = cls.buy1PriceManager.get_price(code) if limit_up_price is None: raise Exception("娑ㄥ仠浠锋棤娉曡幏鍙�") # 鐩爣鎵嬫暟 threshold_num = threshold_money / (limit_up_price * 100) + + buy1_factor = 1 + # 鑾峰彇涔�1鏄惁涓烘定鍋滀环 + if buy1_price is None: + buy1_factor = 1.3 + elif limit_up_price is None: + buy1_factor = 1.3 + elif abs(float(buy1_price) - float(limit_up_price)) >= 0.01: + print("涔�1浠蜂笉涓烘定鍋滀环锛屼拱1浠�-{} 娑ㄥ仠浠�-{}".format(buy1_price, limit_up_price)) + buy1_factor = 1.3 + # 鐩爣璁㈠崟鏁伴噺 threshold_count = l2_trade_factor.L2TradeFactorUtil.get_safe_buy_count(code) @@ -616,14 +677,15 @@ return None, buy_nums, buy_count, ii # 娑ㄥ仠涔� if L2DataUtil.is_limit_up_price_buy(_val): - if cls.__is_big_money(limit_up_price,_val): + if cls.__is_big_money(limit_up_price, _val): sub_threshold_count += int(total_datas[i]["re"]) # 娑ㄥ仠涔� buy_nums += int(_val["num"]) * int(total_datas[i]["re"]) buy_count += int(total_datas[i]["re"]) if buy_nums >= threshold_num and buy_count >= get_threshold_count(): - logger_l2_trade_buy.info("{}鑾峰彇鍒颁拱鍏ユ墽琛岀偣锛歿} 缁熻绾拱鎵嬫暟锛歿} 鐩爣绾拱鎵嬫暟锛歿} 缁熻绾拱鍗曟暟锛歿} 鐩爣绾拱鍗曟暟锛歿}, 澶у崟鏁伴噺锛歿}", code, i, buy_nums, - threshold_num, buy_count, get_threshold_count(),sub_threshold_count) + logger_l2_trade_buy.info("{}鑾峰彇鍒颁拱鍏ユ墽琛岀偣锛歿} 缁熻绾拱鎵嬫暟锛歿} 鐩爣绾拱鎵嬫暟锛歿} 缁熻绾拱鍗曟暟锛歿} 鐩爣绾拱鍗曟暟锛歿}, 澶у崟鏁伴噺锛歿}", code, i, + buy_nums, + threshold_num, buy_count, get_threshold_count(), sub_threshold_count) elif L2DataUtil.is_limit_up_price_buy_cancel(_val): if cls.__is_big_money(limit_up_price, _val): sub_threshold_count -= int(total_datas[i]["re"]) @@ -655,9 +717,10 @@ if buy_nums >= threshold_num and buy_count >= get_threshold_count(): return i, buy_nums, buy_count, None - cls.buy_debug(code, "灏氭湭鑾峰彇鍒颁拱鍏ユ墽琛岀偣锛岃捣濮嬭绠椾綅缃細{} 缁熻绾拱鎵嬫暟锛歿} 鐩爣绾拱鎵嬫暟锛歿} 缁熻绾拱鍗曟暟锛歿} 鐩爣绾拱鍗曟暟锛歿} 澶у崟鏁伴噺锛歿}", compute_start_index, + cls.buy_debug(code, "灏氭湭鑾峰彇鍒颁拱鍏ユ墽琛岀偣锛岃捣濮嬭绠椾綅缃細{} 缁熻绾拱鎵嬫暟锛歿} 鐩爣绾拱鎵嬫暟锛歿} 缁熻绾拱鍗曟暟锛歿} 鐩爣绾拱鍗曟暟锛歿} 澶у崟鏁伴噺锛歿}", + compute_start_index, buy_nums, - threshold_num, buy_count, get_threshold_count(),sub_threshold_count) + threshold_num, buy_count, get_threshold_count(), sub_threshold_count) return None, buy_nums, buy_count, None -- Gitblit v1.8.0