REPOSITORY CODING · MEDIUM
Distribute the last pro-rata lots deterministically
Marginal allocation floors each share and leaves executable lots unfilled. Implement largest-remainder apportionment, using requested lots as weights and order IDs to resolve equal remainders. Keep quantities in whole lots.
Repository ImplementationSingle-price call auction laboratory
Work through a real codebase.
Choose an environment, investigate the existing implementation and use the tests to check your change. Sign in to open a workspace; execution and Ono usage follow your plan’s allowances.
Task requirements and environments
PHP · 55 minute session
- Run an offline single-price call auction over integer limit orders, with positive price and quantity and a positive lot size. Quantities must be whole lots. Order IDs are unique; buy and sell are the only sides. This application computes a rehearsal allocation and never places orders or handles payments.
- Consider each distinct order limit as a candidate price. Eligible buys have limit at least that price and eligible sells have limit at most that price. Maximize executable volume, then minimize absolute demand/supply imbalance, then distance to referencePrice, then price itself. If no price executes a positive volume, emit null price, zero volume and zero fills.
- Allocate each side independently for exactly the clearing volume. Better-priced orders have priority: higher buys and lower sells first. At an equally priced marginal group, distribute whole lots pro rata by requested lots; distribute residual lots by descending fractional remainder, then lexical order ID. Never fill beyond an order quantity.
- Return price, executable volume, signed buy-minus-sell imbalance and every order allocation sorted by ID, including zero fills. Use exact integer arithmetic and bounded batches. The PHP and native Symfony editions share the same domain contract and checked-in modules.
Symfony · 55 minute session
- Run an offline single-price call auction over integer limit orders, with positive price and quantity and a positive lot size. Quantities must be whole lots. Order IDs are unique; buy and sell are the only sides. This application computes a rehearsal allocation and never places orders or handles payments.
- Consider each distinct order limit as a candidate price. Eligible buys have limit at least that price and eligible sells have limit at most that price. Maximize executable volume, then minimize absolute demand/supply imbalance, then distance to referencePrice, then price itself. If no price executes a positive volume, emit null price, zero volume and zero fills.
- Allocate each side independently for exactly the clearing volume. Better-priced orders have priority: higher buys and lower sells first. At an equally priced marginal group, distribute whole lots pro rata by requested lots; distribute residual lots by descending fractional remainder, then lexical order ID. Never fill beyond an order quantity.
- Return price, executable volume, signed buy-minus-sell imbalance and every order allocation sorted by ID, including zero fills. Use exact integer arithmetic and bounded batches. The PHP and native Symfony editions share the same domain contract and checked-in modules.