Skip to content

Commit 0d52432

Browse files
illenne77claude
andcommitted
merge(fix/dotenv-local): fix/dotenv-local -> main
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2 parents 29e3642 + 4830fcd commit 0d52432

3 files changed

Lines changed: 34 additions & 2 deletions

File tree

pages/2_포트폴리오_대시보드.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,17 @@
3939

4040
_kis_key = os.environ.get("KIS_APP_KEY") or os.environ.get("KIS_LIVE_APP_KEY")
4141
_kis_secret = os.environ.get("KIS_APP_SECRET") or os.environ.get("KIS_LIVE_APP_SECRET")
42-
_kis_account = os.environ.get("KIS_ACCOUNT")
42+
_kis_account = (
43+
os.environ.get("KIS_ACCOUNT")
44+
or (
45+
os.environ.get("KIS_LIVE_ACCOUNT_NO")
46+
and f"{os.environ['KIS_LIVE_ACCOUNT_NO']}-{os.environ.get('KIS_LIVE_ACCOUNT_PRDT', '01')}"
47+
)
48+
or (
49+
os.environ.get("KIS_PAPER_ACCOUNT_NO")
50+
and f"{os.environ['KIS_PAPER_ACCOUNT_NO']}-{os.environ.get('KIS_PAPER_ACCOUNT_PRDT', '01')}"
51+
)
52+
)
4353
_kis_ready = bool(_kis_key and _kis_secret and _kis_account)
4454

4555
if not _kis_ready:
@@ -61,6 +71,8 @@
6171
os.environ["KIS_LIVE_APP_SECRET"] = _kis_secret
6272
if not os.environ.get("KIS_LIVE_BASE_URL"):
6373
os.environ["KIS_LIVE_BASE_URL"] = "https://openapi.koreainvestment.com:9443"
74+
if not os.environ.get("KIS_ACCOUNT"):
75+
os.environ["KIS_ACCOUNT"] = _kis_account
6476
os.environ["SENTINELQ_LIVE_ALLOW"] = "1"
6577

6678
from sentinelq.adapters.kis_history import fetch_balance

sentinelq/ui/helpers.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import os
99
from decimal import Decimal
10+
from pathlib import Path
1011
from typing import Any
1112

1213
from sentinelq.adapters.dart_api import DisclosureRecord
@@ -26,6 +27,18 @@ def _inject_secrets() -> None:
2627
pass
2728

2829

30+
def _load_dotenv() -> None:
31+
"""로컬 실행: 프로젝트 루트 .env → os.environ 로딩 (Streamlit Cloud 시 no-op)."""
32+
try:
33+
from dotenv import load_dotenv
34+
35+
_root = Path(__file__).resolve().parent.parent.parent
36+
load_dotenv(_root / ".env")
37+
except Exception:
38+
pass
39+
40+
41+
_load_dotenv()
2942
_inject_secrets()
3043

3144

tests/test_kis_history.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,14 @@ def test_kis_api_error_response_raises(self, monkeypatch, mock_token, mock_accou
238238
assert "계좌번호 오류" in exc_info.value.message
239239

240240
def test_invalid_account_format_raises_value_error(self, monkeypatch, mock_token):
241-
monkeypatch.delenv("KIS_ACCOUNT", raising=False)
241+
for _var in (
242+
"KIS_ACCOUNT",
243+
"KIS_LIVE_ACCOUNT_NO",
244+
"KIS_LIVE_ACCOUNT_PRDT",
245+
"KIS_PAPER_ACCOUNT_NO",
246+
"KIS_PAPER_ACCOUNT_PRDT",
247+
):
248+
monkeypatch.delenv(_var, raising=False)
242249
with pytest.raises(ValueError, match="KIS_ACCOUNT"):
243250
inquire_overseas_period_trans(date(2025, 1, 1), date(2025, 1, 31))
244251

0 commit comments

Comments
 (0)