Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

options-lib

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

options-lib

  • 0.9.4
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Options-Lib

A set of classes for dealing with options. It includes a crawler for Yahoo!Finance. The crawler has an internal thread that can be started to periodically update the option quotes.

Install

gem install options-lib

Usage

require 'options-lib'

# Create a crawler for all the options for ('AAPL') expiring on '2013-01-18'
y = YahooCrawler.new('AAPL', '2013-01-18')

# Fetch the entire options chain for this stock and expiration
y.fetch

# Show an option quote for a given strike price
y.call_options[300] # => AAPL_C300_18JAN2013: bid => 88.5, ask => 90.5
y.put_options[300] # => AAPL_P300_18JAN2013: bid => 40.7, ask => 41.95

# Options quote has stock price, bid and ask for option
q = y.call_options[300]
q.stock_price # => 342.88
q.bid # => 88.5
q.ask # => 90.5

# Crawler also has current stock price, as each option quote
y.stock_price # => 342.88

# You can get a list of all stock prices from the crawler
y.call_strikes # => [135.0, 140.0, ..., 530.0, 540.0]
y.put_strikes # => [135.0, 140.0, ..., 530.0, 540.0]

# So to print the entire options chain, you can do something like that
y.call_strikes.each { |strike| puts y.call_options[strike] }
y.put_strikes.each { |strike| puts y.put_options[strike] }	

# you can place the crawler in auto_reload mode, passing a period to refresh itself
y.auto_reload 5
y.call_options[300].bid # => 88.5
sleep 6
y.call_options[300].bid # => 90.3

# you can also receive callbacks from the internal thread when the crawler gets updated
y.auto_reload(5) do
  puts "Current bid: #{y.call_options[300].bid}"
end

# if you need to block ruby from exiting while your thread is executing in the background
# you can use the method below
y.join_reload_thread

# internal symbol versus real symbol
y.internal_symbol # => AAPL_C300_18JAN2013
y.symbol # => AAPL130119C00300000




FAQs

Package last updated on 24 Feb 2011

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc