class Finnhub::Indicator
Attributes
output[R]
timestamps[R]
Public Class Methods
new(client:, stock:, resolution: "D", from:, to:, indicator:, args: {})
click to toggle source
# File lib/Indicator.rb, line 3 def initialize(client:, stock:, resolution: "D", from:, to:, indicator:, args: {}) url = "/indicator?symbol=#{stock.symbol}&resolution=#{resolution}" from = from.to_i if from.is_a?(Time) url += "&from=#{from}" to = to.to_i if to.is_a?(Time) url += "&to=#{to}" url += "&indicator=#{indicator}" args.each do |attribute, value| url += "&#{attribute}=#{value}" end @output = client.request(url) if @output.is_a?(Hash) && @output[:s] == "ok" @timestamps = @output[:t]&.map{|t| Time.strptime(t.to_s,'%s')} else @timestamps = [] end end
Public Instance Methods
close()
click to toggle source
# File lib/Indicator.rb, line 35 def close operation(:c) end
high()
click to toggle source
# File lib/Indicator.rb, line 27 def high operation(:h) end
low()
click to toggle source
# File lib/Indicator.rb, line 31 def low operation(:l) end
method_missing(name, *args, &block)
click to toggle source
# File lib/Indicator.rb, line 48 def method_missing(name, *args, &block) operation(name.to_sym) end
open()
click to toggle source
# File lib/Indicator.rb, line 23 def open operation(:o) end
status()
click to toggle source
# File lib/Indicator.rb, line 43 def status raise Finnhub::Error message: "Output is not a hash" unless @output.is_a?(Hash) @output[:s] end
volume()
click to toggle source
# File lib/Indicator.rb, line 39 def volume operation(:v) end
Private Instance Methods
operation(type)
click to toggle source
# File lib/Indicator.rb, line 54 def operation(type) raise Finnhub::Error message: "Output is not a hash" unless @output.is_a?(Hash) return [] if @output[type].nil? @timestamps.zip(@output[type]) end