wired = namespace(db=, broker_box=namespace(broker=)) def test_does_not_mark_when_broker_has_matching_sells(wired): # Broker HAS matching sells → reconcile_exits_from_alpaca owns this case (the fill-aware # path). The unmirrored marker must NOT stamp here or it would lose the real fill numbers. _seed_closed_row(wired.db, entry_coid="mktstate-bull-TNA-cuixia", account_nick="cuixia", sym="TNA", shares=100, entry_px=70.0, hh=10, mm=0) wired.broker_box.broker = _FakeBroker([_sell(15, 17, 60, 70.0), _sell(15, 18, 40, 70.0)]) > res = mse.reconcile_external_unmirrored_closes(DAY.isoformat(), now=NOW, accounts=["cuixia"]) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ tests/services/test_market_state_etf_external_unmirrored.py:216: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ rtrader/services/market_state_etf.py:4014: in reconcile_external_unmirrored_closes return {"marked": _count_unmirrored_stamped( rtrader/services/market_state_etf.py:4069: in _count_unmirrored_stamped n += coll.count_documents({ tests/services/test_market_state_etf_external_unmirrored.py:67: in count_documents return sum(1 for d in self.docs if self._matches(d, q)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ tests/services/test_market_state_etf_external_unmirrored.py:67: in return sum(1 for d in self.docs if self._matches(d, q)) ^^^^^^^^^^^^^^^^^^^ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ doc = {'_id': 'fake_1', 'account_nick': 'cuixia', 'created_at': datetime.datetime(2026, 7, 23, 14, 0, tzinfo=datetime.timezone.utc), 'entry_attributes': {'leg': 'bull', 'origin': 'manual'}, ...} q = {'account_nick': 'cuixia', 'entry_trading_day': '2026-07-23', 'exit.unmirrored': True, 'status': 'closed', ...} @staticmethod def _matches(doc, q): for k, v in q.items(): if "." in k: top, sub = k.split(".", 1) > if doc.get(top, {}).get(sub) != v: ^^^^^^^^^^^^^^^^^^^^ E AttributeError: 'NoneType' object has no attribute 'get' tests/services/test_market_state_etf_external_unmirrored.py:95: AttributeError