| | |
| | | |
| | | # 正式账号 |
| | | from huaxin_client.trade_transform_protocol import TradeRequest, TradeResponse |
| | | from log_module import async_log_util |
| | | from log_module.log import logger_local_huaxin_trade_debug, logger_system |
| | | |
| | | UserID = '388000013349' |
| | |
| | | if local_order_id: |
| | | if local_order_id not in cls.local_order_id_map and orderSystemId: |
| | | cls.local_order_id_map[local_order_id] = orderSystemId |
| | | logger_local_huaxin_trade_debug.info(f"本地订单号与系统订单号映射,{code}:{local_order_id} {orderSystemId}") |
| | | async_log_util.info( logger_local_huaxin_trade_debug, f"本地订单号与系统订单号映射,{code}:{local_order_id} {orderSystemId}") |
| | | if local_order_id in cls.not_canceled_local_order_ids: |
| | | logger_local_huaxin_trade_debug.info(f"执行等待撤单,{code}:{local_order_id} {orderSystemId}") |
| | | async_log_util.info(logger_local_huaxin_trade_debug,f"执行等待撤单,{code}:{local_order_id} {orderSystemId}") |
| | | # 执行撤单 |
| | | cls.not_canceled_local_order_ids.discard(local_order_id) |
| | | for i in range(3): |
| | |
| | | |
| | | # 判断当前订单是否已经撤单 |
| | | left_count = l2_data_source_util.L2DataSourceUtils.get_limit_up_buy_no_canceled_count(code, i, total_data, |
| | | local_today_num_operate_map.get(code)) |
| | | local_today_num_operate_map.get( |
| | | code)) |
| | | if left_count > 0: |
| | | watch_indexes.add(i) |
| | | total_num += val['num'] * data['re'] |
| | | |
| | | if len(watch_indexes) >= constant.L_CANCEL_MIN_WATCH_COUNT and total_num > threshold_num: |
| | | break |
| | | l2_log.l_cancel_debug(code, f"设置监听范围,成交进度-{index} , 数据范围:{start_index}-{end_index} 监听范围-{watch_indexes} 纯买手数:{total_num}/{threshold_num}") |
| | | l2_log.l_cancel_debug(code, |
| | | f"设置监听范围,成交进度-{index} , 数据范围:{start_index}-{end_index} 监听范围-{watch_indexes} 纯买手数:{total_num}/{threshold_num}") |
| | | # 数据维护 |
| | | add_indexes = watch_indexes - old_watch_indexes |
| | | delete_indexes = old_watch_indexes - watch_indexes |
| | |
| | | self.__del_watch_indexes(code, delete_indexes) |
| | | |
| | | def __compute_need_cancel(self, code, buy_exec_index, start_index, end_index, total_data, |
| | | local_today_num_operate_map, is_first_code): |
| | | _local_today_num_operate_map, is_first_code): |
| | | watch_indexes = self.__get_watch_indexes_cache(code) |
| | | if not watch_indexes: |
| | | return False, None |
| | |
| | | if L2DataUtil.is_limit_up_price_buy_cancel(val): |
| | | # 查询买入位置 |
| | | buy_index = l2_data_source_util.L2DataSourceUtils.get_buy_index_with_cancel_data(code, data, |
| | | local_today_num_operate_map) |
| | | _local_today_num_operate_map) |
| | | if buy_index is not None and buy_index in watch_indexes: |
| | | need_compute = True |
| | | break |
| | |
| | | left_count = l2_data_source_util.L2DataSourceUtils.get_limit_up_buy_no_canceled_count(code, |
| | | wi, |
| | | total_data, |
| | | local_today_num_operate_map) |
| | | _local_today_num_operate_map) |
| | | canceled_num += (total_data[wi]["re"] - left_count) * int(total_data[wi]["val"]["num"]) |
| | | rate = round(canceled_num / total_num, 3) |
| | | l2_log.l_cancel_debug(code, f"计算范围:{start_index}-{end_index},已撤单比例:{rate}") |
| | |
| | | |
| | | return False, None |
| | | |
| | | def need_cancel(self, code, buy_exec_index, start_index, end_index, total_data, local_today_num_operate_map, |
| | | def need_cancel(self, code, buy_exec_index, start_index, end_index, total_data, _local_today_num_operate_map, |
| | | is_first_code): |
| | | time_space = tool.trade_time_sub(total_data[start_index]["val"]["time"], |
| | | total_data[buy_exec_index]["val"]["time"]) |
| | |
| | | if time_space <= constant.L_CANCEL_START_TIME or int(tool.get_now_time_str().replace(":", "")) > int("145000"): |
| | | return False, None |
| | | can_cancel, cancel_data = self.__compute_need_cancel(code, buy_exec_index, start_index, end_index, total_data, |
| | | local_today_num_operate_map, is_first_code) |
| | | _local_today_num_operate_map, is_first_code) |
| | | if can_cancel: |
| | | # 判断成交进度位置到当前位置的净买入 |
| | | try: |
| | |
| | | if left_count > 0: |
| | | buy_nums += left_count * data["val"]["num"] |
| | | if buy_nums > threshold_num: |
| | | l2_log.l_cancel_debug(code, f"LX阻断L撤撤单:{buy_nums}/{threshold_num}") |
| | | l2_log.l_cancel_debug(code, f"LX阻断L撤撤单:{buy_nums}/{threshold_num} 成交位置-{transaction_index} 真实下单位置-{place_order_index}") |
| | | return False, "LX阻断L撤撤单" |
| | | l2_log.l_cancel_debug(code, f"LX尚未阻断L撤撤单:{buy_nums}/{threshold_num}") |
| | | l2_log.l_cancel_debug(code, f"LX尚未阻断L撤撤单:{buy_nums}/{threshold_num} 成交位置-{transaction_index} 真实下单位置-{place_order_index}") |
| | | return can_cancel, cancel_data |
| | | except Exception as e: |
| | | l2_log.l_cancel_debug(code, f"LX撤单计算异常:{str(e)}") |
| | |
| | | 异步日志管理器 |
| | | """ |
| | | import queue |
| | | import time |
| | | |
| | | from log_module.log import logger_debug |
| | | from utils import tool |
| | | |
| | | log_queue = queue.Queue() |
| | | |
| | | |
| | | def __add_log(logger, method, *args): |
| | | log_queue.put_nowait((logger, method, args)) |
| | | log_queue.put_nowait((logger, time.time(), method, args)) |
| | | |
| | | |
| | | def debug(logger, *args): |
| | |
| | | while True: |
| | | try: |
| | | val = log_queue.get() |
| | | cmd = val[1] |
| | | time_s = val[1] |
| | | cmd = val[2] |
| | | method = getattr(val[0], cmd) |
| | | method(*val[2]) |
| | | d = list(val[3]) |
| | | d[0] = f"[{tool.to_time_str(int(time_s))}.{str(time_s).split('.')[1][:3]}] " + d[0] |
| | | d = tuple(d) |
| | | method(*d) |
| | | except: |
| | | pass |
| | | |
| | | |
| | | if __name__ == "__main__": |
| | | logger_debug.warning() |
| | | info(logger_debug, "*-{}", "test") |
| | | # info(logger_debug, "*-{}", "test") |
| | | info(logger_debug, "123123") |
| | | run_sync() |