tradingview-scraper


Nametradingview-scraper JSON
Version 0.3.2 PyPI version JSON
download
home_pagehttps://github.com/mnwato/tradingview-scraper
SummaryTradingview scraper tool
upload_time2024-11-29 15:36:08
maintainerNone
docs_urlNone
authorMostafa Najmi
requires_pythonNone
licenseMIT
keywords tradingview scraper python crawler financial
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # TradingView Scraper
[![Python 3.8](https://img.shields.io/badge/python-3.8-blue.svg)](https://www.python.org/downloads/release/python-380/)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![MIT License](https://img.shields.io/github/license/mnwato/tradingview-scraper.svg?color=brightgreen)](https://opensource.org/licenses/MIT)


This is a Python library for scraping ideas and indicators from [TradingView.com](https://www.tradingview.com). The goal is to develop this package to scrape anything on [TradingView.com](https://www.tradingview.com) with real-time responses.  
**Thanks to contributors!**


## To-Do List
- Export
  - [x] Export as a `CSV` file
  - [x] Export as `JSON`
- Scrape Symbol Subpages:
  - [x] [Ideas](https://www.tradingview.com/symbols/BTCUSD/ideas/)
  - [x] [Indicators](https://www.tradingview.com/symbols/BTCUSD/technicals/)
  - [ ] [Overview](https://www.tradingview.com/symbols/BTCUSD/)
  - [x] [News](https://www.tradingview.com/symbols/BTCUSD/news/)
  - [ ] [Minds](https://www.tradingview.com/symbols/BTCUSD/minds/)
  - [ ] [Technical](https://www.tradingview.com/symbols/BTCUSD/technicals/)
  - [ ] [Market](https://www.tradingview.com/symbols/BTCUSD/markets/)
  - [ ] Get data using TradingView WebSocket
  - [ ] Additional suggestions welcome!

### To be aware of the latest changes, go to the [end of this page](https://github.com/mnwato/tradingview-scraper#changes).

## Features

- **Idea page Scraping**
  - Title
  - Paragraph
  - Preview Image
  - Author
  - Comments Count
  - Boosts Count
  - Publication Datetime
  - Is Updated
  - Idea Strategy

- **News page Scraping**
  - Breadcrumbs
  - Title
  - Published datetime
  - Related symbols
  - Body
  - Tags

- **Webpage Scraping Options**
  - Scrape All Pages
  - Scrape a Specific Range of Pages

- **Indicator Extraction**
  - Extract values for indicators like `RSI`, `Stoch.K`, etc. 
  - [Full list of indicators](https://github.com/mnwato/tradingview-scraper/blob/dev/tradingview_scraper/indicators.txt)

- **Export Formats**
  - CSV
  - JSON

- **Output Format**
  - Returns data in JSON format

Here’s a revised version of the Installation section that enhances clarity and encourages user engagement:


## Installation

To get started with the TradingView Scraper library, follow these simple steps:

1. **Open your terminal**: Launch your preferred command line interface.

2. **Install the package**: Run the following command to install the TradingView Scraper:
   ```sh
   pip install tradingview-scraper
   ```

3. **Upgrade if necessary**: If you already have the library installed and want to upgrade to the latest version, use:
   ```sh
   pip install --upgrade --no-cache tradingview-scraper
   ```

Here’s a revised version of the Examples section, focusing on clarity, ease of understanding, and providing essential information about default values:


## Examples

### 1. Fast Running (Default Parameters)
To quickly scrape ideas using default settings, use the following code:
```python
from symbols.ideas import Ideas

# Initialize the Ideas scraper with default parameters
ideas_scraper = Ideas()  # Default: export_result=False, export_type='json'
ideas = ideas_scraper.scrape()  # Default symbol: 'BTCUSD'
print("Ideas:", ideas)
```
**Default Parameters:**
- `export_result`: `False` (no file will be saved)
- `export_type`: `'json'` (output format)

### 2. Getting Ideas for a Specific Symbol, Export Type, and Pages
To scrape ideas for a specific symbol and export them as a CSV file, you can specify the parameters:
```python
from symbols.ideas import Ideas

# Initialize the Ideas scraper with custom parameters
ideas_scraper = Ideas(
  export_result=True,  # Set to True to save the results
  export_type='csv'    # Specify the export type (json or csv)
)

# Scrape ideas for the ETHUSD symbol, from page 1 to page 2
ideas = ideas_scraper.scrape(
  symbol="ETHUSD",
  startPage=1,
  endPage=2,
  sort="popular"  #  Could be 'popupar' or 'recent'
)
print("Ideas:", ideas)
```

**Output Format:**
The output will always be a list of Python dictionaries, structured as follows:
```json
[
  {
      "title": "Bitcoin -65% crash, ETH -83%, DOGE -89%, SHIBA -90%",
      "paragraph": "Name your altcoin in the comment section, and I will do a technical analysis for you!\n\nThe crypto market looks ...",
      "preview_image": "https://s3.tradingview.com/6/6VQphWH6_mid.png",
      "author": "Xanrox",
      "comments_count": "295",
      "boosts_count": "678",
      "publication_datetime": "2024-08-18T05:55:19.000Z",
      "is_updated": "True",
      "idea_strategy": "Short"
  }
]
```
- When `export_result=True`, the default `export_type` is `'json'`, and a JSON file will be saved in the `/export` directory. To save as CSV, set `export_type='csv'`.

### 3. Getting Indicators Status
To scrape the status of specific indicators, use the following code:
```python
from tradingview_scraper.symbols.technicals import Indicators

# Initialize the Indicators scraper with export options
indicators_scraper = Indicators(export_result=True, export_type='json')

# Scrape indicators for the BTCUSD symbol from the BINANCE exchange
indicators = indicators_scraper.scrape(
    exchange="BINANCE",
    symbol="BTCUSD",
    timeframe="1d",
    indicators=["RSI", "Stoch.K"]
)
print("Indicators:", indicators)
```

**Output:**
```json
{"RSI": "46.34926112", "Stoch.K": "40.40173723"}
```

### 4. Getting All Indicators
If you want to retrieve all available indicators for a symbol, set `allIndicators=True`:
```python
from tradingview_scraper.symbols.technicals import Indicators

# Scrape all indicators for the BTCUSD symbol
indicators_scraper = Indicators(export_result=True, export_type='json')
indicators = indicators_scraper.scrape(
    symbol="BTCUSD",
    timeframe="4h",
    allIndicators=True
)
print("All Indicators:", indicators)
```

### 5. Getting News Headlines/Content
```python
# Create an instance of the NewsScraper with export options
news_scraper = NewsScraper(export_result=True, export_type='json')

# Retrieve news headlines from a specific provider
news_headlines = news_scraper.scrape_headlines(
    symbol='BTCUSD',      # Uncomment and specify if needed
    exchange='BINANCE', # Uncomment and specify if needed
    # provider='newsbtc',  # Specify the news provider
    # area='world',  # Specify the geographical area
    # section='all',  # Specify the section of news
    sort='latest'
)

# Retrieve detailed news content for a specific story
news_content = news_scraper.scrape_news_content(
    story_path=news_headlines[0]['storyPath']  # Specify the story path from scraped headlines
)
```
- Retrieve news by symbol:
  - Both `symbol` and `exchange` are required parameters
- Filter result by:
  - `area`, `provider` and `section` can be specified to refine the news results.

#### Output (news headline):
```json
[
  {
    "breadcrumbs": "News > U.Today > Bitcoin ETFs Record Enormous Outflows",
    "title": "Bitcoin ETFs Record Enormous Outflows",
    "published_datetime": "Wed, 04 Sep 2024 07:55:38 GMT",
    "related_symbols": [
      {
        "name": "BTCUSDT",
        "logo": "https://s3-symbol-logo.tradingview.com/crypto/XTVCUSDT.svg"
      }
    ],
    "body": ["""<List of text page content>"""],
    "tags": ["Crypto", "U.Today"]}
]
```
#### Output (news content):
```json
[
  {
    "id": "tag:reuters.com,2024:newsml_L1N3KM09S:0",
    "title": "Goldman Sachs sees biggest boost to US economy from Harris win",
    "provider": "reuters",
    "sourceLogoId": "reuters",
    "published": 1725443676,
    "source": "Reuters",
    "urgency": 2,
    "permission": "preview",
    "relatedSymbols": [
      {
        "symbol": "BITMEX:XBTETH.P",
        "currency-logoid": "country/US",
        "base-currency-logoid": "crypto/XTVCBTC"
      },
      {
        "symbol": "ICEUS:DXY",
        "logoid": "indices/u-s-dollar-index"
      }
    ],
    "storyPath": "/news/reuters.com,2024:newsml_L1N3KM09S:0-goldman-sachs-sees-biggest-boost-to-us-economy-from-harris-win/"
  }
]
```

## Changes:
- Release `0.3.2`:
  Support timeframe to get Indicators
- Release `0.3.0`:   
  Add news scraper
- Release `0.2.9`:   
  Refactor for new TradingView structure
- Release `0.1.0`:  
  The name of `ClassA` changed to `Ideas`

## License:
```
[MIT]
```
            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/mnwato/tradingview-scraper",
    "name": "tradingview-scraper",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "tradingview, scraper, python, crawler, financial",
    "author": "Mostafa Najmi",
    "author_email": "m.n.irib@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/12/be/f1cec16d3d673e7b824e7ead2b8f8e38d03fce5ce189a8de57ed018f61aa/tradingview-scraper-0.3.2.tar.gz",
    "platform": null,
    "description": "# TradingView Scraper\n[![Python 3.8](https://img.shields.io/badge/python-3.8-blue.svg)](https://www.python.org/downloads/release/python-380/)\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n[![MIT License](https://img.shields.io/github/license/mnwato/tradingview-scraper.svg?color=brightgreen)](https://opensource.org/licenses/MIT)\n\n\nThis is a Python library for scraping ideas and indicators from [TradingView.com](https://www.tradingview.com). The goal is to develop this package to scrape anything on [TradingView.com](https://www.tradingview.com) with real-time responses.  \n**Thanks to contributors!**\n\n\n## To-Do List\n- Export\n  - [x] Export as a `CSV` file\n  - [x] Export as `JSON`\n- Scrape Symbol Subpages:\n  - [x] [Ideas](https://www.tradingview.com/symbols/BTCUSD/ideas/)\n  - [x] [Indicators](https://www.tradingview.com/symbols/BTCUSD/technicals/)\n  - [ ] [Overview](https://www.tradingview.com/symbols/BTCUSD/)\n  - [x] [News](https://www.tradingview.com/symbols/BTCUSD/news/)\n  - [ ] [Minds](https://www.tradingview.com/symbols/BTCUSD/minds/)\n  - [ ] [Technical](https://www.tradingview.com/symbols/BTCUSD/technicals/)\n  - [ ] [Market](https://www.tradingview.com/symbols/BTCUSD/markets/)\n  - [ ] Get data using TradingView WebSocket\n  - [ ] Additional suggestions welcome!\n\n### To be aware of the latest changes, go to the [end of this page](https://github.com/mnwato/tradingview-scraper#changes).\n\n## Features\n\n- **Idea page Scraping**\n  - Title\n  - Paragraph\n  - Preview Image\n  - Author\n  - Comments Count\n  - Boosts Count\n  - Publication Datetime\n  - Is Updated\n  - Idea Strategy\n\n- **News page Scraping**\n  - Breadcrumbs\n  - Title\n  - Published datetime\n  - Related symbols\n  - Body\n  - Tags\n\n- **Webpage Scraping Options**\n  - Scrape All Pages\n  - Scrape a Specific Range of Pages\n\n- **Indicator Extraction**\n  - Extract values for indicators like `RSI`, `Stoch.K`, etc. \n  - [Full list of indicators](https://github.com/mnwato/tradingview-scraper/blob/dev/tradingview_scraper/indicators.txt)\n\n- **Export Formats**\n  - CSV\n  - JSON\n\n- **Output Format**\n  - Returns data in JSON format\n\nHere\u2019s a revised version of the Installation section that enhances clarity and encourages user engagement:\n\n\n## Installation\n\nTo get started with the TradingView Scraper library, follow these simple steps:\n\n1. **Open your terminal**: Launch your preferred command line interface.\n\n2. **Install the package**: Run the following command to install the TradingView Scraper:\n   ```sh\n   pip install tradingview-scraper\n   ```\n\n3. **Upgrade if necessary**: If you already have the library installed and want to upgrade to the latest version, use:\n   ```sh\n   pip install --upgrade --no-cache tradingview-scraper\n   ```\n\nHere\u2019s a revised version of the Examples section, focusing on clarity, ease of understanding, and providing essential information about default values:\n\n\n## Examples\n\n### 1. Fast Running (Default Parameters)\nTo quickly scrape ideas using default settings, use the following code:\n```python\nfrom symbols.ideas import Ideas\n\n# Initialize the Ideas scraper with default parameters\nideas_scraper = Ideas()  # Default: export_result=False, export_type='json'\nideas = ideas_scraper.scrape()  # Default symbol: 'BTCUSD'\nprint(\"Ideas:\", ideas)\n```\n**Default Parameters:**\n- `export_result`: `False` (no file will be saved)\n- `export_type`: `'json'` (output format)\n\n### 2. Getting Ideas for a Specific Symbol, Export Type, and Pages\nTo scrape ideas for a specific symbol and export them as a CSV file, you can specify the parameters:\n```python\nfrom symbols.ideas import Ideas\n\n# Initialize the Ideas scraper with custom parameters\nideas_scraper = Ideas(\n  export_result=True,  # Set to True to save the results\n  export_type='csv'    # Specify the export type (json or csv)\n)\n\n# Scrape ideas for the ETHUSD symbol, from page 1 to page 2\nideas = ideas_scraper.scrape(\n  symbol=\"ETHUSD\",\n  startPage=1,\n  endPage=2,\n  sort=\"popular\"  #  Could be 'popupar' or 'recent'\n)\nprint(\"Ideas:\", ideas)\n```\n\n**Output Format:**\nThe output will always be a list of Python dictionaries, structured as follows:\n```json\n[\n  {\n      \"title\": \"Bitcoin -65% crash, ETH -83%, DOGE -89%, SHIBA -90%\",\n      \"paragraph\": \"Name your altcoin in the comment section, and I will do a technical analysis for you!\\n\\nThe crypto market looks ...\",\n      \"preview_image\": \"https://s3.tradingview.com/6/6VQphWH6_mid.png\",\n      \"author\": \"Xanrox\",\n      \"comments_count\": \"295\",\n      \"boosts_count\": \"678\",\n      \"publication_datetime\": \"2024-08-18T05:55:19.000Z\",\n      \"is_updated\": \"True\",\n      \"idea_strategy\": \"Short\"\n  }\n]\n```\n- When `export_result=True`, the default `export_type` is `'json'`, and a JSON file will be saved in the `/export` directory. To save as CSV, set `export_type='csv'`.\n\n### 3. Getting Indicators Status\nTo scrape the status of specific indicators, use the following code:\n```python\nfrom tradingview_scraper.symbols.technicals import Indicators\n\n# Initialize the Indicators scraper with export options\nindicators_scraper = Indicators(export_result=True, export_type='json')\n\n# Scrape indicators for the BTCUSD symbol from the BINANCE exchange\nindicators = indicators_scraper.scrape(\n    exchange=\"BINANCE\",\n    symbol=\"BTCUSD\",\n    timeframe=\"1d\",\n    indicators=[\"RSI\", \"Stoch.K\"]\n)\nprint(\"Indicators:\", indicators)\n```\n\n**Output:**\n```json\n{\"RSI\": \"46.34926112\", \"Stoch.K\": \"40.40173723\"}\n```\n\n### 4. Getting All Indicators\nIf you want to retrieve all available indicators for a symbol, set `allIndicators=True`:\n```python\nfrom tradingview_scraper.symbols.technicals import Indicators\n\n# Scrape all indicators for the BTCUSD symbol\nindicators_scraper = Indicators(export_result=True, export_type='json')\nindicators = indicators_scraper.scrape(\n    symbol=\"BTCUSD\",\n    timeframe=\"4h\",\n    allIndicators=True\n)\nprint(\"All Indicators:\", indicators)\n```\n\n### 5. Getting News Headlines/Content\n```python\n# Create an instance of the NewsScraper with export options\nnews_scraper = NewsScraper(export_result=True, export_type='json')\n\n# Retrieve news headlines from a specific provider\nnews_headlines = news_scraper.scrape_headlines(\n    symbol='BTCUSD',      # Uncomment and specify if needed\n    exchange='BINANCE', # Uncomment and specify if needed\n    # provider='newsbtc',  # Specify the news provider\n    # area='world',  # Specify the geographical area\n    # section='all',  # Specify the section of news\n    sort='latest'\n)\n\n# Retrieve detailed news content for a specific story\nnews_content = news_scraper.scrape_news_content(\n    story_path=news_headlines[0]['storyPath']  # Specify the story path from scraped headlines\n)\n```\n- Retrieve news by symbol:\n  - Both `symbol` and `exchange` are required parameters\n- Filter result by:\n  - `area`, `provider` and `section` can be specified to refine the news results.\n\n#### Output (news headline):\n```json\n[\n  {\n    \"breadcrumbs\": \"News > U.Today > Bitcoin ETFs Record Enormous Outflows\",\n    \"title\": \"Bitcoin ETFs Record Enormous Outflows\",\n    \"published_datetime\": \"Wed, 04 Sep 2024 07:55:38 GMT\",\n    \"related_symbols\": [\n      {\n        \"name\": \"BTCUSDT\",\n        \"logo\": \"https://s3-symbol-logo.tradingview.com/crypto/XTVCUSDT.svg\"\n      }\n    ],\n    \"body\": [\"\"\"<List of text page content>\"\"\"],\n    \"tags\": [\"Crypto\", \"U.Today\"]}\n]\n```\n#### Output (news content):\n```json\n[\n  {\n    \"id\": \"tag:reuters.com,2024:newsml_L1N3KM09S:0\",\n    \"title\": \"Goldman Sachs sees biggest boost to US economy from Harris win\",\n    \"provider\": \"reuters\",\n    \"sourceLogoId\": \"reuters\",\n    \"published\": 1725443676,\n    \"source\": \"Reuters\",\n    \"urgency\": 2,\n    \"permission\": \"preview\",\n    \"relatedSymbols\": [\n      {\n        \"symbol\": \"BITMEX:XBTETH.P\",\n        \"currency-logoid\": \"country/US\",\n        \"base-currency-logoid\": \"crypto/XTVCBTC\"\n      },\n      {\n        \"symbol\": \"ICEUS:DXY\",\n        \"logoid\": \"indices/u-s-dollar-index\"\n      }\n    ],\n    \"storyPath\": \"/news/reuters.com,2024:newsml_L1N3KM09S:0-goldman-sachs-sees-biggest-boost-to-us-economy-from-harris-win/\"\n  }\n]\n```\n\n## Changes:\n- Release `0.3.2`:\n  Support timeframe to get Indicators\n- Release `0.3.0`:   \n  Add news scraper\n- Release `0.2.9`:   \n  Refactor for new TradingView structure\n- Release `0.1.0`:  \n  The name of `ClassA` changed to `Ideas`\n\n## License:\n```\n[MIT]\n```",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Tradingview scraper tool",
    "version": "0.3.2",
    "project_urls": {
        "Download": "https://github.com/mnwato/tradingview-scraper/archive/refs/tags/0.3.2.zip",
        "Homepage": "https://github.com/mnwato/tradingview-scraper"
    },
    "split_keywords": [
        "tradingview",
        " scraper",
        " python",
        " crawler",
        " financial"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "12bef1cec16d3d673e7b824e7ead2b8f8e38d03fce5ce189a8de57ed018f61aa",
                "md5": "47f0f112dee84d29c6a9e83f0c682365",
                "sha256": "006c6f471baf79d9e98d8ec0f071e5b50951b45cbabd962c252d64cc43d309d2"
            },
            "downloads": -1,
            "filename": "tradingview-scraper-0.3.2.tar.gz",
            "has_sig": false,
            "md5_digest": "47f0f112dee84d29c6a9e83f0c682365",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 21594,
            "upload_time": "2024-11-29T15:36:08",
            "upload_time_iso_8601": "2024-11-29T15:36:08.273308Z",
            "url": "https://files.pythonhosted.org/packages/12/be/f1cec16d3d673e7b824e7ead2b8f8e38d03fce5ce189a8de57ed018f61aa/tradingview-scraper-0.3.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-29 15:36:08",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "mnwato",
    "github_project": "tradingview-scraper",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "tradingview-scraper"
}
        
Elapsed time: 0.38353s