Simplified unwrapped_add_pair
This commit is contained in:
parent
29fcb74896
commit
67e14de804
|
|
@ -1,3 +1,6 @@
|
||||||
|
2025.05.04:
|
||||||
|
. Simplified unwrapped_add_pair.
|
||||||
|
|
||||||
2025.04.10:
|
2025.04.10:
|
||||||
. Modified Gate.io min_base_size.
|
. Modified Gate.io min_base_size.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -336,8 +336,11 @@ class Broker:
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
|
||||||
def rewrite_config_file(self):
|
def rewrite_config_file(self, backup=False):
|
||||||
try:
|
try:
|
||||||
|
if backup:
|
||||||
|
with open(f"{self.exchange}.bak","w") as c:
|
||||||
|
c.write(json.dumps(self.broker_config, indent=4))
|
||||||
with open(f"{self.config_filename}","w") as f:
|
with open(f"{self.config_filename}","w") as f:
|
||||||
f.write(json.dumps(self.broker_config, indent=4))
|
f.write(json.dumps(self.broker_config, indent=4))
|
||||||
return 0
|
return 0
|
||||||
|
|
|
||||||
36
main.py
36
main.py
|
|
@ -16,7 +16,7 @@ import exchange_wrapper
|
||||||
import trader
|
import trader
|
||||||
|
|
||||||
|
|
||||||
version = "2025.04.10"
|
version = "2025.05.04"
|
||||||
|
|
||||||
'''
|
'''
|
||||||
Color definitions. If you want to change them, check the reference at https://en.wikipedia.org/wiki/ANSI_escape_code#Colors
|
Color definitions. If you want to change them, check the reference at https://en.wikipedia.org/wiki/ANSI_escape_code#Colors
|
||||||
|
|
@ -1326,23 +1326,25 @@ def unwrapped_add_pair(base,quote):
|
||||||
add_instance(base,quote)
|
add_instance(base,quote)
|
||||||
|
|
||||||
broker.add_pair_to_config(f"{base}{quote}")
|
broker.add_pair_to_config(f"{base}{quote}")
|
||||||
|
broker.rewrite_config_file(backup=True)
|
||||||
|
|
||||||
|
# #Adding the pair to the config file (if it's not there yet)
|
||||||
|
# #1. Read the config file
|
||||||
|
# with open(sys.argv[1],"r") as f:
|
||||||
|
# temp_details = json.load(f)
|
||||||
|
# if base+quote not in temp_details["pairs"]:
|
||||||
|
# #2. Save the current config file as .bak
|
||||||
|
# with open(f"{sys.argv[1]}.bak","w") as c:
|
||||||
|
# c.write(json.dumps(temp_details, indent=4))
|
||||||
|
# #3. Add the pair to the right list
|
||||||
|
# temp_details["pairs"].append(f"{base}{quote}")
|
||||||
|
# #4. Write the config file
|
||||||
|
# with open(sys.argv[1],"w") as c:
|
||||||
|
# c.write(json.dumps(temp_details, indent=4))
|
||||||
|
# broker.logger.log_this(f"Broker's config file updated",2,f"{base}/{quote}")
|
||||||
|
# else:
|
||||||
|
# broker.logger.log_this(f"Pair already included in the config file",2,f"{base}/{quote}")
|
||||||
|
|
||||||
#Adding the pair to the config file (if it's not there yet)
|
|
||||||
#1. Read the config file
|
|
||||||
with open(sys.argv[1],"r") as f:
|
|
||||||
temp_details = json.load(f)
|
|
||||||
if base+quote not in temp_details["pairs"]:
|
|
||||||
#2. Save the current config file as .bak
|
|
||||||
with open(f"{sys.argv[1]}.bak","w") as c:
|
|
||||||
c.write(json.dumps(temp_details, indent=4))
|
|
||||||
#3. Add the pair to the right list
|
|
||||||
temp_details["pairs"].append(f"{base}{quote}")
|
|
||||||
#4. Write the config file
|
|
||||||
with open(sys.argv[1],"w") as c:
|
|
||||||
c.write(json.dumps(temp_details, indent=4))
|
|
||||||
broker.logger.log_this(f"Broker's config file updated",2,f"{base}/{quote}")
|
|
||||||
else:
|
|
||||||
broker.logger.log_this(f"Pair already included in the config file",2,f"{base}/{quote}")
|
|
||||||
return jsonify({"Success": "Pair added"})
|
return jsonify({"Success": "Pair added"})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
broker.logger.log_this(f"Exception while initializing new instance: {e}",1,f"{base}/{quote}")
|
broker.logger.log_this(f"Exception while initializing new instance: {e}",1,f"{base}/{quote}")
|
||||||
|
|
|
||||||
|
|
@ -634,7 +634,7 @@ class trader:
|
||||||
with open(f"configs/{self.base}{self.quote}.json","w") as c:
|
with open(f"configs/{self.base}{self.quote}.json","w") as c:
|
||||||
c.write(json.dumps(old_config, indent=4))
|
c.write(json.dumps(old_config, indent=4))
|
||||||
self.config.load_from_file()
|
self.config.load_from_file()
|
||||||
self.config.set_is_short(False)
|
self.config.set_is_short(False) #This probably is not needed
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.broker.logger.log_this(f"Exception in switch_to_long while switching config files: {e}",1,self.config.get_pair())
|
self.broker.logger.log_this(f"Exception in switch_to_long while switching config files: {e}",1,self.config.get_pair())
|
||||||
self.quit = True
|
self.quit = True
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue