Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fundamental data support #9

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Next Next commit
Add support for the fundamental api
  • Loading branch information
tylerhaugen-stanley-amount committed Aug 22, 2020
commit 4233e13b547188a69a83687a747a6c0aad4a4040
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
spec/config.yml
*.lock
Copy link

@federbenjamin federbenjamin Aug 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] Why?

edit: in description, my bad

*.gem
.idea
8 changes: 4 additions & 4 deletions AlphavantageRB.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

Gem::Specification.new do |s|
s.name = "alphavantagerb"
s.version = "1.4.0"
s.authors = ["Stefano Martin"]
s.email = ["stefano.martin87@gmail.com"]
s.homepage = "https://github.com/StefanoMartin/AlphaVantageRB"
s.version = "1.5.0"
s.authors = ["Tyler Haugen-Stanley"]
s.email = ["tyler.mail.04@gmail.com"]
s.homepage = "https://github.com/tylerhaugen-stanley/AlphaVantageRB"
s.license = "MIT"
s.summary = "A gem for Alpha Vantage"
s.description = "A ruby wrapper for Alpha Vantage's HTTP API"
Expand Down
44 changes: 44 additions & 0 deletions lib/Fundamental_Data.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
module Alphavantage
class Fundamental_Data
include HelperFunctions

def initialize(symbol:, datatype: "json", key:, verbose: false)
@client = return_client(key, verbose)
tylerhaugen-stanley marked this conversation as resolved.
Show resolved Hide resolved
@symbol = symbol
@datatype = datatype
end

def overview(file: nil, datatype: @datatype)
make_request(file: file, datatype: datatype, endpoint: 'OVERVIEW')
end

def income_statement(file: nil, datatype: @datatype, period: :both)
make_request(file: file, datatype: datatype, endpoint: 'INCOME_STATEMENT')
end

def balance_sheet(file: nil, datatype: @datatype, period: :both)
payload = make_request(file: file, datatype: datatype, endpoint: 'BALANCE_SHEET')

return quarterly(payload) if period == :quarterly
return annual(payload) if period == :annual
payload
end

private

def make_request(file: nil, datatype: @datatype, endpoint:)
check_datatype(datatype, file)
url = "function=#{endpoint}&symbol=#{@symbol}"
return @client.download(url, file) if datatype == "csv"
@client.request(url)
end

def quarterly(payload)
payload['quarterlyReports']
end

def annual(payload)
payload['annualReports']
end
end
end
4 changes: 4 additions & 0 deletions lib/Stock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ def datatype=(datatype)
@datatype = datatype
end

def fundamental_data datatype: @datatype, file: nil
Alphavantage::Fundamental_Data.new symbol: @symbol, key: @client, datatype: datatype
end

def quote file: nil, datatype: @datatype
check_datatype(datatype, file)
url = "function=GLOBAL_QUOTE&symbol=#{symbol}"
Expand Down
32 changes: 17 additions & 15 deletions lib/alphavantagerb.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
require "httparty"
require "humanize"
require "open-uri"
require "ostruct"
require_relative "helper_function"
require_relative "Timeseries"
require_relative "Indicator"
require_relative "Stock"
require_relative "Errors"
require_relative "Exchange"
require_relative "Exchange_Timeseries"
require_relative "Crypto"
require_relative "Crypto_Timeseries"
require_relative "Sector"
require_relative "Client"
require "httparty"
require "humanize"
require "open-uri"
require "ostruct"
require_relative "helper_function"
require_relative "Timeseries"
require_relative "Indicator"
require_relative "Stock"
require_relative "Errors"
require_relative "Exchange"
require_relative "Exchange_Timeseries"
require_relative "Crypto"
require_relative "Crypto_Timeseries"
require_relative "Sector"
require_relative "Client"
require_relative "Fundamental_Data"