def test_update(): level = Level(price=10.0) order = Order(price=10.0, size=100.0, side=OrderSide.BUY) level.add(order) assert level.volume() == 100.0 order.update_size(size=50.0) level.update(order=order) assert level.volume() == 50.0
def test_level_comparison(): level1 = Level(price=10.0) level2 = Level(price=11.0) level1.add(Order(price=10.0, size=0.0, side=OrderSide.BUY)) level2.add(Order(price=11.0, size=0.0, side=OrderSide.BUY)) assert level2 >= level1 assert level1 < level2 assert level1 != level2
def test_delete_order(): level = Level(price=100.0) orders = [ Order(price=100.0, size=50.0, side=OrderSide.BUY, id="1"), Order(price=100.0, size=50.0, side=OrderSide.BUY, id="2"), ] level.bulk_add(orders=orders) level.delete(order=orders[1]) assert level.volume() == 50.0
def test_update(): order = Order(price=10, volume=100, side=OrderSide.BUY) level = Level(orders=[order]) assert level.volume() == 100 order.update_volume(volume=50) level.update(order=order) assert level.volume() == 50
def empty_level(): return Level()
def test_level_repr(): level = Level(price=10.0) level.add(Order(price=10.0, size=0.0, side=OrderSide.BUY, id="1")) expected = "Level(price=10.0, orders=[Order(10.0, 0.0, BUY, 1)])" assert str(level) == expected
def test_zero_volume_level(): level = Level(price=10.0) level.bulk_add(orders=[Order(price=10.0, size=0.0, side=OrderSide.BUY)]) assert level.volume() == 0.0
def test_add(): level = Level(price=10.0) order = Order(price=10.0, size=100.0, side=OrderSide.BUY, id="1") level.add(order=order) assert len(level.orders) == 1
def test_init(): level = Level(price=10.0) assert len(level.orders) == 0