Skip to main content

A robinhood api wrapper for option data

Project description

Meow-Meow-Hood API

A Robinhood API wrapper for fast option market data

Installation

uv add meow-meow-hood
pip install meow-meow-hood

Why?

If you're using Robinhood as a broker still...
And if you want to view option market data at a reasonable speed. This was made for fun.

Authentication

Ensure you are logged in locally to Robinhood on either:

  • Chrome
  • Firefox

It works by extracting a locally stored access token from your browser data.
By default the client automatically checks Chrome first and then Firefox for a valid token.
If a stored token is rejected and open_browser=True, the refresh helper may briefly open the installed browsers to refresh auth state.
This behavior can be disabled on class creation with extract_token=False.
You will need to pass in the access token manually if token extraction is disabled.
Config folder is created at the cwd labeled .meow-meow-hood.
If cache enabled db file is placed inside this folder. Same for extract_token.

Robinhood(extract_token=False, access_token="...")

Usage

JSON responses are returned as named data classes for easier parsing.
Examples: FullQuote, OptionInstrument, OptionGreekData, etc.\

@dataclass(frozen=True, slots=True)
class FullQuote(ApiPayloadMixin):
    ask_price: float
    ask_size: int
    bid_price: float
    bid_size: int
    ...

(Refer to robinhood/api_dataclasses.py for full implementation details.)

OptionRequest is the main class when requesting option data.

OptionRequest(
    *,
    symbol: str,
    exp_date: str | None = None,
    option_type: Literal['call', 'put'] | None = None,
    strike_price: float | None = None
)

Example:

# With context manager
with Robinhood() as rh:
  spy_dates: list[str] = rh.get_expiration_dates("SPY")
  spy_request1 = OptionRequest(symbol="SPY", exp_date=spy_dates[0])
  spy_option_data = rh.get_option_greeks_batch_request(spy_request1)
  for option_request, options in spy_option_data.items():
    print(option_request, len(options))

# No context manager
rh = Robinhood()
spy_quote: FullQuote = rh.get_stock_quotes("SPY")
print(spy_quote.ask_price)
rh.close()

Local caching

This library uses a local SQLite database to cache option instruments and reduce the amount of requests made per call.
Cache is validated with a TTL of the next day at 9:30 EDT.
See /docs/design_notes.md for more details

Example where caching improves speed.

with Robinhood(enable_cache = True) as rh:
  dates = rh.get_expiration_dates("SPY")
  strike_map = rh.get_strike_prices(symbol="SPY",exp_date=dates[0])
  call_request = OptionRequest(
    symbol="SPY",
    exp_date=dates[0],
    option_type="call",
  )
  strikes = strike_map[call_request]
  spy_option_list = []
  # Generate a list of OptionRequests you want to view
  for s in strikes:
    opt_req = OptionRequest(symbol="SPY",exp_date=dates[0],strike_price=s)
    spy_option_list.append(opt_req)

  while True:
    option_data = rh.get_option_greeks_batch_request(spy_option_list)
    for option_request, options in option_data.items():
      option = options[0]
      print(option_request.strike_price, option.ask_price, option.bid_price)
    # Delay should be added to avoid rate limit
    time.sleep(0.25)

Trust Me Bro Benchmarks

Benchmark summary for 10 symbols[^benchmark-symbols] and the second nearest expiration date across 10 runs(~1.6k options returned per run).

Metric Cold Cache Warm Cache Improvement
Average get_expiration_dates time 0.06957s 0.00013s 99.81%
Average get_strike_prices time 0.31505s 0.00029s 99.91%
Average get_option_greeks_batch_request time 3.48793s 1.18787s 65.94%
Average total time per run 7.33413s 1.19204s 83.75%

Cold cache represents a run without any cached option data. Warm cache represents a run with cache hits.

[^benchmark-symbols]: SPY, TSLA, QQQ, NVDA, GOOG, MSFT, AMZN, TSM, META, JPM

TODO log

See /docs/todo.md for planned features.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

meow_meow_hood-0.2.0.tar.gz (32.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

meow_meow_hood-0.2.0-py3-none-any.whl (24.2 kB view details)

Uploaded Python 3

File details

Details for the file meow_meow_hood-0.2.0.tar.gz.

File metadata

  • Download URL: meow_meow_hood-0.2.0.tar.gz
  • Upload date:
  • Size: 32.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for meow_meow_hood-0.2.0.tar.gz
Algorithm Hash digest
SHA256 4ff623aa368b28546ef2956b94bb4ebcd0d2abd8af3e2e9a7869f9b5374d79bb
MD5 d521208c44b221646e4e9bb949418711
BLAKE2b-256 e9497a1b69c6e27c9ac4bd59947fdbc94c63a17bbd9b641ff07d641c06161fc4

See more details on using hashes here.

File details

Details for the file meow_meow_hood-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: meow_meow_hood-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 24.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for meow_meow_hood-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 71be83f12c979709c03fcef153ce28b5f6c0104b674a2a614878f68396c1d525
MD5 4631a556060bdb0159680c4df3ed73d5
BLAKE2b-256 934633a008fc8e5452ade32244e4bc4e1be9dbc03056a330e8221609ee0227f4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page