Class: Finnhub::Tick
- Inherits:
-
Object
- Object
- Finnhub::Tick
- Defined in:
- lib/Tick.rb
Instance Attribute Summary collapse
-
#output ⇒ Object
readonly
Returns the value of attribute output.
-
#timestamps ⇒ Object
readonly
Returns the value of attribute timestamps.
Instance Method Summary collapse
-
#initialize(client:, stock:, from:, to:) ⇒ Tick
constructor
A new instance of Tick.
- #price ⇒ Object
- #status ⇒ Object
- #volume ⇒ Object
Constructor Details
#initialize(client:, stock:, from:, to:) ⇒ Tick
Returns a new instance of Tick.
3 4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/Tick.rb', line 3 def initialize(client:, stock:, from:, to:) url = "/stock/candle?symbol=#{stock.symbol}" from = from.to_i if from.is_a?(Time) url += "&from=#{from}" to = to.to_i if to.is_a?(Time) @output = client.request(url) if @output.is_a?(Hash) && @output[:s] == "ok" @timestamps = @output[:trades][:t]&.map{|t| Time.strptime(t.to_s,'%L')} else @timestamps = [] end end |
Instance Attribute Details
#output ⇒ Object (readonly)
Returns the value of attribute output.
16 17 18 |
# File 'lib/Tick.rb', line 16 def output @output end |
#timestamps ⇒ Object (readonly)
Returns the value of attribute timestamps.
16 17 18 |
# File 'lib/Tick.rb', line 16 def @timestamps end |
Instance Method Details
#price ⇒ Object
18 19 20 |
# File 'lib/Tick.rb', line 18 def price operation(:p) end |
#status ⇒ Object
27 28 29 30 |
# File 'lib/Tick.rb', line 27 def status raise Finnhub::Error message: "Output is not a hash" unless @output.is_a?(Hash) @output[:s] end |
#volume ⇒ Object
22 23 24 |
# File 'lib/Tick.rb', line 22 def volume operation(:v) end |