feat: 자동매매 신뢰성 개선 — 시세 실서버 라우팅·일일 한도 전역화·수동 매수 API

- korea_investment_api: KIS_QUOTES_VIA_REAL — 모의투자 모드에서 시세/차트/호가 조회를
  실계좌 시세 서버(20/s)로 위임, 주문·잔고는 모의서버 유지 (EGW00201 대응)
- recommendations: execute_auto_trade_background asyncio.Lock 중복 실행 방지 +
  MAX_DAILY_TRADES를 당일 BUY 건수 차감 전역 기준으로 적용 (11종목 동시 매수 재발 방지)
- manual_buy.py 신규: POST /api/v1/portfolio/buy (리스크 가드 + safe_place_order + db_worker)
- mcp-server: claude_code_client(claude -p 헤드리스 모드) 추가, trade_monitor 부분매도 시
  active 유지·remaining_pct 갱신, API 키 헤더·/api/v1 경로 수정, ODNO 주문ID 수정
- config: MCP_REQUEST_TIMEOUT, MCP_RISK_CACHE_TTL, BATCH_ANALYSIS_INTERVAL,
  SWING_INDEX_BREAKER_ENABLED(OFF), API_TRIGGERED_AUTO_TRADE(OFF) 추가
- docker-compose: 포트 충돌 해소 (postgres 15433, frontend 3001)
- frontend: 추천 패널 매수 버튼, 차트/호가/저널 패널 개선
- CLAUDE.md 압축 최적화 (규칙 변경 없음), _sweep_single_axis.py 백테스트 단일축 스윕

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-09-19 23:37:08 +09:00
parent b1da208fd5
commit 028a1c352b
39 changed files with 1073 additions and 694 deletions

View File

@@ -12,11 +12,13 @@ export const useTradeActions = () => {
quantity: number
): Promise<void> => {
try {
// KIS 모의서버 지연 시 주문 1건에 30~60초 걸릴 수 있음 — 기본 15초로 끊으면
// 서버는 체결하는데 화면은 실패로 보여 중복 주문을 유발함
await api.post('/portfolio/sell', {
stock_code: stockCode,
quantity,
price: null,
})
}, { timeout: 90000 })
// Invalidate queries to refresh portfolio
queryClient.invalidateQueries({
@@ -38,6 +40,30 @@ export const useTradeActions = () => {
[queryClient]
)
/** 추천 종목 수동 매수 (시장가, 수량은 서버가 예산 기반 산출) */
const handleBuy = useCallback(
async (stockCode: string, stockName: string): Promise<void> => {
try {
await api.post('/portfolio/buy', {
stock_code: stockCode,
stock_name: stockName,
quantity: null,
price: null,
}, { timeout: 90000 })
queryClient.invalidateQueries({ queryKey: ['portfolio-combined'] })
queryClient.invalidateQueries({ queryKey: ['trade-history'] })
console.log(`✅ ${stockName} buy order completed`)
} catch (error: any) {
console.error(
`❌ Buy order failed for ${stockName}:`,
error.response?.data?.detail || error.message
)
throw error
}
},
[queryClient]
)
const resetPendingTrades = useCallback(async (): Promise<void> => {
try {
const response = await api.delete('/trades/pending')
@@ -62,6 +88,7 @@ export const useTradeActions = () => {
return {
handleSell,
handleBuy,
resetPendingTrades,
invalidateTradeHistory,
}