Gamestudio Links
Zorro Links
Newest Posts
Trading Journey
by howardR. 04/28/24 09:55
basik85278
by basik85278. 04/28/24 08:56
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Help with plotting multiple ZigZag
by M_D. 04/26/24 20:03
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
M1 Oversampling
by jcl. 04/26/24 11:12
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
Eigenwerbung
by jcl. 04/26/24 11:08
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, Quad), 755 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
wandaluciaia, Mega_Rod, EternallyCurious, howardR, 11honza11
19049 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Http function script for trading API #463466
12/05/16 19:50
12/05/16 19:50
Joined: Dec 2016
Posts: 43
F
Fiber Offline OP
Newbie
Fiber  Offline OP
Newbie
F

Joined: Dec 2016
Posts: 43
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!}
  }


Re: Http function script for trading API [Re: Fiber] #463506
12/09/16 09:07
12/09/16 09:07
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
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.

Re: Http function script for trading API [Re: jcl] #463525
12/09/16 23:01
12/09/16 23:01
Joined: Oct 2016
Posts: 23
NSW
M
mayark Offline
Newbie
mayark  Offline
Newbie
M

Joined: Oct 2016
Posts: 23
NSW
with PHP and couple of other languages, the same concept seems to work with the broker.

Re: Http function script for trading API [Re: mayark] #463526
12/10/16 10:43
12/10/16 10:43
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
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.

Re: Http function script for trading API [Re: jcl] #463597
12/15/16 15:09
12/15/16 15:09
Joined: Dec 2016
Posts: 43
F
Fiber Offline OP
Newbie
Fiber  Offline OP
Newbie
F

Joined: Dec 2016
Posts: 43
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!
}


Re: Http function script for trading API [Re: Fiber] #463598
12/15/16 15:22
12/15/16 15:22
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
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.

Re: Http function script for trading API [Re: jcl] #463639
12/19/16 11:37
12/19/16 11:37
Joined: Oct 2016
Posts: 23
NSW
M
mayark Offline
Newbie
mayark  Offline
Newbie
M

Joined: Oct 2016
Posts: 23
NSW
May be also try removing the below bit if what jcl highlighted

&rand=

Re: Http function script for trading API [Re: mayark] #463710
12/22/16 12:03
12/22/16 12:03
Joined: Dec 2016
Posts: 43
F
Fiber Offline OP
Newbie
Fiber  Offline OP
Newbie
F

Joined: Dec 2016
Posts: 43
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");
}



Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1