Http function script for trading API

Posted By: Fiber

Http function script for trading API - 12/05/16 19:50

I'm trying to sent http line to open position.
API description and example - https://trade4.me/API/
My Url:
https://trade4.me/order.php?username=Fib...=1&amount=1
It's demo account, you can test.

If I insert it to the browser window it works fine and I get respond:
Signal Successfully Traded : ID 11292781628, Open Price 0, Open Time 2016-12-05 19:36:36, Expiry Time 2016-12-05 19:37:36

I tried to use script from Zorro Manual example, but got message "Error during transfer!"
Also I tried to use http_send, or remove all code and leave only http_post command, but without success.
Any ideas to solve it?

Code:
void main()
{
  char ip_str[200]; // just a long empty string
  int id = http_post("https://trade4.me/order.php?username=Fiber100&password=Awainter1t&asset=EUR/USD&direction=UP&expiry=1&amount=1",0); 
  if(!id) return;
  while(!http_status(id)) 
	{
		if(!wait(100)) return; // wait for the server to reply    
		printf(".");  
	}
  if(http_status(id) > 0) 
	{	//transfer successful?
		http_result(id,ip_str,200);   //get the replied IP    
		printf("n%s",ip_str);
	} 
	else    printf("nError during transfer!");
	
  http_free(id); //always clean up the id!}
  }

Posted By: jcl

Re: Http function script for trading API - 12/09/16 09:07

Your code looks correct at first glance. Maybe it's something specific to that server. This would be an issue for Support to look into.
Posted By: mayark

Re: Http function script for trading API - 12/09/16 23:01

with PHP and couple of other languages, the same concept seems to work with the broker.
Posted By: jcl

Re: Http function script for trading API - 12/10/16 10:43

Not for me. I've just tried it and the trade4me server always responds "Input validation failed: parameters.symbol" - no matter if I enter the string in the browser or run your script above. So far I see no difference between running the script or directly sending the string. Maybe the server is not working during the weekend.
Posted By: Fiber

Re: Http function script for trading API - 12/15/16 15:09

I solved it by changing https to http.
Also added string data "123" (any number), otherwise new position is not opened, server responds with confirmation of previously opened trade.
Code:
// ------------------------- Trade4me/binary.com API
  
function main()
{
  char ip_str[100]; // just a long empty string
  int id = http_post("http://trade4.me/order.php?username=Fiber100&password=Awainter1t&asset=EUR/USD&direction=UP&expiry=1&amount=10&rand=","123");
  if(!id) return;
  while(!http_status(id)) {
    if(!wait(100)) return; // wait for the server to reply
    printf(".");
  }  if(http_status(id) > 0) { //transfer successful?
    http_result(id,ip_str,100);   //get the replied IP
    printf("n%s",ip_str);
  } else
    printf("nError during transfer!");
  http_free(id); //always clean up the id!
}


Only thing I couldn't resolve how to insert variables into http for instrument, direction, duration and stake.
Error in 'line 11:
Can not convert '' to 'ARRAY'
Code:
// ------------------------- Trade4me/binary.com API
  
function main()
{
  char ip_str[100]; // just a long empty string
  string Instr = "EUR/USD";
  string Direction = "UP";
  string Exp = "1";
  string Size = "10";
  int id = http_post("http://trade4.me/order.php?username=Fiber100&password=Awainter1t&asset="+Instr+"&direction="+Direction+"&expiry="+Exp+"&amount="+Size+"&rand=","123");
  if(!id) return;
  while(!http_status(id)) {
    if(!wait(100)) return; // wait for the server to reply
    printf(".");
  }  if(http_status(id) > 0) { //transfer successful?
    http_result(id,ip_str,100);   //get the replied IP
    printf("n%s",ip_str);
  } else
    printf("nError during transfer!");
  http_free(id); //always clean up the id!
}

Posted By: jcl

Re: Http function script for trading API - 12/15/16 15:22

HTTPS is supported, so that can normally not cause a problem unless you're using a very old Zorro version.

For inserting numbers into text, use the "strf" function - you can find many examples, it's an often used function.
Posted By: mayark

Re: Http function script for trading API - 12/19/16 11:37

May be also try removing the below bit if what jcl highlighted

&rand=
Posted By: Fiber

Re: Http function script for trading API - 12/22/16 12:03

Without &rand= trade is executed only once and on next command instead of opening another trade server returns confirmation of previously executed trade.
Zorro version 1.50, but https doesn't work.

My last working version:

Code:
// ------------------------- Trade4me/binary.com API - 2

function Trade4me( string Instrument, string Direction, string Exp, string Size)
{
  char ip_str[100]; // just a long empty string
  string httpline[200];
  sprintf(httpline,"http://trade4.me/order.php?username=Fiber100&password=Awainter1t&asset=%s&direction=%s&expiry=%s&amount=%s&rand=",Instrument,Direction,Exp,Size);
  int id = http_post(httpline,"123");
  if(!id) return;
  while(!http_status(id)) {
    if(!wait(100)) return; // wait for the server to reply
    printf(".");
  }  if(http_status(id) > 0) { //transfer successful?
    http_result(id,ip_str,100);   //get the replied IP
    printf("n%s",ip_str);
  } else
    printf("nError during transfer!");
  http_free(id); //always clean up the id!
}

function main()
{
	Trade4me ("EUR/USD","UP","5","10");
}

© 2024 lite-C Forums