diff --git a/changelog.txt b/changelog.txt index 254aafa..5e63ca1 100755 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,6 @@ +2025.05.04: +. Simplified unwrapped_add_pair. + 2025.04.10: . Modified Gate.io min_base_size. diff --git a/exchange_wrapper.py b/exchange_wrapper.py index 1388bd6..2fd640a 100755 --- a/exchange_wrapper.py +++ b/exchange_wrapper.py @@ -336,8 +336,11 @@ class Broker: return 1 - def rewrite_config_file(self): + def rewrite_config_file(self, backup=False): 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: f.write(json.dumps(self.broker_config, indent=4)) return 0 diff --git a/main.py b/main.py index e8ea61d..2cca70c 100644 --- a/main.py +++ b/main.py @@ -16,7 +16,7 @@ import exchange_wrapper 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 @@ -1326,23 +1326,25 @@ def unwrapped_add_pair(base,quote): add_instance(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"}) except Exception as e: broker.logger.log_this(f"Exception while initializing new instance: {e}",1,f"{base}/{quote}") diff --git a/trader.py b/trader.py index b874a67..8741cd5 100755 --- a/trader.py +++ b/trader.py @@ -634,7 +634,7 @@ class trader: with open(f"configs/{self.base}{self.quote}.json","w") as c: c.write(json.dumps(old_config, indent=4)) 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: self.broker.logger.log_this(f"Exception in switch_to_long while switching config files: {e}",1,self.config.get_pair()) self.quit = True