Using Yahoo-Stock-Quote Webservice.
dyn_float getQuote(string symbol)
{
// http://download.finance.yahoo.com/d/quotes.csv?s=%s&f=l1v"
string request = "GET /d/quotes.csv?s=%s&f=l1v HTTP/1.1\r\n"
"Connection: keep-alive\r\n"
"Host: download.finance.yahoo.com\n\n";
sprintf(request, request, symbol);
DebugTN("getQuote", symbol);
string response;
int socket=tcpOpen("download.finance.yahoo.com", 80);
tcpWrite(socket, request);
tcpRead(socket, response, 3);
tcpClose(socket);
strreplace(response, "\r", "");
dyn_string lines = strsplit(response, "\n");
// print response lines (debug)
for ( int i=1; i<=dynlen(lines); i++ )
DebugTN(i, lines[i]);
// extract the information we want
if ( dynlen(lines) >= 13 ) {
dyn_string cols=strsplit(lines[13], ",");
float f1, f2;
if ( dynlen(cols) > 0 ) sscanf(cols[1], "%f", f1);
if ( dynlen(cols) > 1 ) sscanf(cols[2], "%f", f2);
DebugTN(symbol, f1, f2);
return makeDynFloat(f1, f2);
}
}