Trader-AngleOne 1.3__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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ROHIT GUPTA
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.
@@ -0,0 +1,109 @@
1
+ Metadata-Version: 2.4
2
+ Name: Trader_AngleOne
3
+ Version: 1.3
4
+ Summary: A lightweight, efficient Python wrapper for fetching historical equity market data via Angel One SmartAPI.
5
+ Author-email: ROHIT GUPTA <everything108rp@gmail.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/Rohit-Gupta-369/Trader_AngleOne
8
+ Project-URL: Bug Tracker, https://github.com/Rohit-Gupta-369/Trader_AngleOne/issues
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Operating System :: OS Independent
12
+ Classifier: Topic :: Office/Business :: Financial :: Investment
13
+ Requires-Python: >=3.7
14
+ Description-Content-Type: text/markdown
15
+ License-File: LICENSE
16
+ Requires-Dist: smartapi-python
17
+ Requires-Dist: pandas
18
+ Dynamic: license-file
19
+
20
+ # Trader_AngleOne
21
+
22
+ A lightweight, efficient Python wrapper for fetching historical equity market data via Angel One SmartAPI.
23
+
24
+ ## Features
25
+
26
+ - **Easy Authentication:** Initialize seamlessly using dictionary unpacking.
27
+ - **Granular Timeframes:** Supports 1-minute up to daily data intervals.
28
+ - **NSE Equity Focus:** Built specifically to fetch NSE - EQ segment data (e.g., NIFTY, BANKNIFTY, RELIANCE, CIPLA).
29
+
30
+ ---
31
+
32
+ ## Installation
33
+
34
+ Install the package via pip (once published to PyPI):
35
+
36
+ ```bash
37
+ pip install Trader_AngleOne
38
+ ```
39
+
40
+ ---
41
+
42
+ ## Quick Start & Usage
43
+
44
+ This library focuses exclusively on the **NSE Equity (NSE-EQ)** segment. It does not support Derivatives/Futures data.
45
+
46
+ Here is how to initialize the trader and fetch historical data across various timeframes:
47
+
48
+ ```python
49
+ from Trader_AngleOne import TraderAngleOne
50
+
51
+ # 1. Define your Angel One API credentials
52
+ crd = {
53
+ "api_key" : "abc",
54
+ "secret_key" : "abc-abc-abc",
55
+ "totp" : "abcAKBDLEMI",
56
+ "userid" : "U8XX1XX",
57
+ "pwd" : "1XX8",
58
+ }
59
+
60
+ # 2. Initialize the client using dictionary unpacking
61
+ angle = TraderAngleOne(**crd)
62
+
63
+ # 3. Fetch Historical Data (Parameters: Token/Symbol, Interval, Start Time, End Time, Exchange)
64
+
65
+ # Fetch 1-Minute Data
66
+ reliance_1 = angle.get_history_data('RELIANCE', '1', '2026-01-01 9:15', '2026-01-02 15:30', 'NSE')
67
+
68
+ # Fetch 3-Minute Data
69
+ reliance_3 = angle.get_history_data('RELIANCE', '3', '2026-01-01 9:15', '2026-01-02 15:30', 'NSE')
70
+
71
+ # Fetch 5-Minute Data
72
+ reliance_5 = angle.get_history_data('RELIANCE', '5', '2026-01-01 9:15', '2026-01-02 15:30', 'NSE')
73
+
74
+ # Fetch 15-Minute Data
75
+ reliance_15 = angle.get_history_data('RELIANCE', '15', '2026-01-01 9:15', '2026-01-02 15:30', 'NSE')
76
+
77
+ # Fetch 30-Minute Data
78
+ reliance_30 = angle.get_history_data('RELIANCE', '30', '2026-01-01 9:15', '2026-01-02 15:30', 'NSE')
79
+
80
+ # Fetch 1-Hour Data
81
+ reliance_1H = angle.get_history_data('RELIANCE', '1H', '2026-01-01 9:15', '2026-01-02 15:30', 'NSE')
82
+
83
+ # Fetch 1-Day Data
84
+ reliance_1D = angle.get_history_data('RELIANCE', '1D', '2026-01-01 9:15', '2026-01-02 15:30', 'NSE')
85
+ ```
86
+
87
+ ---
88
+
89
+ ## Supported Timeframes
90
+
91
+ Pass these exact string values into the second argument of `get_history_data()`:
92
+
93
+ - `"1"` - 1 Minute
94
+ - `"3"` - 3 Minutes
95
+ - `"5"` - 5 Minutes
96
+ - `"15"` - 15 Minutes
97
+ - `"30"` - 30 Minutes
98
+ - `"1H"` - 1 Hour
99
+ - `"1D"` - 1 Day
100
+
101
+ ---
102
+
103
+ ## License
104
+
105
+ # Distributed under the MIT License. See `LICENSE` for more information.
106
+
107
+ # Trader_AngleOne
108
+
109
+ > > > > > > > d983ccc6afe5dd7c494481585c5374dd60606e58
@@ -0,0 +1,90 @@
1
+ # Trader_AngleOne
2
+
3
+ A lightweight, efficient Python wrapper for fetching historical equity market data via Angel One SmartAPI.
4
+
5
+ ## Features
6
+
7
+ - **Easy Authentication:** Initialize seamlessly using dictionary unpacking.
8
+ - **Granular Timeframes:** Supports 1-minute up to daily data intervals.
9
+ - **NSE Equity Focus:** Built specifically to fetch NSE - EQ segment data (e.g., NIFTY, BANKNIFTY, RELIANCE, CIPLA).
10
+
11
+ ---
12
+
13
+ ## Installation
14
+
15
+ Install the package via pip (once published to PyPI):
16
+
17
+ ```bash
18
+ pip install Trader_AngleOne
19
+ ```
20
+
21
+ ---
22
+
23
+ ## Quick Start & Usage
24
+
25
+ This library focuses exclusively on the **NSE Equity (NSE-EQ)** segment. It does not support Derivatives/Futures data.
26
+
27
+ Here is how to initialize the trader and fetch historical data across various timeframes:
28
+
29
+ ```python
30
+ from Trader_AngleOne import TraderAngleOne
31
+
32
+ # 1. Define your Angel One API credentials
33
+ crd = {
34
+ "api_key" : "abc",
35
+ "secret_key" : "abc-abc-abc",
36
+ "totp" : "abcAKBDLEMI",
37
+ "userid" : "U8XX1XX",
38
+ "pwd" : "1XX8",
39
+ }
40
+
41
+ # 2. Initialize the client using dictionary unpacking
42
+ angle = TraderAngleOne(**crd)
43
+
44
+ # 3. Fetch Historical Data (Parameters: Token/Symbol, Interval, Start Time, End Time, Exchange)
45
+
46
+ # Fetch 1-Minute Data
47
+ reliance_1 = angle.get_history_data('RELIANCE', '1', '2026-01-01 9:15', '2026-01-02 15:30', 'NSE')
48
+
49
+ # Fetch 3-Minute Data
50
+ reliance_3 = angle.get_history_data('RELIANCE', '3', '2026-01-01 9:15', '2026-01-02 15:30', 'NSE')
51
+
52
+ # Fetch 5-Minute Data
53
+ reliance_5 = angle.get_history_data('RELIANCE', '5', '2026-01-01 9:15', '2026-01-02 15:30', 'NSE')
54
+
55
+ # Fetch 15-Minute Data
56
+ reliance_15 = angle.get_history_data('RELIANCE', '15', '2026-01-01 9:15', '2026-01-02 15:30', 'NSE')
57
+
58
+ # Fetch 30-Minute Data
59
+ reliance_30 = angle.get_history_data('RELIANCE', '30', '2026-01-01 9:15', '2026-01-02 15:30', 'NSE')
60
+
61
+ # Fetch 1-Hour Data
62
+ reliance_1H = angle.get_history_data('RELIANCE', '1H', '2026-01-01 9:15', '2026-01-02 15:30', 'NSE')
63
+
64
+ # Fetch 1-Day Data
65
+ reliance_1D = angle.get_history_data('RELIANCE', '1D', '2026-01-01 9:15', '2026-01-02 15:30', 'NSE')
66
+ ```
67
+
68
+ ---
69
+
70
+ ## Supported Timeframes
71
+
72
+ Pass these exact string values into the second argument of `get_history_data()`:
73
+
74
+ - `"1"` - 1 Minute
75
+ - `"3"` - 3 Minutes
76
+ - `"5"` - 5 Minutes
77
+ - `"15"` - 15 Minutes
78
+ - `"30"` - 30 Minutes
79
+ - `"1H"` - 1 Hour
80
+ - `"1D"` - 1 Day
81
+
82
+ ---
83
+
84
+ ## License
85
+
86
+ # Distributed under the MIT License. See `LICENSE` for more information.
87
+
88
+ # Trader_AngleOne
89
+
90
+ > > > > > > > d983ccc6afe5dd7c494481585c5374dd60606e58
@@ -0,0 +1,2 @@
1
+ from .map_stock import stocklist
2
+ from .main import TraderAngleOne
@@ -0,0 +1,108 @@
1
+ import io
2
+ import time
3
+ import pyotp
4
+ import logging
5
+ import contextlib
6
+ import pandas as pd
7
+ from .map_stock import stocklist
8
+ from SmartApi import SmartConnect
9
+ from datetime import datetime, timedelta
10
+
11
+
12
+
13
+ class TraderAngleOne:
14
+ def __init__(self, api_key, secret_key, totp, userid, pwd,**kwargs):
15
+ # Initialize API credentials
16
+ self.api_key = api_key
17
+ self.secret_key = secret_key
18
+ self.totp = totp
19
+ self.userid = userid
20
+ self.pwd = pwd
21
+
22
+ with contextlib.redirect_stdout(io.StringIO()), contextlib.redirect_stderr(io.StringIO()):
23
+ self.smartApi = SmartConnect(api_key=self.api_key)
24
+
25
+ print('\n',20*'-',"YOU ARE LOGIN",20*'-','\n')
26
+ self._generate_session()
27
+
28
+ self.TIMEFRAME_MAPPING = {
29
+ '1': "ONE_MINUTE",
30
+ '3': "THREE_MINUTE",
31
+ '5': "FIVE_MINUTE",
32
+ '10': "TEN_MINUTE",
33
+ '15': "FIFTEEN_MINUTE",
34
+ '30': "THIRTY_MINUTE",
35
+ "1H": "ONE_HOUR",
36
+ "1D": "ONE_DAY",
37
+ }
38
+
39
+ def _generate_session(self):
40
+ """Generate a session with the API."""
41
+ data = self.smartApi.generateSession(self.userid, self.pwd, pyotp.TOTP(self.totp).now())
42
+ self.autoken = data['data']['jwtToken']
43
+ self.refreshToken = data['data']['refreshToken']
44
+ self.smartApi.getProfile(self.refreshToken)
45
+ self.feedtoken = self.smartApi.getfeedToken()
46
+
47
+ def _fetch_historical_data(self, symbol, interval, fromdate, todate,exchange='NSE', max_retries=3, retry_delay=1):
48
+ """Helper function to fetch historical data with retry logic."""
49
+ token = stocklist.get(symbol)
50
+ if not token:
51
+ raise ValueError(f"Symbol {symbol} not found in stocklist.")
52
+
53
+ for attempt in range(max_retries):
54
+ try:
55
+ historicParam = {
56
+ "exchange": exchange,
57
+ "symboltoken": token,
58
+ "interval": self.TIMEFRAME_MAPPING.get(interval),
59
+ "fromdate": fromdate,
60
+ "todate": todate
61
+ }
62
+ response = self.smartApi.getCandleData(historicParam)
63
+ if not response or 'data' not in response or not response['data']:
64
+ raise ValueError("No data found in API response.")
65
+
66
+ historicalData = pd.DataFrame(response['data'])
67
+ if len(historicalData.columns) >= 6:
68
+ historicalData = historicalData.rename(columns={
69
+ 0: "Datetime", # Assuming the first column is the timestamp
70
+ 1: "o", # Open
71
+ 2: "h", # High
72
+ 3: "l", # Low
73
+ 4: "c", # Close
74
+ 5: "vol" # Volume
75
+ })
76
+ else:
77
+ raise ValueError("API response does not contain enough columns.")
78
+
79
+ historicalData["Datetime"] = pd.to_datetime(historicalData["Datetime"])
80
+ historicalData = historicalData.set_index('Datetime')
81
+ return historicalData
82
+ except Exception as e:
83
+ print(f"Attempt {attempt + 1} failed for {symbol}: {e}")
84
+ if attempt < max_retries - 1:
85
+ print(f"Retrying in {retry_delay} seconds...")
86
+ time.sleep(retry_delay)
87
+ else:
88
+ print(f"Max retries reached for {symbol}. Skipping this symbol.")
89
+ return None
90
+
91
+ # angle.get_history_data(stockName,'5',f'2023-01-02 09:15',f'2023-01-02 15:30')
92
+ def get_history_data(self, symbol, interval, fromdate, todate,exchange="NSE"):
93
+ """Get historical data for a specific period."""
94
+ ff = fromdate[:10]
95
+ to = todate[:10]
96
+ ff = datetime.strptime(ff, '%Y-%m-%d')
97
+ to = datetime.strptime(to, '%Y-%m-%d')
98
+
99
+
100
+ if (ff > to) or (ff > datetime.strptime(datetime.now().strftime("%Y-%m-%d") + " 00:00:00", "%Y-%m-%d %H:%M:%S")):
101
+ print(f"Provided date {fromdate} is a holiday. Try for the next date.")
102
+ return None
103
+
104
+ return self._fetch_historical_data(symbol, interval, fromdate, todate,exchange)
105
+
106
+
107
+
108
+