diff --git a/changelog.txt b/changelog.txt index 07ee2df..7f133a3 100755 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,6 @@ +2025.04.04: +. Added validate_market method to the broker object. + 2025.03.29: . Enabling last_call disables autoswitch. diff --git a/exchange_wrapper.py b/exchange_wrapper.py index ad2dbf2..e9e45a8 100755 --- a/exchange_wrapper.py +++ b/exchange_wrapper.py @@ -89,6 +89,23 @@ class Broker: return {} + def validate_market(self,symbol): + ''' + Checks that the market for the symbol exists, that it's a spot market and that it's active. + Returns True if the market is valid, False otherwise. + ''' + if symbol not in self.markets: + self.logger.log_this(f"Market {symbol} not found in the exchange") + return False + if self.markets[symbol]['spot'] == False: + self.logger.log_this(f"Market {symbol} is not a spot market") + return False + if self.markets[symbol]['active'] == False: + self.logger.log_this(f"Market {symbol} is not active") + return False + return True + + def reload_markets(self): try: self.markets = self.exchange.load_markets(reload=True) diff --git a/main.py b/main.py index b5f5f1a..42396a5 100644 --- a/main.py +++ b/main.py @@ -16,7 +16,7 @@ import exchange_wrapper import trader -version = "2025.03.29" +version = "2025.04.04" ''' Color definitions. If you want to change them, check the reference at https://en.wikipedia.org/wiki/ANSI_escape_code#Colors @@ -1319,13 +1319,8 @@ def unwrapped_add_pair(base,quote): return jsonify({"Error": "Pair already running"}) #Check if the market exists and it's open - markets = broker.exchange.load_markets() - if f"{base}/{quote}" not in markets: - broker.logger.log_this(f"Market does not exist",1,f"{base}/{quote}") - return jsonify({"Error": "Market does not exist"}) - if not markets[f"{base}/{quote}"]["active"]: - broker.logger.log_this(f"Market is inactive",1,f"{base}/{quote}") - return jsonify({"Error": "Market is inactive"}) + if not broker.validate_market(f"{base}/{quote}"): + return jsonify({"Error": "Market error. Check logs for more info."}) broker.logger.log_this(f"Initializing trader",2,f"{base}/{quote}") add_instance(base,quote)