브랜치 분리 방식: A / B / C
A 선택 시 커밋 메시지: 위 초안 OK / 수정 / 직접 작성 작업 시점: 지금 / 운영 데이터 1~2일 쌓고 / 주말
This commit is contained in:
48
kis_trader/backtest/backtest_web.py
Normal file
48
kis_trader/backtest/backtest_web.py
Normal file
@@ -0,0 +1,48 @@
|
||||
"""
|
||||
kis_trader/backtest/backtest_web.py — 기존 ``backtest_web.py`` 재사용 엔트리.
|
||||
|
||||
실행 예:
|
||||
python -m kis_trader.backtest.backtest_web
|
||||
|
||||
내부에서 프로젝트 루트의 ``backtest_web.py`` 를 import 해서 main 을 호출한다.
|
||||
기존 scalping_engine / tail_engine 을 공유하므로 백테스트-실매매 간 로직 일치 보장.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
|
||||
def _ensure_root_on_path() -> None:
|
||||
root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
if root not in sys.path:
|
||||
sys.path.insert(0, root)
|
||||
|
||||
|
||||
def main() -> None:
|
||||
_ensure_root_on_path()
|
||||
import backtest_web as _bw # type: ignore
|
||||
|
||||
# 1순위: 루트 backtest_web 에 main() 이 정의되어 있으면 그대로 호출
|
||||
fn = getattr(_bw, "main", None)
|
||||
if callable(fn):
|
||||
fn()
|
||||
return
|
||||
|
||||
# 2순위: Flask `app` 객체가 있으면 직접 기동 (원본의 `if __name__ == "__main__":`
|
||||
# 블록은 import 경로에서 동작하지 않으므로 여기서 명시적으로 실행)
|
||||
app = getattr(_bw, "app", None)
|
||||
if app is not None and hasattr(app, "run"):
|
||||
host = os.environ.get("BT_WEB_HOST", "0.0.0.0")
|
||||
port = int(os.environ.get("BT_WEB_PORT", "5050"))
|
||||
print(f"🚀 Backtest Web 기동: http://{host}:{port}", flush=True)
|
||||
app.run(host=host, port=port, debug=False)
|
||||
return
|
||||
|
||||
# 3순위(fallback): 스크립트 스타일 파일을 `__main__` 으로 재실행
|
||||
import runpy
|
||||
runpy.run_path(_bw.__file__, run_name="__main__")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user