From d65751df48e654c84bc70e2097d2a8c69f2aa169 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20S=C3=A1nchez?= Date: Tue, 10 Dec 2024 09:24:03 -0300 Subject: [PATCH] logging --- utils/fetch_pair_volatility.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/utils/fetch_pair_volatility.py b/utils/fetch_pair_volatility.py index 8fb368b..3d9f763 100644 --- a/utils/fetch_pair_volatility.py +++ b/utils/fetch_pair_volatility.py @@ -11,6 +11,13 @@ import statistics from credentials import get_credentials from threading import Thread +def write_to_log(message): + ''' + Writes a message to the log file + ''' + with open("log.txt", "a") as f: + f.write(message) + def yang_zhang(candles): ''' @@ -128,13 +135,13 @@ def fetch_data(broker: str, pair_list: list, timeframe: str, samples: int): try: data = exchange.fetch_ohlcv(pair,timeframe=timeframe,limit=samples) except Exception as e: - print(e) + write_to_log(str(e)) continue try: parkinson_volatility = parkinson(data) yangzhang_volatility = yang_zhang(data) except Exception as e: - print(e) + write_to_log(str(e)) continue for item in data: trading_volume += item[4]*item[5]