From an execution to entries
Securities movements, cash movements, commissions and reversal: the conversion on the back-office side.
Lesson 1210 min
By the end of this lesson
- Turn an execution into securities and cash movements carrying its reference
- Check that the movements of all accounts, commissions included, cancel out
- Correct a wrong execution by a reversing entry, without deleting anything
The engine stops at the Execution object: a buyer, a seller, a price, a quantity. The lesson From engine to MIMS showed the chain that follows, screen by screen. This one goes one level down, into back-office code: how an execution becomes movements, commissions and entries, and how to undo it without erasing anything.
What the texts set
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). The BVMAC sends trading data to the central depository, to guarantee delivery of the securities and payment of the price (BVMAC General Rules 2025, art. 220 and 231). In MIMS, batch validation of executions freezes the commission and produces securities movements, cash movements and entries; a validated execution can be reversed, by two people.
Movement
An entry that changes a position (securities movement) or a cash account (cash movement).
One execution, seven movements
An execution between two clients produces two securities movements (the buyer receives, the seller delivers), two cash movements for the price, and commissions. The type below is a design choice of this course; each movement carries the reference of its execution.
import type { Execution } from '@criee/marche'
type Mouvement =
| { type: 'titres'; compte: string; quantite: number; execution: string }
| { type: 'especes'; compte: string; montant: number; motif: 'prix' | 'commission'; execution: string }
interface Comptes { achat: string; vente: string; commissions: string }
function enMouvements(e: Execution, ref: string, c: Comptes, tauxPourDixMille: number): Mouvement[] {
const montant = e.prix * e.quantite // integer, in francs
const commission = Math.round((montant * tauxPourDixMille) / 10_000) // rounding: a decision
return [
{ type: 'titres', compte: c.achat, quantite: +e.quantite, execution: ref },
{ type: 'titres', compte: c.vente, quantite: -e.quantite, execution: ref },
{ type: 'especes', compte: c.achat, montant: -montant, motif: 'prix', execution: ref },
{ type: 'especes', compte: c.vente, montant: +montant, motif: 'prix', execution: ref },
{ type: 'especes', compte: c.achat, montant: -commission, motif: 'commission', execution: ref },
{ type: 'especes', compte: c.vente, montant: -commission, motif: 'commission', execution: ref },
{ type: 'especes', compte: c.commissions, montant: 2 * commission, motif: 'commission', execution: ref },
]
}
Writing for the price, for the quantity and for the commission rate per ten thousand, the amount and the commission charged on each side are, before rounding:
Across all accounts, commissions included, the cash movements cancel out: .
Commission rates come from no source in this course: 0.5% (50 per ten thousand) is a fictional parameter. In reality each brokerage firm charges its own client; the two commissions are gathered here in one account for readability. In MIMS, the commission comes from the configured fee schedule and is frozen at validation.
Awa buys 30 shares from DidierFictional
Didier's sell B-01 is resting: 30 shares at 10,000. Awa's buy K-01 arrives at 10,100. carnet.passer returns { achat: 'K-01', vente: 'B-01', prix: 10000, quantite: 30 }, at the price of the resting order.
- Amount: 10,000 × 30 = 300,000 francs.
- Commission, at the fictional rate of 50 per ten thousand: 300,000 × 50 / 10,000 = 1,500 francs, on each side.
- Shares: +30 for Awa, −30 for Didier. Sum: 0.
- Cash: −300,000 − 1,500 for Awa, +300,000 − 1,500 for Didier, +3,000 in commissions. Sum: 0.
Run the scene: the movements drop into the accounts, the balances are repainted, then the reversal brings everything back to the start.
Execution
Shares, Awa
0
Cash, Awa
500,000
Shares, Didier
50
Cash, Didier
0
Commissions
0
Execution
An execution arrives
From memory: after commissions, do the cash movements of the clients alone sum to zero?
Undoing without erasing
An execution validated by mistake is not deleted. The opposite movements are added, with the same execution reference: balances return to their starting value, and the history keeps the error and its correction.
Reversal
An opposite entry that cancels the effect of a wrong entry without erasing it.
const contrePasser = (ms: Mouvement[]): Mouvement[] =>
ms.map((m) => (m.type === 'titres' ? { ...m, quantite: -m.quantite } : { ...m, montant: -m.montant }))
// enMouvements(...) then contrePasser(...): 14 movements, every per-account sum at 0
This is the same principle as the append-only log in the lesson Logging and replaying a session: you correct by adding.
Going further
The execution has no identifier. The engine's Execution type carries neither number nor timestamp. Yet idempotence needs a key: without it, importing the same file twice counts everything twice (check no. 7 in lesson 9). The reference must come from outside, from the market or the import, and travel with every movement.
const integrees = new Set<string>()
function integrer(ref: string, ms: Mouvement[]): Mouvement[] {
if (integrees.has(ref)) return [] // already counted: do nothing again
integrees.add(ref)
return ms
}
integrer('EX-1', ms).length // 7
integrer('EX-1', ms).length // 0
Rounding commissions. On 70,350 francs (7 shares at 10,050), 50 per ten thousand gives 351.75. Math.round gives 352, Math.floor 351. Both choices can be defended; what cannot be is computing in floats and rounding at display time. Fix the rule in the specification and in a test, and keep every amount as an integer.
The average price is not an integer. Awa, filled for 25 shares at 10,050 and 15 at 10,100, paid 402,750 francs for 40 shares: a weighted average price of 10,068.75. Store the quantity and the total amount, which are exact, and derive the average price for display. MIMS computes this average price at validation: a good test case, with data that does not come out round.
The settlement date is a parameter. No text found sets the settlement period at the BVMAC; the Official Price List computes accrued interest at T+3, which is only a clue (Official Price List of 02/09/2026). A movement carries a value date computed from a parameter, never from a constant.
From memory, linking to the lesson on modelling an order: up to what amount does price × quantity stay exact as a number, and what then?
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.