Update src/app.py
Browse files- src/app.py +375 -290
src/app.py
CHANGED
|
@@ -26,7 +26,6 @@ today_str = datetime.now().strftime("%Y-%m-%d")
|
|
| 26 |
# ============================================================
|
| 27 |
st.set_page_config(page_title="Invest Pro Alpha", layout="wide", initial_sidebar_state="collapsed")
|
| 28 |
|
| 29 |
-
# ββ λ€λΉκ²μ΄μ
λ° βββββββββββββββββββββββββββββββββββββββββββββ
|
| 30 |
NAV_CSS = """
|
| 31 |
div.element-container:has(.nav-marker) + div {
|
| 32 |
position: fixed !important; bottom: 0 !important; left: 0 !important;
|
|
@@ -67,7 +66,6 @@ div.element-container:has(.nav-marker) + div button:hover em,
|
|
| 67 |
div.element-container:has(.nav-marker) + div button:active em { color: #C9A84C !important; }
|
| 68 |
"""
|
| 69 |
|
| 70 |
-
# ββ ν¬νΈν΄λ¦¬μ€ ν (νΈμ§/μμ /μΌμ§ λ²νΌ) ββββββββββββββββββββββ
|
| 71 |
PORTFOLIO_ROW_CSS = """
|
| 72 |
div.element-container:has(.portfolio-item-row-marker) + div [data-testid="stColumns"],
|
| 73 |
div.element-container:has(.portfolio-item-row-marker) + div [data-testid="stHorizontalBlock"] {
|
|
@@ -89,7 +87,6 @@ div.element-container:has(.action-marker.edit) + div button:hover { color: #42
|
|
| 89 |
div.element-container:has(.action-marker.log) + div button:hover { color: #C9A84C !important; transform: scale(1.15) !important; }
|
| 90 |
"""
|
| 91 |
|
| 92 |
-
# ββ μ€μΊ μΉ΄λ & ν¬νΈν΄λ¦¬μ€ μμ½ μΉ΄λ βββββββββββββββββββββββββ
|
| 93 |
CARD_CSS = """
|
| 94 |
div.element-container:has(.scan-marker) + div.element-container button {
|
| 95 |
background: #0F1623 !important;
|
|
@@ -155,7 +152,6 @@ div.element-container:has(.port-marker) + div.element-container button strong {
|
|
| 155 |
}
|
| 156 |
"""
|
| 157 |
|
| 158 |
-
# ββ κ³΅ν΅ μ»΄ν¬λνΈ βββββββββββββββββββββββββββββββββββββββββββββ
|
| 159 |
COMPONENT_CSS = """
|
| 160 |
.menu-overlay-btn > button {
|
| 161 |
background: #0F1623 !important;
|
|
@@ -300,100 +296,6 @@ button[kind="primary"]:not([title]):hover {
|
|
| 300 |
0%, 100% { opacity: 1; }
|
| 301 |
50% { opacity: 0.65; }
|
| 302 |
}
|
| 303 |
-
|
| 304 |
-
/* ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 305 |
-
NEW: κ·Έλ£Ήν μλ ν¨λ CSS
|
| 306 |
-
ββββββββββββββββββββββββββββββββββββββββββββββββββββββ */
|
| 307 |
-
@keyframes alertSlideUp {
|
| 308 |
-
from { transform: translateY(20px); opacity: 0; }
|
| 309 |
-
to { transform: translateY(0); opacity: 1; }
|
| 310 |
-
}
|
| 311 |
-
@keyframes badgePop {
|
| 312 |
-
from { transform: scale(0.7); opacity: 0; }
|
| 313 |
-
to { transform: scale(1); opacity: 1; }
|
| 314 |
-
}
|
| 315 |
-
@keyframes alertPulseGlow {
|
| 316 |
-
0%, 100% { box-shadow: 0 0 0 0 rgba(255,107,53,0.0); }
|
| 317 |
-
50% { box-shadow: 0 0 12px 2px rgba(255,107,53,0.18); }
|
| 318 |
-
}
|
| 319 |
-
.alert-panel-wrap {
|
| 320 |
-
position: fixed;
|
| 321 |
-
bottom: 72px;
|
| 322 |
-
right: 14px;
|
| 323 |
-
width: min(96vw, 370px);
|
| 324 |
-
z-index: 99999;
|
| 325 |
-
animation: alertSlideUp 0.35s cubic-bezier(0.34,1.56,0.64,1);
|
| 326 |
-
font-family: 'Noto Sans KR', sans-serif;
|
| 327 |
-
}
|
| 328 |
-
.alert-panel-header {
|
| 329 |
-
background: linear-gradient(135deg,#1a2035 0%,#131820 100%);
|
| 330 |
-
border: 1px solid rgba(255,255,255,0.09);
|
| 331 |
-
border-bottom: none;
|
| 332 |
-
border-radius: 14px 14px 0 0;
|
| 333 |
-
padding: 12px 14px 0;
|
| 334 |
-
}
|
| 335 |
-
.alert-tabs-row {
|
| 336 |
-
display: flex; gap: 3px;
|
| 337 |
-
}
|
| 338 |
-
.alert-tab {
|
| 339 |
-
flex: 1;
|
| 340 |
-
background: transparent;
|
| 341 |
-
border: 1px solid transparent;
|
| 342 |
-
border-bottom: none;
|
| 343 |
-
border-radius: 8px 8px 0 0;
|
| 344 |
-
padding: 7px 3px;
|
| 345 |
-
cursor: pointer;
|
| 346 |
-
display: flex; flex-direction: column; align-items: center; gap: 2px;
|
| 347 |
-
transition: all 0.18s;
|
| 348 |
-
}
|
| 349 |
-
.alert-tab.active { background: rgba(255,255,255,0.06); border-color: rgba(255,255,255,0.1); }
|
| 350 |
-
.alert-tab-icon { font-size: 15px; }
|
| 351 |
-
.alert-tab-label { font-size: 9px; font-weight: 700; letter-spacing: 0.04em; }
|
| 352 |
-
.alert-tab-badge {
|
| 353 |
-
font-size: 9px; font-weight: 700; min-width: 16px; height: 16px;
|
| 354 |
-
border-radius: 8px; display: flex; align-items: center; justify-content: center;
|
| 355 |
-
padding: 0 4px;
|
| 356 |
-
}
|
| 357 |
-
.alert-panel-body {
|
| 358 |
-
background: linear-gradient(180deg,#161c2a 0%,#111620 100%);
|
| 359 |
-
border: 1px solid rgba(255,255,255,0.09);
|
| 360 |
-
border-radius: 0 0 14px 14px;
|
| 361 |
-
max-height: 260px;
|
| 362 |
-
overflow-y: auto;
|
| 363 |
-
padding: 6px;
|
| 364 |
-
}
|
| 365 |
-
.alert-item {
|
| 366 |
-
display: flex; align-items: center; gap: 10px;
|
| 367 |
-
padding: 9px 11px;
|
| 368 |
-
border-radius: 9px;
|
| 369 |
-
cursor: pointer;
|
| 370 |
-
border: 1px solid transparent;
|
| 371 |
-
margin-bottom: 3px;
|
| 372 |
-
transition: all 0.15s;
|
| 373 |
-
text-decoration: none;
|
| 374 |
-
}
|
| 375 |
-
.alert-item:hover { background: rgba(255,255,255,0.05) !important; }
|
| 376 |
-
.alert-ticker-box {
|
| 377 |
-
width: 38px; height: 38px; border-radius: 9px;
|
| 378 |
-
display: flex; align-items: center; justify-content: center;
|
| 379 |
-
flex-shrink: 0; font-size: 9px; font-weight: 800; letter-spacing: -0.03em;
|
| 380 |
-
}
|
| 381 |
-
.alert-badge-minimized {
|
| 382 |
-
position: fixed;
|
| 383 |
-
bottom: 72px; right: 14px;
|
| 384 |
-
display: flex; align-items: center; gap: 8px;
|
| 385 |
-
background: linear-gradient(135deg,#1a2035,#131820);
|
| 386 |
-
border: 1px solid rgba(255,107,53,0.4);
|
| 387 |
-
border-radius: 40px; padding: 9px 18px;
|
| 388 |
-
cursor: pointer; z-index: 99999;
|
| 389 |
-
box-shadow: 0 6px 24px rgba(0,0,0,0.5);
|
| 390 |
-
animation: badgePop 0.35s cubic-bezier(0.34,1.56,0.64,1), alertPulseGlow 2s ease-in-out infinite;
|
| 391 |
-
font-family: 'Noto Sans KR', sans-serif;
|
| 392 |
-
user-select: none;
|
| 393 |
-
}
|
| 394 |
-
.alert-panel-wrap { width: min(92vw,340px); bottom: 68px; }
|
| 395 |
-
.alert-badge-minimized { bottom: 68px; }
|
| 396 |
-
}
|
| 397 |
"""
|
| 398 |
|
| 399 |
def load_css():
|
|
@@ -522,6 +424,24 @@ def load_css():
|
|
| 522 |
color: #EEF2F7 !important;
|
| 523 |
}}
|
| 524 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 525 |
{NAV_CSS}
|
| 526 |
{PORTFOLIO_ROW_CSS}
|
| 527 |
{CARD_CSS}
|
|
@@ -539,10 +459,9 @@ if 'api_key' not in st.session_state:
|
|
| 539 |
if 'show_menu' not in st.session_state: st.session_state.show_menu = False
|
| 540 |
if 'main_menu' not in st.session_state: st.session_state.main_menu = "β ν & μ€μΊ"
|
| 541 |
|
| 542 |
-
# ββ μλ ν¨λ μΈμ
μ€ν
μ΄νΈ μ΄κΈ°ν ββββββββββββββββββββββββββ
|
| 543 |
if 'alert_panel_minimized' not in st.session_state: st.session_state.alert_panel_minimized = False
|
| 544 |
if 'alert_panel_start_time' not in st.session_state: st.session_state.alert_panel_start_time = time.time()
|
| 545 |
-
if 'alert_active_tab' not in st.session_state: st.session_state.alert_active_tab = None
|
| 546 |
|
| 547 |
def _key_hash():
|
| 548 |
return hashlib.sha256(st.session_state.api_key.encode()).hexdigest()[:16]
|
|
@@ -1152,15 +1071,10 @@ def render_trade_analytics(tdf):
|
|
| 1152 |
)
|
| 1153 |
|
| 1154 |
# ============================================================
|
| 1155 |
-
# 8.
|
| 1156 |
# ============================================================
|
| 1157 |
|
| 1158 |
def _build_alert_groups(prices, rate):
|
| 1159 |
-
"""
|
| 1160 |
-
보μ μ’
λͺ©μ μννλ©° 4κ° μΉ΄ν
κ³ λ¦¬λ‘ λΆλ₯.
|
| 1161 |
-
λ°ν: { "κΈλ³": [...], "λ§€μ": [...], "μ΅μ ": [...], "μ€ν±λ‘μ€": [...] }
|
| 1162 |
-
κ° νλͺ©: { ticker, name, change_pct, current_price, target_price, action }
|
| 1163 |
-
"""
|
| 1164 |
groups = {"κΈλ³": [], "λ§€μ": [], "μ΅μ ": [], "μ€ν±λ‘μ€": []}
|
| 1165 |
if st.session_state.df.empty:
|
| 1166 |
return groups
|
|
@@ -1182,12 +1096,10 @@ def _build_alert_groups(prices, rate):
|
|
| 1182 |
current_price=int(ck), avg_price=int(ap),
|
| 1183 |
target_price=tgp, action=act)
|
| 1184 |
|
| 1185 |
-
# κΈλ³: Β±15% μ΄μ (λΆμ μ¬λΆ 무κ΄)
|
| 1186 |
if abs(pct) >= 15:
|
| 1187 |
groups["κΈλ³"].append(item)
|
| 1188 |
continue
|
| 1189 |
|
| 1190 |
-
# λΆμλ μ’
λͺ©λ§ λλ¨Έμ§ λΆλ₯
|
| 1191 |
if not act:
|
| 1192 |
continue
|
| 1193 |
|
|
@@ -1201,23 +1113,21 @@ def _build_alert_groups(prices, rate):
|
|
| 1201 |
return groups
|
| 1202 |
|
| 1203 |
|
| 1204 |
-
def _navigate_to_ticker(ticker
|
| 1205 |
-
"""μλ ν¨λμμ μ’
λͺ© ν΄λ¦ μ λΆμ νλ©΄μΌλ‘ μ΄λ"""
|
| 1206 |
-
# 보μ μ’
λͺ©μ΄λ©΄ μμ° μμΈ μ§λ¨μΌλ‘, μλλ©΄ ν μ€μΊμΌλ‘
|
| 1207 |
in_portfolio = ticker in st.session_state.df['ν°μ»€'].values if not st.session_state.df.empty else False
|
| 1208 |
if in_portfolio:
|
| 1209 |
st.session_state.detail_ticker = ticker
|
| 1210 |
st.session_state.main_menu = "β€ μμ° μμΈ μ§λ¨"
|
| 1211 |
st.session_state.p_diag_mode = False
|
|
|
|
| 1212 |
else:
|
| 1213 |
st.session_state.active_ticker = ticker
|
| 1214 |
st.session_state.main_menu = "β ν & μ€μΊ"
|
| 1215 |
st.session_state.p_diag_mode = False
|
| 1216 |
-
|
| 1217 |
|
| 1218 |
|
| 1219 |
def render_grouped_alert_panel(prices, rate):
|
| 1220 |
-
"""μ°νλ¨ νλ‘ν
μλ ν¨λ β components.html + CSS fixed overlay"""
|
| 1221 |
groups = _build_alert_groups(prices, rate)
|
| 1222 |
total_cnt = sum(len(v) for v in groups.values())
|
| 1223 |
if total_cnt == 0:
|
|
@@ -1241,11 +1151,13 @@ def render_grouped_alert_panel(prices, rate):
|
|
| 1241 |
|
| 1242 |
if st.session_state.alert_active_tab not in TAB_CFG:
|
| 1243 |
for pt in ["μ€ν±λ‘μ€", "κΈλ³", "μ΅μ ", "λ§€μ"]:
|
| 1244 |
-
if groups[pt]:
|
| 1245 |
-
|
|
|
|
|
|
|
|
|
|
| 1246 |
active_tab = st.session_state.alert_active_tab
|
| 1247 |
|
| 1248 |
-
# μ’
λͺ© λ°μ΄ν° JSON μ§λ ¬ν
|
| 1249 |
data = {}
|
| 1250 |
for tab, tc in TAB_CFG.items():
|
| 1251 |
rows = []
|
|
@@ -1259,195 +1171,370 @@ def render_grouped_alert_panel(prices, rate):
|
|
| 1259 |
})
|
| 1260 |
data[tab] = rows
|
| 1261 |
|
| 1262 |
-
tab_json = json.dumps(
|
| 1263 |
-
|
| 1264 |
-
|
|
|
|
|
|
|
| 1265 |
data_json = json.dumps(data, ensure_ascii=False)
|
| 1266 |
timer_col = "#E53E3E" if time_left <= 15 else ("#EAB308" if time_left <= 30 else "#8B98B4")
|
| 1267 |
|
| 1268 |
-
|
| 1269 |
-
|
| 1270 |
-
|
| 1271 |
-
|
| 1272 |
-
position: fixed !important;
|
| 1273 |
-
top: 0 !important; left: 0 !important;
|
| 1274 |
-
width: 100vw !important; height: 100vh !important;
|
| 1275 |
-
border: none !important; z-index: 2147483640 !important;
|
| 1276 |
-
background: transparent !important; pointer-events: none !important;
|
| 1277 |
-
}
|
| 1278 |
-
div:has(> iframe[title="components.v1.html"]) {
|
| 1279 |
-
height: 0 !important; overflow: visible !important;
|
| 1280 |
-
}
|
| 1281 |
-
</style>""", unsafe_allow_html=True)
|
| 1282 |
-
|
| 1283 |
-
B = badge_col
|
| 1284 |
-
T = str(time_left)
|
| 1285 |
-
N = str(total_cnt)
|
| 1286 |
-
TC = timer_col
|
| 1287 |
-
DMIN = "flex" if minimized else "none"
|
| 1288 |
-
DPAN = "none" if minimized else "block"
|
| 1289 |
IMIN = "true" if minimized else "false"
|
| 1290 |
ITAB = json.dumps(active_tab, ensure_ascii=False)
|
|
|
|
|
|
|
|
|
|
| 1291 |
|
| 1292 |
-
|
| 1293 |
-
<html>
|
| 1294 |
-
<
|
|
|
|
|
|
|
| 1295 |
<style>
|
| 1296 |
-
*{margin:0;padding:0;box-sizing:border-box;
|
| 1297 |
-
html,body{
|
| 1298 |
-
|
| 1299 |
-
|
| 1300 |
-
|
| 1301 |
-
|
| 1302 |
-
|
| 1303 |
-
|
| 1304 |
-
|
| 1305 |
-
|
| 1306 |
-
|
| 1307 |
-
|
| 1308 |
-
|
| 1309 |
-
|
| 1310 |
-
|
| 1311 |
-
|
| 1312 |
-
|
| 1313 |
-
|
| 1314 |
-
|
| 1315 |
-
|
| 1316 |
-
|
| 1317 |
-
|
| 1318 |
-
|
| 1319 |
-
|
| 1320 |
-
|
| 1321 |
-
|
| 1322 |
-
|
| 1323 |
-
|
| 1324 |
-
|
| 1325 |
-
|
| 1326 |
-
|
| 1327 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1328 |
|
| 1329 |
-
<
|
| 1330 |
-
<div style=
|
| 1331 |
-
<div
|
| 1332 |
-
<div
|
| 1333 |
-
<div style=
|
| 1334 |
-
|
| 1335 |
-
|
| 1336 |
-
|
| 1337 |
-
|
| 1338 |
-
<div style=
|
| 1339 |
-
<
|
| 1340 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1341 |
</div>
|
| 1342 |
-
<button class='min-btn' onclick='minimize()' style='background:transparent;border:1px solid rgba(255,255,255,.1);border-radius:6px;color:rgba(255,255,255,.35);font-size:15px;padding:3px 8px;cursor:pointer;line-height:1'>−</button>
|
| 1343 |
</div>
|
|
|
|
| 1344 |
</div>
|
| 1345 |
-
<div
|
| 1346 |
</div>
|
| 1347 |
-
|
| 1348 |
-
<button class='min-btn' onclick='minimize()' style='width:100%%%%;margin-top:4px;padding:6px;background:rgba(255,255,255,.04);border:1px solid rgba(255,255,255,.08);border-radius:9px;color:rgba(255,255,255,.35);font-size:11px;cursor:pointer;font-family:Noto Sans KR,sans-serif'>− μ΅μν</button>
|
| 1349 |
</div>
|
| 1350 |
|
| 1351 |
<script>
|
| 1352 |
-
var
|
| 1353 |
-
var
|
| 1354 |
-
var
|
| 1355 |
-
var
|
| 1356 |
-
|
| 1357 |
-
|
| 1358 |
-
|
| 1359 |
-
|
| 1360 |
-
var
|
| 1361 |
-
|
| 1362 |
-
|
| 1363 |
-
|
| 1364 |
-
|
| 1365 |
-
|
| 1366 |
-
|
| 1367 |
-
|
| 1368 |
-
|
| 1369 |
-
|
| 1370 |
-
|
| 1371 |
-
|
| 1372 |
-
|
| 1373 |
-
|
| 1374 |
-
|
| 1375 |
-
|
| 1376 |
-
|
| 1377 |
-
|
| 1378 |
-
|
| 1379 |
-
}
|
| 1380 |
-
|
| 1381 |
-
|
| 1382 |
-
|
| 1383 |
-
|
| 1384 |
-
|
| 1385 |
-
|
| 1386 |
-
el.
|
| 1387 |
-
|
| 1388 |
-
|
| 1389 |
-
|
| 1390 |
-
|
| 1391 |
-
|
| 1392 |
-
|
| 1393 |
-
|
| 1394 |
-
|
| 1395 |
-
|
| 1396 |
-
|
| 1397 |
-
|
| 1398 |
-
|
| 1399 |
-
|
| 1400 |
-
|
| 1401 |
-
|
| 1402 |
-
|
| 1403 |
-
|
| 1404 |
-
|
| 1405 |
-
|
| 1406 |
-
|
| 1407 |
-
|
| 1408 |
-
|
| 1409 |
-
|
| 1410 |
-
|
| 1411 |
-
|
| 1412 |
-
|
| 1413 |
-
|
| 1414 |
-
|
| 1415 |
-
|
| 1416 |
-
|
| 1417 |
-
|
| 1418 |
-
|
| 1419 |
-
|
| 1420 |
-
|
| 1421 |
-
|
| 1422 |
-
|
| 1423 |
-
|
| 1424 |
-
|
| 1425 |
-
|
| 1426 |
-
|
| 1427 |
-
|
| 1428 |
-
if(te){te.textContent='60s';te.style.color='#8B98B4';}
|
| 1429 |
-
document.getElementById('badge').style.display='none';
|
| 1430 |
-
document.getElementById('panel').style.display='block';
|
| 1431 |
-
send('open');
|
| 1432 |
-
}
|
| 1433 |
-
function switchTab(t){TAB=t;renderTabs();renderBody();send('tab:'+t);}
|
| 1434 |
-
document.getElementById('badge').onclick=openPanel;
|
| 1435 |
-
</script>
|
| 1436 |
-
</body></html>""" % {
|
| 1437 |
-
"B": B, "T": T, "N": N, "TC": TC,
|
| 1438 |
-
"DMIN": DMIN, "DPAN": DPAN, "IMIN": IMIN, "ITAB": ITAB,
|
| 1439 |
-
"TAB_JSON": tab_json, "DATA_JSON": data_json,
|
| 1440 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1441 |
|
| 1442 |
-
|
| 1443 |
-
|
| 1444 |
-
|
| 1445 |
-
|
| 1446 |
-
|
| 1447 |
-
|
| 1448 |
-
|
| 1449 |
-
|
| 1450 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1451 |
|
| 1452 |
components.html(html, height=0, scrolling=False)
|
| 1453 |
|
|
@@ -1456,7 +1543,6 @@ window.addEventListener('message', function(e){
|
|
| 1456 |
# 9. λ©μΈ λΌμ°ν
|
| 1457 |
# ============================================================
|
| 1458 |
|
| 1459 |
-
# ββ μλ ν¨λ query_params μ‘μ
μ²λ¦¬ (μ΅μλ¨) ββββββββββββββββ
|
| 1460 |
_ap = st.query_params.get("alert_action", "")
|
| 1461 |
if _ap:
|
| 1462 |
st.query_params.clear()
|
|
@@ -1519,7 +1605,6 @@ elif st.session_state.main_menu == "β ν & μ€μΊ":
|
|
| 1519 |
""", unsafe_allow_html=True)
|
| 1520 |
|
| 1521 |
if not st.session_state.df.empty:
|
| 1522 |
-
# β
NEW: κ·Έλ£Ήν μλ ν¨λ (κΈ°μ‘΄ render_alert_banners λ체)
|
| 1523 |
render_grouped_alert_panel(prices, rate)
|
| 1524 |
|
| 1525 |
with st.spinner("ν¬νΈν΄λ¦¬μ€ λΆμ μ€..."):
|
|
|
|
| 26 |
# ============================================================
|
| 27 |
st.set_page_config(page_title="Invest Pro Alpha", layout="wide", initial_sidebar_state="collapsed")
|
| 28 |
|
|
|
|
| 29 |
NAV_CSS = """
|
| 30 |
div.element-container:has(.nav-marker) + div {
|
| 31 |
position: fixed !important; bottom: 0 !important; left: 0 !important;
|
|
|
|
| 66 |
div.element-container:has(.nav-marker) + div button:active em { color: #C9A84C !important; }
|
| 67 |
"""
|
| 68 |
|
|
|
|
| 69 |
PORTFOLIO_ROW_CSS = """
|
| 70 |
div.element-container:has(.portfolio-item-row-marker) + div [data-testid="stColumns"],
|
| 71 |
div.element-container:has(.portfolio-item-row-marker) + div [data-testid="stHorizontalBlock"] {
|
|
|
|
| 87 |
div.element-container:has(.action-marker.log) + div button:hover { color: #C9A84C !important; transform: scale(1.15) !important; }
|
| 88 |
"""
|
| 89 |
|
|
|
|
| 90 |
CARD_CSS = """
|
| 91 |
div.element-container:has(.scan-marker) + div.element-container button {
|
| 92 |
background: #0F1623 !important;
|
|
|
|
| 152 |
}
|
| 153 |
"""
|
| 154 |
|
|
|
|
| 155 |
COMPONENT_CSS = """
|
| 156 |
.menu-overlay-btn > button {
|
| 157 |
background: #0F1623 !important;
|
|
|
|
| 296 |
0%, 100% { opacity: 1; }
|
| 297 |
50% { opacity: 0.65; }
|
| 298 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 299 |
"""
|
| 300 |
|
| 301 |
def load_css():
|
|
|
|
| 424 |
color: #EEF2F7 !important;
|
| 425 |
}}
|
| 426 |
|
| 427 |
+
/* ββ μλ ν¨λ iframe κ³ μ ββ */
|
| 428 |
+
iframe[title="components.v1.html"] {{
|
| 429 |
+
position: fixed !important;
|
| 430 |
+
top: 0 !important;
|
| 431 |
+
left: 0 !important;
|
| 432 |
+
width: 100vw !important;
|
| 433 |
+
height: 100vh !important;
|
| 434 |
+
border: none !important;
|
| 435 |
+
z-index: 2147483640 !important;
|
| 436 |
+
background: transparent !important;
|
| 437 |
+
pointer-events: none !important;
|
| 438 |
+
}}
|
| 439 |
+
div:has(> iframe[title="components.v1.html"]) {{
|
| 440 |
+
height: 0 !important;
|
| 441 |
+
overflow: visible !important;
|
| 442 |
+
position: static !important;
|
| 443 |
+
}}
|
| 444 |
+
|
| 445 |
{NAV_CSS}
|
| 446 |
{PORTFOLIO_ROW_CSS}
|
| 447 |
{CARD_CSS}
|
|
|
|
| 459 |
if 'show_menu' not in st.session_state: st.session_state.show_menu = False
|
| 460 |
if 'main_menu' not in st.session_state: st.session_state.main_menu = "β ν & μ€μΊ"
|
| 461 |
|
|
|
|
| 462 |
if 'alert_panel_minimized' not in st.session_state: st.session_state.alert_panel_minimized = False
|
| 463 |
if 'alert_panel_start_time' not in st.session_state: st.session_state.alert_panel_start_time = time.time()
|
| 464 |
+
if 'alert_active_tab' not in st.session_state: st.session_state.alert_active_tab = None
|
| 465 |
|
| 466 |
def _key_hash():
|
| 467 |
return hashlib.sha256(st.session_state.api_key.encode()).hexdigest()[:16]
|
|
|
|
| 1071 |
)
|
| 1072 |
|
| 1073 |
# ============================================================
|
| 1074 |
+
# 8. κ·Έλ£Ήν μλ ν¨λ (μμ μ¬μμ± β HuggingFace Spaces νΈν)
|
| 1075 |
# ============================================================
|
| 1076 |
|
| 1077 |
def _build_alert_groups(prices, rate):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1078 |
groups = {"κΈλ³": [], "λ§€μ": [], "μ΅μ ": [], "μ€ν±λ‘μ€": []}
|
| 1079 |
if st.session_state.df.empty:
|
| 1080 |
return groups
|
|
|
|
| 1096 |
current_price=int(ck), avg_price=int(ap),
|
| 1097 |
target_price=tgp, action=act)
|
| 1098 |
|
|
|
|
| 1099 |
if abs(pct) >= 15:
|
| 1100 |
groups["κΈλ³"].append(item)
|
| 1101 |
continue
|
| 1102 |
|
|
|
|
| 1103 |
if not act:
|
| 1104 |
continue
|
| 1105 |
|
|
|
|
| 1113 |
return groups
|
| 1114 |
|
| 1115 |
|
| 1116 |
+
def _navigate_to_ticker(ticker):
|
|
|
|
|
|
|
| 1117 |
in_portfolio = ticker in st.session_state.df['ν°μ»€'].values if not st.session_state.df.empty else False
|
| 1118 |
if in_portfolio:
|
| 1119 |
st.session_state.detail_ticker = ticker
|
| 1120 |
st.session_state.main_menu = "β€ μμ° μμΈ μ§λ¨"
|
| 1121 |
st.session_state.p_diag_mode = False
|
| 1122 |
+
st.session_state.pop('active_ticker', None)
|
| 1123 |
else:
|
| 1124 |
st.session_state.active_ticker = ticker
|
| 1125 |
st.session_state.main_menu = "β ν & μ€μΊ"
|
| 1126 |
st.session_state.p_diag_mode = False
|
| 1127 |
+
st.session_state.pop('detail_ticker', None)
|
| 1128 |
|
| 1129 |
|
| 1130 |
def render_grouped_alert_panel(prices, rate):
|
|
|
|
| 1131 |
groups = _build_alert_groups(prices, rate)
|
| 1132 |
total_cnt = sum(len(v) for v in groups.values())
|
| 1133 |
if total_cnt == 0:
|
|
|
|
| 1151 |
|
| 1152 |
if st.session_state.alert_active_tab not in TAB_CFG:
|
| 1153 |
for pt in ["μ€ν±λ‘μ€", "κΈλ³", "μ΅μ ", "λ§€μ"]:
|
| 1154 |
+
if groups[pt]:
|
| 1155 |
+
st.session_state.alert_active_tab = pt
|
| 1156 |
+
break
|
| 1157 |
+
else:
|
| 1158 |
+
st.session_state.alert_active_tab = "κΈλ³"
|
| 1159 |
active_tab = st.session_state.alert_active_tab
|
| 1160 |
|
|
|
|
| 1161 |
data = {}
|
| 1162 |
for tab, tc in TAB_CFG.items():
|
| 1163 |
rows = []
|
|
|
|
| 1171 |
})
|
| 1172 |
data[tab] = rows
|
| 1173 |
|
| 1174 |
+
tab_json = json.dumps(
|
| 1175 |
+
{t: {"icon": v["icon"], "accent": v["accent"], "bg": v["bg"], "border": v["border"]}
|
| 1176 |
+
for t, v in TAB_CFG.items()},
|
| 1177 |
+
ensure_ascii=False
|
| 1178 |
+
)
|
| 1179 |
data_json = json.dumps(data, ensure_ascii=False)
|
| 1180 |
timer_col = "#E53E3E" if time_left <= 15 else ("#EAB308" if time_left <= 30 else "#8B98B4")
|
| 1181 |
|
| 1182 |
+
B = badge_col
|
| 1183 |
+
T = str(time_left)
|
| 1184 |
+
N = str(total_cnt)
|
| 1185 |
+
TC = timer_col
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1186 |
IMIN = "true" if minimized else "false"
|
| 1187 |
ITAB = json.dumps(active_tab, ensure_ascii=False)
|
| 1188 |
+
# CSS display κ°μ μ§μ λ¬Έμμ΄λ‘ μ²λ¦¬ (% ν¬λ§€ν
μΆ©λ λ°©μ§)
|
| 1189 |
+
DMIN = "flex" if minimized else "none"
|
| 1190 |
+
DPAN = "none" if minimized else "flex"
|
| 1191 |
|
| 1192 |
+
html_template = """<!DOCTYPE html>
|
| 1193 |
+
<html>
|
| 1194 |
+
<head>
|
| 1195 |
+
<meta charset="utf-8">
|
| 1196 |
+
<link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@600;700;800&family=Noto+Sans+KR:wght@400;500;700;900&display=swap" rel="stylesheet">
|
| 1197 |
<style>
|
| 1198 |
+
* { margin:0; padding:0; box-sizing:border-box; }
|
| 1199 |
+
html, body {
|
| 1200 |
+
background: transparent;
|
| 1201 |
+
overflow: hidden;
|
| 1202 |
+
width: 100vw;
|
| 1203 |
+
height: 100vh;
|
| 1204 |
+
font-family: 'Noto Sans KR', sans-serif;
|
| 1205 |
+
}
|
| 1206 |
+
#alert-root {
|
| 1207 |
+
position: fixed;
|
| 1208 |
+
bottom: 24px;
|
| 1209 |
+
right: 20px;
|
| 1210 |
+
z-index: 9999;
|
| 1211 |
+
pointer-events: auto;
|
| 1212 |
+
}
|
| 1213 |
+
#badge {
|
| 1214 |
+
align-items: center;
|
| 1215 |
+
gap: 10px;
|
| 1216 |
+
background: linear-gradient(135deg, #1a1f2e 0%%, #151921 100%%);
|
| 1217 |
+
border: 1px solid __BADGE_COL__;
|
| 1218 |
+
border-radius: 40px;
|
| 1219 |
+
padding: 10px 20px;
|
| 1220 |
+
cursor: pointer;
|
| 1221 |
+
box-shadow: 0 8px 32px rgba(0,0,0,0.55), 0 0 0 1px rgba(255,255,255,0.04);
|
| 1222 |
+
animation: badgePop 0.4s cubic-bezier(0.34,1.56,0.64,1);
|
| 1223 |
+
user-select: none;
|
| 1224 |
+
transition: border-color 0.2s;
|
| 1225 |
+
}
|
| 1226 |
+
#badge:hover { border-color: rgba(255,255,255,0.3); }
|
| 1227 |
+
.badge-dot {
|
| 1228 |
+
width: 6px; height: 6px; border-radius: 50%%;
|
| 1229 |
+
background: __BADGE_COL__;
|
| 1230 |
+
animation: pulse 1.5s infinite;
|
| 1231 |
+
display: inline-block;
|
| 1232 |
+
}
|
| 1233 |
+
#panel {
|
| 1234 |
+
flex-direction: column;
|
| 1235 |
+
width: min(96vw, 380px);
|
| 1236 |
+
animation: slideUp 0.4s cubic-bezier(0.34,1.56,0.64,1);
|
| 1237 |
+
}
|
| 1238 |
+
.p-header {
|
| 1239 |
+
background: linear-gradient(135deg, #1e2538 0%%, #161c2c 100%%);
|
| 1240 |
+
border: 1px solid rgba(255,255,255,0.09);
|
| 1241 |
+
border-bottom: none;
|
| 1242 |
+
border-radius: 16px 16px 0 0;
|
| 1243 |
+
padding: 14px 16px 0;
|
| 1244 |
+
}
|
| 1245 |
+
.p-header-row {
|
| 1246 |
+
display: flex; align-items: center;
|
| 1247 |
+
justify-content: space-between;
|
| 1248 |
+
margin-bottom: 14px;
|
| 1249 |
+
}
|
| 1250 |
+
.live-dot {
|
| 1251 |
+
width: 8px; height: 8px; border-radius: 50%%;
|
| 1252 |
+
background: #FF6B35;
|
| 1253 |
+
box-shadow: 0 0 8px rgba(255,107,53,0.8);
|
| 1254 |
+
animation: pulse 1.5s infinite;
|
| 1255 |
+
display: inline-block;
|
| 1256 |
+
}
|
| 1257 |
+
.live-label {
|
| 1258 |
+
font-size: 12px; font-weight: 700; color: #e8eaf0;
|
| 1259 |
+
letter-spacing: 0.08em;
|
| 1260 |
+
font-family: 'JetBrains Mono', monospace;
|
| 1261 |
+
}
|
| 1262 |
+
.total-badge {
|
| 1263 |
+
background: rgba(229,62,62,0.15);
|
| 1264 |
+
border: 1px solid rgba(229,62,62,0.3);
|
| 1265 |
+
border-radius: 5px; padding: 1px 7px;
|
| 1266 |
+
font-size: 10px; color: #E53E3E; font-weight: 700;
|
| 1267 |
+
font-family: 'JetBrains Mono', monospace;
|
| 1268 |
+
}
|
| 1269 |
+
.timer-wrap {
|
| 1270 |
+
display: flex; align-items: center; gap: 5px;
|
| 1271 |
+
background: rgba(255,255,255,0.06);
|
| 1272 |
+
border-radius: 8px; padding: 4px 10px;
|
| 1273 |
+
}
|
| 1274 |
+
.min-btn {
|
| 1275 |
+
background: transparent;
|
| 1276 |
+
border: 1px solid rgba(255,255,255,0.1);
|
| 1277 |
+
border-radius: 6px;
|
| 1278 |
+
color: rgba(255,255,255,0.35);
|
| 1279 |
+
font-size: 16px; padding: 3px 9px;
|
| 1280 |
+
cursor: pointer; line-height: 1;
|
| 1281 |
+
transition: all 0.15s;
|
| 1282 |
+
font-family: 'JetBrains Mono', monospace;
|
| 1283 |
+
}
|
| 1284 |
+
.min-btn:hover { background: rgba(255,255,255,0.1); color: rgba(255,255,255,0.7); }
|
| 1285 |
+
.tabs-row { display: flex; gap: 4px; }
|
| 1286 |
+
.tab-btn {
|
| 1287 |
+
flex: 1;
|
| 1288 |
+
border: 1px solid rgba(255,255,255,0.06);
|
| 1289 |
+
border-bottom: none;
|
| 1290 |
+
border-radius: 8px 8px 0 0;
|
| 1291 |
+
padding: 8px 3px;
|
| 1292 |
+
cursor: pointer;
|
| 1293 |
+
display: flex; flex-direction: column; align-items: center; gap: 3px;
|
| 1294 |
+
transition: all 0.18s;
|
| 1295 |
+
background: transparent;
|
| 1296 |
+
}
|
| 1297 |
+
.tab-btn:hover { opacity: 0.9 !important; }
|
| 1298 |
+
.tab-icon { font-size: 14px; }
|
| 1299 |
+
.tab-label { font-size: 9px; font-weight: 700; letter-spacing: 0.04em; font-family: 'Noto Sans KR', sans-serif; }
|
| 1300 |
+
.tab-count {
|
| 1301 |
+
border-radius: 8px; min-width: 16px; height: 16px;
|
| 1302 |
+
display: flex; align-items: center; justify-content: center;
|
| 1303 |
+
font-size: 9px; font-weight: 700; padding: 0 4px; color: #fff;
|
| 1304 |
+
font-family: 'JetBrains Mono', monospace;
|
| 1305 |
+
}
|
| 1306 |
+
.p-body {
|
| 1307 |
+
background: linear-gradient(180deg, #161c2a 0%%, #111620 100%%);
|
| 1308 |
+
border: 1px solid rgba(255,255,255,0.09);
|
| 1309 |
+
border-radius: 0 0 16px 16px;
|
| 1310 |
+
max-height: 280px;
|
| 1311 |
+
overflow-y: auto;
|
| 1312 |
+
padding: 8px;
|
| 1313 |
+
}
|
| 1314 |
+
.p-body::-webkit-scrollbar { width: 3px; }
|
| 1315 |
+
.p-body::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 3px; }
|
| 1316 |
+
.alert-item {
|
| 1317 |
+
display: flex; align-items: center; gap: 12px;
|
| 1318 |
+
padding: 10px 12px;
|
| 1319 |
+
border-radius: 10px;
|
| 1320 |
+
cursor: pointer;
|
| 1321 |
+
border: 1px solid transparent;
|
| 1322 |
+
margin-bottom: 4px;
|
| 1323 |
+
transition: all 0.15s ease;
|
| 1324 |
+
animation: itemIn 0.3s ease both;
|
| 1325 |
+
}
|
| 1326 |
+
.alert-item:last-child { margin-bottom: 0; }
|
| 1327 |
+
.alert-item:hover { background: rgba(255,255,255,0.06) !important; transform: translateX(-2px); }
|
| 1328 |
+
.ticker-box {
|
| 1329 |
+
width: 40px; height: 40px; border-radius: 10px;
|
| 1330 |
+
display: flex; align-items: center; justify-content: center;
|
| 1331 |
+
flex-shrink: 0;
|
| 1332 |
+
font-size: 9px; font-weight: 800; letter-spacing: -0.02em;
|
| 1333 |
+
font-family: 'JetBrains Mono', monospace;
|
| 1334 |
+
}
|
| 1335 |
+
.item-name { font-size: 12px; font-weight: 700; color: #e8eaf0; margin-bottom: 2px; }
|
| 1336 |
+
.item-sub { font-size: 10px; color: rgba(255,255,255,0.35); font-family: 'Noto Sans KR', sans-serif; }
|
| 1337 |
+
.item-price { font-size: 11px; color: rgba(255,255,255,0.4); margin-top: 1px; font-family: 'Noto Sans KR', sans-serif; }
|
| 1338 |
+
.item-pct { font-size: 12px; font-weight: 700; font-family: 'JetBrains Mono', monospace; }
|
| 1339 |
+
.item-arrow { font-size: 10px; color: rgba(255,255,255,0.25); margin-top: 2px; }
|
| 1340 |
+
.empty-msg { text-align: center; padding: 24px; color: rgba(255,255,255,0.2); font-size: 13px; }
|
| 1341 |
+
@keyframes slideUp {
|
| 1342 |
+
from { transform: translateY(30px); opacity: 0; }
|
| 1343 |
+
to { transform: translateY(0); opacity: 1; }
|
| 1344 |
+
}
|
| 1345 |
+
@keyframes badgePop {
|
| 1346 |
+
from { transform: scale(0.5); opacity: 0; }
|
| 1347 |
+
to { transform: scale(1); opacity: 1; }
|
| 1348 |
+
}
|
| 1349 |
+
@keyframes pulse {
|
| 1350 |
+
0%%, 100%% { opacity: 1; }
|
| 1351 |
+
50%% { opacity: 0.3; }
|
| 1352 |
+
}
|
| 1353 |
+
@keyframes itemIn {
|
| 1354 |
+
from { transform: translateX(10px); opacity: 0; }
|
| 1355 |
+
to { transform: translateX(0); opacity: 1; }
|
| 1356 |
+
}
|
| 1357 |
+
</style>
|
| 1358 |
+
</head>
|
| 1359 |
+
<body>
|
| 1360 |
+
<div id="alert-root">
|
| 1361 |
+
|
| 1362 |
+
<!-- μ΅μν λ°°μ§ -->
|
| 1363 |
+
<div id="badge" style="display:__DMIN__;">
|
| 1364 |
+
<span style="font-size:20px;position:relative;line-height:1;">🔔
|
| 1365 |
+
<span style="position:absolute;top:-7px;right:-10px;
|
| 1366 |
+
background:__BADGE_COL__;color:#fff;border-radius:10px;
|
| 1367 |
+
font-size:9px;font-weight:700;min-width:18px;height:18px;
|
| 1368 |
+
display:flex;align-items:center;justify-content:center;padding:0 4px;
|
| 1369 |
+
font-family:'JetBrains Mono',monospace;
|
| 1370 |
+
box-shadow:0 0 8px __BADGE_COL__80;">__N__</span>
|
| 1371 |
+
</span>
|
| 1372 |
+
<span style="font-size:13px;font-weight:700;color:#e8eaf0;font-family:'JetBrains Mono',monospace;">μλ __N__κ°</span>
|
| 1373 |
+
<span class="badge-dot"></span>
|
| 1374 |
+
</div>
|
| 1375 |
|
| 1376 |
+
<!-- ν ν¨λ -->
|
| 1377 |
+
<div id="panel" style="display:__DPAN__;">
|
| 1378 |
+
<div class="p-header">
|
| 1379 |
+
<div class="p-header-row">
|
| 1380 |
+
<div style="display:flex;align-items:center;gap:8px;">
|
| 1381 |
+
<span class="live-dot"></span>
|
| 1382 |
+
<span class="live-label">LIVE ALERTS</span>
|
| 1383 |
+
<span class="total-badge">__N__</span>
|
| 1384 |
+
</div>
|
| 1385 |
+
<div style="display:flex;align-items:center;gap:6px;">
|
| 1386 |
+
<div class="timer-wrap">
|
| 1387 |
+
<span style="font-size:12px;">⏱</span>
|
| 1388 |
+
<span id="timer-txt"
|
| 1389 |
+
style="font-size:11px;font-weight:700;font-family:'JetBrains Mono',monospace;color:__TC__;">__T__s</span>
|
| 1390 |
+
</div>
|
| 1391 |
+
<button class="min-btn" onclick="minimize()">−</button>
|
| 1392 |
</div>
|
|
|
|
| 1393 |
</div>
|
| 1394 |
+
<div class="tabs-row" id="tabs-row"></div>
|
| 1395 |
</div>
|
| 1396 |
+
<div class="p-body" id="panel-body"></div>
|
| 1397 |
</div>
|
| 1398 |
+
|
|
|
|
| 1399 |
</div>
|
| 1400 |
|
| 1401 |
<script>
|
| 1402 |
+
var MINIMIZED = __IMIN__;
|
| 1403 |
+
var TIME_LEFT = __T__;
|
| 1404 |
+
var ACTIVE_TAB = __ITAB__;
|
| 1405 |
+
var TABS = __TAB_JSON__;
|
| 1406 |
+
var DATA = __DATA_JSON__;
|
| 1407 |
+
var timerEl = document.getElementById('timer-txt');
|
| 1408 |
+
|
| 1409 |
+
function renderTabs() {
|
| 1410 |
+
var el = document.getElementById('tabs-row');
|
| 1411 |
+
el.innerHTML = '';
|
| 1412 |
+
Object.keys(TABS).forEach(function(tab) {
|
| 1413 |
+
var tc = TABS[tab];
|
| 1414 |
+
var cnt = DATA[tab].length;
|
| 1415 |
+
var isA = (tab === ACTIVE_TAB);
|
| 1416 |
+
var btn = document.createElement('div');
|
| 1417 |
+
btn.className = 'tab-btn';
|
| 1418 |
+
btn.style.cssText =
|
| 1419 |
+
'background:' + (isA ? tc.bg : 'transparent') + ';' +
|
| 1420 |
+
'border-color:' + (isA ? tc.border : 'rgba(255,255,255,0.06)') + ';' +
|
| 1421 |
+
'border-bottom:' + (isA ? '2px solid ' + tc.accent : '1px solid transparent') + ';' +
|
| 1422 |
+
'opacity:' + (isA ? '1' : '0.55') + ';';
|
| 1423 |
+
btn.innerHTML =
|
| 1424 |
+
'<span class="tab-icon">' + tc.icon + '</span>' +
|
| 1425 |
+
'<span class="tab-label" style="color:' + (isA ? tc.accent : 'rgba(255,255,255,0.4)') + '">' + tab + '</span>' +
|
| 1426 |
+
'<span class="tab-count" style="background:' + (cnt > 0 ? tc.accent : 'rgba(255,255,255,0.15)') + '">' + cnt + '</span>';
|
| 1427 |
+
btn.onclick = (function(t) { return function() { switchTab(t); }; })(tab);
|
| 1428 |
+
el.appendChild(btn);
|
| 1429 |
+
});
|
| 1430 |
+
}
|
| 1431 |
+
|
| 1432 |
+
function renderBody() {
|
| 1433 |
+
var el = document.getElementById('panel-body');
|
| 1434 |
+
var tc = TABS[ACTIVE_TAB];
|
| 1435 |
+
var items = DATA[ACTIVE_TAB];
|
| 1436 |
+
el.style.borderTop = '2px solid ' + tc.accent;
|
| 1437 |
+
el.innerHTML = '';
|
| 1438 |
+
if (!items.length) {
|
| 1439 |
+
el.innerHTML = '<div class="empty-msg">μλ μμ</div>';
|
| 1440 |
+
return;
|
| 1441 |
+
}
|
| 1442 |
+
items.forEach(function(item, i) {
|
| 1443 |
+
var row = document.createElement('div');
|
| 1444 |
+
row.className = 'alert-item';
|
| 1445 |
+
row.style.animationDelay = (i * 0.06) + 's';
|
| 1446 |
+
row.innerHTML =
|
| 1447 |
+
'<div class="ticker-box" style="background:' + tc.bg + ';border:1px solid ' + tc.border + ';color:' + tc.accent + ';">' +
|
| 1448 |
+
item.ticker.slice(0, 4) +
|
| 1449 |
+
'</div>' +
|
| 1450 |
+
'<div style="flex:1;min-width:0;">' +
|
| 1451 |
+
'<div class="item-name">' + item.ticker + ' <span class="item-sub">' + item.name + '</span></div>' +
|
| 1452 |
+
'<div class="item-price">' + item.price + '</div>' +
|
| 1453 |
+
'</div>' +
|
| 1454 |
+
'<div style="text-align:right;flex-shrink:0;">' +
|
| 1455 |
+
'<div class="item-pct" style="color:' + tc.accent + ';">' + item.pct_str + '</div>' +
|
| 1456 |
+
'<div class="item-arrow">→ λΆμ</div>' +
|
| 1457 |
+
'</div>';
|
| 1458 |
+
row.onclick = (function(tk) { return function() { sendAction('goto:' + tk); }; })(item.ticker);
|
| 1459 |
+
el.appendChild(row);
|
| 1460 |
+
});
|
| 1461 |
+
}
|
| 1462 |
+
|
| 1463 |
+
renderTabs();
|
| 1464 |
+
renderBody();
|
| 1465 |
+
|
| 1466 |
+
var iv = setInterval(function() {
|
| 1467 |
+
if (MINIMIZED) return;
|
| 1468 |
+
TIME_LEFT--;
|
| 1469 |
+
if (TIME_LEFT <= 0) {
|
| 1470 |
+
clearInterval(iv);
|
| 1471 |
+
minimize();
|
| 1472 |
+
sendAction('expired');
|
| 1473 |
+
return;
|
| 1474 |
+
}
|
| 1475 |
+
if (timerEl) {
|
| 1476 |
+
timerEl.textContent = TIME_LEFT + 's';
|
| 1477 |
+
timerEl.style.color = TIME_LEFT <= 15 ? '#E53E3E' : (TIME_LEFT <= 30 ? '#EAB308' : '#8B98B4');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1478 |
}
|
| 1479 |
+
}, 1000);
|
| 1480 |
+
|
| 1481 |
+
function minimize() {
|
| 1482 |
+
MINIMIZED = true;
|
| 1483 |
+
document.getElementById('panel').style.display = 'none';
|
| 1484 |
+
document.getElementById('badge').style.display = 'flex';
|
| 1485 |
+
sendAction('minimize');
|
| 1486 |
+
}
|
| 1487 |
+
|
| 1488 |
+
function openPanel() {
|
| 1489 |
+
MINIMIZED = false;
|
| 1490 |
+
TIME_LEFT = 60;
|
| 1491 |
+
clearInterval(iv);
|
| 1492 |
+
iv = setInterval(function() {
|
| 1493 |
+
if (MINIMIZED) return;
|
| 1494 |
+
TIME_LEFT--;
|
| 1495 |
+
if (TIME_LEFT <= 0) { clearInterval(iv); minimize(); sendAction('expired'); return; }
|
| 1496 |
+
if (timerEl) {
|
| 1497 |
+
timerEl.textContent = TIME_LEFT + 's';
|
| 1498 |
+
timerEl.style.color = TIME_LEFT <= 15 ? '#E53E3E' : (TIME_LEFT <= 30 ? '#EAB308' : '#8B98B4');
|
| 1499 |
+
}
|
| 1500 |
+
}, 1000);
|
| 1501 |
+
if (timerEl) { timerEl.textContent = '60s'; timerEl.style.color = '#8B98B4'; }
|
| 1502 |
+
document.getElementById('badge').style.display = 'none';
|
| 1503 |
+
document.getElementById('panel').style.display = 'flex';
|
| 1504 |
+
sendAction('open');
|
| 1505 |
+
}
|
| 1506 |
|
| 1507 |
+
function switchTab(t) {
|
| 1508 |
+
ACTIVE_TAB = t;
|
| 1509 |
+
renderTabs();
|
| 1510 |
+
renderBody();
|
| 1511 |
+
sendAction('tab:' + t);
|
| 1512 |
+
}
|
| 1513 |
+
|
| 1514 |
+
document.getElementById('badge').onclick = openPanel;
|
| 1515 |
+
|
| 1516 |
+
function sendAction(action) {
|
| 1517 |
+
try {
|
| 1518 |
+
var base = window.parent.location.href.split('?')[0];
|
| 1519 |
+
window.parent.location.href = base + '?alert_action=' + encodeURIComponent(action);
|
| 1520 |
+
} catch(e) {}
|
| 1521 |
+
}
|
| 1522 |
+
</script>
|
| 1523 |
+
</body>
|
| 1524 |
+
</html>"""
|
| 1525 |
+
|
| 1526 |
+
# νλ μ΄μ€νλ μΉν (% ν¬λ§€ν
μμ μ°ν)
|
| 1527 |
+
html = html_template
|
| 1528 |
+
html = html.replace("__BADGE_COL__", B)
|
| 1529 |
+
html = html.replace("__N__", N)
|
| 1530 |
+
html = html.replace("__T__", T)
|
| 1531 |
+
html = html.replace("__TC__", TC)
|
| 1532 |
+
html = html.replace("__DMIN__", DMIN)
|
| 1533 |
+
html = html.replace("__DPAN__", DPAN)
|
| 1534 |
+
html = html.replace("__IMIN__", IMIN)
|
| 1535 |
+
html = html.replace("__ITAB__", ITAB)
|
| 1536 |
+
html = html.replace("__TAB_JSON__", tab_json)
|
| 1537 |
+
html = html.replace("__DATA_JSON__", data_json)
|
| 1538 |
|
| 1539 |
components.html(html, height=0, scrolling=False)
|
| 1540 |
|
|
|
|
| 1543 |
# 9. λ©μΈ λΌμ°ν
|
| 1544 |
# ============================================================
|
| 1545 |
|
|
|
|
| 1546 |
_ap = st.query_params.get("alert_action", "")
|
| 1547 |
if _ap:
|
| 1548 |
st.query_params.clear()
|
|
|
|
| 1605 |
""", unsafe_allow_html=True)
|
| 1606 |
|
| 1607 |
if not st.session_state.df.empty:
|
|
|
|
| 1608 |
render_grouped_alert_panel(prices, rate)
|
| 1609 |
|
| 1610 |
with st.spinner("ν¬νΈν΄λ¦¬μ€ λΆμ μ€..."):
|