# Trading API in PHP requires SOAP extension enabled $soap_client = new SoapClient(‘http://client-api.instaforex.com/soapservices/ClientTrading.svc?wsdl’, array(‘trace’=> 1,’exceptions’ => 0)); $soap_client->soap_defencoding = ‘UTF-8’; # Data for authorizing and getting a token. # Password is sent at Trading API activation $data = array( “Login” => 1231231, “Password” => ‘TestPwd’ ); # Generating authorization data $authdata = array(‘tokenRequest’ => $data); $token = $soap_client->GetAuthenticationToken($authdata); $token = $token->GetAuthenticationTokenResult->Token; $tradeParams = array( “Comment” => “API test”, “Login” => 123456, “Price” => 1.3874, // optional “Deviation” => 1, // optional, max deviation from the current price “Symbol” => “EURUSD”, “Token” => $token, “Type” => “Buy”, “Volume” => 1 ); $BuyData = array(‘tradeTransactionRequest’ => $tradeParams); $result = $soap_client->SetTradeOrder($BuyData); if (is_soap_fault($result)) { # If the resource server returned an error – the error output and its reasons echo “
” ,(“SOAP Fault: (faultcode: {$result->faultcode}, faultstring: {$result->faultstring})”), “
Details:
", print_r($result->detail, true), "
“; }