Administrator
6 天以前 078a4b11c1a5d110ad675a06f50ef9f277e39036
加贝控制中心输出修改/保存L后囊括范围的统计信息快照
4个文件已修改
174 ■■■■ 已修改文件
api/outside_api_command_callback.py 23 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
cancel_strategy/s_l_h_cancel_strategy.py 108 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
inited_data.py 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
trade/buy_radical/radical_buy_data_manager.py 41 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
api/outside_api_command_callback.py
@@ -15,7 +15,7 @@
import inited_data
import outside_api_command_manager
from cancel_strategy.s_l_h_cancel_strategy import SCancelBigNumComputer, LCancelRateManager, \
    CancelRateHumanSettingManager
    CancelRateHumanSettingManager, LCancelBigNumComputer, LDownCancelWatchIndexStatisticManager
from code_attribute import gpcode_manager, code_volumn_manager, zyltgb_util, code_nature_analyse
from code_attribute.code_data_util import ZYLTGBUtil
from code_attribute.code_l1_data_manager import L1DataManager
@@ -886,12 +886,16 @@
                    [huaxin_util.TORA_TSTP_OST_Accepted, huaxin_util.TORA_TSTP_OST_PartTraded])
                fdatas = []
                if current_delegates:
                    codes_set = set()
                    for c in current_delegates:
                        try:
                            if int(c["direction"]) != huaxin_util.TORA_TSTP_D_Buy:
                                continue
                            code = c["securityID"]
                            if code in codes_set:
                                continue
                            orderSysID = c.get("orderSysID")
                            codes_set.add(code)
                            code_name = gpcode_manager.get_code_name(code)
                            # 获取下单位置信息
                            order_begin_pos = TradePointManager().get_buy_compute_start_data_cache(code)
@@ -1160,7 +1164,14 @@
                                    fdata['mode'] = -1
                            except:
                                pass
                            # L后囊括快照
                            current_info = LCancelBigNumComputer().statistic_l_down_watch_indexes_info(code)
                            last_info = LDownCancelWatchIndexStatisticManager().get_statistic_info(code)
                            fdata['l_down_watch_indexes_info'] = {}
                            if current_info:
                                fdata['l_down_watch_indexes_info']['current'] = current_info
                            if last_info:
                                fdata['l_down_watch_indexes_info']['last'] = last_info
                            fdatas.append(fdata)
                        except Exception as e:
                            logger_debug.exception(e)
@@ -1522,13 +1533,19 @@
                # 设置L后撤单比例
                code = data.get("code")
                rate = data.get("rate")
                if rate < 0 or rate > 1:
                if rate < 0 or rate > 2:
                    self.send_response({"code": 1, "msg": "比例范围不在0-1之间"},
                                       client_id,
                                       request_id)
                    return
                rate = round(rate, 2)
                # L后数据快照
                last_info = LCancelBigNumComputer().statistic_l_down_watch_indexes_info(code)
                LDownCancelWatchIndexStatisticManager().set_statistic_info(code, last_info)
                CancelRateHumanSettingManager().set_l_down(code, rate)
                # L后重新囊括
                LCancelBigNumComputer().re_compute_l_down_watch_indexes(code)
                self.send_response({"code": 0, "data": {}},
                                   client_id,
                                   request_id)
cancel_strategy/s_l_h_cancel_strategy.py
@@ -712,6 +712,50 @@
            self.l_down.pop(code)
@tool.singleton
class LDownCancelWatchIndexStatisticManager:
    """
    L后统计信息管理
    """
    def __init__(self):
        self.watch_indexes_statistic_info_dict = {}
        self.__db = 0
        self.__redis_manager = redis_manager.RedisManager(self.__db)
        self.__load_data()
    def __get_redis(self):
        return self.__redis_manager.getRedis()
    def __load_data(self):
        keys = RedisUtils.keys(self.__get_redis(), "l_down_watch_indexes_statistic_info-*")
        if keys:
            for k in keys:
                code = k.split("-")[-1]
                val = RedisUtils.get(self.__get_redis(), k)
                if val:
                    val = json.loads(val)
                    self.watch_indexes_statistic_info_dict[code] = val
    def get_statistic_info(self, code):
        return  self.watch_indexes_statistic_info_dict.get(code)
    def remove_statistic_info(self, code):
        if code not in self.watch_indexes_statistic_info_dict:
            return
        self.watch_indexes_statistic_info_dict.pop(code)
        RedisUtils.delete_async(self.__db, f"l_down_watch_indexes_statistic_info-{code}")
    def set_statistic_info(self, code, val):
        self.watch_indexes_statistic_info_dict[code] = val
        RedisUtils.setex_async(self.__db, f"l_down_watch_indexes_statistic_info-{code}", tool.get_expire(),
                               json.dumps(val))
# 计算成交位置之后的大单(特定笔数)的撤单比例
class LCancelBigNumComputer:
    __db = 0
@@ -737,6 +781,10 @@
    # 权重
    __l_down_after_by_big_order_weight_dict = {}
    # 上一次的L后的统计信息
    __last_l_down_watch_index_statistic_info = {}
    __instance = None
    def __new__(cls, *args, **kwargs):
@@ -875,6 +923,7 @@
    def clear(self, code=None):
        if code:
            LDownCancelWatchIndexStatisticManager().remove_statistic_info(code)
            self.del_watch_index(code)
            if code in self.__l_down_after_by_big_order_dict:
                self.__l_down_after_by_big_order_dict.pop(code)
@@ -944,9 +993,6 @@
                l2_log.l_cancel_debug(code, f"要间隔2分钟过后才能重新计算")
                return
            if total_datas:
                # 计算的上截至位距离下截至位纯买额要小于2.5倍m值
                # thresh_hold_money = l2_trade_factor.L2PlaceOrderParamsManager.get_base_m_val(code)
                # thresh_hold_money = int(thresh_hold_money * 2.5)
                min_num = int(5000 / gpcode_manager.get_limit_up_price_as_num(code))
                # 统计净涨停买的数量
                not_cancel_indexes_with_num = []
@@ -1885,15 +1931,53 @@
    def cancel_success(self, code):
        self.clear(code)
    def test(self):
        code = "000333"
        self.__set_cancel_l_down_after_place_order_index(code, 121, 0)
        time.sleep(6)
        self.__set_cancel_l_down_after_place_order_index(code, 121, 0),
        time.sleep(6)
        self.__set_cancel_l_down_after_place_order_index(code, 122, 1)
        print(self.__get_cancel_l_down_after_place_order_index_dict(code))
    def statistic_l_down_watch_indexes_info(self, code):
        """
        统计L后监听数据信息
        @param code:
        @return:((总笔数, 总金额), (已撤笔数,已撤金额), (已成交笔数,已成交金额), 综合撤单比例)
        """
        watch_indexes_info = self.__get_watch_indexes_cache(code)
        if not watch_indexes_info:
            return True
        trade_index, is_default = TradeBuyQueue().get_traded_index(code)
        if trade_index is None:
            trade_index = 0
        real_place_order_index_info = self.__real_place_order_index_dict.get(code)
        if not real_place_order_index_info:
            return True
        limit_up_price = gpcode_manager.get_limit_up_price_as_num(code)
        # 计算已经成交的比例
        total_datas = local_today_datas.get(code)
        total_deal_nums, total_nums, total_cancel_num, total_after_num = 0, 0, 0, 0
        for index in watch_indexes_info[2]:
            data = total_datas[index]
            val = data["val"]
            left_count = l2_data_source_util.L2DataSourceUtils.get_limit_up_buy_no_canceled_count_v2(code,
                                                                                                     index,
                                                                                                     total_datas,
                                                                                                     local_today_canceled_buyno_map.get(
                                                                                                         code))
            total_nums += val["num"]
            if index > real_place_order_index_info[0]:
                # L后后半段
                total_after_num += val["num"]
            if left_count <= 0:
                total_cancel_num += val["num"]
            else:
                if index < trade_index:
                    total_deal_nums += val["num"]
        # 总单
        # 已撤单
        # 成交单
        fresults = [(total_nums, int(total_nums * limit_up_price * 100)),
                    (total_cancel_num, int(total_cancel_num * limit_up_price * 100)),
                    (total_deal_nums, int(total_deal_nums * limit_up_price * 100))]
        if total_nums - total_after_num <= 0:
            fresults.append(100.00)
        else:
            fresults.append(round(total_cancel_num * 100 / (total_nums - total_after_num), 2))
        return fresults
class LCancelOutOfDateWatchIndexesManager:
inited_data.py
@@ -4,7 +4,7 @@
from __future__ import print_function, absolute_import
from cancel_strategy.s_l_h_cancel_strategy import LCancelBigNumComputer
from cancel_strategy.s_l_h_cancel_strategy import LCancelBigNumComputer, LDownCancelWatchIndexStatisticManager
from code_attribute import big_money_num_manager, global_data_loader, gpcode_manager, gpcode_first_screen_manager
from code_attribute.code_nature_analyse import LatestMaxVolumeManager, HighIncreaseCodeManager, CodeNatureRecordManager
from l2.l2_sell_manager import L2MarketSellManager
trade/buy_radical/radical_buy_data_manager.py
@@ -640,7 +640,7 @@
        @param count:
        @return:
        """
        cls.__process_add_must(code)
        # cls.__process_add_must(code)
        if gpcode_manager.MustBuyCodesManager().is_in_cache(code):
            return
        total_deal_big_order_result = get_total_deal_big_order_info(code,
@@ -651,18 +651,19 @@
    @classmethod
    def place_order_success(cls, code):
        # 如果是加想,且成交大单足够就加红
        total_deal_big_order_result = get_total_deal_big_order_info(code,
                                                                    gpcode_manager.get_limit_up_price_as_num(code))
        if WantBuyCodesManager().is_in_cache(code):
            if total_deal_big_order_result[0] <= 0:
                # 累计大单足够需要加红
                human_setting_money_info = TotalDealBigOrderThresholdMoneyManager().get_money_info_cache(code)
                if not human_setting_money_info or not trade_util.is_delegated(human_setting_money_info[1]):
                    # 没有人为设置累计大单阈值/不是在下单状态设置的 就不能加白
                    return
                gpcode_manager.MustBuyCodesManager().add_code(code)
                trade_record_log_util.add_must_buy(code, "累计成交大单足够")
        cls.__process_add_must(code)
        # total_deal_big_order_result = get_total_deal_big_order_info(code,
        #                                                             gpcode_manager.get_limit_up_price_as_num(code))
        # if WantBuyCodesManager().is_in_cache(code):
        #     if total_deal_big_order_result[0] <= 0:
        #         # 累计大单足够需要加红
        #         human_setting_money_info = TotalDealBigOrderThresholdMoneyManager().get_money_info_cache(code)
        #         if not human_setting_money_info or not trade_util.is_delegated(human_setting_money_info[1]):
        #             # 没有人为设置累计大单阈值/不是在下单状态设置的 就不能加白
        #             return
        #         gpcode_manager.MustBuyCodesManager().add_code(code)
        #         trade_record_log_util.add_must_buy(code, "累计成交大单足够")
        # cls.__process_add_must(code)
        pass
    @classmethod
    def __process_add_must(cls, code):
@@ -744,13 +745,13 @@
        if not trade_util.is_delegated(trade_state):
            return
        if not gpcode_manager.MustBuyCodesManager().is_in_cache(code):
            human_setting_money_info = TotalDealBigOrderThresholdMoneyManager().get_money_info_cache(code)
            if not human_setting_money_info or not trade_util.is_delegated(human_setting_money_info[1]):
                # 没有人为设置累计大单阈值/不是在下单状态设置的 就不能加白
                return
            gpcode_manager.MustBuyCodesManager().add_code(code)
            trade_record_log_util.add_must_buy(code, "大单足够")
        # if not gpcode_manager.MustBuyCodesManager().is_in_cache(code):
        #     human_setting_money_info = TotalDealBigOrderThresholdMoneyManager().get_money_info_cache(code)
        #     if not human_setting_money_info or not trade_util.is_delegated(human_setting_money_info[1]):
        #         # 没有人为设置累计大单阈值/不是在下单状态设置的 就不能加白
        #         return
        #     gpcode_manager.MustBuyCodesManager().add_code(code)
        #     trade_record_log_util.add_must_buy(code, "大单足够")
class RadicalBuyBlockManager: