Class: Finnhub::Timeseries
- Inherits:
-
Object
- Object
- Finnhub::Timeseries
show all
- Defined in:
- lib/Timeseries.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(client:, stock:, resolution: "D", count: 100, from: nil, to: nil, format: nil, adjusted: false) ⇒ Timeseries
Returns a new instance of Timeseries.
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/Timeseries.rb', line 3
def initialize(client:, stock:, resolution: "D", count: 100,
from: nil, to: nil, format: nil, adjusted: false)
url = "/stock/candle?symbol=#{stock.symbol}&resolution=#{resolution}"
url += "&count=#{count}" unless count.nil?
from = from.to_i if from.is_a?(Time)
url += "&from=#{from}" unless from.nil?
to = to.to_i if to.is_a?(Time)
url += "&to=#{to}" unless to.nil?
url += "&format=#{format}" unless format.nil?
url += "&adjusted=#{adjusted}" if adjusted
@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
|
Instance Attribute Details
#output ⇒ Object
Returns the value of attribute output.
21
22
23
|
# File 'lib/Timeseries.rb', line 21
def output
@output
end
|
#timestamps ⇒ Object
Returns the value of attribute timestamps.
21
22
23
|
# File 'lib/Timeseries.rb', line 21
def timestamps
@timestamps
end
|
Instance Method Details
#close ⇒ Object
35
36
37
|
# File 'lib/Timeseries.rb', line 35
def close
operation(:c)
end
|
#high ⇒ Object
27
28
29
|
# File 'lib/Timeseries.rb', line 27
def high
operation(:h)
end
|
#low ⇒ Object
31
32
33
|
# File 'lib/Timeseries.rb', line 31
def low
operation(:l)
end
|
#open ⇒ Object
23
24
25
|
# File 'lib/Timeseries.rb', line 23
def open
operation(:o)
end
|
#status ⇒ Object
43
44
45
46
|
# File 'lib/Timeseries.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/Timeseries.rb', line 39
def volume
operation(:v)
end
|