Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Dec 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Grabbing info from a link, and modifying an ajax script request

    This is way above me. I can't blame anyone for ignoring this, but the end result would be very cool. I have a site, mimictrading - com and track several portfolios. One thing I do for most of them, and makes it easy to update, is keep a link to a finviz screener page. I can add to and remove ticker symbols from the link as needed.

    What I want is to be able to display stock quotes on the lefthand column, drawing from that finviz link so there's only one thing I need to update whenever a portfolio change is made.

    After a lot of searching, I'm going to have to sort of mash something together. First there's an ajax that can load data from google finance. It's designed to show a single stock, but by comma delimiting the ticker request, you can get as many as you need in a single request. What it needs is a loop to properly create a div for each stock.

    found here: http://www.aaronjwhite.org/index.php...e-stock-ticker

    Code:
    $(document).ready(function(){
    
      $.getJSON('https://finance.google.com/finance/info?client=ig&q=goog,aapl,msft&callback=?',function(response){
        var stockInfo = response[0];
        var stockString ='<div class="stockWrapper">STOCK:';
        stockString +='<span class="stockSymbol">'+stockInfo.t+'</span>';
        stockString +='<span class="stockPrice">'+stockInfo.l+'</span>';
        stockString +='<span class="stockChange">'+stockInfo.c+'</span>';
        stockString +='<span>at</span> <span class="stockTime">'+stockInfo.ltt+'</span>';
        stockString +='</div>';
        $('.stockTick').prepend(stockString);
      });
     
    });
    It uses/requires jquery. And further instruction is "remember to put a div on the the page with css class stockTick". I need that div to contain in a list all of the stocks in the request.

    It would get that list from a finviz link on the page, it would search links on the page for finviz.com and then parse out the tickers. It wouldn't have to do each individual, because the request is also comma delimited, so it would just need the string from first to last ticker symbol, then plugged into the request line in the code above.

    Thanks

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    3,763
    Thanks
    23
    Thanked 548 Times in 547 Posts
    Put these in your page and adjust to fit:
    Code:
    <!DOCTYPE html>
    <html>
    <head>
    <style type="text/css">
    /*  YOU MIGHT WANT TO SET THESE VALUES TO YOUR SITE DIMENSIONS  */
    .stockWrapper{
    	border: 1px solid black;
    	width: 320px;
    	height: 35px;
    	text-align:center;
    	padding-top: 15px;
    	margin-bottom: 10px;
    }
    </style>
    </head>
    <body>
    
    <div class="stockTick"></div><!-- PUT THIS WHERE YOU WANT IT-->
    
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
    <script type="text/javascript">
    $(document).ready(function(){
    	$.getJSON('https://finance.google.com/finance/info?client=ig&q=goog,aapl,msft&callback=?',function(response){
    		for(i=0; i<response.length; i++){
    			var stockInfo = response[i];
    			var stockString ='<div class="stockWrapper">STOCK:';
    			stockString +='<span class="stockSymbol">'+stockInfo.t+'</span>';
    			stockString +='<span class="stockPrice">'+stockInfo.l+'</span>';
    			stockString +='<span class="stockChange">'+stockInfo.c+'</span>';
    			stockString +='<span>at</span> <span class="stockTime">'+stockInfo.ltt+'</span>';
    			stockString +='</div>';
    			$('.stockTick').prepend(stockString);
    		}
    	});
    });
    </script>
    </body>
    </html>
    Evolution - The non-random survival of random variants.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •