Task: Import ORE trades onto the anchor and its components

Table of Contents

This page documents a task in the Split the trade into an anchor and its components story. It captures the goal, current status, acceptance, and any notes or results.

1. Goal

An imported ORE trade lives in the anchor and its components, with its envelope resolved to entities: a counterparty or netting set that does not resolve rejects the trade.

2. Status

Field Value
State DONE
Parent story Split the trade into an anchor and its components
Now Nothing.
Waiting on Nothing.
Next Nothing.
Last touched 2026-10-04

3. Acceptance

  • The import books each trade's anchor, booking and state in one write, with entry channel stp.
  • ORE's Trade/@id is a trade_identifier row under the ORE scheme, and each envelope additional field is a trade_additional_field row.
  • An envelope counterparty is resolved by name; a name that matches no counterparty is an item error and nothing is written for the trade. The default counterparty applies only when the envelope names none.
  • An envelope netting set is resolved through its ORE alias; one that resolves to none rejects the trade.
  • The wide trade and the envelope are still written, so export and the instruments keep working until their own tasks.
  • Build, ctest, pgTAP and the local check set pass.

4. Plan

The import resolves the envelope before it writes anything, then books the trade, then writes the wide trade the instruments still reference.

  • The counterparty: the envelope's CounterParty as an ORE counterparty identifier, then as a short code. A name that matches none rejects the trade. The import's default counterparty applies only when the envelope names none.
  • The netting set: the envelope's NettingSetId as an ORE netting set identifier. An id that matches none rejects the trade (owner's choice: the sample netting dataset carries the aliases, instead of the import creating sets). A trade with no NettingSetId books with no netting set, as in ORE.
  • The booking comes first. The anchor, booking and state are one write whose pins check the book, counterparty and netting set against the trade's party, so a trade the booking refuses leaves nothing behind. The booking is stp and actual; the scope is external when the trade has a counterparty. ORE's Trade/@id becomes an ORE trade identifier, and the envelope's additional fields become rows in the document's order.
  • The trade date becomes optional on the booking: ORE documents may omit it.
  • The instrument step skips a trade the trade step did not save, so a rejected trade reports its one reason.

5. Measurements

Every number this task claims about a tree, with the command that produced it and the commit it was measured at. A number without both is not a measurement, because a clean-up record describes a tree and trunk moves under a branch: a consumer count, a gate's component count and a suite's size all change with no code changing, and the reader of a bare number cannot tell which tree it came from. Where the raw output matters, put it in an evidence/ file beside the task and name that file in the Command column.

What Value Command Commit
Example_63 import: trades booked onto the anchor 4 of 4, counterparties and netting sets resolved through ORE aliases round-trip recipe, then the query in evidence/ore_import_onto_the_anchor.txt branch head before commit
Example_63 round trip, in-scope pairs lost 0, unexplained 0 scripts/ore_mapper_roundtrip_diff.py branch head before commit
Unknown counterparty and netting set id 2 trades rejected, one reason each, nothing written the same evidence file branch head before commit

6. Notes

  • Follow-up: the identifier get request matches on the value alone and returns one row, which the import then checks for the ORE scheme. A value that another scheme also holds can hide an ORE alias. A lookup by scheme and value would close it.
  • Follow-up: the handler has no automated test; it needs a service harness with NATS. The live runs in the evidence file stand in for it.
  • Seen, not changed: the CDS instrument of Example_63 fails the credit tenor check in the instrument step, which this task does not touch.
  • The anchor's identifier and additional fields are written after the booking. A failure there leaves a booked anchor without them and skips the wide trade; the import reports it against the trade.

7. Test Scenarios

Manual QA scenarios (scaffolded via compass add test_scenario) that verify this task. Link new ones here as they're created; the scenario doc itself links back via its "Verifies task" field.

Scenario State Notes
     

8. PRs

PR Title
#2603 [ore] Import ORE trades onto the anchor

9. Review

# Comment summary File Decision Notes
1 The WIP wrote the wide trade before the booking, so a refused booking left a wide trade behind. ore_import_execute_handler.cpp Accept The booking is written first.
2 The instrument step saved instruments for trades the trade step rejected, adding a second, misleading error. ore_import_execute_handler.cpp Accept It skips trades the trade step did not save.
3 The WIP created a netting set the tenant lacked. ore_import_execute_handler.cpp Accept Owner's choice: resolve through the ORE alias and reject an unresolved id.
4 PR 2603 review 1: a failed wide-trade write after the booking leaves an orphan anchor; is a re-import safe? ore_import_execute_handler.cpp Decline The planner gives every trade a fresh id each run, so a re-import never meets the earlier anchor; the wide trade is removed later in this story. Recorded in the notes.
5 PR 2603 review 2: a partial set of additional fields after a failure, and stale sequence rows on re-import. ore_import_execute_handler.cpp Decline Fresh trade ids per run, as above.
6 PR 2603 review 3: a lookup error reads as "matches no counterparty". ore_import_execute_handler.cpp Accept An outcome other than ok or missing is reported as the error it is.
7 PR 2603 review 4: a trade with no counterparty becomes intra_entity. ore_import_execute_handler.cpp Decline The anchor's check requires a counterparty for an external trade.
8 PR 2603 review 6: unit test the resolvers with a fake transport. ore_import_execute_handler.cpp Decline They are file-local to the service handler; the handler test harness is the recorded follow-up.
9 CI shell-script drift: the trade booking scripts and the scripts of three earlier recipes were not tangled. projects/ores.shell/scripts/library Accept Tangled and committed. The local check list lacks the tangle check; fixed in the skill separately.

10. Result

An ORE import now books every trade onto the anchor, its booking and its state, records ORE's Trade/@id as an ORE trade identifier and the envelope's additional fields as rows, and still writes the wide trade the instruments reference. The envelope's counterparty and netting set resolve through their ORE aliases. A name that resolves to neither rejects the trade before anything is written. Against the ACME tenant, Example_63 books all four trades onto the sample banks and netting sets, and its envelope round trips with no loss.

Emacs 29.3 (Org mode 9.6.15)