cooldown_multiplier API endpoint

This commit is contained in:
Nicolás Sánchez 2024-10-28 19:37:34 -03:00
parent d3eb8e0512
commit 913d10f751
5 changed files with 62 additions and 4 deletions

View File

@ -1,5 +1,6 @@
2024.10.28:
. Docstrings and comments improvements.
. New endpoint: /edit_cooldown_multiplier.
2024.10.25:
. Modified some strings.

View File

@ -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

View File

@ -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

43
main.py
View File

@ -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.

View File

@ -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 #######