We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 19889
    • 616 Posts
    Hello,

    I hope somebody can help me with the following script or any similar script: http://blog.tc.dk/?itemid=8 - it’s a script to fetch stock quotes from yahoo.

    what would be the easiest way to integrate this into my modx site? are there any better scripts around to get stock quotes? I experienced some speed problems when executing the script above with numerous stock symbols - thus I was wondering whether I could basically setup a cron job to fetch the data and then read it from my local server - however, I have no idea where to start.

    I hope somebody as a little time to get me going.

    thank you in advance for your help.
      • 7231
      • 4,205 Posts
      I have held on to this bit of code I picked up along the way but have not used it for anything yet. It will retrieve stock quotes from yahoo and display the info, with some tweaking you should be able to add an interface for this.

      <?php
      $fd = fopen ("http://quote.yahoo.com/d/quotes.csv?s=AAPL&f=sl1d1t1c1ohgv&e=.csv", "r");
      $contents = fread ($fd, 200);
      fclose ($fd);
       
      $contents = str_replace ("\"", "", $contents);
      $contents = explode (",", $contents);
       
      echo "<p>Apple stock tracker</p><p>Most recent trade: <b>\$$contents[1]</b></p><p>Today's Change: $contents[4]</p><p>(Prices delayed up to 20 minutes.)</p>";
      ?>


      EDIT: It will display this.

      Apple stock tracker
      Most recent trade: $127.43
      Today’s Change: +5.21
      (Prices delayed up to 20 minutes.)
        [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

        Something is happening here, but you don&#39;t know what it is.
        Do you, Mr. Jones? - [bob dylan]
        • 19889
        • 616 Posts
        I’ll give it a try - thank you