From cf3be5f6689d91db9cb2f9310e32353946d2387f Mon Sep 17 00:00:00 2001 From: Hieu Nguyen Date: Tue, 30 Apr 2024 12:25:52 +0300 Subject: [PATCH 1/2] Fix for retry command --- tradeexecutor/state/retry.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/tradeexecutor/state/retry.py b/tradeexecutor/state/retry.py index f44432dbe..fb05218ca 100644 --- a/tradeexecutor/state/retry.py +++ b/tradeexecutor/state/retry.py @@ -2,16 +2,29 @@ """ import datetime import logging +from itertools import chain from tradeexecutor.state.state import State from tradeexecutor.state.trade import TradeExecution, TradeType, TradeStatus from tradeexecutor.strategy.execution_model import ExecutionModel from tradeexecutor.strategy.routing import RoutingModel, RoutingState -from .repair import find_trades_to_be_repaired, RepairAborted, RepairResult, unfreeze_position +from .repair import RepairAborted, RepairResult, unfreeze_position logger = logging.getLogger(__name__) +def find_trades_to_be_retried(state: State) -> list[TradeExecution]: + trades_to_be_repaired = [] + # Closed trades do not need attention + for p in chain(state.portfolio.open_positions.values(), state.portfolio.frozen_positions.values()): + t: TradeExecution + for t in p.trades.values(): + if t.is_repair_needed(): + logger.info("Found a trade needing repair: %s", t) + trades_to_be_repaired.append(t) + + return trades_to_be_repaired + def rebroadcast_trade( t: TradeExecution, @@ -75,7 +88,7 @@ def retry_trades( logger.info("Strategy has %d frozen positions", len(frozen_positions)) - trades_to_be_retried = find_trades_to_be_repaired(state) + trades_to_be_retried = find_trades_to_be_retried(state) logger.info("Found %d trades to be retried", len(trades_to_be_retried)) From 372e3e55ca2ae2bdfd4468640000e679b8cf0ea9 Mon Sep 17 00:00:00 2001 From: Hieu Nguyen Date: Tue, 30 Apr 2024 15:03:33 +0300 Subject: [PATCH 2/2] Temp disable refresh --- tradeexecutor/cli/commands/console.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tradeexecutor/cli/commands/console.py b/tradeexecutor/cli/commands/console.py index 97148ba3a..5bbd75349 100644 --- a/tradeexecutor/cli/commands/console.py +++ b/tradeexecutor/cli/commands/console.py @@ -256,15 +256,15 @@ def console( else: backtested_state = None - refresh_run_state( - run_state, - state, - execution_context, - visualisation=True, - universe=universe, - sync_model=sync_model, - backtested_state=backtested_state, - ) + # refresh_run_state( + # run_state, + # state, + # execution_context, + # visualisation=True, + # universe=universe, + # sync_model=sync_model, + # backtested_state=backtested_state, + # ) # Set up the default objects # availalbe in the interactive session