### Install and Start MCP Server Source: https://context7.com/deepentropy/tvscreener/llms.txt Installs the tvscreener library with optional MCP support for AI integration and starts the MCP server. Also shows how to register the server with the Claude Code CLI. ```bash # Install with MCP support pip install tvscreener[mcp] # Start the MCP server tvscreener-mcp # Register with Claude Code CLI claude mcp add tvscreener -- tvscreener-mcp ``` -------------------------------- ### Full Example Source: https://github.com/deepentropy/tvscreener/blob/main/docs/api/screeners.md A comprehensive example demonstrating the initialization and configuration of a StockScreener. ```APIDOC ## Full Example ### Code ```python from tvscreener import StockScreener, StockField, IndexSymbol ss = StockScreener() # Filter to S&P 500 ss.set_index(IndexSymbol.SP500) # Add conditions ss.where(StockField.PRICE.between(50, 500)) ss.where(StockField.PE_RATIO_TTM.between(10, 30)) ss.where(StockField.RELATIVE_STRENGTH_INDEX_14 < 50) # Select fields ss.select( StockField.NAME, StockField.PRICE, StockField.PE_RATIO_TTM, StockField.RELATIVE_STRENGTH_INDEX_14, StockField.MARKET_CAPITALIZATION ) # Sort and paginate ss.sort_by(StockField.MARKET_CAPITALIZATION, ascending=False) ss.set_range(0, 100) # Execute df = ss.get() ``` ``` -------------------------------- ### Quick Start Forex Screener Source: https://github.com/deepentropy/tvscreener/blob/main/docs/screeners/forex.md Initialize the ForexScreener and fetch data. This is the basic setup for any screening operation. ```python from tvscreener import ForexScreener, ForexField fs = ForexScreener() df = fs.get() ``` -------------------------------- ### Install tvscreener from Source Source: https://github.com/deepentropy/tvscreener/blob/main/docs/getting-started/installation.md Clone the repository and install tvscreener in editable mode for development. ```bash git clone https://github.com/deepentropy/tvscreener.git cd tvscreener pip install -e . ``` -------------------------------- ### Install tvscreener Source: https://context7.com/deepentropy/tvscreener/llms.txt Install the tvscreener library using pip. Install with MCP support using `pip install tvscreener[mcp]`. ```bash pip install tvscreener # With MCP (Model Context Protocol) server support pip install tvscreener[mcp] ``` -------------------------------- ### Quick Start Crypto Screener Source: https://github.com/deepentropy/tvscreener/blob/main/docs/screeners/crypto.md Initialize the CryptoScreener and fetch data. This is the basic setup for any screening operation. ```python from tvscreener import CryptoScreener, CryptoField cs = CryptoScreener() df = cs.get() ``` -------------------------------- ### Install tvscreener from GitHub Source: https://github.com/deepentropy/tvscreener/blob/main/README.md Install the tvscreener library directly from its GitHub repository. Use this if you need the latest development version. ```sh $ pip install git+https://github.com/deepentropy/tvscreener.git ``` -------------------------------- ### Initialize Stock Screener Source: https://github.com/deepentropy/tvscreener/blob/main/docs/screeners/stock.md Initialize the Stock Screener and get all available stocks. This is the basic setup for using the screener. ```python from tvscreener import StockScreener, StockField ss = StockScreener() df = ss.get() ``` -------------------------------- ### Install and Run MCP Server Source: https://github.com/deepentropy/tvscreener/blob/main/README.md Install the tvscreener library with MCP support and run the MCP server. Register the server with Claude Code for AI assistant integration. ```bash # Install with MCP support pip install tvscreener[mcp] # Run MCP server tvscreener-mcp # Register with Claude Code claude mcp add tvscreener -- tvscreener-mcp ``` -------------------------------- ### Install Optional Rich Dependencies Source: https://github.com/deepentropy/tvscreener/blob/main/docs/getting-started/installation.md Install the 'rich' library for styled output, such as colored tables. ```bash pip install rich ``` -------------------------------- ### Full Stock Screener Example with Multiple Filters Source: https://github.com/deepentropy/tvscreener/blob/main/docs/api/screeners.md A comprehensive example demonstrating initialization, index filtering, multiple conditions, field selection, sorting, pagination, and execution. ```python from tvscreener import StockScreener, StockField, IndexSymbol ss = StockScreener() # Filter to S&P 500 ss.set_index(IndexSymbol.SP500) # Add conditions ss.where(StockField.PRICE.between(50, 500)) ss.where(StockField.PE_RATIO_TTM.between(10, 30)) ss.where(StockField.RELATIVE_STRENGTH_INDEX_14 < 50) # Select fields ss.select( StockField.NAME, StockField.PRICE, StockField.PE_RATIO_TTM, StockField.RELATIVE_STRENGTH_INDEX_14, StockField.MARKET_CAPITALIZATION ) # Sort and paginate ss.sort_by(StockField.MARKET_CAPITALIZATION, ascending=False) ss.set_range(0, 100) # Execute df = ss.get() ``` -------------------------------- ### Install and Import tvscreener Source: https://github.com/deepentropy/tvscreener/blob/main/docs/notebooks/01-quickstart.ipynb Installs the tvscreener library if not already present and imports necessary classes for different screeners. ```python # Install tvscreener if needed # !pip install tvscreener import tvscreener as tvs from tvscreener import ( StockScreener, CryptoScreener, ForexScreener, BondScreener, FuturesScreener, CoinScreener ) ``` -------------------------------- ### Initialize Coin Screener Source: https://github.com/deepentropy/tvscreener/blob/main/docs/screeners/coin.md Instantiate the CoinScreener and fetch all available data. This is the basic setup for using the screener. ```python from tvscreener import CoinScreener, CoinField cs = CoinScreener() df = cs.get() ``` -------------------------------- ### Install tvscreener from PyPI Source: https://github.com/deepentropy/tvscreener/blob/main/docs/getting-started/installation.md Use pip to install the latest stable version of tvscreener from the Python Package Index. ```bash pip install tvscreener ``` -------------------------------- ### Verify tvscreener Installation Source: https://github.com/deepentropy/tvscreener/blob/main/docs/getting-started/installation.md Import the library and use the StockScreener to retrieve and print the number of stocks. ```python import tvscreener as tvs ss = tvs.StockScreener() df = ss.get() print(f"Retrieved {len(df)} stocks") ``` -------------------------------- ### Method Chaining Example Source: https://github.com/deepentropy/tvscreener/blob/main/docs/api/screeners.md Demonstrates how to chain common methods for a fluent query building experience. ```APIDOC ## Method Chaining ### Example ```python df = ( StockScreener() .select(StockField.NAME, StockField.PRICE) .where(StockField.PRICE > 100) .sort_by(StockField.VOLUME, ascending=False) .set_range(0, 50) .get() ) ``` ``` -------------------------------- ### Retrieve Analyst Recommendation Fields Source: https://github.com/deepentropy/tvscreener/blob/main/docs/guide/selecting-fields.md Get a list of all analyst recommendation fields. This example prints the names of all recommendation fields. ```python # Get analyst recommendation fields recs = StockField.recommendations() for field in recs: print(field.name) ``` -------------------------------- ### Initialize Futures Screener Source: https://github.com/deepentropy/tvscreener/blob/main/docs/screeners/futures.md Quick start by initializing the FuturesScreener and fetching data. Requires importing FuturesScreener and FuturesField. ```python from tvscreener import FuturesScreener, FuturesField fs = FuturesScreener() df = fs.get() ``` -------------------------------- ### Install Optional MCP Dependencies Source: https://github.com/deepentropy/tvscreener/blob/main/docs/getting-started/installation.md Install tvscreener with MCP server integration for AI assistants. This command also includes instructions for running the MCP server and registering it with Claude Code. ```bash pip install tvscreener[mcp] # Run the MCP server tvscreener-mcp # Register with Claude Code claude mcp add tvscreener -- tvscreener-mcp ``` -------------------------------- ### Initialize Bond Screener Source: https://github.com/deepentropy/tvscreener/blob/main/docs/screeners/bond.md Instantiate the BondScreener and retrieve all available bond data. This is the basic setup for using the screener. ```python from tvscreener import BondScreener, BondField bs = BondScreener() df = bs.get() ``` -------------------------------- ### Install Optional Jupyter Dependencies Source: https://github.com/deepentropy/tvscreener/blob/main/docs/getting-started/installation.md Install 'ipywidgets' for integration with Jupyter notebooks. ```bash pip install ipywidgets ``` -------------------------------- ### Complete Example: S&P 500 Screening Source: https://github.com/deepentropy/tvscreener/blob/main/docs/guide/filtering.md A comprehensive example demonstrating how to filter for S&P 500 stocks with specific price, volume, and valuation criteria. Imports include `StockScreener`, `StockField`, `IndexSymbol`, and `Exchange`. ```python from tvscreener import StockScreener, StockField, IndexSymbol, Exchange ss = StockScreener() # S&P 500 stocks only ss.set_index(IndexSymbol.SP500) # Price and volume filters ss.where(StockField.PRICE.between(20, 500)) ss.where(StockField.VOLUME >= 500_000) # Valuation filters ss.where(StockField.PE_RATIO_TTM.between(5, 30)) ss.where(StockField.PRICE_TO_BOOK_FY < 5) ``` -------------------------------- ### Initialize and Get Stock Screener Data Source: https://github.com/deepentropy/tvscreener/blob/main/docs/api/screeners.md Instantiate a StockScreener and retrieve all data as a pandas DataFrame. This is the most basic usage. ```python ss = StockScreener() df = ss.get() ``` -------------------------------- ### Initialize Other Screeners Source: https://github.com/deepentropy/tvscreener/blob/main/docs/getting-started/quickstart.md Instantiate and get data from different screener types: Forex, Crypto, Bonds, and Futures. ```python import tvscreener as tvs # Forex fs = tvs.ForexScreener() df = fs.get() # Crypto cs = tvs.CryptoScreener() df = cs.get() # Bonds bs = tvs.BondScreener() df = bs.get() # Futures futs = tvs.FuturesScreener() df = futs.get() ``` -------------------------------- ### Retrieve All Technical Indicator Fields Source: https://github.com/deepentropy/tvscreener/blob/main/docs/guide/selecting-fields.md Get a list of all available technical indicator fields. This example prints the names of the first 10. ```python # Get all technical indicator fields technicals = StockField.technicals() for field in technicals[:10]: print(field.name) ``` -------------------------------- ### Find RSI Reversal Setup Source: https://github.com/deepentropy/tvscreener/blob/main/docs/examples/crypto-strategies.md Identify potential reversal setups by looking for cryptocurrencies with a Relative Strength Index (RSI) between 30 and 40, indicating oversold conditions, and positive price change. ```python cs = CryptoScreener() cs.where(CryptoField.RELATIVE_STRENGTH_INDEX_14.between(30, 40)) cs.where(CryptoField.CHANGE_PERCENT > 0) cs.where(CryptoField.MARKET_CAPITALIZATION > 100e6) df = cs.get() ``` -------------------------------- ### Pagination Examples Source: https://github.com/deepentropy/tvscreener/blob/main/docs/guide/sorting-pagination.md Illustrates various ways to set the result range for pagination, including fetching the first N results, specific slices, and the maximum allowed results. ```python # First 50 results ss.set_range(0, 50) # Results 51-100 ss.set_range(50, 100) # Results 101-150 ss.set_range(100, 150) # First 500 results ss.set_range(0, 500) # Maximum results (up to 5000) ss.set_range(0, 5000) ``` -------------------------------- ### Initialize and Get Bond Screener Data Source: https://github.com/deepentropy/tvscreener/blob/main/docs/notebooks/01-quickstart.ipynb Initializes the BondScreener and retrieves all available bond data. Use this for bond market screening. ```python bs = BondScreener() df = bs.get() print(f"Retrieved {len(df)} bonds with {len(df.columns)} columns") df.head() ``` -------------------------------- ### Search for Fields by Name Source: https://github.com/deepentropy/tvscreener/blob/main/docs/guide/selecting-fields.md Discover fields by searching for keywords. This example finds and prints the first 10 RSI-related fields. ```python # Find RSI-related fields matches = StockField.search("rsi") for field in matches[:10]: print(field.name) ``` -------------------------------- ### Initialize and Get Forex Screener Data Source: https://github.com/deepentropy/tvscreener/blob/main/docs/notebooks/01-quickstart.ipynb Initializes the ForexScreener and retrieves all available currency pair data. Use this for forex market analysis. ```python fs = ForexScreener() df = fs.get() print(f"Retrieved {len(df)} forex pairs with {len(df.columns)} columns") df.head() ``` -------------------------------- ### Initialize and Get Crypto Screener Data Source: https://github.com/deepentropy/tvscreener/blob/main/docs/notebooks/01-quickstart.ipynb Initializes the CryptoScreener and retrieves all available cryptocurrency data. Use this for a comprehensive list of cryptocurrencies. ```python cs = CryptoScreener() df = cs.get() print(f"Retrieved {len(df)} cryptos with {len(df.columns)} columns") df.head() ``` -------------------------------- ### Complex Filters Example Source: https://github.com/deepentropy/tvscreener/blob/main/docs/api/filters.md Provides a comprehensive example of applying various filters, including index, price range, volume, valuation, sector, technical, and performance filters. ```APIDOC ## Complex Filters Example ```python from tvscreener import StockScreener, StockField, IndexSymbol ss = StockScreener() # Index filter ss.set_index(IndexSymbol.SP500) # Price range ss.where(StockField.PRICE.between(20, 500)) # Volume filter ss.where(StockField.VOLUME >= 500_000) # Valuation filters ss.where(StockField.PE_RATIO_TTM.between(5, 25)) ss.where(StockField.PRICE_TO_BOOK_FY < 5) # Sector filter ss.where(StockField.SECTOR.not_in(['Finance', 'Utilities'])) # Technical filter ss.where(StockField.RELATIVE_STRENGTH_INDEX_14.between(30, 70)) # Performance filter ss.where(StockField.CHANGE_PERCENT > 0) df = ss.get() ``` ``` -------------------------------- ### Initialize Stock Screener and Set Index Source: https://github.com/deepentropy/tvscreener/blob/main/docs/notebooks/02-stocks.ipynb Initializes the StockScreener and sets the index for screening, such as S&P 500. This is a common setup for many screening strategies. ```python from tvscreener import StockScreener, StockField, IndexSymbol, Market import pandas as pd ``` ```python ss = StockScreener() ss.set_index(IndexSymbol.SP500) ``` -------------------------------- ### Check Python Version Source: https://github.com/deepentropy/tvscreener/blob/main/docs/getting-started/installation.md Verify that your Python installation meets the minimum requirement of Python 3.10. ```bash python --version ``` -------------------------------- ### MCP Server Integration Source: https://context7.com/deepentropy/tvscreener/llms.txt Details on how to install and use the optional Model Context Protocol (MCP) server for AI tool integration. ```APIDOC ## MCP Server ### Description An optional Model Context Protocol server (`tvscreener-mcp`) that enables AI tools to query market data directly. It can be installed with the `mcp` extra and registered as an MCP tool provider. ### Installation ```bash pip install tvscreener[mcp] ``` ### Usage Start the server using `tvscreener-mcp`. Register it with AI assistants like Claude using `claude mcp add tvscreener -- tvscreener-mcp`. ### Exposed Tools * `discover_fields(keyword)` * `custom_query(fields, filters)` * `search_stocks(...)` * `search_crypto(...)` * `search_forex(...)` * `get_top_movers(market)` ``` -------------------------------- ### MCP Server AI Assistant Tool Examples Source: https://context7.com/deepentropy/tvscreener/llms.txt Illustrates the tools exposed by the tvscreener MCP server to AI assistants, such as discovering fields, performing custom queries, and searching for stocks, crypto, or forex. ```python # The MCP server exposes these tools to AI assistants: # - discover_fields(keyword) → search 3,500+ fields by keyword # - custom_query(fields, filters) → flexible screener query # - search_stocks(...) → simplified stock screener # - search_crypto(...) → simplified crypto screener # - search_forex(...) → simplified forex screener # - get_top_movers(market) → top gainers/losers # Example: how an AI assistant would invoke it via MCP # discover_fields("RSI") # custom_query(fields=["name","close","RSI14"], filters=[{"field":"close","op":">","value":100}]) ``` -------------------------------- ### Quick Example: Filter S&P 500 Stocks with tvscreener Source: https://github.com/deepentropy/tvscreener/blob/main/docs/index.md Demonstrates how to initialize the StockScreener, set an index filter (S&P 500), apply Pythonic filters on price and RSI, select specific fields, sort the results, and retrieve the data as a pandas DataFrame. ```python from tvscreener import StockScreener, StockField, IndexSymbol ss = StockScreener() # Filter S&P 500 stocks ss.set_index(IndexSymbol.SP500) # Pythonic filtering ss.where(StockField.PRICE > 50) ss.where(StockField.PE_RATIO_TTM.between(10, 25)) ss.where(StockField.RELATIVE_STRENGTH_INDEX_14 < 40) # Select fields ss.select( StockField.NAME, StockField.PRICE, StockField.CHANGE_PERCENT, StockField.PE_RATIO_TTM, StockField.RELATIVE_STRENGTH_INDEX_14 ) # Sort and limit ss.sort_by(StockField.MARKET_CAPITALIZATION, ascending=False) ss.set_range(0, 100) df = ss.get() ``` -------------------------------- ### Screen for Value Stocks Source: https://github.com/deepentropy/tvscreener/blob/main/docs/screeners/stock.md Example screen to identify value stocks by filtering based on PE Ratio, Price to Book, and Market Capitalization, then sorting by PE Ratio. ```python ss = StockScreener() ss.set_index(IndexSymbol.SP500) ss.where(StockField.PE_RATIO_TTM.between(5, 15)) ss.where(StockField.PRICE_TO_BOOK_FY < 3) ss.where(StockField.MARKET_CAPITALIZATION > 10e9) ss.sort_by(StockField.PE_RATIO_TTM, ascending=True) df = ss.get() ``` -------------------------------- ### Bollinger Squeeze Setup Source: https://github.com/deepentropy/tvscreener/blob/main/docs/examples/technical-analysis.md Identifies potential Bollinger Band squeezes by looking for low volatility (low Average True Range) and price near the middle band. Requires minimum volume. ```python ss = StockScreener() # Price near middle band (low volatility) ss.where(StockField.BOLLINGER_UPPER_BAND_20 > 0) ss.where(StockField.AVERAGE_TRUE_RANGE_14 < 2) # Low ATR ss.where(StockField.VOLUME >= 500_000) ss.select( StockField.NAME, StockField.PRICE, StockField.BOLLINGER_LOWER_BAND_20, StockField.BOLLINGER_UPPER_BAND_20, StockField.AVERAGE_TRUE_RANGE_14 ) df = ss.get() ``` -------------------------------- ### Initialize and Get Coin Screener Data Source: https://github.com/deepentropy/tvscreener/blob/main/docs/notebooks/01-quickstart.ipynb Initializes the CoinScreener and retrieves all available coin data from CoinGecko. Use this for cryptocurrency analysis based on CoinGecko data. ```python coins = CoinScreener() df = coins.get() print(f"Retrieved {len(df)} coins with {len(df.columns)} columns") df.head() ``` -------------------------------- ### Initialize and Get Futures Screener Data Source: https://github.com/deepentropy/tvscreener/blob/main/docs/notebooks/01-quickstart.ipynb Initializes the FuturesScreener and retrieves all available futures contract data. Use this for futures market screening. ```python futs = FuturesScreener() df = futs.get() print(f"Retrieved {len(df)} futures with {len(df.columns)} columns") df.head() ``` -------------------------------- ### Select All Fields and Retrieve Data Source: https://github.com/deepentropy/tvscreener/blob/main/docs/notebooks/04-forex.ipynb Instantiate the ForexScreener, select all available fields, set a range for the data retrieval, and then get the data. This is useful for fetching a comprehensive dataset for analysis. ```python fs = ForexScreener() fs.select_all() fs.set_range(0, 10) df = fs.get() print(f"Retrieved {len(df.columns)} columns for {len(df)} pairs") df.head() ``` -------------------------------- ### RSI Divergence Setup Source: https://github.com/deepentropy/tvscreener/blob/main/docs/examples/technical-analysis.md Screens for stocks where the RSI is in the neutral zone (40-60) but the price has moved significantly (over 3%%). Requires high volume. ```python ss = StockScreener() ss.where(StockField.RELATIVE_STRENGTH_INDEX_14.between(40, 60)) ss.where(StockField.CHANGE_PERCENT > 3) # Price up but RSI neutral ss.where(StockField.VOLUME >= 1_000_000) ss.select( StockField.NAME, StockField.PRICE, StockField.CHANGE_PERCENT, StockField.RELATIVE_STRENGTH_INDEX_14 ) df = ss.get() ``` -------------------------------- ### Basic Usage with Specific Fields Source: https://github.com/deepentropy/tvscreener/blob/main/docs/guide/styled-output.md Select specific stock fields and apply `beautify()` for formatted terminal output. This example shows price, change percentage, volume, and market capitalization. ```python from tvscreener import StockScreener, StockField, beautify ss = StockScreener() ss.select( StockField.NAME, StockField.PRICE, StockField.CHANGE_PERCENT, StockField.VOLUME, StockField.MARKET_CAPITALIZATION ) ss.set_range(0, 20) df = ss.get() beautify(df) ``` -------------------------------- ### Select All Stock Fields and Get Data Source: https://github.com/deepentropy/tvscreener/blob/main/docs/screeners/stock.md Initializes a StockScreener, sets the index to S&P 500, selects all available fields, sets a range of 0 to 500, and retrieves the data. ```python ss = StockScreener() ss.set_index(IndexSymbol.SP500) ss.select_all() ss.set_range(0, 500) df = ss.get() print(f"Columns: {len(df.columns)}") ``` -------------------------------- ### Basic Stream Usage Source: https://github.com/deepentropy/tvscreener/blob/main/docs/guide/streaming.md Use `stream()` to receive continuous updates as data changes. Set the desired fields and range before starting the stream. ```python from tvscreener import StockScreener, StockField ss = StockScreener() ss.select(StockField.NAME, StockField.PRICE, StockField.CHANGE_PERCENT) ss.set_range(0, 10) for df in ss.stream(interval=5): print(df[['name', 'close', 'change']]) ``` -------------------------------- ### Complex Filters Example Source: https://github.com/deepentropy/tvscreener/blob/main/docs/api/filters.md Demonstrates applying a variety of filters including index, price range, volume, valuation, sector, technical indicators, and performance metrics. ```python from tvscreener import StockScreener, StockField, IndexSymbol ss = StockScreener() # Index filter ss.set_index(IndexSymbol.SP500) # Price range ss.where(StockField.PRICE.between(20, 500)) # Volume filter ss.where(StockField.VOLUME >= 500_000) # Valuation filters ss.where(StockField.PE_RATIO_TTM.between(5, 25)) ss.where(StockField.PRICE_TO_BOOK_FY < 5) # Sector filter ss.where(StockField.SECTOR.not_in(['Finance', 'Utilities'])) # Technical filter ss.where(StockField.RELATIVE_STRENGTH_INDEX_14.between(30, 70)) # Performance filter ss.where(StockField.CHANGE_PERCENT > 0) df = ss.get() ``` -------------------------------- ### Screen for Momentum Stocks Source: https://github.com/deepentropy/tvscreener/blob/main/docs/screeners/stock.md Example screen to identify momentum stocks based on 3-month performance and RSI levels, sorted by 3-month performance. ```python ss = StockScreener() ss.set_index(IndexSymbol.SP500) ss.where(StockField.PERFORMANCE_3_MONTH > 20) ss.where(StockField.RELATIVE_STRENGTH_INDEX_14.between(50, 70)) ss.sort_by(StockField.PERFORMANCE_3_MONTH, ascending=False) df = ss.get() ``` -------------------------------- ### Oversold Bounce Setup Source: https://github.com/deepentropy/tvscreener/blob/main/docs/examples/technical-analysis.md Identifies stocks that are oversold on both RSI and Stochastic indicators but are showing signs of reversal with positive price change and sufficient volume. ```python ss = StockScreener() # Oversold conditions ss.where(StockField.RELATIVE_STRENGTH_INDEX_14 < 35) ss.where(StockField.STOCHASTIC_K_14_3_3 < 25) # But showing signs of reversal ss.where(StockField.CHANGE_PERCENT > 0) # Up today # With volume ss.where(StockField.VOLUME >= 500_000) ss.select( StockField.NAME, StockField.PRICE, StockField.CHANGE_PERCENT, StockField.RELATIVE_STRENGTH_INDEX_14, StockField.STOCHASTIC_K_14_3_3 ) df = ss.get() ``` -------------------------------- ### Common Sort Fields Examples Source: https://github.com/deepentropy/tvscreener/blob/main/docs/guide/sorting-pagination.md Demonstrates sorting by various common stock fields like market cap, change percentage, volume, P/E ratio, dividend yield, and RSI. ```python # By market cap (largest first) ss.sort_by(StockField.MARKET_CAPITALIZATION, ascending=False) # Top gainers ss.sort_by(StockField.CHANGE_PERCENT, ascending=False) # Most active (by volume) ss.sort_by(StockField.VOLUME, ascending=False) # Lowest P/E ss.sort_by(StockField.PE_RATIO_TTM, ascending=True) # Highest dividend yield ss.sort_by(StockField.DIVIDEND_YIELD_FY, ascending=False) # Most oversold (lowest RSI) ss.sort_by(StockField.RELATIVE_STRENGTH_INDEX_14, ascending=True) ``` -------------------------------- ### Configure Time Intervals for Technical Indicators Source: https://github.com/deepentropy/tvscreener/blob/main/docs/api/enums.md Example of using the with_interval method to set time intervals for technical indicators like RSI, MACD, and SMA. ```python # RSI on 1-hour timeframe rsi_1h = StockField.RELATIVE_STRENGTH_INDEX_14.with_interval('60') # MACD on 4-hour timeframe macd_4h = StockField.MACD_LEVEL_12_26.with_interval('240') # SMA on weekly timeframe sma_weekly = StockField.SIMPLE_MOVING_AVERAGE_50.with_interval('1W') ``` -------------------------------- ### Multi-Timeframe Analysis with Futures Screener Source: https://github.com/deepentropy/tvscreener/blob/main/docs/notebooks/05-bonds-futures.ipynb Perform multi-timeframe analysis by retrieving all data and filtering with pandas. This example shows how to set a condition on a 4-hour RSI and then further filter by price relative to a 50-period Simple Moving Average. ```python futs = FuturesScreener() # 4-hour RSI moderate rsi_4h = FuturesField.RELATIVE_STRENGTH_INDEX_14.with_interval('240') futs.where(rsi_4h.between(40, 60)) futs.select( FuturesField.NAME, FuturesField.PRICE, FuturesField.SIMPLE_MOVING_AVERAGE_50, FuturesField.RELATIVE_STRENGTH_INDEX_14, rsi_4h, FuturesField.CHANGE_PERCENT ) df = futs.get() # Filter for price above 50 SMA using pandas multi_tf = df[df['Price'] > df['SMA 50']] print(f"Found {len(multi_tf)} multi-timeframe setups") multi_tf.head(15) ``` -------------------------------- ### Stream Top Gainers Source: https://github.com/deepentropy/tvscreener/blob/main/docs/guide/streaming.md Stream the top 10 gainers every 5 seconds, filtering by volume and sorting by change percentage. This example demonstrates setting filters and sorting before initiating the stream. ```python ss = StockScreener() ss.where(StockField.VOLUME >= 1_000_000) ss.sort_by(StockField.CHANGE_PERCENT, ascending=False) ss.set_range(0, 10) ss.select( StockField.NAME, StockField.PRICE, StockField.CHANGE_PERCENT, StockField.VOLUME ) for df in ss.stream(interval=5): print("\n--- Update ---") print(df[['name', 'close', 'change', 'volume']]) ``` -------------------------------- ### Sort and Select Top Coins by Market Cap Source: https://github.com/deepentropy/tvscreener/blob/main/docs/notebooks/03-crypto.ipynb Utilize CoinScreener to retrieve the top coins sorted by market capitalization. This example demonstrates setting a range and selecting specific fields from CoinGecko data. ```python coins = CoinScreener() coins.sort_by(CoinField.MARKET_CAP, ascending=False) coins.set_range(0, 100) coins.select( CoinField.NAME, CoinField.CLOSE, CoinField.MARKET_CAP, CoinField.CHANGE ) df = coins.get() print(f"Top {len(df)} coins by market cap") df.head(15) ``` -------------------------------- ### ETF Screening Example with SymbolType Source: https://github.com/deepentropy/tvscreener/blob/main/docs/api/enums.md Example of screening for ETFs using the SymbolType enum and other filtering criteria. ```python ss = StockScreener() ss.set_symbol_types(SymbolType.ETF) ss.where(StockField.VOLUME > 1_000_000) ss.sort_by(StockField.VOLUME, ascending=False) df = ss.get() ``` -------------------------------- ### Complete Stock Screener Initialization Source: https://github.com/deepentropy/tvscreener/blob/main/docs/api/enums.md Imports all necessary components and initializes a StockScreener instance for comprehensive screening. ```python from tvscreener import ( StockScreener, StockField, IndexSymbol, Market, SymbolType, Exchange ) ss = StockScreener() ``` -------------------------------- ### Chained Method Calls for Stock Screener Source: https://github.com/deepentropy/tvscreener/blob/main/docs/api/screeners.md Demonstrates fluent syntax by chaining multiple configuration methods before executing the query. ```python df = ( StockScreener() .select(StockField.NAME, StockField.PRICE) .where(StockField.PRICE > 100) .sort_by(StockField.VOLUME, ascending=False) .set_range(0, 50) .get() ) ``` -------------------------------- ### Type Validation Example Source: https://github.com/deepentropy/tvscreener/blob/main/docs/api/filters.md Demonstrates type validation for filters, ensuring compatibility between field types and the screener type. ```APIDOC ## Type Validation Filters are validated against the screener type: ```python ss = StockScreener() # Valid - StockField with StockScreener ss.where(StockField.PRICE > 100) # Invalid - CryptoField with StockScreener # ss.where(CryptoField.PRICE > 100) # Raises error ``` ``` -------------------------------- ### Combine Stock Screener Presets Source: https://context7.com/deepentropy/tvscreener/llms.txt Demonstrates combining predefined field lists for stock screening and applying custom filters. Use field presets to quickly define screening criteria. ```python from tvscreener import StockScreener, STOCK_VALUATION_FIELDS, STOCK_DIVIDEND_FIELDS # Combine presets ss = StockScreener() ss.specific_fields = STOCK_VALUATION_FIELDS + STOCK_DIVIDEND_FIELDS ss.where(ss.specific_fields[1] > 1e9) # Use field from preset in filter df = ss.get() # Get preset by name valuation_fields = get_preset('stock_valuation') ss2 = StockScreener() ss2.specific_fields = valuation_fields ss2.where(STOCK_VALUATION_FIELDS[1] < 20) # P/E < 20 df2 = ss2.get() # Oscillator + moving average combo screener ss3 = StockScreener() ss3.specific_fields = STOCK_OSCILLATOR_FIELDS + STOCK_MOVING_AVERAGE_FIELDS df3 = ss3.get() print(df3.columns.tolist()) ``` -------------------------------- ### Retrieve Filtered Stock Data Source: https://github.com/deepentropy/tvscreener/blob/main/docs/api/enums.md Call `get()` on the screening object to retrieve the filtered stock data as a DataFrame. ```python df = ss.get() ``` -------------------------------- ### Pagination Source: https://github.com/deepentropy/tvscreener/blob/main/docs/guide/filtering.md Control the range of results fetched using `set_range(start, end)`. This is useful for retrieving specific pages of results. ```python ss = StockScreener() ss.set_range(0, 100) # First 100 results ss.set_range(100, 200) # Next 100 results ss.set_range(0, 1000) # First 1000 results ``` -------------------------------- ### Bond Screener: Get all yield fields Source: https://context7.com/deepentropy/tvscreener/llms.txt Retrieves bonds with specific yield-related fields. Ensure BOND_YIELD_FIELDS is correctly defined. ```python bs = BondScreener() bs.specific_fields = BOND_YIELD_FIELDS # NAME, COUPON, CURRENT_YIELD, YIELD_TO_MATURITY df = bs.get() print(df) ``` -------------------------------- ### Set Result Range Source: https://github.com/deepentropy/tvscreener/blob/main/docs/guide/filtering.md Limit the number of results returned to a specific range, for example, the top 500. This is useful for pagination or performance. ```python ss.set_range(0, 500) ``` -------------------------------- ### Default Field Selection Source: https://github.com/deepentropy/tvscreener/blob/main/docs/guide/selecting-fields.md If no fields are explicitly selected using `select()` or `select_all()`, a default set of fields is returned when `get()` is called. ```python ss = StockScreener() df = ss.get() print(df.columns.tolist()) ``` -------------------------------- ### Common Fields Reference Source: https://github.com/deepentropy/tvscreener/blob/main/docs/api/fields.md A reference guide to commonly used fields categorized under Price & Volume, Valuation, Dividends, and Technical indicators. ```APIDOC ## Common Fields Reference This section provides a quick reference for frequently used fields across different categories. ### Price & Volume | Field | Description | |---|---| | `PRICE` | Current price | | `OPEN` | Day's open | | `HIGH` | Day's high | | `LOW` | Day's low | | `CLOSE` | Previous close | | `VOLUME` | Trading volume | | `RELATIVE_VOLUME` | Volume vs average | ### Valuation | Field | Description | |---|---| | `PE_RATIO_TTM` | Price/Earnings (TTM) | | `PRICE_TO_BOOK_FY` | Price/Book | | `PRICE_TO_SALES_FY` | Price/Sales | | `EV_TO_EBITDA_TTM` | EV/EBITDA | | `PRICE_EARNINGS_TO_GROWTH_TTM` | PEG Ratio | | `MARKET_CAPITALIZATION` | Market Cap | ### Dividends | Field | Description | |---|---| | `DIVIDEND_YIELD_FY` | Dividend Yield % | | `DIVIDENDS_PER_SHARE_FY` | Dividend Per Share | | `PAYOUT_RATIO_TTM` | Payout Ratio % | | `EX_DIVIDEND_DATE` | Ex-Dividend Date | ### Technical | Field | Description | |---|---| | `RELATIVE_STRENGTH_INDEX_14` | RSI (14) | | `MACD_LEVEL_12_26` | MACD Line | | `MACD_SIGNAL_12_26` | MACD Signal | | `SIMPLE_MOVING_AVERAGE_50` | SMA 50 | | `SIMPLE_MOVING_AVERAGE_200` | SMA 200 | | `EXPONENTIAL_MOVING_AVERAGE_20` | EMA 20 | | `AVERAGE_TRUE_RANGE_14` | ATR (14) | | `AVERAGE_DIRECTIONAL_INDEX_14` | ADX (14) | | `STOCHASTIC_K_14_3_3` | Stochastic %K | | `STOCHASTIC_D_14_3_3` | Stochastic %D | | `BOLLINGER_UPPER_BAND_20` | BB Upper | | `BOLLINGER_LOWER_BAND_20` | BB Lower | ``` -------------------------------- ### Real-time Streaming Monitor for Top Movers Source: https://github.com/deepentropy/tvscreener/blob/main/docs/examples/crypto-strategies.md Set up a real-time streaming monitor to continuously track and display the top 20 large-cap movers based on market capitalization and daily percentage change. The stream updates at a specified interval. ```python cs = CryptoScreener() cs.where(CryptoField.MARKET_CAPITALIZATION > 1e9) cs.sort_by(CryptoField.CHANGE_PERCENT, ascending=False) cs.set_range(0, 20) cs.select( CryptoField.NAME, CryptoField.PRICE, CryptoField.CHANGE_PERCENT, CryptoField.VOLUME ) for df in cs.stream(interval=10): print("\n=== Top 20 Large Cap Movers ===") print(df) ``` -------------------------------- ### Combine Sort and Pagination Source: https://github.com/deepentropy/tvscreener/blob/main/docs/guide/sorting-pagination.md Demonstrates how to combine sorting and pagination to retrieve a specific, ordered subset of stock data, such as the top 100 stocks by market cap. ```python ss = StockScreener() ss.sort_by(StockField.MARKET_CAPITALIZATION, ascending=False) ss.set_range(0, 100) df = ss.get() ``` -------------------------------- ### Screener.set_range(): Pagination control Source: https://context7.com/deepentropy/tvscreener/llms.txt Controls which rows are returned by specifying a start and end index, enabling pagination. Default range is 0 to 150. ```python from tvscreener import StockScreener, StockField # Page 1: rows 0–49 ss = StockScreener() ss.set_range(0, 50) df_page1 = ss.get() # Page 2: rows 50–99 ss2 = StockScreener() ss2.set_range(50, 100) df_page2 = ss2.get() # Get up to 500 results ss3 = StockScreener() ss3.where(StockField.MARKET_CAPITALIZATION > 1e9) ss3.set_range(0, 500) df = ss3.get() print(f"Rows returned: {len(df)}") ``` -------------------------------- ### Basic Bond Screening Source: https://github.com/deepentropy/tvscreener/blob/main/docs/notebooks/05-bonds-futures.ipynb Initializes BondScreener and retrieves all available bonds with their default fields. Useful for a general overview. ```python bs = BondScreener() df = bs.get() print(f"Retrieved {len(df)} bonds with {len(df.columns)} columns") df.head(10) ``` -------------------------------- ### Text Search Source: https://github.com/deepentropy/tvscreener/blob/main/docs/guide/filtering.md Perform a text search across stock names and descriptions using the `search` method. The `get()` method retrieves the results. ```python ss = StockScreener() ss.search('semiconductor') df = ss.get() ``` -------------------------------- ### Basic Screeners in Python Source: https://github.com/deepentropy/tvscreener/blob/main/README.md Initialize and fetch data from various screeners including Stock, Forex, Crypto, Bond, Futures, and Coin screeners. Each screener returns a pandas DataFrame. ```python import tvscreener as tvs # Stock Screener ss = tvs.StockScreener() df = ss.get() # returns a dataframe with 150 rows by default # Forex Screener fs = tvs.ForexScreener() df = fs.get() # Crypto Screener cs = tvs.CryptoScreener() df = cs.get() # Bond Screener (NEW) bs = tvs.BondScreener() df = bs.get() # Futures Screener (NEW) futs = tvs.FuturesScreener() df = futs.get() # Coin Screener (NEW) - CEX and DEX coins coins = tvs.CoinScreener() df = coins.get() ``` -------------------------------- ### Filter Stocks with Pythonic Comparison Operators Source: https://github.com/deepentropy/tvscreener/blob/main/docs/notebooks/01-quickstart.ipynb Demonstrates filtering stocks using direct Python comparison operators on fields like price, volume, and P/E ratio. Also shows how to use the `between` method for range filtering. ```python from tvscreener import StockField ss = StockScreener() # Filter with comparison operators ss.where(StockField.PRICE > 50) ss.where(StockField.PRICE < 500) ss.where(StockField.VOLUME >= 1_000_000) # Range filter ss.where(StockField.PE_RATIO_TTM.between(10, 30)) df = ss.get() print(f"Found {len(df)} stocks matching criteria") df.head() ``` -------------------------------- ### Multi-Timeframe RSI Analysis Source: https://github.com/deepentropy/tvscreener/blob/main/docs/screeners/crypto.md Perform screening using RSI across multiple timeframes. This example checks daily and 4-hour RSI values simultaneously. ```python cs = CryptoScreener() # Daily RSI oversold cs.where(CryptoField.RELATIVE_STRENGTH_INDEX_14 < 35) # 4-hour RSI also oversold rsi_4h = CryptoField.RELATIVE_STRENGTH_INDEX_14.with_interval('240') cs.where(rsi_4h < 30) cs.select( CryptoField.NAME, CryptoField.PRICE, CryptoField.RELATIVE_STRENGTH_INDEX_14, rsi_4h ) df = cs.get() ``` -------------------------------- ### Select All Stock Fields and Limit Results Source: https://github.com/deepentropy/tvscreener/blob/main/docs/notebooks/01-quickstart.ipynb Demonstrates how to retrieve all available fields for stocks and limit the number of results for a concise overview. Useful for exploring the full dataset. ```python ss = StockScreener() ss.select_all() ss.set_range(0, 10) # Limit results for demo df = ss.get() print(f"Retrieved {len(df.columns)} columns for {len(df)} stocks") df.head() ``` -------------------------------- ### Type Validation Example Source: https://github.com/deepentropy/tvscreener/blob/main/docs/api/filters.md Filters are validated against the screener type. Using a field from a different screener type (e.g., CryptoField with StockScreener) will raise an error. ```python ss = StockScreener() # Valid - StockField with StockScreener ss.where(StockField.PRICE > 100) # Invalid - CryptoField with StockScreener # ss.where(CryptoField.PRICE > 100) # Raises error ``` -------------------------------- ### Basic Stock Screening Source: https://github.com/deepentropy/tvscreener/blob/main/docs/getting-started/quickstart.md Create a StockScreener instance and retrieve a default DataFrame of stocks. ```python import tvscreener as tvs # Create a screener and get data ss = tvs.StockScreener() df = ss.get() # Returns pandas DataFrame with 150 stocks ``` -------------------------------- ### Chaining Multiple Filters Source: https://github.com/deepentropy/tvscreener/blob/main/docs/guide/filtering.md Combine various filters using the `where` method; all filters are implicitly combined with AND logic. The `get()` method retrieves the filtered data. ```python ss = StockScreener() ss.where(StockField.PRICE > 10) # AND ss.where(StockField.PRICE < 100) # AND ss.where(StockField.VOLUME >= 1_000_000) # AND ss.where(StockField.MARKET_CAPITALIZATION.between(1e9, 50e9)) # AND ss.where(StockField.PE_RATIO_TTM.between(5, 25)) df = ss.get() ``` -------------------------------- ### Using Field Presets Source: https://github.com/deepentropy/tvscreener/blob/main/README.md Leverage predefined field presets for common analysis tasks. Use `list_presets()` to see available options and `get_preset()` to retrieve a specific set of fields. Presets can be directly assigned to `specific_fields`. ```python from tvscreener import ( StockScreener, get_preset, list_presets, STOCK_PRICE_FIELDS, STOCK_VALUATION_FIELDS, STOCK_DIVIDEND_FIELDS, STOCK_PERFORMANCE_FIELDS, STOCK_OSCILLATOR_FIELDS ) # See all available presets print(list_presets()) # ['stock_price', 'stock_volume', 'stock_valuation', 'stock_dividend', ...] # Use presets directly ss = StockScreener() ss.specific_fields = STOCK_VALUATION_FIELDS + STOCK_DIVIDEND_FIELDS df = ss.get() # Or get preset by name fields = get_preset('stock_performance') ``` -------------------------------- ### Basic StockScreener Usage Source: https://context7.com/deepentropy/tvscreener/llms.txt Fetch the top 150 US stocks by market capitalization. Requires importing `StockScreener` and `StockField`. ```python from tvscreener import StockScreener, StockField, Market, SymbolType, IndexSymbol # Basic usage — returns top 150 US stocks by market cap ss = StockScreener() df = ss.get() print(df[["Symbol", "Name", "Price", "Market Capitalization"]].head()) ``` -------------------------------- ### ScreenerDataFrame Source: https://context7.com/deepentropy/tvscreener/llms.txt An extended Pandas DataFrame subclass returned by the `get()` method. It includes a 'Symbol' column and allows switching between human-readable labels and raw technical field names. ```APIDOC ## ScreenerDataFrame ### Description An extended Pandas DataFrame subclass that enhances standard DataFrames with TradingView-specific functionalities. It ensures a 'Symbol' column is always present and reorders identity columns. It also stores original column mappings and provides a method to switch between human-readable labels and raw technical field names. ### Methods * **set_technical_columns(only=False)**: Switches the column names to use raw technical field names. If `only=True`, only technical columns are switched. Stores original column mappings in `df.attrs['original_columns']`. ``` -------------------------------- ### RSI on Different Timeframes Source: https://github.com/deepentropy/tvscreener/blob/main/docs/guide/time-intervals.md Demonstrates how to fetch data for RSI on daily, 1-hour, and 4-hour intervals, applying different thresholds for each. This allows for a comprehensive view of momentum across multiple timeframes. ```python ss = StockScreener() # Default daily RSI ss.where(StockField.RELATIVE_STRENGTH_INDEX_14 < 40) # 1-hour RSI rsi_1h = StockField.RELATIVE_STRENGTH_INDEX_14.with_interval('60') ss.where(rsi_1h < 30) # 4-hour RSI rsi_4h = StockField.RELATIVE_STRENGTH_INDEX_14.with_interval('240') ss.where(rsi_4h < 35) df = ss.get() ``` -------------------------------- ### Query Specific Bonds by Symbol Source: https://github.com/deepentropy/tvscreener/blob/main/docs/screeners/bond.md Query specific bonds using their ticker symbols. This example selects US 10-Year, US 2-Year, and US 30-Year Treasury yields. ```python bs = BondScreener() bs.symbols = { "query": {"types": []}, "tickers": ["TVC:US10Y", "TVC:US02Y", "TVC:US30Y"] } bs.select_all() df = bs.get() ``` -------------------------------- ### Upgrade tvscreener Source: https://github.com/deepentropy/tvscreener/blob/main/docs/getting-started/installation.md Use pip to upgrade to the latest version of tvscreener. ```bash pip install --upgrade tvscreener ``` -------------------------------- ### Fluent API for Stock Screener Source: https://github.com/deepentropy/tvscreener/blob/main/README.md Chain select() and where() methods on the StockScreener instance for a more readable and concise way to build screener queries. Requires importing StockScreener and StockField. ```python # Chain methods for cleaner code ss = StockScreener() ss.select(StockField.NAME, StockField.PRICE, StockField.CHANGE_PERCENT) ss.where(StockField.PRICE > 100) df = ss.get() ``` -------------------------------- ### Price Alert Monitoring Source: https://github.com/deepentropy/tvscreener/blob/main/docs/guide/streaming.md Monitor specific stock symbols for price changes and trigger an alert when a target price is reached. This example sets a custom list of tickers and target prices. ```python ss = StockScreener() ss.symbols = { "query": {"types": []}, "tickers": ["NASDAQ:AAPL", "NASDAQ:MSFT", "NASDAQ:GOOGL"] } ss.select(StockField.NAME, StockField.PRICE, StockField.CHANGE_PERCENT) target_price = {"AAPL": 200, "MSFT": 450, "GOOGL": 180} for df in ss.stream(interval=10): for _, row in df.iterrows(): symbol = row['name'] price = row['close'] if symbol in target_price and price >= target_price[symbol]: print(f"ALERT: {symbol} reached ${price:.2f}!") ``` -------------------------------- ### Selecting Interval Fields in Output Source: https://github.com/deepentropy/tvscreener/blob/main/docs/guide/time-intervals.md Demonstrates how to include technical indicators from different timeframes (daily, hourly, 4-hour) in the output selection. This allows you to retrieve and analyze data across multiple intervals in a single request. ```python ss = StockScreener() rsi_1h = StockField.RELATIVE_STRENGTH_INDEX_14.with_interval('60') rsi_4h = StockField.RELATIVE_STRENGTH_INDEX_14.with_interval('240') ss.select( StockField.NAME, StockField.PRICE, StockField.RELATIVE_STRENGTH_INDEX_14, # Daily (default) rsi_1h, # Hourly rsi_4h # 4-hour ) df = ss.get() ``` -------------------------------- ### Using Field Presets in Stock Screener Source: https://github.com/deepentropy/tvscreener/blob/main/README.md Combine predefined field groups like STOCK_VALUATION_FIELDS and STOCK_DIVIDEND_FIELDS to easily select multiple relevant fields for your screener. Requires importing StockScreener and the specific field preset constants. ```python from tvscreener import StockScreener, STOCK_VALUATION_FIELDS, STOCK_DIVIDEND_FIELDS ss = StockScreener() ss.specific_fields = STOCK_VALUATION_FIELDS + STOCK_DIVIDEND_FIELDS ```