nepse-data-api 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.
- nepse_data_api-0.1.0/EXAMPLES.md +110 -0
- nepse_data_api-0.1.0/LICENSE +47 -0
- nepse_data_api-0.1.0/MANIFEST.in +5 -0
- nepse_data_api-0.1.0/PKG-INFO +248 -0
- nepse_data_api-0.1.0/README.md +205 -0
- nepse_data_api-0.1.0/nepse_data_api/__init__.py +26 -0
- nepse_data_api-0.1.0/nepse_data_api/assets/css.wasm +0 -0
- nepse_data_api-0.1.0/nepse_data_api/cli.py +146 -0
- nepse_data_api-0.1.0/nepse_data_api/market.py +1007 -0
- nepse_data_api-0.1.0/nepse_data_api/security.py +178 -0
- nepse_data_api-0.1.0/nepse_data_api/version.py +3 -0
- nepse_data_api-0.1.0/nepse_data_api.egg-info/PKG-INFO +248 -0
- nepse_data_api-0.1.0/nepse_data_api.egg-info/SOURCES.txt +20 -0
- nepse_data_api-0.1.0/nepse_data_api.egg-info/dependency_links.txt +1 -0
- nepse_data_api-0.1.0/nepse_data_api.egg-info/entry_points.txt +2 -0
- nepse_data_api-0.1.0/nepse_data_api.egg-info/requires.txt +10 -0
- nepse_data_api-0.1.0/nepse_data_api.egg-info/top_level.txt +1 -0
- nepse_data_api-0.1.0/pyproject.toml +94 -0
- nepse_data_api-0.1.0/setup.cfg +4 -0
- nepse_data_api-0.1.0/setup.py +79 -0
- nepse_data_api-0.1.0/tests/test_market.py +42 -0
- nepse_data_api-0.1.0/tests/test_security.py +34 -0
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# Examples
|
|
2
|
+
|
|
3
|
+
Ready-to-run examples demonstrating nepse_data usage.
|
|
4
|
+
|
|
5
|
+
## Basic Usage
|
|
6
|
+
|
|
7
|
+
```python
|
|
8
|
+
from nepse_data_api import Nepse
|
|
9
|
+
|
|
10
|
+
nepse = Nepse()
|
|
11
|
+
stocks = nepse.get_stocks()
|
|
12
|
+
print(f"Got {len(stocks)} stocks")
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Get Specific Stock
|
|
16
|
+
|
|
17
|
+
```python
|
|
18
|
+
from nepse_data_api import Nepse
|
|
19
|
+
|
|
20
|
+
nepse = Nepse()
|
|
21
|
+
stocks = nepse.get_stocks()
|
|
22
|
+
|
|
23
|
+
# Filter for NABIL
|
|
24
|
+
nabil = next((s for s in stocks if s['symbol'] == 'NABIL'), None)
|
|
25
|
+
|
|
26
|
+
if nabil:
|
|
27
|
+
print(f"{nabil['securityName']}")
|
|
28
|
+
print(f" LTP: {nabil['lastTradedPrice']}")
|
|
29
|
+
print(f" Volume: {nabil['totalTradeQuantity']}")
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Monitor Top Gainers
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
from nepse_data_api import Nepse
|
|
36
|
+
|
|
37
|
+
nepse = Nepse()
|
|
38
|
+
gainers = nepse.get_top_gainers(limit=5)
|
|
39
|
+
|
|
40
|
+
for stock in gainers:
|
|
41
|
+
print(f"{stock['symbol']:6} +{stock.get('percentageChange', 0):.2f}%")
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Historical Data
|
|
45
|
+
|
|
46
|
+
```python
|
|
47
|
+
from datetime import date
|
|
48
|
+
from nepse_data_api import Nepse
|
|
49
|
+
|
|
50
|
+
nepse = Nepse()
|
|
51
|
+
|
|
52
|
+
# Get data for today
|
|
53
|
+
today = date.today().strftime("%Y-%m-%d")
|
|
54
|
+
stocks = nepse.get_stocks(date=today)
|
|
55
|
+
|
|
56
|
+
for stock in stocks[:5]:
|
|
57
|
+
print(f"{stock['symbol']}: {stock['closePrice']}")
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Track Portfolio
|
|
61
|
+
|
|
62
|
+
```python
|
|
63
|
+
from nepse_data_api import Nepse
|
|
64
|
+
|
|
65
|
+
# Your holdings
|
|
66
|
+
portfolio = {
|
|
67
|
+
'NABIL': 50,
|
|
68
|
+
'ADBL': 100,
|
|
69
|
+
'NICA': 200
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
nepse = Nepse()
|
|
73
|
+
stocks = nepse.get_stocks()
|
|
74
|
+
|
|
75
|
+
total_value = 0
|
|
76
|
+
for symbol, quantity in portfolio.items():
|
|
77
|
+
stock = next((s for s in stocks if s['symbol'] == symbol), None)
|
|
78
|
+
if stock:
|
|
79
|
+
value = stock['lastTradedPrice'] * quantity
|
|
80
|
+
total_value += value
|
|
81
|
+
print(f"{symbol}: {quantity} @ {stock['lastTradedPrice']} = Rs. {value:,.2f}")
|
|
82
|
+
|
|
83
|
+
print(f"\nTotal Portfolio Value: Rs. {total_value:,.2f}")
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Async Example
|
|
87
|
+
|
|
88
|
+
```python
|
|
89
|
+
import asyncio
|
|
90
|
+
from nepse_data_api import AsyncNepse
|
|
91
|
+
|
|
92
|
+
async def monitor_market():
|
|
93
|
+
nepse = AsyncNepse()
|
|
94
|
+
|
|
95
|
+
while True:
|
|
96
|
+
stocks = await nepse.get_stocks()
|
|
97
|
+
index = await nepse.get_nepse_index()
|
|
98
|
+
|
|
99
|
+
# Check if we got valid data (index is list)
|
|
100
|
+
if index and isinstance(index, list):
|
|
101
|
+
print(f"NEPSE: {index[0]['close']} ({index[0]['perChange']}%)")
|
|
102
|
+
|
|
103
|
+
print(f"Stocks trading: {len(stocks)}")
|
|
104
|
+
|
|
105
|
+
await asyncio.sleep(60) # Update every minute
|
|
106
|
+
|
|
107
|
+
asyncio.run(monitor_market())
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
See the `test_suite/` directory for comprehensive examples of all features.
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Your Name
|
|
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.
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## Data Source & Disclaimer
|
|
26
|
+
|
|
27
|
+
This software fetches data from Nepal Stock Exchange (NEPSE) public APIs.
|
|
28
|
+
- Data Source: https://www.nepalstock.com.np
|
|
29
|
+
- This is an unofficial library and is not affiliated with or endorsed by NEPSE.
|
|
30
|
+
- Use at your own risk. The authors are not responsible for any financial decisions made using this data.
|
|
31
|
+
|
|
32
|
+
## Credits & Acknowledgments
|
|
33
|
+
|
|
34
|
+
This library uses the following technologies:
|
|
35
|
+
- pywasm (https://github.com/mohanson/pywasm) - For WASM authentication
|
|
36
|
+
- requests (https://requests.readthedocs.io/) - For HTTP requests
|
|
37
|
+
- aiohttp (https://docs.aiohttp.org/) - For async support
|
|
38
|
+
|
|
39
|
+
Inspired by existing NEPSE data libraries in the Python ecosystem.
|
|
40
|
+
|
|
41
|
+
## Fair Use Policy
|
|
42
|
+
|
|
43
|
+
Please be respectful of NEPSE's servers:
|
|
44
|
+
- Don't make excessive requests
|
|
45
|
+
- Implement reasonable caching (this library does)
|
|
46
|
+
- Don't use for commercial redistribution without proper authorization
|
|
47
|
+
- This is for educational and personal portfolio tracking purposes
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: nepse-data-api
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: High-performance Python library for Nepal Stock Exchange (NEPSE) data
|
|
5
|
+
Home-page: https://github.com/ra8in/nepse_data_api
|
|
6
|
+
Author: Rabin Katel
|
|
7
|
+
Author-email: Rabin Katel <kattelrabinraja13@gmail.com>
|
|
8
|
+
License: MIT
|
|
9
|
+
Project-URL: Homepage, https://github.com/ra8in/nepse_data_api
|
|
10
|
+
Project-URL: Documentation, https://github.com/ra8in/nepse_data_api#readme
|
|
11
|
+
Project-URL: Repository, https://github.com/ra8in/nepse_data_api
|
|
12
|
+
Project-URL: Issues, https://github.com/ra8in/nepse_data_api/issues
|
|
13
|
+
Keywords: nepse,nepal,stock,market,finance,trading,data,api,share,investment
|
|
14
|
+
Classifier: Development Status :: 4 - Beta
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: Intended Audience :: Financial and Insurance Industry
|
|
17
|
+
Classifier: Topic :: Office/Business :: Financial :: Investment
|
|
18
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
19
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
20
|
+
Classifier: Operating System :: OS Independent
|
|
21
|
+
Classifier: Programming Language :: Python :: 3
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
25
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
26
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
27
|
+
Requires-Python: >=3.8
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
License-File: LICENSE
|
|
30
|
+
Requires-Dist: requests>=2.31.0
|
|
31
|
+
Requires-Dist: pywasm>=1.0.8
|
|
32
|
+
Requires-Dist: aiohttp>=3.9.0
|
|
33
|
+
Requires-Dist: websockets>=10.0
|
|
34
|
+
Provides-Extra: dev
|
|
35
|
+
Requires-Dist: pytest>=7.4.0; extra == "dev"
|
|
36
|
+
Requires-Dist: black>=23.0.0; extra == "dev"
|
|
37
|
+
Requires-Dist: mypy>=1.5.0; extra == "dev"
|
|
38
|
+
Requires-Dist: flake8>=6.0.0; extra == "dev"
|
|
39
|
+
Dynamic: author
|
|
40
|
+
Dynamic: home-page
|
|
41
|
+
Dynamic: license-file
|
|
42
|
+
Dynamic: requires-python
|
|
43
|
+
|
|
44
|
+
# nepse-data-api
|
|
45
|
+
|
|
46
|
+
**Advanced Python client for Nepal Stock Exchange (NEPSE)**
|
|
47
|
+
|
|
48
|
+
[](https://pypi.org/project/nepse-data-api/)
|
|
49
|
+
[](https://www.python.org/downloads/)
|
|
50
|
+
[](https://opensource.org/licenses/MIT)
|
|
51
|
+
|
|
52
|
+
**nepse-data** is a high-performance, refined Python library for accessing live and historical market data from the Nepal Stock Exchange. It handles authentication, token management, and data scrambling automatically, providing a clean and simple API for developers and researchers.
|
|
53
|
+
|
|
54
|
+
## ✨ Features
|
|
55
|
+
|
|
56
|
+
- ✅ **26+ API Endpoints** - Complete NEPSE data coverage (Live Market, Floorsheets, Depth, etc.)
|
|
57
|
+
- ✅ **WASM Authentication** - Secure, automated token generation and management
|
|
58
|
+
- ✅ **Smart Caching** - Built-in caching layer (5700x faster for repeated requests)
|
|
59
|
+
- ✅ **Async Support** - Full `async`/`await` support for high-concurrency applications
|
|
60
|
+
- ✅ **Validated Data** - Accurate and reliable market information
|
|
61
|
+
|
|
62
|
+
## 🚀 Quick Start
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
pip install nepse-data-api
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
```python
|
|
69
|
+
from nepse_data_api import Nepse
|
|
70
|
+
|
|
71
|
+
# Initialize
|
|
72
|
+
nepse = Nepse()
|
|
73
|
+
|
|
74
|
+
# Get all live stocks
|
|
75
|
+
stocks = nepse.get_stocks()
|
|
76
|
+
print(f"Total listed stocks: {len(stocks)}")
|
|
77
|
+
|
|
78
|
+
# Get market status
|
|
79
|
+
status = nepse.get_market_status()
|
|
80
|
+
print(f"Market is currently: {status['isOpen']}")
|
|
81
|
+
|
|
82
|
+
# Get top gainers
|
|
83
|
+
gainers = nepse.get_top_gainers(limit=5)
|
|
84
|
+
for stock in gainers:
|
|
85
|
+
print(f"{stock['symbol']}: {stock['lastTradedPrice']} ({stock['percentageChange']}%)")
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## 📖 API Reference
|
|
89
|
+
|
|
90
|
+
### Market Overview
|
|
91
|
+
|
|
92
|
+
```python
|
|
93
|
+
# Market status (open/close)
|
|
94
|
+
status = nepse.get_market_status()
|
|
95
|
+
|
|
96
|
+
# Market summary (turnover, transactions)
|
|
97
|
+
summary = nepse.get_market_summary()
|
|
98
|
+
|
|
99
|
+
# NEPSE main index
|
|
100
|
+
index = nepse.get_nepse_index()
|
|
101
|
+
|
|
102
|
+
# All sector indices
|
|
103
|
+
sectors = nepse.get_sub_indices()
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### Stock Data
|
|
107
|
+
|
|
108
|
+
```python
|
|
109
|
+
from datetime import date
|
|
110
|
+
|
|
111
|
+
# Live stock prices (all stocks)
|
|
112
|
+
stocks = nepse.get_stocks()
|
|
113
|
+
|
|
114
|
+
# Historical prices for a specific date (e.g., today)
|
|
115
|
+
today = date.today().strftime("%Y-%m-%d")
|
|
116
|
+
stocks = nepse.get_stocks(date=today)
|
|
117
|
+
|
|
118
|
+
# Specific security details
|
|
119
|
+
# Use security ID from company list
|
|
120
|
+
details = nepse.get_security_details(security_id)
|
|
121
|
+
|
|
122
|
+
# Historical chart data
|
|
123
|
+
# Fetch chart for a date range (YYYY-MM-DD)
|
|
124
|
+
chart = nepse.get_historical_chart(58, start_date="2026-01-01", end_date=today)
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### Top Performers
|
|
128
|
+
|
|
129
|
+
```python
|
|
130
|
+
# Top gainers
|
|
131
|
+
gainers = nepse.get_top_gainers(limit=10)
|
|
132
|
+
|
|
133
|
+
# Top losers
|
|
134
|
+
losers = nepse.get_top_losers(limit=10)
|
|
135
|
+
|
|
136
|
+
# Top by turnover / trade / transaction
|
|
137
|
+
turnover = nepse.get_top_turnover()
|
|
138
|
+
trades = nepse.get_top_trade()
|
|
139
|
+
trans = nepse.get_top_transaction()
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### Company Information
|
|
143
|
+
|
|
144
|
+
```python
|
|
145
|
+
# Company news
|
|
146
|
+
news = nepse.get_company_news(symbol="NABIL")
|
|
147
|
+
|
|
148
|
+
# Dividend & AGM
|
|
149
|
+
dividends = nepse.get_dividends(symbol="NABIL")
|
|
150
|
+
agm = nepse.get_agm(symbol="NABIL")
|
|
151
|
+
|
|
152
|
+
# Metadata
|
|
153
|
+
companies = nepse.get_company_list()
|
|
154
|
+
securities = nepse.get_security_list()
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
### Trading Data
|
|
158
|
+
|
|
159
|
+
```python
|
|
160
|
+
# Market depth (Order Book)
|
|
161
|
+
depth = nepse.get_market_depth(symbol="NABIL")
|
|
162
|
+
|
|
163
|
+
# Floorsheet (Transactions)
|
|
164
|
+
floorsheet = nepse.get_floorsheet(symbol="NABIL")
|
|
165
|
+
|
|
166
|
+
# Daily trade statistics for a specific date
|
|
167
|
+
stats = nepse.get_daily_trade(date="2026-02-12")
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
## ⚡ Advanced Features
|
|
171
|
+
|
|
172
|
+
### Caching
|
|
173
|
+
The library includes a built-in LRU caching layer to respect NEPSE's server load and improve performance.
|
|
174
|
+
|
|
175
|
+
```python
|
|
176
|
+
# Customize cache TTL (default: 30s)
|
|
177
|
+
nepse = Nepse(cache_ttl=120, enable_cache=True)
|
|
178
|
+
|
|
179
|
+
# Force fresh data for a single request
|
|
180
|
+
stocks = nepse.get_stocks(use_cache=False)
|
|
181
|
+
|
|
182
|
+
# Manually clear cache
|
|
183
|
+
nepse.clear_cache()
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
### Async Support
|
|
187
|
+
For web applications or high-frequency polling, use `AsyncNepse`.
|
|
188
|
+
|
|
189
|
+
```python
|
|
190
|
+
import asyncio
|
|
191
|
+
from nepse_data_api import AsyncNepse
|
|
192
|
+
|
|
193
|
+
async def main():
|
|
194
|
+
nepse = AsyncNepse()
|
|
195
|
+
|
|
196
|
+
# Parallel fetching
|
|
197
|
+
status, stocks = await asyncio.gather(
|
|
198
|
+
nepse.get_market_status(),
|
|
199
|
+
nepse.get_stocks()
|
|
200
|
+
)
|
|
201
|
+
print(status, len(stocks))
|
|
202
|
+
|
|
203
|
+
asyncio.run(main())
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
## 📊 Performance
|
|
207
|
+
|
|
208
|
+
| Operation | Fresh Request | Cached | Improvement |
|
|
209
|
+
|-----------|---------------|--------|-------------|
|
|
210
|
+
| Market Status | ~48ms | ~0.01ms | **5700x** |
|
|
211
|
+
| Stock List | ~180ms | ~0.02ms | **12000x** |
|
|
212
|
+
| Top Gainers | ~52ms | ~0.01ms | **5200x** |
|
|
213
|
+
|
|
214
|
+
## 📁 Project Structure
|
|
215
|
+
|
|
216
|
+
```
|
|
217
|
+
nepse-data-api/
|
|
218
|
+
├── README.md # Documentation
|
|
219
|
+
├── LICENSE # MIT License
|
|
220
|
+
├── setup.py # Package config
|
|
221
|
+
└── nepse_data_api/ # Source code
|
|
222
|
+
├── __init__.py # Exports
|
|
223
|
+
├── market.py # NEPSE & AsyncNepse classes
|
|
224
|
+
├── security.py # Token & Security utilities
|
|
225
|
+
└── version.py # Version info
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
## 🤝 Contributing
|
|
229
|
+
|
|
230
|
+
Contributions are welcome!
|
|
231
|
+
1. Fork the repository
|
|
232
|
+
2. Create feature branch (`git checkout -b feature/amazing-feature`)
|
|
233
|
+
3. Commit changes (`git commit -m 'Add amazing feature'`)
|
|
234
|
+
4. Push to branch (`git push origin feature/amazing-feature`)
|
|
235
|
+
5. Open a Pull Request
|
|
236
|
+
|
|
237
|
+
## ⚠️ Disclaimer & Legal
|
|
238
|
+
|
|
239
|
+
**FOR EDUCATIONAL PURPOSES ONLY**
|
|
240
|
+
|
|
241
|
+
This library interfaces with publicly accessible APIs from the **Nepal Stock Exchange (NEPSE)**. It is **not** affiliated with, endorsed by, or connected to NEPSE in any official capacity.
|
|
242
|
+
|
|
243
|
+
- **Data Attribution:** All data is the property of Nepal Stock Exchange Ltd.
|
|
244
|
+
- **No Warranty:** The software is provided "as is", without warranty of any kind.
|
|
245
|
+
- **Use Responsibly:** Please respect NEPSE's servers. The built-in caching is designed to prevent abuse; do not disable it unless necessary.
|
|
246
|
+
- **Not Financial Advice:** Data retrieved via this library should not be the sole basis for financial decisions.
|
|
247
|
+
|
|
248
|
+
**License:** MIT License - See [LICENSE](LICENSE) for details.
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
# nepse-data-api
|
|
2
|
+
|
|
3
|
+
**Advanced Python client for Nepal Stock Exchange (NEPSE)**
|
|
4
|
+
|
|
5
|
+
[](https://pypi.org/project/nepse-data-api/)
|
|
6
|
+
[](https://www.python.org/downloads/)
|
|
7
|
+
[](https://opensource.org/licenses/MIT)
|
|
8
|
+
|
|
9
|
+
**nepse-data** is a high-performance, refined Python library for accessing live and historical market data from the Nepal Stock Exchange. It handles authentication, token management, and data scrambling automatically, providing a clean and simple API for developers and researchers.
|
|
10
|
+
|
|
11
|
+
## ✨ Features
|
|
12
|
+
|
|
13
|
+
- ✅ **26+ API Endpoints** - Complete NEPSE data coverage (Live Market, Floorsheets, Depth, etc.)
|
|
14
|
+
- ✅ **WASM Authentication** - Secure, automated token generation and management
|
|
15
|
+
- ✅ **Smart Caching** - Built-in caching layer (5700x faster for repeated requests)
|
|
16
|
+
- ✅ **Async Support** - Full `async`/`await` support for high-concurrency applications
|
|
17
|
+
- ✅ **Validated Data** - Accurate and reliable market information
|
|
18
|
+
|
|
19
|
+
## 🚀 Quick Start
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
pip install nepse-data-api
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
```python
|
|
26
|
+
from nepse_data_api import Nepse
|
|
27
|
+
|
|
28
|
+
# Initialize
|
|
29
|
+
nepse = Nepse()
|
|
30
|
+
|
|
31
|
+
# Get all live stocks
|
|
32
|
+
stocks = nepse.get_stocks()
|
|
33
|
+
print(f"Total listed stocks: {len(stocks)}")
|
|
34
|
+
|
|
35
|
+
# Get market status
|
|
36
|
+
status = nepse.get_market_status()
|
|
37
|
+
print(f"Market is currently: {status['isOpen']}")
|
|
38
|
+
|
|
39
|
+
# Get top gainers
|
|
40
|
+
gainers = nepse.get_top_gainers(limit=5)
|
|
41
|
+
for stock in gainers:
|
|
42
|
+
print(f"{stock['symbol']}: {stock['lastTradedPrice']} ({stock['percentageChange']}%)")
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## 📖 API Reference
|
|
46
|
+
|
|
47
|
+
### Market Overview
|
|
48
|
+
|
|
49
|
+
```python
|
|
50
|
+
# Market status (open/close)
|
|
51
|
+
status = nepse.get_market_status()
|
|
52
|
+
|
|
53
|
+
# Market summary (turnover, transactions)
|
|
54
|
+
summary = nepse.get_market_summary()
|
|
55
|
+
|
|
56
|
+
# NEPSE main index
|
|
57
|
+
index = nepse.get_nepse_index()
|
|
58
|
+
|
|
59
|
+
# All sector indices
|
|
60
|
+
sectors = nepse.get_sub_indices()
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Stock Data
|
|
64
|
+
|
|
65
|
+
```python
|
|
66
|
+
from datetime import date
|
|
67
|
+
|
|
68
|
+
# Live stock prices (all stocks)
|
|
69
|
+
stocks = nepse.get_stocks()
|
|
70
|
+
|
|
71
|
+
# Historical prices for a specific date (e.g., today)
|
|
72
|
+
today = date.today().strftime("%Y-%m-%d")
|
|
73
|
+
stocks = nepse.get_stocks(date=today)
|
|
74
|
+
|
|
75
|
+
# Specific security details
|
|
76
|
+
# Use security ID from company list
|
|
77
|
+
details = nepse.get_security_details(security_id)
|
|
78
|
+
|
|
79
|
+
# Historical chart data
|
|
80
|
+
# Fetch chart for a date range (YYYY-MM-DD)
|
|
81
|
+
chart = nepse.get_historical_chart(58, start_date="2026-01-01", end_date=today)
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Top Performers
|
|
85
|
+
|
|
86
|
+
```python
|
|
87
|
+
# Top gainers
|
|
88
|
+
gainers = nepse.get_top_gainers(limit=10)
|
|
89
|
+
|
|
90
|
+
# Top losers
|
|
91
|
+
losers = nepse.get_top_losers(limit=10)
|
|
92
|
+
|
|
93
|
+
# Top by turnover / trade / transaction
|
|
94
|
+
turnover = nepse.get_top_turnover()
|
|
95
|
+
trades = nepse.get_top_trade()
|
|
96
|
+
trans = nepse.get_top_transaction()
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### Company Information
|
|
100
|
+
|
|
101
|
+
```python
|
|
102
|
+
# Company news
|
|
103
|
+
news = nepse.get_company_news(symbol="NABIL")
|
|
104
|
+
|
|
105
|
+
# Dividend & AGM
|
|
106
|
+
dividends = nepse.get_dividends(symbol="NABIL")
|
|
107
|
+
agm = nepse.get_agm(symbol="NABIL")
|
|
108
|
+
|
|
109
|
+
# Metadata
|
|
110
|
+
companies = nepse.get_company_list()
|
|
111
|
+
securities = nepse.get_security_list()
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### Trading Data
|
|
115
|
+
|
|
116
|
+
```python
|
|
117
|
+
# Market depth (Order Book)
|
|
118
|
+
depth = nepse.get_market_depth(symbol="NABIL")
|
|
119
|
+
|
|
120
|
+
# Floorsheet (Transactions)
|
|
121
|
+
floorsheet = nepse.get_floorsheet(symbol="NABIL")
|
|
122
|
+
|
|
123
|
+
# Daily trade statistics for a specific date
|
|
124
|
+
stats = nepse.get_daily_trade(date="2026-02-12")
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## ⚡ Advanced Features
|
|
128
|
+
|
|
129
|
+
### Caching
|
|
130
|
+
The library includes a built-in LRU caching layer to respect NEPSE's server load and improve performance.
|
|
131
|
+
|
|
132
|
+
```python
|
|
133
|
+
# Customize cache TTL (default: 30s)
|
|
134
|
+
nepse = Nepse(cache_ttl=120, enable_cache=True)
|
|
135
|
+
|
|
136
|
+
# Force fresh data for a single request
|
|
137
|
+
stocks = nepse.get_stocks(use_cache=False)
|
|
138
|
+
|
|
139
|
+
# Manually clear cache
|
|
140
|
+
nepse.clear_cache()
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### Async Support
|
|
144
|
+
For web applications or high-frequency polling, use `AsyncNepse`.
|
|
145
|
+
|
|
146
|
+
```python
|
|
147
|
+
import asyncio
|
|
148
|
+
from nepse_data_api import AsyncNepse
|
|
149
|
+
|
|
150
|
+
async def main():
|
|
151
|
+
nepse = AsyncNepse()
|
|
152
|
+
|
|
153
|
+
# Parallel fetching
|
|
154
|
+
status, stocks = await asyncio.gather(
|
|
155
|
+
nepse.get_market_status(),
|
|
156
|
+
nepse.get_stocks()
|
|
157
|
+
)
|
|
158
|
+
print(status, len(stocks))
|
|
159
|
+
|
|
160
|
+
asyncio.run(main())
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
## 📊 Performance
|
|
164
|
+
|
|
165
|
+
| Operation | Fresh Request | Cached | Improvement |
|
|
166
|
+
|-----------|---------------|--------|-------------|
|
|
167
|
+
| Market Status | ~48ms | ~0.01ms | **5700x** |
|
|
168
|
+
| Stock List | ~180ms | ~0.02ms | **12000x** |
|
|
169
|
+
| Top Gainers | ~52ms | ~0.01ms | **5200x** |
|
|
170
|
+
|
|
171
|
+
## 📁 Project Structure
|
|
172
|
+
|
|
173
|
+
```
|
|
174
|
+
nepse-data-api/
|
|
175
|
+
├── README.md # Documentation
|
|
176
|
+
├── LICENSE # MIT License
|
|
177
|
+
├── setup.py # Package config
|
|
178
|
+
└── nepse_data_api/ # Source code
|
|
179
|
+
├── __init__.py # Exports
|
|
180
|
+
├── market.py # NEPSE & AsyncNepse classes
|
|
181
|
+
├── security.py # Token & Security utilities
|
|
182
|
+
└── version.py # Version info
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
## 🤝 Contributing
|
|
186
|
+
|
|
187
|
+
Contributions are welcome!
|
|
188
|
+
1. Fork the repository
|
|
189
|
+
2. Create feature branch (`git checkout -b feature/amazing-feature`)
|
|
190
|
+
3. Commit changes (`git commit -m 'Add amazing feature'`)
|
|
191
|
+
4. Push to branch (`git push origin feature/amazing-feature`)
|
|
192
|
+
5. Open a Pull Request
|
|
193
|
+
|
|
194
|
+
## ⚠️ Disclaimer & Legal
|
|
195
|
+
|
|
196
|
+
**FOR EDUCATIONAL PURPOSES ONLY**
|
|
197
|
+
|
|
198
|
+
This library interfaces with publicly accessible APIs from the **Nepal Stock Exchange (NEPSE)**. It is **not** affiliated with, endorsed by, or connected to NEPSE in any official capacity.
|
|
199
|
+
|
|
200
|
+
- **Data Attribution:** All data is the property of Nepal Stock Exchange Ltd.
|
|
201
|
+
- **No Warranty:** The software is provided "as is", without warranty of any kind.
|
|
202
|
+
- **Use Responsibly:** Please respect NEPSE's servers. The built-in caching is designed to prevent abuse; do not disable it unless necessary.
|
|
203
|
+
- **Not Financial Advice:** Data retrieved via this library should not be the sole basis for financial decisions.
|
|
204
|
+
|
|
205
|
+
**License:** MIT License - See [LICENSE](LICENSE) for details.
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"""
|
|
2
|
+
nepse_data - Advanced NEPSE Stock Market Data Library
|
|
3
|
+
======================================================
|
|
4
|
+
|
|
5
|
+
A clean, high-performance Python library for Nepal Stock Exchange (NEPSE) data.
|
|
6
|
+
|
|
7
|
+
Quick Start:
|
|
8
|
+
>>> from nepse_data import Nepse
|
|
9
|
+
>>> nepse = Nepse()
|
|
10
|
+
>>> stocks = nepse.get_stocks() # Get all live stocks
|
|
11
|
+
>>> nabil = [s for s in stocks if s['symbol'] == 'NABIL'][0]
|
|
12
|
+
|
|
13
|
+
Features:
|
|
14
|
+
- Live market data (OHLCV)
|
|
15
|
+
- Sector indices
|
|
16
|
+
- Corporate actions (Dividends, AGM)
|
|
17
|
+
- News & alerts
|
|
18
|
+
- Market depth & floorsheet
|
|
19
|
+
- Built-in caching for performance
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
from .market import Nepse, AsyncNepse
|
|
23
|
+
from .version import __version__
|
|
24
|
+
|
|
25
|
+
__author__ = "NEPSE Core Contributors"
|
|
26
|
+
__all__ = ["Nepse", "AsyncNepse"]
|
|
Binary file
|