class Finnhub::Stock

Attributes

description[R]
displaySymbol[R]
exchange[R]
symbol[R]

Public Class Methods

new(client:, symbol:, displaySymbol: nil, description: nil, exchange: nil) click to toggle source
# File lib/Stock.rb, line 29
def initialize(client:, symbol:,
  displaySymbol: nil, description: nil, exchange: nil)
  @client = client
  @symbol = symbol
  @displaySymbol = displaySymbol
  @description = description
  @exchange = exchange
end

Public Instance Methods

candles(**args)
Alias for: timeseries
ceo_compensation() click to toggle source
# File lib/Stock.rb, line 54
def ceo_compensation
  @client.request("/stock/ceo-compensation?symbol=#{@symbol}")
end
dividends(from:, to:) click to toggle source
# File lib/Stock.rb, line 149
def dividends(from:, to:)
  url = "/stock/dividend?symbol=#{@symbol}"
  from = from.to_date.to_s if from.is_a?(Time)
  url += "&from=#{from}"
  to = to.to_date.to_s if to.is_a?(Time)
  url += "&to=#{to}"
  @client.request(url)
end
earnings(limit: nil) click to toggle source
# File lib/Stock.rb, line 85
def earnings(limit: nil)
  url = "/stock/earnings?symbol=#{@symbol}"
  url += "&limit=#{limit}" unless limit.nil?
  @client.request(url)
end
earnings_calendar(from: nil, to: nil) click to toggle source
# File lib/Stock.rb, line 140
def earnings_calendar(from: nil, to: nil)
  url = "/calendar/earnings?symbol=#{@symbol}"
  from = from.to_date.to_s if from.is_a?(Time)
  url += "&from=#{from}" unless from.nil?
  to = to.to_date.to_s if to.is_a?(Time)
  url += "&to=#{to}" unless to.nil?
  @client.request(url)
end
earnings_estimate() click to toggle source
# File lib/Stock.rb, line 136
def earnings_estimate
  @client.request("/stock/eps-estimate?symbol=#{@symbol}")
end
executive() click to toggle source
# File lib/Stock.rb, line 58
def executive
  @client.request("/stock/executive?symbol=#{@symbol}")
end
financials(statement: "bs", freq: "annual") click to toggle source
# File lib/Stock.rb, line 107
def financials(statement: "bs", freq: "annual")
  @client.request("/stock/financials?symbol=#{@symbol}&statement=#{statement}&freq=#{freq}")
end
funds(limit: nil) click to toggle source
# File lib/Stock.rb, line 101
def funds(limit: nil)
  url = "/stock/fund-ownership?symbol=#{@symbol}"
  url += "&limit=#{limit}" unless limit.nil?
  @client.request(url)
end
indicator(**args) click to toggle source
# File lib/Stock.rb, line 183
def indicator(**args)
  Finnhub::Indicator.new(client: @client, stock: self, **args)
end
investors(limit: nil) click to toggle source
# File lib/Stock.rb, line 95
def investors(limit: nil)
  url = "/stock/investor-ownership?symbol=#{@symbol}"
  url += "&limit=#{limit}" unless limit.nil?
  @client.request(url)
end
major_development(from: nil, to: nil) click to toggle source
# File lib/Stock.rb, line 119
def major_development(from: nil, to: nil)
  url = "/major-development?symbol=#{@symbol}"
  from = from.to_date.to_s if from.is_a?(Time)
  url += "&from=#{from}" unless from.nil?
  to = to.to_date.to_s if to.is_a?(Time)
  url += "&to=#{to}" unless to.nil?
  @client.request(url)
end
metrics(metric: "price") click to toggle source
# File lib/Stock.rb, line 91
def metrics(metric: "price")
  @client.request("/stock/metric?symbol=#{@symbol}&metric=#{metric}")
end
news() click to toggle source
# File lib/Stock.rb, line 115
def news
  @client.request("/news/#{@symbol}")
end
option_chain() click to toggle source
# File lib/Stock.rb, line 74
def option_chain
  @client.request("/stock/option-chain?symbol=#{@symbol}")
end
peers(plain: false) click to toggle source
# File lib/Stock.rb, line 78
def peers(plain: false)
  output = @client.request("/stock/peers?symbol=#{@symbol}")
  return output if plain

  output.map{|o| Finnhub::Stock.new(client: @client, symbol: o)}
end
price_target() click to toggle source
# File lib/Stock.rb, line 66
def price_target
  @client.request("/stock/price-target?symbol=#{@symbol}")
end
profile(isin: nil, cusip: nil) click to toggle source
# File lib/Stock.rb, line 40
def profile(isin: nil, cusip: nil)
  if !isin.nil?
    string = "isin".freeze
    symbol = isin
  elsif !cusip.nil?
    string = "cusip".freeze
    symbol = cusip
  else
    string = "symbol".freeze
    symbol = @symbol
  end
  @client.request("/stock/profile?#{string}=#{symbol}")
end
quote() click to toggle source
# File lib/Stock.rb, line 111
def quote
  @client.request("/quote?symbol=#{@symbol}")
end
recommendation() click to toggle source
# File lib/Stock.rb, line 62
def recommendation
  @client.request("/stock/recommendation?symbol=#{@symbol}")
end
revenue_estimate() click to toggle source
# File lib/Stock.rb, line 132
def revenue_estimate
  @client.request("/stock/revenue-estimate?symbol=#{@symbol}")
end
sentiment() click to toggle source
# File lib/Stock.rb, line 128
def sentiment
  @client.request("/news-sentiment?symbol=#{@symbol}")
end
splits(from:, to:) click to toggle source
# File lib/Stock.rb, line 158
def splits(from:, to:)
  url = "/stock/split?symbol=#{@symbol}"
  from = from.to_date.to_s if from.is_a?(Time)
  url += "&from=#{from}"
  to = to.to_date.to_s if to.is_a?(Time)
  url += "&to=#{to}"
  @client.request(url)
end
tick(**args) click to toggle source
# File lib/Stock.rb, line 179
def tick(**args)
  Finnhub::Tick.new(client: @client, stock: self, **args)
end
timeseries(**args) click to toggle source
# File lib/Stock.rb, line 174
def timeseries(**args)
  Finnhub::Timeseries.new(client: @client, stock: self, **args)
end
Also aliased as: candles
transcripts(plain: false) click to toggle source
# File lib/Stock.rb, line 167
def transcripts(plain: false)
  output = @client.request("/stock/transcripts/list?symbol=#{@symbol}")
  return output if plain

  output[:transcripts].map{|o| Finnhub::Transcript.new(client: self, id: o[:id], hash: o)}
end
upgrade_downgrade() click to toggle source
# File lib/Stock.rb, line 70
def upgrade_downgrade
  @client.request("/stock/upgrade-downgrade?symbol=#{@symbol}")
end