switch_to_long endpoint
This commit is contained in:
parent
9114322191
commit
233bf07a13
|
|
@ -1,3 +1,6 @@
|
|||
2024.11.06b:
|
||||
. Added /switch_to_long_price endpoint: It displays the price at which the automatic switch_to_long routine is triggered.
|
||||
|
||||
2024.11.06:
|
||||
. Optimized the conditionals that lead to switch_to_long.
|
||||
|
||||
|
|
|
|||
53
main.py
53
main.py
|
|
@ -22,7 +22,7 @@ In case the permissions of the certificate changes, reset them this way:
|
|||
# ll /etc/letsencrypt/
|
||||
'''
|
||||
|
||||
version = "2024.11.06"
|
||||
version = "2024.11.06b"
|
||||
|
||||
'''
|
||||
Color definitions. If you want to change them, check the reference at https://en.wikipedia.org/wiki/ANSI_escape_code#Colors
|
||||
|
|
@ -564,6 +564,26 @@ def return_old_long():
|
|||
return jsonify({'Error': 'Halp'})
|
||||
return jsonify({'Error': 'API key invalid'}), 401
|
||||
|
||||
@base_api.route("/switch_to_long_price", methods=["GET"])
|
||||
def return_switch_price():
|
||||
'''
|
||||
GET request
|
||||
|
||||
Parameters:
|
||||
base: str
|
||||
quote: str
|
||||
'''
|
||||
|
||||
if "X-API-KEY" in request.headers and request.headers.get("X-API-KEY") in valid_keys:
|
||||
try:
|
||||
base = request.args.get("base")
|
||||
quote = request.args.get("quote")
|
||||
return unwrapped_switch_to_long_price(base,quote)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
return jsonify({'Error': 'Halp'})
|
||||
return jsonify({'Error': 'API key invalid'}), 401
|
||||
|
||||
@base_api.route("/get_all_worker_status", methods=['GET'])
|
||||
def return_all_worker_status():
|
||||
'''
|
||||
|
|
@ -1475,7 +1495,38 @@ def unwrapped_view_old_long(base,quote,from_file):
|
|||
return jsonify(old_long)
|
||||
for x in running_instances:
|
||||
if f"{base}/{quote}"==x.pair:
|
||||
if "old_long" in x.status_dict:
|
||||
return jsonify(x.status_dict["old_long"])
|
||||
return jsonify({"Error": "No old_long info found"})
|
||||
return jsonify({"Error": "Pair not found"})
|
||||
except Exception as e:
|
||||
broker.logger.log_this(f"Exception while viewing old_long info: {e}",1,f"{base}/{quote}")
|
||||
return jsonify({"Error": f"{e}"})
|
||||
|
||||
|
||||
def unwrapped_switch_to_long_price(base,quote):
|
||||
'''
|
||||
Returns the content of an old_long file
|
||||
|
||||
Parameters:
|
||||
base (str): The base currency of the pair
|
||||
quote (str): The quote currency of the pair
|
||||
from_file (int): 1 if the file is to be loaded from the file system, 0 if it is to be loaded from the trader's status dictionary.
|
||||
|
||||
Returns:
|
||||
jsonify: A jsonified dictionary containing the old_long info.
|
||||
'''
|
||||
|
||||
try:
|
||||
for x in running_instances:
|
||||
if f"{base}/{quote}"==x.pair:
|
||||
if "old_long" in x.status_dict:
|
||||
#minimum_switch_price = (old_target - quote_already_in)/base_left
|
||||
old_target = x.status_dict["old_long"]["tp_price"]*x.status_dict["old_long"]["tp_amount"]
|
||||
base_left = x.status_dict["old_long"]["tp_amount"]-x.status_dict["base_bought"]
|
||||
minimum_switch_price = (old_target - x.status_dict["quote_spent"])/base_left
|
||||
return jsonify({"switch_price": minimum_switch_price})
|
||||
return jsonify({"Error": "No old_long info found"})
|
||||
return jsonify({"Error": "Pair not found"})
|
||||
except Exception as e:
|
||||
broker.logger.log_this(f"Exception while viewing old_long info: {e}",1,f"{base}/{quote}")
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ TRADERS
|
|||
62) mod_tp_level 63) last_call 64) deferred_last_call
|
||||
65) toggle_pause 66) toggle_cleanup 67) toggle_autoswitch
|
||||
68) toggle_check_old_long_price 69) switch_quote_currency
|
||||
70) reload_safety_order 71) view_old_long
|
||||
70) reload_safety_order 71) view_old_long 72) switch_price
|
||||
|
||||
98) Change broker 99) Exit
|
||||
'''
|
||||
|
|
@ -602,3 +602,15 @@ if __name__=="__main__":
|
|||
url = f"{base_url}{port}/view_old_long?base={base}"e={quote}&from_file={from_file}"
|
||||
print(json.loads(requests.get(url,headers=headers).content))
|
||||
input("Press ENTER to continue ")
|
||||
|
||||
elif command==72:
|
||||
print("Returns the price target to reach to switch to long mode")
|
||||
trading_pair = input("Input trader in the format BASE/QUOTE: ").upper()
|
||||
if not validate_pair(trading_pair):
|
||||
print("The input is invalid")
|
||||
break
|
||||
if input("Proceed? (Y/n) ") in ["Y","y",""]:
|
||||
base,quote = trading_pair.split("/")
|
||||
url = f"{base_url}{port}/switch_to_long_price?base={base}"e={quote}"
|
||||
print(json.loads(requests.get(url,headers=headers).content))
|
||||
input("Press ENTER to continue ")
|
||||
Loading…
Reference in New Issue