11
This commit is contained in:
parent
e36c9baa0e
commit
1378b7f87b
79
EmailTest.py
Executable file
79
EmailTest.py
Executable file
@ -0,0 +1,79 @@
|
|||||||
|
import imaplib
|
||||||
|
import smtplib
|
||||||
|
import email
|
||||||
|
from email.header import decode_header
|
||||||
|
from email.mime.text import MIMEText
|
||||||
|
from imapclient import IMAPClient
|
||||||
|
from email.parser import Parser
|
||||||
|
|
||||||
|
def send_email(subject, body, to_email):
|
||||||
|
# 这个函数名为send_email,它接受三个参数:
|
||||||
|
# subject(邮件主题)、body(邮件内容)和to_email(收件人的电子邮件地址)。
|
||||||
|
from_email = 'yizeguo1@126.com'
|
||||||
|
|
||||||
|
mail_pass = 'CHRIZKWQSRWYLBOL'# 126授权码
|
||||||
|
# mail_pass = 'pwvzuqbiysqshgha'# qq授权码
|
||||||
|
|
||||||
|
msg = MIMEText(body)
|
||||||
|
msg['Subject'] = subject
|
||||||
|
msg['From'] = from_email
|
||||||
|
msg['To'] = to_email
|
||||||
|
|
||||||
|
server = smtplib.SMTP('smtp.126.com', 25)
|
||||||
|
# server = smtplib.SMTP('smtp.qq.com', 465)
|
||||||
|
server.starttls()
|
||||||
|
server.login(from_email, mail_pass)
|
||||||
|
server.sendmail(from_email, to_email, msg.as_string())
|
||||||
|
server.quit()
|
||||||
|
|
||||||
|
|
||||||
|
def get_latest_email_body(to_email):
|
||||||
|
# 连接到126邮箱的IMAP服务器
|
||||||
|
mail = IMAPClient("imap.126.com")
|
||||||
|
|
||||||
|
from_email = 'yizeguo1@126.com'
|
||||||
|
mail_pass = 'CHRIZKWQSRWYLBOL'# 126授权码
|
||||||
|
mail.login(from_email, mail_pass)
|
||||||
|
mail.id_({"name": "IMAPClient", "version": "2.1.0"})
|
||||||
|
|
||||||
|
# mail.list_folders()
|
||||||
|
print(mail.list_folders())
|
||||||
|
# 选择收件箱
|
||||||
|
# messages = mail.select_folder(folder="inbox", readonly=True)
|
||||||
|
mail.select_folder('INBOX')
|
||||||
|
# 搜索发件人为指定邮箱的所有邮件
|
||||||
|
encoded_email = to_email.encode('utf-8')
|
||||||
|
|
||||||
|
# 构建搜索条件:HEADER FROM "<发件人邮箱>"
|
||||||
|
search_criteria = f'FROM "{encoded_email.decode("utf-8")}"'
|
||||||
|
|
||||||
|
# 执行搜索操作
|
||||||
|
messages = mail.search(search_criteria)
|
||||||
|
# print(f"Search Status: {status}")
|
||||||
|
print(f"Matching Emails: {messages}")
|
||||||
|
|
||||||
|
response = mail.fetch(messages, ['FLAGS', 'RFC822.SIZE'])
|
||||||
|
|
||||||
|
# `response` is keyed by message id and contains parsed,
|
||||||
|
# converted response items.
|
||||||
|
for message_id, data in response.items():
|
||||||
|
print('{id}: {size} bytes, flags={flags}'.format(
|
||||||
|
id=message_id,
|
||||||
|
size=data[b'RFC822.SIZE'],
|
||||||
|
flags=data[b'FLAGS']))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
|
||||||
|
# send_email("测试", 'test', "guoyize2209@163.com")
|
||||||
|
# id_info = {
|
||||||
|
# 'name': 'myname',
|
||||||
|
# 'version': '1.0.0',
|
||||||
|
# 'vendor': 'myclient',
|
||||||
|
# 'support-email': 'yizeguo1@126.com'
|
||||||
|
# }
|
||||||
|
body = get_latest_email_body("guoyize2209@163.com")
|
||||||
|
# if body:
|
||||||
|
# print("Latest email body:", body)
|
||||||
|
# else:
|
||||||
|
# print("No plain text email found.")
|
@ -228,10 +228,10 @@ class TurtleTrading(object):
|
|||||||
|
|
||||||
def system1EnterNormal(self, PriceNow, TempDonchian20Upper, BreakOutLog):
|
def system1EnterNormal(self, PriceNow, TempDonchian20Upper, BreakOutLog):
|
||||||
# 没有持仓且价格向上突破---此时包含两种情形:1 对某标的首次使用系统,2 已发生过突破,此时上次突破天然是失败的
|
# 没有持仓且价格向上突破---此时包含两种情形:1 对某标的首次使用系统,2 已发生过突破,此时上次突破天然是失败的
|
||||||
if self.TrigerTime == 0 and PriceNow > TempDonchian20Upper[-1]:
|
if self.TrigerTime == 0 and PriceNow > TempDonchian20Upper:
|
||||||
# 买入
|
# 买入
|
||||||
return True
|
return True
|
||||||
elif self.TrigerTime != 0 and PriceNow > TempDonchian20Upper[-1]:
|
elif PriceNow > TempDonchian20Upper:#todo !=0不会满足条件 先跳过
|
||||||
self.system1BreakoutValid(PriceNow)
|
self.system1BreakoutValid(PriceNow)
|
||||||
if BreakOutLog[-1][5] == 'Lose': # TT!= 0且突破且上一次突破unseccessful
|
if BreakOutLog[-1][5] == 'Lose': # TT!= 0且突破且上一次突破unseccessful
|
||||||
return True
|
return True
|
||||||
@ -257,15 +257,32 @@ class TurtleTrading(object):
|
|||||||
self.BreakOutLog[-1][5] = 'None'
|
self.BreakOutLog[-1][5] = 'None'
|
||||||
# 一天结束,计算ATR,计算唐奇安通道,追加到已有的mysql数据库中
|
# 一天结束,计算ATR,计算唐奇安通道,追加到已有的mysql数据库中
|
||||||
|
|
||||||
def system1Out(self, PriceNow, TempDonchian10Lower):
|
def system_1_Out(self, PriceNow, TempDonchian10Lower):
|
||||||
# 退出:低于20日最低价(多头方向),空头以突破20日最高价为止损价格--有持仓且价格向下突破
|
# 退出:低于20日最低价(多头方向),空头以突破20日最高价为止损价格--有持仓且价格向下突破
|
||||||
if self.TrigerTime != 0 and PriceNow < TempDonchian10Lower[-1]:
|
if self.TrigerTime != 0 and PriceNow < TempDonchian10Lower:
|
||||||
# 退出
|
# 退出
|
||||||
return True
|
return True
|
||||||
|
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
def add(self, PriceNow):
|
||||||
|
"""加仓
|
||||||
|
"""
|
||||||
|
if self.TrigerTime < 4 and PriceNow > self.BuyStates[self.TrigerTime - 1][2]:#todo BuyStates是空的
|
||||||
|
# 买入
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
def system_1_stop(self, PriceNow):
|
||||||
|
"""止损判断:如果当前价格<上一次买入后的止损价格则止损
|
||||||
|
"""
|
||||||
|
if PriceNow < self.BuyStates[self.TrigerTime - 1][3]:
|
||||||
|
# 买入
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
def day_end(self):
|
def day_end(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -297,8 +314,8 @@ class TurtleTrading_OnTime(object):
|
|||||||
# mysql_database.insert_db(etf_data, "etf_price", True, "代码")
|
# mysql_database.insert_db(etf_data, "etf_price", True, "代码")
|
||||||
return stock_data, etf_data
|
return stock_data, etf_data
|
||||||
|
|
||||||
def Start_S1_system(self):
|
def Start_short_system(self):
|
||||||
"""启动S1系统
|
"""启动short系统
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# ------------------准备阶段--------------------
|
# ------------------准备阶段--------------------
|
||||||
@ -308,7 +325,7 @@ class TurtleTrading_OnTime(object):
|
|||||||
self.turtle.Donchian_20_up = self.turtle.CurrentData['Donchian_20_upper'].iloc[-1]
|
self.turtle.Donchian_20_up = self.turtle.CurrentData['Donchian_20_upper'].iloc[-1]
|
||||||
self.turtle.Donchian_50_up = self.turtle.CurrentData['Donchian_50_upper'].iloc[-1]
|
self.turtle.Donchian_50_up = self.turtle.CurrentData['Donchian_50_upper'].iloc[-1]
|
||||||
self.turtle.Donchian_10_down = self.turtle.CurrentData['Donchian_10_lower'].iloc[-1]
|
self.turtle.Donchian_10_down = self.turtle.CurrentData['Donchian_10_lower'].iloc[-1]
|
||||||
|
self.turtle.CalPositionSize()
|
||||||
# ------------------实时监测阶段--------------------
|
# ------------------实时监测阶段--------------------
|
||||||
# 9:00 1、判断是否是新的一周,是则重新计算Position Size
|
# 9:00 1、判断是否是新的一周,是则重新计算Position Size
|
||||||
# 判断是否是新的一周
|
# 判断是否是新的一周
|
||||||
@ -319,9 +336,62 @@ class TurtleTrading_OnTime(object):
|
|||||||
|
|
||||||
# 根据type,code, 取得实时价格self.turtle.PriceNow
|
# 根据type,code, 取得实时价格self.turtle.PriceNow
|
||||||
|
|
||||||
|
if self.turtle.Type == "stock":
|
||||||
|
self.turtle.PriceNow = stock_data[stock_data['代码'] == self.turtle.TradeCode]['最新价'].iloc[-1]
|
||||||
|
elif self.turtle.Type == "etf":
|
||||||
|
self.turtle.PriceNow = etf_data[etf_data['代码'] == self.turtle.TradeCode]['当前-单位净值'].iloc[-1]
|
||||||
|
|
||||||
|
# 空仓
|
||||||
|
if self.turtle.TrigerTime == 0:
|
||||||
|
if self.turtle.system1EnterNormal(self.turtle.PriceNow, self.turtle.Donchian_20_up, self.turtle.BreakOutLog):
|
||||||
|
|
||||||
|
# 发出买入指令
|
||||||
|
pass
|
||||||
|
elif self.turtle.system1EnterSafe(self.turtle.PriceNow, self.turtle.Donchian_50_up):
|
||||||
|
# 发出买入指令
|
||||||
|
pass
|
||||||
|
|
||||||
|
# 已有仓位,加仓 / 止损 / 退出
|
||||||
|
elif 1<=self.turtle.TrigerTime <= 3:
|
||||||
|
|
||||||
|
# ---------------------加仓---------------------
|
||||||
|
# 继续突破
|
||||||
|
if self.turtle.system1EnterNormal(self.turtle.PriceNow, self.turtle.Donchian_20_up, self.turtle.BreakOutLog):
|
||||||
|
# 发出买入指令
|
||||||
|
pass
|
||||||
|
#
|
||||||
|
elif self.turtle.system1EnterSafe(self.turtle.PriceNow, self.turtle.Donchian_50_up):
|
||||||
|
# 发出买入指令
|
||||||
|
pass
|
||||||
|
|
||||||
|
# 触发加仓价格
|
||||||
|
elif self.turtle.add(self.turtle.PriceNow):
|
||||||
|
# 发出买入指令
|
||||||
|
pass
|
||||||
|
|
||||||
|
# ---------------------止损-------------------
|
||||||
|
elif self.turtle.system_1_stop(self.turtle.PriceNow):
|
||||||
|
# 发出卖出指令
|
||||||
|
pass
|
||||||
|
|
||||||
|
# ---------------------止盈退出---------------------
|
||||||
|
elif self.turtle.system_1_Out(self.turtle.PriceNow, self.turtle.Donchian_10_down):
|
||||||
|
# 发出卖出指令
|
||||||
|
pass
|
||||||
|
|
||||||
|
# 满仓 止损 / 退出
|
||||||
|
elif self.turtle.TrigerTime == 4:
|
||||||
|
|
||||||
|
# ---------------------止损-------------------
|
||||||
|
if self.turtle.system_1_stop(self.turtle.PriceNow):
|
||||||
|
# 发出卖出指令
|
||||||
|
pass
|
||||||
|
|
||||||
|
# ---------------------止盈退出---------------------
|
||||||
|
elif self.turtle.system_1_Out(self.turtle.PriceNow, self.turtle.Donchian_10_down):
|
||||||
|
# 发出卖出指令
|
||||||
|
pass
|
||||||
|
|
||||||
# ------------------结束阶段--------------------
|
# ------------------结束阶段--------------------
|
||||||
# 数据库更新当天数据,增加ATR、donchian数据
|
# 数据库更新当天数据,增加ATR、donchian数据
|
||||||
pass
|
pass
|
||||||
|
Loading…
x
Reference in New Issue
Block a user