1111from ..types import Direction
1212from .journal import JournalEntry , PositionJournal
1313from .runner import PortfolioRunner
14- from .types import Instrument , ReconcilableStrategy
14+ from .types import ReconcilableStrategy
1515
1616log = logging .getLogger (__name__ )
1717
@@ -324,7 +324,7 @@ async def reconcile_on_startup(self) -> set[str]:
324324 restored_instruments = self ._restore_from_journal (journal_positions )
325325 return restored_instruments
326326
327- managed_instruments = {str (inst ) for inst in self ._runner .strategies .keys ()}
327+ managed_instruments = {str (s . instrument ) for s in self ._runner .strategies .values ()}
328328
329329 result = reconcile (
330330 journal_positions = journal_positions ,
@@ -398,9 +398,9 @@ async def reconcile_on_startup(self) -> set[str]:
398398 def _restore_from_journal (self , journal_positions : dict [str , JournalEntry ]) -> set [str ]:
399399 """Restore positions from journal only (broker unreachable)."""
400400 restored : set [str ] = set ()
401- for inst , s in self ._runner .strategies .items ():
401+ for s in self ._runner .strategies .values ():
402402 strat = cast (ReconcilableStrategy , s )
403- epic = str (inst )
403+ epic = str (s . instrument )
404404 entry = journal_positions .get (epic )
405405 if entry is None or entry .direction is None :
406406 continue
@@ -428,9 +428,9 @@ def _apply_reconciliation(
428428 broker_by_instrument = {bp .instrument : bp for bp in broker_positions }
429429 restored : set [str ] = set ()
430430
431- for inst , s in self ._runner .strategies .items ():
431+ for s in self ._runner .strategies .values ():
432432 strat = cast (ReconcilableStrategy , s )
433- epic = str (inst )
433+ epic = str (s . instrument )
434434 entry = next ((e for e in result .entries if e .instrument == epic ), None )
435435 if entry is None :
436436 continue
@@ -511,9 +511,9 @@ async def post_warmup_check(self, restored_instruments: set[str]) -> None:
511511 or adopted might be stale (e.g. stop-loss breached, regime deactivated).
512512 This method checks each one and exits immediately if warranted.
513513 """
514- for inst , s in self ._runner .strategies .items ():
514+ for s in self ._runner .strategies .values ():
515515 strat = cast (ReconcilableStrategy , s )
516- epic = str (inst )
516+ epic = str (s . instrument )
517517 if epic not in restored_instruments :
518518 continue
519519 if strat .position .is_flat ():
@@ -558,9 +558,9 @@ def persist_positions(self, changed_epic: str = "") -> None:
558558 return
559559
560560 entries = []
561- for inst , s in self ._runner .strategies .items ():
561+ for s in self ._runner .strategies .values ():
562562 strat = cast (ReconcilableStrategy , s )
563- entries .append (strat .to_journal_entry (str (inst )))
563+ entries .append (strat .to_journal_entry (str (s . instrument )))
564564
565565 self ._journal .save (entries )
566566
@@ -578,12 +578,12 @@ async def periodic_reconcile(self) -> None:
578578
579579 # Build current local state
580580 journal_positions : dict [str , JournalEntry ] = {}
581- for inst , s in self ._runner .strategies .items ():
581+ for s in self ._runner .strategies .values ():
582582 strat = cast (ReconcilableStrategy , s )
583- epic = str (inst )
583+ epic = str (s . instrument )
584584 journal_positions [epic ] = strat .to_journal_entry (epic )
585585
586- managed_instruments = {str (inst ) for inst in self ._runner .strategies .keys ()}
586+ managed_instruments = {str (s . instrument ) for s in self ._runner .strategies .values ()}
587587
588588 # Exclude instruments with recent position changes to avoid settlement race
589589 skipped = self ._recently_changed_instruments .copy ()
@@ -613,7 +613,11 @@ async def periodic_reconcile(self) -> None:
613613 if entry .discrepancy == DiscrepancyType .MATCHED :
614614 continue
615615
616- maybe_strat = self ._runner .strategies .get (Instrument (entry .instrument ))
616+ maybe_strat = next (
617+ (s for s in self ._runner .strategies .values ()
618+ if str (s .instrument ) == entry .instrument ),
619+ None ,
620+ )
617621 if maybe_strat is None :
618622 continue
619623 strat = cast (ReconcilableStrategy , maybe_strat )
0 commit comments