forked from Chavithra/degiro-connector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogout.py
54 lines (43 loc) · 1.09 KB
/
logout.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
# IMPORTATIONS
import json
import logging
import random
import time
from trading.api import API as TradingAPI
from trading.pb.trading_pb2 import Credentials
# SETUP LOGGING LEVEL
logging.basicConfig(level=logging.DEBUG)
# SETUP CONFIG DICT
with open('config/config.json') as config_file:
config_dict = json.load(config_file)
# SETUP CREDENTIALS
username = config_dict['username']
password = config_dict['password']
credentials = Credentials(
int_account=None,
username=username,
password=password,
)
# SETUP TRADING API
trading_api = TradingAPI(credentials=credentials)
# CONNECT
trading_api.connect()
# ACCESS SESSION_ID
session_id = trading_api.connection_storage.session_id
# Waiting
sleep_time = random.uniform(1, 5)
print(f'Waiting : {sleep_time}s ')
time.sleep(sleep_time)
# FETCH CONFIG TABLE
print(len(trading_api.get_config()))
# LOGOUT
print('Logout, session id : ', session_id)
trading_api.logout()
try:
# FETCH CONFIG TABLE
print(len(trading_api.get_config()))
except ConnectionError as e:
print(e)
print('Logout : success !')
else:
print('Logout : fail !')