Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tweepy
- import socket
- import requests
- import time
- from Authentication import authentication
- from pyredictit import *
- import json
- import datetime
- class TwitterStreamListener(tweepy.StreamListener):
- """ A listener handles tweets are the received from the stream.
- This is a basic listener that just prints received tweets to stdout.
- """
- def on_status(self, status):
- get_user_informations(status)
- def get_user_informations(tweet):
- if str(tweet.user.id) == 'twitter_id':
- tweet_count = tweet.user.statuses_count
- print("Apoc Tweet Count is ", tweet_count, " ", datetime.datetime.now())
- buytest()
- def connectToApi():
- auth = authentication()
- consumer_key = auth.getconsumer_key()
- consumer_secret = auth.getconsumer_secret()
- access_token = auth.getaccess_token()
- access_token_secret = auth.getaccess_token_secret()
- # Authentication
- auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
- auth.secure = True
- auth.set_access_token(access_token, access_token_secret)
- api = tweepy.API(auth, wait_on_rate_limit=True, wait_on_rate_limit_notify=True, retry_count=10, retry_delay=5,
- retry_errors=5)
- streamListener = TwitterStreamListener()
- myStream = tweepy.Stream(auth=api.auth, listener=streamListener)
- myStream.filter(follow=['Twitter_Id'], async=True)
- user = api.get_user('TwitterUserName')
- print("Initial Tweet Count is ", str(user.statuses_count), " at ", datetime.datetime.now())
- def buytest():
- pyt1 = pyredictit()
- pyt1.create_authed_session(username=' ',
- password=' ')
- short_sell_contracts = pyt1.search_for_contracts(market='politics', buy_sell='buy', type_='short')
- first_contract = short_sell_contracts[151]
- print(first_contract.market)
- print(first_contract.type_)
- first_contract.buy_shares(number_of_shares=100, api=pyt1, buy_price=first_contract.buy)
- def buytest_all():
- pyt1 = pyredictit()
- pyt1.create_authed_session(username=' ',
- password=' ')
- short_sell_contracts = pyt1.search_for_contracts(market='politics', buy_sell='buy', type_='short')
- first_contract = short_sell_contracts[150]
- print(first_contract.market)
- print(first_contract.type_)
- while True:
- pyt1.monitor_price_of_contract(contract=first_contract, monitor_type='buy_at',
- number_of_shares=1, trigger_price=0.70)
- sleep(30)
- if __name__ == '__main__':
- connectToApi()
- # Get access and key from another class
Add Comment
Please, Sign In to add comment