Class: Finnhub::Indicator
- Inherits:
-
Object
- Object
- Finnhub::Indicator
show all
- Defined in:
- lib/Indicator.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(client:, stock:, resolution: "D", from:, to:, indicator:, args: {}) ⇒ Indicator
Returns a new instance of Indicator.
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
# 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
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
48
49
50
|
# File 'lib/Indicator.rb', line 48
def method_missing(name, *args, &block)
operation(name.to_sym)
end
|
Instance Attribute Details
#output ⇒ Object
Returns the value of attribute output.
21
22
23
|
# File 'lib/Indicator.rb', line 21
def output
@output
end
|
#timestamps ⇒ Object
Returns the value of attribute timestamps.
21
22
23
|
# File 'lib/Indicator.rb', line 21
def timestamps
@timestamps
end
|
Instance Method Details
#close ⇒ Object
35
36
37
|
# File 'lib/Indicator.rb', line 35
def close
operation(:c)
end
|
#high ⇒ Object
27
28
29
|
# File 'lib/Indicator.rb', line 27
def high
operation(:h)
end
|
#low ⇒ Object
31
32
33
|
# File 'lib/Indicator.rb', line 31
def low
operation(:l)
end
|
#open ⇒ Object
23
24
25
|
# File 'lib/Indicator.rb', line 23
def open
operation(:o)
end
|
#status ⇒ Object
43
44
45
46
|
# 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 ⇒ Object
39
40
41
|
# File 'lib/Indicator.rb', line 39
def volume
operation(:v)
end
|