-
-
Save ptim/f9fd38f3ba13566123df516fcaf5178f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def readmail(volume): | |
time.sleep(1.5) | |
m = imaplib.IMAP4_SSL("imap.gmail.com") | |
m.login(user, pwd) | |
m.select('"[Gmail]/All Mail"') | |
resp, items = m.search(None, | |
"NOT SEEN FROM tradingview") | |
items = items[0].split() | |
for emailid in items: | |
resp, data = m.fetch(emailid, | |
"(RFC822)") | |
email_body = data[0][1] | |
mail = email.message_from_bytes(email_body) | |
ts = time.time() | |
st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S') | |
try: | |
pair = mail['Subject'].split()[2] | |
if mail['Subject'].split()[3] == "Buy": | |
m.store(emailid, '+FLAGS', '\Seen') | |
print(st + ' \x1b[6;30;42m' + 'Buy' + '\x1b[0m' + ' Triggered on ' + pair) | |
logging.info(st + ' Buy' + ' Triggered on ' + pair) | |
trade('0', volume, pair) | |
if mail['Subject'].split()[3] == "Sell": | |
m.store(emailid, '+FLAGS', '\Seen') | |
print(st + ' \x1b[6;30;41m' + 'Sell' + '\x1b[0m' + ' Triggered on ' + pair) | |
logging.info(st + ' Sell' + ' Triggered on ' + pair) | |
trade("1", volume, pair) | |
except Exception as e: | |
print(e) | |
logging.info(e) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment