class Nse1::Stock
Public Class Methods
list()
click to toggle source
# File lib/nse1.rb, line 49 def self.list url = "http://www.nseindia.com/live_market/dynaContent/live_analysis/pre_open/all.json" content = open(url).read parselist = Crack::JSON.parse(content)["data"] listarr = [] parselist.each do |has| listarr << has["symbol"] end return listarr end
new(symbol)
click to toggle source
# File lib/nse1.rb, line 11 def initialize(symbol) if symbol.include? "&" symbol.gsub!("&", "%26") end @symbol = symbol base_url = "http://www.nseindia.com/live_market/dynaContent/live_watch/get_quote/ajaxGetQuoteJSON.jsp?symbol=" # base_url_suffix = "&series=EQ" full_url = base_url+@symbol content = open(full_url).read @parsed_local_content = Crack::JSON.parse(content) if @parsed_local_content['data'][0].nil? base_url = "http://www.nseindia.com/live_market/dynaContent/live_watch/get_quote/ajaxGetQuoteILJSON.jsp?symbol=" full_url = base_url+@symbol content = open(full_url).read @parsed_local_content = Crack::JSON.parse(content) end end
nifty()
click to toggle source
# File lib/nse1.rb, line 36 def self.nifty url = "http://www.nseindia.com/live_market/dynaContent/live_analysis/pre_open/nifty.json" content = open(url).read parsednifty = Crack::JSON.parse(content)["data"] # niftyarr = Nse1::Stock.list["data"] nifarr = [] parsednifty.each do |has| nifarr << has["symbol"] end return nifarr end
Public Instance Methods
change()
click to toggle source
# File lib/nse1.rb, line 102 def change return @parsed_local_content['data'][0]['change'] end
dayHigh()
click to toggle source
# File lib/nse1.rb, line 126 def dayHigh return @parsed_local_content['data'][0]['dayHigh'] end
dayLow()
click to toggle source
# File lib/nse1.rb, line 130 def dayLow return @parsed_local_content['data'][0]['dayLow'] end
fulljson()
click to toggle source
# File lib/nse1.rb, line 60 def fulljson return @parsed_local_content end
fullname()
click to toggle source
# File lib/nse1.rb, line 68 def fullname unless @parsed_local_content['data'][0].nil? return @parsed_local_content['data'][0]['companyName'] else return "some problem with the quote #{@symbol}" end end
high52()
click to toggle source
# File lib/nse1.rb, line 122 def high52 return @parsed_local_content['data'][0]['high52'] end
last()
click to toggle source
# File lib/nse1.rb, line 64 def last return @parsed_local_content['data'][0]['lastPrice'].to_s end
lastUpdateTime()
click to toggle source
# File lib/nse1.rb, line 98 def lastUpdateTime return @parsed_local_content['lastUpdateTime'] end
low52()
click to toggle source
# File lib/nse1.rb, line 114 def low52 return @parsed_local_content['data'][0]['low52'] end
openPrice()
click to toggle source
# File lib/nse1.rb, line 110 def openPrice return @parsed_local_content['data'][0]['open'] end
previousClose()
click to toggle source
# File lib/nse1.rb, line 118 def previousClose return @parsed_local_content['data'][0]['previousClose'] end
sector()
click to toggle source
# File lib/nse1.rb, line 81 def sector # @symboll = "SBIN" base_url_sector = "http://www.moneycontrol.com/mccode/common/autosuggesion.php?query=#{@symbol}&type=1&format=json&callback=suggest1" # puts base_url_sector page_sector = Nokogiri::HTML(open(base_url_sector)) # puts page_sector link_suffix_sector = page_sector.text.split("{")[1].split(",")[0].split(":")[2].gsub!("\"","") # puts link_suffix_sector full_link_sector = "http:"+link_suffix_sector # puts full_link_sector page = Nokogiri::HTML(open(full_link_sector)) sector_name = page.css("div.FL").css("div.gry10")[0].text.split("|")[3].split(":")[1].strip return sector_name end
symbol()
click to toggle source
# File lib/nse1.rb, line 76 def symbol return @symbol end
volume()
click to toggle source
# File lib/nse1.rb, line 106 def volume return @parsed_local_content['data'][0]['quantityTraded'] end