todo update

This commit is contained in:
Nicolás Sánchez 2025-06-06 17:39:15 -03:00
parent f087d0c19b
commit 846411f550
2 changed files with 18 additions and 19 deletions

26
main.py
View File

@ -1862,7 +1862,7 @@ def unwrapped_cancel_global_last_call():
def unwrapped_add_quote(base,quote,amount):
'''
Adds more funds to the deal, bringing down the average buy price.
I do not recommend to use this, it's preferable to switch to short mode, but you do you.
I do not recommend to use this, it's preferable to add safety orders or switching to short mode, but you do you.
Maybe it's more useful in a bull market's high volatility moment.
Parameters:
@ -1878,39 +1878,39 @@ def unwrapped_add_quote(base,quote,amount):
if x.config.get_is_short():
return jsonify({"Error": "Quote can't be added to short traders"})
x.pause = True
new_average_price = (x.status.get_quote_spent()+float(amount))/(x.status.get_base_bought()+(float(amount)/x.get_status_dict()["price"]))
broker.logger.log_this(f"Your new average buy price will be {new_average_price} {x.quote}",2,f"{base}/{quote}")
broker.logger.log_this(f"Your new take profit price price will be {new_average_price*x.get_tp_level()} {x.quote}",2,f"{base}/{quote}")
new_average_price = (x.status.get_quote_spent()+float(amount))/(x.status.get_base_bought()+(float(amount)/x.status.get_price()))
broker.logger.log_this(f"Your new average buy price will be {new_average_price} {quote}",2,x.config.get_pair())
broker.logger.log_this(f"Your new take profit price price will be {new_average_price*x.get_tp_level()} {quote}",2,x.config.get_pair())
new_order = broker.new_market_order(x.config.get_pair(),float(amount),"buy")
if new_order is None:
broker.logger.log_this("Error: Market order returned None",2,f"{base}/{quote}")
broker.logger.log_this("Error: Market order returned None",2,x.config.get_pair())
x.pause = False
return jsonify({"Error": "Market order returned None"})
while True:
time.sleep(broker.get_wait_time())
returned_order = broker.get_order(new_order["id"],x.config.get_pair())
if returned_order==broker.empty_order:
broker.logger.log_this("Problems sending the order",2,f"{base}/{quote}")
broker.logger.log_this("Problems sending the order",2,x.config.get_pair())
x.pause = False
return jsonify({"Error": "Problems sending the order"})
elif returned_order["status"]=="expired":
x.pause = False
return jsonify({"Error": "New order expired"})
elif returned_order["status"]=="closed":
broker.logger.log_this("Order sent",2,f"{base}/{quote}")
broker.logger.log_this("Order sent",2,x.config.get_pair())
new_fees_in_base, new_fees_in_quote = x.parse_fees(returned_order)
x.status.set_fees_paid_in_base(x.status.get_fees_paid_in_base() + new_fees_in_base)
x.status.set_fees_paid_in_quote(x.status.get_fees_paid_in_quote() + new_fees_in_quote)
x.status.set_base_bought(x.status.get_base_bought() + returned_order["filled"] - new_fees_in_base)
x.status.set_quote_spent(x.status.get_quote_spent()+returned_order["cost"])
broker.logger.log_this("Cancelling old take profit order and sending a new one",2,f"{base}/{quote}")
broker.logger.log_this("Cancelling old take profit order and sending a new one",2,x.config.get_pair())
attempts = 5
while broker.cancel_order(x.status.get_take_profit_order()["id"],x.config.get_pair())==1:
broker.logger.log_this("Can't cancel old take profit order, retrying...",2,f"{base}/{quote}")
broker.logger.log_this("Can't cancel old take profit order, retrying...",2,x.config.get_pair())
time.sleep(broker.get_wait_time())
attempts-=1
if attempts==0:
broker.logger.log_this("Can't cancel old take profit order, cancelling...",2,f"{base}/{quote}")
broker.logger.log_this("Can't cancel old take profit order, cancelling...",2,x.config.get_pair())
x.pause = False
return jsonify({"Error": "Can't cancel old take profit order."})
x.status.set_take_profit_price(x.status.get_quote_spent()/x.status.get_base_bought()*x.get_tp_level())
@ -1918,11 +1918,11 @@ def unwrapped_add_quote(base,quote,amount):
x.update_status(True)
break
else:
broker.logger.log_this("Waiting for initial order to get filled",2,f"{base}/{quote}")
broker.logger.log_this(f"{returned_order}",2,f"{base}/{quote}")
broker.logger.log_this("Waiting for initial order to get filled",2,x.config.get_pair())
broker.logger.log_this(f"{returned_order}",2,x.config.get_pair())
time.sleep(broker.get_wait_time())
x.pause = False
broker.logger.log_this("Done",2,f"{base}/{quote}")
broker.logger.log_this("Done",2,x.config.get_pair())
return jsonify({"Success": "Quote added successfully"})
return jsonify({"Error": "Something horrible happened :S"})

View File

@ -3,15 +3,14 @@ Mandatory:
1. Stats webpage.
2. Maintain local orderbooks for each trading pair, which enables:
2a. Smart order pricing: Prioritization of fill speed over instant profit or vice versa
3. Base add for short traders.
4. Proper handling of order price too high/low in OKX (rare, it happens when under heavy volatility).
5. Multiple safety orders open at the same time (to catch big volatility spikes more effectively)
6. Things that should be objects (it's not 1994):
3. Proper handling of order price too high/low in OKX (rare, it happens when under heavy volatility).
4. Multiple safety orders open at the same time (to catch big volatility spikes more effectively)
5. Things that should be objects (it's not 1994):
* Orders.
* Config (Mostly done).
* Status (Mostly done).
7. API documentation.
8. Implement api key hashing.
6. API documentation.
7. Implement api key hashing.
Would be nice to have: