fix: current_price=0 stop-loss 오발동 및 해외 주문 소수점 초과 수정 (#251, #252) #253

Merged
jihoson merged 1 commits from feature/issue-251-252-trading-cycle-guards into main 2026-02-25 02:30:01 +09:00
Collaborator

Summary

모니터링 중 발견된 두 버그를 수정합니다.

  • #251 current_price=0 시 stop-loss/take-profit 오발동 → HOLD가 잘못 SELL로 전환
  • #252 해외 주문 가격 round(x, 4) → KIS 1$이상 소수점 2자리까지만 가능 거절

Root Cause & Fix

Fix 1: stop-loss 가드 (src/main.py)

현재가 API가 0.0을 반환하면 loss_pct = (0 - entry) / entry = -100% → stop-loss 오발동.
이로 인해 overseas_price=0ORD_DVSN="01"(시장가)주문구분 입력오류 연쇄 발생.

# Before
if entry_price > 0:
# After
if entry_price > 0 and current_price > 0:

Fix 2: 해외 주문 가격 소수점 (src/main.py)

KIS API는 $1 이상 종목에 소수점 2자리 제한. 페니스탁(< $1)은 4자리 유지.

_price_decimals = 2 if current_price >= 1.0 else 4
overseas_price = round(current_price * 1.002, _price_decimals)

Test plan

  • test_stop_loss_not_triggered_when_current_price_is_zero — current_price=0일 때 SELL 주문 없음
  • test_overseas_buy_price_rounded_to_2_decimals_for_dollar_plus_stock — $50 주식 → 2자리
  • test_overseas_penny_stock_price_keeps_4_decimals — $0.57 주식 → 4자리
  • 기존 overseas limit price 테스트 expected_price 2자리로 갱신
  • 전체 885개 통과

Closes #251
Closes #252

🤖 Generated with Claude Code

## Summary 모니터링 중 발견된 두 버그를 수정합니다. - **#251** `current_price=0` 시 stop-loss/take-profit 오발동 → HOLD가 잘못 SELL로 전환 - **#252** 해외 주문 가격 `round(x, 4)` → KIS `1$이상 소수점 2자리까지만 가능` 거절 ## Root Cause & Fix ### Fix 1: stop-loss 가드 (`src/main.py`) 현재가 API가 0.0을 반환하면 `loss_pct = (0 - entry) / entry = -100%` → stop-loss 오발동. 이로 인해 `overseas_price=0` → `ORD_DVSN="01"(시장가)` → `주문구분 입력오류` 연쇄 발생. ```python # Before if entry_price > 0: # After if entry_price > 0 and current_price > 0: ``` ### Fix 2: 해외 주문 가격 소수점 (`src/main.py`) KIS API는 $1 이상 종목에 소수점 2자리 제한. 페니스탁(< $1)은 4자리 유지. ```python _price_decimals = 2 if current_price >= 1.0 else 4 overseas_price = round(current_price * 1.002, _price_decimals) ``` ## Test plan - [x] `test_stop_loss_not_triggered_when_current_price_is_zero` — current_price=0일 때 SELL 주문 없음 - [x] `test_overseas_buy_price_rounded_to_2_decimals_for_dollar_plus_stock` — $50 주식 → 2자리 - [x] `test_overseas_penny_stock_price_keeps_4_decimals` — $0.57 주식 → 4자리 - [x] 기존 overseas limit price 테스트 expected_price 2자리로 갱신 - [x] 전체 885개 통과 Closes #251 Closes #252 🤖 Generated with [Claude Code](https://claude.com/claude-code)
agentson added 1 commit 2026-02-25 02:28:58 +09:00
1. stop-loss/take-profit 가드에 current_price > 0 조건 추가 (#251)
   - 현재가 API 실패(0.0 반환) 시 loss_pct=-100% 계산으로 오발동되던 문제 수정
   - if entry_price > 0 → if entry_price > 0 and current_price > 0
   - LLY '주문구분 입력오류'는 이 오발동의 연쇄 결과(overseas_price=0 → ORD_DVSN='01')

2. 해외 주문 가격 소수점을 $1 이상은 2자리로 제한 (#252)
   - round(x, 4) → $1+ 종목은 round(x, 2), 페니스탁은 round(x, 4) 유지
   - KIS '1$이상 소수점 2자리까지만 가능' 오류(TQQQ) 수정

테스트:
- test_stop_loss_not_triggered_when_current_price_is_zero 추가
- test_overseas_buy_price_rounded_to_2_decimals_for_dollar_plus_stock 추가
- test_overseas_penny_stock_price_keeps_4_decimals 추가
- 기존 overseas limit price 테스트 expected_price 2자리로 갱신

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
jihoson merged commit adc5211fd2 into main 2026-02-25 02:30:01 +09:00
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: jihoson/The-Ouroboros#253