Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tweepy
- import sys, signal, json, time
- from bittrex import bittrex
- import datetime
- import urllib
- import urllib2
- import yagmail
- # Specify the account credentials in the following variables:
- consumer_key = ''
- consumer_secret = ''
- access_token = ''
- access_token_secret = ''
- gmail_user = ''
- gmail_password = ''
- target_user = 909009874498940928
- api = bittrex('KEY', 'SECRET')
- def sigint_handler(signum, frame):
- """Handler for ctrl+c"""
- print '\n[!] CTRL+C pressed. Exiting...'
- sys.exit(0)
- signal.signal(signal.SIGINT, sigint_handler)
- def SplitTweet(twt):
- file = open("logs.txt","a")
- coin =''
- rsi = 0
- first_letter = twt[:1]
- #if it's 5min RSI
- if '5' in first_letter:
- #before read line per line
- lines = twt.split('\n')
- #Read line per line
- for line in lines:
- btc_balance = api.getbalance("BTC")['Available']
- #Split to get $BTC and the rest
- split = line.split("-", 1)
- if '$BTC' in split[0]:
- #Split into all things
- split_coin = split[1].split("$", 1)
- #Only coin and RSI
- coin_et_rsi = split_coin[1]
- coin_et_rsi_split = coin_et_rsi.split(": ", 1)
- coin = coin_et_rsi_split[0]
- rsi_string = coin_et_rsi_split[1]
- rsi = float(rsi_string)
- open_order = api.getopenorders("BTC-" + coin)
- if coin != 'MTL' and coin != 'TRIG':
- if not open_order:
- market = "BTC-" + coin
- marketsummary = api.getmarketsummary(market)
- volume_str = marketsummary[0]['BaseVolume']
- volume = float(volume_str)
- if rsi< 24.1 and volume >=200:
- if btc_balance > 0.028:
- print '\n[+] {} has a RSI of {} '.format(coin, rsi)
- print 'BTC Balance {} BTC\n\n'.format(btc_balance)
- file.write(" %s %s RSI: %s " % (market, datetime.datetime.now(), rsi))
- pricecoin = api.getticker("BTC-" + coin)
- pricebuy = pricecoin['Last']
- pricesell = pricebuy + (0.036 * pricebuy)
- stoploss = pricebuy - (0.04 * pricebuy)
- subject = '%s RSI: %s' %(coin, rsi)
- body = '%s RSI is: %s\nPlaced a buy order at %s and sell order at %s\nYou should place a stop loss at %s\n' %(coin, rsi,pricebuy, pricesell, stoploss)
- yag = yagmail.SMTP(gmail_user, gmail_password)
- yag.send("zidanesignal@gmail.com", subject, body)
- else:
- print 'BTC balance < 0 : {}\n\n'.format(btc_balance)
- file.close()
- # This listener will print out all Tweets it receives
- class PrintListener(tweepy.StreamListener):
- def on_data(self, data):
- # Decode the JSON data
- tweet = json.loads(data)
- #Reading tweet
- twt = (tweet['text'].encode('ascii', 'ignore'))
- SplitTweet(twt)
- def on_error(self, status):
- print(status)
- if __name__ == '__main__':
- listener = PrintListener()
- # Show system message
- print('Waiting for tweets ...')
- # Authenticate
- auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
- auth.set_access_token(access_token, access_token_secret)
- # Connect the stream to our listener
- stream = tweepy.Stream(auth, listener)
- stream.filter(follow=[unicode(target_user)])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement