Skip to content

Commit

Permalink
Rename GenericData to CustomData
Browse files Browse the repository at this point in the history
  • Loading branch information
cjdsellers committed Jan 8, 2024
1 parent 8df5e56 commit ec4ea37
Show file tree
Hide file tree
Showing 40 changed files with 95 additions and 92 deletions.
3 changes: 3 additions & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ Released on TBD (UTC).
- Changed `ComponentStateChanged` Arrow schema for `config` from `string` to `binary`
- Changed `OrderInitialized` Arrow schema for `options` from `string` to `binary`
- Changed `OrderBookDeltas` dictionary representation of `deltas` field from JSON `bytes` to a list of `dict` (standardize with all other data types)
- Renamed `GenericData` to `CustomData` (more accurately reflects the nature of the type)
- Renamed `DataClient.subscribed_generic_data` to `.subscribed_custom_data`
- Renamed `ParquetDataCatalog.generic_data` to `.custom_data`
- Renamed all version 2 data wrangler classes with a `V2` suffix for clarity
- Renamed `TradeReport` to `FillReport` (more conventional terminology, and more clearly separates market data from user execution reports)
- Renamed `AssetType` enum to `InstrumentClass` (more conventional terminology)
Expand Down
4 changes: 2 additions & 2 deletions docs/concepts/advanced/custom_data.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Custom/Generic Data
# Custom Data
Due to the modular nature of the Nautilus design, it is possible to set up systems
with very flexible data streams, including custom user defined data types. This
guide covers some possible use cases for this functionality.
Expand Down Expand Up @@ -92,7 +92,7 @@ self.subscribe_data(

This will result in your actor/strategy passing these received `MyDataPoint`
objects to your `on_data` method. You will need to check the type, as this
method acts as a flexible handler for all custom/generic data.
method acts as a flexible handler for all custom data.

```python
def on_data(self, data: Data) -> None:
Expand Down
2 changes: 1 addition & 1 deletion docs/concepts/advanced/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ highest to lowest level (although they are self-contained and can be read in any
Explore more advanced concepts of NautilusTrader through these guides:

- [Actors](actors.md)
- [Custom/Generic data](custom_data.md)
- [Custom Data](custom_data.md)
- [Advanced Orders](advanced_orders.md)
- [Emulated Orders](emulated_orders.md)
- [Synthetic Instruments](synthetic_instruments.md)
Expand Down
2 changes: 1 addition & 1 deletion docs/concepts/data.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ This inheritance ensures chronological data ordering (vital for backtesting), wh
Consistency is key; data flows through the platform in exactly the same way for all system environment contexts (`backtest`, `sandbox`, `live`)
primarily through the `MessageBus` to the `DataEngine` and onto subscribed or registered handlers.

For those seeking customization, the platform supports user-defined data types. Refer to the advanced [Custom/Generic data guide](advanced/custom_data.md) for more details.
For those seeking customization, the platform supports user-defined data types. Refer to the advanced [Custom data guide](advanced/custom_data.md) for more details.

## Loading data

Expand Down
2 changes: 1 addition & 1 deletion docs/concepts/strategies.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def on_instrument(self, instrument: Instrument) -> None:
def on_instrument_status(self, data: InstrumentStatus) -> None:
def on_instrument_close(self, data: InstrumentClose) -> None:
def on_historical_data(self, data: Data) -> None:
def on_data(self, data: Data) -> None: # Generic data passed to this handler
def on_data(self, data: Data) -> None: # Custom data passed to this handler
```

#### Order management
Expand Down
6 changes: 3 additions & 3 deletions nautilus_trader/adapters/betfair/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
from nautilus_trader.core.data import Data
from nautilus_trader.core.message import Event
from nautilus_trader.live.data_client import LiveMarketDataClient
from nautilus_trader.model.data import CustomData
from nautilus_trader.model.data import DataType
from nautilus_trader.model.data import GenericData
from nautilus_trader.model.enums import BookType
from nautilus_trader.model.identifiers import ClientId
from nautilus_trader.model.identifiers import InstrumentId
Expand Down Expand Up @@ -262,11 +262,11 @@ def _on_market_update(self, mcm: MCM) -> None:
self._log.debug(f"{data}")
if isinstance(data, BetfairStartingPrice | BSPOrderBookDelta):
# Not a regular data type
generic_data = GenericData(
custom_data = CustomData(
DataType(data.__class__, {"instrument_id": data.instrument_id}),
data,
)
self._handle_data(generic_data)
self._handle_data(custom_data)
elif isinstance(data, Data):
if self._strict_handling and (
hasattr(data, "instrument_id")
Expand Down
4 changes: 2 additions & 2 deletions nautilus_trader/adapters/binance/common/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@
from nautilus_trader.model.data import Bar
from nautilus_trader.model.data import BarSpecification
from nautilus_trader.model.data import BarType
from nautilus_trader.model.data import CustomData
from nautilus_trader.model.data import DataType
from nautilus_trader.model.data import GenericData
from nautilus_trader.model.data import OrderBookDelta
from nautilus_trader.model.data import OrderBookDeltas
from nautilus_trader.model.data import QuoteTick
Expand Down Expand Up @@ -956,7 +956,7 @@ def _handle_ticker(self, raw: bytes) -> None:
BinanceTicker,
metadata={"instrument_id": instrument_id},
)
custom = GenericData(data_type=data_type, data=ticker)
custom = CustomData(data_type=data_type, data=ticker)
self._handle_data(custom)

def _handle_kline(self, raw: bytes) -> None:
Expand Down
4 changes: 2 additions & 2 deletions nautilus_trader/adapters/binance/futures/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
from nautilus_trader.common.logging import Logger
from nautilus_trader.common.providers import InstrumentProvider
from nautilus_trader.core.correctness import PyCondition
from nautilus_trader.model.data import CustomData
from nautilus_trader.model.data import DataType
from nautilus_trader.model.data import GenericData
from nautilus_trader.model.data import OrderBookDelta
from nautilus_trader.model.data import OrderBookDeltas
from nautilus_trader.model.data import TradeTick
Expand Down Expand Up @@ -155,5 +155,5 @@ def _handle_mark_price(self, raw: bytes) -> None:
BinanceFuturesMarkPriceUpdate,
metadata={"instrument_id": instrument_id},
)
generic = GenericData(data_type=data_type, data=data)
generic = CustomData(data_type=data_type, data=data)
self._handle_data(generic)
4 changes: 2 additions & 2 deletions nautilus_trader/adapters/bybit/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
from nautilus_trader.live.data_client import LiveMarketDataClient
from nautilus_trader.model.data import Bar
from nautilus_trader.model.data import BarType
from nautilus_trader.model.data import CustomData
from nautilus_trader.model.data import DataType
from nautilus_trader.model.data import GenericData
from nautilus_trader.model.data import TradeTick
from nautilus_trader.model.enums import PriceType
from nautilus_trader.model.identifiers import ClientId
Expand Down Expand Up @@ -132,7 +132,7 @@ async def fetch_send_tickers(
data = DataResponse(
client_id=ClientId(BYBIT_VENUE.value),
venue=BYBIT_VENUE,
data_type=DataType(GenericData),
data_type=DataType(CustomData),
data=tickers,
correlation_id=id,
response_id=UUID4(),
Expand Down
8 changes: 4 additions & 4 deletions nautilus_trader/backtest/engine.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ from nautilus_trader.core.rust.model cimport OmsType
from nautilus_trader.core.uuid cimport UUID4
from nautilus_trader.execution.algorithm cimport ExecAlgorithm
from nautilus_trader.model.data cimport Bar
from nautilus_trader.model.data cimport GenericData
from nautilus_trader.model.data cimport CustomData
from nautilus_trader.model.data cimport InstrumentStatus
from nautilus_trader.model.data cimport OrderBookDelta
from nautilus_trader.model.data cimport OrderBookDeltas
Expand Down Expand Up @@ -557,14 +557,14 @@ cdef class BacktestEngine:
bint sort = True,
) -> None:
"""
Add the given data to the backtest engine.
Add the given custom data to the backtest engine.

Parameters
----------
data : list[Data]
The data to add.
client_id : ClientId, optional
The data client ID to associate with generic data.
The data client ID to associate with custom data.
validate : bool, default True
If `data` should be validated
(recommended when adding data directly to the engine).
Expand Down Expand Up @@ -634,7 +634,7 @@ cdef class BacktestEngine:
Condition.not_none(client_id, "client_id")
# Check client has been registered
self._add_data_client_if_not_exists(client_id)
if isinstance(first, GenericData):
if isinstance(first, CustomData):
data_added_str = f"{type(first.data).__name__} "

# Add data
Expand Down
2 changes: 1 addition & 1 deletion nautilus_trader/common/actor.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ cdef class Actor(Component):

cpdef void on_data(self, Data data):
"""
Actions to be performed when running and receives generic data.
Actions to be performed when running and receives data.
Parameters
----------
Expand Down
2 changes: 1 addition & 1 deletion nautilus_trader/data/client.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ cdef class DataClient(Component):

# -- SUBSCRIPTIONS --------------------------------------------------------------------------------

cpdef list subscribed_generic_data(self)
cpdef list subscribed_custom_data(self)

cpdef void subscribe(self, DataType data_type)
cpdef void unsubscribe(self, DataType data_type)
Expand Down
8 changes: 4 additions & 4 deletions nautilus_trader/data/client.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ cdef class DataClient(Component):

# -- SUBSCRIPTIONS --------------------------------------------------------------------------------

cpdef list subscribed_generic_data(self):
cpdef list subscribed_custom_data(self):
"""
Return the generic data types subscribed to.
Return the custom data types subscribed to.
Returns
-------
Expand Down Expand Up @@ -262,9 +262,9 @@ cdef class MarketDataClient(DataClient):

# -- SUBSCRIPTIONS --------------------------------------------------------------------------------

cpdef list subscribed_generic_data(self):
cpdef list subscribed_custom_data(self):
"""
Return the generic data types subscribed to.
Return the custom data types subscribed to.
Returns
-------
Expand Down
6 changes: 3 additions & 3 deletions nautilus_trader/data/engine.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ from nautilus_trader.data.messages cimport Subscribe
from nautilus_trader.data.messages cimport Unsubscribe
from nautilus_trader.model.data cimport Bar
from nautilus_trader.model.data cimport BarType
from nautilus_trader.model.data cimport CustomData
from nautilus_trader.model.data cimport DataType
from nautilus_trader.model.data cimport GenericData
from nautilus_trader.model.data cimport InstrumentClose
from nautilus_trader.model.data cimport InstrumentStatus
from nautilus_trader.model.data cimport OrderBookDelta
Expand Down Expand Up @@ -90,7 +90,7 @@ cdef class DataEngine(Component):

# -- SUBSCRIPTIONS --------------------------------------------------------------------------------

cpdef list subscribed_generic_data(self)
cpdef list subscribed_custom_data(self)
cpdef list subscribed_instruments(self)
cpdef list subscribed_order_book_deltas(self)
cpdef list subscribed_order_book_snapshots(self)
Expand Down Expand Up @@ -147,7 +147,7 @@ cdef class DataEngine(Component):
cpdef void _handle_quote_tick(self, QuoteTick tick)
cpdef void _handle_trade_tick(self, TradeTick tick)
cpdef void _handle_bar(self, Bar bar)
cpdef void _handle_generic_data(self, GenericData data)
cpdef void _handle_custom_data(self, CustomData data)
cpdef void _handle_venue_status(self, VenueStatus data)
cpdef void _handle_instrument_status(self, InstrumentStatus data)
cpdef void _handle_close_price(self, InstrumentClose data)
Expand Down
16 changes: 8 additions & 8 deletions nautilus_trader/data/engine.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,9 @@ cdef class DataEngine(Component):

# -- SUBSCRIPTIONS --------------------------------------------------------------------------------

cpdef list subscribed_generic_data(self):
cpdef list subscribed_custom_data(self):
"""
Return the generic data types subscribed to.
Return the custom data types subscribed to.
Returns
-------
Expand All @@ -351,7 +351,7 @@ cdef class DataEngine(Component):
cdef list subscriptions = []
cdef DataClient client
for client in self._clients.values():
subscriptions += client.subscribed_generic_data()
subscriptions += client.subscribed_custom_data()
return subscriptions

cpdef list subscribed_instruments(self):
Expand Down Expand Up @@ -995,7 +995,7 @@ cdef class DataEngine(Component):
Condition.not_none(data_type, "data_type")

try:
if data_type not in client.subscribed_generic_data():
if data_type not in client.subscribed_custom_data():
client.subscribe(data_type)
except NotImplementedError:
self._log.error(
Expand Down Expand Up @@ -1310,7 +1310,7 @@ cdef class DataEngine(Component):
end=ts_end,
)
else:
data = self._catalog.generic_data(
data = self._catalog.custom_data(
cls=request.data_type.type,
metadata=request.data_type.metadata,
start=ts_start,
Expand Down Expand Up @@ -1360,8 +1360,8 @@ cdef class DataEngine(Component):
self._handle_instrument_status(data)
elif isinstance(data, InstrumentClose):
self._handle_close_price(data)
elif isinstance(data, GenericData):
self._handle_generic_data(data)
elif isinstance(data, CustomData):
self._handle_custom_data(data)
else:
self._log.error(f"Cannot handle data: unrecognized type {type(data)} {data}.")

Expand Down Expand Up @@ -1480,7 +1480,7 @@ cdef class DataEngine(Component):
cpdef void _handle_close_price(self, InstrumentClose data):
self._msgbus.publish_c(topic=f"data.venue.close_price.{data.instrument_id}", msg=data)

cpdef void _handle_generic_data(self, GenericData data):
cpdef void _handle_custom_data(self, CustomData data):
self._msgbus.publish_c(topic=f"data.{data.data_type.topic}", msg=data.data)

# -- RESPONSE HANDLERS ----------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion nautilus_trader/examples/strategies/blank.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def sell(self) -> None:

def on_data(self, data: Data) -> None:
"""
Actions to be performed when the strategy is running and receives generic data.
Actions to be performed when the strategy is running and receives data.
Parameters
----------
Expand Down
2 changes: 1 addition & 1 deletion nautilus_trader/examples/strategies/ema_cross.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ def sell(self) -> None:

def on_data(self, data: Data) -> None:
"""
Actions to be performed when the strategy is running and receives generic data.
Actions to be performed when the strategy is running and receives data.
Parameters
----------
Expand Down
2 changes: 1 addition & 1 deletion nautilus_trader/examples/strategies/ema_cross_bracket.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def sell(self, last_bar: Bar) -> None:

def on_data(self, data: Data) -> None:
"""
Actions to be performed when the strategy is running and receives generic data.
Actions to be performed when the strategy is running and receives data.
Parameters
----------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ def sell(self, last_bar: Bar) -> None:

def on_data(self, data: Data) -> None:
"""
Actions to be performed when the strategy is running and receives generic data.
Actions to be performed when the strategy is running and receives data.
Parameters
----------
Expand Down
2 changes: 1 addition & 1 deletion nautilus_trader/examples/strategies/ema_cross_cython.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ cdef class EMACross(Strategy):

cpdef void on_data(self, Data data):
"""
Actions to be performed when the strategy is running and receives generic data.
Actions to be performed when the strategy is running and receives data.
Parameters
----------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ def trailing_stop_sell(self) -> None:

def on_data(self, data: Data) -> None:
"""
Actions to be performed when the strategy is running and receives generic data.
Actions to be performed when the strategy is running and receives data.
Parameters
----------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ def trailing_stop_sell(self) -> None:

def on_data(self, data: Data) -> None:
"""
Actions to be performed when the strategy is running and receives generic data.
Actions to be performed when the strategy is running and receives data.
Parameters
----------
Expand Down
2 changes: 1 addition & 1 deletion nautilus_trader/examples/strategies/ema_cross_twap.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def sell(self) -> None:

def on_data(self, data: Data) -> None:
"""
Actions to be performed when the strategy is running and receives generic data.
Actions to be performed when the strategy is running and receives data.
Parameters
----------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def on_start(self) -> None:

def on_data(self, data: Data) -> None:
"""
Actions to be performed when the strategy is running and receives generic data.
Actions to be performed when the strategy is running and receives data.
Parameters
----------
Expand Down
2 changes: 1 addition & 1 deletion nautilus_trader/model/data.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ cdef class DataType:
"""The data types topic string.\n\n:returns: `str`"""


cdef class GenericData(Data):
cdef class CustomData(Data):
cdef readonly DataType data_type
"""The data type.\n\n:returns: `DataType`"""
cdef readonly Data data
Expand Down
4 changes: 2 additions & 2 deletions nautilus_trader/model/data.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1161,9 +1161,9 @@ cdef class DataType:
return f"{type(self).__name__}(type={self.type.__name__}, metadata={self.metadata})"


cdef class GenericData(Data):
cdef class CustomData(Data):
"""
Provides a generic data wrapper which includes data type information.
Provides a wrapper for custom data which includes data type information.
Parameters
----------
Expand Down
Loading

0 comments on commit ec4ea37

Please sign in to comment.