From 7b19aaa11f82e166dcc2566fb6fc2d7db904f050 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20S=C3=A1nchez?= Date: Wed, 3 Jun 2026 19:39:00 -0300 Subject: [PATCH] - Fixed colons in backup filenames - Fixed shallow copy in config handler - Fixed no URL encoding for Telegram messages - Fixed no SQLite thread safety --- config_handler.py | 3 ++- duster.py | 6 +++--- exchange_wrapper.py | 5 ++++- status_handler.py | 2 +- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/config_handler.py b/config_handler.py index 3a77c49..7141cf6 100644 --- a/config_handler.py +++ b/config_handler.py @@ -1,5 +1,6 @@ from time import time from json import dumps, load +from copy import deepcopy class ConfigHandler: ''' @@ -55,7 +56,7 @@ class ConfigHandler: def reset_to_default(self): - self.config_dictionary = self.default_config_dictionary.copy() + self.config_dictionary = deepcopy(self.default_config_dictionary) return 0 def get_pair(self): diff --git a/duster.py b/duster.py index 729b632..ed38bc9 100644 --- a/duster.py +++ b/duster.py @@ -15,7 +15,7 @@ class duster: self.broker = broker if not importing: order = self.broker.get_order(status_info["tp_order_id"],status_info["market"]["symbol"]) - self.duster_status = {"duster_id": status_info["tp_order_id"], + self.duster_status = {"id": status_info["tp_order_id"], "pair": status_info["market"]["symbol"], "amount_spent": status_info["quote_spent"], "current_price": current_price, @@ -51,7 +51,7 @@ class duster: #Check if necessary mid_price = 0 high_price = 0 - if self.duster_status["price"] is not None: + if self.duster_status.get("current_price") is not None: mid_price = self.duster_status["current_price"] if self.duster_status["deal_close_price"] is not None: high_price = self.duster_status["deal_close_price"] @@ -189,7 +189,7 @@ class duster: if self.broker.get_exchange_name()=="binance": #CCXT still to this day does not take Binance fees into account. try: - market = self.broker.fetch_maker(self.duster_status["pair"]) + market = self.broker.fetch_market(self.duster_status["pair"]) fee_rate = market["maker"] if order["type"]=="limit" else market["taker"] except Exception as e: self.broker.logger.log_this(f"Exception fetching market information: {e}. Using default fee rate of 0.1%",1,f"{base}{quote}") diff --git a/exchange_wrapper.py b/exchange_wrapper.py index 7b980b3..0a01e3d 100755 --- a/exchange_wrapper.py +++ b/exchange_wrapper.py @@ -6,6 +6,7 @@ from contextlib import contextmanager from requests import get as requests_get from json import load, dumps from copy import deepcopy +from urllib.parse import quote class Broker: @@ -34,6 +35,8 @@ class Broker: self._db = sqlite3.connect(self.profits_database_filename, detect_types=sqlite3.PARSE_DECLTYPES | sqlite3.PARSE_COLNAMES, check_same_thread=False) + self._db.execute("PRAGMA journal_mode=WAL") + self._db.execute("PRAGMA synchronous=NORMAL") self._db.row_factory = sqlite3.Row with self._db: self._db.execute(''' @@ -1120,7 +1123,7 @@ class Logger: ''' try: tg_credentials = credentials.get_credentials("telegram") - send_text = f"https://api.telegram.org/bot{tg_credentials['token']}/sendMessage?chat_id={tg_credentials['chatid']}&parse_mode=Markdown&text={message}" + send_text = f"https://api.telegram.org/bot{tg_credentials['token']}/sendMessage?chat_id={tg_credentials['chatid']}&parse_mode=Markdown&text={quote(message)}" output = None if self.broker_config["telegram"] or ignore_config: output = requests_get(send_text,timeout=5).json() #5 seconds timeout. This could also be a tunable. diff --git a/status_handler.py b/status_handler.py index 13c704e..f79575e 100644 --- a/status_handler.py +++ b/status_handler.py @@ -430,7 +430,7 @@ class StatusHandler: file_path = self.status_file_path if is_backup: try: - with open(strftime(f"{file_path}_%Y-%m-%d_%H:%M:%S.json"), "w") as f: + with open(strftime(f"{file_path}_%Y-%m-%d_%H-%M-%S.json"), "w") as f: f.write(dumps(self.status_dictionary, indent=4)) except Exception as e: self.broker.logger.log_this(f"Error creating status backup file: {e}",1)