FA-84701 / Betting odds conversion / Open access
Cash-out margin applied as a flat or grossed-up deduction · case 01
Offers differ from the stated percentage deduction.
ROOT CAUSE
The margin percentage is subtracted as cents.
VERIFIED REPAIR
Multiply the value by (100 - margin) / 100.
Unsuccessful approach: Dividing by 1 + margin grosses the value down by a different amount.
Case contract
Cash-out offer for a single or multiple back bet. legs rows are [price taken, current] where current is a decimal price for an open leg, "won" or "lost". Any lost leg makes the offer [0, 0]. Otherwise value = stake * product of prices taken / product of current prices of open legs, reduced by margin_pct percent, rounded down to a cent. partial_cents 0 means full cash-out: return [value, 0]. A partial amount above the value returns "invalid"; otherwise return [partial, remaining stake] with remaining = floor(stake * (1 - partial / value)).
Why this case matters
Cash-out and partial cash-out offers are recomputed from live prices on every tick.
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(legs, stake_cents, margin_pct, partial_cents):
value = Fraction(stake_cents)
for price, cur in legs:
if cur == 'lost':
return [0, 0]
value *= Fraction(price)
if cur != 'won':
value /= Fraction(cur)
value = value - Fraction(margin_pct)
full = math.floor(value)
if partial_cents == 0:
return [full, 0]
if partial_cents > full:
return 'invalid'
remaining = math.floor(stake_cents * (1 - Fraction(partial_cents, full)))
return [partial_cents, remaining]
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 single shortened', ([['3.00', '2.00']], 1000, '0', 0), [1500, 0]),
('control margin applied', ([['3.00', '2.00']], 1000, '5', 0), [1425, 0]),
('boundary won leg keeps price', ([['2.00', 'won'], ['2.00', '1.50']], 1000, '0', 0), [2666, 0]),
('boundary partial cash out', ([['3.00', '2.00']], 1000, '0', 500), [500, 666]),
('control lost leg', ([['2.00', 'lost'], ['2.00', '1.50']], 1000, '0', 0), [0, 0]),
('boundary partial above value', ([['2.00', '4.00']], 1000, '0', 600), 'invalid'),
('regression: margin application',
([['3.98', 'won'], ['3.24', 'won'], ['2.39', '4.03'], ['2.04', 'won']], 500, '5', 500),
[500, 466]),
('regression: margin application',
([['3.31', '5.65'], ['4.82', '5.34']], 2500, '5', 0),
[1255, 0]),
('variant scenario 1',
([['2.61', 'won'], ['2.54', '3.04'], ['4.36', 'won'], ['3.63', '5.65']], 2500, '0', 500),
[500, 2418]),
('variant scenario 2', ([['2.56', 'lost']], 500, '7.5', 800), [0, 0])],
[('control single shortened', ([['3.00', '2.00']], 1000, '0', 0), [1500, 0]),
('control margin applied', ([['3.00', '2.00']], 1000, '5', 0), [1425, 0]),
('boundary won leg keeps price', ([['2.00', 'won'], ['2.00', '1.50']], 1000, '0', 0), [2666, 0]),
('boundary partial cash out', ([['3.00', '2.00']], 1000, '0', 500), [500, 666]),
('control lost leg', ([['2.00', 'lost'], ['2.00', '1.50']], 1000, '0', 0), [0, 0]),
('boundary partial above value', ([['2.00', '4.00']], 1000, '0', 600), 'invalid'),
('regression: margin application', ([['4.31', '1.48']], 500, '5', 500), [500, 319]),
('regression: margin application', ([['2.56', '3.02']], 1000, '5', 0), [805, 0]),
('variant scenario 1',
([['3.54', 'won'], ['4.17', '2.42'], ['3.80', 'won'], ['3.99', 'lost']], 500, '7.5', 200),
[0, 0]),
('variant scenario 2', ([['2.56', 'won']], 2500, '0', 200), [200, 2421])],
[('control single shortened', ([['3.00', '2.00']], 1000, '0', 0), [1500, 0]),
('control margin applied', ([['3.00', '2.00']], 1000, '5', 0), [1425, 0]),
('boundary won leg keeps price', ([['2.00', 'won'], ['2.00', '1.50']], 1000, '0', 0), [2666, 0]),
('boundary partial cash out', ([['3.00', '2.00']], 1000, '0', 500), [500, 666]),
('control lost leg', ([['2.00', 'lost'], ['2.00', '1.50']], 1000, '0', 0), [0, 0]),
('boundary partial above value', ([['2.00', '4.00']], 1000, '0', 600), 'invalid'),
('regression: margin application',
([['1.77', '5.47'], ['4.57', 'won'], ['4.63', 'won'], ['4.20', 'won']], 1000, '5', 200),
[200, 992]),
('regression: margin application', ([['4.21', 'won']], 500, '5', 0), [1999, 0]),
('variant scenario 1',
([['4.24', 'lost'], ['4.73', '5.96'], ['3.59', 'won']], 1000, '7.5', 0),
[0, 0]),
('variant scenario 2', ([['4.94', '1.31'], ['2.71', '5.06']], 1000, '0', 800), [800, 603])],
[('control single shortened', ([['3.00', '2.00']], 1000, '0', 0), [1500, 0]),
('control margin applied', ([['3.00', '2.00']], 1000, '5', 0), [1425, 0]),
('boundary won leg keeps price', ([['2.00', 'won'], ['2.00', '1.50']], 1000, '0', 0), [2666, 0]),
('boundary partial cash out', ([['3.00', '2.00']], 1000, '0', 500), [500, 666]),
('control lost leg', ([['2.00', 'lost'], ['2.00', '1.50']], 1000, '0', 0), [0, 0]),
('boundary partial above value', ([['2.00', '4.00']], 1000, '0', 600), 'invalid'),
('regression: margin application', ([['1.66', '3.53']], 2500, '5', 200), [200, 2051]),
('variant scenario 1', ([['1.54', 'won'], ['3.01', '3.82']], 1000, '0', 500), [500, 587]),
('variant scenario 2', ([['3.86', '5.37']], 500, '7.5', 0), [332, 0])],
[('control single shortened', ([['3.00', '2.00']], 1000, '0', 0), [1500, 0]),
('control margin applied', ([['3.00', '2.00']], 1000, '5', 0), [1425, 0]),
('boundary won leg keeps price', ([['2.00', 'won'], ['2.00', '1.50']], 1000, '0', 0), [2666, 0]),
('boundary partial cash out', ([['3.00', '2.00']], 1000, '0', 500), [500, 666]),
('control lost leg', ([['2.00', 'lost'], ['2.00', '1.50']], 1000, '0', 0), [0, 0]),
('boundary partial above value', ([['2.00', '4.00']], 1000, '0', 600), 'invalid'),
('regression: margin application',
([['4.64', '5.35'], ['4.09', 'won'], ['4.50', '2.09']], 1000, '7.5', 0),
[7064, 0]),
('variant scenario 1',
([['2.22', 'lost'], ['2.66', 'won'], ['4.77', '1.58'], ['3.17', 'lost']], 2500, '5', 200),
[0, 0]),
('variant scenario 2',
([['4.16', '1.91'], ['4.67', '5.15'], ['2.46', '4.20'], ['3.13', '3.40']], 500, '0', 0),
[532, 0])]]
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 fixture | Actual | Expected | Outcome |
|---|---|---|---|
| control single shortened | [1500, 0] | [1500, 0] | Passed |
| control margin applied | [1495, 0] | [1425, 0] | Failed |
| boundary won leg keeps price | [2666, 0] | [2666, 0] | Passed |
| boundary partial cash out | [500, 666] | [500, 666] | Passed |
| control lost leg | [0, 0] | [0, 0] | Passed |
| boundary partial above value | invalid | invalid | Passed |
| regression: margin application | [500, 467] | [500, 466] | Failed |
| regression: margin application | [1316, 0] | [1255, 0] | Failed |
| variant scenario 1 | [500, 2418] | [500, 2418] | Passed |
| variant scenario 2 | [0, 0] | [0, 0] | Passed |
SHA-256 / 71a75b8a4edb3fdee6fd9ca2bf8fc9f550de25e5f7d4293c1e9aaa29d8f6eecd
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(legs, stake_cents, margin_pct, partial_cents):
value = Fraction(stake_cents)
for price, cur in legs:
if cur == 'lost':
return [0, 0]
value *= Fraction(price)
if cur != 'won':
value /= Fraction(cur)
value = value / (1 + Fraction(margin_pct) / 100)
full = math.floor(value)
if partial_cents == 0:
return [full, 0]
if partial_cents > full:
return 'invalid'
remaining = math.floor(stake_cents * (1 - Fraction(partial_cents, full)))
return [partial_cents, remaining]
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 single shortened', ([['3.00', '2.00']], 1000, '0', 0), [1500, 0]),
('control margin applied', ([['3.00', '2.00']], 1000, '5', 0), [1425, 0]),
('boundary won leg keeps price', ([['2.00', 'won'], ['2.00', '1.50']], 1000, '0', 0), [2666, 0]),
('boundary partial cash out', ([['3.00', '2.00']], 1000, '0', 500), [500, 666]),
('control lost leg', ([['2.00', 'lost'], ['2.00', '1.50']], 1000, '0', 0), [0, 0]),
('boundary partial above value', ([['2.00', '4.00']], 1000, '0', 600), 'invalid'),
('regression: margin application',
([['3.98', 'won'], ['3.24', 'won'], ['2.39', '4.03'], ['2.04', 'won']], 500, '5', 500),
[500, 466]),
('regression: margin application',
([['3.31', '5.65'], ['4.82', '5.34']], 2500, '5', 0),
[1255, 0]),
('variant scenario 1',
([['2.61', 'won'], ['2.54', '3.04'], ['4.36', 'won'], ['3.63', '5.65']], 2500, '0', 500),
[500, 2418]),
('variant scenario 2', ([['2.56', 'lost']], 500, '7.5', 800), [0, 0])],
[('control single shortened', ([['3.00', '2.00']], 1000, '0', 0), [1500, 0]),
('control margin applied', ([['3.00', '2.00']], 1000, '5', 0), [1425, 0]),
('boundary won leg keeps price', ([['2.00', 'won'], ['2.00', '1.50']], 1000, '0', 0), [2666, 0]),
('boundary partial cash out', ([['3.00', '2.00']], 1000, '0', 500), [500, 666]),
('control lost leg', ([['2.00', 'lost'], ['2.00', '1.50']], 1000, '0', 0), [0, 0]),
('boundary partial above value', ([['2.00', '4.00']], 1000, '0', 600), 'invalid'),
('regression: margin application', ([['4.31', '1.48']], 500, '5', 500), [500, 319]),
('regression: margin application', ([['2.56', '3.02']], 1000, '5', 0), [805, 0]),
('variant scenario 1',
([['3.54', 'won'], ['4.17', '2.42'], ['3.80', 'won'], ['3.99', 'lost']], 500, '7.5', 200),
[0, 0]),
('variant scenario 2', ([['2.56', 'won']], 2500, '0', 200), [200, 2421])],
[('control single shortened', ([['3.00', '2.00']], 1000, '0', 0), [1500, 0]),
('control margin applied', ([['3.00', '2.00']], 1000, '5', 0), [1425, 0]),
('boundary won leg keeps price', ([['2.00', 'won'], ['2.00', '1.50']], 1000, '0', 0), [2666, 0]),
('boundary partial cash out', ([['3.00', '2.00']], 1000, '0', 500), [500, 666]),
('control lost leg', ([['2.00', 'lost'], ['2.00', '1.50']], 1000, '0', 0), [0, 0]),
('boundary partial above value', ([['2.00', '4.00']], 1000, '0', 600), 'invalid'),
('regression: margin application',
([['1.77', '5.47'], ['4.57', 'won'], ['4.63', 'won'], ['4.20', 'won']], 1000, '5', 200),
[200, 992]),
('regression: margin application', ([['4.21', 'won']], 500, '5', 0), [1999, 0]),
('variant scenario 1',
([['4.24', 'lost'], ['4.73', '5.96'], ['3.59', 'won']], 1000, '7.5', 0),
[0, 0]),
('variant scenario 2', ([['4.94', '1.31'], ['2.71', '5.06']], 1000, '0', 800), [800, 603])],
[('control single shortened', ([['3.00', '2.00']], 1000, '0', 0), [1500, 0]),
('control margin applied', ([['3.00', '2.00']], 1000, '5', 0), [1425, 0]),
('boundary won leg keeps price', ([['2.00', 'won'], ['2.00', '1.50']], 1000, '0', 0), [2666, 0]),
('boundary partial cash out', ([['3.00', '2.00']], 1000, '0', 500), [500, 666]),
('control lost leg', ([['2.00', 'lost'], ['2.00', '1.50']], 1000, '0', 0), [0, 0]),
('boundary partial above value', ([['2.00', '4.00']], 1000, '0', 600), 'invalid'),
('regression: margin application', ([['1.66', '3.53']], 2500, '5', 200), [200, 2051]),
('variant scenario 1', ([['1.54', 'won'], ['3.01', '3.82']], 1000, '0', 500), [500, 587]),
('variant scenario 2', ([['3.86', '5.37']], 500, '7.5', 0), [332, 0])],
[('control single shortened', ([['3.00', '2.00']], 1000, '0', 0), [1500, 0]),
('control margin applied', ([['3.00', '2.00']], 1000, '5', 0), [1425, 0]),
('boundary won leg keeps price', ([['2.00', 'won'], ['2.00', '1.50']], 1000, '0', 0), [2666, 0]),
('boundary partial cash out', ([['3.00', '2.00']], 1000, '0', 500), [500, 666]),
('control lost leg', ([['2.00', 'lost'], ['2.00', '1.50']], 1000, '0', 0), [0, 0]),
('boundary partial above value', ([['2.00', '4.00']], 1000, '0', 600), 'invalid'),
('regression: margin application',
([['4.64', '5.35'], ['4.09', 'won'], ['4.50', '2.09']], 1000, '7.5', 0),
[7064, 0]),
('variant scenario 1',
([['2.22', 'lost'], ['2.66', 'won'], ['4.77', '1.58'], ['3.17', 'lost']], 2500, '5', 200),
[0, 0]),
('variant scenario 2',
([['4.16', '1.91'], ['4.67', '5.15'], ['2.46', '4.20'], ['3.13', '3.40']], 500, '0', 0),
[532, 0])]]
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 fixture | Actual | Expected | Outcome |
|---|---|---|---|
| control single shortened | [1500, 0] | [1500, 0] | Passed |
| control margin applied | [1428, 0] | [1425, 0] | Failed |
| boundary won leg keeps price | [2666, 0] | [2666, 0] | Passed |
| boundary partial cash out | [500, 666] | [500, 666] | Passed |
| control lost leg | [0, 0] | [0, 0] | Passed |
| boundary partial above value | invalid | invalid | Passed |
| regression: margin application | [500, 466] | [500, 466] | Passed |
| regression: margin application | [1259, 0] | [1255, 0] | Failed |
| variant scenario 1 | [500, 2418] | [500, 2418] | Passed |
| variant scenario 2 | [0, 0] | [0, 0] | Passed |
SHA-256 / 96955c2159ecadf95f0f0500bf2d38b06339ed0012197c42198a5b00bd142b33
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(legs, stake_cents, margin_pct, partial_cents):
value = Fraction(stake_cents)
for price, cur in legs:
if cur == 'lost':
return [0, 0]
value *= Fraction(price)
if cur != 'won':
value /= Fraction(cur)
value = value * (100 - Fraction(margin_pct)) / 100
full = math.floor(value)
if partial_cents == 0:
return [full, 0]
if partial_cents > full:
return 'invalid'
remaining = math.floor(stake_cents * (1 - Fraction(partial_cents, full)))
return [partial_cents, remaining]
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 single shortened', ([['3.00', '2.00']], 1000, '0', 0), [1500, 0]),
('control margin applied', ([['3.00', '2.00']], 1000, '5', 0), [1425, 0]),
('boundary won leg keeps price', ([['2.00', 'won'], ['2.00', '1.50']], 1000, '0', 0), [2666, 0]),
('boundary partial cash out', ([['3.00', '2.00']], 1000, '0', 500), [500, 666]),
('control lost leg', ([['2.00', 'lost'], ['2.00', '1.50']], 1000, '0', 0), [0, 0]),
('boundary partial above value', ([['2.00', '4.00']], 1000, '0', 600), 'invalid'),
('regression: margin application',
([['3.98', 'won'], ['3.24', 'won'], ['2.39', '4.03'], ['2.04', 'won']], 500, '5', 500),
[500, 466]),
('regression: margin application',
([['3.31', '5.65'], ['4.82', '5.34']], 2500, '5', 0),
[1255, 0]),
('variant scenario 1',
([['2.61', 'won'], ['2.54', '3.04'], ['4.36', 'won'], ['3.63', '5.65']], 2500, '0', 500),
[500, 2418]),
('variant scenario 2', ([['2.56', 'lost']], 500, '7.5', 800), [0, 0])],
[('control single shortened', ([['3.00', '2.00']], 1000, '0', 0), [1500, 0]),
('control margin applied', ([['3.00', '2.00']], 1000, '5', 0), [1425, 0]),
('boundary won leg keeps price', ([['2.00', 'won'], ['2.00', '1.50']], 1000, '0', 0), [2666, 0]),
('boundary partial cash out', ([['3.00', '2.00']], 1000, '0', 500), [500, 666]),
('control lost leg', ([['2.00', 'lost'], ['2.00', '1.50']], 1000, '0', 0), [0, 0]),
('boundary partial above value', ([['2.00', '4.00']], 1000, '0', 600), 'invalid'),
('regression: margin application', ([['4.31', '1.48']], 500, '5', 500), [500, 319]),
('regression: margin application', ([['2.56', '3.02']], 1000, '5', 0), [805, 0]),
('variant scenario 1',
([['3.54', 'won'], ['4.17', '2.42'], ['3.80', 'won'], ['3.99', 'lost']], 500, '7.5', 200),
[0, 0]),
('variant scenario 2', ([['2.56', 'won']], 2500, '0', 200), [200, 2421])],
[('control single shortened', ([['3.00', '2.00']], 1000, '0', 0), [1500, 0]),
('control margin applied', ([['3.00', '2.00']], 1000, '5', 0), [1425, 0]),
('boundary won leg keeps price', ([['2.00', 'won'], ['2.00', '1.50']], 1000, '0', 0), [2666, 0]),
('boundary partial cash out', ([['3.00', '2.00']], 1000, '0', 500), [500, 666]),
('control lost leg', ([['2.00', 'lost'], ['2.00', '1.50']], 1000, '0', 0), [0, 0]),
('boundary partial above value', ([['2.00', '4.00']], 1000, '0', 600), 'invalid'),
('regression: margin application',
([['1.77', '5.47'], ['4.57', 'won'], ['4.63', 'won'], ['4.20', 'won']], 1000, '5', 200),
[200, 992]),
('regression: margin application', ([['4.21', 'won']], 500, '5', 0), [1999, 0]),
('variant scenario 1',
([['4.24', 'lost'], ['4.73', '5.96'], ['3.59', 'won']], 1000, '7.5', 0),
[0, 0]),
('variant scenario 2', ([['4.94', '1.31'], ['2.71', '5.06']], 1000, '0', 800), [800, 603])],
[('control single shortened', ([['3.00', '2.00']], 1000, '0', 0), [1500, 0]),
('control margin applied', ([['3.00', '2.00']], 1000, '5', 0), [1425, 0]),
('boundary won leg keeps price', ([['2.00', 'won'], ['2.00', '1.50']], 1000, '0', 0), [2666, 0]),
('boundary partial cash out', ([['3.00', '2.00']], 1000, '0', 500), [500, 666]),
('control lost leg', ([['2.00', 'lost'], ['2.00', '1.50']], 1000, '0', 0), [0, 0]),
('boundary partial above value', ([['2.00', '4.00']], 1000, '0', 600), 'invalid'),
('regression: margin application', ([['1.66', '3.53']], 2500, '5', 200), [200, 2051]),
('variant scenario 1', ([['1.54', 'won'], ['3.01', '3.82']], 1000, '0', 500), [500, 587]),
('variant scenario 2', ([['3.86', '5.37']], 500, '7.5', 0), [332, 0])],
[('control single shortened', ([['3.00', '2.00']], 1000, '0', 0), [1500, 0]),
('control margin applied', ([['3.00', '2.00']], 1000, '5', 0), [1425, 0]),
('boundary won leg keeps price', ([['2.00', 'won'], ['2.00', '1.50']], 1000, '0', 0), [2666, 0]),
('boundary partial cash out', ([['3.00', '2.00']], 1000, '0', 500), [500, 666]),
('control lost leg', ([['2.00', 'lost'], ['2.00', '1.50']], 1000, '0', 0), [0, 0]),
('boundary partial above value', ([['2.00', '4.00']], 1000, '0', 600), 'invalid'),
('regression: margin application',
([['4.64', '5.35'], ['4.09', 'won'], ['4.50', '2.09']], 1000, '7.5', 0),
[7064, 0]),
('variant scenario 1',
([['2.22', 'lost'], ['2.66', 'won'], ['4.77', '1.58'], ['3.17', 'lost']], 2500, '5', 200),
[0, 0]),
('variant scenario 2',
([['4.16', '1.91'], ['4.67', '5.15'], ['2.46', '4.20'], ['3.13', '3.40']], 500, '0', 0),
[532, 0])]]
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 fixture | Actual | Expected | Outcome |
|---|---|---|---|
| control single shortened | [1500, 0] | [1500, 0] | Passed |
| control margin applied | [1425, 0] | [1425, 0] | Passed |
| boundary won leg keeps price | [2666, 0] | [2666, 0] | Passed |
| boundary partial cash out | [500, 666] | [500, 666] | Passed |
| control lost leg | [0, 0] | [0, 0] | Passed |
| boundary partial above value | invalid | invalid | Passed |
| regression: margin application | [500, 466] | [500, 466] | Passed |
| regression: margin application | [1255, 0] | [1255, 0] | Passed |
| variant scenario 1 | [500, 2418] | [500, 2418] | Passed |
| variant scenario 2 | [0, 0] | [0, 0] | Passed |
SHA-256 / 2bf84c26555309e433fce3ebff48f01cd3388a61e374039d71dc4cf386975df1
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:33.401964+00:00.
Case digest / c9550f9ace298f4405bba44fdeb0b6afb12841530b6b77c9da1860328b71e903