fix: overseas order uses limit price, not hardcoded 0 (#149) #150

Merged
jihoson merged 2 commits from feature/issue-149-overseas-limit-order-price into main 2026-02-19 05:50:31 +09:00
Collaborator

문제 요약 (Issue #149)

Issue #147 수정 이후 해외주식 주문이 전송되기 시작했으나 KIS VTS가 거부:

Overseas order submitted  ✓
Order result: 모의투자 주문처리가 안되었습니다(지정가만 가능한 상품입니다)  ✗

근본 원인

trading_cycle() (line 513)과 run_daily_session() (line 922)에서
해외주식 주문 시 price=0.0 하드코딩 → 시장가(ORD_DVSN="01") 전송.

KIS VTS는 해외주식 모의투자에서 시장가 주문을 거부하고 지정가만 허용.

Fix #147에서 이미 current_price를 올바르게 계산하고 있었으나 (get_overseas_price()
exchange code 매핑 + candidate.price 폴백), 이 값이 send_overseas_order() 호출 시
사용되지 않았음.

변경 내용

파일 변경 내용
src/main.py trading_cycle(), run_daily_session() 해외 주문에 price=0.0price=current_price
tests/test_main.py test_overseas_buy_order_uses_limit_price 추가 (가격 182.5 전달 검증)

참고

  • 국내 주식(send_order())은 price=0 유지 — KRX는 시장가 허용
  • 해외 주식만 지정가로 변경

테스트 결과

617 passed in 16.46s
TestOverseasBalanceParsing::test_overseas_buy_order_uses_limit_price ✓

Closes #149

## 문제 요약 (Issue #149) Issue #147 수정 이후 해외주식 주문이 전송되기 시작했으나 KIS VTS가 거부: ``` Overseas order submitted ✓ Order result: 모의투자 주문처리가 안되었습니다(지정가만 가능한 상품입니다) ✗ ``` ## 근본 원인 `trading_cycle()` (line 513)과 `run_daily_session()` (line 922)에서 해외주식 주문 시 `price=0.0` 하드코딩 → 시장가(ORD_DVSN="01") 전송. KIS VTS는 해외주식 모의투자에서 시장가 주문을 거부하고 지정가만 허용. Fix #147에서 이미 `current_price`를 올바르게 계산하고 있었으나 (`get_overseas_price()` exchange code 매핑 + candidate.price 폴백), 이 값이 `send_overseas_order()` 호출 시 사용되지 않았음. ## 변경 내용 | 파일 | 변경 내용 | |------|----------| | `src/main.py` | `trading_cycle()`, `run_daily_session()` 해외 주문에 `price=0.0` → `price=current_price` | | `tests/test_main.py` | `test_overseas_buy_order_uses_limit_price` 추가 (가격 182.5 전달 검증) | ## 참고 - 국내 주식(`send_order()`)은 `price=0` 유지 — KRX는 시장가 허용 - 해외 주식만 지정가로 변경 ## 테스트 결과 ``` 617 passed in 16.46s TestOverseasBalanceParsing::test_overseas_buy_order_uses_limit_price ✓ ``` Closes #149
agentson added 3 commits 2026-02-18 23:53:32 +09:00
fix: use smart rule-based fallback playbook when Gemini fails (issue #145)
Some checks failed
CI / test (pull_request) Has been cancelled
96e2ad4f1f
When gemini-2.5-flash quota is exhausted (20 RPD free tier), generate_playbook()
fell back to _defensive_playbook() which only had price_change_pct_below: -3.0 SELL
conditions — no BUY conditions — causing zero trades on US market despite scanner
finding strong momentum/oversold candidates.

Changes:
- Add _smart_fallback_playbook() that uses scanner signals to build BUY conditions:
  - momentum signal: BUY when volume_ratio_above=VOL_MULTIPLIER
  - oversold signal: BUY when rsi_below=RSI_OVERSOLD_THRESHOLD
  - always: SELL stop-loss at price_change_pct_below=-3.0
- Use _smart_fallback_playbook() instead of _defensive_playbook() on Gemini failure
- Add 10 new tests for _smart_fallback_playbook() covering momentum/oversold/empty cases
- Update existing test_gemini_failure_returns_defensive to match new behavior

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
fix: price API exchange code mapping and VTS overseas balance fallback (#147)
Some checks failed
CI / test (pull_request) Has been cancelled
3a54db8948
- Apply _PRICE_EXCHANGE_MAP in get_overseas_price() to send short codes
  (NASD→NAS, NYSE→NYS, AMEX→AMS) required by HHDFS00000300 price API
- Add PAPER_OVERSEAS_CASH config setting (default $50,000) for simulated
  USD balance when VTS overseas balance API returns 0 in paper mode
- Fall back to scan candidate price when live price API returns 0
- Both fixes together resolve "no affordable quantity (cash=0, price=0)"
  which was preventing all overseas trade execution

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
fix: use current_price for overseas limit orders (KIS VTS rejects market orders) (#149)
Some checks failed
CI / test (pull_request) Has been cancelled
ccc97ebaa9
KIS VTS (paper trading) rejects overseas market orders with:
  "모의투자 주문처리가 안되었습니다(지정가만 가능한 상품입니다)"

Root cause: send_overseas_order() was called with price=0.0 (market order)
in both trading_cycle() and run_daily_session(), even though current_price
was already computed correctly by Fix #147 (exchange code mapping).

Fix: pass current_price as the limit order price in both call sites.
Domestic broker send_order() keeps price=0 (market orders are fine on KRX).

Adds regression test TestOverseasBalanceParsing::test_overseas_buy_order_uses_limit_price
verifying price=182.5 is passed, not 0.0.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
agentson added 1 commit 2026-02-18 23:54:22 +09:00
docs: add requirements log entry for overseas limit order fix (#149)
Some checks failed
CI / test (pull_request) Has been cancelled
3952a5337b
jihoson merged commit cd1579058c into main 2026-02-19 05:50:31 +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#150