| | |
| | | # 扫入下单只有L撤能撤单 |
| | | if order_begin_pos and order_begin_pos.mode == OrderBeginPosInfo.MODE_RADICAL and cancel_type not in { |
| | | trade_constant.CANCEL_TYPE_L_DOWN, trade_constant.CANCEL_TYPE_L, trade_constant.CANCEL_TYPE_RD, |
| | | trade_constant.CANCEL_TYPE_P, trade_constant.CANCEL_TYPE_F}: |
| | | trade_constant.CANCEL_TYPE_P}: |
| | | l2_log.cancel_debug(code, "撤单中断,原因:{}", "扫入下单不是L撤") |
| | | return False |
| | | # 加绿只有L撤/人撤生效 |
| | | if gpcode_manager.GreenListCodeManager().is_in_cache(code): |
| | | if cancel_type not in {trade_constant.CANCEL_TYPE_L, trade_constant.CANCEL_TYPE_L_UP, |
| | | trade_constant.CANCEL_TYPE_L_DOWN, trade_constant.CANCEL_TYPE_RD, |
| | | trade_constant.CANCEL_TYPE_P, trade_constant.CANCEL_TYPE_F}: |
| | | trade_constant.CANCEL_TYPE_P}: |
| | | l2_log.cancel_debug(code, "撤单中断,原因:{}", "加绿不是L撤") |
| | | return False |
| | | |
| | |
| | | return False, -1, "未获取到积极买的起始信号", '', OrderBeginPosInfo.MODE_NORMAL |
| | | |
| | | # 计算激进买的下单信号 |
| | | # 计算激进买的下单信号 |
| | | @classmethod |
| | | def __compute_radical_order_begin_pos(cls, code, start_index, end_index): |
| | | """ |
| | |
| | | limit_up_price = gpcode_manager.get_limit_up_price_as_num(code) |
| | | bigger_money = l2_data_util.get_big_money_val(limit_up_price, tool.is_ge_code(code)) |
| | | min_num = int(bigger_money / limit_up_price / 100) |
| | | refer_sell_data = L2MarketSellManager().get_refer_sell_data(code, radical_data[3]) |
| | | # 参考总卖额 |
| | | refer_sell_money = 0 |
| | | if refer_sell_data: |
| | | refer_sell_money = refer_sell_data[1] |
| | | big_order_deal_enough_result = radical_buy_data_manager.is_big_order_deal_enough(code, |
| | | code_volumn_manager.CodeVolumeManager().get_volume_rate_refer_in_5days( |
| | | code), |
| | | refer_sell_money, |
| | | for_buy=True, |
| | | is_almost_open_limit_up= |
| | | radical_data[5]) |
| | | # 缺乏的大单金额 |
| | | lack_money = big_order_deal_enough_result[3] |
| | | # 如果有大单成交就不需要看大单 |
| | | if constant.CAN_RADICAL_BUY_NEED_BIG_ORDER_EVERYTIME: |
| | | # 每次下单都需要大单 |
| | | current_big_order_deal_money_info = EveryLimitupBigDealOrderManager.get_big_buy_deal_order_money_info( |
| | | code) |
| | | if current_big_order_deal_money_info and tool.trade_time_sub(tool.get_now_time_str(), |
| | | current_big_order_deal_money_info[1]) > 60: |
| | | # 60s以上就不下单了 |
| | | return False, None, "距离上次统计大单时间过去60s", set() |
| | | |
| | | if lack_money == 0: |
| | | if not tool.is_sh_code(code): |
| | | # 非上证的票看50w |
| | | min_num = int(5000 / limit_up_price) |
| | | # 需要监听的大单 |
| | | watch_indexes = set() |
| | | # 总委托大单金额 |
| | | total_delegating_big_money = 0 |
| | | single_index = None |
| | | # 从成交进度位开始看 |
| | | trade_index, is_default = cls.__TradeBuyQueue.get_traded_index(code) |
| | | if trade_index is None: |
| | | trade_index = 0 |
| | | canceled_buyno_map = local_today_canceled_buyno_map.get(code) |
| | | for i in range(trade_index, end_index + 1): |
| | | data = total_datas[i] |
| | | val = data["val"] |
| | | if not L2DataUtil.is_limit_up_price_buy(val): |
| | | continue |
| | | if val["num"] < min_num: |
| | | 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: |
| | | continue |
| | | |
| | | # 上证有可能是部分成交的大单 |
| | | if i == start_index and tool.is_sh_code(code): |
| | | dealing_active_order_info = HuaXinBuyOrderManager().get_dealing_active_order_info(code) |
| | | if dealing_active_order_info and dealing_active_order_info[0] == int(val["orderNo"]): |
| | | # 判断是否为大单 |
| | | order_money = dealing_active_order_info[2] + round(val["price"], 2) * val["num"] * 100 |
| | | if order_money >= bigger_money: |
| | | lack_money -= order_money |
| | | watch_indexes.add(i) |
| | | if lack_money < 0: |
| | | single_index = i |
| | | break |
| | | |
| | | if int(val["orderNo"]) <= radical_data[1]: |
| | | # 主动买单后的数据不算 |
| | | continue |
| | | watch_indexes.add(i) |
| | | lack_money -= round(val["price"], 2) * val["num"] * 100 |
| | | if lack_money < 0: |
| | | single_index = i |
| | | break |
| | | if single_index is not None: |
| | | return True, single_index, "有大单", watch_indexes |
| | | return False, None, f"大单不足:{trade_index}-{end_index} 缺少的大单-{lack_money}", watch_indexes |
| | | |
| | | def __can_order_v2(): |
| | | # 判断是否是板上放量 |
| | | if cls.__is_at_limit_up_buy(code, start_index): |
| | | return False, None, "板上放量", None |
| | | total_datas = local_today_datas[code] |
| | | limit_up_price = gpcode_manager.get_limit_up_price_as_num(code) |
| | | bigger_money = l2_data_util.get_big_money_val(limit_up_price, tool.is_ge_code(code)) |
| | | min_num = int(bigger_money / limit_up_price / 100) |
| | | # 统计委托大买单 |
| | | bigger_money_delegate_list = [] |
| | | for i in range(start_index, end_index + 1): |
| | | val = total_datas[i]["val"] |
| | | if val["num"] < min_num: |
| | | continue |
| | | if not L2DataUtil.is_limit_up_price_buy(val): |
| | | continue |
| | | bigger_money_delegate_list.append( |
| | | (val["orderNo"], int(float(val["price"]) * val["num"] * 100), val["time"])) |
| | | radical_buy_data_manager.EveryLimitupBigDelegateOrderManager.add_big_buy_order_delegate(code, |
| | | bigger_money_delegate_list) |
| | | |
| | | refer_sell_data = L2MarketSellManager().get_refer_sell_data(code, radical_data[3]) |
| | | # 参考总卖额 |
| | |
| | | # 板上放量可扫入 |
| | | if t.time() > radical_data[0] and not is_radical_buy: |
| | | # 没扫入过才需要判断时间 |
| | | radical_buy_data_manager.EveryLimitupBigDelegateOrderManager.clear(code, '超过生效时间') |
| | | return False, None, "超过生效时间" |
| | | else: |
| | | # 板上放量不可扫入 |
| | | if t.time() > radical_data[0]: |
| | | radical_buy_data_manager.EveryLimitupBigDelegateOrderManager.clear(code, '超过生效时间') |
| | | return False, None, "超过生效时间" |
| | | |
| | | result = __can_order_v2() |
| | | result = __can_order() |
| | | l2_log.debug(code, f"L2扫入判断:{result}") |
| | | if result[0]: |
| | | # 已经扫入下过单且允许板上放量扫入的就需要判断板上放量的距离 |
| | |
| | | @param end_index: |
| | | @return: 信号信息(信号位,执行位), 消息, 可买入的板块 |
| | | """ |
| | | if True: |
| | | return None, "暂不生效", None |
| | | if not tool.is_sz_code(code): |
| | | return None, "非深证的票", None |
| | | # 判断抛压是否大于5000w |
| | |
| | | |
| | | if cls.__delegating_sell_num_dict.get(code): |
| | | cls.__delegating_sell_num_dict[code] = 0 |
| | | async_log_util.l2_data_log.info(hx_logger_l2_sell_delegate, |
| | | f"出现主动卖清除数据:{code}") |
| | | l2_log.info(code, hx_logger_l2_sell_delegate, |
| | | f"出现主动卖清除数据:{code}") |
| | | |
| | | |
| | | if __name__ == "__main__": |
| | |
| | | if is_limit_up: |
| | | cls.__dealing_order_info_dict[code][7] += money |
| | | else: |
| | | if cls.__dealing_order_info_dict[code][0] == data[0][6]: |
| | | dealing_order_info = cls.__dealing_order_info_dict[code] |
| | | if dealing_order_info[0] == data[0][6]: |
| | | # 成交同一个订单号 |
| | | cls.__dealing_order_info_dict[code][1] += data[0][2] |
| | | cls.__dealing_order_info_dict[code][2] += money |
| | | cls.__dealing_order_info_dict[code][4] = data[0][3] |
| | | cls.__dealing_order_info_dict[code][5] = data[0][1] |
| | | cls.__dealing_order_info_dict[code][6] = data[0][7] |
| | | dealing_order_info[1] += data[0][2] |
| | | dealing_order_info[2] += money |
| | | dealing_order_info[4] = data[0][3] |
| | | dealing_order_info[5] = data[0][1] |
| | | dealing_order_info[6] = data[0][7] |
| | | if is_limit_up: |
| | | cls.__dealing_order_info_dict[code][7] += money |
| | | dealing_order_info[7] += money |
| | | else: |
| | | # 保存上一条数据 |
| | | l2_log.info(code, hx_logger_l2_transaction_desc, f"{code}#{cls.__dealing_order_info_dict[code]}") |
| | | l2_log.info(code, hx_logger_l2_transaction_desc, f"{code}#{dealing_order_info}") |
| | | # 设置最近成交完成的一条数据 |
| | | deal_info = cls.__dealing_order_info_dict[code] |
| | | deal_info = dealing_order_info |
| | | cls.__latest_deal_order_info_dict[code] = deal_info |
| | | # 是否为大买单 |
| | | if deal_info[7] >= threshold_big_money: |
| | |
| | | big_buy_datas.append(deal_info) |
| | | if deal_info[2] >= 500000: |
| | | normal_buy_datas.append(deal_info) |
| | | |
| | | # 初始化本条数据 |
| | | cls.__dealing_order_info_dict[code] = [data[0][6], data[0][2], money, data[0][3], data[0][3], |
| | | data[0][1], data[0][7], 0] |
| | |
| | | cls.__dealing_active_buy_order_info_dict[code] = [data[0][6], data[0][2], money, data[0][3], |
| | | data[0][3]] |
| | | else: |
| | | if cls.__dealing_active_buy_order_info_dict[code][0] == data[0][6]: |
| | | dealing_active_buy_order_info = cls.__dealing_active_buy_order_info_dict[code] |
| | | if dealing_active_buy_order_info[0] == data[0][6]: |
| | | # 成交同一个订单号 |
| | | cls.__dealing_active_buy_order_info_dict[code][1] += data[0][2] |
| | | cls.__dealing_active_buy_order_info_dict[code][2] += money |
| | | cls.__dealing_active_buy_order_info_dict[code][4] = data[0][3] |
| | | dealing_active_buy_order_info[1] += data[0][2] |
| | | dealing_active_buy_order_info[2] += money |
| | | dealing_active_buy_order_info[4] = data[0][3] |
| | | else: |
| | | # 初始化本条数据 |
| | | cls.__dealing_active_buy_order_info_dict[code] = [data[0][6], data[0][2], money, |
| | |
| | | if buy_progress_index is not None: |
| | | buy_progress_index_changed = cls.__TradeBuyQueue.set_traded_index(code, buy_progress_index, |
| | | total_datas) |
| | | async_log_util.info(logger_l2_trade_buy_queue, "获取成交位置成功: code-{} index-{}", code, |
| | | buy_progress_index) |
| | | l2_log.info(code, logger_l2_trade_buy_queue, "获取成交位置成功: code-{} index-{}", code, buy_progress_index) |
| | | if is_placed_order: |
| | | NewGCancelBigNumComputer().set_trade_progress(code, order_begin_pos.buy_single_index, |
| | | buy_progress_index) |
| | | # NewGCancelBigNumComputer().set_trade_progress(code, order_begin_pos.buy_single_index, |
| | | # buy_progress_index) |
| | | LCancelBigNumComputer().set_trade_progress(code, order_begin_pos.buy_single_index, |
| | | buy_progress_index, |
| | | total_datas) |
| | |
| | | cancel_type=trade_constant.CANCEL_TYPE_W) |
| | | except: |
| | | pass |
| | | |
| | | SCancelBigNumComputer().set_transaction_index(code, order_begin_pos.buy_single_index, |
| | | buy_progress_index) |
| | | HourCancelBigNumComputer().set_transaction_index(code, order_begin_pos.buy_single_index, |
| | | buy_progress_index) |
| | | # SCancelBigNumComputer().set_transaction_index(code, order_begin_pos.buy_single_index, |
| | | # buy_progress_index) |
| | | # HourCancelBigNumComputer().set_transaction_index(code, order_begin_pos.buy_single_index, |
| | | # buy_progress_index) |
| | | else: |
| | | pass |
| | | if is_placed_order: |
| | |
| | | # 设置成交价 |
| | | try: |
| | | current_price_process_manager.set_trade_price(code, fdatas[-1][0][1]) |
| | | if limit_up_price > fdatas[-1][0][1]: |
| | | if not fdatas[-1][2]: |
| | | # 没有涨停 |
| | | EveryLimitupBigDealOrderManager.open_limit_up(code, f"最新成交价:{fdatas[-1][0][1]}") |
| | | radical_buy_strategy.clear_data(code) |
| | |
| | | current_price_process_manager.set_latest_not_limit_up_time(code, last_data[5]) |
| | | elif not last_data[1] and last_data[2]: |
| | | # 涨停主动卖 |
| | | if last_data[2]: |
| | | L2LimitUpSellDataManager.clear_data(code) |
| | | L2LimitUpSellDataManager.clear_data(code) |
| | | except: |
| | | pass |
| | | |
| | |
| | | def l2_transaction(cls, code, datas): |
| | | # async_log_util.info(hx_logger_l2_transaction, f"{code}#{datas}") |
| | | if datas: |
| | | HuaXinTransactionDatasProcessor().process_huaxin_transaction_datas_v2(code, datas) |
| | | HuaXinTransactionDatasProcessor().process_huaxin_transaction_datas(code, datas) |
| | | |
| | | @classmethod |
| | | def l2_market_data(cls, code, data): |
| | |
| | | l2_log.info(code, logger_debug, f"扫入处理时长:{code}-{use_time}") |
| | | |
| | | def OnLimitUpActiveBuy(self, code, transaction_datas, no_left_limit_up_sell): |
| | | # can_clear_before_data = self.process_limit_up_active_buy(code, transaction_datas, |
| | | # no_left_limit_up_sell=no_left_limit_up_sell) |
| | | # if can_clear_before_data: |
| | | # # 清除 |
| | | # EveryLimitupBigDealOrderManager.clear(code, "处理涨停成交数据") |
| | | can_clear_before_data = self.process_limit_up_active_buy(code, transaction_datas, |
| | | no_left_limit_up_sell=no_left_limit_up_sell) |
| | | if can_clear_before_data: |
| | | # 清除 |
| | | EveryLimitupBigDealOrderManager.clear(code, "处理涨停成交数据") |
| | | pass |
| | | |
| | | def OnLastLimitUpSellDeal(self, code, data): |
| | |
| | | @param data: (data['SecurityID'], data['TradePrice'], data['TradeVolume'], data['OrderTime'], data['MainSeq'], data['SubSeq'], data['BuyNo'], data['SellNo'], data['ExecType']) |
| | | @return: |
| | | """ |
| | | if True: |
| | | return |
| | | |
| | | if data[6] < data[7]: |
| | | # 非主动买 |
| | | return |
| | |
| | | |
| | | import constant |
| | | import l2_data_util |
| | | from l2 import l2_data_util as l2_data_util_new |
| | | from l2 import l2_data_util as l2_data_util_new, l2_log |
| | | from code_attribute import code_nature_analyse, code_volumn_manager, gpcode_manager |
| | | from code_attribute.code_l1_data_manager import L1DataManager |
| | | from code_attribute.gpcode_manager import WantBuyCodesManager |
| | |
| | | temp_info = BeforeSubDealBigOrderManager().get_temp_deal_big_order_threshold_info(code) |
| | | if temp_info: |
| | | THRESHOLD_MONEY = temp_info[0] |
| | | else: |
| | | # 没有临时大单就取L2前2个委托数据 |
| | | money_info_list = EveryLimitupBigDelegateOrderManager.get_big_buy_delegate_order_money_info(code) |
| | | if money_info_list and len(money_info_list) >= 2: |
| | | THRESHOLD_MONEY = sum(x[1] for x in money_info_list[:2]) // 2 |
| | | else: |
| | | # 如果委托订单不足2个就取1亿 |
| | | THRESHOLD_MONEY = 1e8 |
| | | |
| | | if THRESHOLD_MONEY < 600e4 and current_threshold_count < 3: |
| | | # 均大单金额≤600万,则就需要加倍大单数 |
| | | current_threshold_count *= 2 |
| | |
| | | total_lack_money_info[2] |
| | | # ===========判断单次大单成交============== |
| | | current_big_order_deal_money = 0 |
| | | current_big_order_deal_money_info = EveryLimitupBigDelegateOrderManager.get_big_buy_delegate_order_money_info(code) |
| | | current_big_order_deal_money_info = EveryLimitupBigDealOrderManager.get_big_buy_deal_order_money_info(code) |
| | | if current_big_order_deal_money_info: |
| | | if tool.trade_time_sub(tool.get_now_time_str(), current_big_order_deal_money_info[0][2]) > 60: |
| | | if tool.trade_time_sub(tool.get_now_time_str(), current_big_order_deal_money_info[1]) > 60: |
| | | # 60s以上的大单不看 |
| | | current_big_order_deal_money = 0 |
| | | else: |
| | | current_big_order_deal_money = sum(x[1] for x in current_big_order_deal_money_info) |
| | | current_big_order_deal_money = current_big_order_deal_money_info[0] |
| | | current_lack_money = max(0, int(current_threshold_money - current_big_order_deal_money)) |
| | | if for_buy and not tool.is_ge_code(code): |
| | | # 要下单的且不是创业版的目标代码大单数量打8折 |
| | |
| | | total_lack_money = int(total_threshold_money - total_deal_money) |
| | | if total_lack_money < 0: |
| | | total_lack_money = 0 |
| | | total_lack_money = 0 |
| | | # 不考虑总大单 |
| | | if current_lack_money == 0 and total_lack_money == 0: |
| | | return True, f"量比-{volume_rate}, 瞬时大单成交-({current_big_order_deal_money}/{current_threshold_money}),总大单成交-({total_lack_money_info[1]}/{total_lack_money_info[2]})", before_time, 0 |
| | | return False, f"量比-{volume_rate}, 瞬时大单成交-({current_big_order_deal_money}/{current_threshold_money}),总大单成交-({total_lack_money_info[1]}/{total_lack_money_info[2]})", before_time, max( |
| | |
| | | def open_limit_up(cls, code, msg=""): |
| | | if code in cls.__deal_big_order_infos_dict: |
| | | cls.__deal_big_order_infos_dict[code].clear() |
| | | async_log_util.info(logger_l2_radical_buy_data, f"清除每次涨停大单数据({msg}):{code}") |
| | | l2_log.info(code, logger_l2_radical_buy_data, f"清除每次涨停大单数据({msg}):{code}") |
| | | |
| | | @classmethod |
| | | def clear(cls, code, msg=""): |
| | |
| | | if order_info[0] not in cls.__deal_big_order_no_dict[code]: |
| | | cls.__deal_big_order_infos_dict[code].append(order_info) |
| | | cls.__deal_big_order_no_dict[code].add(order_info[0]) |
| | | async_log_util.info(logger_l2_radical_buy_data, f"添加每次上板的大单成交:{code}-{order_info}") |
| | | l2_log.info(code, logger_l2_radical_buy_data, f"添加每次上板的大单成交:{code}-{order_info}") |
| | | |
| | | @classmethod |
| | | def get_big_buy_deal_order_count(cls, code): |