# Official Python repository for TrueData (Market Data APIs)
----
This Python library attempts to make it easy for you to connect to TrueData Market Data Apis, thereby allowing you to concentrate on startegy development, while this library works to get you all the data you need from the TrueData backend both for Real Time & Historical.
Please make sure you follow us on our Telegram channel where we push a lot of information with regards to API updates, implementation ideas, tips & tricks to use this library & raw feed, etc...
* [TrueData Market Data API - Telegram Channel](https://t.me/truedata_ws_api)
* [TrueData Market Data APIs - Website](https://www.truedata.in/api)
We have also built a sandbox environmemt for testing the raw feed. Please feel free to use this environment to check/test/compare your results with the raw data feed (real time & historical).
* [TrueData Market Data API - Sandbox Environment](https://wstest.truedata.in)
* [sample code to use Truedata package](https://github.com/Nahas-N/Truedata-sample-code)
We are trying to improve this library continuously and feedback for the same is welcome.
It is essential to ensure that the data received through our APIs is not being utilized for any commercial purposes. Additionally, please be mindful that all information or data provided to you is exclusively intended for your internal use and must be utilized and discontinued at your end as required.
----
## What have we covered so far ?
we have total three packages live , historical and analytics
**WebSocket APIs**
* Live data (Streaming Ticks) - Enabled by Default
* Live Data (Streaming 1 min bars) - Needs to be enabled from our backend
* Live Data (Streaming 5 min bars) - Needs to be enabled from our backend
* Live data (Streaming Ticks + 1 min bars) - Needs to be enabled from our backend
* Live Data (Streaming Ticks + 5 min bars) - Needs to be enabled from our backend
* Live Data (Streaming Ticks + 1 min bars + 5 min bars) - Needs to be enabled from our backend
* Live Data (Streaming 1 min + 5 min bars) - Needs to be enabled from our backend
* Option Greek streaming - Needs to be enabled from our backend
Note:- Kindly note that data that is not enabled by default may require exchange approvals, which vary depending on the specific exchange and segment in question. For any inquiries or clarifications, please feel free to reach out to our dedicated support team.
**REST APIs**
* Historical Data
* Analytical Data
----
# Getting Started
**Installation**
* Installing the truedata library from PyPi
```shell script
python3 -m pip install truedata
```
**Minimum Requirements**
```
- Python >= 3.10
In-built dependencies
- websocket-client>=0.57.0
- colorama>=0.4.3
- python-dateutil>=2.8.1
- pandas>=1.0.3
- setuptools>=50.3.2
- requests>=2.25.0
- tqdm>=4.66.6
- lz4==3.1.3 (Note lz4 versions >3.1.3 currently have some errors and thus
lz4 should not be upgraded till these dependency issues are resolved).
```
**Connecting / Logging in**
* Connecting / Logging in for Real time data feed subscriptions
```python
from truedata import TD_live
td_obj = TD_live('<enter_your_login_id>', '<enter_your_password>' )
```
* Connecting / Logging in for Historical Data Subscription Only
```python
from truedata import TD_hist
td_hist = TD_hist('<enter_your_login_id>', '<enter_your_password>')
```
**importing multiple module from truedata package**
* to use live and history module together
```python
from truedata import TD_live, TD_hist
td_obj = TD_live('<enter_your_login_id>', '<enter_your_password>' )
td_hist = TD_hist('<enter_your_login_id>', '<enter_your_password>' )
```
# Logging
We have integrated the python stdlib logger.
You can provide LOG_LEVEL, LOG_HANDLER and LOG_FORMAT if you want.
Please try with various log levels & formats to understand what works best for you for a particular setting. Below are 2 samples provided to you. Please test with both to see what works best for you.
```python
from truedata import TD_live
import logging
td_obj = TD_live('<enter_your_login_id>', '<enter_your_password>', live_port=realtime_port, url=url,
log_level=logging.WARNING, log_format="%(message)s")
```
To enable the *Heartbeats*, change your logging level to DEBUG as follows:-
```python
log_level=logging.DEBUG
```
The logging level to DEBUG, enables you to see:-
1) Market Status messages (Market Open / Close messages as and when they happen)
2) Automatic Touchline update messages
3) Symbol Add Remove messages
4) Heartbeat messages (every 5 seconds)
If you do not want to see these messages, set your logging level to WARNING
Additional LOG_LEVEL info can be found [here](https://docs.python.org/3/library/logging.html#logging-levels).
Additional LOG_FORMAT info can be found [here](https://docs.python.org/3/library/logging.html#logrecord-attributes).
Additional LOG_HANDER info can be found [here](https://docs.python.org/3/library/logging.html#handler-objects).
----
# Real Time Data Streaming (Live)
* Starting Live Data For Multiple symbols
```python
symbols = ['<symbol_1>', '<symbol_2>', '<symbol_3>', ...]
td_obj.start_live_data(symbols)
```
* Accessing live streaming data
all livedata information available inside td_obj.live_data dict can be accessed via symbol as key. if new data for the same symbol comes then it will replace with latest data.
```python
td_obj.live_data[symbol_1]
```
> if subscribed to `1 Min` streaming bar data can be found at `td_obj.one_min_live_data[symbol_1]`.
>
>if subcribed to `5 Min` streaming bar data can be found at `td_obj.five_min_live_data[symbol_1]`.
* all data can be accessed with dot access
```python
ltp = td_obj.live_data[symbol_1].ltp
timestamp = td_obj.live_data[symbol_1].timestamp
```
* live_data available fields are
```python
["timestamp","symbol_id","symbol","ltp","ltq","atp","ttq","day_open","day_high","day_low","prev_day_close","oi","prev_day_oi","turnover","special_tag","tick_seq","best_bid_price","best_bid_qty","best_ask_price","best_ask_qty","change","change_perc","oi_change","oi_change_perc" ]
```
one_min_live_data and five_min_live_data available fields are
```python
[ "symbol", "symbol_id", "day_open", "day_high", "day_low", "prev_day_close", "prev_day_oi", "oi", "ttq", "timestamp", "open", "high", "low", "close", "volume", "change","change_perc","oi_change","oi_change_perc" ]
```
* callback functions
* Accessing live streaming data
user need to define callback function for ticks or minute stream according to their subscription. if callback function defined then when ever new tick or minute bar received then the corresponding callback function will be executed, so please dont block the functions using any indefinite loops
* available call back decorators are mentioned below . all fields corresponding tick_data or bar_data can be accessed with dotaccess mentioned above
```python
@td_obj.trade_callback
def my_tick_data( tick_data):
print( "tick data " , tick_data )
@td_obj.bidask_callback
def my_bidask_data( bidask_data):
print("bid ask data" , bidask_data)
@td_obj.one_min_bar_callback
def my_one_min_bar_data( bar_data):
print("one min bar data ", bar_data)
@td_obj.five_min_bar_callback
def my_five_min_bar_data( bar_data):
print( "five min bar data ", bar_data)
@td_obj.greek_callback
def my_greek_data( greek_data):
print("greek data ", greek_data)
@td_obj.full_feed_trade_callback
def my_ff_trade_data( tick_data):
print("full feed tick ", tick_data)
@td_obj.full_feed_bar_callback
def my_ff_min_bar_data( bar_data):
print("full feed bar ", bar_data )
```
* Stopping live data
```python
td_obj.stop_live_data(['<symbol_1>', '<symbol_2>', '<symbol_3>', ...])
```
* Disconnect from the WebSocket service
```python
td_obj.disconnect()
```
----
# Option Greeks streaming
If user is subscribed to Nse options and also opt for option greek then whenever new greek data arrived the below function executed.
```Python
@td_obj.greek_callback
def mygreek_callback( greek_data):
print("Greek > ", greek_data)
```
* These are available fields for greek_data ->
```python
[ "timestamp", "symbol_id", "symbol", "iv", "delta", "theta", "gamma", "vega", "rho" ]
```
* Each field can be accessed with dot access such as greek_data.symbol , greek_data.delta etc...
----
# Bidask Streaming
If user is subscribed to bidask then whenever new bidask changed in exchange the below function executed.
```Python
@td_obj.bidask_callback
def mybidask_callback( bidask_data):
print("BidAsk > ", bidask_data )
```
* These are available fields for bidask_data ->
```python
[ "timestamp", "symbol_id", "symbol", "bid", "ask", "total_bid", "total_ask" ]
```
* Each field can be accessed with dot access such as bidask_data.symbol , bidask_data.ask etc...
* For Nse symbols we offer level 1 bid ask which have one best bid and ask data.
* For bse symbols we offer level 2 bid ask which have five best bid and ask data.
* For level 1 bid ask -> bidask_data.ask return with a list of tuples, containing ```[ ( ask, ask_qnty )]``` in the format, This has total length of one.
* For level 2 bid ask -> bidask_data.ask return with a list of tuples, containing ```[ ( ask_1, ask_1_qnty, ask_1_no_of_trades ) , ( ask_2, ask_2_qnty, ask_2_no_of_trades ) , ....... ]``` in the format , This has total length of five in bid and also same as the ask.
----
**QUICK START LIVE DATA CODE**
All code snippet can be found [here](https://github.com/Nahas-N/Truedata-sample-code).
----
**CONVERTING REAL TIME STREAM TO DICT**
if you need to convert the stream data to dict, use the dunder __dict__ method.
```python
td_obj.live_data[symbol_1].to_dict()
tick_data.to_dict()
```
----
# Option Chain Streaming
It is possible to stream single or multiple option chains.
```symbols , strike , type , ltp , ltt , ltq , volume , price_change , price_change_perc, oi , prev_oi , oi_change , oi_change_perc , bid ,bid_qty , ask , ask_qty , iv, delta, theta, gamma, vega, rho```
**Starting Option Chain data for a symbol**
```python
nifty_chain = td_obj.start_option_chain( 'NIFTY' , dt(2021 , 8 , 26) )
sensex_chain = td_obj.start_option_chain("SENSEX" , dt(2023 , 9 , 1) , chain_length = 80 )
#enabling option chain for NIFTY with corresponding expiry.
```
* start_option_chain function takes following arguments:
* symbols for egs: NIFTY , BANKNIFTY , SBIN etc......
* expiry : date (datetime object)
* chain_length : number of strike need to pull with respect to future prices. default value is 10 (int)
* bid_ask : enable live quote . default value is false (boolean)
* greek : boolean, default value is false if need to stream greeks along with option chain
**Pulling an Option Chain**
```python
df = nifty_chain.get_option_chain()
#returns a dataframe that contain option chain for repective symbol
```
this get_option_chain function can call anywhere that will return respective option chain
**Stop Option Chain Updates**
```python
nifty_chain.stop_option_chain()
```
**An example for pulling option chain and live data simultaneously**
code snippet can be found [here](https://github.com/Nahas-N/Truedata-sample-code).
----
# Historical Data
>Historical Data is provided over REST
In version v6 we have seperated live and history as modules. so please import according to your configuration.
All historical success call return pandas dataframe.
importing historical module
```python
from truedata import TD_hist
import logging
td_hist = TD_hist(username ,password , log_level= logging.WARNING )
```
all these are the available methods in historical module.
```python
td_hist.get_historic_data('BANKNIFTY-I')
td_hist.get_historic_data('BANKNIFTY-I', duration='3 D')
td_hist.get_historic_data('BANKNIFTY-I', bar_size='30 mins')
td_hist.get_historic_data('BANKNIFTY-I', start_time=datetime.now()-relativedelta(days=3))
td_hist.get_historic_data('BANKNIFTY-I', end_time=datetime(2023, 11, 17, 12, 30))
td_hist.get_historic_data("BANKNIFTY-I", duration='2 D', bar_size='ticks', bidask=True , delivery = True)
td_hist.get_n_historical_bars('BANKNIFTY-I', no_of_bars=30, bar_size= '5 min')
td_hist.get_n_historical_bars("BANKNIFTY-I", no_of_bars=10, bar_size= 'ticks')
td_hist.get_gainers("NSEEQ", topn = 25 )
td_hist.get_losers("NSEEQ", topn = 25 )
td_hist.get_bhavcopy('EQ' , date=datetime(2023, 11, 16) )
td_hist.get_bhavcopy('FO')
result = td_hist.get_historic_data("NIFTY BANK", duration='1 D', bar_size='tick')
# print(result.to_dict(orient = 'records'))
```
**IMPORTANT NOTE:**
* all method returns pandas dataframe if want to convert to list of dict please use pandas inherent method `result.to_dict(orient = 'records')`
Now that we have covered the basic parameters, you can mix and match the parameters as you please. If a parameter is not specified, the defaults are as follows
```python
end_time = datetime.now()
duration = "1 D"
bar_size = "1 min"
```
**Get Bhavcopy**
This function enables you to get the NSE & MCX bhavcopies for the day / date.
```python
eq_bhav = td_obj.get_bhavcopy('EQ')
fo_bhav = td_obj.get_bhavcopy('FO')
mcx_bhav = td_obj.get_bhavcopy('MCX')
```
The request checks if the latest completed bhavcopy has arrived for that segment and, if arrived, it returns the data.
In case it has not arrived it provides the date and time of the last bhavcopy available which can also be pulled by providing the bhavcopy date.
**Limitations and caveats for historical data**
1) If you provide both duration and start time, duration will be used and start time will be ignored.
2) If you provide neither duration nor start time, duration = "1 D" will be used
3) If you do not provide the bar size bar_size = "1 min" will be used
4) The following BAR_SIZES are available:
- tick
- 1 min
- 2 mins
- 3 mins
- 5 mins
- 10 mins
- 15 mins
- 30 mins
- 60 mins
- eod (or EOD)
- week (or WEEK)
- month (or MONTH)
5) The following annotation can be used for DURATION:-
- D = Days
- W = Weeks
- M = Months
- Y = Years
**Get Gainers losers information**
This function enables you to get the NSE gainers losers information at present state.
```python
gainers = td_obj.get_gainers(segment = "NSEEQ" , topn= 10 )
losers = td_obj.get_losers(segment = "NSEEQ" , topn= 10 )
```
* gainers , losers function takes following arguments:
* segment (string) : NSEEQ, NSEFUT, NSEOPT, MCX
* topn (int) : default 10 , top n number
----
# Release Notes
Version 7.0.1
* bugfix for the compression
Version 7.0.0
* all websocket messages are compressed for performance improvments by default.
Version 6.0.7
* bug fix and performance improved
Version 6.0.5
* added compression in analytical calls for faster perfomance
Version 6.0.4
* removing automatic reconnection after manual disconnection
Version 6.0.3
* lz4 version released to latest one without prebuild
Version 6.0.2
* analytics new methods added
Version 6.0.0
* change: TD_live and TD_hist are two new modules under the package of truedata
* change: option chain are coming with greeks
* change: all historical calls returns pandas dataframe
* change: while loop methods are deprecated only efficient call back method is available now.
* change: TD_analytics module is added to package
Raw data
{
"_id": null,
"home_page": "https://github.com/kapilmar/truedata-ws",
"name": "truedata",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": null,
"keywords": null,
"author": "Nahas N",
"author_email": "nahas@truedata.in",
"download_url": "https://files.pythonhosted.org/packages/de/71/820f6d53dbbb5a0a478b5a0df6817a87e113cab7d2e446469a5915564168/truedata-7.0.1.tar.gz",
"platform": null,
"description": "# Official Python repository for TrueData (Market Data APIs)\r\n----\r\nThis Python library attempts to make it easy for you to connect to TrueData Market Data Apis, thereby allowing you to concentrate on startegy development, while this library works to get you all the data you need from the TrueData backend both for Real Time & Historical.\r\n\r\nPlease make sure you follow us on our Telegram channel where we push a lot of information with regards to API updates, implementation ideas, tips & tricks to use this library & raw feed, etc...\r\n* [TrueData Market Data API - Telegram Channel](https://t.me/truedata_ws_api)\r\n* [TrueData Market Data APIs - Website](https://www.truedata.in/api)\r\n\r\nWe have also built a sandbox environmemt for testing the raw feed. Please feel free to use this environment to check/test/compare your results with the raw data feed (real time & historical).\r\n* [TrueData Market Data API - Sandbox Environment](https://wstest.truedata.in)\r\n* [sample code to use Truedata package](https://github.com/Nahas-N/Truedata-sample-code)\r\n\r\nWe are trying to improve this library continuously and feedback for the same is welcome. \r\n\r\nIt is essential to ensure that the data received through our APIs is not being utilized for any commercial purposes. Additionally, please be mindful that all information or data provided to you is exclusively intended for your internal use and must be utilized and discontinued at your end as required.\r\n\r\n----\r\n## What have we covered so far ?\r\n\r\nwe have total three packages live , historical and analytics\r\n\r\n**WebSocket APIs**\r\n\r\n * Live data (Streaming Ticks) - Enabled by Default\r\n * Live Data (Streaming 1 min bars) - Needs to be enabled from our backend\r\n * Live Data (Streaming 5 min bars) - Needs to be enabled from our backend \r\n * Live data (Streaming Ticks + 1 min bars) - Needs to be enabled from our backend\r\n * Live Data (Streaming Ticks + 5 min bars) - Needs to be enabled from our backend\r\n * Live Data (Streaming Ticks + 1 min bars + 5 min bars) - Needs to be enabled from our backend\r\n * Live Data (Streaming 1 min + 5 min bars) - Needs to be enabled from our backend \r\n * Option Greek streaming - Needs to be enabled from our backend\r\n\r\nNote:- Kindly note that data that is not enabled by default may require exchange approvals, which vary depending on the specific exchange and segment in question. For any inquiries or clarifications, please feel free to reach out to our dedicated support team.\r\n\r\n**REST APIs**\r\n\r\n * Historical Data\r\n * Analytical Data\r\n \r\n----\r\n# Getting Started \r\n**Installation**\r\n\r\n* Installing the truedata library from PyPi\r\n```shell script\r\npython3 -m pip install truedata\r\n```\r\n\r\n**Minimum Requirements**\r\n```\r\n- Python >= 3.10\r\n\r\nIn-built dependencies\r\n\r\n- websocket-client>=0.57.0\r\n- colorama>=0.4.3\r\n- python-dateutil>=2.8.1\r\n- pandas>=1.0.3\r\n- setuptools>=50.3.2\r\n- requests>=2.25.0\r\n- tqdm>=4.66.6\r\n- lz4==3.1.3 (Note lz4 versions >3.1.3 currently have some errors and thus\r\n lz4 should not be upgraded till these dependency issues are resolved).\r\n\r\n```\r\n\r\n**Connecting / Logging in**\r\n* Connecting / Logging in for Real time data feed subscriptions\r\n```python\r\nfrom truedata import TD_live\r\ntd_obj = TD_live('<enter_your_login_id>', '<enter_your_password>' )\r\n```\r\n* Connecting / Logging in for Historical Data Subscription Only\r\n```python\r\nfrom truedata import TD_hist\r\ntd_hist = TD_hist('<enter_your_login_id>', '<enter_your_password>')\r\n```\r\n**importing multiple module from truedata package**\r\n\r\n* to use live and history module together \r\n```python\r\nfrom truedata import TD_live, TD_hist\r\ntd_obj = TD_live('<enter_your_login_id>', '<enter_your_password>' )\r\ntd_hist = TD_hist('<enter_your_login_id>', '<enter_your_password>' )\r\n```\r\n\r\n\r\n# Logging\r\n\r\nWe have integrated the python stdlib logger.\r\n\r\nYou can provide LOG_LEVEL, LOG_HANDLER and LOG_FORMAT if you want.\r\n\r\nPlease try with various log levels & formats to understand what works best for you for a particular setting. Below are 2 samples provided to you. Please test with both to see what works best for you.\r\n \r\n\r\n```python\r\nfrom truedata import TD_live\r\nimport logging\r\ntd_obj = TD_live('<enter_your_login_id>', '<enter_your_password>', live_port=realtime_port, url=url, \r\n log_level=logging.WARNING, log_format=\"%(message)s\")\r\n```\r\nTo enable the *Heartbeats*, change your logging level to DEBUG as follows:-\r\n\r\n```python\r\nlog_level=logging.DEBUG\r\n```\r\nThe logging level to DEBUG, enables you to see:-\r\n\r\n1) Market Status messages (Market Open / Close messages as and when they happen) \r\n2) Automatic Touchline update messages\r\n3) Symbol Add Remove messages\r\n4) Heartbeat messages (every 5 seconds)\r\n\r\nIf you do not want to see these messages, set your logging level to WARNING\r\n\r\nAdditional LOG_LEVEL info can be found [here](https://docs.python.org/3/library/logging.html#logging-levels). \r\n\r\nAdditional LOG_FORMAT info can be found [here](https://docs.python.org/3/library/logging.html#logrecord-attributes).\r\n\r\nAdditional LOG_HANDER info can be found [here](https://docs.python.org/3/library/logging.html#handler-objects).\r\n\r\n----\r\n# Real Time Data Streaming (Live)\r\n* Starting Live Data For Multiple symbols\r\n\r\n```python\r\nsymbols = ['<symbol_1>', '<symbol_2>', '<symbol_3>', ...]\r\ntd_obj.start_live_data(symbols)\r\n```\r\n\r\n* Accessing live streaming data\r\n \r\n all livedata information available inside td_obj.live_data dict can be accessed via symbol as key. if new data for the same symbol comes then it will replace with latest data.\r\n```python\r\ntd_obj.live_data[symbol_1]\r\n```\r\n\r\n> if subscribed to `1 Min` streaming bar data can be found at `td_obj.one_min_live_data[symbol_1]`.\r\n> \r\n>if subcribed to `5 Min` streaming bar data can be found at `td_obj.five_min_live_data[symbol_1]`.\r\n\r\n* all data can be accessed with dot access\r\n```python\r\nltp = td_obj.live_data[symbol_1].ltp\r\ntimestamp = td_obj.live_data[symbol_1].timestamp\r\n```\r\n* live_data available fields are \r\n \r\n```python\r\n[\"timestamp\",\"symbol_id\",\"symbol\",\"ltp\",\"ltq\",\"atp\",\"ttq\",\"day_open\",\"day_high\",\"day_low\",\"prev_day_close\",\"oi\",\"prev_day_oi\",\"turnover\",\"special_tag\",\"tick_seq\",\"best_bid_price\",\"best_bid_qty\",\"best_ask_price\",\"best_ask_qty\",\"change\",\"change_perc\",\"oi_change\",\"oi_change_perc\" ]\r\n```\r\n\r\none_min_live_data and five_min_live_data available fields are \r\n\r\n```python\r\n[ \"symbol\", \"symbol_id\", \"day_open\", \"day_high\", \"day_low\", \"prev_day_close\", \"prev_day_oi\", \"oi\", \"ttq\", \"timestamp\", \"open\", \"high\", \"low\", \"close\", \"volume\", \"change\",\"change_perc\",\"oi_change\",\"oi_change_perc\" ]\r\n```\r\n\r\n* callback functions\r\n\r\n* Accessing live streaming data\r\n user need to define callback function for ticks or minute stream according to their subscription. if callback function defined then when ever new tick or minute bar received then the corresponding callback function will be executed, so please dont block the functions using any indefinite loops\r\n \r\n* available call back decorators are mentioned below . all fields corresponding tick_data or bar_data can be accessed with dotaccess mentioned above\r\n\r\n```python\r\n\r\n@td_obj.trade_callback\r\ndef my_tick_data( tick_data):\r\n print( \"tick data \" , tick_data )\r\n\r\n@td_obj.bidask_callback\r\ndef my_bidask_data( bidask_data):\r\n print(\"bid ask data\" , bidask_data)\r\n\r\n@td_obj.one_min_bar_callback\r\ndef my_one_min_bar_data( bar_data):\r\n print(\"one min bar data \", bar_data)\r\n\r\n@td_obj.five_min_bar_callback\r\ndef my_five_min_bar_data( bar_data):\r\n print( \"five min bar data \", bar_data)\r\n\r\n@td_obj.greek_callback\r\ndef my_greek_data( greek_data):\r\n print(\"greek data \", greek_data)\r\n\r\n@td_obj.full_feed_trade_callback\r\ndef my_ff_trade_data( tick_data):\r\n print(\"full feed tick \", tick_data)\r\n\r\n@td_obj.full_feed_bar_callback\r\ndef my_ff_min_bar_data( bar_data):\r\n print(\"full feed bar \", bar_data )\r\n```\r\n* Stopping live data\r\n\r\n```python\r\ntd_obj.stop_live_data(['<symbol_1>', '<symbol_2>', '<symbol_3>', ...])\r\n```\r\n* Disconnect from the WebSocket service\r\n```python\r\ntd_obj.disconnect()\r\n```\r\n----\r\n# Option Greeks streaming\r\nIf user is subscribed to Nse options and also opt for option greek then whenever new greek data arrived the below function executed. \r\n```Python\r\n@td_obj.greek_callback\r\ndef mygreek_callback( greek_data):\r\n print(\"Greek > \", greek_data)\r\n```\r\n\r\n* These are available fields for greek_data ->\r\n```python \r\n [ \"timestamp\", \"symbol_id\", \"symbol\", \"iv\", \"delta\", \"theta\", \"gamma\", \"vega\", \"rho\" ] \r\n```\r\n\r\n* Each field can be accessed with dot access such as greek_data.symbol , greek_data.delta etc...\r\n----\r\n# Bidask Streaming \r\nIf user is subscribed to bidask then whenever new bidask changed in exchange the below function executed. \r\n```Python\r\n@td_obj.bidask_callback\r\ndef mybidask_callback( bidask_data):\r\n print(\"BidAsk > \", bidask_data )\r\n```\r\n\r\n* These are available fields for bidask_data -> \r\n```python\r\n [ \"timestamp\", \"symbol_id\", \"symbol\", \"bid\", \"ask\", \"total_bid\", \"total_ask\" ]\r\n``` \r\n* Each field can be accessed with dot access such as bidask_data.symbol , bidask_data.ask etc...\r\n* For Nse symbols we offer level 1 bid ask which have one best bid and ask data.\r\n* For bse symbols we offer level 2 bid ask which have five best bid and ask data.\r\n* For level 1 bid ask -> bidask_data.ask return with a list of tuples, containing ```[ ( ask, ask_qnty )]``` in the format, This has total length of one.\r\n* For level 2 bid ask -> bidask_data.ask return with a list of tuples, containing ```[ ( ask_1, ask_1_qnty, ask_1_no_of_trades ) , ( ask_2, ask_2_qnty, ask_2_no_of_trades ) , ....... ]``` in the format , This has total length of five in bid and also same as the ask.\r\n----\r\n\r\n**QUICK START LIVE DATA CODE**\r\n\r\nAll code snippet can be found [here](https://github.com/Nahas-N/Truedata-sample-code).\r\n\r\n\r\n----\r\n**CONVERTING REAL TIME STREAM TO DICT**\r\n\r\nif you need to convert the stream data to dict, use the dunder __dict__ method.\r\n\r\n```python\r\ntd_obj.live_data[symbol_1].to_dict()\r\n\r\ntick_data.to_dict()\r\n```\r\n\r\n----\r\n# Option Chain Streaming\r\nIt is possible to stream single or multiple option chains.\r\n\r\n```symbols , strike , type , ltp , ltt , ltq , volume , price_change , price_change_perc, oi , prev_oi , oi_change , oi_change_perc , bid ,bid_qty , ask , ask_qty , iv, delta, theta, gamma, vega, rho``` \r\n\r\n**Starting Option Chain data for a symbol**\r\n```python\r\nnifty_chain = td_obj.start_option_chain( 'NIFTY' , dt(2021 , 8 , 26) )\r\nsensex_chain = td_obj.start_option_chain(\"SENSEX\" , dt(2023 , 9 , 1) , chain_length = 80 )\r\n#enabling option chain for NIFTY with corresponding expiry. \r\n```\r\n* start_option_chain function takes following arguments:\r\n * symbols for egs: NIFTY , BANKNIFTY , SBIN etc......\r\n * expiry : date (datetime object) \r\n * chain_length : number of strike need to pull with respect to future prices. default value is 10 (int)\r\n * bid_ask : enable live quote . default value is false (boolean)\r\n * greek : boolean, default value is false if need to stream greeks along with option chain\r\n\r\n**Pulling an Option Chain**\r\n```python\r\ndf = nifty_chain.get_option_chain()\r\n#returns a dataframe that contain option chain for repective symbol\r\n```\r\nthis get_option_chain function can call anywhere that will return respective option chain\r\n\r\n**Stop Option Chain Updates**\r\n```python\r\nnifty_chain.stop_option_chain()\r\n```\r\n\r\n**An example for pulling option chain and live data simultaneously**\r\n\r\ncode snippet can be found [here](https://github.com/Nahas-N/Truedata-sample-code).\r\n\r\n\r\n----\r\n# Historical Data\r\n>Historical Data is provided over REST \r\n\r\nIn version v6 we have seperated live and history as modules. so please import according to your configuration.\r\n\r\nAll historical success call return pandas dataframe. \r\n\r\nimporting historical module\r\n\r\n```python\r\nfrom truedata import TD_hist\r\nimport logging\r\ntd_hist = TD_hist(username ,password , log_level= logging.WARNING )\r\n```\r\nall these are the available methods in historical module.\r\n\r\n```python\r\ntd_hist.get_historic_data('BANKNIFTY-I')\r\ntd_hist.get_historic_data('BANKNIFTY-I', duration='3 D')\r\ntd_hist.get_historic_data('BANKNIFTY-I', bar_size='30 mins')\r\ntd_hist.get_historic_data('BANKNIFTY-I', start_time=datetime.now()-relativedelta(days=3))\r\ntd_hist.get_historic_data('BANKNIFTY-I', end_time=datetime(2023, 11, 17, 12, 30))\r\ntd_hist.get_historic_data(\"BANKNIFTY-I\", duration='2 D', bar_size='ticks', bidask=True , delivery = True)\r\ntd_hist.get_n_historical_bars('BANKNIFTY-I', no_of_bars=30, bar_size= '5 min')\r\ntd_hist.get_n_historical_bars(\"BANKNIFTY-I\", no_of_bars=10, bar_size= 'ticks')\r\ntd_hist.get_gainers(\"NSEEQ\", topn = 25 )\r\ntd_hist.get_losers(\"NSEEQ\", topn = 25 )\r\ntd_hist.get_bhavcopy('EQ' , date=datetime(2023, 11, 16) )\r\ntd_hist.get_bhavcopy('FO')\r\nresult = td_hist.get_historic_data(\"NIFTY BANK\", duration='1 D', bar_size='tick')\r\n# print(result.to_dict(orient = 'records'))\r\n```\r\n**IMPORTANT NOTE:**\r\n\r\n* all method returns pandas dataframe if want to convert to list of dict please use pandas inherent method `result.to_dict(orient = 'records')`\r\n\r\nNow that we have covered the basic parameters, you can mix and match the parameters as you please. If a parameter is not specified, the defaults are as follows\r\n```python\r\nend_time = datetime.now()\r\nduration = \"1 D\"\r\nbar_size = \"1 min\"\r\n```\r\n**Get Bhavcopy**\r\n\r\nThis function enables you to get the NSE & MCX bhavcopies for the day / date. \r\n```python\r\neq_bhav = td_obj.get_bhavcopy('EQ')\r\nfo_bhav = td_obj.get_bhavcopy('FO')\r\nmcx_bhav = td_obj.get_bhavcopy('MCX')\r\n```\r\nThe request checks if the latest completed bhavcopy has arrived for that segment and, if arrived, it returns the data. \r\n\r\nIn case it has not arrived it provides the date and time of the last bhavcopy available which can also be pulled by providing the bhavcopy date.\r\n\r\n**Limitations and caveats for historical data**\r\n\r\n1) If you provide both duration and start time, duration will be used and start time will be ignored.\r\n2) If you provide neither duration nor start time, duration = \"1 D\" will be used\r\n3) If you do not provide the bar size bar_size = \"1 min\" will be used\r\n4) The following BAR_SIZES are available:\r\n\r\n - tick\r\n - 1 min\r\n - 2 mins\r\n - 3 mins\r\n - 5 mins\r\n - 10 mins\r\n - 15 mins\r\n - 30 mins\r\n - 60 mins\r\n - eod (or EOD)\r\n - week (or WEEK)\r\n - month (or MONTH)\r\n \r\n\r\n5) The following annotation can be used for DURATION:-\r\n\r\n - D = Days\r\n - W = Weeks\r\n - M = Months\r\n - Y = Years\r\n\r\n**Get Gainers losers information**\r\n\r\nThis function enables you to get the NSE gainers losers information at present state. \r\n```python\r\ngainers = td_obj.get_gainers(segment = \"NSEEQ\" , topn= 10 )\r\nlosers = td_obj.get_losers(segment = \"NSEEQ\" , topn= 10 )\r\n```\r\n* gainers , losers function takes following arguments:\r\n * segment (string) : NSEEQ, NSEFUT, NSEOPT, MCX\r\n * topn (int) : default 10 , top n number \r\n\r\n----\r\n# Release Notes\r\nVersion 7.0.1\r\n* bugfix for the compression\r\n\r\nVersion 7.0.0\r\n* all websocket messages are compressed for performance improvments by default.\r\n\r\nVersion 6.0.7\r\n* bug fix and performance improved \r\n\r\nVersion 6.0.5\r\n* added compression in analytical calls for faster perfomance \r\n\r\nVersion 6.0.4\r\n* removing automatic reconnection after manual disconnection \r\n\r\nVersion 6.0.3\r\n* lz4 version released to latest one without prebuild\r\n\r\nVersion 6.0.2\r\n* analytics new methods added \r\n\r\nVersion 6.0.0\r\n* change: TD_live and TD_hist are two new modules under the package of truedata\r\n* change: option chain are coming with greeks\r\n* change: all historical calls returns pandas dataframe \r\n* change: while loop methods are deprecated only efficient call back method is available now. \r\n* change: TD_analytics module is added to package\r\n",
"bugtrack_url": null,
"license": null,
"summary": "Truedata's Official Python Package",
"version": "7.0.1",
"project_urls": {
"Homepage": "https://github.com/kapilmar/truedata-ws"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "96428bd21d7eda49a2666f113674fc43a5eed40d314f39aa6b5a6ad7982c112c",
"md5": "c1b9da5179203303fcdc2870016ec5d8",
"sha256": "c3aaee95c97541cb14758053abedee798255eba49ed87175cb26bd07d211397c"
},
"downloads": -1,
"filename": "truedata-7.0.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "c1b9da5179203303fcdc2870016ec5d8",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 41787,
"upload_time": "2025-07-14T10:19:37",
"upload_time_iso_8601": "2025-07-14T10:19:37.506748Z",
"url": "https://files.pythonhosted.org/packages/96/42/8bd21d7eda49a2666f113674fc43a5eed40d314f39aa6b5a6ad7982c112c/truedata-7.0.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "de71820f6d53dbbb5a0a478b5a0df6817a87e113cab7d2e446469a5915564168",
"md5": "ef53f8b3336943eb074abb5d1eeaf969",
"sha256": "d8dce657cf7596beaad1c92f870eae7239440cf24481369f6697f7e6b37fe087"
},
"downloads": -1,
"filename": "truedata-7.0.1.tar.gz",
"has_sig": false,
"md5_digest": "ef53f8b3336943eb074abb5d1eeaf969",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 41638,
"upload_time": "2025-07-14T10:19:39",
"upload_time_iso_8601": "2025-07-14T10:19:39.225798Z",
"url": "https://files.pythonhosted.org/packages/de/71/820f6d53dbbb5a0a478b5a0df6817a87e113cab7d2e446469a5915564168/truedata-7.0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-07-14 10:19:39",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "kapilmar",
"github_project": "truedata-ws",
"github_not_found": true,
"lcname": "truedata"
}