لوحة التحكم MT5
🧪 الاختبارات EN English
MT5 Control Panel جاهز

لوحة التحكم MT5

لوحة تشغيل للأوامر والسياسات والاختبارات والتنفيذ الآمن.
Laravel → Python
Python → Laravel
MT5 live commands
Policy snapshots
Protective execution
Idempotency
UTC only
الحالة السريعة
استخدم المنشئ أدناه لتوليد طلبات دقيقة لكل أمر أو تقرير.
نظرة عامة
هدف المشروع

هذه اللوحة تجمع المحتوى القديم مع سير العمل الجديد في مكان واحد: تنفيذ MT5، الطابور، منع التكرار، لقطة السياسات، إجراءات الحماية، وقوالب الاختبار. تم تصميمها كمركز عمل موحّد للجسر ولمطوّر Laravel.

حقائق أساسية
  • تم الحفاظ على المحتوى القديم وتوسيعه داخل لوحة تشغيل واحدة.
  • كل طلب يستخدم نفس بنية الـ envelope.
  • يرى المطور الأوامر وقوالب الاختبار وملاحظات البيئة في مكان واحد.
المعمارية
Laravel هو مصدر الحقيقة
Python يتولى الاستقبال والتنفيذ
العميل يدعم official API / manager API stub
الطابور للأوامر العادية
FastLane للأوامر الحرجة
Idempotency يمنع التكرار
UTC في كل الأوقات
عزل المستأجر إلزامي
الأوامر
البيئة / الهيدرز
الهيدرز المطلوبة
Authorization: Bearer <TOKEN>
Content-Type: application/json
X-Correlation-ID: <uuid>
X-Idempotency-Key: <uuid>
X-Protocol-Version: 1
متغيرات البيئة
PYTHON_INGEST_TOKEN=...
PYTHON_BRIDGE_URL=...
LARAVEL_INTERNAL_TOKEN=...
LARAVEL_API_URL=...
السياسات
حمولة لقطة السياسات
{
  "meta": {
    "protocol_version": "1.0",
    "request_id": "0a0b0c0d-1111-2222-3333-444444444444",
    "correlation_id": "11112222-3333-4444-5555-666677778888",
    "idempotency_key": "policy-uuid-0001",
    "tenant_id": "tenant_1",
    "environment": "prod",
    "source": "laravel",
    "sent_at_utc": "2026-05-29T12:00:00Z"
  },
  "actor": {
    "trading_account_id": "1001",
    "account_login": 50040367,
    "server": "Broker-Server",
    "platform": "MT5"
  },
  "context": {
    "session_id": "daily-reset",
    "correlation_group": "policy-sync"
  },
  "request": {
    "type": "policy_snapshot",
    "version": "1"
  },
  "payload": {
    "account_status": "active",
    "policy_version": 12,
    "initial_balance_snapshot": 100000,
    "daily_starting_balance": 98500,
    "daily_starting_balance_date": "2026-05-29",
    "max_daily_dd_pct": 5,
    "max_total_dd_pct": 10,
    "drawdown_type": "equity",
    "lock_trailing_drawdown": true,
    "max_single_trade_loss_pct": 2,
    "max_single_trade_loss_violations_allowed": 1,
    "current_single_trade_exceed_count": 0,
    "enforcement_flags": {
      "close_position_on_single_trade_breach": true,
      "close_all_on_daily_dd": true,
      "disable_trading_on_breach": false
    }
  }
}
حمولة تقرير الحماية
{
  "meta": {
    "protocol_version": "1.0",
    "request_id": "aaaa1111-bbbb-2222-cccc-333333333333",
    "correlation_id": "99998888-7777-6666-5555-444433332222",
    "idempotency_key": "protect-001",
    "tenant_id": "tenant_1",
    "environment": "prod",
    "source": "python",
    "sent_at_utc": "2026-05-29T12:01:01Z"
  },
  "actor": {
    "trading_account_id": "1001",
    "account_login": 50040367,
    "server": "Broker-Server",
    "platform": "MT5"
  },
  "context": {
    "session_id": "risk-engine",
    "correlation_group": "protective-action"
  },
  "request": {
    "type": "protective_action_report",
    "version": "1"
  },
  "payload": {
    "rule_key": "single_trade_loss",
    "policy_version": 12,
    "position_id": "555111",
    "ticket": 555111,
    "symbol": "EURUSD",
    "volume": 1.0,
    "floating_pnl": -2500,
    "closed_pnl": 0,
    "equity": 97500,
    "balance": 100000,
    "threshold_used": 2,
    "detection_timestamp": "2026-05-29T12:01:00Z",
    "execution_timestamp": "2026-05-29T12:01:01Z",
    "execution_status": "success",
    "mt5_response": "position closed successfully",
    "error_message": null
  }
}
الاختبارات
اختبارات PowerShell السريعة
إغلاق الصفقات
Invoke-RestMethod -Uri "http://localhost:8000/api/v1/mt5/commands" `
  -Method Post `
  -Headers @{ Authorization = "Bearer test_token_123"; "Content-Type" = "application/json" } `
  -Body $body
فتح صفقة
$body = @{
    command_id = "test-open-$(Get-Date -Format 'yyyyMMddHHmmss')"
    tenant_id = "tenant_1"
    account_id = 50040367
    command_type = "فتح صفقة"
    payload = @{
        symbol = "EURUSD"
        direction = "buy"
        volume = 0.1
        open_price = 1.0850
        stop_loss = 1.0800
        take_profit = 1.0900
        comment = "test from middleware"
    }
    issued_at = (Get-Date -Format "yyyy-MM-ddTHH:mm:ssZ")
} | ConvertTo-Json
طلب مزامنة
Invoke-RestMethod -Uri "http://localhost:8000/api/v1/mt5/accounts/50040367" `
  -Method Get `
  -Headers @{ Authorization = "Bearer test_token_123" }
قواعد التحقق
  1. مفاتيح idempotency المكررة لا يجب أن تنشئ أثرًا جديدًا.
  2. اختلاف tenant يجب أن يعيد 403.
  3. التوكن غير الصحيح يجب أن يعيد 401.
  4. كل التواريخ تبقى UTC.
الأمثلة
Laravel → Python: إغلاق الصفقات
{
  "meta": {
    "protocol_version": "1.0",
    "request_id": "1a2b3c4d-1111-2222-3333-444444444444",
    "correlation_id": "9f8e7d6c-aaaa-bbbb-cccc-123456789000",
    "idempotency_key": "f1f2f3f4-5555-6666-7777-888888888888",
    "tenant_id": "tenant_1",
    "environment": "prod",
    "source": "laravel",
    "sent_at_utc": "2026-05-29T12:00:00Z"
  },
  "actor": {
    "trading_account_id": "1001",
    "account_login": 50040367,
    "server": "Broker-Server",
    "platform": "MT5"
  },
  "context": {
    "session_id": "risk-control",
    "terminal_id": "optional",
    "correlation_group": "risk-control"
  },
  "request": {
    "type": "command",
    "version": "1"
  },
  "payload": {
    "command_id": "cmd-10001",
    "command_type": "close_positions",
    "priority": "critical",
    "fast_lane": true,
    "reason": "daily_drawdown_breach",
    "target": {
      "mode": "all_positions"
    },
    "execution": {
      "allow_partial_close": false,
      "close_only_profitable": false,
      "force_market": true
    }
  }
}
Laravel → Python: لقطة السياسات
{
  "meta": {
    "protocol_version": "1.0",
    "request_id": "0a0b0c0d-1111-2222-3333-444444444444",
    "correlation_id": "11112222-3333-4444-5555-666677778888",
    "idempotency_key": "policy-uuid-0001",
    "tenant_id": "tenant_1",
    "environment": "prod",
    "source": "laravel",
    "sent_at_utc": "2026-05-29T12:00:00Z"
  },
  "actor": {
    "trading_account_id": "1001",
    "account_login": 50040367,
    "server": "Broker-Server",
    "platform": "MT5"
  },
  "context": {
    "session_id": "daily-reset",
    "correlation_group": "policy-sync"
  },
  "request": {
    "type": "policy_snapshot",
    "version": "1"
  },
  "payload": {
    "account_status": "active",
    "policy_version": 12,
    "initial_balance_snapshot": 100000,
    "daily_starting_balance": 98500,
    "daily_starting_balance_date": "2026-05-29",
    "max_daily_dd_pct": 5,
    "max_total_dd_pct": 10,
    "drawdown_type": "equity",
    "lock_trailing_drawdown": true,
    "max_single_trade_loss_pct": 2,
    "max_single_trade_loss_violations_allowed": 1,
    "current_single_trade_exceed_count": 0,
    "enforcement_flags": {
      "close_position_on_single_trade_breach": true,
      "close_all_on_daily_dd": true,
      "disable_trading_on_breach": false
    }
  }
}
Python → Laravel: تقرير إجراء حماية
{
  "meta": {
    "protocol_version": "1.0",
    "request_id": "aaaa1111-bbbb-2222-cccc-333333333333",
    "correlation_id": "99998888-7777-6666-5555-444433332222",
    "idempotency_key": "protect-001",
    "tenant_id": "tenant_1",
    "environment": "prod",
    "source": "python",
    "sent_at_utc": "2026-05-29T12:01:01Z"
  },
  "actor": {
    "trading_account_id": "1001",
    "account_login": 50040367,
    "server": "Broker-Server",
    "platform": "MT5"
  },
  "context": {
    "session_id": "risk-engine",
    "correlation_group": "protective-action"
  },
  "request": {
    "type": "protective_action_report",
    "version": "1"
  },
  "payload": {
    "rule_key": "single_trade_loss",
    "policy_version": 12,
    "position_id": "555111",
    "ticket": 555111,
    "symbol": "EURUSD",
    "volume": 1.0,
    "floating_pnl": -2500,
    "closed_pnl": 0,
    "equity": 97500,
    "balance": 100000,
    "threshold_used": 2,
    "detection_timestamp": "2026-05-29T12:01:00Z",
    "execution_timestamp": "2026-05-29T12:01:01Z",
    "execution_status": "success",
    "mt5_response": "position closed successfully",
    "error_message": null
  }
}
منشئ الطلب