Skip to content

Commit

Permalink
update statistics by adding name, price and changesPercentage
Browse files Browse the repository at this point in the history
  • Loading branch information
MuslemRahimi committed Jul 28, 2024
1 parent 6577085 commit 52d710f
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion app/cron_reddit_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,18 +140,36 @@ def compute_trending_tickers(daily_stats):
'count': counts['total'],
'put': counts['PUT'],
'call': counts['CALL'],
'avgSentiment': sum(counts['sentiment']) / len(counts['sentiment']) if counts['sentiment'] else 0
'avgSentiment': round(sum(counts['sentiment']) / len(counts['sentiment']),2) if counts['sentiment'] else 0
}
for symbol, counts in trending.items()
]
trending_list.sort(key=lambda x: x['count'], reverse=True)

for item in trending_list:
symbol = item['symbol']
try:
with open(f'json/quote/{symbol}.json') as f:
data = json.load(f)
name = data['name']
price = round(data['price'],2)
changes_percentage = round(data['changesPercentage'],2)
except Exception as e:
print(e)
name = None
price = None
changes_percentage = None

if symbol in stock_symbols:
item['assetType'] = 'stocks'
item['name'] = name
item['price'] = price
item['changesPercentage'] = changes_percentage
elif symbol in etf_symbols:
item['assetType'] = 'etf'
item['name'] = name
item['price'] = price
item['changesPercentage'] = changes_percentage
else:
item['assetType'] = ''

Expand Down

0 comments on commit 52d710f

Please sign in to comment.