-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgenerate_token.py
executable file
·52 lines (38 loc) · 1.31 KB
/
generate_token.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
import os
import webbrowser
import configparser
from constants import *
from fyers_apiv3 import fyersModel
config = configparser.ConfigParser()
config.read('credentials.ini')
client_id = config['fyers']['client_id']
secret_key = config['fyers']['secret_key']
redirect_url = config['fyers']['redirect_url']
response_type = config['fyers']['response_type']
state = config['fyers']['state']
grant_type = config['fyers']['grant_type']
log_dir = config['fyers']['log_dir']
file_name = config['fyers']['file_name']
time_zone = config['fyers']['time_zone']
verbose = config['fyers']['verbose']
def generate_access_token():
session = fyersModel.SessionModel(
client_id=client_id,
secret_key=secret_key,
redirect_uri=redirect_url,
response_type=response_type,
grant_type=grant_type
)
response = session.generate_authcode()
print("Login Url : ", response)
# This command is used to open the url in default system browser
webbrowser.open(response, new=1)
auth_code = input("Auth Code : ")
session.set_token(auth_code)
access_token = session.generate_token()['access_token']
if os.path.exists(file_name):
os.remove(file_name)
with open(file_name, 'w') as f:
f.write(access_token)
if __name__ == '__main__':
generate_access_token()