• Stars
    star
    191
  • Rank 202,877 (Top 4 %)
  • Language
    Ruby
  • Created over 15 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

[DEPRECATED] A simple wrapper for yahoo finance quotes end-point.

IMPORTANT: Yahoo Finance CSV API is no longer operational - this Gem is currently not working until support to the v7 API is added

Build Status

Ruby's Yahoo Finance Wrapper

A dead simple wrapper for yahoo finance quotes end-point.

Installation:

Just add it to your Gemfile:

gem 'yahoo-finance'

Usage:

Getting latest quotes for a set of symbols

Pass an array of valid symbols (stock names, indexes, exchange rates) and a list of fields you want:

yahoo_client = YahooFinance::Client.new
data = yahoo_client.quotes(["BVSP", "NATU3.SA", "USDJPY=X"], [:ask, :bid, :last_trade_date])

Data is now an array of results. You now have accessor methods to retrieve the data, with the return results being strings:

puts data[0].symbol + " value is: " + data[0].ask 

Passing raw: false will return numerical values

yahoo_client = YahooFinance::Client.new
data = yahoo_client.quotes(["BVSP", "NATU3.SA", "USDJPY=X"], [:ask, :bid, :last_trade_date], { raw: false } )
data[0].ask # This is now a BigDecimal

Passing na_as_nil: true will convert "N/A" responses to nil

yahoo_client = YahooFinance::Client.new

data = yahoo_client.quotes(["BVSP"], [:ask] )
data[0].ask
> "N/A"

data = yahoo_client.quotes(["BVSP"], [:ask], { na_as_nil: true } )
data[0].ask
> nil

The full list of fields follows:

     :after_hours_change_real_time
     :annualized_gain 
     :ask
     :ask_real_time
     :ask_size
     :average_daily_volume
     :bid
     :bid_real_time
     :bid_size
     :book_value
     :change
     :change_and_percent_change
     :change_from_200_day_moving_average 
     :change_from_50_day_moving_average 
     :change_from_52_week_high 
     :change_From_52_week_low 
     :change_in_percent 
     :change_percent_realtime 
     :change_real_time
     :close 
     :comission
     :day_value_change 
     :day_value_change_realtime 
     :days_range
     :days_range_realtime 
     :dividend_pay_date 
     :dividend_per_share
     :dividend_yield
     :earnings_per_share
     :ebitda 
     :eps_estimate_current_year 
     :eps_estimate_next_quarter 
     :eps_estimate_next_year 
     :error_indicator 
     :ex_dividend_date
     :float_shares 
     :high 
     :high_52_weeks 
     :high_limit 
     :holdings_gain 
     :holdings_gain_percent 
     :holdings_gain_percent_realtime 
     :holdings_gain_realtime 
     :holdings_value 
     :holdings_value_realtime 
     :last_trade_date
     :last_trade_price
     :last_trade_realtime_withtime 
     :last_trade_size 
     :last_trade_time 
     :last_trade_with_time 
     :low 
     :low_52_weeks 
     :low_limit 
     :market_cap_realtime 
     :market_capitalization 
     :more_info 
     :moving_average_200_day 
     :moving_average_50_day 
     :name 
     :notes 
     :one_year_target_price 
     :open 
     :order_book 
     :pe_ratio 
     :pe_ratio_realtime 
     :peg_ratio 
     :percent_change_from_200_day_moving_average 
     :percent_change_from_50_day_moving_average 
     :percent_change_from_52_week_high 
     :percent_change_from_52_week_low 
     :previous_close 
     :price_eps_estimate_current_year 
     :price_eps_Estimate_next_year 
     :price_paid 
     :price_per_book 
     :price_per_sales 
     :revenue
     :shares_outstanding
     :shares_owned 
     :short_ratio 
     :stock_exchange 
     :symbol 
     :ticker_trend 
     :trade_date
     :trade_links 
     :volume
     :weeks_range_52 

Getting symbols by stock market (beta)

Create a YahooFinance::Client instance

yahoo_client = YahooFinance::Client.new

Calling symbols_by_market method (symbols_by_market(country, stock_market))

Note: Can only be called with US Stock Markets for now.

Important: This data comes directly from NASDAQ's CSV endpoints, NOT Yahoo Finance. It might be extracted into a different Gem in the future.

yahoo_client.symbols_by_market('us', 'nyse') # Only US Stock Markets For Now

This method returns an array of symbols that can be used with the quotes method

data = yahoo_client.quotes(yahoo_client.symbols_by_market('us', 'nyse'), [:ask, :bid, :last_trade_date])

Getting companies by stock market (beta)

Create a YahooFinance::Client instance

yahoo_client = YahooFinance::Client.new

Calling companies_by_market method (companies_by_market(country, stock_market))

Note: Can only be called with US Stock Markets for now.

Important: This data comes directly from NASDAQ's CSV endpoints, NOT Yahoo Finance. It might be extracted into a different Gem in the future.

 # Only US Stock Markets For Now
yahoo_client.companies_by_market('us', 'nyse')
yahoo_client.companies_by_market('us', ['nyse', 'nasdaq'])
yahoo_client.companies_by_market('us') #All available markets by default

This method returns an hash of companies grouped by market. Each company object contains the following fields: symbol, name, last_sale, market_cap, ipo_year, sector, industry, summary_quote, market

Getting sectors (beta)

Create a YahooFinance::Client instance

yahoo_client = YahooFinance::Client.new

Calling sectors method (sectors(country, stock_market))

Note: Can only be called with US Stock Markets for now.

Important: This data comes directly from NASDAQ's CSV endpoints, NOT Yahoo Finance. It might be extracted into a different Gem in the future.

 # Only US Stock Markets For Now
yahoo_client.sectors('us', 'nyse')
yahoo_client.sectors('us', ['nyse', 'nasdaq'])
yahoo_client.sectors('us') #All available markets by default

This method returns an array of sectors on the selected markets. Each sector object contains the following fields: name

Getting industries (beta)

Create a YahooFinance::Client instance

yahoo_client = YahooFinance::Client.new

Calling industries method (industries(country, stock_market))

Note: Can only be called with US Stock Markets for now.

Important: This data comes directly from NASDAQ's CSV endpoints, NOT Yahoo Finance. It might be extracted into a different Gem in the future.

 # Only US Stock Markets For Now
yahoo_client.industries('us', 'nyse')
yahoo_client.industries('us', ['nyse', 'nasdaq'])
yahoo_client.industries('us') #All available markets by default

This method returns an array of industries on the selected markets. Each industry object contains the following fields: name, sector

Getting historical quotes

Retrieve historical data for a specific symbol (i.e. AAPL).

The last parameter (options) can include:

  • period: can be specified as :daily, :monthly, :weekly
  • start_date: the date from which historical quotes should be fetched (the parameter value should respond to to_time) (default: yesterday)
  • end_date: the date up to which historical quotes should be fetched (the parameter value should respond to to_time) (default: today)
yahoo_client = YahooFinance::Client.new
data = yahoo_client.historical_quotes("AAPL") # entire historical data

or

yahoo_client = YahooFinance::Client.new
data = yahoo_client.historical_quotes("AAPL", { start_date: Time::now-(24*60*60*10), end_date: Time::now }) # 10 days worth of data

or

yahoo_client = YahooFinance::Client.new
data = yahoo_client.historical_quotes("AAPL", { period: :monthly })

Getting splits

You can also retrieve split data.

yahoo_client = YahooFinance::Client.new
data = yahoo_client.splits('AAPL', :start_date => Date.today - 10*365)
data[0].date   # Date<2014-06-09>
data[0].before # 1
data[0].after  # 7

Enjoy! :-)

More Repositories

1

cliobot

open source bot framework for generative AI on telegram, discord, whatsapp & more
Python
81
star
2

deepdream-docker

Docker Container for Google's DeepDream project
Python
63
star
3

render_static

render_static makes any Rails/js single-page app SEO friendly by pre-rendering content for SEO bots
Ruby
19
star
4

double_submit_protection

A server-side control to avoid double-submission of html forms with sensitive data
Ruby
16
star
5

creative_machines

Experiments on content generation & machine "intelligence"
Kotlin
14
star
6

got

The got command is here. Winter is coming.
Go
10
star
7

react-three-fpscontrols

React Three Fiber FPS Controls for mobile and desktop. Joystick for mobile, Keyboard for desktop.
JavaScript
10
star
8

OpenSourceChess

A very basic game of chess
C#
9
star
9

campline

A tiny Campfire client for the command line
Ruby
9
star
10

mngmnt

A collection of resources, findings & references for becoming a better manager
9
star
11

sms.py

GSM Modem Adapter for Python (send and receive SMS using a regular GSM Modem)
Python
8
star
12

gradle-kotlin-docker-multiproject-boilerplate

A small boilerplate covering a bunch of things at the same time
Kotlin
8
star
13

thrurl

A cURL-like tool for calling Thrift services from the command line
Ruby
8
star
14

thrift-ios-nodejs-example

An example iOS client using Thrift to connect to a NodeJs server
Objective-C
7
star
15

cloudsearch_cmd

A tiny realtime search tool for cloud accounts
Go
5
star
16

kb

A tiny build tool for Kotlin & Java
Kotlin
5
star
17

twtr

A Twitter command-line client
Go
4
star
18

ruby_intelligence

Collective Intelligence in Ruby
Ruby
4
star
19

markovian_literature

Eventually generating literary text based on pseudo-random babble extracted from the top 100 books from Project Gutenberg.
Scala
4
star
20

groundcontrol

An Arduino-based Gobot device with knobs & buttons & bibs & bobs
Go
3
star
21

game-of-life-ios

A Conway's Game of Life implementation in Swift
Swift
3
star
22

haikuzao

A Haiku LSTM RNN
Scala
3
star
23

antisocial-chrome

An Anti-Social plugin for Chrome
JavaScript
3
star
24

bt_daemon

A little Bluetooth device detector in Python
Python
3
star
25

issuer

Issuer plugs in to your Rails app, catching exceptions and posting them to your Github project as issues.
Ruby
2
star
26

Shortr

Shortr is a wrapper around different URL shortening sites. It shortens stuff.
Ruby
2
star
27

backbone.styleguide

A live styleguide "extension" for BackboneJS-based apps
JavaScript
2
star
28

hello_swift

Scratchpad of basic tests of Swift lang
Swift
2
star
29

swogo

A simple and incomplete implementation of LOGO in Swift, as an XCode Playground
Swift
2
star
30

rfiduino

Arduino + RFID reader = a general purpose RFID card authenticator
Arduino
1
star
31

issuer_webapp

Issuer Oauth app
Ruby
1
star
32

cloudsearch

Kotlin
1
star
33

issuer_sample_app

Sample app demonstrating Issuer
Ruby
1
star
34

authgateway

A simple Oauth2 gateway for client-side apps that need to do OAuth2 authorization w/ multiple services
Go
1
star
35

imagemaker

1
star
36

feelsgoodstation

A RaspberryPi-powered weather & ambient noise station
Go
1
star
37

cgi-go

"Wait, what if we built self-contained CGIs... in 2017?"
Go
1
star
38

org_photos

Organize photos in folders using EXIF data or filename patterns
Ruby
1
star
39

ToDoApp

A sample Rubymotion task list app
Ruby
1
star
40

herval.github.io

SCSS
1
star
41

llm_router

Python
1
star
42

coinstream

Monitoring cryptocurrencies for fun, but not profit
Scala
1
star