-
Notifications
You must be signed in to change notification settings - Fork 5
/
advances.py
102 lines (75 loc) · 2.54 KB
/
advances.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
from bse import BSE
from os import system
from sys import platform
# Check if system is windows or linux
if 'win' in platform:
# enable color support in Windows
system('color')
class C:
'''Color values for terminal'''
GREEN = '\033[92m'
CYAN = '\033[96m'
FAIL = '\033[91m'
ENDC = '\033[0m'
def adRatio(adv, dec):
return 0 if adv == 0 else (adv if dec == 0 else round(adv / dec, 2))
def adRatioFormatted(adv, dec):
ratio = adRatio(int(adv), int(dec))
sRatio = str(ratio).ljust(5)
if ratio >= 1.5:
s = f'{C.GREEN}++ ▲'
elif 1 <= ratio < 1.5:
s = f'{C.GREEN}+ ▲'
elif 0.8 <= ratio < 1:
s = f'{C.GREEN}- ▲'
elif 0.5 <= ratio < 0.8:
s = f'{C.CYAN}◀ ▶'
elif 0.3 <= ratio < 0.5:
s = f'{C.FAIL}+ ▼'
else:
s = f'{C.FAIL}++ ▼'
return f'{s.ljust(10)}{C.ENDC} {sRatio}'.ljust(11)
broad = {'100': '100', 'midcap': 'Midcap', 'smallcap': 'Smallcap'}
sector = {
'auto': 'Auto',
'bankex': 'Banking',
'basic materials': 'Materials',
'capital goods': 'Capital Goods',
'consumer discretionary goods & services': 'Con Discretionary',
'consumer durables': 'Con Durables',
'energy': 'Energy',
'fast moving consumer goods': 'FMCG',
'finance': 'Finance',
'healthcare': 'Healthcare',
'industrials': 'Industrials',
'information technology': 'Info Tech',
'metal': 'Metal',
'oil & gas': 'Oil & Gas',
'realty': 'Realty',
'telecom': 'Telecom',
'utilities': 'Utilities'
}
with BSE('./') as bse:
data = bse.advanceDecline()
broad_out, sector_out = '', ''
for idx in data:
name = idx['Sens_ind'][8:].lower()
if name in broad:
idx_name = f'BSE {broad[name].ljust(10)}'
ratio = adRatioFormatted(idx['UP'], idx['DN'])
up = idx['UP'].ljust(8)
down = idx['DN'].ljust(8)
unchanged = idx['UC'].ljust(2)
broad_out += f"{idx_name}: {ratio} ▲ {up} ▼ {down} {unchanged}\n"
if name in sector:
ratio = adRatioFormatted(idx['UP'], idx['DN'])
idx_name = sector[name].ljust(24)
up = idx['UP'].ljust(4)
down = idx['DN'].ljust(4)
unchanged = idx['UC'].ljust(2)
sector_out += f"{idx_name}: {ratio} ▲ {up} ▼ {down} {unchanged}\n"
HR = '-' * 58
print(f'{C.CYAN}++ : Very Strong + : Strong - : Weak')
print(f'▲ : Uptrend ▼ : Downtrend ◀ ▶ : Neutral{C.ENDC}\n')
print(f"{C.CYAN}Broad Market\n{HR}{C.ENDC}\n{broad_out}")
print(f"{C.CYAN}Sector Wise\n{HR}{C.ENDC}\n{sector_out}")