The unofficial python interface for the WeBull API
Extensive market data access including real-time quotes, historical price data, news, analyst ratings, financial statements, and institutional holdings across stocks, options, and cryptocurrencies.
Get current market prices and basic quote information for stocks and other securities.
def get_quote(self, stock=None, tId=None):
"""
Get real-time quote for a security.
Parameters:
- stock (str, optional): Stock symbol (e.g., 'AAPL')
- tId (int, optional): Ticker ID (alternative to stock symbol)
Returns:
dict: Quote data including open, high, low, close, volume, change, changeRatio
Raises:
ValueError: If neither stock nor tId provided, or if symbol not found
"""Usage example:
# Get quote by symbol
quote = wb.get_quote(stock='AAPL')
print(f"AAPL: ${quote['close']} ({quote['changeRatio']}%)")
# Get quote by ticker ID
quote = wb.get_quote(tId=913256135)Get ticker metadata and search for securities by symbol.
def get_ticker(self, stock=''):
"""
Get ticker ID from stock symbol.
Parameters:
- stock (str): Stock symbol to look up
Returns:
int: Ticker ID for the symbol
Raises:
ValueError: If stock symbol not provided or not found
"""
def get_ticker_info(self, stock=None, tId=None):
"""
Get detailed ticker information and metadata.
Parameters:
- stock (str, optional): Stock symbol
- tId (int, optional): Ticker ID
Returns:
dict: Detailed ticker information including name, exchange, currency, etc.
"""
def get_all_tickers(self, region_code=None):
"""
Get list of all available tickers for a region.
Parameters:
- region_code (str, optional): Region code (defaults to user's region)
Returns:
list: List of all available tickers with metadata
"""Usage examples:
# Convert symbol to ticker ID
ticker_id = wb.get_ticker('AAPL')
print(f"AAPL ticker ID: {ticker_id}")
# Get detailed ticker information
info = wb.get_ticker_info(stock='AAPL')
print(f"Company: {info['name']}")
# Get all available US tickers
all_tickers = wb.get_all_tickers(region_code='US')Retrieve historical price bars and chart data with various time intervals.
def get_bars(self, stock=None, tId=None, interval='m1', count=1, extendTrading=0, timeStamp=None):
"""
Get historical price bars for stocks.
Parameters:
- stock (str, optional): Stock symbol
- tId (int, optional): Ticker ID
- interval (str): Time interval - 'm1', 'm5', 'm15', 'm30', 'h1', 'h2', 'h4', 'd1', 'w1'
- count (int): Number of bars to retrieve
- extendTrading (int): Include extended hours data (0=no, 1=yes)
- timeStamp (int, optional): Start timestamp for historical data
Returns:
list: List of price bars with open, high, low, close, volume, timestamp
"""
def get_bars_crypto(self, stock=None, tId=None, interval='m1', count=1, extendTrading=0, timeStamp=None):
"""
Get historical price bars for cryptocurrencies.
Parameters:
- stock (str, optional): Crypto symbol (e.g., 'BTCUSD')
- tId (int, optional): Ticker ID
- interval (str): Time interval - 'm1', 'm5', 'm15', 'm30', 'h1', 'h2', 'h4', 'd1', 'w1'
- count (int): Number of bars to retrieve
- extendTrading (int): Include 24/7 data for crypto
- timeStamp (int, optional): Start timestamp
Returns:
list: List of crypto price bars
"""
def get_chart_data(self, stock=None, tId=None, ma=5, timestamp=None):
"""
Get chart data with moving averages.
Parameters:
- stock (str, optional): Stock symbol
- tId (int, optional): Ticker ID
- ma (int): Moving average period
- timestamp (int, optional): Chart timestamp
Returns:
dict: Chart data with price and moving average information
"""Usage examples:
# Get daily bars for last 30 days
daily_bars = wb.get_bars(
stock='AAPL',
interval='d1',
count=30
)
# Get 5-minute bars with extended hours
minute_bars = wb.get_bars(
stock='TSLA',
interval='m5',
count=100,
extendTrading=1
)
# Get crypto data (24/7 available)
crypto_bars = wb.get_bars_crypto(
stock='BTCUSD',
interval='h1',
count=24
)Access news articles and press releases for securities and market events.
def get_news(self, stock=None, tId=None, Id=0, items=20):
"""
Get news articles for a security.
Parameters:
- stock (str, optional): Stock symbol
- tId (int, optional): Ticker ID
- Id (int): Starting news ID for pagination
- items (int): Number of news items to retrieve
Returns:
list: List of news articles with title, summary, source, timestamp, URL
"""
def get_press_releases(self, stock=None, tId=None, typeIds=None, num=50):
"""
Get press releases for a security.
Parameters:
- stock (str, optional): Stock symbol
- tId (int, optional): Ticker ID
- typeIds (list, optional): Filter by press release type IDs
- num (int): Number of press releases to retrieve
Returns:
list: List of press releases
"""Usage examples:
# Get latest news for Apple
news = wb.get_news(stock='AAPL', items=10)
for article in news:
print(f"{article['title']} - {article['sourceName']}")
# Get press releases
releases = wb.get_press_releases(stock='AAPL', num=5)Access analyst ratings, financial analysis, and institutional data.
def get_analysis(self, stock=None):
"""
Get analyst ratings and analysis data.
Parameters:
- stock (str): Stock symbol
Returns:
dict: Analysis data including ratings, price targets, recommendations
"""
def get_financials(self, stock=None):
"""
Get financial statements and key financial metrics.
Parameters:
- stock (str): Stock symbol
Returns:
dict: Financial data including income statement, balance sheet, cash flow
"""
def get_institutional_holding(self, stock=None, tId=None):
"""
Get institutional ownership and holdings data.
Parameters:
- stock (str, optional): Stock symbol
- tId (int, optional): Ticker ID
Returns:
dict: Institutional holdings with ownership percentages and changes
"""
def get_short_interest(self, stock=None, tId=None):
"""
Get short interest data and statistics.
Parameters:
- stock (str, optional): Stock symbol
- tId (int, optional): Ticker ID
Returns:
dict: Short interest data including short ratio, days to cover
"""Usage examples:
# Get analyst analysis
analysis = wb.get_analysis(stock='AAPL')
print(f"Rating: {analysis['rating']}")
print(f"Price Target: ${analysis['priceTarget']}")
# Get financial statements
financials = wb.get_financials(stock='AAPL')
print(f"Revenue: ${financials['revenue']}")
# Get institutional holdings
institutions = wb.get_institutional_holding(stock='AAPL')
for holding in institutions['data']:
print(f"{holding['name']}: {holding['percentage']}%")Access advanced market data including capital flow and ETF holdings.
def get_capital_flow(self, stock=None, tId=None, show_hist=True):
"""
Get capital flow data showing money flow in/out of security.
Parameters:
- stock (str, optional): Stock symbol
- tId (int, optional): Ticker ID
- show_hist (bool): Include historical capital flow data
Returns:
dict: Capital flow data with inflow/outflow amounts and trends
"""
def get_etf_holding(self, stock=None, tId=None, has_num=0, count=50):
"""
Get ETF holdings data for securities held by ETFs.
Parameters:
- stock (str, optional): Stock symbol
- tId (int, optional): Ticker ID
- has_num (int): Filter parameter for holdings data
- count (int): Number of ETF holdings to retrieve
Returns:
dict: ETF holdings data showing which ETFs hold the security
"""
def get_five_min_ranking(self, extendTrading=0):
"""
Get 5-minute ranking data for market movers.
Parameters:
- extendTrading (int): Include extended hours data
Returns:
dict: Ranking data for most active stocks in 5-minute intervals
"""Access earnings calendar and market events.
def get_calendar(self, stock=None, tId=None):
"""
Get earnings calendar and important dates for a security.
Parameters:
- stock (str, optional): Stock symbol
- tId (int, optional): Ticker ID
Returns:
dict: Calendar events including earnings dates, dividends, splits
"""
def get_calendar_events(self, event, start_date=None, page=1, num=50):
"""
Get market calendar events by type.
Parameters:
- event (str): Event type (e.g., 'earnings', 'dividends')
- start_date (str, optional): Start date for events (YYYY-MM-DD)
- page (int): Page number for pagination
- num (int): Number of events per page
Returns:
list: List of calendar events
"""Usage examples:
# Get earnings calendar for Apple
calendar = wb.get_calendar(stock='AAPL')
print(f"Next earnings: {calendar['earningsDate']}")
# Get all earnings events for a date range
earnings = wb.get_calendar_events(
event='earnings',
start_date='2024-01-01',
num=100
)Get options-specific market data and pricing information.
def get_options_bars(self, derivativeId=None, interval='1m', count=1, direction=1, timeStamp=None):
"""
Get historical price bars for options contracts.
Parameters:
- derivativeId (int): Options contract derivative ID
- interval (str): Time interval - '1m', '5m', '15m', '30m', '1h', '1d'
- count (int): Number of bars to retrieve
- direction (int): Direction flag (1 for ascending, -1 for descending)
- timeStamp (int, optional): Start timestamp
Returns:
list: Options price bars with open, high, low, close, volume
"""Find stocks and market opportunities using built-in screening tools.
def active_gainer_loser(self, direction='gainer', rank_type='afterMarket', count=50):
"""
Get list of active gainers or losers.
Parameters:
- direction (str): 'gainer', 'loser', or 'active'
- rank_type (str): 'afterMarket', 'preMarket', or 'regular'
- count (int): Number of results to return
Returns:
list: List of stocks with price change data
"""
def run_screener(self, region=None, price_lte=None, price_gte=None, pct_chg_gte=None, pct_chg_lte=None, sort=None, ...):
"""
Run custom stock screener with filtering criteria.
Parameters:
- region (str, optional): Market region to screen
- price_lte (float, optional): Maximum price filter
- price_gte (float, optional): Minimum price filter
- pct_chg_gte (float, optional): Minimum percentage change
- pct_chg_lte (float, optional): Maximum percentage change
- sort (str, optional): Sort criteria for results
- ... (additional screening parameters)
Returns:
list: Filtered list of stocks matching criteria
"""Usage examples:
# Get top gainers
gainers = wb.active_gainer_loser(
direction='gainer',
rank_type='regular',
count=20
)
# Screen for stocks under $50 with >5% gain
screen_results = wb.run_screener(
price_lte=50.0,
pct_chg_gte=5.0,
sort='pct_chg_desc'
)from webull import webull
wb = webull()
wb.login('your_email@example.com', 'your_password')
# Get comprehensive market data for a stock
symbol = 'AAPL'
try:
# Basic quote and ticker info
quote = wb.get_quote(stock=symbol)
ticker_info = wb.get_ticker_info(stock=symbol)
print(f"{ticker_info['name']} ({symbol})")
print(f"Price: ${quote['close']} ({quote['changeRatio']}%)")
print(f"Volume: {quote['volume']:,}")
# Historical data
daily_bars = wb.get_bars(stock=symbol, interval='d1', count=30)
print(f"30-day high: ${max(bar['high'] for bar in daily_bars)}")
print(f"30-day low: ${min(bar['low'] for bar in daily_bars)}")
# News and analysis
news = wb.get_news(stock=symbol, items=3)
print(f"\nLatest news:")
for article in news:
print(f"- {article['title']}")
# Financial analysis
analysis = wb.get_analysis(stock=symbol)
if analysis:
print(f"\nAnalyst rating: {analysis.get('rating', 'N/A')}")
print(f"Price target: ${analysis.get('priceTarget', 'N/A')}")
# Institutional holdings
institutions = wb.get_institutional_holding(stock=symbol)
print(f"\nTop institutional holders:")
for holding in institutions.get('data', [])[:3]:
print(f"- {holding['name']}: {holding['percentage']}%")
except ValueError as e:
print(f"Error getting market data: {e}")Install with Tessl CLI
npx tessl i tessl/pypi-webull