| | |
| | | return info |
| | | |
| | | |
| | | RELIABILITY_TYPE_REAL = 1 # 真实下单位 |
| | | RELIABILITY_TYPE_VIRTUAL = 2 # 影子单下单位 |
| | | RELIABILITY_TYPE_ESTIMATE = 3 # 估算下单位 |
| | | |
| | | |
| | | # 计算预估下单位 |
| | | def __compute_estimate_order_position(code, exec_buy_index): |
| | | total_datas = l2_data_util.local_today_datas.get(code) |
| | | exec_data = total_datas[exec_buy_index] |
| | | THRESH_MS = 20 if code.find('00') == 0 else 100 |
| | | for i in range(exec_buy_index, total_datas[-1]["index"]): |
| | | if L2DataUtil.time_sub_as_ms(total_datas[i]['val'], exec_data["val"]) >= THRESH_MS: |
| | | return i |
| | | return None |
| | | |
| | | |
| | | # L2数据列表 |
| | | # 范围(位置信息,可信的类型) |
| | | def get_l2_place_order_position(code, limit_up_price, datas): |
| | | order_info = get_order_info(code) |
| | | if not order_info: |
| | |
| | | price = order_info[0] |
| | | volume = order_info[1] |
| | | exec_data = order_info[2] |
| | | order_time = order_info[3] # 下单时间 |
| | | order_ref = order_info[4] |
| | | shadow_price = order_info[5] |
| | | shadow_place_order_index = None |
| | |
| | | continue |
| | | shadow_place_order_index = d["index"] |
| | | break |
| | | if shadow_place_order_index is None: |
| | | return None |
| | | total_datas = l2_data_util.local_today_datas.get(code) |
| | | # 找到不是同一ms的结束 |
| | | temp_start_index = shadow_place_order_index |
| | | for i in range(shadow_place_order_index - 1, -1, -1): |
| | | val = total_datas[i]["val"] |
| | | if val["tms"] != total_datas[shadow_place_order_index]["val"]["tms"]: |
| | | break |
| | | temp_start_index = i |
| | | start_index = max(min(temp_start_index, min(datas[0]["index"], shadow_place_order_index - 15)), 0) |
| | | end_index = min(shadow_place_order_index + 10, datas[-1]["index"]) |
| | | real_place_index = None |
| | | # 从中间向两头遍历 |
| | | for i in range(shadow_place_order_index - 1, start_index - 1, -1): |
| | | d = total_datas[i] |
| | | if d["val"]["num"] != volume // 100: |
| | | continue |
| | | if abs(float(price) - float(d["val"]["price"])) >= 0.01: |
| | | continue |
| | | # 必须是买入 |
| | | if not L2DataUtil.is_limit_up_price_buy(d["val"]): |
| | | continue |
| | | real_place_index = i |
| | | break |
| | | if not real_place_index: |
| | | for i in range(shadow_place_order_index + 1, end_index): |
| | | real_place_index_info = None |
| | | if shadow_place_order_index: |
| | | total_datas = l2_data_util.local_today_datas.get(code) |
| | | # 找到不是同一ms的结束 |
| | | temp_start_index = shadow_place_order_index |
| | | for i in range(shadow_place_order_index - 1, -1, -1): |
| | | val = total_datas[i]["val"] |
| | | if val["tms"] != total_datas[shadow_place_order_index]["val"]["tms"]: |
| | | break |
| | | temp_start_index = i |
| | | start_index = max(min(temp_start_index, min(datas[0]["index"], shadow_place_order_index - 15)), 0) |
| | | end_index = min(shadow_place_order_index + 10, datas[-1]["index"]) |
| | | real_place_index = None |
| | | # 从中间向两头遍历 |
| | | for i in range(shadow_place_order_index - 1, start_index - 1, -1): |
| | | d = total_datas[i] |
| | | if d["val"]["num"] != volume // 100: |
| | | continue |
| | |
| | | continue |
| | | real_place_index = i |
| | | break |
| | | if not real_place_index: |
| | | real_place_index = shadow_place_order_index |
| | | # 获取到了下单位置 |
| | | async_log_util.info(hx_logger_trade_debug, f"真实下单位置:{code}-{real_place_index}") |
| | | async_log_util.info(logger_real_place_order_position, f"真实下单位置:{code}-{real_place_index}") |
| | | if code in _place_order_info_dict: |
| | | _place_order_info_dict.pop(code) |
| | | __place_order_position[code] = real_place_index |
| | | return real_place_index |
| | | if not real_place_index: |
| | | for i in range(shadow_place_order_index + 1, end_index): |
| | | d = total_datas[i] |
| | | if d["val"]["num"] != volume // 100: |
| | | continue |
| | | if abs(float(price) - float(d["val"]["price"])) >= 0.01: |
| | | continue |
| | | # 必须是买入 |
| | | if not L2DataUtil.is_limit_up_price_buy(d["val"]): |
| | | continue |
| | | real_place_index = i |
| | | break |
| | | |
| | | if not real_place_index: |
| | | real_place_index_info = shadow_place_order_index, RELIABILITY_TYPE_VIRTUAL |
| | | else: |
| | | real_place_index_info = real_place_index, RELIABILITY_TYPE_REAL |
| | | elif time.time() - order_time >= 1: |
| | | # 下单超过1s |
| | | estimate_index = __compute_estimate_order_position(code, exec_data["index"]) |
| | | if estimate_index: |
| | | real_place_index_info = estimate_index, RELIABILITY_TYPE_ESTIMATE |
| | | if real_place_index_info: |
| | | # 获取到了下单位置 |
| | | async_log_util.info(hx_logger_trade_debug, f"真实下单位置:{code}-{real_place_index_info}") |
| | | async_log_util.info(logger_real_place_order_position, f"真实下单位置:{code}-{real_place_index_info}") |
| | | if code in _place_order_info_dict: |
| | | _place_order_info_dict.pop(code) |
| | | __place_order_position[code] = real_place_index_info[0] |
| | | return real_place_index_info[0] |
| | | else: |
| | | return None |
| | | |
| | | |
| | | # 获取真实下单位置 |