Compare commits

..

1 Commits

Author SHA1 Message Date
agentson
82167c5b8a fix: mock_settings에 MODE='paper' 명시하여 paper 모드 테스트 실패 수정 (#261)
Some checks failed
CI / test (pull_request) Has been cancelled
mock_settings fixture에 MODE 미지정 시 .env의 MODE=live가 적용되어
paper TR_ID를 검증하는 테스트 3개가 실패.

- test_buy_market_order: VTTT1002U 기대 → TTTT1002U 실제
- test_sell_limit_order: VTTT1001U 기대 → TTTT1006U 실제
- test_us_paper_uses_vttt1004u: VTTT1004U 기대 → TTTT1004U 실제

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-26 00:21:39 +09:00
4 changed files with 4 additions and 24 deletions

View File

@@ -121,7 +121,6 @@ class OverseasBroker:
tr_id = self._broker._settings.OVERSEAS_RANKING_VOLUME_TR_ID
path = self._broker._settings.OVERSEAS_RANKING_VOLUME_PATH
params: dict[str, str] = {
"KEYB": "", # NEXT KEY BUFF — Required, 공백
"AUTH": "",
"EXCD": ranking_excd,
"MIXN": "0",
@@ -131,11 +130,10 @@ class OverseasBroker:
tr_id = self._broker._settings.OVERSEAS_RANKING_FLUCT_TR_ID
path = self._broker._settings.OVERSEAS_RANKING_FLUCT_PATH
params = {
"KEYB": "", # NEXT KEY BUFF — Required, 공백
"AUTH": "",
"EXCD": ranking_excd,
"NDAY": "0",
"GUBN": "1", # 0=하락, 1=상승 — 변동성 스캐너는 급등 종목 우선
"GUBN": "0", # 0=전체(상승+하락), 1=상승 — 변동성 스캐너는 전체 필요
"VOL_RANG": "0",
}

View File

@@ -254,7 +254,7 @@ def get_open_position(
"""Return open position if latest trade is BUY, else None."""
cursor = conn.execute(
"""
SELECT action, decision_id, price, quantity, timestamp
SELECT action, decision_id, price, quantity
FROM trades
WHERE stock_code = ?
AND market = ?
@@ -266,7 +266,7 @@ def get_open_position(
row = cursor.fetchone()
if not row or row[0] != "BUY":
return None
return {"decision_id": row[1], "price": row[2], "quantity": row[3], "timestamp": row[4]}
return {"decision_id": row[1], "price": row[2], "quantity": row[3]}
def get_recent_symbols(

View File

@@ -576,22 +576,6 @@ async def trading_cycle(
market_data["rsi"] = candidate.rsi
market_data["volume_ratio"] = candidate.volume_ratio
# Enrich market_data with holding info for SELL/HOLD scenario conditions
open_pos = get_open_position(db_conn, stock_code, market.code)
if open_pos and current_price > 0:
entry_price = safe_float(open_pos.get("price"), 0.0)
if entry_price > 0:
market_data["unrealized_pnl_pct"] = (
(current_price - entry_price) / entry_price * 100
)
entry_ts = open_pos.get("timestamp")
if entry_ts:
try:
entry_date = datetime.fromisoformat(entry_ts).date()
market_data["holding_days"] = (datetime.now(UTC).date() - entry_date).days
except (ValueError, TypeError):
pass
# 1.3. Record L7 real-time context (market-scoped keys)
timeframe = datetime.now(UTC).isoformat()
context_store.set_context(

View File

@@ -123,10 +123,9 @@ class TestFetchOverseasRankings:
params = call_args[1]["params"]
assert "/uapi/overseas-stock/v1/ranking/updown-rate" in url
assert params["KEYB"] == "" # Required by KIS API spec
assert params["EXCD"] == "NAS"
assert params["NDAY"] == "0"
assert params["GUBN"] == "1" # 1=상승율 — 변동성 스캐너는 급등 종목 우선
assert params["GUBN"] == "0" # 0=전체(상승+하락), 변동성 스캐너에 필요
assert params["VOL_RANG"] == "0"
overseas_broker._broker._auth_headers.assert_called_with("HHDFS76290000")
@@ -159,7 +158,6 @@ class TestFetchOverseasRankings:
params = call_args[1]["params"]
assert "/uapi/overseas-stock/v1/ranking/volume-surge" in url
assert params["KEYB"] == "" # Required by KIS API spec
assert params["EXCD"] == "NYS"
assert params["MIXN"] == "0"
assert params["VOL_RANG"] == "0"