Skip to the content.

MetaQuotes MT5 WebAPI Laravel Wrapper

All of the functionality of the MT5 WebAPI fully integrated with Laravel. This is a composer package for Laravel that brings all of the MT5 Trader (API) from MetaQuotes functionality to your Laravel application.

This documentation references a private repository - so GitHub links return a 404 Error.

To get access you must purchase a license

Last Update: April 11 1, 2023

Buy Now - $250 Purchase includes repository access and all future updates as well as any support you may need. Maintenance and ownership of this package has been sold and transferred to NerdSnipe


Welcome

Use this package to make use of all MetaQuotes MT5 API Functionality inside your Laravel Application. You can also use this to enable REST API Access to MT5 and get access to all source API functionality.

Full source and repository access available upon purchase and includes lifetime free updates.

Installation

Add the following to the repositories section of your composer.json file

    "repositories": [
      {
        {
            "type": "vcs",
            "url": "https://github.com/NerdSnipe/mt5webapi.git"
        }
      }
    ]

Then add the following to the require section

  "nerdsnipe/mt5webapi": "dev-master",

You will now need to add a key (issued on purchase) in the config section of your composer.json file to enable repository access

"config": {
        "github-oauth": {
            "github.com": "Issued_Key_From_Purchase"
        }
    },

Now run

composer install or composer update depending on your preference

Configuration

After installing the package - find and open the config/metaquotes.php configuration file. Here is where you set up the server details, authentication etc.


<?php

return [
    /*
    |--------------------------------------------------------------------------
    | MT5 Credentials
    |--------------------------------------------------------------------------
    |
    | this is credentials for access to the mt5 server account
    |
    */

    'mt5' => [
        'ip' => env('MT5_SERVER_IP', '127.0.0.1'),
        'port' => env('MT5_SERVER_PORT', 443),
        'login' => env('MT5_SERVER_WEB_LOGIN', ''),
        'password' => env('MT5_SERVER_WEB_PASSWORD', ''),
    ],

    /*
    |--------------------------------------------------------------------------
    | Package Route and Middleware
    |--------------------------------------------------------------------------
    |
    | this is where you set the routes used by the package
    |
    */
    'route' => [
        'prefix' => 'mt5',
        'middleware' => ['web'],
    ],
    
    /*
    |--------------------------------------------------------------------------
    | Package To Be Used With REST End Points
    |--------------------------------------------------------------------------
    |
    | this is where you set enable the REST endpoints.
    |
    */    
    'enable_rest' => false,

    'locale'    => 'en_US',

    'timezone' => "Asia/Bangkok",
];

Usage

This is a basic review of the functionality but you are free to use included methods as required to fit your specific needs

Get Account Details

End Point: /mt5/account/100001 will return a view of the account details. By adding /data to the end of that route /mt5/account/100001/data you have the account details as JSON.

This information can also be called programmatically:

To get results as JSON

    /**
     * Returns the full details of the MT5 Account
     *
     * @param $meta_id
     * @param bool $justData
     * @return false|string |null
     */ 
    Mt5Controller::account(100001, true) 

Example Output:

{
  "Login": 100001,
  "CurrencyDigits": 2,
  "Balance": 9251701.96,
  "Credit": 0,
  "Margin": 124.03,
  "MarginFree": 9251575.73,
  "MarginLevel": 7459243.54,
  "MarginLeverage": 500,
  "Profit": -2.2,
  "Storage": 0,
  "Commission": 0,
  "Floating": -2.2,
  "Equity": 9251699.76,
  "SOActivation": 0,
  "SOTime": 0,
  "SOLevel": 0,
  "SOEquity": 0,
  "SOMargin": 0,
  "Assets": 0,
  "Liabilities": 0,
  "BlockedCommission": 0,
  "BlockedProfit": -35919.77,
  "MarginInitial": 0,
  "MarginMaintenance": 0
}

Get User Details

End Point: /mt5/user/100001 will return a view of the user details. By adding /data to the end of that route /mt5/user/100001/data you have the user details as JSON.

This information can also be called programmatically:

To get results as JSON

    /**
     * Returns all the MT5 user details
     *
     * @param int $meta_id MT5 Id of the contact
     * @param bool $justData
     * @return MTUser
     */
    Mt5Controller::user(100001, true) 

Example Output: (some values have been changed for security)

{
  "Login": 100001,
  "Group": "managers\\administrators",
  "CertSerialNumber": 0,
  "Rights": 6627,
  "MQID": "xxxxx",
  "Registration": 11111,
  "LastAccess": 1572676989,
  "LastPassChange": 1515853068,
  "LastIP": "0.0.0.0",
  "Name": "The Users Name",
  "Company": "",
  "Account": "",
  "Country": "Hong Kong S.A.R.",
  "Language": 9,
  "ClientID": 999999,
  "City": "",
  "State": "",
  "ZipCode": "",
  "Address": "",
  "Phone": "",
  "Email": "",
  "ID": "",
  "Status": "",
  "Comment": "",
  "Color": 15624315,
  "PhonePassword": "",
  "Leverage": 500,
  "Agent": 0,
  "Balance": 9251701.96,
  "Credit": 0,
  "InterestRate": 0,
  "CommissionDaily": 0,
  "CommissionMonthly": 0,
  "BalancePrevDay": 0,
  "BalancePrevMonth": 0,
  "EquityPrevDay": 0,
  "EquityPrevMonth": 0,
  "TradeAccounts": "",
  "LeadCampaign": "WebInstaller",
  "LeadSource": "download.mql5.com",
  "MainPassword": null,
  "InvestPassword": null
}

Get User Positions

End Point: /mt5/positions/100001 will return a view of the user’s positions. By adding /data to the end of that route /mt5/positions/100001/data you have the results as JSON.

This information can also be called programmatically:

To get results as JSON

    /**
     * Get the list of open positions for this user
     *
     * @param $meta_id
     * @param bool $justData
     * @return array
     */
    Mt5Controller::positions(100001, true) 

Example Output:

[
  {
    "Position": 4914645,
    "ExternalID": "",
    "Login": 100001,
    "Dealer": 0,
    "Symbol": "BTCUSD",
    "Action": 0,
    "Digits": 2,
    "DigitsCurrency": 2,
    "Reason": 2,
    "ContractSize": 1,
    "TimeCreate": 1572407504,
    "TimeUpdate": 1572407504,
    "ModifyFlags": 0,
    "PriceOpen": 9350,
    "PriceCurrent": 9230,
    "PriceSL": 0,
    "PriceTP": 0,
    "Volume": 1,
    "VolumeExt": 10000,
    "Profit": -0.01,
    "Storage": 0,
    "RateProfit": 1,
    "RateMargin": 1,
    "ExpertID": 0,
    "ExpertPositionID": 4914645,
    "Comment": " ",
    "ActivationMode": 0,
    "ActivationTime": 0,
    "ActivationPrice": 0,
    "ActivationFlags": 0
  }
]

Get User Deals

End Point: /mt5/deals/100001 will return a view of the account deals. By adding /data to the end of that route /mt5/deals/100001/data you have the deals as JSON.

This information can also be called programmatically:

To get results as JSON

    /**
     * Get the list of deals for this user
     *
     * @param $meta_id
     * @param bool $justData
     * @param int $offset
     * @return array
     */
    Mt5Controller::deals(100001, true)             

Example Output:

(A single deal is shown here - method returns full array of all user deals)

[
  {
    "Deal": 1538866,
    "ExternalID": "",
    "Login": 100001,
    "Dealer": 0,
    "Order": 2744366,
    "Action": 0,
    "Entry": 0,
    "Reason": 2,
    "Digits": 5,
    "DigitsCurrency": 2,
    "ContractSize": 100000,
    "Time": 1550139278,
    "TimeMsc": 1550139278391,
    "Symbol": "EURUSD",
    "Price": 1.12754,
    "Volume": 10000,
    "VolumeExt": 100000000,
    "Profit": 0,
    "Storage": 0,
    "Commission": 0,
    "RateProfit": 0,
    "RateMargin": 1,
    "ExpertID": 0,
    "PositionID": 2744366,
    "Comment": "",
    "ProfitRaw": 0,
    "PricePosition": 0,
    "VolumeClosed": 0,
    "VolumeClosedExt": 0,
    "TickValue": 0,
    "TickSize": 0,
    "Flags": 0,
    "Gateway": "",
    "PriceGateway": 0,
    "ModifyFlags": 0,
    "PriceSL": 0,
    "PriceTP": 0
  }
]

Get User Orders

End Point: /mt5/orders/100001 will return a view of the account orders. By adding /data to the end of that route /mt5/orders/100001/data you have the orders as JSON.

This information can also be called programmatically:

To get results as JSON

    /**
     * Get the list of orders for this user
     *
     * @param $meta_id
     * @param bool $justData
     * @return array
     */
    Mt5Controller::orders(100001, true)

Example Output:

Get Symbols The User’s Group Has Access To

End Point: /mt5/symbols/100001 will return a view of the symbols. By adding /data to the end of that route /mt5/symbols/100001/data you have the symbols as JSON.

This information can also be called programmatically:

To get results as JSON

    /**
     * Get the list of symbols this user/group has access to
     *
     * @param $meta_id
     * @param bool $justData
     * @return false|string
     */
    Mt5Controller::symbols(100001, true)

Example Output:

(A single symbol is shown here - method returns full array of all available symbols)

{
  "Path": "Indices FXE\\AUS200.fxe",
  "TradeMode": 4294967295,
  "ExecMode": 4294967295,
  "FillFlags": 4294967295,
  "ExpirFlags": 4294967295,
  "OrderFlags": 0,
  "SpreadDiff": 0,
  "SpreadDiffBalance": 0,
  "StopsLevel": 2147483647,
  "FreezeLevel": 2147483647,
  "VolumeMin": 1.8446744073709552e+19,
  "VolumeMinExt": 1.8446744073709552e+19,
  "VolumeMax": 1.8446744073709552e+19,
  "VolumeMaxExt": 1.8446744073709552e+19,
  "VolumeStep": 1.8446744073709552e+19,
  "VolumeStepExt": 1.8446744073709552e+19,
  "VolumeLimit": 1.8446744073709552e+19,
  "VolumeLimitExt": 1.8446744073709552e+19,
  "MarginFlags": 4294967295,
  "MarginInitial": 1.7976931348623157e+308,
  "MarginMaintenance": 1.7976931348623157e+308,
  "MarginRateInitial": [
    "default",
    "default",
    "default",
    "default",
    "default",
    "default",
    "default",
    "default"
  ],
  "MarginRateMaintenance": [
    "default",
    "default",
    "default",
    "default",
    "default",
    "default",
    "default",
    "default"
  ],
  "MarginRateLiquidity": 1.7976931348623157e+308,
  "MarginHedged": 1.7976931348623157e+308,
  "MarginRateCurrency": 1.7976931348623157e+308,
  "MarginLong": "default",
  "MarginShort": "default",
  "MarginLimit": 0,
  "MarginStop": 0,
  "MarginStopLimit": 0,
  "SwapMode": 4294967295,
  "SwapLong": 1.7976931348623157e+308,
  "SwapShort": 1.7976931348623157e+308,
  "Swap3Day": 2147483647,
  "REFlags": 4294967295,
  "RETimeout": 4294967295,
  "IEFlags": 4294967295,
  "IECheckMode": 4294967295,
  "IETimeout": 4294967295,
  "IESlipProfit": 4294967295,
  "IESlipLosing": 4294967295,
  "IEVolumeMax": 1.8446744073709552e+19,
  "IEVolumeMaxExt": 1.8446744073709552e+19,
  "PermissionsFlags": 1,
  "BookDepthLimit": 0
}

Send News Into The Platform

This method allows you to send news directly to the trader’s accounts.

This will return true if success

    /**
     * Sends News Into the Platform Accounts
     *
     * @param string $subject
     * @param string $category
     * @param $html_message
     * @param string $language
     * @param string $priority
     * @return bool
     */
    Mt5Controller::sendNews($subject,$category,$html_message,$language,$priority)

Send Mail to the User’s Platform Inbox

This method allows you to send messages directly to the trader’s inbox.

This will return true if success

    /**
     * Sends Messages to the Traders Platform Inbox
     * 
     * @param int $meta_id
     * @param string $subject
     * @param $html_message
     * @return bool
     */
    Mt5Controller::sendMail($meta_id,$subject,$html_message)

Create a New Platform Account

    $account_details = array(
        'Email'         => '', // * required
        'MainPassword'  => '', // * required
        'Agent'         => '',
        'LeadSource'    => '',
        'Group'         => '', // * required
        'Leverage'      => '', // defaults to 1:1
        'ZipCode'       => '',
        'Country'       => '',
        'State'         => '',
        'City'          => '',
        'Address'       => '',
        'Phone'         => '',
        'FirstName'     => '', 
        'LastName'      => '', 
        'PhonePassword' => '',
        'InvestPassword' => '',
    );
    /**
     * Creates a new user account in the MT5 Platform
     *
     * @param array $account_details
     * @return int $login_id
     */
    Mt5Controller::create($account_details)

Deposit Funds To Account

    /**
     * Used to deposit funds to the member ($meta_id) account in the MT5 Platform
     *
     * @param int $meta_id Login ID of the account to credit
     * @param mixed $trans_id Transaction Id of the 3rd-party payment processor
     * @param int $amount Amount to credit the account
     */
    Mt5Controller::deposit($meta_id,$trans_id,$amount)

Withdrawal Funds From Account

    /**
     * Used to witdrawal funds from the member ($meta_id) account in the MT5 Platform
     *
     * @param int $meta_id Login ID of the account to debit
     * @param mixed $trans_id Transaction Id of the 3rd-party payment processor
     * @param int $amount Amount to debit the account 
     */
    Mt5Controller::withdrawal($meta_id,$trans_id,$amount)

Buy Now - $250