|
|
|
|
|
|
|
|
from pydantic import BaseModel, Field |
|
|
from typing import List, Dict, Any, Optional |
|
|
from datetime import datetime |
|
|
import uuid |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Delta(BaseModel): |
|
|
id: str = Field(default_factory=lambda: f"delta_{uuid.uuid4().hex[:10]}") |
|
|
text: str = Field(..., description="القاعدة المقترحة نصياً") |
|
|
domain: str = Field(..., description="المجال (strategy, pattern, indicator, monte_carlo, general)") |
|
|
priority: str = Field(default="medium", description="الأولوية (high, medium, low)") |
|
|
score: float = Field(default=0.5, description="النتيجة الإجمالية للدلتا") |
|
|
evidence_refs: List[str] = Field(default=[], description="المعرفات المرجعية") |
|
|
created_by: str = Field(default="reflector_v1") |
|
|
created_at: str = Field(default_factory=lambda: datetime.now().isoformat()) |
|
|
approved: bool = Field(default=False) |
|
|
usage_count: int = Field(default=0) |
|
|
last_used: Optional[str] = None |
|
|
trade_strategy: Optional[str] = None |
|
|
exit_profile: Optional[str] = None |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ReflectorOutput(BaseModel): |
|
|
success: bool = Field(..., description="هل كانت النتيجة ناجحة؟") |
|
|
score: float = Field(..., description="تقييم التجربة (0.0 إلى 1.0)") |
|
|
error_mode: str = Field(..., description="وصف لنمط الخطأ") |
|
|
suggested_rule: str = Field(..., description="القاعدة المقترحة (max 25 words)") |
|
|
confidence: float = Field(..., description="ثقة النموذج في القاعدة") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TraceLog(BaseModel): |
|
|
trace_id: str = Field(default_factory=lambda: f"trace_{uuid.uuid4().hex[:10]}") |
|
|
timestamp: str = Field(default_factory=lambda: datetime.now().isoformat()) |
|
|
|
|
|
decision_context: Dict[str, Any] = Field(..., description="بيانات القرار الأصلية") |
|
|
market_context_at_decision: Dict[str, Any] = Field(default={}, description="سياق السوق عند فتح الصفقة") |
|
|
indicators_at_decision: Dict[str, Any] = Field(default={}, description="المؤشرات عند فتح الصفقة") |
|
|
|
|
|
|
|
|
hybrid_weights_used: Dict[str, float] = Field( |
|
|
default={"titan": 0.5, "patterns": 0.4, "monte_carlo": 0.1}, |
|
|
description="الأوزان الدقيقة التي استخدمت في المعادلة الهجينة لهذه الصفقة." |
|
|
) |
|
|
|
|
|
closed_trade_object: Dict[str, Any] = Field(..., description="كائن الصفقة المغلقة") |
|
|
actual_outcome_reason: str = Field(..., description="سبب الإغلاق") |