# **NOTE**
This is a fork of the original [TvDatafeed](https://github.com/rongardF/tvdatafeed.git) project by StreamAlpha. This fork has live data retrieving feature implemented.
More information about this will be found in the TvDatafeedLive section down below in the README.
# **TvDatafeed**
A simple TradingView historical Data Downloader. Tvdatafeed allows downloading upto 5000 bars on any of the supported timeframe.
If you found the content useful and want to support my work, you can buy me a coffee!
[](https://www.buymeacoffee.com/StreamAlpha)
## Installation
This module can be installed from github repo
```sh
pip install --upgrade --no-cache-dir git+https://github.com/rongardF/tvdatafeed.git
```
For usage instructions, watch these videos-
v1.2 tutorial with installation and backtrader usage
[](https://youtu.be/f76dOZW2gwI)
Full tutorial
[](https://youtu.be/qDrXmb2ZRjo)
---
## About release 2.0.0
Version 2.0.0 is a major release and is not backward compatible. make sure you update your code accordingly. Thanks to [stefanomorni](https://github.com/stefanomorni) for contributing and removing selenium dependancy.
## Usage
Import the packages and initialize with your tradingview username and password.
```python
from tvDatafeed import TvDatafeed, Interval
username = 'YourTradingViewUsername'
password = 'YourTradingViewPassword'
tv = TvDatafeed(username, password)
```
You may use without logging in, but in some cases tradingview may limit the symbols and some symbols might not be available.
To use it without logging in
```python
tv = TvDatafeed()
```
when using without login, following warning will be shown `you are using nologin method, data you access may be limited`
---
## Getting Data
To download the data use `tv.get_hist` method.
It accepts following arguments and returns pandas dataframe
```python
(symbol: str, exchange: str = 'NSE', interval: Interval = Interval.in_daily, n_bars: int = 10, fut_contract: int | None = None, extended_session: bool = False) -> DataFrame)
```
for example-
```python
# index
nifty_index_data = tv.get_hist(symbol='NIFTY',exchange='NSE',interval=Interval.in_1_hour,n_bars=1000)
# futures continuous contract
nifty_futures_data = tv.get_hist(symbol='NIFTY',exchange='NSE',interval=Interval.in_1_hour,n_bars=1000,fut_contract=1)
# crudeoil
crudeoil_data = tv.get_hist(symbol='CRUDEOIL',exchange='MCX',interval=Interval.in_1_hour,n_bars=5000,fut_contract=1)
# downloading data for extended market hours
extended_price_data = tv.get_hist(symbol="EICHERMOT",exchange="NSE",interval=Interval.in_1_hour,n_bars=500, extended_session=False)
```
---
## Search Symbol
To find the exact symbols for an instrument you can use `tv.search_symbol` method.
You need to provide search text and optional exchange. This will return a list of macthing instruments and their symbol.
```python
tv.search_symbol('CRUDE','MCX')
```
---
## Calculating Indicators
Indicators data is not downloaded from tradingview. For that you can use [TA-Lib](https://github.com/mrjbq7/ta-lib). Check out this video for installation and usage instructions-
[](https://youtu.be/0MeHXJm9HRk)
---
## Live feed (TvDatafeedLive)
### Description
**TvDatafeedLive** is a sub-class of **TvDatafeed** to extend the functionality and provide live data feed feature. The live data feed feature means that the user can specify
symbol, exchange and interval set (also called as seis) for which they want the new data bar to be retrieved from TradingView whenever it is produced. The user can then
provide any number of callback functions for that seis which will be called with the newly retrieved data bar. Callback functions and retrieving data from TradingView is
implemented in threads so live data is as close to realtime as possible, but it **does not provide realtime** data samples!
### Usage
Import the packages and initialize with your tradingview username and password. As TvDatafeedLive is an extension of TvDatafeed class then all the rules about initialization
are the same.
```python
from tvDatafeed import TvDatafeedLive, Interval
username = 'YourTradingViewUsername'
password = 'YourTradingViewPassword'
tvl = TvDatafeedLive(username, password)
```
### Creating new seis
TvDatafeedLive works with **Seis** and **Consumer** objects. Seis is short for symbol-exchange-interval-set. It is a class to contain a unique combination of symbol, exchange
and interval values together with methods to make managing and using various symbols easier for the user.
User can create a new Seis by calling `tvl.new_seis` method.
```python
seis = tvl.new_seis('ETHUSDT', 'BINANCE', Interval.in_1_hour)
seis2 = tvl.new_seis('ETHUSDT', 'BINANCE', Interval.in_2_hour)
```
The interface for this method is similar to the `get_hist` method as it accepts the same three arguments - symbol, exchange and interval. Once the `seis` is created
it will automatically be added into live feed of `tvl`. This means that a thread will be created which will continously wait until new data bar is
produced for this symbol in TradingView and will retrieve it. If no consumer instances are added to `seis` then nothing will be done with the retrieved data
sample and it will be discarded.
All TvDatafeedLive method calls have an optional *timeout* parameter. TvDatafeedLive uses threading so method calls are blocking if the resources are in use. The user
can specify maximum amount to wait before aborting the call and returning. This parameter defaults to -1 which means no timeout.
```python
seis = tvl.new_seis('ETHUSDT', 'BINANCE', Interval.in_1_hour, timeout=10)
seis2 = tvl.new_seis('ETHUSDT', 'BINANCE', Interval.in_2_hour, timeout=10)
```
### Removing seis
The user can remove the `seis` from `tvl` using the `tvl.del_seis(seis)` or `seis.del_seis` method. In the former case the method must have the
`seis` to be deleted provided as an argument to reference a specific seis instance.
```python
tvl.del_seis(seis)
seis2.del_seis()
```
### Creating new consumer
The user can consume/use retrieved data by registering callback functions to `seis`. The `tvl.new_consumer` method accepts `seis` and a function as an argument
and returns a consumer object. The `seis.new_consumer` method simply needs the function as an argument. The function provided must follow the prototype function shown below:
```python
def consumer_func1(seis, data):
print("Open price for "+seis.symbol+" on "+seis.exchange+" exchange with "+seis.interval.name+" interval was "+str(data.open[0]))
def consumer_func2(seis, data):
print("Volume of "+seis.symbol+" on "+seis.exchange+" exchange with "+seis.interval.name+" interval was "+str(data.volume[0]))
def consumer_func3(seis, data):
print("Close price for "+seis.symbol+" on "+seis.exchange+" exchange with "+seis.interval.name+" interval was "+str(data.close[0]))
consumer1=tvl.new_consumer(seis, consumer_func1)
consumer2=seis.new_consumer(consumer_func2)
consumer3=seis.new_consumer(consumer_func3)
```
When there is new data produced and retrieved from TradingView for this seis then the provided function will
be called with `seis` and pandas DataFrame as arguments. The user can add one or many callback functions to `seis` - each of them will create a new
`consumer`.
### Removing consumer
The user can remove a `consumer` from `seis` by using the `tvl.del_consumer`, `seis.del_consumer` or `consumer.del_consumer` methods.
```python
tvl.del_consumer(consumer1)
seis.del_consumer(consumer2)
consumer3.del_consumer()
```
### Getting Data
TvDatafeedLive supports retrieving historic data in addition to retrieving live data. The user can use the `tvl.get_hist` or `seis.get_hist` method.
The former method has the same API as the TvDatafeed `get_hist` method, except it accepts one additional optional argument - `timeout`. This parameter
defaults to -1 which means no timeout. The `seis.get_hist` method only accepts two arguments - `n_bars` and `timeout`. Both of these parameters are
optional and default to 10 bars and no timeout.
```python
data=tvl.get_hist(symbol, exchange, interval=tvDatafeed.Interval.in_daily, n_bars=10, fut_contract=None, extended_session=False, timeout=-1)
data=seis.get_hist(n_bars=10, timeout=-1)
```
---
## Supported Time Intervals
Following timeframes intervals are supported-
`Interval.in_1_minute`
`Interval.in_3_minute`
`Interval.in_5_minute`
`Interval.in_15_minute`
`Interval.in_30_minute`
`Interval.in_45_minute`
`Interval.in_1_hour`
`Interval.in_2_hour`
`Interval.in_3_hour`
`Interval.in_4_hour`
`Interval.in_daily`
`Interval.in_weekly`
`Interval.in_monthly`
---
## Read this before creating an issue
Before creating an issue in this library, please follow the following steps.
1. Search the problem you are facing is already asked by someone else. There might be some issues already there, either solved/unsolved related to your problem. Go to [issues](https://github.com/StreamAlpha/tvdatafeed/issues) page, use `is:issue` as filter and search your problem. 
2. If you feel your problem is not asked by anyone or no issues are related to your problem, then create a new issue.
3. Describe your problem in detail while creating the issue. If you don't have time to detail/describe the problem you are facing, assume that I also won't be having time to respond to your problem.
4. Post a sample code of the problem you are facing. If I copy paste the code directly from issue, I should be able to reproduce the problem you are facing.
5. Before posting the sample code, test your sample code yourself once. Only sample code should be tested, no other addition should be there while you are testing.
6. Have some print() function calls to display the values of some variables related to your problem.
7. Post the results of print() functions also in the issue.
8. Use the insert code feature of github to inset code and print outputs, so that the code is displyed neat. !
9. If you have multiple lines of code, use tripple grave accent ( ``` ) to insert multiple lines of code.
[Example:](https://docs.github.com/en/github/writing-on-github/creating-and-highlighting-code-blocks)

Raw data
{
"_id": null,
"home_page": "https://github.com/demonarch/tvdatafeed/",
"name": "tradingview-datafeed",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "",
"author": "@StreamAlpha",
"author_email": "",
"download_url": "https://files.pythonhosted.org/packages/a6/4e/c3bfda76da31ddd25985b539e72fb1c502d8390540036fefbe63d63b681a/tradingview-datafeed-2.1.1.tar.gz",
"platform": null,
"description": "# **NOTE**\n\nThis is a fork of the original [TvDatafeed](https://github.com/rongardF/tvdatafeed.git) project by StreamAlpha. This fork has live data retrieving feature implemented. \nMore information about this will be found in the TvDatafeedLive section down below in the README.\n\n# **TvDatafeed**\n\nA simple TradingView historical Data Downloader. Tvdatafeed allows downloading upto 5000 bars on any of the supported timeframe.\n\nIf you found the content useful and want to support my work, you can buy me a coffee!\n[](https://www.buymeacoffee.com/StreamAlpha)\n\n## Installation\n\nThis module can be installed from github repo\n\n```sh\npip install --upgrade --no-cache-dir git+https://github.com/rongardF/tvdatafeed.git\n```\n\nFor usage instructions, watch these videos-\n\nv1.2 tutorial with installation and backtrader usage\n\n[](https://youtu.be/f76dOZW2gwI)\n\nFull tutorial\n\n[](https://youtu.be/qDrXmb2ZRjo)\n\n---\n\n## About release 2.0.0\n\nVersion 2.0.0 is a major release and is not backward compatible. make sure you update your code accordingly. Thanks to [stefanomorni](https://github.com/stefanomorni) for contributing and removing selenium dependancy.\n\n## Usage\n\nImport the packages and initialize with your tradingview username and password.\n\n```python\nfrom tvDatafeed import TvDatafeed, Interval\n\nusername = 'YourTradingViewUsername'\npassword = 'YourTradingViewPassword'\n\ntv = TvDatafeed(username, password)\n```\n\nYou may use without logging in, but in some cases tradingview may limit the symbols and some symbols might not be available.\n\nTo use it without logging in\n\n```python\ntv = TvDatafeed()\n```\n\nwhen using without login, following warning will be shown `you are using nologin method, data you access may be limited`\n\n---\n\n## Getting Data\n\nTo download the data use `tv.get_hist` method.\n\nIt accepts following arguments and returns pandas dataframe\n\n```python\n(symbol: str, exchange: str = 'NSE', interval: Interval = Interval.in_daily, n_bars: int = 10, fut_contract: int | None = None, extended_session: bool = False) -> DataFrame)\n```\n\nfor example-\n\n```python\n# index\nnifty_index_data = tv.get_hist(symbol='NIFTY',exchange='NSE',interval=Interval.in_1_hour,n_bars=1000)\n\n# futures continuous contract\nnifty_futures_data = tv.get_hist(symbol='NIFTY',exchange='NSE',interval=Interval.in_1_hour,n_bars=1000,fut_contract=1)\n\n# crudeoil\ncrudeoil_data = tv.get_hist(symbol='CRUDEOIL',exchange='MCX',interval=Interval.in_1_hour,n_bars=5000,fut_contract=1)\n\n# downloading data for extended market hours\nextended_price_data = tv.get_hist(symbol=\"EICHERMOT\",exchange=\"NSE\",interval=Interval.in_1_hour,n_bars=500, extended_session=False)\n```\n\n---\n\n## Search Symbol\n\nTo find the exact symbols for an instrument you can use `tv.search_symbol` method.\n\nYou need to provide search text and optional exchange. This will return a list of macthing instruments and their symbol.\n\n```python\ntv.search_symbol('CRUDE','MCX')\n```\n\n---\n\n## Calculating Indicators\n\nIndicators data is not downloaded from tradingview. For that you can use [TA-Lib](https://github.com/mrjbq7/ta-lib). Check out this video for installation and usage instructions-\n\n[](https://youtu.be/0MeHXJm9HRk)\n\n---\n\n## Live feed (TvDatafeedLive)\n\n### Description\n\n**TvDatafeedLive** is a sub-class of **TvDatafeed** to extend the functionality and provide live data feed feature. The live data feed feature means that the user can specify\nsymbol, exchange and interval set (also called as seis) for which they want the new data bar to be retrieved from TradingView whenever it is produced. The user can then\nprovide any number of callback functions for that seis which will be called with the newly retrieved data bar. Callback functions and retrieving data from TradingView is\nimplemented in threads so live data is as close to realtime as possible, but it **does not provide realtime** data samples!\n\n### Usage\n\nImport the packages and initialize with your tradingview username and password. As TvDatafeedLive is an extension of TvDatafeed class then all the rules about initialization\nare the same.\n\n```python\nfrom tvDatafeed import TvDatafeedLive, Interval\n\nusername = 'YourTradingViewUsername'\npassword = 'YourTradingViewPassword'\n\ntvl = TvDatafeedLive(username, password)\n```\n\n### Creating new seis\n\nTvDatafeedLive works with **Seis** and **Consumer** objects. Seis is short for symbol-exchange-interval-set. It is a class to contain a unique combination of symbol, exchange\nand interval values together with methods to make managing and using various symbols easier for the user.\n\nUser can create a new Seis by calling `tvl.new_seis` method.\n\n```python\n\nseis = tvl.new_seis('ETHUSDT', 'BINANCE', Interval.in_1_hour)\nseis2 = tvl.new_seis('ETHUSDT', 'BINANCE', Interval.in_2_hour)\n\n```\n\nThe interface for this method is similar to the `get_hist` method as it accepts the same three arguments - symbol, exchange and interval. Once the `seis` is created\nit will automatically be added into live feed of `tvl`. This means that a thread will be created which will continously wait until new data bar is \nproduced for this symbol in TradingView and will retrieve it. If no consumer instances are added to `seis` then nothing will be done with the retrieved data \nsample and it will be discarded.\n\nAll TvDatafeedLive method calls have an optional *timeout* parameter. TvDatafeedLive uses threading so method calls are blocking if the resources are in use. The user \ncan specify maximum amount to wait before aborting the call and returning. This parameter defaults to -1 which means no timeout.\n\n```python\n\nseis = tvl.new_seis('ETHUSDT', 'BINANCE', Interval.in_1_hour, timeout=10)\nseis2 = tvl.new_seis('ETHUSDT', 'BINANCE', Interval.in_2_hour, timeout=10)\n\n```\n\n### Removing seis\n\nThe user can remove the `seis` from `tvl` using the `tvl.del_seis(seis)` or `seis.del_seis` method. In the former case the method must have the \n`seis` to be deleted provided as an argument to reference a specific seis instance.\n\n```python\n\ntvl.del_seis(seis)\nseis2.del_seis()\n\n```\n\n### Creating new consumer\n\nThe user can consume/use retrieved data by registering callback functions to `seis`. The `tvl.new_consumer` method accepts `seis` and a function as an argument\nand returns a consumer object. The `seis.new_consumer` method simply needs the function as an argument. The function provided must follow the prototype function shown below:\n\n```python\n\ndef consumer_func1(seis, data):\n\tprint(\"Open price for \"+seis.symbol+\" on \"+seis.exchange+\" exchange with \"+seis.interval.name+\" interval was \"+str(data.open[0]))\n\ndef consumer_func2(seis, data):\n\tprint(\"Volume of \"+seis.symbol+\" on \"+seis.exchange+\" exchange with \"+seis.interval.name+\" interval was \"+str(data.volume[0]))\n\ndef consumer_func3(seis, data):\n\tprint(\"Close price for \"+seis.symbol+\" on \"+seis.exchange+\" exchange with \"+seis.interval.name+\" interval was \"+str(data.close[0]))\n\nconsumer1=tvl.new_consumer(seis, consumer_func1)\nconsumer2=seis.new_consumer(consumer_func2)\nconsumer3=seis.new_consumer(consumer_func3)\n\n```\n\nWhen there is new data produced and retrieved from TradingView for this seis then the provided function will\nbe called with `seis` and pandas DataFrame as arguments. The user can add one or many callback functions to `seis` - each of them will create a new\n`consumer`.\n\n### Removing consumer\n\nThe user can remove a `consumer` from `seis` by using the `tvl.del_consumer`, `seis.del_consumer` or `consumer.del_consumer` methods.\n\n```python\n\ntvl.del_consumer(consumer1)\nseis.del_consumer(consumer2)\nconsumer3.del_consumer()\n\n```\n\n### Getting Data\n\nTvDatafeedLive supports retrieving historic data in addition to retrieving live data. The user can use the `tvl.get_hist` or `seis.get_hist` method. \nThe former method has the same API as the TvDatafeed `get_hist` method, except it accepts one additional optional argument - `timeout`. This parameter \ndefaults to -1 which means no timeout. The `seis.get_hist` method only accepts two arguments - `n_bars` and `timeout`. Both of these parameters are\noptional and default to 10 bars and no timeout.\n\n```python\n\ndata=tvl.get_hist(symbol, exchange, interval=tvDatafeed.Interval.in_daily, n_bars=10, fut_contract=None, extended_session=False, timeout=-1)\ndata=seis.get_hist(n_bars=10, timeout=-1)\n\n```\n\n---\n\n## Supported Time Intervals\n\nFollowing timeframes intervals are supported-\n\n`Interval.in_1_minute`\n\n`Interval.in_3_minute`\n\n`Interval.in_5_minute`\n\n`Interval.in_15_minute`\n\n`Interval.in_30_minute`\n\n`Interval.in_45_minute`\n\n`Interval.in_1_hour`\n\n`Interval.in_2_hour`\n\n`Interval.in_3_hour`\n\n`Interval.in_4_hour`\n\n`Interval.in_daily`\n\n`Interval.in_weekly`\n\n`Interval.in_monthly`\n\n---\n\n## Read this before creating an issue\n\nBefore creating an issue in this library, please follow the following steps.\n\n1. Search the problem you are facing is already asked by someone else. There might be some issues already there, either solved/unsolved related to your problem. Go to [issues](https://github.com/StreamAlpha/tvdatafeed/issues) page, use `is:issue` as filter and search your problem. \n2. If you feel your problem is not asked by anyone or no issues are related to your problem, then create a new issue.\n3. Describe your problem in detail while creating the issue. If you don't have time to detail/describe the problem you are facing, assume that I also won't be having time to respond to your problem.\n4. Post a sample code of the problem you are facing. If I copy paste the code directly from issue, I should be able to reproduce the problem you are facing.\n5. Before posting the sample code, test your sample code yourself once. Only sample code should be tested, no other addition should be there while you are testing.\n6. Have some print() function calls to display the values of some variables related to your problem.\n7. Post the results of print() functions also in the issue.\n8. Use the insert code feature of github to inset code and print outputs, so that the code is displyed neat. !\n9. If you have multiple lines of code, use tripple grave accent ( ``` ) to insert multiple lines of code.\n\n [Example:](https://docs.github.com/en/github/writing-on-github/creating-and-highlighting-code-blocks)\n\n \n",
"bugtrack_url": null,
"license": "MIT License",
"summary": "TradingView historical data downloader",
"version": "2.1.1",
"project_urls": {
"Funding": "https://www.buymeacoffee.com/StreamAlpha",
"Homepage": "https://github.com/demonarch/tvdatafeed/",
"Source": "https://github.com/StreamAlpha/tvdatafeed/",
"Telegram Channel": "https://t.me/streamAlpha",
"Tracker": "https://github.com/StreamAlpha/tvdatafeed/issues",
"YouTube": "https://youtube.com/StreamAlpha?sub_confirmation=1"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "5b1e7e91de87db9ef194db8966860b3ec8b32d23bab2d8e3bf1481ef83064463",
"md5": "44f43b0b778f0cc64e898cd84ad91bc7",
"sha256": "2d008dbccc2e98778c7f9825046243873e37e933be7c3f061db66efc0dba83d7"
},
"downloads": -1,
"filename": "tradingview_datafeed-2.1.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "44f43b0b778f0cc64e898cd84ad91bc7",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 17679,
"upload_time": "2024-03-16T13:02:57",
"upload_time_iso_8601": "2024-03-16T13:02:57.016125Z",
"url": "https://files.pythonhosted.org/packages/5b/1e/7e91de87db9ef194db8966860b3ec8b32d23bab2d8e3bf1481ef83064463/tradingview_datafeed-2.1.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "a64ec3bfda76da31ddd25985b539e72fb1c502d8390540036fefbe63d63b681a",
"md5": "568ad3fdb4e28982b68056e91dd852d7",
"sha256": "875b8e537d7846f910a57eda754fa1192b94b6e75d0f7676ff34f84cbe2bfc8b"
},
"downloads": -1,
"filename": "tradingview-datafeed-2.1.1.tar.gz",
"has_sig": false,
"md5_digest": "568ad3fdb4e28982b68056e91dd852d7",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 16222,
"upload_time": "2024-03-16T13:02:59",
"upload_time_iso_8601": "2024-03-16T13:02:59.124506Z",
"url": "https://files.pythonhosted.org/packages/a6/4e/c3bfda76da31ddd25985b539e72fb1c502d8390540036fefbe63d63b681a/tradingview-datafeed-2.1.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-03-16 13:02:59",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "demonarch",
"github_project": "tvdatafeed",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [
{
"name": "setuptools",
"specs": [
[
"~=",
"49.2.0"
]
]
},
{
"name": "pandas",
"specs": [
[
"~=",
"1.0.5"
]
]
},
{
"name": "websocket-client",
"specs": [
[
"~=",
"0.57.0"
]
]
},
{
"name": "requests",
"specs": []
}
],
"lcname": "tradingview-datafeed"
}