From 01304f5966f2de36267068391c1a7c2145ac7d41 Mon Sep 17 00:00:00 2001 From: Chris Sellers Date: Mon, 30 Oct 2023 18:45:19 +1100 Subject: [PATCH] Remove redundant venue from InstrumentProvider --- RELEASES.md | 1 + nautilus_trader/adapters/betfair/providers.py | 1 - .../adapters/binance/futures/providers.py | 5 ++--- .../adapters/binance/spot/providers.py | 5 ++--- .../adapters/interactive_brokers/providers.py | 2 -- nautilus_trader/adapters/sandbox/execution.py | 2 +- nautilus_trader/common/providers.py | 18 ------------------ nautilus_trader/test_kit/mocks/data.py | 4 +--- .../_template/test_template_providers.py | 2 -- tests/unit_tests/common/test_providers.py | 3 --- tests/unit_tests/live/test_data_client.py | 5 +---- tests/unit_tests/live/test_execution_engine.py | 5 +---- tests/unit_tests/live/test_execution_recon.py | 5 +---- 13 files changed, 10 insertions(+), 48 deletions(-) diff --git a/RELEASES.md b/RELEASES.md index 567fb17eddb6..0f1ed74967dc 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -10,6 +10,7 @@ Released on TBC (UTC). ### Breaking Changes - Transformed orders will now retain the original `ts_init` timestamp - Removed unimplemented `batch_more` option for `Strategy.modify_order` +- Removed `InstrumentProvider.venue` property (redundant as a provider may have many venues) - Dropped support for Python 3.9 ### Fixes diff --git a/nautilus_trader/adapters/betfair/providers.py b/nautilus_trader/adapters/betfair/providers.py index 76343a443486..6f718ab22fb0 100644 --- a/nautilus_trader/adapters/betfair/providers.py +++ b/nautilus_trader/adapters/betfair/providers.py @@ -72,7 +72,6 @@ def __init__( ): assert config is not None, "Must pass config to BetfairInstrumentProvider" super().__init__( - venue=BETFAIR_VENUE, logger=logger, config=config, ) diff --git a/nautilus_trader/adapters/binance/futures/providers.py b/nautilus_trader/adapters/binance/futures/providers.py index 4b572ec5b296..3aa499fe5eac 100644 --- a/nautilus_trader/adapters/binance/futures/providers.py +++ b/nautilus_trader/adapters/binance/futures/providers.py @@ -76,7 +76,6 @@ def __init__( config: InstrumentProviderConfig | None = None, ): super().__init__( - venue=BINANCE_VENUE, logger=logger, config=config, ) @@ -153,7 +152,7 @@ async def load_ids_async( # Check all instrument IDs for instrument_id in instrument_ids: - PyCondition.equal(instrument_id.venue, self.venue, "instrument_id.venue", "self.venue") + PyCondition.equal(instrument_id.venue, BINANCE_VENUE, "instrument_id.venue", "BINANCE") filters_str = "..." if not filters else f" with filters {filters}..." self._log.info(f"Loading instruments {instrument_ids}{filters_str}.") @@ -192,7 +191,7 @@ async def load_ids_async( async def load_async(self, instrument_id: InstrumentId, filters: dict | None = None) -> None: PyCondition.not_none(instrument_id, "instrument_id") - PyCondition.equal(instrument_id.venue, self.venue, "instrument_id.venue", "self.venue") + PyCondition.equal(instrument_id.venue, BINANCE_VENUE, "instrument_id.venue", "BINANCE") filters_str = "..." if not filters else f" with filters {filters}..." self._log.debug(f"Loading instrument {instrument_id}{filters_str}.") diff --git a/nautilus_trader/adapters/binance/spot/providers.py b/nautilus_trader/adapters/binance/spot/providers.py index 1d753423eea0..ec4639bfe1e6 100644 --- a/nautilus_trader/adapters/binance/spot/providers.py +++ b/nautilus_trader/adapters/binance/spot/providers.py @@ -77,7 +77,6 @@ def __init__( config: InstrumentProviderConfig | None = None, ): super().__init__( - venue=BINANCE_VENUE, logger=logger, config=config, ) @@ -141,7 +140,7 @@ async def load_ids_async( # Check all instrument IDs for instrument_id in instrument_ids: - PyCondition.equal(instrument_id.venue, self.venue, "instrument_id.venue", "self.venue") + PyCondition.equal(instrument_id.venue, BINANCE_VENUE, "instrument_id.venue", "BINANCE") filters_str = "..." if not filters else f" with filters {filters}..." self._log.info(f"Loading instruments {instrument_ids}{filters_str}.") @@ -183,7 +182,7 @@ async def load_ids_async( async def load_async(self, instrument_id: InstrumentId, filters: dict | None = None) -> None: PyCondition.not_none(instrument_id, "instrument_id") - PyCondition.equal(instrument_id.venue, self.venue, "instrument_id.venue", "self.venue") + PyCondition.equal(instrument_id.venue, BINANCE_VENUE, "instrument_id.venue", "BINANCE") filters_str = "..." if not filters else f" with filters {filters}..." self._log.debug(f"Loading instrument {instrument_id}{filters_str}.") diff --git a/nautilus_trader/adapters/interactive_brokers/providers.py b/nautilus_trader/adapters/interactive_brokers/providers.py index f60b6a8c4cc4..3c684db0e2cb 100644 --- a/nautilus_trader/adapters/interactive_brokers/providers.py +++ b/nautilus_trader/adapters/interactive_brokers/providers.py @@ -20,7 +20,6 @@ # fmt: off from nautilus_trader.adapters.interactive_brokers.client import InteractiveBrokersClient -from nautilus_trader.adapters.interactive_brokers.common import IB_VENUE from nautilus_trader.adapters.interactive_brokers.common import IBContract from nautilus_trader.adapters.interactive_brokers.common import IBContractDetails from nautilus_trader.adapters.interactive_brokers.config import InteractiveBrokersInstrumentProviderConfig @@ -61,7 +60,6 @@ def __init__( """ super().__init__( - venue=IB_VENUE, logger=logger, config=config, ) diff --git a/nautilus_trader/adapters/sandbox/execution.py b/nautilus_trader/adapters/sandbox/execution.py index 8c539b1a7bfd..3b5a486bf8b9 100644 --- a/nautilus_trader/adapters/sandbox/execution.py +++ b/nautilus_trader/adapters/sandbox/execution.py @@ -99,7 +99,7 @@ def __init__( oms_type=oms_type, account_type=account_type, base_currency=self._currency, - instrument_provider=InstrumentProvider(venue=sandbox_venue, logger=logger), + instrument_provider=InstrumentProvider(logger=logger), msgbus=msgbus, cache=cache, clock=clock, diff --git a/nautilus_trader/common/providers.py b/nautilus_trader/common/providers.py index cee93dad81ad..254083a1a773 100644 --- a/nautilus_trader/common/providers.py +++ b/nautilus_trader/common/providers.py @@ -21,7 +21,6 @@ from nautilus_trader.core.correctness import PyCondition from nautilus_trader.model.currency import Currency from nautilus_trader.model.identifiers import InstrumentId -from nautilus_trader.model.identifiers import Venue from nautilus_trader.model.instruments import Instrument @@ -31,8 +30,6 @@ class InstrumentProvider: Parameters ---------- - venue : Venue - The venue for the provider. logger : Logger The logger for the provider. config :InstrumentProviderConfig, optional @@ -46,18 +43,15 @@ class InstrumentProvider: def __init__( self, - venue: Venue, logger: Logger, config: InstrumentProviderConfig | None = None, ) -> None: - PyCondition.not_none(venue, "venue") PyCondition.not_none(logger, "logger") if config is None: config = InstrumentProviderConfig() self._log = LoggerAdapter(type(self).__name__, logger) - self._venue = venue self._instruments: dict[InstrumentId, Instrument] = {} self._currencies: dict[str, Currency] = {} @@ -70,18 +64,6 @@ def __init__( self._loaded = False self._loading = False - @property - def venue(self) -> Venue: - """ - Return the providers venue. - - Returns - ------- - Venue - - """ - return self._venue - @property def count(self) -> int: """ diff --git a/nautilus_trader/test_kit/mocks/data.py b/nautilus_trader/test_kit/mocks/data.py index 7c1379accf1e..bcbf7919609b 100644 --- a/nautilus_trader/test_kit/mocks/data.py +++ b/nautilus_trader/test_kit/mocks/data.py @@ -65,14 +65,12 @@ def data_catalog_setup( def aud_usd_data_loader(catalog: ParquetDataCatalog) -> None: from nautilus_trader.test_kit.providers import TestInstrumentProvider - venue = Venue("SIM") - instrument = TestInstrumentProvider.default_fx_ccy("AUD/USD", venue=venue) + instrument = TestInstrumentProvider.default_fx_ccy("AUD/USD", venue=Venue("SIM")) clock = TestClock() logger = Logger(clock) instrument_provider = InstrumentProvider( - venue=venue, logger=logger, ) instrument_provider.add(instrument) diff --git a/tests/integration_tests/adapters/_template/test_template_providers.py b/tests/integration_tests/adapters/_template/test_template_providers.py index 2dad50882d85..d5ea86383614 100644 --- a/tests/integration_tests/adapters/_template/test_template_providers.py +++ b/tests/integration_tests/adapters/_template/test_template_providers.py @@ -15,7 +15,6 @@ import pytest -from nautilus_trader.adapters._template.core import TEMPLATE_VENUE from nautilus_trader.adapters._template.providers import TemplateInstrumentProvider from nautilus_trader.common.clock import TestClock from nautilus_trader.common.logging import Logger @@ -28,7 +27,6 @@ def instrument_provider(): clock = TestClock() return TemplateInstrumentProvider( - venue=TEMPLATE_VENUE, logger=Logger(clock), ) diff --git a/tests/unit_tests/common/test_providers.py b/tests/unit_tests/common/test_providers.py index ade4cfbfbe9e..011c87bb602b 100644 --- a/tests/unit_tests/common/test_providers.py +++ b/tests/unit_tests/common/test_providers.py @@ -16,11 +16,9 @@ from nautilus_trader.common.clock import TestClock from nautilus_trader.common.logging import Logger from nautilus_trader.common.providers import InstrumentProvider -from nautilus_trader.model.identifiers import Venue from nautilus_trader.test_kit.stubs.identifiers import TestIdStubs -BITMEX = Venue("BITMEX") AUDUSD = TestIdStubs.audusd_id() @@ -29,7 +27,6 @@ def setup(self): # Fixture Setup clock = TestClock() self.provider = InstrumentProvider( - venue=BITMEX, logger=Logger(clock, bypass=True), ) diff --git a/tests/unit_tests/live/test_data_client.py b/tests/unit_tests/live/test_data_client.py index 226630db16a9..a0bf2ada9802 100644 --- a/tests/unit_tests/live/test_data_client.py +++ b/tests/unit_tests/live/test_data_client.py @@ -120,10 +120,7 @@ def setup(self): loop=self.loop, client_id=ClientId(BINANCE.value), venue=BINANCE, - instrument_provider=InstrumentProvider( - venue=Venue("SIM"), - logger=self.logger, - ), + instrument_provider=InstrumentProvider(logger=self.logger), msgbus=self.msgbus, cache=self.cache, clock=self.clock, diff --git a/tests/unit_tests/live/test_execution_engine.py b/tests/unit_tests/live/test_execution_engine.py index 415623680f56..b8cf4dc80a4a 100644 --- a/tests/unit_tests/live/test_execution_engine.py +++ b/tests/unit_tests/live/test_execution_engine.py @@ -151,10 +151,7 @@ def setup(self): logger=self.logger, ) - self.instrument_provider = InstrumentProvider( - venue=SIM, - logger=self.logger, - ) + self.instrument_provider = InstrumentProvider(logger=self.logger) self.instrument_provider.add(AUDUSD_SIM) self.instrument_provider.add(GBPUSD_SIM) self.cache.add_instrument(AUDUSD_SIM) diff --git a/tests/unit_tests/live/test_execution_recon.py b/tests/unit_tests/live/test_execution_recon.py index ba2a579ce859..84324de21ebc 100644 --- a/tests/unit_tests/live/test_execution_recon.py +++ b/tests/unit_tests/live/test_execution_recon.py @@ -127,10 +127,7 @@ def setup(self): venue=SIM, account_type=AccountType.CASH, base_currency=USD, - instrument_provider=InstrumentProvider( - venue=SIM, - logger=self.logger, - ), + instrument_provider=InstrumentProvider(logger=self.logger), msgbus=self.msgbus, cache=self.cache, clock=self.clock,