{"id":382,"date":"2014-03-15T13:27:14","date_gmt":"2014-03-15T11:27:14","guid":{"rendered":"http:\/\/www.rocworks.at\/wordpress\/?p=382"},"modified":"2014-06-03T10:07:01","modified_gmt":"2014-06-03T08:07:01","slug":"wincc-oa-howto-get-stock-quotes-from-yahoo-httprequest","status":"publish","type":"post","link":"https:\/\/www.rocworks.at\/wordpress\/?p=382","title":{"rendered":"WinCC OA HowTo get Stock-Quotes from Yahoo (HttpRequest)&#8230;"},"content":{"rendered":"<p>Using Yahoo-Stock-Quote Webservice.<br \/>\n<code><\/p>\n<div>dyn_float getQuote(string symbol)<\/div>\n<div>{<\/div>\n<div>\u00a0 \/\/ http:\/\/download.finance.yahoo.com\/d\/quotes.csv?s=%s&amp;f=l1v\"<\/div>\n<div>\u00a0 string request = \"GET \/d\/quotes.csv?s=%s&amp;f=l1v HTTP\/1.1\\r\\n\"<\/div>\n<div>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\"Connection: keep-alive\\r\\n\"<\/div>\n<div>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\"Host: download.finance.yahoo.com\\n\\n\";<\/div>\n<div><\/div>\n<div>\u00a0 sprintf(request, request, symbol);<\/div>\n<div>\u00a0 DebugTN(\"getQuote\", symbol);<\/div>\n<div><\/div>\n<div>\u00a0 string response;<\/div>\n<div>\u00a0 int socket=tcpOpen(\"download.finance.yahoo.com\", 80);<\/div>\n<div>\u00a0 tcpWrite(socket, request);<\/div>\n<div>\u00a0 tcpRead(socket, response, 3);<\/div>\n<div>\u00a0 tcpClose(socket);<\/div>\n<div><\/div>\n<div>\u00a0 strreplace(response, \"\\r\", \"\");<\/div>\n<div>\u00a0 dyn_string lines = strsplit(response, \"\\n\");<\/div>\n<div><\/div>\n<div>\u00a0 \/\/ print response lines (debug)<\/div>\n<div>\u00a0 for ( int i=1; i&lt;=dynlen(lines); i++ )<\/div>\n<div>\u00a0 \u00a0 DebugTN(i, lines[i]);<\/div>\n<div><\/div>\n<div>\u00a0 \/\/ extract the information we want<\/div>\n<div>\u00a0 if ( dynlen(lines) &gt;= 13 ) {<\/div>\n<div>\u00a0 \u00a0 dyn_string cols=strsplit(lines[13], \",\");<\/div>\n<div>\u00a0 \u00a0 float f1, f2;<\/div>\n<div>\u00a0 \u00a0 if ( dynlen(cols) &gt; 0 ) sscanf(cols[1], \"%f\", f1);<\/div>\n<div>\u00a0 \u00a0 if ( dynlen(cols) &gt; 1 ) sscanf(cols[2], \"%f\", f2);<\/div>\n<div>\u00a0 \u00a0 DebugTN(symbol, f1, f2);<\/div>\n<div>\u00a0 \u00a0 return makeDynFloat(f1, f2);<\/div>\n<div>\u00a0 }<\/div>\n<div>}<\/div>\n<div><\/div>\n<p><\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Using Yahoo-Stock-Quote Webservice. dyn_float getQuote(string symbol) { \u00a0 \/\/ http:\/\/download.finance.yahoo.com\/d\/quotes.csv?s=%s&amp;f=l1v&#8221; \u00a0 string request = &#8220;GET \/d\/quotes.csv?s=%s&amp;f=l1v HTTP\/1.1\\r\\n&#8221; \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&#8220;Connection: keep-alive\\r\\n&#8221; \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&#8220;Host: download.finance.yahoo.com\\n\\n&#8221;; \u00a0 sprintf(request, request, symbol); \u00a0 DebugTN(&#8220;getQuote&#8221;, symbol); \u00a0 string response; \u00a0 int socket=tcpOpen(&#8220;download.finance.yahoo.com&#8221;, 80); \u00a0 tcpWrite(socket, &hellip; <a href=\"https:\/\/www.rocworks.at\/wordpress\/?p=382\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">WinCC OA HowTo get Stock-Quotes from Yahoo (HttpRequest)&#8230;<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-382","post","type-post","status-publish","format-standard","hentry","category-wincc-oa"],"_links":{"self":[{"href":"https:\/\/www.rocworks.at\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/382","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rocworks.at\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rocworks.at\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rocworks.at\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rocworks.at\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=382"}],"version-history":[{"count":3,"href":"https:\/\/www.rocworks.at\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/382\/revisions"}],"predecessor-version":[{"id":441,"href":"https:\/\/www.rocworks.at\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/382\/revisions\/441"}],"wp:attachment":[{"href":"https:\/\/www.rocworks.at\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=382"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rocworks.at\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=382"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rocworks.at\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=382"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}