diff --git a/changelog.txt b/changelog.txt index bcc2492..829b811 100755 --- a/changelog.txt +++ b/changelog.txt @@ -1,5 +1,6 @@ 2024.10.28: . Docstrings and comments improvements. +. New endpoint: /edit_cooldown_multiplier. 2024.10.25: . Modified some strings. diff --git a/configs/exchange_config.json.example b/configs/exchange_config.json.example index cb187ef..29199be 100755 --- a/configs/exchange_config.json.example +++ b/configs/exchange_config.json.example @@ -15,6 +15,7 @@ ], "reconnect": 30, #Deprecated "lap_time": 1, #Time in seconds between each iteration of the instance. + "cooldown_multiplier": 2, #Time in seconds to wait between closing a new trade and starting a new one. Useful to combat big orderbook movements. "host": "0.0.0.0", #API host "port": "5006", #API port "telegram": false, #Send Telegram notifications diff --git a/exchange_wrapper.py b/exchange_wrapper.py index 53dc26d..1f921ba 100755 --- a/exchange_wrapper.py +++ b/exchange_wrapper.py @@ -13,7 +13,9 @@ class broker: self.exchange = exchange self.last_price = 0 self.wait_time = 1 #Default wait time for API breathing room - self.cooldown_multiplier = 2 #Cooldown multiplier of the value above between trader restarts or when slippage is exceeded (this should be in the config file) + self.cooldown_multiplier = 2 #Default cooldown multiplier value + if "cooldown_multiplier" in self.read_config: + self.cooldown_multiplier = self.read_config["cooldown_multiplier"] self.empty_order = {"id": "", "status": "", "filled": 0, "remaining": 0, "price": 0, "cost": 0, "fees": [], "symbol": ""} self.retries = read_config["retries"] if "retries" in self.read_config else 10 self.slippage_default_threshold = self.read_config["slippage_default_threshold"] if "slippage_default_threshold" in read_config else .03 diff --git a/main.py b/main.py index 4c5641f..9e840be 100644 --- a/main.py +++ b/main.py @@ -1121,6 +1121,29 @@ def call_wait_time(): return jsonify({'Error': 'Halp'}) return jsonify({'Error': 'API key invalid'}), 401 + +@base_api.route("/edit_cooldown_multiplier", methods=['POST']) +def edit_cooldown_multiplier(): + ''' + POST request + + Parameters: + cooldown_multiplier: 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 + multiplier = data["cooldown_multiplier"] + return unwrapped_edit_cooldown_multiplier(multiplier) + except Exception as e: + print(e) + return jsonify({'Error': 'Halp'}) + return jsonify({'Error': 'API key invalid'}), 401 + + @base_api.route("/reload_markets", methods=['POST']) def reload_markets(): ''' @@ -1919,7 +1942,7 @@ def unwrapped_call_wait_time(wait_time): Modifies the time between some API calls and retries. Parameters: - wait_time (int): The new amount of time to wait between calls and retries. + wait_time (float): The new amount of time to wait between calls and retries. Returns: jsonify: A jsonified dictionary detailing the outcome of the operation. @@ -1929,6 +1952,24 @@ def unwrapped_call_wait_time(wait_time): return jsonify({"Success": "Call wait time modified successfully"}) +def unwrapped_edit_cooldown_multiplier(cooldown_multiplier): + ''' + Modifies the broker's cooldown multiplier. + + Parameters: + cooldown_multiplier (float): The new cooldown multiplier. + + Returns: + jsonify: A jsonified dictionary detailing the outcome of the operation. + ''' + + old_value = broker.get_cooldown_multiplier() + broker.set_cooldown_multiplier(cooldown_multiplier) + broker.logger.log_this(f"Done! New cooldown multiplier changed from {old_value} seconds to {broker.get_cooldown_multiplier()} seconds.") + return jsonify({"Success": "Call cooldown multiplier modified successfully"}) + + + def unwrapped_reload_markets(): ''' Reloads the markets from the exchange. diff --git a/utils/commander.py b/utils/commander.py index 13f8d9a..78b90ff 100644 --- a/utils/commander.py +++ b/utils/commander.py @@ -32,7 +32,7 @@ INSTANCE 4) trader_time 5) toggle_restart 6) toggle_telegram 7) mod_global_tp_level 8) global_last_call 9) edit_loop_wait_time 10) edit_call_wait_time 11) reload_markets 12) fetch_full_log -13) paused_traders 14) fetch_log +13) paused_traders 14) fetch_log 15) edit_cooldown_multiplier TRADERS 51) worker_status 52) get_all_worker_status @@ -263,7 +263,20 @@ if __name__=="__main__": for item in json.loads(requests.get(url, headers=headers).content)["line"]: print(item) input("Press ENTER to continue ") - + + elif command==15: + print("edit_cooldown_multiplier modifies the pause's multiplier after it hits profit.") + print("This aims to reduce the volatility when there are big orderbook movements.") + print("The input value can be an integer or a float") + new_multiplier = input("Desired multiplier: ") + if not validate_float_or_int(new_multiplier): + print("The input is invalid") + break + if input("Proceed? (Y/n) ") in ["Y","y",""]: + url = f"{base_url}{port}/edit_cooldown_multiplier" + parameters = {"cooldown_multiplier": new_multiplier} + print(json.loads(requests.post(url, headers=headers, json=parameters).content)) + input("Press ENTER to continue ") ###################### ####### TRADER #######