| | |
| | | from db import redis_manager_delegate as redis_manager |
| | | from db.redis_manager_delegate import RedisUtils |
| | | from l2.l2_data_manager import OrderBeginPosInfo |
| | | from l2.l2_transaction_data_manager import HuaXinBuyOrderManager |
| | | from l2.l2_transaction_data_manager import HuaXinBuyOrderManager, HuaXinSellOrderStatisticManager |
| | | from trade.sell.sell_rule_manager import TradeRuleManager |
| | | |
| | | from utils import tool |
| | |
| | | from l2 import l2_log, l2_data_source_util |
| | | from l2.l2_data_util import L2DataUtil, local_today_num_operate_map, local_today_datas, local_today_buyno_map, \ |
| | | local_today_canceled_buyno_map |
| | | from log_module.log import logger_buy_1_volumn |
| | | from log_module.log import logger_buy_1_volumn, logger_l2_error |
| | | from utils.tool import CodeDataCacheUtil |
| | | |
| | | |
| | |
| | | return i |
| | | return end_index |
| | | |
| | | @classmethod |
| | | def compute_max_buy_order_info(cls, code, start_index, end_index): |
| | | """ |
| | | 计算区间最大买单 |
| | | @param code: |
| | | @param start_index: |
| | | @param end_index: |
| | | @return: |
| | | """ |
| | | total_datas = local_today_datas.get(code) |
| | | canceled_buyno_map = local_today_canceled_buyno_map.get(code) |
| | | max_info = (0, None) # 索引,手数 |
| | | for i in range(start_index, end_index + 1): |
| | | data = total_datas[i] |
| | | val = data['val'] |
| | | if not L2DataUtil.is_limit_up_price_buy(val): |
| | | continue |
| | | left_count = l2_data_source_util.L2DataSourceUtils.get_limit_up_buy_no_canceled_count_v2(code, i, |
| | | total_datas, |
| | | canceled_buyno_map) |
| | | if left_count > 0: |
| | | if val["num"] > max_info[0]: |
| | | max_info = (i, val["num"]) |
| | | return total_datas[max_info[0]] |
| | | |
| | | |
| | | # ---------------------------------D撤------------------------------- |
| | | # 计算 成交位->真实下单位置 总共还剩下多少手没有撤单 |
| | |
| | | __db = 0 |
| | | __redis_manager = redis_manager.RedisManager(0) |
| | | __real_order_index_cache = {} |
| | | __max_buy_order_num_cache = {} |
| | | |
| | | __instance = None |
| | | |
| | |
| | | def clear(self, code=None): |
| | | if code: |
| | | self.__del_real_order_index(code) |
| | | if code in self.__max_buy_order_num_cache: |
| | | self.__max_buy_order_num_cache.pop(code) |
| | | else: |
| | | keys = RedisUtils.keys(self.__get_redis(), "f_cancel_real_order_index-*") |
| | | if keys: |
| | |
| | | # 设置真实的下单位置 |
| | | def set_real_order_index(self, code, index, is_default): |
| | | self.__set_real_order_index(code, index, is_default) |
| | | if not is_default and code.find("60") == 0: |
| | | try: |
| | | # 统计未成交的最大单 |
| | | trade_index = 0 |
| | | trade_info = TradeBuyQueue().get_traded_index(code) |
| | | if trade_info and not trade_info[1] and trade_info[0] is not None: |
| | | trade_index = trade_info[0] |
| | | data = L2DataComputeUtil.compute_max_buy_order_info(code, trade_index, index) |
| | | # 保存最大单 |
| | | self.__max_buy_order_num_cache[code] = data["val"]["num"] |
| | | l2_log.f_cancel_debug(code, f"最大单计算:索引-{data['index']} 范围:{trade_index}-{index}") |
| | | except Exception as e: |
| | | logger_l2_error.exception(e) |
| | | |
| | | def place_order_success(self, code): |
| | | self.clear(code) |
| | |
| | | # 是否是下单1分钟内 |
| | | if tool.trade_time_sub(tool.get_now_time_str(), total_datas[real_order_index]['val']['time']) > 1 * 60: |
| | | return False, "下单超过60s" |
| | | try: |
| | | if code in self.__max_buy_order_num_cache: |
| | | max_num = self.__max_buy_order_num_cache[code] |
| | | total_num, details = HuaXinSellOrderStatisticManager.get_latest_2s_continue_deal_volume(code) |
| | | if total_num // 100 > max_num * 0.6: |
| | | return True, f"连续两秒抛压过大:{total_num // 100}/{max_num}手" |
| | | except Exception as e: |
| | | l2_log.f_cancel_debug(code,f"大抛压撤单计算出错:{str(e)}") |
| | | |
| | | # 查询最近2秒成交是否超过阈值 |
| | | |
| | | THRESHOLD_MONEY_W, THRESHOLD_COUNT = self.__get_fast_deal_threshold_value(code, |
| | | total_datas[real_order_index]['val'][ |
| | |
| | | return False, True, f"均价涨幅({average_rate})小于1%" |
| | | |
| | | total_data = local_today_datas.get(code) |
| | | |
| | | # 9:32之前上证开1的票不买 |
| | | if code.find("60") == 0 and int(total_data[-1]["val"]["time"].replace(":", "")) <= int("093200"): |
| | | # 获取涨停时间 |
| | | limit_up_data = kpl_data_manager.KPLLimitUpDataRecordManager.record_code_dict.get(code) |
| | | if limit_up_data: |
| | | limit_up_time = tool.to_time_str(limit_up_data[2]) |
| | | if int(limit_up_time.replace(":", "")) < int("093000"): |
| | | return False, True, f"上证开一09:32之前不下单" |
| | | |
| | | order_begin_pos = cls.__get_order_begin_pos( |
| | | code) |
| | | if not trade_result_manager.can_place_order_for_cancel_time(code, total_data[order_begin_pos.buy_exec_index]): |
| | |
| | | else: |
| | | if not can_buy_result[0]: |
| | | place_order_count = trade_data_manager.PlaceOrderCountManager().get_place_order_count(code) |
| | | if place_order_count <=0 or can_buy_result[1]: |
| | | if place_order_count <= 0 or can_buy_result[1]: |
| | | return False, True, f"非强势30分钟,不满足身位:{can_buy_result[2]}" |
| | | else: |
| | | return True, False, "之前下过单" |
| | |
| | | cls.__dealing_order_info_dict[code] = [data[7], data[2], data[2] * data[1]] |
| | | return big_sell_datas |
| | | |
| | | # 统计所有的成交量 |
| | | __deal_volume_list_dict = {} |
| | | |
| | | @classmethod |
| | | def statistic_total_deal_volume(cls, code, datas): |
| | | if code not in cls.__deal_volume_list_dict: |
| | | cls.__deal_volume_list_dict[code] = [] |
| | | time_dict = {} |
| | | for d in datas: |
| | | time_str = '' |
| | | if d[3] in time_dict: |
| | | time_str = time_dict[d[3]] |
| | | else: |
| | | time_dict[d[3]] = l2_huaxin_util.convert_time(d[3]) |
| | | time_str = time_dict[d[3]] |
| | | if cls.__deal_volume_list_dict[code]: |
| | | if cls.__deal_volume_list_dict[code][-1][0] == time_str: |
| | | # 如果是同一秒 |
| | | cls.__deal_volume_list_dict[code][-1][1] += d[2] |
| | | else: |
| | | # 不是同一秒 |
| | | cls.__deal_volume_list_dict[code].append([time_str, d[2]]) |
| | | else: |
| | | cls.__deal_volume_list_dict[code].append([time_str, d[2]]) |
| | | # 删除超过5条数据 |
| | | if len(cls.__deal_volume_list_dict[code]) > 5: |
| | | cls.__deal_volume_list_dict[code] = cls.__deal_volume_list_dict[code][-5:] |
| | | time_dict.clear() |
| | | |
| | | @classmethod |
| | | def get_latest_2s_continue_deal_volume(cls, code): |
| | | """ |
| | | 获取最近连续2s的成交量 |
| | | @param code: |
| | | @return: 成交量,详细信息 |
| | | """ |
| | | deal_list = cls.__deal_volume_list_dict.get(code) |
| | | if not deal_list: |
| | | return 0, None |
| | | if len(deal_list) == 0: |
| | | return deal_list[0][1], deal_list |
| | | if tool.trade_time_sub(deal_list[-1][0], deal_list[-2][0]) > 1: |
| | | return deal_list[-1][1], deal_list |
| | | else: |
| | | return deal_list[-1][1] + deal_list[-2][1], deal_list |
| | | |
| | | # 返回最近1s的大单卖:(总卖金额,[(卖单号,总手数,价格,('开始时间',买单号),('结束时间',买单号)),...]) |
| | | @classmethod |
| | | def add_transaction_datas(cls, code, datas, limit_up_price=None): |
| | |
| | | # GCancelBigNumComputer().set_big_sell_order_info(code, big_sell_order_info) |
| | | use_time_list.append(("处理卖单相关撤数据", time.time() - _start_time)) |
| | | _start_time = time.time() |
| | | HuaXinSellOrderStatisticManager.statistic_total_deal_volume(code, datas) |
| | | use_time_list.append(("统计成交量数据", time.time() - _start_time)) |
| | | except Exception as e: |
| | | async_log_util.error(logger_debug, f"卖单统计异常:{big_sell_order_info}") |
| | | logger_debug.exception(e) |
| | | |
| | | _start_time = time.time() |
| | | cls.__statistic_thread_pool.submit(cls.statistic_big_order_infos, code, datas, order_begin_pos) |
| | | |
| | |
| | | cancel_result = FCancelBigNumComputer().need_cancel_for_deal_fast(code, buy_progress_index) |
| | | if cancel_result[0]: |
| | | L2TradeDataProcessor.cancel_buy(code, f"F撤:{cancel_result[1]}") |
| | | # if not cancel_result[0]: |
| | | # try: |
| | | # cancel_result = NBCancelBigNumComputer().need_cancel(code, buy_progress_index) |
| | | # if cancel_result[0]: |
| | | # L2TradeDataProcessor.cancel_buy(code, f"大市值无大单撤:{cancel_result[1]}") |
| | | # except: |
| | | # pass |
| | | if not cancel_result[0]: |
| | | try: |
| | | cancel_result = NBCancelBigNumComputer().need_cancel(code, buy_progress_index) |
| | | if cancel_result[0]: |
| | | L2TradeDataProcessor.cancel_buy(code, f"大市值无大单撤:{cancel_result[1]}") |
| | | except: |
| | | pass |
| | | |
| | | if not cancel_result[0] and buy_progress_index_changed: |
| | | try: |