fix: domestic order price — wrong orderbook field + missing KRX tick rounding #157

Closed
opened 2026-02-19 12:35:19 +09:00 by agentson · 0 comments
Collaborator

문제

1. 현재가 조회 오류 (price=0.00)

  • get_orderbook()inquire-asking-price-exp-ccn API를 사용
  • output1.stck_prpr 필드가 해당 API에 없음 → 항상 0 반환
  • 결과: Skip BUY: no affordable quantity (cash=10000000.00, price=0.00) 로그 반복

2. KRX 호가단위 미적용 (호가단위 오류)

  • 현재가를 그대로 주문 가격으로 사용
  • KRX 호가단위 미달 시 모의투자 주문처리가 안되었습니다(호가단위 오류) 발생
  • 예: 188,150원 → 100원 단위 미달

수정 방법

1. kis_api.pyget_current_price(stock_code) 추가

  • FHKST01010100 TR_ID, /uapi/domestic-stock/v1/quotations/inquire-price 사용
  • VTS에서 정상 작동 확인 (188,600원 반환)

2. kis_api.py에 KRX 호가단위 내림 함수 추가 및 주문 시 적용

  • kr_tick_unit(price) → KRX 호가단위 반환
  • round_down_to_tick(price) → 호가단위 내림 적용
  • send_order() 또는 main.py에서 주문 가격에 적용

3. main.py에서 현재가 조회 방식 변경

  • 기존: orderbook.get('output1', {}).get('stck_prpr', '0')
  • 변경: await broker.get_current_price(stock_code)

영향

  • 국내 실시간 거래에서 가격이 항상 0으로 조회되어 모든 매수가 건너뛰어짐
  • VTS 주문 시 호가단위 오류로 주문 실패
## 문제 ### 1. 현재가 조회 오류 (price=0.00) - `get_orderbook()`는 `inquire-asking-price-exp-ccn` API를 사용 - `output1.stck_prpr` 필드가 해당 API에 없음 → 항상 0 반환 - 결과: `Skip BUY: no affordable quantity (cash=10000000.00, price=0.00)` 로그 반복 ### 2. KRX 호가단위 미적용 (호가단위 오류) - 현재가를 그대로 주문 가격으로 사용 - KRX 호가단위 미달 시 `모의투자 주문처리가 안되었습니다(호가단위 오류)` 발생 - 예: 188,150원 → 100원 단위 미달 ## 수정 방법 ### 1. `kis_api.py`에 `get_current_price(stock_code)` 추가 - `FHKST01010100` TR_ID, `/uapi/domestic-stock/v1/quotations/inquire-price` 사용 - VTS에서 정상 작동 확인 (188,600원 반환) ### 2. `kis_api.py`에 KRX 호가단위 내림 함수 추가 및 주문 시 적용 - `kr_tick_unit(price)` → KRX 호가단위 반환 - `round_down_to_tick(price)` → 호가단위 내림 적용 - `send_order()` 또는 `main.py`에서 주문 가격에 적용 ### 3. `main.py`에서 현재가 조회 방식 변경 - 기존: `orderbook.get('output1', {}).get('stck_prpr', '0')` - 변경: `await broker.get_current_price(stock_code)` ## 영향 - 국내 실시간 거래에서 가격이 항상 0으로 조회되어 모든 매수가 건너뛰어짐 - VTS 주문 시 호가단위 오류로 주문 실패
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: jihoson/The-Ouroboros#157