Administrator
2024-08-14 a51d5c5cfadafdc2cf75ca581d212c1d7c8e12ca
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
"""
买入策略帮助类
"""
from code_attribute import gpcode_manager
from l2 import l2_data_util, l2_data_source_util
from utils import tool
 
 
def is_has_small_batch_cancel(code, start_index, end_index):
    """
    是否有小群撤单:有连续10笔涨停撤单且连续10笔涨停撤单中小于2笔涨停买单
    @param code:
    @param total_datas:
    @param start_index:
    @param end_index:
    @return:
    """
    # 从end_index找到start_index
    limit_up_price = gpcode_manager.get_limit_up_price_as_num(code)
    min_num = int(round(5000 / limit_up_price))
    total_datas = l2_data_util.local_today_datas.get(code)
    end_time_with_ms = l2_data_util.L2DataUtil.get_time_with_ms(total_datas[end_index]["val"])
    buy_count = 0
    cancel_count = 0
    for i in range(end_index - 1, start_index - 1, -1):
        data = total_datas[i]
        val = data["val"]
        if val["num"] < min_num:
            continue
 
        if not l2_data_util.L2DataUtil.is_limit_up_price_buy_cancel(val):
            if l2_data_util.L2DataUtil.is_limit_up_price_buy(val):
                if cancel_count > 0:
                    # 当统计到一个涨停买撤的时候才能统计买
                    buy_count += 1
                    if buy_count > 1:
                        break
            continue
        # 与当前时间相差3s的结束
        if tool.trade_time_sub_with_ms(end_time_with_ms, l2_data_util.L2DataUtil.get_time_with_ms(val)) > 3000:
            break
 
        cancel_count += 1
        if cancel_count >= 10:
            break
    if cancel_count >= 10 and buy_count < 2:
        return True
    return False
 
 
def is_cancel_rate_reieved(code, threshhold_rate, start_index, end_index):
    # 统计总共的涨停买
    limit_up_price = gpcode_manager.get_limit_up_price_as_num(code)
    min_num = int(round(5000 / limit_up_price))
    total_datas = l2_data_util.local_today_datas.get(code)
    buyno_map = l2_data_util.local_today_buyno_map.get(code)
    buy_count = 0
    for i in range(start_index, end_index):
        data = total_datas[i]
        val = data["val"]
        if not l2_data_util.L2DataUtil.is_limit_up_price_buy(val):
            continue
        if val["num"] < min_num:
            continue
        buy_count += 1
    # 统计总共的涨停买撤
    cancel_count = 0
    for i in range(start_index, end_index):
        data = total_datas[i]
        val = data["val"]
        if not l2_data_util.L2DataUtil.is_limit_up_price_buy_cancel(val):
            continue
        if val["num"] < min_num:
            continue
 
        buy_index = l2_data_source_util.L2DataSourceUtils.get_buy_index_with_cancel_data_v2(val, buyno_map)
        if buy_index and start_index <= buy_index:
            cancel_count += 1
    if buy_count == 0:
        return False
    if round(cancel_count / buy_count, 2) > threshhold_rate:
        return True
    return False
 
 
def is_near_by_trade_index(code, trade_index):
    """
    是否距离成交位近
    @param code:
    @param trade_index:
    @return:
    """
    total_data = l2_data_util.local_today_datas.get(code)
    total_count = 0
    total_big_count = 0
    for i in range(trade_index + 1, total_data[-1]["index"] + 1):
        data = total_data[i]
        val = data["val"]
        if not l2_data_util.L2DataUtil.is_limit_up_price_buy(val):
            continue
        money = val["num"] * float(val["price"])
        if money < 5000:
            continue
 
        left_count = l2_data_source_util.L2DataSourceUtils.get_limit_up_buy_no_canceled_count_v2(
            code,
            i,
            total_data,
            l2_data_util.local_today_canceled_buyno_map.get(
                code))
        if left_count > 0:
            total_count += 1
            if money > 29900:
                total_big_count += 1
            if total_count > 10:
                break
    if total_count > 10 or total_big_count < 1:
        return False, f"未成交数量-{total_count},大单数量-{total_big_count}"
    return True, ""