nepse-data-api 0.1.0__py3-none-any.whl
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/__init__.py +26 -0
- nepse_data_api/assets/css.wasm +0 -0
- nepse_data_api/cli.py +146 -0
- nepse_data_api/market.py +1007 -0
- nepse_data_api/security.py +178 -0
- nepse_data_api/version.py +3 -0
- nepse_data_api-0.1.0.dist-info/METADATA +248 -0
- nepse_data_api-0.1.0.dist-info/RECORD +12 -0
- nepse_data_api-0.1.0.dist-info/WHEEL +5 -0
- nepse_data_api-0.1.0.dist-info/entry_points.txt +2 -0
- nepse_data_api-0.1.0.dist-info/licenses/LICENSE +47 -0
- nepse_data_api-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -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
|
nepse_data_api/cli.py
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
NEPSE CLI Tool - Command-line interface for NEPSE data
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import argparse
|
|
7
|
+
import json
|
|
8
|
+
import sys
|
|
9
|
+
from nepse_data.market import Nepse
|
|
10
|
+
from datetime import datetime
|
|
11
|
+
|
|
12
|
+
def format_json(data):
|
|
13
|
+
"""Pretty print JSON"""
|
|
14
|
+
return json.dumps(data, indent=2, ensure_ascii=False)
|
|
15
|
+
|
|
16
|
+
def display_market_status(nepse):
|
|
17
|
+
"""Display market status"""
|
|
18
|
+
status = nepse.get_market_status()
|
|
19
|
+
is_open = status.get('isOpen', 'Unknown')
|
|
20
|
+
as_of = status.get('asOf', '')
|
|
21
|
+
|
|
22
|
+
color = '\033[92m' if is_open == 'OPEN' else '\033[91m'
|
|
23
|
+
print(f"{color}Market Status: {is_open}\033[0m")
|
|
24
|
+
print(f"As of: {as_of}")
|
|
25
|
+
|
|
26
|
+
def display_top_performers(nepse, limit=5):
|
|
27
|
+
"""Display top gainers and losers"""
|
|
28
|
+
gainers = nepse.get_top_gainers(limit=limit)
|
|
29
|
+
losers = nepse.get_top_losers(limit=limit)
|
|
30
|
+
|
|
31
|
+
print(f"\n\033[92mTop {limit} Gainers:\033[0m")
|
|
32
|
+
print(f"{'Symbol':<12} {'LTP':<10} {'Change %':<10}")
|
|
33
|
+
print("-" * 40)
|
|
34
|
+
for stock in gainers:
|
|
35
|
+
print(f"{stock['symbol']:<12} {stock['ltp']:<10} +{stock['percentageChange']}%")
|
|
36
|
+
|
|
37
|
+
print(f"\n\033[91mTop {limit} Losers:\033[0m")
|
|
38
|
+
print(f"{'Symbol':<12} {'LTP':<10} {'Change %':<10}")
|
|
39
|
+
print("-" * 40)
|
|
40
|
+
for stock in losers:
|
|
41
|
+
print(f"{stock['symbol']:<12} {stock['ltp']:<10} {stock['percentageChange']}%")
|
|
42
|
+
|
|
43
|
+
def display_nepse_index(nepse):
|
|
44
|
+
"""Display NEPSE index"""
|
|
45
|
+
indices = nepse.get_nepse_index()
|
|
46
|
+
if isinstance(indices, list):
|
|
47
|
+
nepse_index = next((item for item in indices if item.get('index') == 'NEPSE Index'), indices[0])
|
|
48
|
+
else:
|
|
49
|
+
nepse_index = indices
|
|
50
|
+
|
|
51
|
+
print(f"\n\033[1mNEPSE Index: {nepse_index.get('currentValue')}\033[0m")
|
|
52
|
+
change = nepse_index.get('change', 0)
|
|
53
|
+
color = '\033[92m' if change > 0 else '\033[91m'
|
|
54
|
+
print(f"Change: {color}{change} ({nepse_index.get('perChange', 0)}%)\033[0m")
|
|
55
|
+
|
|
56
|
+
def main():
|
|
57
|
+
parser = argparse.ArgumentParser(
|
|
58
|
+
description='NEPSE CLI - Access Nepal Stock Exchange data from command line',
|
|
59
|
+
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
60
|
+
epilog="""
|
|
61
|
+
Examples:
|
|
62
|
+
nepse-cli status # Show market status
|
|
63
|
+
nepse-cli gainers --limit 10 # Top 10 gainers
|
|
64
|
+
nepse-cli index # NEPSE index
|
|
65
|
+
nepse-cli all # Show everything
|
|
66
|
+
"""
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
parser.add_argument('command',
|
|
70
|
+
choices=['status', 'gainers', 'losers', 'index', 'summary', 'all'],
|
|
71
|
+
help='Command to execute')
|
|
72
|
+
parser.add_argument('--limit', type=int, default=5,
|
|
73
|
+
help='Limit number of results (default: 5)')
|
|
74
|
+
parser.add_argument('--json', action='store_true',
|
|
75
|
+
help='Output in JSON format')
|
|
76
|
+
parser.add_argument('--no-cache', action='store_true',
|
|
77
|
+
help='Disable caching')
|
|
78
|
+
|
|
79
|
+
args = parser.parse_args()
|
|
80
|
+
|
|
81
|
+
try:
|
|
82
|
+
# Initialize NEPSE interface
|
|
83
|
+
nepse = Nepse(enable_cache=not args.no_cache)
|
|
84
|
+
|
|
85
|
+
if args.json:
|
|
86
|
+
# JSON output mode
|
|
87
|
+
if args.command == 'status':
|
|
88
|
+
print(format_json(nepse.get_market_status()))
|
|
89
|
+
elif args.command == 'gainers':
|
|
90
|
+
print(format_json(nepse.get_top_gainers(limit=args.limit)))
|
|
91
|
+
elif args.command == 'losers':
|
|
92
|
+
print(format_json(nepse.get_top_losers(limit=args.limit)))
|
|
93
|
+
elif args.command == 'index':
|
|
94
|
+
print(format_json(nepse.get_nepse_index()))
|
|
95
|
+
elif args.command == 'summary':
|
|
96
|
+
print(format_json(nepse.get_market_summary()))
|
|
97
|
+
elif args.command == 'all':
|
|
98
|
+
data = {
|
|
99
|
+
'status': nepse.get_market_status(),
|
|
100
|
+
'index': nepse.get_nepse_index(),
|
|
101
|
+
'gainers': nepse.get_top_gainers(limit=args.limit),
|
|
102
|
+
'losers': nepse.get_top_losers(limit=args.limit)
|
|
103
|
+
}
|
|
104
|
+
print(format_json(data))
|
|
105
|
+
else:
|
|
106
|
+
# Pretty output mode
|
|
107
|
+
print(f"\n{'=' * 60}")
|
|
108
|
+
print(f" NEPSE Data - {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
|
|
109
|
+
print(f"{'=' * 60}\n")
|
|
110
|
+
|
|
111
|
+
if args.command in ['status', 'all']:
|
|
112
|
+
display_market_status(nepse)
|
|
113
|
+
|
|
114
|
+
if args.command in ['index', 'all']:
|
|
115
|
+
display_nepse_index(nepse)
|
|
116
|
+
|
|
117
|
+
if args.command in ['gainers', 'all']:
|
|
118
|
+
display_top_performers(nepse, limit=args.limit)
|
|
119
|
+
elif args.command == 'losers':
|
|
120
|
+
print(f"\n\033[91mTop {args.limit} Losers:\033[0m")
|
|
121
|
+
losers = nepse.get_top_losers(limit=args.limit)
|
|
122
|
+
print(f"{'Symbol':<12} {'LTP':<10} {'Change %':<10}")
|
|
123
|
+
print("-" * 40)
|
|
124
|
+
for stock in losers:
|
|
125
|
+
print(f"{stock['symbol']:<12} {stock['ltp']:<10} {stock['percentageChange']}%")
|
|
126
|
+
|
|
127
|
+
if args.command == 'summary':
|
|
128
|
+
summary = nepse.get_market_summary()
|
|
129
|
+
print("\nMarket Summary:")
|
|
130
|
+
if isinstance(summary, list):
|
|
131
|
+
for item in summary:
|
|
132
|
+
print(f" {item.get('detail', '')}: {item.get('value', '')}")
|
|
133
|
+
else:
|
|
134
|
+
print(format_json(summary))
|
|
135
|
+
|
|
136
|
+
print(f"\n{'=' * 60}\n")
|
|
137
|
+
|
|
138
|
+
except KeyboardInterrupt:
|
|
139
|
+
print("\nInterrupted by user")
|
|
140
|
+
sys.exit(0)
|
|
141
|
+
except Exception as e:
|
|
142
|
+
print(f"\033[91mError: {e}\033[0m", file=sys.stderr)
|
|
143
|
+
sys.exit(1)
|
|
144
|
+
|
|
145
|
+
if __name__ == "__main__":
|
|
146
|
+
main()
|