コード例 #1
0
def test_basic_partial_fill_replenish_visible():
    n = NewOrderCommand(121234, 1234235.123, 2342, "user_x", MARKET, BID_SIDE, FAR, Price("34.52"), 100, 40)
    oec = OrderEventChain(n, LOGGER, MonotonicIntID())
    # now ack it
    ack = AcknowledgementReport(121235, 1234235.123, 2342, "user_x", MARKET, n, Price("34.52"), 100, 40)
    oec.apply_acknowledgement_report(ack)
    aggressor = NewOrderCommand(1111, 1234237.123, 22222, "user_y", MARKET, ASK_SIDE, FAR, Price("34.52"), 40)
    # now resting partial fill
    pf = PartialFillReport(121236, 1234237.123, 2342, "user_x", MARKET, aggressor, 40, Price("34.52"),
                           BID_SIDE, 99999, 100-40)
    oec.apply_partial_fill_report(pf)

    assert oec.open_exposure_requests() == []
    assert oec.current_exposure().price() == Price("34.52")
    assert oec.current_exposure().qty() == 100-40
    assert oec.visible_qty() == 40  # should have replenished
    assert oec.iceberg_peak_qty() == 40  # should not have changed
    assert oec.has_partial_fill()

    # now test the partial fill wipes out 40 more, so visible is min
    aggressor2 = NewOrderCommand(1114, 1234237.123, 33333, "user_y", MARKET, ASK_SIDE, FAR, Price("34.52"), 40)
    # now resting partial fill
    pf2 = PartialFillReport(121236, 1234237.123, 2342, "user_x", MARKET, aggressor2, 40, Price("34.52"),
                            BID_SIDE, 99999, 100-40-40)  # subtract out the size of 2 40 lot fills now
    oec.apply_partial_fill_report(pf2)
    assert oec.open_exposure_requests() == []
    assert oec.current_exposure().price() == Price("34.52")
    assert oec.current_exposure().qty() == 100-40-40
    assert oec.visible_qty() == 100-40-40  # should have replenished to min of 40 and 100-40-40
    assert oec.iceberg_peak_qty() == 40  # should not have changed
    assert oec.has_partial_fill()
コード例 #2
0
def test_close_exposure_cancel_closes_all():
    id_gen = MonotonicIntID(seed=23043, increment=1)
    n = NewOrderCommand(id_gen.id(), 1234235.123, 2342, "user_x", MARKET, BID_SIDE, FAR, Price("34.52"), 1000)
    oec = OrderEventChain(n, LOGGER, MonotonicIntID())
    # should have 1 open exposure
    assert len(oec.open_exposure_requests()) == 1
    assert oec.most_recent_requested_exposure() == Exposure(Price("34.52"), 1000, id_gen.last_id())

    cr = CancelReplaceCommand(id_gen.id(), 1234235.863, 2342, "user_x", MARKET, BID_SIDE, Price("34.51"), 800)
    oec.apply_cancel_replace_command(cr)
    # now should have 2 open exposures
    assert len(oec.open_exposure_requests()) == 2
    assert oec.open_exposure_requests()[1] == Exposure(Price("34.51"), 800, id_gen.last_id())
    assert oec.most_recent_requested_exposure() == Exposure(Price("34.51"), 800, id_gen.last_id())

    cancel_command = CancelCommand(id_gen.id(), 1234274.663, 2342, "user_x", MARKET, CancelReasons.USER_CANCEL)
    oec.apply_cancel_command(cancel_command)
    # now should have 3 open exposures
    assert len(oec.open_exposure_requests()) == 3
    assert oec.open_exposure_requests()[2] == Exposure(None, 0, id_gen.last_id())
    assert oec.most_recent_requested_exposure() == Exposure(None, 0, id_gen.last_id())

    cancel_confirm = CancelReport(id_gen.id(), 1234278.663, 2342, "user_x", MARKET, cancel_command, CancelReasons.USER_CANCEL)
    oec.apply_cancel_report(cancel_confirm)
    # all exposures should be closed now
    assert len(oec.open_exposure_requests()) == 0
    assert oec.most_recent_requested_exposure() is None
    assert oec.has_partial_fill() is False
コード例 #3
0
def test_basic_partial_fill():
    n = NewOrderCommand(121234, 1234235.123, 2342, "user_x", MARKET, BID_SIDE, FAR, Price("34.52"), 1000)
    oec = OrderEventChain(n, LOGGER, MonotonicIntID())
    # now ack it
    ack = AcknowledgementReport(121235, 1234235.123, 2342, "user_x", MARKET, n, Price("34.52"), 1000, 1000)
    oec.apply_acknowledgement_report(ack)
    aggressor = NewOrderCommand(1111, 1234237.123, 22222, "user_x", MARKET, ASK_SIDE, FAR, Price("34.52"), 44)
    # now resting partial fill
    pf = PartialFillReport(121236, 1234237.123, 2342, "user_x", MARKET, aggressor, 44, Price("34.52"),
                           BID_SIDE, 99999, 1000-44)
    oec.apply_partial_fill_report(pf)

    assert oec.open_exposure_requests() == []
    assert oec.current_exposure().price() == Price("34.52")
    assert oec.current_exposure().qty() == 1000-44
    assert oec.visible_qty() == 1000-44
    assert oec.iceberg_peak_qty() == 1000  # should not have changed
    assert oec.has_partial_fill()