Author Topic: Finance data  (Read 2635 times)

epoxa

  • Newbie
  • *
  • Posts: 1
    • View Profile
Finance data
« on: January 19, 2015, 08:25:12 pm »
Good day! Is it possible to dynamically add data to the table from Yhoo!Finance:


http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20=%20%22BAC%22&format=json&diagnostics=true&env=http://datatables.org/alltables.env

I need to create a list of companies with market data.

Did not succeed.
Here is some sample code:
<script>

 
   var tickers = ['"c"','"ge"'];
   for (var k = 0; k < tickers.length; k++) {
     
   
var query = "select * from yahoo.finance.quotes where symbol = " + tickers[k];

var yql = "http://query.yahooapis.com/v1/public/yql?q=" + escape(query) + "&format=json&diagnostics=true&env=store://datatables.org/alltableswithkeys&callback=?";

//$("#yql").text(yql);

$.ajax({
    url: yql,
    dataType: 'json',
    success: function(data) {
       
        var keys = _.keys(data.query.results.quote);
        //var values = _.values(data.query.results.quote);
               
           
       for (var x=0; x<keys.length; x++) {
          switch (keys
  • ) {

            case 'Symbol':
            var Symbol = data.query.results.quote[keys
  • ];


            break;
            case 'PERatio':
            var PERatio = data.query.results.quote[keys
  • ];

            break;

            $(document).ready(function(){
       
    $(Symbol).append(Symbol);
  });
       
            }
           }
           
            $(function () {

        var data = [[Symbol, PERatio]];
       
       
        alert(data[0]);
       

       


        var obj = { width: 700, height: 400, title: "ParamQuery Grid Example",resizable:true,draggable:true };
        obj.colModel = [
        { title: "Rank", width: 100, dataType: "integer" },
        { title: "Company", width: 100, dataType: "string" },
        { title: "Rank", width: 100, dataType: "integer" },
        { title: "Company", width: 100, dataType: "string" },
        { title: "Rank", width: 100, dataType: "integer" },
        { title: "Company", width: 100, dataType: "string" },
        { title: "Rank", width: 100, dataType: "integer" },
        { title: "Company", width: 100, dataType: "string" }];
        obj.dataModel = { data: data };
        $("#grid_array").pqGrid(obj);


    });   
       
       
       
        $("#info").html(results);
       
    }
   
});

 };



   
       
</script> 

However, it generates only one row in the table and one element...

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6265
    • View Profile
Re: Finance data
« Reply #1 on: January 23, 2015, 12:42:34 am »
Any kind of JSON data can be read by grid as long as it's valid JSON i.e., an array of row objects.

The URLs included in your post don't work. You may attach a sample of the data returned by yql.