Skip to content

Commit

Permalink
1.104.0
Browse files Browse the repository at this point in the history
  • Loading branch information
cjdsellers authored Feb 19, 2021
2 parents a25dfe0 + 2f5b7b2 commit ea441c3
Show file tree
Hide file tree
Showing 35 changed files with 851 additions and 557 deletions.
1 change: 1 addition & 0 deletions examples/backtest/fx_market_maker_gbpusd_bars.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# limitations under the License.
# -------------------------------------------------------------------------------------------------

from datetime import datetime
from decimal import Decimal
import os
import pathlib
Expand Down
4 changes: 2 additions & 2 deletions nautilus_trader/adapters/ccxt/data.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
# -------------------------------------------------------------------------------------------------

from nautilus_trader.adapters.ccxt.providers cimport CCXTInstrumentProvider
from nautilus_trader.live.data_client cimport LiveDataClient
from nautilus_trader.live.data_client cimport LiveMarketDataClient
from nautilus_trader.model.bar cimport Bar
from nautilus_trader.model.bar cimport BarSpecification
from nautilus_trader.model.bar cimport BarType
from nautilus_trader.model.identifiers cimport Symbol
from nautilus_trader.model.tick cimport TradeTick


cdef class CCXTDataClient(LiveDataClient):
cdef class CCXTDataClient(LiveMarketDataClient):
cdef object _client
cdef CCXTInstrumentProvider _instrument_provider

Expand Down
7 changes: 3 additions & 4 deletions nautilus_trader/adapters/ccxt/data.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ from nautilus_trader.core.correctness cimport Condition
from nautilus_trader.core.datetime cimport from_unix_time_ms
from nautilus_trader.core.datetime cimport to_unix_time_ms
from nautilus_trader.core.uuid cimport UUID
from nautilus_trader.live.data_client cimport LiveDataClient
from nautilus_trader.live.data_client cimport LiveMarketDataClient
from nautilus_trader.live.data_engine cimport LiveDataEngine
from nautilus_trader.model.bar cimport Bar
from nautilus_trader.model.bar cimport BarSpecification
Expand All @@ -40,7 +40,6 @@ from nautilus_trader.model.c_enums.price_type cimport PriceType
from nautilus_trader.model.c_enums.price_type cimport PriceTypeParser
from nautilus_trader.model.identifiers cimport Symbol
from nautilus_trader.model.identifiers cimport TradeMatchId
from nautilus_trader.model.identifiers cimport Venue
from nautilus_trader.model.instrument cimport Instrument
from nautilus_trader.model.objects cimport Price
from nautilus_trader.model.objects cimport Quantity
Expand All @@ -52,7 +51,7 @@ from nautilus_trader.model.tick cimport TradeTick
cdef int _SECONDS_IN_HOUR = 60 * 60


cdef class CCXTDataClient(LiveDataClient):
cdef class CCXTDataClient(LiveMarketDataClient):
"""
Provides a data client for the unified CCXT Pro API.
"""
Expand Down Expand Up @@ -85,7 +84,7 @@ cdef class CCXTDataClient(LiveDataClient):
"""
super().__init__(
Venue(client.name.upper()),
client.name.upper(),
engine,
clock,
logger,
Expand Down
4 changes: 2 additions & 2 deletions nautilus_trader/adapters/oanda/data.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import threading

from nautilus_trader.adapters.oanda.providers cimport OandaInstrumentProvider
from nautilus_trader.core.uuid cimport UUID
from nautilus_trader.live.data_client cimport LiveDataClient
from nautilus_trader.live.data_client cimport LiveMarketDataClient
from nautilus_trader.model.bar cimport Bar
from nautilus_trader.model.bar cimport BarType
from nautilus_trader.model.c_enums.price_type cimport PriceType
Expand All @@ -29,7 +29,7 @@ from nautilus_trader.model.tick cimport QuoteTick
from nautilus_trader.model.tick cimport TradeTick


cdef class OandaDataClient(LiveDataClient):
cdef class OandaDataClient(LiveMarketDataClient):
cdef object _client
cdef str _account_id
cdef set _subscribed_instruments
Expand Down
7 changes: 3 additions & 4 deletions nautilus_trader/adapters/oanda/data.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ from nautilus_trader.core.constants cimport * # str constants only
from nautilus_trader.core.correctness cimport Condition
from nautilus_trader.core.datetime cimport format_iso8601
from nautilus_trader.core.uuid cimport UUID
from nautilus_trader.live.data_client cimport LiveDataClient
from nautilus_trader.live.data_client cimport LiveMarketDataClient
from nautilus_trader.live.data_engine cimport LiveDataEngine
from nautilus_trader.model.bar cimport Bar
from nautilus_trader.model.bar cimport BarData
Expand All @@ -42,7 +42,6 @@ from nautilus_trader.model.c_enums.bar_aggregation cimport BarAggregationParser
from nautilus_trader.model.c_enums.price_type cimport PriceType
from nautilus_trader.model.c_enums.price_type cimport PriceTypeParser
from nautilus_trader.model.identifiers cimport Symbol
from nautilus_trader.model.identifiers cimport Venue
from nautilus_trader.model.instrument cimport Instrument
from nautilus_trader.model.objects cimport Price
from nautilus_trader.model.objects cimport Quantity
Expand All @@ -52,7 +51,7 @@ from nautilus_trader.model.tick cimport QuoteTick
cdef int _SECONDS_IN_HOUR = 60 * 60


cdef class OandaDataClient(LiveDataClient):
cdef class OandaDataClient(LiveMarketDataClient):
"""
Provides a data client for the `Oanda` brokerage.
"""
Expand Down Expand Up @@ -83,7 +82,7 @@ cdef class OandaDataClient(LiveDataClient):
"""
super().__init__(
Venue("OANDA"),
"OANDA",
engine,
clock,
logger,
Expand Down
4 changes: 2 additions & 2 deletions nautilus_trader/backtest/data_client.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
# limitations under the License.
# -------------------------------------------------------------------------------------------------

from nautilus_trader.data.client cimport DataClient
from nautilus_trader.data.client cimport MarketDataClient


cdef class BacktestDataClient(DataClient):
cdef class BacktestMarketDataClient(MarketDataClient):
cdef dict _instruments
cdef bint _is_connected
17 changes: 11 additions & 6 deletions nautilus_trader/backtest/data_client.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,22 @@ from nautilus_trader.common.clock cimport Clock
from nautilus_trader.common.logging cimport Logger
from nautilus_trader.core.correctness cimport Condition
from nautilus_trader.core.uuid cimport UUID
from nautilus_trader.data.client cimport DataClient
from nautilus_trader.data.client cimport MarketDataClient
from nautilus_trader.data.engine cimport DataEngine
from nautilus_trader.model.bar cimport BarType
from nautilus_trader.model.identifiers cimport Symbol
from nautilus_trader.model.identifiers cimport Venue
from nautilus_trader.model.instrument cimport Instrument


cdef class BacktestDataClient(DataClient):
cdef class BacktestMarketDataClient(MarketDataClient):
"""
Provides an implementation of `DataClient` for backtesting.
"""

def __init__(
self,
list instruments not None,
Venue venue not None,
str name not None,
DataEngine engine not None,
Clock clock not None,
Logger logger not None,
Expand All @@ -60,15 +59,21 @@ cdef class BacktestDataClient(DataClient):
"""
super().__init__(
venue,
name,
engine,
clock,
logger,
)

self._instruments = {}
for instrument in instruments:
Condition.equal(instrument.symbol.venue, self.venue, "instrument.symbol.venue", "self.venue")
# Check the instrument is for the correct client
Condition.equal(
instrument.symbol.venue.value,
self.name,
"instrument.symbol.venue.value",
"self.name",
)
self._instruments[instrument.symbol] = instrument

self.is_connected = False
Expand Down
6 changes: 3 additions & 3 deletions nautilus_trader/backtest/engine.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import pytz
from cpython.datetime cimport datetime

from nautilus_trader.analysis.performance cimport PerformanceAnalyzer
from nautilus_trader.backtest.data_client cimport BacktestDataClient
from nautilus_trader.backtest.data_client cimport BacktestMarketDataClient
from nautilus_trader.backtest.data_container cimport BacktestDataContainer
from nautilus_trader.backtest.data_producer cimport BacktestDataProducer
from nautilus_trader.backtest.data_producer cimport CachedProducer
Expand Down Expand Up @@ -238,9 +238,9 @@ cdef class BacktestEngine:
if instrument.symbol.venue == venue:
instruments.append(instrument)

data_client = BacktestDataClient(
data_client = BacktestMarketDataClient(
instruments=instruments,
venue=venue,
name=venue.value,
engine=self._data_engine,
clock=self._test_clock,
logger=self._test_logger,
Expand Down
14 changes: 14 additions & 0 deletions nautilus_trader/data/base.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,20 @@ from nautilus_trader.model.tick cimport QuoteTick
from nautilus_trader.model.tick cimport TradeTick


cdef class Data:
cdef readonly DataType data_type
"""The data type for the data.\n\n:returns: `DataType`"""
cdef readonly object data
"""The data.\n\n:returns: `object`"""


cdef class DataType:
cdef readonly type type
"""The type of the data.\n\n:returns: `type`"""
cdef readonly dict metadata
"""The data types metadata.\n\n:returns: `dict[str, object]`"""


cdef class DataCacheFacade:

# -- QUERIES --------------------------------------------------------------------------------------- # noqa
Expand Down
60 changes: 60 additions & 0 deletions nautilus_trader/data/base.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,66 @@ from nautilus_trader.model.tick cimport QuoteTick
from nautilus_trader.model.tick cimport TradeTick


cdef class Data:
"""
Represents wrapped data which includes data type information.
"""

def __init__(self, DataType data_type not None, data not None):
"""
Initialize a new instance of the `Data` class.
Parameters
----------
data_type : DataType
The data type.
data : object
The data object to wrap.
"""
self.data_type = data_type
self.data = data


cdef class DataType:
"""
Represents a data type including its metadata.
"""

def __init__(self, type data_type not None, dict metadata=None):
"""
Initialize a new instance of the `DataType` class.
Parameters
----------
data_type : type
The PyObject type of the data.
metadata : dict
The data types metadata.
"""
if metadata is None:
metadata = {}

self.type = data_type
self.metadata = metadata

def __eq__(self, DataType other) -> bool:
return self.type == other.type and self.metadata == other.metadata

def __ne__(self, DataType other) -> bool:
return self.type != other.type or self.metadata != other.metadata

def __hash__(self) -> int:
return hash((self.type, self.metadata))

def __str__(self) -> str:
return f"<{self.type.__name__}> {self.metadata}"

def __repr__(self) -> str:
return f"{type(self).__name__}(type={self.type.__name__}, metadata={self.metadata})"


cdef class DataCacheFacade:
"""
Provides a read-only facade for a `DataCache`.
Expand Down
25 changes: 21 additions & 4 deletions nautilus_trader/data/client.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ from nautilus_trader.common.clock cimport Clock
from nautilus_trader.common.logging cimport LoggerAdapter
from nautilus_trader.common.uuid cimport UUIDFactory
from nautilus_trader.core.uuid cimport UUID
from nautilus_trader.data.base cimport DataType
from nautilus_trader.data.engine cimport DataEngine
from nautilus_trader.model.bar cimport Bar
from nautilus_trader.model.bar cimport BarType
from nautilus_trader.model.identifiers cimport Symbol
from nautilus_trader.model.identifiers cimport Venue
from nautilus_trader.model.instrument cimport Instrument
from nautilus_trader.model.order_book cimport OrderBook
from nautilus_trader.model.tick cimport QuoteTick
Expand All @@ -37,18 +37,35 @@ cdef class DataClient:
cdef DataEngine _engine
cdef dict _config

cdef readonly Venue venue
cdef readonly str name
"""The clients venue.\n\n:returns: `Venue`"""
cdef readonly bint is_connected
"""If the client is connected.\n\n:returns: `bool`"""

cpdef list unavailable_methods(self)

cpdef void connect(self) except *
cpdef void disconnect(self) except *
cpdef void reset(self) except *
cpdef void dispose(self) except *

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

cpdef void subscribe(self, DataType data_type) except *
cpdef void unsubscribe(self, DataType data_type) except *

# -- REQUEST HANDLERS ------------------------------------------------------------------------------

cpdef void request(self, DataType data_type, UUID correlation_id) except *

# -- DATA HANDLERS ---------------------------------------------------------------------------------

cdef void _handle_data(self, DataType data_type, data) except *
cdef void _handle_data_response(self, DataType data_type, data, UUID correlation_id) except *


cdef class MarketDataClient(DataClient):

cpdef list unavailable_methods(self)

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

cpdef void subscribe_instrument(self, Symbol symbol) except *
Expand Down
Loading

0 comments on commit ea441c3

Please sign in to comment.