@@ -4634,6 +4634,75 @@ async def counting_query(instrument_id, clients):
46344634 assert len (queries ) == 1
46354635
46364636
4637+ @pytest .mark .asyncio
4638+ async def test_position_activity_stamped_from_receipt_time_for_venue_ahead_fill (
4639+ live_exec_engine ,
4640+ exec_client ,
4641+ cache ,
4642+ ):
4643+ # Arrange
4644+ live_exec_engine .register_client (exec_client )
4645+ live_exec_engine .generate_missing_orders = False
4646+ live_exec_engine ._position_check_threshold_ns = 0
4647+
4648+ account = AccountId ("SIM-A" )
4649+ order = TestExecStubs .limit_order (instrument = AUDUSD_SIM , order_side = OrderSide .BUY )
4650+ order .apply (TestEventStubs .order_submitted (order , account_id = account ))
4651+ order .apply (TestEventStubs .order_accepted (order , account_id = account ))
4652+ cache .add_order (order , position_id = None )
4653+
4654+ venue_ahead_ns = live_exec_engine ._clock .timestamp_ns () + 900 * 86_400 * 1_000_000_000
4655+ fill = TestEventStubs .order_filled (
4656+ order ,
4657+ instrument = AUDUSD_SIM ,
4658+ account_id = account ,
4659+ trade_id = TradeId ("T-AXIS-1" ),
4660+ last_qty = Quantity .from_int (1000 ),
4661+ last_px = Price .from_str ("1.00000" ),
4662+ ts_event = venue_ahead_ns ,
4663+ )
4664+
4665+ # Act
4666+ live_exec_engine ._handle_event_with_tracking (fill )
4667+
4668+ # Assert - stamp is on the local clock axis
4669+ stamp = live_exec_engine ._position_local_activity_ns [(AUDUSD_SIM .id , account )]
4670+ assert stamp <= live_exec_engine ._clock .timestamp_ns ()
4671+ assert stamp != venue_ahead_ns
4672+
4673+ # A cached position with no venue report: a genuine discrepancy
4674+ order_b = TestExecStubs .limit_order (instrument = AUDUSD_SIM , order_side = OrderSide .BUY )
4675+ fill_b = TestEventStubs .order_filled (
4676+ order_b ,
4677+ instrument = AUDUSD_SIM ,
4678+ account_id = account ,
4679+ trade_id = TradeId ("T-AXIS-2" ),
4680+ last_qty = Quantity .from_int (1000 ),
4681+ last_px = Price .from_str ("1.00000" ),
4682+ position_id = PositionId ("P-AXIS-B" ),
4683+ )
4684+ position = Position (instrument = AUDUSD_SIM , fill = fill_b )
4685+ cache .add_position (position , OmsType .HEDGING )
4686+
4687+ queries = []
4688+
4689+ async def counting_query (instrument_id , clients ):
4690+ queries .append (instrument_id )
4691+ return [], False
4692+
4693+ live_exec_engine ._query_and_find_missing_fills = counting_query
4694+
4695+ # Act - zero threshold: a receipt-time stamp is already expired, a venue-axis
4696+ # stamp would make the delta negative and suppress forever
4697+ await live_exec_engine ._process_cached_position_discrepancies (
4698+ {(AUDUSD_SIM .id , account ): [position ]},
4699+ {},
4700+ )
4701+
4702+ # Assert - the grace does not suppress the discrepancy query
4703+ assert len (queries ) == 1
4704+
4705+
46374706@pytest .mark .asyncio
46384707async def test_check_positions_consistency_processes_only_discrepant_account (
46394708 live_exec_engine ,
0 commit comments