### Install tradingview-ta using pip Source: https://github.com/analyzerrest/python-tradingview-ta/blob/main/docs/overview.md Installs the tradingview-ta package using pip. Requires Python 3.6 or newer and internet access. ```console pip install tradingview-ta ``` -------------------------------- ### Install TradingView TA Python Library Source: https://context7.com/analyzerrest/python-tradingview-ta/llms.txt Instructions for installing the tradingview_ta Python library from PyPI for stable releases or directly from GitHub for the latest version. Includes commands for initial installation and upgrading. ```bash pip install tradingview_ta pip install git+https://github.com/analyzerrest/python-tradingview-ta.git pip install -U tradingview_ta ``` -------------------------------- ### Install tradingview-ta using pip Source: https://github.com/analyzerrest/python-tradingview-ta/blob/main/README.md Installs the stable version of the tradingview-ta library from PyPI. This is the recommended installation method for general use. ```bash pip install tradingview_ta ``` -------------------------------- ### Simple Trading Bot Example with TradingView TA (Python) Source: https://context7.com/analyzerrest/python-tradingview-ta/llms.txt A basic example of an automated trading bot that uses TradingView TA recommendations to make trading decisions. It continuously fetches analysis, checks the recommendation, and simulates buy/sell orders. This requires the 'tradingview_ta' library and 'time' module. It's a simplified example and needs integration with an actual exchange API for real trading. ```python from tradingview_ta import TA_Handler, Interval import time # Initialize handler handler = TA_Handler( symbol="BTCUSDT", exchange="BINANCE", screener="crypto", interval=Interval.INTERVAL_1_HOUR ) last_order = "sell" while True: try: analysis = handler.get_analysis() recommendation = analysis.summary["RECOMMENDATION"] print(f"Current recommendation: {recommendation}") print(f"Buy signals: {analysis.summary['BUY']}") print(f"Sell signals: {analysis.summary['SELL']}") if recommendation in ["BUY", "STRONG_BUY"] and last_order == "sell": # Execute buy order via exchange API print("Signal: BUY") last_order = "buy" elif recommendation in ["SELL", "STRONG_SELL"] and last_order == "buy": # Execute sell order via exchange API print("Signal: SELL") last_order = "sell" except Exception as e: print(f"Error: {e}") # Wait interval before next check (match your interval setting) time.sleep(3600) # 1 hour for INTERVAL_1_HOUR ``` -------------------------------- ### Install latest tradingview-ta from GitHub Source: https://github.com/analyzerrest/python-tradingview-ta/blob/main/README.md Installs the latest development version of the tradingview-ta library directly from its GitHub repository. Use this for access to the newest features and bug fixes. ```bash pip install git+https://github.com/analyzerrest/python-tradingview-ta.git ``` -------------------------------- ### Get TradingView TA Library Version (Python) Source: https://context7.com/analyzerrest/python-tradingview-ta/llms.txt Retrieves the currently installed version of the tradingview_ta Python library. This is useful for debugging and ensuring compatibility. It requires the 'tradingview_ta' library to be installed. ```python import tradingview_ta print(tradingview_ta.__version__) # Output: 3.3.0 ``` -------------------------------- ### Get Technical Analysis Summary for TSLA Source: https://github.com/analyzerrest/python-tradingview-ta/blob/main/docs/overview.md Fetches the technical analysis summary for the TSLA stock on NASDAQ for daily intervals using the TA_Handler class. Outputs a dictionary containing recommendation and counts for buy, neutral, and sell signals. Requires the tradingview-ta package. ```python3 from tradingview_ta import TA_Handler, Interval, Exchange tesla = TA_Handler( symbol="TSLA", screener="america", exchange="NASDAQ", interval=Interval.INTERVAL_1_DAY ) print(tesla.get_analysis().summary) # Example output: {"RECOMMENDATION": "BUY", "BUY": 8, "NEUTRAL": 6, "SELL": 3} ``` -------------------------------- ### Initialize TA_Handler and Get Analysis (Python) Source: https://context7.com/analyzerrest/python-tradingview-ta/llms.txt Demonstrates how to initialize the TA_Handler class to fetch technical analysis for a single stock symbol. Shows how to access the summary, oscillators, moving averages, and raw indicator values. ```python from tradingview_ta import TA_Handler, Interval, Exchange # Create handler for Tesla stock tesla = TA_Handler( symbol="TSLA", screener="america", exchange="NASDAQ", interval=Interval.INTERVAL_1_DAY, timeout=10 # Optional: timeout in seconds ) # Get complete analysis analysis = tesla.get_analysis() # Access analysis results print(analysis.summary) # Output: {'RECOMMENDATION': 'BUY', 'BUY': 12, 'SELL': 7, 'NEUTRAL': 9} print(analysis.oscillators) # Output: {'RECOMMENDATION': 'BUY', 'BUY': 2, 'SELL': 1, 'NEUTRAL': 8, 'COMPUTE': {'RSI': 'NEUTRAL', 'STOCH.K': 'NEUTRAL', ...}} print(analysis.moving_averages) # Output: {'RECOMMENDATION': 'BUY', 'BUY': 9, 'SELL': 5, 'NEUTRAL': 1, 'COMPUTE': {'EMA10': 'SELL', 'SMA10': 'SELL', ...}} # Access raw indicator values print(analysis.indicators["RSI"]) print(analysis.indicators["close"]) print(analysis.indicators["volume"]) ``` -------------------------------- ### Define Time Intervals for TA_Handler (Python) Source: https://context7.com/analyzerrest/python-tradingview-ta/llms.txt Illustrates the use of the Interval class to specify various time intervals for technical analysis. Shows example initializations of TA_Handler with different intervals for crypto and stocks. ```python from tradingview_ta import Interval # Available intervals # Interval.INTERVAL_1_MINUTE # "1m" # Interval.INTERVAL_5_MINUTES # "5m" # Interval.INTERVAL_15_MINUTES # "15m" # Interval.INTERVAL_30_MINUTES # "30m" # Interval.INTERVAL_1_HOUR # "1h" # Interval.INTERVAL_2_HOURS # "2h" # Interval.INTERVAL_4_HOURS # "4h" # Interval.INTERVAL_1_DAY # "1d" (default) # Interval.INTERVAL_1_WEEK # "1W" # Interval.INTERVAL_1_MONTH # "1M" # Example usage with different intervals handler_hourly = TA_Handler( symbol="BTCUSDT", screener="crypto", exchange="BINANCE", interval=Interval.INTERVAL_1_HOUR ) handler_weekly = TA_Handler( symbol="AAPL", screener="america", exchange="NASDAQ", interval=Interval.INTERVAL_1_WEEK ) ``` -------------------------------- ### Use Exchange Constants for Forex and CFD (Python) Source: https://context7.com/analyzerrest/python-tradingview-ta/llms.txt Demonstrates how to use the Exchange class constants to specify forex and CFD markets when initializing TA_Handler. Includes examples for EURUSD and GOLD. ```python from tradingview_ta import TA_Handler, Interval, Exchange # Forex example forex_handler = TA_Handler( symbol="EURUSD", screener="forex", exchange=Exchange.FOREX, # "FX_IDC" interval=Interval.INTERVAL_4_HOURS ) print(forex_handler.get_analysis().summary) # CFD example cfd_handler = TA_Handler( symbol="GOLD", screener="cfd", exchange=Exchange.CFD, # "TVC" interval=Interval.INTERVAL_1_DAY ) print(cfd_handler.get_analysis().summary) ``` -------------------------------- ### Get Multiple Cryptocurrency Analyses with Indicators Source: https://context7.com/analyzerrest/python-tradingview-ta/llms.txt Fetches technical analysis for multiple cryptocurrency symbols, including additional custom indicators like RSI and MACD. Requires specifying the screener, interval, and a list of symbols. ```python from tradingview_ta import get_multiple_analysis, Interval crypto_analyses = get_multiple_analysis( screener="crypto", interval=Interval.INTERVAL_1_DAY, symbols=["BINANCE:BTCUSDT", "BINANCE:ETHUSDT", "BINANCE:SOLUSDT"], additional_indicators=["RSI", "MACD.macd", "MACD.signal"] ) ``` -------------------------------- ### Import TradingView TA Library Source: https://github.com/analyzerrest/python-tradingview-ta/blob/main/docs/usage.md Imports necessary classes and modules from the tradingview_ta library. Ensure the library is installed or updated to the latest version. ```python from tradingview_ta import TA_Handler, Interval, Exchange import tradingview_ta ``` -------------------------------- ### Check TradingView TA Library Version Source: https://github.com/analyzerrest/python-tradingview-ta/blob/main/docs/usage.md Retrieves the installed version of the tradingview_ta library using the __version__ attribute. This feature is available from version 3.1.3 onwards. ```python print(tradingview_ta.__version__) # Example output: 3.1.3 ``` -------------------------------- ### Get Raw Indicator Values with TA_Handler Source: https://context7.com/analyzerrest/python-tradingview-ta/llms.txt Retrieves raw indicator values for a given symbol, exchange, screener, and interval without performing a full analysis. Supports fetching a default set or a custom list of indicators. ```python from tradingview_ta import TA_Handler, Interval handler = TA_Handler( symbol="BTCUSDT", screener="crypto", exchange="BINANCE", interval=Interval.INTERVAL_1_DAY ) # Get default indicators all_indicators = handler.get_indicators() print(f"RSI: {all_indicators['RSI']}") print(f"MACD: {all_indicators['MACD.macd']}") print(f"Close: {all_indicators['close']}") # Get specific indicators only specific_indicators = handler.get_indicators(["RSI", "close", "volume", "MACD.macd"]) print(specific_indicators) # Output: {'RSI': 55.23, 'close': 45326.97, 'volume': 32744.42, 'MACD.macd': 2444.73} ``` -------------------------------- ### Get Multiple Analysis Source: https://github.com/analyzerrest/python-tradingview-ta/blob/main/docs/usage.md Fetches technical analysis data for multiple symbols across a specified screener and interval. Note that you cannot mix different screeners and intervals in a single request. ```APIDOC ## GET /analyzerrest/python-tradingview-ta/get_multiple_analysis ### Description Fetches technical analysis data for multiple symbols. Ensure all symbols belong to the same screener and interval. ### Method GET ### Endpoint /analyzerrest/python-tradingview-ta/get_multiple_analysis ### Parameters #### Query Parameters - **symbols** (list) - Required - List of exchange and ticker symbols separated by a colon. Example: ["NASDAQ:TSLA", "NYSE:DOCN"] - **screener** (str) - Required - Screener type (e.g., "america", "indonesia", "forex", "crypto"). - **interval** (str) - Required - Time frame. Use constants from the Interval class (e.g., Interval.INTERVAL_1_DAY). - **timeout** (float) - Optional - How long to wait (in seconds) for the server to return a response. - **additional_indicators** (list) - Optional - List of additional indicators to retrieve. Example: ["RSI", "Mom"]. ### Request Example ```python from tradingview_ta import TA_Handler, Interval analysis = TA_Handler.get_multiple_analysis( symbols=["NASDAQ:TSLA", "NYSE:DOCN"], screener="america", interval=Interval.INTERVAL_1_DAY ) print(analysis) ``` ### Response #### Success Response (200) - **dict** - A dictionary where keys are the symbols (e.g., "NASDAQ:TSLA") and values are either an `Analysis` object or `None` if no analysis is found for that symbol. #### Response Example ```json { "NASDAQ:TSLA": {"RECOMMENDATION": "BUY", "BUY": 8, "NEUTRAL": 6, "SELL": 3}, "NYSE:DOCN": {"RECOMMENDATION": "SELL", "BUY": 2, "NEUTRAL": 5, "SELL": 9} } ``` #### Error Response (e.g., 400) - **dict** - Error message detailing the issue. ```json { "error": "Invalid screener or interval combination." } ``` ``` -------------------------------- ### Get Multiple TradingView Analysis Data Source: https://github.com/analyzerrest/python-tradingview-ta/blob/main/docs/usage.md Fetches technical analysis data for multiple symbols from TradingView. Requires specifying the screener, interval, and a list of symbols. The result is a dictionary where keys are symbols and values are Analysis objects. ```python from tradingview_ta import * analysis = get_multiple_analysis(screener="america", interval=Interval.INTERVAL_1_HOUR, symbols=["nasdaq:tsla", "nyse:docn", "nasdaq:aapl"]) ``` -------------------------------- ### Configure Proxy for Analysis Requests Source: https://context7.com/analyzerrest/python-tradingview-ta/llms.txt Shows how to configure proxy settings for both single and multiple analysis requests. Proxies can be specified as a dictionary with 'http' and 'https' keys. ```python from tradingview_ta import TA_Handler, Interval, get_multiple_analysis # Single analysis with proxy handler = TA_Handler( symbol="TSLA", screener="america", exchange="NASDAQ", interval=Interval.INTERVAL_1_DAY, proxies={'http': 'http://proxy.example.com:8080', 'https': 'https://proxy.example.com:443'} ) print(handler.get_analysis().summary) # Multiple analysis with proxy analyses = get_multiple_analysis( screener="crypto", interval=Interval.INTERVAL_1_HOUR, symbols=["BINANCE:BTCUSDT", "BINANCE:ETHUSDT"], proxies={'http': 'http://proxy.example.com:8080'} ) ``` -------------------------------- ### Create a Trading Bot with Python TradingView TA Source: https://github.com/analyzerrest/python-tradingview-ta/blob/main/docs/faq.md This Python code snippet demonstrates how to create a basic trading bot using the TradingView TA library. It continuously fetches analysis recommendations and simulates buy/sell orders based on predefined logic. Ensure you replace placeholder comments with your actual exchange API calls for order execution. The `last_order` variable is not persistent across program restarts. ```python # Import packages. from tradingview_ta import TA_Handler, Interval, Exchange import time # Store the last order. last_order = "sell" # Instantiate TA_Handler. handler = TA_Handler( symbol="SYMBOL", exchange="EXCHANGE", screener="SCREENER", interval="INTERVAL", ) # Repeat forever. while True: # Retrieve recommendation. rec = handler.get_analysis()["RECOMMENDATION"] # Create a buy order if the recommendation is "BUY" or "STRONG_BUY" and the last order is "sell". # Create a sell order if the recommendation is "SELL" or "STRONG_SELL" and the last order is "buy". if "BUY" in rec and last_order == "sell": # REPLACE COMMENT: Create a buy order using your exchange's API. last_order = "buy" elif "SELL" in rec and last_order == "buy": # REPLACE COMMENT: Create a sell order using your exchange's API. last_order = "sell" # Wait for x seconds before retrieving new analysis. # The time should be the same as the interval. time.sleep(x) ``` -------------------------------- ### TA_Handler Instantiation and Parameters Source: https://github.com/analyzerrest/python-tradingview-ta/blob/main/docs/usage.md Demonstrates how to instantiate the TA_Handler class and explains its various parameters for configuring symbol, exchange, screener, interval, and timeout. ```APIDOC ## POST /analyzerrest/python-tradingview-ta ### Description Instantiate the TA_Handler to configure and retrieve financial analysis data from TradingView. ### Method POST ### Endpoint /analyzerrest/python-tradingview-ta ### Parameters #### Request Body - **symbol** (str) - Required - Ticker symbol (e.g., "AAPL", "TLKM", "USDEUR", "BTCUSDT"). - **exchange** (str) - Required - Exchange (e.g., "nasdaq", "idx", "forex", "binance"). Use `Exchange` enum for predefined values. - **screener** (str) - Required - Screener (e.g., "america", "indonesia", "forex", "crypto"). - For stocks, use the exchange's country. - For cryptocurrency, use "crypto". - For forex, use "forex". - **interval** (str) - Required - Time frame. Use `Interval` enum for available intervals (e.g., "1m", "5m", "1h", "1d", "1W", "1M"). - **timeout** (float) - Optional - How long to wait (in seconds) for the server to return a response. ### Request Example ```json { "symbol": "AAPL", "exchange": "nasdaq", "screener": "america", "interval": "1d", "timeout": 10 } ``` ### Response #### Success Response (200) - **analysis** (object) - Contains the technical analysis data. #### Response Example ```json { "analysis": { "summary": { "RECOMMENDATION": "BUY", "BUY": 10, "SELL": 5, "NEUTRAL": 11 }, "oscillators": { "RECOMMENDATION": "SELL", "BUY": 2, "SELL": 9, "NEUTRAL": 5 }, "moving_averages": { "RECOMMENDATION": "STRONG_BUY", "BUY": 16, "SELL": 0, "NEUTRAL": 0 } } } ``` ``` -------------------------------- ### Configure Screener Types with TradingView TA Methods (Python) Source: https://context7.com/analyzerrest/python-tradingview-ta/llms.txt Demonstrates how to configure different screener types (stocks, cryptocurrency, forex, CFD) using explicit methods on a TA_Handler object. This allows for precise control over the data source for technical analysis. It requires the 'tradingview_ta' library. ```python from tradingview_ta import TA_Handler, Interval # Create handler and configure using methods handler = TA_Handler() # For stocks - set country as screener handler.set_screener_as_stock("america") handler.set_exchange_as_crypto_or_stock("NASDAQ") handler.set_symbol_as("AAPL") handler.set_interval_as(Interval.INTERVAL_1_DAY) print(handler.get_analysis().summary) # For cryptocurrency crypto_handler = TA_Handler() crypto_handler.set_screener_as_crypto() crypto_handler.set_exchange_as_crypto_or_stock("BINANCE") crypto_handler.set_symbol_as("BTCUSDT") crypto_handler.set_interval_as(Interval.INTERVAL_4_HOURS) print(crypto_handler.get_analysis().summary) # For forex forex_handler = TA_Handler() forex_handler.set_screener_as_forex() forex_handler.set_exchange_as_forex() forex_handler.set_symbol_as("EURUSD") forex_handler.set_interval_as(Interval.INTERVAL_1_HOUR) print(forex_handler.get_analysis().summary) # For CFD cfd_handler = TA_Handler() cfd_handler.set_screener_as_cfd() cfd_handler.set_exchange_as_cfd() cfd_handler.set_symbol_as("GOLD") cfd_handler.set_interval_as(Interval.INTERVAL_1_DAY) print(cfd_handler.get_analysis().summary) ``` -------------------------------- ### Proxy Configuration Source: https://context7.com/analyzerrest/python-tradingview-ta/llms.txt Use proxies for requests with both single and multiple analysis functions. ```APIDOC ## Proxy Configuration ### Description Configure proxy settings to route requests through a proxy server when performing financial market analysis. ### Method Proxies are configured by passing a `proxies` dictionary to the `TA_Handler` constructor or the `get_multiple_analysis` function. ### Parameters #### Request Body - **proxies** (dict) - Required - A dictionary where keys are protocol names ('http', 'https') and values are proxy URLs (e.g., 'http://proxy.example.com:8080'). ### Request Example ```python from tradingview_ta import TA_Handler, Interval, get_multiple_analysis # Single analysis with proxy handler = TA_Handler( symbol="TSLA", screener="america", exchange="NASDAQ", interval=Interval.INTERVAL_1_DAY, proxies={'http': 'http://proxy.example.com:8080', 'https': 'https://proxy.example.com:443'} ) print(handler.get_analysis().summary) # Multiple analysis with proxy analyses = get_multiple_analysis( screener="crypto", interval=Interval.INTERVAL_1_HOUR, symbols=["BINANCE:BTCUSDT", "BINANCE:ETHUSDT"], proxies={'http': 'http://proxy.example.com:8080'} ) ``` ### Response This feature configures the underlying HTTP client to use the specified proxies. The response structure depends on the analysis function being called (e.g., `get_analysis()` or `get_multiple_analysis()`). ### Response Example (The response will be the result of the analysis function, e.g., the `Analysis` object or a dictionary of analyses, with requests routed through the configured proxy.) ``` -------------------------------- ### Fetch Multiple Symbol Analysis (Python) Source: https://context7.com/analyzerrest/python-tradingview-ta/llms.txt Shows how to use the get_multiple_analysis function to retrieve technical analysis data for several symbols in a single request. Explains how to access individual results and iterate through the returned dictionary. ```python from tradingview_ta import get_multiple_analysis, Interval # Fetch analysis for multiple US stocks analyses = get_multiple_analysis( screener="america", interval=Interval.INTERVAL_1_HOUR, symbols=["NASDAQ:TSLA", "NYSE:DOCN", "NASDAQ:AAPL"] ) # Access individual analysis (use UPPERCASE) tesla_analysis = analyses["NASDAQ:TSLA"] print(f"Tesla: {tesla_analysis.summary['RECOMMENDATION']}") apple_analysis = analyses["NASDAQ:AAPL"] print(f"Apple: {apple_analysis.summary['RECOMMENDATION']}") # Iterate through all results for symbol, analysis in analyses.items(): if analysis is not None: print(f"{symbol}: {analysis.summary['RECOMMENDATION']}") else: print(f"{symbol}: No analysis available") ``` -------------------------------- ### get_indicators Method Source: https://context7.com/analyzerrest/python-tradingview-ta/llms.txt Retrieve raw indicator values without computed analysis. Supports custom indicator lists. ```APIDOC ## get_indicators Method ### Description Retrieve raw indicator values without computed analysis. Supports custom indicator lists. ### Method `handler.get_indicators(indicators: Optional[List[str]] = None)` ### Parameters #### Query Parameters - **indicators** (List[str]) - Optional - A list of specific indicator names to retrieve. If not provided, all default indicators are returned. ### Request Example ```python from tradingview_ta import TA_Handler, Interval handler = TA_Handler( symbol="BTCUSDT", screener="crypto", exchange="BINANCE", interval=Interval.INTERVAL_1_DAY ) # Get default indicators all_indicators = handler.get_indicators() print(f"RSI: {all_indicators['RSI']}") print(f"MACD: {all_indicators['MACD.macd']}") print(f"Close: {all_indicators['close']}") # Get specific indicators only specific_indicators = handler.get_indicators(["RSI", "close", "volume", "MACD.macd"]) print(specific_indicators) ``` ### Response #### Success Response (200) - **indicator_name** (float) - The raw value of the requested indicator. #### Response Example ```json { "RSI": 55.23, "close": 45326.97, "volume": 32744.42, "MACD.macd": 2444.73 } ``` ``` -------------------------------- ### add_indicators Method Source: https://context7.com/analyzerrest/python-tradingview-ta/llms.txt Add custom indicators to the handler's indicator list for retrieval. ```APIDOC ## add_indicators Method ### Description Add custom indicators to the handler's indicator list for retrieval. ### Method `handler.add_indicators(indicators: List[str])` ### Parameters #### Request Body - **indicators** (List[str]) - Required - A list of custom indicator names to add. ### Request Example ```python from tradingview_ta import TA_Handler, Interval handler = TA_Handler( symbol="AAPL", screener="america", exchange="NASDAQ", interval=Interval.INTERVAL_1_DAY ) # Add custom indicators to the list handler.add_indicators(["RSI7", "VWMA", "Pivot.M.Classic.S1", "Pivot.M.Classic.R1"]) # Now get_analysis will include the custom indicators analysis = handler.get_analysis() print(analysis.indicators.get("RSI7")) print(analysis.indicators.get("Pivot.M.Classic.S1")) ``` ### Response This method does not return a value directly but modifies the internal state of the `TA_Handler` object to include the specified indicators for subsequent analysis. ### Response Example (No direct response body, but subsequent calls to `get_analysis().indicators` will contain the added indicators.) ``` -------------------------------- ### TradingView.search Method Source: https://context7.com/analyzerrest/python-tradingview-ta/llms.txt Search for symbols using TradingView's symbol search API. Returns matching symbols, exchanges, types, descriptions, and logo URLs. ```APIDOC ## TradingView.search Method ### Description Search for symbols using TradingView's symbol search API. Returns matching symbols, exchanges, types, descriptions, and logo URLs. ### Method `TradingView.search(symbol: str, exchange: Optional[str] = None, type: Optional[str] = None)` ### Parameters #### Query Parameters - **symbol** (str) - Required - The symbol or name to search for (e.g., "tesla", "bitcoin"). - **exchange** (str) - Optional - The exchange to filter the search by (e.g., "NASDAQ", "BINANCE"). - **type** (str) - Optional - The asset type to filter by (e.g., "stock", "crypto", "forex"). ### Request Example ```python from tradingview_ta import TradingView # Search for Tesla results = TradingView.search("tesla", "america") print(results) # Search for Bitcoin across all types btc_results = TradingView.search("bitcoin") for result in btc_results[:5]: print(f"{result['exchange']}:{result['symbol']} - {result['description']}") # Search for specific asset type crypto_results = TradingView.search("ethereum", type="crypto") stock_results = TradingView.search("apple", type="stock") ``` ### Response #### Success Response (200) - **symbol** (str) - The trading symbol. - **exchange** (str) - The exchange where the symbol is listed. - **type** (str) - The type of asset (e.g., 'stock', 'crypto'). - **description** (str) - A description of the symbol. - **logo** (str) - URL of the symbol's logo. #### Response Example ```json [ { "symbol": "TSLA", "exchange": "NASDAQ", "type": "stock", "description": "Tesla, Inc.", "logo": "https://s3-symbol-logo.tradingview.com/tesla.svg" } ] ``` ``` -------------------------------- ### Access Analysis Object Attributes Source: https://context7.com/analyzerrest/python-tradingview-ta/llms.txt Demonstrates how to access various attributes of the Analysis object returned by get_analysis(), including metadata, summary recommendations, oscillator and moving average analyses, and raw indicator values. ```python from tradingview_ta import TA_Handler, Interval handler = TA_Handler( symbol="GOOGL", screener="america", exchange="NASDAQ", interval=Interval.INTERVAL_1_DAY ) analysis = handler.get_analysis() # Metadata print(f"Symbol: {analysis.symbol}") # "GOOGL" print(f"Exchange: {analysis.exchange}") # "NASDAQ" print(f"Screener: {analysis.screener}") # "america" print(f"Interval: {analysis.interval}") # "1d" print(f"Time: {analysis.time}") # datetime object # Summary recommendation (combined oscillators + moving averages) print(analysis.summary) # {'RECOMMENDATION': 'BUY', 'BUY': 12, 'SELL': 7, 'NEUTRAL': 9} # Oscillators analysis print(analysis.oscillators) # {'RECOMMENDATION': 'NEUTRAL', 'BUY': 2, 'SELL': 1, 'NEUTRAL': 8, # 'COMPUTE': {'RSI': 'NEUTRAL', 'STOCH.K': 'NEUTRAL', 'CCI': 'NEUTRAL', # 'ADX': 'NEUTRAL', 'AO': 'NEUTRAL', 'Mom': 'BUY', 'MACD': 'SELL', ...}} # Moving averages analysis print(analysis.moving_averages) # {'RECOMMENDATION': 'BUY', 'BUY': 9, 'SELL': 5, 'NEUTRAL': 1, # 'COMPUTE': {'EMA10': 'SELL', 'SMA10': 'SELL', 'EMA20': 'SELL', # 'EMA50': 'BUY', 'SMA50': 'BUY', 'EMA200': 'BUY', ...}} # Raw indicator values indicators = analysis.indicators print(f"RSI: {indicators['RSI']}") print(f"MACD: {indicators['MACD.macd']}") print(f"Stochastic K: {indicators['Stoch.K']}") print(f"Close: {indicators['close']}") print(f"Open: {indicators['open']}") print(f"High: {indicators['high']}") print(f"Low: {indicators['low']}") print(f"Volume: {indicators['volume']}") print(f"Change %: {indicators['change']}") ``` -------------------------------- ### TA Handler with Proxy Source: https://github.com/analyzerrest/python-tradingview-ta/blob/main/docs/usage.md Demonstrates how to use the TA_Handler with proxy settings to retrieve technical analysis for a specific symbol. ```APIDOC ## POST /analyzerrest/python-tradingview-ta/TA_Handler ### Description Initializes a TA_Handler object to fetch technical analysis for a specific symbol, allowing for proxy configuration. ### Method POST ### Endpoint /analyzerrest/python-tradingview-ta/TA_Handler ### Parameters #### Request Body - **symbol** (str) - Required - The ticker symbol (e.g., "TSLA"). - **screener** (str) - Required - The screener type (e.g., "america"). - **exchange** (str) - Required - The exchange where the symbol is listed (e.g., "NASDAQ"). - **interval** (str) - Required - The time frame. Use constants from the Interval class (e.g., Interval.INTERVAL_1_DAY). - **proxies** (dict) - Optional - A dictionary containing proxy configurations for HTTP and HTTPS. Example: `{'http': 'http://0.0.0.0:8080', 'https': 'https://0.0.0.0:443'}`. ### Request Example ```python from tradingview_ta import TA_Handler, Interval handler = TA_Handler( symbol="TSLA", screener="america", exchange="NASDAQ", interval=Interval.INTERVAL_1_DAY, proxies={ 'http': 'http://your_proxy_address:port', 'https': 'https://your_proxy_address:port' } ) analysis = handler.get_analysis() print(analysis.summary) ``` ### Response #### Success Response (200) - **Analysis object** - An object containing the technical analysis summary. #### Response Example ```json { "RECOMMENDATION": "BUY", "BUY": 8, "NEUTRAL": 6, "SELL": 3 } ``` #### Error Response (e.g., 400) - **dict** - Error message detailing the issue, potentially related to proxy configuration or invalid parameters. ```json { "error": "Failed to connect to the server. Check proxy settings." } ``` ``` -------------------------------- ### Retrieving Analysis Source: https://github.com/analyzerrest/python-tradingview-ta/blob/main/docs/usage.md Shows how to retrieve the technical analysis data using the instantiated TA_Handler object. ```APIDOC ## GET /analyzerrest/python-tradingview-ta/analysis ### Description Retrieves the technical analysis for the configured symbol, exchange, screener, and interval. ### Method GET ### Endpoint /analyzerrest/python-tradingview-ta/analysis ### Parameters #### Query Parameters - **symbol** (str) - Required - Ticker symbol. - **exchange** (str) - Required - Exchange. - **screener** (str) - Required - Screener. - **interval** (str) - Required - Time frame. - **timeout** (float) - Optional - Timeout in seconds. ### Request Example ``` GET /analyzerrest/python-tradingview-ta/analysis?symbol=AAPL&exchange=nasdaq&screener=america&interval=1d&timeout=10 ``` ### Response #### Success Response (200) - **analysis** (object) - Contains the technical analysis data. #### Response Example ```json { "analysis": { "summary": { "RECOMMENDATION": "BUY", "BUY": 10, "SELL": 5, "NEUTRAL": 11 }, "oscillators": { "RECOMMENDATION": "SELL", "BUY": 2, "SELL": 9, "NEUTRAL": 5 }, "moving_averages": { "RECOMMENDATION": "STRONG_BUY", "BUY": 16, "SELL": 0, "NEUTRAL": 0 } } } ``` ``` -------------------------------- ### Instantiate TA_Handler for Financial Analysis Source: https://github.com/analyzerrest/python-tradingview-ta/blob/main/docs/usage.md Creates an instance of the TA_Handler class to fetch financial analysis data. Requires specifying symbol, exchange, screener, and interval. A timeout can also be set. ```python handler = TA_Handler( symbol="", exchange="", screener="", interval="", timeout=None ) ``` -------------------------------- ### Add Custom Indicators with TA_Handler Source: https://context7.com/analyzerrest/python-tradingview-ta/llms.txt Allows adding custom indicator names to the TA_Handler's internal list. Once added, these custom indicators can be retrieved using get_analysis(). ```python from tradingview_ta import TA_Handler, Interval handler = TA_Handler( symbol="AAPL", screener="america", exchange="NASDAQ", interval=Interval.INTERVAL_1_DAY ) # Add custom indicators to the list handler.add_indicators(["RSI7", "VWMA", "Pivot.M.Classic.S1", "Pivot.M.Classic.R1"]) # Now get_analysis will include the custom indicators analysis = handler.get_analysis() print(analysis.indicators.get("RSI7")) print(analysis.indicators.get("Pivot.M.Classic.S1")) ``` -------------------------------- ### Fetch Technical Analysis Summary in Python Source: https://github.com/analyzerrest/python-tradingview-ta/blob/main/README.md Demonstrates how to fetch the technical analysis summary for a given stock symbol using the TA_Handler class. It requires specifying the symbol, screener, exchange, and interval. The output is a dictionary containing recommendation and counts for buy, neutral, and sell signals. ```python from tradingview_ta import TA_Handler, Interval, Exchange tesla = TA_Handler( symbol="TSLA", screener="america", exchange="NASDAQ", interval=Interval.INTERVAL_1_DAY, # proxies={'http': 'http://example.com:8080'} # Uncomment to enable proxy (replace the URL). ) print(tesla.get_analysis().summary) # Example output: {"RECOMMENDATION": "BUY", "BUY": 8, "NEUTRAL": 6, "SELL": 3} ``` -------------------------------- ### Search Symbols with TradingView.search Source: https://context7.com/analyzerrest/python-tradingview-ta/llms.txt Searches for financial symbols using TradingView's symbol search API. It can filter by symbol name, exchange, and asset type. Returns a list of dictionaries, each containing symbol details. ```python from tradingview_ta import TradingView # Search for Tesla results = TradingView.search("tesla", "america") print(results) # Output: [{'symbol': 'TSLA', 'exchange': 'NASDAQ', 'type': 'stock', # 'description': 'Tesla, Inc.', # 'logo': 'https://s3-symbol-logo.tradingview.com/tesla.svg'}, ...] # Search for Bitcoin across all types btc_results = TradingView.search("bitcoin") for result in btc_results[:5]: print(f"{result['exchange']}:{result['symbol']} - {result['description']}") # Search for specific asset type crypto_results = TradingView.search("ethereum", type="crypto") stock_results = TradingView.search("apple", type="stock") ``` -------------------------------- ### Fetch Analysis with Proxy Source: https://github.com/analyzerrest/python-tradingview-ta/blob/main/docs/usage.md Retrieves market analysis for a given symbol using the TA_Handler, incorporating proxy settings. This allows users to route requests through a specified proxy server. A faulty proxy can lead to request rejection by TradingView. ```python from tradingview_ta import TA_Handler, Interval, Exchange tesla = TA_Handler( symbol="TSLA", screener="america", exchange="NASDAQ", interval=Interval.INTERVAL_1_DAY, proxies={'http': 'http://0.0.0.0:8080', 'https': 'https://0.0.0.0:443'} ) print(tesla.get_analysis().summary) ``` -------------------------------- ### Analysis Object Attributes Source: https://context7.com/analyzerrest/python-tradingview-ta/llms.txt The Analysis object returned by get_analysis() contains comprehensive technical analysis data. ```APIDOC ## Analysis Object Attributes ### Description The Analysis object returned by `get_analysis()` contains comprehensive technical analysis data, including metadata, summary recommendations, oscillator and moving average analysis, and raw indicator values. ### Attributes - **symbol** (str) - The trading symbol. - **exchange** (str) - The exchange where the symbol is listed. - **screener** (str) - The screener used for the analysis. - **interval** (str) - The time interval for the analysis (e.g., "1d", "1h"). - **time** (datetime) - The timestamp of the analysis. - **summary** (dict) - A dictionary containing the overall recommendation and counts for buy, sell, and neutral signals. - **oscillators** (dict) - A dictionary containing the recommendation and counts for oscillators, along with detailed compute results for each oscillator. - **moving_averages** (dict) - A dictionary containing the recommendation and counts for moving averages, along with detailed compute results for each moving average. - **indicators** (dict) - A dictionary containing the raw values of all computed indicators. ### Request Example ```python from tradingview_ta import TA_Handler, Interval handler = TA_Handler( symbol="GOOGL", screener="america", exchange="NASDAQ", interval=Interval.INTERVAL_1_DAY ) analysis = handler.get_analysis() # Metadata print(f"Symbol: {analysis.symbol}") print(f"Exchange: {analysis.exchange}") print(f"Screener: {analysis.screener}") print(f"Interval: {analysis.interval}") print(f"Time: {analysis.time}") # Summary recommendation print(analysis.summary) # Oscillators analysis print(analysis.oscillators) # Moving averages analysis print(analysis.moving_averages) # Raw indicator values indicators = analysis.indicators print(f"RSI: {indicators['RSI']}") print(f"MACD: {indicators['MACD.macd']}") print(f"Stochastic K: {indicators['Stoch.K']}") print(f"Close: {indicators['close']}") ``` ### Response Example ```json { "symbol": "GOOGL", "exchange": "NASDAQ", "screener": "america", "interval": "1d", "time": "2023-10-27T10:00:00Z", "summary": { "RECOMMENDATION": "BUY", "BUY": 12, "SELL": 7, "NEUTRAL": 9 }, "oscillators": { "RECOMMENDATION": "NEUTRAL", "BUY": 2, "SELL": 1, "NEUTRAL": 8, "COMPUTE": { "RSI": "NEUTRAL", "STOCH.K": "NEUTRAL", "CCI": "NEUTRAL", "ADX": "NEUTRAL", "AO": "NEUTRAL", "Mom": "BUY", "MACD": "SELL", "Stoch.RSI": "NEUTRAL", "Bulls": "BUY", "WillR": "SELL" } }, "moving_averages": { "RECOMMENDATION": "BUY", "BUY": 9, "SELL": 5, "NEUTRAL": 1, "COMPUTE": { "EMA10": "SELL", "SMA10": "SELL", "EMA20": "SELL", "EMA50": "BUY", "SMA50": "BUY", "EMA100": "BUY", "SMA100": "BUY", "EMA200": "BUY", "SMA200": "BUY", "Ichimoku.B": "BUY", "VWMA": "BUY", "HullMA": "BUY" } }, "indicators": { "RSI": 55.23, "MACD.macd": 2444.73, "Stoch.K": 75.5, "close": 45326.97, "open": 45000.00, "high": 45500.00, "low": 44800.00, "volume": 32744.42, "change": 0.75 } } ``` ``` -------------------------------- ### Define TradingView Intervals Source: https://github.com/analyzerrest/python-tradingview-ta/blob/main/docs/usage.md Defines constants for various time intervals supported by TradingView, such as 1 minute, 5 minutes, 1 hour, and 1 day. These constants are used to specify the desired time frame for market analysis. ```python class Interval: INTERVAL_1_MINUTE = "1m" INTERVAL_5_MINUTES = "5m" INTERVAL_15_MINUTES = "15m" INTERVAL_30_MINUTES = "30m" INTERVAL_1_HOUR = "1h" INTERVAL_2_HOURS = "2h" INTERVAL_4_HOURS = "4h" INTERVAL_1_DAY = "1d" INTERVAL_1_WEEK = "1W" INTERVAL_1_MONTH = "1M" ``` -------------------------------- ### Symbol Search API Source: https://github.com/analyzerrest/python-tradingview-ta/blob/main/docs/usage.md Searches for symbols using the TradingView symbol search API. Returns a list of symbols, exchanges, types, descriptions, and logo URLs matching the search query. ```APIDOC ## GET /analyzerrest/python-tradingview-ta/search ### Description Searches for trading symbols based on a text query and optional asset type. ### Method GET ### Endpoint /analyzerrest/python-tradingview-ta/search ### Parameters #### Query Parameters - **text** (str) - Required - The search query string. - **type** (str) - Optional - The type of asset to search for (e.g., "stock", "crypto", "futures", "index"). Defaults to None (searches all types). ### Request Example ```python from tradingview_ta import TradingView results = TradingView.search(text="tesla", type="stock") print(results) ``` ### Response #### Success Response (200) - **list** - A list of dictionaries, where each dictionary contains details about a found symbol: - **symbol** (str) - The ticker symbol. - **exchange** (str) - The exchange where the symbol is listed. - **type** (str) - The type of asset. - **description** (str) - A description of the symbol. - **logo** (str) - The URL of the symbol's logo. #### Response Example ```json [ { "symbol": "TSLA", "exchange": "NASDAQ", "type": "stock", "description": "Tesla, Inc.", "logo": "https://s3-symbol-logo.tradingview.com/tesla.svg" } ] ``` #### NOTE Symbols returned by this function may not always be compatible with the `get_analysis()` function. ``` -------------------------------- ### Search TradingView Symbols Source: https://github.com/analyzerrest/python-tradingview-ta/blob/main/docs/usage.md Searches for trading symbols on TradingView based on a query string and an optional asset type. It returns a list of matching symbols, their exchanges, types, descriptions, and logo URLs. Note that symbols returned may not always be compatible with analysis functions. ```python from tradingview_ta import TradingView print(TradingView.search("tesla", "america")) ``` -------------------------------- ### Retrieve Financial Analysis Data Source: https://github.com/analyzerrest/python-tradingview-ta/blob/main/docs/usage.md Fetches the financial analysis data for the configured TA_Handler instance. This method sends a request to the TradingView servers and returns the analysis results. ```python analysis = handler.get_analysis() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.