Beispiel #1
0
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
Beispiel #2
0
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
Beispiel #3
0
def check_for_trade(orderbook, order: Order):
    """
    Run an auction match on this order to see if any would trade
    :param order:
    :return: trade, order
    """
    ladder_trades, order_trades = auction_match(other=Ladder.from_orders([order]))
    traded_volume = sum((t.volume for t in ladder_trades))

    remaining_order = None
    if order.volume != traded_volume:
        remaining_order = Order(
            price=order.price,
            volume=order.volume - traded_volume,
            side=order.side,
        )

    return ladder_trades, remaining_order
Beispiel #4
0
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
Beispiel #5
0
def test_init():
    ladder = Ladder(reverse=False, price_precision=2, size_precision=2)
    assert ladder
Beispiel #6
0
 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