mod_order_size

This commit is contained in:
Nicolás Sánchez 2025-07-11 17:09:53 -03:00
parent bfd1cc34d2
commit 5e3ec38ea7
2 changed files with 53 additions and 0 deletions

View File

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

52
main.py
View File

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