-
Notifications
You must be signed in to change notification settings - Fork 217
/
NSE_Option_Chain_Analyzer.py
1588 lines (1464 loc) · 82.8 KB
/
NSE_Option_Chain_Analyzer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import configparser
import csv
import datetime
import os
import platform
import sys
import time
import webbrowser
from tkinter import Tk, Toplevel, Event, TclError, StringVar, Frame, Menu, Label, Entry, SOLID, RIDGE, \
DISABLED, NORMAL, N, S, E, W, LEFT, messagebox, PhotoImage
from tkinter.ttk import Combobox, Button
from typing import Union, Optional, List, Dict, Tuple, TextIO, Any
import pandas
import requests
import streamtologger
import tksheet
is_windows: bool = platform.system() == "Windows"
is_windows_10_or_11: bool = is_windows and platform.release() == "10"
if is_windows_10_or_11:
# noinspection PyUnresolvedReferences
import win10toast
# noinspection PyAttributeOutsideInit
class Nse:
version: str = '5.6'
def __init__(self, window: Tk) -> None:
self.intervals: List[int] = [1, 2, 3, 5, 10, 15]
self.stdout: TextIO = sys.stdout
self.stderr: TextIO = sys.stderr
self.previous_date: Optional[datetime.date] = None
self.previous_time: Optional[datetime.time] = None
self.time_difference_factor: int = 5
self.first_run: bool = True
self.stop: bool = False
self.dates: List[str] = [""]
self.indices: List[str] = []
self.stocks: List[str] = []
self.url_oc: str = "https://www.nseindia.com/option-chain"
self.url_index: str = "https://www.nseindia.com/api/option-chain-indices?symbol="
self.url_stock: str = "https://www.nseindia.com/api/option-chain-equities?symbol="
self.url_symbols: str = "https://www.nseindia.com/api/underlying-information"
self.url_icon_png: str = "https://raw.githubusercontent.com/VarunS2002/" \
"Python-NSE-Option-Chain-Analyzer/master/nse_logo.png"
self.url_icon_ico: str = "https://raw.githubusercontent.com/VarunS2002/" \
"Python-NSE-Option-Chain-Analyzer/master/nse_logo.ico"
self.url_update: str = "https://api.github.com/repos/VarunS2002/" \
"Python-NSE-Option-Chain-Analyzer/releases/latest"
self.headers: Dict[str, str] = {
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) '
'Chrome/130.0.0.0 Safari/537.36',
'accept-language': 'en,gu;q=0.9,hi;q=0.8',
'accept-encoding': 'gzip, deflate, br'}
self.session: requests.Session = requests.Session()
self.cookies: Dict[str, str] = {}
self.get_symbols(window)
self.config_parser: configparser.ConfigParser = configparser.ConfigParser()
self.create_config(new=True) if not os.path.isfile('NSE-OCA.ini') else None
self.get_config()
self.log_file: Optional[TextIO] = None
self.log() if self.logging else None
self.units_str: str = 'in K' if self.option_mode == 'Index' else 'in 10s'
self.output_columns: Tuple[str, str, str, str, str, str, str, str, str] = (
'Time', 'Value', f'Call Sum\n({self.units_str})', f'Put Sum\n({self.units_str})',
f'Difference\n({self.units_str})', f'Call Boundary\n({self.units_str})',
f'Put Boundary\n({self.units_str})', 'Call ITM', 'Put ITM')
self.csv_headers: Tuple[str, str, str, str, str, str, str, str, str] = (
'Time', 'Value', f'Call Sum ({self.units_str})', f'Put Sum ({self.units_str})',
f'Difference ({self.units_str})',
f'Call Boundary ({self.units_str})', f'Put Boundary ({self.units_str})', 'Call ITM', 'Put ITM')
self.toaster: win10toast.ToastNotifier = win10toast.ToastNotifier() if is_windows_10_or_11 else None
self.get_icon()
self.login_win(window)
def get_symbols(self, window: Tk) -> None:
def create_error_window(error_window: Tk):
error_window.title("NSE-Option-Chain-Analyzer")
window_width: int = error_window.winfo_reqwidth()
window_height: int = error_window.winfo_reqheight()
position_right: int = int(error_window.winfo_screenwidth() / 2 - window_width / 2)
position_down: int = int(error_window.winfo_screenheight() / 2 - window_height / 2)
error_window.geometry("320x160+{}+{}".format(position_right, position_down))
messagebox.showerror(title="Error", message="Failed to fetch Symbols.\nThe program will now exit.")
error_window.destroy()
try:
request: requests.Response = self.session.get(self.url_oc, headers=self.headers, timeout=5)
self.cookies = dict(request.cookies)
response: requests.Response = self.session.get(self.url_symbols, headers=self.headers, timeout=5,
cookies=self.cookies)
except Exception as err:
print(err, sys.exc_info()[0], "19")
create_error_window(window)
sys.exit()
try:
json_data: Dict[str, Dict[str, List[Dict[str, Union[str, int]]]]] = response.json()
except Exception as err:
print(response)
print(err, sys.exc_info()[0], "20")
create_error_window(window)
sys.exit()
self.indices = [item['symbol'] for item in json_data['data']['IndexList']]
self.stocks = [item['symbol'] for item in json_data['data']['UnderlyingList']]
def get_icon(self) -> None:
self.icon_png_path: str
self.icon_ico_path: str
try:
# noinspection PyProtectedMember,PyUnresolvedReferences
base_path: str = sys._MEIPASS
self.icon_png_path = os.path.join(base_path, 'nse_logo.png')
self.icon_ico_path = os.path.join(base_path, 'nse_logo.ico')
self.load_nse_icon = True
except AttributeError:
if self.load_nse_icon:
try:
icon_png_raw: requests.Response = requests.get(self.url_icon_png, headers=self.headers, stream=True)
with open('.NSE-OCA.png', 'wb') as f:
for chunk in icon_png_raw.iter_content(1024):
f.write(chunk)
self.icon_png_path = '.NSE-OCA.png'
PhotoImage(file=self.icon_png_path)
except Exception as err:
print(err, sys.exc_info()[0], "17")
self.load_nse_icon = False
return
if is_windows_10_or_11:
try:
icon_ico_raw: requests.Response = requests.get(self.url_icon_ico,
headers=self.headers, stream=True)
with open('.NSE-OCA.ico', 'wb') as f:
for chunk in icon_ico_raw.iter_content(1024):
f.write(chunk)
self.icon_ico_path = '.NSE-OCA.ico'
except Exception as err:
print(err, sys.exc_info()[0], "18")
self.icon_ico_path = None
return
def check_for_updates(self, auto: bool = True) -> None:
try:
release_data: requests.Response = requests.get(self.url_update, headers=self.headers, timeout=5)
latest_version: str = release_data.json()['tag_name']
except Exception as err:
print(err, sys.exc_info()[0], "21")
if not auto:
self.info.attributes('-topmost', False)
messagebox.showerror(title="Error", message="Failed to check for updates.")
self.info.attributes('-topmost', True)
return
if float(latest_version) > float(Nse.version):
self.info.attributes('-topmost', False) if not auto else None
update: bool = messagebox.askyesno(
title="New Update Available",
message=f"You are running version: {Nse.version}\n"
f"Latest version: {latest_version}\n"
f"Do you want to update now ?\n"
f"{'You can disable auto check for updates from the menu.' if auto and self.update else ''}")
if update:
webbrowser.open_new("https://github.com/VarunS2002/Python-NSE-Option-Chain-Analyzer/releases/latest")
self.info.attributes('-topmost', False) if not auto else None
else:
self.info.attributes('-topmost', True) if not auto else None
else:
if not auto:
self.info.attributes('-topmost', False)
messagebox.showinfo(title="No Updates Available", message=f"You are running the latest version.\n"
f"Version: {Nse.version}")
self.info.attributes('-topmost', True)
def get_config(self) -> None:
try:
self.config_parser.read('NSE-OCA.ini')
try:
self.load_nse_icon: bool = self.config_parser.getboolean('main', 'load_nse_icon')
except (configparser.NoOptionError, ValueError) as err:
print(err, sys.exc_info()[0], "0")
self.create_config(attribute="load_nse_icon")
self.load_nse_icon: bool = self.config_parser.getboolean('main', 'load_nse_icon')
try:
self.index: str = self.config_parser.get('main', 'index')
if self.index not in self.indices:
raise ValueError(f'{self.index} is not a valid index')
except (configparser.NoOptionError, ValueError) as err:
print(err, sys.exc_info()[0], "0")
self.create_config(attribute="index")
self.index: str = self.config_parser.get('main', 'index')
try:
self.stock: str = self.config_parser.get('main', 'stock')
if self.stock not in self.stocks:
raise ValueError(f'{self.stock} is not a valid stock')
except (configparser.NoOptionError, ValueError) as err:
print(err, sys.exc_info()[0], "0")
self.create_config(attribute="stock")
self.stock: str = self.config_parser.get('main', 'stock')
try:
self.option_mode: str = self.config_parser.get('main', 'option_mode')
if self.option_mode not in ('Index', 'Stock'):
raise ValueError(f'{self.option_mode} is not a valid option mode')
except (configparser.NoOptionError, ValueError) as err:
print(err, sys.exc_info()[0], "0")
self.create_config(attribute="option_mode")
self.option_mode: str = self.config_parser.get('main', 'option_mode')
try:
self.seconds: int = self.config_parser.getint('main', 'seconds')
if self.seconds not in (60, 120, 180, 300, 600, 900):
raise ValueError(f'{self.seconds} is not a refresh interval')
except (configparser.NoOptionError, ValueError) as err:
print(err, sys.exc_info()[0], "0")
self.create_config(attribute="seconds")
self.seconds: int = self.config_parser.getint('main', 'seconds')
try:
self.live_export: bool = self.config_parser.getboolean('main', 'live_export')
except (configparser.NoOptionError, ValueError) as err:
print(err, sys.exc_info()[0], "0")
self.create_config(attribute="live_export")
self.live_export: bool = self.config_parser.getboolean('main', 'live_export')
try:
self.save_oc: bool = self.config_parser.getboolean('main', 'save_oc')
except (configparser.NoOptionError, ValueError) as err:
print(err, sys.exc_info()[0], "0")
self.create_config(attribute="save_oc")
self.save_oc: bool = self.config_parser.getboolean('main', 'save_oc')
try:
self.notifications: bool = self.config_parser.getboolean('main', 'notifications') \
if is_windows_10_or_11 else False
except (configparser.NoOptionError, ValueError) as err:
print(err, sys.exc_info()[0], "0")
self.create_config(attribute="notifications")
self.notifications: bool = self.config_parser.getboolean('main', 'notifications') \
if is_windows_10_or_11 else False
try:
self.auto_stop: bool = self.config_parser.getboolean('main', 'auto_stop')
except (configparser.NoOptionError, ValueError) as err:
print(err, sys.exc_info()[0], "0")
self.create_config(attribute="auto_stop")
self.auto_stop: bool = self.config_parser.getboolean('main', 'auto_stop')
try:
self.update: bool = self.config_parser.getboolean('main', 'update')
except (configparser.NoOptionError, ValueError) as err:
print(err, sys.exc_info()[0], "0")
self.create_config(attribute="update")
self.update: bool = self.config_parser.getboolean('main', 'update')
try:
self.logging: bool = self.config_parser.getboolean('main', 'logging')
except (configparser.NoOptionError, ValueError) as err:
print(err, sys.exc_info()[0], "0")
self.create_config(attribute="logging")
self.logging: bool = self.config_parser.getboolean('main', 'logging')
try:
self.warn_late_update: bool = self.config_parser.getboolean('main', 'warn_late_update')
except (configparser.NoOptionError, ValueError) as err:
print(err, sys.exc_info()[0], "0")
self.create_config(attribute="warn_late_update")
self.warn_late_update: bool = self.config_parser.getboolean('main', 'warn_late_update')
except (configparser.NoSectionError, configparser.MissingSectionHeaderError,
configparser.DuplicateSectionError, configparser.DuplicateOptionError) as err:
print(err, sys.exc_info()[0], "0")
self.create_config(corrupted=True)
return self.get_config()
def create_config(self, new: bool = False, corrupted: bool = False, attribute: Optional[str] = None) -> None:
if new or corrupted:
if corrupted:
os.remove('NSE-OCA.ini')
self.config_parser = configparser.ConfigParser()
self.config_parser.read('NSE-OCA.ini')
self.config_parser.add_section('main')
self.config_parser.set('main', 'load_nse_icon', 'True')
self.config_parser.set('main', 'index', self.indices[0])
self.config_parser.set('main', 'stock', self.stocks[0])
self.config_parser.set('main', 'option_mode', 'Index')
self.config_parser.set('main', 'seconds', '60')
self.config_parser.set('main', 'live_export', 'False')
self.config_parser.set('main', 'save_oc', 'False')
self.config_parser.set('main', 'notifications', 'False')
self.config_parser.set('main', 'auto_stop', 'False')
self.config_parser.set('main', 'update', 'True')
self.config_parser.set('main', 'logging', 'False')
self.config_parser.set('main', 'warn_late_update', 'False')
elif attribute is not None:
if attribute == "load_nse_icon":
self.config_parser.set('main', 'load_nse_icon', 'True')
elif attribute == "index":
self.config_parser.set('main', 'index', self.indices[0])
elif attribute == "stock":
self.config_parser.set('main', 'stock', self.stocks[0])
elif attribute == "option_mode":
self.config_parser.set('main', 'option_mode', 'Index')
elif attribute == "seconds":
self.config_parser.set('main', 'seconds', '60')
elif attribute in ("live_export", "save_oc", "notifications", "auto_stop", "logging"):
self.config_parser.set('main', attribute, 'False')
elif attribute == "update":
self.config_parser.set('main', 'update', 'True')
elif attribute == "warn_late_update":
self.config_parser.set('main', 'warn_late_update', 'False')
with open('NSE-OCA.ini', 'w') as f:
self.config_parser.write(f)
# noinspection PyUnusedLocal
def get_data(self, event: Optional[Event] = None) -> Optional[Tuple[Optional[requests.Response], Any]]:
if self.first_run:
return self.get_data_first_run()
else:
return self.get_data_refresh()
def get_data_first_run(self) -> Optional[Tuple[Optional[requests.Response], Any]]:
response: Optional[requests.Response] = None
self.units_str = 'in K' if self.option_mode == 'Index' else 'in 10s'
self.output_columns: Tuple[str, str, str, str, str, str, str, str, str] = (
'Time', 'Value', f'Call Sum\n({self.units_str})', f'Put Sum\n({self.units_str})',
f'Difference\n({self.units_str})', f'Call Boundary\n({self.units_str})',
f'Put Boundary\n({self.units_str})', 'Call ITM', 'Put ITM')
self.csv_headers: Tuple[str, str, str, str, str, str, str, str, str] = (
'Time', 'Value', f'Call Sum ({self.units_str})', f'Put Sum ({self.units_str})',
f'Difference ({self.units_str})',
f'Call Boundary ({self.units_str})', f'Put Boundary ({self.units_str})', 'Call ITM', 'Put ITM')
self.round_factor: int = 1000 if self.option_mode == 'Index' else 10
if self.option_mode == 'Index':
self.index = self.index_var.get()
self.config_parser.set('main', 'index', f'{self.index}')
else:
self.stock = self.stock_var.get()
self.config_parser.set('main', 'stock', f'{self.stock}')
with open('NSE-OCA.ini', 'w') as f:
self.config_parser.write(f)
url: str = self.url_index + self.index if self.option_mode == 'Index' else self.url_stock + self.stock
try:
response = self.session.get(url, headers=self.headers, timeout=5, cookies=self.cookies)
except Exception as err:
print(response)
print(err, sys.exc_info()[0], "1")
messagebox.showerror(title="Error", message="Error in fetching dates.\nPlease retry.")
self.dates.clear()
self.dates = [""]
self.date_menu.config(values=tuple(self.dates))
self.date_menu.current(0)
return
json_data: Dict[str, Any]
if response is not None:
try:
json_data = response.json()
except Exception as err:
print(response)
print(err, sys.exc_info()[0], "2")
json_data = {}
else:
json_data = {}
if json_data == {}:
messagebox.showerror(title="Error", message="Error in fetching dates.\nPlease retry.")
self.dates.clear()
self.dates = [""]
try:
self.date_menu.config(values=tuple(self.dates))
self.date_menu.current(0)
except TclError as err:
print(err, sys.exc_info()[0], "3")
return
self.dates.clear()
for dates in json_data['records']['expiryDates']:
self.dates.append(dates)
try:
self.date_menu.config(values=tuple(self.dates))
self.date_menu.current(0)
except TclError:
pass
return response, json_data
def get_data_refresh(self) -> Optional[Tuple[Optional[requests.Response], Any]]:
request: Optional[requests.Response] = None
response: Optional[requests.Response] = None
url: str = self.url_index + self.index if self.option_mode == 'Index' else self.url_stock + self.stock
try:
response = self.session.get(url, headers=self.headers, timeout=5, cookies=self.cookies)
if response.status_code == 401:
self.session.close()
self.session = requests.Session()
request = self.session.get(self.url_oc, headers=self.headers, timeout=5)
self.cookies = dict(request.cookies)
response = self.session.get(url, headers=self.headers, timeout=5, cookies=self.cookies)
print("reset cookies")
except Exception as err:
print(request)
print(response)
print(err, sys.exc_info()[0], "4")
try:
self.session.close()
self.session = requests.Session()
request = self.session.get(self.url_oc, headers=self.headers, timeout=5)
self.cookies = dict(request.cookies)
response = self.session.get(url, headers=self.headers, timeout=5, cookies=self.cookies)
print("reset cookies")
except Exception as err:
print(request)
print(response)
print(err, sys.exc_info()[0], "5")
return
if response is not None:
try:
json_data: Any = response.json()
except Exception as err:
print(response)
print(err, sys.exc_info()[0], "6")
json_data = {}
else:
json_data = {}
if json_data == {}:
return
return response, json_data
def login_win(self, window: Tk) -> None:
self.login: Tk = window
self.login.title("NSE-Option-Chain-Analyzer")
self.login.protocol('WM_DELETE_WINDOW', self.close_login)
window_width: int = self.login.winfo_reqwidth()
window_height: int = self.login.winfo_reqheight()
position_right: int = int(self.login.winfo_screenwidth() / 2 - window_width / 2)
position_down: int = int(self.login.winfo_screenheight() / 2 - window_height / 2)
self.login.geometry("320x160+{}+{}".format(position_right, position_down))
self.login.resizable(False, False)
self.login.iconphoto(True, PhotoImage(file=self.icon_png_path)) if self.load_nse_icon else None
self.login.rowconfigure(0, weight=1)
self.login.rowconfigure(1, weight=1)
self.login.rowconfigure(2, weight=1)
self.login.rowconfigure(3, weight=1)
self.login.rowconfigure(4, weight=1)
self.login.rowconfigure(5, weight=1)
self.login.columnconfigure(0, weight=1)
self.login.columnconfigure(1, weight=1)
self.login.columnconfigure(2, weight=1)
self.intervals_var: StringVar = StringVar()
self.intervals_var.set(str(self.intervals[0]))
self.index_var: StringVar = StringVar()
self.index_var.set(self.indices[0])
self.stock_var: StringVar = StringVar()
self.stock_var.set(self.stocks[0])
self.dates_var: StringVar = StringVar()
self.dates_var.set(self.dates[0])
option_mode_label: Label = Label(self.login, text="Mode: ", justify=LEFT)
option_mode_label.grid(row=0, column=0, sticky=N + S + W)
self.option_mode_btn: Button = Button(self.login, text=f"{'Index' if self.option_mode == 'Index' else 'Stock'}",
command=self.change_option_mode, width=10)
self.option_mode_btn.grid(row=0, column=1, sticky=N + S + E + W)
index_label: Label = Label(self.login, text="Index: ", justify=LEFT)
index_label.grid(row=1, column=0, sticky=N + S + W)
self.index_menu: Combobox = Combobox(self.login, textvariable=self.index_var, values=self.indices)
self.index_menu.config(width=15, state='readonly' if self.option_mode == 'Index' else DISABLED)
self.index_menu.grid(row=1, column=1, sticky=N + S + E)
self.index_menu.current(self.indices.index(self.index))
stock_label: Label = Label(self.login, text="Stock: ", justify=LEFT)
stock_label.grid(row=2, column=0, sticky=N + S + W)
self.stock_menu: Combobox = Combobox(self.login, textvariable=self.stock_var, values=self.stocks)
self.stock_menu.config(width=15, state='readonly' if self.option_mode == 'Stock' else DISABLED)
self.stock_menu.grid(row=2, column=1, sticky=N + S + E)
self.stock_menu.current(self.stocks.index(self.stock))
date_label: Label = Label(self.login, text="Expiry Date: ", justify=LEFT)
date_label.grid(row=3, column=0, sticky=N + S + W)
self.date_menu: Combobox = Combobox(self.login, textvariable=self.dates_var, state="readonly")
self.date_menu.config(width=15)
self.date_menu.grid(row=3, column=1, sticky=N + S + E)
self.date_get: Button = Button(self.login, text="Refresh", command=self.get_data, width=10)
self.date_get.grid(row=3, column=2, sticky=N + S + E + W)
sp_label: Label = Label(self.login, text="Strike Price (eg. 14750): ")
sp_label.grid(row=4, column=0, sticky=N + S + W)
self.sp_entry = Entry(self.login, width=18, relief=SOLID)
self.sp_entry.grid(row=4, column=1, sticky=N + S + E)
start_btn: Button = Button(self.login, text="Start", command=self.start, width=10)
start_btn.grid(row=4, column=2, rowspan=2, sticky=N + S + E + W)
intervals_label: Label = Label(self.login, text="Refresh Interval (in min): ", justify=LEFT)
intervals_label.grid(row=5, column=0, sticky=N + S + W)
self.intervals_menu: Combobox = Combobox(self.login, textvariable=self.intervals_var,
values=[str(interval) for interval in self.intervals],
state="readonly")
self.intervals_menu.config(width=15)
self.intervals_menu.grid(row=5, column=1, sticky=N + S + E)
self.intervals_menu.current(self.intervals.index(int(self.seconds / 60)))
self.sp_entry.focus_set()
self.get_data()
# noinspection PyUnusedLocal
def focus_widget(event: Event, mode: int) -> None:
if mode == 1:
self.get_data()
self.date_menu.focus_set()
elif mode == 2:
self.sp_entry.focus_set()
self.index_menu.bind('<Return>', lambda event, a=1: focus_widget(event, a))
self.index_menu.bind("<<ComboboxSelected>>", self.get_data)
self.stock_menu.bind('<Return>', lambda event, a=1: focus_widget(event, a))
self.stock_menu.bind("<<ComboboxSelected>>", self.get_data)
self.date_menu.bind('<Return>', lambda event, a=2: focus_widget(event, a))
self.sp_entry.bind('<Return>', self.start)
self.login.mainloop()
def change_option_mode(self) -> None:
if self.option_mode_btn['text'] == 'Index':
self.option_mode = 'Stock'
self.option_mode_btn.config(text='Stock')
self.index_menu.config(state=DISABLED)
self.stock_menu.config(state='readonly')
else:
self.option_mode = 'Index'
self.option_mode_btn.config(text='Index')
self.index_menu.config(state='readonly')
self.stock_menu.config(state=DISABLED)
self.config_parser.set('main', 'option_mode', f'{self.option_mode}')
with open('NSE-OCA.ini', 'w') as f:
self.config_parser.write(f)
# noinspection PyUnusedLocal
def start(self, event: Optional[Event] = None) -> None:
self.seconds = int(self.intervals_var.get()) * 60
self.config_parser.set('main', 'seconds', f'{self.seconds}')
with open('NSE-OCA.ini', 'w') as f:
self.config_parser.write(f)
self.expiry_date: str = self.dates_var.get()
if self.expiry_date == "":
messagebox.showerror(title="Error", message="Incorrect Expiry Date.\nPlease enter correct Expiry Date.")
return
if self.live_export:
self.export_row(None)
try:
self.sp: int = int(self.sp_entry.get())
self.login.destroy()
self.main_win()
except ValueError as err:
print(err, sys.exc_info()[0], "7")
messagebox.showerror(title="Error", message="Incorrect Strike Price.\nPlease enter correct Strike Price.")
# noinspection PyUnusedLocal
def change_state(self, event: Optional[Event] = None) -> None:
if not self.stop:
self.stop = True
self.options.entryconfig(self.options.index(0), label="Start")
messagebox.showinfo(title="Stopped", message="Retrieving new data has been stopped.")
else:
self.stop = False
self.options.entryconfig(self.options.index(0), label="Stop")
messagebox.showinfo(title="Started", message="Retrieving new data has been started.")
self.main()
# noinspection PyUnusedLocal
def export(self, event: Optional[Event] = None) -> None:
sheet_data: List[List[str]] = self.sheet.get_sheet_data()
csv_exists: bool = os.path.isfile(
f"NSE-OCA-{self.index if self.option_mode == 'Index' else self.stock}-{self.expiry_date}.csv")
try:
if not csv_exists:
with open(f"NSE-OCA-{self.index if self.option_mode == 'Index' else self.stock}-{self.expiry_date}.csv",
"a", newline="") as row:
data_writer: csv.writer = csv.writer(row)
data_writer.writerow(self.csv_headers)
with open(f"NSE-OCA-{self.index if self.option_mode == 'Index' else self.stock}-{self.expiry_date}.csv",
"a", newline="") as row:
data_writer: csv.writer = csv.writer(row)
data_writer.writerows(sheet_data)
messagebox.showinfo(title="Export Successful",
message=f"Data has been exported to NSE-OCA-"
f"{self.index if self.option_mode == 'Index' else self.stock}-"
f"{self.expiry_date}.csv.")
except PermissionError as err:
print(err, sys.exc_info()[0], "12")
messagebox.showerror(title="Export Failed",
message=f"Failed to access NSE-OCA-"
f"{self.index if self.option_mode == 'Index' else self.stock}-"
f"{self.expiry_date}.csv.\n"
f"Permission Denied. Try closing any apps using it.")
except Exception as err:
print(err, sys.exc_info()[0], "8")
messagebox.showerror(title="Export Failed",
message="An error occurred while exporting the data.")
def export_row(self, values: Optional[List[Union[str, float]]]) -> None:
if values is None:
csv_exists: bool = os.path.isfile(
f"NSE-OCA-{self.index if self.option_mode == 'Index' else self.stock}-{self.expiry_date}.csv")
try:
if not csv_exists:
with open(
f"NSE-OCA-{self.index if self.option_mode == 'Index' else self.stock}-"
f"{self.expiry_date}.csv",
"a", newline="") as row:
data_writer: csv.writer = csv.writer(row)
data_writer.writerow(self.csv_headers)
except PermissionError as err:
print(err, sys.exc_info()[0], "13")
messagebox.showerror(title="Export Failed",
message=f"Failed to access NSE-OCA-"
f"{self.index if self.option_mode == 'Index' else self.stock}-"
f"{self.expiry_date}.csv.\n"
f"Permission Denied. Try closing any apps using it.")
except Exception as err:
print(err, sys.exc_info()[0], "9")
else:
try:
with open(f"NSE-OCA-{self.index if self.option_mode == 'Index' else self.stock}-{self.expiry_date}.csv",
"a", newline="") as row:
data_writer: csv.writer = csv.writer(row)
data_writer.writerow(values)
except PermissionError as err:
print(err, sys.exc_info()[0], "14")
messagebox.showerror(title="Export Failed",
message=f"Failed to access NSE-OCA-"
f"{self.index if self.option_mode == 'Index' else self.stock}-"
f"{self.expiry_date}.csv.\n"
f"Permission Denied. Try closing any apps using it.")
except Exception as err:
print(err, sys.exc_info()[0], "15")
# noinspection PyUnusedLocal
def toggle_live_export(self, event: Optional[Event] = None) -> None:
if self.live_export:
self.live_export = False
self.options.entryconfig(self.options.index(2), label="Live Exporting to CSV: Off")
messagebox.showinfo(title="Live Exporting Disabled",
message="Data rows will not be exported.")
else:
self.live_export = True
self.options.entryconfig(self.options.index(2), label="Live Exporting to CSV: On")
messagebox.showinfo(title="Live Exporting Enabled",
message=f"Data rows will be exported in real time to "
f"NSE-OCA-{self.index if self.option_mode == 'Index' else self.stock}-"
f"{self.expiry_date}.csv.")
self.config_parser.set('main', 'live_export', f'{self.live_export}')
with open('NSE-OCA.ini', 'w') as f:
self.config_parser.write(f)
self.export_row(None)
# noinspection PyUnusedLocal
def toggle_save_oc(self, event: Optional[Event] = None) -> None:
if self.save_oc:
self.save_oc = False
self.options.entryconfig(self.options.index(3), label="Dump Entire Option Chain to CSV: Off")
messagebox.showinfo(title="Dump Entire Option Chain Disabled",
message=f"Entire Option Chain data will not be exported.")
else:
self.save_oc = True
self.options.entryconfig(self.options.index(3), label="Dump Entire Option Chain to CSV: On")
messagebox.showinfo(title="Dump Entire Option Chain Enabled",
message=f"Entire Option Chain data will be exported to "
f"NSE-OCA-"
f"{self.index if self.option_mode == 'Index' else self.stock}-"
f"{self.expiry_date}-Full.csv.")
self.config_parser.set('main', 'save_oc', f'{self.save_oc}')
with open('NSE-OCA.ini', 'w') as f:
self.config_parser.write(f)
# noinspection PyUnusedLocal
def toggle_notifications(self, event: Optional[Event] = None) -> None:
if self.notifications:
self.notifications = False
self.options.entryconfig(self.options.index(4), label="Notifications: Off")
messagebox.showinfo(title="Notifications Disabled",
message="You will not receive any Notifications.")
else:
self.notifications = True
self.options.entryconfig(self.options.index(4), label="Notifications: On")
messagebox.showinfo(title="Notifications Enabled",
message="You will receive Notifications when the state of a label changes.")
self.config_parser.set('main', 'notifications', f'{self.notifications}')
with open('NSE-OCA.ini', 'w') as f:
self.config_parser.write(f)
# noinspection PyUnusedLocal
def toggle_auto_stop(self, event: Optional[Event] = None) -> None:
if self.auto_stop:
self.auto_stop = False
self.options.entryconfig(self.options.index(5), label="Stop automatically at 3:30pm: Off")
messagebox.showinfo(title="Auto Stop Disabled", message="Program will not automatically stop at 3:30pm")
else:
self.auto_stop = True
self.options.entryconfig(self.options.index(5), label="Stop automatically at 3:30pm: On")
messagebox.showinfo(title="Auto Stop Enabled", message="Program will automatically stop at 3:30pm")
self.config_parser.set('main', 'auto_stop', f'{self.auto_stop}')
with open('NSE-OCA.ini', 'w') as f:
self.config_parser.write(f)
# noinspection PyUnusedLocal
def toggle_warn_late_update(self, event: Optional[Event] = None) -> None:
if self.warn_late_update:
self.warn_late_update = False
self.options.entryconfig(self.options.index(6), label="Warn Late Server Updates: Off")
messagebox.showinfo(title="Warn Late Server Updates Disabled",
message="Program will not alert you if the server updates late.")
else:
self.warn_late_update = True
self.options.entryconfig(self.options.index(6), label="Warn Late Server Updates: On")
messagebox.showinfo(title="Warn Late Server Updates Enabled",
message="Program will alert you if the server update time is 5 minutes or more.")
self.config_parser.set('main', 'warn_late_update', f'{self.warn_late_update}')
with open('NSE-OCA.ini', 'w') as f:
self.config_parser.write(f)
# noinspection PyUnusedLocal
def toggle_updates(self, event: Optional[Event] = None) -> None:
if self.update:
self.update = False
self.options.entryconfig(self.options.index(8), label="Auto Check for Updates: Off")
messagebox.showinfo(title="Auto Checking for Updates Disabled",
message="Program will not check for updates at start.")
else:
self.update = True
self.options.entryconfig(self.options.index(8), label="Auto Check for Updates: On")
messagebox.showinfo(title="Auto Checking for Updates Enabled",
message="Program will check for updates at start.")
self.config_parser.set('main', 'update', f'{self.update}')
with open('NSE-OCA.ini', 'w') as f:
self.config_parser.write(f)
# noinspection PyUnusedLocal
def log(self, event: Optional[Event] = None) -> None:
if self.first_run and self.logging or not self.logging:
try:
# noinspection PyProtectedMember,PyUnresolvedReferences
base_path: str = sys._MEIPASS
self.log_file = open('NSE-OCA.log', 'a', buffering=1)
sys.stdout = self.log_file
sys.stderr = self.log_file
except AttributeError:
streamtologger.redirect(target="NSE-OCA.log",
header_format="[{timestamp:%Y-%m-%d %H:%M:%S} - {level:5}] ")
self.logging = True
print('----------Logging Started----------')
try:
# noinspection PyProtectedMember,PyUnresolvedReferences
base_path: str = sys._MEIPASS
print(platform.system() + ' ' + platform.release() + ' .exe version ' + Nse.version)
except AttributeError:
print(platform.system() + ' ' + platform.release() + ' .py version ' + Nse.version)
if not self.load_nse_icon:
print("NSE icon loading disabled")
try:
self.options.entryconfig(self.options.index(9), label="Debug Logging: On")
messagebox.showinfo(title="Debug Logging Enabled",
message="Errors will be logged to NSE-OCA.log.")
except AttributeError:
pass
elif self.logging:
print('----------Logging Stopped----------')
sys.stdout = self.stdout
sys.stderr = self.stderr
try:
# noinspection PyProtectedMember,PyUnresolvedReferences
base_path: str = sys._MEIPASS
self.log_file.close()
except AttributeError:
streamtologger._is_redirected = False
self.logging = False
self.options.entryconfig(self.options.index(9), label="Debug Logging: Off")
messagebox.showinfo(title="Debug Logging Disabled", message="Errors will not be logged.")
self.config_parser.set('main', 'logging', f'{self.logging}')
with open('NSE-OCA.ini', 'w') as f:
self.config_parser.write(f)
# noinspection PyUnusedLocal
def links(self, link: str, event: Optional[Event] = None) -> None:
if link == "developer":
webbrowser.open_new("https://github.com/VarunS2002/")
elif link == "readme":
webbrowser.open_new("https://github.com/VarunS2002/Python-NSE-Option-Chain-Analyzer/blob/master/README.md/")
elif link == "license":
webbrowser.open_new("https://github.com/VarunS2002/Python-NSE-Option-Chain-Analyzer/blob/master/LICENSE/")
elif link == "releases":
webbrowser.open_new("https://github.com/VarunS2002/Python-NSE-Option-Chain-Analyzer/releases/")
elif link == "sources":
webbrowser.open_new("https://github.com/VarunS2002/Python-NSE-Option-Chain-Analyzer/")
self.info.attributes('-topmost', False)
def about_window(self) -> Toplevel:
self.info: Toplevel = Toplevel()
self.info.title("About")
window_width: int = self.info.winfo_reqwidth()
window_height: int = self.info.winfo_reqheight()
position_right: int = int(self.info.winfo_screenwidth() / 2 - window_width / 2)
position_down: int = int(self.info.winfo_screenheight() / 2 - window_height / 2)
self.info.geometry("250x150+{}+{}".format(position_right, position_down))
self.info.resizable(False, False)
self.info.iconphoto(True, PhotoImage(file=self.icon_png_path)) if self.load_nse_icon else None
self.info.attributes('-topmost', True)
self.info.grab_set()
self.info.focus_force()
return self.info
# noinspection PyUnusedLocal
def about(self, event: Optional[Event] = None) -> None:
self.info: Toplevel = self.about_window()
self.info.rowconfigure(0, weight=1)
self.info.rowconfigure(1, weight=1)
self.info.rowconfigure(2, weight=1)
self.info.rowconfigure(3, weight=1)
self.info.rowconfigure(4, weight=1)
self.info.columnconfigure(0, weight=1)
self.info.columnconfigure(1, weight=1)
heading: Label = Label(self.info, text="NSE-Option-Chain-Analyzer", relief=RIDGE,
font=("TkDefaultFont", 10, "bold"))
heading.grid(row=0, column=0, columnspan=2, sticky=N + S + W + E)
version_label: Label = Label(self.info, text="Version:", relief=RIDGE)
version_label.grid(row=1, column=0, sticky=N + S + W + E)
version_val: Label = Label(self.info, text=f"{Nse.version}", relief=RIDGE)
version_val.grid(row=1, column=1, sticky=N + S + W + E)
dev_label: Label = Label(self.info, text="Developer:", relief=RIDGE)
dev_label.grid(row=2, column=0, sticky=N + S + W + E)
dev_val: Label = Label(self.info, text="Varun Shanbhag", fg="blue", cursor="hand2", relief=RIDGE)
dev_val.bind("<Button-1>", lambda click, link="developer": self.links(link, click))
dev_val.grid(row=2, column=1, sticky=N + S + W + E)
readme: Label = Label(self.info, text="README", fg="blue", cursor="hand2", relief=RIDGE)
readme.bind("<Button-1>", lambda click, link="readme": self.links(link, click))
readme.grid(row=3, column=0, sticky=N + S + W + E)
licenses: Label = Label(self.info, text="LICENSE", fg="blue", cursor="hand2", relief=RIDGE)
licenses.bind("<Button-1>", lambda click, link="license": self.links(link, click))
licenses.grid(row=3, column=1, sticky=N + S + W + E)
releases: Label = Label(self.info, text="Releases", fg="blue", cursor="hand2", relief=RIDGE)
releases.bind("<Button-1>", lambda click, link="releases": self.links(link, click))
releases.grid(row=4, column=0, sticky=N + S + W + E)
sources: Label = Label(self.info, text="Sources", fg="blue", cursor="hand2", relief=RIDGE)
sources.bind("<Button-1>", lambda click, link="sources": self.links(link, click))
sources.grid(row=4, column=1, sticky=N + S + W + E)
updates: Button = Button(self.info, text="Check for Updates",
command=lambda auto=False: self.check_for_updates(auto))
updates.grid(row=5, column=0, columnspan=2, sticky=N + S + W + E)
self.info.mainloop()
def close_login(self) -> None:
self.session.close()
if self.logging:
print('----------Quitting Program----------')
os.remove('.NSE-OCA.png') if os.path.isfile('.NSE-OCA.png') else None
os.remove('.NSE-OCA.ico') if os.path.isfile('.NSE-OCA.ico') else None
self.login.destroy()
sys.exit()
# noinspection PyUnusedLocal
def close_main(self, event: Optional[Event] = None) -> None:
ask_quit: bool = messagebox.askyesno("Quit", "All unsaved data will be lost.\nProceed to quit?", icon='warning',
default='no')
if ask_quit:
self.session.close()
if self.logging:
print('----------Quitting Program----------')
os.remove('.NSE-OCA.png') if os.path.isfile('.NSE-OCA.png') else None
os.remove('.NSE-OCA.ico') if os.path.isfile('.NSE-OCA.ico') else None
self.root.destroy()
sys.exit()
elif not ask_quit:
pass
def main_win(self) -> None:
self.root: Tk = Tk()
self.root.focus_force()
self.root.title("NSE-Option-Chain-Analyzer")
self.root.protocol('WM_DELETE_WINDOW', self.close_main)
window_width: int = self.root.winfo_reqwidth()
window_height: int = self.root.winfo_reqheight()
position_right: int = int(self.root.winfo_screenwidth() / 3 - window_width / 2)
position_down: int = int(self.root.winfo_screenheight() / 3 - window_height / 2)
self.root.geometry("815x560+{}+{}".format(position_right, position_down))
self.root.iconphoto(True, PhotoImage(file=self.icon_png_path)) if self.load_nse_icon else None
self.root.rowconfigure(0, weight=1)
self.root.columnconfigure(0, weight=1)
menubar: Menu = Menu(self.root)
self.options: Menu = Menu(menubar, tearoff=0)
self.options.add_command(label="Stop", accelerator="(Ctrl+X)", command=self.change_state)
self.options.add_command(label="Export Table to CSV", accelerator="(Ctrl+S)", command=self.export)
self.options.add_command(label=f"Live Exporting to CSV: {'On' if self.live_export else 'Off'}",
accelerator="(Ctrl+B)", command=self.toggle_live_export)
self.options.add_command(label=f"Dump Entire Option Chain to CSV: {'On' if self.save_oc else 'Off'}",
accelerator="(Ctrl+O)", command=self.toggle_save_oc)
self.options.add_command(label=f"Notifications: {'On' if self.notifications else 'Off'}",
accelerator="(Ctrl+N)", command=self.toggle_notifications,
state=NORMAL if is_windows_10_or_11 else DISABLED)
self.options.add_command(label=f"Stop automatically at 3:30pm: {'On' if self.auto_stop else 'Off'}",
accelerator="(Ctrl+K)", command=self.toggle_auto_stop)
self.options.add_command(label=f"Warn Late Server Updates: {'On' if self.warn_late_update else 'Off'}",
accelerator="(Ctrl+W)", command=self.toggle_warn_late_update)
self.options.add_separator()
self.options.add_command(label=f"Auto Check for Updates: {'On' if self.update else 'Off'}",
accelerator="(Ctrl+U)", command=self.toggle_updates)
self.options.add_command(label=f"Debug Logging: {'On' if self.logging else 'Off'}", accelerator="(Ctrl+L)",
command=self.log)
self.options.add_command(label="About", accelerator="(Ctrl+M)", command=self.about)
self.options.add_command(label="Quit", accelerator="(Ctrl+Q)", command=self.close_main)
menubar.add_cascade(label="Menu", menu=self.options)
self.root.config(menu=menubar)
self.root.bind('<Control-x>', self.change_state)
self.root.bind('<Control-s>', self.export)
self.root.bind('<Control-b>', self.toggle_live_export)
self.root.bind('<Control-o>', self.toggle_save_oc)
self.root.bind('<Control-n>', self.toggle_notifications) if is_windows_10_or_11 else None
self.root.bind('<Control-k>', self.toggle_auto_stop)
self.root.bind('<Control-w>', self.toggle_warn_late_update)
self.root.bind('<Control-u>', self.toggle_updates)
self.root.bind('<Control-l>', self.log)
self.root.bind('<Control-m>', self.about)
self.root.bind('<Control-q>', self.close_main)
top_frame: Frame = Frame(self.root)
top_frame.rowconfigure(0, weight=1)
top_frame.columnconfigure(0, weight=1)
top_frame.pack(fill="both", expand=True)
# noinspection PyTypeChecker
self.sheet: tksheet.Sheet = tksheet.Sheet(top_frame, column_width=85, align="center",
headers=self.output_columns, header_font=("TkDefaultFont", 9, "bold"),
empty_horizontal=0, empty_vertical=20, header_height=35)
self.sheet.enable_bindings(
("toggle_select", "drag_select", "column_select", "row_select", "column_width_resize",
"arrowkeys", "right_click_popup_menu", "rc_select", "copy", "select_all"))
self.sheet.grid(row=0, column=0, sticky=N + S + W + E)
bottom_frame: Frame = Frame(self.root)
bottom_frame.rowconfigure(0, weight=1)
bottom_frame.rowconfigure(1, weight=1)
bottom_frame.rowconfigure(2, weight=1)
bottom_frame.rowconfigure(3, weight=1)
bottom_frame.rowconfigure(4, weight=1)
bottom_frame.rowconfigure(5, weight=1)
bottom_frame.columnconfigure(0, weight=1)
bottom_frame.columnconfigure(1, weight=1)
bottom_frame.columnconfigure(2, weight=1)
bottom_frame.columnconfigure(3, weight=1)
bottom_frame.columnconfigure(4, weight=1)
bottom_frame.columnconfigure(5, weight=1)
bottom_frame.columnconfigure(6, weight=1)
bottom_frame.columnconfigure(7, weight=1)
bottom_frame.pack(fill="both", expand=True)
oi_ub_label: Label = Label(bottom_frame, text="Open Interest Upper Boundary", relief=RIDGE,
font=("TkDefaultFont", 10, "bold"))
oi_ub_label.grid(row=0, column=0, columnspan=4, sticky=N + S + W + E)
max_call_oi_sp_label: Label = Label(bottom_frame, text="Strike Price 1:", relief=RIDGE,
font=("TkDefaultFont", 9, "bold"))
max_call_oi_sp_label.grid(row=1, column=0, sticky=N + S + W + E)
self.max_call_oi_sp_val: Label = Label(bottom_frame, text="", relief=RIDGE)
self.max_call_oi_sp_val.grid(row=1, column=1, sticky=N + S + W + E)
max_call_oi_label: Label = Label(bottom_frame, text=f"OI ({self.units_str}):", relief=RIDGE,
font=("TkDefaultFont", 9, "bold"))
max_call_oi_label.grid(row=1, column=2, sticky=N + S + W + E)
self.max_call_oi_val: Label = Label(bottom_frame, text="", relief=RIDGE)
self.max_call_oi_val.grid(row=1, column=3, sticky=N + S + W + E)
oi_lb_label: Label = Label(bottom_frame, text="Open Interest Lower Boundary", relief=RIDGE,
font=("TkDefaultFont", 10, "bold"))
oi_lb_label.grid(row=0, column=4, columnspan=4, sticky=N + S + W + E)
max_put_oi_sp_label: Label = Label(bottom_frame, text="Strike Price 1:", relief=RIDGE,
font=("TkDefaultFont", 9, "bold"))
max_put_oi_sp_label.grid(row=1, column=4, sticky=N + S + W + E)
self.max_put_oi_sp_val: Label = Label(bottom_frame, text="", relief=RIDGE)
self.max_put_oi_sp_val.grid(row=1, column=5, sticky=N + S + W + E)
max_put_oi_label: Label = Label(bottom_frame, text=f"OI ({self.units_str}):", relief=RIDGE,
font=("TkDefaultFont", 9, "bold"))
max_put_oi_label.grid(row=1, column=6, sticky=N + S + W + E)
self.max_put_oi_val: Label = Label(bottom_frame, text="", relief=RIDGE)
self.max_put_oi_val.grid(row=1, column=7, sticky=N + S + W + E)
max_call_oi_sp_2_label: Label = Label(bottom_frame, text="Strike Price 2:", relief=RIDGE,
font=("TkDefaultFont", 9, "bold"))
max_call_oi_sp_2_label.grid(row=2, column=0, sticky=N + S + W + E)
self.max_call_oi_sp_2_val: Label = Label(bottom_frame, text="", relief=RIDGE)
self.max_call_oi_sp_2_val.grid(row=2, column=1, sticky=N + S + W + E)
max_call_oi_2_label: Label = Label(bottom_frame, text=f"OI ({self.units_str}):", relief=RIDGE,
font=("TkDefaultFont", 9, "bold"))
max_call_oi_2_label.grid(row=2, column=2, sticky=N + S + W + E)
self.max_call_oi_2_val: Label = Label(bottom_frame, text="", relief=RIDGE)
self.max_call_oi_2_val.grid(row=2, column=3, sticky=N + S + W + E)
oi_lb_2_label: Label = Label(bottom_frame, text="Open Interest Lower Boundary", relief=RIDGE,
font=("TkDefaultFont", 10, "bold"))
oi_lb_2_label.grid(row=2, column=4, columnspan=4, sticky=N + S + W + E)
max_put_oi_sp_2_label: Label = Label(bottom_frame, text="Strike Price 2:", relief=RIDGE,
font=("TkDefaultFont", 9, "bold"))