fix: current_price=0 stop-loss 오발동 및 해외 주문 소수점 초과 수정 (#251, #252)
Some checks failed
CI / test (pull_request) Has been cancelled
Some checks failed
CI / test (pull_request) Has been cancelled
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>
This commit is contained in:
@@ -730,7 +730,7 @@ async def trading_cycle(
|
||||
open_position = get_open_position(db_conn, stock_code, market.code)
|
||||
if open_position:
|
||||
entry_price = safe_float(open_position.get("price"), 0.0)
|
||||
if entry_price > 0:
|
||||
if entry_price > 0 and current_price > 0:
|
||||
loss_pct = (current_price - entry_price) / entry_price * 100
|
||||
stop_loss_threshold = -2.0
|
||||
take_profit_threshold = 3.0
|
||||
@@ -925,10 +925,13 @@ async def trading_cycle(
|
||||
# - SELL: -0.2% below last price — ensures fill even when price dips slightly
|
||||
# (placing at exact last price risks no-fill if the bid is just below).
|
||||
overseas_price: float
|
||||
# KIS requires at most 2 decimal places for prices >= $1 (≥1달러 소수점 2자리 제한).
|
||||
# Penny stocks (< $1) keep 4 decimal places to preserve price precision.
|
||||
_price_decimals = 2 if current_price >= 1.0 else 4
|
||||
if decision.action == "BUY":
|
||||
overseas_price = round(current_price * 1.002, 4)
|
||||
overseas_price = round(current_price * 1.002, _price_decimals)
|
||||
else:
|
||||
overseas_price = round(current_price * 0.998, 4)
|
||||
overseas_price = round(current_price * 0.998, _price_decimals)
|
||||
result = await overseas_broker.send_overseas_order(
|
||||
exchange_code=market.exchange_code,
|
||||
stock_code=stock_code,
|
||||
|
||||
Reference in New Issue
Block a user