# Size-Time Priority

`D12-F01-A03` · 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/size-time-priority/
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 { sizeTimePriority } from "fintech-algorithms/matching-engines-and-venue-logic/continuous-matching/size-time-priority";
```

## Signature

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

Orders by size first and arrival second — rewarding large resting orders. Used where a venue wants to attract size rather than speed.

## Parameters

| Name | Type | Required | Notes |
| --- | --- | --- | --- |
| `incomingRaw` | `Order` | yes | The aggressing order. |
| `priceRaw` | `number` | yes | Price level. |
| `lotRaw` | `number` | yes | Lot size. · min: 1, integer: true |
| `restingRaw` | `Order[]` | yes | Resting orders at that price. |

## Returns

`{ fills, residual, ordering, … }`

Fills with the priority ordering that produced them.

## Errors

- When lot size is not a positive integer — throws

## Complexity

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

## 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
650
```

`priceRaw`:

```json
50
```

`lotRaw`:

```json
10
```

`restingRaw`:

```json
[
  {
    "order_id": "ST-1",
    "side": "buy",
    "price": 50,
    "remaining_quantity": 300,
    "arrival_sequence": 10
  },
  {
    "order_id": "ST-2",
    "side": "buy",
    "price": 50,
    "remaining_quantity": 500,
    "arrival_sequence": 30
  },
  {
    "order_id": "ST-3",
    "side": "buy",
    "price": 50,
    "remaining_quantity": 500,
    "arrival_sequence": 20
  }
]
```

Showing 3 of 4 elements.

### Call

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

### Returns

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

```json
{
  "model": "single-price-size-then-time-priority",
  "price": 50,
  "lot_size": 10,
  "incoming_quantity": 650,
  "allocated_quantity": 650,
  "unfilled_quantity": 0,
  "ranked_order_ids": ["ST-3", "ST-2", "ST-1", "ST-4"],
  "allocations": [
    {
      "rank": 1,
      "order_id": "ST-3",
      "resting_quantity": 500,
      "allocated_quantity": 500,
      "remaining_quantity": 0,
      "arrival_sequence": 20
    },
    {
      "rank": 2,
      "order_id": "ST-2",
      "resting_quantity": 500,
      "allocated_quantity": 150,
      "remaining_quantity": 350,
      "arrival_sequence": 30
    }
  ],
  "state": "fully-allocated"
}
```

## Other exports

`priceTimePriority`, `proRataMatching`, `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/size-time-priority/
- Implementation source: https://github.com/IslamBaraka90/Fintech-Algorithms-Library/blob/main/src/matching-engines-and-venue-logic/continuous-matching/size-time-priority/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
