-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathconnection_spread.py
121 lines (102 loc) · 4.57 KB
/
connection_spread.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
from vavabot_options_strategy_10_0 import Deribit, CredentialsSaved, ConfigSaved
import time
from lists import list_monitor_log
import threading
global connect
ConfigSaved().remove_log_spread_log_if_bigger_500kb_when_open_app()
ConfigSaved().setup_ini_check()
led = 'red'
def connection1():
global connect
global led
connect = Deribit(client_id=CredentialsSaved.api_secret_saved(),
client_secret=CredentialsSaved.secret_key_saved(),
wss_url=CredentialsSaved.url())
connection_test = connect.test()
if 'version' in str(connection_test):
connect.logwriter('*** First Connection - connection ok ***')
led = 'green'
hello = connect.hello()
connect.logwriter(str(hello))
time.sleep(2)
pass
else:
list_monitor_log.append('********** First Connection - Connection Error **********')
set_led_red()
def set_led_red():
global led
led = 'red'
def set_led_green():
global led
led = 'green'
def led_color():
global led
led_color1 = led
return str(led_color1)
def connection():
global connect
global led
while True:
try:
global connect
connection_test = connect.test()
if 'version' in str(connection_test):
list_monitor_log.append('* Thread_connection - connection ok *')
time.sleep(2)
connect.cancel_all()
set_led_green()
break
elif 'too_many_requests' in str(connection_test) or '10028' in str(connection_test):
list_monitor_log.append(str('***************** Thread_connection - ERROR too_many_requests '
'******************'))
connect.logwriter(str('***************** Thread_connection - ERROR too_many_requests '
'******************'))
connect.cancel_all()
time.sleep(10)
connect.cancel_all()
else:
list_monitor_log.append('********** Thread_connection - Offline - Connection ERROR **********')
connect.logwriter(str('********** Thread_connection - OffLine - Connection ERROR **********'))
led = 'red'
time.sleep(2)
connect = Deribit(client_id=CredentialsSaved.api_secret_saved(),
client_secret=CredentialsSaved.secret_key_saved(),
wss_url=CredentialsSaved.url())
connection_test2 = connect.test()
if 'version' in str(connection_test2):
list_monitor_log.append(str('***************** Thread_connection - Reeturn Connection '
'******************'))
connect.logwriter(str('***************** Thread_connection - Reeturn Connection '
'******************'))
connect.cancel_all()
set_led_green()
break
elif 'too_many_requests' in str(connection_test2) or '10028' in str(connection_test2):
list_monitor_log.append(str('***************** Thread_connection - ERROR too_many_requests '
'******************'))
connect.logwriter(str('***************** Thread_connection - ERROR too_many_requests '
'******************'))
connect.cancel_all()
time.sleep(10)
connect.cancel_all()
else:
pass
except Exception as e:
led = 'red'
time.sleep(10)
list_monitor_log.append('********** Thread_connection ERROR: ' + str(e) + ' - Offline - **********')
connect.logwriter('********** Thread_connection ERROR: ' + str(e) + ' - Offline - **********')
connect = Deribit(client_id=CredentialsSaved.api_secret_saved(),
client_secret=CredentialsSaved.secret_key_saved(),
wss_url=CredentialsSaved.url())
connect.cancel_all()
time.sleep(2)
connect.cancel_all()
pass
finally:
pass
run_thread = threading.Thread(daemon=True, target=connection, name='run_thread')
def connection_thread():
global run_thread
run_thread = threading.Thread(daemon=True, target=connection, name='run_thread')
run_thread.start()