def process_fill_event(self, fill_event):
"""Extension of abstract base class method. The extension implements the
capability to send email notifications when fill events are received.
"""
# Call super class method to handle the fill event.
super(InteractiveBrokersPortfolio, self).process_fill_event(fill_event)
# Send an email notification containing the details of the fill event.
#
# TODO: Would it be better to make server an instance variable so that we
# don't have to recreate it every time there's a fill event?
if self.gmail_and_password is not None:
server = smtplib.SMTP("smtp.gmail.com", 587)
server.starttls()
server.login(*self.gmail_and_pass)
msg = MIMEText(str(fill_event), "plain", "utf-8")
msg["From"] = msg["To"] = self.gmail_and_pass[0]
msg["Subject"] = "Odin Trade Notification"
server.sendmail(
self.gmail_and_pass[0], self.gmail_and_pass[0], msg.as_string()
)
server.quit()
评论列表
文章目录