Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keystats fix 447 #452

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 33 additions & 33 deletions yahoo/finance/option_chain/yahoo.finance.option_chain.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,55 +18,55 @@
</url>
</urls>
<inputs>
<key id="symbol" type="xs:string" paramType="variable" required="true" />
<key id="expiration" type="xs:string" paramType="variable" required="true" />
<key id="type" type="xs:string" paramType="variable" required="true" />
<key id="symbol" type="xs:string" paramType="variable" required="true" />
<key id="expiration" type="xs:string" paramType="variable" required="true" />
<key id="type" type="xs:string" paramType="variable" required="true" />
</inputs>
<execute>
<![CDATA[
function getOptionsChain()

function getOptionsChain()
{
// Get the Options Chain for the given symbol from the Options page

var results = optionsChainQuery;

elements = results.*.length();

if ( elements == 0 )
{
return false;
}

var optionElem;

var strikePrice;
var optionSymbol;
var optionType;
var lastPrice;
var change;

var optTypeMatch;

for each ( var tr in results )
{
strikePrice = parseFloat( tr.td[0].a.strong.text().toString().replace(/\,/g,'') );
optionSymbol = tr.td[1].a.text();

// Check to see what type of option
// the current option is

optTypeMatch = optionSymbol.match( /^[\w]{7,}([P|C])/ );

if ( optTypeMatch != null )
{
optionType = optTypeMatch[1];
}

lastPrice = tr.td[2].strong.text();
change = tr.td[3].span.strong.text();
changeDir = tr.td[3][email protected]();

if ( changeDir.toLowerCase() == "down" )
{
change = parseFloat( change ) * -1;
Expand All @@ -87,7 +87,7 @@ if (type.toUpperCase() === optionType)
optionsChainCount++;
}
}

return true;
}

Expand All @@ -96,9 +96,9 @@ function getExpiration()
var results = expiresQuery;

y.log( "results.length(): " + results.length() );

elements = results.*.length();

if ( elements == 0 )
{
y.log( "no elements" );
Expand All @@ -108,7 +108,7 @@ function getExpiration()
var dateRegEx = /.*([\d]{2})\,\s+?[\d]{4}/g;

var dateRes = dateRegEx.exec( results[0] );

var dd;

if ( dateRes != null &&
Expand All @@ -120,46 +120,46 @@ function getExpiration()
return dd;
}


// Queue the query

var optionsChainURL = "http://finance.yahoo.com/q/op?s=" + symbol;
var queryHasExpiration = false;
var optionsChainCount = 0;

if ( expiration != null )
{
var expPattern = /^[\d]{4}\-[\d]{2}$/;

if ( expPattern.test( expiration ) )
{
optionsChainURL += "&m=" + expiration;
queryHasExpiration = true;
}
}

var yQuery = y.rest( optionsChainURL );
var yQuery = y.rest( optionsChainURL );
var data = yQuery.accept( "text/html" ).get().response;

var optionsChainQuery = y.xpath(
data,
"//table[@class='yfnc_datamodoutline1']/tr/td/table/tr[td[@class='yfnc_h' or " +
data,
"//table[@class='yfnc_datamodoutline1']/tr/td/table/tr[td[@class='yfnc_h' or " +
"@class='yfnc_tabledata1']]"
);
var expiresQuery = y.xpath(

var expiresQuery = y.xpath(
data,
"//table[@class='yfnc_mod_table_title1']/tr/td[last()]/p"
);

var expiryDay = getExpiration();

var optionsChain;
var expDate = expiration;

if ( queryHasExpiration == true )
{
if ( expiryDay != null &&
if ( expiryDay != null &&
expiryDay != "" )
{
expDate += "-" + expiryDay;
Expand All @@ -176,9 +176,9 @@ getOptionsChain();
optionsChain.@["count"] = optionsChainCount;
response.object = optionsChain;

]]>

]]>
</execute>
</select>
</bindings>
</table>
</table>
88 changes: 44 additions & 44 deletions yahoo/finance/option_contract/yahoo.finance.option_contract.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,69 +14,69 @@
<bindings>
<select itemPath="" produces="XML">
<urls>
<url>
</url>
<url>
</url>
</urls>
<inputs>
<key id="symbol" type="xs:string" paramType="variable" required="true" />
<key id="symbol" type="xs:string" paramType="variable" required="true" />
</inputs>
<execute>
<![CDATA[

function getContracts()
{
var results = optionsPath;
<![CDATA[

elements = results.*.length();
function getContracts()
{
var results = optionsPath;

if ( elements == 0 )
{
return false;
}
elements = results.*.length();

var yearRegEx = /\d{4}/;
var monthRegEx = /\-\d{2}/;
if ( elements == 0 )
{
return false;
}

for each ( var a in results )
{
//grab the link w/ href containing date
var contract = [email protected]();
var yearRegEx = /\d{4}/;
var monthRegEx = /\-\d{2}/;

//YYYY-MM format
var result = yearRegEx.exec(contract) + monthRegEx.exec(contract);
for each ( var a in results )
{
//grab the link w/ href containing date
var contract = [email protected]();

var contractElem = <contract>{result}</contract>;
//YYYY-MM format
var result = yearRegEx.exec(contract) + monthRegEx.exec(contract);

//maintain sorted ordering by date
if (a == results[results.length()-1]) {
contractList.prependChild( contractElem );
}
else {
contractList.appendChild( contractElem );
}
var contractElem = <contract>{result}</contract>;

}
return true;
}
//maintain sorted ordering by date
if (a == results[results.length()-1]) {
contractList.prependChild( contractElem );
}
else {
contractList.appendChild( contractElem );
}

}
return true;
}

//build the query string
var StockquoteURL = "http://finance.yahoo.com/q/op?s=" + symbol;

//get thy results
var yQuery = y.rest( StockquoteURL );
var data = yQuery.accept( "text/html" ).get().response;
//build the query string
var StockquoteURL = "http://finance.yahoo.com/q/op?s=" + symbol;

//grab the appropriate path
var optionsPath = y.xpath(data, "//table[@id='yfncsumtab']/tr/td/table/tr/td/p/a");
//get thy results
var yQuery = y.rest( StockquoteURL );
var data = yQuery.accept( "text/html" ).get().response;

var contractList = <option symbol={symbol}></option>;
//grab the appropriate path
var optionsPath = y.xpath(data, "//table[@id='yfncsumtab']/tr/td/table/tr/td/p/a");

getContracts();
var contractList = <option symbol={symbol}></option>;

response.object = contractList;
]]>
getContracts();

response.object = contractList;
]]>
</execute>
</select>
</bindings>
</table>
</table>
Loading