"""
|
买入策略帮助类
|
"""
|
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, ""
|