· 4 years ago · Jun 15, 2021, 04:24 AM
1# original script credit goes to https://www.reddit.com/r/algotrading/comments/n7xa2e/screener_for_finding_penny_stocks_about_to_blow/?utm_source=share&utm_medium=ios_app&utm_name=iossmf
2# modified with asyncio for much faster results (~30 seconds OLD vs ~3 seconds NEW)
3
4'''
5INSTRUCTIONS
6> pip install sentiment-investor, aiohttp
7sign up for an api key at https://sentimentinvestor.com/
8enter your token and key before running the script
9'''
10
11!pip install sentiment-investor
12!pip install aiohttp
13!pip install nest-asyncio
14
15import re
16import json
17import asyncio
18import nest_asyncio
19import aiohttp
20from sentipy.sentipy import Sentipy
21
22token = "XXXXXX"
23key = "XXXXXX"
24sentipy = Sentipy(token=token, key=key)
25metric = "RHI"
26limit = 96 # can be up to 96
27sorted_data = sentipy.sort(metric, limit)
28trending_stocks = sorted_data.sort
29
30urls = []
31results = []
32
33for stock in trending_stocks:
34 if stock.SGP > 1.05:
35 urls.append(f'https://query2.finance.yahoo.com/v10/finance/quoteSummary/{stock.ticker}?modules=defaultKeyStatistics')
36
37
38async def get(url):
39 try:
40 async with aiohttp.ClientSession() as session:
41 async with session.get(url=url) as response:
42 response = await response.read()
43 response = json.loads(response)
44 stock_cap = int(response['quoteSummary']['result'][0]['defaultKeyStatistics']['enterpriseValue']['raw'])
45 if 1000000000 > stock_cap > 1:
46 ticker = re.split('https://query2.finance.yahoo.com/v10/finance/quoteSummary/| ?modules=defaultKeyStatistics', url)[1][:-1]
47 results.append(ticker)
48 except:
49 pass
50
51async def main(urls):
52 await asyncio.gather(*[get(url) for url in urls])
53
54
55if __name__ == '__main__':
56 nest_asyncio.apply()
57 asyncio.run(main(urls))
58print(results)
59