# MT4 API Coverage Matrix

All requests target the configured `MT4_API_BASE_URL` plus `MT4_API_ENDPOINT`. The provider credentials `name` and `pass` are injected server-side by `App\Services\Mt4Service`; they are never accepted from browser input.

| # | Postman request | Provider `mode` | Service method | Application exposure |
|---:|---|---|---|---|
| 1 | GetTrade | `trades` | `getTrades()` | Read-only client and administrator trade/history views |
| 2 | AddTrade | `openorder` | `addTrade()` | Administrator/API service only; client order entry is available only through the configured WebTrader |
| 3 | UpdateTrade | `editorder` | `updateTrade()` | Administrator only |
| 4 | UpdateTrade_new | `editorder_new` | `updateTradeDetailed()` | Administrator detailed order correction |
| 5 | EditBalance | `editbalance` | `editBalance()` | Administrator balance-record correction |
| 6 | CloseTrade | `closeorder` | `closeTrade()` | Administrator only; the client portal has no order-closing endpoint |
| 7 | DeleteTrade | `deleteorder` | `deleteTrade()` | Administrator only |
| 8 | GetChart | `GetChart` | `getChart()` | Client dashboard and administrator market-data endpoints |
| 9 | Get All Symbols | `GetAllSymbol` | `getAllSymbols()` | Client read-only chart/symbol selection and administrator tools |
| 10 | GetLastPrice | `GetLastPrice` | `getLastPrice()` | Client and administrator quote endpoints |
| 11 | GetLastPriceAll | `GetLastPriceAll` | `getLastPrices()` | Service and administrator all-quotes endpoint |
| 12 | CreateAccount | `CreateAccount` | `createAccount()` | Client and administrator account creation; client group choices come only from active database groups configured by an administrator |
| 13 | Enable/Disable Trade Account | `enable_disable_trade_account` | `setAccountEnabled()` | Administrator only |
| 14 | SetReadOnlyAccount | `SetReadOnly` | `setAccountReadOnly()` | Administrator only |
| 15 | SetAccountLeverage | `change_leverage` | `setAccountLeverage()` | Client-owned account and administrator controls |
| 16 | SetAccountPassword | `changepassword` | `setAccountPassword()` | Client-owned account and administrator controls |
| 17 | SetAccountInvestorPassword | `SetAccountPassword` | `setInvestorPassword()` | Client-owned account and administrator controls |
| 18 | Set Account Group | `SetAccountGroup` | `setAccountGroup()` | Administrator only |
| 19 | Deposit | `depositnew` | `deposit()` | Direct administrator economy operation; a client deposit request can be settled by an administrator as balance |
| 20 | Withdrawal | `depositnew` | `withdraw()` | Client submits a withdrawal request; administrator approval executes the negative balance operation |
| 21 | Credit In | `depositnew` | `creditIn()` | Administrator operation; a client deposit request can alternatively be settled by an administrator as account credit |
| 22 | Credit Out | `depositnew` | `creditOut()` | Administrator only; clients cannot request credit-out |
| 23 | GetAllGroups | `GetAllGroup` | `getAllGroups()` | Administrator/provider synchronization only; client account forms do not load the full provider list |
| 24 | GetSingleGroup | `SingleGroup` | `getSingleGroup()` | Administrator group inspection and service access |
| 25 | FixBalance | `GetFixBalance` | `fixBalance()` | Administrator only |
| 26 | Get Single Symbol | `SingleSymbol` | `getSingleSymbol()` | Administrator symbol inspection and service access |
| 27 | GetAccount | `GetAccount` | `getAccount()` | Client and administrator statistics/synchronization |
| 28 | Edit Account | `AccountEdit` | `editAccount()` | Client-owned remote profile and administrator controls |
| 29 | Re-Open Order | `reopenorder` | `reopenTrade()` | Administrator only |

## CreateAccount field separation

The bridge uses distinct fields that must not be conflated:

| Purpose | Request field |
|---|---|
| Client first name | `uname` |
| Client last name | `lname` |
| MT4 master password | `pwd` |
| Separate trading-account password | `trading_account_pass` |
| API credential name | `name` |
| API credential password | `pass` |

The application validates an active local group before making a client-side CreateAccount call. A local account is stored only after a remote MT4 login is recognized from the provider response.

## WebTerminal auto-login

WebTerminal auto-login is an application-level integration rather than one of
the 29 bridge modes. For the selected client-owned account, Laravel decrypts
the encrypted value originally sent as `trading_account_pass` and generates:

```text
Base64(MT4_LOGIN|TRADING_ACCOUNT_PASSWORD)
```

The client is redirected to the configured HTTPS terminal URL using:

```text
?autologin=1&one=<BASE64_VALUE>
```

The plaintext password is never stored in the database, rendered into Blade,
or returned as its own API field. Existing installations that predate the
separate trading-account credential fall back to the encrypted master password.

## Provider response normalization

The supplied bridge does not return one consistent shape. The service normalizes:

- bare JSON objects and arrays;
- nested wrappers such as `data`, `response`, `result`, `trades`, `orders`, `items`, and `records`;
- single-row associative objects;
- plain-text `Success` and numeric/login-bearing responses;
- bridge responses containing surrounding HTML or whitespace;
- HTTP failures and provider-level failure payloads.

Every transport call returns a stable internal envelope:

```php
[
    'status' => 'success' | 'failed',
    'response' => mixed,
    'message' => ?string,
    'http_status' => ?int,
    'mode' => string,
    'request_id' => string,
    'duration_ms' => int,
    'request' => array, // sensitive values redacted
]
```

Trade-list normalization also accepts wrapped and single-row responses. Closed-order retrieval first requests `trade_type=close_order`; if the provider returns an empty or malformed wrapper, the service requests `trade_type=all` and derives only closed market orders, excluding open positions, pending orders, deposits, withdrawals, and credit entries.

## Safety boundaries

- Client routes resolve the authenticated client’s local account before every provider call.
- Browser-supplied account IDs cannot operate another client’s MT4 login.
- The client portal is a read-only trading monitor; order placement, modification, and closing are routed to WebTrader rather than Laravel mutation routes.
- Client financial actions create only Deposit or Withdrawal approval records; they do not directly move balance or credit.
- The administrator chooses whether an approved Deposit becomes balance or account credit.
- Bonuses, credit-out, deletion, reopening, balance correction, historical editing, enable/disable, read-only, group, and direct economy operations remain administrator-only.
- Provider credentials are server-side only and are redacted from request metadata and logs.
