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.
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 );
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.
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 );
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 " ;
}
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
Symbol Browser
Symbol Information Lookup
Group Configuration Report
Market Data Service
<? 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:
Property Type Description symbolstring Symbol name (e.g., EURUSD) descriptionstring Human-readable description pathstring Category path digitsinteger Price decimal places contract_sizefloat Size of 1 lot currency_basestring Base currency currency_profitstring Profit currency currency_marginstring Margin currency tick_sizefloat Minimum price change tick_valuefloat Value of 1 tick volume_minfloat Minimum trade volume volume_maxfloat Maximum trade volume volume_stepfloat Volume increment step
Group Properties
The Group model contains trading group configuration:
Property Type Description groupstring Group name companystring Company name currencystring Account currency leverageinteger Maximum leverage margin_callfloat Margin call level (%) margin_stopoutfloat Stop out level (%) deposit_defaultfloat Default deposit amount reportsboolean Reports enabled newsboolean News 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
Method Parameters Description Returns symbolsGet()None Get all trading symbols Symbol[] symbolsGetAsync()None Get symbols asynchronously Promise
GroupApi Methods
Method Parameters Description Returns groupsGet()None Get all group names string[] groupGroupNameGet($name)name: Group nameGet group details Group groupsGetAsync()None Get groups asynchronously Promise groupGroupNameGetAsync($name)name: Group nameGet group async Promise
Use Cases
Symbol Validation
Group Leverage Check
Symbol Search
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
}
function getGroupLeverage ( $groupName , $groupApi ) {
try {
$group = $groupApi -> groupGroupNameGet ( $groupName );
return $group -> getLeverage ();
} catch ( \D4T\MT5Sdk\ ApiException $e ) {
return null ;
}
}
// Check leverage before user creation
$leverage = getGroupLeverage ( 'demo \\\\ demoforex' , $groupApi );
echo "Maximum leverage: 1: $leverage \n " ;
function searchSymbols ( $query , $symbolApi ) {
try {
$symbols = $symbolApi -> symbolsGet ();
$results = [];
foreach ( $symbols as $symbol ) {
if ( stripos ( $symbol -> getSymbol (), $query ) !== false ||
stripos ( $symbol -> getDescription (), $query ) !== false ) {
$results [] = [
'symbol' => $symbol -> getSymbol (),
'description' => $symbol -> getDescription ()
];
}
}
return $results ;
} catch ( \D4T\MT5Sdk\ ApiException $e ) {
return [];
}
}
// Search for EUR symbols
$results = searchSymbols ( 'EUR' , $symbolApi );
foreach ( $results as $result ) {
echo "{ $result ['symbol']}: { $result ['description']} \n " ;
}
Best Practices
Caching : Cache symbol and group data to reduce API calls
Validation : Always validate symbols before using them in trading operations
Error Handling : Implement proper error handling for API failures
Async Loading : Use async methods when loading large datasets
Category Organization : Organize symbols by category for better user experience
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.
// 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