Spaces:
Sleeping
Sleeping
Add application file
Browse files
app.py
ADDED
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from nsepython import *
|
2 |
+
import seaborn as sns
|
3 |
+
import pandas as pd
|
4 |
+
import streamlit as st
|
5 |
+
from datetime import datetime
|
6 |
+
from time import gmtime, strftime
|
7 |
+
from IPython.display import clear_output
|
8 |
+
import matplotlib.pyplot as plt
|
9 |
+
from pytz import timezone
|
10 |
+
|
11 |
+
def get_data():
|
12 |
+
a=(nse_fno("BANKNIFTY"))
|
13 |
+
last_prices=round(nse_quote_ltp("BANKNIFTY"))
|
14 |
+
exp=list(set(a['expiryDates']))
|
15 |
+
exp.sort(key = lambda date: datetime.strptime(date, '%d-%b-%Y'))
|
16 |
+
if last_prices%100>50:
|
17 |
+
x=(last_prices-last_prices%100+100)
|
18 |
+
strike=[x-200,x-100,x,x+100,x+200]
|
19 |
+
elif last_prices%100<50:
|
20 |
+
x=(last_prices-last_prices%100)
|
21 |
+
strike=[x-200,x-100,x,x+100,x+200]
|
22 |
+
d={'call change op':[],
|
23 |
+
'call vwap':[],
|
24 |
+
'% change op':[],
|
25 |
+
'strike':[],
|
26 |
+
'put change op':[],
|
27 |
+
'put vwap':[],
|
28 |
+
'% change op put':[]
|
29 |
+
}
|
30 |
+
for i in a['stocks']:
|
31 |
+
for sp in strike:
|
32 |
+
if i['metadata']['expiryDate']==exp[0] and i['metadata']['optionType']=='Call' and i['metadata']['strikePrice']==sp:
|
33 |
+
d['strike'].append(sp)
|
34 |
+
d['call change op'].append(i['marketDeptOrderBook']['tradeInfo']['changeinOpenInterest'])
|
35 |
+
d['% change op'].append(i['marketDeptOrderBook']['tradeInfo']['pchangeinOpenInterest'])
|
36 |
+
d['call vwap'].append(i['marketDeptOrderBook']['tradeInfo']['vmap'])
|
37 |
+
|
38 |
+
elif i['metadata']['expiryDate']==exp[0] and i['metadata']['optionType']=='Put' and i['metadata']['strikePrice']==sp:
|
39 |
+
d['put change op'].append(i['marketDeptOrderBook']['tradeInfo']['changeinOpenInterest'])
|
40 |
+
d['% change op put'].append(i['marketDeptOrderBook']['tradeInfo']['pchangeinOpenInterest'])
|
41 |
+
d['put vwap'].append(i['marketDeptOrderBook']['tradeInfo']['vmap'])
|
42 |
+
|
43 |
+
out=pd.json_normalize(d)
|
44 |
+
out=out.explode(list(out.columns)).reset_index(drop = True)
|
45 |
+
out.fillna(0,inplace=True)
|
46 |
+
x=out.astype(float).round(2)
|
47 |
+
return x
|
48 |
+
def get_info(dataset):
|
49 |
+
df= pd.DataFrame(columns=['value', 'pcr', 'cal_per','put_per'])
|
50 |
+
value= dataset['put change op'].sum() - dataset['call change op'].sum()
|
51 |
+
pcr= dataset['put change op'].sum()/dataset['call change op'].sum()
|
52 |
+
cal_per= dataset['% change op'].mean()
|
53 |
+
put_per= dataset['% change op put'].mean()
|
54 |
+
new_row={'time':datetime.now(timezone("Asia/Kolkata")).strftime('%I.%M %p'),'value':value, 'pcr':round(pcr,2), 'cal_per':round(cal_per,2), 'put_per':round(put_per,2)}
|
55 |
+
df = df.append(new_row,ignore_index=True, verify_integrity=False, sort=None)
|
56 |
+
return df
|
57 |
+
def ploting():
|
58 |
+
try:
|
59 |
+
global final
|
60 |
+
except:
|
61 |
+
df = pd.DataFrame(columns=['value', 'pcr', 'cal_per','put_per'])
|
62 |
+
dataset= get_data()
|
63 |
+
main= get_info(dataset)
|
64 |
+
final =final.append(main,ignore_index=True, verify_integrity=False, sort=None)
|
65 |
+
return dataset,final
|
66 |
+
|
67 |
+
final = pd.DataFrame(columns=['value', 'pcr', 'cal_per','put_per','time'])
|
68 |
+
|
69 |
+
|
70 |
+
if __name__=='__main__':
|
71 |
+
|
72 |
+
st.title('WELCOME BULLS CARTEL')
|
73 |
+
today_date =strftime("%d %b %Y", gmtime()),datetime.now(timezone("Asia/Kolkata")).strftime('%I.%M %p')
|
74 |
+
st.markdown(f"as at {today_date}")
|
75 |
+
option= st.selectbox(
|
76 |
+
'How would you like to be contacted?',
|
77 |
+
('5', '10', '15'))
|
78 |
+
st.write('You selected:', option)
|
79 |
+
st.header('Important Information')
|
80 |
+
st.markdown(""" CALL % INCREASE MEANS MARKET GOES DOWN
|
81 |
+
PUT % INCREASE MEANS MARKET GOES UP
|
82 |
+
""")
|
83 |
+
while True:
|
84 |
+
dataset,final=ploting()
|
85 |
+
p1=st.empty()
|
86 |
+
p2=st.empty()
|
87 |
+
p3=st.empty()
|
88 |
+
p1.dataframe(dataset.style.highlight_max(['% change op put','% change op'],axis=0)) #Column hightlight
|
89 |
+
p2.dataframe(final.style.highlight_max(['cal_per','put_per'],axis=1)) # row highlight
|
90 |
+
fig, ax = plt.subplots(figsize=(6, 2))
|
91 |
+
ax.plot(final['time'],final['pcr'])
|
92 |
+
ax.axhline(y=0, color='black', linestyle='solid') # 0 line graph
|
93 |
+
fig.autofmt_xdate(rotation=70)
|
94 |
+
p3.pyplot(fig)
|
95 |
+
time.sleep(3*60) # how to the start again code check upper condition min * sec
|
96 |
+
p1.empty() # then clean all data frame
|
97 |
+
p2.empty()
|
98 |
+
p3.empty()
|
99 |
+
|