def setUp(self): # Fixture Setup self.clock = TestClock() self.uuid_factory = UUIDFactory() self.logger = Logger(self.clock) self.cache = TestStubs.cache() self.portfolio = Portfolio( cache=self.cache, clock=self.clock, logger=self.logger, ) self.data_engine = DataEngine( portfolio=self.portfolio, cache=self.cache, clock=self.clock, logger=self.logger, ) self.venue = Venue("SIM") self.client = DataClient( client_id=ClientId("TEST_PROVIDER"), engine=self.data_engine, clock=self.clock, logger=self.logger, )
def setUp(self): # Fixture Setup self.clock = TestClock() self.uuid_factory = UUIDFactory() self.logger = TestLogger(self.clock) self.portfolio = Portfolio( clock=self.clock, logger=self.logger, ) self.data_engine = DataEngine( portfolio=self.portfolio, clock=self.clock, logger=self.logger, ) self.venue = Venue("SIM") self.client = DataClient( venue=self.venue, engine=self.data_engine, clock=self.clock, logger=self.logger, )
def setup(self): # Fixture Setup self.clock = TestClock() self.uuid_factory = UUIDFactory() self.logger = Logger(self.clock) self.trader_id = TestIdStubs.trader_id() self.msgbus = MessageBus( trader_id=self.trader_id, clock=self.clock, logger=self.logger, ) self.cache = TestComponentStubs.cache() self.portfolio = Portfolio( msgbus=self.msgbus, cache=self.cache, clock=self.clock, logger=self.logger, ) self.data_engine = DataEngine( msgbus=self.msgbus, cache=self.cache, clock=self.clock, logger=self.logger, ) self.venue = Venue("SIM") self.client = DataClient( client_id=ClientId("TEST_PROVIDER"), venue=self.venue, msgbus=self.msgbus, cache=self.cache, clock=self.clock, logger=self.logger, )
class DataClientTests(unittest.TestCase): def setUp(self): # Fixture Setup self.clock = TestClock() self.uuid_factory = UUIDFactory() self.logger = TestLogger(self.clock) self.portfolio = Portfolio( clock=self.clock, logger=self.logger, ) self.data_engine = DataEngine( portfolio=self.portfolio, clock=self.clock, logger=self.logger, ) self.venue = Venue("SIM") self.client = DataClient( venue=self.venue, engine=self.data_engine, clock=self.clock, logger=self.logger, ) def test_connect_when_not_implemented_raises_exception(self): # Arrange # Act # Assert self.assertRaises(NotImplementedError, self.client.connect) def test_disconnect_when_not_implemented_raises_exception(self): # Arrange # Act # Assert self.assertRaises(NotImplementedError, self.client.disconnect) def test_reset_when_not_implemented_raises_exception(self): # Arrange # Act # Assert self.assertRaises(NotImplementedError, self.client.reset) def test_dispose_when_not_implemented_raises_exception(self): # Arrange # Act # Assert self.assertRaises(NotImplementedError, self.client.dispose) def test_subscribe_instrument_when_not_implemented_raises_exception(self): # Arrange # Act # Assert self.assertRaises(NotImplementedError, self.client.subscribe_instrument, AUDUSD_SIM.symbol) def test_subscribe_quote_ticks_when_not_implemented_raises_exception(self): # Arrange # Act # Assert self.assertRaises(NotImplementedError, self.client.subscribe_quote_ticks, AUDUSD_SIM.symbol) def test_subscribe_trade_ticks_when_not_implemented_raises_exception(self): # Arrange # Act # Assert self.assertRaises(NotImplementedError, self.client.subscribe_trade_ticks, AUDUSD_SIM.symbol) def test_subscribe_bars_when_not_implemented_raises_exception(self): # Arrange # Act # Assert self.assertRaises(NotImplementedError, self.client.subscribe_bars, TestStubs.bartype_gbpusd_1sec_mid()) def test_unsubscribe_instrument_when_not_implemented_raises_exception(self): # Arrange # Act # Assert self.assertRaises(NotImplementedError, self.client.unsubscribe_instrument, AUDUSD_SIM.symbol) def test_unsubscribe_quote_ticks_when_not_implemented_raises_exception(self): # Arrange # Act # Assert self.assertRaises(NotImplementedError, self.client.unsubscribe_quote_ticks, AUDUSD_SIM.symbol) def test_unsubscribe_trade_ticks_when_not_implemented_raises_exception(self): # Arrange # Act # Assert self.assertRaises(NotImplementedError, self.client.unsubscribe_trade_ticks, AUDUSD_SIM.symbol) def test_unsubscribe_bars_when_not_implemented_raises_exception(self): # Arrange # Act # Assert self.assertRaises(NotImplementedError, self.client.unsubscribe_bars, TestStubs.bartype_gbpusd_1sec_mid()) def test_request_instrument_when_not_implemented_raises_exception(self): # Arrange # Act # Assert self.assertRaises(NotImplementedError, self.client.request_instrument, None, None) def test_request_instruments_when_not_implemented_raises_exception(self): # Arrange # Act # Assert self.assertRaises(NotImplementedError, self.client.request_instruments, None) def test_request_quote_ticks_when_not_implemented_raises_exception(self): # Arrange # Act # Assert self.assertRaises(NotImplementedError, self.client.request_quote_ticks, None, None, None, 0, None) def test_request_trade_ticks_when_not_implemented_raises_exception(self): # Arrange # Act # Assert self.assertRaises(NotImplementedError, self.client.request_trade_ticks, None, None, None, 0, None) def test_request_bars_when_not_implemented_raises_exception(self): # Arrange # Act # Assert self.assertRaises(NotImplementedError, self.client.request_bars, None, None, None, 0, None) def test_handle_instrument_sends_to_data_engine(self): # Arrange # Act self.client._handle_instrument_py(AUDUSD_SIM) # Assert self.assertEqual(1, self.data_engine.data_count) def test_handle_quote_tick_sends_to_data_engine(self): # Arrange tick = QuoteTick( AUDUSD_SIM.symbol, Price("1.00050"), Price("1.00048"), Quantity(1), Quantity(1), UNIX_EPOCH, ) # Act self.client._handle_quote_tick_py(tick) # Assert self.assertEqual(1, self.data_engine.data_count) def test_handle_trade_tick_sends_to_data_engine(self): # Arrange tick = TradeTick( AUDUSD_SIM.symbol, Price("1.00050"), Quantity(1), OrderSide.BUY, TradeMatchId("123456"), UNIX_EPOCH, ) # Act self.client._handle_trade_tick_py(tick) # Assert self.assertEqual(1, self.data_engine.data_count) def test_handle_bar_sends_to_data_engine(self): # Arrange bar_type = TestStubs.bartype_gbpusd_1sec_mid() bar = Bar( Price("1.00001"), Price("1.00004"), Price("1.00002"), Price("1.00003"), Quantity(100000), UNIX_EPOCH, ) # Act self.client._handle_bar_py(bar_type, bar) # Assert self.assertEqual(1, self.data_engine.data_count) def test_handle_instruments_sends_to_data_engine(self): # Arrange # Act self.client._handle_instruments_py([], self.uuid_factory.generate()) # Assert self.assertEqual(1, self.data_engine.response_count) def test_handle_quote_ticks_sends_to_data_engine(self): # Arrange # Act self.client._handle_quote_ticks_py(AUDUSD_SIM.symbol, [], self.uuid_factory.generate()) # Assert self.assertEqual(1, self.data_engine.response_count) def test_handle_trade_ticks_sends_to_data_engine(self): # Arrange # Act self.client._handle_trade_ticks_py(AUDUSD_SIM.symbol, [], self.uuid_factory.generate()) # Assert self.assertEqual(1, self.data_engine.response_count) def test_handle_bars_sends_to_data_engine(self): # Arrange # Act self.client._handle_bars_py( TestStubs.bartype_gbpusd_1sec_mid(), [], None, self.uuid_factory.generate(), ) # Assert self.assertEqual(1, self.data_engine.response_count)
class TestDataClient: def setup(self): # Fixture Setup self.clock = TestClock() self.uuid_factory = UUIDFactory() self.logger = Logger(self.clock) self.trader_id = TestStubs.trader_id() self.msgbus = MessageBus( trader_id=self.trader_id, clock=self.clock, logger=self.logger, ) self.cache = TestStubs.cache() self.portfolio = Portfolio( msgbus=self.msgbus, cache=self.cache, clock=self.clock, logger=self.logger, ) self.data_engine = DataEngine( msgbus=self.msgbus, cache=self.cache, clock=self.clock, logger=self.logger, ) self.venue = Venue("SIM") self.client = DataClient( client_id=ClientId("TEST_PROVIDER"), msgbus=self.msgbus, cache=self.cache, clock=self.clock, logger=self.logger, ) def test_handle_data_sends_to_data_engine(self): # Arrange data_type = DataType(NewsEvent, {"Type": "NEWS_WIRE"}) data = NewsEvent( impact=NewsImpact.HIGH, name="Unemployment Rate", currency=USD, ts_event=0, ts_init=0, ) generic_data = GenericData(data_type, data) # Act self.client._handle_data_py(generic_data) # Assert assert self.data_engine.data_count == 1 def test_handle_data_response_sends_to_data_engine(self): # Arrange data_type = DataType(NewsEvent, {"Type": "NEWS_WIRE"}) data = NewsEvent( impact=NewsImpact.HIGH, name="Unemployment Rate", currency=USD, ts_event=0, ts_init=0, ) # Act self.client._handle_data_response_py(data_type, data, self.uuid_factory.generate()) # Assert assert self.data_engine.response_count == 1
class DataClientTests(unittest.TestCase): def setUp(self): # Fixture Setup self.clock = TestClock() self.uuid_factory = UUIDFactory() self.logger = TestLogger(self.clock) self.portfolio = Portfolio( clock=self.clock, logger=self.logger, ) self.data_engine = DataEngine( portfolio=self.portfolio, clock=self.clock, logger=self.logger, ) self.venue = Venue("SIM") self.client = DataClient( name="TEST_PROVIDER", engine=self.data_engine, clock=self.clock, logger=self.logger, ) def test_connect_when_not_implemented_raises_exception(self): # Arrange # Act # Assert self.assertRaises(NotImplementedError, self.client.connect) def test_disconnect_when_not_implemented_raises_exception(self): # Arrange # Act # Assert self.assertRaises(NotImplementedError, self.client.disconnect) def test_reset_when_not_implemented_raises_exception(self): # Arrange # Act # Assert self.assertRaises(NotImplementedError, self.client.reset) def test_dispose_when_not_implemented_raises_exception(self): # Arrange # Act # Assert self.assertRaises(NotImplementedError, self.client.dispose) def test_subscribe_when_not_implemented_raises_exception(self): # Arrange # Act # Assert self.assertRaises(NotImplementedError, self.client.subscribe, DataType(str)) def test_unsubscribe_when_not_implemented_raises_exception(self): # Arrange # Act # Assert self.assertRaises(NotImplementedError, self.client.unsubscribe, DataType(str)) def test_request_when_not_implemented_raises_exception(self): # Arrange # Act # Assert self.assertRaises(NotImplementedError, self.client.request, DataType(str), self.uuid_factory.generate()) def test_handle_data_sends_to_data_engine(self): # Arrange data_type = DataType(str, {"Type": "NEWS_WIRE"}) data = GenericData(data_type, "Some news headline", UNIX_EPOCH) # Act self.client._handle_data_py(data) # Assert self.assertEqual(1, self.data_engine.data_count) def test_handle_data_response_sends_to_data_engine(self): # Arrange data_type = DataType(str, { "Type": "ECONOMIC_DATA", "topic": "unemployment" }) data = GenericData(data_type, "may 2020, 6.9%", UNIX_EPOCH) # Act self.client._handle_data_response_py(data, self.uuid_factory.generate()) # Assert self.assertEqual(1, self.data_engine.response_count)
class DataClientTests(unittest.TestCase): def setUp(self): # Fixture Setup self.clock = TestClock() self.uuid_factory = UUIDFactory() self.logger = Logger(self.clock) self.cache = TestStubs.cache() self.portfolio = Portfolio( cache=self.cache, clock=self.clock, logger=self.logger, ) self.data_engine = DataEngine( portfolio=self.portfolio, cache=self.cache, clock=self.clock, logger=self.logger, ) self.venue = Venue("SIM") self.client = DataClient( client_id=ClientId("TEST_PROVIDER"), engine=self.data_engine, clock=self.clock, logger=self.logger, ) def test_connect_when_not_implemented_raises_exception(self): # Arrange # Act # Assert self.assertRaises(NotImplementedError, self.client.connect) def test_disconnect_when_not_implemented_raises_exception(self): # Arrange # Act # Assert self.assertRaises(NotImplementedError, self.client.disconnect) def test_reset_when_not_implemented_raises_exception(self): # Arrange # Act # Assert self.assertRaises(NotImplementedError, self.client.reset) def test_dispose_when_not_implemented_raises_exception(self): # Arrange # Act # Assert self.assertRaises(NotImplementedError, self.client.dispose) def test_subscribe_when_not_implemented_raises_exception(self): # Arrange # Act # Assert self.assertRaises(NotImplementedError, self.client.subscribe, DataType(str)) def test_unsubscribe_when_not_implemented_raises_exception(self): # Arrange # Act # Assert self.assertRaises(NotImplementedError, self.client.unsubscribe, DataType(str)) def test_request_when_not_implemented_raises_exception(self): # Arrange # Act # Assert self.assertRaises( NotImplementedError, self.client.request, DataType(str), self.uuid_factory.generate(), ) def test_handle_data_sends_to_data_engine(self): # Arrange data_type = DataType(NewsEvent, {"Type": "NEWS_WIRE"}) data = NewsEvent( impact=NewsImpact.HIGH, name="Unemployment Rate", currency=USD, ts_event_ns=0, ts_recv_ns=0, ) generic_data = GenericData(data_type, data) # Act self.client._handle_data_py(generic_data) # Assert self.assertEqual(1, self.data_engine.data_count) def test_handle_data_response_sends_to_data_engine(self): # Arrange data_type = DataType(NewsEvent, {"Type": "NEWS_WIRE"}) data = NewsEvent( impact=NewsImpact.HIGH, name="Unemployment Rate", currency=USD, ts_event_ns=0, ts_recv_ns=0, ) # Act self.client._handle_data_response_py( data_type, data, self.uuid_factory.generate() ) # Assert self.assertEqual(1, self.data_engine.response_count)