aynse 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
aynse-0.1.0/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) [2025] [Satyam Kashyap]
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
aynse-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,143 @@
1
+ Metadata-Version: 2.4
2
+ Name: aynse
3
+ Version: 0.1.0
4
+ Summary: A lean and modern python library to fetch data from NSE
5
+ Author-email: satyam-kashyap <abc@xyz.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/a-y-n/aynse
8
+ Project-URL: Documentation, https://github.com/a-y-n/aynse
9
+ Project-URL: Repository, https://github.com/a-y-n/aynse
10
+ Project-URL: Issues, https://github.com/a-y-n/aynse/issues
11
+ Keywords: nse,bhavcopy,pro,library,finance,stock,jugaad,data,aynse
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Intended Audience :: Developers
17
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
18
+ Requires-Python: >=3.6
19
+ Description-Content-Type: text/markdown
20
+ License-File: LICENSE.md
21
+ Dynamic: license-file
22
+
23
+ # `aynse`
24
+
25
+ [![build status](https://github.com/a-y-n/aynse/actions/workflows/run-tests.yml/badge.svg)](https://github.com/a-y-n/aynse/actions/workflows/run-tests.yml)
26
+ [![PyPI version](https://badge.fury.io/py/aynse.svg)](https://badge.fury.io/py/aynse)
27
+ [![license: mit](https://img.shields.io/badge/license-MIT-green.svg)](https://opensource.org/licenses/MIT)
28
+
29
+ `aynse` is a lean, modern python library for fetching data from the national stock exchange (NSE) of india. it is a fork of the unmaintained `jugaad-data` library, aiming to provide a robust and regularly updated tool for financial data analysis.
30
+
31
+ ## features
32
+
33
+ - **historical data:** fetch historical stock and index data.
34
+ - **derivatives data:** download futures and options data.
35
+ - **bhavcopy:** download daily bhavcopy reports for equity, f&o, and indices.
36
+ - **live market data:** get real-time stock quotes.
37
+ - **holiday information:** retrieve a list of trading holidays for a given year.
38
+ - **command-line interface:** a simple cli for quick data downloads.
39
+ - **pandas integration:** returns data as pandas dataframes for easy analysis.
40
+
41
+ ## etymology / musings
42
+ aynse is a portmanteau of "ayn" from miss ayn rand and "nse" from national stock exchange. ayn rand was a russian-american writer and philosopher known for her philosophy of objectivism, which emphasizes individualism and rational self-interest and among other things, she was a strong advocate for laissez-faire capitalism. the name serves as a fun ironical reminder of the library's purpose: to provide a tool for individuals to access and analyze financial data independently, without relying on large institutions or complex systems. in a cruel twist of fate, this open source library wouldn't exist under ayn rand's philosophy, as she was against altruism and believed in the pursuit of one's own happiness as the highest moral purpose. and as the final act of irony, we gather to use this library to analyze financial markets while generating zero (and possibly, negative) intrinsic value for humans or human kind as a whole - this is capitalism.
43
+
44
+
45
+ ## installation
46
+
47
+ you can install `aynse` directly from PyPI:
48
+
49
+ ```sh
50
+ pip install aynse
51
+ ```
52
+
53
+ ## usage
54
+
55
+ here are a few examples of how to use `aynse` to fetch data.
56
+
57
+ ### get historical stock data
58
+
59
+ retrieve historical data for a stock as a pandas dataframe.
60
+
61
+ ```python
62
+ from datetime import date
63
+ import pandas as pd
64
+ from aynse.nse import stock_df
65
+
66
+ # set pandas display options to view all columns
67
+ pd.set_option('display.max_rows', None)
68
+ pd.set_option('display.max_columns', None)
69
+ pd.set_option('display.width', None)
70
+
71
+ # fetch data for reliance from january 1, 2024, to january 31, 2024
72
+ df = stock_df(symbol="RELIANCE",
73
+ from_date=date(2024, 1, 1),
74
+ to_date=date(2024, 1, 31))
75
+
76
+ print(df.head())
77
+ ```
78
+
79
+ ### download daily bhavcopy
80
+
81
+ download the daily bhavcopy for a specific date to a local directory.
82
+
83
+ ```python
84
+ from datetime import date
85
+ from aynse.nse import bhavcopy_save
86
+
87
+ # download equity bhavcopy for july 26, 2024, into the "tmp" directory
88
+ bhavcopy_save(date(2024, 7, 26), "tmp")
89
+ ```
90
+
91
+ ### get live stock quote
92
+
93
+ fetch live price information for a stock.
94
+
95
+ ```python
96
+ from aynse.nse import NSELive
97
+
98
+ n = NSELive()
99
+ quote = n.stock_quote("INFY")
100
+ print(quote['priceInfo'])
101
+ ```
102
+
103
+ ### get trading holidays
104
+
105
+ get the list of trading holidays for a specific year.
106
+
107
+ ```python
108
+ from aynse.holidays import holidays
109
+
110
+ # get trading holidays for the year 2024
111
+ trading_holidays = holidays(2024)
112
+ print(trading_holidays)
113
+ ```
114
+
115
+ ## command-line interface
116
+
117
+ `aynse` also comes with a simple command-line tool for quick downloads.
118
+
119
+ **download today's bhavcopy:**
120
+
121
+ ```sh
122
+ aynse bhavcopy -d /path/to/your/directory
123
+ ```
124
+
125
+ **download bhavcopy for a specific date range:**
126
+
127
+ ```sh
128
+ aynse bhavcopy -d /path/to/your/directory -f 2024-01-01 -t 2024-01-31
129
+ ```
130
+
131
+ **download historical stock data:**
132
+
133
+ ```sh
134
+ aynse stock --symbol RELIANCE -f 2024-01-01 -t 2024-01-31 -o reliance_data.csv
135
+ ```
136
+
137
+ ## contributing
138
+
139
+ contributions are welcome! if you find a bug or have a feature request, please open an issue on the [github repository](https://github.com/a-y-n/aynse/issues).
140
+
141
+ ## license
142
+
143
+ this project is in the public domain. see the [license](LICENSE.YOLO.md) file for more details.
aynse-0.1.0/README.md ADDED
@@ -0,0 +1,121 @@
1
+ # `aynse`
2
+
3
+ [![build status](https://github.com/a-y-n/aynse/actions/workflows/run-tests.yml/badge.svg)](https://github.com/a-y-n/aynse/actions/workflows/run-tests.yml)
4
+ [![PyPI version](https://badge.fury.io/py/aynse.svg)](https://badge.fury.io/py/aynse)
5
+ [![license: mit](https://img.shields.io/badge/license-MIT-green.svg)](https://opensource.org/licenses/MIT)
6
+
7
+ `aynse` is a lean, modern python library for fetching data from the national stock exchange (NSE) of india. it is a fork of the unmaintained `jugaad-data` library, aiming to provide a robust and regularly updated tool for financial data analysis.
8
+
9
+ ## features
10
+
11
+ - **historical data:** fetch historical stock and index data.
12
+ - **derivatives data:** download futures and options data.
13
+ - **bhavcopy:** download daily bhavcopy reports for equity, f&o, and indices.
14
+ - **live market data:** get real-time stock quotes.
15
+ - **holiday information:** retrieve a list of trading holidays for a given year.
16
+ - **command-line interface:** a simple cli for quick data downloads.
17
+ - **pandas integration:** returns data as pandas dataframes for easy analysis.
18
+
19
+ ## etymology / musings
20
+ aynse is a portmanteau of "ayn" from miss ayn rand and "nse" from national stock exchange. ayn rand was a russian-american writer and philosopher known for her philosophy of objectivism, which emphasizes individualism and rational self-interest and among other things, she was a strong advocate for laissez-faire capitalism. the name serves as a fun ironical reminder of the library's purpose: to provide a tool for individuals to access and analyze financial data independently, without relying on large institutions or complex systems. in a cruel twist of fate, this open source library wouldn't exist under ayn rand's philosophy, as she was against altruism and believed in the pursuit of one's own happiness as the highest moral purpose. and as the final act of irony, we gather to use this library to analyze financial markets while generating zero (and possibly, negative) intrinsic value for humans or human kind as a whole - this is capitalism.
21
+
22
+
23
+ ## installation
24
+
25
+ you can install `aynse` directly from PyPI:
26
+
27
+ ```sh
28
+ pip install aynse
29
+ ```
30
+
31
+ ## usage
32
+
33
+ here are a few examples of how to use `aynse` to fetch data.
34
+
35
+ ### get historical stock data
36
+
37
+ retrieve historical data for a stock as a pandas dataframe.
38
+
39
+ ```python
40
+ from datetime import date
41
+ import pandas as pd
42
+ from aynse.nse import stock_df
43
+
44
+ # set pandas display options to view all columns
45
+ pd.set_option('display.max_rows', None)
46
+ pd.set_option('display.max_columns', None)
47
+ pd.set_option('display.width', None)
48
+
49
+ # fetch data for reliance from january 1, 2024, to january 31, 2024
50
+ df = stock_df(symbol="RELIANCE",
51
+ from_date=date(2024, 1, 1),
52
+ to_date=date(2024, 1, 31))
53
+
54
+ print(df.head())
55
+ ```
56
+
57
+ ### download daily bhavcopy
58
+
59
+ download the daily bhavcopy for a specific date to a local directory.
60
+
61
+ ```python
62
+ from datetime import date
63
+ from aynse.nse import bhavcopy_save
64
+
65
+ # download equity bhavcopy for july 26, 2024, into the "tmp" directory
66
+ bhavcopy_save(date(2024, 7, 26), "tmp")
67
+ ```
68
+
69
+ ### get live stock quote
70
+
71
+ fetch live price information for a stock.
72
+
73
+ ```python
74
+ from aynse.nse import NSELive
75
+
76
+ n = NSELive()
77
+ quote = n.stock_quote("INFY")
78
+ print(quote['priceInfo'])
79
+ ```
80
+
81
+ ### get trading holidays
82
+
83
+ get the list of trading holidays for a specific year.
84
+
85
+ ```python
86
+ from aynse.holidays import holidays
87
+
88
+ # get trading holidays for the year 2024
89
+ trading_holidays = holidays(2024)
90
+ print(trading_holidays)
91
+ ```
92
+
93
+ ## command-line interface
94
+
95
+ `aynse` also comes with a simple command-line tool for quick downloads.
96
+
97
+ **download today's bhavcopy:**
98
+
99
+ ```sh
100
+ aynse bhavcopy -d /path/to/your/directory
101
+ ```
102
+
103
+ **download bhavcopy for a specific date range:**
104
+
105
+ ```sh
106
+ aynse bhavcopy -d /path/to/your/directory -f 2024-01-01 -t 2024-01-31
107
+ ```
108
+
109
+ **download historical stock data:**
110
+
111
+ ```sh
112
+ aynse stock --symbol RELIANCE -f 2024-01-01 -t 2024-01-31 -o reliance_data.csv
113
+ ```
114
+
115
+ ## contributing
116
+
117
+ contributions are welcome! if you find a bug or have a feature request, please open an issue on the [github repository](https://github.com/a-y-n/aynse/issues).
118
+
119
+ ## license
120
+
121
+ this project is in the public domain. see the [license](LICENSE.YOLO.md) file for more details.
@@ -0,0 +1 @@
1
+ __version__= "0.26"
@@ -0,0 +1,222 @@
1
+ import os
2
+ import click
3
+ import datetime
4
+ import logging
5
+ import requests
6
+ from datetime import date, timedelta
7
+ from concurrent.futures import ThreadPoolExecutor
8
+
9
+
10
+ from aynse import nse
11
+ from aynse import holidays
12
+ from aynse.rbi import RBI
13
+
14
+
15
+
16
+ logging.basicConfig(level=logging.DEBUG)
17
+
18
+ @click.group()
19
+ def cli():
20
+ """ This is a command line tool to download stock market data to csv files.
21
+
22
+ """
23
+
24
+ def bhavcopy_wrapper(bhavcopy_function, dt, dest):
25
+ try:
26
+ bhavcopy_function(dt, dest)
27
+ return True
28
+ except:
29
+ return False
30
+
31
+
32
+
33
+ @cli.command("bhavcopy")
34
+ @click.option("--dest", "-d", help="Destination directory path", required=True, type=click.Path(exists=True, file_okay=False, dir_okay=True))
35
+ @click.option("--from", "-f", "from_", help="From date", type=click.DateTime(["%Y-%m-%d"]))
36
+ @click.option("--to", "-t", help="To date", type=click.DateTime(["%Y-%m-%d"]))
37
+ @click.option("--fo/--no-fo", help="Downloads F&O bhavcopy", default=False, type=bool)
38
+ @click.option("--idx/--no-idx", help="Downloads Index bhavcopy", default=False, type=bool)
39
+ @click.option("--full/--no-full", help="Full Bhavcopy", default=False, type=bool)
40
+ def bhavcopy(from_, to, dest, fo, idx, full):
41
+ """Downloads bhavcopy from NSE's website
42
+
43
+ Download today's bhavcopy
44
+
45
+ $ jdata bhavcopy -d /path/to/dir
46
+
47
+ Download bhavcopy for a date
48
+
49
+ $ jdata bhavcopy -d /path/to/dir -f 2020-01-01
50
+
51
+ Downlad bhavcopy for a date range
52
+
53
+ $ jdata bhavcopy -d /path/to/dir -f 2020-01-01 -t 2020-02-01
54
+
55
+ """
56
+
57
+ downloader = nse.bhavcopy_save
58
+ if full:
59
+ downloader = nse.full_bhavcopy_save
60
+ if idx:
61
+ downloader = nse.bhavcopy_index_save
62
+ if fo:
63
+ downloader = nse.bhavcopy_fo_save
64
+
65
+ if not from_:
66
+ dt = date.today()
67
+ try:
68
+ path = downloader(dt, dest)
69
+ click.echo("Saved to : " + path)
70
+ except requests.exceptions.ReadTimeout:
71
+ click.echo("""Error: Timeout while downloading, This may be due to-
72
+ \b1. Bad internet connection
73
+ \b2. Today is holiday or file is not ready yet""", err=True)
74
+
75
+ if from_ and not to:
76
+ # if from_ provided but not to
77
+ dt = from_.date()
78
+ try:
79
+ path = downloader(dt, dest)
80
+ click.echo("Saved to : " + path)
81
+ except requests.exceptions.ReadTimeout:
82
+ click.echo("""Error: Timeout while downloading, This may be due to-
83
+ \b1. Bad internet connection
84
+ \b2. {} is holiday or file is not ready yet""".format(dt), err=True)
85
+
86
+ if from_ and to:
87
+ failed_downloads = []
88
+ date_range = []
89
+ delta = to - from_
90
+ for i in range(delta.days + 1):
91
+ dt = from_ + timedelta(days=i)
92
+ w = dt.weekday()
93
+ if w not in [5,6]:
94
+ date_range.append(dt.date())
95
+
96
+ with ThreadPoolExecutor() as executor:
97
+ futures = [executor.submit(bhavcopy_wrapper, downloader, dt, dest) for dt in date_range]
98
+
99
+ with click.progressbar(futures, label="Downloading Bhavcopies") as bar:
100
+ for i, future in enumerate(bar):
101
+ result = future.result()
102
+ if not result:
103
+ failed_downloads.append(date_range[i])
104
+
105
+
106
+ """
107
+ for dt in bar:
108
+ try:
109
+ nse.bhavcopy_save(dt, dest)
110
+ except requests.exceptions.ReadTimeout:
111
+ failed_downloads.append(dt)
112
+ """
113
+ click.echo("Saved to : " + dest)
114
+ if failed_downloads:
115
+ click.echo("Failed to download for below dates, these might be holidays, please check -")
116
+ for dt in failed_downloads:
117
+ click.echo(dt)
118
+
119
+ @cli.command("stock")
120
+ @click.option("--symbol", "-s", required=True, help="Stock symbol")
121
+ @click.option("--from", "-f", "from_", required=True, help="From date - yyyy-mm-dd")
122
+ @click.option("--to", "-t", required=True, help="From date - yyyy-mm-dd")
123
+ @click.option("--series", "-S", default="EQ", show_default=True, help="Series - EQ, BE etc.")
124
+ @click.option("--output", "-o", default="", help="Full path for output file")
125
+ def stock(symbol, from_, to, series, output):
126
+ """Download historical stock data
127
+
128
+
129
+ $jdata stock --symbol STOCK1 -f yyyy-mm-dd -t yyyy-mm-dd -o file_name.csv
130
+ """
131
+ import traceback
132
+ from_date = datetime.strptime(from_, "%Y-%m-%d").date()
133
+ to_date = datetime.strptime(to, "%Y-%m-%d").date()
134
+ try:
135
+ o = nse.stock_csv(symbol, from_date, to_date, series, output, show_progress=True)
136
+ except Exception as e:
137
+ print(e)
138
+ traceback.print_exc()
139
+ click.echo("\nSaved file to : {}".format(o))
140
+
141
+ @cli.command("index")
142
+ @click.option("--symbol", "-s", required=True, help="Stock symbol")
143
+ @click.option("--from", "-f", "from_", required=True, help="From date - yyyy-mm-dd")
144
+ @click.option("--to", "-t", required=True, help="From date - yyyy-mm-dd")
145
+ @click.option("--output", "-o", default="", help="Full path for output file")
146
+ def index(symbol, from_, to, output):
147
+ """Download historical index data
148
+
149
+
150
+ $jdata index --symbol "NIFTY 50" -f yyyy-mm-dd -t yyyy-mm-dd -o file_name.csv
151
+ """
152
+ import traceback
153
+ from_date = datetime.strptime(from_, "%Y-%m-%d").date()
154
+ to_date = datetime.strptime(to, "%Y-%m-%d").date()
155
+ try:
156
+ o = nse.index_csv(symbol, from_date, to_date, output, show_progress=True)
157
+ except Exception as e:
158
+ print(e)
159
+ traceback.print_exc()
160
+ click.echo("\nSaved file to : {}".format(o))
161
+
162
+ @cli.command("derivatives")
163
+ @click.option("--symbol", "-s", required=True, help="Stock/Index symbol")
164
+ @click.option("--from", "-f", "from_", required=True, help="From date - yyyy-mm-dd")
165
+ @click.option("--to", "-t", required=True, help="To date - yyyy-mm-dd")
166
+ @click.option("--expiry", "-e", required=True, help="Expiry date - yyyy-mm-dd")
167
+ @click.option("--instru", "-i", required=True, help="""FUTSTK - Stock futures, FUTIDX - Index Futures,\tOPTSTK - Stock Options, OPTIDX - Index Options""")
168
+ @click.option("--price", "-p", help="Strike price (Only for OPTSTK and OPTIDX)")
169
+ @click.option("--ce/--pe", help="--ce for call and --pe for put (Only for OPTSTK and OPTIDX)")
170
+ @click.option("--output", "-o", default="", help="Full path of output file")
171
+ def stock(symbol, from_, to, expiry, instru, price, ce, output):
172
+ """Sample usage-
173
+
174
+ Download stock futures-
175
+
176
+ \b
177
+ jdata derivatives -s SBIN -f 2020-01-01 -t 2020-01-30 -e 2020-01-30 -i FUTSTK -o file_name.csv
178
+
179
+ Download index futures-
180
+
181
+ \b
182
+ jdata derivatives -s NIFTY -f 2020-01-01 -t 2020-01-30 -e 2020-01-30 -i FUTIDX -o file_name.csv
183
+
184
+ Download stock options-
185
+
186
+ \b
187
+ jdata derivatives -s SBIN -f 2020-01-01 -t 2020-01-30 -e 2020-01-30 -i OPTSTK -p 330 --ce -o file_name.csv
188
+
189
+ Download index options-
190
+
191
+ \b
192
+ jdata derivatives -s NIFTY -f 2020-01-01 -t 2020-01-30 -e 2020-01-23 -i OPTIDX -p 11000 --pe -o file_name.csv
193
+
194
+
195
+ """
196
+ import traceback
197
+ import sys
198
+ from_date = datetime.strptime(from_, "%Y-%m-%d").date()
199
+ to_date = datetime.strptime(to, "%Y-%m-%d").date()
200
+ expiry = datetime.strptime(expiry, "%Y-%m-%d").date()
201
+ if "OPT" in instru:
202
+ if ce:
203
+ ot = "CE"
204
+ else:
205
+ ot = "PE"
206
+
207
+ if price:
208
+ price = float(price)
209
+ else:
210
+ ot = None
211
+ o = nse.derivatives_csv(symbol, from_date, to_date, expiry, instru, price, ot,
212
+ output, show_progress=True)
213
+
214
+ click.echo("\nSaved file to : {}".format(o))
215
+
216
+
217
+
218
+
219
+ if __name__ == "__main__":
220
+ cli()
221
+
222
+