Add open_order_updater
This commit is contained in:
parent
c4d7aff5c3
commit
95efc0d688
@ -227,6 +227,22 @@ class FreqtradeBot:
|
||||
open_trades = len(Trade.get_open_trades())
|
||||
return max(0, self.config['max_open_trades'] - open_trades)
|
||||
|
||||
def update_open_orders(self):
|
||||
"""
|
||||
Updates open orders based on order list kept in the database
|
||||
"""
|
||||
orders = Order.get_open_orders()
|
||||
logger.info(f"Updating {len(orders)} open orders.")
|
||||
for order in orders:
|
||||
try:
|
||||
if order.ft_order_side == 'stoposs':
|
||||
fo = self.exchange.fetch_stoploss_order(order.order_id, order.ft_pair)
|
||||
else:
|
||||
fo = self.exchange.fetch_order(order.order_id, order.ft_pair)
|
||||
order.update_from_ccxt_object(fo)
|
||||
except ExchangeError:
|
||||
logger.warning(f"Error updating {order.order_id}")
|
||||
|
||||
#
|
||||
# BUY / enter positions / open trades logic and methods
|
||||
#
|
||||
|
@ -159,6 +159,7 @@ class Order(_DECL_BASE):
|
||||
@staticmethod
|
||||
def update_orders(orders: List['Order'], order: Dict[str, Any]):
|
||||
"""
|
||||
Get all non-closed orders - useful when trying to batch-update orders
|
||||
"""
|
||||
filtered_orders = [o for o in orders if o.order_id == order['id']]
|
||||
if filtered_orders:
|
||||
@ -177,6 +178,12 @@ class Order(_DECL_BASE):
|
||||
o.update_from_ccxt_object(order)
|
||||
return o
|
||||
|
||||
@staticmethod
|
||||
def get_open_orders():
|
||||
"""
|
||||
"""
|
||||
return Order.query.filter(Order.ft_is_open.is_(True)).all()
|
||||
|
||||
|
||||
class Trade(_DECL_BASE):
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user