Skip to content
Criée

The auction in code

Candidate prices, cumulative curves, tie-break rules and allocation: predict the output before the engine.

Lesson 513 min

By the end of this lesson

  • Calculate the demand, supply and volume curve over the candidate prices
  • Apply the auction tie-break rules and read which rule decided
  • Predict who is filled at the equilibrium price, by time priority
In this lesson4

In an auction, all orders entered during the pre-opening are matched in one go, and a single price is determined (BVMAC General Rules 2025, art. 14). This is the mode in use on the BVMAC: according to its published hours, the session includes one auction, at 11:00 (session hours). For a developer, the auction is a pure function: a list of orders goes in, a price, a volume and executions come out.

Auction (fixing)

A trading mode in which accumulated orders are matched in one go, at a single price.

The algorithm in three steps

1. Candidate prices. Only the limits present in the book can be the equilibrium price: between two limits, the quantities do not change.

const candidats = [...new Set(ordres.map((o) => o.limite).filter((p) => p !== null))]
candidats.sort((a, b) => a - b)

2. The curve. For each candidate, add up demand (buy orders willing to pay at least this price) and supply (sell orders willing to sell at this price or less). A market order counts at every price.

const courbe = candidats.map((prix) => {
  const demande = somme(achats.filter((o) => o.limite === null || o.limite >= prix))
  const offre = somme(ventes.filter((o) => o.limite === null || o.limite <= prix))
  return { prix, demande, offre, volume: Math.min(demande, offre), desequilibre: demande - offre }
})

Writing D(p)D(p) for cumulative demand and S(p)S(p) for cumulative supply at price pp, each point on the curve carries:

volume(p)=min⁡(D(p), S(p))imbalance(p)=D(p)−S(p)\text{volume}(p) = \min\big(D(p),\, S(p)\big) \qquad \text{imbalance}(p) = D(p) - S(p)

3. The choice. The engine applies tie-break rules in order and stops as soon as a single candidate remains:

  1. the largest volume traded;
  2. the smallest imbalance, in absolute value;
  3. the direction of pressure: the highest price if demand exceeds everywhere, the lowest if supply does;
  4. the price closest to the reference price.

Rules 1, 2 and 4 are those of the Euronext manual (Euronext Trading Manual, 2021, sections 3.1.1 to 3.1.4). Rule 3 comes from the BVMAC's 2008 draft market rules (Instruction no. 2, 2008) and is absent from the Euronext manual. The result carries a regle field stating which one decided: valuable for testing and for explaining.

No current text describing the BVMAC's auction algorithm was found; only the 2008 draft describes it. The four rules above are the teaching engine's, not a BVMAC specification.

Predict, then check

Work out the curve by hand, state the price and quantity, then let the engine decide. First exercise: one rule is enough.

Exercise 1reference 10,000
  • a1 · buy60 × 10,100#1
  • a2 · buy40 × 10,000#2
  • v1 · sell50 × 9,900#3
  • v2 · sell30 × 10,000#4
  • v3 · sell40 × 10,100#5

Second exercise: two prices give the same volume. Which does the engine keep, and by which rule?

Exercise 2reference 10,000
  • a1 · buy100 × 10,200#1
  • a2 · buy50 × 10,000#2
  • v1 · sell80 × 9,900#3
  • v2 · sell70 × 10,100#4

Who gets filled?

Once the price is found, the volume remains to be allocated. Market orders and orders more aggressive than the price are filled in full; at a limit equal to the price, time priority decides (Euronext Trading Manual, 2021, section 3.1). The engine sorts each side with trierCote, keeps the orders compatible with the price, then pairs the two lists like two queues:

while (restant > 0 && i < a.length && j < v.length) {
  const q = Math.min(a[i].reste, v[j].reste, restant)
  executions.push({ achat: a[i].id, vente: v[j].id, prix, quantite: q })
  a[i].reste -= q; v[j].reste -= q; restant -= q
  if (a[i].reste === 0) i++
  if (v[j].reste === 0) j++
}

The scene replays exercise 2 from start to finish, from the orders' point of view: they pile up without executing, the curve is drawn, two prices tie, a rule decides, then each order learns its fate.

The life of orders at the auction1/6
a1rank 1
100 × 10,200
waiting
a2rank 2
50 × 10,000
waiting

pre-opening: buys received

Buys pile up

During pre-opening, orders come in without executing. a1 and a2 wait.

In exercise 2, a1 is filled for its 100 shares; a2, at 10,000, is below the price and gets nothing. On the sell side, v1 gives its 80 shares and v2 adds 20: it keeps 50.

Challenge: a case the engine may not cover

The Euronext manual states that if only market orders are executable against each other, they trade at the reference price (section 3.1). Write the test below and predict its output before reading the answer.

it('trades at the reference price when only market orders cross', () => {
  const r = fixing([
    { id: 'm1', sens: 'achat', quantite: 10, limite: null, rang: 1 },
    { id: 'm2', sens: 'vente', quantite: 10, limite: null, rang: 2 },
    { id: 'a1', sens: 'achat', quantite: 5, limite: 9900, rang: 3 },
    { id: 'v1', sens: 'vente', quantite: 5, limite: 10100, rang: 4 },
  ], 10000)
  expect(r.prix).toBe(10000)
})

Does the teaching engine pass this test? Reread how candidates are built.

To finish, play with the curve from exercise 2: remove an order and watch which rule takes over.

The auction: one price for everyone
9,90010,00010,10010,200Cumulative demandCumulative supply

Equilibrium price 10,100 · 100 shares traded

Still tied: follow the side under more pressure (buyers or sellers).

Switch an order on or off: the equilibrium price is recomputed.

Going further

The allocation reuses trierCote, seen in the lesson The book, a sorted structure; what changes compared with continuous trading is that all orders are filled at a single price, computed before any execution.

A pure function needs no set-up to test. fixing reads no clock, no state, no network: a test is one call and one comparison. Its edges can therefore be explored in a few lines. Take the case of market orders only:

const marche: Ordre[] = [
  { id: 'm1', sens: 'achat', quantite: 10, limite: null, rang: 1 },
  { id: 'm2', sens: 'vente', quantite: 10, limite: null, rang: 2 },
]
fixing(marche, 10000)
// { prix: 10000, volume: 10, regle: 'volume',
//   executions: [{ achat: 'm1', vente: 'm2', prix: 10000, quantite: 10 }], … }
fixing(marche)
// { prix: null, volume: 0, regle: 'aucun-echange', courbe: [], executions: [] }
  1. No limit: the list of candidates is empty.
  2. With a reference price, the engine adds it as the only candidate: 10 shares trade at 10,000.
  3. With no reference price, no candidate, so no trade, even though two compatible orders are waiting.

The second result calls for a test and a decision: the Euronext manual trades market orders executable only against each other at the reference price (Euronext Trading Manual, 2021, section 3.1), which assumes a reference price exists.

The "reference" rule with no reference. Take the four orders of the challenge again, with then without the second argument:

fixing(ordresDuDefi, 10000).prix // 9900, regle 'reference'
fixing(ordresDuDefi).prix        // 10100, regle 'reference'

With 10,000 as reference, 9,900 and 10,100 are equally distant; the engine then breaks the tie with the lower price. With no reference, it takes the median candidate, retenus[Math.floor(retenus.length / 2)], here the second of the two. This is a known limit on the engine contract sheet: undocumented behaviour, which the test must pin down or get changed.

Complexity. For c candidate prices and n orders, the curve filters every order at each candidate: O(c × n), that is O(n²) when each order has its own limit. A design alternative: sort buys by falling limit and sells by rising limit, then accumulate quantities in a single pass, O(n log n). For a few hundred orders, the readable version is enough; measure before changing.

From memory: in continuous trading (lesson 4), a sell of 10 at 9,950 is resting and a buy of 10 at 10,050 arrives. Trade price? And at the auction, with only these two orders and a reference price of 10,000?

Your turn

Why are only the limits present candidate prices?

1Why are only the limits present candidate prices?

Two prices give the same volume and the same negative imbalance. The engine takes...

2Two prices give the same volume and the same negative imbalance. The engine takes...

At the equilibrium price, two buy orders have a limit equal to that price. Which is filled first?

3At the equilibrium price, two buy orders have a limit equal to that price. Which is filled first?

What is regle when a single price maximises the volume?

4What is regle when a single price maximises the volume?

With no reference price, fixing on just two market orders returns...

5With no reference price, fixing on just two market orders returns...

What complexity to compute the curve, with c candidates and n orders?

6What complexity to compute the curve, with c candidates and n orders?

Read next: Euronext Trading Manual, 5 juillet 2021

A question? Ask your teacher, or an AI assistant, giving it the title of this lesson.

Share:WhatsAppLinkedIn

Going further