Difference between revisions of "Module:Stock tickers/NYSE"

From Wikidot - Australian Business Wiki
Jump to navigation Jump to search
Module:Stock_tickers/NYSE>JJMC89
m (Changed protection level for "Module:Stock tickers/NYSE": Highly visible module ([Edit=Require template editor access] (indefinite) [Move=Require template editor access] (indefinite)))
 
m (1 revision imported)
 
(No difference)

Latest revision as of 11:53, 26 March 2021

Lua error: Internal error: The interpreter exited with status 127. Lua error: Internal error: The interpreter exited with status 127.


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

  • Lua error: Internal error: The interpreter exited with status 127.
  • Lua error: Internal error: The interpreter exited with status 127.
  • Lua error: Internal error: The interpreter exited with status 127.
  • Lua error: Internal error: The interpreter exited with status 127.



Script error: Lua error: Internal error: The interpreter exited with status 127.

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 official URL
	url = 'https://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 / when issued
	-- Example: Input: PRE.PRD, Output: PREpD
	ticker = string.gsub(ticker, "%.PR", "p")
	ticker = string.gsub(ticker, "%.WI", "w")
	
	return ticker
end

-- Get NYSE exchange codes
exchangeCode = {
	['NYSE'] = 'XNYS',
	['AMEX'] = 'XASE',
	['ARCA'] = 'ARCX',
	['NASDAQ'] = 'XNAS'
}

return p