完善turtle监视
This commit is contained in:
parent
c9841014c1
commit
43a419a56f
@ -785,26 +785,70 @@ class TurtleTrading_OnTime(object):
|
|||||||
|
|
||||||
def monitor_single_turtle(self, turtle: TurtleTrading, stock_data, etf_data):
|
def monitor_single_turtle(self, turtle: TurtleTrading, stock_data, etf_data):
|
||||||
"""监控单个turtle的交易条件"""
|
"""监控单个turtle的交易条件"""
|
||||||
# 获取当前价格
|
|
||||||
if turtle.TradeCode in stock_data['代码'].values:
|
now = datetime.now().time()
|
||||||
price_now = stock_data[stock_data['代码'] == turtle.TradeCode]['最新价'].values[0]
|
if turtle.type == "stock":
|
||||||
elif turtle.TradeCode in etf_data['代码'].values:
|
turtle.PriceNow = float(stock_data.loc[etf_data['代码'] == self.turtle.TradeCode, '最新价'].values[0])
|
||||||
price_now = etf_data[etf_data['代码'] == turtle.TradeCode]['最新价'].values[0]
|
|
||||||
else:
|
elif turtle.type == "etf":
|
||||||
return # 未找到对应标的
|
# self.turtle.PriceNow = float(etf_data.loc[etf_data['基金代码'] == self.turtle.TradeCode, '当前-单位净值'].values[0])
|
||||||
|
turtle.PriceNow = float(etf_data.loc[etf_data['代码'] == self.turtle.TradeCode, '最新价'].values[0])
|
||||||
|
|
||||||
# 检查买入条件
|
if now.hour == 9 and now.minute == 30 and self.turtle.PriceNow > self.turtle.prev_heigh:
|
||||||
if self.system1EnterNormal(price_now, turtle.Donchian_20_ups, turtle.BreakOutLog):
|
turtle.is_gap_up = True
|
||||||
self.start_email_thread(turtle, "买入", price_now)
|
|
||||||
|
# 判断当前仓位状态并执行相应操作
|
||||||
# 检查加仓条件
|
if turtle.TrigerTime == 0:
|
||||||
if self.add(price_now):
|
if turtle.system1EnterNormal(
|
||||||
self.start_email_thread(turtle, "加仓", price_now)
|
turtle.PriceNow,
|
||||||
|
turtle.Donchian_20_up,
|
||||||
# 检查止损条件
|
turtle.BreakOutLog
|
||||||
if self.system_1_stop(price_now):
|
):
|
||||||
self.start_email_thread(turtle, "止损", price_now)
|
|
||||||
|
self.start_email_thread(turtle, "买入", turtle.PriceNow)
|
||||||
|
|
||||||
|
# 突破 记录self.turtle.breakoutlog
|
||||||
|
today = datetime.now().strftime("%Y-%m-%d")
|
||||||
|
breakout_this_time = BreakOutLog(today,
|
||||||
|
turtle.Donchian_20_up,
|
||||||
|
turtle.Donchian_20_up - 2 * turtle.N,
|
||||||
|
'valid',
|
||||||
|
None)
|
||||||
|
turtle.BreakOutLog.append(breakout_this_time)
|
||||||
|
|
||||||
|
elif turtle.system1EnterSafe(
|
||||||
|
turtle.PriceNow,
|
||||||
|
turtle.Donchian_50_up
|
||||||
|
):
|
||||||
|
self.start_email_thread(turtle, "买入", turtle.PriceNow)
|
||||||
|
|
||||||
|
elif 1 <= turtle.TrigerTime <= 3:
|
||||||
|
|
||||||
|
# 加仓状态
|
||||||
|
if turtle.add(turtle.PriceNow):
|
||||||
|
self.start_email_thread(turtle, "加仓", turtle.PriceNow)
|
||||||
|
|
||||||
|
# 止损状态
|
||||||
|
elif turtle.system_1_stop(turtle.PriceNow):
|
||||||
|
self.start_email_thread(turtle, "止损", turtle.PriceNow)
|
||||||
|
|
||||||
|
# 止盈
|
||||||
|
elif turtle.system_1_Out(
|
||||||
|
turtle.PriceNow,
|
||||||
|
turtle.Donchian_10_down
|
||||||
|
):
|
||||||
|
self.start_email_thread(turtle, "止盈", turtle.PriceNow)
|
||||||
|
|
||||||
|
elif turtle.TrigerTime == 4:
|
||||||
|
# 满仓 止损 止盈
|
||||||
|
if turtle.system_1_stop(turtle.PriceNow):
|
||||||
|
self.start_email_thread(turtle, "止损", turtle.PriceNow)
|
||||||
|
elif turtle.system_1_Out(
|
||||||
|
turtle.PriceNow,
|
||||||
|
turtle.Donchian_10_down
|
||||||
|
):
|
||||||
|
self.start_email_thread(turtle, "止盈", turtle.PriceNow)
|
||||||
|
|
||||||
def start_email_thread(self, turtle, action, price_now):
|
def start_email_thread(self, turtle, action, price_now):
|
||||||
"""启动邮件处理线程"""
|
"""启动邮件处理线程"""
|
||||||
event = threading.Event()
|
event = threading.Event()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user