Administrator
4 天以前 48fb7a00951f91bdc707e5dd2d196e5bccb752c3
trade/l2_trade_factor.py
@@ -4,16 +4,13 @@
# l2交易因子
import big_money_num_manager
from code_attribute import big_money_num_manager, limit_up_time_manager, global_data_loader, gpcode_manager
import constant
import global_data_loader
import global_util
import gpcode_manager
import limit_up_time_manager
from trade import trade_manager, deal_big_money_manager, trade_constant
from utils import global_util, tool
# 下单参数
import tool
from l2 import code_price_manager
class L2PlaceOrderParamsManager:
@@ -23,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:
@@ -56,7 +53,7 @@
            return 100
        # 暂时不需要次此中策略
        # # 判断有没有炸开
        # if code_price_manager.Buy1PriceManager.is_can_buy(self.code):
        # if code_price_manager.Buy1PriceManager().is_can_buy(self.code):
        #     # 回封
        #     if self.score_index == 0:
        #         return 0
@@ -93,17 +90,18 @@
        self.is_first_code = is_first_code
        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
        # 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
        # score_index = -1
        # for i in range(0, len(score_ranks)):
        #     if self.score >= score_ranks[i]:
        #         score_index = i
        #         break
        # 固定设置为2
        self.score_index = 2
        # 只要加入想买单的,全部执行主动买入二星方案
        if gpcode_manager.WantBuyCodesManager.is_in(code):
        if gpcode_manager.WantBuyCodesManager().is_in_cache(code):
            self.score_index = 1
            self.is_want_buy = True
        else:
@@ -116,6 +114,11 @@
        self.volume_rate_index = volume_rate_index
        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):
@@ -132,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
@@ -150,22 +152,24 @@
        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 = [2, 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):
@@ -182,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, ""
@@ -240,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 rates[volume_rate_index]
        return 0.79  # rates[volume_rate_index]
# H撤参数
@@ -257,10 +258,12 @@
    # 获取撤销比例
    @staticmethod
    def get_cancel_rate(volume_rate_index):
        rates = [0.35, 0.45, 0.55, 0.65, 0.65, 0.75, 0.75, 0.75]
        if volume_rate_index >= len(rates):
            volume_rate_index = -1
        return rates[volume_rate_index]
        # 暂时固定死
        # rates = [0.35, 0.45, 0.55, 0.65, 0.65, 0.75, 0.75, 0.75]
        # if volume_rate_index >= len(rates):
        #     volume_rate_index = -1
        # return rates[volume_rate_index]
        return 0.89
class L2TradeFactorUtil:
@@ -272,8 +275,9 @@
        yi = round(zyltgb / 100000000)
        if yi < 1:
            yi = 1
        m = 5000000 + (yi - 1) * 500000
        return round(m * (1 - 0.3))
        return int(-0.058 * yi * yi + 60.9 * yi) * 10000
        # m = 5000000 + (yi - 1) * 500000
        # return round(m * (1 - 0.3))
    # 获取行业影响比例
    # total_limit_percent为统计的比例之和乘以100
@@ -435,11 +439,11 @@
        # 首次涨停时间
        limit_up_time = global_util.limit_up_time.get(code)
        if limit_up_time is None:
            limit_up_time = limit_up_time_manager.get_limit_up_time(code)
            limit_up_time = limit_up_time_manager.LimitUpTimeManager().get_limit_up_time_cache(code)
        big_money_num = global_util.big_money_num.get(code)
        if big_money_num is None:
            big_money_num = big_money_num_manager.get_num(code)
            big_money_num = big_money_num_manager.get_num_cache(code)
        return (
            zyltgb, total_industry_limit_percent, volumn_day60_max, volumn_yest, volumn_today, limit_up_time,
            big_money_num)
@@ -537,8 +541,9 @@
    # print(L2TradeFactorUtil.get_safe_buy_count("003005"))
    # print(L2TradeFactorUtil.get_rate_factors("003004"))
    # print(L2TradeFactorUtil.factors_to_string("003004"))
    for i in range(2, 50):
        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"))