def setUp(self): yield super(TickEntryTestSuite, self).setUp() # Object creation tick = Tick(OrderId(TraderId(b'0' * 20), OrderNumber(1)), AssetPair(AssetAmount(60, 'BTC'), AssetAmount(30, 'MB')), Timeout(0), Timestamp(0), True) tick2 = Tick(OrderId(TraderId(b'0' * 20), OrderNumber(2)), AssetPair(AssetAmount(63400, 'BTC'), AssetAmount(30, 'MB')), Timeout(100), Timestamp.now(), True) self.price_level = PriceLevel(Price(100, 1, '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' * 20), OrderNumber(1)), AssetPair(AssetAmount(60, 'BTC'), AssetAmount(30, 'MC')), Timeout(100), Timestamp.now(), True) tick2 = Tick(OrderId(TraderId(b'0' * 20), OrderNumber(2)), AssetPair(AssetAmount(30, 'BTC'), AssetAmount(30, 'MC')), Timeout(100), Timestamp.now(), True) self.price_level = PriceLevel(Price(50, 5, '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)
async def tick_entry2(price_level): tick = Tick(OrderId(TraderId(b'0' * 20), OrderNumber(2)), AssetPair(AssetAmount(63400, 'BTC'), AssetAmount(30, 'MB')), Timeout(100), Timestamp.now(), True) tick_entry = TickEntry(tick, price_level) yield tick_entry await tick_entry.shutdown_task_manager()
def insert_tick(self, tick): """ :param tick: The tick to insert :type tick: Tick """ if (tick.assets.second.asset_id, tick.assets.first.asset_id) not in self._price_level_list_map: self._price_level_list_map[( tick.assets.second.asset_id, tick.assets.first.asset_id)] = PriceLevelList() self._depth[(tick.assets.second.asset_id, tick.assets.first.asset_id)] = 0 if not self._price_level_exists( tick.price): # First tick for that price self._create_price_level(tick.price) tick_entry = TickEntry(tick, self._price_map[tick.price]) self.get_price_level(tick.price).append_tick(tick_entry) self._tick_map[tick.order_id] = tick_entry
class TickEntryTestSuite(AbstractServer): """TickEntry test cases.""" @inlineCallbacks def setUp(self): yield super(TickEntryTestSuite, self).setUp() # Object creation tick = Tick(OrderId(TraderId(b'0' * 20), OrderNumber(1)), AssetPair(AssetAmount(60, 'BTC'), AssetAmount(30, 'MB')), Timeout(0), Timestamp(0), True) tick2 = Tick(OrderId(TraderId(b'0' * 20), OrderNumber(2)), AssetPair(AssetAmount(63400, 'BTC'), AssetAmount(30, 'MB')), Timeout(100), Timestamp.now(), True) self.price_level = PriceLevel(Price(100, 1, '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', 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'a' * 20), 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'a' * 20), OrderNumber(3))) self.assertEqual(len(self.tick_entry._blocked_for_matching), 1)