quantmod 0.1.0__tar.gz → 0.1.1__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.
- {quantmod-0.1.0 → quantmod-0.1.1}/PKG-INFO +1 -1
- {quantmod-0.1.0 → quantmod-0.1.1}/quantmod/charts/plotting.py +2 -2
- {quantmod-0.1.0 → quantmod-0.1.1}/quantmod/derivatives/nse.py +147 -75
- quantmod-0.1.1/quantmod/version.py +1 -0
- {quantmod-0.1.0 → quantmod-0.1.1}/quantmod.egg-info/PKG-INFO +1 -1
- quantmod-0.1.0/quantmod/version.py +0 -1
- {quantmod-0.1.0 → quantmod-0.1.1}/LICENSE.txt +0 -0
- {quantmod-0.1.0 → quantmod-0.1.1}/README.md +0 -0
- {quantmod-0.1.0 → quantmod-0.1.1}/quantmod/__init__.py +0 -0
- {quantmod-0.1.0 → quantmod-0.1.1}/quantmod/_version.py +0 -0
- {quantmod-0.1.0 → quantmod-0.1.1}/quantmod/charts/__init__.py +0 -0
- {quantmod-0.1.0 → quantmod-0.1.1}/quantmod/charts/themes.py +0 -0
- {quantmod-0.1.0 → quantmod-0.1.1}/quantmod/datasets/__init__.py +0 -0
- {quantmod-0.1.0 → quantmod-0.1.1}/quantmod/datasets/data/nifty50.csv +0 -0
- {quantmod-0.1.0 → quantmod-0.1.1}/quantmod/datasets/data/spx.csv +0 -0
- {quantmod-0.1.0 → quantmod-0.1.1}/quantmod/datasets/dataloader.py +0 -0
- {quantmod-0.1.0 → quantmod-0.1.1}/quantmod/derivatives/__init__.py +0 -0
- {quantmod-0.1.0 → quantmod-0.1.1}/quantmod/indicators/__init__.py +0 -0
- {quantmod-0.1.0 → quantmod-0.1.1}/quantmod/indicators/indicators.py +0 -0
- {quantmod-0.1.0 → quantmod-0.1.1}/quantmod/main.py +0 -0
- {quantmod-0.1.0 → quantmod-0.1.1}/quantmod/markets/__init__.py +0 -0
- {quantmod-0.1.0 → quantmod-0.1.1}/quantmod/markets/bb.py +0 -0
- {quantmod-0.1.0 → quantmod-0.1.1}/quantmod/markets/yahoo.py +0 -0
- {quantmod-0.1.0 → quantmod-0.1.1}/quantmod/models/__init__.py +0 -0
- {quantmod-0.1.0 → quantmod-0.1.1}/quantmod/models/binomial.py +0 -0
- {quantmod-0.1.0 → quantmod-0.1.1}/quantmod/models/blackscholes.py +0 -0
- {quantmod-0.1.0 → quantmod-0.1.1}/quantmod/models/montecarlo.py +0 -0
- {quantmod-0.1.0 → quantmod-0.1.1}/quantmod/models/optioninputs.py +0 -0
- {quantmod-0.1.0 → quantmod-0.1.1}/quantmod/risk/__init__.py +0 -0
- {quantmod-0.1.0 → quantmod-0.1.1}/quantmod/risk/var.py +0 -0
- {quantmod-0.1.0 → quantmod-0.1.1}/quantmod/risk/varbacktest.py +0 -0
- {quantmod-0.1.0 → quantmod-0.1.1}/quantmod/risk/varinputs.py +0 -0
- {quantmod-0.1.0 → quantmod-0.1.1}/quantmod/timeseries/__init__.py +0 -0
- {quantmod-0.1.0 → quantmod-0.1.1}/quantmod/timeseries/performance.py +0 -0
- {quantmod-0.1.0 → quantmod-0.1.1}/quantmod/timeseries/timeseries.py +0 -0
- {quantmod-0.1.0 → quantmod-0.1.1}/quantmod/utils.py +0 -0
- {quantmod-0.1.0 → quantmod-0.1.1}/quantmod.egg-info/SOURCES.txt +0 -0
- {quantmod-0.1.0 → quantmod-0.1.1}/quantmod.egg-info/dependency_links.txt +0 -0
- {quantmod-0.1.0 → quantmod-0.1.1}/quantmod.egg-info/entry_points.txt +0 -0
- {quantmod-0.1.0 → quantmod-0.1.1}/quantmod.egg-info/not-zip-safe +0 -0
- {quantmod-0.1.0 → quantmod-0.1.1}/quantmod.egg-info/requires.txt +0 -0
- {quantmod-0.1.0 → quantmod-0.1.1}/quantmod.egg-info/top_level.txt +0 -0
- {quantmod-0.1.0 → quantmod-0.1.1}/setup.cfg +0 -0
- {quantmod-0.1.0 → quantmod-0.1.1}/setup.py +0 -0
|
@@ -235,7 +235,7 @@ def _plot_histogram(df, columns=None, **kwargs):
|
|
|
235
235
|
for i, col in enumerate(columns):
|
|
236
236
|
fig.add_trace(
|
|
237
237
|
go.Histogram(
|
|
238
|
-
x=df[col]
|
|
238
|
+
x=df[col],
|
|
239
239
|
nbinsx=kwargs.get("nbinsx", 50),
|
|
240
240
|
name=col,
|
|
241
241
|
opacity=0.75,
|
|
@@ -249,7 +249,7 @@ def _plot_histogram(df, columns=None, **kwargs):
|
|
|
249
249
|
r, c = divmod(i, ncols)
|
|
250
250
|
fig.add_trace(
|
|
251
251
|
go.Histogram(
|
|
252
|
-
x=df[col]
|
|
252
|
+
x=df[col],
|
|
253
253
|
nbinsx=kwargs.get("nbinsx", 50),
|
|
254
254
|
name=col,
|
|
255
255
|
opacity=0.75,
|
|
@@ -12,87 +12,159 @@ import logging
|
|
|
12
12
|
import re
|
|
13
13
|
import urllib.parse
|
|
14
14
|
|
|
15
|
-
#
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
headers = {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
"upgrade-insecure-requests": "1",
|
|
31
|
-
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36 Edg/129.0.0.0",
|
|
15
|
+
# --- Configuration ---
|
|
16
|
+
mode = "auto" # can be "local", "vpn", or "auto"
|
|
17
|
+
|
|
18
|
+
headers = {"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
|
|
19
|
+
"accept-language": "en-US,en;q=0.9,en-IN;q=0.8,en-GB;q=0.7",
|
|
20
|
+
"cache-control": "max-age=0",
|
|
21
|
+
"priority": "u=0, i",
|
|
22
|
+
"sec-ch-ua": '"Microsoft Edge";v="129", "Not=A?Brand";v="8", "Chromium";v="129"', "sec-ch-ua-mobile": "?0",
|
|
23
|
+
"sec-ch-ua-platform": '"Windows"',
|
|
24
|
+
"sec-fetch-dest": "document",
|
|
25
|
+
"sec-fetch-mode": "navigate",
|
|
26
|
+
"sec-fetch-site": "none",
|
|
27
|
+
"sec-fetch-user": "?1",
|
|
28
|
+
"upgrade-insecure-requests": "1",
|
|
29
|
+
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36 Edg/129.0.0.0",
|
|
32
30
|
}
|
|
33
31
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
mode = "local" if country_code == "IN" else "vpn"
|
|
54
|
-
else:
|
|
55
|
-
mode = "local"
|
|
56
|
-
|
|
57
|
-
except Exception:
|
|
58
|
-
mode = "local"
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
def nsefetch(payload):
|
|
62
|
-
if mode == "vpn":
|
|
63
|
-
if ("%26" in payload) or ("%20" in payload):
|
|
64
|
-
encoded_url = payload
|
|
65
|
-
else:
|
|
66
|
-
encoded_url = urllib.parse.quote(payload, safe=":/?&=")
|
|
67
|
-
payload_var = 'curl -b cookies.txt "' + encoded_url + '"' + curl_headers + ""
|
|
32
|
+
curl_headers = ''' -H "authority: beta.nseindia.com" -H "cache-control: max-age=0" -H "dnt: 1" -H "upgrade-insecure-requests: 1" -H "user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36" -H "sec-fetch-user: ?1" -H "accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9" -H "sec-fetch-site: none" -H "sec-fetch-mode: navigate" -H "accept-encoding: gzip, deflate, br" -H "accept-language: en-US,en;q=0.9,hi;q=0.8" --compressed'''
|
|
33
|
+
|
|
34
|
+
# --- Main function ---
|
|
35
|
+
def nsefetch(payload: str):
|
|
36
|
+
def encode(url: str) -> str:
|
|
37
|
+
if "%26" in url or "%20" in url:
|
|
38
|
+
return url
|
|
39
|
+
return urllib.parse.quote(url, safe=":/?&=")
|
|
40
|
+
|
|
41
|
+
def refresh_cookies():
|
|
42
|
+
os.popen(f'curl -c cookies.txt "https://www.nseindia.com" {curl_headers}').read()
|
|
43
|
+
os.popen(f'curl -b cookies.txt -c cookies.txt "https://www.nseindia.com/option-chain" {curl_headers}').read()
|
|
44
|
+
|
|
45
|
+
def curl_fetch(url: str):
|
|
46
|
+
encoded_url = encode(url)
|
|
47
|
+
if not os.path.exists("cookies.txt"):
|
|
48
|
+
refresh_cookies()
|
|
49
|
+
cmd = f'curl -b cookies.txt "{encoded_url}" {curl_headers}'
|
|
50
|
+
raw = os.popen(cmd).read()
|
|
68
51
|
try:
|
|
69
|
-
|
|
70
|
-
output = json.loads(output)
|
|
71
|
-
except ValueError: # includes simplejson.decoder.JSONDecodeError:
|
|
72
|
-
payload2 = "https://www.nseindia.com"
|
|
73
|
-
output2 = os.popen(
|
|
74
|
-
'curl -c cookies.txt "' + payload2 + '"' + curl_headers + ""
|
|
75
|
-
).read()
|
|
76
|
-
|
|
77
|
-
output = os.popen(payload_var).read()
|
|
78
|
-
output = json.loads(output)
|
|
79
|
-
return output
|
|
80
|
-
|
|
81
|
-
else: # mode == "local":
|
|
82
|
-
try:
|
|
83
|
-
output = requests.get(payload, headers=headers).json()
|
|
84
|
-
# print(output)
|
|
52
|
+
return json.loads(raw)
|
|
85
53
|
except ValueError:
|
|
86
|
-
|
|
54
|
+
refresh_cookies()
|
|
55
|
+
raw = os.popen(cmd).read()
|
|
87
56
|
try:
|
|
88
|
-
|
|
89
|
-
output = s.get(payload, headers=headers).json()
|
|
57
|
+
return json.loads(raw)
|
|
90
58
|
except ValueError:
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
59
|
+
return {}
|
|
60
|
+
|
|
61
|
+
def requests_fetch(url: str):
|
|
62
|
+
try:
|
|
63
|
+
s = requests.Session()
|
|
64
|
+
s.get("https://www.nseindia.com", headers=headers, timeout=10)
|
|
65
|
+
s.get("https://www.nseindia.com/option-chain", headers=headers, timeout=10)
|
|
66
|
+
return s.get(url, headers=headers, timeout=10).json()
|
|
67
|
+
except Exception:
|
|
68
|
+
return {}
|
|
69
|
+
|
|
70
|
+
# --- Auto / Mode selection ---
|
|
71
|
+
if mode == "local":
|
|
72
|
+
return requests_fetch(payload)
|
|
73
|
+
elif mode == "vpn":
|
|
74
|
+
return curl_fetch(payload)
|
|
75
|
+
else:
|
|
76
|
+
# Auto mode: try requests first, fallback to curl
|
|
77
|
+
data = requests_fetch(payload)
|
|
78
|
+
if not data:
|
|
79
|
+
print("⚠️ Local fetch failed — switching to curl + cookies.")
|
|
80
|
+
data = curl_fetch(payload)
|
|
81
|
+
return data
|
|
82
|
+
|
|
83
|
+
# --- Utility constants ---
|
|
84
|
+
indices = ["NIFTY", "FINNIFTY", "BANKNIFTY"]
|
|
85
|
+
|
|
86
|
+
# # Constants
|
|
87
|
+
# indices = ["NIFTY", "FINNIFTY", "BANKNIFTY"]
|
|
88
|
+
|
|
89
|
+
# headers = {
|
|
90
|
+
# "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
|
|
91
|
+
# "accept-language": "en-US,en;q=0.9,en-IN;q=0.8,en-GB;q=0.7",
|
|
92
|
+
# "cache-control": "max-age=0",
|
|
93
|
+
# "priority": "u=0, i",
|
|
94
|
+
# "sec-ch-ua": '"Microsoft Edge";v="129", "Not=A?Brand";v="8", "Chromium";v="129"',
|
|
95
|
+
# "sec-ch-ua-mobile": "?0",
|
|
96
|
+
# "sec-ch-ua-platform": '"Windows"',
|
|
97
|
+
# "sec-fetch-dest": "document",
|
|
98
|
+
# "sec-fetch-mode": "navigate",
|
|
99
|
+
# "sec-fetch-site": "none",
|
|
100
|
+
# "sec-fetch-user": "?1",
|
|
101
|
+
# "upgrade-insecure-requests": "1",
|
|
102
|
+
# "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36 Edg/129.0.0.0",
|
|
103
|
+
# }
|
|
104
|
+
|
|
105
|
+
# # Curl headers
|
|
106
|
+
# curl_headers = """ -H "authority: beta.nseindia.com" -H "cache-control: max-age=0" -H "dnt: 1" -H "upgrade-insecure-requests: 1" -H "user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36" -H "sec-fetch-user: ?1" -H "accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9" -H "sec-fetch-site: none" -H "sec-fetch-mode: navigate" -H "accept-encoding: gzip, deflate, br" -H "accept-language: en-US,en;q=0.9,hi;q=0.8" --compressed"""
|
|
107
|
+
|
|
108
|
+
# # https://ipapi.co/json
|
|
109
|
+
# # https://ipinfo.io/json
|
|
110
|
+
|
|
111
|
+
# try:
|
|
112
|
+
# # Try ipapi.co
|
|
113
|
+
# response = requests.get("https://ipapi.co/json/", timeout=5)
|
|
114
|
+
# if response.status_code == 200:
|
|
115
|
+
# data = response.json()
|
|
116
|
+
# country_code = data.get('country_code', '').upper()
|
|
117
|
+
# mode = "local" if country_code == "IN" else "vpn"
|
|
118
|
+
# else:
|
|
119
|
+
# # Fallback to ipinfo.io
|
|
120
|
+
# response = requests.get("https://ipinfo.io/json", timeout=5)
|
|
121
|
+
# if response.status_code == 200:
|
|
122
|
+
# data = response.json()
|
|
123
|
+
# country_code = data.get('country', '').upper()
|
|
124
|
+
# mode = "local" if country_code == "IN" else "vpn"
|
|
125
|
+
# else:
|
|
126
|
+
# mode = "local"
|
|
127
|
+
|
|
128
|
+
# except Exception:
|
|
129
|
+
# mode = "local"
|
|
130
|
+
|
|
131
|
+
# # Force local mode only if you’re sure your machine is in India
|
|
132
|
+
# mode = "local"
|
|
133
|
+
# def nsefetch(payload):
|
|
134
|
+
# if mode == "vpn":
|
|
135
|
+
# if ("%26" in payload) or ("%20" in payload):
|
|
136
|
+
# encoded_url = payload
|
|
137
|
+
# else:
|
|
138
|
+
# encoded_url = urllib.parse.quote(payload, safe=":/?&=")
|
|
139
|
+
# payload_var = 'curl -b cookies.txt "' + encoded_url + '"' + curl_headers + ""
|
|
140
|
+
# try:
|
|
141
|
+
# output = os.popen(payload_var).read()
|
|
142
|
+
# output = json.loads(output)
|
|
143
|
+
# except ValueError: # includes simplejson.decoder.JSONDecodeError:
|
|
144
|
+
# payload2 = "https://www.nseindia.com"
|
|
145
|
+
# output2 = os.popen(
|
|
146
|
+
# 'curl -c cookies.txt "' + payload2 + '"' + curl_headers + ""
|
|
147
|
+
# ).read()
|
|
148
|
+
|
|
149
|
+
# output = os.popen(payload_var).read()
|
|
150
|
+
# output = json.loads(output)
|
|
151
|
+
# return output
|
|
152
|
+
|
|
153
|
+
# else: # mode == "local":
|
|
154
|
+
# try:
|
|
155
|
+
# output = requests.get(payload, headers=headers).json()
|
|
156
|
+
# # print(output)
|
|
157
|
+
# except ValueError:
|
|
158
|
+
# s = requests.Session()
|
|
159
|
+
# try:
|
|
160
|
+
# output = s.get("http://nseindia.com/option-chain", headers=headers)
|
|
161
|
+
# output = s.get(payload, headers=headers).json()
|
|
162
|
+
# except ValueError:
|
|
163
|
+
# output = s.get("https://www.nseindia.com", headers=headers)
|
|
164
|
+
# output = output.json()
|
|
165
|
+
# # output = s.get("https://www.nseindia.com/option-chain", headers=headers) # replaced http://nseindia.com with https://www.nseindia.com/option-chain
|
|
166
|
+
# output = s.get(payload, headers=headers).json()
|
|
167
|
+
# return output
|
|
96
168
|
|
|
97
169
|
|
|
98
170
|
class OptionData:
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
version = "0.1.1"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
version = "0.1.0"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|