?
Solved

Retrieve a Stock Quote in ASP

Posted on 1999-09-09
14
Medium Priority
?
515 Views
Last Modified: 2010-08-05
I would like to create an ASP page that returns a stock quote entered by a user. I guess that it would be using an something like PCQuote, or Yahoo Finance as an engine. How do I do that?
0
Comment
Question by:chiche
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 4
  • 2
  • +1
14 Comments
 

Expert Comment

by:flachance
ID: 2038608
Do you want to simply retrieve the financial information to display it the way you want it?  Or do you simply pass the information so that the quote site displays the right page?
0
 

Author Comment

by:chiche
ID: 2039599
I want to retrieve the info to display it the way I want it. A VB Script (or JavaScript) ASP function which returns the stock price for a given ticker symbol would be fine.

0
 

Expert Comment

by:Diodeus
ID: 2043367
I don't think you can use ASP (or javascript) alone to do this.

I would do it like this:

- Use an HTML form to obtain the stock symbol
- In VB create an Active-X control the uses the browser object to fetch the page from the data supplier
- Parse the page for the stock symbol in the Active-X control
- Pass the value back to your ASP page
- Show the results
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:chiche
ID: 2043380
I agree with your process, but why do I need to go through an ActiveX object? I am quiet sure that an ASP script could just as well instanciate the browser object..

My ISP will not allow me to install my own ActiveX..
0
 

Expert Comment

by:Diodeus
ID: 2046041
The browser object *IS* an Active-X control. It's shipped with VB. It allows you to tell the browser to navigate to a page, then retrieve the output of that page as a text stream then perform whatever processing on it you need. ASP cannot fetch the contents of the browser on its own.
0
 

Author Comment

by:chiche
ID: 2047030
ok, ok. I misunderstood your comment.

when you wrote "- In VB create an Active-X control the uses the browser object ", I thought VB meant VB and not VBScript, used in ASP.

what I need is a sample of VBScript code to accomplish what you are describing with the browser object. That's the earth of the problem.

I am increasing to 150
0
 
LVL 3

Expert Comment

by:xav
ID: 2054327
Diodeus is right, you need some sort of server side object that can retrieve a URL as a text stream.  Since your ISP will not allow you to register your own objects, you could use a server that already has such an object.  PharLap software offers a server with several JavaScript helper objects that will let you do just that.  You can use their server to get the URL (which sends the contents down as a variable FileContents), and then parse the source of that file until you get the price.  Since it has to download the full URL from PCquote, it's not fast. It's not pretty.  But it does do the job.

Name it getQuote.asp, and use it something like this:
http://servername/getQuote.asp?cTicker=MSFT

*------------------------getQuote.asp---------------------*
<html><head>
<title></title>
<% cTicker=request("cTicker") %>
<SCRIPT LANGUAGE="JavaScript" SRC="http://jshelper.pharlap.com/netutils/httpget.js?http://www.pcquote.com/cgi-bin/getquote.exe?ticker=<%= cTicker %>"></SCRIPT>
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
function test() {
      aGeneralArea=FileContents.split("Last Sale")
      strPriceForward=aGeneralArea[1].split("<b>")
      strPrice=strPriceForward[1].split("</b>")
      alert("Current price for <%= cTicker %> is: $"+strPrice[0])
}
//-->
</script>
</head><body onLoad="test()">
<form name="frmMain" action="getQuote.asp" method="post">
Enter Ticker Symbol: <input type="text" name="cTicker" maxlength="5" size="5" value=""><br>
<input type="Submit" value="Submit">
</form>
</body>
</html>
0
 

Author Comment

by:chiche
ID: 2056877
Very interesting comment. I tried it and it works. The problem is that the "parsing" is done on the client, rather than on the server and I really want to have a server based solution. What I really need is the code that pharlap is using...

A friend showed me a very easy way to retrieve the content of an internet web site using PHP (similar to ASP) on the server:

<?
$contents = file("http://www.pcquote.com/cgi-bin/getquote.exe?ticker=MSFT");
?>

How I do the same thing with ASP?
0
 
LVL 3

Expert Comment

by:xav
ID: 2060302
The parsing is done on the client because ASP does not have an inherent way of reading a URL into a variable.  Basically, if you're using ASP, you need to use some sort of object on the server as Diodeus describes.

Presumably, the ISP has IE on it, which has a webBrowser control that I believe you can access via server.createObject("dll.webBrowser"), which will do what you're looking for.  However, I'm not really sure what the proper syntax would be.  I'm sure someone else can give you the proper syntax.

P.S. You can get the source for the Parlap javascript, and java applet at: http://jshelper.pharlap.com/applet/test.htm

Also remember that anytime you're using someone else's content, you need to get permission from them.  Even though it's on the web, they still have copyright protection.
0
 

Author Comment

by:chiche
ID: 2061437
"ASP does not have an inherent way of reading a URL into a variable". It's hard for me to believe but you are probably right and that makes me think that once more Microsoft is getting away with a mediocre product. How else explain it? Why would you have to instance an object to simply read an http file?

Can anyone else help me?

0
 
LVL 3

Accepted Solution

by:
xav earned 600 total points
ID: 2159968
I discovered an object that MS ships with VB Pro. and Enterprise (but is undocumented anywhere in ASP) called the Internet Transfer Control.  With it, you can do what you're looking for.

<%@ language="JavaScript" %>
<html><head>
<title></title>
</head><body>
Loading...<br>
<br>
<%
cTicker="MSFT";
urlAddress="http://www.pcquote.com/cgi-bin/getquote.exe?ticker="+cTicker
Inet = new ActiveXObject("InetCtls.Inet.1");
Inet.RequestTimeOut=30;
Inet.Url = urlAddress;
FileContents = Inet.OpenUrl();
aGeneralArea=FileContents.split("Last Sale");
strPriceForward=aGeneralArea[1].split("<b>");
strPrice=strPriceForward[1].split("</b>");
Response.Write("Current price for "+ cTicker +" is: $"+strPrice[0]);
%>
</body>
</html>
0
 

Author Comment

by:chiche
ID: 2161343
Thanks. That's kind of what I was looking for. It worked on my PWS. Unfortunately my host provider (IMC Online) doesn't have this control registered on their server so I can't use it. Any idea?
0
 
LVL 3

Expert Comment

by:xav
ID: 2161482
I'd just ask them if they have any internet browser/transfer type controls that can load another page.  If not, they probably wouldn't be too averse to registering that component, since it does come from Microsoft.  Usually, they only object to home-made controls, since they're never sure what they'll do.  But, if they're friendly, they probably wouldn't think twice about registering it (especially if you sent them the control along with the request).
0
 

Author Comment

by:chiche
ID: 2162236
Well, those guys wouldn't want to do that. I am looking for a provider that is more "flexible", the way you describe it. Look at question http://www.experts-exchange.com/jsp/qShow.jsp?ta=webauthor&qid=10222845 
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question