일단 커밋

This commit is contained in:
2026-09-09 00:47:34 +09:00
parent 3008f8e0bf
commit a190a40bde
40 changed files with 181 additions and 36 deletions
+45
View File
@@ -1,11 +1,34 @@
from __future__ import annotations
import os
from pathlib import Path
from typing import Any
import yaml
def _load_dotenv(path: Path) -> None:
"""간단한 .env 파서 (python-dotenv 의존성 대신 내장 구현)."""
if not path.exists():
return
for line in path.read_text(encoding="utf-8").splitlines():
line = line.strip()
if not line or line.startswith("#") or "=" not in line:
continue
key, _, value = line.partition("=")
key = key.strip()
value = value.strip().strip('"').strip("'")
if key and key not in os.environ:
os.environ[key] = value
_load_dotenv(Path(".env"))
def _env(name: str, default: Any = None) -> Any:
return os.environ.get(name, default)
class KISConfig:
app_key: str = ""
app_secret: str = ""
@@ -14,6 +37,27 @@ class KISConfig:
hts_id: str = ""
server_mode: str = "vps"
def apply_env(self) -> None:
app_key = _env("KIS_APP_KEY")
app_secret = _env("KIS_APP_SECRET")
account_no = _env("KIS_ACCOUNT_NO")
account_code = _env("KIS_ACCOUNT_CODE")
hts_id = _env("KIS_HTS_ID")
server_mode = _env("KIS_SERVER_MODE")
if app_key:
self.app_key = app_key
if app_secret:
self.app_secret = app_secret
if account_no:
self.account_no = account_no
if account_code:
self.account_code = account_code
if hts_id:
self.hts_id = hts_id
if server_mode:
self.server_mode = server_mode
class AppConfig:
name: str = "StockAutomation"
@@ -58,6 +102,7 @@ class Settings:
self.trading = TradingConfig()
self.rate_limit = RateLimitConfig()
self._load_yaml()
self.kis.apply_env()
def _load_yaml(self) -> None:
yaml_path = Path("config.yaml")