Skip to content

Commit

Permalink
added: feature to get historical option data (#48)
Browse files Browse the repository at this point in the history
Co-authored-by: Witchking <[email protected]>
  • Loading branch information
jitendravarma and Witchking authored Apr 30, 2024
1 parent 2c19a86 commit 37939bd
Show file tree
Hide file tree
Showing 10 changed files with 1,450 additions and 68 deletions.
74 changes: 43 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,36 @@ This library serves as an api to fetch data from the NSE about stocks and indice
Thank you for using Nsedt. Please feel free to send pull requests, comments, and suggestions, as well as get in touch with me if you require any additional help. I sincerely hope you will find this library useful.

#### For detailed doc please refer [nse-doc](https://pratikanand.co.in/nsedt/html)

## How to start

1. clone the repository
`git clone https://github.com/pratik141/nsedt`
`git clone https://github.com/pratik141/nsedt`
2. Install the requirements file after changing to cloned folder above
`pip install -r requirements.txt`
3. Install locally
`pip install . --upgrade`

`pip install -r requirements.txt`
3. Install locally
`pip install . --upgrade`
---

## Equity

### Details
| Name | Module name | Description | Argument | Response|
| ----- | ----------- | ----------- | -------- | ------- |
| companyinfo | get_companyinfo | Company info | symbol , response_type | json, panda df |
| marketstatus | get_marketstatus | marketstatus | -- | panda_df |
| price | get_price | price | start_date, end_date, symbol, input_type | json, panda df |
| corpinfo | get_corpinfo | corpinfo | arg | |
| event | get_event | event | start_date, end_date | panda df |
| chartdata | get_chartdata | chartdata | symbol | panda df |
| symbols_list | get_symbols_list | symbols_list | -- | json |
| asm_list | get_asm_list | symbols_list | asm_type | json |

| Name | Module name | Description | Argument | Response |
| ------------ | ---------------- | ------------ | ---------------------------------------- | -------------- |
| companyinfo | get_companyinfo | Company info | symbol , response_type | json, panda df |
| marketstatus | get_marketstatus | marketstatus | -- | panda_df |
| price | get_price | price | start_date, end_date, symbol, input_type | json, panda df |
| corpinfo | get_corpinfo | corpinfo | arg | |
| event | get_event | event | start_date, end_date | panda df |
| chartdata | get_chartdata | chartdata | symbol | panda df |
| symbols_list | get_symbols_list | symbols_list | -- | json |
| asm_list | get_asm_list | symbols_list | asm_type | json |

Now get_price work with start_date, end_date without datetime format it support `%d-%m-%Y`

### step to run
### step to run

```py
from nsedt import equity as eq
from datetime import date
Expand All @@ -53,11 +58,15 @@ print(eq.get_asm_list(asm_type = "shortterm"))
```

## Indices

### Details
| Name | Module name | Description | Argument | Response|
| ----- | ----------- | ----------- | -------- | ------- |
| price | get_price | price | start_date, end_date, symbol | panda df |
### step to run

| Name | Module name | Description | Argument | Response |
| ----- | ----------- | ----------- | ---------------------------- | -------- |
| price | get_price | price | start_date, end_date, symbol | panda df |

### step to run

```py

from nsedt import indices as ind
Expand All @@ -72,25 +81,28 @@ data["Date"] = pd.to_datetime(data["Date"],format='%d-%b-%Y')
```

## Derivatives

### Details
| Name | Module name | Description | Argument | Response|
| ----- | ----------- | ----------- | -------- | ------- |
| vix | get_vix | price | start_date, end_date,columns_drop_list | panda df |
| option chain | get_option_chain | get option price | symbol,strikePrice,expiryDate | panda df |
| option chain expiry date | get_option_chain_expdate | option chain expiry date | symbol | json |
| future price | get_future_price | get future price | symbol, start_date, end_date, expiryDate,response_type, columns_drop_list | panda df |
| future expiry date | get_future_expdate | future expiry date | symbol | json |

| Name | Module name | Description | Argument | Response |
| ------------------------ | ------------------------ | ------------------------ | ------------------------------------------------------------------------- | -------- |
| vix | get_vix | price | start_date, end_date,columns_drop_list | panda df |
| option chain | get_option_chain | get option price | symbol,strikePrice,expiryDate | panda df |
| option chain expiry date | get_option_chain_expdate | option chain expiry date | symbol | json |
| future price | get_future_price | get future price | symbol, start_date, end_date, expiryDate,response_type, columns_drop_list | panda df |
| future expiry date | get_future_expdate | future expiry date | symbol | json |

### step to run

### step to run
```py
from nsedt import derivatives as de
start_date = "01-09-2023"
end_date = "03-09-2023"
start_date = "24-04-2024"
end_date = "25-04-2024"
# date format "%d-%m-%Y"
print(de.get_vix(start_date, end_date))
print(de.get_option_chain_expdate(symbol="TCS"))
print(de.get_option_chain(symbol="TCS", strike_price=3300, expiry_date="expiryDate"))
print(de.get_option_chain(symbol="TCS", strike_price=3300, expiry_date="30-05-2024"))
print(de.get_future_price(symbol="TCS", start_date=start_date, end_date=end_date))
print(de.get_future_expdate(symbol="TCS"))
print(de.get_historical_option_data(symbol="TATAMOTORS", start_date=start_date, end_date=end_date, option_type="CE", strike_price="1020", year="2024", expiry_date="30-May-2024"))
```
8 changes: 4 additions & 4 deletions docs/html/nsedt/derivatives/futures.html
Original file line number Diff line number Diff line change
Expand Up @@ -1495,7 +1495,7 @@ <h1 class="modulename">
</span><span id="L-32"><a href="#L-32"><span class="linenos">32</span></a><span class="sd"> &quot;&quot;&quot;</span>
</span><span id="L-33"><a href="#L-33"><span class="linenos">33</span></a> <span class="n">cookies</span> <span class="o">=</span> <span class="n">utils</span><span class="o">.</span><span class="n">get_cookies</span><span class="p">()</span>
</span><span id="L-34"><a href="#L-34"><span class="linenos">34</span></a> <span class="n">base_url</span> <span class="o">=</span> <span class="n">cns</span><span class="o">.</span><span class="n">BASE_URL</span>
</span><span id="L-35"><a href="#L-35"><span class="linenos">35</span></a> <span class="n">event_api</span> <span class="o">=</span> <span class="n">cns</span><span class="o">.</span><span class="n">FUTURES_PRICE</span>
</span><span id="L-35"><a href="#L-35"><span class="linenos">35</span></a> <span class="n">event_api</span> <span class="o">=</span> <span class="n">cns</span><span class="o">.</span><span class="n">FNO_HISTORY</span>
</span><span id="L-36"><a href="#L-36"><span class="linenos">36</span></a> <span class="n">symbol</span> <span class="o">=</span> <span class="n">utils</span><span class="o">.</span><span class="n">get_symbol</span><span class="p">(</span><span class="n">symbol</span><span class="o">=</span><span class="n">symbol</span><span class="p">,</span> <span class="n">get_key</span><span class="o">=</span><span class="s2">&quot;derivatives&quot;</span><span class="p">)</span>
</span><span id="L-37"><a href="#L-37"><span class="linenos">37</span></a> <span class="n">params</span> <span class="o">=</span> <span class="p">{</span>
</span><span id="L-38"><a href="#L-38"><span class="linenos">38</span></a> <span class="s2">&quot;symbol&quot;</span><span class="p">:</span> <span class="n">symbol</span><span class="p">,</span>
Expand Down Expand Up @@ -1538,7 +1538,7 @@ <h1 class="modulename">
</span><span id="L-75"><a href="#L-75"><span class="linenos">75</span></a><span class="sd"> &quot;&quot;&quot;</span>
</span><span id="L-76"><a href="#L-76"><span class="linenos">76</span></a> <span class="n">cookies</span> <span class="o">=</span> <span class="n">utils</span><span class="o">.</span><span class="n">get_cookies</span><span class="p">()</span>
</span><span id="L-77"><a href="#L-77"><span class="linenos">77</span></a> <span class="n">base_url</span> <span class="o">=</span> <span class="n">cns</span><span class="o">.</span><span class="n">BASE_URL</span>
</span><span id="L-78"><a href="#L-78"><span class="linenos">78</span></a> <span class="n">event_api</span> <span class="o">=</span> <span class="n">cns</span><span class="o">.</span><span class="n">FUTURES_PRICE</span>
</span><span id="L-78"><a href="#L-78"><span class="linenos">78</span></a> <span class="n">event_api</span> <span class="o">=</span> <span class="n">cns</span><span class="o">.</span><span class="n">FNO_HISTORY</span>
</span><span id="L-79"><a href="#L-79"><span class="linenos">79</span></a> <span class="n">params</span> <span class="o">=</span> <span class="p">{</span>
</span><span id="L-80"><a href="#L-80"><span class="linenos">80</span></a> <span class="s2">&quot;symbol&quot;</span><span class="p">:</span> <span class="n">symbol</span><span class="p">,</span>
</span><span id="L-81"><a href="#L-81"><span class="linenos">81</span></a> <span class="s2">&quot;from&quot;</span><span class="p">:</span> <span class="p">(</span><span class="n">datetime</span><span class="o">.</span><span class="n">now</span><span class="p">()</span> <span class="o">-</span> <span class="n">timedelta</span><span class="p">(</span><span class="n">days</span><span class="o">=</span><span class="mi">3</span><span class="p">))</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">%d</span><span class="s2">-%m-%Y&quot;</span><span class="p">),</span>
Expand Down Expand Up @@ -1610,7 +1610,7 @@ <h1 class="modulename">
</span><span id="get_future_price-33"><a href="#get_future_price-33"><span class="linenos">33</span></a><span class="sd"> &quot;&quot;&quot;</span>
</span><span id="get_future_price-34"><a href="#get_future_price-34"><span class="linenos">34</span></a> <span class="n">cookies</span> <span class="o">=</span> <span class="n">utils</span><span class="o">.</span><span class="n">get_cookies</span><span class="p">()</span>
</span><span id="get_future_price-35"><a href="#get_future_price-35"><span class="linenos">35</span></a> <span class="n">base_url</span> <span class="o">=</span> <span class="n">cns</span><span class="o">.</span><span class="n">BASE_URL</span>
</span><span id="get_future_price-36"><a href="#get_future_price-36"><span class="linenos">36</span></a> <span class="n">event_api</span> <span class="o">=</span> <span class="n">cns</span><span class="o">.</span><span class="n">FUTURES_PRICE</span>
</span><span id="get_future_price-36"><a href="#get_future_price-36"><span class="linenos">36</span></a> <span class="n">event_api</span> <span class="o">=</span> <span class="n">cns</span><span class="o">.</span><span class="n">FNO_HISTORY</span>
</span><span id="get_future_price-37"><a href="#get_future_price-37"><span class="linenos">37</span></a> <span class="n">symbol</span> <span class="o">=</span> <span class="n">utils</span><span class="o">.</span><span class="n">get_symbol</span><span class="p">(</span><span class="n">symbol</span><span class="o">=</span><span class="n">symbol</span><span class="p">,</span> <span class="n">get_key</span><span class="o">=</span><span class="s2">&quot;derivatives&quot;</span><span class="p">)</span>
</span><span id="get_future_price-38"><a href="#get_future_price-38"><span class="linenos">38</span></a> <span class="n">params</span> <span class="o">=</span> <span class="p">{</span>
</span><span id="get_future_price-39"><a href="#get_future_price-39"><span class="linenos">39</span></a> <span class="s2">&quot;symbol&quot;</span><span class="p">:</span> <span class="n">symbol</span><span class="p">,</span>
Expand Down Expand Up @@ -1687,7 +1687,7 @@ <h1 class="modulename">
</span><span id="get_future_expdate-76"><a href="#get_future_expdate-76"><span class="linenos">76</span></a><span class="sd"> &quot;&quot;&quot;</span>
</span><span id="get_future_expdate-77"><a href="#get_future_expdate-77"><span class="linenos">77</span></a> <span class="n">cookies</span> <span class="o">=</span> <span class="n">utils</span><span class="o">.</span><span class="n">get_cookies</span><span class="p">()</span>
</span><span id="get_future_expdate-78"><a href="#get_future_expdate-78"><span class="linenos">78</span></a> <span class="n">base_url</span> <span class="o">=</span> <span class="n">cns</span><span class="o">.</span><span class="n">BASE_URL</span>
</span><span id="get_future_expdate-79"><a href="#get_future_expdate-79"><span class="linenos">79</span></a> <span class="n">event_api</span> <span class="o">=</span> <span class="n">cns</span><span class="o">.</span><span class="n">FUTURES_PRICE</span>
</span><span id="get_future_expdate-79"><a href="#get_future_expdate-79"><span class="linenos">79</span></a> <span class="n">event_api</span> <span class="o">=</span> <span class="n">cns</span><span class="o">.</span><span class="n">FNO_HISTORY</span>
</span><span id="get_future_expdate-80"><a href="#get_future_expdate-80"><span class="linenos">80</span></a> <span class="n">params</span> <span class="o">=</span> <span class="p">{</span>
</span><span id="get_future_expdate-81"><a href="#get_future_expdate-81"><span class="linenos">81</span></a> <span class="s2">&quot;symbol&quot;</span><span class="p">:</span> <span class="n">symbol</span><span class="p">,</span>
</span><span id="get_future_expdate-82"><a href="#get_future_expdate-82"><span class="linenos">82</span></a> <span class="s2">&quot;from&quot;</span><span class="p">:</span> <span class="p">(</span><span class="n">datetime</span><span class="o">.</span><span class="n">now</span><span class="p">()</span> <span class="o">-</span> <span class="n">timedelta</span><span class="p">(</span><span class="n">days</span><span class="o">=</span><span class="mi">3</span><span class="p">))</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">%d</span><span class="s2">-%m-%Y&quot;</span><span class="p">),</span>
Expand Down
10 changes: 5 additions & 5 deletions docs/html/nsedt/resources/constants.html
Original file line number Diff line number Diff line change
Expand Up @@ -1483,7 +1483,7 @@ <h2>API Documentation</h2>
<a class="variable" href="#VIX_HISTORY">VIX_HISTORY</a>
</li>
<li>
<a class="variable" href="#FUTURES_PRICE">FUTURES_PRICE</a>
<a class="variable" href="#FNO_HISTORY">FNO_HISTORY</a>
</li>
</ul>

Expand Down Expand Up @@ -1551,7 +1551,7 @@ <h1 class="modulename">
</span><span id="L-37"><a href="#L-37"><span class="linenos">37</span></a><span class="n">OPTIONS_PRICE_INDICES</span> <span class="o">=</span> <span class="s2">&quot;api/option-chain-indices?&quot;</span>
</span><span id="L-38"><a href="#L-38"><span class="linenos">38</span></a><span class="n">INDICES</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;NIFTY&quot;</span><span class="p">,</span> <span class="s2">&quot;FINNIFTY&quot;</span><span class="p">,</span> <span class="s2">&quot;BANKNIFTY&quot;</span><span class="p">]</span>
</span><span id="L-39"><a href="#L-39"><span class="linenos">39</span></a><span class="n">VIX_HISTORY</span> <span class="o">=</span> <span class="s2">&quot;api/historical/vixhistory?&quot;</span>
</span><span id="L-40"><a href="#L-40"><span class="linenos">40</span></a><span class="n">FUTURES_PRICE</span> <span class="o">=</span> <span class="s2">&quot;api/historical/foCPV?&quot;</span>
</span><span id="L-40"><a href="#L-40"><span class="linenos">40</span></a><span class="n">FNO_HISTORY</span> <span class="o">=</span> <span class="s2">&quot;api/historical/foCPV?&quot;</span>
</span></pre>
</div>

Expand Down Expand Up @@ -1864,14 +1864,14 @@ <h1 class="modulename">


</section>
<section id="FUTURES_PRICE">
<section id="FNO_HISTORY">
<div class="attr variable">
<span class="name">FUTURES_PRICE</span> =
<span class="name">FNO_HISTORY</span> =
<span class="default_value">&#39;api/historical/foCPV?&#39;</span>


</div>
<a class="headerlink" href="#FUTURES_PRICE"></a>
<a class="headerlink" href="#FNO_HISTORY"></a>



Expand Down
Loading

0 comments on commit 37939bd

Please sign in to comment.