Created
August 30, 2018 19:40
-
-
Save slapglif/1b808f0ccb181f4998fdf98f93ef61a7 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
import email, imaplib | |
import random | |
import datetime, time | |
import logging | |
import json | |
import threading | |
SIGNALS = range(4) | |
with open('config.json') as json_data_file: | |
config = json.load(json_data_file) | |
volume = config['volume'] | |
debug = config['debug'] | |
LOG_FILENAME = config['LOG_FILENAME'] | |
STOPLOSS = config['STOPLOSS'] | |
TAKEPROFIT = config['TAKEPROFIT'] | |
token = config['token'] | |
imap = config['imap'] | |
user = config['user'] | |
pwd = config['pwd'] | |
folder = config['folder'] | |
def readmail(): | |
print("Listening to email...") | |
while True: | |
time.sleep(1.5) | |
m = imaplib.IMAP4_SSL(imap) | |
m.login(user, pwd) | |
m.select('"' + folder + '"') | |
resp, items = m.search(None, | |
"NOT SEEN SUBJECT 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') | |
direction = mail['Subject'].split()[3] | |
pair = mail['Subject'].split()[2] | |
for x in bots: | |
bot = x | |
for x in updates: | |
update = x | |
try: | |
if "Close" not in direction: | |
m.store(emailid, '+FLAGS', '\Seen') | |
log(st + ' ' + direction + ' Triggered on ' + pair) | |
tele(direction, pair, bot, update) | |
# Close Trade | |
else: | |
direction = mail['Subject'].split()[4] | |
m.store(emailid, '+FLAGS', '\Seen') | |
tele(direction, pair, bot, update) | |
log(st + " Closed trade on " + pair) | |
except Exception as e: | |
log(e) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment