Link to home
Start Free TrialLog in
Avatar of Treder
Treder

asked on

Help on Real time mulitple stock quote script - php or javascript

Hi,

I'm trying to create a script which outputs basic information on 5 stocks, which updates every 30 seconds or so.  

In fact there is a google app based script which comes very close to showing what I'm trying to do already.  I have included it (via iframe) to the following page:

http://www.nwlist.net/test/stockquote/index.html 

It updates and gives a colour class to the price change according to '+' or '-'.  However the Ads by Google etc and the fact I can't style it makes it a no-go for me.

I've hammed together a php page which outputs the basic info I need but it doesn't update and doesn't interpret the different class for the price change:

http://www.nwlist.net/test/stockquote/basic.php

The php code for this (minus body and html tags is:

<style type="text/css">
#boxtable {
	border-bottom: 7px solid #9BAFF1;
    border-collapse: collapse;
    border-top: 7px solid #9BAFF1;
    font-family: "Lucida Sans Unicode","Lucida Grande",Sans-Serif;
    font-size: 12px;
    margin: 10px;
    width: 300px;
}
#boxtable td {
    background: none repeat scroll 0 0 #E8EDFF;
    border-left: 1px solid #AABCFE;
    border-right: 1px solid #AABCFE;
    color: #666699;
    padding: 8px;
}
</style>
</head>

<body>


<table id="boxtable">
  <tr>
<?php
$row = 1;
if (($handle = fopen("http://finance.yahoo.com/d/quotes.csv?s=^FTSE&f=nl1c1", "r")) !== FALSE) {
    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
        $num = count($data);
        $row++;
        for ($c=0; $c < $num; $c++) {
            echo "<td>" . $data[$c] . "</td>\n";
        }
    }
    fclose($handle);
}
?>
  </tr>
  <tr>
<?php
$row = 1;
if (($handle = fopen("http://finance.yahoo.com/d/quotes.csv?s=^GSPC&f=nl1c1", "r")) !== FALSE) {
    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
        $num = count($data);
        $row++;
        for ($c=0; $c < $num; $c++) {
            echo "<td>" . $data[$c] . "</td>\n";
        }
    }
    fclose($handle);
}
?>
  </tr>
  <tr>
<?php
$row = 1;
if (($handle = fopen("http://finance.yahoo.com/d/quotes.csv?s=E3X.FGI&f=nl1c1", "r")) !== FALSE) {
    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
        $num = count($data);
        $row++;
        for ($c=0; $c < $num; $c++) {
            echo "<td>" . $data[$c] . "</td>\n";
        }
    }
    fclose($handle);
}
?>
  </tr>
  <tr>
<?php
$row = 1;
if (($handle = fopen("http://finance.yahoo.com/d/quotes.csv?s=^N225&f=nl1c1", "r")) !== FALSE) {
    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
        $num = count($data);
        $row++;
        for ($c=0; $c < $num; $c++) {
            echo "<td>" . $data[$c] . "</td>\n";
        }
    }
    fclose($handle);
}
?>
  </tr>
  <tr>
<?php
$row = 1;
if (($handle = fopen("http://finance.yahoo.com/d/quotes.csv?s=510210.SS&f=nl1c1", "r")) !== FALSE) {
    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
        $num = count($data);
        $row++;
        for ($c=0; $c < $num; $c++) {
            echo "<td>" . $data[$c] . "</td>\n";
        }
    }
    fclose($handle);
}
?>
  </tr>
</table>

Open in new window


I would really appreciate help with this.  I've spent probably a couple of days now looking at all sorts of different implementations and examples trawled on the www.  But nothing either works or give me what I want.  Here are some of the resources I've tried:

http://usefulphp.blogspot.co.uk/2010/04/stock-quotes-with-php.html 
http://www.phptoys.com/tutorial/getting-stock-quote.html
http://www.phptoys.com/product/micro-stock.html

And for any others reference, I found this page giving yahoo quotes.csv format tags very useful:
http://www.gummy-stuff.org/Yahoo-data.htm

Best,
Tony
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

What is the question here?  Do you need help developing an application?  If so, it might be good to hire a professional developer.  You may need to have some budget to buy access to a data source for this kind of information.  My clients pay about $2,000 per month for a Bloomberg data feed and they get this information in near-real-time.  It is cheaper to get it with a delay and there are even some "free" (meaning "advertising supported") data feeds out there.  Looks like you have found some of those.

Here is an example of the Yahoo return data:
"S&P 500", 1385.14, -5.64
Given that, you can look at the third field and interpret it as a positive number (green) or negative number (red).  You can use inline CSS styling to color the display.  I believe that this would be $data[2] in the code samples above.  You can use a client-side action, maybe something using AJAX or jQuery to cause repeated queries against the Yahoo web service.  You might want to check the terms of service carefully before you do this -- there may be limitations on how often you can call the service or how you are permitted to use the data you get back from the service.
Avatar of Treder
Treder

ASKER

Ray,
Many thanks for your reply. $2000 a month - i hope whatever they are doing its paying them back!  My needs are much more crude - its basic info and doesnt have to Be real time.  I'll check the terms of service, hopefully I won't get too down in the dumps.

I'm a front end guy, so I'm comfortable in HTML/CSS land. But i try to have a go at any php that i think i might be ok at.  Actually I did task this to a developer for $$ and they solution that was offered was based on the first URL I gave above (but I've tidied it up a bit!).

Seems which ever place a turn to on this, there is another hurdle to jump.

Many thanks.
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Treder

ASKER

Ray, thanks very much for that.  I will have a study and see if I can mold to my needs.  Do you have a paypal address so that I can buy you a coffee?
You can find my email address in my profile here at EE, however there is no payment solicited or expected.  We're all volunteers in community here.
https://www.experts-exchange.com/M_3774417.html

All the best, ~Ray