Advertisement
Guest User

Untitled

a guest
Jan 11th, 2018
466
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.13 KB | None | 0 0
  1. import tweepy
  2. import sys, signal, json, time
  3. from bittrex import bittrex
  4. import datetime
  5. import urllib
  6. import urllib2
  7. import yagmail
  8.  
  9.  
  10. # Specify the account credentials in the following variables:
  11. consumer_key = ''
  12. consumer_secret = ''
  13. access_token = ''
  14. access_token_secret = ''
  15. gmail_user = ''  
  16. gmail_password = ''
  17.  
  18.  
  19. target_user = 909009874498940928
  20. api = bittrex('KEY', 'SECRET')
  21.  
  22.  
  23.  
  24. def sigint_handler(signum, frame):
  25.     """Handler for ctrl+c"""
  26.     print '\n[!] CTRL+C pressed. Exiting...'
  27.     sys.exit(0)
  28.    
  29. signal.signal(signal.SIGINT, sigint_handler)
  30.  
  31.  
  32.    
  33.    
  34. def SplitTweet(twt):
  35.     file = open("logs.txt","a")
  36.     coin =''
  37.     rsi = 0
  38.     first_letter = twt[:1]
  39.     #if it's 5min RSI
  40.     if '5' in first_letter:
  41.         #before read line per line
  42.         lines = twt.split('\n')
  43.         #Read line per line
  44.         for line in lines:
  45.             btc_balance  = api.getbalance("BTC")['Available']
  46.             #Split to get $BTC and the rest
  47.             split = line.split("-", 1)
  48.             if '$BTC' in split[0]:
  49.                 #Split into all things
  50.                 split_coin = split[1].split("$", 1)
  51.                 #Only coin and RSI
  52.                 coin_et_rsi = split_coin[1]
  53.                 coin_et_rsi_split = coin_et_rsi.split(": ", 1)
  54.                 coin = coin_et_rsi_split[0]
  55.                 rsi_string = coin_et_rsi_split[1]
  56.                 rsi = float(rsi_string)
  57.                 open_order = api.getopenorders("BTC-" + coin)
  58.                 if coin != 'MTL' and coin != 'TRIG':
  59.                     if not open_order:
  60.                         market = "BTC-" + coin
  61.                         marketsummary = api.getmarketsummary(market)
  62.                         volume_str = marketsummary[0]['BaseVolume']
  63.                         volume = float(volume_str)
  64.                         if rsi< 24.1 and volume >=200:
  65.                             if btc_balance > 0.028:
  66.                                 print '\n[+] {} has a RSI of {} '.format(coin, rsi)
  67.                                 print 'BTC Balance {} BTC\n\n'.format(btc_balance)                         
  68.                                 file.write(" %s %s RSI: %s " % (market, datetime.datetime.now(), rsi))
  69.                                 pricecoin = api.getticker("BTC-" + coin)
  70.                                 pricebuy = pricecoin['Last']
  71.                                 pricesell = pricebuy + (0.036 * pricebuy)
  72.                                 stoploss = pricebuy - (0.04 * pricebuy)
  73.                                 subject = '%s RSI: %s' %(coin, rsi)  
  74.                                 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)
  75.                                 yag = yagmail.SMTP(gmail_user, gmail_password)
  76.                                 yag.send("zidanesignal@gmail.com", subject, body)
  77.                             else:
  78.                                 print 'BTC balance < 0 : {}\n\n'.format(btc_balance)
  79.     file.close()
  80.                    
  81.    
  82. # This listener will print out all Tweets it receives
  83. class PrintListener(tweepy.StreamListener):
  84.     def on_data(self, data):
  85.         # Decode the JSON data
  86.         tweet = json.loads(data)
  87.     #Reading tweet
  88.     twt = (tweet['text'].encode('ascii', 'ignore'))
  89.     SplitTweet(twt)
  90.  
  91.     def on_error(self, status):
  92.         print(status)
  93.  
  94.  
  95. if __name__ == '__main__':
  96.     listener = PrintListener()
  97.  
  98.     # Show system message
  99.     print('Waiting for tweets ...')
  100.  
  101.     # Authenticate
  102.     auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
  103.     auth.set_access_token(access_token, access_token_secret)
  104.  
  105.     # Connect the stream to our listener
  106.     stream = tweepy.Stream(auth, listener)
  107.     stream.filter(follow=[unicode(target_user)])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement