Improve order catchup
This commit is contained in:
parent
95efc0d688
commit
8458a380b8
@ -134,6 +134,8 @@ class FreqtradeBot:
|
|||||||
# Adjust stoploss if it was changed
|
# Adjust stoploss if it was changed
|
||||||
Trade.stoploss_reinitialization(self.strategy.stoploss)
|
Trade.stoploss_reinitialization(self.strategy.stoploss)
|
||||||
|
|
||||||
|
self.update_open_orders()
|
||||||
|
|
||||||
def process(self) -> None:
|
def process(self) -> None:
|
||||||
"""
|
"""
|
||||||
Queries the persistence layer for open trades and handles them,
|
Queries the persistence layer for open trades and handles them,
|
||||||
@ -235,11 +237,13 @@ class FreqtradeBot:
|
|||||||
logger.info(f"Updating {len(orders)} open orders.")
|
logger.info(f"Updating {len(orders)} open orders.")
|
||||||
for order in orders:
|
for order in orders:
|
||||||
try:
|
try:
|
||||||
if order.ft_order_side == 'stoposs':
|
if order.ft_order_side == 'stoploss':
|
||||||
fo = self.exchange.fetch_stoploss_order(order.order_id, order.ft_pair)
|
fo = self.exchange.fetch_stoploss_order(order.order_id, order.ft_pair)
|
||||||
else:
|
else:
|
||||||
fo = self.exchange.fetch_order(order.order_id, order.ft_pair)
|
fo = self.exchange.fetch_order(order.order_id, order.ft_pair)
|
||||||
order.update_from_ccxt_object(fo)
|
|
||||||
|
self.update_trade_state(order.trade, fo, sl_order=order.ft_order_side == 'stoploss')
|
||||||
|
|
||||||
except ExchangeError:
|
except ExchangeError:
|
||||||
logger.warning(f"Error updating {order.order_id}")
|
logger.warning(f"Error updating {order.order_id}")
|
||||||
|
|
||||||
|
@ -144,7 +144,6 @@ def check_migrate(engine, decl_base, previous_tables) -> None:
|
|||||||
logger.info('Moving open orders to Orders table.')
|
logger.info('Moving open orders to Orders table.')
|
||||||
migrate_open_orders_to_trades(engine)
|
migrate_open_orders_to_trades(engine)
|
||||||
else:
|
else:
|
||||||
logger.info(f'Running database migration for orders - backup: {table_back_name}')
|
|
||||||
pass
|
pass
|
||||||
# Empty for now - as there is only one iteration of the orders table so far.
|
# Empty for now - as there is only one iteration of the orders table so far.
|
||||||
# table_back_name = get_backup_name(tabs, 'orders_bak')
|
# table_back_name = get_backup_name(tabs, 'orders_bak')
|
||||||
|
@ -109,6 +109,8 @@ class Order(_DECL_BASE):
|
|||||||
id = Column(Integer, primary_key=True)
|
id = Column(Integer, primary_key=True)
|
||||||
ft_trade_id = Column(Integer, ForeignKey('trades.id'), index=True)
|
ft_trade_id = Column(Integer, ForeignKey('trades.id'), index=True)
|
||||||
|
|
||||||
|
trade = relationship("Trade", back_populates="orders")
|
||||||
|
|
||||||
ft_order_side = Column(String, nullable=False)
|
ft_order_side = Column(String, nullable=False)
|
||||||
ft_pair = Column(String, nullable=False)
|
ft_pair = Column(String, nullable=False)
|
||||||
ft_is_open = Column(Boolean, nullable=False, default=True, index=True)
|
ft_is_open = Column(Boolean, nullable=False, default=True, index=True)
|
||||||
@ -179,7 +181,7 @@ class Order(_DECL_BASE):
|
|||||||
return o
|
return o
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_open_orders():
|
def get_open_orders() -> List['Order']:
|
||||||
"""
|
"""
|
||||||
"""
|
"""
|
||||||
return Order.query.filter(Order.ft_is_open.is_(True)).all()
|
return Order.query.filter(Order.ft_is_open.is_(True)).all()
|
||||||
|
Loading…
Reference in New Issue
Block a user