Update src/app.py
Browse files- src/app.py +80 -91
src/app.py
CHANGED
|
@@ -2890,7 +2890,7 @@ elif st.session_state.main_menu == "โค ์์ฐ ์์ธ ์ง๋จ":
|
|
| 2890 |
st.divider()
|
| 2891 |
st.markdown("### ๋ด ํฌํธํด๋ฆฌ์ค")
|
| 2892 |
|
| 2893 |
-
# โโ
|
| 2894 |
for idx, row in st.session_state.df.iterrows():
|
| 2895 |
t = row['ํฐ์ปค']; ap = row['ํ๋จ๊ฐ']
|
| 2896 |
ck = int(prices.get(t,0)*rate) if prices.get(t,0)>0 else int(ap)
|
|
@@ -2906,115 +2906,104 @@ elif st.session_state.main_menu == "โค ์์ฐ ์์ธ ์ง๋จ":
|
|
| 2906 |
pc = "#D45A5A" if pct>=0 else "#7EAAD4"
|
| 2907 |
pa = "โฒ" if pct>=0 else "โผ"
|
| 2908 |
buy_reason = str(row.get('๋งค์๊ทผ๊ฑฐ', '') or '').strip()
|
| 2909 |
-
buy_date = str(row.get('๋งค์์ผ', '') or '').strip()
|
| 2910 |
|
| 2911 |
with st.container(border=True):
|
| 2912 |
-
# ์ข
๋ชฉ๋ช
+
|
| 2913 |
-
|
| 2914 |
-
|
|
|
|
| 2915 |
tv_tag = (
|
| 2916 |
f'<span style="font-size:9px;color:{tv_color};background:{tv_color}15;'
|
| 2917 |
f'border:1px solid {tv_color}33;padding:1px 6px;border-radius:3px;margin-left:6px;">{tv}</span>'
|
| 2918 |
) if tv else ""
|
| 2919 |
st.markdown(
|
| 2920 |
-
f'<div style="font-size:
|
| 2921 |
f'{row["์ข
๋ชฉ๋ช
"]} '
|
| 2922 |
-
f'<span style="font-size:
|
| 2923 |
f'padding:2px 6px;border-radius:4px;border:1px solid rgba(201,168,76,0.2);">{t}</span>'
|
| 2924 |
f'{tv_tag}</div>',
|
| 2925 |
unsafe_allow_html=True
|
| 2926 |
)
|
| 2927 |
-
with hc2:
|
| 2928 |
-
st.markdown(
|
| 2929 |
-
f'<div style="text-align:right;">'
|
| 2930 |
-
f'<div style="font-size:15px;font-weight:800;color:{pc};font-family:DM Mono,monospace;">{pa} {abs(pct):.1f}%</div>'
|
| 2931 |
-
f'<div style="font-size:10px;color:#5C5247;margin-top:1px;">[{act}]</div>'
|
| 2932 |
-
f'</div>',
|
| 2933 |
-
unsafe_allow_html=True
|
| 2934 |
-
)
|
| 2935 |
|
| 2936 |
-
|
| 2937 |
-
|
| 2938 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2939 |
f'ํ๋จ <b style="color:#EEE8DC;font-family:DM Mono,monospace;">{int(ap):,}</b>์ โ '
|
| 2940 |
-
f'<b style="color:
|
| 2941 |
-
f'
|
| 2942 |
-
f'</div>'
|
| 2943 |
-
|
|
|
|
| 2944 |
)
|
|
|
|
| 2945 |
|
| 2946 |
-
|
| 2947 |
-
if buy_reason:
|
| 2948 |
-
preview = buy_reason[:45] + ("..." if len(buy_reason) > 45 else "")
|
| 2949 |
-
st.markdown(
|
| 2950 |
-
f'<div style="font-size:12px;color:#5C5247;margin-bottom:8px;">'
|
| 2951 |
-
f'๐ {preview}</div>',
|
| 2952 |
-
unsafe_allow_html=True
|
| 2953 |
-
)
|
| 2954 |
-
|
| 2955 |
-
# โโ ๋ฉ์ธ CTA: ํฐ์นํ๋ฉด ์์ธ ์ง๋จ์ผ๋ก
|
| 2956 |
-
if st.button(f"์์ธ ์ง๋จ ๋ฆฌํฌํธ โ", key=f"rep_{idx}", use_container_width=True):
|
| 2957 |
st.session_state.detail_ticker = t; st.rerun()
|
| 2958 |
|
| 2959 |
-
# โโ
|
| 2960 |
-
|
| 2961 |
-
|
| 2962 |
-
|
| 2963 |
-
|
| 2964 |
-
|
| 2965 |
-
|
| 2966 |
-
|
| 2967 |
-
|
| 2968 |
-
|
| 2969 |
-
|
| 2970 |
-
|
| 2971 |
-
|
| 2972 |
-
|
| 2973 |
-
|
| 2974 |
-
|
| 2975 |
-
|
| 2976 |
-
|
| 2977 |
-
|
| 2978 |
-
|
| 2979 |
-
|
| 2980 |
-
|
| 2981 |
-
|
| 2982 |
-
|
| 2983 |
-
|
| 2984 |
-
|
| 2985 |
-
|
| 2986 |
-
|
| 2987 |
-
|
| 2988 |
-
|
| 2989 |
-
|
| 2990 |
-
|
| 2991 |
-
|
| 2992 |
-
|
| 2993 |
-
|
| 2994 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2995 |
save_assets()
|
| 2996 |
-
st.session_state[f"
|
| 2997 |
-
st.session_state.price_cache_ts = 0; st.rerun()
|
| 2998 |
-
st.markdown('</div>', unsafe_allow_html=True)
|
| 2999 |
-
|
| 3000 |
-
# ํธ์ง
|
| 3001 |
-
if st.session_state.get(f"edit_mode_{idx}", False):
|
| 3002 |
-
ec1, ec2 = st.columns([0.5, 0.5], vertical_alignment="bottom")
|
| 3003 |
-
with ec1: np2 = st.number_input("์ ํ๋จ๊ฐ(์)", value=float(ap), min_value=0.0, step=100.0, key=f"ep_{idx}")
|
| 3004 |
-
with ec2: nq2 = st.number_input("์ ์๋", value=float(row['์๋']), min_value=0.01, step=1.0, key=f"eq_{idx}")
|
| 3005 |
-
cur_reason = str(row.get('๋งค์๊ทผ๊ฑฐ', '') or '')
|
| 3006 |
-
cur_date = str(row.get('๋งค์์ผ', '') or '')
|
| 3007 |
-
new_reason = st.text_input("๋งค์ ๊ทผ๊ฑฐ", value=cur_reason, key=f"er_{idx}")
|
| 3008 |
-
ed1, ed2 = st.columns([0.5, 0.5], vertical_alignment="bottom")
|
| 3009 |
-
with ed1: new_date = st.text_input("๋งค์์ผ", value=cur_date, key=f"ed_{idx}")
|
| 3010 |
-
with ed2:
|
| 3011 |
-
if st.button("์ ์ฅ", key=f"esv_{idx}", type="primary", use_container_width=True):
|
| 3012 |
-
st.session_state.df.at[idx,'ํ๋จ๊ฐ'] = np2
|
| 3013 |
-
st.session_state.df.at[idx,'์๋'] = nq2
|
| 3014 |
-
st.session_state.df.at[idx,'๋งค์๊ทผ๊ฑฐ'] = new_reason
|
| 3015 |
-
st.session_state.df.at[idx,'๋งค์์ผ'] = new_date
|
| 3016 |
-
save_assets()
|
| 3017 |
-
st.session_state[f"edit_mode_{idx}"] = False; st.rerun()
|
| 3018 |
|
| 3019 |
elif st.session_state.main_menu == "๐ ๋์ ๋งค๋งค ์ผ์ง":
|
| 3020 |
st.markdown("### ๋งค๋งค ๋ณต๊ธฐ๋ก")
|
|
|
|
| 2890 |
st.divider()
|
| 2891 |
st.markdown("### ๋ด ํฌํธํด๋ฆฌ์ค")
|
| 2892 |
|
| 2893 |
+
# โโ ํฌํธํด๋ฆฌ์ค ์นด๋: ์นด๋ ํด๋ฆญ โ ์์ธ ์ด๋ / ์ฐ์๋จ ์์ด์ฝ์ผ๋ก ํธ์งยท๋งค๋ยท์ญ์
|
| 2894 |
for idx, row in st.session_state.df.iterrows():
|
| 2895 |
t = row['ํฐ์ปค']; ap = row['ํ๋จ๊ฐ']
|
| 2896 |
ck = int(prices.get(t,0)*rate) if prices.get(t,0)>0 else int(ap)
|
|
|
|
| 2906 |
pc = "#D45A5A" if pct>=0 else "#7EAAD4"
|
| 2907 |
pa = "โฒ" if pct>=0 else "โผ"
|
| 2908 |
buy_reason = str(row.get('๋งค์๊ทผ๊ฑฐ', '') or '').strip()
|
|
|
|
| 2909 |
|
| 2910 |
with st.container(border=True):
|
| 2911 |
+
# โโ ํค๋: ์ข
๋ชฉ๋ช
(ํด๋ฆญโ์์ธ) + ์์ด์ฝ 3๊ฐ
|
| 2912 |
+
hc_name, hc_edit, hc_sell, hc_del = st.columns([0.67, 0.11, 0.11, 0.11], vertical_alignment="center")
|
| 2913 |
+
|
| 2914 |
+
with hc_name:
|
| 2915 |
tv_tag = (
|
| 2916 |
f'<span style="font-size:9px;color:{tv_color};background:{tv_color}15;'
|
| 2917 |
f'border:1px solid {tv_color}33;padding:1px 6px;border-radius:3px;margin-left:6px;">{tv}</span>'
|
| 2918 |
) if tv else ""
|
| 2919 |
st.markdown(
|
| 2920 |
+
f'<div style="font-size:15px;font-weight:800;color:#EEE8DC;line-height:1.3;">'
|
| 2921 |
f'{row["์ข
๋ชฉ๋ช
"]} '
|
| 2922 |
+
f'<span style="font-size:10px;color:#C9A84C;background:rgba(201,168,76,0.1);'
|
| 2923 |
f'padding:2px 6px;border-radius:4px;border:1px solid rgba(201,168,76,0.2);">{t}</span>'
|
| 2924 |
f'{tv_tag}</div>',
|
| 2925 |
unsafe_allow_html=True
|
| 2926 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2927 |
|
| 2928 |
+
with hc_edit:
|
| 2929 |
+
if st.button("โ", key=f"edit_btn_{idx}", use_container_width=True, help="ํธ์ง"):
|
| 2930 |
+
st.session_state[f"edit_mode_{idx}"] = not st.session_state.get(f"edit_mode_{idx}", False)
|
| 2931 |
+
st.session_state[f"log_mode_{idx}"] = False
|
| 2932 |
+
st.rerun()
|
| 2933 |
+
|
| 2934 |
+
with hc_sell:
|
| 2935 |
+
if st.button("โ", key=f"log_btn_{idx}", use_container_width=True, help="๋งค๋ ์ผ์ง"):
|
| 2936 |
+
st.session_state[f"log_mode_{idx}"] = not st.session_state.get(f"log_mode_{idx}", False)
|
| 2937 |
+
st.session_state[f"edit_mode_{idx}"] = False
|
| 2938 |
+
st.rerun()
|
| 2939 |
+
|
| 2940 |
+
with hc_del:
|
| 2941 |
+
if st.button("โ", key=f"del_btn_{idx}", use_container_width=True, help="์ญ์ "):
|
| 2942 |
+
st.session_state.df = st.session_state.df.drop(idx).reset_index(drop=True)
|
| 2943 |
+
save_assets(); st.session_state.price_cache_ts = 0; st.rerun()
|
| 2944 |
+
|
| 2945 |
+
# โโ ์นด๋ ๋ณธ๋ฌธ ํด๋ฆญ โ ์์ธ ์ง๋จ ์ด๋
|
| 2946 |
+
tgp_html = f" ยท <span style='color:#C9A84C;'>๋ชฉํ {tgp}</span>" if tgp != "-" else ""
|
| 2947 |
+
preview = ("๐ " + buy_reason[:42] + ("..." if len(buy_reason) > 42 else "")) if buy_reason else ""
|
| 2948 |
+
card_body = (
|
| 2949 |
+
f'<div style="margin:6px 0 2px;font-size:13px;color:#9A8F7E;">'
|
| 2950 |
f'ํ๋จ <b style="color:#EEE8DC;font-family:DM Mono,monospace;">{int(ap):,}</b>์ โ '
|
| 2951 |
+
f'<b style="color:{pc};font-family:DM Mono,monospace;">{ck:,}</b>์'
|
| 2952 |
+
f' <span style="font-size:12px;color:{pc};">{pa} {abs(pct):.1f}%</span>'
|
| 2953 |
+
f'{tgp_html}</div>'
|
| 2954 |
+
f'<div style="font-size:11px;color:#5C5247;margin-top:2px;">[{act}]'
|
| 2955 |
+
f'{" " + preview if preview else ""}</div>'
|
| 2956 |
)
|
| 2957 |
+
st.markdown(card_body, unsafe_allow_html=True)
|
| 2958 |
|
| 2959 |
+
if st.button("โ ์์ธ ์ง๋จ", key=f"card_{idx}", use_container_width=True):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2960 |
st.session_state.detail_ticker = t; st.rerun()
|
| 2961 |
|
| 2962 |
+
# โโ ๋งค๋ ์ผ์ง ํผ (โ ํด๋ฆญ ์ ์ธ๋ผ์ธ ํ์)
|
| 2963 |
+
if st.session_state.get(f"log_mode_{idx}", False):
|
| 2964 |
+
st.markdown('<div class="inline-edit-box" style="border-color:rgba(126,170,212,0.18);">', unsafe_allow_html=True)
|
| 2965 |
+
lc1, lc2 = st.columns(2)
|
| 2966 |
+
with lc1: sp = st.number_input("๋งค๋ ๋จ๊ฐ(์)", value=float(ck), step=100.0, key=f"sp_{idx}")
|
| 2967 |
+
with lc2: sq = st.number_input("๋งค๋ ์๋", value=float(row['์๋']), max_value=float(row['์๋']), min_value=0.01, step=1.0, key=f"sq_{idx}")
|
| 2968 |
+
tags = ["#๋ชฉํ๊ฐ๋๋ฌ_์ต์ ","#ํ
์ ๋ถ๊ดด_์์ ","#๋น์ค์กฐ์ ","#๋๋๋งค๋งค_๋ฐ์ฑ","#์ถ์ธ์ดํ","#ํด์ด๋ผ์ด๋_์คํจ"]
|
| 2969 |
+
stag = st.selectbox("์ ๋ต ํ๊ทธ", tags, key=f"tag_{idx}")
|
| 2970 |
+
memo = st.text_input("๋ณต๊ธฐ ๋ฉ๋ชจ", placeholder="์: ์ฑ์ฅ ์คํ ๋ฆฌ ํผ์์ผ๋ก ์์ ", key=f"memo_{idx}")
|
| 2971 |
+
if st.button("์ผ์ง ์ ์ฅ", key=f"slog_{idx}", type="primary", use_container_width=True):
|
| 2972 |
+
net_pnl, fee_amt = calc_realized_pnl(sp, row['ํ๋จ๊ฐ'], sq)
|
| 2973 |
+
orig_reason = str(row.get('๋งค์๊ทผ๊ฑฐ', '') or '')
|
| 2974 |
+
st.session_state.trade_df = pd.concat([pd.DataFrame([{
|
| 2975 |
+
"์ผ์": datetime.now().strftime("%Y-%m-%d %H:%M"),
|
| 2976 |
+
"ํฐ์ปค": t, "์ข
๋ชฉ๋ช
": row['์ข
๋ชฉ๋ช
'],
|
| 2977 |
+
"๊ตฌ๋ถ": "๋งค๋", "๋งค๋งค๊ฐ": sp, "์๋": sq,
|
| 2978 |
+
"์คํ์์ต": net_pnl, "์์๋ฃ": fee_amt,
|
| 2979 |
+
"ํ๊ทธ": stag, "๋ฉ๋ชจ": memo, "๋งค์๊ทผ๊ฑฐ": orig_reason
|
| 2980 |
+
}]), st.session_state.trade_df], ignore_index=True)
|
| 2981 |
+
save_trades()
|
| 2982 |
+
if sq >= row['์๋']: st.session_state.df = st.session_state.df.drop(idx).reset_index(drop=True)
|
| 2983 |
+
else: st.session_state.df.at[idx,'์๋'] = row['์๋'] - sq
|
| 2984 |
+
save_assets()
|
| 2985 |
+
st.session_state[f"log_mode_{idx}"] = False
|
| 2986 |
+
st.session_state.price_cache_ts = 0; st.rerun()
|
| 2987 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
| 2988 |
+
|
| 2989 |
+
# โโ ํธ์ง ํผ (โ ํด๋ฆญ ์ ์ธ๋ผ์ธ ํ์)
|
| 2990 |
+
if st.session_state.get(f"edit_mode_{idx}", False):
|
| 2991 |
+
ec1, ec2 = st.columns([0.5, 0.5], vertical_alignment="bottom")
|
| 2992 |
+
with ec1: np2 = st.number_input("์ ํ๋จ๊ฐ(์)", value=float(ap), min_value=0.0, step=100.0, key=f"ep_{idx}")
|
| 2993 |
+
with ec2: nq2 = st.number_input("์ ์๋", value=float(row['์๋']), min_value=0.01, step=1.0, key=f"eq_{idx}")
|
| 2994 |
+
cur_reason = str(row.get('๋งค์๊ทผ๊ฑฐ', '') or '')
|
| 2995 |
+
cur_date = str(row.get('๋งค์์ผ', '') or '')
|
| 2996 |
+
new_reason = st.text_input("๋งค์ ๊ทผ๊ฑฐ", value=cur_reason, key=f"er_{idx}")
|
| 2997 |
+
ed1, ed2 = st.columns([0.5, 0.5], vertical_alignment="bottom")
|
| 2998 |
+
with ed1: new_date = st.text_input("๋งค์์ผ", value=cur_date, key=f"ed_{idx}")
|
| 2999 |
+
with ed2:
|
| 3000 |
+
if st.button("์ ์ฅ", key=f"esv_{idx}", type="primary", use_container_width=True):
|
| 3001 |
+
st.session_state.df.at[idx,'ํ๋จ๊ฐ'] = np2
|
| 3002 |
+
st.session_state.df.at[idx,'์๋'] = nq2
|
| 3003 |
+
st.session_state.df.at[idx,'๋งค์๊ทผ๊ฑฐ'] = new_reason
|
| 3004 |
+
st.session_state.df.at[idx,'๋งค์์ผ'] = new_date
|
| 3005 |
save_assets()
|
| 3006 |
+
st.session_state[f"edit_mode_{idx}"] = False; st.rerun()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3007 |
|
| 3008 |
elif st.session_state.main_menu == "๐ ๋์ ๋งค๋งค ์ผ์ง":
|
| 3009 |
st.markdown("### ๋งค๋งค ๋ณต๊ธฐ๋ก")
|