From engine to MIMS: checking a session
From executions to positions and cash: what a tester checks after a session.
Lesson 912 min
By the end of this lesson
- Follow an engine session through to the client account movements
- Check the allocation and the cash total to reveal an anomaly
- Choose the key that makes importing an executions file idempotent
In this lesson4
The engine stops at executions. For a brokerage firm, the day goes on: each execution must be linked to its clients' orders, move their positions and cash accounts, then settle at the central depository. Testing MIMS after a session means checking that this chain creates nothing and loses nothing.
The chain, screen by screen
1/6Orders
The order register (/fr/orders) lists the orders entered, checked by the Middle Office before forwarding.
The same chain, seen by the order: a fictional order crosses the screens, changes status, receives two executions at two different prices, then becomes a position. Watch the fill bar: it moves when each execution arrives, never at validation.
- client
- C-0042
- security
- KAPOK
- side
- buy
- quantity
- 40
- limit
- 10,100
filled 0/40
/en/orders/new
Order entry
Two market rules frame this chain. Every order is timestamped on receipt and forwarded to the BVMAC "without netting or aggregation" (BVMAC General Rules 2025, art. 150): each execution must therefore be linked to identifiable client orders. And trading is for cash: the former rules required the buyer to hold the funds and the seller the securities as soon as the order was placed (BVMAC General Rules 2008, art. 30).
Replay a session and check it
Two fictional brokerage firms, six invented clients, one auction. Step through: the engine's executions, then movements per client, then checks. Commissions are left aside: they do not come from the engine.
| order | client | asked | shares | cash |
|---|---|---|---|---|
| K-01 | AwaSDB Kapok | +40 × 10,100 | · | · |
| K-02 | BertrandSDB Kapok | -30 × 9,900 | · | · |
| K-03 | ChantalSDB Kapok | +20 × market | · | · |
| B-01 | DidierSDB Baobab | -50 × 10,000 | · | · |
| B-02 | EstherSDB Baobab | -20 × 10,100 | · | · |
| B-03 | FabriceSDB Baobab | +30 × 9,950 | · | · |
Notice three details the tester must be able to explain:
- Didier was selling 50 shares at 10,000, exactly the auction price, and only sells 30: Bertrand, more aggressive at 9,900, is filled in full first, and Didier gets the rest.
- Chantal, with a market order, is filled first, even though she arrived after Awa.
- Esther and Fabrice have no movement: their limits do not cross the price.
From memory: before any commission, what is the sum of all cash movements in a session, across all brokerage firms?
The tester's checklist
After a session, for each security:
- Orders: quantity executed less than or equal to the order's quantity; state consistent with that quantity.
- Allocation: the quantity allocated from an execution equals its quantity, no more and no less.
- Positions: change in each position = shares bought − shares sold by the client, execution by execution.
- Cash: change = sale amounts − purchase amounts − commissions; no negative balance without an authorised overdraft.
- Market: shares bought = shares sold; sum of cash zero before commissions.
- Price: the price used matches the one published in the Official Price List, which gives among other things the first and last prices, high and low (BVMAC General Rules 2025, art. 132).
- Replay: importing the same execution file twice must not count anything twice.
These checks are invariants in the sense of An engine's invariants: they must hold after every session, whatever the inputs. So test them as such, on generated sessions, not only on today's.
Who settles, and when? The BEAC has acted as central depository on a transitional basis since 2019 (BVMAC Annual Report 2024). The future single central depository was not operational at the end of 2025, and its current status is not confirmed. No text found sets the settlement delay: in tests, treat it as a parameter.
Going further
The zero-sum check, in code
Checks 3 to 5 fit in a few lines, from the executions alone. Take the session replayed above:
import { fixing, type Execution } from '@criee/marche'
const r = fixing(ordres, 10000) // the six orders of the session above
// r.prix 10000, r.volume 60
// [{ achat: 'K-03', vente: 'K-02', prix: 10000, quantite: 20 },
// { achat: 'K-01', vente: 'K-02', prix: 10000, quantite: 10 },
// { achat: 'K-01', vente: 'B-01', prix: 10000, quantite: 30 }]
const mouvements = r.executions.flatMap((e: Execution) => [
{ ordre: e.achat, titres: e.quantite, especes: -e.prix * e.quantite },
{ ordre: e.vente, titres: -e.quantite, especes: e.prix * e.quantite },
])
const somme = (k: 'titres' | 'especes') => mouvements.reduce((s, m) => s + m[k], 0)
expect(somme('titres')).toBe(0)
expect(somme('especes')).toBe(0)
Step by step: each execution gives two opposite movements, so the sum is zero by construction. This test checks nothing about the engine; it checks your translation. It becomes useful when the movements come from elsewhere: an import, a manual entry, a batch validation. Replace mouvements with what the back-office software actually produced, and the same test catches an execution recorded on one side only. Note the first line too: Chantal (K-03), served as a market order, comes before Awa (K-01) right down to the movements.
Importing twice without counting twice
Check 7 hides a design choice: the deduplication key. The safe key is the execution's reference, as the file transmits it.
function importer(registre: Map<string, Execution>, lignes: { ref: string; e: Execution }[]): number {
let ajoutees = 0
for (const { ref, e } of lignes) {
if (registre.has(ref)) continue // already imported
registre.set(ref, e)
ajoutees++
}
return ajoutees
}
const registre = new Map<string, Execution>()
importer(registre, fichier) // 3 (the three executions of the session)
importer(registre, fichier) // 0 (nothing is counted twice)
Pitfall. A key derived from the content (price, quantity, orders) looks handy, but two distinct executions can carry the same price and the same quantity: the second would be lost without any error. Edge case. In a file, "1.500" can read as 1,500 or 1.5 depending on the separator: the number parsing seen in Modelling an order must know the file's format, otherwise a quantity is silently divided by a thousand.
The lesson From an execution to entries continues the chain: how a validated execution becomes movements, commissions and entries.
From memory, lesson 1: what is the relationship between an order and its executions, and what does allocation change?
Your turn
Read next: Règlement général de la BVMAC (2025)
A question? Ask your teacher, or an AI assistant, giving it the title of this lesson.