os.getenv("MODE")는 .env 파일을 읽지 못해 항상 paper를 반환함.
create_dashboard_app에 mode 파라미터 추가 후 main.py에서
settings.MODE를 직접 전달하도록 수정.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- /api/status 응답에 MODE 환경변수 기반 mode 필드 추가
- 대시보드 헤더에 모드 배지 표시 (live=빨간색 깜빡임, paper=노란색)
- 모드 관련 테스트 3개 추가 (total 26 passed)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- _extract_held_codes_from_balance / _extract_held_qty_from_balance:
해외 잔고 수량 필드를 ovrs_cblc_qty(총 보유수량) → ord_psbl_qty(주문가능수량)
우선으로 변경. KIS 공식 문서(VTTS3012R) 확인 결과 ord_psbl_qty가 실제
매도 가능 수량이며, ovrs_cblc_qty는 만료/결제 미완료 포지션을 포함함.
MLECW 등 만료된 Warrant는 ovrs_cblc_qty=289456이지만 ord_psbl_qty=0이라
startup sync 대상에서 제외되고 SELL 수량도 0이 됨.
- trading_cycle: 해외 SELL이 '잔고내역이 없습니다'로 실패할 때 DB 포지션을
ghost-close SELL 로그로 닫아 무한 재시도 방지. exchange code 불일치 등
예외 상황에서 DB가 계속 open 상태로 남는 문제 해소.
- docstring: _extract_held_qty_from_balance 해외 필드 설명 업데이트
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- KISBroker에 get_domestic_pending_orders (TTTC0084R, 실전전용)
및 cancel_domestic_order (실전 TTTC0013U / 모의 VTTC0013U) 추가
- main.py 국내 주문 price=0 → 지정가 전환 (2곳):
· BUY +0.2% / SELL -0.2%, kr_round_down으로 KRX 틱 반올림 적용
- handle_domestic_pending_orders 함수 추가:
· BUY 미체결 → 취소 + buy_cooldown 설정
· SELL 미체결 → 취소 후 -0.4% 재주문 (최대 1회)
- daily/realtime 두 모드 market 루프 내 domestic pending 호출 추가
(sell_resubmit_counts는 해외용과 공유, key prefix "KR:" vs 거래소코드)
- 테스트 14개 추가:
· test_broker.py: TestGetDomesticPendingOrders 3개 + TestCancelDomesticOrder 5개
· test_main.py: TestHandleDomesticPendingOrders 4개 + TestDomesticLimitOrderPrice 2개
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- OverseasBroker에 get_overseas_pending_orders (TTTS3018R, 실전전용)
및 cancel_overseas_order (거래소별 TR_ID, hashkey 필수) 추가
- TelegramClient에 notify_unfilled_order 추가
(BUY취소=MEDIUM, SELL미체결=HIGH 우선순위)
- handle_overseas_pending_orders 함수 추가:
· BUY 미체결 → 취소 + 쿨다운 설정
· SELL 미체결 → 취소 후 -0.4% 재주문 (최대 1회)
· 미국 거래소(NASD/NYSE/AMEX) 중복 조회 방지
- daily/realtime 두 모드 모두 market 루프 시작 전 호출
- 테스트 13개 추가 (test_overseas_broker.py 8개, test_main.py 5개)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
기존 정책(BUY +0.5%, SELL 현재가)의 두 가지 문제를 해결:
- BUY 0.5% 버퍼는 대형주에서 불필요한 과다 지불 유발 ($50K 규모에서 연간 수십 달러 손실)
- SELL 현재가 지정가는 가격이 소폭 하락 시 미체결 위험 (bid < last_price 구간)
변경:
- BUY: current_price * 1.005 → current_price * 1.002 (+0.2%)
대형주 기준 90%+ 체결률 유지하면서 과다 지불 최소화
- SELL: current_price → current_price * 0.998 (-0.2%)
bid가 last_price 아래일 때도 체결 보장
- VTS(paper)와 live 동일 정책 적용 — 더 현실적인 시뮬레이션
- KIS 시장가 주문은 상한가 기준 수량 계산 버그로 사용 안 함(유지)
테스트:
- test_overseas_buy_order_uses_limit_price: 1.005 → 1.002 업데이트
- test_overseas_sell_order_uses_limit_price_below_current: 신규 추가
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- sync_positions_from_broker() 함수 추가
- 시스템 시작 시 브로커 잔고를 조회해 DB에 없는 포지션을 BUY 레코드로 삽입
- 국내: get_balance(), 해외: get_overseas_balance(exchange_code) 순회
- ConnectionError는 경고 로그만 남기고 계속 진행 (non-fatal)
- 동일 exchange_code 중복 조회 방지 (seen_exchange_codes 집합)
- run() 초기화 후 최초 한 번 자동 호출
- 국내주식 BUY 이중 방지 로직 확장
- trading_cycle 및 run_daily_session에서 기존에 해외 전용(not market.is_domestic)
으로만 적용하던 broker balance 체크를 국내/해외 공통으로 변경
- _extract_held_qty_from_balance(is_domestic=market.is_domestic)
- 테스트 (827 passed)
- TestSyncPositionsFromBroker (6개): 국내/해외 동기화, 중복 skip, 공란, ConnectionError, dedup
- TestDomesticBuyDoublePreventionTradingCycle (1개): 국내 보유 주식 BUY 억제
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- run_daily_session에 daily_start_eval 파라미터 추가 (반환 타입: float)
- 세션 첫 잔고 조회 시 total_eval을 baseline으로 캡처
- 이후 세션에서 pnl_pct = (total_eval - daily_start_eval) / daily_start_eval
- 기존 purchase_total(누적) 기반 계산 제거
- run 함수 daily 루프에서 날짜 변경 시 baseline 리셋 (_cb_last_date 추적)
- early return 시 daily_start_eval 반환하도록 버그 수정 (None 반환 방지)
- TestDailyCBBaseline 클래스 4개 테스트 추가
- no_markets: 0.0/기존값 그대로 반환
- first session: total_eval을 baseline으로 캡처
- subsequent session: 기존 baseline 유지 (덮어쓰기 방지)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- _retry_connection() 헬퍼 추가: MAX_CONNECTION_RETRIES(3회) 지수 백오프
(2^attempt 초) 재시도, 읽기 전용 API 호출에만 적용 (주문 제외)
- run_daily_session(): get_current_price / get_overseas_price 호출에 적용
- run_daily_session(): get_balance / get_overseas_balance 호출에 적용
- 잔고 조회 전체 실패 시 해당 마켓을 skip하고 다른 마켓은 계속 처리
- 테스트 5개 추가: TestRetryConnection 클래스
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- trades 테이블에 mode TEXT DEFAULT 'paper' 컬럼 추가
- 기존 DB 마이그레이션: ALTER TABLE으로 mode 컬럼 자동 추가
- log_trade() 함수에 mode 파라미터 추가 (기본값 'paper')
- trading_cycle(), run_daily_session()에서 settings.MODE 전달
- 테스트 5개 추가 (mode 저장, 기본값, 스키마 검증, 마이그레이션)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- #210: init_db()에 WAL 저널 모드 적용 (파일 DB에만, :memory: 제외)
- 대시보드(READ)와 거래루프(WRITE) 동시 접근 시 SQLite 락 오류 방지
- busy_timeout=5000ms 설정
- #213: RATE_LIMIT_RPS 기본값 2.0으로 통일 (.env.example이 5.0으로 잘못 표기됨)
- #216: .env.example 중요 변수 추가 및 정리
- KIS_BASE_URL 모의/실전 URL 주석 명시 (포트 29443 수정 포함)
- MODE, TRADE_MODE, ENABLED_MARKETS, PAPER_OVERSEAS_CASH 추가
- GEMINI_MODEL 업데이트 (gemini-pro → gemini-2.0-flash-exp)
- DASHBOARD 설정 섹션 추가
테스트 2개 추가 (WAL 파일 DB 적용, 메모리 DB 미적용 검증)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
KIS VTS는 SELL 지정가 주문을 접수 즉시 rt_cd=0으로 반환하지만
실제 체결은 시장가 도달 시까지 지연된다. 이 기간 동안 DB는 포지션을
"종료"로 기록해 다음 사이클에서 이중 매수가 발생할 수 있었다.
- trading_cycle(): BUY 게이팅에 브로커 잔고 추가 확인 로직 삽입
- run_daily_session(): 동일 패턴의 BUY 중복 방지 로직 추가
- 두 함수 모두 이미 fetch된 balance_data 재사용 (추가 API 호출 없음)
- TestOverseasBrokerIntegration 클래스에 테스트 2개 추가
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
대시보드 표시 전용 데이터를 AI 의사결정용 context tree에 저장하는 것은
관심사 분리 위반. system_metrics 경량 테이블을 신설하여 완전히 분리. (PR #197 코드리뷰 반영)
- db.py: system_metrics 테이블 추가 (key/value/updated_at)
- main.py: context_store.set_context(L6_DAILY) → db_conn.execute(system_metrics)
- app.py: contexts 쿼리 → system_metrics 쿼리
- tests: _seed_cb_context를 system_metrics 삽입으로 변경
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- trading_cycle()의 L7 context에 portfolio_pnl_pct_{market} 저장 추가
→ 대시보드가 최신 pnl_pct를 DB에서 직접 조회 가능해짐
- /api/status 응답에 circuit_breaker 섹션 추가
(threshold_pct, current_pnl_pct, status: ok/warning/tripped/unknown)
- warning: CB 임계값까지 1% 이내 (-2.0% 이하)
- tripped: 임계값(-3.0%) 이하
- 대시보드 헤더에 CB 게이지 추가 (점멸 도트 + 진행 바 + 수치)
- ok: 녹색, warning: 오렌지 점멸, tripped: 빨간 점멸
- CB 상태 테스트 4개 추가 (ok/warning/tripped/unknown)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- /api/positions 엔드포인트 신설: 마지막 거래가 BUY인 종목을 오픈 포지션으로 반환
- _connect()에 WAL 모드 + busy_timeout=8000 추가 (트레이딩 루프와 동시 읽기 안전)
- init_db()에 idx_trades_stock_market_ts 인덱스 추가 (포지션 쿼리 최적화)
- index.html: 카드와 P&L 차트 사이에 포지션 패널 삽입 (종목/시장/수량/진입가/보유시간)
- 포지션 패널 테스트 3개 추가 (open BUY 반환, SELL 제외, 빈 DB 처리)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
어제(2026-02-20) 거래 로그에서 NP 7번, KNRX 5번 중복 매수 발생.
trading_cycle()의 BUY 브랜치에 get_open_position() 체크를 추가하여
이미 보유 중인 종목은 HOLD로 전환, 재매수를 차단함.
- src/main.py: BUY 결정 직후 기존 포지션 확인 → 있으면 HOLD 변환
- tests/test_main.py: 테스트 2개 추가
- test_buy_suppressed_when_open_position_exists
- test_buy_proceeds_when_no_open_position
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
KIS 공식 문서(20260221) '해외주식 주문' 시트 확인 결과:
- 모의투자 미국 매수: VTTT1002U (기존 정상)
- 모의투자 미국 매도: VTTT1001U (기존 VTTT1006U → 잘못된 TR_ID)
VTTT1006U는 존재하지 않는 TR_ID로, 모든 해외 SELL 주문이
"모의투자에서는 해당업무가 제공되지 않습니다." 오류로 거부되었음.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
SELL 주문은 현금을 소비하지 않고 받는 것이므로 Fat Finger 체크 대상이
아님. 포지션 가치가 잔여 현금의 30%를 초과해도 SELL은 정상 실행돼야 함.
- realtime/daily 사이클 두 곳 모두 수정
- SELL: check_circuit_breaker만 호출 (Fat Finger 스킵)
- BUY: 기존대로 validate_order 호출 (Fat Finger + Circuit Breaker)
- 테스트 2개 추가: SELL Fat Finger 스킵, SELL 서킷브레이커 적용 확인
재현 사례 (2026-02-21):
JELD stop-loss -6.20% → FAT FINGER: 49,548 is 99.1% of cash 50,000
RXT take-profit +46.13% → FAT FINGER: 88,676 is 177.4% of cash 50,000
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
409 충돌 감지 시 30초 백오프 후 재시도하는 방식에서
_running = False로 polling을 즉시 중단하는 방식으로 변경.
다중 인스턴스가 실행 중인 경우 재시도는 의미 없고 충돌만 반복됨.
이제 409 발생 시 이 프로세스의 Telegram 명령어 polling을 완전히 비활성화.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
SmartScanner의 implied_rsi 공식에서 계수를 4.0에서 2.0으로 수정.
12.5% 이상 변동률에서 RSI=100으로 포화되던 문제를 개선.
변경 전: 50 + (change_rate * 4.0) → 12.5% 변동 시 RSI=100
변경 후: 50 + (change_rate * 2.0) → 25% 변동 시 RSI=100
이제 10% 상승 → RSI=70, 12.5% 상승 → RSI=75 (의미 있는 구분 가능)
해외 소형주(NYSE American 등)의 RSI=100 집단 현상 완화.
- smart_scanner.py 3곳 동일 공식 모두 수정
- TestImpliedRSIFormula 클래스 5개 테스트 추가
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
다중 인스턴스 실행 시 Telegram getUpdates 409 응답을 ERROR가 아닌 WARNING으로
처리하고, 30초 동안 polling을 일시 중단하여 충돌을 완화.
- _conflict_backoff_until 속성 추가
- 409 감지 시 명확한 "another instance is polling" 메시지 출력
- poll_loop에서 백오프 활성 중 polling 스킵
- TestGetUpdates에 409 관련 테스트 2개 추가
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
스레드 시작 전에 uvicorn import를 검증하도록 _start_dashboard_server 수정.
uvicorn 미설치 시 "started" 로그 없이 즉시 WARNING 출력 후 None 반환.
- 사전 import 검증으로 "started" → "failed" 오해 소지 있는 로그 쌍 제거
- uvicorn 미설치 시 명확한 경고 메시지 출력
- test_start_dashboard_server_returns_none_when_uvicorn_missing 테스트 추가
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
잔액 부족(주문가능금액 부족) 에러 발생 시 해당 종목을 10분간 BUY 시도에서
제외하는 cooldown 메커니즘을 realtime/daily 루프 모두에 적용.
- _BUY_COOLDOWN_SECONDS = 600 상수 추가
- trading_cycle()에 buy_cooldown 파라미터 추가
- 잔액 부족 에러(주문가능금액) 감지 후 cooldown 설정
- BUY 실행 전 cooldown 체크 (realtime + daily session 모두)
- TestBuyCooldown 테스트 클래스 4개 추가
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Import MarketOutlook at module level in main.py
- After scenario evaluation, check market_outlook and apply BUY confidence
threshold: BEARISH→90, BULLISH→75, others→settings.CONFIDENCE_THRESHOLD
- BUY actions below the adjusted threshold are downgraded to HOLD with
a descriptive rationale including the outlook and threshold values
- Add 5 integration tests covering bearish suppression, bearish allow,
bullish allow, bullish suppression, and neutral default threshold
Closes#173
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Add playbook_allocation_pct and scenario_confidence parameters to
_determine_order_quantity() with playbook-based sizing taking priority
over volatility-score fallback when provided
- Confidence scaling: confidence/80 multiplier (confidence 96 → 1.2x)
clipped to [POSITION_MIN_ALLOCATION_PCT, POSITION_MAX_ALLOCATION_PCT]
- Pass matched_scenario.allocation_pct and match.confidence from
trading_cycle so AI's allocation decisions reach order execution
- Add 4 new tests: playbook priority, confidence scaling, max clamp,
and fallback behavior
Closes#172
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Add unrealized_pnl_pct_above/below and holding_days_above/below fields
to StockCondition so AI can generate rules like 'P&L > 3% → SELL'
- Evaluate new fields in ScenarioEngine.evaluate_condition() with same
AND-combining logic as existing technical indicator fields
- Include position fields in _build_match_details() for audit logging
- Parse new fields from AI JSON response in PreMarketPlanner._parse_scenario()
- Update prompt schema example to show new position-aware condition fields
- Add 13 tests covering all new condition combinations and edge cases
Closes#171
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Add current_holdings parameter to generate_playbook() and _build_prompt()
- Inject '## Current Holdings' section into Gemini prompt with qty, entry
price, unrealized PnL%, and holding days for each held position
- Instruct AI to generate SELL/HOLD scenarios for held stocks even if not
in scanner candidates list
- Allow held stock codes in _parse_response() valid_codes set so AI-
generated SELL scenarios for holdings pass validation
- Add 6 tests covering prompt inclusion, omission, and response parsing
Closes#170
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
DB의 주문 수량 기록은 실제 체결 수량과 다를 수 있음(부분 체결, 외부 수동 거래).
브로커 잔고 API(output1)를 source of truth로 사용하도록 수정.
## 변경 사항
### SELL 수량 (#164)
- _extract_held_qty_from_balance() 추가
- 국내: output1의 ord_psbl_qty (→ hldg_qty fallback)
- 해외: output1의 ovrs_cblc_qty (→ hldg_qty fallback)
- _determine_order_quantity()에 broker_held_qty 파라미터 추가
- SELL 시 broker_held_qty 반환 (0이면 주문 스킵)
- trading_cycle / run_daily_session 양쪽 호출 지점 수정
- 이미 fetch된 balance_data에서 수량 추출 (추가 API 호출 없음)
### 보유 종목 루프 (#165)
- _extract_held_codes_from_balance() 추가
- ord_psbl_qty > 0인 종목 코드 목록 반환
- 실시간 루프에서 스캔 시점에 get_balance() 호출해 보유 종목 병합
- 스캐너 후보 + 실제 보유 종목 union으로 trading_cycle 순회
- 실패 시 경고 로그 후 스캐너 후보만으로 계속 진행
### 테스트
- TestExtractHeldQtyFromBalance: 7개 (국내/해외/fallback/미보유)
- TestExtractHeldCodesFromBalance: 4개 (qty>0 포함, qty=0 제외 등)
- TestDetermineOrderQuantity: 5개 (SELL qty, BUY sizing)
- test_sell_order_uses_broker_balance_qty_not_db:
DB 10주 기록 vs 브로커 5주 확인 → 브로커 값(5) 사용 검증
- 기존 SELL/stop-loss/take-profit 테스트에 output1 mock 추가
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
HOLD 판정 후 보유 포지션에 대해 stop_loss와 함께 take_profit도 체크하도록 수정.
AI가 생성한 take_profit_pct가 실제 거래 로직에 반영되지 않던 구조적 결함 수정.
- HOLD 블록에서 loss_pct >= take_profit_threshold 조건 추가
- stop_loss와 상호 배타적으로 동작 (stop_loss 우선 체크)
- take_profit 기본값 3.0% (playbook 없는 경우 적용)
- 테스트 2개 추가:
- test_hold_overridden_to_sell_when_take_profit_triggered
- test_hold_not_overridden_when_between_stop_loss_and_take_profit
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Add /api/pnl/history endpoint to app.py for daily P&L history charting
- Rewrite index.html as full SPA with Chart.js bar chart, summary cards,
and decisions log table with market filter tabs and 30s auto-refresh
- Add test_pnl_history_all_markets and test_pnl_history_market_filter tests
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
**Problem 1 — Current price always 0**
get_orderbook() used inquire-asking-price-exp-ccn which has no stck_prpr
in output1 (only askp/bidp data). This caused every domestic BUY to be
skipped with "no affordable quantity (cash=..., price=0.00)".
**Problem 2 — KRX tick unit error on limit orders**
Limit order prices were passed unrounded, triggering 호가단위 오류 in VTS.
Also ORD_DVSN was wrongly set to "01" (시장가) for limit orders.
**Fix**
- Add kr_tick_unit(price) and kr_round_down(price) module-level helpers
implementing KRX 7-tier price tick rules (1/5/10/50/100/500/1000원).
- Add get_current_price(stock_code) → (price, change_pct, foreigner_net)
using FHKST01010100 / inquire-price API (works in VTS, returns correct
stck_prpr, prdy_ctrt, frgn_ntby_qty).
- Fix send_order() ORD_DVSN: "00"=지정가, "01"=시장가 (was "01"/"06").
- Apply kr_round_down() to limit order price inside send_order().
- Replace both get_orderbook() calls in main.py with get_current_price().
- Update all 4 test_main.py mock sites to use get_current_price AsyncMock.
**Tests added** (25 new tests, all 646 pass)
- TestKrTickUnit: 13 parametrized boundary cases + 7 round-down cases
- TestGetCurrentPrice: correct fields, correct API path/TR_ID, HTTP error
- TestSendOrderTickRounding: tick rounding, ORD_DVSN 00/01
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Three bugs found by comparing against KIS official GitHub examples:
1. FID_COND_SCR_DIV_CODE: "20001" → "20171" (volume-rank screen code)
2. FID_TRGT_EXLS_CLS_CODE: "000000" (6-digit) → "0000000000" (10-digit)
3. fluctuation ranking:
- TR_ID: "FHPST01710100" (invalid) → "FHPST01700000"
- path: /quotations/volume-rank → /ranking/fluctuation
- params: volume-rank params → lowercase fluctuation-specific params
(fid_rank_sort_cls_code, fid_input_cnt_1, fid_prc_cls_code,
fid_rsfl_rate1, fid_rsfl_rate2, etc.)
Note: VTS (paper trading) does not return data from ranking APIs regardless
of parameter correctness — this is a KIS policy restriction, not a code bug.
These fixes ensure correct behavior when switching to a live account.
Tests: TestFetchMarketRankings (3 tests) added to test_broker.py
Closes#155
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Three fixes for overseas stock trading failures:
1. Price API exchange code mapping:
- get_overseas_price() now applies _PRICE_EXCHANGE_MAP (NASD→NAS, NYSE→NYS, AMEX→AMS)
- Price API HHDFS00000300 requires short exchange codes same as ranking API
2. rt_cd check in send_overseas_order():
- Log WARNING (not INFO) when rt_cd != "0" (e.g., "주문가능금액이 부족합니다")
- Caller (main.py) checks rt_cd == "0" before calling log_trade()
- Prevents DB from recording failed orders as successful trades
3. Limit order price premium for BUY:
- BUY limit price = current_price * 1.005 (0.5% premium)
- SELL limit price = current_price (no premium)
- Improves fill probability: KIS VTS only accepts limit orders,
and last price is typically at or below ask
4. PAPER_OVERSEAS_CASH fallback (config + main.py):
- New setting: PAPER_OVERSEAS_CASH = 50000.0 (USD)
- When VTS overseas balance API fails/returns 0, use this as simulated cash
- Applied in both trading_cycle() and run_daily_session()
5. Candidate price fallback:
- If price API returns 0, use scanner candidate price as fallback
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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>
- 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>