Skip to content

Commit

Permalink
Remove redundant venue from InstrumentProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
cjdsellers committed Oct 30, 2023
1 parent fd701b2 commit 01304f5
Show file tree
Hide file tree
Showing 13 changed files with 10 additions and 48 deletions.
1 change: 1 addition & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion nautilus_trader/adapters/betfair/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
5 changes: 2 additions & 3 deletions nautilus_trader/adapters/binance/futures/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ def __init__(
config: InstrumentProviderConfig | None = None,
):
super().__init__(
venue=BINANCE_VENUE,
logger=logger,
config=config,
)
Expand Down Expand Up @@ -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}.")
Expand Down Expand Up @@ -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}.")
Expand Down
5 changes: 2 additions & 3 deletions nautilus_trader/adapters/binance/spot/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ def __init__(
config: InstrumentProviderConfig | None = None,
):
super().__init__(
venue=BINANCE_VENUE,
logger=logger,
config=config,
)
Expand Down Expand Up @@ -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}.")
Expand Down Expand Up @@ -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}.")
Expand Down
2 changes: 0 additions & 2 deletions nautilus_trader/adapters/interactive_brokers/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -61,7 +60,6 @@ def __init__(
"""
super().__init__(
venue=IB_VENUE,
logger=logger,
config=config,
)
Expand Down
2 changes: 1 addition & 1 deletion nautilus_trader/adapters/sandbox/execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
18 changes: 0 additions & 18 deletions nautilus_trader/common/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -31,8 +30,6 @@ class InstrumentProvider:
Parameters
----------
venue : Venue
The venue for the provider.
logger : Logger
The logger for the provider.
config :InstrumentProviderConfig, optional
Expand All @@ -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] = {}

Expand All @@ -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:
"""
Expand Down
4 changes: 1 addition & 3 deletions nautilus_trader/test_kit/mocks/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -28,7 +27,6 @@
def instrument_provider():
clock = TestClock()
return TemplateInstrumentProvider(
venue=TEMPLATE_VENUE,
logger=Logger(clock),
)

Expand Down
3 changes: 0 additions & 3 deletions tests/unit_tests/common/test_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()


Expand All @@ -29,7 +27,6 @@ def setup(self):
# Fixture Setup
clock = TestClock()
self.provider = InstrumentProvider(
venue=BITMEX,
logger=Logger(clock, bypass=True),
)

Expand Down
5 changes: 1 addition & 4 deletions tests/unit_tests/live/test_data_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 1 addition & 4 deletions tests/unit_tests/live/test_execution_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 1 addition & 4 deletions tests/unit_tests/live/test_execution_recon.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 01304f5

Please sign in to comment.