MCP 차단관련 로직 추가
This commit is contained in:
@@ -694,6 +694,13 @@ async def websocket_endpoint(websocket: WebSocket, client_id: str):
|
|||||||
websocket_manager.disconnect(client_id)
|
websocket_manager.disconnect(client_id)
|
||||||
logger.info(f"Client {client_id} disconnected")
|
logger.info(f"Client {client_id} disconnected")
|
||||||
|
|
||||||
|
@app.post("/api/admin/reset-daily-loss")
|
||||||
|
async def reset_daily_loss():
|
||||||
|
"""테스트용 일일 손실 한도 강제 리셋"""
|
||||||
|
from app.services.mdd_manager import mdd_manager
|
||||||
|
mdd_manager.reset() # 이미 reset() 메서드 존재 [cite:9]
|
||||||
|
return {"status": "ok", "message": "daily loss limit reset"}
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
import uvicorn
|
import uvicorn
|
||||||
|
|||||||
@@ -494,9 +494,11 @@ def is_daily_loss_exceeded(
|
|||||||
total_assets: float,
|
total_assets: float,
|
||||||
realized_pnl_today: float,
|
realized_pnl_today: float,
|
||||||
) -> bool:
|
) -> bool:
|
||||||
"""일일 손실 한도 초과 여부 (전체 자본 -3%)"""
|
|
||||||
if total_assets <= 0:
|
if total_assets <= 0:
|
||||||
return False
|
return False
|
||||||
|
# realized_pnl_today가 0이면 손실 없음 → 한도 미초과
|
||||||
|
if realized_pnl_today >= 0:
|
||||||
|
return False
|
||||||
return (realized_pnl_today / total_assets) <= DAILY_LOSS_LIMIT
|
return (realized_pnl_today / total_assets) <= DAILY_LOSS_LIMIT
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -64,6 +64,14 @@ async def _mcp_validate_buy(stock: dict) -> tuple:
|
|||||||
else:
|
else:
|
||||||
return False, f"mcp_rejected(decision={decision}, conf={confidence:.2f})"
|
return False, f"mcp_rejected(decision={decision}, conf={confidence:.2f})"
|
||||||
|
|
||||||
|
except httpx.HTTPStatusError as e:
|
||||||
|
if e.response.status_code == 500:
|
||||||
|
# 500 에러 → MCP 서버 내부 오류 → 룰 기반으로 우회
|
||||||
|
logger.warning(f"⚠️ MCP 서버 500 에러 — 룰 기반으로 우회: {e}")
|
||||||
|
return True, "mcp_500_fallback_to_rules"
|
||||||
|
logger.warning(f"⚠️ MCP 검증 실패 — 매매 차단: {e}")
|
||||||
|
return False, "mcp_unavailable"
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning(f"⚠️ MCP 검증 실패 — 매매 차단: {e}")
|
logger.warning(f"⚠️ MCP 검증 실패 — 매매 차단: {e}")
|
||||||
return False, "mcp_unavailable"
|
return False, "mcp_unavailable"
|
||||||
|
|||||||
Reference in New Issue
Block a user