Administrator
2023-04-21 0ed2c53acd278d57a39390fd4db78c5aaf088e0a
trade/l2_trade_factor.py
@@ -8,17 +8,79 @@
import constant
import global_data_loader
import global_util
import gpcode_manager
import limit_up_time_manager
# 下单参数
import tool
from l2 import code_price_manager
class L2PlaceOrderParamsManager:
    # 获取买入等级描述
    def get_buy_rank_desc(self):
        continue_count = self.get_begin_continue_buy_count()
        time_range = self.get_time_range()
        desc = ""
        if self.buy_rank == 0:
            desc = f"买入信号({continue_count})"
        elif self.buy_rank == 1:
            desc = f"买入信号({continue_count})+M值≥1000万"
        elif self.buy_rank == 2:
            desc = f"买入信号({continue_count})+M值≥1000万+至少含1笔大单"
        elif self.buy_rank == 3:
            desc = f"买入信号({continue_count})+M值≥1000万+至少含2笔大单"
        else:
            desc = "常规买入"
        desc += f"+囊括时间{time_range}s"
        return desc
    # 获取买入等级
    # 0:买入信号
    # 1:买入信号+M1000万
    # 2:买入信号+M1000万+1笔大单
    # 3:买入信号+M1000+2笔大单
    # 100:执行之前固有方案
    def get_buy_rank(self):
        # 判断有没有炸开
        if code_price_manager.Buy1PriceManager.is_can_buy(self.code):
            # 回封
            if self.score_index == 0:
                return 0
            elif self.score_index == 1:
                return 1
            elif self.score_index == 2:
                return 2
            else:
                return 100
        else:
            # 首封
            if tool.trade_time_sub(self.now_time, "10:30:00") < 0 or tool.trade_time_sub(self.now_time, "14:00:00") > 0:
                if self.score_index == 0:
                    return 1
                elif self.score_index == 1:
                    return 2
                elif self.score_index == 2:
                    return 3
                else:
                    return 100
            else:
                if self.score_index == 0:
                    return 2
                elif self.score_index == 1:
                    return 3
                elif self.score_index == 2:
                    return 100
                else:
                    return 100
    # 得分
    def __init__(self, code, is_first_code, volume_rate, volume_rate_index, score):
    def __init__(self, code, is_first_code, volume_rate, volume_rate_index, score, now_time=tool.get_now_time_str()):
        self.code = code
        self.is_first_code = is_first_code
        score_ranks = [200, 190, 180, 100]
        score_ranks = [constant.BUY_SCORE_RANK_3, constant.BUY_SCORE_RANK_2, constant.BUY_SCORE_RANK_1,
                       constant.BUY_SCORE_RANK_0]
        self.score = score[0][0]
        self.score_info = score
        # 为分数设置等级
@@ -28,8 +90,28 @@
                score_index = i
                break
        self.score_index = score_index
        # 只要加入想买单的,全部执行主动买入一星方案
        if gpcode_manager.WantBuyCodesManager.is_in(code) and self.score_index >= 3:
            self.score_index = 2
        self.volume_rate = volume_rate
        self.volume_rate_index = volume_rate_index
        self.now_time = now_time
        self.buy_rank = self.get_buy_rank()
    # 设置分数
    def set_score(self, score):
        score_ranks = [constant.BUY_SCORE_RANK_3, constant.BUY_SCORE_RANK_2, constant.BUY_SCORE_RANK_1,
                       constant.BUY_SCORE_RANK_0]
        self.score = score[0][0]
        self.score_info = score
        # 为分数设置等级
        score_index = -1
        for i in range(0, len(score_ranks)):
            if self.score >= score_ranks[i]:
                score_index = i
                break
        self.score_index = score_index
    # 获取信号连续买笔数
@@ -43,6 +125,8 @@
    # 获取时间计算范围,返回s
    def get_time_range(self):
        ts = [pow(3, 1), pow(3, 1), pow(3, 1), pow(3, 2), pow(3, 2), pow(3, 3), pow(3, 3), pow(3, 3)]
        if -1 < self.score_index < 3:
            return ts[0]
        volume_rate_index = self.volume_rate_index
        if self.volume_rate_index >= len(ts):
            volume_rate_index = -1
@@ -51,14 +135,12 @@
    # 获取需要的大单个数
    def get_big_num_count(self):
        if self.is_first_code:
            if self.score_index == 0:
            if self.buy_rank < 2:
                return 0
            elif self.score_index == 1:
                return 0
            elif self.score_index == 2:
            elif self.buy_rank == 2:
                return 1
            elif self.score_index < 0:
                return 65535
            elif self.buy_rank == 3:
                return 2
        counts = [3, 1, 1, 1, 0, 0, 0, 0]
        volume_rate_index = self.volume_rate_index
        if self.volume_rate_index >= len(counts):
@@ -75,10 +157,8 @@
    def get_safe_count(self):
        if self.is_first_code:
            if 3 > self.score_index > -1:
            if self.buy_rank < 4:
                return 2
            elif self.score_index < 0:
                return 65535
        base_count, min_count, max_count = L2TradeFactorUtil.get_safe_buy_count(self.code, True)
        rate = self.get_safe_count_rate()
        count = int(round(base_count * (1 + rate)))
@@ -87,7 +167,7 @@
    # 获取m值影响比例
    @classmethod
    def get_m_val_rate(cls, volume_rate_index):
        rates = [0.0, 0.0, 0.0, -0.3, -0.4, -0.5, -0.6, -0.7]
        rates = [0.0, -0.1, -0.2, -0.3, -0.4, -0.5, -0.6, -0.7]
        if volume_rate_index >= len(rates):
            volume_rate_index = -1
        return rates[volume_rate_index]
@@ -95,14 +175,10 @@
    # 获取m值
    def get_m_val(self):
        if self.is_first_code:
            if self.score_index == 0:
            if self.buy_rank == 0:
                return 0, ""
            elif self.score_index == 1:
            elif self.buy_rank < 4:
                return 1000 * 10000, ""
            elif self.score_index == 2:
                return 1000 * 10000, ""
            elif self.score_index < 0:
                return 65535 * 10000, ""
        # 获取固定m值
        zyltgb = global_util.zyltgb_map.get(self.code)
        if zyltgb is None:
@@ -128,7 +204,8 @@
    # 获取买时间范围(距离执行位),返回s
    @staticmethod
    def get_buy_time_range(volume_rate_index):
        seconds = [pow(2, 1), pow(2, 2), pow(2, 3), pow(2, 4), pow(2, 4), pow(2, 5), pow(2, 6), pow(2, 6)]
        # rates = [0.2, 0.4, 0.6, 0.8, 1, 1.2, 1.4, 1.6]
        seconds = [pow(2, 1), pow(2, 2), pow(2, 3), pow(2, 4), pow(2, 5), pow(2, 5), pow(2, 4), pow(2, 4)]
        if volume_rate_index >= len(seconds):
            volume_rate_index = -1
        return seconds[volume_rate_index]
@@ -388,7 +465,7 @@
            MAX_VAL = 13
        if not gb:
            # 默认8笔
            return MIN_VAL,MIN_VAL, MAX_VAL
            return MIN_VAL, MIN_VAL, MAX_VAL
        count = gb // 100000000
        if True:
            if count < 8: