def ladder(): ladder = Ladder() orders = [ Order(price=100, volume=10, side=OrderSide.SELL), Order(price=100, volume=1, side=OrderSide.SELL), Order(price=105, volume=20, side=OrderSide.SELL), ] for order in orders: ladder.add(order=order) return ladder
def test_simulate_order_fills_l3(): ladder = Ladder(False, 4, 4) orders = [ Order(price=15, volume=1, side=OrderSide.SELL, id="1"), Order(price=16, volume=2, side=OrderSide.SELL, id="2"), Order(price=16, volume=3, side=OrderSide.SELL, id="3"), Order(price=20, volume=10, side=OrderSide.SELL, id="4"), ] for order in orders: ladder.add(order) fills = ladder.simulate_order_fills( order=Order(price=16.5, volume=4, side=OrderSide.BUY, id="1")) expected = [ (Price("15.0000"), Quantity("1.0000")), (Price("16.0000"), Quantity("2.0000")), (Price("16.0000"), Quantity("1.0000")), ] assert fills == expected
def test_insert(): orders = [ Order(price=100.0, volume=10.0, side=OrderSide.BUY), Order(price=100.0, volume=1.0, side=OrderSide.BUY), Order(price=105.0, volume=20.0, side=OrderSide.BUY), ] ladder = Ladder(reverse=False, price_precision=0, size_precision=0) for order in orders: ladder.add(order=order) ladder.add(order=Order(price=100.0, volume=10.0, side=OrderSide.BUY)) ladder.add(order=Order(price=101.0, volume=5.0, side=OrderSide.BUY)) ladder.add(order=Order(price=101.0, volume=5.0, side=OrderSide.BUY)) expected = [ (100, 21), (101, 10), (105, 20), ] result = [(level.price, level.volume()) for level in ladder.levels] assert result == expected
def ladder(reverse: bool, orders: List[Order]): ladder = Ladder(reverse=reverse, price_precision=2, size_precision=2) for order in orders: ladder.add(order) return ladder