Administrator
2023-09-27 ad7a3d78a9547d9b0ae26c5fc059872fbb3be9be
华鑫L2非缓存模式/L撤比例动态变化
6个文件已修改
81 ■■■■ 已修改文件
constant.py 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
huaxin_client/l2_client.py 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/cancel_buy_strategy.py 54 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/code_price_manager.py 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
test/test.py 14 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
trade/l2_trade_factor.py 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
constant.py
@@ -79,7 +79,7 @@
H_CANCEL_MIN_MONEY = 98
H_CANCEL_MIN_COUNT = 40
H_CANCEL_MIN_BIG_NUM_COUNT = 3
H_CANCEL_START_TIME = 10
H_CANCEL_START_TIME = 900
# L2监控的最低金额
L2_MIN_MONEY = 500000
huaxin_client/l2_client.py
@@ -536,9 +536,9 @@
    g_SubMode = lev2mdapi.TORA_TSTP_MST_MCAST
    # case 1缓存模式
    api = lev2mdapi.CTORATstpLev2MdApi_CreateTstpLev2MdApi(g_SubMode, True)
    # api = lev2mdapi.CTORATstpLev2MdApi_CreateTstpLev2MdApi(g_SubMode, True)
    # case 2非缓存模式
    # api = lev2mdapi.CTORATstpLev2MdApi_CreateTstpLev2MdApi(g_SubMode, False)
    api = lev2mdapi.CTORATstpLev2MdApi_CreateTstpLev2MdApi(g_SubMode, False)
    global spi
    spi = Lev2MdSpi(api)
    api.RegisterSpi(spi)
l2/cancel_buy_strategy.py
@@ -662,6 +662,45 @@
# ---------------------------------L撤-------------------------------
class LCancelRateManager:
    __block_limit_up_count_dict = {}
    __big_num_deal_rate_dict = {}
    # 获取撤单比例
    @classmethod
    def get_cancel_rate(cls, code):
        base_rate = constant.L_CANCEL_RATE
        if code in cls.__block_limit_up_count_dict:
            count = cls.__block_limit_up_count_dict[code]
            rates = [0, 0.03, 0.06, 0.08, 0.12]
            rate = 0
            if count >= len(rates):
                rate = rates[-1]
            else:
                rate = rates[count]
            base_rate += rate
        if code in cls.__big_num_deal_rate_dict:
            temp_rate = cls.__big_num_deal_rate_dict[code]
            rate = 0
            if temp_rate >= 1:
                if temp_rate > 3:
                    temp_rate = 3
                rate = round((temp_rate * 3.5 - 2.5) / 100, 4)
            base_rate += rate
        return round(base_rate,2)
    # 设置板块涨停数量(除开自己)
    @classmethod
    def set_block_limit_up_count(cls, code, count):
        cls.__block_limit_up_count_dict[code] = count
    # 设置大单成交金额➗固定m值比例
    @classmethod
    def set_big_num_deal_rate(cls, code, rate):
        cls.__big_num_deal_rate_dict[code] = rate
# 计算成交位置之后的大单(特定笔数)的撤单比例
class LCancelBigNumComputer:
    __db = 0
@@ -828,7 +867,7 @@
        if start_index is None or end_index is None:
            return
        total_datas = local_today_datas.get(code)
        MIN_MONEY = 50 * 100
        MIN_MONEY = 99 * 100
        MAX_COUNT = 10
        watch_indexes = set()
        total_num = 0
@@ -849,10 +888,10 @@
            if left_count > 0:
                total_num += val['num'] * left_count
                watch_indexes.add(i)
                if len(watch_indexes) > MAX_COUNT or total_num >= threshold_num:
                if len(watch_indexes) >= MAX_COUNT or total_num >= threshold_num:
                    break
        # 保存数据
        l2_log.l_cancel_debug(code,f"设置成交位临近撤单监控范围:{watch_indexes} 计算范围:{start_index}-{end_index}")
        l2_log.l_cancel_debug(code, f"设置成交位临近撤单监控范围:{watch_indexes} 计算范围:{start_index}-{end_index}")
        self.__set_near_by_trade_progress_indexes(code, watch_indexes)
    # 设置成交位置,成交位置变化之后相应的监听数据也会发生变化
@@ -885,7 +924,7 @@
        # 计算监听的总条数
        total_num = 0
        for wi in watch_indexes:
            total_num += total_data[wi]["val"]["num"]*total_data[wi]["re"]
            total_num += total_data[wi]["val"]["num"] * total_data[wi]["re"]
        # 判断撤单中是否有监听中的索引
        need_compute = False
        for i in range(start_index, end_index + 1):
@@ -908,7 +947,7 @@
                                                                                                      wi,
                                                                                                      total_data,
                                                                                                      _local_today_num_operate_map)
                canceled_num += (total_data[wi]["re"] - left_count)*total_data[wi]["val"]["num"]
                canceled_num += (total_data[wi]["re"] - left_count) * total_data[wi]["val"]["num"]
                # if wi == watch_indexes_list[-1] and left_count == 0:
                #     # 离下单位置最近的一个撤单,必须触发撤单
                #     l2_log.l_cancel_debug(code, f"计算范围:{start_index}-{end_index},临近撤单:{wi}")
@@ -916,7 +955,7 @@
            rate = round(canceled_num / total_num, 3)
            l2_log.l_cancel_debug(code, f"计算范围:{start_index}-{end_index},已撤单比例:{rate}")
            if rate >= constant.L_CANCEL_RATE:
            if rate >= LCancelRateManager.get_cancel_rate(code):
                return True, total_data[-1]
        return False, None
@@ -953,7 +992,7 @@
                canceled_count += total_data[wi]["re"] - left_count
            rate = round(canceled_count / total_count, 3)
            l2_log.l_cancel_debug(code, f"计算范围:{start_index}-{end_index},成交位临近已撤单比例:{rate}")
            if rate >= constant.L_CANCEL_RATE:
            if rate >= LCancelRateManager.get_cancel_rate(code):
                return True, total_data[-1]
        return False, None
@@ -1494,3 +1533,4 @@
if __name__ == "__main__":
    pass
l2/code_price_manager.py
@@ -5,6 +5,7 @@
from code_attribute import gpcode_manager
from db.redis_manager_delegate import RedisUtils
from log_module import async_log_util
from trade import l2_trade_util
from utils import tool
from db import redis_manager_delegate as redis_manager
@@ -166,7 +167,7 @@
            if (float(buy_1_price) - pre_close_price) / pre_close_price < 0.05:
                # 涨幅小于5%
                l2_trade_util.forbidden_trade(code, "涨停炸开后现价涨幅小于5%之后不买")
                logger_trade_queue_price_info.add(f"涨停炸开后现价涨幅小于5%之后不买:code-{code}")
                async_log_util.info(logger_trade_queue_price_info, f"涨停炸开后现价涨幅小于5%之后不买:code-{code}")
            # 之前涨停过且现在尚未涨停
            self.set_open_limit_up_lowest_price(code, buy_1_price)
test/test.py
@@ -2,6 +2,8 @@
import queue
import time
from l2.cancel_buy_strategy import LCancelRateManager
__queue = queue.Queue()
@@ -29,11 +31,7 @@
if __name__ == "__main__":
    p1, p2 = multiprocessing.Pipe()
    # L1订阅数据
    progress1 = multiprocessing.Process(target=lambda: test_process_1(p1))
    progress2 = multiprocessing.Process(target=lambda: test_process_2(p2))
    progress1.start()
    progress2.start()
    input()
    code = "000333"
    LCancelRateManager.set_block_limit_up_count(code, 100)
    LCancelRateManager.set_big_num_deal_rate(code, 10)
    print(LCancelRateManager.get_cancel_rate(code))
trade/l2_trade_factor.py
@@ -212,8 +212,8 @@
    # 获取m值
    def get_m_val(self):
        base_m = self.get_base_m_val(self.code)
        if self.is_first_place_order(self.code):
            base_m = int(base_m * 1.5)
        # if self.is_first_place_order(self.code):
        #     base_m = int(base_m * 1.5)
        rate = self.get_m_val_rate(self.volume_rate_index)
        m = round(base_m * (1 + rate))
        return m, ""