-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatus_helper.py
More file actions
52 lines (46 loc) Β· 1.77 KB
/
status_helper.py
File metadata and controls
52 lines (46 loc) Β· 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import streamlit as st
import requests
import time
def display_status_sidebar():
try:
api_key = st.secrets["POLYGON_API_KEY"]
except:
st.sidebar.markdown("### π‘ Data Status")
st.sidebar.markdown("π΄ **API Key Missing**")
return False
st.sidebar.markdown("### π‘ Data Status")
# Check API
try:
url = f"https://api.polygon.io/v2/aggs/ticker/SPY/prev?apiKey={api_key}"
response = requests.get(url, timeout=5)
if response.status_code == 200 and response.json().get('results'):
st.sidebar.markdown("π’ **API Connected**")
api_ok = True
else:
st.sidebar.markdown("π‘ **API Issue**")
api_ok = False
except:
st.sidebar.markdown("π΄ **API Disconnected**")
api_ok = False
# Check Options
try:
url = f"https://api.polygon.io/v3/snapshot/options/SPY?apiKey={api_key}"
response = requests.get(url, timeout=5)
if response.status_code == 200:
results = response.json().get('results', [])
if results and results[0].get('greeks', {}).get('implied_volatility'):
st.sidebar.markdown("π’ **Options + Greeks**")
st.sidebar.success("β
Paid Tier Active")
else:
st.sidebar.markdown("π‘ **Options Limited**")
st.sidebar.warning("β οΈ Free Tier")
else:
st.sidebar.markdown("π΄ **No Options**")
st.sidebar.error("β Upgrade Required")
except:
st.sidebar.markdown("π΄ **Options Error**")
st.sidebar.caption(f"Checked: {time.strftime('%H:%M:%S')}")
if st.sidebar.button("π Refresh"):
st.cache_data.clear()
st.rerun()
return api_ok