Code Monkey home page Code Monkey logo

tradingview-selenium-data's Introduction

tradingview-selenium-data

Simple Selenium (Python Helium) script to pull TradingView data into CSV files

Objective

In order to perform useful backtesting and also create training data, it's useful to be able to download TradingView data as CSV data. This script uses a Python implementation of Selenum called Helium to pull of this data into CSV files.

Why use TradingView?

  • TradingView can provide longer time series than some of the other data APIs, although you need to scroll left for it to load that data.

  • Also TradingView will download data for your indicators into the CSV file also and that allows you to use that data in your backtests or ML training data.

  • It allows you to work together with others that use TradingView or Pinescript for building out potential strategies and indicators

WARNING - Scraping data this way does not seem to be against TradingView's current use policy but that might change. So check the use policy. And in any event, excessive scraping of any data is not the polite thing to do so keep this to the minimum and do so sparingly.

Getting started

Prerequisites

  1. You need a paid TradingView account with permissions to download data as a CSV. You know if you have the right sort of account if you can use the Export chart data ... option in the TradingView UI

  2. Python 3.8+ installed on your machine and some ability to use it.

  3. Google Chrome installed

  4. Relevant chromedriver installed for your version of Chrome - https://chromedriver.chromium.org/downloads

Installation

Clone the repo

git clone https://github.com/ttamg/tradingview-selenium-data.git

Either, install using poetry. From the cloned project directory

poetry install

Or alternatively install using pip from the cloned project directory

pip install -r requirements.txt

Scraping data

The scripts use the TradingView class that is in the scripts.common.tradingview module. This is a simple set of helium methods that interact with the TradingView UI

The TradingView class has methods that do the following:

  • Connect to TradingView and log in
  • Navigate to the chart layout you wish to download (with all the indicators you have defined)
  • Switch the asset or periodicity of the candles
  • Scroll to load the candles from a particular start date (so as to fetch more data)
  • Download the data as CSV

The class does not do anything particularly special beyond scraping and replicates what you would do with the UI yourself in the browser.

The run() method in the scripts.common.run module is a method that loops over the assets and periodicities you provide to fetch and download the market data you require. It calls the TradingView class at the relevant points.

See the Python code in scripts.common for more information.

NOTE - some of the HTML tags on TradingView are a bit brittle so this may need some tweaks from time to time as TradingView update their UI.

Scripts

See the example scripts in the scripts folder for examples on how to scrape data.

If all is set up correctly with your chromedriver the 00_example.py file should run the script and download a few test CSV files

python 00_example.py

Issues

Note that the asset given picks up the top of the list asset with that ticker. On TradingView there are many assets options with the same ticker so this may not pick up quite what you want. It is not obvious how this can be improved without significant work.

tradingview-selenium-data's People

Contributors

ttamg avatar

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.