|
5 | 5 |
|
6 | 6 | from __future__ import annotations |
7 | 7 |
|
| 8 | +import ast |
8 | 9 | import json |
9 | 10 | import logging |
10 | 11 | import socket |
@@ -173,15 +174,17 @@ def accumulation_distribution( |
173 | 174 | result = data.decode("utf-8") |
174 | 175 | try: |
175 | 176 | return json.loads(result) |
176 | | - |
177 | 177 | except ValueError: |
178 | 178 | logger.exception("Connection lost to MQL5 Service") |
179 | | - |
180 | 179 | except ConnectionResetError: |
181 | | - pass |
182 | | - |
| 180 | + logger.exception("Connection reset by MQL5 Service") |
183 | 181 | except ConnectionAbortedError: |
184 | | - pass |
| 182 | + logger.exception("Connection aborted by MQL5 Service") |
| 183 | + finally: |
| 184 | + if "client_socket" in locals(): |
| 185 | + client_socket.close() |
| 186 | + |
| 187 | + return None |
185 | 188 |
|
186 | 189 | # -------------------------------------------------------------------- # |
187 | 190 |
|
@@ -236,15 +239,17 @@ def adaptive_moving_average( |
236 | 239 | result = data.decode("utf-8") |
237 | 240 | try: |
238 | 241 | return json.loads(result) |
239 | | - |
240 | 242 | except ValueError: |
241 | 243 | logger.exception("Connection lost to MQL5 Service") |
242 | | - |
243 | 244 | except ConnectionResetError: |
244 | | - pass |
245 | | - |
| 245 | + logger.exception("Connection reset by MQL5 Service") |
246 | 246 | except ConnectionAbortedError: |
247 | | - pass |
| 247 | + logger.exception("Connection aborted by MQL5 Service") |
| 248 | + finally: |
| 249 | + if "client_socket" in locals(): |
| 250 | + client_socket.close() |
| 251 | + |
| 252 | + return None |
248 | 253 |
|
249 | 254 | # -------------------------------------------------------------------- # |
250 | 255 |
|
@@ -307,15 +312,17 @@ def alligator( |
307 | 312 | result = data.decode("utf-8") |
308 | 313 | try: |
309 | 314 | return json.loads(result) |
310 | | - |
311 | 315 | except ValueError: |
312 | 316 | logger.exception("Connection lost to MQL5 Service") |
313 | | - |
314 | 317 | except ConnectionResetError: |
315 | | - pass |
316 | | - |
| 318 | + logger.exception("Connection reset by MQL5 Service") |
317 | 319 | except ConnectionAbortedError: |
318 | | - pass |
| 320 | + logger.exception("Connection aborted by MQL5 Service") |
| 321 | + finally: |
| 322 | + if "client_socket" in locals(): |
| 323 | + client_socket.close() |
| 324 | + |
| 325 | + return None |
319 | 326 |
|
320 | 327 | # -------------------------------------------------------------------- # |
321 | 328 |
|
@@ -347,15 +354,17 @@ def average_directional_index( |
347 | 354 | result = data.decode("utf-8") |
348 | 355 | try: |
349 | 356 | return json.loads(result) |
350 | | - |
351 | 357 | except ValueError: |
352 | 358 | logger.exception("Connection lost to MQL5 Service") |
353 | | - |
354 | 359 | except ConnectionResetError: |
355 | | - pass |
356 | | - |
| 360 | + logger.exception("Connection reset by MQL5 Service") |
357 | 361 | except ConnectionAbortedError: |
358 | | - pass |
| 362 | + logger.exception("Connection aborted by MQL5 Service") |
| 363 | + finally: |
| 364 | + if "client_socket" in locals(): |
| 365 | + client_socket.close() |
| 366 | + |
| 367 | + return None |
359 | 368 |
|
360 | 369 | # -------------------------------------------------------------------- # |
361 | 370 |
|
@@ -389,15 +398,17 @@ def average_directional_index_wilder( |
389 | 398 | result = data.decode("utf-8") |
390 | 399 | try: |
391 | 400 | return json.loads(result) |
392 | | - |
393 | 401 | except ValueError: |
394 | 402 | logger.exception("Connection lost to MQL5 Service") |
395 | | - |
396 | 403 | except ConnectionResetError: |
397 | | - pass |
398 | | - |
| 404 | + logger.exception("Connection reset by MQL5 Service") |
399 | 405 | except ConnectionAbortedError: |
400 | | - pass |
| 406 | + logger.exception("Connection aborted by MQL5 Service") |
| 407 | + finally: |
| 408 | + if "client_socket" in locals(): |
| 409 | + client_socket.close() |
| 410 | + |
| 411 | + return None |
401 | 412 |
|
402 | 413 | # -------------------------------------------------------------------- # |
403 | 414 |
|
@@ -429,15 +440,17 @@ def average_true_range( |
429 | 440 | result = data.decode("utf-8") |
430 | 441 | try: |
431 | 442 | return json.loads(result) |
432 | | - |
433 | 443 | except ValueError: |
434 | 444 | logger.exception("Connection lost to MQL5 Service") |
435 | | - |
436 | 445 | except ConnectionResetError: |
437 | | - pass |
438 | | - |
| 446 | + logger.exception("Connection reset by MQL5 Service") |
439 | 447 | except ConnectionAbortedError: |
440 | | - pass |
| 448 | + logger.exception("Connection aborted by MQL5 Service") |
| 449 | + finally: |
| 450 | + if "client_socket" in locals(): |
| 451 | + client_socket.close() |
| 452 | + |
| 453 | + return None |
441 | 454 |
|
442 | 455 | # -------------------------------------------------------------------- # |
443 | 456 |
|
@@ -1879,7 +1892,7 @@ def triple_exponential_ma_oscillator( |
1879 | 1892 | data = f"TEMA_OSC,{symbol},{time_frame},{start_position},{count},{ma_period},{applied_price}" |
1880 | 1893 | client_socket.send(data.encode()) |
1881 | 1894 | response = client_socket.recv(1024).decode() |
1882 | | - return eval(response) |
| 1895 | + return ast.literal_eval(response) |
1883 | 1896 | except ValueError: |
1884 | 1897 | logger.exception("Connection lost to MQL5 Service") |
1885 | 1898 | except ConnectionResetError: |
|
0 commit comments