fix: bracket fills stay on legs; by-tag lookup surfaces entry-leg fill
General translation must not echo leg fills onto the OTOCO parent — flatten_fills adds parent AND legs, double-counting entries in journal reconstruction. The cancel-vs-fill reconcile still sees executed shares: get_order_by_client_order_id surfaces the entry leg's fill on its result. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a2de50479a
commit
80422d91cd
2 files changed
+39
-8
No files matched your search
@@ -81,7 +81,9 @@ class TranslateOrderTests(unittest.TestCase):
|
||||
self.assertEqual(o["symbol"], "DAMD")
|
||||
self.assertEqual(o["side"], "buy")
|
||||
self.assertEqual(o["qty"], "8000")
|
||||
self.assertEqual(o["filled_qty"], "8000")
|
||||
# fills stay on legs only — parent echoing them double-counts in
|
||||
# journal reconstruction (flatten_fills adds parent AND legs)
|
||||
self.assertEqual(o["filled_qty"], "0")
|
||||
# the stop leg is findable the way exit_manager._stop_leg looks
|
||||
stops = [leg for leg in o["legs"] if leg["type"] == "stop"
|
||||
and leg["side"] == "sell" and leg["symbol"] == "DAMD"]
|
||||
@@ -271,3 +273,19 @@ class CancelRacedFillTests(unittest.TestCase):
|
||||
emitted = [c.args[0].__class__.__name__ for c in store.emit.call_args_list]
|
||||
self.assertIn("OrderCancelledEvent", emitted)
|
||||
self.assertNotIn("OrderFilledEvent", emitted)
|
||||
|
||||
|
||||
class ByTagLookupFillTests(unittest.TestCase):
|
||||
def test_lookup_surfaces_entry_leg_fill_on_bracket(self):
|
||||
client = TradierClient(SETTINGS)
|
||||
raw = [{"id": 1, "class": "otoco", "status": "open", "tag": "cid-9",
|
||||
"leg": [{"id": 2, "symbol": "DAMD", "side": "buy", "quantity": 8000,
|
||||
"type": "limit", "status": "filled",
|
||||
"exec_quantity": 8000, "avg_fill_price": 1.96},
|
||||
{"id": 3, "symbol": "DAMD", "side": "sell", "type": "stop",
|
||||
"status": "open", "stop_price": 1.8}]}]
|
||||
with patch.object(client, "_orders_raw", return_value=raw):
|
||||
found = client.get_order_by_client_order_id("cid-9")
|
||||
self.assertEqual(found["filled_qty"], "8000")
|
||||
self.assertEqual(found["filled_avg_price"], "1.96")
|
||||
self.assertEqual(found["status"], "filled")
|
||||
Reference in new issue
Block a user