Download the PHP package aleedhillon/meta-trader-client without Composer
On this page you can find all versions of the php package aleedhillon/meta-trader-client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download aleedhillon/meta-trader-client
More information about aleedhillon/meta-trader-client
Files in aleedhillon/meta-trader-client
Package meta-trader-client
Short Description A Laravel package for seamless integration with the MetaTrader 5 web API, enabling account management, trading operations, and more.
License MIT
Homepage https://github.com/aleedhillon/meta-trader-client
Informations about the package meta-trader-client
MetaTrader Client for Laravel
A powerful Laravel package for seamless integration with the MetaTrader 5 Web API. This package enables brokers and financial applications to connect with MT5 servers and perform various operations including account management, trading operations, and market data retrieval.
โจ Modernized for PHP 8.4 - Features modern PHP syntax, proper exception handling, type safety, and clean API design.
๐ Features
- ๐ Server Connection Management: Establish secure connections to MT5 servers with automatic connection handling
- ๐ฅ User Management: Create, update, and manage trading accounts with full lifecycle support
- ๐ Trading Operations: Execute trades, manage orders and positions with real-time updates
- ๐ Market Data: Access real-time quotes, ticks, and symbol information
- ๐ฅ Group Management: Create and manage user groups with flexible permissions
- โ๏ธ Symbol Configuration: Configure trading instruments with advanced settings
- ๐ง Communication Tools: Send emails and news to platform users
- ๐จ Exception Handling: Comprehensive exception system with specific error types
- ๐ Type Safety: Modern PHP 8.4 with strict typing and null safety
- ๐ฏ Clean API: No more reference parameters - all methods return values directly
๐ Installation
You can install the package via composer:
The package will automatically register its service provider and facade.
โ๏ธ Configuration
Publish the configuration file:
This will create a config/meta-trader-client.php
file with the following content:
Add the following environment variables to your .env
file:
๐ฏ Exception Handling
The modernized client uses a comprehensive exception system instead of return codes. All exceptions extend MetaTraderException
:
Exception Types
- AuthenticationException - Authentication and authorization errors (codes 1000-1023)
- ConfigurationException - Configuration and setup errors (codes 2000-2012)
- UserManagementException - User management operations (codes 3001-3012)
- TradeManagementException - Trade management operations (codes 4001-4005)
- TradingException - Trading operations (codes 10001-11002)
- ReportException - Report generation (codes 5001-6001)
- NetworkException - Network and connection issues (codes 7-10)
๐ Usage
Basic Connection
The client now features automatic connection management - you don't need to manually connect/disconnect:
User Management
All user management methods now return objects directly and throw exceptions on errors:
Trading Operations
Trading operations now return objects directly with full type safety:
Market Data
Market data operations with modern return types:
Group Management
Group management with modern API design:
Symbol Management
Symbol configuration with type-safe operations:
Communication
Send notifications with error handling:
Server Management
Server operations with modern exception handling:
Custom Commands
Execute custom commands with structured responses:
Utility Methods
The client provides many static utility methods for working with MT5 data:
๐งช Development & Testing
Using Workbench
This package includes a Workbench environment for development and testing. The workbench provides a complete Laravel application environment to test the package functionality.
Setup Workbench
-
Copy the environment file:
-
Configure your MT5 server details in
workbench/.env
: - Test the connection:
Available Commands
- Test Connection:
php vendor/bin/testbench test:mt5
- Demo Mode:
php vendor/bin/testbench test:mt5 --demo
- Status Check:
php vendor/bin/testbench mt5:status
- Configuration Only:
php vendor/bin/testbench mt5:status --config
- Connection Test Only:
php vendor/bin/testbench mt5:status --test
- Serve Application:
composer run serve
(if configured)
The workbench command provides a comprehensive test of your MT5 connection including:
- Server connectivity validation
- Authentication testing
- Server information retrieval
- Error handling demonstration
Package Information
View package information using Laravel's built-in about command:
This will display MetaTrader Client information including version, WebAPI details, and Laravel compatibility.
Advanced Publishing Options
For more specific publishing needs, you can also use:
Note: The --provider
flag publishes all publishable files defined by the package's service provider, giving you access to all available resources in one command.
Artisan Commands
The package includes comprehensive Artisan commands to help you manage and monitor your MT5 integration:
mt5
- Package Information & Configuration
Display package configuration and basic information without making any API calls.
What it shows:
- ๐ Configuration settings and validation
- ๐ข Version information (package, API, PHP, Laravel)
- ๐ฏ Available commands overview
mt5:status
- Server Status Report
Display server status, connection information, and statistics.
What it shows:
- ๐ Configuration settings and validation
- ๐ Connection status and response time
- ๐ฅ๏ธ Server information (name, owner, product)
- ๐ Server statistics (users, deals, orders, positions)
- ๐ License information and expiration dates
- ๐ข Version information (package, API, PHP, Laravel)
mt5:groups
- Display All Trading Groups
Show all trading groups with progress indicator.
What it shows:
- ๐ฅ Complete list of all trading groups
- ๐ Group details (name, company, currency, leverage)
- ๐ Progress bar during data loading
- โ Total count and completion status
mt5:symbols
- Display All Trading Symbols
Show all trading symbols with progress indicator.
What it shows:
- ๐ Complete list of all trading symbols
- ๐ Symbol details (name, description, currencies, digits, path)
- ๐ Progress bar during data loading
- โ Total count and completion status
Example Outputs:
mt5
Command Example:
mt5:status
Command Example:
mt5:groups
Command Example:
mt5:symbols
Command Example:
General Laravel Commands
๐ง Advanced Usage
Error Code to Exception Mapping
The client automatically maps MT5 error codes to specific exception types:
Direct Instantiation
For advanced use cases, instantiate the client directly:
Configuration Options
Option | Environment Variable | Default | Description |
---|---|---|---|
agent |
MT5_AGENT |
WebAPI |
User agent string for API requests |
should_crypt |
MT5_SHOULD_CRYPT |
true |
Enable/disable connection encryption |
ip |
MT5_SERVER_IP |
null |
MT5 server IP address |
port |
MT5_SERVER_PORT |
443 |
MT5 server port |
login |
MT5_SERVER_WEB_LOGIN |
null |
Web API login |
password |
MT5_SERVER_WEB_PASSWORD |
null |
Web API password |
timeout |
MT5_SERVER_TIMEOUT |
30 |
Connection timeout in seconds |
๐ Complete API Reference
Connection Management
connect()
- Manual Connection
Note: Connection is handled automatically, manual connection is optional.
disconnect()
- Manual Disconnection
isConnected()
- Check Connection Status
ping()
- Test Server Response
Server Information
timeGet()
- Get Detailed Time Information
timeServer()
- Get Server Timestamp
commonGet()
- Get Server Information
serverRestart()
- Restart Server (Admin Only)
User Management
userCreate()
- Create User Template
userAdd()
- Add New User
userGet()
- Get User Information
userUpdate()
- Update User Information
userDelete()
- Delete User
userPasswordCheck()
- Verify User Password
userPasswordChange()
- Change User Password
userDepositChange()
- Change User Balance
userAccountGet()
- Get Account Information
userLogins()
- Get User Logins by Group
Trading Operations
orderGet()
- Get Order Information
orderGetTotal()
- Get Total Orders Count
orderGetPage()
- Get Orders by Page
positionGet()
- Get Position Information
positionGetTotal()
- Get Total Positions Count
positionGetPage()
- Get Positions by Page
dealGet()
- Get Deal Information
dealGetTotal()
- Get Total Deals Count
dealGetPage()
- Get Deals by Page
historyGet()
- Get History Order
historyGetTotal()
- Get History Count
historyGetPage()
- Get History by Page
tradeBalance()
- Execute Balance Operation
Market Data
symbolGet()
- Get Symbol Information
symbolTotal()
- Get Total Symbols Count
symbolNext()
- Get Symbol by Position
symbolGetGroup()
- Get Symbol by Group
symbolCreate()
- Create Symbol Template
symbolAdd()
- Add New Symbol
symbolDelete()
- Delete Symbol
tickLast()
- Get Last Ticks
tickLastGroup()
- Get Last Ticks by Group
tickStat()
- Get Tick Statistics
Group Management
groupTotal()
- Get Total Groups Count
groupNext()
- Get Group by Position
groupGet()
- Get Group Information
groupCreate()
- Create Group Template
groupAdd()
- Add New Group
groupDelete()
- Delete Group
Communication
mailSend()
- Send Email to User
newsSend()
- Send News
Custom Commands
customSend()
- Send Custom Command
Utility Methods
Error Handling
Volume Conversion
Validation
Data Conversion
Time Utilities
Default Values
Version Information
๐ Migration from Legacy Code
If you're upgrading from an older version, here are the key changes:
Before (Legacy)
After (Modern)
๐ API Reference
For a complete list of available methods and their parameters, please refer to the MetaTrader 5 Web API Documentation.
Key Method Changes
- All methods now use
camelCase
naming (e.g.,userGet
instead ofUserGet
) - Methods return objects directly instead of using reference parameters
- All methods throw
MetaTraderException
on errors instead of returning error codes - Automatic connection management - no need to manually connect/disconnect
- Added comprehensive utility methods for data conversion, validation, and formatting
- Static helper methods for working with MT5 data formats, timestamps, and error codes
๐ Security
If you discover any security-related issues, please email [email protected] instead of using the issue tracker.
๐ค Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
๐ License
The MIT License (MIT). Please see the License File for more information.
๐จโ๐ป Credits
- Ali A. Dhillon
- All Contributors