From b03f1ca7c2d77be46ca55c7fb68ae6215783840a Mon Sep 17 00:00:00 2001 From: Administrator <admin@example.com> Date: 星期三, 17 四月 2024 18:46:35 +0800 Subject: [PATCH] 买入调整 --- l2/l2_data_manager_new.py | 179 +++++++++++++++++++++++++++++++++++++---------------------- 1 files changed, 111 insertions(+), 68 deletions(-) diff --git a/l2/l2_data_manager_new.py b/l2/l2_data_manager_new.py index 14a093c..c312313 100644 --- a/l2/l2_data_manager_new.py +++ b/l2/l2_data_manager_new.py @@ -1360,8 +1360,9 @@ # if code.find('60') == 0: # 婵�杩涗拱 continue_count = 1 - has_single, _index, sell_info = cls.__compute_active_order_begin_pos(code, continue_count, - compute_start_index, compute_end_index) + has_single, _index, sell_info, single_msg = cls.__compute_active_order_begin_pos(code, continue_count, + compute_start_index, + compute_end_index) fast_msg = None if has_single: order_begin_pos.mode = OrderBeginPosInfo.MODE_ACTIVE @@ -1453,11 +1454,12 @@ # 鎬诲崠棰濈殑1鍊� order_begin_pos.threshold_money = int(sell_info[1] * 1.0) - l2_log.debug(code, "鑾峰彇鍒颁拱鍏ヤ俊鍙疯捣濮嬬偣锛歿} ,璁$畻鑼冨洿锛歿}-{} 锛岄噺姣旓細{}锛屾槸鍚︽澘涓婁拱锛歿}锛屾暟鎹細{} 妯″紡锛歿}锛坽}锛�", buy_single_index, + l2_log.debug(code, "鑾峰彇鍒颁拱鍏ヤ俊鍙疯捣濮嬬偣锛歿} ,璁$畻鑼冨洿锛歿}-{} 锛岄噺姣旓細{}锛屾槸鍚︽澘涓婁拱锛歿}锛屾暟鎹細{} 妯″紡锛歿}锛坽}锛� 淇″彿绫诲瀷锛歿}", + buy_single_index, compute_start_index, compute_end_index, cls.volume_rate_info[code], order_begin_pos.at_limit_up, total_datas[buy_single_index], - order_begin_pos.mode, fast_msg) + order_begin_pos.mode, fast_msg, single_msg) # _start_time = l2_data_log.l2_time(code, tool.get_now_timestamp() - _start_time, "涓嬪崟淇″彿璁$畻鏃堕棿") @@ -1695,11 +1697,66 @@ return True, i, [refer_sell_data[0], threshold_money] return False, None, None + @classmethod + def __get_active_single_start_index(cls, code, start_index, end_index, continue_count, valid_single=False): + """ + 鑾峰彇涓诲姩涔扮殑淇″彿璧峰绱㈠紩 + @param code: + @param start_index: + @param end_index: + @param continue_count: + @param valid_single: 鏄惁楠岃瘉鎴愪氦涔板叆淇″彿 + @return: + """ + total_datas = local_today_datas[code] + last_index = None + count = 0 + start = None + for i in range(start_index, end_index + 1): + _val = total_datas[i]["val"] + if L2DataUtil.is_limit_up_price_buy(_val): + # 鏃堕棿瑕�>=09:30:00 + if tool.trade_time_sub(_val["time"], "09:30:00") < 0: + continue + # 閲戦瑕佸ぇ浜�50涓� + if _val["num"] * float(_val["price"]) < 5000: + continue + if last_index is None or ( + total_datas[last_index]["val"]["time"] == total_datas[i]["val"]["time"]): + # 娣辫瘉闈炴澘涓婃斁閲忛渶瑕佸垽鏂槸鍚︽湁淇″彿 + if valid_single: + _single = place_order_single_data_manager.L2TradeSingleDataManager.get_valid_trade_single( + code, + tool.to_time_with_ms( + _val['time'], + _val['tms'])) + if not _single: + continue + if start is None: + start = i + last_index = i + count += total_datas[i]["re"] + if count >= continue_count: + return start + else: + # 鏈潯鏁版嵁浣滀负璧风偣 + last_index = i + count = total_datas[i]["re"] + start = i + elif not L2DataUtil.is_sell(_val) and not L2DataUtil.is_sell_cancel(_val): + # 鍓旈櫎鍗栦笌鍗栨挙 + last_index = None + count = 0 + start = None + return None + # 璁$畻婵�杩涗拱鐨勪笅鍗曚俊鍙� @classmethod def __compute_active_order_begin_pos(cls, code, continue_count, start_index, end_index): total_datas = local_today_datas[code] start_time_str = total_datas[start_index]["val"]["time"] + if end_index - start_index + 1 < continue_count: + return False, -1, "淇″彿涓嶈繛缁�", '' # 鑾峰彇鏈�杩戠殑鎬诲崠淇℃伅 # (time_str, round(money), volume, sell_1_info) refer_sell_data = cls.__L2MarketSellManager.get_refer_sell_data(code, start_time_str) @@ -1718,12 +1775,12 @@ # 閲戦瑕佸ぇ浜�50涓� if _val["num"] * float(_val["price"]) < 5000: continue - return True, i, [refer_sell_data[0], refer_sell_data[1]] - return False, -1, "鏈幏鍙栧埌婵�杩涗拱鐨勮捣濮嬩俊鍙�" + return True, i, [refer_sell_data[0], 0], '涓婅瘉涔板叆' + return False, -1, "鏈幏鍙栧埌婵�杩涗拱鐨勮捣濮嬩俊鍙�", '' else: # 娣辫瘉 if refer_sell_data is None: - return False, -1, "鎬诲崠涓虹┖" + return False, -1, "鎬诲崠涓虹┖", '' if refer_sell_data is None: refer_sell_data = (start_time_str, 0, 0, (round(float(total_datas[start_index]["val"]["price"]), 2), 0)) l2_log.debug(code, f"涓㈠け鎬诲崠棰濓紝璁剧疆榛樿涓�0锛岃绠楄寖鍥达細{start_index}-{end_index}") @@ -1738,66 +1795,47 @@ is_limit_up = True if refer_sell_data[1] > 0 or single or not is_limit_up: # 涓嶆槸鏉夸笂鏀鹃噺 - pass + # 鍒ゆ柇鏈�杩戞湁娌℃湁娑ㄥ仠鍗栨暟鎹� + limit_up_sell_count = L2TradeSingleDataProcessor.get_latest_limit_up_sell_order_count(code) + if limit_up_sell_count == 0 and not single: + # 濡傛灉娌℃湁娑ㄥ仠鍗栨暟鎹�屼笖杩樻病鏈夋垚浜や拱鍏ヤ俊鍙凤紝灏辨寜鐓у師鏉ョ殑鎬诲崠棰濊绠� + threshold_money, sell_1_price = refer_sell_data[1], refer_sell_data[3][0] + for i in range(start_index - 1, -1, -1): + val = total_datas[i]["val"] + if tool.compare_time(val["time"], refer_sell_data[0]) < 0: + # 灏嗘湰s鐨勮绠椾笂鍘� + break + if L2DataUtil.is_sell(val): + threshold_money += val["num"] * int(float(val["price"]) * 100) + elif L2DataUtil.is_sell_cancel(val): + threshold_money -= val["num"] * int(float(val["price"]) * 100) + elif L2DataUtil.is_buy(val): + # 鍒ゆ柇浠锋牸锛堝ぇ浜庡崠1锛� 琚拱鍚冩帀 + if round(float(val["price"]), 2) - sell_1_price >= 0: + threshold_money -= val["num"] * int(float(val["price"]) * 100) + buy_single_index = cls.__get_active_single_start_index(code, start_index, end_index, continue_count, + valid_single=False) + if buy_single_index is not None: + return True, buy_single_index, [refer_sell_data[0], threshold_money], "涓婃澘鏃犳定鍋滃崠" + + else: + # 鎸夌収鎴愪氦涔板叆淇″彿璁$畻 + buy_single_index = cls.__get_active_single_start_index(code, start_index, end_index, continue_count, + valid_single=True) + if buy_single_index is not None: + return True, buy_single_index, [refer_sell_data[0], 0], "涓婃澘鏈夋垚浜や拱鍏ヤ俊鍙�" else: - # 鏉夸笂鏀鹃噺 - pass + # 鏉夸笂鏀鹃噺锛氬彧闇�瑕佷竴绗旀定鍋滀拱鍙綔涓轰俊鍙� + buy_single_index = cls.__get_active_single_start_index(code, start_index, end_index, continue_count, + valid_single=False) + if buy_single_index is not None: + return True, buy_single_index, [refer_sell_data[0], 0], "鏉夸笂鏀鹃噺" - # 鑾峰彇褰撳墠鏄惁鍙縺杩涗拱 - # 鑾峰彇鏉垮潡鏄惁鍙互婵�杩涗拱 - # 鍙拱鐨勬澘鍧�, 鏄惁鐙嫍, 娑堟伅, 鍙拱鐨勫己鍔挎澘鍧�, 鍏抽敭璇�, 婵�杩涗拱鐨勬澘鍧� - can_buy_result = CodePlateKeyBuyManager.can_buy(code) - if (can_buy_result and can_buy_result[0] and can_buy_result[5]) or constant.ALL_ACTIVE_BUY: - # 鏈夊彲涔版澘鍧楋紝鏈夋縺杩涗拱鏉垮潡 - # 绗竴姝ワ細 璁$畻鎬诲崠棰� - threshold_money, sell_1_price = refer_sell_data[1], refer_sell_data[3][0] - # 绗簩姝ワ細璁$畻璧峰淇″彿 - second_930 = 9 * 3600 + 30 * 60 + 0 - total_datas = local_today_datas.get(code) - if end_index - start_index + 1 < continue_count: - return False, -1, "淇″彿涓嶈繛缁�" - last_index = None - count = 0 - start = None - for i in range(start_index, end_index + 1): - _val = total_datas[i]["val"] - time_s = L2DataUtil.get_time_as_second(_val["time"]) - # 鏃堕棿瑕�>=09:30:00 - if time_s < second_930: - continue - if L2DataUtil.is_limit_up_price_buy(_val): - # 閲戦瑕佸ぇ浜�50涓� - if _val["num"] * float(_val["price"]) < 5000: - continue - if last_index is None or ( - total_datas[last_index]["val"]["time"] == total_datas[i]["val"]["time"]): - if code.find("00") == 0 and threshold_money > 0: - # 娣辫瘉闈炴澘涓婃斁閲忛渶瑕佸垽鏂槸鍚︽湁淇″彿 - single = place_order_single_data_manager.L2TradeSingleDataManager.get_valid_trade_single( - code, - tool.to_time_with_ms( - _val['time'], - _val['tms'])) - if not single: - continue - if start is None: - start = i - last_index = i - count += total_datas[i]["re"] - if count >= continue_count: - return True, start, [refer_sell_data[0], threshold_money] - else: - # 鏈潯鏁版嵁浣滀负璧风偣 - last_index = i - count = total_datas[i]["re"] - start = i + return False, -1, "鏈幏鍙栧埌婵�杩涗拱鐨勮捣濮嬩俊鍙�", '' - elif not L2DataUtil.is_sell(_val) and not L2DataUtil.is_sell_cancel(_val): - # 鍓旈櫎鍗栦笌鍗栨挙 - last_index = None - count = 0 - start = None - return False, -1, "鏈幏鍙栧埌婵�杩涗拱鐨勮捣濮嬩俊鍙�" + @classmethod + def test__compute_active_order_begin_pos(cls, code, continue_count, start_index, end_index): + return cls.__compute_active_order_begin_pos(code, continue_count, start_index, end_index) @classmethod def __get_threshmoney(cls, code): @@ -2159,9 +2197,16 @@ raise Exception("娑ㄥ仠浠锋棤娉曡幏鍙�") limit_up_price = float(limit_up_price) + is_at_limit_up = False + current_sell_data = cls.__L2MarketSellManager.get_current_total_sell_data(code) + if current_sell_data and current_sell_data[1] ==0: + # 鏉夸笂鏀鹃噺涔� + is_at_limit_up = True + + threshold_money = threshold_money_origin # 鐩爣鎵嬫暟 - threshold_num = 0 # round(threshold_money / (limit_up_price * 100)) + threshold_num = round(threshold_money / (limit_up_price * 100)) bigger_threshold_num = round(5000 / (limit_up_price)) # buy_single_time_seconds = L2DataUtil.get_time_as_second(total_datas[buy_single_index]["val"]["time"]) @@ -2170,11 +2215,9 @@ trigger_buy = True # 闂撮殧鏈�澶ф椂闂翠负3s max_space_time_ms = 3 * 1000 - if code.find("00") == 0 and threshold_money > 0: + if code.find("00") == 0 and not is_at_limit_up: # 娣辫瘉闈炴澘涓婃斁閲� max_space_time_ms = 1 * 1000 - # 涓嶇湅绾拱棰� - threshold_num = 0 # 涓嶄笅鍗曠殑淇℃伅 not_buy_msg = "" -- Gitblit v1.8.0