def test_full_fill_on_unacked_cr_with_acked_new_order(): n = NewOrderCommand(1, 1234235.123, 2342, "user_x", MARKET, BID_SIDE, FAR, Price("34.52"), 1000) oec = OrderEventChain(n, LOGGER, MonotonicIntID()) # now ack it ack = AcknowledgementReport(2, 1234235.123, 2342, "user_x", MARKET, n, Price("34.52"), 1000, 1000) oec.apply_acknowledgement_report(ack) assert oec.visible_qty() == 1000 assert oec.current_exposure().qty() == 1000 assert oec.current_exposure().price() == Price("34.52") assert len(oec.open_exposure_requests()) == 0 assert oec.is_open() cr = CancelReplaceCommand(3, 1234236.842, 2342, "user_x", MARKET, BID_SIDE, Price("34.56"), 800) oec.apply_cancel_replace_command(cr) # now should have 2 open exposures assert oec.visible_qty() == 1000 assert oec.current_exposure().qty() == 1000 assert oec.current_exposure().price() == Price("34.52") assert oec.is_open() assert len(oec.open_exposure_requests()) == 1 assert oec.most_recent_requested_exposure() == Exposure(Price("34.56"), 800, 3) full_fill = FullFillReport(4, 1234237.123, 2342, "user_x", MARKET, cr, 800, Price("34.56"), BID_SIDE, 12345) oec.apply_full_fill_report(full_fill) assert oec.visible_qty() == 0 assert oec.current_exposure().price() is None assert oec.current_exposure().qty() == 0 assert oec.current_exposure().causing_event_id() == 4 assert len(oec.open_exposure_requests()) == 0 assert oec.is_open() is False
def test_full_fill_with_too_much_size_on_unacked_new_order(): # should balk but shouldn't keep it from working n = NewOrderCommand(1, 1234235.123, 2342, "user_x", MARKET, BID_SIDE, FAR, Price("34.52"), 1000) oec = OrderEventChain(n, LOGGER, MonotonicIntID()) assert oec.visible_qty() == 0 assert oec.current_exposure() is None assert oec.most_recent_requested_exposure().price() == Price("34.52") assert oec.most_recent_requested_exposure().qty() == 1000 assert oec.is_open() full_fill = FullFillReport(3, 1234237.123, 2342, "user_x", MARKET, n, 17, Price('34.52'), BID_SIDE, 12345) oec.apply_full_fill_report(full_fill) assert oec.visible_qty() == 0 assert oec.current_exposure().price() is None assert oec.current_exposure().qty() == 0 assert oec.current_exposure().causing_event_id() == 3 assert oec.is_open() is False
def test_basic_full_fill_on_unacked_order(): n = NewOrderCommand(1, 1234235.123, 2342, "user_x", MARKET, BID_SIDE, FAR, Price("34.52"), 1000) oec = OrderEventChain(n, LOGGER, MonotonicIntID()) assert oec.visible_qty() == 0 assert oec.current_exposure() is None assert oec.most_recent_requested_exposure().price() == Price("34.52") assert oec.most_recent_requested_exposure().qty() == 1000 assert oec.is_open() full_fill = FullFillReport(3, 1234237.123, 2342, "user_x", MARKET, n, 1000, Price('34.52'), BID_SIDE, 12345) oec.apply_full_fill_report(full_fill) assert oec.visible_qty() == 0 assert oec.current_exposure().price() is None assert oec.current_exposure().qty() == 0 assert oec.current_exposure().causing_event_id() == 3 assert len(oec.open_exposure_requests()) == 0 assert oec.is_open() is False
def test_basic_full_fill_on_acked_order(): n = NewOrderCommand(1, 1234235.123, 2342, "user_x", MARKET, BID_SIDE, FAR, Price("34.52"), 1000) oec = OrderEventChain(n, LOGGER, MonotonicIntID()) # now ack it ack = AcknowledgementReport(2, 1234235.123, 2342, "user_x", MARKET, n, Price("34.52"), 1000, 1000) oec.apply_acknowledgement_report(ack) assert oec.visible_qty() == 1000 assert oec.current_exposure().qty() == 1000 assert oec.current_exposure().price() == Price("34.52") assert oec.is_open() aggressor = NewOrderCommand(1111, 1234237.123, 22222, "user_y", MARKET, ASK_SIDE, FAR, Price("34.52"), 1000) full_fill = FullFillReport(3, 1234237.123, 2342, "user_x", MARKET, aggressor, 1000, Price('34.52'), BID_SIDE, 12345) oec.apply_full_fill_report(full_fill) assert oec.visible_qty() == 0 assert oec.current_exposure().price() is None assert oec.current_exposure().qty() == 0 assert oec.current_exposure().causing_event_id() == 3 assert oec.is_open() is False
def test_partial_fill_to_zero_closes_out_order(): # when a partialfill closses out to an order there should be a balking because it is a paritial fill so shouldn't happen, but should allow n = NewOrderCommand(121234, 1234235.123, 2342, "user_x", MARKET, BID_SIDE, FAR, Price("34.52"), 100) oec = OrderEventChain(n, LOGGER, MonotonicIntID()) # now ack it ack = AcknowledgementReport(121235, 1234235.123, 2342, "user_x", MARKET, n, Price("34.52"), 100, 100) oec.apply_acknowledgement_report(ack) aggressor = NewOrderCommand(1111, 1234237.123, 22222, "user_y", MARKET, ASK_SIDE, FAR, Price("34.52"), 100) # now resting partial fill pf = PartialFillReport(1212344, 1234237.123, 2342, "user_x", MARKET, aggressor, 100, Price("34.52"), BID_SIDE, 99999, 0) oec.apply_partial_fill_report(pf) assert oec.open_exposure_requests() == [] assert oec.is_open() is False assert oec.visible_qty() == 0 assert oec.current_exposure() == Exposure(None, 0, 1212344)