Question

I am able to get stock prices from yahoo finance API with the following code. I can get US stocks, EFT, and even international quotes, but unable to get PUTS or CALLS. Any idea what technique I need to get these values?

try:<br/>
TD.TO, GDX, C, C140322C00018000<br/><br/>

<input type="text" id="symbol" />

<button type="submit" onClick="getYahooFinanceData();">Get Data</button>

<div id='result'></div>
<script src="jquery.js"></script>

<script>
function getYahooFinanceData() {    
    var url = 'http://query.yahooapis.com/v1/public/yql';
    var symbol = $("#symbol").val();    
    //var data = encodeURIComponent("select * from yahoo.finance.quotes where symbol in ('" + 'C140322C00018000' + "')");   
    var data = encodeURIComponent("select * from yahoo.finance.quotes where symbol in ('" + symbol + "')"); 
    $.getJSON(url, 'q=' + data + "&format=json&diagnostics=true&env=http://datatables.org/alltables.env")
        .done(function (data) {
            $('#result').append(data.query.results.quote.Name + "..." + data.query.results.quote.LastTradePriceOnly + "<br/>");

        })
        .fail(function (jqxhr, textStatus, error) {
            var err = textStatus + ", " + error;
            console.log('Request failed: ' + err);
        });
}
</script>

thanks itp

Was it helpful?

Solution

Try the data source:

yahoo.finance.options

instead of:

yahoo.finance.quotes

Here's one example:

SELECT * FROM yahoo.finance.options WHERE symbol IN ( "GDX", "C" )

where the results would be inside this object:

data.query.results.optionsChain

where the drilldown looks like this:

objects

Useful Resources:

http://developer.yahoo.com/yql/

http://developer.yahoo.com/yql/guide/yql-code-examples.html#yql_javascript

Search Stackoverflow for yahoo.finance.options

OTHER TIPS

i think you enter wrong symbol. i try your method is works. enter symbol like RCOM.NS and RPOWER.NS

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top