Skip to content

Commit c2e2551

Browse files
authored
Update NSE-Option-Chain-Analyzer.py
1 parent 51d60fd commit c2e2551

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed

NSE-Option-Chain-Analyzer.py

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
class Nse:
1414
def __init__(self, window):
1515
self.seconds = 60
16+
self.previous_date = None
17+
self.previous_time = None
1618
self.first_run = True
1719
self.stop = False
1820
self.dates = [""]
@@ -44,7 +46,6 @@ def get_data(self, event="empty"):
4446
response = requests.get(url, headers=self.headers, timeout=5)
4547
except Exception as err:
4648
print(err)
47-
self.root.after((self.seconds * 1000), self.main)
4849
return
4950

5051
if response is not None:
@@ -64,7 +65,6 @@ def get_data(self, event="empty"):
6465
self.date_menu.current(0)
6566
return
6667
elif json_data == {}:
67-
self.root.after((self.seconds * 1000), self.main)
6868
return
6969

7070
if self.first_run:
@@ -212,7 +212,7 @@ def about(self, event="empty"):
212212
heading.grid(row=0, column=0, columnspan=2, sticky=N + S + W + E)
213213
version_label = Label(self.info, text="Version:", relief=RIDGE)
214214
version_label.grid(row=1, column=0, sticky=N + S + W + E)
215-
version_val = Label(self.info, text="3.1", relief=RIDGE)
215+
version_val = Label(self.info, text="3.2", relief=RIDGE)
216216
version_val.grid(row=1, column=1, sticky=N + S + W + E)
217217
dev_label = Label(self.info, text="Developer:", relief=RIDGE)
218218
dev_label.grid(row=2, column=0, sticky=N + S + W + E)
@@ -252,7 +252,7 @@ def main_win(self):
252252
window_height = self.root.winfo_reqheight()
253253
position_right = int(self.root.winfo_screenwidth() / 3 - window_width / 2)
254254
position_down = int(self.root.winfo_screenheight() / 3 - window_height / 2)
255-
self.root.geometry("910x510+{}+{}".format(position_right, position_down))
255+
self.root.geometry("815x510+{}+{}".format(position_right, position_down))
256256
self.root.rowconfigure(0, weight=1)
257257
self.root.columnconfigure(0, weight=1)
258258

@@ -277,10 +277,11 @@ def main_win(self):
277277
top_frame.pack(fill="both", expand=True)
278278

279279
output_columns = (
280-
'Time', 'Points', 'Call Sum', 'Put Sum', 'Difference', 'Call Boundary', 'Put Boundary', 'Call ITM',
281-
'Put ITM')
282-
self.sheet = tksheet.Sheet(top_frame, column_width=95, align="center", headers=output_columns,
283-
header_font=("TkDefaultFont", 9, "bold"), empty_horizontal=0, empty_vertical=20)
280+
'Time', 'Points', 'Call Sum\n(in K)', 'Put Sum\n(in K)', 'Difference\n(in K)', 'Call Boundary\n(in K)',
281+
'Put Boundary\n(in K)', 'Call ITM', 'Put ITM')
282+
self.sheet = tksheet.Sheet(top_frame, column_width=85, align="center", headers=output_columns,
283+
header_font=("TkDefaultFont", 9, "bold"), empty_horizontal=0,
284+
empty_vertical=20, header_height=35)
284285
self.sheet.enable_bindings(
285286
("toggle_select", "drag_select", "column_select", "row_select", "column_width_resize",
286287
"arrowkeys", "right_click_popup_menu", "rc_select", "copy", "select_all"))
@@ -380,6 +381,11 @@ def get_dataframe(self):
380381
pe_data = pandas.DataFrame(pe_values)
381382
ce_data_f = ce_data.loc[ce_data['expiryDate'] == self.expiry_date]
382383
pe_data_f = pe_data.loc[pe_data['expiryDate'] == self.expiry_date]
384+
if ce_data_f.empty:
385+
messagebox.showerror(title="Error",
386+
message="Invalid Expiry Date.\nPlease restart and enter a new Expiry Date.")
387+
self.change_state()
388+
return
383389
columns_ce = ['openInterest', 'changeinOpenInterest', 'totalTradedVolume', 'impliedVolatility', 'lastPrice',
384390
'change', 'bidQty', 'bidprice', 'askPrice', 'askQty', 'strikePrice']
385391
columns_pe = ['strikePrice', 'bidQty', 'bidprice', 'askPrice', 'askQty', 'change', 'lastPrice',
@@ -544,15 +550,20 @@ def main(self):
544550
return
545551

546552
self.str_current_time = current_time.split(" ")[1]
547-
current_time = datetime.datetime.strptime(self.str_current_time, '%H:%M:%S').time()
548-
553+
current_date = datetime.datetime.strptime(current_time.split(" ")[0], '%d-%b-%Y').date()
554+
current_time = datetime.datetime.strptime(current_time.split(" ")[1], '%H:%M:%S').time()
549555
if self.first_run:
556+
self.previous_date = current_date
550557
self.previous_time = current_time
551-
elif current_time > self.previous_time:
558+
elif current_date > self.previous_date:
559+
self.previous_date = current_date
552560
self.previous_time = current_time
553-
else:
554-
self.root.after((self.seconds * 1000), self.main)
555-
return
561+
elif current_date == self.previous_date:
562+
if current_time > self.previous_time:
563+
self.previous_time = current_time
564+
else:
565+
self.root.after((self.seconds * 1000), self.main)
566+
return
556567

557568
call_oi_list = []
558569
for i in range(len(df)):

0 commit comments

Comments
 (0)