# Pro-Rata Matching

`D12-F01-A02` · Matching Engines and Venue Logic → Continuous Matching · archetype `record-transform` · difficulty 4/5 · verification **verified**

Full page: https://docs.thefintechbuilder.com/matching-engines-and-venue-logic/continuous-matching/pro-rata-matching/
Agent skill: `npx skills add IslamBaraka90/Fintech-Algorithms-Library` — https://docs.thefintechbuilder.com/guides/agent-skill/

## Install and import

```bash
npm install fintech-algorithms
```

```ts
import { proRataMatching } from "fintech-algorithms/matching-engines-and-venue-logic/continuous-matching/pro-rata-matching";
```

## Signature

```ts
proRataMatching(incomingRaw, priceRaw, lotRaw, restingRaw)
```

Allocates a fill across all resting orders at a price in proportion to size, ignoring arrival time. Common in some futures markets, and it removes the incentive to queue that price-time creates — participants instead inflate size.

## Parameters

| Name | Type | Required | Notes |
| --- | --- | --- | --- |
| `incomingRaw` | `Order` | yes | The aggressing order. |
| `priceRaw` | `number` | yes | Price level at which allocation occurs. |
| `lotRaw` | `number` | yes | Lot size; allocations round to it, and the rounding remainder must be redistributed rather than lost. · min: 1, integer: true |
| `restingRaw` | `Order[]` | yes | Resting orders at that price. |

## Returns

`{ allocations, residual, remainder_handling, … }`

Per-order allocation with how the rounding remainder was distributed.

## Errors

- When lot size is not a positive integer — throws

## Complexity

Time `O(resting)`, space `O(resting)`.

## Worked example

Captured by running this function on the input its own test provides. Real output of real code — but not asserted against a published figure.

### Input

`incomingRaw`:

```json
600
```

`priceRaw`:

```json
100
```

`lotRaw`:

```json
10
```

`restingRaw`:

```json
[
  {
    "order_id": "R-1",
    "side": "sell",
    "price": 100,
    "remaining_quantity": 500,
    "arrival_sequence": 10
  },
  {
    "order_id": "R-2",
    "side": "sell",
    "price": 100,
    "remaining_quantity": 300,
    "arrival_sequence": 20
  },
  {
    "order_id": "R-3",
    "side": "sell",
    "price": 100,
    "remaining_quantity": 200,
    "arrival_sequence": 30
  }
]
```

### Call

```ts
proRataMatching(incomingRaw, priceRaw, lotRaw, restingRaw)
```

### Returns

object with 9 fields: model, price, lot_size, incoming_quantity, executable_quantity, allocated_quantity, unfilled_quantity, allocations, …

```json
{
  "model": "single-price-lot-aware-pro-rata",
  "price": 100,
  "lot_size": 10,
  "incoming_quantity": 600,
  "executable_quantity": 600,
  "allocated_quantity": 600,
  "unfilled_quantity": 0,
  "allocations": [
    {
      "order_id": "R-1",
      "resting_quantity": 500,
      "allocated_quantity": 300,
      "remaining_quantity": 200,
      "arrival_sequence": 10
    },
    {
      "order_id": "R-2",
      "resting_quantity": 300,
      "allocated_quantity": 180,
      "remaining_quantity": 120,
      "arrival_sequence": 20
    },
    {
      "order_id": "R-3",
      "resting_quantity": 200,
      "allocated_quantity": 120,
      "remaining_quantity": 80,
      "arrival_sequence": 30
    }
  ],
  "state": "fully-allocated"
}
```

## Other exports

`priceTimePriority`, `sizeTimePriority`, `hybridProRataTime`, `calculate`. Every module additionally exports `run` as an alias of its primary
function, and a `meta` object carrying its catalog id, domain, family, shape and article URL.

## Verification and provenance

Tier: **verified** (via D).

The worked example below is the figure published in this algorithm's article, replayed and asserted by the test suite on every build. The arithmetic cannot drift without the build failing.

Both tiers guarantee the signature. Full explanation: https://docs.thefintechbuilder.com/guides/verification/

Generated from the docs.json payload shipped inside fintech-algorithms@0.13.1.
The signature and parameter list are checked against the compiled implementation at build time,
so a description that contradicts the code fails the build rather than reaching this file.

## Links

- Article (how it works, step by step): https://thefintechbuilder.com/matching-engines-and-venue-logic/continuous-matching/pro-rata-matching/
- Implementation source: https://github.com/IslamBaraka90/Fintech-Algorithms-Library/blob/main/src/matching-engines-and-venue-logic/continuous-matching/pro-rata-matching/impl.ts
- Package on npm: https://www.npmjs.com/package/fintech-algorithms
- Domain index for agents: https://docs.thefintechbuilder.com/matching-engines-and-venue-logic/llms.txt
