{"repo":"shner-elmo/TradingView-Screener","free":true,"listed":false,"github":"https://github.com/shner-elmo/TradingView-Screener","clone":"git clone https://github.com/shner-elmo/TradingView-Screener.git","description":"A package that lets you create TradingView screeners in Python","language":"Python","stars":1133,"topics":["cfd","crypto","forex","indices","live-data","quant","quantitative-finance","stock","stock-market","stock-scanner","stock-screener","stonk","ta","technical-analysis","trading","tradingview","tradingview-api","tradingview-scanner","tradingview-screener","tvscreener"],"license":"MIT","category":"quant_tool","readme_excerpt":"<div align=\"center\">\n    \n  <a href=\"https://pypi.org/project/tradingview-screener\">\n    <img alt=\"PyPi Version\"\n         src=\"https://badge.fury.io/py/tradingview-screener.svg?icon=si%3Apython\">\n  </a>\n  <a href=\"https://pypi.org/project/tradingview-screener\">\n    <img alt=\"Supported Python versions\"\n         src=\"https://img.shields.io/pypi/pyversions/tradingview-screener.svg?color=%2334D058\">\n  </a>\n  <a href=\"https://pepy.tech/project/tradingview-screener\">\n    <img alt=\"Downloads\"\n         src=\"https://static.pepy.tech/badge/tradingview-screener\">\n  </a>\n  <a href=\"https://pepy.tech/project/tradingview-screener\">\n    <img alt=\"Downloads\"\n         src=\"https://static.pepy.tech/badge/tradingview-screener/month\">\n  </a>\n    \n</div>\n\n\n## Overview\n\n```bash\npip install tradingview-screener\n```\n\n`tradingview-screener` is a Python package that allows you to create custom stock screeners using TradingView's official\nAPI. This package retrieves data directly from TradingView without the need for web scraping or HTML parsing.\n\n\n### Key Features\n\n- Stocks (~70 countries), options, crypto, forex, CFDs, futures, bonds, and more.\n- **3000+ Data Fields**: OHLC data, technical indicators, fundamental metrics (e.g. P/E, EPS), and even internal TradingView-only fields.\n- **Timeframes**: Use 1m, 5m, 15m, 30m, 1h, 2h, 4h, 1d, 1w, and 1mo — freely mix timeframes per field, no subscription required.\n- **Filtering**: SQL-like syntax with full support for `AND`/`OR` logic.\n\n\n### Links\n\n- [GitHub Repository](https://github.com/shner-elmo/TradingView-Screener)\n- [Documentation](https://shner-elmo.github.io/TradingView-Screener/3.2.1/tradingview_screener.html)\n- [Fields](https://shner-elmo.github.io/TradingView-Screener/fields/stocks.html)\n- [Markets](https://shner-elmo.github.io/TradingView-Screener/markets.html)\n- [Screeners](https://shner-elmo.github.io/TradingView-Screener/screeners/stocks/america.html)\n\nNote that throughout the documentation, \"field\" and \"column\" are used interchangeably.\nSame with \"Scanner\" and \"Screener\".\n\n## Quickstart\n\nHere’s a simple example to get you started:\n\n```python\nfrom tradingview_screener import Query\n\nx = (Query()\n .select('name', 'close', 'volume', 'market_cap_basic')\n .get_scanner_data())\nprint(x)\n```\n\n**Output:**\n\n```\n(17580,\n          ticker  name   close     volume  market_cap_basic\n 0   NASDAQ:NVDA  NVDA  127.25  298220762      3.130350e+12\n 1      AMEX:SPY   SPY  558.70   33701795               NaN\n 2   NASDAQ:TSLA  TSLA  221.10   73869589      7.063350e+11\n 3    NASDAQ:QQQ   QQQ  480.26   29102854               NaN\n 4    NASDAQ:AMD   AMD  156.40   76693809      2.531306e+11\n ..          ...   ...     ...        ...               ...\n 45   NASDAQ:PDD   PDD  144.22    8653323      2.007628e+11\n 46     NYSE:JPM   JPM  214.52    5639973      6.103447e+11\n 47     NYSE:JNJ   JNJ  160.16    7274621      3.855442e+11\n 48  NASDAQ:SQQQ  SQQQ    7.99  139721164               NaN\n 49  NASDAQ:ASTS  ASTS   34.32   32361315      9.245616e+09\n \n [50 rows x 5 columns])\n```\n\nBy default, the result is limited to 50 rows. You can adjust this limit, but be mindful of server load and potential\nbans.\n\nA more advanced query:\n\n```python\nfrom tradingview_screener import Query, col\n\n(Query()\n .select('name', 'close', 'close|1', 'close|5', 'volume', 'relative_volume_10d_calc')\n .where(\n     col('market_cap_basic').between(1_000_000, 50_000_000),\n     col('relative_volume_10d_calc') > 1.2,\n     col('MACD.macd|1') >= col('MACD.signal|1')  # 1 minute MACD\n )\n .order_by('volume', ascending=False)\n .offset(5)\n .limit(25)\n .get_scanner_data())\n```\n\n### Other Screeners\n\n```python\nfrom tradingview_screener import stocks, crypto, options\n\n# top stocks by market cap in Italy\nstocks('italy').limit(5).get_scanner_data()\n\n# top CEX crypto pairs by 24 h volume\ncrypto().limit(5).get_scanner_data()\n\n# AAPL options chain\noptions('NASDAQ:AAPL').limit(5).get_scanner_data()\n```\n\nAll screener functions return a `Query` object, so you can chain any of the usual methods\n(`.select()`, `.where()`, `.order_by()`, etc.) on top of them:\n\n```python\nfrom tradingview_screener import options, col\n\n(options('NASDAQ:AAPL')\n .select('name', 'close', 'ask', 'bid', 'expiration', 'volume')\n .where(col('expiration') == 20260427)  # 2026/4/27\n .order_by('strike')\n .limit(10)\n .get_scanner_data())\n```\n\nThe full list of available screeners: `stocks`, `crypto`, `crypto_dex`, `coin`, `forex`,\n`futures`, `bond`, `cfd`, `options`.\n\n<br>\nNote that some fields (usually prices and indicators) have multiple timeframes that you can choose from, for example:\n\n| Timeframe | Column |\n|---|---|\n| 1 Minute | `close\\|1` |\n| 5 Minutes | `close\\|5` |\n| 15 Minutes | `close\\|15` |\n| 30 Minutes | `close\\|30` |\n| 1 Hour | `close\\|60` |\n| 2 Hours | `close\\|120` |\n| 4 Hours | `close\\|240` |\n| 1 Day | `close` |\n| 1 Week | `close\\|1W` |\n| 1 Month | `close\\|1M` |\n\n## Real-Time Data Access\n\nTo access real-time data, you need to pass your session cookies, as even free real-time data requires authentication.\n\n### Verify Update Mode\n\nYou can run this query to get an overview on the `update_mode` you get for each exchange:\n```python\nfrom tradingview_screener import Query\n\n_, df = Query().select('exchange', 'update_mode').limit(1_000_000).get_scanner_data()\ndf = df.groupby('exchange')['update_mode'].value_counts()\nprint(df)\n```\n```\nexchange  update_mode          \nAMEX      delayed_streaming_900    3255\nNASDAQ    delayed_streaming_900    4294\nNYSE      delayed_streaming_900    2863\nOTC       delayed_streaming_900    7129\n```\n\n### Using rookiepy\n\n`rookiepy` is a library that loads the cookies from your local browser.\nSo if you are logged in on Chrome (or whatever browser you use), it will use the same session.\n\n1. Install `rookiepy`:\n\n    ```bash\n    pip install rookiepy\n    ```\n\n2. Load the cookies:\n\n    ```python\n    import rookiepy\n    cookies = rookiepy.to_cookiejar(rookiepy.chrome(['.tradingview.com']))  # replace chrome() with your browser\n    ```\n\n3. Pass the cookies when querying:\n\n    ```python\n    Query().get_scanner_data(cookies=cookies)\n    ```\n\nNow, if you re-run the update mode check:\n\n```python\n_, df = Query().select('exchange', 'update_mode').limit(1_000_000).get_scanner_data(cookies=cookies)\ndf = df.groupby('exchange')['update_mode'].value_counts()\nprint(df)\n```\n```\nexchange  update_mode          \nAMEX      streaming                3256\nNASDAQ    streaming                4286\nNYSE      streaming                2860\nOTC       delayed_streaming_900    7175\n```\nWe now get live-data for all exchanges except `OTC` (because my subscription dosent include live-data for OTC tickers).\n\n\n### Other Ways For Loading Cookies\n\n<details>\n<summary>Extract Cookies Manually</summary>\n\n1. Go to [TradingView](https://www.tradingview.com)\n2. Open the developer tools (`Ctrl + Shift + I`)\n3. Navigate to the `Application` tab.\n4. Go to `Storage > Cookies > https://www.tradingview.com/`\n5. Copy the value of `sessionid`\n6. Pass it in your query:\n\n    ```python\n    cookies = {'sessionid': '<your-session-id>'}\n    Query().get_scanner_data(cookies=cookies)\n    ```\n\n</details>\n\n\n<details>\n<summary>Authenticate via API</summary>\n\nWhile it's possible to authenticate directly via API, TradingView has restrictions on login frequency, which may result\nin CAPTCHA requests and account flagging (meaning this method won't work again until the cooldown expires and the CAPTCHA\nis gone).  \nIf you wish to proceed, here’s how:\n\n```python\nfrom http.cookiejar import CookieJar\n\nimport requests\nfrom tradingview_screener import Query\n\n\ndef authenticate(username: str, password: str) -> CookieJar:\n    session = requests.Session()\n    r = session.post(\n       'https://www.tradingview.com/accounts/signin/', \n       headers={'User-Agent': 'Mozilla/5.0', 'Referer': 'https://www.tradingview.com'}, \n       data={'username': username, 'password': password, 'remember': 'on'}, \n       timeout=60,\n    )\n    r.raise_for_status()\n    if r.json().get('error'):\n        raise Exception(f'Failed to authenticate: \\n{r.json()}')\n    return session.cookies\n\n\ncookies = authenticate('<your-username-or-email>', '<your-password>')\nQuery().get_scanner_data(cookies=cookies)\n```\n\n</details>\n\n## Comparison to Similar Packages\n\nUnlike other Python libraries that have specific features like extracting the sentiment, or what not.\nThis package is but a (low-level) wrapper around TradingView's `/screener` API endpoint.\n\nIt merely documents the endpoint, by listing all the functions and operations available, the different fields you can \nuse, the markets, instruments (even some that you wont find on TradingView's website), and so on.\n\nThis library is also a wrapper that makes it easier to generate those verbose JSON payloads.\n\n\n## Robustness & Longevity\n\nThis package is designed to be future-proof. There are no hard-coded values in the package, all fields/columns and markets are documented on the website, which is updated\ndaily via a GitHub Actions script.\n\n## How It Works\n\nWhen using methods like `select()` or `where()`, the `Query` object constructs a dictionary representing the API\nrequest. Here’s an example of the dictionary generated:\n\n```python\n{\n    'markets': ['america'],\n    'symbols': {'query': {'types': []}, 'tickers': []},\n    'options': {'lang': 'en'},\n    'columns': ['name', 'close', 'volume', 'relative_volume_10d_calc'],\n    'sort': {'sortBy': 'volume', 'sortOrder': 'desc'},\n    'range': [5, 25],\n    'filter': [\n        {'left': 'market_cap_basic', 'operation': 'in_range', 'right': [1000000, 50000000]},\n        {'left': 'relative_volume_10d_calc', 'operation': 'greater', 'right': 1.2},\n        {'left': 'MACD.macd', 'operation': 'egreater', 'right': 'MACD.signal'},\n    ],\n}\n```\n\nThe `get_scanner_data()` method sends this dictionary as a JSON payload to the TradingView API,\nallowing you to query data using SQL-like syntax without knowing the specifics of the API.\n\n## Feedback and Improvement\n\nIf this package has bought value to your projects,","default_branch":"master","files":20,"tree":[".github/FUNDING.yml",".github/workflows/docs-release.yml",".github/workflows/docs.yml",".github/workflows/test.yml",".gitignore","LICENSE","README.md","pyproject.toml","src/tradingview_screener/__init__.py","src/tradingview_screener/column.py","src/tradingview_screener/models.py","src/tradingview_screener/py.typed","src/tradingview_screener/query.py","src/tradingview_screener/screeners.py","src/tradingview_screener/util.py","templates/module.html.jinja2","tests/test_query.py","tests/test_readme.py","tests/test_screeners.py","uv.lock"],"storefront":"/r/shner-elmo","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/shner-elmo/TradingView-Screener/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}