class NseFinance
Public Class Methods
all_closing_prices_today()
click to toggle source
get closing prices for all the symbols for the trading day
# File lib/nse_finance.rb, line 20 def self.all_closing_prices_today json_package = Net::HTTP.get( URI(@@base_uri) ) day_records = JSON.parse(json_package) result = Array.new day_records.map {|day_record| result << day_record["close"].to_f } result end
all_closing_today()
click to toggle source
get the full trading day records for all stocks as at closing time
# File lib/nse_finance.rb, line 14 def self.all_closing_today tmp = Net::HTTP.get( URI(@@base_uri) ) JSON.parse(tmp) end
symbol(symbol)
click to toggle source
get the full trading day record for the last 5 trading days for a symbol
# File lib/nse_finance.rb, line 32 def self.symbol(symbol) result = '{"error" : "Invalid symbol"}' if !symbol.nil? url = "#{@@base_uri}/#{symbol.upcase}" tmp = Net::HTTP.get( URI(url) ) result = JSON.parse(tmp) end result end
symbol_closing_price_on(symbol, date)
click to toggle source
get the closing price for a particular symbol on a particular day
# File lib/nse_finance.rb, line 89 def self.symbol_closing_price_on(symbol, date) result = '' record = NseFinance.symbol_on(symbol, date) if record.include?("error") result = record elsif record.empty? result = '{"response": "No data"}' else result = record["#{symbol}"]["close"] end result end
symbol_closing_prices(symbol)
click to toggle source
get the closing price for the last 5 trading days for a symbol
# File lib/nse_finance.rb, line 44 def self.symbol_closing_prices(symbol) result = '' records = NseFinance.symbol(symbol) if records.include?("error") result = records else result = Array.new records.map { |day_record| result << day_record["close"].to_f } end result end
symbol_on(symbol, date)
click to toggle source
get the full trading day record for a particular symbol on a particular day
# File lib/nse_finance.rb, line 60 def self.symbol_on(symbol, date) # check if the date is in the proper format: YYYY-MM-dd parsed_date = nil begin parsed_date = Date.parse(date) rescue result = '{"error" : "Invalid date"}' end if !symbol.nil? && !parsed_date.nil? url = "#{@@base_uri}/#{symbol.upcase}/#{date}" tmp = Net::HTTP.get( URI(url) ) if tmp.include?("error") result = '{"error" : "Invalid symbol"}' else tmp_result = JSON.parse(tmp) result = tmp_result if tmp_result.length > 1 result = '{"error" : "Invalid date"}' end end end result end