Example #1
0
def test_orderbook_replace_price_and_size():
    order = Order("TEST", 23.54, 100, "B", 2, "NEWORDER_1", "TESTSESSION")
    orderbook = Orderbook("TEST")

    orderbook.new_order(order)

    order = Order("TEST", 23.55, 120, "B", 2, "NEWORDER_2", "TESTSESSION")

    orderbook.replace_order("NEWORDER_1", order)

    assert orderbook.bids[23.55][0].quantity == 120
    assert orderbook.bids[23.55][0].price == 23.55
Example #2
0
def test_orderbook_replace_size():
    order = Order("TEST", 23.54, 100, "B", 2, "NEWORDER_1", "TESTSESSION")
    orderbook = Orderbook("TEST")

    orderbook.new_order(order)

    print(orderbook._show_orderbook())

    order = Order("TEST", 23.54, 120, "B", 2, "NEWORDER_2", "TESTSESSION")

    orderbook.replace_order("NEWORDER_1", order)

    print(orderbook._show_orderbook())

    assert orderbook.bids[23.54][0].quantity == 120
Example #3
0
def test_orderbook_replace_execution_deletion():
    orderbook = Orderbook("TEST")

    order = Order("TEST", 23.54, 150, "B", 2, "TESTSESSION_1_NEWORDER_1",
                  "TESTSESSION_1")
    orderbook.new_order(order)

    order = Order("TEST", 23.54, 250, "B", 2, "TESTSESSION_3_NEWORDER_1",
                  "TESTSESSION_3")
    orderbook.new_order(order)

    order = Order("TEST", 23.57, 130, "S", 2, "TESTSESSION_2_NEWORDER_1",
                  "TESTSESSION_2")
    orderbook.new_order(order)

    order = Order("TEST", 23.59, 120, "S", 2, "TESTSESSION_2_NEWORDER_2",
                  "TESTSESSION_2")
    orderbook.new_order(order)

    assert orderbook.bbo() == (23.54, 23.57)

    order = Order("TEST", 23.56, 350, "B", 2, "TESTSESSION_3_NEWORDER_2",
                  "TESTSESSION_3")
    orderbook.replace_order("TESTSESSION_3_NEWORDER_1", order)

    assert orderbook.bbo() == (23.56, 23.57)
    # orderbook.delete_order("TESTSESSION_2_NEWORDER_1")

    order = Order("TEST", 23.56, 351, "S", 2, "TESTSESSION_2_NEWORDER_3",
                  "TESTSESSION_2")
    orderbook.replace_order("TESTSESSION_2_NEWORDER_2", order)

    assert orderbook.trades.qsize() == 2

    assert orderbook.bbo() == (23.54, 23.56)

    while not orderbook.trades.empty():
        trade = orderbook.trades.get()

        assert trade.price == 23.56
        assert trade.quantity == 350

    orderbook.delete_order("TESTSESSION_2_NEWORDER_3")

    assert orderbook.bbo() == (23.54, 23.57)
Example #4
0
def test_orderbook_replace_execution():
    orderbook = Orderbook("TEST")

    order = Order("TEST", 23.54, 150, "B", 2, "TESTSESSION_1_NEWORDER_1",
                  "TESTSESSION_1")
    orderbook.new_order(order)

    order = Order("TEST", 23.55, 130, "S", 2, "TESTSESSION_2_NEWORDER_1",
                  "TESTSESSION_2")
    orderbook.new_order(order)

    order = Order("TEST", 23.55, 140, "B", 2, "TESTSESSION_1_NEWORDER_2",
                  "TESTSESSION_1")
    orderbook.replace_order("TESTSESSION_1_NEWORDER_1", order)

    assert orderbook.trades.qsize() == 2

    while not orderbook.trades.empty():
        trade = orderbook.trades.get()

        assert trade.price == 23.55
        assert trade.quantity == 130

    assert orderbook.bbo() == (23.55, float("inf"))