Overview
Project intent
This panel keeps the old project material and the new command workflows together: MT5 execution, queue, idempotency, policy snapshots, protective actions, and test payloads. It is designed as a single working area for the bridge and for the Laravel developer.
Key facts
- Existing files are preserved and expanded into a single operational panel.
- Each request uses the same envelope structure.
- The developer sees commands, test payloads, and environment notes in one place.
Architecture
Laravel is the source of truth
Python handles ingestion + execution
MT5 client supports official API / manager API stub
Queue handles normal commands
FastLane handles urgent protective commands
Idempotency prevents duplicates
UTC is used everywhere
Tenant isolation is mandatory
Commands
Environment / Headers
Required headers
Authorization: Bearer <TOKEN> Content-Type: application/json X-Correlation-ID: <uuid> X-Idempotency-Key: <uuid> X-Protocol-Version: 1
Environment variables
PYTHON_INGEST_TOKEN=... PYTHON_BRIDGE_URL=... LARAVEL_INTERNAL_TOKEN=... LARAVEL_API_URL=...
Policies
Policy snapshot payload
{
"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
}
}
}
Protective action callback payload
{
"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
}
}
Tests
PowerShell quick tests
close_positionsInvoke-RestMethod -Uri "http://localhost:8000/api/v1/mt5/commands" ` -Method Post ` -Headers @{ Authorization = "Bearer test_token_123"; "Content-Type" = "application/json" } ` -Body $bodyopen_position$body = @{ command_id = "test-open-$(Get-Date -Format 'yyyyMMddHHmmss')" tenant_id = "tenant_1" account_id = 50040367 command_type = "open_position" 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-Jsonsync_requestInvoke-RestMethod -Uri "http://localhost:8000/api/v1/mt5/accounts/50040367" ` -Method Get ` -Headers @{ Authorization = "Bearer test_token_123" }
Validation rules
- Duplicate idempotency keys must not create side effects.
- Tenant mismatch must return 403.
- Invalid token must return 401.
- All timestamps remain in UTC.
Examples
Laravel โ Python: close positions
{
"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: policy snapshot
{
"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: protective action report
{
"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
}
}
Payload builder