Skip to main content
The TradeApi class provides methods for retrieving trading information and managing open positions.

Constructor

public function __construct(
    ClientInterface $client = null,
    Configuration $config = null,
    HeaderSelector $selector = null
)
Creates a new TradeApi 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

positionsUserLoginGet

Retrieves all open positions for a specific user.
public function positionsUserLoginGet(string $user_login): \D4T\MT5Sdk\Models\Position[]
user_login
string
required
The user login ID to fetch positions for
Position[]
array
Array of Position objects representing all open positions for the user
Throws:
  • \D4T\MT5Sdk\ApiException - On non-2xx response (200 success, 400 error)
  • \InvalidArgumentException - When user_login is missing
Example:
use D4T\MT5Sdk\MT5Manager\TradeApi;

$tradeApi = new TradeApi();

try {
    $positions = $tradeApi->positionsUserLoginGet('12345');
    
    foreach ($positions as $position) {
        echo "Symbol: " . $position->getSymbol() . "\n";
        echo "Volume: " . $position->getVolume() . "\n";
        echo "Profit: " . $position->getProfit() . "\n";
        echo "---\n";
    }
} catch (\D4T\MT5Sdk\ApiException $e) {
    echo "Error: " . $e->getMessage();
}

positionsUserLoginGetWithHttpInfo

Retrieves open positions with HTTP response details.
public function positionsUserLoginGetWithHttpInfo(string $user_login): array
user_login
string
required
The user login ID to fetch positions for
array
array
Array containing:
  • [0]: \D4T\MT5Sdk\Models\Position[] - Array of position objects
  • [1]: int - HTTP status code
  • [2]: array - HTTP response headers
Throws:
  • \D4T\MT5Sdk\ApiException - On non-2xx response
  • \InvalidArgumentException - When user_login is missing

ordersUserLoginGet

Retrieves orders for a specific user.
public function ordersUserLoginGet(
    string $user_login,
    string $days_back,
    string $types
): \D4T\MT5Sdk\Models\Order[]
user_login
string
required
The user login ID to fetch orders for
days_back
string
required
Number of days to look back for historical orders
types
string
required
Order types to retrieve (comma-separated or specific type identifier)
Order[]
array
Array of Order objects matching the specified criteria
Throws:
  • \D4T\MT5Sdk\ApiException - On non-2xx response (200 success, 400 error)
  • \InvalidArgumentException - When required parameters are missing
Example:
try {
    $orders = $tradeApi->ordersUserLoginGet(
        '12345',
        '7',      // Last 7 days
        'all'     // All order types
    );
    
    foreach ($orders as $order) {
        echo "Order ID: " . $order->getOrder() . "\n";
        echo "Symbol: " . $order->getSymbol() . "\n";
        echo "Type: " . $order->getType() . "\n";
        echo "Volume: " . $order->getVolume() . "\n";
        echo "---\n";
    }
} catch (\D4T\MT5Sdk\ApiException $e) {
    echo "Error: " . $e->getMessage();
}

ordersUserLoginGetWithHttpInfo

Retrieves orders with HTTP response details.
public function ordersUserLoginGetWithHttpInfo(
    string $user_login,
    string $days_back,
    string $types
): array
user_login
string
required
The user login ID to fetch orders for
days_back
string
required
Number of days to look back
types
string
required
Order types to retrieve
array
array
Array containing:
  • [0]: \D4T\MT5Sdk\Models\Order[] - Array of order objects
  • [1]: int - HTTP status code
  • [2]: array - HTTP response headers
Throws:
  • \D4T\MT5Sdk\ApiException - On non-2xx response
  • \InvalidArgumentException - When required parameters are missing

dealsUserLoginGet

Retrieves deal history for a specific user.
public function dealsUserLoginGet(
    string $user_login,
    string $days_back
): \D4T\MT5Sdk\Models\Deal[]
user_login
string
required
The user login ID to fetch deals for
days_back
string
required
Number of days to look back for historical deals
Deal[]
array
Array of Deal objects representing completed trades and transactions
Throws:
  • \D4T\MT5Sdk\ApiException - On non-2xx response (200 success, 400 error)
  • \InvalidArgumentException - When required parameters are missing
Example:
try {
    $deals = $tradeApi->dealsUserLoginGet('12345', '30');
    
    foreach ($deals as $deal) {
        echo "Deal ID: " . $deal->getDeal() . "\n";
        echo "Order: " . $deal->getOrder() . "\n";
        echo "Symbol: " . $deal->getSymbol() . "\n";
        echo "Volume: " . $deal->getVolume() . "\n";
        echo "Profit: " . $deal->getProfit() . "\n";
        echo "Time: " . $deal->getTime() . "\n";
        echo "---\n";
    }
} catch (\D4T\MT5Sdk\ApiException $e) {
    echo "Error: " . $e->getMessage();
}

dealsUserLoginGetWithHttpInfo

Retrieves deal history with HTTP response details.
public function dealsUserLoginGetWithHttpInfo(
    string $user_login,
    string $days_back
): array
user_login
string
required
The user login ID to fetch deals for
days_back
string
required
Number of days to look back
array
array
Array containing:
  • [0]: \D4T\MT5Sdk\Models\Deal[] - Array of deal objects
  • [1]: int - HTTP status code
  • [2]: array - HTTP response headers
Throws:
  • \D4T\MT5Sdk\ApiException - On non-2xx response
  • \InvalidArgumentException - When required parameters are missing

closeAllUserLoginDelete

Closes all open positions for a specific user (flatten account).
public function closeAllUserLoginDelete(string $user_login): void
user_login
string
required
The user login ID whose positions should be closed
Throws:
  • \D4T\MT5Sdk\ApiException - On non-2xx response (400 error)
  • \InvalidArgumentException - When user_login is missing
Example:
try {
    $tradeApi->closeAllUserLoginDelete('12345');
    echo "All positions closed successfully";
} catch (\D4T\MT5Sdk\ApiException $e) {
    echo "Error closing positions: " . $e->getMessage();
}

closeAllUserLoginDeleteWithHttpInfo

Closes all open positions with HTTP response details.
public function closeAllUserLoginDeleteWithHttpInfo(string $user_login): array
user_login
string
required
The user login ID whose positions should be closed
array
array
Array containing:
  • [0]: null - No response body
  • [1]: int - HTTP status code
  • [2]: array - HTTP response headers
Throws:
  • \D4T\MT5Sdk\ApiException - On non-2xx response
  • \InvalidArgumentException - When user_login is missing

Async Method Variants

All methods have async variants with the following naming patterns:
  • methodNameAsync() - Returns a Promise resolving to the response object
  • methodNameAsyncWithHttpInfo() - Returns a Promise resolving to [response, statusCode, headers]
Example:
$promise = $tradeApi->positionsUserLoginGetAsync('12345');

$promise->then(
    function ($positions) {
        foreach ($positions as $position) {
            echo "Position: " . $position->getSymbol() . "\n";
        }
    },
    function ($exception) {
        echo "Error: " . $exception->getMessage();
    }
);

Build docs developers (and LLMs) love