bugfixing
This commit is contained in:
parent
58d0791dc7
commit
225c8cb008
@ -146,7 +146,7 @@ headers = {
|
|||||||
"Authorization": api_key
|
"Authorization": api_key
|
||||||
}
|
}
|
||||||
|
|
||||||
#total_symbols = ['AAPL']
|
#total_symbols = ['NVDA']
|
||||||
|
|
||||||
counter = 0
|
counter = 0
|
||||||
for symbol in tqdm(total_symbols):
|
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"}
|
headers={"Content-Encoding": "gzip"}
|
||||||
)
|
)
|
||||||
|
|
||||||
@app.post("/heatmaps")
|
@app.get("/heatmap")
|
||||||
async def get_trending(data: HeatMapData, api_key: str = Security(get_api_key)):
|
async def get_heatmap(api_key: str = Security(get_api_key)):
|
||||||
index = data.index
|
cache_key = "heatmap"
|
||||||
cache_key = f"get-heatmaps-{index}"
|
|
||||||
cached_result = redis_client.get(cache_key)
|
cached_result = redis_client.get(cache_key)
|
||||||
|
|
||||||
if cached_result:
|
if cached_result:
|
||||||
return StreamingResponse(
|
return StreamingResponse(
|
||||||
io.BytesIO(cached_result),
|
io.BytesIO(cached_result),
|
||||||
media_type="application/json",
|
media_type="text/html",
|
||||||
headers={"Content-Encoding": "gzip"})
|
headers={"Content-Encoding": "gzip"}
|
||||||
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(f"json/heatmaps/{index}.json", 'rb') as file:
|
with open("json/heatmap/data.html", 'r', encoding='utf-8') as file:
|
||||||
res = orjson.loads(file.read())
|
html_content = file.read()
|
||||||
except:
|
except FileNotFoundError:
|
||||||
res = []
|
raise HTTPException(status_code=404, detail="Heatmap file not found")
|
||||||
|
except Exception as e:
|
||||||
data = orjson.dumps(res)
|
raise HTTPException(status_code=500, detail=f"Error reading heatmap file: {str(e)}")
|
||||||
compressed_data = gzip.compress(data)
|
|
||||||
|
# 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.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(
|
return StreamingResponse(
|
||||||
io.BytesIO(compressed_data),
|
io.BytesIO(compressed_data),
|
||||||
media_type="application/json",
|
media_type="text/html",
|
||||||
headers={"Content-Encoding": "gzip"}
|
headers={
|
||||||
|
"Content-Encoding": "gzip",
|
||||||
|
"Cache-Control": "public, max-age=300" # 5 minutes cache
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@app.post("/pre-post-quote")
|
@app.post("/pre-post-quote")
|
||||||
|
|||||||
@ -95,11 +95,11 @@ def run_options_jobs():
|
|||||||
time.sleep(60)
|
time.sleep(60)
|
||||||
run_command(["python3", "cron_options_stats.py"])
|
run_command(["python3", "cron_options_stats.py"])
|
||||||
time.sleep(60)
|
time.sleep(60)
|
||||||
run_command(["python3", "cron_options_historical_volume.py"])
|
|
||||||
time.sleep(60)
|
|
||||||
run_command(["python3", "cron_options_hottest_contracts.py"])
|
run_command(["python3", "cron_options_hottest_contracts.py"])
|
||||||
time.sleep(60)
|
time.sleep(60)
|
||||||
run_command(["python3", "cron_options_single_contract.py"])
|
run_command(["python3", "cron_options_single_contract.py"])
|
||||||
|
time.sleep(60)
|
||||||
|
run_command(["python3", "cron_options_historical_volume.py"])
|
||||||
|
|
||||||
def run_fda_calendar():
|
def run_fda_calendar():
|
||||||
now = datetime.now(ny_tz)
|
now = datetime.now(ny_tz)
|
||||||
|
|||||||
75
app/test.py
75
app/test.py
@ -1,8 +1,69 @@
|
|||||||
import plotly.express as px
|
import plotly.graph_objects as go
|
||||||
fig = px.treemap(
|
|
||||||
names = ["Eve","Cain", "Seth", "Enos", "Noam", "Abel", "Awan", "Enoch", "Azura"],
|
# Data for the semiconductor stocks
|
||||||
parents = ["", "Eve", "Eve", "Seth", "Seth", "Eve", "Eve", "Awan", "Eve"]
|
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))
|
# Configuration to remove interactivity
|
||||||
fig.show()
|
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