From fddfc0e7c3b2938f70637e54d214faab478f7ca4 Mon Sep 17 00:00:00 2001 From: Administrator <admin@example.com> Date: 星期五, 13 十月 2023 12:54:20 +0800 Subject: [PATCH] 测试影子订单 --- l2/huaxin/huaxin_delegate_postion_manager.py | 16 ++++++++++------ huaxin_client/trade_client.py | 16 +++++++++++++++- utils/huaxin_util.py | 2 +- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/huaxin_client/trade_client.py b/huaxin_client/trade_client.py index 2999033..d6404da 100644 --- a/huaxin_client/trade_client.py +++ b/huaxin_client/trade_client.py @@ -161,7 +161,9 @@ return # 鎾や拱 - def cancel_buy(self, code, sinfo, order_sys_id=None, order_ref=None, order_action_ref=None): + def cancel_buy(self, code, sinfo, order_sys_id=None, order_ref=None, order_action_ref=None, delay_s=0.0): + if delay_s > 0: + time.sleep(delay_s) if sinfo in self.__cancel_buy_sinfo_set: raise Exception(f'鎾ゅ崟璇锋眰宸茬粡鎻愪氦锛歿sinfo}') async_log_util.info(logger_local_huaxin_trade_debug, @@ -851,6 +853,18 @@ # threading.Thread(target=lambda: self.__tradeSimpleApi.buy(code, volume, price, sinfo, order_ref), # daemon=True).start() self.trade_thread_pool.submit(self.__tradeSimpleApi.buy, code, volume, price, sinfo, order_ref) + # 涓嬩竴涓奖瀛愯鍗� + shadow_order_ref = order_ref + 1 + shadow_sinfo = f"s_b_{order_ref}" + shadow_price = price - 0.05 + self.trade_thread_pool.submit(self.__tradeSimpleApi.buy, code, volume, shadow_price, shadow_sinfo, + shadow_order_ref) + # 鎾ゆ帀褰卞瓙鍗� + shadow_cancel_order_ref = shadow_order_ref + 1 + self.trade_thread_pool.submit( + lambda: self.__tradeSimpleApi.cancel_buy(code, f"s_c_{shadow_order_ref}", order_sys_id=None, + order_ref=shadow_order_ref, + order_action_ref=shadow_cancel_order_ref, delay_s=0.05)) async_log_util.info(logger_trade, f"{code}鍗庨懌鏈湴涓嬪崟绾跨▼缁撴潫") except Exception as e: send_response(json.dumps({"code": 1, "msg": str(e)}), TYPE_ORDER, client_id, diff --git a/l2/huaxin/huaxin_delegate_postion_manager.py b/l2/huaxin/huaxin_delegate_postion_manager.py index a0d862d..31fa507 100644 --- a/l2/huaxin/huaxin_delegate_postion_manager.py +++ b/l2/huaxin/huaxin_delegate_postion_manager.py @@ -13,17 +13,17 @@ # 涓嬪崟 -def place_order(code, price, volume, data): +def place_order(code, price, volume, data, order_ref): async_log_util.info(logger_real_place_order_position, - f"涓嬪崟锛歝ode-{code} price-{price} volume-{volume} exec-index-{data['index']}") - _place_order_info_dict[code] = (price, volume, data, time.time()) + f"涓嬪崟锛歝ode-{code} price-{price} volume-{volume} exec-index-{data['index']} order_ref-{order_ref}") + _place_order_info_dict[code] = (price, volume, data, time.time(), order_ref) # 鑾峰彇涓嬪崟淇℃伅 def get_order_info(code): info = _place_order_info_dict.get(code) - if info and time.time() - info[3] > 3: - async_log_util.info(logger_real_place_order_position, "get_order_info 闂撮殧3s浠ヤ笂锛歝ode-{}", code) + if info and time.time() - info[3] > 1: + async_log_util.info(logger_real_place_order_position, "get_order_info 闂撮殧1s浠ヤ笂锛歝ode-{}", code) # 闂撮殧3s浠ヤ笂灏辨棤鏁堜簡 info = None _place_order_info_dict.pop(code) @@ -39,10 +39,11 @@ price = order_info[0] volume = order_info[1] exec_data = order_info[2] + order_ref = order_info[4] # 鑾峰彇閲� is_sz = code.startswith("00") # 鎻愪氦鍒颁氦鏄撴墍鐨勬椂闂撮浼� - min_space_time_ms = 10 if is_sz else 50 + min_space_time_ms = -1 if is_sz else 50 for d in datas: if d["val"]["num"] != volume // 100: continue @@ -59,6 +60,9 @@ # 鏃堕棿宸笉鑳藉皬浜庨浼颁笅鍗曠敤鏃� if L2DataUtil.time_sub_as_ms(d['val'], exec_data['val']) <= min_space_time_ms: continue + # 鐪熷疄涓嬪崟浣嶇疆涓庢寕鍗曚綅缃笉鑳界浉宸�1s + if L2DataUtil.time_sub_as_ms(d["val"], exec_data['val']) >= 1000: + continue # 鑾峰彇鍒颁簡涓嬪崟浣嶇疆 async_log_util.info(hx_logger_trade_debug, f"鐪熷疄涓嬪崟浣嶇疆锛歿code}-{d['index']}") async_log_util.info(logger_real_place_order_position, f"鐪熷疄涓嬪崟浣嶇疆锛歿code}-{d['index']}") diff --git a/utils/huaxin_util.py b/utils/huaxin_util.py index 6dbef0a..2ce0e45 100644 --- a/utils/huaxin_util.py +++ b/utils/huaxin_util.py @@ -64,7 +64,7 @@ __order_ref_lock.acquire() try: global __public_order_ref - __public_order_ref += random.randint(1, 20) + __public_order_ref += random.randint(5, 20) return __public_order_ref finally: __order_ref_lock.release() -- Gitblit v1.8.0