validate_market
This commit is contained in:
parent
35dc6e75ce
commit
9620747e12
|
|
@ -1,3 +1,6 @@
|
||||||
|
2025.04.04:
|
||||||
|
. Added validate_market method to the broker object.
|
||||||
|
|
||||||
2025.03.29:
|
2025.03.29:
|
||||||
. Enabling last_call disables autoswitch.
|
. Enabling last_call disables autoswitch.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -89,6 +89,23 @@ class Broker:
|
||||||
return {}
|
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):
|
def reload_markets(self):
|
||||||
try:
|
try:
|
||||||
self.markets = self.exchange.load_markets(reload=True)
|
self.markets = self.exchange.load_markets(reload=True)
|
||||||
|
|
|
||||||
11
main.py
11
main.py
|
|
@ -16,7 +16,7 @@ import exchange_wrapper
|
||||||
import trader
|
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
|
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"})
|
return jsonify({"Error": "Pair already running"})
|
||||||
|
|
||||||
#Check if the market exists and it's open
|
#Check if the market exists and it's open
|
||||||
markets = broker.exchange.load_markets()
|
if not broker.validate_market(f"{base}/{quote}"):
|
||||||
if f"{base}/{quote}" not in markets:
|
return jsonify({"Error": "Market error. Check logs for more info."})
|
||||||
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"})
|
|
||||||
|
|
||||||
broker.logger.log_this(f"Initializing trader",2,f"{base}/{quote}")
|
broker.logger.log_this(f"Initializing trader",2,f"{base}/{quote}")
|
||||||
add_instance(base,quote)
|
add_instance(base,quote)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue