Skip to content

Commit

Permalink
Fix InstrumentProvider initialization behavior
Browse files Browse the repository at this point in the history
Allow reload when `reload` flag is `True`.
  • Loading branch information
cjdsellers committed Jan 19, 2025
1 parent f74d23c commit d21b1cb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
1 change: 1 addition & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ This release will be the final version that uses Poetry for package and dependen
- Fixed `CustomData` import in `DataEngine` (#2207), thanks @graceyangfan and @faysou
- Fixed databento helper function (#2208), thanks @faysou
- Fixed live reconciliation of generated order fills to use the `venue_position_id` (when provided)
- Fixed `InstrumentProvider` initialization behavior when `reload` flag `True`, thanks @ryantam626

### Documentation Updates
None
Expand Down
31 changes: 16 additions & 15 deletions nautilus_trader/common/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,25 +160,26 @@ async def initialize(self, reload: bool = False) -> None:
while self._loading:
await asyncio.sleep(0.1)

if not self._loaded:
self._log.info("Initializing instruments")
if not reload and self._loaded:
return # Already loaded

# Set state flag
self._loading = True
# Set state flag
self._loading = True
self._log.info("Initializing instruments")

if self._load_all_on_start:
await self.load_all_async(self._filters)
elif self._load_ids_on_start:
instrument_ids = [
i if isinstance(i, InstrumentId) else InstrumentId.from_str(i)
for i in self._load_ids_on_start
]
if self._load_all_on_start:
await self.load_all_async(self._filters)
elif self._load_ids_on_start:
instrument_ids = [
i if isinstance(i, InstrumentId) else InstrumentId.from_str(i)
for i in self._load_ids_on_start
]

instruments_str = ", ".join([i.value for i in instrument_ids])
filters_str = "..." if not self._filters else f" with filters {self._filters}..."
self._log.info(f"Loading instruments: {instruments_str}{filters_str}")
instruments_str = ", ".join([i.value for i in instrument_ids])
filters_str = "..." if not self._filters else f" with filters {self._filters}..."
self._log.info(f"Loading instruments: {instruments_str}{filters_str}")

await self.load_ids_async(instrument_ids, self._filters)
await self.load_ids_async(instrument_ids, self._filters)

if self._instruments:
self._log.info(f"Loaded {self.count} instruments")
Expand Down

0 comments on commit d21b1cb

Please sign in to comment.