PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Mon Dec 22, 2014 10:35 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 10 posts ] 
Author Message
PostPosted: Fri Oct 24, 2003 9:38 pm 
Offline
Moderator
User avatar

Joined: Sat Apr 20, 2002 3:14 pm
Posts: 1416
Location: Dallas, TX
Small class-based php program to grab the latest stocks (specified in the url [stock.php?symbols=YHOO,MSFT,etc...]). I forget where I got the original source from, but I edited it to enhance a small section of my website. Enjoy :)

Syntax: [ Download ] [ Hide ]
<?php

// Code by:   Don Wilson

// Edited:     October 24, 2003

class stock

{

        function getLastTrade($symbol)

        {

                $file = fopen("http://quote.yahoo.com/d/quotes.csv?s={$symbol}&f=sl1d1t1c1ohgv&e=.csv", "r");

                        $read = fread($file, 2000);

                        fclose($file);

                $read = str_replace(""", "", $read);

                $read = explode("
,", $read);

                return $read[1];

        }



        function getChange($symbol)

        {

                $file = fopen("
http://quote.yahoo.com/d/quotes.csv?s={$symbol}&f=sl1d1t1c1ohgv&e=.csv", "r");

                        $read = fread($file, 2000);

                        fclose($file);

                $read = str_replace(""", "", $read);

                $read = explode("
,", $read);

                return $read[4];

        }



        function getDateClosed($symbol)

        {

                $file = fopen("
http://quote.yahoo.com/d/quotes.csv?s={$symbol}&f=sl1d1t1c1ohgv&e=.csv", "r");

                        $read = fread($file, 2000);

                        fclose($file);

                $read = str_replace(""", "", $read);

                $read = explode("
,", $read);

                return $read[2] . "
" . $read[3];

        }



}



$stock = new Stock();



echo "
<pre>\n";

if(isset($symbols))

{

        $symbols = explode("
,", $symbols);

        foreach($symbols as $symbol)

        {

        $change = $stock->getChange($symbol);

        if($change < 0)

          $change = "
<font color=red>{$change}</font>";

        elseif($change > 0)

          $change = "
<font color=green>{$change}</font>";

        else

          $change = "
0.00";

         

                echo "
Symbol:                   " . $symbol                                                                             . "\n";

                echo "
Last Trade:               " . $stock->getLastTrade($symbol)               . "\n";

                echo "
Change:                   " . $change                     . "\n";

                echo "
Date Closed:              " . $stock->getDateClosed($symbol)      . "\n";

                echo "
\n";

        }

}

echo "
</pre>\n";

?>


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 22, 2004 11:13 am 
Offline
Forum Contributor

Joined: Fri Jun 21, 2002 5:57 pm
Posts: 466
Location: Atherstone, Warks
Sounds silly... but where could i get all the stock exchange symbols?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 22, 2004 10:19 pm 
Offline
Forum Donator

Joined: Mon Oct 20, 2003 8:31 pm
Posts: 1661
Location: Maine, USA
Phice, do you know how legal it would be to use these stocks/prices in a game that makes profit?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 22, 2004 10:28 pm 
Offline
Neighborhood Spidermoddy
User avatar

Joined: Mon Mar 29, 2004 4:24 pm
Posts: 31559
Location: Bothell, Washington, USA
you can use them as entropy data for seeding randoms pretty easy.. however using them straight.. I dunno.. need to talk to a lawyer, but I'd guess it's "okay"


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 24, 2004 1:02 pm 
Offline
Forum Newbie

Joined: Thu Jun 24, 2004 12:49 pm
Posts: 6
Location: Seaton Easy Devon UK
LiLpunkSkateR wrote:
Phice, do you know how legal it would be to use these stocks/prices in a game that makes profit?



Now thats an idea. But how you you use it to make profit?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 25, 2004 4:59 am 
Offline
Moderator
User avatar

Joined: Sat Apr 20, 2002 3:14 pm
Posts: 1416
Location: Dallas, TX
computingfuture.net wrote:
LiLpunkSkateR wrote:
Phice, do you know how legal it would be to use these stocks/prices in a game that makes profit?



Now thats an idea. But how you you use it to make profit?


I'm guessing he meant a game that sells account activation, etc that uses the data for it's game contents..?


Top
 Profile  
 
PostPosted: Thu Jun 10, 2010 4:18 pm 
Offline
Forum Newbie

Joined: Thu Jun 10, 2010 3:23 pm
Posts: 2
Thank you so much for this. I am a real amateur .. I found a stock ticker online, for a client who wanted it on a website I am building - here is the code:


It works great, but is missing the code to get the actual stock info. Can I use your script to modify this? If so, could I trouble you to tell me where to add it into this code? Thank you so much!


Last edited by mybelle on Thu Jun 10, 2010 5:25 pm, edited 2 times in total.

Top
 Profile  
 
PostPosted: Thu Jun 10, 2010 5:24 pm 
Offline
Forum Newbie

Joined: Thu Jun 10, 2010 3:23 pm
Posts: 2
Thank you so much for this. I am a real amateur .. I found a stock ticker online, for a client who wanted it on a website I am building - here is the code:
<?php
///// Replace with Yahoo Finance stock quotes of your choice //////
$raw_stock_data = array('AAPL 200 205',
'BIDU 500 510','RIMM 150 155', 'SNDK 70 72',
'GOOG 500 510','MSFT 30 32','AMD 9 10');
sort($raw_stock_data);
//////////////////////////////////////////////////////////////////////////
?>
<div align="center">
<marquee bgcolor="#e0e1e1" direction="left" loop="20" width="100%%">
<?php
foreach ($raw_stock_data as $value) {
$results = explode(' ',$value);

$ticker = $results[0];
$buy = $results[1];
$sell = $results[2];

echo "<font color=\"#ffffff\">$ticker </font>";
echo "<font color=\"#00ff00\">$buy </font>";
echo "<font color=\"#ff0000\">$sell </font>";
echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
}
?>
It works great, but is missing the code to get the actual stock info. Can I use your script to modify this? If so, could I trouble you to tell me where to add it into this code? Thank you so much!


Top
 Profile  
 
PostPosted: Wed Oct 27, 2010 1:02 pm 
Offline
Forum Commoner

Joined: Tue Oct 12, 2010 7:26 pm
Posts: 38
I put it all together into a ticker with live quotes. You can see (and run) the code here:

http://www.exorithm.com/algorithm/view/stock_ticker


Top
 Profile  
 
PostPosted: Fri Mar 04, 2011 12:00 am 
Offline
Forum Newbie

Joined: Thu Mar 03, 2011 11:53 pm
Posts: 1
I like your information very much about yahoo stock market retrieval system. Thanks for sharing this useful info.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group