Skip to main content
The BasicApi class provides fundamental operations for connecting to and managing MetaTrader 5 server connections.

Constructor

public function __construct(
    ClientInterface $client = null,
    Configuration $config = null,
    HeaderSelector $selector = null
)
Creates a new BasicApi instance.
client
ClientInterface
Guzzle HTTP client instance. If not provided, a new Client will be created.
config
Configuration
SDK configuration object. If not provided, a new Configuration will be created.
selector
HeaderSelector
Header selector instance. If not provided, a new HeaderSelector will be created.

Methods

getConfig

Retrieves the current configuration object.
public function getConfig(): Configuration
Configuration
Configuration
The current SDK configuration object

initGet

Initializes a connection to the MetaTrader 5 server and returns an authentication token.
public function initGet(
    string $server,
    string $login,
    string $password,
    float $timeout = null
): \D4T\MT5Sdk\Models\InitReturnType
server
string
required
MetaTrader5 server IP with port. Example: 127.0.0.1:443
login
string
required
MetaTrader manager login
password
string
required
MetaTrader manager password
timeout
float
Connection timeout in milliseconds
InitReturnType
\D4T\MT5Sdk\Models\InitReturnType
Object containing the authentication token and connection details
Throws:
  • \D4T\MT5Sdk\ApiException - On non-2xx response
  • \InvalidArgumentException - When required parameters are missing
Example:
use D4T\MT5Sdk\MT5Manager\BasicApi;

$basicApi = new BasicApi();

try {
    $result = $basicApi->initGet(
        '127.0.0.1:443',
        'manager_login',
        'manager_password',
        5000
    );
    
    echo "Token: " . $result->getToken();
} catch (\D4T\MT5Sdk\ApiException $e) {
    echo "API Error: " . $e->getMessage();
}

initGetWithHttpInfo

Initializes a connection and returns response with HTTP information.
public function initGetWithHttpInfo(
    string $server,
    string $login,
    string $password,
    float $timeout = null
): array
server
string
required
MetaTrader5 server IP with port. Example: 127.0.0.1:443
login
string
required
MetaTrader manager login
password
string
required
MetaTrader manager password
timeout
float
Connection timeout in milliseconds
array
array
Array containing:
  • [0]: \D4T\MT5Sdk\Models\InitReturnType - The response object
  • [1]: int - HTTP status code
  • [2]: array - HTTP response headers
Throws:
  • \D4T\MT5Sdk\ApiException - On non-2xx response
  • \InvalidArgumentException - When required parameters are missing

initGetAsync

Asynchronously initializes a connection to the MetaTrader 5 server.
public function initGetAsync(
    string $server,
    string $login,
    string $password,
    float $timeout = null
): \GuzzleHttp\Promise\PromiseInterface
server
string
required
MetaTrader5 server IP with port. Example: 127.0.0.1:443
login
string
required
MetaTrader manager login
password
string
required
MetaTrader manager password
timeout
float
Connection timeout in milliseconds
PromiseInterface
\GuzzleHttp\Promise\PromiseInterface
Promise that resolves to \D4T\MT5Sdk\Models\InitReturnType
Throws:
  • \InvalidArgumentException - When required parameters are missing
Example:
$promise = $basicApi->initGetAsync(
    '127.0.0.1:443',
    'manager_login',
    'manager_password'
);

$promise->then(
    function ($result) {
        echo "Connected! Token: " . $result->getToken();
    },
    function ($exception) {
        echo "Error: " . $exception->getMessage();
    }
);

initGetAsyncWithHttpInfo

Asynchronously initializes a connection with HTTP information.
public function initGetAsyncWithHttpInfo(
    string $server,
    string $login,
    string $password,
    float $timeout = null
): \GuzzleHttp\Promise\PromiseInterface
server
string
required
MetaTrader5 server IP with port. Example: 127.0.0.1:443
login
string
required
MetaTrader manager login
password
string
required
MetaTrader manager password
timeout
float
Connection timeout in milliseconds
PromiseInterface
\GuzzleHttp\Promise\PromiseInterface
Promise that resolves to an array containing response object, status code, and headers
Throws:
  • \InvalidArgumentException - When required parameters are missing

pingGet

Pings the API to verify connectivity.
public function pingGet(): \D4T\MT5Sdk\Models\PingReturnType
PingReturnType
\D4T\MT5Sdk\Models\PingReturnType
Object containing ping response data
Throws:
  • \D4T\MT5Sdk\ApiException - On non-2xx response (including 400 Bad Request)
  • \InvalidArgumentException - On invalid arguments
Example:
try {
    $ping = $basicApi->pingGet();
    echo "Server is online";
} catch (\D4T\MT5Sdk\ApiException $e) {
    echo "Server is offline or unreachable";
}

pingGetWithHttpInfo

Pings the API and returns response with HTTP information.
public function pingGetWithHttpInfo(): array
array
array
Array containing:
  • [0]: \D4T\MT5Sdk\Models\PingReturnType - The response object
  • [1]: int - HTTP status code
  • [2]: array - HTTP response headers
Throws:
  • \D4T\MT5Sdk\ApiException - On non-2xx response (200 success, 400 error)
  • \InvalidArgumentException - On invalid arguments

pingGetAsync

Asynchronously pings the API.
public function pingGetAsync(): \GuzzleHttp\Promise\PromiseInterface
PromiseInterface
\GuzzleHttp\Promise\PromiseInterface
Promise that resolves to \D4T\MT5Sdk\Models\PingReturnType
Throws:
  • \InvalidArgumentException - On invalid arguments
Example:
$promise = $basicApi->pingGetAsync();

$promise->then(
    function ($result) {
        echo "Ping successful";
    },
    function ($exception) {
        echo "Ping failed";
    }
);

pingGetAsyncWithHttpInfo

Asynchronously pings the API with HTTP information.
public function pingGetAsyncWithHttpInfo(): \GuzzleHttp\Promise\PromiseInterface
PromiseInterface
\GuzzleHttp\Promise\PromiseInterface
Promise that resolves to an array containing response object, status code, and headers
Throws:
  • \InvalidArgumentException - On invalid arguments

Build docs developers (and LLMs) love