def test_adds_bid_to_empty_book_when_update_on_bid(self): book = Book() bid_update = MBLUpdate(13.1, 4, 126) mbl = MBL(5) updated_book = mbl.update(book, bid_update) expected_book = Book() expected_book.add_bid(Level(13.1, 4, 126)) self.assertEqual(expected_book, updated_book)
def test_keeps_book_intact_when_delete_missing_level(self): book = Book() book.add_bid(Level(13.1, 1, 2)) book.add_bid(Level(15.1, 1, 2)) delete_bid = MBLUpdate.create_delete_bid_level(18.1) mbl = MBL(5) updated_book = mbl.update(book, delete_bid) expected_book = Book([Level(13.1, 1, 2), Level(15.1, 1, 2)], []) self.assertEqual(expected_book, updated_book)
def test_deletes_existing_level_when_update_on_bid(self): book = Book() book.add_bid(Level(13.1, 1, 2)) book.add_bid(Level(15.1, 1, 2)) delete_bid = MBLUpdate.create_delete_bid_level(13.1) mbl = MBL(5) updated_book = mbl.update(book, delete_bid) expected_book = Book([Level(15.1, 1, 2)], []) self.assertEqual(expected_book, updated_book)
def test_cut_extra_levels_when_update_on_full_bid(self): book = Book() book.add_bid(Level(15.1, 1, 2)) book.add_bid(Level(13.1, 1, 2)) bid_update = MBLUpdate(17.1, 1, 2) mbl = MBL(length=2) updated_book = mbl.update(book, bid_update) expected_book = Book([Level(17.1, 1, 2), Level(15.1, 1, 2)], []) self.assertEqual(expected_book, updated_book)
def test_updates_existing_bid_level_when_update_on_bid(self): book = Book() book.add_bid(Level(13.1, 2, 7)) bid_update = MBLUpdate(13.1, 4, 126) mbl = MBL(5) updated_book = mbl.update(book, bid_update) expected_book = Book() expected_book.add_bid(Level(13.1, 4, 126)) self.assertEqual(expected_book, updated_book)
def test_displays_nicely_a_MBL(self): book = Book() book.add_bid(Level(6.3, 4, 80)) book.add_bid(Level(4, 1, 5)) book.add_ask(Level(7, 1, 1)) book.add_ask(Level(10, 26, 150)) book.add_ask(Level(16, 17, 42)) expected_str = " BID | ASK \n" \ " +6.300000 x 80.000000 @ 4 | +7.000000 x 1.000000 @ 1\n" \ " +4.000000 x 5.000000 @ 1 | +10.000000 x 150.000000 @ 26\n" \ " | +16.000000 x 42.000000 @ 17" self.assertEqual(expected_str, str(book))
def test_displays_nicely_an_unaligned_book(self): book = Book() book.add_bid(Order(6.3, 80)) book.add_bid(Order(4, 5)) book.add_ask(Order(7, 1)) book.add_ask(Order(10, 150)) book.add_ask(Order(16, 42)) expected_str = " BID | ASK \n" \ " +6.300000 x 80.000000 | +7.000000 x 1.000000\n" \ " +4.000000 x 5.000000 | +10.000000 x 150.000000\n" \ " | +16.000000 x 42.000000" self.assertEqual(expected_str, str(book))
def test_updates_existing_bid(self): book = Book() book.add_bid(Level(11705.0, 1, 0.381988)) book.add_bid(Level(11704.0, 4, 0.955999)) book.add_bid(Level(11703.0, 1, 0.165141)) print(book) mbl = MBL(3) bid_update = MBLUpdate(11704.0, 3, 0.94745498) updated_book = mbl.update(book, bid_update) print(updated_book) expected_book = Book() expected_book.add_bid(Level(11705.0, 1, 0.381988)) expected_book.add_bid(Level(11704.0, 3, 0.94745498)) expected_book.add_bid(Level(11703.0, 1, 0.165141)) self.assertEqual(expected_book, updated_book)
def test_a_book_with_three_bid_lines_has_a_bid_depth_of_three(self): book = Book() book.add_bid(Level(7, 10, 2)) book.add_bid(Level(5, 10, 2)) book.add_bid(Level(4, 10, 2)) self.assertEqual(3, book.bid_depth())
def test_best_bid_is_the_greatest_price(self): book = Book() book.add_bid(Order(7, 10)) book.add_bid(Order(5, 10)) self.assertEqual(Order(7, 10), book.best_bid())