From 3feb5f3a7719f1c465db96deb5c7ea9b55566aed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20S=C3=A1nchez?= Date: Sun, 10 Aug 2025 10:53:08 -0300 Subject: [PATCH] 2025.08.10 --- changelog.txt | 5 +++++ config_handler.py | 5 +++-- main.py | 48 ++++++++++++++++++++++++++++++++++++++++++++--- todo.txt | 1 + trader.py | 2 +- 5 files changed, 55 insertions(+), 6 deletions(-) diff --git a/changelog.txt b/changelog.txt index 570281d..3d0961b 100755 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,8 @@ +2025.08.10: +. Added exchange name to the trader quit notification. +. New endpoint: mod_default_order_size. It modified the default order size of a broker. +. Added "generated_at" field to any new generated trader config file. + 2025.07.21: . Corrected an error in switch_to_long. diff --git a/config_handler.py b/config_handler.py index dcc979d..4bc3a93 100644 --- a/config_handler.py +++ b/config_handler.py @@ -1,5 +1,5 @@ import json -import os +import time class ConfigHandler: ''' @@ -40,7 +40,8 @@ class ConfigHandler: #Loads from disk the config file (if it exists) if self.load_from_file()==1: - #If the config file does not exist, write a new one with the default values + #If the config file does not exist, write a new one with the default values and sign it with timestamp. + self.config_dictionary["generated_at"] = int(time.time()) self.save_to_file() if config_dict is not None: self.config_dictionary = {**self.config_dictionary, **config_dict} diff --git a/main.py b/main.py index 3e133eb..6675ae6 100644 --- a/main.py +++ b/main.py @@ -16,7 +16,7 @@ import exchange_wrapper import trader -version = "2025.07.21" +version = "2025.08.10" ''' Color definitions. If you want to change them, check the reference at https://en.wikipedia.org/wiki/ANSI_escape_code#Colors @@ -269,8 +269,8 @@ def main_loop(): restart_pair_no_json(instance.base,instance.quote) if instance.quit: #Here, check if a duster is needed - broker.logger.log_this(f"Quit flag raised, removing pair.",0,instance.config.get_pair()) - broker.logger.log_this(f"Quit flag raised, removing pair: {instance.config.get_pair()}",-1) #Forced message to TG + broker.logger.log_this(f"{broker.get_exchange_name().capitalize()} | Quit flag raised, removing trader.",0,instance.config.get_pair()) + broker.logger.log_this(f"{broker.get_exchange_name().capitalize()} | Quit flag raised, removing trader: {instance.config.get_pair()}",-1) #Forced message to TG if f"{instance.base}{instance.quote}" in tickers: tickers.remove(f"{instance.base}{instance.quote}") broker.remove_pair_from_config(f"{instance.base}{instance.quote}") @@ -827,6 +827,28 @@ def mod_order_size(): return jsonify({'Error': 'API key invalid'}), 401 +@base_api.route("/mod_default_order_size", methods=['POST']) +def mod_default_order_size(): + ''' + POST request + + Parameters: + amount: float + ''' + + if "X-API-KEY" in request.headers and request.headers.get("X-API-KEY") in valid_keys: + try: + if request.json is None: + return jsonify({'Error': 'request.json is None'}) + data = request.json + amount = data["amount"] + return unwrapped_mod_default_order_size(amount) + except Exception as e: + print(e) + return jsonify({'Error': 'Halp'}) + return jsonify({'Error': 'API key invalid'}), 401 + + @base_api.route("/mod_global_tp_level", methods=['POST']) def mod_global_tp_level(): ''' @@ -1764,7 +1786,27 @@ def unwrapped_mod_order_size(base,quote,amount): except Exception: broker.logger.log_this("Error changing order size. Ignoring...",2,f"{base}/{quote}") return jsonify({"Error": "Error changing order size"}) + + +def unwrapped_mod_default_order_size(amount): + ''' + Modifies the default order size of a broker. + Parameters: + amount (str): The new order size. + + Returns: + jsonify: A jsonified dictionary detailing the outcome of the operation + ''' + + try: + broker.set_default_order_size(float(amount)) + broker.logger.log_this(f"Done. Default order size modified to {float(amount)}",2) + return jsonify({"Success": f"Success. Default order size modified to {float(amount)}"}) + except Exception: + broker.logger.log_this("Error modifying default order size",2) + return jsonify({"Error": "Error modifying default order size"}) + def unwrapped_mod_global_tp_level(amount): ''' diff --git a/todo.txt b/todo.txt index 14cd303..16ff8c2 100755 --- a/todo.txt +++ b/todo.txt @@ -11,6 +11,7 @@ Mandatory: * Status (Mostly done). 6. API documentation. 7. Implement api key hashing. +8. Dockerize. Would be nice to have: diff --git a/trader.py b/trader.py index df0dd7a..522d878 100755 --- a/trader.py +++ b/trader.py @@ -1583,7 +1583,7 @@ class trader: return f"{white}{line1}\n{line3}{white}" - + def load_imported_trader(self, forced_tp_order_id = None, forced_safety_order_id = None) -> int: ''' Loads status dictionary, orders and sets up variables