L后稳定后囊括修复/真实下单位完善/单笔下单金额改为2w
| | |
| | | if tool.trade_time_sub(total_datas[-1]["val"]["time"], |
| | | canceled_buyno_map[orderNo]["val"]["time"]) < 10 * 60: |
| | | continue |
| | | val = total_datas[index]["val"] |
| | | time_str = L2DataUtil.get_time_with_ms(val) |
| | | # 统计撤单时间 |
| | | cancel_val = canceled_buyno_map[orderNo]["val"] |
| | | time_str = L2DataUtil.get_time_with_ms(cancel_val) |
| | | if time_str not in cancel_time_dict: |
| | | cancel_time_dict[time_str] = set() |
| | | cancel_time_dict[time_str].add(index) |
| | |
| | | ########华鑫配置######## |
| | | if not is_windows() or True: |
| | | # 下单1手 |
| | | BUY_MONEY_PER_CODE = 500 if constant.IS_A else 15000 |
| | | BUY_MONEY_PER_CODE = 500 if constant.IS_A else 20000 |
| | | L2_SOURCE_TYPE = L2_SOURCE_TYPE_HUAXIN |
| | | JUEJIN_LOCAL_API = False |
| | | TRADE_WAY = TRADE_WAY_HUAXIN |
| | |
| | | # L2数据列表 |
| | | # 范围(位置信息,可信的类型) |
| | | def get_l2_place_order_position(code, limit_up_price, datas): |
| | | """ |
| | | 计算真实下单位置 |
| | | @param code: |
| | | @param limit_up_price: |
| | | @param datas: |
| | | @return:(真实下单位置,下单数据,真实下单计算类型) |
| | | """ |
| | | order_info = get_order_info(code) |
| | | if not order_info: |
| | | # 暂无下单信息 |
| | |
| | | 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: |
| | |
| | | real_place_index = i |
| | | break |
| | | 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: |
| | |
| | | break |
| | | |
| | | if not real_place_index: |
| | | real_place_index_info = shadow_place_order_index, RELIABILITY_TYPE_VIRTUAL |
| | | # 与真实下单下单时间超过500ms才能以虚拟单的位置作为真实下单位置 |
| | | if time.time() - order_time > 0.5: |
| | | real_place_index_info = shadow_place_order_index, RELIABILITY_TYPE_VIRTUAL |
| | | else: |
| | | real_place_index_info = real_place_index, RELIABILITY_TYPE_REAL |
| | | elif tool.trade_time_sub(datas[-1]['val']['time'], exec_data['val']['time']) >= estimate_time_space and time.time() - order_time >5: |
| | |
| | | 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], order_info |
| | | return real_place_index_info[0], order_info, real_place_index_info[1] |
| | | else: |
| | | return None, order_info |
| | | return None, order_info, None |
| | | |
| | | |
| | | # 因为L2数据慢的问题而重新计算 |
| | | def recompute_for_slow_time(code, order_info, real_place_index): |
| | | def recompute_for_slow_time(code, order_info, real_place_index, compute_type): |
| | | try: |
| | | # 计算当前时间是否满足时间条件 |
| | | now_time_str = tool.get_now_time_str() |
| | | if tool.trade_time_sub(now_time_str, "09:30:00") < 60 or 0 <= tool.trade_time_sub(now_time_str, |
| | | "13:00:00") <= 60: |
| | | "13:00:00") <= 60 or compute_type == RELIABILITY_TYPE_VIRTUAL: |
| | | price = order_info[0] |
| | | volume = order_info[1] |
| | | exec_data = order_info[2] |
| | |
| | | origin_datas.clear() |
| | | |
| | | @classmethod |
| | | def __recompute_real_order_index(cls, code, pre_real_order_index, order_info): |
| | | def __recompute_real_order_index(cls, code, pre_real_order_index, order_info, compute_type): |
| | | # 因为数据慢的问题重新计算 |
| | | real_order_index = huaxin_delegate_postion_manager.recompute_for_slow_time(code, order_info, |
| | | pre_real_order_index) |
| | | pre_real_order_index, compute_type) |
| | | if real_order_index: |
| | | try: |
| | | exec_index = order_info[6] |
| | |
| | | # cls.set_real_place_order_index(code, place_order_index, order_begin_pos.buy_single_index) |
| | | else: |
| | | # 获取下单位置 |
| | | place_order_index, order_info = huaxin_delegate_postion_manager.get_l2_place_order_position( |
| | | place_order_index, order_info, compute_type = huaxin_delegate_postion_manager.get_l2_place_order_position( |
| | | code, float( |
| | | gpcode_manager.get_limit_up_price(code)), add_datas) |
| | | if place_order_index: |
| | |
| | | cls.set_real_place_order_index(code, place_order_index, order_begin_pos) |
| | | try: |
| | | cls.__re_compute_threading_pool.submit( |
| | | cls.__recompute_real_order_index, code, place_order_index, order_info) |
| | | cls.__recompute_real_order_index, code, place_order_index, order_info, compute_type) |
| | | except: |
| | | pass |
| | | async_log_util.info(logger_l2_process, f"code:{code} 获取到下单真实位置:{place_order_index}") |
| | |
| | | if cancel_index is None: |
| | | cancel_index = total_datas[-1]["index"] |
| | | cls.__LatestCancelIndexManager.set_latest_cancel_index(code, cancel_index) |
| | | |
| | | # 记录撤单日志 |
| | | real_place_order_index = SCancelBigNumComputer().get_real_place_order_index_cache(code) |
| | | # 添加撤单日志记录 |
| | | trade_record_log_util.add_cancel_msg_log(code, msg) |
| | | trade_record_log_util.add_cancel_msg_log(code, real_place_order_index, msg) |
| | | cancel_result = cls.__cancel_buy(code) |
| | | if cancel_result: |
| | | trade_result_manager.real_cancel_success(code, order_begin_pos.buy_single_index, |
| | |
| | | |
| | | class PlaceOrderInfo(object): |
| | | def __init__(self, buy_single_index=None, buy_exec_index=None, m_val=None, safe_count=None, big_num_indexes=None, |
| | | kpl_blocks=None, kpl_match_blocks=None, mode=None, mode_desc=None, sell_info = None): |
| | | kpl_blocks=None, kpl_match_blocks=None, mode=None, mode_desc=None, sell_info=None): |
| | | self.buy_single_index = buy_single_index |
| | | self.buy_exec_index = buy_exec_index |
| | | self.m_val = m_val |
| | |
| | | |
| | | |
| | | # 添加撤单信息 |
| | | def add_cancel_msg_log(code, msg): |
| | | __add_log(TYPE_CANCEL, code, {"msg": msg}) |
| | | def add_cancel_msg_log(code, real_place_order_index, msg): |
| | | __add_log(TYPE_CANCEL, code, {"msg": msg, "real_place_order_index": real_place_order_index}) |
| | | |
| | | |
| | | if __name__ == "__main__": |