From 5e3ec38ea75736e2b40952628f396c8fb4b4e8da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20S=C3=A1nchez?= Date: Fri, 11 Jul 2025 17:09:53 -0300 Subject: [PATCH] mod_order_size --- changelog.txt | 1 + main.py | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/changelog.txt b/changelog.txt index 4e4b3a6..a4add7e 100755 --- a/changelog.txt +++ b/changelog.txt @@ -2,6 +2,7 @@ . Default "check_slippage" value now False. . The default order size is now enforced per exchange. . Reinstated config reloading when a deal is closed. +. New endpoint: mod_order_size. 2025.06.04: . Added "base_add_calculation" endpoint: Calculates how many safety orders can be added with the amount of base currency available on the exchange. diff --git a/main.py b/main.py index 6526f37..25db4cf 100644 --- a/main.py +++ b/main.py @@ -774,6 +774,7 @@ def add_so(): return jsonify({'Error': 'Halp'}) return jsonify({'Error': 'API key invalid'}), 401 + @base_api.route("/mod_tp_level", methods=['POST']) def mod_tp_level(): ''' @@ -799,6 +800,33 @@ def mod_tp_level(): return jsonify({'Error': 'Halp'}) return jsonify({'Error': 'API key invalid'}), 401 + +@base_api.route("/mod_order_size", methods=['POST']) +def mod_order_size(): + ''' + POST request + + Parameters: + base: str + quote: str + 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 + base = data["base"] + quote = data["quote"] + amount = data["amount"] + return unwrapped_mod_order_size(base,quote,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(): ''' @@ -1714,6 +1742,30 @@ def unwrapped_mod_tp_level(base,quote,amount): return jsonify({"Error": "Error changing percentage"}) +def unwrapped_mod_order_size(base,quote,amount): + ''' + Modifies the order size of a pair. It applies the new order size as soon as a new deal is started. + + Parameters: + base (str): The base currency of the pair. + quote (str): The quote currency of the pair. + amount (str): The new order size. + + Returns: + jsonify: A jsonified dictionary detailing the outcome of the operation + ''' + + try: + for instance in running_traders: + if f"{base}/{quote}"==instance.config.get_pair(): + instance.config.set_order_size(float(amount)) + broker.logger.log_this("Done. The change will take effect when the next deal is started",2,f"{base}/{quote}") + return jsonify({"Success": "Success. The change will take effect when the next deal is started"}) + 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_global_tp_level(amount): ''' Modifies the take profit percentage of all pairs. It applies the new percentage only after a new TP order is sent.