HTTP functions

The HTTP functions can retreive or scrape content - prices, signals, news, or indicators - from external websites and use them in the trading strategy. They can also execute PHP scripts f.i. for sending emails from a web server, or can be used by a broker plugin for communicating with a REST or FIX API.

http_transfer (string url, string data): string

Transfers data to or from the web address given by url. The function waits until the web page content or the PHP script response is transferred back to Zorro. The data string can contain arguments to be passed to a PHP script (such as the content of an email). The function returns a temporary string containing the web page content for further evaluation; the content remains valid until the next http_transfer call. The number of bytes received can be retrieved with http_status(0).

http_send (string url, string data, string header): int

Starts a HTTP_GET (when data == 0) or HTTP POST (when data != 0) data transfer to or from a web address. The function returns a identifier number (id) for controlling the data transfer with http_status. The data string can contain arguments to be passed to the PHP script (such as the content of an email). If the data string begins with a '#' character, the following word, ending with a space, is used for the request type instead of POST (f.i. "#DELETE ...", "#PATCH ...", or "#HTTPGET"). The header string can contain custom headers f.i. for authorization, or 0 for not using a custom header. After the transfer is finished, the identifier number must be freed with http_free.

http_proxy (string proxy, int port)

Sets up a HTTP proxy server for the connection to the Internet. If no proxy is used, or if you don't know what a HTTP proxy is, you won't need this function.

http_status (int id): long

Returns the number of bytes received with the HTTP data transfer with the identifier id, or the number of bytes received with the last http_transfer call when id == 0, or the transfer status info: 0  - transfer is still in progress; -1 - transfer failed; -2 - id is invalid; -3 - website did not respond; -4 - host could not be resolved..

http_result (int id, string content, long size): long

Stores the received data of a HTTP data transfer in the content string, up to size bytes, and returns the received number of bytes. A string terminator (0) is added at the end of the received data.

http_free (int id)

Frees the identifier number of a HTTP data transfer and stops the transfer. Must be called at the end of each HTTP data transfer. For stopping the last transfer, set id to 0.


proxy - proxy server name (example: "").
port - port of the proxy server (example: 8080).
url - URL of the web page (examples: "" or ""). 
data - string (or char array) containing the data to be sent (example: "user=John&password=Secret"), or 0 for no data.
content - string (or char array) to receive the web page content or the result data of a HTTP POST operation.
header - one or several header strings separated by line feeds ('\n'):
size - maximum number of characters to be received, or 0 for using the actual content string length.
id - identifier number, returned by http_post().



// access the CFTC website, read the current Commitment Of Traders Report,
// and store it in a file.
function main()
{ file_delete("cot.txt"); // delete previous report file_append("cot.txt", http_transfer("",0)); }
// get current date and time from the Internet
function main()
{ string Response = http_transfer("",0); string Date = strtext(Response,"\"datetime\":","0"); printf("\n%s",Date); }
// Download historical EOD price data from Google
function main()
  string Code = "SPY";
  string URL = strf("",Code);
  string Content = http_transfer(URL,0);
  if(!Content) continue;
// start the script "ip.php" on a remote server, and 
// print dots until Zorro's IP address is returned
function main() { char ip_str[100]; // just a long empty string int id = http_post("",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,100); //get the replied IP printf("\n%s",ip_str); } else printf("\nError during transfer!"); http_free(id); //always clean up the id! } ip.php: <?php
echo "Your IP address: " . $_SERVER['REMOTE_ADDR'];
// send an email when a trade is entered
function sendEmailAboutTrade()
// compose the message
  string Content = strf("content=Zorro has entered a trade!\n%d Lots of %s",

$to = "";
$subject = "Message from Zorro!";
$body = $_POST['content'];

See also:

ftp functions, file functions, email

► latest version online