-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOptionChain SingleCall.py
86 lines (45 loc) · 1.23 KB
/
OptionChain SingleCall.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
#!/usr/bin/env python
# coding: utf-8
#
#
#
#
#
#
#
# In[ ]:
pip install stocknotebridge
# In[ ]:
from snapi_py_client.snapi_bridge import StocknoteAPIPythonBridge
import json
import pandas as pd
# In[ ]:
#pip uninstall websocket-client
#pip install websocket-client
# In[ ]:
username = 'RS31209'
password = 'PASSWORD'
yob = '1994'
# In[ ]:
samco=StocknoteAPIPythonBridge()
login=samco.login(body={"userId":username,'password':password,'yob':yob})
login = json.loads(login)
samco.set_session_token(sessionToken=login['sessionToken'])
login
# In[ ]:
ocres=samco.get_option_chain(search_symbol_name='Nifty',exchange=samco.EXCHANGE_NFO,expiry_date='2022-10-20')
ocres = json.loads(ocres)
ocdf = pd.DataFrame(ocres['optionChainDetails'])
ocdf = ocdf[['tradingSymbol','optionType','expiryDate','lastTradedPrice','openInterest','openInterestChange','volume','strikePrice']]
ocdf = ocdf.astype({"strikePrice": float, "lastTradedPrice": float, "openInterest": int, "openInterestChange": int, "volume": int})
ocdf = ocdf[ocdf.openInterest >0]
ocdf
# In[ ]:
ceocdf = ocdf[ocdf.optionType =='CE' ]
peocdf = ocdf[ocdf.optionType =='PE' ]
# In[ ]:
ceocdf
# In[ ]:
peocdf
# In[ ]:
ceocdf.merge(peocdf,on = 'strikePrice')