import logging
|
|
from strategy.strategy_params_settings import StrategyParamsSettings
|
from strategy.strategy_variable import StockVariables
|
|
sv = StockVariables()
|
settings = StrategyParamsSettings()
|
target_code = ''
|
|
|
def format_time(huaxin_timestamp):
|
huaxin_timestamp = str(huaxin_timestamp)
|
if huaxin_timestamp.find("9") == 0:
|
return f"0{huaxin_timestamp[0]}:{huaxin_timestamp[1: 3]}:{huaxin_timestamp[3: 5]}"
|
return f"{huaxin_timestamp[0:2]}:{huaxin_timestamp[2: 4]}:{huaxin_timestamp[4: 6]}"
|
|
|
def can_buy():
|
"""
|
@return: 是否可买, 不能买的原因/可买的板块, 是否量够
|
"""
|
# print(f"{target_code}:执行策略")
|
if not settings.can_buy_ge_code:
|
if target_code.find("60") != 0 and target_code.find("00") != 0:
|
return False, "创业板/科创板的票不买"
|
else:
|
if target_code.find("60") != 0 and target_code.find("00") != 0 and target_code.find("30") != 0:
|
return False, "科创板的票不买"
|
|
# 目标票板块涨停个数>=2
|
can_buy_plates = set()
|
for plate in sv.代码板块:
|
if not sv.资金流入板块 or plate not in sv.资金流入板块:
|
continue
|
if plate in sv.连续老题材:
|
continue
|
if plate in sv.日出现的板块_2:
|
# 老题材
|
threshold_count = settings.limit_up_count_of_old_plate
|
else:
|
# 新题材
|
threshold_count = settings.limit_up_count_of_new_plate
|
if len(sv.开盘啦最正板块涨停.get(plate, [])) >= threshold_count:
|
can_buy_plates.add(plate)
|
|
if not sv.当前价:
|
return False, "无当前价"
|
|
# if getattr(sv, f"涨停数_{settings.has_limit_up_days}") < 1 and getattr(sv, f"炸板数_{settings.has_limit_up_days}") < 1:
|
# return False, f"近{settings.has_limit_up_days}个交易日无涨停/无炸板"
|
|
if settings.cant_yesterday_limit_down and not sv.昨日非跌停:
|
return False, "昨日跌停"
|
if settings.cant_yesterday_limit_up and not sv.昨日非涨停:
|
return False, "昨日涨停"
|
if settings.cant_yesterday_open_limit_up and not sv.昨日非炸板:
|
return False, "昨日炸板"
|
|
if sv.今日涨停价 > settings.price_range[1] or sv.今日涨停价 < settings.price_range[0]:
|
return False, f"今日涨停价高于{settings.price_range[1]}/低于{settings.price_range[0]}"
|
|
if getattr(sv, f"涨停数_{settings.trade_days_count_of_limit_up}") >= settings.count_of_limit_up:
|
return False, f"{settings.trade_days_count_of_limit_up}日涨停数>{settings.count_of_limit_up}"
|
|
if getattr(sv, f"跌停数_{settings.trade_days_count_of_limit_down}") >= settings.count_of_limit_down:
|
return False, f"{settings.trade_days_count_of_limit_down}日跌停数>{settings.count_of_limit_down}"
|
|
if getattr(sv, f"炸板数_{settings.trade_days_count_of_open_limit_up}") >= settings.count_of_open_limit_up:
|
return False, f"{settings.trade_days_count_of_open_limit_up}日炸板数>{settings.count_of_open_limit_up}"
|
|
if sv.涨停数_10 + sv.炸板数_10 >= 4:
|
return False, f"10天内>=4个涨停/炸板"
|
|
if sv.今日开盘价 and (sv.今日开盘价 - sv.昨日收盘价) / sv.昨日收盘价 < settings.min_open_rate:
|
return False, f"开盘涨幅小于{settings.min_open_rate}"
|
|
rate = (sv.当前价 - sv.昨日收盘价) / sv.昨日收盘价
|
if rate >= settings.avaiable_rates[1] or rate < settings.avaiable_rates[0]:
|
return False, f"涨幅不在区间内({settings.avaiable_rates[0]}-{settings.avaiable_rates[1]}):{rate}"
|
|
if sv.自由流通市值 > settings.zyltgb_range[1] or sv.自由流通市值 < settings.zyltgb_range[0]:
|
return False, f"自由市值({sv.自由流通市值})不满足要求"
|
|
if sv.六个交易日涨幅过高:
|
return False, f"6个交易日涨幅过高"
|
|
# if sv.当前价 > sv.昨日最低价 * 1.1:
|
# return False, f"买入时的价格必须≤昨日最低价*110%"
|
|
# if (sv.当前价 - sv.今日最低价) / sv.昨日收盘价 > 0.03:
|
# return False, f"买入时的价格不能高于今日最低价的3%"
|
|
if abs((sv.当前价 - round(sv.今日成交额 / sv.今日成交量, 2)) / sv.昨日收盘价) >= settings.max_rate_than_average_price:
|
return False, f"买入价高于均价{settings.max_rate_than_average_price}({abs((sv.当前价 - round(sv.今日成交额 / sv.今日成交量, 2)) / sv.昨日收盘价)})"
|
|
if (sv.今日最高价信息[0] - sv.当前价) / sv.昨日收盘价 > settings.min_rate_of_highest_and_price:
|
return False, f"低于分时高价{settings.min_rate_of_highest_and_price}"
|
|
if not settings.can_buy_limited_up and abs(sv.今日最高价信息[0] - sv.今日涨停价) <= 0.001:
|
return False, f"今日有涨停"
|
|
# if sv.涨停数_30 <= 0 and not sv.日放倍量日期_15:
|
# return False, "30个交易日无涨停且15个交易日无倍量"
|
|
# 目标票板块涨停个数>=2
|
|
if sv.板块成交代码:
|
can_buy_plates -= set(sv.板块成交代码.keys())
|
|
if not can_buy_plates:
|
return False, "没有涨停的板块"
|
# new_plates = set(can_buy_plates) - sv.日出现的板块_2
|
# if new_plates:
|
# # 有新题材,判断是否过昨日前高
|
# if sv.今日最高价信息[0] - sv.昨日最高价 < 0.02:
|
# return False, "今日最高价需大于昨日最高价"
|
# else:
|
# if sv.今日最高价信息[0] - sv.日最高价_5 < 0.02:
|
# return False, "今日最高价需大于5日最高价"
|
|
if settings.trade_days_count_of_limit_up_price_over_high and sv.今日涨停价 <= getattr(sv,
|
f"日最高价_{settings.trade_days_count_of_limit_up_price_over_high}"):
|
return False, f"今日涨停价要突破{settings.trade_days_count_of_limit_up_price_over_high}日最高价"
|
|
# if sv.今日成交量 < sv.昨日成交量 * 0.8:
|
# return False, f"实时成交量必须≥80%昨日总成交量"
|
|
# =======成交大单=====
|
big_order_money = 0
|
if sv.今日大单数据:
|
# print(sv.今日大单数据[-1][3], format_time(sv.今日大单数据[-1][3]))
|
# filter_orders = [(o[0], o[2]) for o in sv.今日大单数据 if format_time(o[3]) >= sv.今日量够信息[0]]
|
filter_orders = [(o[0], o[2]) for o in sv.今日大单数据]
|
filter_orders.reverse()
|
orderids = set()
|
for o in filter_orders:
|
if o[0] in orderids:
|
continue
|
orderids.add(o[0])
|
big_order_money += o[1]
|
threshold_money = max(sv.自由流通市值 // 1000, 200e4)
|
|
limit_up_codes_count = max([(p, len(sv.开盘啦最正板块涨停.get(p, []))) for p in can_buy_plates], key=lambda x: x[1])[1]
|
|
threshold_money *= max(min(10 - limit_up_codes_count + 3, 10), 5)/10
|
|
# print(target_code, sv.自由流通市值, threshold_money, limit_up_codes_count)
|
|
|
# threshold_money = 200e4 # int(sv.昨日成交量 * 0.2 * sv.今日涨停价 * 0.05)
|
if big_order_money < threshold_money:
|
return False, f"({big_order_money}/{threshold_money})大单金额不足"
|
|
return True, f" \n\t大单信息:{big_order_money}/{threshold_money}\n\t量够信息:{sv.今日量够信息}\n\t今日最高价:{sv.今日最高价信息} \n\t5日最高价:{sv.日最高价_5}", f"\n\t板块信息:{[(p, sv.开盘啦最正板块涨停.get(p)) for p in can_buy_plates]}", can_buy_plates
|
|
|
compute_result = can_buy()
|