update dashboard
This commit is contained in:
parent
8a8d2ce5b8
commit
2559795c7b
@ -371,6 +371,36 @@ async def get_analyst_report():
|
|||||||
print(f"An error occurred: {e}")
|
print(f"An error occurred: {e}")
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
|
async def get_latest_wiim():
|
||||||
|
url = "https://api.benzinga.com/api/v2/news"
|
||||||
|
querystring = {"token": benzinga_api_key,"dateFrom":yesterday,"dateTo":today,"sort":"created:desc", "pageSize": 1000, "channels":"WIIM"}
|
||||||
|
res_list = []
|
||||||
|
|
||||||
|
async with aiohttp.ClientSession() as session:
|
||||||
|
|
||||||
|
async with session.get(url, params=querystring, headers=headers) as response:
|
||||||
|
data = ujson.loads(await response.text())
|
||||||
|
|
||||||
|
for item in data:
|
||||||
|
try:
|
||||||
|
if len(item['stocks']) == 1:
|
||||||
|
item['ticker'] = item['stocks'][0].get('name',None)
|
||||||
|
|
||||||
|
with open(f"/home/mrahimi/stocknear/backend/app/json/quote/{item['ticker']}.json","r") as file:
|
||||||
|
quote_data = ujson.load(file)
|
||||||
|
item['marketCap'] = quote_data.get('marketCap',None)
|
||||||
|
|
||||||
|
res_list.append({'date': item['created'], 'text': item['title'], 'marketCap': item['marketCap'],'ticker': item['ticker']})
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
res_list = sorted(
|
||||||
|
res_list,
|
||||||
|
key=lambda item: (item['marketCap'], datetime.strptime(item['date'], '%a, %d %b %Y %H:%M:%S %z')),
|
||||||
|
reverse=True
|
||||||
|
)
|
||||||
|
|
||||||
|
return res_list[:10]
|
||||||
|
|
||||||
async def run():
|
async def run():
|
||||||
async with aiohttp.ClientSession() as session:
|
async with aiohttp.ClientSession() as session:
|
||||||
recent_earnings = await get_recent_earnings(session)
|
recent_earnings = await get_recent_earnings(session)
|
||||||
@ -390,6 +420,8 @@ async def run():
|
|||||||
|
|
||||||
recent_analyst_report = await get_analyst_report()
|
recent_analyst_report = await get_analyst_report()
|
||||||
|
|
||||||
|
recent_wiim = await get_latest_wiim()
|
||||||
|
|
||||||
upcoming_earnings = [
|
upcoming_earnings = [
|
||||||
item for item in upcoming_earnings
|
item for item in upcoming_earnings
|
||||||
if item['symbol'] not in [earning['symbol'] for earning in recent_earnings]
|
if item['symbol'] not in [earning['symbol'] for earning in recent_earnings]
|
||||||
@ -411,7 +443,6 @@ async def run():
|
|||||||
'ivRank': highest_iv_rank,
|
'ivRank': highest_iv_rank,
|
||||||
'openInterest': highest_open_interest_change
|
'openInterest': highest_open_interest_change
|
||||||
}
|
}
|
||||||
print(optionsData)
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
optionsData = {}
|
optionsData = {}
|
||||||
@ -477,6 +508,7 @@ async def run():
|
|||||||
'recentEarnings': recent_earnings,
|
'recentEarnings': recent_earnings,
|
||||||
'upcomingEarnings': upcoming_earnings,
|
'upcomingEarnings': upcoming_earnings,
|
||||||
'analystReport': recent_analyst_report,
|
'analystReport': recent_analyst_report,
|
||||||
|
'wiim': recent_wiim,
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(data) > 0:
|
if len(data) > 0:
|
||||||
|
|||||||
130
app/test.py
130
app/test.py
@ -1,69 +1,77 @@
|
|||||||
import plotly.graph_objects as go
|
import aiohttp
|
||||||
|
import aiofiles
|
||||||
|
import ujson
|
||||||
|
import sqlite3
|
||||||
|
import pandas as pd
|
||||||
|
import asyncio
|
||||||
|
import pytz
|
||||||
|
import time
|
||||||
|
import os
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
from datetime import datetime, timedelta
|
||||||
|
from tqdm import tqdm
|
||||||
|
import pytz
|
||||||
|
|
||||||
# Data for the semiconductor stocks
|
|
||||||
data = {
|
|
||||||
'labels': ['Semiconductors', 'NVDA', 'AVGO', 'AMD', 'TXN', 'QCOM', 'ADI', 'INTC', 'MU', 'NXPI', 'MPWR'],
|
|
||||||
'parents': ['', 'Semiconductors', 'Semiconductors', 'Semiconductors', 'Semiconductors',
|
|
||||||
'Semiconductors', 'Semiconductors', 'Semiconductors', 'Semiconductors',
|
|
||||||
'Semiconductors', 'Semiconductors'],
|
|
||||||
'values': [100, 40, 15, 10, 8, 7, 6, 5, 4, 3, 2], # Approximate sizes
|
|
||||||
'performance': [0, -0.02, 0.29, -4.31, -0.29, -0.9, 2.12, -0.65, -2.45, -1.55, -1.9]
|
|
||||||
}
|
|
||||||
|
|
||||||
# Function to determine color based on performance with updated colors
|
date_format = "%a, %d %b %Y %H:%M:%S %z"
|
||||||
def get_color(perf):
|
|
||||||
if perf > 0:
|
|
||||||
return f'rgb(75, 192, 75)' # Brighter green
|
|
||||||
elif perf < 0:
|
|
||||||
return f'rgb(255, 82, 82)' # Brighter red
|
|
||||||
else:
|
|
||||||
return f'rgb(128, 128, 128)' # Gray for neutral
|
|
||||||
|
|
||||||
# Create color list
|
load_dotenv()
|
||||||
colors = [get_color(perf) for perf in data['performance']]
|
api_key = os.getenv('BENZINGA_API_KEY')
|
||||||
|
|
||||||
# Create text labels with performance
|
headers = {"accept": "application/json"}
|
||||||
text = [f"{label}<br>{perf}%" if i > 0 else ""
|
|
||||||
for i, (label, perf) in enumerate(zip(data['labels'], data['performance']))]
|
|
||||||
|
|
||||||
# Create the treemap
|
async def get_latest_wiim(session):
|
||||||
fig = go.Figure(go.Treemap(
|
url = "https://api.benzinga.com/api/v2/news"
|
||||||
labels=data['labels'],
|
querystring = {"token": api_key,"dateFrom":"2025-01-16","dateTo":"2025-01-17","sort":"created:desc", "pageSize": 1000, "channels":"WIIM"}
|
||||||
parents=data['parents'],
|
|
||||||
values=data['values'],
|
|
||||||
text=text,
|
|
||||||
textinfo="label",
|
|
||||||
hovertext=text,
|
|
||||||
marker=dict(
|
|
||||||
colors=colors,
|
|
||||||
line=dict(width=2, color='white')
|
|
||||||
),
|
|
||||||
textfont=dict(
|
|
||||||
size=16,
|
|
||||||
color='white'
|
|
||||||
),
|
|
||||||
))
|
|
||||||
|
|
||||||
# Update layout
|
try:
|
||||||
fig.update_layout(
|
async with session.get(url, params=querystring, headers=headers) as response:
|
||||||
title="Semiconductors",
|
res_list = []
|
||||||
width=800,
|
data = ujson.loads(await response.text())
|
||||||
height=500,
|
|
||||||
margin=dict(t=50, l=0, r=0, b=0),
|
|
||||||
paper_bgcolor='rgb(128, 128, 128)',
|
|
||||||
plot_bgcolor='rgb(128, 128, 128)',
|
|
||||||
showlegend=False,
|
|
||||||
)
|
|
||||||
|
|
||||||
# Configuration to remove interactivity
|
for item in data:
|
||||||
config = {
|
try:
|
||||||
'displayModeBar': False,
|
if len(item['stocks']) ==1:
|
||||||
'staticPlot': True, # Makes the plot completely static
|
item['ticker'] = item['stocks'][0].get('name',None)
|
||||||
'scrollZoom': False,
|
|
||||||
'doubleClick': False,
|
|
||||||
'showTips': False,
|
|
||||||
'responsive': False
|
|
||||||
}
|
|
||||||
|
|
||||||
# Save as HTML file
|
with open(f"json/quote/{item['ticker']}.json","r") as file:
|
||||||
fig.write_html("json/heatmap/data.html", config=config)
|
quote_data = ujson.load(file)
|
||||||
|
item['marketCap'] = quote_data.get('marketCap',None)
|
||||||
|
|
||||||
|
res_list.append({'date': item['created'], 'text': item['title'], 'marketCap': item['marketCap'],'ticker': item['ticker']})
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
res_list = sorted(
|
||||||
|
res_list,
|
||||||
|
key=lambda item: (item['marketCap'], datetime.strptime(item['date'], '%a, %d %b %Y %H:%M:%S %z')),
|
||||||
|
reverse=True
|
||||||
|
)
|
||||||
|
|
||||||
|
print(res_list[:10])
|
||||||
|
|
||||||
|
'''
|
||||||
|
for item in res:
|
||||||
|
for el in item['stocks']:
|
||||||
|
# Update the 'name' key to 'ticker'
|
||||||
|
if 'name' in el:
|
||||||
|
el['ticker'] = el.pop('name')
|
||||||
|
if el['ticker'] in stock_symbols:
|
||||||
|
el['assetType'] = 'stock'
|
||||||
|
elif el['ticker'] in etf_symbols:
|
||||||
|
el['assetType'] = 'etf'
|
||||||
|
res_list.append({'date': item['created'], 'text': item['title'], 'stocks': item['stocks']})
|
||||||
|
with open(f"json/wiim/rss-feed/data.json", 'w') as file:
|
||||||
|
ujson.dump(res_list, file)
|
||||||
|
'''
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
|
||||||
|
async def run():
|
||||||
|
async with aiohttp.ClientSession() as session:
|
||||||
|
await get_latest_wiim(session)
|
||||||
|
|
||||||
|
try:
|
||||||
|
asyncio.run(run())
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
Loading…
x
Reference in New Issue
Block a user