{"id":26961126,"url":"https://github.com/shner-elmo/TradingView-Screener","last_synced_at":"2025-04-03T05:02:31.339Z","repository":{"id":86592193,"uuid":"497854996","full_name":"shner-elmo/TradingView-Screener","owner":"shner-elmo","description":"A package that lets you create TradingView screeners in Python","archived":false,"fork":false,"pushed_at":"2024-05-28T20:22:41.000Z","size":188,"stargazers_count":150,"open_issues_count":3,"forks_count":23,"subscribers_count":11,"default_branch":"master","last_synced_at":"2024-05-29T11:20:10.004Z","etag":null,"topics":["crypto","forex","live-data","quant","quantitative-finance","scanner","stock","stock-market","stock-scanner","stock-screener","ta","technical-analysis","trading","tradingview"],"latest_commit_sha":null,"homepage":"https://shner-elmo.github.io/TradingView-Screener/tradingview_screener.html","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shner-elmo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-05-30T08:31:01.000Z","updated_at":"2024-06-03T23:31:29.353Z","dependencies_parsed_at":"2024-05-28T23:38:56.230Z","dependency_job_id":null,"html_url":"https://github.com/shner-elmo/TradingView-Screener","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shner-elmo%2FTradingView-Screener","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shner-elmo%2FTradingView-Screener/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shner-elmo%2FTradingView-Screener/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shner-elmo%2FTradingView-Screener/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shner-elmo","download_url":"https://codeload.github.com/shner-elmo/TradingView-Screener/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246939207,"owners_count":20857920,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["crypto","forex","live-data","quant","quantitative-finance","scanner","stock","stock-market","stock-scanner","stock-screener","ta","technical-analysis","trading","tradingview"],"created_at":"2025-04-03T05:01:31.377Z","updated_at":"2025-04-03T05:02:31.317Z","avatar_url":"https://github.com/shner-elmo.png","language":"Python","funding_links":[],"categories":["Indicators"],"sub_categories":["Screeners"],"readme":"\u003cdiv align=\"center\"\u003e\n    \n  \u003ca href=\"https://pypi.org/project/tradingview-screener\"\u003e\n    \u003cimg alt=\"PyPi Version\"\n         src=\"https://badge.fury.io/py/tradingview-screener.svg?icon=si%3Apython\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://pypi.org/project/tradingview-screener\"\u003e\n    \u003cimg alt=\"Supported Python versions\"\n         src=\"https://img.shields.io/pypi/pyversions/tradingview-screener.svg?color=%2334D058\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://pepy.tech/project/tradingview-screener\"\u003e\n    \u003cimg alt=\"Downloads\"\n         src=\"https://static.pepy.tech/badge/tradingview-screener\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://pepy.tech/project/tradingview-screener\"\u003e\n    \u003cimg alt=\"Downloads\"\n         src=\"https://static.pepy.tech/badge/tradingview-screener/month\"\u003e\n  \u003c/a\u003e\n    \n\u003c/div\u003e\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- **Over 3000 Fields**: OHLC, indicators, fundamental metrics, and much more.\n- **Multiple Markets**: Stocks, crypto, forex, CFD, futures, bonds, and more.\n- **Customizable Timeframes**: Choose timeframes like 1 minute, 5 minutes, 1 hour, or 1 day for each field.\n- **Filter and sort** the results using a SQL-like syntax, with support for And/Or operators for advanced filtering.\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.0.0/tradingview_screener.html)\n- [Fields](https://shner-elmo.github.io/TradingView-Screener/fields/stocks.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\n(Query()\n .select('name', 'close', 'volume', 'market_cap_basic')\n .get_scanner_data())\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', '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') \u003e 1.2,\n     col('MACD.macd') \u003e= col('MACD.signal')\n )\n .order_by('volume', ascending=False)\n .offset(5)\n .limit(25)\n .get_scanner_data())\n```\n\n\u003cbr\u003e\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.groupby('exchange')['update_mode'].value_counts()\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.groupby('exchange')['update_mode'].value_counts()\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\u003cdetails\u003e\n\u003csummary\u003eExtract Cookies Manually\u003c/summary\u003e\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 \u003e Cookies \u003e https://www.tradingview.com/`\n5. Copy the value of `sessionid`\n6. Pass it in your query:\n\n    ```python\n    cookies = {'sessionid': '\u003cyour-session-id\u003e'}\n    Query().get_scanner_data(cookies=cookies)\n    ```\n\n\u003c/details\u003e\n\n\n\u003cdetails\u003e\n\u003csummary\u003eAuthenticate via API\u003c/summary\u003e\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) -\u003e 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('\u003cyour-username-or-email\u003e', '\u003cyour-password\u003e')\nQuery().get_scanner_data(cookies=cookies)\n```\n\n\u003c/details\u003e\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 \u0026 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, please consider starring it.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshner-elmo%2FTradingView-Screener","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshner-elmo%2FTradingView-Screener","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshner-elmo%2FTradingView-Screener/lists"}