Merge branch 'main' of http://localhost:3001/gyz/TurtleTrade
This commit is contained in:
commit
cd299b891a
32
EmailTest.py
32
EmailTest.py
@ -52,9 +52,37 @@ def get_latest_email_body(to_email):
|
||||
# print(f"Search Status: {status}")
|
||||
print(f"Matching Emails: {messages}")
|
||||
|
||||
for msgid, data in mail.fetch(messages, ['ENVELOPE']).items():
|
||||
for msgid, data in mail.fetch(messages, ['ENVELOPE', 'BODY[]']).items():
|
||||
envelope = data[b'ENVELOPE']
|
||||
print('ID #%d: "%s" received %s' % (msgid, envelope.subject.decode(), envelope.date))
|
||||
raw_email = data[b'BODY[]']
|
||||
|
||||
# 使用 email 库解析原始内容
|
||||
email_message = email.message_from_bytes(raw_email)
|
||||
|
||||
# 获取邮件正文(处理多部分的情况)
|
||||
body = ""
|
||||
if email_message.is_multipart():
|
||||
for part in email_message.walk():
|
||||
content_type = part.get_content_type()
|
||||
content_disposition = str(part.get("Content-Disposition"))
|
||||
if content_type == "text/plain" and "attachment" not in content_disposition:
|
||||
body = part.get_payload(decode=True).decode(part.get_content_charset() or 'utf-8')
|
||||
break
|
||||
else:
|
||||
body = email_message.get_payload(decode=True).decode(email_message.get_content_charset() or 'utf-8')
|
||||
|
||||
raw_subject = envelope.subject.decode()
|
||||
|
||||
# 然后 decode_header 接受 str 类型
|
||||
decoded_parts = decode_header(raw_subject)
|
||||
subject = ''.join(
|
||||
part.decode(encoding or 'utf-8') if isinstance(part, bytes) else part
|
||||
for part, encoding in decoded_parts
|
||||
)
|
||||
|
||||
print('ID #%d: "%s" received %s' % (msgid, subject, envelope.date))
|
||||
print('Body:', body)
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
@ -8,7 +8,19 @@ import mplfinance as mpf
|
||||
import sqlite3
|
||||
import stock_database
|
||||
import mysql_database
|
||||
from EmailTest import send_email
|
||||
from dataclasses import dataclass
|
||||
|
||||
@dataclass
|
||||
class BuyState:
|
||||
trigger_time: float
|
||||
buy_price: float
|
||||
add_price: float
|
||||
stop_price: float
|
||||
quantity: int
|
||||
n: int
|
||||
available_cash: float
|
||||
|
||||
def calc_sma_atr_pd(kdf,period):
|
||||
"""计算TR与ATR
|
||||
|
||||
@ -46,7 +58,7 @@ class TurtleTrading(object):
|
||||
self.Capital = Capital
|
||||
self.cash = cash
|
||||
self.TrigerTime = 0
|
||||
self.BuyStates = [[0, None, None, 0, 0, self.cash]]
|
||||
self.BuyStates = list[BuyState] = []
|
||||
|
||||
self.tradeslog = [] # 交易记录
|
||||
|
||||
@ -314,6 +326,15 @@ class TurtleTrading_OnTime(object):
|
||||
# mysql_database.insert_db(etf_data, "etf_price", True, "代码")
|
||||
return stock_data, etf_data
|
||||
|
||||
def Buy_stock(self, price_now):
|
||||
# 发送邮件 代码self.turtle.TradeCode, 建议买入价格price_now,买入份额self.turtle.IntPositionSize
|
||||
send_email()
|
||||
|
||||
# 每隔1分钟检测回信,解析邮件。
|
||||
|
||||
# 记录self.turtle.BuyStates
|
||||
pass
|
||||
|
||||
def Start_short_system(self):
|
||||
"""启动short系统
|
||||
"""
|
||||
@ -346,6 +367,7 @@ class TurtleTrading_OnTime(object):
|
||||
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):
|
||||
# 发出买入指令
|
||||
@ -397,6 +419,7 @@ class TurtleTrading_OnTime(object):
|
||||
pass
|
||||
|
||||
if __name__ == '__main__':
|
||||
user_email = "guoyize2209@163.com"
|
||||
t = TurtleTrading('513300', "etf", 0.25, 100000, 200000)
|
||||
# t.get_ready(100)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user