Module:Stock tickers/NYSE: Difference between revisions
Appearance
Content deleted Content added
Svgalbertian (talk | contribs) do not support preferred shares without period, otherwise you have cases like PRE (PartnerRe Ltd.) that you have to work around |
Svgalbertian (talk | contribs) Support Arca and NYSE MKT |
||
Line 9: | Line 9: | ||
function p._GetURL(args) |
function p._GetURL(args) |
||
local ticker = args[1] |
local ticker = args[1] |
||
local exchange = args.exchange |
|||
-- By default the exchange will be NYSE |
|||
if not exchange then exchange = 'NYSE' end |
|||
-- Get corrected ticker |
-- Get corrected ticker |
||
Line 14: | Line 18: | ||
-- NYSE offical URL |
-- NYSE offical URL |
||
url = 'http://www.nyse.com/quote/ |
url = 'http://www.nyse.com/quote/' .. exchangeCode[exchange] .. ':' .. ticker |
||
return url |
return url |
||
Line 25: | Line 29: | ||
-- NYSE.com formats for preferred shares |
-- NYSE.com formats for preferred shares |
||
-- Example: Input: PRE.PRD, Output: |
-- Example: Input: PRE.PRD, Output: PREpD |
||
ticker = string.gsub(ticker, "%.PR", "p") |
ticker = string.gsub(ticker, "%.PR", "p") |
||
return ticker |
return ticker |
||
end |
end |
||
-- Get NYSE exchange codes |
|||
exchangeCode = { |
|||
['NYSE'] = 'XNYS', |
|||
['AMEX'] = 'XASE', |
|||
['ARCA'] = 'ARCX', |
|||
} |
|||
return p |
return p |
Revision as of 13:41, 3 August 2014
![]() | This Lua module is used on 2,000+ pages and changes may be widely noticed. Test changes in the module's /sandbox or /testcases subpages, or in your own module sandbox. Consider discussing changes on the talk page before implementing them. |
![]() | This module is rated as ready for general use. It has reached a mature form and is thought to be relatively bug-free and ready for use wherever appropriate. It is ready to mention on help pages and other Wikipedia resources as an option for new users to learn. To reduce server load and bad output, it should be improved by sandbox testing rather than repeated trial-and-error editing. |
![]() | This module is subject to page protection. It is a highly visible module in use by a very large number of pages, or is substituted very frequently. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is protected from editing. |
Usage
If you supply a NYSE stock ticker to the function. It will return a URL to that stock's listing on NYSE.com.
{{#invoke:Stock tickers|GetURL|ticker}}
Module usage
{{New York Stock Exchange}}
{{NYSE link}}
{{NYSE American}}
{{NYSE Arca}}
local getArgs = require('Module:Arguments').getArgs
local p = {}
function p.GetURL(frame)
local args = getArgs(frame)
return p._GetURL(args)
end
function p._GetURL(args)
local ticker = args[1]
local exchange = args.exchange
-- By default the exchange will be NYSE
if not exchange then exchange = 'NYSE' end
-- Get corrected ticker
ticker = p.FormatTickerURL(ticker)
-- NYSE offical URL
url = 'http://www.nyse.com/quote/' .. exchangeCode[exchange] .. ':' .. ticker
return url
end
function p.FormatTickerURL(ticker)
-- Convert to upper case
ticker = string.upper(ticker)
-- NYSE.com formats for preferred shares
-- Example: Input: PRE.PRD, Output: PREpD
ticker = string.gsub(ticker, "%.PR", "p")
return ticker
end
-- Get NYSE exchange codes
exchangeCode = {
['NYSE'] = 'XNYS',
['AMEX'] = 'XASE',
['ARCA'] = 'ARCX',
}
return p