feat: Enhance trading system with new permanent subscription features and order book management

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 제거 븅신같은 초기설계 아예 제거
진입모드에 구멍메움
호가진입을 켜도 호가가 안들어올때 호가 안보고 그냥 사버림
This commit is contained in:
Your Name
2026-08-15 23:01:14 +09:00
parent 4a18ce2697
commit 36a3e2b4a1
94 changed files with 6368 additions and 1639 deletions

View File

@@ -26,6 +26,9 @@ MIN_PF="${MIN_PF:-0}"
# STRATEGIES="momentum tail" bash ...
# STRATEGIES="us_momentum momentum" bash ...
STRATEGIES="${STRATEGIES:-momentum tail breakout scalp}"
# 꼬리 TPE 진입모드 — 한 스터디에 섞지 않음. 공백 구분 시 순차 2회.
# TAIL_OPTUNA_ENTRY_MODES="align limit_atr"
TAIL_OPTUNA_ENTRY_MODES="${TAIL_OPTUNA_ENTRY_MODES:-align}"
# kiwoom|ls — 웹 Optuna 이력소스 / CLI UNIVERSE_HISTORY_SOURCE
UNIVERSE_HISTORY_SOURCE="${UNIVERSE_HISTORY_SOURCE:-${BACKTEST_UNIVERSE_HISTORY_SOURCE:-kiwoom}}"
PY="${PY:-.venv/bin/python}"
@@ -36,6 +39,7 @@ MASTER="logs/optuna_4strat_tpe_${START}_${END}_${TS0}_master.log"
echo "======== Optuna 4전략 TPE 순차 시작 $(date -Is) ========"
echo "START=$START END=$END MODE=$MODE TRIALS=$TRIALS"
echo "STRATEGIES=$STRATEGIES"
echo "TAIL_OPTUNA_ENTRY_MODES=$TAIL_OPTUNA_ENTRY_MODES"
echo "UNIVERSE_HISTORY_SOURCE=$UNIVERSE_HISTORY_SOURCE"
echo "min_wr=$MIN_WIN_RATE min_pf=$MIN_PF min_trades=$MIN_TRADES"
echo "apply-best=OFF orderbook=off n_jobs=1 (사후 results_gated + briefing.md)"
@@ -47,10 +51,15 @@ echo "$MASTER" > logs/optuna_4strat_tpe_latest_master.logpath
run_one() {
local strat="$1"
local entry_mode="${2:-}"
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"
if [[ "$strat" == "tail" && -n "$entry_mode" ]]; then
study="${strat}_${entry_mode}_tpe_${START//-/}_${END//-/}_${ts}"
log="logs/optuna_${strat}_${entry_mode}_tpe_${ts}.log"
fi
sort_by="pnl"
case "$strat" in
momentum|us_momentum|scalp) sort_by="score" ;;
@@ -58,7 +67,7 @@ run_one() {
{
echo ""
echo "-------- [$strat] START $(date -Is) study=$study univ=$UNIVERSE_HISTORY_SOURCE --------"
echo "-------- [$strat${entry_mode:+/$entry_mode}] 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"
@@ -80,6 +89,9 @@ run_one() {
--sort-by "$sort_by"
--universe-history-source "$UNIVERSE_HISTORY_SOURCE"
)
if [[ "$strat" == "tail" && -n "$entry_mode" ]]; then
cmd_args+=(--entry-mode "$entry_mode")
fi
if [[ -n "${TICK_SOURCE:-}" ]]; then
cmd_args+=("--tick-source" "$TICK_SOURCE")
@@ -93,7 +105,7 @@ run_one() {
set -e
{
echo "-------- [$strat] END rc=$rc $(date -Is) --------"
echo "-------- [$strat${entry_mode:+/$entry_mode}] END rc=$rc $(date -Is) --------"
echo "LOG=$log"
grep -E 'OPTUNA_RESULT_JSON=|OPTUNA_BRIEFING_MD=|Best trial|optuna_best|❌|KeyError|Traceback' "$log" | tail -n 24 || true
} | tee -a "$MASTER"
@@ -105,7 +117,13 @@ run_one() {
}
for s in $STRATEGIES; do
run_one "$s"
if [[ "$s" == "tail" ]]; then
for em in $TAIL_OPTUNA_ENTRY_MODES; do
run_one tail "$em"
done
else
run_one "$s"
fi
done
{