feat: Enhance Optuna integration and logging for backtesting framework

Changes:
- Added new API endpoints for continuing and confirming Optuna jobs, allowing for better management of ongoing studies.
- Introduced detailed logging for tick feed tracking and order book processing, improving traceability of vendor performance during backtests.
- Updated database schema to include new fields for managing Optuna study results, enhancing the ability to track study progress and outcomes.
- Refactored existing functions to utilize the new logging and tracking features, ensuring consistency across the backtesting framework.

Impact:
- These enhancements improve the robustness and transparency of the Optuna backtesting process, facilitating better analysis and optimization of trading strategies.
This commit is contained in:
Your Name
2026-08-21 19:05:23 +09:00
parent 0ecac7cb95
commit 0780b2cdd0
76 changed files with 4648 additions and 516 deletions

View File

@@ -188,17 +188,28 @@ def build_live_config_groups() -> List[GroupDef]:
"갭보정은 키움 REST만. 영구구독 KR은 LS WS."
),
"fields": [
_f("LIVE_TICK_PROVIDER", "📊 실매매 틱(시세) 소스 (재시작 필요)", "text", default="kiwoom",
_f("LIVE_TICK_PROVIDER", "📊 실매매 틱(시세) 소스 (재시작 필요)", "select", default="kiwoom",
choices=[
{"value": "kiwoom", "label": "키움 (kiwoom)"},
{"value": "kis", "label": "한투 (kis)"},
],
hint=(
"get_price 가 어느 RAM 을 먼저 볼지(1차). 폴백 나이 넘으면 실패로 보고 "
"2차(상대 체결소켓)→3차(LS)→매도는 4차 키움 REST(ka10007). "
"한투 60초 캐시는 안 씀. MINIMAL 이면 한투 RAM 은 보유만"
"1차 RAM. 키움=kiwoom / 한투=kis. LS는 여기 없음(3차 spill). "
"폴백 나이 넘으면 실패로 보고 2차(상대 체결소켓)→3차(LS)→매도는 4차 키움 REST(ka10007). "
"한투 60초 캐시는 안 씀. MINIMAL 이면 한투 RAM 은 보유만. "
"저장 후 kis_trader_main 재시작"
)),
_f("LIVE_OB_PROVIDER", "📊 실매매 호가(OB) 소스 (재시작 필요)", "text", default="kiwoom",
_f("LIVE_OB_PROVIDER", "📊 실매매 호가(OB) 소스 (재시작 필요)", "select", default="kiwoom",
choices=[
{"value": "kiwoom", "label": "키움 (kiwoom)"},
{"value": "kis", "label": "한투 (kis)"},
],
hint=(
"호가 1차. 폴백 나이 넘으면 그 벤더는 없는 것과 같고 2차→3차(LS UH1). "
"호가 1차. 키움=kiwoom / 한투=kis. LS는 여기 없음(3차 UH1). "
"폴백 나이 넘으면 그 벤더는 없는 것과 같고 2차→3차. "
"만료로 None 만 만들어서 필터 ON 통과 구멍을 만들지 않음. "
"kis 선택 시 아래 'KIS 실시간 호가 수집' ON"
"kis 선택 시 아래 'KIS 실시간 호가 수집' ON + 2번째 앱키(KIS_APP_KEY_OB_REAL). "
"저장 후 kis_trader_main 재시작"
)),
_f("LIVE_FEED_FALLBACK_MAX_AGE_SEC", "⏱ 시세·호가 읽기 폴백 나이(초)", "float", default=3.0,
hint=(
@@ -208,6 +219,18 @@ def build_live_config_groups() -> List[GroupDef]:
"넘기면 그 벤더 실패. 적재(공책)와 분리. 기본 3. "
"분봉 쓰레기 판정 나이도 이 값(봉 끝시각 대비)."
)),
_f("TRIGGER_FEED_DETAIL_LOG", "📝 트리거 로그에 틱·호가·벤더 상세", "bool", default=True,
hint=(
"ON=매수체크(🔍) 로그 끝에 틱1차설정/실제(kis|kiwoom|ls)·현재가·틱타임·"
"호가 bid/ask/잔량비·스냅시각을 붙임. OFF=접두 T/O/R 만. 재시작 없이 반영(수 초)"
)),
_f("BT_FEED_DETAIL_LOG", "📝 옵투나/백테에도 틱·호가 벤더 추적", "bool", default=True,
hint=(
"ON=옵투나·백테 로그에 틱/호가 로드 벤더 비율 + TRIGGER 샘플 "
"(실매 TRIGGER_FEED_DETAIL_LOG 과 같은 축). OFF=샘플만 끔(비율 INFO는 유지)"
)),
_f("BT_FEED_DETAIL_LOG_MAX", "옵투나 TRIGGER 샘플 상한(건)", "int", default=40,
hint="프로세스당 매수 후보 상세 샘플 최대. 0=샘플 없음. 기본 40"),
_f("CANDLE_GARBAGE_FALLBACK", "🕯 분봉 쓰레기→2차·3차 봉 통째", "bool", default=True,
hint=(
"ON(기본)=그 분 메인 틱이 0건이거나 전부 봉끝 대비 읽기나이 초과면 "
@@ -403,6 +426,17 @@ def build_live_config_groups() -> List[GroupDef]:
default=30.0,
hint="죽은선 REST를 종목당 이 초마다 1회. 유량 보호. 코드 기본 30",
),
_f(
"SELL_WS_LAST_RAM_MAX_AGE_SEC",
"⏱ 매도 last-RAM 허용나이(초)",
"float",
default=30.0,
hint=(
"3초 체인 실패 시 마지막 WS RAM을 이 초까지 매도에 사용. "
"FID20 동결(패킷나이 초과)은 거부. 0=last-RAM 안 씀. "
"그 다음 직전가 캐시 → 키움 ka10007"
),
),
_f(
"WS_ORDERBOOK_FILTER_REJECT_IF_EMPTY",
"⛔ 호가 사진 없으면 매수 안 함",