The AccountApi provides methods to retrieve detailed information about trading accounts in MetaTrader 5. This guide demonstrates how to fetch account data, including balance, equity, margin, and trading permissions.
Use the accountLoginGet() method to retrieve comprehensive account details for a specific user.
1
Initialize the API Client
Set up the AccountApi with your configuration and authentication token.
use D4T\MT5Sdk\MT5Manager\AccountApi;use D4T\MT5Sdk\Configuration;use GuzzleHttp\Client;// Configure API client$config = Configuration::getDefaultConfiguration() ->setHost('https://your-mt5-server.com/api') ->setAccessToken('your_bearer_token');// Initialize AccountApi$accountApi = new AccountApi( new Client(), $config);
2
Retrieve Account Data
Call the accountLoginGet() method with the user’s login ID.
The API throws ApiException when errors occur. Common error codes:
// Bad Request - Invalid login ID or parameterstry { $account = $accountApi->accountLoginGet('invalid');} catch (\D4T\MT5Sdk\ApiException $e) { if ($e->getCode() === 400) { echo "Invalid request: " . $e->getMessage(); // Check response body for details $errorDetails = json_decode($e->getResponseBody(), true); print_r($errorDetails); }}
Always validate the login ID before making API calls to avoid unnecessary errors. Account data is sensitive - ensure proper access control in your application.