Skip to main content

Overview

The MT5 Manager API provides two key endpoints for accessing market data: the SymbolApi for retrieving trading symbols and their properties, and the GroupApi for managing trading group configurations. This guide covers both APIs and their practical applications.

Working with Symbols

The SymbolApi allows you to retrieve information about all available trading instruments on your MT5 server.
1

Initialize the SymbolApi

Set up the SymbolApi client with your configuration.
use D4T\MT5Sdk\MT5Manager\SymbolApi;
use D4T\MT5Sdk\Configuration;
use GuzzleHttp\Client;

$config = Configuration::getDefaultConfiguration()
    ->setHost('https://your-mt5-server.com/api')
    ->setAccessToken('your_bearer_token');

$symbolApi = new SymbolApi(new Client(), $config);
2

Retrieve All Symbols

Get the complete list of trading symbols available on your server.
try {
    $symbols = $symbolApi->symbolsGet();
    
    echo "Total symbols available: " . count($symbols) . "\n\n";
    
    foreach ($symbols as $symbol) {
        echo "Symbol: " . $symbol->getSymbol() . "\n";
        echo "Description: " . $symbol->getDescription() . "\n";
        echo "Path: " . $symbol->getPath() . "\n";
        echo "Digits: " . $symbol->getDigits() . "\n";
        echo "Contract Size: " . $symbol->getContractSize() . "\n";
        echo "Currency: " . $symbol->getCurrencyBase() . "/" . 
             $symbol->getCurrencyProfit() . "\n";
        echo "---\n";
    }
    
} catch (\D4T\MT5Sdk\ApiException $e) {
    echo "Error: " . $e->getMessage() . "\n";
}

Working with Groups

The GroupApi provides methods to retrieve trading group configurations and individual group details.
1

Initialize the GroupApi

Set up the GroupApi client.
use D4T\MT5Sdk\MT5Manager\GroupApi;
use D4T\MT5Sdk\Configuration;
use GuzzleHttp\Client;

$config = Configuration::getDefaultConfiguration()
    ->setHost('https://your-mt5-server.com/api')
    ->setAccessToken('your_bearer_token');

$groupApi = new GroupApi(new Client(), $config);
2

List All Groups

Retrieve all trading group names.
try {
    $groups = $groupApi->groupsGet();
    
    echo "Available trading groups:\n";
    foreach ($groups as $groupName) {
        echo "- $groupName\n";
    }
    
} catch (\D4T\MT5Sdk\ApiException $e) {
    echo "Error: " . $e->getMessage() . "\n";
}
3

Get Group Details

Retrieve detailed configuration for a specific group.
try {
    $groupName = 'demo\\\\demoforex';
    $group = $groupApi->groupGroupNameGet($groupName);
    
    echo "Group: " . $group->getGroup() . "\n";
    echo "Company: " . $group->getCompany() . "\n";
    echo "Currency: " . $group->getCurrency() . "\n";
    echo "Leverage: " . $group->getLeverage() . "\n";
    echo "Margin Call: " . $group->getMarginCall() . "%\n";
    echo "Margin Stop Out: " . $group->getMarginStopout() . "%\n";
    
} catch (\D4T\MT5Sdk\ApiException $e) {
    echo "Error: " . $e->getMessage() . "\n";
}

Complete Working Examples

<?php
require_once(__DIR__ . '/vendor/autoload.php');

use D4T\MT5Sdk\MT5Manager\SymbolApi;
use D4T\MT5Sdk\Configuration;
use GuzzleHttp\Client;

$config = Configuration::getDefaultConfiguration()
    ->setHost('https://your-mt5-server.com/api')
    ->setAccessToken('your_bearer_token');

$symbolApi = new SymbolApi(new Client(), $config);

function categorizeSymbols() {
    global $symbolApi;
    
    try {
        $symbols = $symbolApi->symbolsGet();
        
        $categories = [
            'Forex' => [],
            'Metals' => [],
            'Indices' => [],
            'Crypto' => [],
            'Other' => []
        ];
        
        foreach ($symbols as $symbol) {
            $symbolName = $symbol->getSymbol();
            $path = $symbol->getPath();
            
            if (stripos($path, 'forex') !== false) {
                $categories['Forex'][] = $symbolName;
            } elseif (stripos($path, 'metals') !== false || 
                      stripos($symbolName, 'XAU') !== false || 
                      stripos($symbolName, 'XAG') !== false) {
                $categories['Metals'][] = $symbolName;
            } elseif (stripos($path, 'indices') !== false || 
                      stripos($path, 'index') !== false) {
                $categories['Indices'][] = $symbolName;
            } elseif (stripos($path, 'crypto') !== false || 
                      stripos($symbolName, 'BTC') !== false || 
                      stripos($symbolName, 'ETH') !== false) {
                $categories['Crypto'][] = $symbolName;
            } else {
                $categories['Other'][] = $symbolName;
            }
        }
        
        return $categories;
        
    } catch (\D4T\MT5Sdk\ApiException $e) {
        echo "Error: " . $e->getMessage() . "\n";
        return null;
    }
}

// Display categorized symbols
$categories = categorizeSymbols();

if ($categories) {
    foreach ($categories as $category => $symbols) {
        if (count($symbols) > 0) {
            echo "\n=== $category (" . count($symbols) . ") ===\n";
            foreach ($symbols as $symbol) {
                echo "  - $symbol\n";
            }
        }
    }
}

Symbol Properties

The Symbol model includes comprehensive trading instrument information:
PropertyTypeDescription
symbolstringSymbol name (e.g., EURUSD)
descriptionstringHuman-readable description
pathstringCategory path
digitsintegerPrice decimal places
contract_sizefloatSize of 1 lot
currency_basestringBase currency
currency_profitstringProfit currency
currency_marginstringMargin currency
tick_sizefloatMinimum price change
tick_valuefloatValue of 1 tick
volume_minfloatMinimum trade volume
volume_maxfloatMaximum trade volume
volume_stepfloatVolume increment step

Group Properties

The Group model contains trading group configuration:
PropertyTypeDescription
groupstringGroup name
companystringCompany name
currencystringAccount currency
leverageintegerMaximum leverage
margin_callfloatMargin call level (%)
margin_stopoutfloatStop out level (%)
deposit_defaultfloatDefault deposit amount
reportsbooleanReports enabled
newsbooleanNews enabled
Symbol and group data is relatively static but can change. Consider implementing a caching strategy to reduce API calls while keeping data reasonably current.

API Methods Reference

SymbolApi Methods

MethodParametersDescriptionReturns
symbolsGet()NoneGet all trading symbolsSymbol[]
symbolsGetAsync()NoneGet symbols asynchronouslyPromise

GroupApi Methods

MethodParametersDescriptionReturns
groupsGet()NoneGet all group namesstring[]
groupGroupNameGet($name)name: Group nameGet group detailsGroup
groupsGetAsync()NoneGet groups asynchronouslyPromise
groupGroupNameGetAsync($name)name: Group nameGet group asyncPromise

Use Cases

function isValidSymbol($symbolName, $symbolApi) {
    try {
        $symbols = $symbolApi->symbolsGet();
        
        foreach ($symbols as $symbol) {
            if (strtoupper($symbol->getSymbol()) === strtoupper($symbolName)) {
                return true;
            }
        }
        return false;
    } catch (\D4T\MT5Sdk\ApiException $e) {
        return false;
    }
}

// Validate before placing order
if (isValidSymbol('EURUSD', $symbolApi)) {
    // Proceed with order
}

Best Practices

  1. Caching: Cache symbol and group data to reduce API calls
  2. Validation: Always validate symbols before using them in trading operations
  3. Error Handling: Implement proper error handling for API failures
  4. Async Loading: Use async methods when loading large datasets
  5. Category Organization: Organize symbols by category for better user experience
  6. Group Escaping: Remember to properly escape backslashes in group names (demo\\\\demoforex)
Group names containing backslashes (path separators) must be properly escaped when used in API calls. For example, demo\demoforex should be passed as demo\\\\demoforex in PHP strings.

Performance Optimization

// Implement caching to reduce API calls
class CachedMarketData {
    private $cache = [];
    private $ttl = 3600; // 1 hour
    
    public function getSymbols($symbolApi) {
        if (isset($this->cache['symbols']) && 
            time() - $this->cache['symbols']['time'] < $this->ttl) {
            return $this->cache['symbols']['data'];
        }
        
        $symbols = $symbolApi->symbolsGet();
        $this->cache['symbols'] = [
            'data' => $symbols,
            'time' => time()
        ];
        
        return $symbols;
    }
}

Next Steps