|
|
|
|
|
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="القاعدة المقترحة نصياً (e.g., When RSI<25...)") |
|
|
domain: str = Field(..., description="المجال (e.g., 'strategy', 'pattern', 'indicator', 'monte_carlo')") |
|
|
priority: str = Field(default="medium", description="الأولوية (high, medium, low)") |
|
|
score: float = Field(default=0.5, description="النتيجة الإجمالية للدلتا (للاسترجاع)") |
|
|
evidence_refs: List[str] = Field(default=[], description="المعرفات المرجعية (e.g., trace_id, trade_id)") |
|
|
created_by: str = Field(default="reflector_v1", description="المكون الذي أنشأ هذه الدلتا") |
|
|
created_at: str = Field(default_factory=lambda: datetime.now().isoformat()) |
|
|
approved: bool = Field(default=False, description="هل تمت الموافقة عليها (تلقائياً أو يدوياً)") |
|
|
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="هل كانت النتيجة الفعلية (Outcome) ناجحة؟") |
|
|
score: float = Field(..., description="تقييم التجربة (0.0 إلى 1.0)") |
|
|
error_mode: str = Field(..., description="وصف لنمط الخطأ (e.g., 'ignored_volatility', 'premature_exit')") |
|
|
suggested_rule: str = Field(..., description="القاعدة المقترحة (الدلتا) بحد أقصى 25 كلمة.") |
|
|
confidence: float = Field(..., description="ثقة النموذج في هذه القاعدة المقترحة (0.0 إلى 1.0)") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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="بيانات القرار الأصلية من الصفقة (decision_data)") |
|
|
|
|
|
|
|
|
|
|
|
market_context_at_decision: Dict[str, Any] = Field(default={}, description="سياق السوق عند فتح الصفقة") |
|
|
indicators_at_decision: Dict[str, Any] = Field(default={}, description="المؤشرات عند فتح الصفقة") |
|
|
|
|
|
|
|
|
closed_trade_object: Dict[str, Any] = Field(..., description="كائن الصفقة المغلقة بالكامل") |
|
|
actual_outcome_reason: str = Field(..., description="سبب الإغلاق (e.g., 'Hard Stop Loss hit', 'Tactical Monitor')") |
|
|
|
|
|
print("✅ Learning Hub Module: Schemas loaded (Delta, ReflectorOutput, TraceLog)") |