브랜치 분리 방식: A / B / C
A 선택 시 커밋 메시지: 위 초안 OK / 수정 / 직접 작성 작업 시점: 지금 / 운영 데이터 1~2일 쌓고 / 주말
This commit is contained in:
43
kiwwom_trader/config.py
Normal file
43
kiwwom_trader/config.py
Normal file
@@ -0,0 +1,43 @@
|
||||
# kiwwom_trader/config.py
|
||||
# 폴더를 /home/hoon 밑으로 옮겨도 경로 변경 없이 동작하도록 ROOT·경로 독립 처리
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
# 프로젝트 루트: 환경변수 우선, 없으면 이 파일 기준 상위 디렉터리 (kiwwom_trader)
|
||||
_THIS_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
ROOT = os.environ.get("KIWOOM_TRADER_ROOT", _THIS_DIR)
|
||||
|
||||
# kiwoom_rest_api 패키지 경로 후보 (폴더 이전 후에도 import 가능하도록)
|
||||
def _ensure_paths():
|
||||
if ROOT not in sys.path:
|
||||
sys.path.insert(0, ROOT)
|
||||
# 부모 디렉터리: /home/hoon/kiwwom_trader → /home/hoon (kiwoom_rest_api, kis_bot 형제)
|
||||
_parent = os.path.dirname(ROOT)
|
||||
if _parent not in sys.path:
|
||||
sys.path.insert(0, _parent)
|
||||
# kis_bot (database, scalping_engine): 환경변수로 명시 가능
|
||||
_kis_bot = os.environ.get("KIS_BOT_PATH", os.path.join(_parent, "kis_bot"))
|
||||
if os.path.isdir(_kis_bot) and _kis_bot not in sys.path:
|
||||
sys.path.insert(0, _kis_bot)
|
||||
|
||||
_ensure_paths()
|
||||
|
||||
# .env 로드: kiwoom_rest_api/.env 또는 ROOT/.env
|
||||
def load_dotenv():
|
||||
try:
|
||||
from dotenv import load_dotenv as _load
|
||||
for p in [
|
||||
os.path.join(ROOT, "kiwoom_rest_api", ".env"),
|
||||
os.path.join(ROOT, ".env"),
|
||||
os.path.join(os.path.dirname(ROOT), "kiwoom_rest_api", ".env"),
|
||||
]:
|
||||
if os.path.isfile(p):
|
||||
_load(p)
|
||||
return p
|
||||
except ImportError:
|
||||
pass
|
||||
return None
|
||||
|
||||
LOG_DIR = os.environ.get("KIWOOM_TRADER_LOG_DIR", os.path.join(ROOT, "logs"))
|
||||
os.makedirs(LOG_DIR, exist_ok=True)
|
||||
Reference in New Issue
Block a user