Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix retry command #914

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions tradeexecutor/cli/commands/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 15 additions & 2 deletions tradeexecutor/state/retry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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))

Expand Down
Loading