closed orders methods

This commit is contained in:
Nicolás Sánchez 2025-05-26 19:01:34 -03:00
parent 0ef0a512d8
commit 8ad157d17d
1 changed files with 70 additions and 8 deletions

View File

@ -540,10 +540,10 @@ class Broker:
def fetch_open_orders(self,pairs=None) -> list: def fetch_open_orders(self,pairs=None) -> list:
''' '''
Returns a list of IDs of all open orders on the exchange Returns a list of all open orders on the exchange
:param pairs: list of pairs to get opened orders :param pairs: list of pairs to get opened orders
:return: list of IDs of all open orders :return: list of all open orders
''' '''
if pairs is None: if pairs is None:
@ -553,11 +553,26 @@ class Broker:
if self.get_exchange_name()=="binance": if self.get_exchange_name()=="binance":
return self.get_opened_orders_binance(pairs) return self.get_opened_orders_binance(pairs)
return self.get_opened_orders() return self.get_opened_orders()
#else: except Exception as e:
# orders = self.get_opened_orders() self.logger.log_this(f"Exception in fetch_open_orders: {e}",2)
#if orders!=[]: return []
# id_list.extend(x["id"] for x in orders)
#return id_list
def fetch_closed_orders(self,pairs=None) -> list:
'''
Returns a list of all closed orders on the exchange
:param pairs: list of pairs to get opened orders
:return: list of all open orders
'''
if pairs is None:
pairs = []
try:
#id_list = []
if self.get_exchange_name()=="binance":
return self.get_closed_orders_binance(pairs)
return self.get_closed_orders()
except Exception as e: except Exception as e:
self.logger.log_this(f"Exception in fetch_open_orders: {e}",2) self.logger.log_this(f"Exception in fetch_open_orders: {e}",2)
return [] return []
@ -565,7 +580,7 @@ class Broker:
def get_opened_orders(self,no_retries=False): #It should return a list of all opened orders def get_opened_orders(self,no_retries=False): #It should return a list of all opened orders
''' '''
Returns a list of all the orders on the exchange Returns a list of all the open orders on the exchange
:param pairs: list of pairs :param pairs: list of pairs
:return: list of all the open orders on the exchange :return: list of all the open orders on the exchange
@ -584,6 +599,27 @@ class Broker:
return [] return []
def get_closed_orders(self,no_retries=False): #It should return a list of all opened orders
'''
Returns a list of all the open orders on the exchange
:param pairs: list of pairs
:return: list of all the open orders on the exchange
'''
retries = self.retries
while retries>0:
try:
return self.exchange.fetch_closed_orders()
except Exception as e:
self.logger.log_this(f"Exception in get_closed_orders: {e}",1)
if no_retries:
break
time.sleep(self.wait_time)
retries-=1
return []
def get_opened_orders_binance(self,pairs): def get_opened_orders_binance(self,pairs):
''' '''
Returns a list of all the open orders on the exchange Returns a list of all the open orders on the exchange
@ -605,6 +641,27 @@ class Broker:
return [] return []
def get_closed_orders_binance(self,pairs):
'''
Returns a list of all the closed orders on the exchange
:param pairs: list of pairs
:return: list of all the closed orders on the exchange
'''
try:
if "unified_order_query" in self.broker_config and self.broker_config["unified_order_query"] is True:
return self.exchange.fetch_closed_orders()
result = []
for pair in pairs:
a = self.exchange.fetch_closed_orders(pair)
result.extend(iter(a))
return result
except Exception as e:
self.logger.log_this(f"Exception in get_closed_orders_binance: {e}",1)
return []
def cancel_order(self,id,symbol,no_retries=False): def cancel_order(self,id,symbol,no_retries=False):
''' '''
Receives an order id and cancels the corresponding order Receives an order id and cancels the corresponding order
@ -1102,4 +1159,9 @@ class Logger:
return 0 return 0
class Order:
def __init__(self, order: dict = {}):
pass