feat: add time stop rule for stale positions

Sell position if held for TIME_STOP_HOURS (default 24h) with less than
TIME_STOP_MIN_GAIN_PCT (default +3%) gain. Frees up capital for
fresh momentum opportunities.

Priority: trailing stop (-10%) checked first, then time stop.
Both thresholds configurable via .env.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
joungmin
2026-02-28 10:23:32 +09:00
parent 83bd51117f
commit 0713fb1e11
3 changed files with 78 additions and 23 deletions

View File

@@ -6,6 +6,7 @@ import logging
import os
import threading
import time
from datetime import datetime
from typing import Optional
import pyupbit
@@ -21,7 +22,7 @@ PER_POSITION = MAX_BUDGET // MAX_POSITIONS # 종목당 33만3천원
_lock = threading.Lock()
_positions: dict = {}
# 구조: { ticker: { buy_price, peak_price, amount, invested_krw } }
# 구조: { ticker: { buy_price, peak_price, amount, invested_krw, entry_time } }
_upbit: Optional[pyupbit.Upbit] = None
@@ -73,6 +74,7 @@ def buy(ticker: str) -> bool:
"peak_price": current,
"amount": amount,
"invested_krw": order_krw,
"entry_time": datetime.now(),
}
logger.info(
f"[매수] {ticker} @ {current:,.0f}원 | "