def setUp(self): # Object creation tick = Tick(MessageId(TraderId('0'), MessageNumber('message_number')), OrderId(TraderId('0'), OrderNumber(1)), Price(63400, 'BTC'), Quantity(30, 'MC'), Timeout(0.0), Timestamp(0.0), True) tick2 = Tick(MessageId(TraderId('0'), MessageNumber('message_number')), OrderId(TraderId('0'), OrderNumber(2)), Price(63400, 'BTC'), Quantity(30, 'MC'), Timeout(100), Timestamp.now(), True) self.price_level = PriceLevel('MC') self.tick_entry = TickEntry(tick, self.price_level) self.tick_entry2 = TickEntry(tick2, self.price_level)
def setUp(self, annotate=True): yield super(TickEntryTestSuite, self).setUp(annotate=annotate) # Object creation tick = Tick(OrderId(TraderId('0'), OrderNumber(1)), Price(63400, 'BTC'), Quantity(30, 'MC'), Timeout(0.0), Timestamp(0.0), True) tick2 = Tick(OrderId(TraderId('0'), OrderNumber(2)), Price(63400, 'BTC'), Quantity(30, 'MC'), Timeout(100), Timestamp.now(), True) self.price_level = PriceLevel('MC') self.tick_entry = TickEntry(tick, self.price_level) self.tick_entry2 = TickEntry(tick2, self.price_level)
class TickEntryTestSuite(AbstractServer): """TickEntry test cases.""" @inlineCallbacks def setUp(self): yield super(TickEntryTestSuite, self).setUp() # Object creation tick = Tick(OrderId(TraderId(b'0'), OrderNumber(1)), AssetPair(AssetAmount(60, 'BTC'), AssetAmount(30, 'MB')), Timeout(0), Timestamp(0.0), True) tick2 = Tick(OrderId(TraderId(b'0'), OrderNumber(2)), AssetPair(AssetAmount(63400, 'BTC'), AssetAmount(30, 'MB')), Timeout(100), Timestamp.now(), True) self.price_level = PriceLevel(Price(100, 'MB', 'BTC')) self.tick_entry = TickEntry(tick, self.price_level) self.tick_entry2 = TickEntry(tick2, self.price_level) @inlineCallbacks def tearDown(self): self.tick_entry.shutdown_task_manager() self.tick_entry2.shutdown_task_manager() yield super(TickEntryTestSuite, self).tearDown() def test_price_level(self): self.assertEquals(self.price_level, self.tick_entry.price_level()) def test_next_tick(self): # Test for next tick self.assertEquals(None, self.tick_entry.next_tick) self.price_level.append_tick(self.tick_entry) self.price_level.append_tick(self.tick_entry2) self.assertEquals(self.tick_entry2, self.tick_entry.next_tick) def test_prev_tick(self): # Test for previous tick self.assertEquals(None, self.tick_entry.prev_tick) self.price_level.append_tick(self.tick_entry) self.price_level.append_tick(self.tick_entry2) self.assertEquals(self.tick_entry, self.tick_entry2.prev_tick) def test_str(self): # Test for tick string representation self.assertEquals('60 BTC\t@\t0.5 MB (R: 0)', str(self.tick_entry)) def test_is_valid(self): # Test for is valid self.assertFalse(self.tick_entry.is_valid()) self.assertTrue(self.tick_entry2.is_valid()) def test_block_for_matching(self): """ Test blocking of a match """ self.tick_entry.block_for_matching(OrderId(TraderId(b"abc"), OrderNumber(3))) self.assertEqual(len(self.tick_entry._blocked_for_matching), 1) # Try to add it again - should be ignored self.tick_entry.block_for_matching(OrderId(TraderId(b"abc"), OrderNumber(3))) self.assertEqual(len(self.tick_entry._blocked_for_matching), 1)
def setUp(self): yield super(TickEntryTestSuite, self).setUp() # Object creation tick = Tick(OrderId(TraderId(b'0'), OrderNumber(1)), AssetPair(AssetAmount(60, 'BTC'), AssetAmount(30, 'MB')), Timeout(0), Timestamp(0.0), True) tick2 = Tick( OrderId(TraderId(b'0'), OrderNumber(2)), AssetPair(AssetAmount(63400, 'BTC'), AssetAmount(30, 'MB')), Timeout(100), Timestamp.now(), True) self.price_level = PriceLevel(Price(100, 'MB', 'BTC')) self.tick_entry = TickEntry(tick, self.price_level) self.tick_entry2 = TickEntry(tick2, self.price_level)
def setUp(self): # Object creation tick = Tick(OrderId(TraderId(b'0'), OrderNumber(1)), AssetPair(AssetAmount(60, 'BTC'), AssetAmount(30, 'MC')), Timeout(100), Timestamp.now(), True) tick2 = Tick(OrderId(TraderId(b'0'), OrderNumber(2)), AssetPair(AssetAmount(30, 'BTC'), AssetAmount(30, 'MC')), Timeout(100), Timestamp.now(), True) self.price_level = PriceLevel(Price(10, 'MC', 'BTC')) self.tick_entry1 = TickEntry(tick, self.price_level) self.tick_entry2 = TickEntry(tick, self.price_level) self.tick_entry3 = TickEntry(tick, self.price_level) self.tick_entry4 = TickEntry(tick, self.price_level) self.tick_entry5 = TickEntry(tick2, self.price_level)
def setUp(self): # Object creation tick = Tick(OrderId(TraderId('0'), OrderNumber(1)), Price(63400, 'BTC'), Quantity(30, 'MC'), Timeout(float("inf")), Timestamp(float("inf")), True) tick2 = Tick(OrderId(TraderId('0'), OrderNumber(2)), Price(30, 'MC'), Quantity(30, 'BTC'), Timeout(float("inf")), Timestamp(float("inf")), True) self.price_level = PriceLevel('MC') self.tick_entry1 = TickEntry(tick, self.price_level) self.tick_entry2 = TickEntry(tick, self.price_level) self.tick_entry3 = TickEntry(tick, self.price_level) self.tick_entry4 = TickEntry(tick, self.price_level) self.tick_entry5 = TickEntry(tick2, self.price_level)
def _create_price_level(self, price): """ :param price: The price to create the level for :type price: Price """ self._depth[(price.numerator, price.denominator)] += 1 price_level = PriceLevel(price) self._price_level_list_map[(price.numerator, price.denominator)].insert(price_level) self._price_map[price] = price_level
def setUp(self): # Object creation self.price_level_list = PriceLevelList() self.price_level_list2 = PriceLevelList() self.price = Price(1, 'BTC') self.price2 = Price(2, 'BTC') self.price3 = Price(3, 'BTC') self.price4 = Price(4, 'BTC') self.price_level = PriceLevel('MC') self.price_level2 = PriceLevel('MC') self.price_level3 = PriceLevel('MC') self.price_level4 = PriceLevel('MC') # Fill price level list self.price_level_list.insert(self.price, self.price_level) self.price_level_list.insert(self.price2, self.price_level2) self.price_level_list.insert(self.price3, self.price_level3) self.price_level_list.insert(self.price4, self.price_level4)
def setUp(self): yield super(TickEntryTestSuite, self).setUp() # Object creation tick = Tick(OrderId(TraderId(b'0'), OrderNumber(1)), AssetPair(AssetAmount(60, 'BTC'), AssetAmount(30, 'MB')), Timeout(0), Timestamp(0.0), True) tick2 = Tick(OrderId(TraderId(b'0'), OrderNumber(2)), AssetPair(AssetAmount(63400, 'BTC'), AssetAmount(30, 'MB')), Timeout(100), Timestamp.now(), True) self.price_level = PriceLevel(Price(100, 'MB', 'BTC')) self.tick_entry = TickEntry(tick, self.price_level) self.tick_entry2 = TickEntry(tick2, self.price_level)
def setUp(self): # Object creation tick = Tick(OrderId(TraderId('0'), OrderNumber(1)), AssetPair(AssetAmount(60, 'BTC'), AssetAmount(30, 'MC')), Timeout(100), Timestamp.now(), True) tick2 = Tick(OrderId(TraderId('0'), OrderNumber(2)), AssetPair(AssetAmount(30, 'BTC'), AssetAmount(30, 'MC')), Timeout(100), Timestamp.now(), True) self.price_level = PriceLevel(Price(10, 'MC', 'BTC')) self.tick_entry1 = TickEntry(tick, self.price_level) self.tick_entry2 = TickEntry(tick, self.price_level) self.tick_entry3 = TickEntry(tick, self.price_level) self.tick_entry4 = TickEntry(tick, self.price_level) self.tick_entry5 = TickEntry(tick2, self.price_level)
def _create_price_level(self, price, quantity_wallet_id): """ :param price: The price to create the level for :param quantity_wallet_id: the id of the quantities stored in this price level :type price: Price :type quantity_wallet_id: str """ assert isinstance(price, Price), type(price) self._depth[(price.wallet_id, quantity_wallet_id)] += 1 price_level = PriceLevel(quantity_wallet_id) self._price_level_list_map[(price.wallet_id, quantity_wallet_id)].insert(price, price_level) self._price_map[price] = price_level
class PriceLevelTestSuite(unittest.TestCase): """PriceLevel test cases.""" def setUp(self): # Object creation tick = Tick(OrderId(TraderId(b'0'), OrderNumber(1)), AssetPair(AssetAmount(60, 'BTC'), AssetAmount(30, 'MC')), Timeout(100), Timestamp.now(), True) tick2 = Tick(OrderId(TraderId(b'0'), OrderNumber(2)), AssetPair(AssetAmount(30, 'BTC'), AssetAmount(30, 'MC')), Timeout(100), Timestamp.now(), True) self.price_level = PriceLevel(Price(10, 'MC', 'BTC')) self.tick_entry1 = TickEntry(tick, self.price_level) self.tick_entry2 = TickEntry(tick, self.price_level) self.tick_entry3 = TickEntry(tick, self.price_level) self.tick_entry4 = TickEntry(tick, self.price_level) self.tick_entry5 = TickEntry(tick2, self.price_level) def test_appending_length(self): # Test for tick appending and length self.assertEquals(0, self.price_level.length) self.assertEquals(0, len(self.price_level)) self.price_level.append_tick(self.tick_entry1) self.price_level.append_tick(self.tick_entry2) self.price_level.append_tick(self.tick_entry3) self.price_level.append_tick(self.tick_entry4) self.assertEquals(4, self.price_level.length) self.assertEquals(4, len(self.price_level)) def test_tick_removal(self): # Test for tick removal self.price_level.append_tick(self.tick_entry1) self.price_level.append_tick(self.tick_entry2) self.price_level.append_tick(self.tick_entry3) self.price_level.append_tick(self.tick_entry4) self.price_level.remove_tick(self.tick_entry2) self.price_level.remove_tick(self.tick_entry1) self.price_level.remove_tick(self.tick_entry4) self.price_level.remove_tick(self.tick_entry3) self.assertEquals(0, self.price_level.length) def test_str(self): # Test for price level string representation self.price_level.append_tick(self.tick_entry1) self.price_level.append_tick(self.tick_entry2) self.assertEquals( '60 BTC\t@\t0.5 MC (R: 0)\n' '60 BTC\t@\t0.5 MC (R: 0)\n', str(self.price_level))
class PriceLevelTestSuite(unittest.TestCase): """PriceLevel test cases.""" def setUp(self): # Object creation tick = Tick(OrderId(TraderId('0'), OrderNumber(1)), AssetPair(AssetAmount(60, 'BTC'), AssetAmount(30, 'MC')), Timeout(100), Timestamp.now(), True) tick2 = Tick(OrderId(TraderId('0'), OrderNumber(2)), AssetPair(AssetAmount(30, 'BTC'), AssetAmount(30, 'MC')), Timeout(100), Timestamp.now(), True) self.price_level = PriceLevel(Price(10, 'MC', 'BTC')) self.tick_entry1 = TickEntry(tick, self.price_level) self.tick_entry2 = TickEntry(tick, self.price_level) self.tick_entry3 = TickEntry(tick, self.price_level) self.tick_entry4 = TickEntry(tick, self.price_level) self.tick_entry5 = TickEntry(tick2, self.price_level) def test_appending_length(self): # Test for tick appending and length self.assertEquals(0, self.price_level.length) self.assertEquals(0, len(self.price_level)) self.price_level.append_tick(self.tick_entry1) self.price_level.append_tick(self.tick_entry2) self.price_level.append_tick(self.tick_entry3) self.price_level.append_tick(self.tick_entry4) self.assertEquals(4, self.price_level.length) self.assertEquals(4, len(self.price_level)) def test_tick_removal(self): # Test for tick removal self.price_level.append_tick(self.tick_entry1) self.price_level.append_tick(self.tick_entry2) self.price_level.append_tick(self.tick_entry3) self.price_level.append_tick(self.tick_entry4) self.price_level.remove_tick(self.tick_entry2) self.price_level.remove_tick(self.tick_entry1) self.price_level.remove_tick(self.tick_entry4) self.price_level.remove_tick(self.tick_entry3) self.assertEquals(0, self.price_level.length) def test_str(self): # Test for price level string representation self.price_level.append_tick(self.tick_entry1) self.price_level.append_tick(self.tick_entry2) self.assertEquals('60 BTC\t@\t0.5 MC (R: 0)\n' '60 BTC\t@\t0.5 MC (R: 0)\n', str(self.price_level))
class TickEntryTestSuite(unittest.TestCase): """TickEntry test cases.""" def setUp(self): # Object creation tick = Tick(MessageId(TraderId('0'), MessageNumber('message_number')), OrderId(TraderId('0'), OrderNumber(1)), Price(63400, 'BTC'), Quantity(30, 'MC'), Timeout(0.0), Timestamp(0.0), True) tick2 = Tick(MessageId(TraderId('0'), MessageNumber('message_number')), OrderId(TraderId('0'), OrderNumber(2)), Price(63400, 'BTC'), Quantity(30, 'MC'), Timeout(100), Timestamp.now(), True) self.price_level = PriceLevel('MC') self.tick_entry = TickEntry(tick, self.price_level) self.tick_entry2 = TickEntry(tick2, self.price_level) def test_price_level(self): self.assertEquals(self.price_level, self.tick_entry.price_level()) def test_next_tick(self): # Test for next tick self.assertEquals(None, self.tick_entry.next_tick) self.price_level.append_tick(self.tick_entry) self.price_level.append_tick(self.tick_entry2) self.assertEquals(self.tick_entry2, self.tick_entry.next_tick) def test_prev_tick(self): # Test for previous tick self.assertEquals(None, self.tick_entry.prev_tick) self.price_level.append_tick(self.tick_entry) self.price_level.append_tick(self.tick_entry2) self.assertEquals(self.tick_entry, self.tick_entry2.prev_tick) def test_str(self): # Test for tick string representation self.assertEquals('30.000000 MC\t@\t63400.000000 BTC', str(self.tick_entry)) def test_is_valid(self): # Test for is valid self.assertFalse(self.tick_entry.is_valid()) self.assertTrue(self.tick_entry2.is_valid()) def test_quantity_setter(self): # Test for quantity setter self.price_level.append_tick(self.tick_entry) self.price_level.append_tick(self.tick_entry2) self.tick_entry.quantity = Quantity(15, 'MC') self.assertEquals(Quantity(15, 'MC'), self.tick_entry.quantity)
class TickEntryTestSuite(AbstractServer): """TickEntry test cases.""" @blocking_call_on_reactor_thread @inlineCallbacks def setUp(self, annotate=True): yield super(TickEntryTestSuite, self).setUp(annotate=annotate) # Object creation tick = Tick(OrderId(TraderId('0'), OrderNumber(1)), Price(63400, 'BTC'), Quantity(30, 'MC'), Timeout(0.0), Timestamp(0.0), True) tick2 = Tick(OrderId(TraderId('0'), OrderNumber(2)), Price(63400, 'BTC'), Quantity(30, 'MC'), Timeout(100), Timestamp.now(), True) self.price_level = PriceLevel('MC') self.tick_entry = TickEntry(tick, self.price_level) self.tick_entry2 = TickEntry(tick2, self.price_level) @blocking_call_on_reactor_thread @inlineCallbacks def tearDown(self, annotate=True): self.tick_entry.cancel_all_pending_tasks() self.tick_entry2.cancel_all_pending_tasks() yield super(TickEntryTestSuite, self).tearDown(annotate=annotate) def test_price_level(self): self.assertEquals(self.price_level, self.tick_entry.price_level()) def test_next_tick(self): # Test for next tick self.assertEquals(None, self.tick_entry.next_tick) self.price_level.append_tick(self.tick_entry) self.price_level.append_tick(self.tick_entry2) self.assertEquals(self.tick_entry2, self.tick_entry.next_tick) def test_prev_tick(self): # Test for previous tick self.assertEquals(None, self.tick_entry.prev_tick) self.price_level.append_tick(self.tick_entry) self.price_level.append_tick(self.tick_entry2) self.assertEquals(self.tick_entry, self.tick_entry2.prev_tick) def test_str(self): # Test for tick string representation self.assertEquals('30.000000 MC\t@\t63400.000000 BTC', str(self.tick_entry)) def test_is_valid(self): # Test for is valid self.assertFalse(self.tick_entry.is_valid()) self.assertTrue(self.tick_entry2.is_valid()) def test_quantity_setter(self): # Test for quantity setter self.price_level.append_tick(self.tick_entry) self.price_level.append_tick(self.tick_entry2) self.tick_entry.quantity = Quantity(15, 'MC') self.assertEquals(Quantity(15, 'MC'), self.tick_entry.quantity) def test_block_for_matching(self): """ Test blocking of a match """ self.tick_entry.block_for_matching( OrderId(TraderId("abc"), OrderNumber(3))) self.assertEqual(len(self.tick_entry._blocked_for_matching), 1) # Try to add it again - should be ignored self.tick_entry.block_for_matching( OrderId(TraderId("abc"), OrderNumber(3))) self.assertEqual(len(self.tick_entry._blocked_for_matching), 1)
class TickEntryTestSuite(AbstractServer): """TickEntry test cases.""" @inlineCallbacks def setUp(self): yield super(TickEntryTestSuite, self).setUp() # Object creation tick = Tick(OrderId(TraderId(b'0'), OrderNumber(1)), AssetPair(AssetAmount(60, 'BTC'), AssetAmount(30, 'MB')), Timeout(0), Timestamp(0.0), True) tick2 = Tick( OrderId(TraderId(b'0'), OrderNumber(2)), AssetPair(AssetAmount(63400, 'BTC'), AssetAmount(30, 'MB')), Timeout(100), Timestamp.now(), True) self.price_level = PriceLevel(Price(100, 'MB', 'BTC')) self.tick_entry = TickEntry(tick, self.price_level) self.tick_entry2 = TickEntry(tick2, self.price_level) @inlineCallbacks def tearDown(self): self.tick_entry.shutdown_task_manager() self.tick_entry2.shutdown_task_manager() yield super(TickEntryTestSuite, self).tearDown() def test_price_level(self): self.assertEquals(self.price_level, self.tick_entry.price_level()) def test_next_tick(self): # Test for next tick self.assertEquals(None, self.tick_entry.next_tick) self.price_level.append_tick(self.tick_entry) self.price_level.append_tick(self.tick_entry2) self.assertEquals(self.tick_entry2, self.tick_entry.next_tick) def test_prev_tick(self): # Test for previous tick self.assertEquals(None, self.tick_entry.prev_tick) self.price_level.append_tick(self.tick_entry) self.price_level.append_tick(self.tick_entry2) self.assertEquals(self.tick_entry, self.tick_entry2.prev_tick) def test_str(self): # Test for tick string representation self.assertEquals('60 BTC\t@\t0.5 MB (R: 0)', str(self.tick_entry)) def test_is_valid(self): # Test for is valid self.assertFalse(self.tick_entry.is_valid()) self.assertTrue(self.tick_entry2.is_valid()) def test_block_for_matching(self): """ Test blocking of a match """ self.tick_entry.block_for_matching( OrderId(TraderId(b"abc"), OrderNumber(3))) self.assertEqual(len(self.tick_entry._blocked_for_matching), 1) # Try to add it again - should be ignored self.tick_entry.block_for_matching( OrderId(TraderId(b"abc"), OrderNumber(3))) self.assertEqual(len(self.tick_entry._blocked_for_matching), 1)
class PriceLevelTestSuite(unittest.TestCase): """PriceLevel test cases.""" def setUp(self): # Object creation tick = Tick(OrderId(TraderId('0'), OrderNumber(1)), Price(63400, 'BTC'), Quantity(30, 'MC'), Timeout(float("inf")), Timestamp(float("inf")), True) tick2 = Tick(OrderId(TraderId('0'), OrderNumber(2)), Price(30, 'MC'), Quantity(30, 'BTC'), Timeout(float("inf")), Timestamp(float("inf")), True) self.price_level = PriceLevel('MC') self.tick_entry1 = TickEntry(tick, self.price_level) self.tick_entry2 = TickEntry(tick, self.price_level) self.tick_entry3 = TickEntry(tick, self.price_level) self.tick_entry4 = TickEntry(tick, self.price_level) self.tick_entry5 = TickEntry(tick2, self.price_level) def test_appending_length(self): # Test for tick appending and length self.assertEquals(0, self.price_level.length) self.assertEquals(0, len(self.price_level)) self.price_level.append_tick(self.tick_entry1) self.price_level.append_tick(self.tick_entry2) self.price_level.append_tick(self.tick_entry3) self.price_level.append_tick(self.tick_entry4) self.assertEquals(4, self.price_level.length) self.assertEquals(4, len(self.price_level)) self.assertRaises(AssertionError, self.price_level.append_tick, self.tick_entry5) def test_tick_removal(self): # Test for tick removal self.price_level.append_tick(self.tick_entry1) self.price_level.append_tick(self.tick_entry2) self.price_level.append_tick(self.tick_entry3) self.price_level.append_tick(self.tick_entry4) self.price_level.remove_tick(self.tick_entry2) self.price_level.remove_tick(self.tick_entry1) self.price_level.remove_tick(self.tick_entry4) self.price_level.remove_tick(self.tick_entry3) self.assertEquals(0, self.price_level.length) def test_str(self): # Test for price level string representation self.price_level.append_tick(self.tick_entry1) self.price_level.append_tick(self.tick_entry2) self.assertEquals( '30.000000 MC\t@\t63400.000000 BTC (R: 0.000000 MC)\n' '30.000000 MC\t@\t63400.000000 BTC (R: 0.000000 MC)\n', str(self.price_level))