Administrator
4 小时以前 2f2516749615da866e96d8d24e499b7ecbb63a3e
trade/l2_trade_factor.py
@@ -6,6 +6,7 @@
from code_attribute import big_money_num_manager, limit_up_time_manager, global_data_loader, gpcode_manager
import constant
from trade import trade_manager, deal_big_money_manager, trade_constant
from utils import global_util, tool
@@ -19,7 +20,7 @@
        continue_count = self.get_begin_continue_buy_count()
        time_range = self.get_time_range()
        m = self.get_m_val()[0]
        m = m//10000
        m = m // 10000
        desc = ""
        if self.buy_rank == 0:
@@ -114,6 +115,11 @@
        self.now_time = now_time
        self.buy_rank = self.get_buy_rank()
    # 是否是初次下单
    @classmethod
    def is_first_place_order(cls, code):
        return trade_manager.CodesTradeStateManager().get_trade_state_cache(code) == trade_constant.TRADE_STATE_NOT_TRADE
    # 设置分数
    def set_score(self, score):
        score_ranks = [constant.BUY_SCORE_RANK_3, constant.BUY_SCORE_RANK_2, constant.BUY_SCORE_RANK_1,
@@ -129,7 +135,6 @@
        self.score_index = score_index
    # 获取信号连续买笔数
    def get_begin_continue_buy_count(self):
        counts = [3, 3, 3, 2, 2, 2, 2]
        volume_rate_index = self.volume_rate_index
@@ -140,29 +145,31 @@
    # 获取时间计算范围,返回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)]
        ts = [pow(2, 1), pow(2, 1), pow(2, 1), pow(2, 1), pow(2, 2), pow(2, 2), pow(2, 2), pow(2, 2)]
        ts = [pow(2, 1), pow(2, 1), pow(2, 1), pow(2, 1), pow(2, 1), pow(2, 1), pow(2, 1), pow(2, 1)]
        # 暂时去除分的影响
        # 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
        # 首次下单必须同1s
        if self.is_first_place_order(self.code):
            return 1
        return ts[volume_rate_index]
    # 获取需要的大单个数
    def get_big_num_count(self):
        # if self.is_first_code:
        #     if self.buy_rank < 2:
        #         return 0
        #     elif self.buy_rank == 2:
        #         return 1
        #     elif self.buy_rank == 3:
        #         return 2
        counts = [1, 1, 1, 1, 0, 0, 0, 0]
        volume_rate_index = self.volume_rate_index
        if self.volume_rate_index >= len(counts):
            volume_rate_index = -1
        return counts[volume_rate_index]
        # counts = [1, 1, 1, 1, 0, 0, 0, 0]
        # volume_rate_index = self.volume_rate_index
        # if self.volume_rate_index >= len(counts):
        #     volume_rate_index = -1
        # return counts[volume_rate_index]
        # 有大单成交就不需要大单了,没有大单成交就需要大单
        deal_big_money_count = deal_big_money_manager.get_deal_big_money_count(self.code)
        if deal_big_money_count > 0:
            return 0
        else:
            return 1
    # 获取安全笔数影响比例
    def get_safe_count_rate(self):
@@ -179,34 +186,31 @@
        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)))
        return count
        # 最少8笔
        return max(count, 8)
    # 获取m值影响比例
    @classmethod
    def get_m_val_rate(cls, volume_rate_index):
        rates = [0.0, -0.1, -0.2, -0.3, -0.4, -0.5, -0.6, -0.7]
        rates = [0.0, -0.1, -0.15, -0.2, -0.25, -0.3, -0.35, -0.4]
        if volume_rate_index >= len(rates):
            volume_rate_index = -1
        return rates[volume_rate_index]
    # 获取m值
    def get_m_val(self):
        # 获取固定m值
        zyltgb = global_util.zyltgb_map.get(self.code)
    @classmethod
    def get_base_m_val(cls, code):
        zyltgb = global_util.zyltgb_map.get(code)
        if zyltgb is None:
            global_data_loader.load_zyltgb()
            zyltgb = global_util.zyltgb_map.get(self.code)
        # if self.is_first_code:
        #     if self.buy_rank == 0:
        #         return 0, ""
        #     elif self.is_want_buy and zyltgb and zyltgb < 20 * 10000 * 10000:
        #         # 小于20亿的想买单
        #         return 500 * 10000, ""
        #     elif self.buy_rank < 4:
        #         return 1000 * 10000, ""
            zyltgb = global_util.zyltgb_map.get(code)
        base_m = L2TradeFactorUtil.get_base_safe_val(zyltgb)
        return base_m
    # 获取m值
    def get_m_val(self):
        base_m = self.get_base_m_val(self.code)
        if self.is_first_place_order(self.code) and tool.is_sz_code(self.code):
            base_m = int(base_m * 2)
        rate = self.get_m_val_rate(self.volume_rate_index)
        m = round(base_m * (1 + rate))
        return m, ""
@@ -237,7 +241,7 @@
        rates = [0.34, 0.44, 0.54, 0.64, 0.74, 0.84, 0.94, 1.04]
        if volume_rate_index >= len(rates):
            volume_rate_index = -1
        return 0.59 #rates[volume_rate_index]
        return 0.79  # rates[volume_rate_index]
# H撤参数
@@ -271,7 +275,7 @@
        yi = round(zyltgb / 100000000)
        if yi < 1:
            yi = 1
        return int(-0.058*yi*yi + 60.9*yi)*10000
        return int(-0.058 * yi * yi + 60.9 * yi) * 10000
        # m = 5000000 + (yi - 1) * 500000
        # return round(m * (1 - 0.3))
@@ -538,8 +542,8 @@
    # print(L2TradeFactorUtil.get_rate_factors("003004"))
    # print(L2TradeFactorUtil.factors_to_string("003004"))
    for i in range(2, 150):
        print(i, L2TradeFactorUtil.get_base_safe_val(100000000 * i))
    # for i in range(2, 150):
    print(22, L2TradeFactorUtil.get_base_safe_val(100000000 * 22))
    # print(L2TradeFactorUtil.get_limit_up_time_rate("11:30:00"))
    # print(L2TradeFactorUtil.get_limit_up_time_rate("13:00:00"))
    # print(L2TradeFactorUtil.get_limit_up_time_rate("13:48:00"))