bugfixing
This commit is contained in:
parent
58d0791dc7
commit
225c8cb008
@ -146,7 +146,7 @@ headers = {
|
||||
"Authorization": api_key
|
||||
}
|
||||
|
||||
#total_symbols = ['AAPL']
|
||||
#total_symbols = ['NVDA']
|
||||
|
||||
counter = 0
|
||||
for symbol in tqdm(total_symbols):
|
||||
|
||||
46
app/main.py
46
app/main.py
@ -2564,32 +2564,40 @@ async def get_trending(api_key: str = Security(get_api_key)):
|
||||
headers={"Content-Encoding": "gzip"}
|
||||
)
|
||||
|
||||
@app.post("/heatmaps")
|
||||
async def get_trending(data: HeatMapData, api_key: str = Security(get_api_key)):
|
||||
index = data.index
|
||||
cache_key = f"get-heatmaps-{index}"
|
||||
@app.get("/heatmap")
|
||||
async def get_heatmap(api_key: str = Security(get_api_key)):
|
||||
cache_key = "heatmap"
|
||||
cached_result = redis_client.get(cache_key)
|
||||
|
||||
if cached_result:
|
||||
return StreamingResponse(
|
||||
io.BytesIO(cached_result),
|
||||
media_type="application/json",
|
||||
headers={"Content-Encoding": "gzip"})
|
||||
|
||||
io.BytesIO(cached_result),
|
||||
media_type="text/html",
|
||||
headers={"Content-Encoding": "gzip"}
|
||||
)
|
||||
|
||||
try:
|
||||
with open(f"json/heatmaps/{index}.json", 'rb') as file:
|
||||
res = orjson.loads(file.read())
|
||||
except:
|
||||
res = []
|
||||
|
||||
data = orjson.dumps(res)
|
||||
compressed_data = gzip.compress(data)
|
||||
with open("json/heatmap/data.html", 'r', encoding='utf-8') as file:
|
||||
html_content = file.read()
|
||||
except FileNotFoundError:
|
||||
raise HTTPException(status_code=404, detail="Heatmap file not found")
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=500, detail=f"Error reading heatmap file: {str(e)}")
|
||||
|
||||
# Compress the HTML content
|
||||
compressed_data = gzip.compress(html_content.encode('utf-8'))
|
||||
|
||||
# Cache the compressed HTML
|
||||
redis_client.set(cache_key, compressed_data)
|
||||
redis_client.expire(cache_key, 60*5) # Set cache expiration time to 5 min
|
||||
|
||||
redis_client.expire(cache_key, 60 * 5) # Set cache expiration time to 5 min
|
||||
|
||||
return StreamingResponse(
|
||||
io.BytesIO(compressed_data),
|
||||
media_type="application/json",
|
||||
headers={"Content-Encoding": "gzip"}
|
||||
media_type="text/html",
|
||||
headers={
|
||||
"Content-Encoding": "gzip",
|
||||
"Cache-Control": "public, max-age=300" # 5 minutes cache
|
||||
}
|
||||
)
|
||||
|
||||
@app.post("/pre-post-quote")
|
||||
|
||||
@ -95,11 +95,11 @@ def run_options_jobs():
|
||||
time.sleep(60)
|
||||
run_command(["python3", "cron_options_stats.py"])
|
||||
time.sleep(60)
|
||||
run_command(["python3", "cron_options_historical_volume.py"])
|
||||
time.sleep(60)
|
||||
run_command(["python3", "cron_options_hottest_contracts.py"])
|
||||
time.sleep(60)
|
||||
run_command(["python3", "cron_options_single_contract.py"])
|
||||
time.sleep(60)
|
||||
run_command(["python3", "cron_options_historical_volume.py"])
|
||||
|
||||
def run_fda_calendar():
|
||||
now = datetime.now(ny_tz)
|
||||
|
||||
75
app/test.py
75
app/test.py
@ -1,8 +1,69 @@
|
||||
import plotly.express as px
|
||||
fig = px.treemap(
|
||||
names = ["Eve","Cain", "Seth", "Enos", "Noam", "Abel", "Awan", "Enoch", "Azura"],
|
||||
parents = ["", "Eve", "Eve", "Seth", "Seth", "Eve", "Eve", "Awan", "Eve"]
|
||||
import plotly.graph_objects as go
|
||||
|
||||
# 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
|
||||
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
|
||||
colors = [get_color(perf) for perf in data['performance']]
|
||||
|
||||
# Create text labels with performance
|
||||
text = [f"{label}<br>{perf}%" if i > 0 else ""
|
||||
for i, (label, perf) in enumerate(zip(data['labels'], data['performance']))]
|
||||
|
||||
# Create the treemap
|
||||
fig = go.Figure(go.Treemap(
|
||||
labels=data['labels'],
|
||||
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
|
||||
fig.update_layout(
|
||||
title="Semiconductors",
|
||||
width=800,
|
||||
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,
|
||||
)
|
||||
fig.update_traces(root_color="lightgrey")
|
||||
fig.update_layout(margin = dict(t=50, l=25, r=25, b=25))
|
||||
fig.show()
|
||||
|
||||
# Configuration to remove interactivity
|
||||
config = {
|
||||
'displayModeBar': False,
|
||||
'staticPlot': True, # Makes the plot completely static
|
||||
'scrollZoom': False,
|
||||
'doubleClick': False,
|
||||
'showTips': False,
|
||||
'responsive': False
|
||||
}
|
||||
|
||||
# Save as HTML file
|
||||
fig.write_html("json/heatmap/data.html", config=config)
|
||||
Loading…
x
Reference in New Issue
Block a user