From a7a394e1525cfb85aff1ba02f0961dbb07748bc8 Mon Sep 17 00:00:00 2001 From: Administrator <admin@example.com> Date: 星期五, 10 二月 2023 19:06:09 +0800 Subject: [PATCH] 日志优化,部分大单并行化处理 --- l2/l2_data_manager_new.py | 241 +++++++++++++++++++++++------------------------ 1 files changed, 118 insertions(+), 123 deletions(-) diff --git a/l2/l2_data_manager_new.py b/l2/l2_data_manager_new.py index d9cb6be..3d741bc 100644 --- a/l2/l2_data_manager_new.py +++ b/l2/l2_data_manager_new.py @@ -16,7 +16,7 @@ import tool from trade import trade_data_manager, trade_manager, trade_queue_manager, l2_trade_factor, l2_trade_util, \ trade_result_manager -from l2 import safe_count_manager, l2_data_manager, l2_data_log +from l2 import safe_count_manager, l2_data_manager, l2_data_log, l2_log from l2.cancel_buy_strategy import SecondCancelBigNumComputer, HourCancelBigNumComputer, L2LimitUpMoneyStatisticUtil, \ L2LimitUpSellStatisticUtil from l2.l2_data_manager import L2DataException, TradePointManager @@ -161,20 +161,6 @@ __buyL2SafeCountManager = safe_count_manager.BuyL2SafeCountManager() @classmethod - def debug(cls, code, content, *args): - logger_l2_trade.debug(("thread-id={} code={} ".format(cls.random_key[code], code) + content).format(*args)) - - @classmethod - def cancel_debug(cls, code, content, *args): - logger_l2_trade_cancel.debug( - ("thread-id={} code={} ".format(cls.random_key[code], code) + content).format(*args)) - - @classmethod - def buy_debug(cls, code, content, *args): - logger_l2_trade_buy.debug( - ("thread-id={} code={} ".format(cls.random_key[code], code) + content).format(*args)) - - @classmethod # 鏁版嵁澶勭悊鍏ュ彛 # datas: 鏈鎴浘鏁版嵁 # capture_timestamp:鎴浘鏃堕棿鎴� @@ -204,7 +190,7 @@ # 淇濆瓨鏁版嵁 __start_time = round(t.time() * 1000) l2.l2_data_util.save_l2_data(code, datas, add_datas, cls.random_key[code]) - __start_time = l2_data_log.l2_time(code, cls.random_key[code], + __start_time = l2_data_log.l2_time(code, round(t.time() * 1000) - __start_time, "淇濆瓨鏁版嵁鏃堕棿锛坽}锛�".format(len(add_datas))) finally: @@ -231,7 +217,7 @@ limit_up_time_manager.save_limit_up_time(code, "09:30:00") total_datas = local_today_datas[code] - __start_time = l2_data_log.l2_time(code, cls.random_key[code], round(t.time() * 1000) - __start_time, + __start_time = l2_data_log.l2_time(code, round(t.time() * 1000) - __start_time, "l2鏁版嵁棰勫鐞嗘椂闂�") if len(add_datas) > 0: @@ -254,7 +240,7 @@ logger_l2_process.info("code:{} 澶勭悊鏁版嵁鑼冨洿: {}-{} 澶勭悊鏃堕棿:{} 鎴浘鏃堕棿鎴筹細{}", code, add_datas[0]["index"], add_datas[-1]["index"], round(t.time() * 1000) - __start_time, capture_timestamp) - __start_time = l2_data_log.l2_time(code, cls.random_key[code], round(t.time() * 1000) - __start_time, + __start_time = l2_data_log.l2_time(code, round(t.time() * 1000) - __start_time, "l2鏁版嵁澶勭悊鏃堕棿") # 澶勭悊鏈寕鍗� @@ -264,7 +250,7 @@ # 鑾峰彇闃堝�� threshold_money, msg = cls.__get_threshmoney(code) if round(t.time() * 1000) - __start_time > 10: - __start_time = l2_data_log.l2_time(code, cls.random_key.get(code), round(t.time() * 1000) - __start_time, + __start_time = l2_data_log.l2_time(code, round(t.time() * 1000) - __start_time, "鑾峰彇m鍊兼暟鎹�楁椂") cls.__start_compute_buy(code, start_index, end_index, threshold_money, capture_time) @@ -285,7 +271,7 @@ cls.__buyL2SafeCountManager.compute_left_rate(code, start_index, end_index, total_data, local_today_num_operate_map.get(code)) - l2_data_log.l2_time(code, cls.random_key[code], round(t.time() * 1000) - _start_time, + l2_data_log.l2_time(code, round(t.time() * 1000) - _start_time, "宸蹭笅鍗�-鑾峰彇涔板叆淇℃伅鑰楁椂") return None, "" @@ -296,7 +282,7 @@ # 璁$畻m鍊煎ぇ鍗� cls.l2BigNumForMProcessor.process(code, max(buy_single_index, start_index), end_index, gpcode_manager.get_limit_up_price(code)) - l2_data_log.l2_time(code, cls.random_key[code], round(t.time() * 1000) - _start_time, + l2_data_log.l2_time(code, round(t.time() * 1000) - _start_time, "宸蹭笅鍗�-m鍊煎ぇ鍗曡绠�") return None, "" @@ -309,7 +295,7 @@ end_index, buy_single_index, buy_exec_index) - l2_data_log.l2_time(code, cls.random_key[code], round(t.time() * 1000) - _start_time, + l2_data_log.l2_time(code, round(t.time() * 1000) - _start_time, "宸蹭笅鍗�-涔�1缁熻鑰楁椂") return cancel_data, cancel_msg @@ -328,7 +314,7 @@ except Exception as e: logging.exception(e) finally: - l2_data_log.l2_time(code, cls.random_key[code], round(t.time() * 1000) - _start_time, + l2_data_log.l2_time(code, round(t.time() * 1000) - _start_time, "宸蹭笅鍗�-s绾уぇ鍗曚及绠�") return None, "" @@ -345,7 +331,7 @@ except Exception as e: logging.exception(e) finally: - l2_data_log.l2_time(code, cls.random_key[code], round(t.time() * 1000) - _start_time, "宸蹭笅鍗�-H鎾ゅぇ鍗曡绠�") + l2_data_log.l2_time(code, round(t.time() * 1000) - _start_time, "宸蹭笅鍗�-H鎾ゅぇ鍗曡绠�") return None, "" # 鏉夸笂鍗栨挙 @@ -361,7 +347,7 @@ except Exception as e: logging.exception(e) finally: - l2_data_log.l2_time(code, cls.random_key[code], round(t.time() * 1000) - _start_time, "宸蹭笅鍗�-鏉夸笂鍗栬�楁椂") + l2_data_log.l2_time(code, round(t.time() * 1000) - _start_time, "宸蹭笅鍗�-鏉夸笂鍗栬�楁椂") return None, "" # 鏄惁闇�瑕佹挙閿� @@ -384,7 +370,7 @@ if end_index < start_index: return total_data = local_today_datas.get(code) - _start_time = round(t.time() * 1000) + _start_time = tool.get_now_timestamp() # 鑾峰彇涔板叆淇″彿璧峰鐐� buy_single_index, buy_exec_index, buy_compute_index, num, count, max_num_set = cls.__get_order_begin_pos(code) @@ -397,18 +383,18 @@ dask_result = is_need_cancel(f1, f2, f3, f4, f5, f6) cancel_data, cancel_msg = dask_result.compute() - _start_time = l2_data_log.l2_time(code, cls.random_key[code], round(t.time() * 1000) - _start_time, + _start_time = l2_data_log.l2_time(code, tool.get_now_timestamp() - _start_time, "宸蹭笅鍗�-鎾ゅ崟 鍒ゆ柇鏄惁闇�瑕佹挙鍗�") if cancel_data: - cls.debug(code, "瑙﹀彂鎾ゅ崟锛屾挙鍗曚綅缃細{} 锛屾挙鍗曞師鍥狅細{}", cancel_data["index"], cancel_msg) + l2_log.debug(code, "瑙﹀彂鎾ゅ崟锛屾挙鍗曚綅缃細{} 锛屾挙鍗曞師鍥狅細{}", cancel_data["index"], cancel_msg) # 鎾ゅ崟 if cls.cancel_buy(code, cancel_msg): - _start_time = l2_data_log.l2_time(code, cls.random_key[code], round(t.time() * 1000) - _start_time, + _start_time = l2_data_log.l2_time(code, tool.get_now_timestamp() - _start_time, "宸蹭笅鍗�-鎾ゅ崟 鑰楁椂") # 鎾ゅ崟鎴愬姛锛岀户缁绠椾笅鍗� cls.__process_not_order(code, cancel_data["index"] + 1, end_index, capture_time) - _start_time = l2_data_log.l2_time(code, cls.random_key[code], round(t.time() * 1000) - _start_time, + _start_time = l2_data_log.l2_time(code, tool.get_now_timestamp() - _start_time, "澶勭悊鍓╀綑鏁版嵁 鑰楁椂") else: # 鎾ゅ崟灏氭湭鎴愬姛 @@ -417,41 +403,43 @@ # 濡傛灉鏈夎櫄鎷熶笅鍗曢渶瑕佺湡瀹炰笅鍗� unreal_buy_info = cls.unreal_buy_dict.get(code) if unreal_buy_info is not None: - cls.debug(code, "鏈夎櫄鎷熶笅鍗曪紝鏃犱拱鎾や俊鍙凤紝寮�濮嬫墽琛屼拱鍏ワ紝鎵ц浣嶇疆锛歿},鎴浘鏃堕棿锛歿}", unreal_buy_info[0], capture_time) + l2_log.debug(code, "鏈夎櫄鎷熶笅鍗曪紝鏃犱拱鎾や俊鍙凤紝寮�濮嬫墽琛屼拱鍏ワ紝鎵ц浣嶇疆锛歿},鎴浘鏃堕棿锛歿}", unreal_buy_info[0], capture_time) # unreal_buy_info 鐨勫唴瀹规牸寮忎负锛�(瑙︽硶涔版搷浣滀笅鏍�,鎴浘鏃堕棿) # 鐪熷疄涓嬪崟 cls.__buy(code, unreal_buy_info[1], local_today_datas[code][unreal_buy_info[0]], unreal_buy_info[0]) - _start_time = l2_data_log.l2_time(code, cls.random_key[code], round(t.time() * 1000) - _start_time, - "宸蹭笅鍗�-鐪熷疄涓嬪崟 鑰楁椂") + _start_time = l2_data_log.l2_time(code, tool.get_now_timestamp() - _start_time, + "宸茶櫄鎷熶笅鍗�-鎵ц鐪熷疄涓嬪崟 澶栭儴鑰楁椂") @classmethod def __buy(cls, code, capture_timestamp, last_data, last_data_index): + __start_time = tool.get_now_timestamp() can, reason = cls.__can_buy(code) + __start_time = l2_data_log.l2_time(code, tool.get_now_timestamp() - __start_time, "鏈�鍚庡垽鏂槸鍚﹁兘涓嬪崟", force=True) # 鍒犻櫎铏氭嫙涓嬪崟 if code in cls.unreal_buy_dict: cls.unreal_buy_dict.pop(code) if not can: - cls.debug(code, "涓嶅彲浠ヤ笅鍗曪紝鍘熷洜锛歿}", reason) + l2_log.debug(code, "涓嶅彲浠ヤ笅鍗曪紝鍘熷洜锛歿}", reason) if not reason.startswith("涔�1浠蜂笉涓烘定鍋滀环"): # 涓柇涔板叆 trade_manager.break_buy(code, reason) return else: - cls.debug(code, "鍙互涓嬪崟锛屽師鍥狅細{}", reason) + l2_log.debug(code, "鍙互涓嬪崟锛屽師鍥狅細{}", reason) try: - cls.debug(code, "寮�濮嬫墽琛屼拱鍏�") + l2_log.debug(code, "寮�濮嬫墽琛屼拱鍏�") trade_manager.start_buy(code, capture_timestamp, last_data, last_data_index) ################涓嬪崟鎴愬姛澶勭悊################ trade_result_manager.real_buy_success(code) - cls.debug(code, "鎵ц涔板叆鎴愬姛") + l2_log.debug(code, "鎵ц涔板叆鎴愬姛") except Exception as e: - cls.debug(code, "鎵ц涔板叆寮傚父:{}", str(e)) + l2_log.debug(code, "鎵ц涔板叆寮傚父:{}", str(e)) pass finally: - cls.debug(code, "m鍊煎奖鍝嶅洜瀛愶細{}", l2_trade_factor.L2TradeFactorUtil.factors_to_string(code)) + l2_log.debug(code, "m鍊煎奖鍝嶅洜瀛愶細{}", l2_trade_factor.L2TradeFactorUtil.factors_to_string(code)) # 鏄惁鍙互鍙栨秷 @classmethod @@ -502,7 +490,7 @@ total_datas = local_today_datas[code] try: sell1_time, sell1_price, sell1_volumn = cls.__ths_l2_trade_queue_manager.get_sell1_info(code) - cls.buy_debug(code, "鍗�1淇℃伅涓猴細({},{},{})", sell1_time, sell1_price, sell1_volumn) + l2_log.buy_debug(code, "鍗�1淇℃伅涓猴細({},{},{})", sell1_time, sell1_price, sell1_volumn) if sell1_time is not None and sell1_volumn > 0: # 鑾峰彇鎵ц浣嶄俊鎭� @@ -591,18 +579,18 @@ # 鍙互涓嬪崟 return True, None finally: - l2_data_log.l2_time(code, cls.random_key[code], round((t.time() - __start_time) * 1000), "鏄惁鍙互涓嬪崟璁$畻") + l2_data_log.l2_time(code, round((t.time() - __start_time) * 1000), "鏄惁鍙互涓嬪崟璁$畻") @classmethod def __cancel_buy(cls, code): try: - cls.debug(code, "寮�濮嬫墽琛屾挙鍗�") + l2_log.debug(code, "寮�濮嬫墽琛屾挙鍗�") trade_manager.start_cancel_buy(code) - cls.debug(code, "鎵ц鎾ゅ崟鎴愬姛") + l2_log.debug(code, "鎵ц鎾ゅ崟鎴愬姛") return True except Exception as e: logging.exception(e) - cls.debug(code, "鎵ц鎾ゅ崟寮傚父锛歿}", str(e)) + l2_log.debug(code, "鎵ц鎾ゅ崟寮傚父锛歿}", str(e)) return False @classmethod @@ -626,13 +614,13 @@ can_cancel, reason = cls.__can_cancel(code) if not can_cancel: # 涓嶈兘鍙栨秷 - cls.cancel_debug(code, "鎾ゅ崟涓柇锛屽師鍥狅細{}", reason) - cls.debug(code, "鎾ゅ崟涓柇锛屽師鍥狅細{}", reason) + l2_log.cancel_debug(code, "鎾ゅ崟涓柇锛屽師鍥狅細{}", reason) + l2_log.debug(code, "鎾ゅ崟涓柇锛屽師鍥狅細{}", reason) return False cancel_result = cls.__cancel_buy(code) if cancel_result: trade_result_manager.real_cancel_success(code, buy_single_index, buy_exec_index, total_datas) - cls.debug(code, "鎵ц鎾ゅ崟缁撴潫锛屽師鍥狅細{}", msg) + l2_log.debug(code, "鎵ц鎾ゅ崟缁撴潫锛屽師鍥狅細{}", msg) return True # 铏氭嫙涓嬪崟 @@ -646,7 +634,7 @@ new_add=True): if compute_end_index < compute_start_index: return - _start_time = round(t.time() * 1000) + _start_time = tool.get_now_timestamp() total_datas = local_today_datas[code] # 澶勭悊瀹夊叏绗旀暟 cls.__buyL2SafeCountManager.compute_left_rate(code, compute_start_index, compute_end_index, total_datas, @@ -657,6 +645,7 @@ code) # 鏄惁涓烘柊鑾峰彇鍒扮殑浣嶇疆 + new_get_single = False if buy_single_index is None: place_order_count = trade_data_manager.placeordercountmanager.get_place_order_count(code) continue_count = 3 @@ -669,33 +658,46 @@ compute_end_index) buy_single_index = _index if has_single: + new_get_single = True num = 0 count = 0 - cls.debug(code, "鑾峰彇鍒颁拱鍏ヤ俊鍙疯捣濮嬬偣锛歿} ,璁$畻鑼冨洿锛歿}-{} 锛屾暟鎹細{}", buy_single_index, compute_start_index, - compute_end_index, total_datas[buy_single_index]) + l2_log.debug(code, "鑾峰彇鍒颁拱鍏ヤ俊鍙疯捣濮嬬偣锛歿} ,璁$畻鑼冨洿锛歿}-{} 锛屾暟鎹細{}", buy_single_index, compute_start_index, + compute_end_index, total_datas[buy_single_index]) # 濡傛灉鏄粖澶╃涓�娆℃湁涓嬪崟寮�濮嬩俊鍙凤紝闇�瑕佽缃ぇ鍗曡捣濮嬬偣 cls.l2BigNumForMProcessor.set_begin_pos(code, buy_single_index) - _start_time = l2_data_log.l2_time(code, cls.random_key[code], round(t.time() * 1000) - _start_time, "涓嬪崟淇″彿璁$畻鏃堕棿") + _start_time = l2_data_log.l2_time(code, tool.get_now_timestamp() - _start_time, "涓嬪崟淇″彿璁$畻鏃堕棿") if buy_single_index is None: # 鏈幏鍙栧埌涔板叆淇″彿锛岀粓姝㈢▼搴� return None + # 寮�濮嬭绠楃殑浣嶇疆 + start_process_index = min(buy_single_index, compute_start_index) if new_get_single else max(buy_single_index, + compute_start_index) + # 璁$畻m鍊煎ぇ鍗� - cls.l2BigNumForMProcessor.process(code, max(buy_single_index, compute_start_index), compute_end_index, + cls.l2BigNumForMProcessor.process(code, start_process_index, + compute_end_index, gpcode_manager.get_limit_up_price(code)) - _start_time = l2_data_log.l2_time(code, cls.random_key[code], round(t.time() * 1000) - _start_time, "璁$畻m鍊煎ぇ鍗�") + _start_time = l2_data_log.l2_time(code, tool.get_now_timestamp() - _start_time, "璁$畻m鍊煎ぇ鍗�") threshold_money, msg = cls.__get_threshmoney(code) - # 涔板叆绾拱棰濈粺璁� - compute_index, buy_nums, buy_count, rebegin_buy_pos, max_num_set_new = cls.__sum_buy_num_for_order_3(code, max( - buy_single_index, compute_start_index), compute_end_index, num, count, threshold_money, buy_single_index, - max_num_set) - _start_time = l2_data_log.l2_time(code, cls.random_key[code], round(t.time() * 1000) - _start_time, "绾拱棰濈粺璁℃椂闂�") - cls.debug(code, "m鍊�-{} m鍊煎洜瀛�-{}", threshold_money, msg) + _start_time = l2_data_log.l2_time(code, tool.get_now_timestamp() - _start_time, "m鍊奸槇鍊艰绠�") + + # 涔板叆绾拱棰濈粺璁� + compute_index, buy_nums, buy_count, rebegin_buy_pos, max_num_set_new = cls.__sum_buy_num_for_order_3(code, + start_process_index, + compute_end_index, + num, count, + threshold_money, + buy_single_index, + max_num_set) + _start_time = l2_data_log.l2_time(code, tool.get_now_timestamp() - _start_time, "绾拱棰濈粺璁℃椂闂�") + + l2_log.debug(code, "m鍊�-{} m鍊煎洜瀛�-{}", threshold_money, msg) # 涔板叆淇″彿浣嶄笌璁$畻浣嶇疆闂撮殧2s鍙婁互涓婁簡 if rebegin_buy_pos is not None: @@ -704,25 +706,37 @@ return if compute_index is not None: - cls.debug(code, "鑾峰彇鍒颁拱鍏ユ墽琛屼綅缃細{} m鍊硷細{} 绾拱鎵嬫暟锛歿} 绾拱鍗曟暟锛歿} 鏁版嵁锛歿}", compute_index, threshold_money, buy_nums, - buy_count, - total_datas[compute_index]) - # 璁板綍涔板叆淇″彿浣嶇疆 - cls.__save_order_begin_data(code, buy_single_index, compute_index, compute_index, buy_nums, buy_count, - max_num_set_new) - # 濡傛灉鏄粖澶╃涓�娆℃湁涓嬪崟鎵ц淇″彿锛屾定鍋滄椂闂达紙涔板叆鎵ц浣嶆椂闂达級 - limit_up_time_manager.save_limit_up_time(code, total_datas[compute_index]["val"]["time"]) - # 铏氭嫙涓嬪崟 - cls.__virtual_buy(code, buy_single_index, compute_index, capture_time) - # 鍒犻櫎涔嬪墠鐨勬墍鏈夋挙鍗曚俊鍙� - l2_data_manager.TradePointManager.delete_buy_cancel_point(code) + l2_log.debug(code, "鑾峰彇鍒颁拱鍏ユ墽琛屼綅缃細{} m鍊硷細{} 绾拱鎵嬫暟锛歿} 绾拱鍗曟暟锛歿} 鏁版嵁锛歿}", compute_index, threshold_money, buy_nums, + buy_count, total_datas[compute_index]) - # 娑ㄥ仠灏佸崟棰濊绠� - L2LimitUpMoneyStatisticUtil.process_data(cls.random_key[code], code, buy_single_index, compute_index, - buy_single_index, - buy_exec_index, False) + f1 = dask.delayed(cls.__save_order_begin_data)(code, buy_single_index, compute_index, compute_index, + buy_nums, buy_count, max_num_set_new) + f2 = dask.delayed(limit_up_time_manager.save_limit_up_time)(code, total_datas[compute_index]["val"]["time"]) + f3 = dask.delayed(cls.__virtual_buy)(code, buy_single_index, compute_index, capture_time) + f4 = dask.delayed(l2_data_manager.TradePointManager.delete_buy_cancel_point)(code) + f5 = dask.delayed(L2LimitUpMoneyStatisticUtil.process_data)(cls.random_key[code], code, buy_single_index, + compute_index, + buy_single_index, + buy_exec_index, False) + dask.compute(f1, f2, f3, f4, f5) - _start_time = l2_data_log.l2_time(code, cls.random_key[code], round(t.time() * 1000) - _start_time, + # 宸茶骞惰澶勭悊 + # # 璁板綍涔板叆淇″彿浣嶇疆 + # cls.__save_order_begin_data(code, buy_single_index, compute_index, compute_index, buy_nums, buy_count, + # max_num_set_new) + # # 濡傛灉鏄粖澶╃涓�娆℃湁涓嬪崟鎵ц淇″彿锛屾定鍋滄椂闂达紙涔板叆鎵ц浣嶆椂闂达級 + # limit_up_time_manager.save_limit_up_time(code, total_datas[compute_index]["val"]["time"]) + # # 铏氭嫙涓嬪崟 + # cls.__virtual_buy(code, buy_single_index, compute_index, capture_time) + # # 鍒犻櫎涔嬪墠鐨勬墍鏈夋挙鍗曚俊鍙� + # l2_data_manager.TradePointManager.delete_buy_cancel_point(code) + # + # # 娑ㄥ仠灏佸崟棰濊绠� + # L2LimitUpMoneyStatisticUtil.process_data(cls.random_key[code], code, buy_single_index, compute_index, + # buy_single_index, + # buy_exec_index, False) + + _start_time = l2_data_log.l2_time(code, tool.get_now_timestamp() - _start_time, "璁板綍鎵ц涔板叆鏁版嵁", force=True) # 鏁版嵁鏄惁澶勭悊瀹屾瘯 @@ -732,9 +746,9 @@ buy_single_index, compute_index, total_datas, cls.random_key[code], True) - _start_time = l2_data_log.l2_time(code, cls.random_key[code], round(t.time() * 1000) - _start_time, + _start_time = l2_data_log.l2_time(code, tool.get_now_timestamp() - _start_time, "S绾уぇ鍗曞鐞嗚�楁椂", force=True) - cls.debug(code, "鏁版嵁澶勭悊瀹屾瘯锛屼笅鍗�, 鏁版嵁鎴浘鏃堕棿-{}", capture_time) + l2_log.debug(code, "鏁版嵁澶勭悊瀹屾瘯锛屼笅鍗�, 鏁版嵁鎴浘鏃堕棿-{}", capture_time) # 鏁版嵁宸茬粡澶勭悊瀹屾瘯锛屽鏋滆繕娌℃挙鍗曞氨瀹為檯涓嬪崟 if need_cancel: if cls.cancel_buy(code, "S绾уぇ鍗曟挙閿�"): @@ -746,13 +760,13 @@ SecondCancelBigNumComputer.need_cancel(code, buy_single_index, compute_index, buy_single_index, compute_index, total_datas, cls.random_key[code], False) - _start_time = l2_data_log.l2_time(code, cls.random_key[code], round(t.time() * 1000) - _start_time, + _start_time = l2_data_log.l2_time(code, tool.get_now_timestamp() - _start_time, "S绾уぇ鍗曞鐞嗚�楁椂", force=True) # 鏁版嵁灏氭湭澶勭悊瀹屾瘯锛岃繘琛屼笅涓�姝ュ鐞� - cls.debug(code, "鏁版嵁灏氭湭澶勭悊瀹屾瘯锛岃繘琛屼笅涓�姝ュ鐞嗭紝澶勭悊杩涘害锛歿}", compute_index) + l2_log.debug(code, "鏁版嵁灏氭湭澶勭悊瀹屾瘯锛岃繘琛屼笅涓�姝ュ鐞嗭紝澶勭悊杩涘害锛歿}", compute_index) # 澶勭悊鎾ゅ崟姝ラ cls.__process_order(code, compute_index + 1, compute_end_index, capture_time, False) - _start_time = l2_data_log.l2_time(code, cls.random_key[code], round(t.time() * 1000) - _start_time, + _start_time = l2_data_log.l2_time(code, tool.get_now_timestamp() - _start_time, f"澶勭悊鎾ゅ崟姝ラ鑰楁椂锛岃寖鍥达細{compute_index + 1}-{compute_end_index}", force=True) else: @@ -841,23 +855,11 @@ def __sum_buy_num_for_order_3(cls, code, compute_start_index, compute_end_index, origin_num, origin_count, threshold_money, buy_single_index, max_num_set): def get_threshold_count(): - count = threshold_count # - sub_threshold_count - # if count < 3: - # count = 3 - # count = round(count * buy1_factor) - # # 鏈�楂�30绗旓紝鏈�浣�8绗� - # if count > 21: - # count = 21 - # if count < 8: - # count = 8 + count = threshold_count return count _start_time = t.time() total_datas = local_today_datas[code] - # 璁$畻浠庝拱鍏ヤ俊鍙峰紑濮嬪埌璁$畻寮�濮嬩綅缃殑澶у崟鏁伴噺 - sub_threshold_count = cls.__compute_big_money_count(total_datas, buy_single_index, compute_start_index - 1) - if sub_threshold_count < 0: - sub_threshold_count = 0 buy_nums = origin_num buy_count = origin_count @@ -868,15 +870,6 @@ # 鐩爣鎵嬫暟 threshold_num = round(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 = cls.__buyL2SafeCountManager.get_safe_count(code) @@ -899,6 +892,9 @@ # 绗竴娆′笅鍗曢渶瑕佸ぇ鍗曟渶灏�2绗旓紝浠ュ悗鍙渶瑕�1绗� big_num_count = 1 + # 杈冨ぇ鍗曠殑鎵嬫暟 + bigger_num = round(5900 / limit_up_price) + for i in range(compute_start_index, compute_end_index + 1): data = total_datas[i] _val = total_datas[i]["val"] @@ -917,22 +913,17 @@ # 娑ㄥ仠涔� if L2DataUtil.is_limit_up_price_buy(_val): if l2_data_util.is_big_money(_val): - # sub_threshold_count += int(total_datas[i]["re"]) max_buy_num_set.add(i) - if round(int(_val["num"]) * float(_val["price"])) >= 5900: + if _val["num"] >= bigger_num: trigger_buy = True # 鍙粺璁�59涓囦互涓婄殑閲戦 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( + f"{code}鑾峰彇鍒颁拱鍏ユ墽琛岀偣锛歿i} 缁熻绾拱鎵嬫暟锛歿buy_nums} 鐩爣绾拱鎵嬫暟锛歿threshold_num} 缁熻绾拱鍗曟暟锛歿buy_count} 鐩爣绾拱鍗曟暟锛歿get_threshold_count()}, 澶у崟鏁伴噺锛歿len(max_buy_num_set)}") elif L2DataUtil.is_limit_up_price_buy_cancel(_val): - if l2_data_util.is_big_money(_val): - sub_threshold_count -= int(total_datas[i]["re"]) - if round(int(_val["num"]) * float(_val["price"])) >= 5900: + if _val["num"] >= bigger_num: # 鍙粺璁�59涓囦互涓婄殑閲戦 # 娑ㄥ仠涔版挙 # 鍒ゆ柇涔板叆浣嶇疆鏄惁鍦ㄤ拱鍏ヤ俊鍙蜂箣鍓� @@ -944,31 +935,35 @@ if buy_index >= buy_single_index: buy_nums -= int(_val["num"]) * int(data["re"]) buy_count -= int(data["re"]) - cls.buy_debug(code, "{}鏁版嵁鍦ㄤ拱鍏ヤ俊鍙蜂箣鍚� 鎾や拱绾拱鎵嬫暟锛歿} 鐩爣鎵嬫暟锛歿}", i, buy_nums, threshold_num) + # 澶у崟鎾ら攢 + max_buy_num_set.discard(buy_index) + l2_log.buy_debug(code, "{}鏁版嵁鍦ㄤ拱鍏ヤ俊鍙蜂箣鍚� 鎾や拱绾拱鎵嬫暟锛歿} 鐩爣鎵嬫暟锛歿}", i, buy_nums, threshold_num) else: - cls.buy_debug(code, "{}鏁版嵁鍦ㄤ拱鍏ヤ俊鍙蜂箣鍓嶏紝涔板叆浣嶏細{}", i, buy_index) + l2_log.buy_debug(code, "{}鏁版嵁鍦ㄤ拱鍏ヤ俊鍙蜂箣鍓嶏紝涔板叆浣嶏細{}", i, buy_index) if total_datas[buy_single_index]["val"]["time"] == buy_data["val"]["time"]: # 鍚屼竴绉�,褰撲綔涔板叆淇″彿涔嬪悗澶勭悊 buy_nums -= int(_val["num"]) * int(data["re"]) buy_count -= int(data["re"]) - cls.buy_debug(code, "{}鏁版嵁涔板叆浣嶄笌棰勪及涔板叆浣嶅湪鍚屼竴绉�", i) + # 澶у崟鎾ら攢 + max_buy_num_set.discard(buy_index) + l2_log.buy_debug(code, "{}鏁版嵁涔板叆浣嶄笌棰勪及涔板叆浣嶅湪鍚屼竴绉�", i) else: # 鏈壘鍒颁拱鎾ゆ暟鎹殑涔板叆鐐� - cls.buy_debug(code, "鏈壘鍒颁拱鎾ゆ暟鎹殑涔板叆鐐�: 浣嶇疆-{} 鏁版嵁-{}", i, data) + l2_log.buy_debug(code, "鏈壘鍒颁拱鎾ゆ暟鎹殑涔板叆鐐�: 浣嶇疆-{} 鏁版嵁-{}", i, data) buy_nums -= int(_val["num"]) * int(total_datas[i]["re"]) buy_count -= int(total_datas[i]["re"]) - cls.buy_debug(code, "浣嶇疆-{}锛屾�绘墜鏁帮細{}锛岀洰鏍囨墜鏁帮細{}", i, - buy_nums, threshold_num) + l2_log.buy_debug(code, "浣嶇疆-{}锛屾�绘墜鏁帮細{}锛岀洰鏍囨墜鏁帮細{}", i, + buy_nums, threshold_num) # 鏈夋挙鍗曚俊鍙凤紝涓斿皬浜庨槇鍊� if buy_nums >= threshold_num and buy_count >= get_threshold_count() and trigger_buy and len( max_buy_num_set) >= big_num_count: return i, buy_nums, buy_count, None, max_buy_num_set - cls.buy_debug(code, "灏氭湭鑾峰彇鍒颁拱鍏ユ墽琛岀偣锛岃捣濮嬭绠椾綅缃細{} 缁熻绾拱鎵嬫暟锛歿} 鐩爣绾拱鎵嬫暟锛歿} 缁熻绾拱鍗曟暟锛歿} 鐩爣绾拱鍗曟暟锛歿} 澶у崟鏁伴噺锛歿} 鐩爣澶у崟鏁伴噺锛歿}", - compute_start_index, - buy_nums, - threshold_num, buy_count, get_threshold_count(), len(max_buy_num_set), big_num_count) + l2_log.buy_debug(code, "灏氭湭鑾峰彇鍒颁拱鍏ユ墽琛岀偣锛岃捣濮嬭绠椾綅缃細{} 缁熻绾拱鎵嬫暟锛歿} 鐩爣绾拱鎵嬫暟锛歿} 缁熻绾拱鍗曟暟锛歿} 鐩爣绾拱鍗曟暟锛歿} 澶у崟鏁伴噺锛歿} 鐩爣澶у崟鏁伴噺锛歿}", + compute_start_index, + buy_nums, + threshold_num, buy_count, get_threshold_count(), len(max_buy_num_set), big_num_count) return None, buy_nums, buy_count, None, max_buy_num_set @@ -1132,6 +1127,6 @@ # local_today_num_operate_map.get( # "600213")) # print(buy_index, buy_data) - dict_={"code":0} + dict_ = {"code": 0} dict_.clear() print(dict_) -- Gitblit v1.8.0