FAILURE MAP
← Case archive

FA-84596 / Betting odds conversion / Open access

Back and lay requests rounded the wrong way · case 01

A back order is snapped to a better price than requested.

Verified by executionVariant 1 · 9 checks per implementationDownload source bundle ↓JSON ↗

ROOT CAUSE

The rounding directions for back and lay are swapped.

VERIFIED REPAIR

Round back requests down and lay requests up.

Unsuccessful approach: Rounding both sides to the nearest tick can still move a back price up.

Case contract

Snap a requested price onto an exchange tick ladder. Bands in hundredths [lo, hi, step]: [(101, 200, 1), (200, 300, 2), (300, 400, 5), (400, 600, 10), (600, 1000, 20), (1000, 2000, 50), (2000, 3000, 100), (3000, 5000, 200), (5000, 10000, 500), (10000, 100001, 1000)]. Prices outside 1.01..1000 return "invalid". A back request rounds down to a valid tick and a lay request rounds up (ticks counted from the band lower bound). Return the tick as "%d.%02d".

Why this case matters

Exchange order entry must snap arbitrary prices to valid ticks in the customer-safe direction.

1 / The failure

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
import math
N = 1
observations = []
def solve(price, side):
    BANDS = [(101, 200, 1), (200, 300, 2), (300, 400, 5), (400, 600, 10), (600, 1000, 20), (1000, 2000, 50), (2000, 3000, 100), (3000, 5000, 200), (5000, 10000, 500), (10000, 100001, 1000)]
    c = Fraction(price) * 100
    if c < 101 or c > 100000:
        return 'invalid'
    for lo, hi, step in BANDS:
        if lo <= c < hi:
            k = (c - lo) / step
            k = math.ceil(k) if side == 'back' else math.floor(k)
            v = lo + k * step
            break
    return '%d.%02d' % (v // 100, v % 100)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control on-tick price', ('2.50', 'back'), '2.50'),
  ('boundary back rounds down', ('3.03', 'back'), '3.00'),
  ('boundary lay rounds up', ('3.03', 'lay'), '3.05'),
  ('boundary lay rounds into next band', ('1.995', 'lay'), '2.00'),
  ('boundary below ladder', ('1.00', 'back'), 'invalid'),
  ('control top of ladder', ('1000', 'lay'), '1000.00'),
  ('regression: rounding direction', ('11.88', 'back'), '11.50'),
  ('variant scenario 1', ('1.94', 'lay'), '1.94'),
  ('variant scenario 2', ('1.00', 'back'), 'invalid')],
 [('control on-tick price', ('2.50', 'back'), '2.50'),
  ('boundary back rounds down', ('3.03', 'back'), '3.00'),
  ('boundary lay rounds up', ('3.03', 'lay'), '3.05'),
  ('boundary lay rounds into next band', ('1.995', 'lay'), '2.00'),
  ('boundary below ladder', ('1.00', 'back'), 'invalid'),
  ('control top of ladder', ('1000', 'lay'), '1000.00'),
  ('regression: rounding direction', ('484.08', 'lay'), '490.00'),
  ('variant scenario 1', ('1.25', 'lay'), '1.25'),
  ('variant scenario 2', ('21.34', 'lay'), '22.00')],
 [('control on-tick price', ('2.50', 'back'), '2.50'),
  ('boundary back rounds down', ('3.03', 'back'), '3.00'),
  ('boundary lay rounds up', ('3.03', 'lay'), '3.05'),
  ('boundary lay rounds into next band', ('1.995', 'lay'), '2.00'),
  ('boundary below ladder', ('1.00', 'back'), 'invalid'),
  ('control top of ladder', ('1000', 'lay'), '1000.00'),
  ('regression: rounding direction', ('3.14', 'back'), '3.10'),
  ('variant scenario 1', ('21.44', 'lay'), '22.00'),
  ('variant scenario 2', ('853.33', 'back'), '850.00')],
 [('control on-tick price', ('2.50', 'back'), '2.50'),
  ('boundary back rounds down', ('3.03', 'back'), '3.00'),
  ('boundary lay rounds up', ('3.03', 'lay'), '3.05'),
  ('boundary lay rounds into next band', ('1.995', 'lay'), '2.00'),
  ('boundary below ladder', ('1.00', 'back'), 'invalid'),
  ('control top of ladder', ('1000', 'lay'), '1000.00'),
  ('regression: rounding direction', ('2.27', 'back'), '2.26'),
  ('variant scenario 1', ('1.94', 'lay'), '1.94'),
  ('variant scenario 2', ('248.87', 'back'), '240.00')],
 [('control on-tick price', ('2.50', 'back'), '2.50'),
  ('boundary back rounds down', ('3.03', 'back'), '3.00'),
  ('boundary lay rounds up', ('3.03', 'lay'), '3.05'),
  ('boundary lay rounds into next band', ('1.995', 'lay'), '2.00'),
  ('boundary below ladder', ('1.00', 'back'), 'invalid'),
  ('control top of ladder', ('1000', 'lay'), '1000.00'),
  ('regression: rounding direction', ('3.52', 'back'), '3.50'),
  ('regression: rounding direction', ('221.87', 'lay'), '230.00'),
  ('variant scenario 1', ('785.23', 'lay'), '790.00'),
  ('variant scenario 2', ('1.67', 'lay'), '1.67')]]
for label, args, expected in cases[N - 1]:
    check(label, run(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
control on-tick price2.502.50Passed
boundary back rounds down3.053.00Failed
boundary lay rounds up3.003.05Failed
boundary lay rounds into next band1.992.00Failed
boundary below ladderinvalidinvalidPassed
control top of ladder1000.001000.00Passed
regression: rounding direction12.0011.50Failed
variant scenario 11.941.94Passed
variant scenario 2invalidinvalidPassed

SHA-256 / 54bd82e0750fa1b4214c81a25f6343fd83a1b3dbca7a4aa5b2f3b8b47f8a00e2

2 / The unsuccessful fix

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
import math
N = 1
observations = []
def solve(price, side):
    BANDS = [(101, 200, 1), (200, 300, 2), (300, 400, 5), (400, 600, 10), (600, 1000, 20), (1000, 2000, 50), (2000, 3000, 100), (3000, 5000, 200), (5000, 10000, 500), (10000, 100001, 1000)]
    c = Fraction(price) * 100
    if c < 101 or c > 100000:
        return 'invalid'
    for lo, hi, step in BANDS:
        if lo <= c < hi:
            k = (c - lo) / step
            k = round(k)
            v = lo + k * step
            break
    return '%d.%02d' % (v // 100, v % 100)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control on-tick price', ('2.50', 'back'), '2.50'),
  ('boundary back rounds down', ('3.03', 'back'), '3.00'),
  ('boundary lay rounds up', ('3.03', 'lay'), '3.05'),
  ('boundary lay rounds into next band', ('1.995', 'lay'), '2.00'),
  ('boundary below ladder', ('1.00', 'back'), 'invalid'),
  ('control top of ladder', ('1000', 'lay'), '1000.00'),
  ('regression: rounding direction', ('11.88', 'back'), '11.50'),
  ('variant scenario 1', ('1.94', 'lay'), '1.94'),
  ('variant scenario 2', ('1.00', 'back'), 'invalid')],
 [('control on-tick price', ('2.50', 'back'), '2.50'),
  ('boundary back rounds down', ('3.03', 'back'), '3.00'),
  ('boundary lay rounds up', ('3.03', 'lay'), '3.05'),
  ('boundary lay rounds into next band', ('1.995', 'lay'), '2.00'),
  ('boundary below ladder', ('1.00', 'back'), 'invalid'),
  ('control top of ladder', ('1000', 'lay'), '1000.00'),
  ('regression: rounding direction', ('484.08', 'lay'), '490.00'),
  ('variant scenario 1', ('1.25', 'lay'), '1.25'),
  ('variant scenario 2', ('21.34', 'lay'), '22.00')],
 [('control on-tick price', ('2.50', 'back'), '2.50'),
  ('boundary back rounds down', ('3.03', 'back'), '3.00'),
  ('boundary lay rounds up', ('3.03', 'lay'), '3.05'),
  ('boundary lay rounds into next band', ('1.995', 'lay'), '2.00'),
  ('boundary below ladder', ('1.00', 'back'), 'invalid'),
  ('control top of ladder', ('1000', 'lay'), '1000.00'),
  ('regression: rounding direction', ('3.14', 'back'), '3.10'),
  ('variant scenario 1', ('21.44', 'lay'), '22.00'),
  ('variant scenario 2', ('853.33', 'back'), '850.00')],
 [('control on-tick price', ('2.50', 'back'), '2.50'),
  ('boundary back rounds down', ('3.03', 'back'), '3.00'),
  ('boundary lay rounds up', ('3.03', 'lay'), '3.05'),
  ('boundary lay rounds into next band', ('1.995', 'lay'), '2.00'),
  ('boundary below ladder', ('1.00', 'back'), 'invalid'),
  ('control top of ladder', ('1000', 'lay'), '1000.00'),
  ('regression: rounding direction', ('2.27', 'back'), '2.26'),
  ('variant scenario 1', ('1.94', 'lay'), '1.94'),
  ('variant scenario 2', ('248.87', 'back'), '240.00')],
 [('control on-tick price', ('2.50', 'back'), '2.50'),
  ('boundary back rounds down', ('3.03', 'back'), '3.00'),
  ('boundary lay rounds up', ('3.03', 'lay'), '3.05'),
  ('boundary lay rounds into next band', ('1.995', 'lay'), '2.00'),
  ('boundary below ladder', ('1.00', 'back'), 'invalid'),
  ('control top of ladder', ('1000', 'lay'), '1000.00'),
  ('regression: rounding direction', ('3.52', 'back'), '3.50'),
  ('regression: rounding direction', ('221.87', 'lay'), '230.00'),
  ('variant scenario 1', ('785.23', 'lay'), '790.00'),
  ('variant scenario 2', ('1.67', 'lay'), '1.67')]]
for label, args, expected in cases[N - 1]:
    check(label, run(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
control on-tick price2.502.50Passed
boundary back rounds down3.053.00Failed
boundary lay rounds up3.053.05Passed
boundary lay rounds into next band1.992.00Failed
boundary below ladderinvalidinvalidPassed
control top of ladder1000.001000.00Passed
regression: rounding direction12.0011.50Failed
variant scenario 11.941.94Passed
variant scenario 2invalidinvalidPassed

SHA-256 / 60e90475065543d89a3aa2ea19e406bfbd06265f38dee3e180fae00e3d4893db

3 / The verified repair

Exit 0
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
import math
N = 1
observations = []
def solve(price, side):
    BANDS = [(101, 200, 1), (200, 300, 2), (300, 400, 5), (400, 600, 10), (600, 1000, 20), (1000, 2000, 50), (2000, 3000, 100), (3000, 5000, 200), (5000, 10000, 500), (10000, 100001, 1000)]
    c = Fraction(price) * 100
    if c < 101 or c > 100000:
        return 'invalid'
    for lo, hi, step in BANDS:
        if lo <= c < hi:
            k = (c - lo) / step
            k = math.floor(k) if side == 'back' else math.ceil(k)
            v = lo + k * step
            break
    return '%d.%02d' % (v // 100, v % 100)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control on-tick price', ('2.50', 'back'), '2.50'),
  ('boundary back rounds down', ('3.03', 'back'), '3.00'),
  ('boundary lay rounds up', ('3.03', 'lay'), '3.05'),
  ('boundary lay rounds into next band', ('1.995', 'lay'), '2.00'),
  ('boundary below ladder', ('1.00', 'back'), 'invalid'),
  ('control top of ladder', ('1000', 'lay'), '1000.00'),
  ('regression: rounding direction', ('11.88', 'back'), '11.50'),
  ('variant scenario 1', ('1.94', 'lay'), '1.94'),
  ('variant scenario 2', ('1.00', 'back'), 'invalid')],
 [('control on-tick price', ('2.50', 'back'), '2.50'),
  ('boundary back rounds down', ('3.03', 'back'), '3.00'),
  ('boundary lay rounds up', ('3.03', 'lay'), '3.05'),
  ('boundary lay rounds into next band', ('1.995', 'lay'), '2.00'),
  ('boundary below ladder', ('1.00', 'back'), 'invalid'),
  ('control top of ladder', ('1000', 'lay'), '1000.00'),
  ('regression: rounding direction', ('484.08', 'lay'), '490.00'),
  ('variant scenario 1', ('1.25', 'lay'), '1.25'),
  ('variant scenario 2', ('21.34', 'lay'), '22.00')],
 [('control on-tick price', ('2.50', 'back'), '2.50'),
  ('boundary back rounds down', ('3.03', 'back'), '3.00'),
  ('boundary lay rounds up', ('3.03', 'lay'), '3.05'),
  ('boundary lay rounds into next band', ('1.995', 'lay'), '2.00'),
  ('boundary below ladder', ('1.00', 'back'), 'invalid'),
  ('control top of ladder', ('1000', 'lay'), '1000.00'),
  ('regression: rounding direction', ('3.14', 'back'), '3.10'),
  ('variant scenario 1', ('21.44', 'lay'), '22.00'),
  ('variant scenario 2', ('853.33', 'back'), '850.00')],
 [('control on-tick price', ('2.50', 'back'), '2.50'),
  ('boundary back rounds down', ('3.03', 'back'), '3.00'),
  ('boundary lay rounds up', ('3.03', 'lay'), '3.05'),
  ('boundary lay rounds into next band', ('1.995', 'lay'), '2.00'),
  ('boundary below ladder', ('1.00', 'back'), 'invalid'),
  ('control top of ladder', ('1000', 'lay'), '1000.00'),
  ('regression: rounding direction', ('2.27', 'back'), '2.26'),
  ('variant scenario 1', ('1.94', 'lay'), '1.94'),
  ('variant scenario 2', ('248.87', 'back'), '240.00')],
 [('control on-tick price', ('2.50', 'back'), '2.50'),
  ('boundary back rounds down', ('3.03', 'back'), '3.00'),
  ('boundary lay rounds up', ('3.03', 'lay'), '3.05'),
  ('boundary lay rounds into next band', ('1.995', 'lay'), '2.00'),
  ('boundary below ladder', ('1.00', 'back'), 'invalid'),
  ('control top of ladder', ('1000', 'lay'), '1000.00'),
  ('regression: rounding direction', ('3.52', 'back'), '3.50'),
  ('regression: rounding direction', ('221.87', 'lay'), '230.00'),
  ('variant scenario 1', ('785.23', 'lay'), '790.00'),
  ('variant scenario 2', ('1.67', 'lay'), '1.67')]]
for label, args, expected in cases[N - 1]:
    check(label, run(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
control on-tick price2.502.50Passed
boundary back rounds down3.003.00Passed
boundary lay rounds up3.053.05Passed
boundary lay rounds into next band2.002.00Passed
boundary below ladderinvalidinvalidPassed
control top of ladder1000.001000.00Passed
regression: rounding direction11.5011.50Passed
variant scenario 11.941.94Passed
variant scenario 2invalidinvalidPassed

SHA-256 / ab28ff6a789e51dac937b68e3105533ab5e13df9ec23474ea308cbb6c0319e3b

Verification & scope

Stipulated, bounded toy contract stated in the contract field; not a claim of conformance with any operator, exchange or regulator rule set. This reproducer isolates one failure mechanism. Results cover the supplied fixtures. Variants within a family share a test contract and should remain grouped when constructing evaluation splits. Related mechanisms with a shared evaluation_group must also remain together; these controlled models are not independent production incidents.

Observations recorded using Python 3.12.14 at 2026-09-29T14:50:32.462962+00:00.

Case digest / e8ba656dcba3b11d6f377da6f9fc8deebab61ee501c2f68c317f74cdb9290906