fintech-algorithms
Using a coding agent? Give it the skill: npx skills add IslamBaraka90/Fintech-Algorithms-Library What it does →

Size-Time Priority

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#

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#

NameTypeNotes
incomingRawOrderThe aggressing order.
priceRawnumberPrice level.
lotRawnumberLot size.
min: 1 · integer: true
restingRawOrder[]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#

executed 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
650
priceRaw
50
lotRaw
10
restingRaw
[
  {
    "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#

sizeTimePriority(incomingRaw, priceRaw, lotRaw, restingRaw)

Returns#

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

{
  "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#

This module also 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.

Diagrams#

Size-Time Priority — system map

Calculation flow#

Size-Time Priority calculation flow
flowchart LR
    S1["Validate oneprice and wholelot inputs"]
    S2["Sort open quantity descending"]
    S3["Break equalsize ties by oldest sequence"]
    S4["Sequentially fill the ranked queue"]
    S5["Return rank and quantity conservation trace"]
    S1 --> S2
    S2 --> S3
    S3 --> S4
    S4 --> S5
    S5 --> D{"equalsize time priority and postpartialfill reranking"}
    D --> O["allocated_quantity + diagnostics"]
    O --> A["Audit: A smaller open order never ranks ahead of a larger one"]

How it works#

This page states the contract — how to call it correctly. The article explains the concept: why it works, and where it breaks.

Read the article →

References#

The rest of the Continuous Matching family#