Class: Finnhub::Tick

Inherits:
Object
  • Object
show all
Defined in:
lib/Tick.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#outputObject (readonly)

Returns the value of attribute output.



16
17
18
# File 'lib/Tick.rb', line 16

def output
  @output
end

#timestampsObject (readonly)

Returns the value of attribute timestamps.



16
17
18
# File 'lib/Tick.rb', line 16

def timestamps
  @timestamps
end

Instance Method Details

#priceObject



18
19
20
# File 'lib/Tick.rb', line 18

def price
  operation(:p)
end

#statusObject



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

#volumeObject



22
23
24
# File 'lib/Tick.rb', line 22

def volume
  operation(:v)
end