HTTP Object
The HTTP object allows EFS to open a file from a URL to import data for use within the EFS script. The HTTP functionality can be used to read text files (e.g., .txt, .htm, .html, .xml, etc.)
Notes:
- It is highly recommended that you do not use the HTTP object within the main() function where it has the potential of being called on every new trade. Instead, use the HTTP object either in the preMain() function or in custom user functions that are only called when needed. Either call it once when the script initializes or call it when specific logic triggers.
- Always prefix the url in question with http://
- Always match the case of any files you are retrieving using HTTP() (i.e., MyFile.txt is not the same as myfile.txt).
- If a page is not downloading properly, try adding another forward slash ( / ) to any single forward slashes in the url (i.e. http://www.somepage.com//MyFile.txt).
HTTP Methods
open() |
URL of page to retrieve |
readln() |
read a line from page |
eof() |
check for end-of-file condition |
Usage
var v = new HTTP("http://www.somepage.com/whatever.txt");
OR
var v =new HTTP("http://www.somepage.com/something.asp?symbol=" + getSymbol());
//After constructing the object, do something like this:
if(v.open()) {
while(!v.eof()) {
debugPrintln(v.readln());
}
}
//Here's an example of a custom function for
//loading a text file from a URL, which can
//be called from preMain().
//The MyFile.txt file would need to contain 6
//numbers, each on a separate line. This example
//populates a global array with the 6 numbers
//from MyFile.txt.
var aArray = new Array(6);
function preMain() {
loadData();
}
function loadData() {
var f = new HTTP("http://www.somepage.com/MyFile.txt");
var i = 0;
f.open("rt");
if (f.open()) {
for (i = 0; i < 6; ++i) {
aArray[i] = f.readln();
}
}
f = null;
//debugPrintln(aArray);
return;
}