MT4 PHP via COM_DOT_NET.

easy direct connection to any MT4 and MT5 server

MT4 PHP via COM_DOT_NET.

This way works just for Windows hosting.

Lets start with our PHP installation, later you can do all the same with yours PHP installation.
1. Unzip php.zip to c:\
2. Run php/test1/netphp/register_x86. Its php x86 so even if you have x64 system run register_x86.
3. Run php/test1/run.cmd
If no luck let me know, we’ll solve.
In sample used following account that you can open in any MT4 terminal:
user: 67611
pass: wx1yhpn
server: demo.fxgerchik.com

If you want to use your own php you just need to put in php.ini following lines:
[COM_DOT_NET]
extension=php_com_dotnet.dll

<?php

    include_once('netphp/src/Core/ComProxy.php');
    include_once('netphp/src/Core/NetProxy.php');
    include_once('netphp/src/Core/MagicWrapper.php');
    include_once('netphp/src/Core/NetPhpRuntime.php');
 
    try 
    {
        $rt = new \NetPhp\Core\NetPhpRuntime('COM''netutilities.NetPhpRuntime');
        $rt->Initialize();
        $rt->RegisterNetFramework2();
        $rt->RegisterAssemblyFromFile("MT4ServerAPI.dll""MT4ServerAPI");
        
        $qc = $rt->TypeFromName("TradingAPI.MT4Server.QuoteClient");
        $srv = $qc->LoadSrv("GerchikCo-Demo.srv");
		$host = $srv->Host;
        $port = $srv->Port;
		echo $host->Val();
        echo "\n";
        echo $port->Val();
        echo "\n";
        $qc->Instantiate();
        $qc->Init(67611, "wx1yhpn"$host$port);
        $qc->Connect();
        echo "Account balance = ".$qc->AccountBalance->Val()."\n";
        $qc->Subscribe("EURUSD");
        while ($qc->GetQuote("EURUSD")->Val() == null) 
        {
        }
        $ask = $qc->GetQuote("EURUSD")->GetAsk()->Val();
        echo "EURUSD Ask = ".$ask."\n";
 
        $oc = $rt->TypeFromName("TradingAPI.MT4Server.OrderClient");
        $oc->Instantiate();
        $oc->Init($qc);
        $oc->Connect();
        $op = $rt->TypeFromName("TradingAPI.MT4Server.Op");
        $order = $oc->OrderSend("EURUSD"$op->Enum("Buy"), 0.1, $ask, 0, 0.0, 0.0);
        echo "Order opened ".$order->ToString()->Val();
 
    } catch (Exception $e) 
    {
        echo $e->getMessage();
    }
?>

Leave a Reply