Administrator
2024-05-15 d4a18ee8c2c5159568a7bf2c27f4722ae144f560
W撤/L后囊括规则修改
3个文件已修改
141 ■■■■ 已修改文件
l2/cancel_buy_strategy.py 126 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/l2_transaction_data_processor.py 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
output/l2_output_util.py 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/cancel_buy_strategy.py
@@ -27,7 +27,7 @@
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, logger_l2_l_cancel, logger_l2_h_cancel, logger_l2_s_cancel
from log_module.log import logger_buy_1_volumn, logger_l2_l_cancel, logger_l2_h_cancel, logger_l2_s_cancel, logger_debug
from utils.tool import CodeDataCacheUtil
@@ -92,6 +92,39 @@
                total_count += 1
                total_num += val["num"]
        return total_count, total_num
    @classmethod
    def compute_end_index(cls, code, start_index, end_index, limit_up_price, max_count, min_money=500000):
        """
        计算结束索引
        @param code: 代码
        @param start_index:起始索引(包含)
        @param end_index: 结束索引(包含)
        @param limit_up_price: 涨停价
        @param max_count: 最大数量
        @param min_money: 最小的资金
        @return:结束索引
        """
        min_volume = min_money // int(limit_up_price * 100)
        total_datas = local_today_datas.get(code)
        canceled_buyno_map = local_today_canceled_buyno_map.get(code)
        total_count = 0
        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
            if val['num'] < min_volume:
                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:
                total_count += 1
                if total_count>=max_count:
                    return i
        return end_index
class SCancelBigNumComputer:
@@ -384,11 +417,31 @@
        zyltgb = l2_trade_factor.L2TradeFactorUtil.get_zyltgb(code)
        zyltgb_unit_y = round(zyltgb / 100000000, 1)
        limit_up_price = gpcode_manager.get_limit_up_price(code)
        limit_up_price = round(float(limit_up_price), 2)
        # 有超大单砸
        threshold_big_deal = (2 * zyltgb_unit_y + 339) * 10000
        if total_deal_money >= threshold_big_deal:
            return True, f"1s内大于{threshold_big_deal}大卖单({total_deal_money})"
            # S撤重砸必撤的金额满足以后,以前是无脑撤。现在优化一下,看成交进度位---真实下单位的区间额≤重砸金额*5倍,就撤。
            try:
                need_compute = False
                trade_index, is_default = TradeBuyQueue().get_traded_index(code)
                if trade_index is None:
                    trade_index = 0
                if real_order_index_info and not real_order_index_info[1]:
                    need_compute = True
        limit_up_price = gpcode_manager.get_limit_up_price(code)
                if need_compute:
                    total_count, total_num = L2DataComputeUtil.compute_left_buy_order(code, trade_index,
                                                                                      real_order_index_info[0],
                                                                                      limit_up_price)
                    if total_num * limit_up_price * 100 < 5 * total_deal_money:
                        return True, f"1s内大于{threshold_big_deal}大卖单({total_deal_money})"
                else:
                    return True, f"1s内大于{threshold_big_deal}大卖单({total_deal_money})"
            except Exception as e:
                l2_log.info(code, logger_debug, f"S快计算出错:{str(e)}")
        # 判断是否为激进下单
        threash_money_w, threash_money_danger_w = self.__get_fast_threshold_value(code)
        total_fast_num = 0
@@ -1212,7 +1265,6 @@
                    if val["num"] < min_num:
                        continue
                    cancel_data = l2_data_source_util.L2DataSourceUtils.get_limit_up_buy_canceled_data_v2(code,
                                                                                                          j,
                                                                                                          total_datas,
@@ -1313,13 +1365,12 @@
                    # 获取真实下单位后面10笔大单
                    try:
                        # 真实下单位置后面的数据就只看大单
                        big_min_num = int(29900 / (float(gpcode_manager.get_limit_up_price(code))))
                        MIN_NUM = int(5000 / (float(gpcode_manager.get_limit_up_price(code))))
                        real_place_order_info = self.__real_place_order_index_dict.get(code)
                        if real_place_order_info and not real_place_order_info[1]:
                            # 从真实下单位往后找
                            after_count = 0
                            for i in range(real_place_order_info[0] + 1, total_datas[-1]['index']+1):
                            for i in range(real_place_order_info[0] + 1, total_datas[-1]['index'] + 1):
                                if after_count > 10:
                                    break
                                data = total_datas[i]
@@ -1336,8 +1387,8 @@
                                    local_today_canceled_buyno_map.get(
                                        code))
                                if left_count > 0:
                                    after_count+=1
                                    if val['num']>=big_min_num:
                                    after_count += 1
                                    if l2_data_util.is_big_money(val):
                                        watch_indexes.add(i)
                    except Exception as e:
                        pass
@@ -1529,6 +1580,31 @@
                    watch_indexes.add(data["index"])
                    l2_log.l_cancel_debug(code, f"L后有成交重新囊括:成交索引-{index} 囊括索引-{data['index']}")
                    break
            # 从真实下单位置往后囊括大单
            try:
                left_count_after = 0
                for j in range(real_place_order_info[0] + 1, total_datas[-1]["index"]):
                    data = total_datas[j]
                    val = data['val']
                    if left_count_after > 10:
                        break
                    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,
                                                                                                             j,
                                                                                                             total_datas,
                                                                                                             local_today_canceled_buyno_map.get(
                                                                                                                 code))
                    if left_count > 0:
                        left_count_after += 1
                        if l2_data_util.is_big_money(val) and j not in watch_indexes:
                            watch_indexes.add(j)
                            break
            except:
                pass
        self.__set_watch_indexes(code, watch_indexes_info[0], watch_indexes_info[1], watch_indexes)
    def __compute_need_cancel(self, code, buy_exec_index, start_index, end_index, total_data, is_first_code):
@@ -1993,7 +2069,29 @@
                # 实际下单位后方所有涨停纯买额≤1000万或没有任何大单(≥299万)
                return True, f"P撤:封单纯买额-{round(left_money / 100, 1)}万 大单数量-{total_big_num_count} 下单位-{real_order_index} 成交位-{real_trade_index}"
        return False, "不满足撤单条件"
    # w撤
    def need_cancel_for_w(self,code):
        real_order_index_info = self.__get_real_order_index_cache(code)
        if not real_order_index_info:
            return False, "没找到真实下单位"
        if real_order_index_info[1]:
            return False, "真实下单位为默认"
        trade_index, is_default = TradeBuyQueue().get_traded_index(code)
        if trade_index is None:
            return False, "没获取到成交进度位"
        real_order_index = real_order_index_info[0]
        total_datas = local_today_datas.get(code)
        if tool.trade_time_sub(total_datas[-1]['val']['time'], total_datas[real_order_index]['val']['time']) > 60:
            return False, "超过守护时间"
        limit_up_price = round(float(gpcode_manager.get_limit_up_price(code)) , 2)
        end_index = L2DataComputeUtil.compute_end_index(code, real_order_index+1, total_datas[-1]["index"],limit_up_price, 10)
        # 从成交进度位到截至位置计算大单
        min_money =  l2_data_util.get_big_money_val(limit_up_price)
        left_count, left_money = L2DataComputeUtil.compute_left_buy_order(code,trade_index,end_index,limit_up_price,min_money=min_money)
        if left_count < 1:
            return True, f"大单数量:{left_count}"
        return False, "大单数量够"
# ---------------------------------G撤-------------------------------
class GCancelBigNumComputer:
@@ -3257,7 +3355,7 @@
        l2_log.j_cancel_debug(code, f"触发囊括:{self.__cancel_single_cache[code]}")
    def need_cancel(self, code, start_index, end_index):
        if 1>0:
        if 1 > 0:
            return False, None, "J撤不生效"
        # 需要先计算
        self.__compute_cancel_single(code, start_index, end_index)
@@ -3268,7 +3366,7 @@
        # 计算剩余数量
        total_datas = local_today_datas.get(code)
        if int(total_datas[end_index]['val']['time'].replace(":","")) > 145000:
        if int(total_datas[end_index]['val']['time'].replace(":", "")) > 145000:
            return False, None, "超过生效时间"
        buyno_map = local_today_buyno_map.get(code)
@@ -3341,7 +3439,7 @@
            return False, "没有找到真实下单位"
        real_place_order_index = real_place_order_index_info[0]
        limit_up_price = round(float(gpcode_manager.get_limit_up_price(code)),2)
        limit_up_price = round(float(gpcode_manager.get_limit_up_price(code)), 2)
        if limit_up_price < 3:
            return False, "股价小于3块"
@@ -3354,7 +3452,9 @@
        total_datas = local_today_datas.get(code)
        if tool.trade_time_sub(tool.get_now_time_str(), total_datas[real_place_order_index]['val']['time']) > 300:
            return False, "超过生效时间"
        total_left_count, total_left_num = L2DataComputeUtil.compute_left_buy_order(code, trade_index, real_place_order_index,limit_up_price, 299*10000)
        total_left_count, total_left_num = L2DataComputeUtil.compute_left_buy_order(code, trade_index,
                                                                                    real_place_order_index,
                                                                                    limit_up_price, 299 * 10000)
        if total_left_count > 0:
            return False, '有大单'
        return True, f'无大单:{trade_index}-{real_place_order_index}'
@@ -3368,8 +3468,6 @@
    def place_order_success(self, code):
        self.__clear_data(code)
if __name__ == "__main__":
l2/l2_transaction_data_processor.py
@@ -145,7 +145,7 @@
                    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]}")
                    else:
                    if not cancel_result[0]:
                        try:
                            cancel_result = NBCancelBigNumComputer().need_cancel(code, buy_progress_index)
                            if cancel_result[0]:
@@ -153,6 +153,17 @@
                        except:
                            pass
                    if not cancel_result[0] and buy_progress_index_changed:
                        try:
                            cancel_result = FCancelBigNumComputer().need_cancel_for_w(code)
                            if cancel_result[0]:
                                L2TradeDataProcessor.cancel_buy(code, f"W撤:{cancel_result[1]}")
                        except:
                            pass
                    SCancelBigNumComputer().set_transaction_index(code, order_begin_pos.buy_single_index,
                                                                  buy_progress_index)
output/l2_output_util.py
@@ -35,7 +35,7 @@
            elif num * float(val['price']) >= 29900:
                type_ = 2
            fresults.append((val['num'], type_))
            fresults.append((num, type_))
            if len(fresults) > max_count:
                break
    return fresults