Skip to main content

A collection of stock analysis functions and api wrappers

Project description

lukhed_stocks

A collection of stocks analysis utility functions and API wrappers. Repo is in development. Please note that you are responsible for how you access and use the data. See the responsible data usage section for more info.

Installation

pip install lukhed-stocks

TOC

Available Functions
Available Wrappers
Responsible Data Usage

Available Functions

Available Wrappers

  • CAT Wrapper - Conolidated Audit Trail (CAT) for exchange data provided by CAT Webpage
  • Wikipedia Stocks - For obtaining various stock data from Wikipedia (various pages)
  • Schwab Wrapper - Wrapper for schwab-py wrapper. Adds key management and convenience functions to the unopinionated wrapper which provides auth, quotes, history, options, account info and more.
  • Robinhood Wrapper - Wrapper for Robinhood's public API endpoints. Provides access to stock data, fundamentals, charts, and popular stock lists without requiring authentication. Auth methods coming later.
  • Polygon.io Wrapper - Wrapper for Polygon.io's API. Provides free access to market status and holiday information with up to 5 API requests per minute and 500 requests per day.
  • TradingView Wrapper - Wrapper for TradingView's stock screener. Provides access to stock lists, filters by sector/industry, and customizable screening criteria.

Ticker Functions

Tickers Import

from lukhed_stocks import tickers

Get Tickers By Exchange

Provides a list of stock data for the given exchange. Each function can optionally be called with 'tickers_only' parameter to return a list of strings only. These functions utilize CAT data by default and do not require an API key.

nasdaq = tickers.get_nasdaq_stocks()
nyse = tickers.get_nyse_stocks(tickers_only=True)
otc = tickers.get_otc_stocks()
iex = tickers.get_iex_stocks(tickers_only=True)
Function Default Source
tickers.get_nasdaq_stocks CAT
tickers.get_nyse_stocks CAT
tickers.get_otc_stocks CAT
tickers.get_iex_stocks CAT

Get Tickers By Index

Provides a list of stock data for the given index. Each function can optionally be called with 'tickers_only' parameter to return a list of strings only. The default source for each function does not require an API key.

sp500 = tickers.get_sp500_stocks()
djia = tickers.get_dow_stocks(tickers_only=True)
otc = tickers.get_russell2000_stocks()
Function Default Source
tickers.get_sp500_stocks Wikipedia
tickers.get_dow_stocks Wikipedia
tickers.get_russell2000_stocks TradingView

Get Company Logo by Ticker

logo_url = tickers.get_company_logo('ALLT')
logo_url_with_download = tickers.get_company_logo('WAY', output_file='way.png')
Function Default Source
tickers.get_company_log Synth

CAT Wrapper

Documentation coming soon.

Wikipedia Stocks

Documentation coming soon.

Schwab Wrapper

Setup

Setup the API auth once and use it across hardware. To setup, instantiate with schwab_api_setup=True. By default, your private github repo is used for key mangement (you will need a github account and token). Setup will ask for your Schwab developer app key, secret, and callback url, then take you through authenticating with Schwab.

Note: this wrapper uses schwab-py for actual Schwab auth. See the documentation there for any issues or questions in setting up your schwab account.

#Github setup
schwab = SchwabPy(schwab_api_setup=True)
#Local setup (won't work across hardware)
schwab = SchwabPy(schwab_api_setup=True, key_management='local')

Usage Examples After Setup

schwab = SchwabPy()
quotes = schwab.get_stock_quote(['allt', 'way', 'pplt', 'impuy'])
price = schwab.get_stock_price('allt')
low = schwab.get_stock_52w_low('gld')
percent_below_high = schwab.get_percent_below_52w_high('aapl')

Cache Option

If prices are stale when using this wrapper (e.g., after market) or realtime price is not needed for your analysis, you can use cache to speed up calls.

schwab = SchwabPy(use_ticker_cache=True)
quotes = schwab.get_stock_quote(['allt', 'way', 'pplt', 'impuy'])   # 'allt' in cache
price = schwab.get_stock_price('allt')  # retrieve price from cache

Utilizing schwab-py

My wrapper is built for key management, advanced analysis, and ease of use. The exposed methods are recommended when using my wrapper, but you can access any of the endpoints available from schwab-py like below.

schwab.api.get_price_history_every_minute("ALLT")

Robinhood Wrapper

Setup

No authentication required. The wrapper provides access to Robinhood's public API endpoints.

from lukhed_stocks.robinhood import Robinhood

rh = Robinhood()

Basic Usage Examples

# Get basic instrument data
basic_data = rh.get_basic_data('AAPL')
multiple_stocks = rh.get_basic_data(['AAPL', 'TSLA', 'MSFT'])

# Get fundamental data
fundamentals = rh.get_fundamentals('AAPL')

# Get chart data for different time spans
daily_chart = rh.get_basic_chart_data('AAPL', span='day')
yearly_chart = rh.get_basic_chart_data('AAPL', span='year', extended_hours=True)

Popular Lists

# Get most held stocks on Robinhood
top_50 = rh.get_most_held_instruments(top_x=50)
symbols_only = rh.get_most_held_instruments(return_symbols_only=True)

# Search for instruments
search_results = rh.search_instruments_by_symbol_keyword('TECH')

API Rate Limiting

The wrapper includes built-in rate limiting to be respectful of Robinhood's servers.

# Adjust delay between API calls (default is 0.5 seconds)
rh = Robinhood(api_delay=1.0)

# Disable user agent randomization if needed
rh = Robinhood(random_user_agent=False)

Polygon.io Wrapper

Setup

Setup the API auth once and use it across hardware. To setup, instantiate the class and follow the prompts to enter your Polygon.io API key. By default, your private github repo is used for key management (you will need a github account and token).

# Github setup
from lukhed_stocks.polygon import PolygonIo

# Default instantiation uses github key_management
poly = PolygonIo()
# If you want to use local hardware key storage only
poly = PolygonIo(key_management='local')

Usage Examples After Setup

poly = PolygonIo()

# Get current market status
market_status = poly.get_market_status_now()

# Get upcoming market holidays
holidays = poly.get_upcoming_market_holidays()

# Check if market is open today
is_open = poly.is_market_open_today()

API Rate Limiting

The wrapper includes built-in rate limiting. The free tier allows 5 API requests per minute and 500 requests per day.

# Adjust delay between API calls (default is 1 second)
poly = PolygonIo(api_delay=2.0)

Skip Setup with Auth Dictionary

# Provide auth data directly to skip setup prompts
auth_data = {"key": "your_api_key_here"}
poly = PolygonIo(auth_dict=auth_data)

TradingView Wrapper

Setup

No authentication required. The wrapper provides access to TradingView's stock screener endpoints.

from lukhed_stocks.tradingview import TradingView

tv = TradingView()

Basic Usage Examples

# Get all stocks with default TradingView filters and columns
all_stocks = tv.screener_get_all_stocks()

# Get stocks by index
dow_stocks = tv.screener_get_stocks_by_index('dow')
sp500_stocks = tv.screener_get_stocks_by_index('s&p')
nasdaq_stocks = tv.screener_get_stocks_by_index('nasdaq')
russell_stocks = tv.screener_get_stocks_by_index('russel 2000')

# Get stocks at new highs or lows
new_52w_highs = tv.screener_new_highs_lows(new_high_or_low='high', month_time_frame=12)
new_3m_lows = tv.screener_new_highs_lows(new_high_or_low='low', month_time_frame=3)
all_time_highs = tv.screener_new_highs_lows(new_high_or_low='high', month_time_frame='all time')

Filtering Stock Lists

# Filter by sector or industry
tech_stocks = tv.filter_stock_list_by_sector('Technology', all_stocks['data'])
multiple_sectors = tv.filter_stock_list_by_sector(['Healthcare', 'Finance'], all_stocks['data'])
industry_filtered = tv.filter_stock_list_by_industry('Software', all_stocks['data'])

# Get sector/industry information
sectors = tv.get_all_sectors_in_list(all_stocks['data'])
industries = tv.get_all_industries_in_list(all_stocks['data'])
breakdown = tv.get_sector_industry_breakdown_of_list(all_stocks['data'])
tickers = tv.get_unique_stock_tickers_in_list(all_stocks['data'])

Customizing Screener Columns

# Use predefined column sets
tv.set_stock_screener_columns_overview()
tv.set_stock_screener_columns_performance()
tv.set_stock_screener_columns_valuation()
tv.set_stock_screener_columns_dividends()
tv.set_stock_screener_columns_technicals()
tv.set_stock_screener_columns_profitiability()
tv.set_stock_screener_columns_per_share()

# Add custom columns
tv.custom_define_columns(["name", "description", "Perf.W", "Perf.1M", "Perf.3M", "Perf.6M", "Perf.YTD", "exchange"])

# Add to existing columns instead of replacing
tv.set_stock_screener_columns_time_period_performance(add_to_current_columns=True)

# Reset to defaults
tv.reset_screener_columns()

Custom Filters

# Add custom filters
custom_filter = {
    "left": "market_cap_basic",
    "operation": "egreater",
    "right": 1000000000
}
tv.add_screener_filters(custom_filter)

# Reset filters to default
tv.reset_screener_filters()

# Clear all filters
tv.clear_screener_filters()

# Set completely custom filter
tv.set_custom_screener_filter(custom_filter)

Supported Index Filters

The wrapper supports filtering by the following indices (check tv.index_lookup for full list):

  • Dow Jones: 'dow'
  • S&P 500: 's&p'
  • Nasdaq Composite: 'nasdaq'
  • Nasdaq 100: 'nasdaq 100'
  • Russell 2000: 'russel 2000'
  • And many more sector-specific indices

Responsible Data Usage

  • Each method or wrapper in the documentation lists the source that is utilized by default
  • Below is information related to data retrieval and usage for each source

CAT Data Usage

CAT Data is pulled from this page. They provide a legal notice here.

Wikipedia Data Usage

Wikipedia content is licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License. For more details on the terms of use, please refer to the Wikimedia Foundation's Terms of Use.

Synth

Full Synth terms are found here. This library provides access to synth:

  • Images, free to use if attribution is provided (please confirm with synthfinance.com or the terms above)

Robinhood Data Usage

Data is accessed through Robinhood's public API endpoints without authentication. This wrapper is intended for educational and research purposes. Please respect Robinhood's terms of service and API usage guidelines. Users are responsible for ensuring their usage complies with Robinhood's policies.

Polygon.io Data Usage

Data is accessed through Polygon.io's API. Free tier provides up to 5 API requests per minute and 500 requests per day. For higher volume usage, please visit Polygon.io's pricing page. Users are responsible for ensuring their usage complies with Polygon.io's terms of service and API usage limits.

Tradingview Data Usage

I am currently trying to remove trading view as a source, as their policy is restrictive and confusing. Please read trading view policies here

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

lukhed_stocks-0.2.4.tar.gz (29.8 kB view details)

Uploaded Source

Built Distribution

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

lukhed_stocks-0.2.4-py3-none-any.whl (28.8 kB view details)

Uploaded Python 3

File details

Details for the file lukhed_stocks-0.2.4.tar.gz.

File metadata

  • Download URL: lukhed_stocks-0.2.4.tar.gz
  • Upload date:
  • Size: 29.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.9

File hashes

Hashes for lukhed_stocks-0.2.4.tar.gz
Algorithm Hash digest
SHA256 f3f88b8773eba5ba8a1d4bdcc2015257506c979b195f10a877248cd2a554adad
MD5 30e132d1f773380318dd9c45978ad619
BLAKE2b-256 513fc50d3ba4ea3cd7a5eabedff370e191ab4147d6afb4e1a02db3e6d862d648

See more details on using hashes here.

File details

Details for the file lukhed_stocks-0.2.4-py3-none-any.whl.

File metadata

  • Download URL: lukhed_stocks-0.2.4-py3-none-any.whl
  • Upload date:
  • Size: 28.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.9

File hashes

Hashes for lukhed_stocks-0.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 227723a81d0f3430f9eba46815f8d1472b0778a07198059c9c43c8a46cfb23f5
MD5 a65bd2e7802457753873fe6577867a9f
BLAKE2b-256 16116d97e2c23ffb9e843140ecb116eebdef4fd1c8b7793bde594eee5ce511dc

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