Changes: - Added a new API endpoint for managing permanent subscriptions, allowing users to enable or disable subscriptions dynamically. - Implemented a function to fill candle data from Kiwoom, ensuring that only relevant data is inserted into the database. - Introduced a mechanism to handle master subscription states, improving the management of subscription statuses. - Updated the database schema to include new fields for managing subscription states and order book filtering. Impact: - These enhancements improve the flexibility and reliability of the trading system, allowing for better management of subscriptions and order book data, while reducing the risk of data inconsistencies. 히스토리 align 제거 븅신같은 초기설계 아예 제거 진입모드에 구멍메움 호가진입을 켜도 호가가 안들어올때 호가 안보고 그냥 사버림
119 lines
3.7 KiB
Bash
Executable File
119 lines
3.7 KiB
Bash
Executable File
#!/bin/bash
|
|
# 웹 systemctl restart 로 SIGTERM 당한 seq 잡 재개용.
|
|
# - momentum: 기존 study 이어쓰기 (추가 trials = 목표-현재)
|
|
# - breakout/scalp: 원래 순차와 동일하게 새 study
|
|
set -euo pipefail
|
|
cd /home/hoon/kis_bot
|
|
mkdir -p logs kis_trader/backtest/results
|
|
|
|
START="${START:-2026-08-12}"
|
|
END="${END:-2026-08-13}"
|
|
TRIALS_TARGET="${TRIALS_TARGET:-400}"
|
|
MOM_STUDY="${MOM_STUDY:-momentum_tpe_20260812_20260813_20260814_014442}"
|
|
UNIVERSE_HISTORY_SOURCE="${UNIVERSE_HISTORY_SOURCE:-kiwoom}"
|
|
PY="${PY:-.venv/bin/python}"
|
|
TS0="$(date +%Y%m%d_%H%M%S)"
|
|
MASTER="logs/optuna_4strat_tpe_${START}_${END}_${TS0}_resume_master.log"
|
|
JOB_ID="${JOB_ID:-opt_20260814_014442_seq}"
|
|
|
|
{
|
|
echo "======== Optuna seq RESUME $(date -Is) ========"
|
|
echo "START=$START END=$END TRIALS_TARGET=$TRIALS_TARGET"
|
|
echo "MOM_STUDY=$MOM_STUDY JOB_ID=$JOB_ID"
|
|
echo "master_log=$MASTER"
|
|
} | tee -a "$MASTER"
|
|
echo "$MASTER" > logs/optuna_4strat_tpe_latest_master.logpath
|
|
|
|
# 현재 study trial 수 → 남은 횟수
|
|
MOM_DONE="$("$PY" - <<PY
|
|
import optuna
|
|
from kis_trader.backtest.optuna_common import resolve_optuna_storage_url
|
|
s = optuna.load_study(study_name="$MOM_STUDY", storage=resolve_optuna_storage_url())
|
|
print(len(s.trials))
|
|
PY
|
|
)"
|
|
MOM_LEFT=$(( TRIALS_TARGET - MOM_DONE ))
|
|
if [[ "$MOM_LEFT" -lt 1 ]]; then
|
|
MOM_LEFT=0
|
|
fi
|
|
echo "momentum done=$MOM_DONE left=$MOM_LEFT" | tee -a "$MASTER"
|
|
|
|
run_mom() {
|
|
local log="logs/optuna_momentum_tpe_${TS0}_resume.log"
|
|
echo "$log" > logs/optuna_momentum_tpe_latest.logpath
|
|
echo "$MOM_STUDY" > logs/optuna_momentum_tpe_latest.study
|
|
{
|
|
echo ""
|
|
echo "-------- [momentum] RESUME $(date -Is) study=$MOM_STUDY left=$MOM_LEFT --------"
|
|
} | tee -a "$MASTER"
|
|
if [[ "$MOM_LEFT" -le 0 ]]; then
|
|
echo "momentum already >= target — skip optimize" | tee -a "$MASTER"
|
|
return 0
|
|
fi
|
|
set +e
|
|
"$PY" -u kis_trader/backtest/param_search_optuna.py \
|
|
--strategy momentum --mode tpe \
|
|
--start "$START" --end "$END" \
|
|
--trials "$MOM_LEFT" \
|
|
--min_trades 1 --min_win_rate 0 --min_pf 0 \
|
|
--orderbook-filter off --no-progress \
|
|
--study-name "$MOM_STUDY" \
|
|
--sort-by score \
|
|
--universe-history-source "$UNIVERSE_HISTORY_SOURCE" \
|
|
>"$log" 2>&1
|
|
local rc=$?
|
|
set -e
|
|
{
|
|
echo "-------- [momentum] END rc=$rc $(date -Is) --------"
|
|
echo "LOG=$log"
|
|
grep -E 'OPTUNA_RESULT_JSON=|OPTUNA_BRIEFING_MD=|❌|Traceback' "$log" | tail -n 20 || true
|
|
} | tee -a "$MASTER"
|
|
return 0
|
|
}
|
|
|
|
run_one() {
|
|
local strat="$1"
|
|
local ts study log sort_by
|
|
ts="$(date +%Y%m%d_%H%M%S)"
|
|
study="${strat}_tpe_${START//-/}_${END//-/}_${ts}"
|
|
log="logs/optuna_${strat}_tpe_${ts}.log"
|
|
sort_by="pnl"
|
|
case "$strat" in
|
|
momentum|us_momentum|scalp) sort_by="score" ;;
|
|
esac
|
|
{
|
|
echo ""
|
|
echo "-------- [$strat] START $(date -Is) study=$study univ=$UNIVERSE_HISTORY_SOURCE --------"
|
|
} | tee -a "$MASTER"
|
|
echo "$log" > "logs/optuna_${strat}_tpe_latest.logpath"
|
|
echo "$study" > "logs/optuna_${strat}_tpe_latest.study"
|
|
set +e
|
|
"$PY" -u kis_trader/backtest/param_search_optuna.py \
|
|
--strategy "$strat" --mode tpe \
|
|
--start "$START" --end "$END" \
|
|
--trials "$TRIALS_TARGET" \
|
|
--min_trades 1 --min_win_rate 0 --min_pf 0 \
|
|
--orderbook-filter off --no-progress \
|
|
--study-name "$study" \
|
|
--sort-by "$sort_by" \
|
|
--universe-history-source "$UNIVERSE_HISTORY_SOURCE" \
|
|
>"$log" 2>&1
|
|
local rc=$?
|
|
set -e
|
|
{
|
|
echo "-------- [$strat] END rc=$rc $(date -Is) --------"
|
|
echo "LOG=$log"
|
|
grep -E 'OPTUNA_RESULT_JSON=|OPTUNA_BRIEFING_MD=|❌|Traceback' "$log" | tail -n 20 || true
|
|
} | tee -a "$MASTER"
|
|
return 0
|
|
}
|
|
|
|
run_mom
|
|
run_one breakout
|
|
run_one scalp
|
|
|
|
{
|
|
echo ""
|
|
echo "======== ALL DONE $(date -Is) ========"
|
|
} | tee -a "$MASTER"
|