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 the locally stored access token from the browser folder.
By default it will automatically try to extract the token, this can be disabled on class creation.
You will need to pass in the access token manually if extract_token is disabled.
Config folder is created at the cwd labeled .meow-meow-hood.
Ensure you select the correct browser on class creation current default is Chrome.
Use either Chrome() or Firefox() for the browser= parameter.
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.1.0.tar.gz (23.9 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.1.0-py3-none-any.whl (20.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: meow_meow_hood-0.1.0.tar.gz
  • Upload date:
  • Size: 23.9 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.1.0.tar.gz
Algorithm Hash digest
SHA256 9102f62f5c104f986536e38442c89b6d167764e945449b816c3a47818c0d5506
MD5 f7da7cbd791f769606060fda1d027915
BLAKE2b-256 a420a61574e6a4fcb0f553e153062b2c37432d7925ddf63e4ebdb5847559876b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: meow_meow_hood-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 20.0 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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4442ca03c85d5ccac5da36380faa07a99bd589331d717b165a64b81a0c3bd601
MD5 059a373a0c4a86ba187fdd1ad64a43a8
BLAKE2b-256 62bd19963f7f510e5be3719b82f98e8b08e0b052716c7588f1e5bf83afca8e5d

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